2 * OMAP3 Power Management Routines
4 * Copyright (C) 2006-2008 Nokia Corporation
5 * Tony Lindgren <tony@atomide.com>
8 * Copyright (C) 2007 Texas Instruments, Inc.
9 * Rajendra Nayak <rnayak@ti.com>
11 * Copyright (C) 2005 Texas Instruments, Inc.
12 * Richard Woodruff <r-woodruff2@ti.com>
14 * Based on pm.c for omap1
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
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 #include <linux/clk.h>
30 #include <plat/sram.h>
31 #include <plat/clockdomain.h>
32 #include <plat/powerdomain.h>
33 #include <plat/control.h>
34 #include <plat/serial.h>
35 #include <plat/sdrc.h>
36 #include <plat/prcm.h>
37 #include <plat/gpmc.h>
39 #include <plat/dmtimer.h>
41 #include <asm/tlbflush.h>
44 #include "cm-regbits-34xx.h"
45 #include "prm-regbits-34xx.h"
47 #include "smartreflex.h"
52 /* Scratchpad offsets */
53 #define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
54 #define OMAP343X_TABLE_VALUE_OFFSET 0x30
55 #define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
59 u32 wakeup_timer_seconds
;
62 struct powerdomain
*pwrdm
;
67 struct list_head node
;
70 static LIST_HEAD(pwrst_list
);
72 static void (*_omap_sram_idle
)(u32
*addr
, int save_state
);
74 static int (*_omap_save_secure_sram
)(u32
*addr
);
76 static struct powerdomain
*mpu_pwrdm
, *neon_pwrdm
;
77 static struct powerdomain
*core_pwrdm
, *per_pwrdm
;
78 static struct powerdomain
*cam_pwrdm
;
80 static inline void omap3_per_save_context(void)
82 omap_gpio_save_context();
85 static inline void omap3_per_restore_context(void)
87 omap_gpio_restore_context();
90 static void omap3_enable_io_chain(void)
94 if (omap_rev() >= OMAP3430_REV_ES3_1
) {
95 prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN
, WKUP_MOD
, PM_WKEN
);
96 /* Do a readback to assure write has been done */
97 prm_read_mod_reg(WKUP_MOD
, PM_WKEN
);
99 while (!(prm_read_mod_reg(WKUP_MOD
, PM_WKST
) &
100 OMAP3430_ST_IO_CHAIN
)) {
102 if (timeout
> 1000) {
103 printk(KERN_ERR
"Wake up daisy chain "
104 "activation failed.\n");
107 prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN
,
113 static void omap3_disable_io_chain(void)
115 if (omap_rev() >= OMAP3430_REV_ES3_1
)
116 prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN
, WKUP_MOD
, PM_WKEN
);
119 static void omap3_core_save_context(void)
121 u32 control_padconf_off
;
123 /* Save the padconf registers */
124 control_padconf_off
= omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF
);
125 control_padconf_off
|= START_PADCONF_SAVE
;
126 omap_ctrl_writel(control_padconf_off
, OMAP343X_CONTROL_PADCONF_OFF
);
127 /* wait for the save to complete */
128 while (!omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS
)
131 /* Save the Interrupt controller context */
132 omap_intc_save_context();
133 /* Save the GPMC context */
134 omap3_gpmc_save_context();
135 /* Save the system control module context, padconf already save above*/
136 omap3_control_save_context();
137 omap_dma_global_context_save();
140 static void omap3_core_restore_context(void)
142 /* Restore the control module context, padconf restored by h/w */
143 omap3_control_restore_context();
144 /* Restore the GPMC context */
145 omap3_gpmc_restore_context();
146 /* Restore the interrupt controller context */
147 omap_intc_restore_context();
148 omap_dma_global_context_restore();
152 * FIXME: This function should be called before entering off-mode after
153 * OMAP3 secure services have been accessed. Currently it is only called
154 * once during boot sequence, but this works as we are not using secure
157 static void omap3_save_secure_ram_context(u32 target_mpu_state
)
161 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
163 * MPU next state must be set to POWER_ON temporarily,
164 * otherwise the WFI executed inside the ROM code
165 * will hang the system.
167 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_ON
);
168 ret
= _omap_save_secure_sram((u32
*)
169 __pa(omap3_secure_ram_storage
));
170 pwrdm_set_next_pwrst(mpu_pwrdm
, target_mpu_state
);
171 /* Following is for error tracking, it should not happen */
173 printk(KERN_ERR
"save_secure_sram() returns %08x\n",
182 * PRCM Interrupt Handler Helper Function
184 * The purpose of this function is to clear any wake-up events latched
185 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
186 * may occur whilst attempting to clear a PM_WKST_x register and thus
187 * set another bit in this register. A while loop is used to ensure
188 * that any peripheral wake-up events occurring while attempting to
189 * clear the PM_WKST_x are detected and cleared.
191 static int prcm_clear_mod_irqs(s16 module
, u8 regs
)
193 u32 wkst
, fclk
, iclk
, clken
;
194 u16 wkst_off
= (regs
== 3) ? OMAP3430ES2_PM_WKST3
: PM_WKST1
;
195 u16 fclk_off
= (regs
== 3) ? OMAP3430ES2_CM_FCLKEN3
: CM_FCLKEN1
;
196 u16 iclk_off
= (regs
== 3) ? CM_ICLKEN3
: CM_ICLKEN1
;
197 u16 grpsel_off
= (regs
== 3) ?
198 OMAP3430ES2_PM_MPUGRPSEL3
: OMAP3430_PM_MPUGRPSEL
;
201 wkst
= prm_read_mod_reg(module
, wkst_off
);
202 wkst
&= prm_read_mod_reg(module
, grpsel_off
);
204 iclk
= cm_read_mod_reg(module
, iclk_off
);
205 fclk
= cm_read_mod_reg(module
, fclk_off
);
208 cm_set_mod_reg_bits(clken
, module
, iclk_off
);
210 * For USBHOST, we don't know whether HOST1 or
211 * HOST2 woke us up, so enable both f-clocks
213 if (module
== OMAP3430ES2_USBHOST_MOD
)
214 clken
|= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT
;
215 cm_set_mod_reg_bits(clken
, module
, fclk_off
);
216 prm_write_mod_reg(wkst
, module
, wkst_off
);
217 wkst
= prm_read_mod_reg(module
, wkst_off
);
220 cm_write_mod_reg(iclk
, module
, iclk_off
);
221 cm_write_mod_reg(fclk
, module
, fclk_off
);
227 static int _prcm_int_handle_wakeup(void)
231 c
= prcm_clear_mod_irqs(WKUP_MOD
, 1);
232 c
+= prcm_clear_mod_irqs(CORE_MOD
, 1);
233 c
+= prcm_clear_mod_irqs(OMAP3430_PER_MOD
, 1);
234 if (omap_rev() > OMAP3430_REV_ES1_0
) {
235 c
+= prcm_clear_mod_irqs(CORE_MOD
, 3);
236 c
+= prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD
, 1);
243 * PRCM Interrupt Handler
245 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
246 * interrupts from the PRCM for the MPU. These bits must be cleared in
247 * order to clear the PRCM interrupt. The PRCM interrupt handler is
248 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
249 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
250 * register indicates that a wake-up event is pending for the MPU and
251 * this bit can only be cleared if the all the wake-up events latched
252 * in the various PM_WKST_x registers have been cleared. The interrupt
253 * handler is implemented using a do-while loop so that if a wake-up
254 * event occurred during the processing of the prcm interrupt handler
255 * (setting a bit in the corresponding PM_WKST_x register and thus
256 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
257 * this would be handled.
259 static irqreturn_t
prcm_interrupt_handler (int irq
, void *dev_id
)
265 irqstatus_mpu
= prm_read_mod_reg(OCP_MOD
,
266 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
268 if (irqstatus_mpu
& (OMAP3430_WKUP_ST
| OMAP3430_IO_ST
)) {
269 c
= _prcm_int_handle_wakeup();
272 * Is the MPU PRCM interrupt handler racing with the
273 * IVA2 PRCM interrupt handler ?
275 WARN(c
== 0, "prcm: WARNING: PRCM indicated MPU wakeup "
276 "but no wakeup sources are marked\n");
278 /* XXX we need to expand our PRCM interrupt handler */
279 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
280 "no code to handle it (%08x)\n", irqstatus_mpu
);
283 prm_write_mod_reg(irqstatus_mpu
, OCP_MOD
,
284 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
286 } while (prm_read_mod_reg(OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
));
291 static void restore_control_register(u32 val
)
293 __asm__
__volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val
));
296 /* Function to restore the table entry that was modified for enabling MMU */
297 static void restore_table_entry(void)
299 u32
*scratchpad_address
;
300 u32 previous_value
, control_reg_value
;
303 scratchpad_address
= OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD
);
305 /* Get address of entry that was modified */
306 address
= (u32
*)__raw_readl(scratchpad_address
+
307 OMAP343X_TABLE_ADDRESS_OFFSET
);
308 /* Get the previous value which needs to be restored */
309 previous_value
= __raw_readl(scratchpad_address
+
310 OMAP343X_TABLE_VALUE_OFFSET
);
311 address
= __va(address
);
312 *address
= previous_value
;
314 control_reg_value
= __raw_readl(scratchpad_address
315 + OMAP343X_CONTROL_REG_VALUE_OFFSET
);
316 /* This will enable caches and prediction */
317 restore_control_register(control_reg_value
);
320 void omap_sram_idle(void)
322 /* Variable to tell what needs to be saved and restored
323 * in omap_sram_idle*/
324 /* save_state = 0 => Nothing to save and restored */
325 /* save_state = 1 => Only L1 and logic lost */
326 /* save_state = 2 => Only L2 lost */
327 /* save_state = 3 => L1, L2 and logic lost */
329 int mpu_next_state
= PWRDM_POWER_ON
;
330 int per_next_state
= PWRDM_POWER_ON
;
331 int core_next_state
= PWRDM_POWER_ON
;
332 int core_prev_state
, per_prev_state
;
334 int per_state_modified
= 0;
336 if (!_omap_sram_idle
)
339 pwrdm_clear_all_prev_pwrst(mpu_pwrdm
);
340 pwrdm_clear_all_prev_pwrst(neon_pwrdm
);
341 pwrdm_clear_all_prev_pwrst(core_pwrdm
);
342 pwrdm_clear_all_prev_pwrst(per_pwrdm
);
344 mpu_next_state
= pwrdm_read_next_pwrst(mpu_pwrdm
);
345 switch (mpu_next_state
) {
347 case PWRDM_POWER_RET
:
348 /* No need to save context */
351 case PWRDM_POWER_OFF
:
356 printk(KERN_ERR
"Invalid mpu state in sram_idle\n");
360 /* Disable smartreflex before entering WFI */
361 disable_smartreflex(SR1
);
362 disable_smartreflex(SR2
);
364 pwrdm_pre_transition();
367 if (pwrdm_read_pwrst(neon_pwrdm
) == PWRDM_POWER_ON
)
368 pwrdm_set_next_pwrst(neon_pwrdm
, mpu_next_state
);
371 per_next_state
= pwrdm_read_next_pwrst(per_pwrdm
);
372 core_next_state
= pwrdm_read_next_pwrst(core_pwrdm
);
373 if (per_next_state
< PWRDM_POWER_ON
) {
374 omap_uart_prepare_idle(2);
375 omap2_gpio_prepare_for_idle(per_next_state
);
376 if (per_next_state
== PWRDM_POWER_OFF
) {
377 if (core_next_state
== PWRDM_POWER_ON
) {
378 per_next_state
= PWRDM_POWER_RET
;
379 pwrdm_set_next_pwrst(per_pwrdm
, per_next_state
);
380 per_state_modified
= 1;
382 omap3_per_save_context();
386 if (pwrdm_read_pwrst(cam_pwrdm
) == PWRDM_POWER_ON
)
387 omap2_clkdm_deny_idle(mpu_pwrdm
->pwrdm_clkdms
[0]);
390 if (core_next_state
< PWRDM_POWER_ON
) {
391 omap_uart_prepare_idle(0);
392 omap_uart_prepare_idle(1);
393 if (core_next_state
== PWRDM_POWER_OFF
) {
394 omap3_core_save_context();
395 omap3_prcm_save_context();
397 /* Enable IO-PAD and IO-CHAIN wakeups */
398 prm_set_mod_reg_bits(OMAP3430_EN_IO
, WKUP_MOD
, PM_WKEN
);
399 omap3_enable_io_chain();
403 * On EMU/HS devices ROM code restores a SRDC value
404 * from scratchpad which has automatic self refresh on timeout
405 * of AUTO_CNT = 1 enabled. This takes care of errata 1.142.
406 * Hence store/restore the SDRC_POWER register here.
408 if (omap_rev() >= OMAP3430_REV_ES3_0
&&
409 omap_type() != OMAP2_DEVICE_TYPE_GP
&&
410 core_next_state
== PWRDM_POWER_OFF
)
411 sdrc_pwr
= sdrc_read_reg(SDRC_POWER
);
414 * omap3_arm_context is the location where ARM registers
415 * get saved. The restore path then reads from this
416 * location and restores them back.
418 _omap_sram_idle(omap3_arm_context
, save_state
);
421 /* Restore normal SDRC POWER settings */
422 if (omap_rev() >= OMAP3430_REV_ES3_0
&&
423 omap_type() != OMAP2_DEVICE_TYPE_GP
&&
424 core_next_state
== PWRDM_POWER_OFF
)
425 sdrc_write_reg(sdrc_pwr
, SDRC_POWER
);
427 /* Restore table entry modified during MMU restoration */
428 if (pwrdm_read_prev_pwrst(mpu_pwrdm
) == PWRDM_POWER_OFF
)
429 restore_table_entry();
432 if (core_next_state
< PWRDM_POWER_ON
) {
433 core_prev_state
= pwrdm_read_prev_pwrst(core_pwrdm
);
434 if (core_prev_state
== PWRDM_POWER_OFF
) {
435 omap3_core_restore_context();
436 omap3_prcm_restore_context();
437 omap3_sram_restore_context();
438 omap2_sms_restore_context();
440 omap_uart_resume_idle(0);
441 omap_uart_resume_idle(1);
442 if (core_next_state
== PWRDM_POWER_OFF
)
443 prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF
,
445 OMAP3_PRM_VOLTCTRL_OFFSET
);
449 if (per_next_state
< PWRDM_POWER_ON
) {
450 per_prev_state
= pwrdm_read_prev_pwrst(per_pwrdm
);
451 if (per_prev_state
== PWRDM_POWER_OFF
) {
452 omap3_per_restore_context();
453 omap3_gpio_restore_pad_context(0);
454 } else if (per_next_state
== PWRDM_POWER_OFF
)
455 omap3_gpio_restore_pad_context(1);
456 omap2_gpio_resume_after_idle();
457 omap_uart_resume_idle(2);
458 if (per_state_modified
)
459 pwrdm_set_next_pwrst(per_pwrdm
, PWRDM_POWER_OFF
);
462 /* Disable IO-PAD and IO-CHAIN wakeup */
463 if (core_next_state
< PWRDM_POWER_ON
) {
464 prm_clear_mod_reg_bits(OMAP3430_EN_IO
, WKUP_MOD
, PM_WKEN
);
465 omap3_disable_io_chain();
468 /* Enable smartreflex after WFI */
469 enable_smartreflex(SR1
);
470 enable_smartreflex(SR2
);
472 pwrdm_post_transition();
474 omap2_clkdm_allow_idle(mpu_pwrdm
->pwrdm_clkdms
[0]);
477 int omap3_can_sleep(void)
479 if (!sleep_while_idle
)
481 if (!omap_uart_can_sleep())
486 /* This sets pwrdm state (other than mpu & core. Currently only ON &
487 * RET are supported. Function is assuming that clkdm doesn't have
488 * hw_sup mode enabled. */
489 int set_pwrdm_state(struct powerdomain
*pwrdm
, u32 state
)
492 int sleep_switch
= 0;
495 if (pwrdm
== NULL
|| IS_ERR(pwrdm
))
498 while (!(pwrdm
->pwrsts
& (1 << state
))) {
499 if (state
== PWRDM_POWER_OFF
)
504 cur_state
= pwrdm_read_next_pwrst(pwrdm
);
505 if (cur_state
== state
)
508 if (pwrdm_read_pwrst(pwrdm
) < PWRDM_POWER_ON
) {
509 omap2_clkdm_wakeup(pwrdm
->pwrdm_clkdms
[0]);
511 pwrdm_wait_transition(pwrdm
);
514 ret
= pwrdm_set_next_pwrst(pwrdm
, state
);
516 printk(KERN_ERR
"Unable to set state of powerdomain: %s\n",
522 omap2_clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
523 pwrdm_wait_transition(pwrdm
);
524 pwrdm_state_switch(pwrdm
);
531 static void omap3_pm_idle(void)
536 if (!omap3_can_sleep())
539 if (omap_irq_pending() || need_resched())
549 #ifdef CONFIG_SUSPEND
550 static suspend_state_t suspend_state
;
552 static void omap2_pm_wakeup_on_timer(u32 seconds
)
554 u32 tick_rate
, cycles
;
559 tick_rate
= clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup
));
560 cycles
= tick_rate
* seconds
;
561 omap_dm_timer_stop(gptimer_wakeup
);
562 omap_dm_timer_set_load_start(gptimer_wakeup
, 0, 0xffffffff - cycles
);
564 pr_info("PM: Resume timer in %d secs (%d ticks at %d ticks/sec.)\n",
565 seconds
, cycles
, tick_rate
);
568 static int omap3_pm_prepare(void)
574 static int omap3_pm_suspend(void)
576 struct power_state
*pwrst
;
579 if (wakeup_timer_seconds
)
580 omap2_pm_wakeup_on_timer(wakeup_timer_seconds
);
582 /* Read current next_pwrsts */
583 list_for_each_entry(pwrst
, &pwrst_list
, node
)
584 pwrst
->saved_state
= pwrdm_read_next_pwrst(pwrst
->pwrdm
);
585 /* Set ones wanted by suspend */
586 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
587 if (set_pwrdm_state(pwrst
->pwrdm
, pwrst
->next_state
))
589 if (pwrdm_clear_all_prev_pwrst(pwrst
->pwrdm
))
593 omap_uart_prepare_suspend();
597 /* Restore next_pwrsts */
598 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
599 state
= pwrdm_read_prev_pwrst(pwrst
->pwrdm
);
600 if (state
> pwrst
->next_state
) {
601 printk(KERN_INFO
"Powerdomain (%s) didn't enter "
603 pwrst
->pwrdm
->name
, pwrst
->next_state
);
606 set_pwrdm_state(pwrst
->pwrdm
, pwrst
->saved_state
);
609 printk(KERN_ERR
"Could not enter target state in pm_suspend\n");
611 printk(KERN_INFO
"Successfully put all powerdomains "
612 "to target state\n");
617 static int omap3_pm_enter(suspend_state_t unused
)
621 switch (suspend_state
) {
622 case PM_SUSPEND_STANDBY
:
624 ret
= omap3_pm_suspend();
633 static void omap3_pm_finish(void)
638 /* Hooks to enable / disable UART interrupts during suspend */
639 static int omap3_pm_begin(suspend_state_t state
)
641 suspend_state
= state
;
642 omap_uart_enable_irqs(0);
646 static void omap3_pm_end(void)
648 suspend_state
= PM_SUSPEND_ON
;
649 omap_uart_enable_irqs(1);
653 static struct platform_suspend_ops omap_pm_ops
= {
654 .begin
= omap3_pm_begin
,
656 .prepare
= omap3_pm_prepare
,
657 .enter
= omap3_pm_enter
,
658 .finish
= omap3_pm_finish
,
659 .valid
= suspend_valid_only_mem
,
661 #endif /* CONFIG_SUSPEND */
665 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
668 * In cases where IVA2 is activated by bootcode, it may prevent
669 * full-chip retention or off-mode because it is not idle. This
670 * function forces the IVA2 into idle state so it can go
671 * into retention/off and thus allow full-chip retention/off.
674 static void __init
omap3_iva_idle(void)
676 /* ensure IVA2 clock is disabled */
677 cm_write_mod_reg(0, OMAP3430_IVA2_MOD
, CM_FCLKEN
);
679 /* if no clock activity, nothing else to do */
680 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD
, OMAP3430_CM_CLKSTST
) &
681 OMAP3430_CLKACTIVITY_IVA2_MASK
))
685 prm_write_mod_reg(OMAP3430_RST1_IVA2
|
688 OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
690 /* Enable IVA2 clock */
691 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2
,
692 OMAP3430_IVA2_MOD
, CM_FCLKEN
);
694 /* Set IVA2 boot mode to 'idle' */
695 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE
,
696 OMAP343X_CONTROL_IVA2_BOOTMOD
);
699 prm_write_mod_reg(0, OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
701 /* Disable IVA2 clock */
702 cm_write_mod_reg(0, OMAP3430_IVA2_MOD
, CM_FCLKEN
);
705 prm_write_mod_reg(OMAP3430_RST1_IVA2
|
708 OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
711 static void __init
omap3_d2d_idle(void)
715 /* In a stand alone OMAP3430 where there is not a stacked
716 * modem for the D2D Idle Ack and D2D MStandby must be pulled
717 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
718 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
719 mask
= (1 << 4) | (1 << 3); /* pull-up, enabled */
720 padconf
= omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY
);
722 omap_ctrl_writew(padconf
, OMAP3_PADCONF_SAD2D_MSTANDBY
);
724 padconf
= omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK
);
726 omap_ctrl_writew(padconf
, OMAP3_PADCONF_SAD2D_IDLEACK
);
729 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON
|
730 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST
,
731 CORE_MOD
, RM_RSTCTRL
);
732 prm_write_mod_reg(0, CORE_MOD
, RM_RSTCTRL
);
735 static void __init
prcm_setup_regs(void)
737 /* XXX Reset all wkdeps. This should be done when initializing
739 prm_write_mod_reg(0, OMAP3430_IVA2_MOD
, PM_WKDEP
);
740 prm_write_mod_reg(0, MPU_MOD
, PM_WKDEP
);
741 prm_write_mod_reg(0, OMAP3430_DSS_MOD
, PM_WKDEP
);
742 prm_write_mod_reg(0, OMAP3430_NEON_MOD
, PM_WKDEP
);
743 prm_write_mod_reg(0, OMAP3430_CAM_MOD
, PM_WKDEP
);
744 prm_write_mod_reg(0, OMAP3430_PER_MOD
, PM_WKDEP
);
745 if (omap_rev() > OMAP3430_REV_ES1_0
) {
746 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD
, PM_WKDEP
);
747 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD
, PM_WKDEP
);
749 prm_write_mod_reg(0, GFX_MOD
, PM_WKDEP
);
752 * Enable interface clock autoidle for all modules.
753 * Note that in the long run this should be done by clockfw
756 OMAP3430_AUTO_MODEM
|
757 OMAP3430ES2_AUTO_MMC3
|
758 OMAP3430ES2_AUTO_ICR
|
760 OMAP3430_AUTO_SHA12
|
764 OMAP3430_AUTO_MSPRO
|
766 OMAP3430_AUTO_MCSPI4
|
767 OMAP3430_AUTO_MCSPI3
|
768 OMAP3430_AUTO_MCSPI2
|
769 OMAP3430_AUTO_MCSPI1
|
773 OMAP3430_AUTO_UART2
|
774 OMAP3430_AUTO_UART1
|
775 OMAP3430_AUTO_GPT11
|
776 OMAP3430_AUTO_GPT10
|
777 OMAP3430_AUTO_MCBSP5
|
778 OMAP3430_AUTO_MCBSP1
|
779 OMAP3430ES1_AUTO_FAC
| /* This is es1 only */
780 OMAP3430_AUTO_MAILBOXES
|
781 OMAP3430_AUTO_OMAPCTRL
|
782 OMAP3430ES1_AUTO_FSHOSTUSB
|
783 OMAP3430_AUTO_HSOTGUSB
|
784 OMAP3430_AUTO_SAD2D
|
786 CORE_MOD
, CM_AUTOIDLE1
);
792 OMAP3430_AUTO_SHA11
|
794 CORE_MOD
, CM_AUTOIDLE2
);
796 if (omap_rev() > OMAP3430_REV_ES1_0
) {
798 OMAP3430_AUTO_MAD2D
|
799 OMAP3430ES2_AUTO_USBTLL
,
800 CORE_MOD
, CM_AUTOIDLE3
);
806 OMAP3430_AUTO_GPIO1
|
807 OMAP3430_AUTO_32KSYNC
|
808 OMAP3430_AUTO_GPT12
|
810 WKUP_MOD
, CM_AUTOIDLE
);
823 OMAP3430_AUTO_GPIO6
|
824 OMAP3430_AUTO_GPIO5
|
825 OMAP3430_AUTO_GPIO4
|
826 OMAP3430_AUTO_GPIO3
|
827 OMAP3430_AUTO_GPIO2
|
829 OMAP3430_AUTO_UART3
|
838 OMAP3430_AUTO_MCBSP4
|
839 OMAP3430_AUTO_MCBSP3
|
840 OMAP3430_AUTO_MCBSP2
,
844 if (omap_rev() > OMAP3430_REV_ES1_0
) {
846 OMAP3430ES2_AUTO_USBHOST
,
847 OMAP3430ES2_USBHOST_MOD
,
852 * Set all plls to autoidle. This is needed until autoidle is
855 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT
,
856 OMAP3430_IVA2_MOD
, CM_AUTOIDLE2
);
857 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT
,
860 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT
) |
861 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT
),
864 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT
,
869 * Enable control of expternal oscillator through
870 * sys_clkreq. In the long run clock framework should
873 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK
,
874 1 << OMAP_AUTOEXTCLKMODE_SHIFT
,
876 OMAP3_PRM_CLKSRC_CTRL_OFFSET
);
878 /* setup wakup source */
879 prm_write_mod_reg(OMAP3430_EN_IO
| OMAP3430_EN_GPIO1
|
880 OMAP3430_EN_GPT1
| OMAP3430_EN_GPT12
,
882 /* No need to write EN_IO, that is always enabled */
883 prm_write_mod_reg(OMAP3430_EN_GPIO1
| OMAP3430_EN_GPT1
|
885 WKUP_MOD
, OMAP3430_PM_MPUGRPSEL
);
886 /* For some reason IO doesn't generate wakeup event even if
887 * it is selected to mpu wakeup goup */
888 prm_write_mod_reg(OMAP3430_IO_EN
| OMAP3430_WKUP_EN
,
889 OCP_MOD
, OMAP3_PRM_IRQENABLE_MPU_OFFSET
);
891 /* Enable wakeups in PER */
892 prm_write_mod_reg(OMAP3430_EN_GPIO2
| OMAP3430_EN_GPIO3
|
893 OMAP3430_EN_GPIO4
| OMAP3430_EN_GPIO5
|
894 OMAP3430_EN_GPIO6
| OMAP3430_EN_UART3
,
895 OMAP3430_PER_MOD
, PM_WKEN
);
896 /* and allow them to wake up MPU */
897 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2
| OMAP3430_EN_GPIO3
|
898 OMAP3430_GRPSEL_GPIO4
| OMAP3430_EN_GPIO5
|
899 OMAP3430_GRPSEL_GPIO6
| OMAP3430_EN_UART3
,
900 OMAP3430_PER_MOD
, OMAP3430_PM_MPUGRPSEL
);
902 /* Don't attach IVA interrupts */
903 prm_write_mod_reg(0, WKUP_MOD
, OMAP3430_PM_IVAGRPSEL
);
904 prm_write_mod_reg(0, CORE_MOD
, OMAP3430_PM_IVAGRPSEL1
);
905 prm_write_mod_reg(0, CORE_MOD
, OMAP3430ES2_PM_IVAGRPSEL3
);
906 prm_write_mod_reg(0, OMAP3430_PER_MOD
, OMAP3430_PM_IVAGRPSEL
);
908 /* Clear any pending 'reset' flags */
909 prm_write_mod_reg(0xffffffff, MPU_MOD
, RM_RSTST
);
910 prm_write_mod_reg(0xffffffff, CORE_MOD
, RM_RSTST
);
911 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD
, RM_RSTST
);
912 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD
, RM_RSTST
);
913 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD
, RM_RSTST
);
914 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD
, RM_RSTST
);
915 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD
, RM_RSTST
);
917 /* Clear any pending PRCM interrupts */
918 prm_write_mod_reg(0, OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
920 /* Don't attach IVA interrupts */
921 prm_write_mod_reg(0, WKUP_MOD
, OMAP3430_PM_IVAGRPSEL
);
922 prm_write_mod_reg(0, CORE_MOD
, OMAP3430_PM_IVAGRPSEL1
);
923 prm_write_mod_reg(0, CORE_MOD
, OMAP3430ES2_PM_IVAGRPSEL3
);
924 prm_write_mod_reg(0, OMAP3430_PER_MOD
, OMAP3430_PM_IVAGRPSEL
);
926 /* Clear any pending 'reset' flags */
927 prm_write_mod_reg(0xffffffff, MPU_MOD
, RM_RSTST
);
928 prm_write_mod_reg(0xffffffff, CORE_MOD
, RM_RSTST
);
929 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD
, RM_RSTST
);
930 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD
, RM_RSTST
);
931 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD
, RM_RSTST
);
932 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD
, RM_RSTST
);
933 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD
, RM_RSTST
);
935 /* Clear any pending PRCM interrupts */
936 prm_write_mod_reg(0, OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
942 void omap3_pm_off_mode_enable(int enable
)
944 struct power_state
*pwrst
;
948 state
= PWRDM_POWER_OFF
;
950 state
= PWRDM_POWER_RET
;
952 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
953 pwrst
->next_state
= state
;
954 set_pwrdm_state(pwrst
->pwrdm
, state
);
958 int omap3_pm_get_suspend_state(struct powerdomain
*pwrdm
)
960 struct power_state
*pwrst
;
962 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
963 if (pwrst
->pwrdm
== pwrdm
)
964 return pwrst
->next_state
;
969 int omap3_pm_set_suspend_state(struct powerdomain
*pwrdm
, int state
)
971 struct power_state
*pwrst
;
973 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
974 if (pwrst
->pwrdm
== pwrdm
) {
975 pwrst
->next_state
= state
;
982 static int __init
pwrdms_setup(struct powerdomain
*pwrdm
, void *unused
)
984 struct power_state
*pwrst
;
989 pwrst
= kmalloc(sizeof(struct power_state
), GFP_ATOMIC
);
992 pwrst
->pwrdm
= pwrdm
;
993 pwrst
->next_state
= PWRDM_POWER_RET
;
994 list_add(&pwrst
->node
, &pwrst_list
);
996 if (pwrdm_has_hdwr_sar(pwrdm
))
997 pwrdm_enable_hdwr_sar(pwrdm
);
999 return set_pwrdm_state(pwrst
->pwrdm
, pwrst
->next_state
);
1003 * Enable hw supervised mode for all clockdomains if it's
1004 * supported. Initiate sleep transition for other clockdomains, if
1007 static int __init
clkdms_setup(struct clockdomain
*clkdm
, void *unused
)
1009 if (clkdm
->flags
& CLKDM_CAN_ENABLE_AUTO
)
1010 omap2_clkdm_allow_idle(clkdm
);
1011 else if (clkdm
->flags
& CLKDM_CAN_FORCE_SLEEP
&&
1012 atomic_read(&clkdm
->usecount
) == 0)
1013 omap2_clkdm_sleep(clkdm
);
1017 void omap_push_sram_idle(void)
1019 _omap_sram_idle
= omap_sram_push(omap34xx_cpu_suspend
,
1020 omap34xx_cpu_suspend_sz
);
1021 if (omap_type() != OMAP2_DEVICE_TYPE_GP
)
1022 _omap_save_secure_sram
= omap_sram_push(save_secure_ram_context
,
1023 save_secure_ram_context_sz
);
1026 static int __init
omap3_pm_init(void)
1028 struct power_state
*pwrst
, *tmp
;
1031 if (!cpu_is_omap34xx())
1034 printk(KERN_ERR
"Power Management for TI OMAP3.\n");
1036 /* XXX prcm_setup_regs needs to be before enabling hw
1037 * supervised mode for powerdomains */
1040 ret
= request_irq(INT_34XX_PRCM_MPU_IRQ
,
1041 (irq_handler_t
)prcm_interrupt_handler
,
1042 IRQF_DISABLED
, "prcm", NULL
);
1044 printk(KERN_ERR
"request_irq failed to register for 0x%x\n",
1045 INT_34XX_PRCM_MPU_IRQ
);
1049 ret
= pwrdm_for_each(pwrdms_setup
, NULL
);
1051 printk(KERN_ERR
"Failed to setup powerdomains\n");
1055 (void) clkdm_for_each(clkdms_setup
, NULL
);
1057 mpu_pwrdm
= pwrdm_lookup("mpu_pwrdm");
1058 if (mpu_pwrdm
== NULL
) {
1059 printk(KERN_ERR
"Failed to get mpu_pwrdm\n");
1063 neon_pwrdm
= pwrdm_lookup("neon_pwrdm");
1064 per_pwrdm
= pwrdm_lookup("per_pwrdm");
1065 core_pwrdm
= pwrdm_lookup("core_pwrdm");
1066 cam_pwrdm
= pwrdm_lookup("cam_pwrdm");
1068 omap_push_sram_idle();
1069 #ifdef CONFIG_SUSPEND
1070 suspend_set_ops(&omap_pm_ops
);
1071 #endif /* CONFIG_SUSPEND */
1073 pm_idle
= omap3_pm_idle
;
1076 pwrdm_add_wkdep(neon_pwrdm
, mpu_pwrdm
);
1078 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
1079 * IO-pad wakeup. Otherwise it will unnecessarily waste power
1080 * waking up PER with every CORE wakeup - see
1081 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
1083 pwrdm_add_wkdep(per_pwrdm
, core_pwrdm
);
1085 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
1086 omap3_secure_ram_storage
=
1087 kmalloc(0x803F, GFP_KERNEL
);
1088 if (!omap3_secure_ram_storage
)
1089 printk(KERN_ERR
"Memory allocation failed when"
1090 "allocating for secure sram context\n");
1092 local_irq_disable();
1093 local_fiq_disable();
1095 omap_dma_global_context_save();
1096 omap3_save_secure_ram_context(PWRDM_POWER_ON
);
1097 omap_dma_global_context_restore();
1103 omap3_save_scratchpad_contents();
1107 free_irq(INT_34XX_PRCM_MPU_IRQ
, NULL
);
1108 list_for_each_entry_safe(pwrst
, tmp
, &pwrst_list
, node
) {
1109 list_del(&pwrst
->node
);
1115 /* PRM_VC_CMD_VAL_0 specific bits */
1116 #define OMAP3430_VC_CMD_VAL0_ON (0x3 << 4)
1117 #define OMAP3430_VC_CMD_VAL0_ONLP (0x3 << 3)
1118 #define OMAP3430_VC_CMD_VAL0_RET (0x3 << 3)
1119 #define OMAP3430_VC_CMD_VAL0_OFF (0x3 << 3)
1121 /* PRM_VC_CMD_VAL_1 specific bits */
1122 #define OMAP3430_VC_CMD_VAL1_ON (0xB << 2)
1123 #define OMAP3430_VC_CMD_VAL1_ONLP (0x3 << 3)
1124 #define OMAP3430_VC_CMD_VAL1_RET (0x3 << 3)
1125 #define OMAP3430_VC_CMD_VAL1_OFF (0x3 << 3)
1127 /* Constants to define setup durations */
1128 #define OMAP3430_CLKSETUP_DURATION 0xff
1129 #define OMAP3430_VOLTSETUP_TIME2 0xfff
1130 #define OMAP3430_VOLTSETUP_TIME1 0xfff
1131 #define OMAP3430_VOLTOFFSET_DURATION 0xff
1132 #define OMAP3430_VOLTSETUP2_DURATION 0xff
1134 static void __init
configure_vc(void)
1136 prm_write_mod_reg((R_SRI2C_SLAVE_ADDR
<< OMAP3430_SMPS_SA1_SHIFT
) |
1137 (R_SRI2C_SLAVE_ADDR
<< OMAP3430_SMPS_SA0_SHIFT
),
1138 OMAP3430_GR_MOD
, OMAP3_PRM_VC_SMPS_SA_OFFSET
);
1139 prm_write_mod_reg((R_VDD2_SR_CONTROL
<< OMAP3430_VOLRA1_SHIFT
) |
1140 (R_VDD1_SR_CONTROL
<< OMAP3430_VOLRA0_SHIFT
),
1141 OMAP3430_GR_MOD
, OMAP3_PRM_VC_SMPS_VOL_RA_OFFSET
);
1144 (OMAP3430_VC_CMD_VAL0_ON
<< OMAP3430_VC_CMD_ON_SHIFT
) |
1145 (OMAP3430_VC_CMD_VAL0_ONLP
<< OMAP3430_VC_CMD_ONLP_SHIFT
) |
1146 (OMAP3430_VC_CMD_VAL0_RET
<< OMAP3430_VC_CMD_RET_SHIFT
) |
1147 (OMAP3430_VC_CMD_VAL0_OFF
<< OMAP3430_VC_CMD_OFF_SHIFT
),
1148 OMAP3430_GR_MOD
, OMAP3_PRM_VC_CMD_VAL_0_OFFSET
);
1151 (OMAP3430_VC_CMD_VAL1_ON
<< OMAP3430_VC_CMD_ON_SHIFT
) |
1152 (OMAP3430_VC_CMD_VAL1_ONLP
<< OMAP3430_VC_CMD_ONLP_SHIFT
) |
1153 (OMAP3430_VC_CMD_VAL1_RET
<< OMAP3430_VC_CMD_RET_SHIFT
) |
1154 (OMAP3430_VC_CMD_VAL1_OFF
<< OMAP3430_VC_CMD_OFF_SHIFT
),
1155 OMAP3430_GR_MOD
, OMAP3_PRM_VC_CMD_VAL_1_OFFSET
);
1157 prm_write_mod_reg(OMAP3430_CMD1
| OMAP3430_RAV1
, OMAP3430_GR_MOD
,
1158 OMAP3_PRM_VC_CH_CONF_OFFSET
);
1160 prm_write_mod_reg(OMAP3430_MCODE_SHIFT
| OMAP3430_HSEN
| OMAP3430_SREN
,
1162 OMAP3_PRM_VC_I2C_CFG_OFFSET
);
1164 /* Setup voltctrl and other setup times */
1165 prm_write_mod_reg(OMAP3430_AUTO_RET
, OMAP3430_GR_MOD
,
1166 OMAP3_PRM_VOLTCTRL_OFFSET
);
1168 prm_write_mod_reg(OMAP3430_CLKSETUP_DURATION
, OMAP3430_GR_MOD
,
1169 OMAP3_PRM_CLKSETUP_OFFSET
);
1171 (OMAP3430_VOLTSETUP_TIME2
<< OMAP3430_SETUP_TIME2_SHIFT
) |
1172 (OMAP3430_VOLTSETUP_TIME1
<< OMAP3430_SETUP_TIME1_SHIFT
),
1173 OMAP3430_GR_MOD
, OMAP3_PRM_VOLTSETUP1_OFFSET
);
1175 prm_write_mod_reg(OMAP3430_VOLTOFFSET_DURATION
, OMAP3430_GR_MOD
,
1176 OMAP3_PRM_VOLTOFFSET_OFFSET
);
1177 prm_write_mod_reg(OMAP3430_VOLTSETUP2_DURATION
, OMAP3430_GR_MOD
,
1178 OMAP3_PRM_VOLTSETUP2_OFFSET
);
1181 static int __init
omap3_pm_early_init(void)
1183 prm_clear_mod_reg_bits(OMAP3430_OFFMODE_POL
, OMAP3430_GR_MOD
,
1184 OMAP3_PRM_POLCTRL_OFFSET
);
1191 arch_initcall(omap3_pm_early_init
);
1192 late_initcall(omap3_pm_init
);