pm.c 7.7 KB

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