2 * OMAP2 Power Management Routines
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
8 * Richard Woodruff <r-woodruff2@ti.com>
11 * Amit Kucheria <amit.kucheria@nokia.com>
12 * Igor Stoppa <igor.stoppa@nokia.com>
14 * Based on pm.c for omap1
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.
21 #include <linux/suspend.h>
22 #include <linux/sched.h>
23 #include <linux/proc_fs.h>
24 #include <linux/interrupt.h>
25 #include <linux/sysfs.h>
26 #include <linux/module.h>
27 #include <linux/delay.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>
34 #include <asm/fncpy.h>
36 #include <asm/mach/time.h>
37 #include <asm/mach/irq.h>
38 #include <asm/mach-types.h>
39 #include <asm/system_misc.h>
41 #include <linux/omap-dma.h>
47 #include "prm-regbits-24xx.h"
49 #include "cm-regbits-24xx.h"
54 #include "powerdomain.h"
55 #include "clockdomain.h"
57 static void (*omap2_sram_suspend
)(u32 dllctrl
, void __iomem
*sdrc_dlla_ctrl
,
58 void __iomem
*sdrc_power
);
60 static struct powerdomain
*mpu_pwrdm
, *core_pwrdm
;
61 static struct clockdomain
*dsp_clkdm
, *mpu_clkdm
, *wkup_clkdm
, *gfx_clkdm
;
63 static struct clk
*osc_ck
, *emul_ck
;
65 static int omap2_fclks_active(void)
69 f1
= omap2_cm_read_mod_reg(CORE_MOD
, CM_FCLKEN1
);
70 f2
= omap2_cm_read_mod_reg(CORE_MOD
, OMAP24XX_CM_FCLKEN2
);
72 return (f1
| f2
) ? 1 : 0;
75 static int omap2_enter_full_retention(void)
79 /* There is 1 reference hold for all children of the oscillator
80 * clock, the following will remove it. If no one else uses the
81 * oscillator itself it will be disabled if/when we enter retention
86 /* Clear old wake-up events */
87 /* REVISIT: These write to reserved bits? */
88 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, PM_WKST1
);
89 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, OMAP24XX_PM_WKST2
);
90 omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD
, PM_WKST
);
92 pwrdm_set_next_pwrst(core_pwrdm
, PWRDM_POWER_RET
);
93 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_RET
);
95 /* Workaround to kill USB */
96 l
= omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0
) | OMAP24XX_USBSTANDBYCTRL
;
97 omap_ctrl_writel(l
, OMAP2_CONTROL_DEVCONF0
);
99 omap2_gpio_prepare_for_idle(0);
101 /* One last check for pending IRQs to avoid extra latency due
102 * to sleeping unnecessarily. */
103 if (omap_irq_pending())
106 /* Jump to SRAM suspend code */
107 omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL
),
108 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL
),
109 OMAP_SDRC_REGADDR(SDRC_POWER
));
112 omap2_gpio_resume_after_idle();
116 /* clear CORE wake-up events */
117 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, PM_WKST1
);
118 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, OMAP24XX_PM_WKST2
);
120 /* wakeup domain events - bit 1: GPT1, bit5 GPIO */
121 omap2_prm_clear_mod_reg_bits(0x4 | 0x1, WKUP_MOD
, PM_WKST
);
123 /* MPU domain wake events */
124 l
= omap2_prm_read_mod_reg(OCP_MOD
, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET
);
126 omap2_prm_write_mod_reg(0x01, OCP_MOD
,
127 OMAP2_PRCM_IRQSTATUS_MPU_OFFSET
);
129 omap2_prm_write_mod_reg(0x20, OCP_MOD
,
130 OMAP2_PRCM_IRQSTATUS_MPU_OFFSET
);
132 /* Mask future PRCM-to-MPU interrupts */
133 omap2_prm_write_mod_reg(0x0, OCP_MOD
, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET
);
135 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_ON
);
136 pwrdm_set_next_pwrst(core_pwrdm
, PWRDM_POWER_ON
);
141 static int sti_console_enabled
;
143 static int omap2_allow_mpu_retention(void)
147 /* Check for MMC, UART2, UART1, McSPI2, McSPI1 and DSS1. */
148 l
= omap2_cm_read_mod_reg(CORE_MOD
, CM_FCLKEN1
);
149 if (l
& (OMAP2420_EN_MMC_MASK
| OMAP24XX_EN_UART2_MASK
|
150 OMAP24XX_EN_UART1_MASK
| OMAP24XX_EN_MCSPI2_MASK
|
151 OMAP24XX_EN_MCSPI1_MASK
| OMAP24XX_EN_DSS1_MASK
))
153 /* Check for UART3. */
154 l
= omap2_cm_read_mod_reg(CORE_MOD
, OMAP24XX_CM_FCLKEN2
);
155 if (l
& OMAP24XX_EN_UART3_MASK
)
157 if (sti_console_enabled
)
163 static void omap2_enter_mpu_retention(void)
167 /* The peripherals seem not to be able to wake up the MPU when
168 * it is in retention mode. */
169 if (omap2_allow_mpu_retention()) {
170 /* REVISIT: These write to reserved bits? */
171 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, PM_WKST1
);
172 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD
, OMAP24XX_PM_WKST2
);
173 omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD
, PM_WKST
);
175 /* Try to enter MPU retention */
176 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_RET
);
179 /* Block MPU retention */
180 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_ON
);
184 asm("mcr p15, 0, %0, c7, c0, 4" : : "r" (zero
) : "memory", "cc");
186 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_ON
);
189 static int omap2_can_sleep(void)
191 if (omap2_fclks_active())
193 if (__clk_is_enabled(osc_ck
))
195 if (omap_dma_running())
201 static void omap2_pm_idle(void)
203 if (!omap2_can_sleep()) {
204 if (omap_irq_pending())
206 omap2_enter_mpu_retention();
210 if (omap_irq_pending())
213 omap2_enter_full_retention();
216 static void __init
prcm_setup_regs(void)
218 int i
, num_mem_banks
;
219 struct powerdomain
*pwrdm
;
223 * XXX This should be handled by hwmod code or PRCM init code
225 omap2_prm_write_mod_reg(OMAP24XX_AUTOIDLE_MASK
, OCP_MOD
,
226 OMAP2_PRCM_SYSCONFIG_OFFSET
);
229 * Set CORE powerdomain memory banks to retain their contents
232 num_mem_banks
= pwrdm_get_mem_bank_count(core_pwrdm
);
233 for (i
= 0; i
< num_mem_banks
; i
++)
234 pwrdm_set_mem_retst(core_pwrdm
, i
, PWRDM_POWER_RET
);
236 pwrdm_set_logic_retst(core_pwrdm
, PWRDM_POWER_RET
);
238 pwrdm_set_logic_retst(mpu_pwrdm
, PWRDM_POWER_RET
);
240 /* Force-power down DSP, GFX powerdomains */
242 pwrdm
= clkdm_get_pwrdm(dsp_clkdm
);
243 pwrdm_set_next_pwrst(pwrdm
, PWRDM_POWER_OFF
);
245 pwrdm
= clkdm_get_pwrdm(gfx_clkdm
);
246 pwrdm_set_next_pwrst(pwrdm
, PWRDM_POWER_OFF
);
248 /* Enable hardware-supervised idle for all clkdms */
249 clkdm_for_each(omap_pm_clkdms_setup
, NULL
);
250 clkdm_add_wkdep(mpu_clkdm
, wkup_clkdm
);
252 #ifdef CONFIG_SUSPEND
253 omap_pm_suspend
= omap2_enter_full_retention
;
256 /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk
258 omap2_prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT
, OMAP24XX_GR_MOD
,
259 OMAP2_PRCM_CLKSSETUP_OFFSET
);
261 /* Configure automatic voltage transition */
262 omap2_prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT
, OMAP24XX_GR_MOD
,
263 OMAP2_PRCM_VOLTSETUP_OFFSET
);
264 omap2_prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT_MASK
|
265 (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT
) |
266 OMAP24XX_MEMRETCTRL_MASK
|
267 (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT
) |
268 (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT
),
269 OMAP24XX_GR_MOD
, OMAP2_PRCM_VOLTCTRL_OFFSET
);
271 /* Enable wake-up events */
272 omap2_prm_write_mod_reg(OMAP24XX_EN_GPIOS_MASK
| OMAP24XX_EN_GPT1_MASK
,
276 int __init
omap2_pm_init(void)
280 printk(KERN_INFO
"Power Management for OMAP2 initializing\n");
281 l
= omap2_prm_read_mod_reg(OCP_MOD
, OMAP2_PRCM_REVISION_OFFSET
);
282 printk(KERN_INFO
"PRCM revision %d.%d\n", (l
>> 4) & 0x0f, l
& 0x0f);
284 /* Look up important powerdomains */
286 mpu_pwrdm
= pwrdm_lookup("mpu_pwrdm");
288 pr_err("PM: mpu_pwrdm not found\n");
290 core_pwrdm
= pwrdm_lookup("core_pwrdm");
292 pr_err("PM: core_pwrdm not found\n");
294 /* Look up important clockdomains */
296 mpu_clkdm
= clkdm_lookup("mpu_clkdm");
298 pr_err("PM: mpu_clkdm not found\n");
300 wkup_clkdm
= clkdm_lookup("wkup_clkdm");
302 pr_err("PM: wkup_clkdm not found\n");
304 dsp_clkdm
= clkdm_lookup("dsp_clkdm");
306 pr_err("PM: dsp_clkdm not found\n");
308 gfx_clkdm
= clkdm_lookup("gfx_clkdm");
310 pr_err("PM: gfx_clkdm not found\n");
313 osc_ck
= clk_get(NULL
, "osc_ck");
314 if (IS_ERR(osc_ck
)) {
315 printk(KERN_ERR
"could not get osc_ck\n");
319 if (cpu_is_omap242x()) {
320 emul_ck
= clk_get(NULL
, "emul_ck");
321 if (IS_ERR(emul_ck
)) {
322 printk(KERN_ERR
"could not get emul_ck\n");
331 * We copy the assembler sleep/wakeup routines to SRAM.
332 * These routines need to be in SRAM as that's the only
333 * memory the MPU can see when it wakes up after the entire
336 omap2_sram_suspend
= omap_sram_push(omap24xx_cpu_suspend
,
337 omap24xx_cpu_suspend_sz
);
339 arm_pm_idle
= omap2_pm_idle
;