2 * linux/arch/arm/mach-omap2/pm.c
4 * OMAP2 Power Management Routines
6 * Copyright (C) 2005 Texas Instruments, Inc.
7 * Copyright (C) 2006-2008 Nokia Corporation
10 * Richard Woodruff <r-woodruff2@ti.com>
13 * Amit Kucheria <amit.kucheria@nokia.com>
14 * Igor Stoppa <igor.stoppa@nokia.com>
16 * Based on pm.c for omap1
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2 as
20 * published by the Free Software Foundation.
23 #include <linux/suspend.h>
24 #include <linux/sched.h>
25 #include <linux/proc_fs.h>
26 #include <linux/interrupt.h>
27 #include <linux/sysfs.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/clk.h>
32 #include <linux/irq.h>
34 #include <asm/mach/time.h>
35 #include <asm/mach/irq.h>
36 #include <asm/mach-types.h>
38 #include <asm/arch/irqs.h>
39 #include <asm/arch/clock.h>
40 #include <asm/arch/sram.h>
41 #include <asm/arch/control.h>
42 #include <asm/arch/gpio.h>
43 #include <asm/arch/pm.h>
44 #include <asm/arch/mux.h>
45 #include <asm/arch/dma.h>
46 #include <asm/arch/board.h>
49 #include "prm-regbits-24xx.h"
51 #include "cm-regbits-24xx.h"
55 #include <asm/arch/powerdomain.h>
56 #include <asm/arch/clockdomain.h>
58 static void (*omap2_sram_idle)(void);
59 static void (*omap2_sram_suspend)(void __iomem *dllctrl);
60 static void (*saved_idle)(void);
62 static struct powerdomain *mpu_pwrdm;
63 static struct powerdomain *core_pwrdm;
65 static struct clockdomain *dsp_clkdm;
66 static struct clockdomain *gfx_clkdm;
68 static struct clk *osc_ck, *emul_ck;
70 static int omap2_fclks_active(void)
74 f1 = cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
75 f2 = cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
76 serial_console_fclk_mask(&f1, &f2);
82 static void omap2_enter_full_retention(void)
84 u32 l, sleep_time = 0;
86 /* There is 1 reference hold for all children of the oscillator
87 * clock, the following will remove it. If no one else uses the
88 * oscillator itself it will be disabled if/when we enter retention
93 /* Clear old wake-up events */
94 /* REVISIT: These write to reserved bits? */
95 prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
96 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
97 prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST);
100 * Set MPU powerdomain's next power state to RETENTION;
101 * preserve logic state during retention
103 pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
104 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
106 /* Workaround to kill USB */
107 l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL;
108 omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0);
110 omap2_gpio_prepare_for_retention();
112 if (omap2_pm_debug) {
113 omap2_pm_dump(0, 0, 0);
114 sleep_time = omap2_read_32k_sync_counter();
117 /* One last check for pending IRQs to avoid extra latency due
118 * to sleeping unnecessarily. */
119 if (omap_irq_pending())
122 serial_console_sleep(1);
123 /* Jump to SRAM suspend code */
124 omap2_sram_suspend(OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL));
126 serial_console_sleep(0);
128 if (omap2_pm_debug) {
129 unsigned long long tmp;
132 resume_time = omap2_read_32k_sync_counter();
133 tmp = resume_time - sleep_time;
135 omap2_pm_dump(0, 1, tmp / 32768);
137 omap2_gpio_resume_after_retention();
141 /* clear CORE wake-up events */
142 prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
143 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
145 /* wakeup domain events - bit 1: GPT1, bit5 GPIO */
146 prm_clear_mod_reg_bits(0x4 | 0x1, WKUP_MOD, PM_WKST);
148 /* MPU domain wake events */
149 l = prm_read_mod_reg(OCP_MOD, OMAP2_PRM_IRQSTATUS_MPU_OFFSET);
151 prm_write_mod_reg(0x01, OCP_MOD,
152 OMAP2_PRM_IRQSTATUS_MPU_OFFSET);
154 prm_write_mod_reg(0x20, OCP_MOD,
155 OMAP2_PRM_IRQSTATUS_MPU_OFFSET);
157 /* Mask future PRCM-to-MPU interrupts */
158 prm_write_mod_reg(0x0, OCP_MOD, OMAP2_PRM_IRQSTATUS_MPU_OFFSET);
161 static int omap2_i2c_active(void)
165 l = cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
166 return l & (OMAP2420_EN_I2C2 | OMAP2420_EN_I2C1);
169 static int sti_console_enabled;
171 static int omap2_allow_mpu_retention(void)
175 if (atomic_read(&sleep_block))
178 /* Check for MMC, UART2, UART1, McSPI2, McSPI1 and DSS1. */
179 l = cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
180 if (l & (OMAP2420_EN_MMC | OMAP24XX_EN_UART2 |
181 OMAP24XX_EN_UART1 | OMAP24XX_EN_MCSPI2 |
182 OMAP24XX_EN_MCSPI1 | OMAP24XX_EN_DSS1))
184 /* Check for UART3. */
185 l = cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
186 if (l & OMAP24XX_EN_UART3)
188 if (sti_console_enabled)
194 static void omap2_enter_mpu_retention(void)
199 /* Putting MPU into the WFI state while a transfer is active
200 * seems to cause the I2C block to timeout. Why? Good question. */
201 if (omap2_i2c_active())
204 /* The peripherals seem not to be able to wake up the MPU when
205 * it is in retention mode. */
206 if (omap2_allow_mpu_retention()) {
207 /* REVISIT: These write to reserved bits? */
208 prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
209 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
210 prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST);
212 /* Try to enter MPU retention */
213 prm_write_mod_reg((0x01 << OMAP_POWERSTATE_SHIFT) |
215 MPU_MOD, PM_PWSTCTRL);
217 /* Block MPU retention */
219 prm_write_mod_reg(OMAP_LOGICRETSTATE, MPU_MOD, PM_PWSTCTRL);
223 if (omap2_pm_debug) {
224 omap2_pm_dump(only_idle ? 2 : 1, 0, 0);
225 sleep_time = omap2_read_32k_sync_counter();
230 if (omap2_pm_debug) {
231 unsigned long long tmp;
234 resume_time = omap2_read_32k_sync_counter();
235 tmp = resume_time - sleep_time;
237 omap2_pm_dump(only_idle ? 2 : 1, 1, tmp / 32768);
241 static int omap2_can_sleep(void)
243 if (!enable_dyn_sleep)
245 if (omap2_fclks_active())
247 if (atomic_read(&sleep_block) > 0)
249 if (clk_get_usecount(osc_ck) > 1)
251 if (omap_dma_running())
258 * Note that you can use clock_event_device->min_delta_ns if you want to
259 * avoid reprogramming timer too often when using CONFIG_NO_HZ.
261 static void omap2_pm_idle(void)
266 if (!omap2_can_sleep()) {
267 if (!atomic_read(&sleep_block) && omap_irq_pending())
269 omap2_enter_mpu_retention();
273 if (omap_irq_pending())
276 omap2_enter_full_retention();
283 static int omap2_pm_prepare(void)
285 /* We cannot sleep in idle until we have resumed */
286 saved_idle = pm_idle;
292 static int omap2_pm_suspend(void)
296 wken_wkup = prm_read_mod_reg(WKUP_MOD, PM_WKEN);
297 prm_write_mod_reg(wken_wkup & ~OMAP24XX_EN_GPT1, WKUP_MOD, PM_WKEN);
300 mir1 = omap_readl(0x480fe0a4);
301 omap_writel(1 << 5, 0x480fe0ac);
303 omap2_enter_full_retention();
305 omap_writel(mir1, 0x480fe0a4);
306 prm_write_mod_reg(wken_wkup, WKUP_MOD, PM_WKEN);
311 static int omap2_pm_enter(suspend_state_t state)
316 case PM_SUSPEND_STANDBY:
318 ret = omap2_pm_suspend();
327 static void omap2_pm_finish(void)
329 pm_idle = saved_idle;
332 static struct platform_suspend_ops omap_pm_ops = {
333 .prepare = omap2_pm_prepare,
334 .enter = omap2_pm_enter,
335 .finish = omap2_pm_finish,
336 .valid = suspend_valid_only_mem,
339 static int _pm_clkdm_enable_hwsup(struct clockdomain *clkdm)
341 omap2_clkdm_allow_idle(clkdm);
345 static void __init prcm_setup_regs(void)
347 int i, num_mem_banks;
348 struct powerdomain *pwrdm;
350 /* Enable autoidle */
351 prm_write_mod_reg(OMAP24XX_AUTOIDLE, OCP_MOD,
352 OMAP24XX_PRM_SYSCONFIG_OFFSET);
354 /* Set all domain wakeup dependencies */
355 prm_write_mod_reg(OMAP_EN_WKUP_MASK, MPU_MOD, PM_WKDEP);
356 prm_write_mod_reg(0, OMAP24XX_DSP_MOD, PM_WKDEP);
357 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
358 prm_write_mod_reg(0, CORE_MOD, PM_WKDEP);
359 if (cpu_is_omap2430())
360 prm_write_mod_reg(0, OMAP2430_MDM_MOD, PM_WKDEP);
363 * Set CORE powerdomain memory banks to retain their contents
366 num_mem_banks = pwrdm_get_mem_bank_count(core_pwrdm);
367 for (i = 0; i < num_mem_banks; i++)
368 pwrdm_set_mem_retst(core_pwrdm, i, PWRDM_POWER_RET);
370 /* Set CORE powerdomain's next power state to RETENTION */
371 pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_RET);
374 * Set MPU powerdomain's next power state to RETENTION;
375 * preserve logic state during retention
377 pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
378 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
380 /* Force-power down DSP, GFX powerdomains */
382 pwrdm = clkdm_get_pwrdm(dsp_clkdm);
383 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
384 omap2_clkdm_sleep(dsp_clkdm);
386 pwrdm = clkdm_get_pwrdm(gfx_clkdm);
387 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
388 omap2_clkdm_sleep(gfx_clkdm);
390 /* Enable clockdomain hardware-supervised control for all clkdms */
391 clkdm_for_each(_pm_clkdm_enable_hwsup);
393 /* Enable clock autoidle for all domains */
394 cm_write_mod_reg(OMAP24XX_AUTO_CAM |
395 OMAP24XX_AUTO_MAILBOXES |
398 OMAP24XX_AUTO_MSPRO |
403 OMAP24XX_AUTO_UART2 |
404 OMAP24XX_AUTO_UART1 |
407 OMAP24XX_AUTO_MCSPI2 |
408 OMAP24XX_AUTO_MCSPI1 |
409 OMAP24XX_AUTO_MCBSP2 |
410 OMAP24XX_AUTO_MCBSP1 |
411 OMAP24XX_AUTO_GPT12 |
412 OMAP24XX_AUTO_GPT11 |
413 OMAP24XX_AUTO_GPT10 |
422 OMAP2420_AUTO_VLYNQ |
424 CORE_MOD, CM_AUTOIDLE1);
425 cm_write_mod_reg(OMAP24XX_AUTO_UART3 |
428 CORE_MOD, CM_AUTOIDLE2);
429 cm_write_mod_reg(OMAP24XX_AUTO_SDRC |
432 CORE_MOD, CM_AUTOIDLE3);
433 cm_write_mod_reg(OMAP24XX_AUTO_PKA |
438 CORE_MOD, OMAP24XX_CM_AUTOIDLE4);
440 cm_write_mod_reg(OMAP2420_AUTO_DSP_IPI, OMAP24XX_DSP_MOD, CM_AUTOIDLE);
442 /* Put DPLL and both APLLs into autoidle mode */
443 cm_write_mod_reg((0x03 << OMAP24XX_AUTO_DPLL_SHIFT) |
444 (0x03 << OMAP24XX_AUTO_96M_SHIFT) |
445 (0x03 << OMAP24XX_AUTO_54M_SHIFT),
446 PLL_MOD, CM_AUTOIDLE);
448 cm_write_mod_reg(OMAP24XX_AUTO_OMAPCTRL |
450 OMAP24XX_AUTO_MPU_WDT |
451 OMAP24XX_AUTO_GPIOS |
452 OMAP24XX_AUTO_32KSYNC |
454 WKUP_MOD, CM_AUTOIDLE);
456 /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk
458 prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
459 OMAP24XX_PRCM_CLKSSETUP_OFFSET);
461 /* Configure automatic voltage transition */
462 prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
463 OMAP24XX_PRCM_VOLTSETUP_OFFSET);
464 prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT |
465 (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT) |
466 OMAP24XX_MEMRETCTRL |
467 (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT) |
468 (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT),
469 OMAP24XX_GR_MOD, OMAP24XX_PRCM_VOLTCTRL_OFFSET);
471 /* Enable wake-up events */
472 prm_write_mod_reg(OMAP24XX_EN_GPIOS | OMAP24XX_EN_GPT1,
476 int __init omap2_pm_init(void)
480 printk(KERN_INFO "Power Management for OMAP2 initializing\n");
481 l = prm_read_mod_reg(OCP_MOD, OMAP24XX_PRM_REVISION_OFFSET);
482 printk(KERN_INFO "PRCM revision %d.%d\n", (l >> 4) & 0x0f, l & 0x0f);
484 /* Look up important powerdomains, clockdomains */
486 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
488 pr_err("PM: mpu_pwrdm not found\n");
490 core_pwrdm = pwrdm_lookup("core_pwrdm");
492 pr_err("PM: core_pwrdm not found\n");
494 dsp_clkdm = clkdm_lookup("dsp_clkdm");
496 pr_err("PM: mpu_clkdm not found\n");
498 gfx_clkdm = clkdm_lookup("gfx_clkdm");
500 pr_err("PM: gfx_clkdm not found\n");
503 osc_ck = clk_get(NULL, "osc_ck");
504 if (IS_ERR(osc_ck)) {
505 printk(KERN_ERR "could not get osc_ck\n");
509 if (cpu_is_omap242x()) {
510 emul_ck = clk_get(NULL, "emul_ck");
511 if (IS_ERR(emul_ck)) {
512 printk(KERN_ERR "could not get emul_ck\n");
520 pm_init_serial_console();
522 /* Hack to prevent MPU retention when STI console is enabled. */
524 const struct omap_sti_console_config *sti;
526 sti = omap_get_config(OMAP_TAG_STI_CONSOLE,
527 struct omap_sti_console_config);
528 if (sti != NULL && sti->enable)
529 sti_console_enabled = 1;
533 * We copy the assembler sleep/wakeup routines to SRAM.
534 * These routines need to be in SRAM as that's the only
535 * memory the MPU can see when it wakes up.
537 if (cpu_is_omap242x()) {
538 omap2_sram_idle = omap_sram_push(omap242x_idle_loop_suspend,
539 omap242x_idle_loop_suspend_sz);
541 omap2_sram_suspend = omap_sram_push(omap242x_cpu_suspend,
542 omap242x_cpu_suspend_sz);
544 omap2_sram_idle = omap_sram_push(omap243x_idle_loop_suspend,
545 omap243x_idle_loop_suspend_sz);
547 omap2_sram_suspend = omap_sram_push(omap243x_cpu_suspend,
548 omap243x_cpu_suspend_sz);
551 suspend_set_ops(&omap_pm_ops);
552 pm_idle = omap2_pm_idle;