pm.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* linux/arch/arm/plat-s3c64xx/pm.c
  2. *
  3. * Copyright 2008 Openmoko, Inc.
  4. * Copyright 2008 Simtec Electronics
  5. * Ben Dooks <ben@simtec.co.uk>
  6. * http://armlinux.simtec.co.uk/
  7. *
  8. * S3C64XX CPU PM support.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/suspend.h>
  16. #include <linux/serial_core.h>
  17. #include <linux/io.h>
  18. #include <linux/gpio.h>
  19. #include <linux/pm_domain.h>
  20. #include <mach/map.h>
  21. #include <mach/irqs.h>
  22. #include <plat/cpu.h>
  23. #include <plat/devs.h>
  24. #include <plat/pm.h>
  25. #include <plat/wakeup-mask.h>
  26. #include <mach/regs-gpio.h>
  27. #include <mach/regs-clock.h>
  28. #include <mach/gpio-samsung.h>
  29. #include "regs-gpio-memport.h"
  30. #include "regs-modem.h"
  31. #include "regs-sys.h"
  32. #include "regs-syscon-power.h"
  33. struct s3c64xx_pm_domain {
  34. char *const name;
  35. u32 ena;
  36. u32 pwr_stat;
  37. struct generic_pm_domain pd;
  38. };
  39. static int s3c64xx_pd_off(struct generic_pm_domain *domain)
  40. {
  41. struct s3c64xx_pm_domain *pd;
  42. u32 val;
  43. pd = container_of(domain, struct s3c64xx_pm_domain, pd);
  44. val = __raw_readl(S3C64XX_NORMAL_CFG);
  45. val &= ~(pd->ena);
  46. __raw_writel(val, S3C64XX_NORMAL_CFG);
  47. return 0;
  48. }
  49. static int s3c64xx_pd_on(struct generic_pm_domain *domain)
  50. {
  51. struct s3c64xx_pm_domain *pd;
  52. u32 val;
  53. long retry = 1000000L;
  54. pd = container_of(domain, struct s3c64xx_pm_domain, pd);
  55. val = __raw_readl(S3C64XX_NORMAL_CFG);
  56. val |= pd->ena;
  57. __raw_writel(val, S3C64XX_NORMAL_CFG);
  58. /* Not all domains provide power status readback */
  59. if (pd->pwr_stat) {
  60. do {
  61. cpu_relax();
  62. if (__raw_readl(S3C64XX_BLK_PWR_STAT) & pd->pwr_stat)
  63. break;
  64. } while (retry--);
  65. if (!retry) {
  66. pr_err("Failed to start domain %s\n", pd->name);
  67. return -EBUSY;
  68. }
  69. }
  70. return 0;
  71. }
  72. static struct s3c64xx_pm_domain s3c64xx_pm_irom = {
  73. .name = "IROM",
  74. .ena = S3C64XX_NORMALCFG_IROM_ON,
  75. .pd = {
  76. .power_off = s3c64xx_pd_off,
  77. .power_on = s3c64xx_pd_on,
  78. },
  79. };
  80. static struct s3c64xx_pm_domain s3c64xx_pm_etm = {
  81. .name = "ETM",
  82. .ena = S3C64XX_NORMALCFG_DOMAIN_ETM_ON,
  83. .pwr_stat = S3C64XX_BLKPWRSTAT_ETM,
  84. .pd = {
  85. .power_off = s3c64xx_pd_off,
  86. .power_on = s3c64xx_pd_on,
  87. },
  88. };
  89. static struct s3c64xx_pm_domain s3c64xx_pm_s = {
  90. .name = "S",
  91. .ena = S3C64XX_NORMALCFG_DOMAIN_S_ON,
  92. .pwr_stat = S3C64XX_BLKPWRSTAT_S,
  93. .pd = {
  94. .power_off = s3c64xx_pd_off,
  95. .power_on = s3c64xx_pd_on,
  96. },
  97. };
  98. static struct s3c64xx_pm_domain s3c64xx_pm_f = {
  99. .name = "F",
  100. .ena = S3C64XX_NORMALCFG_DOMAIN_F_ON,
  101. .pwr_stat = S3C64XX_BLKPWRSTAT_F,
  102. .pd = {
  103. .power_off = s3c64xx_pd_off,
  104. .power_on = s3c64xx_pd_on,
  105. },
  106. };
  107. static struct s3c64xx_pm_domain s3c64xx_pm_p = {
  108. .name = "P",
  109. .ena = S3C64XX_NORMALCFG_DOMAIN_P_ON,
  110. .pwr_stat = S3C64XX_BLKPWRSTAT_P,
  111. .pd = {
  112. .power_off = s3c64xx_pd_off,
  113. .power_on = s3c64xx_pd_on,
  114. },
  115. };
  116. static struct s3c64xx_pm_domain s3c64xx_pm_i = {
  117. .name = "I",
  118. .ena = S3C64XX_NORMALCFG_DOMAIN_I_ON,
  119. .pwr_stat = S3C64XX_BLKPWRSTAT_I,
  120. .pd = {
  121. .power_off = s3c64xx_pd_off,
  122. .power_on = s3c64xx_pd_on,
  123. },
  124. };
  125. static struct s3c64xx_pm_domain s3c64xx_pm_g = {
  126. .name = "G",
  127. .ena = S3C64XX_NORMALCFG_DOMAIN_G_ON,
  128. .pd = {
  129. .power_off = s3c64xx_pd_off,
  130. .power_on = s3c64xx_pd_on,
  131. },
  132. };
  133. static struct s3c64xx_pm_domain s3c64xx_pm_v = {
  134. .name = "V",
  135. .ena = S3C64XX_NORMALCFG_DOMAIN_V_ON,
  136. .pwr_stat = S3C64XX_BLKPWRSTAT_V,
  137. .pd = {
  138. .power_off = s3c64xx_pd_off,
  139. .power_on = s3c64xx_pd_on,
  140. },
  141. };
  142. static struct s3c64xx_pm_domain *s3c64xx_always_on_pm_domains[] = {
  143. &s3c64xx_pm_irom,
  144. };
  145. static struct s3c64xx_pm_domain *s3c64xx_pm_domains[] = {
  146. &s3c64xx_pm_etm,
  147. &s3c64xx_pm_g,
  148. &s3c64xx_pm_v,
  149. &s3c64xx_pm_i,
  150. &s3c64xx_pm_p,
  151. &s3c64xx_pm_s,
  152. &s3c64xx_pm_f,
  153. };
  154. #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
  155. void s3c_pm_debug_smdkled(u32 set, u32 clear)
  156. {
  157. unsigned long flags;
  158. int i;
  159. local_irq_save(flags);
  160. for (i = 0; i < 4; i++) {
  161. if (clear & (1 << i))
  162. gpio_set_value(S3C64XX_GPN(12 + i), 0);
  163. if (set & (1 << i))
  164. gpio_set_value(S3C64XX_GPN(12 + i), 1);
  165. }
  166. local_irq_restore(flags);
  167. }
  168. #endif
  169. #ifdef CONFIG_PM_SLEEP
  170. static struct sleep_save core_save[] = {
  171. SAVE_ITEM(S3C64XX_MEM0DRVCON),
  172. SAVE_ITEM(S3C64XX_MEM1DRVCON),
  173. };
  174. static struct sleep_save misc_save[] = {
  175. SAVE_ITEM(S3C64XX_AHB_CON0),
  176. SAVE_ITEM(S3C64XX_AHB_CON1),
  177. SAVE_ITEM(S3C64XX_AHB_CON2),
  178. SAVE_ITEM(S3C64XX_SPCON),
  179. SAVE_ITEM(S3C64XX_MEM0CONSTOP),
  180. SAVE_ITEM(S3C64XX_MEM1CONSTOP),
  181. SAVE_ITEM(S3C64XX_MEM0CONSLP0),
  182. SAVE_ITEM(S3C64XX_MEM0CONSLP1),
  183. SAVE_ITEM(S3C64XX_MEM1CONSLP),
  184. SAVE_ITEM(S3C64XX_SDMA_SEL),
  185. SAVE_ITEM(S3C64XX_MODEM_MIFPCON),
  186. SAVE_ITEM(S3C64XX_NORMAL_CFG),
  187. };
  188. void s3c_pm_configure_extint(void)
  189. {
  190. __raw_writel(s3c_irqwake_eintmask, S3C64XX_EINT_MASK);
  191. }
  192. void s3c_pm_restore_core(void)
  193. {
  194. __raw_writel(0, S3C64XX_EINT_MASK);
  195. s3c_pm_debug_smdkled(1 << 2, 0);
  196. s3c_pm_do_restore_core(core_save, ARRAY_SIZE(core_save));
  197. s3c_pm_do_restore(misc_save, ARRAY_SIZE(misc_save));
  198. }
  199. void s3c_pm_save_core(void)
  200. {
  201. s3c_pm_do_save(misc_save, ARRAY_SIZE(misc_save));
  202. s3c_pm_do_save(core_save, ARRAY_SIZE(core_save));
  203. }
  204. #endif
  205. /* since both s3c6400 and s3c6410 share the same sleep pm calls, we
  206. * put the per-cpu code in here until any new cpu comes along and changes
  207. * this.
  208. */
  209. static int s3c64xx_cpu_suspend(unsigned long arg)
  210. {
  211. unsigned long tmp;
  212. /* set our standby method to sleep */
  213. tmp = __raw_readl(S3C64XX_PWR_CFG);
  214. tmp &= ~S3C64XX_PWRCFG_CFG_WFI_MASK;
  215. tmp |= S3C64XX_PWRCFG_CFG_WFI_SLEEP;
  216. __raw_writel(tmp, S3C64XX_PWR_CFG);
  217. /* clear any old wakeup */
  218. __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT),
  219. S3C64XX_WAKEUP_STAT);
  220. /* set the LED state to 0110 over sleep */
  221. s3c_pm_debug_smdkled(3 << 1, 0xf);
  222. /* issue the standby signal into the pm unit. Note, we
  223. * issue a write-buffer drain just in case */
  224. tmp = 0;
  225. asm("b 1f\n\t"
  226. ".align 5\n\t"
  227. "1:\n\t"
  228. "mcr p15, 0, %0, c7, c10, 5\n\t"
  229. "mcr p15, 0, %0, c7, c10, 4\n\t"
  230. "mcr p15, 0, %0, c7, c0, 4" :: "r" (tmp));
  231. /* we should never get past here */
  232. pr_info("Failed to suspend the system\n");
  233. return 1; /* Aborting suspend */
  234. }
  235. /* mapping of interrupts to parts of the wakeup mask */
  236. static struct samsung_wakeup_mask wake_irqs[] = {
  237. { .irq = IRQ_RTC_ALARM, .bit = S3C64XX_PWRCFG_RTC_ALARM_DISABLE, },
  238. { .irq = IRQ_RTC_TIC, .bit = S3C64XX_PWRCFG_RTC_TICK_DISABLE, },
  239. { .irq = IRQ_PENDN, .bit = S3C64XX_PWRCFG_TS_DISABLE, },
  240. { .irq = IRQ_HSMMC0, .bit = S3C64XX_PWRCFG_MMC0_DISABLE, },
  241. { .irq = IRQ_HSMMC1, .bit = S3C64XX_PWRCFG_MMC1_DISABLE, },
  242. { .irq = IRQ_HSMMC2, .bit = S3C64XX_PWRCFG_MMC2_DISABLE, },
  243. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_BATF_DISABLE},
  244. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
  245. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_HSI_DISABLE },
  246. { .irq = NO_WAKEUP_IRQ, .bit = S3C64XX_PWRCFG_MSM_DISABLE },
  247. };
  248. static void s3c64xx_pm_prepare(void)
  249. {
  250. samsung_sync_wakemask(S3C64XX_PWR_CFG,
  251. wake_irqs, ARRAY_SIZE(wake_irqs));
  252. /* store address of resume. */
  253. __raw_writel(virt_to_phys(s3c_cpu_resume), S3C64XX_INFORM0);
  254. /* ensure previous wakeup state is cleared before sleeping */
  255. __raw_writel(__raw_readl(S3C64XX_WAKEUP_STAT), S3C64XX_WAKEUP_STAT);
  256. }
  257. int __init s3c64xx_pm_init(void)
  258. {
  259. int i;
  260. s3c_pm_init();
  261. for (i = 0; i < ARRAY_SIZE(s3c64xx_always_on_pm_domains); i++)
  262. pm_genpd_init(&s3c64xx_always_on_pm_domains[i]->pd,
  263. &pm_domain_always_on_gov, false);
  264. for (i = 0; i < ARRAY_SIZE(s3c64xx_pm_domains); i++)
  265. pm_genpd_init(&s3c64xx_pm_domains[i]->pd, NULL, false);
  266. #ifdef CONFIG_S3C_DEV_FB
  267. if (dev_get_platdata(&s3c_device_fb.dev))
  268. pm_genpd_add_device(&s3c64xx_pm_f.pd, &s3c_device_fb.dev);
  269. #endif
  270. return 0;
  271. }
  272. static __init int s3c64xx_pm_initcall(void)
  273. {
  274. if (!soc_is_s3c64xx())
  275. return 0;
  276. pm_cpu_prep = s3c64xx_pm_prepare;
  277. pm_cpu_sleep = s3c64xx_cpu_suspend;
  278. #ifdef CONFIG_S3C_PM_DEBUG_LED_SMDK
  279. gpio_request(S3C64XX_GPN(12), "DEBUG_LED0");
  280. gpio_request(S3C64XX_GPN(13), "DEBUG_LED1");
  281. gpio_request(S3C64XX_GPN(14), "DEBUG_LED2");
  282. gpio_request(S3C64XX_GPN(15), "DEBUG_LED3");
  283. gpio_direction_output(S3C64XX_GPN(12), 0);
  284. gpio_direction_output(S3C64XX_GPN(13), 0);
  285. gpio_direction_output(S3C64XX_GPN(14), 0);
  286. gpio_direction_output(S3C64XX_GPN(15), 0);
  287. #endif
  288. return 0;
  289. }
  290. arch_initcall(s3c64xx_pm_initcall);