blob: ebb88f3aae316b8b7dacca7feefd08807d11af01 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * OMAP3 Power Management Routines
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation
5 * Tony Lindgren <tony@atomide.com>
6 * Jouni Hogander
7 *
Rajendra Nayak2f5939c2008-09-26 17:50:07 +05308 * Copyright (C) 2007 Texas Instruments, Inc.
9 * Rajendra Nayak <rnayak@ti.com>
10 *
Kevin Hilman8bd22942009-05-28 10:56:16 -070011 * Copyright (C) 2005 Texas Instruments, Inc.
12 * Richard Woodruff <r-woodruff2@ti.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/pm.h>
22#include <linux/suspend.h>
23#include <linux/interrupt.h>
24#include <linux/module.h>
25#include <linux/list.h>
26#include <linux/err.h>
27#include <linux/gpio.h>
28
Tony Lindgrence491cf2009-10-20 09:40:47 -070029#include <plat/sram.h>
30#include <plat/clockdomain.h>
31#include <plat/powerdomain.h>
32#include <plat/control.h>
33#include <plat/serial.h>
Rajendra Nayak61255ab2008-09-26 17:49:56 +053034#include <plat/sdrc.h>
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053035#include <plat/prcm.h>
36#include <plat/gpmc.h>
Tero Kristof2d11852008-08-28 13:13:31 +000037#include <plat/dma.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070038
Rajendra Nayak57f277b2008-09-26 17:49:34 +053039#include <asm/tlbflush.h>
40
Kevin Hilman8bd22942009-05-28 10:56:16 -070041#include "cm.h"
42#include "cm-regbits-34xx.h"
43#include "prm-regbits-34xx.h"
44
45#include "prm.h"
46#include "pm.h"
47
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053048/* Scratchpad offsets */
49#define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
50#define OMAP343X_TABLE_VALUE_OFFSET 0x30
51#define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
52
Kevin Hilman8bd22942009-05-28 10:56:16 -070053struct power_state {
54 struct powerdomain *pwrdm;
55 u32 next_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070056#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -070057 u32 saved_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070058#endif
Kevin Hilman8bd22942009-05-28 10:56:16 -070059 struct list_head node;
60};
61
62static LIST_HEAD(pwrst_list);
63
64static void (*_omap_sram_idle)(u32 *addr, int save_state);
65
Tero Kristo27d59a42008-10-13 13:15:00 +030066static int (*_omap_save_secure_sram)(u32 *addr);
67
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053068static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
69static struct powerdomain *core_pwrdm, *per_pwrdm;
70
71static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state);
Kevin Hilman8bd22942009-05-28 10:56:16 -070072
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053073static inline void omap3_per_save_context(void)
74{
75 omap_gpio_save_context();
76}
77
78static inline void omap3_per_restore_context(void)
79{
80 omap_gpio_restore_context();
81}
82
83static void omap3_core_save_context(void)
84{
85 u32 control_padconf_off;
86
87 /* Save the padconf registers */
88 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
89 control_padconf_off |= START_PADCONF_SAVE;
90 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
91 /* wait for the save to complete */
92 while (!omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
93 & PADCONF_SAVE_DONE)
94 ;
95 /* Save the Interrupt controller context */
96 omap_intc_save_context();
97 /* Save the GPMC context */
98 omap3_gpmc_save_context();
99 /* Save the system control module context, padconf already save above*/
100 omap3_control_save_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000101 omap_dma_global_context_save();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530102}
103
104static void omap3_core_restore_context(void)
105{
106 /* Restore the control module context, padconf restored by h/w */
107 omap3_control_restore_context();
108 /* Restore the GPMC context */
109 omap3_gpmc_restore_context();
110 /* Restore the interrupt controller context */
111 omap_intc_restore_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000112 omap_dma_global_context_restore();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530113}
114
Tero Kristo27d59a42008-10-13 13:15:00 +0300115static void omap3_save_secure_ram_context(u32 target_mpu_state)
116{
117 u32 ret;
118
119 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
120 /* Disable dma irq before calling secure rom code API */
121 omap_dma_disable_irq(0);
122 omap_dma_disable_irq(1);
123 /*
124 * MPU next state must be set to POWER_ON temporarily,
125 * otherwise the WFI executed inside the ROM code
126 * will hang the system.
127 */
128 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
129 ret = _omap_save_secure_sram((u32 *)
130 __pa(omap3_secure_ram_storage));
131 pwrdm_set_next_pwrst(mpu_pwrdm, target_mpu_state);
132 /* Following is for error tracking, it should not happen */
133 if (ret) {
134 printk(KERN_ERR "save_secure_sram() returns %08x\n",
135 ret);
136 while (1)
137 ;
138 }
139 }
140}
141
Jon Hunter77da2d92009-06-27 00:07:25 -0500142/*
143 * PRCM Interrupt Handler Helper Function
144 *
145 * The purpose of this function is to clear any wake-up events latched
146 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
147 * may occur whilst attempting to clear a PM_WKST_x register and thus
148 * set another bit in this register. A while loop is used to ensure
149 * that any peripheral wake-up events occurring while attempting to
150 * clear the PM_WKST_x are detected and cleared.
151 */
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700152static int prcm_clear_mod_irqs(s16 module, u8 regs)
Jon Hunter77da2d92009-06-27 00:07:25 -0500153{
Vikram Pandita71a80772009-07-17 19:33:09 -0500154 u32 wkst, fclk, iclk, clken;
Jon Hunter77da2d92009-06-27 00:07:25 -0500155 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
156 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
157 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
Paul Walmsley5d805972009-07-22 10:18:07 -0700158 u16 grpsel_off = (regs == 3) ?
159 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700160 int c = 0;
Jon Hunter77da2d92009-06-27 00:07:25 -0500161
162 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley5d805972009-07-22 10:18:07 -0700163 wkst &= prm_read_mod_reg(module, grpsel_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500164 if (wkst) {
165 iclk = cm_read_mod_reg(module, iclk_off);
166 fclk = cm_read_mod_reg(module, fclk_off);
167 while (wkst) {
Vikram Pandita71a80772009-07-17 19:33:09 -0500168 clken = wkst;
169 cm_set_mod_reg_bits(clken, module, iclk_off);
170 /*
171 * For USBHOST, we don't know whether HOST1 or
172 * HOST2 woke us up, so enable both f-clocks
173 */
174 if (module == OMAP3430ES2_USBHOST_MOD)
175 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
176 cm_set_mod_reg_bits(clken, module, fclk_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500177 prm_write_mod_reg(wkst, module, wkst_off);
178 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700179 c++;
Jon Hunter77da2d92009-06-27 00:07:25 -0500180 }
181 cm_write_mod_reg(iclk, module, iclk_off);
182 cm_write_mod_reg(fclk, module, fclk_off);
183 }
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700184
185 return c;
186}
187
188static int _prcm_int_handle_wakeup(void)
189{
190 int c;
191
192 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
193 c += prcm_clear_mod_irqs(CORE_MOD, 1);
194 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
195 if (omap_rev() > OMAP3430_REV_ES1_0) {
196 c += prcm_clear_mod_irqs(CORE_MOD, 3);
197 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
198 }
199
200 return c;
Jon Hunter77da2d92009-06-27 00:07:25 -0500201}
202
203/*
204 * PRCM Interrupt Handler
205 *
206 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
207 * interrupts from the PRCM for the MPU. These bits must be cleared in
208 * order to clear the PRCM interrupt. The PRCM interrupt handler is
209 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
210 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
211 * register indicates that a wake-up event is pending for the MPU and
212 * this bit can only be cleared if the all the wake-up events latched
213 * in the various PM_WKST_x registers have been cleared. The interrupt
214 * handler is implemented using a do-while loop so that if a wake-up
215 * event occurred during the processing of the prcm interrupt handler
216 * (setting a bit in the corresponding PM_WKST_x register and thus
217 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
218 * this would be handled.
219 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700220static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
221{
Jon Hunter77da2d92009-06-27 00:07:25 -0500222 u32 irqstatus_mpu;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700223 int c = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700224
Jon Hunter77da2d92009-06-27 00:07:25 -0500225 do {
Jon Hunter77da2d92009-06-27 00:07:25 -0500226 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
227 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700228
229 if (irqstatus_mpu & (OMAP3430_WKUP_ST | OMAP3430_IO_ST)) {
230 c = _prcm_int_handle_wakeup();
231
232 /*
233 * Is the MPU PRCM interrupt handler racing with the
234 * IVA2 PRCM interrupt handler ?
235 */
236 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
237 "but no wakeup sources are marked\n");
238 } else {
239 /* XXX we need to expand our PRCM interrupt handler */
240 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
241 "no code to handle it (%08x)\n", irqstatus_mpu);
242 }
243
Jon Hunter77da2d92009-06-27 00:07:25 -0500244 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
245 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700246
Jon Hunter77da2d92009-06-27 00:07:25 -0500247 } while (prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET));
Kevin Hilman8bd22942009-05-28 10:56:16 -0700248
249 return IRQ_HANDLED;
250}
251
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530252static void restore_control_register(u32 val)
253{
254 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
255}
256
257/* Function to restore the table entry that was modified for enabling MMU */
258static void restore_table_entry(void)
259{
260 u32 *scratchpad_address;
261 u32 previous_value, control_reg_value;
262 u32 *address;
263
264 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
265
266 /* Get address of entry that was modified */
267 address = (u32 *)__raw_readl(scratchpad_address +
268 OMAP343X_TABLE_ADDRESS_OFFSET);
269 /* Get the previous value which needs to be restored */
270 previous_value = __raw_readl(scratchpad_address +
271 OMAP343X_TABLE_VALUE_OFFSET);
272 address = __va(address);
273 *address = previous_value;
274 flush_tlb_all();
275 control_reg_value = __raw_readl(scratchpad_address
276 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
277 /* This will enable caches and prediction */
278 restore_control_register(control_reg_value);
279}
280
Kevin Hilman8bd22942009-05-28 10:56:16 -0700281static void omap_sram_idle(void)
282{
283 /* Variable to tell what needs to be saved and restored
284 * in omap_sram_idle*/
285 /* save_state = 0 => Nothing to save and restored */
286 /* save_state = 1 => Only L1 and logic lost */
287 /* save_state = 2 => Only L2 lost */
288 /* save_state = 3 => L1, L2 and logic lost */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530289 int save_state = 0;
290 int mpu_next_state = PWRDM_POWER_ON;
291 int per_next_state = PWRDM_POWER_ON;
292 int core_next_state = PWRDM_POWER_ON;
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530293 int core_prev_state, per_prev_state;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700294
295 if (!_omap_sram_idle)
296 return;
297
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530298 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
299 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
300 pwrdm_clear_all_prev_pwrst(core_pwrdm);
301 pwrdm_clear_all_prev_pwrst(per_pwrdm);
302
Kevin Hilman8bd22942009-05-28 10:56:16 -0700303 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
304 switch (mpu_next_state) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530305 case PWRDM_POWER_ON:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700306 case PWRDM_POWER_RET:
307 /* No need to save context */
308 save_state = 0;
309 break;
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530310 case PWRDM_POWER_OFF:
311 save_state = 3;
312 break;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700313 default:
314 /* Invalid state */
315 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
316 return;
317 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300318 pwrdm_pre_transition();
319
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530320 /* NEON control */
321 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
322 set_pwrdm_state(neon_pwrdm, mpu_next_state);
323
324 /* CORE & PER */
325 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
326 if (core_next_state < PWRDM_POWER_ON) {
327 omap2_gpio_prepare_for_retention();
328 omap_uart_prepare_idle(0);
329 omap_uart_prepare_idle(1);
330 /* PER changes only with core */
331 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530332 if (per_next_state < PWRDM_POWER_ON) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530333 omap_uart_prepare_idle(2);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530334 if (per_next_state == PWRDM_POWER_OFF)
335 omap3_per_save_context();
336 }
337 if (core_next_state == PWRDM_POWER_OFF) {
338 omap3_core_save_context();
339 omap3_prcm_save_context();
Tero Kristo27d59a42008-10-13 13:15:00 +0300340 omap3_save_secure_ram_context(mpu_next_state);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530341 }
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530342 /* Enable IO-PAD wakeup */
343 prm_set_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
344 }
Kevin Hilman8bd22942009-05-28 10:56:16 -0700345
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530346 /*
347 * omap3_arm_context is the location where ARM registers
348 * get saved. The restore path then reads from this
349 * location and restores them back.
350 */
351 _omap_sram_idle(omap3_arm_context, save_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700352 cpu_init();
353
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530354 /* Restore table entry modified during MMU restoration */
355 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
356 restore_table_entry();
357
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530358 if (core_next_state < PWRDM_POWER_ON) {
359 if (per_next_state < PWRDM_POWER_ON)
360 omap_uart_resume_idle(2);
361 omap_uart_resume_idle(1);
362 omap_uart_resume_idle(0);
363
364 /* Disable IO-PAD wakeup */
365 prm_clear_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530366 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
367 if (core_prev_state == PWRDM_POWER_OFF) {
368 omap3_core_restore_context();
369 omap3_prcm_restore_context();
370 omap3_sram_restore_context();
371 }
372 if (per_next_state < PWRDM_POWER_ON) {
373 per_prev_state =
374 pwrdm_read_prev_pwrst(per_pwrdm);
375 if (per_prev_state == PWRDM_POWER_OFF)
376 omap3_per_restore_context();
377 }
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530378 omap2_gpio_resume_after_retention();
379 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300380
381 pwrdm_post_transition();
382
Kevin Hilman8bd22942009-05-28 10:56:16 -0700383}
384
385/*
386 * Check if functional clocks are enabled before entering
387 * sleep. This function could be behind CONFIG_PM_DEBUG
388 * when all drivers are configuring their sysconfig registers
389 * properly and using their clocks properly.
390 */
391static int omap3_fclks_active(void)
392{
393 u32 fck_core1 = 0, fck_core3 = 0, fck_sgx = 0, fck_dss = 0,
394 fck_cam = 0, fck_per = 0, fck_usbhost = 0;
395
396 fck_core1 = cm_read_mod_reg(CORE_MOD,
397 CM_FCLKEN1);
398 if (omap_rev() > OMAP3430_REV_ES1_0) {
399 fck_core3 = cm_read_mod_reg(CORE_MOD,
400 OMAP3430ES2_CM_FCLKEN3);
401 fck_sgx = cm_read_mod_reg(OMAP3430ES2_SGX_MOD,
402 CM_FCLKEN);
403 fck_usbhost = cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD,
404 CM_FCLKEN);
405 } else
406 fck_sgx = cm_read_mod_reg(GFX_MOD,
407 OMAP3430ES2_CM_FCLKEN3);
408 fck_dss = cm_read_mod_reg(OMAP3430_DSS_MOD,
409 CM_FCLKEN);
410 fck_cam = cm_read_mod_reg(OMAP3430_CAM_MOD,
411 CM_FCLKEN);
412 fck_per = cm_read_mod_reg(OMAP3430_PER_MOD,
413 CM_FCLKEN);
Kevin Hilman4af40162009-02-04 10:51:40 -0800414
415 /* Ignore UART clocks. These are handled by UART core (serial.c) */
416 fck_core1 &= ~(OMAP3430_EN_UART1 | OMAP3430_EN_UART2);
417 fck_per &= ~OMAP3430_EN_UART3;
418
Kevin Hilman8bd22942009-05-28 10:56:16 -0700419 if (fck_core1 | fck_core3 | fck_sgx | fck_dss |
420 fck_cam | fck_per | fck_usbhost)
421 return 1;
422 return 0;
423}
424
425static int omap3_can_sleep(void)
426{
Kevin Hilman4af40162009-02-04 10:51:40 -0800427 if (!omap_uart_can_sleep())
428 return 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700429 if (omap3_fclks_active())
430 return 0;
431 return 1;
432}
433
434/* This sets pwrdm state (other than mpu & core. Currently only ON &
435 * RET are supported. Function is assuming that clkdm doesn't have
436 * hw_sup mode enabled. */
437static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
438{
439 u32 cur_state;
440 int sleep_switch = 0;
441 int ret = 0;
442
443 if (pwrdm == NULL || IS_ERR(pwrdm))
444 return -EINVAL;
445
446 while (!(pwrdm->pwrsts & (1 << state))) {
447 if (state == PWRDM_POWER_OFF)
448 return ret;
449 state--;
450 }
451
452 cur_state = pwrdm_read_next_pwrst(pwrdm);
453 if (cur_state == state)
454 return ret;
455
456 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
457 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
458 sleep_switch = 1;
459 pwrdm_wait_transition(pwrdm);
460 }
461
462 ret = pwrdm_set_next_pwrst(pwrdm, state);
463 if (ret) {
464 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
465 pwrdm->name);
466 goto err;
467 }
468
469 if (sleep_switch) {
470 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
471 pwrdm_wait_transition(pwrdm);
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300472 pwrdm_state_switch(pwrdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700473 }
474
475err:
476 return ret;
477}
478
479static void omap3_pm_idle(void)
480{
481 local_irq_disable();
482 local_fiq_disable();
483
484 if (!omap3_can_sleep())
485 goto out;
486
487 if (omap_irq_pending())
488 goto out;
489
490 omap_sram_idle();
491
492out:
493 local_fiq_enable();
494 local_irq_enable();
495}
496
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700497#ifdef CONFIG_SUSPEND
Tero Kristo24662112009-03-05 16:32:23 +0200498static suspend_state_t suspend_state;
499
Kevin Hilman8bd22942009-05-28 10:56:16 -0700500static int omap3_pm_prepare(void)
501{
502 disable_hlt();
503 return 0;
504}
505
506static int omap3_pm_suspend(void)
507{
508 struct power_state *pwrst;
509 int state, ret = 0;
510
511 /* Read current next_pwrsts */
512 list_for_each_entry(pwrst, &pwrst_list, node)
513 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
514 /* Set ones wanted by suspend */
515 list_for_each_entry(pwrst, &pwrst_list, node) {
516 if (set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
517 goto restore;
518 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
519 goto restore;
520 }
521
Kevin Hilman4af40162009-02-04 10:51:40 -0800522 omap_uart_prepare_suspend();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700523 omap_sram_idle();
524
525restore:
526 /* Restore next_pwrsts */
527 list_for_each_entry(pwrst, &pwrst_list, node) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700528 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
529 if (state > pwrst->next_state) {
530 printk(KERN_INFO "Powerdomain (%s) didn't enter "
531 "target state %d\n",
532 pwrst->pwrdm->name, pwrst->next_state);
533 ret = -1;
534 }
Jouni Hogander6c5f8032008-10-29 12:06:04 +0200535 set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700536 }
537 if (ret)
538 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
539 else
540 printk(KERN_INFO "Successfully put all powerdomains "
541 "to target state\n");
542
543 return ret;
544}
545
Tero Kristo24662112009-03-05 16:32:23 +0200546static int omap3_pm_enter(suspend_state_t unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700547{
548 int ret = 0;
549
Tero Kristo24662112009-03-05 16:32:23 +0200550 switch (suspend_state) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700551 case PM_SUSPEND_STANDBY:
552 case PM_SUSPEND_MEM:
553 ret = omap3_pm_suspend();
554 break;
555 default:
556 ret = -EINVAL;
557 }
558
559 return ret;
560}
561
562static void omap3_pm_finish(void)
563{
564 enable_hlt();
565}
566
Tero Kristo24662112009-03-05 16:32:23 +0200567/* Hooks to enable / disable UART interrupts during suspend */
568static int omap3_pm_begin(suspend_state_t state)
569{
570 suspend_state = state;
571 omap_uart_enable_irqs(0);
572 return 0;
573}
574
575static void omap3_pm_end(void)
576{
577 suspend_state = PM_SUSPEND_ON;
578 omap_uart_enable_irqs(1);
579 return;
580}
581
Kevin Hilman8bd22942009-05-28 10:56:16 -0700582static struct platform_suspend_ops omap_pm_ops = {
Tero Kristo24662112009-03-05 16:32:23 +0200583 .begin = omap3_pm_begin,
584 .end = omap3_pm_end,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700585 .prepare = omap3_pm_prepare,
586 .enter = omap3_pm_enter,
587 .finish = omap3_pm_finish,
588 .valid = suspend_valid_only_mem,
589};
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700590#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700591
Kevin Hilman1155e422008-11-25 11:48:24 -0800592
593/**
594 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
595 * retention
596 *
597 * In cases where IVA2 is activated by bootcode, it may prevent
598 * full-chip retention or off-mode because it is not idle. This
599 * function forces the IVA2 into idle state so it can go
600 * into retention/off and thus allow full-chip retention/off.
601 *
602 **/
603static void __init omap3_iva_idle(void)
604{
605 /* ensure IVA2 clock is disabled */
606 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
607
608 /* if no clock activity, nothing else to do */
609 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
610 OMAP3430_CLKACTIVITY_IVA2_MASK))
611 return;
612
613 /* Reset IVA2 */
614 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
615 OMAP3430_RST2_IVA2 |
616 OMAP3430_RST3_IVA2,
617 OMAP3430_IVA2_MOD, RM_RSTCTRL);
618
619 /* Enable IVA2 clock */
620 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2,
621 OMAP3430_IVA2_MOD, CM_FCLKEN);
622
623 /* Set IVA2 boot mode to 'idle' */
624 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
625 OMAP343X_CONTROL_IVA2_BOOTMOD);
626
627 /* Un-reset IVA2 */
628 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, RM_RSTCTRL);
629
630 /* Disable IVA2 clock */
631 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
632
633 /* Reset IVA2 */
634 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
635 OMAP3430_RST2_IVA2 |
636 OMAP3430_RST3_IVA2,
637 OMAP3430_IVA2_MOD, RM_RSTCTRL);
638}
639
Kevin Hilman8111b222009-04-28 15:27:44 -0700640static void __init omap3_d2d_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700641{
Kevin Hilman8111b222009-04-28 15:27:44 -0700642 u16 mask, padconf;
643
644 /* In a stand alone OMAP3430 where there is not a stacked
645 * modem for the D2D Idle Ack and D2D MStandby must be pulled
646 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
647 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
648 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
649 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
650 padconf |= mask;
651 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
652
653 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
654 padconf |= mask;
655 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
656
Kevin Hilman8bd22942009-05-28 10:56:16 -0700657 /* reset modem */
658 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON |
659 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST,
660 CORE_MOD, RM_RSTCTRL);
661 prm_write_mod_reg(0, CORE_MOD, RM_RSTCTRL);
Kevin Hilman8111b222009-04-28 15:27:44 -0700662}
Kevin Hilman8bd22942009-05-28 10:56:16 -0700663
Kevin Hilman8111b222009-04-28 15:27:44 -0700664static void __init prcm_setup_regs(void)
665{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700666 /* XXX Reset all wkdeps. This should be done when initializing
667 * powerdomains */
668 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
669 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
670 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
671 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
672 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
673 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
674 if (omap_rev() > OMAP3430_REV_ES1_0) {
675 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
676 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
677 } else
678 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
679
680 /*
681 * Enable interface clock autoidle for all modules.
682 * Note that in the long run this should be done by clockfw
683 */
684 cm_write_mod_reg(
Kevin Hilman8111b222009-04-28 15:27:44 -0700685 OMAP3430_AUTO_MODEM |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700686 OMAP3430ES2_AUTO_MMC3 |
687 OMAP3430ES2_AUTO_ICR |
688 OMAP3430_AUTO_AES2 |
689 OMAP3430_AUTO_SHA12 |
690 OMAP3430_AUTO_DES2 |
691 OMAP3430_AUTO_MMC2 |
692 OMAP3430_AUTO_MMC1 |
693 OMAP3430_AUTO_MSPRO |
694 OMAP3430_AUTO_HDQ |
695 OMAP3430_AUTO_MCSPI4 |
696 OMAP3430_AUTO_MCSPI3 |
697 OMAP3430_AUTO_MCSPI2 |
698 OMAP3430_AUTO_MCSPI1 |
699 OMAP3430_AUTO_I2C3 |
700 OMAP3430_AUTO_I2C2 |
701 OMAP3430_AUTO_I2C1 |
702 OMAP3430_AUTO_UART2 |
703 OMAP3430_AUTO_UART1 |
704 OMAP3430_AUTO_GPT11 |
705 OMAP3430_AUTO_GPT10 |
706 OMAP3430_AUTO_MCBSP5 |
707 OMAP3430_AUTO_MCBSP1 |
708 OMAP3430ES1_AUTO_FAC | /* This is es1 only */
709 OMAP3430_AUTO_MAILBOXES |
710 OMAP3430_AUTO_OMAPCTRL |
711 OMAP3430ES1_AUTO_FSHOSTUSB |
712 OMAP3430_AUTO_HSOTGUSB |
Kevin Hilman8111b222009-04-28 15:27:44 -0700713 OMAP3430_AUTO_SAD2D |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700714 OMAP3430_AUTO_SSI,
715 CORE_MOD, CM_AUTOIDLE1);
716
717 cm_write_mod_reg(
718 OMAP3430_AUTO_PKA |
719 OMAP3430_AUTO_AES1 |
720 OMAP3430_AUTO_RNG |
721 OMAP3430_AUTO_SHA11 |
722 OMAP3430_AUTO_DES1,
723 CORE_MOD, CM_AUTOIDLE2);
724
725 if (omap_rev() > OMAP3430_REV_ES1_0) {
726 cm_write_mod_reg(
Kevin Hilman8111b222009-04-28 15:27:44 -0700727 OMAP3430_AUTO_MAD2D |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700728 OMAP3430ES2_AUTO_USBTLL,
729 CORE_MOD, CM_AUTOIDLE3);
730 }
731
732 cm_write_mod_reg(
733 OMAP3430_AUTO_WDT2 |
734 OMAP3430_AUTO_WDT1 |
735 OMAP3430_AUTO_GPIO1 |
736 OMAP3430_AUTO_32KSYNC |
737 OMAP3430_AUTO_GPT12 |
738 OMAP3430_AUTO_GPT1 ,
739 WKUP_MOD, CM_AUTOIDLE);
740
741 cm_write_mod_reg(
742 OMAP3430_AUTO_DSS,
743 OMAP3430_DSS_MOD,
744 CM_AUTOIDLE);
745
746 cm_write_mod_reg(
747 OMAP3430_AUTO_CAM,
748 OMAP3430_CAM_MOD,
749 CM_AUTOIDLE);
750
751 cm_write_mod_reg(
752 OMAP3430_AUTO_GPIO6 |
753 OMAP3430_AUTO_GPIO5 |
754 OMAP3430_AUTO_GPIO4 |
755 OMAP3430_AUTO_GPIO3 |
756 OMAP3430_AUTO_GPIO2 |
757 OMAP3430_AUTO_WDT3 |
758 OMAP3430_AUTO_UART3 |
759 OMAP3430_AUTO_GPT9 |
760 OMAP3430_AUTO_GPT8 |
761 OMAP3430_AUTO_GPT7 |
762 OMAP3430_AUTO_GPT6 |
763 OMAP3430_AUTO_GPT5 |
764 OMAP3430_AUTO_GPT4 |
765 OMAP3430_AUTO_GPT3 |
766 OMAP3430_AUTO_GPT2 |
767 OMAP3430_AUTO_MCBSP4 |
768 OMAP3430_AUTO_MCBSP3 |
769 OMAP3430_AUTO_MCBSP2,
770 OMAP3430_PER_MOD,
771 CM_AUTOIDLE);
772
773 if (omap_rev() > OMAP3430_REV_ES1_0) {
774 cm_write_mod_reg(
775 OMAP3430ES2_AUTO_USBHOST,
776 OMAP3430ES2_USBHOST_MOD,
777 CM_AUTOIDLE);
778 }
779
780 /*
781 * Set all plls to autoidle. This is needed until autoidle is
782 * enabled by clockfw
783 */
784 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
785 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
786 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
787 MPU_MOD,
788 CM_AUTOIDLE2);
789 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
790 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
791 PLL_MOD,
792 CM_AUTOIDLE);
793 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
794 PLL_MOD,
795 CM_AUTOIDLE2);
796
797 /*
798 * Enable control of expternal oscillator through
799 * sys_clkreq. In the long run clock framework should
800 * take care of this.
801 */
802 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
803 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
804 OMAP3430_GR_MOD,
805 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
806
807 /* setup wakup source */
808 prm_write_mod_reg(OMAP3430_EN_IO | OMAP3430_EN_GPIO1 |
809 OMAP3430_EN_GPT1 | OMAP3430_EN_GPT12,
810 WKUP_MOD, PM_WKEN);
811 /* No need to write EN_IO, that is always enabled */
812 prm_write_mod_reg(OMAP3430_EN_GPIO1 | OMAP3430_EN_GPT1 |
813 OMAP3430_EN_GPT12,
814 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
815 /* For some reason IO doesn't generate wakeup event even if
816 * it is selected to mpu wakeup goup */
817 prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
818 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
Kevin Hilman1155e422008-11-25 11:48:24 -0800819
Kevin Hilmanb427f922009-10-22 14:48:13 -0700820 /* Enable wakeups in PER */
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000821 prm_write_mod_reg(OMAP3430_EN_GPIO2 | OMAP3430_EN_GPIO3 |
822 OMAP3430_EN_GPIO4 | OMAP3430_EN_GPIO5 |
Kevin Hilmanb427f922009-10-22 14:48:13 -0700823 OMAP3430_EN_GPIO6 | OMAP3430_EN_UART3,
824 OMAP3430_PER_MOD, PM_WKEN);
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000825 /* and allow them to wake up MPU */
826 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2 | OMAP3430_EN_GPIO3 |
827 OMAP3430_GRPSEL_GPIO4 | OMAP3430_EN_GPIO5 |
Kevin Hilmanb427f922009-10-22 14:48:13 -0700828 OMAP3430_GRPSEL_GPIO6 | OMAP3430_EN_UART3,
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000829 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
830
Kevin Hilmand3fd3292009-05-05 16:34:25 -0700831 /* Don't attach IVA interrupts */
832 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
833 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
834 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
835 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
836
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700837 /* Clear any pending 'reset' flags */
838 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
839 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
840 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
841 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
842 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
843 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
844 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
845
Kevin Hilman014c46d2009-04-27 07:50:23 -0700846 /* Clear any pending PRCM interrupts */
847 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
848
Kevin Hilman040fed02009-05-05 16:34:25 -0700849 /* Don't attach IVA interrupts */
850 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
851 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
852 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
853 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
854
Kevin Hilman3a07ae32009-04-27 16:14:54 -0700855 /* Clear any pending 'reset' flags */
856 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
857 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
858 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
859 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
860 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
861 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
862 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
863
Kevin Hilman3a6667a2009-04-27 07:50:23 -0700864 /* Clear any pending PRCM interrupts */
865 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
866
Kevin Hilman1155e422008-11-25 11:48:24 -0800867 omap3_iva_idle();
Kevin Hilman8111b222009-04-28 15:27:44 -0700868 omap3_d2d_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700869}
870
Tero Kristo68d47782008-11-26 12:26:24 +0200871int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
872{
873 struct power_state *pwrst;
874
875 list_for_each_entry(pwrst, &pwrst_list, node) {
876 if (pwrst->pwrdm == pwrdm)
877 return pwrst->next_state;
878 }
879 return -EINVAL;
880}
881
882int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
883{
884 struct power_state *pwrst;
885
886 list_for_each_entry(pwrst, &pwrst_list, node) {
887 if (pwrst->pwrdm == pwrdm) {
888 pwrst->next_state = state;
889 return 0;
890 }
891 }
892 return -EINVAL;
893}
894
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300895static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700896{
897 struct power_state *pwrst;
898
899 if (!pwrdm->pwrsts)
900 return 0;
901
Ming Leid3d381c2009-08-22 21:20:26 +0800902 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700903 if (!pwrst)
904 return -ENOMEM;
905 pwrst->pwrdm = pwrdm;
906 pwrst->next_state = PWRDM_POWER_RET;
907 list_add(&pwrst->node, &pwrst_list);
908
909 if (pwrdm_has_hdwr_sar(pwrdm))
910 pwrdm_enable_hdwr_sar(pwrdm);
911
912 return set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
913}
914
915/*
916 * Enable hw supervised mode for all clockdomains if it's
917 * supported. Initiate sleep transition for other clockdomains, if
918 * they are not used
919 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300920static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700921{
922 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
923 omap2_clkdm_allow_idle(clkdm);
924 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
925 atomic_read(&clkdm->usecount) == 0)
926 omap2_clkdm_sleep(clkdm);
927 return 0;
928}
929
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530930void omap_push_sram_idle(void)
931{
932 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
933 omap34xx_cpu_suspend_sz);
Tero Kristo27d59a42008-10-13 13:15:00 +0300934 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
935 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
936 save_secure_ram_context_sz);
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530937}
938
Kevin Hilman7cc515f2009-06-10 09:02:25 -0700939static int __init omap3_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700940{
941 struct power_state *pwrst, *tmp;
942 int ret;
943
944 if (!cpu_is_omap34xx())
945 return -ENODEV;
946
947 printk(KERN_ERR "Power Management for TI OMAP3.\n");
948
949 /* XXX prcm_setup_regs needs to be before enabling hw
950 * supervised mode for powerdomains */
951 prcm_setup_regs();
952
953 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
954 (irq_handler_t)prcm_interrupt_handler,
955 IRQF_DISABLED, "prcm", NULL);
956 if (ret) {
957 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
958 INT_34XX_PRCM_MPU_IRQ);
959 goto err1;
960 }
961
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300962 ret = pwrdm_for_each(pwrdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700963 if (ret) {
964 printk(KERN_ERR "Failed to setup powerdomains\n");
965 goto err2;
966 }
967
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300968 (void) clkdm_for_each(clkdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700969
970 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
971 if (mpu_pwrdm == NULL) {
972 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
973 goto err2;
974 }
975
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530976 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
977 per_pwrdm = pwrdm_lookup("per_pwrdm");
978 core_pwrdm = pwrdm_lookup("core_pwrdm");
979
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530980 omap_push_sram_idle();
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700981#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -0700982 suspend_set_ops(&omap_pm_ops);
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700983#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700984
985 pm_idle = omap3_pm_idle;
986
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530987 pwrdm_add_wkdep(neon_pwrdm, mpu_pwrdm);
988 /*
989 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
990 * IO-pad wakeup. Otherwise it will unnecessarily waste power
991 * waking up PER with every CORE wakeup - see
992 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
993 */
994 pwrdm_add_wkdep(per_pwrdm, core_pwrdm);
995
Tero Kristo27d59a42008-10-13 13:15:00 +0300996 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
997 omap3_secure_ram_storage =
998 kmalloc(0x803F, GFP_KERNEL);
999 if (!omap3_secure_ram_storage)
1000 printk(KERN_ERR "Memory allocation failed when"
1001 "allocating for secure sram context\n");
1002 }
1003 omap3_save_scratchpad_contents();
1004
Kevin Hilman8bd22942009-05-28 10:56:16 -07001005err1:
1006 return ret;
1007err2:
1008 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
1009 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
1010 list_del(&pwrst->node);
1011 kfree(pwrst);
1012 }
1013 return ret;
1014}
1015
1016late_initcall(omap3_pm_init);