pm-s3c64xx.c 9.3 KB

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