pm.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS - Power Management support
  6. *
  7. * Based on arch/arm/mach-s3c2410/pm.c
  8. * Copyright (c) 2006 Simtec Electronics
  9. * Ben Dooks <ben@simtec.co.uk>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/suspend.h>
  17. #include <linux/syscore_ops.h>
  18. #include <linux/io.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/hardware/cache-l2x0.h>
  23. #include <asm/smp_scu.h>
  24. #include <plat/cpu.h>
  25. #include <plat/pm.h>
  26. #include <plat/pll.h>
  27. #include <plat/regs-srom.h>
  28. #include <mach/regs-irq.h>
  29. #include <mach/regs-gpio.h>
  30. #include <mach/regs-clock.h>
  31. #include <mach/regs-pmu.h>
  32. #include <mach/pm-core.h>
  33. #include <mach/pmu.h>
  34. static struct sleep_save exynos4_set_clksrc[] = {
  35. { .reg = EXYNOS4_CLKSRC_MASK_TOP , .val = 0x00000001, },
  36. { .reg = EXYNOS4_CLKSRC_MASK_CAM , .val = 0x11111111, },
  37. { .reg = EXYNOS4_CLKSRC_MASK_TV , .val = 0x00000111, },
  38. { .reg = EXYNOS4_CLKSRC_MASK_LCD0 , .val = 0x00001111, },
  39. { .reg = EXYNOS4_CLKSRC_MASK_MAUDIO , .val = 0x00000001, },
  40. { .reg = EXYNOS4_CLKSRC_MASK_FSYS , .val = 0x01011111, },
  41. { .reg = EXYNOS4_CLKSRC_MASK_PERIL0 , .val = 0x01111111, },
  42. { .reg = EXYNOS4_CLKSRC_MASK_PERIL1 , .val = 0x01110111, },
  43. { .reg = EXYNOS4_CLKSRC_MASK_DMC , .val = 0x00010000, },
  44. };
  45. static struct sleep_save exynos4210_set_clksrc[] = {
  46. { .reg = EXYNOS4210_CLKSRC_MASK_LCD1 , .val = 0x00001111, },
  47. };
  48. static struct sleep_save exynos4_epll_save[] = {
  49. SAVE_ITEM(EXYNOS4_EPLL_CON0),
  50. SAVE_ITEM(EXYNOS4_EPLL_CON1),
  51. };
  52. static struct sleep_save exynos4_vpll_save[] = {
  53. SAVE_ITEM(EXYNOS4_VPLL_CON0),
  54. SAVE_ITEM(EXYNOS4_VPLL_CON1),
  55. };
  56. static struct sleep_save exynos5_sys_save[] = {
  57. SAVE_ITEM(EXYNOS5_SYS_I2C_CFG),
  58. };
  59. static struct sleep_save exynos_core_save[] = {
  60. /* SROM side */
  61. SAVE_ITEM(S5P_SROM_BW),
  62. SAVE_ITEM(S5P_SROM_BC0),
  63. SAVE_ITEM(S5P_SROM_BC1),
  64. SAVE_ITEM(S5P_SROM_BC2),
  65. SAVE_ITEM(S5P_SROM_BC3),
  66. };
  67. /* For Cortex-A9 Diagnostic and Power control register */
  68. static unsigned int save_arm_register[2];
  69. static int exynos_cpu_suspend(unsigned long arg)
  70. {
  71. #ifdef CONFIG_CACHE_L2X0
  72. outer_flush_all();
  73. #endif
  74. /* issue the standby signal into the pm unit. */
  75. cpu_do_idle();
  76. /* we should never get past here */
  77. panic("sleep resumed to originator?");
  78. }
  79. static void exynos_pm_prepare(void)
  80. {
  81. unsigned int tmp;
  82. s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
  83. if (!soc_is_exynos5250()) {
  84. s3c_pm_do_save(exynos4_epll_save, ARRAY_SIZE(exynos4_epll_save));
  85. s3c_pm_do_save(exynos4_vpll_save, ARRAY_SIZE(exynos4_vpll_save));
  86. } else {
  87. s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save));
  88. /* Disable USE_RETENTION of JPEG_MEM_OPTION */
  89. tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
  90. tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
  91. __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
  92. }
  93. /* Set value of power down register for sleep mode */
  94. exynos_sys_powerdown_conf(SYS_SLEEP);
  95. __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
  96. /* ensure at least INFORM0 has the resume address */
  97. __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
  98. /* Before enter central sequence mode, clock src register have to set */
  99. if (!soc_is_exynos5250())
  100. s3c_pm_do_restore_core(exynos4_set_clksrc, ARRAY_SIZE(exynos4_set_clksrc));
  101. if (soc_is_exynos4210())
  102. s3c_pm_do_restore_core(exynos4210_set_clksrc, ARRAY_SIZE(exynos4210_set_clksrc));
  103. }
  104. static int exynos_pm_add(struct device *dev, struct subsys_interface *sif)
  105. {
  106. pm_cpu_prep = exynos_pm_prepare;
  107. pm_cpu_sleep = exynos_cpu_suspend;
  108. return 0;
  109. }
  110. static unsigned long pll_base_rate;
  111. static void exynos4_restore_pll(void)
  112. {
  113. unsigned long pll_con, locktime, lockcnt;
  114. unsigned long pll_in_rate;
  115. unsigned int p_div, epll_wait = 0, vpll_wait = 0;
  116. if (pll_base_rate == 0)
  117. return;
  118. pll_in_rate = pll_base_rate;
  119. /* EPLL */
  120. pll_con = exynos4_epll_save[0].val;
  121. if (pll_con & (1 << 31)) {
  122. pll_con &= (PLL46XX_PDIV_MASK << PLL46XX_PDIV_SHIFT);
  123. p_div = (pll_con >> PLL46XX_PDIV_SHIFT);
  124. pll_in_rate /= 1000000;
  125. locktime = (3000 / pll_in_rate) * p_div;
  126. lockcnt = locktime * 10000 / (10000 / pll_in_rate);
  127. __raw_writel(lockcnt, EXYNOS4_EPLL_LOCK);
  128. s3c_pm_do_restore_core(exynos4_epll_save,
  129. ARRAY_SIZE(exynos4_epll_save));
  130. epll_wait = 1;
  131. }
  132. pll_in_rate = pll_base_rate;
  133. /* VPLL */
  134. pll_con = exynos4_vpll_save[0].val;
  135. if (pll_con & (1 << 31)) {
  136. pll_in_rate /= 1000000;
  137. /* 750us */
  138. locktime = 750;
  139. lockcnt = locktime * 10000 / (10000 / pll_in_rate);
  140. __raw_writel(lockcnt, EXYNOS4_VPLL_LOCK);
  141. s3c_pm_do_restore_core(exynos4_vpll_save,
  142. ARRAY_SIZE(exynos4_vpll_save));
  143. vpll_wait = 1;
  144. }
  145. /* Wait PLL locking */
  146. do {
  147. if (epll_wait) {
  148. pll_con = __raw_readl(EXYNOS4_EPLL_CON0);
  149. if (pll_con & (1 << EXYNOS4_EPLLCON0_LOCKED_SHIFT))
  150. epll_wait = 0;
  151. }
  152. if (vpll_wait) {
  153. pll_con = __raw_readl(EXYNOS4_VPLL_CON0);
  154. if (pll_con & (1 << EXYNOS4_VPLLCON0_LOCKED_SHIFT))
  155. vpll_wait = 0;
  156. }
  157. } while (epll_wait || vpll_wait);
  158. }
  159. static struct subsys_interface exynos_pm_interface = {
  160. .name = "exynos_pm",
  161. .subsys = &exynos_subsys,
  162. .add_dev = exynos_pm_add,
  163. };
  164. static __init int exynos_pm_drvinit(void)
  165. {
  166. struct clk *pll_base;
  167. unsigned int tmp;
  168. s3c_pm_init();
  169. /* All wakeup disable */
  170. tmp = __raw_readl(S5P_WAKEUP_MASK);
  171. tmp |= ((0xFF << 8) | (0x1F << 1));
  172. __raw_writel(tmp, S5P_WAKEUP_MASK);
  173. if (!soc_is_exynos5250()) {
  174. pll_base = clk_get(NULL, "xtal");
  175. if (!IS_ERR(pll_base)) {
  176. pll_base_rate = clk_get_rate(pll_base);
  177. clk_put(pll_base);
  178. }
  179. }
  180. return subsys_interface_register(&exynos_pm_interface);
  181. }
  182. arch_initcall(exynos_pm_drvinit);
  183. static int exynos_pm_suspend(void)
  184. {
  185. unsigned long tmp;
  186. /* Setting Central Sequence Register for power down mode */
  187. tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
  188. tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
  189. __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
  190. /* Setting SEQ_OPTION register */
  191. tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
  192. __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
  193. if (!soc_is_exynos5250()) {
  194. /* Save Power control register */
  195. asm ("mrc p15, 0, %0, c15, c0, 0"
  196. : "=r" (tmp) : : "cc");
  197. save_arm_register[0] = tmp;
  198. /* Save Diagnostic register */
  199. asm ("mrc p15, 0, %0, c15, c0, 1"
  200. : "=r" (tmp) : : "cc");
  201. save_arm_register[1] = tmp;
  202. }
  203. return 0;
  204. }
  205. static void exynos_pm_resume(void)
  206. {
  207. unsigned long tmp;
  208. /*
  209. * If PMU failed while entering sleep mode, WFI will be
  210. * ignored by PMU and then exiting cpu_do_idle().
  211. * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
  212. * in this situation.
  213. */
  214. tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
  215. if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
  216. tmp |= S5P_CENTRAL_LOWPWR_CFG;
  217. __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
  218. /* No need to perform below restore code */
  219. goto early_wakeup;
  220. }
  221. if (!soc_is_exynos5250()) {
  222. /* Restore Power control register */
  223. tmp = save_arm_register[0];
  224. asm volatile ("mcr p15, 0, %0, c15, c0, 0"
  225. : : "r" (tmp)
  226. : "cc");
  227. /* Restore Diagnostic register */
  228. tmp = save_arm_register[1];
  229. asm volatile ("mcr p15, 0, %0, c15, c0, 1"
  230. : : "r" (tmp)
  231. : "cc");
  232. }
  233. /* For release retention */
  234. __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
  235. __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
  236. __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
  237. __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
  238. __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
  239. __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
  240. __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
  241. if (soc_is_exynos5250())
  242. s3c_pm_do_restore(exynos5_sys_save,
  243. ARRAY_SIZE(exynos5_sys_save));
  244. s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
  245. if (!soc_is_exynos5250()) {
  246. exynos4_restore_pll();
  247. #ifdef CONFIG_SMP
  248. scu_enable(S5P_VA_SCU);
  249. #endif
  250. }
  251. early_wakeup:
  252. return;
  253. }
  254. static struct syscore_ops exynos_pm_syscore_ops = {
  255. .suspend = exynos_pm_suspend,
  256. .resume = exynos_pm_resume,
  257. };
  258. static __init int exynos_pm_syscore_init(void)
  259. {
  260. register_syscore_ops(&exynos_pm_syscore_ops);
  261. return 0;
  262. }
  263. arch_initcall(exynos_pm_syscore_init);