pm24xx.c 8.0 KB

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