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 <plat/resource.h>
43 #include <asm/tlbflush.h>
46 #include "cm-regbits-34xx.h"
47 #include "prm-regbits-34xx.h"
49 #include "smartreflex.h"
54 /* Scratchpad offsets */
55 #define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
56 #define OMAP343X_TABLE_VALUE_OFFSET 0x30
57 #define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
61 u32 wakeup_timer_seconds
;
62 u32 voltage_off_while_idle
;
65 struct powerdomain
*pwrdm
;
70 struct list_head node
;
73 static LIST_HEAD(pwrst_list
);
75 static void (*_omap_sram_idle
)(u32
*addr
, int save_state
);
77 static int (*_omap_save_secure_sram
)(u32
*addr
);
79 static struct powerdomain
*mpu_pwrdm
, *neon_pwrdm
;
80 static struct powerdomain
*core_pwrdm
, *per_pwrdm
;
81 static struct powerdomain
*cam_pwrdm
;
83 static struct prm_setup_times prm_setup
= {
85 .voltsetup_time1
= 0xfff,
86 .voltsetup_time2
= 0xfff,
91 static inline void omap3_per_save_context(void)
93 omap_gpio_save_context();
96 static inline void omap3_per_restore_context(void)
98 omap_gpio_restore_context();
101 static void omap3_enable_io_chain(void)
105 if (omap_rev() >= OMAP3430_REV_ES3_1
) {
106 prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN
, WKUP_MOD
, PM_WKEN
);
107 /* Do a readback to assure write has been done */
108 prm_read_mod_reg(WKUP_MOD
, PM_WKEN
);
110 while (!(prm_read_mod_reg(WKUP_MOD
, PM_WKST
) &
111 OMAP3430_ST_IO_CHAIN
)) {
113 if (timeout
> 1000) {
114 printk(KERN_ERR
"Wake up daisy chain "
115 "activation failed.\n");
118 prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN
,
124 static void omap3_disable_io_chain(void)
126 if (omap_rev() >= OMAP3430_REV_ES3_1
)
127 prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN
, WKUP_MOD
, PM_WKEN
);
130 static void omap3_core_save_context(void)
132 u32 control_padconf_off
;
134 /* Save the padconf registers */
135 control_padconf_off
= omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF
);
136 control_padconf_off
|= START_PADCONF_SAVE
;
137 omap_ctrl_writel(control_padconf_off
, OMAP343X_CONTROL_PADCONF_OFF
);
138 /* wait for the save to complete */
139 while (!omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS
)
142 /* Save the Interrupt controller context */
143 omap_intc_save_context();
144 /* Save the GPMC context */
145 omap3_gpmc_save_context();
146 /* Save the system control module context, padconf already save above*/
147 omap3_control_save_context();
148 omap_dma_global_context_save();
151 static void omap3_core_restore_context(void)
153 /* Restore the control module context, padconf restored by h/w */
154 omap3_control_restore_context();
155 /* Restore the GPMC context */
156 omap3_gpmc_restore_context();
157 /* Restore the interrupt controller context */
158 omap_intc_restore_context();
159 omap_dma_global_context_restore();
163 * FIXME: This function should be called before entering off-mode after
164 * OMAP3 secure services have been accessed. Currently it is only called
165 * once during boot sequence, but this works as we are not using secure
168 static void omap3_save_secure_ram_context(u32 target_mpu_state
)
172 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
174 * MPU next state must be set to POWER_ON temporarily,
175 * otherwise the WFI executed inside the ROM code
176 * will hang the system.
178 pwrdm_set_next_pwrst(mpu_pwrdm
, PWRDM_POWER_ON
);
179 ret
= _omap_save_secure_sram((u32
*)
180 __pa(omap3_secure_ram_storage
));
181 pwrdm_set_next_pwrst(mpu_pwrdm
, target_mpu_state
);
182 /* Following is for error tracking, it should not happen */
184 printk(KERN_ERR
"save_secure_sram() returns %08x\n",
193 * PRCM Interrupt Handler Helper Function
195 * The purpose of this function is to clear any wake-up events latched
196 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
197 * may occur whilst attempting to clear a PM_WKST_x register and thus
198 * set another bit in this register. A while loop is used to ensure
199 * that any peripheral wake-up events occurring while attempting to
200 * clear the PM_WKST_x are detected and cleared.
202 static int prcm_clear_mod_irqs(s16 module
, u8 regs
)
204 u32 wkst
, fclk
, iclk
, clken
;
205 u16 wkst_off
= (regs
== 3) ? OMAP3430ES2_PM_WKST3
: PM_WKST1
;
206 u16 fclk_off
= (regs
== 3) ? OMAP3430ES2_CM_FCLKEN3
: CM_FCLKEN1
;
207 u16 iclk_off
= (regs
== 3) ? CM_ICLKEN3
: CM_ICLKEN1
;
208 u16 grpsel_off
= (regs
== 3) ?
209 OMAP3430ES2_PM_MPUGRPSEL3
: OMAP3430_PM_MPUGRPSEL
;
212 wkst
= prm_read_mod_reg(module
, wkst_off
);
213 wkst
&= prm_read_mod_reg(module
, grpsel_off
);
215 iclk
= cm_read_mod_reg(module
, iclk_off
);
216 fclk
= cm_read_mod_reg(module
, fclk_off
);
219 cm_set_mod_reg_bits(clken
, module
, iclk_off
);
221 * For USBHOST, we don't know whether HOST1 or
222 * HOST2 woke us up, so enable both f-clocks
224 if (module
== OMAP3430ES2_USBHOST_MOD
)
225 clken
|= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT
;
226 cm_set_mod_reg_bits(clken
, module
, fclk_off
);
227 prm_write_mod_reg(wkst
, module
, wkst_off
);
228 wkst
= prm_read_mod_reg(module
, wkst_off
);
231 cm_write_mod_reg(iclk
, module
, iclk_off
);
232 cm_write_mod_reg(fclk
, module
, fclk_off
);
238 static int _prcm_int_handle_wakeup(void)
242 c
= prcm_clear_mod_irqs(WKUP_MOD
, 1);
243 c
+= prcm_clear_mod_irqs(CORE_MOD
, 1);
244 c
+= prcm_clear_mod_irqs(OMAP3430_PER_MOD
, 1);
245 if (omap_rev() > OMAP3430_REV_ES1_0
) {
246 c
+= prcm_clear_mod_irqs(CORE_MOD
, 3);
247 c
+= prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD
, 1);
254 * PRCM Interrupt Handler
256 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
257 * interrupts from the PRCM for the MPU. These bits must be cleared in
258 * order to clear the PRCM interrupt. The PRCM interrupt handler is
259 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
260 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
261 * register indicates that a wake-up event is pending for the MPU and
262 * this bit can only be cleared if the all the wake-up events latched
263 * in the various PM_WKST_x registers have been cleared. The interrupt
264 * handler is implemented using a do-while loop so that if a wake-up
265 * event occurred during the processing of the prcm interrupt handler
266 * (setting a bit in the corresponding PM_WKST_x register and thus
267 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
268 * this would be handled.
270 static irqreturn_t
prcm_interrupt_handler (int irq
, void *dev_id
)
276 irqstatus_mpu
= prm_read_mod_reg(OCP_MOD
,
277 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
279 if (irqstatus_mpu
& (OMAP3430_WKUP_ST
| OMAP3430_IO_ST
)) {
280 c
= _prcm_int_handle_wakeup();
283 * Is the MPU PRCM interrupt handler racing with the
284 * IVA2 PRCM interrupt handler ?
286 WARN(c
== 0, "prcm: WARNING: PRCM indicated MPU wakeup "
287 "but no wakeup sources are marked\n");
289 /* XXX we need to expand our PRCM interrupt handler */
290 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
291 "no code to handle it (%08x)\n", irqstatus_mpu
);
294 prm_write_mod_reg(irqstatus_mpu
, OCP_MOD
,
295 OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
297 } while (prm_read_mod_reg(OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
));
302 static void restore_control_register(u32 val
)
304 __asm__
__volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val
));
307 /* Function to restore the table entry that was modified for enabling MMU */
308 static void restore_table_entry(void)
310 u32
*scratchpad_address
;
311 u32 previous_value
, control_reg_value
;
314 scratchpad_address
= OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD
);
316 /* Get address of entry that was modified */
317 address
= (u32
*)__raw_readl(scratchpad_address
+
318 OMAP343X_TABLE_ADDRESS_OFFSET
);
319 /* Get the previous value which needs to be restored */
320 previous_value
= __raw_readl(scratchpad_address
+
321 OMAP343X_TABLE_VALUE_OFFSET
);
322 address
= __va(address
);
323 *address
= previous_value
;
325 control_reg_value
= __raw_readl(scratchpad_address
326 + OMAP343X_CONTROL_REG_VALUE_OFFSET
);
327 /* This will enable caches and prediction */
328 restore_control_register(control_reg_value
);
331 void omap_sram_idle(void)
333 /* Variable to tell what needs to be saved and restored
334 * in omap_sram_idle*/
335 /* save_state = 0 => Nothing to save and restored */
336 /* save_state = 1 => Only L1 and logic lost */
337 /* save_state = 2 => Only L2 lost */
338 /* save_state = 3 => L1, L2 and logic lost */
340 int mpu_next_state
= PWRDM_POWER_ON
;
341 int per_next_state
= PWRDM_POWER_ON
;
342 int core_next_state
= PWRDM_POWER_ON
;
343 int core_prev_state
, per_prev_state
;
345 int per_state_modified
= 0;
347 if (!_omap_sram_idle
)
350 pwrdm_clear_all_prev_pwrst(mpu_pwrdm
);
351 pwrdm_clear_all_prev_pwrst(neon_pwrdm
);
352 pwrdm_clear_all_prev_pwrst(core_pwrdm
);
353 pwrdm_clear_all_prev_pwrst(per_pwrdm
);
355 mpu_next_state
= pwrdm_read_next_pwrst(mpu_pwrdm
);
356 switch (mpu_next_state
) {
358 case PWRDM_POWER_RET
:
359 /* No need to save context */
362 case PWRDM_POWER_OFF
:
367 printk(KERN_ERR
"Invalid mpu state in sram_idle\n");
371 /* Disable smartreflex before entering WFI */
372 disable_smartreflex(SR1
);
373 disable_smartreflex(SR2
);
375 pwrdm_pre_transition();
378 if (pwrdm_read_pwrst(neon_pwrdm
) == PWRDM_POWER_ON
)
379 pwrdm_set_next_pwrst(neon_pwrdm
, mpu_next_state
);
382 per_next_state
= pwrdm_read_next_pwrst(per_pwrdm
);
383 core_next_state
= pwrdm_read_next_pwrst(core_pwrdm
);
384 if (per_next_state
< PWRDM_POWER_ON
) {
385 omap_uart_prepare_idle(2);
386 omap2_gpio_prepare_for_idle(per_next_state
);
387 if (per_next_state
== PWRDM_POWER_OFF
) {
388 if (core_next_state
== PWRDM_POWER_ON
) {
389 per_next_state
= PWRDM_POWER_RET
;
390 pwrdm_set_next_pwrst(per_pwrdm
, per_next_state
);
391 per_state_modified
= 1;
393 omap3_per_save_context();
397 if (pwrdm_read_pwrst(cam_pwrdm
) == PWRDM_POWER_ON
)
398 omap2_clkdm_deny_idle(mpu_pwrdm
->pwrdm_clkdms
[0]);
401 if (core_next_state
< PWRDM_POWER_ON
) {
402 omap_uart_prepare_idle(0);
403 omap_uart_prepare_idle(1);
404 if (core_next_state
== PWRDM_POWER_OFF
) {
405 prm_set_mod_reg_bits(OMAP3430_AUTO_OFF
,
407 OMAP3_PRM_VOLTCTRL_OFFSET
);
408 omap3_core_save_context();
409 omap3_prcm_save_context();
411 /* Enable IO-PAD and IO-CHAIN wakeups */
412 prm_set_mod_reg_bits(OMAP3430_EN_IO
, WKUP_MOD
, PM_WKEN
);
413 omap3_enable_io_chain();
417 * On EMU/HS devices ROM code restores a SRDC value
418 * from scratchpad which has automatic self refresh on timeout
419 * of AUTO_CNT = 1 enabled. This takes care of errata 1.142.
420 * Hence store/restore the SDRC_POWER register here.
422 if (omap_rev() >= OMAP3430_REV_ES3_0
&&
423 omap_type() != OMAP2_DEVICE_TYPE_GP
&&
424 core_next_state
== PWRDM_POWER_OFF
)
425 sdrc_pwr
= sdrc_read_reg(SDRC_POWER
);
428 * omap3_arm_context is the location where ARM registers
429 * get saved. The restore path then reads from this
430 * location and restores them back.
432 _omap_sram_idle(omap3_arm_context
, save_state
);
435 /* Restore normal SDRC POWER settings */
436 if (omap_rev() >= OMAP3430_REV_ES3_0
&&
437 omap_type() != OMAP2_DEVICE_TYPE_GP
&&
438 core_next_state
== PWRDM_POWER_OFF
)
439 sdrc_write_reg(sdrc_pwr
, SDRC_POWER
);
441 /* Restore table entry modified during MMU restoration */
442 if (pwrdm_read_prev_pwrst(mpu_pwrdm
) == PWRDM_POWER_OFF
)
443 restore_table_entry();
446 if (core_next_state
< PWRDM_POWER_ON
) {
447 core_prev_state
= pwrdm_read_prev_pwrst(core_pwrdm
);
448 if (core_prev_state
== PWRDM_POWER_OFF
) {
449 omap3_core_restore_context();
450 omap3_prcm_restore_context();
451 omap3_sram_restore_context();
452 omap2_sms_restore_context();
454 omap_uart_resume_idle(0);
455 omap_uart_resume_idle(1);
456 if (core_next_state
== PWRDM_POWER_OFF
)
457 prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF
,
459 OMAP3_PRM_VOLTCTRL_OFFSET
);
463 if (per_next_state
< PWRDM_POWER_ON
) {
464 per_prev_state
= pwrdm_read_prev_pwrst(per_pwrdm
);
465 if (per_prev_state
== PWRDM_POWER_OFF
) {
466 omap3_per_restore_context();
467 omap3_gpio_restore_pad_context(0);
468 } else if (per_next_state
== PWRDM_POWER_OFF
)
469 omap3_gpio_restore_pad_context(1);
470 omap2_gpio_resume_after_idle();
471 omap_uart_resume_idle(2);
472 if (per_state_modified
)
473 pwrdm_set_next_pwrst(per_pwrdm
, PWRDM_POWER_OFF
);
476 /* Disable IO-PAD and IO-CHAIN wakeup */
477 if (core_next_state
< PWRDM_POWER_ON
) {
478 prm_clear_mod_reg_bits(OMAP3430_EN_IO
, WKUP_MOD
, PM_WKEN
);
479 omap3_disable_io_chain();
482 /* Enable smartreflex after WFI */
483 enable_smartreflex(SR1
);
484 enable_smartreflex(SR2
);
486 pwrdm_post_transition();
488 omap2_clkdm_allow_idle(mpu_pwrdm
->pwrdm_clkdms
[0]);
491 int omap3_can_sleep(void)
493 if (!sleep_while_idle
)
495 if (!omap_uart_can_sleep())
500 /* This sets pwrdm state (other than mpu & core. Currently only ON &
501 * RET are supported. Function is assuming that clkdm doesn't have
502 * hw_sup mode enabled. */
503 int set_pwrdm_state(struct powerdomain
*pwrdm
, u32 state
)
506 int sleep_switch
= 0;
509 if (pwrdm
== NULL
|| IS_ERR(pwrdm
))
512 while (!(pwrdm
->pwrsts
& (1 << state
))) {
513 if (state
== PWRDM_POWER_OFF
)
518 cur_state
= pwrdm_read_next_pwrst(pwrdm
);
519 if (cur_state
== state
)
522 if (pwrdm_read_pwrst(pwrdm
) < PWRDM_POWER_ON
) {
523 omap2_clkdm_wakeup(pwrdm
->pwrdm_clkdms
[0]);
525 pwrdm_wait_transition(pwrdm
);
528 ret
= pwrdm_set_next_pwrst(pwrdm
, state
);
530 printk(KERN_ERR
"Unable to set state of powerdomain: %s\n",
536 omap2_clkdm_allow_idle(pwrdm
->pwrdm_clkdms
[0]);
537 pwrdm_wait_transition(pwrdm
);
538 pwrdm_state_switch(pwrdm
);
545 static void omap3_pm_idle(void)
550 if (!omap3_can_sleep())
553 if (omap_irq_pending() || need_resched())
563 #ifdef CONFIG_SUSPEND
564 static suspend_state_t suspend_state
;
566 static void omap2_pm_wakeup_on_timer(u32 seconds
)
568 u32 tick_rate
, cycles
;
573 tick_rate
= clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup
));
574 cycles
= tick_rate
* seconds
;
575 omap_dm_timer_stop(gptimer_wakeup
);
576 omap_dm_timer_set_load_start(gptimer_wakeup
, 0, 0xffffffff - cycles
);
578 pr_info("PM: Resume timer in %d secs (%d ticks at %d ticks/sec.)\n",
579 seconds
, cycles
, tick_rate
);
582 static int omap3_pm_prepare(void)
588 static int omap3_pm_suspend(void)
590 struct power_state
*pwrst
;
593 if (wakeup_timer_seconds
)
594 omap2_pm_wakeup_on_timer(wakeup_timer_seconds
);
596 /* Read current next_pwrsts */
597 list_for_each_entry(pwrst
, &pwrst_list
, node
)
598 pwrst
->saved_state
= pwrdm_read_next_pwrst(pwrst
->pwrdm
);
599 /* Set ones wanted by suspend */
600 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
601 if (set_pwrdm_state(pwrst
->pwrdm
, pwrst
->next_state
))
603 if (pwrdm_clear_all_prev_pwrst(pwrst
->pwrdm
))
607 omap_uart_prepare_suspend();
611 /* Restore next_pwrsts */
612 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
613 state
= pwrdm_read_prev_pwrst(pwrst
->pwrdm
);
614 if (state
> pwrst
->next_state
) {
615 printk(KERN_INFO
"Powerdomain (%s) didn't enter "
617 pwrst
->pwrdm
->name
, pwrst
->next_state
);
620 set_pwrdm_state(pwrst
->pwrdm
, pwrst
->saved_state
);
623 printk(KERN_ERR
"Could not enter target state in pm_suspend\n");
625 printk(KERN_INFO
"Successfully put all powerdomains "
626 "to target state\n");
631 static int omap3_pm_enter(suspend_state_t unused
)
635 switch (suspend_state
) {
636 case PM_SUSPEND_STANDBY
:
638 ret
= omap3_pm_suspend();
647 static void omap3_pm_finish(void)
652 /* Hooks to enable / disable UART interrupts during suspend */
653 static int omap3_pm_begin(suspend_state_t state
)
655 suspend_state
= state
;
656 omap_uart_enable_irqs(0);
660 static void omap3_pm_end(void)
662 suspend_state
= PM_SUSPEND_ON
;
663 omap_uart_enable_irqs(1);
667 static struct platform_suspend_ops omap_pm_ops
= {
668 .begin
= omap3_pm_begin
,
670 .prepare
= omap3_pm_prepare
,
671 .enter
= omap3_pm_enter
,
672 .finish
= omap3_pm_finish
,
673 .valid
= suspend_valid_only_mem
,
675 #endif /* CONFIG_SUSPEND */
679 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
682 * In cases where IVA2 is activated by bootcode, it may prevent
683 * full-chip retention or off-mode because it is not idle. This
684 * function forces the IVA2 into idle state so it can go
685 * into retention/off and thus allow full-chip retention/off.
688 static void __init
omap3_iva_idle(void)
690 /* ensure IVA2 clock is disabled */
691 cm_write_mod_reg(0, OMAP3430_IVA2_MOD
, CM_FCLKEN
);
693 /* if no clock activity, nothing else to do */
694 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD
, OMAP3430_CM_CLKSTST
) &
695 OMAP3430_CLKACTIVITY_IVA2_MASK
))
699 prm_write_mod_reg(OMAP3430_RST1_IVA2
|
702 OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
704 /* Enable IVA2 clock */
705 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2
,
706 OMAP3430_IVA2_MOD
, CM_FCLKEN
);
708 /* Set IVA2 boot mode to 'idle' */
709 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE
,
710 OMAP343X_CONTROL_IVA2_BOOTMOD
);
713 prm_write_mod_reg(0, OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
715 /* Disable IVA2 clock */
716 cm_write_mod_reg(0, OMAP3430_IVA2_MOD
, CM_FCLKEN
);
719 prm_write_mod_reg(OMAP3430_RST1_IVA2
|
722 OMAP3430_IVA2_MOD
, RM_RSTCTRL
);
725 static void __init
omap3_d2d_idle(void)
729 /* In a stand alone OMAP3430 where there is not a stacked
730 * modem for the D2D Idle Ack and D2D MStandby must be pulled
731 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
732 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
733 mask
= (1 << 4) | (1 << 3); /* pull-up, enabled */
734 padconf
= omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY
);
736 omap_ctrl_writew(padconf
, OMAP3_PADCONF_SAD2D_MSTANDBY
);
738 padconf
= omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK
);
740 omap_ctrl_writew(padconf
, OMAP3_PADCONF_SAD2D_IDLEACK
);
743 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON
|
744 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST
,
745 CORE_MOD
, RM_RSTCTRL
);
746 prm_write_mod_reg(0, CORE_MOD
, RM_RSTCTRL
);
749 static void __init
prcm_setup_regs(void)
751 /* XXX Reset all wkdeps. This should be done when initializing
753 prm_write_mod_reg(0, OMAP3430_IVA2_MOD
, PM_WKDEP
);
754 prm_write_mod_reg(0, MPU_MOD
, PM_WKDEP
);
755 prm_write_mod_reg(0, OMAP3430_DSS_MOD
, PM_WKDEP
);
756 prm_write_mod_reg(0, OMAP3430_NEON_MOD
, PM_WKDEP
);
757 prm_write_mod_reg(0, OMAP3430_CAM_MOD
, PM_WKDEP
);
758 prm_write_mod_reg(0, OMAP3430_PER_MOD
, PM_WKDEP
);
759 if (omap_rev() > OMAP3430_REV_ES1_0
) {
760 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD
, PM_WKDEP
);
761 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD
, PM_WKDEP
);
763 prm_write_mod_reg(0, GFX_MOD
, PM_WKDEP
);
766 * Enable interface clock autoidle for all modules.
767 * Note that in the long run this should be done by clockfw
770 OMAP3430_AUTO_MODEM
|
771 OMAP3430ES2_AUTO_MMC3
|
772 OMAP3430ES2_AUTO_ICR
|
774 OMAP3430_AUTO_SHA12
|
778 OMAP3430_AUTO_MSPRO
|
780 OMAP3430_AUTO_MCSPI4
|
781 OMAP3430_AUTO_MCSPI3
|
782 OMAP3430_AUTO_MCSPI2
|
783 OMAP3430_AUTO_MCSPI1
|
787 OMAP3430_AUTO_UART2
|
788 OMAP3430_AUTO_UART1
|
789 OMAP3430_AUTO_GPT11
|
790 OMAP3430_AUTO_GPT10
|
791 OMAP3430_AUTO_MCBSP5
|
792 OMAP3430_AUTO_MCBSP1
|
793 OMAP3430ES1_AUTO_FAC
| /* This is es1 only */
794 OMAP3430_AUTO_MAILBOXES
|
795 OMAP3430_AUTO_OMAPCTRL
|
796 OMAP3430ES1_AUTO_FSHOSTUSB
|
797 OMAP3430_AUTO_HSOTGUSB
|
798 OMAP3430_AUTO_SAD2D
|
800 CORE_MOD
, CM_AUTOIDLE1
);
806 OMAP3430_AUTO_SHA11
|
808 CORE_MOD
, CM_AUTOIDLE2
);
810 if (omap_rev() > OMAP3430_REV_ES1_0
) {
812 OMAP3430_AUTO_MAD2D
|
813 OMAP3430ES2_AUTO_USBTLL
,
814 CORE_MOD
, CM_AUTOIDLE3
);
820 OMAP3430_AUTO_GPIO1
|
821 OMAP3430_AUTO_32KSYNC
|
822 OMAP3430_AUTO_GPT12
|
824 WKUP_MOD
, CM_AUTOIDLE
);
837 OMAP3430_AUTO_GPIO6
|
838 OMAP3430_AUTO_GPIO5
|
839 OMAP3430_AUTO_GPIO4
|
840 OMAP3430_AUTO_GPIO3
|
841 OMAP3430_AUTO_GPIO2
|
843 OMAP3430_AUTO_UART3
|
852 OMAP3430_AUTO_MCBSP4
|
853 OMAP3430_AUTO_MCBSP3
|
854 OMAP3430_AUTO_MCBSP2
,
858 if (omap_rev() > OMAP3430_REV_ES1_0
) {
860 OMAP3430ES2_AUTO_USBHOST
,
861 OMAP3430ES2_USBHOST_MOD
,
866 * Set all plls to autoidle. This is needed until autoidle is
869 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT
,
870 OMAP3430_IVA2_MOD
, CM_AUTOIDLE2
);
871 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT
,
874 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT
) |
875 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT
),
878 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT
,
883 * Enable control of expternal oscillator through
884 * sys_clkreq. In the long run clock framework should
887 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK
,
888 1 << OMAP_AUTOEXTCLKMODE_SHIFT
,
890 OMAP3_PRM_CLKSRC_CTRL_OFFSET
);
892 /* setup wakup source */
893 prm_write_mod_reg(OMAP3430_EN_IO
| OMAP3430_EN_GPIO1
|
894 OMAP3430_EN_GPT1
| OMAP3430_EN_GPT12
,
896 /* No need to write EN_IO, that is always enabled */
897 prm_write_mod_reg(OMAP3430_EN_GPIO1
| OMAP3430_EN_GPT1
|
899 WKUP_MOD
, OMAP3430_PM_MPUGRPSEL
);
900 /* For some reason IO doesn't generate wakeup event even if
901 * it is selected to mpu wakeup goup */
902 prm_write_mod_reg(OMAP3430_IO_EN
| OMAP3430_WKUP_EN
,
903 OCP_MOD
, OMAP3_PRM_IRQENABLE_MPU_OFFSET
);
905 /* Enable wakeups in PER */
906 prm_write_mod_reg(OMAP3430_EN_GPIO2
| OMAP3430_EN_GPIO3
|
907 OMAP3430_EN_GPIO4
| OMAP3430_EN_GPIO5
|
908 OMAP3430_EN_GPIO6
| OMAP3430_EN_UART3
,
909 OMAP3430_PER_MOD
, PM_WKEN
);
910 /* and allow them to wake up MPU */
911 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2
| OMAP3430_EN_GPIO3
|
912 OMAP3430_GRPSEL_GPIO4
| OMAP3430_EN_GPIO5
|
913 OMAP3430_GRPSEL_GPIO6
| OMAP3430_EN_UART3
,
914 OMAP3430_PER_MOD
, OMAP3430_PM_MPUGRPSEL
);
916 /* Don't attach IVA interrupts */
917 prm_write_mod_reg(0, WKUP_MOD
, OMAP3430_PM_IVAGRPSEL
);
918 prm_write_mod_reg(0, CORE_MOD
, OMAP3430_PM_IVAGRPSEL1
);
919 prm_write_mod_reg(0, CORE_MOD
, OMAP3430ES2_PM_IVAGRPSEL3
);
920 prm_write_mod_reg(0, OMAP3430_PER_MOD
, OMAP3430_PM_IVAGRPSEL
);
922 /* Clear any pending 'reset' flags */
923 prm_write_mod_reg(0xffffffff, MPU_MOD
, RM_RSTST
);
924 prm_write_mod_reg(0xffffffff, CORE_MOD
, RM_RSTST
);
925 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD
, RM_RSTST
);
926 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD
, RM_RSTST
);
927 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD
, RM_RSTST
);
928 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD
, RM_RSTST
);
929 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD
, RM_RSTST
);
931 /* Clear any pending PRCM interrupts */
932 prm_write_mod_reg(0, OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
934 /* Don't attach IVA interrupts */
935 prm_write_mod_reg(0, WKUP_MOD
, OMAP3430_PM_IVAGRPSEL
);
936 prm_write_mod_reg(0, CORE_MOD
, OMAP3430_PM_IVAGRPSEL1
);
937 prm_write_mod_reg(0, CORE_MOD
, OMAP3430ES2_PM_IVAGRPSEL3
);
938 prm_write_mod_reg(0, OMAP3430_PER_MOD
, OMAP3430_PM_IVAGRPSEL
);
940 /* Clear any pending 'reset' flags */
941 prm_write_mod_reg(0xffffffff, MPU_MOD
, RM_RSTST
);
942 prm_write_mod_reg(0xffffffff, CORE_MOD
, RM_RSTST
);
943 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD
, RM_RSTST
);
944 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD
, RM_RSTST
);
945 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD
, RM_RSTST
);
946 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD
, RM_RSTST
);
947 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD
, RM_RSTST
);
949 /* Clear any pending PRCM interrupts */
950 prm_write_mod_reg(0, OCP_MOD
, OMAP3_PRM_IRQSTATUS_MPU_OFFSET
);
956 void omap3_pm_off_mode_enable(int enable
)
958 struct power_state
*pwrst
;
962 state
= PWRDM_POWER_OFF
;
964 state
= PWRDM_POWER_RET
;
966 #ifdef CONFIG_OMAP_PM_SRF
967 resource_lock_opp(VDD1_OPP
);
968 resource_lock_opp(VDD2_OPP
);
969 if (resource_refresh())
970 printk(KERN_ERR
"Error: could not refresh resources\n");
971 resource_unlock_opp(VDD1_OPP
);
972 resource_unlock_opp(VDD2_OPP
);
974 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
975 pwrst
->next_state
= state
;
976 set_pwrdm_state(pwrst
->pwrdm
, state
);
980 int omap3_pm_get_suspend_state(struct powerdomain
*pwrdm
)
982 struct power_state
*pwrst
;
984 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
985 if (pwrst
->pwrdm
== pwrdm
)
986 return pwrst
->next_state
;
991 int omap3_pm_set_suspend_state(struct powerdomain
*pwrdm
, int state
)
993 struct power_state
*pwrst
;
995 list_for_each_entry(pwrst
, &pwrst_list
, node
) {
996 if (pwrst
->pwrdm
== pwrdm
) {
997 pwrst
->next_state
= state
;
1004 void omap3_set_prm_setup_times(struct prm_setup_times
*setup_times
)
1006 prm_setup
.clksetup
= setup_times
->clksetup
;
1007 prm_setup
.voltsetup_time1
= setup_times
->voltsetup_time1
;
1008 prm_setup
.voltsetup_time2
= setup_times
->voltsetup_time2
;
1009 prm_setup
.voltoffset
= setup_times
->voltoffset
;
1010 prm_setup
.voltsetup2
= setup_times
->voltsetup2
;
1013 static int __init
pwrdms_setup(struct powerdomain
*pwrdm
, void *unused
)
1015 struct power_state
*pwrst
;
1020 pwrst
= kmalloc(sizeof(struct power_state
), GFP_ATOMIC
);
1023 pwrst
->pwrdm
= pwrdm
;
1024 pwrst
->next_state
= PWRDM_POWER_RET
;
1025 list_add(&pwrst
->node
, &pwrst_list
);
1027 if (pwrdm_has_hdwr_sar(pwrdm
))
1028 pwrdm_enable_hdwr_sar(pwrdm
);
1030 return set_pwrdm_state(pwrst
->pwrdm
, pwrst
->next_state
);
1034 * Enable hw supervised mode for all clockdomains if it's
1035 * supported. Initiate sleep transition for other clockdomains, if
1038 static int __init
clkdms_setup(struct clockdomain
*clkdm
, void *unused
)
1040 if (clkdm
->flags
& CLKDM_CAN_ENABLE_AUTO
)
1041 omap2_clkdm_allow_idle(clkdm
);
1042 else if (clkdm
->flags
& CLKDM_CAN_FORCE_SLEEP
&&
1043 atomic_read(&clkdm
->usecount
) == 0)
1044 omap2_clkdm_sleep(clkdm
);
1048 void omap_push_sram_idle(void)
1050 _omap_sram_idle
= omap_sram_push(omap34xx_cpu_suspend
,
1051 omap34xx_cpu_suspend_sz
);
1052 if (omap_type() != OMAP2_DEVICE_TYPE_GP
)
1053 _omap_save_secure_sram
= omap_sram_push(save_secure_ram_context
,
1054 save_secure_ram_context_sz
);
1057 static int __init
omap3_pm_init(void)
1059 struct power_state
*pwrst
, *tmp
;
1062 if (!cpu_is_omap34xx())
1065 printk(KERN_ERR
"Power Management for TI OMAP3.\n");
1067 /* XXX prcm_setup_regs needs to be before enabling hw
1068 * supervised mode for powerdomains */
1071 ret
= request_irq(INT_34XX_PRCM_MPU_IRQ
,
1072 (irq_handler_t
)prcm_interrupt_handler
,
1073 IRQF_DISABLED
, "prcm", NULL
);
1075 printk(KERN_ERR
"request_irq failed to register for 0x%x\n",
1076 INT_34XX_PRCM_MPU_IRQ
);
1080 ret
= pwrdm_for_each(pwrdms_setup
, NULL
);
1082 printk(KERN_ERR
"Failed to setup powerdomains\n");
1086 (void) clkdm_for_each(clkdms_setup
, NULL
);
1088 mpu_pwrdm
= pwrdm_lookup("mpu_pwrdm");
1089 if (mpu_pwrdm
== NULL
) {
1090 printk(KERN_ERR
"Failed to get mpu_pwrdm\n");
1094 neon_pwrdm
= pwrdm_lookup("neon_pwrdm");
1095 per_pwrdm
= pwrdm_lookup("per_pwrdm");
1096 core_pwrdm
= pwrdm_lookup("core_pwrdm");
1097 cam_pwrdm
= pwrdm_lookup("cam_pwrdm");
1099 omap_push_sram_idle();
1100 #ifdef CONFIG_SUSPEND
1101 suspend_set_ops(&omap_pm_ops
);
1102 #endif /* CONFIG_SUSPEND */
1104 pm_idle
= omap3_pm_idle
;
1107 pwrdm_add_wkdep(neon_pwrdm
, mpu_pwrdm
);
1109 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
1110 * IO-pad wakeup. Otherwise it will unnecessarily waste power
1111 * waking up PER with every CORE wakeup - see
1112 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
1114 pwrdm_add_wkdep(per_pwrdm
, core_pwrdm
);
1116 if (omap_type() != OMAP2_DEVICE_TYPE_GP
) {
1117 omap3_secure_ram_storage
=
1118 kmalloc(0x803F, GFP_KERNEL
);
1119 if (!omap3_secure_ram_storage
)
1120 printk(KERN_ERR
"Memory allocation failed when"
1121 "allocating for secure sram context\n");
1123 local_irq_disable();
1124 local_fiq_disable();
1126 omap_dma_global_context_save();
1127 omap3_save_secure_ram_context(PWRDM_POWER_ON
);
1128 omap_dma_global_context_restore();
1134 omap3_save_scratchpad_contents();
1138 free_irq(INT_34XX_PRCM_MPU_IRQ
, NULL
);
1139 list_for_each_entry_safe(pwrst
, tmp
, &pwrst_list
, node
) {
1140 list_del(&pwrst
->node
);
1146 /* PRM_VC_CMD_VAL_0 specific bits */
1147 #define OMAP3430_VC_CMD_VAL0_ON (0x3 << 4)
1148 #define OMAP3430_VC_CMD_VAL0_ONLP (0x3 << 3)
1149 #define OMAP3430_VC_CMD_VAL0_RET (0x3 << 3)
1150 #define OMAP3430_VC_CMD_VAL0_OFF (0x3 << 3)
1152 /* PRM_VC_CMD_VAL_1 specific bits */
1153 #define OMAP3430_VC_CMD_VAL1_ON (0xB << 2)
1154 #define OMAP3430_VC_CMD_VAL1_ONLP (0x3 << 3)
1155 #define OMAP3430_VC_CMD_VAL1_RET (0x3 << 3)
1156 #define OMAP3430_VC_CMD_VAL1_OFF (0x3 << 3)
1158 /* Constants to define setup durations */
1159 #define OMAP3430_CLKSETUP_DURATION 0xff
1160 #define OMAP3430_VOLTSETUP_TIME2 0xfff
1161 #define OMAP3430_VOLTSETUP_TIME1 0xfff
1162 #define OMAP3430_VOLTOFFSET_DURATION 0xff
1163 #define OMAP3430_VOLTSETUP2_DURATION 0xff
1165 static void __init
configure_vc(void)
1168 prm_write_mod_reg((R_SRI2C_SLAVE_ADDR
<< OMAP3430_SMPS_SA1_SHIFT
) |
1169 (R_SRI2C_SLAVE_ADDR
<< OMAP3430_SMPS_SA0_SHIFT
),
1170 OMAP3430_GR_MOD
, OMAP3_PRM_VC_SMPS_SA_OFFSET
);
1171 prm_write_mod_reg((R_VDD2_SR_CONTROL
<< OMAP3430_VOLRA1_SHIFT
) |
1172 (R_VDD1_SR_CONTROL
<< OMAP3430_VOLRA0_SHIFT
),
1173 OMAP3430_GR_MOD
, OMAP3_PRM_VC_SMPS_VOL_RA_OFFSET
);
1176 (OMAP3430_VC_CMD_VAL0_ON
<< OMAP3430_VC_CMD_ON_SHIFT
) |
1177 (OMAP3430_VC_CMD_VAL0_ONLP
<< OMAP3430_VC_CMD_ONLP_SHIFT
) |
1178 (OMAP3430_VC_CMD_VAL0_RET
<< OMAP3430_VC_CMD_RET_SHIFT
) |
1179 (OMAP3430_VC_CMD_VAL0_OFF
<< OMAP3430_VC_CMD_OFF_SHIFT
),
1180 OMAP3430_GR_MOD
, OMAP3_PRM_VC_CMD_VAL_0_OFFSET
);
1183 (OMAP3430_VC_CMD_VAL1_ON
<< OMAP3430_VC_CMD_ON_SHIFT
) |
1184 (OMAP3430_VC_CMD_VAL1_ONLP
<< OMAP3430_VC_CMD_ONLP_SHIFT
) |
1185 (OMAP3430_VC_CMD_VAL1_RET
<< OMAP3430_VC_CMD_RET_SHIFT
) |
1186 (OMAP3430_VC_CMD_VAL1_OFF
<< OMAP3430_VC_CMD_OFF_SHIFT
),
1187 OMAP3430_GR_MOD
, OMAP3_PRM_VC_CMD_VAL_1_OFFSET
);
1189 prm_write_mod_reg(OMAP3430_CMD1
| OMAP3430_RAV1
, OMAP3430_GR_MOD
,
1190 OMAP3_PRM_VC_CH_CONF_OFFSET
);
1192 prm_write_mod_reg(OMAP3430_MCODE_SHIFT
| OMAP3430_HSEN
| OMAP3430_SREN
,
1194 OMAP3_PRM_VC_I2C_CFG_OFFSET
);
1196 /* Setup value for voltctrl */
1197 prm_write_mod_reg(OMAP3430_AUTO_RET
,
1198 OMAP3430_GR_MOD
, OMAP3_PRM_VOLTCTRL_OFFSET
);
1200 /* Write setup times */
1201 prm_write_mod_reg(prm_setup
.clksetup
, OMAP3430_GR_MOD
,
1202 OMAP3_PRM_CLKSETUP_OFFSET
);
1203 prm_write_mod_reg((prm_setup
.voltsetup_time2
<<
1204 OMAP3430_SETUP_TIME2_SHIFT
) |
1205 (prm_setup
.voltsetup_time1
<<
1206 OMAP3430_SETUP_TIME1_SHIFT
),
1207 OMAP3430_GR_MOD
, OMAP3_PRM_VOLTSETUP1_OFFSET
);
1209 prm_write_mod_reg(prm_setup
.voltoffset
, OMAP3430_GR_MOD
,
1210 OMAP3_PRM_VOLTOFFSET_OFFSET
);
1211 prm_write_mod_reg(prm_setup
.voltsetup2
, OMAP3430_GR_MOD
,
1212 OMAP3_PRM_VOLTSETUP2_OFFSET
);
1215 static int __init
omap3_pm_early_init(void)
1217 prm_clear_mod_reg_bits(OMAP3430_OFFMODE_POL
, OMAP3430_GR_MOD
,
1218 OMAP3_PRM_POLCTRL_OFFSET
);
1225 arch_initcall(omap3_pm_early_init
);
1226 late_initcall(omap3_pm_init
);