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