blob: ef8595c802966e53993103fcbecaeed33318e1fe [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
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
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.h>
29#include <linux/io.h>
30#include <linux/irq.h>
31#include <linux/time.h>
32#include <linux/gpio.h>
Paul Walmsley0d8e2d02010-11-24 16:49:05 -070033#include <linux/console.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070034
35#include <asm/mach/time.h>
36#include <asm/mach/irq.h>
37#include <asm/mach-types.h>
38
39#include <mach/irqs.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070040#include <plat/clock.h>
41#include <plat/sram.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070042#include <plat/dma.h>
43#include <plat/board.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070044
Tony Lindgren4e653312011-11-10 22:45:17 +010045#include "common.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070046#include "prm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070047#include "prm-regbits-24xx.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070048#include "cm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070049#include "cm-regbits-24xx.h"
50#include "sdrc.h"
51#include "pm.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060052#include "control.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070053
Paul Walmsley72e06d02010-12-21 21:05:16 -070054#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070055#include "clockdomain.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070056
Kevin Hilmane83df172010-12-08 22:40:40 +000057#ifdef CONFIG_SUSPEND
58static suspend_state_t suspend_state = PM_SUSPEND_ON;
59static inline bool is_suspending(void)
60{
61 return (suspend_state != PM_SUSPEND_ON);
62}
63#else
64static inline bool is_suspending(void)
65{
66 return false;
67}
68#endif
69
Kevin Hilman8bd22942009-05-28 10:56:16 -070070static void (*omap2_sram_idle)(void);
71static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
72 void __iomem *sdrc_power);
73
Paul Walmsley369d5612010-01-26 20:13:01 -070074static struct powerdomain *mpu_pwrdm, *core_pwrdm;
75static struct clockdomain *dsp_clkdm, *mpu_clkdm, *wkup_clkdm, *gfx_clkdm;
Kevin Hilman8bd22942009-05-28 10:56:16 -070076
77static struct clk *osc_ck, *emul_ck;
78
79static int omap2_fclks_active(void)
80{
81 u32 f1, f2;
82
Paul Walmsleyc4d7e582010-12-21 21:05:14 -070083 f1 = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
84 f2 = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
Kevin Hilman4af40162009-02-04 10:51:40 -080085
86 /* Ignore UART clocks. These are handled by UART core (serial.c) */
Paul Walmsley2fd0f752010-05-18 18:40:23 -060087 f1 &= ~(OMAP24XX_EN_UART1_MASK | OMAP24XX_EN_UART2_MASK);
88 f2 &= ~OMAP24XX_EN_UART3_MASK;
Kevin Hilman4af40162009-02-04 10:51:40 -080089
Kevin Hilman8bd22942009-05-28 10:56:16 -070090 if (f1 | f2)
91 return 1;
92 return 0;
93}
94
Kevin Hilman8bd22942009-05-28 10:56:16 -070095static void omap2_enter_full_retention(void)
96{
97 u32 l;
Kevin Hilman8bd22942009-05-28 10:56:16 -070098
99 /* There is 1 reference hold for all children of the oscillator
100 * clock, the following will remove it. If no one else uses the
101 * oscillator itself it will be disabled if/when we enter retention
102 * mode.
103 */
104 clk_disable(osc_ck);
105
106 /* Clear old wake-up events */
107 /* REVISIT: These write to reserved bits? */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700108 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
109 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
110 omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700111
112 /*
113 * Set MPU powerdomain's next power state to RETENTION;
114 * preserve logic state during retention
115 */
116 pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
117 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
118
119 /* Workaround to kill USB */
120 l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL;
121 omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0);
122
Paul Walmsley72e06d02010-12-21 21:05:16 -0700123 omap2_gpio_prepare_for_idle(0);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700124
Kevin Hilman8bd22942009-05-28 10:56:16 -0700125 /* One last check for pending IRQs to avoid extra latency due
126 * to sleeping unnecessarily. */
Jouni Hogander94434532009-02-03 15:49:04 -0800127 if (omap_irq_pending())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700128 goto no_sleep;
129
Paul Walmsley0d8e2d02010-11-24 16:49:05 -0700130 /* Block console output in case it is on one of the OMAP UARTs */
Kevin Hilmane83df172010-12-08 22:40:40 +0000131 if (!is_suspending())
Torben Hohnac751ef2011-01-25 15:07:35 -0800132 if (!console_trylock())
Kevin Hilmane83df172010-12-08 22:40:40 +0000133 goto no_sleep;
Paul Walmsley0d8e2d02010-11-24 16:49:05 -0700134
Kevin Hilman4af40162009-02-04 10:51:40 -0800135 omap_uart_prepare_idle(0);
136 omap_uart_prepare_idle(1);
137 omap_uart_prepare_idle(2);
138
Kevin Hilman8bd22942009-05-28 10:56:16 -0700139 /* Jump to SRAM suspend code */
140 omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL),
141 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL),
142 OMAP_SDRC_REGADDR(SDRC_POWER));
Kevin Hilman8bd22942009-05-28 10:56:16 -0700143
Kevin Hilman4af40162009-02-04 10:51:40 -0800144 omap_uart_resume_idle(2);
145 omap_uart_resume_idle(1);
146 omap_uart_resume_idle(0);
147
Kevin Hilmane83df172010-12-08 22:40:40 +0000148 if (!is_suspending())
Torben Hohnac751ef2011-01-25 15:07:35 -0800149 console_unlock();
Paul Walmsley0d8e2d02010-11-24 16:49:05 -0700150
Kevin Hilman4af40162009-02-04 10:51:40 -0800151no_sleep:
Kevin Hilman43ffcd92009-01-27 11:09:24 -0800152 omap2_gpio_resume_after_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700153
154 clk_enable(osc_ck);
155
156 /* clear CORE wake-up events */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700157 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
158 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700159
160 /* wakeup domain events - bit 1: GPT1, bit5 GPIO */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700161 omap2_prm_clear_mod_reg_bits(0x4 | 0x1, WKUP_MOD, PM_WKST);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700162
163 /* MPU domain wake events */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700164 l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700165 if (l & 0x01)
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700166 omap2_prm_write_mod_reg(0x01, OCP_MOD,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700167 OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
168 if (l & 0x20)
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700169 omap2_prm_write_mod_reg(0x20, OCP_MOD,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700170 OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
171
172 /* Mask future PRCM-to-MPU interrupts */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700173 omap2_prm_write_mod_reg(0x0, OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700174}
175
176static int omap2_i2c_active(void)
177{
178 u32 l;
179
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700180 l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
Paul Walmsleyf38ca102010-05-20 12:31:04 -0600181 return l & (OMAP2420_EN_I2C2_MASK | OMAP2420_EN_I2C1_MASK);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700182}
183
184static int sti_console_enabled;
185
186static int omap2_allow_mpu_retention(void)
187{
188 u32 l;
189
190 /* Check for MMC, UART2, UART1, McSPI2, McSPI1 and DSS1. */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700191 l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1);
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600192 if (l & (OMAP2420_EN_MMC_MASK | OMAP24XX_EN_UART2_MASK |
193 OMAP24XX_EN_UART1_MASK | OMAP24XX_EN_MCSPI2_MASK |
194 OMAP24XX_EN_MCSPI1_MASK | OMAP24XX_EN_DSS1_MASK))
Kevin Hilman8bd22942009-05-28 10:56:16 -0700195 return 0;
196 /* Check for UART3. */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700197 l = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2);
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600198 if (l & OMAP24XX_EN_UART3_MASK)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700199 return 0;
200 if (sti_console_enabled)
201 return 0;
202
203 return 1;
204}
205
206static void omap2_enter_mpu_retention(void)
207{
208 int only_idle = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700209
210 /* Putting MPU into the WFI state while a transfer is active
211 * seems to cause the I2C block to timeout. Why? Good question. */
212 if (omap2_i2c_active())
213 return;
214
215 /* The peripherals seem not to be able to wake up the MPU when
216 * it is in retention mode. */
217 if (omap2_allow_mpu_retention()) {
218 /* REVISIT: These write to reserved bits? */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700219 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1);
220 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2);
221 omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700222
223 /* Try to enter MPU retention */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700224 omap2_prm_write_mod_reg((0x01 << OMAP_POWERSTATE_SHIFT) |
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600225 OMAP_LOGICRETSTATE_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700226 MPU_MOD, OMAP2_PM_PWSTCTRL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700227 } else {
228 /* Block MPU retention */
229
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700230 omap2_prm_write_mod_reg(OMAP_LOGICRETSTATE_MASK, MPU_MOD,
Abhijit Pagare37903002010-01-26 20:12:51 -0700231 OMAP2_PM_PWSTCTRL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700232 only_idle = 1;
233 }
234
Kevin Hilman8bd22942009-05-28 10:56:16 -0700235 omap2_sram_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700236}
237
238static int omap2_can_sleep(void)
239{
240 if (omap2_fclks_active())
241 return 0;
Kevin Hilman503923e2010-10-08 10:23:32 -0700242 if (!omap_uart_can_sleep())
243 return 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700244 if (osc_ck->usecount > 1)
245 return 0;
246 if (omap_dma_running())
247 return 0;
248
249 return 1;
250}
251
252static void omap2_pm_idle(void)
253{
254 local_irq_disable();
255 local_fiq_disable();
256
257 if (!omap2_can_sleep()) {
Jouni Hogander94434532009-02-03 15:49:04 -0800258 if (omap_irq_pending())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700259 goto out;
260 omap2_enter_mpu_retention();
261 goto out;
262 }
263
Jouni Hogander94434532009-02-03 15:49:04 -0800264 if (omap_irq_pending())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700265 goto out;
266
267 omap2_enter_full_retention();
268
269out:
270 local_fiq_enable();
271 local_irq_enable();
272}
273
Kevin Hilman05fad3e2010-12-22 23:04:17 +0000274#ifdef CONFIG_SUSPEND
Kevin Hilmane83df172010-12-08 22:40:40 +0000275static int omap2_pm_begin(suspend_state_t state)
276{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700277 disable_hlt();
Jean Pihetc1663812010-12-09 18:39:58 +0100278 suspend_state = state;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700279 return 0;
280}
281
282static int omap2_pm_suspend(void)
283{
284 u32 wken_wkup, mir1;
285
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700286 wken_wkup = omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600287 wken_wkup &= ~OMAP24XX_EN_GPT1_MASK;
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700288 omap2_prm_write_mod_reg(wken_wkup, WKUP_MOD, PM_WKEN);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700289
290 /* Mask GPT1 */
291 mir1 = omap_readl(0x480fe0a4);
292 omap_writel(1 << 5, 0x480fe0ac);
293
Kevin Hilman4af40162009-02-04 10:51:40 -0800294 omap_uart_prepare_suspend();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700295 omap2_enter_full_retention();
296
297 omap_writel(mir1, 0x480fe0a4);
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700298 omap2_prm_write_mod_reg(wken_wkup, WKUP_MOD, PM_WKEN);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700299
300 return 0;
301}
302
303static int omap2_pm_enter(suspend_state_t state)
304{
305 int ret = 0;
306
307 switch (state) {
308 case PM_SUSPEND_STANDBY:
309 case PM_SUSPEND_MEM:
310 ret = omap2_pm_suspend();
311 break;
312 default:
313 ret = -EINVAL;
314 }
315
316 return ret;
317}
318
Kevin Hilmane83df172010-12-08 22:40:40 +0000319static void omap2_pm_end(void)
320{
321 suspend_state = PM_SUSPEND_ON;
Jean Pihetc1663812010-12-09 18:39:58 +0100322 enable_hlt();
Kevin Hilmane83df172010-12-08 22:40:40 +0000323}
324
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100325static const struct platform_suspend_ops omap_pm_ops = {
Kevin Hilmane83df172010-12-08 22:40:40 +0000326 .begin = omap2_pm_begin,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700327 .enter = omap2_pm_enter,
Kevin Hilmane83df172010-12-08 22:40:40 +0000328 .end = omap2_pm_end,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700329 .valid = suspend_valid_only_mem,
330};
Kevin Hilman05fad3e2010-12-22 23:04:17 +0000331#else
332static const struct platform_suspend_ops __initdata omap_pm_ops;
333#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700334
Paul Walmsley369d5612010-01-26 20:13:01 -0700335/* XXX This function should be shareable between OMAP2xxx and OMAP3 */
336static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700337{
Paul Walmsley369d5612010-01-26 20:13:01 -0700338 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700339 clkdm_allow_idle(clkdm);
Paul Walmsley369d5612010-01-26 20:13:01 -0700340 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
341 atomic_read(&clkdm->usecount) == 0)
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700342 clkdm_sleep(clkdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700343 return 0;
344}
345
346static void __init prcm_setup_regs(void)
347{
348 int i, num_mem_banks;
349 struct powerdomain *pwrdm;
350
Paul Walmsley4ef70c02011-02-25 15:39:30 -0700351 /*
352 * Enable autoidle
353 * XXX This should be handled by hwmod code or PRCM init code
354 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700355 omap2_prm_write_mod_reg(OMAP24XX_AUTOIDLE_MASK, OCP_MOD,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700356 OMAP2_PRCM_SYSCONFIG_OFFSET);
357
Kevin Hilman8bd22942009-05-28 10:56:16 -0700358 /*
359 * Set CORE powerdomain memory banks to retain their contents
360 * during RETENTION
361 */
362 num_mem_banks = pwrdm_get_mem_bank_count(core_pwrdm);
363 for (i = 0; i < num_mem_banks; i++)
364 pwrdm_set_mem_retst(core_pwrdm, i, PWRDM_POWER_RET);
365
366 /* Set CORE powerdomain's next power state to RETENTION */
367 pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_RET);
368
369 /*
370 * Set MPU powerdomain's next power state to RETENTION;
371 * preserve logic state during retention
372 */
373 pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
374 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
375
376 /* Force-power down DSP, GFX powerdomains */
377
378 pwrdm = clkdm_get_pwrdm(dsp_clkdm);
379 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700380 clkdm_sleep(dsp_clkdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700381
382 pwrdm = clkdm_get_pwrdm(gfx_clkdm);
383 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
Rajendra Nayak68b921a2011-02-25 16:06:47 -0700384 clkdm_sleep(gfx_clkdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700385
Paul Walmsley51d070a2011-01-27 02:52:55 -0700386 /* Enable hardware-supervised idle for all clkdms */
Paul Walmsley369d5612010-01-26 20:13:01 -0700387 clkdm_for_each(clkdms_setup, NULL);
388 clkdm_add_wkdep(mpu_clkdm, wkup_clkdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700389
Kevin Hilman8bd22942009-05-28 10:56:16 -0700390 /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk
391 * stabilisation */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700392 omap2_prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
393 OMAP2_PRCM_CLKSSETUP_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700394
395 /* Configure automatic voltage transition */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700396 omap2_prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
397 OMAP2_PRCM_VOLTSETUP_OFFSET);
398 omap2_prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT_MASK |
399 (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT) |
400 OMAP24XX_MEMRETCTRL_MASK |
401 (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT) |
402 (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT),
403 OMAP24XX_GR_MOD, OMAP2_PRCM_VOLTCTRL_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700404
405 /* Enable wake-up events */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700406 omap2_prm_write_mod_reg(OMAP24XX_EN_GPIOS_MASK | OMAP24XX_EN_GPT1_MASK,
407 WKUP_MOD, PM_WKEN);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700408}
409
Kevin Hilman7cc515f2009-06-10 09:02:25 -0700410static int __init omap2_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700411{
412 u32 l;
413
414 if (!cpu_is_omap24xx())
415 return -ENODEV;
416
417 printk(KERN_INFO "Power Management for OMAP2 initializing\n");
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700418 l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_REVISION_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700419 printk(KERN_INFO "PRCM revision %d.%d\n", (l >> 4) & 0x0f, l & 0x0f);
420
Paul Walmsley369d5612010-01-26 20:13:01 -0700421 /* Look up important powerdomains */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700422
423 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
424 if (!mpu_pwrdm)
425 pr_err("PM: mpu_pwrdm not found\n");
426
427 core_pwrdm = pwrdm_lookup("core_pwrdm");
428 if (!core_pwrdm)
429 pr_err("PM: core_pwrdm not found\n");
430
Paul Walmsley369d5612010-01-26 20:13:01 -0700431 /* Look up important clockdomains */
432
433 mpu_clkdm = clkdm_lookup("mpu_clkdm");
434 if (!mpu_clkdm)
435 pr_err("PM: mpu_clkdm not found\n");
436
437 wkup_clkdm = clkdm_lookup("wkup_clkdm");
438 if (!wkup_clkdm)
439 pr_err("PM: wkup_clkdm not found\n");
440
Kevin Hilman8bd22942009-05-28 10:56:16 -0700441 dsp_clkdm = clkdm_lookup("dsp_clkdm");
442 if (!dsp_clkdm)
Paul Walmsley369d5612010-01-26 20:13:01 -0700443 pr_err("PM: dsp_clkdm not found\n");
Kevin Hilman8bd22942009-05-28 10:56:16 -0700444
445 gfx_clkdm = clkdm_lookup("gfx_clkdm");
446 if (!gfx_clkdm)
447 pr_err("PM: gfx_clkdm not found\n");
448
449
450 osc_ck = clk_get(NULL, "osc_ck");
451 if (IS_ERR(osc_ck)) {
452 printk(KERN_ERR "could not get osc_ck\n");
453 return -ENODEV;
454 }
455
456 if (cpu_is_omap242x()) {
457 emul_ck = clk_get(NULL, "emul_ck");
458 if (IS_ERR(emul_ck)) {
459 printk(KERN_ERR "could not get emul_ck\n");
460 clk_put(osc_ck);
461 return -ENODEV;
462 }
463 }
464
465 prcm_setup_regs();
466
467 /* Hack to prevent MPU retention when STI console is enabled. */
468 {
469 const struct omap_sti_console_config *sti;
470
471 sti = omap_get_config(OMAP_TAG_STI_CONSOLE,
472 struct omap_sti_console_config);
473 if (sti != NULL && sti->enable)
474 sti_console_enabled = 1;
475 }
476
477 /*
478 * We copy the assembler sleep/wakeup routines to SRAM.
479 * These routines need to be in SRAM as that's the only
480 * memory the MPU can see when it wakes up.
481 */
482 if (cpu_is_omap24xx()) {
483 omap2_sram_idle = omap_sram_push(omap24xx_idle_loop_suspend,
484 omap24xx_idle_loop_suspend_sz);
485
486 omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend,
487 omap24xx_cpu_suspend_sz);
488 }
489
490 suspend_set_ops(&omap_pm_ops);
491 pm_idle = omap2_pm_idle;
492
493 return 0;
494}
495
496late_initcall(omap2_pm_init);