omap: Fix omap_4430sdp_defconfig for make oldconfig
[deliverable/linux.git] / arch / arm / mach-omap2 / pm34xx.c
CommitLineData
8bd22949
KH
1/*
2 * OMAP3 Power Management Routines
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation
5 * Tony Lindgren <tony@atomide.com>
6 * Jouni Hogander
7 *
2f5939c3
RN
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 * Rajendra Nayak <rnayak@ti.com>
10 *
8bd22949
KH
11 * 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>
c40552bc 28#include <linux/clk.h>
dccaad89 29#include <linux/delay.h>
5a0e3ad6 30#include <linux/slab.h>
8bd22949 31
ce491cf8
TL
32#include <plat/sram.h>
33#include <plat/clockdomain.h>
34#include <plat/powerdomain.h>
35#include <plat/control.h>
36#include <plat/serial.h>
61255ab9 37#include <plat/sdrc.h>
2f5939c3
RN
38#include <plat/prcm.h>
39#include <plat/gpmc.h>
f2d11858 40#include <plat/dma.h>
d7814e4d 41#include <plat/dmtimer.h>
8bd22949 42
57f277b0
RN
43#include <asm/tlbflush.h>
44
8bd22949
KH
45#include "cm.h"
46#include "cm-regbits-34xx.h"
47#include "prm-regbits-34xx.h"
48
49#include "prm.h"
50#include "pm.h"
13a6fe0f
TK
51#include "sdrc.h"
52
2f5939c3
RN
53/* Scratchpad offsets */
54#define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
55#define OMAP343X_TABLE_VALUE_OFFSET 0x30
56#define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
57
c40552bc
KH
58u32 enable_off_mode;
59u32 sleep_while_idle;
d7814e4d 60u32 wakeup_timer_seconds;
8e2efde9 61u32 wakeup_timer_milliseconds;
c40552bc 62
8bd22949
KH
63struct power_state {
64 struct powerdomain *pwrdm;
65 u32 next_state;
10f90ed2 66#ifdef CONFIG_SUSPEND
8bd22949 67 u32 saved_state;
10f90ed2 68#endif
8bd22949
KH
69 struct list_head node;
70};
71
72static LIST_HEAD(pwrst_list);
73
74static void (*_omap_sram_idle)(u32 *addr, int save_state);
75
27d59a4a
TK
76static int (*_omap_save_secure_sram)(u32 *addr);
77
fa3c2a4f
RN
78static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
79static struct powerdomain *core_pwrdm, *per_pwrdm;
c16c3f67 80static struct powerdomain *cam_pwrdm;
fa3c2a4f 81
2f5939c3
RN
82static inline void omap3_per_save_context(void)
83{
84 omap_gpio_save_context();
85}
86
87static inline void omap3_per_restore_context(void)
88{
89 omap_gpio_restore_context();
90}
91
3a7ec26b
KJ
92static void omap3_enable_io_chain(void)
93{
94 int timeout = 0;
95
96 if (omap_rev() >= OMAP3430_REV_ES3_1) {
2bc4ef71
PW
97 prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
98 PM_WKEN);
3a7ec26b
KJ
99 /* Do a readback to assure write has been done */
100 prm_read_mod_reg(WKUP_MOD, PM_WKEN);
101
0b96a3a3 102 while (!(prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
2bc4ef71 103 OMAP3430_ST_IO_CHAIN_MASK)) {
3a7ec26b
KJ
104 timeout++;
105 if (timeout > 1000) {
106 printk(KERN_ERR "Wake up daisy chain "
107 "activation failed.\n");
108 return;
109 }
2bc4ef71 110 prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
0b96a3a3 111 WKUP_MOD, PM_WKEN);
3a7ec26b
KJ
112 }
113 }
114}
115
116static void omap3_disable_io_chain(void)
117{
118 if (omap_rev() >= OMAP3430_REV_ES3_1)
2bc4ef71
PW
119 prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
120 PM_WKEN);
3a7ec26b
KJ
121}
122
2f5939c3
RN
123static void omap3_core_save_context(void)
124{
125 u32 control_padconf_off;
126
127 /* Save the padconf registers */
128 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
129 control_padconf_off |= START_PADCONF_SAVE;
130 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
131 /* wait for the save to complete */
1b6e821f
RK
132 while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
133 & PADCONF_SAVE_DONE))
dccaad89
TK
134 udelay(1);
135
136 /*
137 * Force write last pad into memory, as this can fail in some
138 * cases according to erratas 1.157, 1.185
139 */
140 omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
141 OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
142
2f5939c3
RN
143 /* Save the Interrupt controller context */
144 omap_intc_save_context();
145 /* Save the GPMC context */
146 omap3_gpmc_save_context();
147 /* Save the system control module context, padconf already save above*/
148 omap3_control_save_context();
f2d11858 149 omap_dma_global_context_save();
2f5939c3
RN
150}
151
152static void omap3_core_restore_context(void)
153{
154 /* Restore the control module context, padconf restored by h/w */
155 omap3_control_restore_context();
156 /* Restore the GPMC context */
157 omap3_gpmc_restore_context();
158 /* Restore the interrupt controller context */
159 omap_intc_restore_context();
f2d11858 160 omap_dma_global_context_restore();
2f5939c3
RN
161}
162
9d97140b
TK
163/*
164 * FIXME: This function should be called before entering off-mode after
165 * OMAP3 secure services have been accessed. Currently it is only called
166 * once during boot sequence, but this works as we are not using secure
167 * services.
168 */
27d59a4a
TK
169static void omap3_save_secure_ram_context(u32 target_mpu_state)
170{
171 u32 ret;
172
173 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
27d59a4a
TK
174 /*
175 * MPU next state must be set to POWER_ON temporarily,
176 * otherwise the WFI executed inside the ROM code
177 * will hang the system.
178 */
179 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
180 ret = _omap_save_secure_sram((u32 *)
181 __pa(omap3_secure_ram_storage));
182 pwrdm_set_next_pwrst(mpu_pwrdm, target_mpu_state);
183 /* Following is for error tracking, it should not happen */
184 if (ret) {
185 printk(KERN_ERR "save_secure_sram() returns %08x\n",
186 ret);
187 while (1)
188 ;
189 }
190 }
191}
192
77da2d91
JH
193/*
194 * PRCM Interrupt Handler Helper Function
195 *
196 * The purpose of this function is to clear any wake-up events latched
197 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
198 * may occur whilst attempting to clear a PM_WKST_x register and thus
199 * set another bit in this register. A while loop is used to ensure
200 * that any peripheral wake-up events occurring while attempting to
201 * clear the PM_WKST_x are detected and cleared.
202 */
8cb0ac99 203static int prcm_clear_mod_irqs(s16 module, u8 regs)
8bd22949 204{
71a80775 205 u32 wkst, fclk, iclk, clken;
77da2d91
JH
206 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
207 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
208 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
5d805978
PW
209 u16 grpsel_off = (regs == 3) ?
210 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
8cb0ac99 211 int c = 0;
8bd22949 212
77da2d91 213 wkst = prm_read_mod_reg(module, wkst_off);
5d805978 214 wkst &= prm_read_mod_reg(module, grpsel_off);
8bd22949 215 if (wkst) {
77da2d91
JH
216 iclk = cm_read_mod_reg(module, iclk_off);
217 fclk = cm_read_mod_reg(module, fclk_off);
218 while (wkst) {
71a80775
VP
219 clken = wkst;
220 cm_set_mod_reg_bits(clken, module, iclk_off);
221 /*
222 * For USBHOST, we don't know whether HOST1 or
223 * HOST2 woke us up, so enable both f-clocks
224 */
225 if (module == OMAP3430ES2_USBHOST_MOD)
226 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
227 cm_set_mod_reg_bits(clken, module, fclk_off);
77da2d91
JH
228 prm_write_mod_reg(wkst, module, wkst_off);
229 wkst = prm_read_mod_reg(module, wkst_off);
8cb0ac99 230 c++;
77da2d91
JH
231 }
232 cm_write_mod_reg(iclk, module, iclk_off);
233 cm_write_mod_reg(fclk, module, fclk_off);
8bd22949 234 }
8cb0ac99
PW
235
236 return c;
237}
238
239static int _prcm_int_handle_wakeup(void)
240{
241 int c;
242
243 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
244 c += prcm_clear_mod_irqs(CORE_MOD, 1);
245 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
246 if (omap_rev() > OMAP3430_REV_ES1_0) {
247 c += prcm_clear_mod_irqs(CORE_MOD, 3);
248 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
249 }
250
251 return c;
77da2d91 252}
8bd22949 253
77da2d91
JH
254/*
255 * PRCM Interrupt Handler
256 *
257 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
258 * interrupts from the PRCM for the MPU. These bits must be cleared in
259 * order to clear the PRCM interrupt. The PRCM interrupt handler is
260 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
261 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
262 * register indicates that a wake-up event is pending for the MPU and
263 * this bit can only be cleared if the all the wake-up events latched
264 * in the various PM_WKST_x registers have been cleared. The interrupt
265 * handler is implemented using a do-while loop so that if a wake-up
266 * event occurred during the processing of the prcm interrupt handler
267 * (setting a bit in the corresponding PM_WKST_x register and thus
268 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
269 * this would be handled.
270 */
271static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
272{
d6290a3e 273 u32 irqenable_mpu, irqstatus_mpu;
8cb0ac99 274 int c = 0;
77da2d91 275
d6290a3e
KH
276 irqenable_mpu = prm_read_mod_reg(OCP_MOD,
277 OMAP3_PRM_IRQENABLE_MPU_OFFSET);
278 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
279 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
280 irqstatus_mpu &= irqenable_mpu;
8cb0ac99 281
d6290a3e 282 do {
2bc4ef71
PW
283 if (irqstatus_mpu & (OMAP3430_WKUP_ST_MASK |
284 OMAP3430_IO_ST_MASK)) {
8cb0ac99
PW
285 c = _prcm_int_handle_wakeup();
286
287 /*
288 * Is the MPU PRCM interrupt handler racing with the
289 * IVA2 PRCM interrupt handler ?
290 */
291 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
292 "but no wakeup sources are marked\n");
293 } else {
294 /* XXX we need to expand our PRCM interrupt handler */
295 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
296 "no code to handle it (%08x)\n", irqstatus_mpu);
297 }
298
77da2d91
JH
299 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
300 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
8bd22949 301
d6290a3e
KH
302 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
303 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
304 irqstatus_mpu &= irqenable_mpu;
305
306 } while (irqstatus_mpu);
8bd22949
KH
307
308 return IRQ_HANDLED;
309}
310
57f277b0
RN
311static void restore_control_register(u32 val)
312{
313 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
314}
315
316/* Function to restore the table entry that was modified for enabling MMU */
317static void restore_table_entry(void)
318{
319 u32 *scratchpad_address;
320 u32 previous_value, control_reg_value;
321 u32 *address;
322
323 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
324
325 /* Get address of entry that was modified */
326 address = (u32 *)__raw_readl(scratchpad_address +
327 OMAP343X_TABLE_ADDRESS_OFFSET);
328 /* Get the previous value which needs to be restored */
329 previous_value = __raw_readl(scratchpad_address +
330 OMAP343X_TABLE_VALUE_OFFSET);
331 address = __va(address);
332 *address = previous_value;
333 flush_tlb_all();
334 control_reg_value = __raw_readl(scratchpad_address
335 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
336 /* This will enable caches and prediction */
337 restore_control_register(control_reg_value);
338}
339
99e6a4d2 340void omap_sram_idle(void)
8bd22949
KH
341{
342 /* Variable to tell what needs to be saved and restored
343 * in omap_sram_idle*/
344 /* save_state = 0 => Nothing to save and restored */
345 /* save_state = 1 => Only L1 and logic lost */
346 /* save_state = 2 => Only L2 lost */
347 /* save_state = 3 => L1, L2 and logic lost */
fa3c2a4f
RN
348 int save_state = 0;
349 int mpu_next_state = PWRDM_POWER_ON;
350 int per_next_state = PWRDM_POWER_ON;
351 int core_next_state = PWRDM_POWER_ON;
2f5939c3 352 int core_prev_state, per_prev_state;
13a6fe0f 353 u32 sdrc_pwr = 0;
ecf157d0 354 int per_state_modified = 0;
8bd22949
KH
355
356 if (!_omap_sram_idle)
357 return;
358
fa3c2a4f
RN
359 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
360 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
361 pwrdm_clear_all_prev_pwrst(core_pwrdm);
362 pwrdm_clear_all_prev_pwrst(per_pwrdm);
363
8bd22949
KH
364 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
365 switch (mpu_next_state) {
fa3c2a4f 366 case PWRDM_POWER_ON:
8bd22949
KH
367 case PWRDM_POWER_RET:
368 /* No need to save context */
369 save_state = 0;
370 break;
61255ab9
RN
371 case PWRDM_POWER_OFF:
372 save_state = 3;
373 break;
8bd22949
KH
374 default:
375 /* Invalid state */
376 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
377 return;
378 }
fe617af7
PDS
379 pwrdm_pre_transition();
380
fa3c2a4f
RN
381 /* NEON control */
382 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
7139178e 383 pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
fa3c2a4f 384
40742fa8 385 /* Enable IO-PAD and IO-CHAIN wakeups */
658ce97e 386 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
ecf157d0 387 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
ad0c63f1 388 if (omap3_has_io_wakeup() && \
389 (per_next_state < PWRDM_POWER_ON ||
390 core_next_state < PWRDM_POWER_ON)) {
2bc4ef71 391 prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
40742fa8
MC
392 omap3_enable_io_chain();
393 }
394
395 /* PER */
658ce97e 396 if (per_next_state < PWRDM_POWER_ON) {
658ce97e 397 omap_uart_prepare_idle(2);
43ffcd9a 398 omap2_gpio_prepare_for_idle(per_next_state);
ecf157d0
TK
399 if (per_next_state == PWRDM_POWER_OFF) {
400 if (core_next_state == PWRDM_POWER_ON) {
401 per_next_state = PWRDM_POWER_RET;
402 pwrdm_set_next_pwrst(per_pwrdm, per_next_state);
403 per_state_modified = 1;
43ffcd9a 404 } else
ecf157d0
TK
405 omap3_per_save_context();
406 }
658ce97e
KH
407 }
408
c16c3f67
TK
409 if (pwrdm_read_pwrst(cam_pwrdm) == PWRDM_POWER_ON)
410 omap2_clkdm_deny_idle(mpu_pwrdm->pwrdm_clkdms[0]);
411
658ce97e 412 /* CORE */
fa3c2a4f 413 if (core_next_state < PWRDM_POWER_ON) {
fa3c2a4f
RN
414 omap_uart_prepare_idle(0);
415 omap_uart_prepare_idle(1);
2f5939c3
RN
416 if (core_next_state == PWRDM_POWER_OFF) {
417 omap3_core_save_context();
418 omap3_prcm_save_context();
419 }
fa3c2a4f 420 }
40742fa8 421
f18cc2ff 422 omap3_intc_prepare_idle();
8bd22949 423
13a6fe0f 424 /*
f265dc4c
RN
425 * On EMU/HS devices ROM code restores a SRDC value
426 * from scratchpad which has automatic self refresh on timeout
427 * of AUTO_CNT = 1 enabled. This takes care of errata 1.142.
428 * Hence store/restore the SDRC_POWER register here.
429 */
13a6fe0f
TK
430 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
431 omap_type() != OMAP2_DEVICE_TYPE_GP &&
f265dc4c 432 core_next_state == PWRDM_POWER_OFF)
13a6fe0f 433 sdrc_pwr = sdrc_read_reg(SDRC_POWER);
13a6fe0f 434
61255ab9
RN
435 /*
436 * omap3_arm_context is the location where ARM registers
437 * get saved. The restore path then reads from this
438 * location and restores them back.
439 */
440 _omap_sram_idle(omap3_arm_context, save_state);
8bd22949
KH
441 cpu_init();
442
f265dc4c 443 /* Restore normal SDRC POWER settings */
13a6fe0f
TK
444 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
445 omap_type() != OMAP2_DEVICE_TYPE_GP &&
446 core_next_state == PWRDM_POWER_OFF)
447 sdrc_write_reg(sdrc_pwr, SDRC_POWER);
448
57f277b0
RN
449 /* Restore table entry modified during MMU restoration */
450 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
451 restore_table_entry();
452
658ce97e 453 /* CORE */
fa3c2a4f 454 if (core_next_state < PWRDM_POWER_ON) {
2f5939c3
RN
455 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
456 if (core_prev_state == PWRDM_POWER_OFF) {
457 omap3_core_restore_context();
458 omap3_prcm_restore_context();
459 omap3_sram_restore_context();
8a917d2f 460 omap2_sms_restore_context();
2f5939c3 461 }
658ce97e
KH
462 omap_uart_resume_idle(0);
463 omap_uart_resume_idle(1);
464 if (core_next_state == PWRDM_POWER_OFF)
2bc4ef71 465 prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
658ce97e
KH
466 OMAP3430_GR_MOD,
467 OMAP3_PRM_VOLTCTRL_OFFSET);
468 }
f18cc2ff 469 omap3_intc_resume_idle();
658ce97e
KH
470
471 /* PER */
472 if (per_next_state < PWRDM_POWER_ON) {
473 per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
43ffcd9a
KH
474 omap2_gpio_resume_after_idle();
475 if (per_prev_state == PWRDM_POWER_OFF)
658ce97e 476 omap3_per_restore_context();
ecf157d0
TK
477 omap_uart_resume_idle(2);
478 if (per_state_modified)
479 pwrdm_set_next_pwrst(per_pwrdm, PWRDM_POWER_OFF);
fa3c2a4f 480 }
fe617af7 481
3a7ec26b 482 /* Disable IO-PAD and IO-CHAIN wakeup */
ad0c63f1 483 if (omap3_has_io_wakeup() && core_next_state < PWRDM_POWER_ON) {
2bc4ef71 484 prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
3a7ec26b
KJ
485 omap3_disable_io_chain();
486 }
658ce97e 487
fe617af7
PDS
488 pwrdm_post_transition();
489
c16c3f67 490 omap2_clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
8bd22949
KH
491}
492
20b01669 493int omap3_can_sleep(void)
8bd22949 494{
c40552bc
KH
495 if (!sleep_while_idle)
496 return 0;
4af4016c
KH
497 if (!omap_uart_can_sleep())
498 return 0;
8bd22949
KH
499 return 1;
500}
501
502/* This sets pwrdm state (other than mpu & core. Currently only ON &
503 * RET are supported. Function is assuming that clkdm doesn't have
504 * hw_sup mode enabled. */
20b01669 505int set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
8bd22949
KH
506{
507 u32 cur_state;
508 int sleep_switch = 0;
509 int ret = 0;
510
511 if (pwrdm == NULL || IS_ERR(pwrdm))
512 return -EINVAL;
513
514 while (!(pwrdm->pwrsts & (1 << state))) {
515 if (state == PWRDM_POWER_OFF)
516 return ret;
517 state--;
518 }
519
520 cur_state = pwrdm_read_next_pwrst(pwrdm);
521 if (cur_state == state)
522 return ret;
523
524 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
525 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
526 sleep_switch = 1;
527 pwrdm_wait_transition(pwrdm);
528 }
529
530 ret = pwrdm_set_next_pwrst(pwrdm, state);
531 if (ret) {
532 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
533 pwrdm->name);
534 goto err;
535 }
536
537 if (sleep_switch) {
538 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
539 pwrdm_wait_transition(pwrdm);
fe617af7 540 pwrdm_state_switch(pwrdm);
8bd22949
KH
541 }
542
543err:
544 return ret;
545}
546
547static void omap3_pm_idle(void)
548{
549 local_irq_disable();
550 local_fiq_disable();
551
552 if (!omap3_can_sleep())
553 goto out;
554
cf22854c 555 if (omap_irq_pending() || need_resched())
8bd22949
KH
556 goto out;
557
558 omap_sram_idle();
559
560out:
561 local_fiq_enable();
562 local_irq_enable();
563}
564
10f90ed2 565#ifdef CONFIG_SUSPEND
2466211e
TK
566static suspend_state_t suspend_state;
567
8e2efde9 568static void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
d7814e4d
KH
569{
570 u32 tick_rate, cycles;
571
8e2efde9 572 if (!seconds && !milliseconds)
d7814e4d
KH
573 return;
574
575 tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
8e2efde9 576 cycles = tick_rate * seconds + tick_rate * milliseconds / 1000;
d7814e4d
KH
577 omap_dm_timer_stop(gptimer_wakeup);
578 omap_dm_timer_set_load_start(gptimer_wakeup, 0, 0xffffffff - cycles);
579
8e2efde9
AK
580 pr_info("PM: Resume timer in %u.%03u secs"
581 " (%d ticks at %d ticks/sec.)\n",
582 seconds, milliseconds, cycles, tick_rate);
d7814e4d
KH
583}
584
8bd22949
KH
585static int omap3_pm_prepare(void)
586{
587 disable_hlt();
588 return 0;
589}
590
591static int omap3_pm_suspend(void)
592{
593 struct power_state *pwrst;
594 int state, ret = 0;
595
8e2efde9
AK
596 if (wakeup_timer_seconds || wakeup_timer_milliseconds)
597 omap2_pm_wakeup_on_timer(wakeup_timer_seconds,
598 wakeup_timer_milliseconds);
d7814e4d 599
8bd22949
KH
600 /* Read current next_pwrsts */
601 list_for_each_entry(pwrst, &pwrst_list, node)
602 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
603 /* Set ones wanted by suspend */
604 list_for_each_entry(pwrst, &pwrst_list, node) {
605 if (set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
606 goto restore;
607 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
608 goto restore;
609 }
610
4af4016c 611 omap_uart_prepare_suspend();
2bbe3af3
TK
612 omap3_intc_suspend();
613
8bd22949
KH
614 omap_sram_idle();
615
616restore:
617 /* Restore next_pwrsts */
618 list_for_each_entry(pwrst, &pwrst_list, node) {
8bd22949
KH
619 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
620 if (state > pwrst->next_state) {
621 printk(KERN_INFO "Powerdomain (%s) didn't enter "
622 "target state %d\n",
623 pwrst->pwrdm->name, pwrst->next_state);
624 ret = -1;
625 }
6c5f8039 626 set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
8bd22949
KH
627 }
628 if (ret)
629 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
630 else
631 printk(KERN_INFO "Successfully put all powerdomains "
632 "to target state\n");
633
634 return ret;
635}
636
2466211e 637static int omap3_pm_enter(suspend_state_t unused)
8bd22949
KH
638{
639 int ret = 0;
640
2466211e 641 switch (suspend_state) {
8bd22949
KH
642 case PM_SUSPEND_STANDBY:
643 case PM_SUSPEND_MEM:
644 ret = omap3_pm_suspend();
645 break;
646 default:
647 ret = -EINVAL;
648 }
649
650 return ret;
651}
652
653static void omap3_pm_finish(void)
654{
655 enable_hlt();
656}
657
2466211e
TK
658/* Hooks to enable / disable UART interrupts during suspend */
659static int omap3_pm_begin(suspend_state_t state)
660{
661 suspend_state = state;
662 omap_uart_enable_irqs(0);
663 return 0;
664}
665
666static void omap3_pm_end(void)
667{
668 suspend_state = PM_SUSPEND_ON;
669 omap_uart_enable_irqs(1);
670 return;
671}
672
8bd22949 673static struct platform_suspend_ops omap_pm_ops = {
2466211e
TK
674 .begin = omap3_pm_begin,
675 .end = omap3_pm_end,
8bd22949
KH
676 .prepare = omap3_pm_prepare,
677 .enter = omap3_pm_enter,
678 .finish = omap3_pm_finish,
679 .valid = suspend_valid_only_mem,
680};
10f90ed2 681#endif /* CONFIG_SUSPEND */
8bd22949 682
1155e426
KH
683
684/**
685 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
686 * retention
687 *
688 * In cases where IVA2 is activated by bootcode, it may prevent
689 * full-chip retention or off-mode because it is not idle. This
690 * function forces the IVA2 into idle state so it can go
691 * into retention/off and thus allow full-chip retention/off.
692 *
693 **/
694static void __init omap3_iva_idle(void)
695{
696 /* ensure IVA2 clock is disabled */
697 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
698
699 /* if no clock activity, nothing else to do */
700 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
701 OMAP3430_CLKACTIVITY_IVA2_MASK))
702 return;
703
704 /* Reset IVA2 */
2bc4ef71
PW
705 prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
706 OMAP3430_RST2_IVA2_MASK |
707 OMAP3430_RST3_IVA2_MASK,
37903009 708 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
1155e426
KH
709
710 /* Enable IVA2 clock */
dfa6d6f8 711 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
1155e426
KH
712 OMAP3430_IVA2_MOD, CM_FCLKEN);
713
714 /* Set IVA2 boot mode to 'idle' */
715 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
716 OMAP343X_CONTROL_IVA2_BOOTMOD);
717
718 /* Un-reset IVA2 */
37903009 719 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
1155e426
KH
720
721 /* Disable IVA2 clock */
722 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
723
724 /* Reset IVA2 */
2bc4ef71
PW
725 prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
726 OMAP3430_RST2_IVA2_MASK |
727 OMAP3430_RST3_IVA2_MASK,
37903009 728 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
1155e426
KH
729}
730
8111b221 731static void __init omap3_d2d_idle(void)
8bd22949 732{
8111b221
KH
733 u16 mask, padconf;
734
735 /* In a stand alone OMAP3430 where there is not a stacked
736 * modem for the D2D Idle Ack and D2D MStandby must be pulled
737 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
738 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
739 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
740 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
741 padconf |= mask;
742 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
743
744 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
745 padconf |= mask;
746 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
747
8bd22949 748 /* reset modem */
2bc4ef71
PW
749 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
750 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
37903009
AP
751 CORE_MOD, OMAP2_RM_RSTCTRL);
752 prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
8111b221 753}
8bd22949 754
8111b221
KH
755static void __init prcm_setup_regs(void)
756{
8bd22949
KH
757 /* XXX Reset all wkdeps. This should be done when initializing
758 * powerdomains */
759 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
760 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
761 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
762 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
763 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
764 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
765 if (omap_rev() > OMAP3430_REV_ES1_0) {
766 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
767 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
768 } else
769 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
770
771 /*
772 * Enable interface clock autoidle for all modules.
773 * Note that in the long run this should be done by clockfw
774 */
775 cm_write_mod_reg(
2bc4ef71
PW
776 OMAP3430_AUTO_MODEM_MASK |
777 OMAP3430ES2_AUTO_MMC3_MASK |
778 OMAP3430ES2_AUTO_ICR_MASK |
779 OMAP3430_AUTO_AES2_MASK |
780 OMAP3430_AUTO_SHA12_MASK |
781 OMAP3430_AUTO_DES2_MASK |
782 OMAP3430_AUTO_MMC2_MASK |
783 OMAP3430_AUTO_MMC1_MASK |
784 OMAP3430_AUTO_MSPRO_MASK |
785 OMAP3430_AUTO_HDQ_MASK |
786 OMAP3430_AUTO_MCSPI4_MASK |
787 OMAP3430_AUTO_MCSPI3_MASK |
788 OMAP3430_AUTO_MCSPI2_MASK |
789 OMAP3430_AUTO_MCSPI1_MASK |
790 OMAP3430_AUTO_I2C3_MASK |
791 OMAP3430_AUTO_I2C2_MASK |
792 OMAP3430_AUTO_I2C1_MASK |
793 OMAP3430_AUTO_UART2_MASK |
794 OMAP3430_AUTO_UART1_MASK |
795 OMAP3430_AUTO_GPT11_MASK |
796 OMAP3430_AUTO_GPT10_MASK |
797 OMAP3430_AUTO_MCBSP5_MASK |
798 OMAP3430_AUTO_MCBSP1_MASK |
799 OMAP3430ES1_AUTO_FAC_MASK | /* This is es1 only */
800 OMAP3430_AUTO_MAILBOXES_MASK |
801 OMAP3430_AUTO_OMAPCTRL_MASK |
802 OMAP3430ES1_AUTO_FSHOSTUSB_MASK |
803 OMAP3430_AUTO_HSOTGUSB_MASK |
804 OMAP3430_AUTO_SAD2D_MASK |
805 OMAP3430_AUTO_SSI_MASK,
8bd22949
KH
806 CORE_MOD, CM_AUTOIDLE1);
807
808 cm_write_mod_reg(
2bc4ef71
PW
809 OMAP3430_AUTO_PKA_MASK |
810 OMAP3430_AUTO_AES1_MASK |
811 OMAP3430_AUTO_RNG_MASK |
812 OMAP3430_AUTO_SHA11_MASK |
813 OMAP3430_AUTO_DES1_MASK,
8bd22949
KH
814 CORE_MOD, CM_AUTOIDLE2);
815
816 if (omap_rev() > OMAP3430_REV_ES1_0) {
817 cm_write_mod_reg(
2bc4ef71
PW
818 OMAP3430_AUTO_MAD2D_MASK |
819 OMAP3430ES2_AUTO_USBTLL_MASK,
8bd22949
KH
820 CORE_MOD, CM_AUTOIDLE3);
821 }
822
823 cm_write_mod_reg(
2bc4ef71
PW
824 OMAP3430_AUTO_WDT2_MASK |
825 OMAP3430_AUTO_WDT1_MASK |
826 OMAP3430_AUTO_GPIO1_MASK |
827 OMAP3430_AUTO_32KSYNC_MASK |
828 OMAP3430_AUTO_GPT12_MASK |
829 OMAP3430_AUTO_GPT1_MASK,
8bd22949
KH
830 WKUP_MOD, CM_AUTOIDLE);
831
832 cm_write_mod_reg(
2bc4ef71 833 OMAP3430_AUTO_DSS_MASK,
8bd22949
KH
834 OMAP3430_DSS_MOD,
835 CM_AUTOIDLE);
836
837 cm_write_mod_reg(
2bc4ef71 838 OMAP3430_AUTO_CAM_MASK,
8bd22949
KH
839 OMAP3430_CAM_MOD,
840 CM_AUTOIDLE);
841
842 cm_write_mod_reg(
2bc4ef71
PW
843 OMAP3430_AUTO_GPIO6_MASK |
844 OMAP3430_AUTO_GPIO5_MASK |
845 OMAP3430_AUTO_GPIO4_MASK |
846 OMAP3430_AUTO_GPIO3_MASK |
847 OMAP3430_AUTO_GPIO2_MASK |
848 OMAP3430_AUTO_WDT3_MASK |
849 OMAP3430_AUTO_UART3_MASK |
850 OMAP3430_AUTO_GPT9_MASK |
851 OMAP3430_AUTO_GPT8_MASK |
852 OMAP3430_AUTO_GPT7_MASK |
853 OMAP3430_AUTO_GPT6_MASK |
854 OMAP3430_AUTO_GPT5_MASK |
855 OMAP3430_AUTO_GPT4_MASK |
856 OMAP3430_AUTO_GPT3_MASK |
857 OMAP3430_AUTO_GPT2_MASK |
858 OMAP3430_AUTO_MCBSP4_MASK |
859 OMAP3430_AUTO_MCBSP3_MASK |
860 OMAP3430_AUTO_MCBSP2_MASK,
8bd22949
KH
861 OMAP3430_PER_MOD,
862 CM_AUTOIDLE);
863
864 if (omap_rev() > OMAP3430_REV_ES1_0) {
865 cm_write_mod_reg(
2bc4ef71 866 OMAP3430ES2_AUTO_USBHOST_MASK,
8bd22949
KH
867 OMAP3430ES2_USBHOST_MOD,
868 CM_AUTOIDLE);
869 }
870
2fd0f75c 871 omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
b296c811 872
8bd22949
KH
873 /*
874 * Set all plls to autoidle. This is needed until autoidle is
875 * enabled by clockfw
876 */
877 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
878 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
879 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
880 MPU_MOD,
881 CM_AUTOIDLE2);
882 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
883 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
884 PLL_MOD,
885 CM_AUTOIDLE);
886 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
887 PLL_MOD,
888 CM_AUTOIDLE2);
889
890 /*
891 * Enable control of expternal oscillator through
892 * sys_clkreq. In the long run clock framework should
893 * take care of this.
894 */
895 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
896 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
897 OMAP3430_GR_MOD,
898 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
899
900 /* setup wakup source */
2fd0f75c
PW
901 prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
902 OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
8bd22949
KH
903 WKUP_MOD, PM_WKEN);
904 /* No need to write EN_IO, that is always enabled */
275f675c
PW
905 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
906 OMAP3430_GRPSEL_GPT1_MASK |
907 OMAP3430_GRPSEL_GPT12_MASK,
8bd22949
KH
908 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
909 /* For some reason IO doesn't generate wakeup event even if
910 * it is selected to mpu wakeup goup */
2bc4ef71 911 prm_write_mod_reg(OMAP3430_IO_EN_MASK | OMAP3430_WKUP_EN_MASK,
8bd22949 912 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
1155e426 913
b92c5721 914 /* Enable PM_WKEN to support DSS LPR */
2bc4ef71 915 prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
b92c5721
SV
916 OMAP3430_DSS_MOD, PM_WKEN);
917
b427f92f 918 /* Enable wakeups in PER */
2fd0f75c
PW
919 prm_write_mod_reg(OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
920 OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
921 OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
922 OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
923 OMAP3430_EN_MCBSP4_MASK,
b427f92f 924 OMAP3430_PER_MOD, PM_WKEN);
eb350f74 925 /* and allow them to wake up MPU */
275f675c
PW
926 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2_MASK |
927 OMAP3430_GRPSEL_GPIO3_MASK |
928 OMAP3430_GRPSEL_GPIO4_MASK |
929 OMAP3430_GRPSEL_GPIO5_MASK |
930 OMAP3430_GRPSEL_GPIO6_MASK |
931 OMAP3430_GRPSEL_UART3_MASK |
932 OMAP3430_GRPSEL_MCBSP2_MASK |
933 OMAP3430_GRPSEL_MCBSP3_MASK |
934 OMAP3430_GRPSEL_MCBSP4_MASK,
eb350f74
KH
935 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
936
d3fd3290
KH
937 /* Don't attach IVA interrupts */
938 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
939 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
940 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
941 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
942
b1340d17 943 /* Clear any pending 'reset' flags */
37903009
AP
944 prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
945 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
946 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
947 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
948 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
949 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
950 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
b1340d17 951
014c46db
KH
952 /* Clear any pending PRCM interrupts */
953 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
954
1155e426 955 omap3_iva_idle();
8111b221 956 omap3_d2d_idle();
8bd22949
KH
957}
958
c40552bc
KH
959void omap3_pm_off_mode_enable(int enable)
960{
961 struct power_state *pwrst;
962 u32 state;
963
964 if (enable)
965 state = PWRDM_POWER_OFF;
966 else
967 state = PWRDM_POWER_RET;
968
6af83b38
SP
969#ifdef CONFIG_CPU_IDLE
970 omap3_cpuidle_update_states();
971#endif
972
c40552bc
KH
973 list_for_each_entry(pwrst, &pwrst_list, node) {
974 pwrst->next_state = state;
975 set_pwrdm_state(pwrst->pwrdm, state);
976 }
977}
978
68d4778c
TK
979int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
980{
981 struct power_state *pwrst;
982
983 list_for_each_entry(pwrst, &pwrst_list, node) {
984 if (pwrst->pwrdm == pwrdm)
985 return pwrst->next_state;
986 }
987 return -EINVAL;
988}
989
990int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
991{
992 struct power_state *pwrst;
993
994 list_for_each_entry(pwrst, &pwrst_list, node) {
995 if (pwrst->pwrdm == pwrdm) {
996 pwrst->next_state = state;
997 return 0;
998 }
999 }
1000 return -EINVAL;
1001}
1002
a23456e9 1003static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
8bd22949
KH
1004{
1005 struct power_state *pwrst;
1006
1007 if (!pwrdm->pwrsts)
1008 return 0;
1009
d3d381c6 1010 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
8bd22949
KH
1011 if (!pwrst)
1012 return -ENOMEM;
1013 pwrst->pwrdm = pwrdm;
1014 pwrst->next_state = PWRDM_POWER_RET;
1015 list_add(&pwrst->node, &pwrst_list);
1016
1017 if (pwrdm_has_hdwr_sar(pwrdm))
1018 pwrdm_enable_hdwr_sar(pwrdm);
1019
1020 return set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
1021}
1022
1023/*
1024 * Enable hw supervised mode for all clockdomains if it's
1025 * supported. Initiate sleep transition for other clockdomains, if
1026 * they are not used
1027 */
a23456e9 1028static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
8bd22949 1029{
369d5614
PW
1030 clkdm_clear_all_wkdeps(clkdm);
1031 clkdm_clear_all_sleepdeps(clkdm);
1032
8bd22949
KH
1033 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
1034 omap2_clkdm_allow_idle(clkdm);
1035 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
1036 atomic_read(&clkdm->usecount) == 0)
1037 omap2_clkdm_sleep(clkdm);
1038 return 0;
1039}
1040
3231fc88
RN
1041void omap_push_sram_idle(void)
1042{
1043 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
1044 omap34xx_cpu_suspend_sz);
27d59a4a
TK
1045 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
1046 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
1047 save_secure_ram_context_sz);
3231fc88
RN
1048}
1049
7cc515f7 1050static int __init omap3_pm_init(void)
8bd22949
KH
1051{
1052 struct power_state *pwrst, *tmp;
55ed9694 1053 struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
8bd22949
KH
1054 int ret;
1055
1056 if (!cpu_is_omap34xx())
1057 return -ENODEV;
1058
1059 printk(KERN_ERR "Power Management for TI OMAP3.\n");
1060
1061 /* XXX prcm_setup_regs needs to be before enabling hw
1062 * supervised mode for powerdomains */
1063 prcm_setup_regs();
1064
1065 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
1066 (irq_handler_t)prcm_interrupt_handler,
1067 IRQF_DISABLED, "prcm", NULL);
1068 if (ret) {
1069 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
1070 INT_34XX_PRCM_MPU_IRQ);
1071 goto err1;
1072 }
1073
a23456e9 1074 ret = pwrdm_for_each(pwrdms_setup, NULL);
8bd22949
KH
1075 if (ret) {
1076 printk(KERN_ERR "Failed to setup powerdomains\n");
1077 goto err2;
1078 }
1079
a23456e9 1080 (void) clkdm_for_each(clkdms_setup, NULL);
8bd22949
KH
1081
1082 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
1083 if (mpu_pwrdm == NULL) {
1084 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
1085 goto err2;
1086 }
1087
fa3c2a4f
RN
1088 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
1089 per_pwrdm = pwrdm_lookup("per_pwrdm");
1090 core_pwrdm = pwrdm_lookup("core_pwrdm");
c16c3f67 1091 cam_pwrdm = pwrdm_lookup("cam_pwrdm");
fa3c2a4f 1092
55ed9694
PW
1093 neon_clkdm = clkdm_lookup("neon_clkdm");
1094 mpu_clkdm = clkdm_lookup("mpu_clkdm");
1095 per_clkdm = clkdm_lookup("per_clkdm");
1096 core_clkdm = clkdm_lookup("core_clkdm");
1097
3231fc88 1098 omap_push_sram_idle();
10f90ed2 1099#ifdef CONFIG_SUSPEND
8bd22949 1100 suspend_set_ops(&omap_pm_ops);
10f90ed2 1101#endif /* CONFIG_SUSPEND */
8bd22949
KH
1102
1103 pm_idle = omap3_pm_idle;
0343371e 1104 omap3_idle_init();
8bd22949 1105
55ed9694 1106 clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
27d59a4a
TK
1107 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
1108 omap3_secure_ram_storage =
1109 kmalloc(0x803F, GFP_KERNEL);
1110 if (!omap3_secure_ram_storage)
1111 printk(KERN_ERR "Memory allocation failed when"
1112 "allocating for secure sram context\n");
9d97140b
TK
1113
1114 local_irq_disable();
1115 local_fiq_disable();
1116
1117 omap_dma_global_context_save();
1118 omap3_save_secure_ram_context(PWRDM_POWER_ON);
1119 omap_dma_global_context_restore();
1120
1121 local_irq_enable();
1122 local_fiq_enable();
27d59a4a 1123 }
27d59a4a 1124
9d97140b 1125 omap3_save_scratchpad_contents();
8bd22949
KH
1126err1:
1127 return ret;
1128err2:
1129 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
1130 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
1131 list_del(&pwrst->node);
1132 kfree(pwrst);
1133 }
1134 return ret;
1135}
1136
1137late_initcall(omap3_pm_init);
This page took 0.151124 seconds and 5 git commands to generate.