pm24xx.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP2 Power Management Routines
  4. *
  5. * Copyright (C) 2005 Texas Instruments, Inc.
  6. * Copyright (C) 2006-2008 Nokia Corporation
  7. *
  8. * Written by:
  9. * Richard Woodruff <[email protected]>
  10. * Tony Lindgren
  11. * Juha Yrjola
  12. * Amit Kucheria <[email protected]>
  13. * Igor Stoppa <[email protected]>
  14. *
  15. * Based on pm.c for omap1
  16. */
  17. #include <linux/cpu_pm.h>
  18. #include <linux/suspend.h>
  19. #include <linux/sched.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/sysfs.h>
  23. #include <linux/module.h>
  24. #include <linux/delay.h>
  25. #include <linux/clk.h>
  26. #include <linux/clk-provider.h>
  27. #include <linux/irq.h>
  28. #include <linux/time.h>
  29. #include <asm/fncpy.h>
  30. #include <asm/mach/time.h>
  31. #include <asm/mach/irq.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/system_misc.h>
  34. #include <linux/omap-dma.h>
  35. #include "soc.h"
  36. #include "common.h"
  37. #include "clock.h"
  38. #include "prm2xxx.h"
  39. #include "prm-regbits-24xx.h"
  40. #include "cm2xxx.h"
  41. #include "cm-regbits-24xx.h"
  42. #include "sdrc.h"
  43. #include "sram.h"
  44. #include "pm.h"
  45. #include "control.h"
  46. #include "powerdomain.h"
  47. #include "clockdomain.h"
  48. static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
  49. void __iomem *sdrc_power);
  50. static struct powerdomain *mpu_pwrdm, *core_pwrdm;
  51. static struct clockdomain *dsp_clkdm, *mpu_clkdm, *wkup_clkdm, *gfx_clkdm;
  52. static struct clk *osc_ck, *emul_ck;
  53. static int omap2_enter_full_retention(void)
  54. {
  55. u32 l;
  56. /* There is 1 reference hold for all children of the oscillator
  57. * clock, the following will remove it. If no one else uses the
  58. * oscillator itself it will be disabled if/when we enter retention
  59. * mode.
  60. */
  61. clk_disable(osc_ck);
  62. /* Clear old wake-up events */
  63. /* REVISIT: These write to reserved bits? */
  64. omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
  65. omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
  66. omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, ~0);
  67. pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_RET);
  68. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
  69. /* Workaround to kill USB */
  70. l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL;
  71. omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0);
  72. /* One last check for pending IRQs to avoid extra latency due
  73. * to sleeping unnecessarily. */
  74. if (omap_irq_pending())
  75. goto no_sleep;
  76. /* Jump to SRAM suspend code */
  77. omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL),
  78. OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL),
  79. OMAP_SDRC_REGADDR(SDRC_POWER));
  80. no_sleep:
  81. clk_enable(osc_ck);
  82. /* clear CORE wake-up events */
  83. omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
  84. omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
  85. /* wakeup domain events - bit 1: GPT1, bit5 GPIO */
  86. omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, 0x4 | 0x1);
  87. /* MPU domain wake events */
  88. omap_prm_clear_mod_irqs(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET, 0x1);
  89. omap_prm_clear_mod_irqs(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET, 0x20);
  90. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  91. pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_ON);
  92. return 0;
  93. }
  94. static int sti_console_enabled;
  95. static int omap2_allow_mpu_retention(void)
  96. {
  97. if (!omap2xxx_cm_mpu_retention_allowed())
  98. return 0;
  99. if (sti_console_enabled)
  100. return 0;
  101. return 1;
  102. }
  103. static void omap2_enter_mpu_retention(void)
  104. {
  105. const int zero = 0;
  106. /* The peripherals seem not to be able to wake up the MPU when
  107. * it is in retention mode. */
  108. if (omap2_allow_mpu_retention()) {
  109. /* REVISIT: These write to reserved bits? */
  110. omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
  111. omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
  112. omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, ~0);
  113. /* Try to enter MPU retention */
  114. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
  115. } else {
  116. /* Block MPU retention */
  117. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  118. }
  119. /* WFI */
  120. asm("mcr p15, 0, %0, c7, c0, 4" : : "r" (zero) : "memory", "cc");
  121. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  122. }
  123. static int omap2_can_sleep(void)
  124. {
  125. if (omap2xxx_cm_fclks_active())
  126. return 0;
  127. if (__clk_is_enabled(osc_ck))
  128. return 0;
  129. return 1;
  130. }
  131. static void omap2_pm_idle(void)
  132. {
  133. int error;
  134. if (omap_irq_pending())
  135. return;
  136. error = cpu_cluster_pm_enter();
  137. if (error || !omap2_can_sleep()) {
  138. omap2_enter_mpu_retention();
  139. goto out_cpu_cluster_pm;
  140. }
  141. omap2_enter_full_retention();
  142. out_cpu_cluster_pm:
  143. cpu_cluster_pm_exit();
  144. }
  145. static void __init prcm_setup_regs(void)
  146. {
  147. int i, num_mem_banks;
  148. struct powerdomain *pwrdm;
  149. /*
  150. * Enable autoidle
  151. * XXX This should be handled by hwmod code or PRCM init code
  152. */
  153. omap2_prm_write_mod_reg(OMAP24XX_AUTOIDLE_MASK, OCP_MOD,
  154. OMAP2_PRCM_SYSCONFIG_OFFSET);
  155. /*
  156. * Set CORE powerdomain memory banks to retain their contents
  157. * during RETENTION
  158. */
  159. num_mem_banks = pwrdm_get_mem_bank_count(core_pwrdm);
  160. for (i = 0; i < num_mem_banks; i++)
  161. pwrdm_set_mem_retst(core_pwrdm, i, PWRDM_POWER_RET);
  162. pwrdm_set_logic_retst(core_pwrdm, PWRDM_POWER_RET);
  163. pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
  164. /* Force-power down DSP, GFX powerdomains */
  165. pwrdm = clkdm_get_pwrdm(dsp_clkdm);
  166. pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
  167. pwrdm = clkdm_get_pwrdm(gfx_clkdm);
  168. pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
  169. /* Enable hardware-supervised idle for all clkdms */
  170. clkdm_for_each(omap_pm_clkdms_setup, NULL);
  171. clkdm_add_wkdep(mpu_clkdm, wkup_clkdm);
  172. omap_common_suspend_init(omap2_enter_full_retention);
  173. /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk
  174. * stabilisation */
  175. omap2_prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
  176. OMAP2_PRCM_CLKSSETUP_OFFSET);
  177. /* Configure automatic voltage transition */
  178. omap2_prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
  179. OMAP2_PRCM_VOLTSETUP_OFFSET);
  180. omap2_prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT_MASK |
  181. (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT) |
  182. OMAP24XX_MEMRETCTRL_MASK |
  183. (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT) |
  184. (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT),
  185. OMAP24XX_GR_MOD, OMAP2_PRCM_VOLTCTRL_OFFSET);
  186. /* Enable wake-up events */
  187. omap2_prm_write_mod_reg(OMAP24XX_EN_GPIOS_MASK | OMAP24XX_EN_GPT1_MASK,
  188. WKUP_MOD, PM_WKEN);
  189. /* Enable SYS_CLKEN control when all domains idle */
  190. omap2_prm_set_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK, OMAP24XX_GR_MOD,
  191. OMAP2_PRCM_CLKSRC_CTRL_OFFSET);
  192. }
  193. int __init omap2_pm_init(void)
  194. {
  195. u32 l;
  196. printk(KERN_INFO "Power Management for OMAP2 initializing\n");
  197. l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_REVISION_OFFSET);
  198. printk(KERN_INFO "PRCM revision %d.%d\n", (l >> 4) & 0x0f, l & 0x0f);
  199. /* Look up important powerdomains */
  200. mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
  201. if (!mpu_pwrdm)
  202. pr_err("PM: mpu_pwrdm not found\n");
  203. core_pwrdm = pwrdm_lookup("core_pwrdm");
  204. if (!core_pwrdm)
  205. pr_err("PM: core_pwrdm not found\n");
  206. /* Look up important clockdomains */
  207. mpu_clkdm = clkdm_lookup("mpu_clkdm");
  208. if (!mpu_clkdm)
  209. pr_err("PM: mpu_clkdm not found\n");
  210. wkup_clkdm = clkdm_lookup("wkup_clkdm");
  211. if (!wkup_clkdm)
  212. pr_err("PM: wkup_clkdm not found\n");
  213. dsp_clkdm = clkdm_lookup("dsp_clkdm");
  214. if (!dsp_clkdm)
  215. pr_err("PM: dsp_clkdm not found\n");
  216. gfx_clkdm = clkdm_lookup("gfx_clkdm");
  217. if (!gfx_clkdm)
  218. pr_err("PM: gfx_clkdm not found\n");
  219. osc_ck = clk_get(NULL, "osc_ck");
  220. if (IS_ERR(osc_ck)) {
  221. printk(KERN_ERR "could not get osc_ck\n");
  222. return -ENODEV;
  223. }
  224. if (cpu_is_omap242x()) {
  225. emul_ck = clk_get(NULL, "emul_ck");
  226. if (IS_ERR(emul_ck)) {
  227. printk(KERN_ERR "could not get emul_ck\n");
  228. clk_put(osc_ck);
  229. return -ENODEV;
  230. }
  231. }
  232. prcm_setup_regs();
  233. /*
  234. * We copy the assembler sleep/wakeup routines to SRAM.
  235. * These routines need to be in SRAM as that's the only
  236. * memory the MPU can see when it wakes up after the entire
  237. * chip enters idle.
  238. */
  239. omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend,
  240. omap24xx_cpu_suspend_sz);
  241. arm_pm_idle = omap2_pm_idle;
  242. return 0;
  243. }