pm.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* linux/arch/arm/mach-s3c2416/pm.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * http://armlinux.simtec.co.uk/.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/list.h>
  16. #include <linux/timer.h>
  17. #include <linux/init.h>
  18. #include <linux/sysdev.h>
  19. #include <linux/platform_device.h>
  20. #include <asm/cacheflush.h>
  21. #include <asm/hardware.h>
  22. #include <asm/io.h>
  23. #include <asm/irq.h>
  24. #include <asm/arch/regs-mem.h>
  25. #include <asm/arch/regs-power.h>
  26. #include <asm/arch/regs-gpioj.h>
  27. #include <asm/arch/regs-gpio.h>
  28. #include <asm/arch/regs-irq.h>
  29. #include <asm/arch/regs-dsc.h>
  30. #include <asm/arch/regs-s3c2416-clock.h>
  31. #include <asm/plat-s3c24xx/cpu.h>
  32. #include <asm/plat-s3c24xx/pm.h>
  33. #include <asm/plat-s3c24xx/s3c2416.h>
  34. #include <asm/gpio.h>
  35. #ifdef CONFIG_PM_CPU_MODE
  36. extern unsigned char pm_cpu_mode;
  37. #endif
  38. static void s3c2416_cpu_suspend(void)
  39. {
  40. unsigned long tmp;
  41. #if 0
  42. /* This is the USB driver work not PM */
  43. /* USB Physical power */
  44. __raw_writel(__raw_readl(S3C2443_PHYPWR) | 0xf, S3C2443_PHYPWR);
  45. /* USB Suspend mode */
  46. __raw_writel(__raw_readl(S3C2410_MISCCR)|(1<<12)|(1<<13), S3C2410_MISCCR);
  47. #endif
  48. #if 0
  49. /* What the heck??? We configure (even badly) MASK & PENDING ints, and we
  50. * set them after to a more bad value ???? */
  51. __raw_writel(0xffffffff, S3C2410_INTMSK);
  52. __raw_writel(__raw_readl(S3C2410_SRCPND), S3C2410_SRCPND);
  53. __raw_writel(__raw_readl(S3C2410_INTPND), S3C2410_INTPND);
  54. __raw_writel(0xffffffff, S3C2410_EINTPEND);
  55. __raw_writel(0xffffffff, S3C2410_EINTMASK);
  56. __raw_writel(0xffffffff, S3C2410_SRCPND);
  57. __raw_writel(0xffffffff, S3C2410_INTPND);
  58. __raw_writel((0xffffffff & ~((1<<0) | (1<<3) | (1<<30))) , S3C2410_INTMSK);
  59. #endif
  60. /* TODO: Need verification */
  61. __raw_writel(0xff80, S3C2443_RSTCON);
  62. __raw_writel(0xffff, S3C2443_OSCSET);
  63. /* Allow wakeup even if BATT_FLT is asserted */
  64. __raw_writel( (1<<15), S3C2443_PWRCFG);
  65. #if 0
  66. /* Test */
  67. /* shutdown as many device as possible */
  68. /* Disable USB power */
  69. /* Disable SD Power */
  70. tmp = __raw_readl(S3C2410_GPHCON);
  71. tmp &= ~((3<<28)|(3<<8));
  72. tmp |= (1<<28)|(1<<8);
  73. __raw_writel(tmp, S3C2410_GPHCON);
  74. tmp = __raw_readl(S3C2410_GPHUP);
  75. tmp &= ~((3<<28)|(3<<8));
  76. __raw_writel(tmp, S3C2410_GPHUP);
  77. tmp = __raw_readl(S3C2410_GPHDAT);
  78. tmp &= ~((1<<14)|(1<<4));
  79. __raw_writel(tmp, S3C2410_GPHDAT);
  80. /* Disable TCON power */
  81. tmp = __raw_readl(S3C2410_GPBCON);
  82. tmp &= ~((3<<6));
  83. tmp |= (1<<6);
  84. __raw_writel(tmp, S3C2410_GPBCON);
  85. tmp = __raw_readl(S3C2410_GPBUP);
  86. tmp &= ~((3<<6));
  87. __raw_writel(tmp, S3C2410_GPBUP);
  88. tmp = __raw_readl(S3C2410_GPBDAT);
  89. tmp &= ~(1<<3);
  90. __raw_writel(tmp, S3C2410_GPBDAT);
  91. /* Disable Touch power */
  92. /* Disable wifi/bt power */
  93. tmp = __raw_readl(S3C2410_GPDCON);
  94. tmp &= ~((3<<20)|(3<22));
  95. tmp |= (1<<20)|(1<<22);
  96. __raw_writel(tmp, S3C2410_GPDCON);
  97. tmp = __raw_readl(S3C2410_GPDUP);
  98. tmp &= ~((3<<20)|(3<<22));
  99. __raw_writel(tmp, S3C2410_GPDUP);
  100. tmp = __raw_readl(S3C2410_GPDDAT);
  101. tmp &= ~((1<<11)|(1<<10));
  102. __raw_writel(tmp, S3C2410_GPDDAT);
  103. #endif
  104. #ifdef CONFIG_PM_CPU_MODE
  105. /* set our standby method to sleep */
  106. switch(pm_cpu_mode)
  107. {
  108. case PM_CPU_DEVICE_MODE_SUSPEND:
  109. __raw_writel(0x2BED, S3C2443_PWRMODE);
  110. break;
  111. case PM_CPU_MODE_STOP:
  112. __raw_writel(((__raw_readl(S3C2443_PWRMODE) & ~(1<<16))| (1<<16)), S3C2443_PWRMODE);
  113. break;
  114. case PM_CPU_MODE_DEEP_STOP:
  115. __raw_writel(((__raw_readl(S3C2443_PWRCFG) & ~(1<<16))| (1<<16)), S3C2443_PWRCFG);
  116. __raw_writel(((__raw_readl(S3C2443_PWRMODE) & ~(1<<16))| (1<<16)), S3C2443_PWRMODE);
  117. break;
  118. case PM_CPU_MODE_IDLE:
  119. __raw_writel(((__raw_readl(S3C2443_PWRCFG) & ~(1<<17))| (1<<17)), S3C2443_PWRCFG);
  120. asm("mcr p15, 0, r0, c7, c0, 4"); /* wait for interrupt "STANDBYWFI" */
  121. break;
  122. case PM_CPU_MODE_SLEEP:
  123. __raw_writel(0x2BED, S3C2443_PWRMODE);
  124. break;
  125. default:
  126. __raw_writel(0x2BED, S3C2443_PWRMODE);
  127. break;
  128. }
  129. #else
  130. __raw_writel(0x2BED, S3C2443_PWRMODE);
  131. #endif
  132. }
  133. static void s3c2416_pm_prepare(void)
  134. {
  135. /* set flag to wake up */
  136. __raw_writel(0x2BED, S3C2443_INFORM0);
  137. /* Set Power_Mode to low */
  138. //s3c2410_gpio_cfgpin(S3C2410_GPD12, S3C2410_GPD12_OUTP); /* <- D12 should already be configured */
  139. /* TODO: have a "charger/battery driver" (maybe inside the USB driver?) */
  140. s3c2410_gpio_setpin(S3C2410_GPD12, 0);
  141. }
  142. static int s3c2416_pm_add(struct sys_device *sysdev)
  143. {
  144. pm_cpu_prep = s3c2416_pm_prepare;
  145. pm_cpu_sleep = s3c2416_cpu_suspend;
  146. return 0;
  147. }
  148. static int s3c2416_pm_suspend(struct sys_device *dev, pm_message_t state)
  149. {
  150. return 0;
  151. }
  152. static int s3c2416_pm_resume(struct sys_device *dev)
  153. {
  154. __raw_writel(0x0, S3C2443_INFORM0);
  155. /* set PowerMode as high */
  156. // s3c2410_gpio_cfgpin(S3C2410_GPD12, S3C2410_GPD12_OUTP); /* <- D12 should already be configured */
  157. s3c2410_gpio_setpin(S3C2410_GPD12, 1);
  158. return 0;
  159. }
  160. static struct sysdev_driver s3c2416_pm_driver = {
  161. .add = s3c2416_pm_add,
  162. .suspend = s3c2416_pm_suspend,
  163. .resume = s3c2416_pm_resume,
  164. };
  165. static __init int s3c2416_pm_init(void)
  166. {
  167. return sysdev_driver_register(&s3c2416_sysclass, &s3c2416_pm_driver);
  168. }
  169. arch_initcall(s3c2416_pm_init);