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>
29 #include <plat/sram.h>
30 #include <plat/clockdomain.h>
31 #include <plat/powerdomain.h>
32 #include <plat/control.h>
33 #include <plat/serial.h>
34 #include <plat/sdrc.h>
35 #include <plat/prcm.h>
36 #include <plat/gpmc.h>
39 #include <asm/tlbflush.h>
42 #include "cm-regbits-34xx.h"
43 #include "prm-regbits-34xx.h"
49 #define SDRC_POWER_AUTOCOUNT_SHIFT 8
50 #define SDRC_POWER_AUTOCOUNT_MASK (0xffff << SDRC_POWER_AUTOCOUNT_SHIFT)
51 #define SDRC_POWER_CLKCTRL_SHIFT 4
52 #define SDRC_POWER_CLKCTRL_MASK (0x3 << SDRC_POWER_CLKCTRL_SHIFT)
53 #define SDRC_SELF_REFRESH_ON_AUTOCOUNT (0x2 << SDRC_POWER_CLKCTRL_SHIFT)
55 /* Scratchpad offsets */
56 #define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
57 #define OMAP343X_TABLE_VALUE_OFFSET 0x30
58 #define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
61 struct powerdomain *pwrdm;
66 struct list_head node;
69 static LIST_HEAD(pwrst_list);
71 static void (*_omap_sram_idle)(u32 *addr, int save_state);
73 static int (*_omap_save_secure_sram)(u32 *addr);
75 static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
76 static struct powerdomain *core_pwrdm, *per_pwrdm;
78 static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state);
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_core_save_context(void)
92 u32 control_padconf_off;
94 /* Save the padconf registers */
95 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
96 control_padconf_off |= START_PADCONF_SAVE;
97 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
98 /* wait for the save to complete */
99 while (!omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
102 /* Save the Interrupt controller context */
103 omap_intc_save_context();
104 /* Save the GPMC context */
105 omap3_gpmc_save_context();
106 /* Save the system control module context, padconf already save above*/
107 omap3_control_save_context();
108 omap_dma_global_context_save();
111 static void omap3_core_restore_context(void)
113 /* Restore the control module context, padconf restored by h/w */
114 omap3_control_restore_context();
115 /* Restore the GPMC context */
116 omap3_gpmc_restore_context();
117 /* Restore the interrupt controller context */
118 omap_intc_restore_context();
119 omap_dma_global_context_restore();
123 * FIXME: This function should be called before entering off-mode after
124 * OMAP3 secure services have been accessed. Currently it is only called
125 * once during boot sequence, but this works as we are not using secure
128 static void omap3_save_secure_ram_context(u32 target_mpu_state)
132 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
134 * MPU next state must be set to POWER_ON temporarily,
135 * otherwise the WFI executed inside the ROM code
136 * will hang the system.
138 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
139 ret = _omap_save_secure_sram((u32 *)
140 __pa(omap3_secure_ram_storage));
141 pwrdm_set_next_pwrst(mpu_pwrdm, target_mpu_state);
142 /* Following is for error tracking, it should not happen */
144 printk(KERN_ERR "save_secure_sram() returns %08x\n",
153 * PRCM Interrupt Handler Helper Function
155 * The purpose of this function is to clear any wake-up events latched
156 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
157 * may occur whilst attempting to clear a PM_WKST_x register and thus
158 * set another bit in this register. A while loop is used to ensure
159 * that any peripheral wake-up events occurring while attempting to
160 * clear the PM_WKST_x are detected and cleared.
162 static int prcm_clear_mod_irqs(s16 module, u8 regs)
164 u32 wkst, fclk, iclk, clken;
165 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
166 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
167 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
168 u16 grpsel_off = (regs == 3) ?
169 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
172 wkst = prm_read_mod_reg(module, wkst_off);
173 wkst &= prm_read_mod_reg(module, grpsel_off);
175 iclk = cm_read_mod_reg(module, iclk_off);
176 fclk = cm_read_mod_reg(module, fclk_off);
179 cm_set_mod_reg_bits(clken, module, iclk_off);
181 * For USBHOST, we don't know whether HOST1 or
182 * HOST2 woke us up, so enable both f-clocks
184 if (module == OMAP3430ES2_USBHOST_MOD)
185 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
186 cm_set_mod_reg_bits(clken, module, fclk_off);
187 prm_write_mod_reg(wkst, module, wkst_off);
188 wkst = prm_read_mod_reg(module, wkst_off);
191 cm_write_mod_reg(iclk, module, iclk_off);
192 cm_write_mod_reg(fclk, module, fclk_off);
198 static int _prcm_int_handle_wakeup(void)
202 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
203 c += prcm_clear_mod_irqs(CORE_MOD, 1);
204 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
205 if (omap_rev() > OMAP3430_REV_ES1_0) {
206 c += prcm_clear_mod_irqs(CORE_MOD, 3);
207 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
214 * PRCM Interrupt Handler
216 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
217 * interrupts from the PRCM for the MPU. These bits must be cleared in
218 * order to clear the PRCM interrupt. The PRCM interrupt handler is
219 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
220 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
221 * register indicates that a wake-up event is pending for the MPU and
222 * this bit can only be cleared if the all the wake-up events latched
223 * in the various PM_WKST_x registers have been cleared. The interrupt
224 * handler is implemented using a do-while loop so that if a wake-up
225 * event occurred during the processing of the prcm interrupt handler
226 * (setting a bit in the corresponding PM_WKST_x register and thus
227 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
228 * this would be handled.
230 static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
236 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
237 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
239 if (irqstatus_mpu & (OMAP3430_WKUP_ST | OMAP3430_IO_ST)) {
240 c = _prcm_int_handle_wakeup();
243 * Is the MPU PRCM interrupt handler racing with the
244 * IVA2 PRCM interrupt handler ?
246 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
247 "but no wakeup sources are marked\n");
249 /* XXX we need to expand our PRCM interrupt handler */
250 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
251 "no code to handle it (%08x)\n", irqstatus_mpu);
254 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
255 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
257 } while (prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET));
262 static void restore_control_register(u32 val)
264 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
267 /* Function to restore the table entry that was modified for enabling MMU */
268 static void restore_table_entry(void)
270 u32 *scratchpad_address;
271 u32 previous_value, control_reg_value;
274 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
276 /* Get address of entry that was modified */
277 address = (u32 *)__raw_readl(scratchpad_address +
278 OMAP343X_TABLE_ADDRESS_OFFSET);
279 /* Get the previous value which needs to be restored */
280 previous_value = __raw_readl(scratchpad_address +
281 OMAP343X_TABLE_VALUE_OFFSET);
282 address = __va(address);
283 *address = previous_value;
285 control_reg_value = __raw_readl(scratchpad_address
286 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
287 /* This will enable caches and prediction */
288 restore_control_register(control_reg_value);
291 static void omap_sram_idle(void)
293 /* Variable to tell what needs to be saved and restored
294 * in omap_sram_idle*/
295 /* save_state = 0 => Nothing to save and restored */
296 /* save_state = 1 => Only L1 and logic lost */
297 /* save_state = 2 => Only L2 lost */
298 /* save_state = 3 => L1, L2 and logic lost */
300 int mpu_next_state = PWRDM_POWER_ON;
301 int per_next_state = PWRDM_POWER_ON;
302 int core_next_state = PWRDM_POWER_ON;
303 int core_prev_state, per_prev_state;
306 if (!_omap_sram_idle)
309 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
310 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
311 pwrdm_clear_all_prev_pwrst(core_pwrdm);
312 pwrdm_clear_all_prev_pwrst(per_pwrdm);
314 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
315 switch (mpu_next_state) {
317 case PWRDM_POWER_RET:
318 /* No need to save context */
321 case PWRDM_POWER_OFF:
326 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
329 pwrdm_pre_transition();
332 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
333 set_pwrdm_state(neon_pwrdm, mpu_next_state);
336 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
337 if (core_next_state < PWRDM_POWER_ON) {
338 omap2_gpio_prepare_for_retention();
339 omap_uart_prepare_idle(0);
340 omap_uart_prepare_idle(1);
341 /* PER changes only with core */
342 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
343 if (per_next_state < PWRDM_POWER_ON) {
344 omap_uart_prepare_idle(2);
345 if (per_next_state == PWRDM_POWER_OFF)
346 omap3_per_save_context();
348 if (core_next_state == PWRDM_POWER_OFF) {
349 omap3_core_save_context();
350 omap3_prcm_save_context();
352 /* Enable IO-PAD wakeup */
353 prm_set_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
357 * Force SDRAM controller to self-refresh mode after timeout on
358 * autocount. This is needed on ES3.0 to avoid SDRAM controller
361 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
362 omap_type() != OMAP2_DEVICE_TYPE_GP &&
363 core_next_state == PWRDM_POWER_OFF) {
364 sdrc_pwr = sdrc_read_reg(SDRC_POWER);
365 sdrc_write_reg((sdrc_pwr &
366 ~(SDRC_POWER_AUTOCOUNT_MASK|SDRC_POWER_CLKCTRL_MASK)) |
367 (1 << SDRC_POWER_AUTOCOUNT_SHIFT) |
368 SDRC_SELF_REFRESH_ON_AUTOCOUNT, SDRC_POWER);
372 * omap3_arm_context is the location where ARM registers
373 * get saved. The restore path then reads from this
374 * location and restores them back.
376 _omap_sram_idle(omap3_arm_context, save_state);
379 /* Restore normal SDRAM settings */
380 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
381 omap_type() != OMAP2_DEVICE_TYPE_GP &&
382 core_next_state == PWRDM_POWER_OFF)
383 sdrc_write_reg(sdrc_pwr, SDRC_POWER);
385 /* Restore table entry modified during MMU restoration */
386 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
387 restore_table_entry();
389 if (core_next_state < PWRDM_POWER_ON) {
390 if (per_next_state < PWRDM_POWER_ON)
391 omap_uart_resume_idle(2);
392 omap_uart_resume_idle(1);
393 omap_uart_resume_idle(0);
395 /* Disable IO-PAD wakeup */
396 prm_clear_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
397 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
398 if (core_prev_state == PWRDM_POWER_OFF) {
399 omap3_core_restore_context();
400 omap3_prcm_restore_context();
401 omap3_sram_restore_context();
403 if (per_next_state < PWRDM_POWER_ON) {
405 pwrdm_read_prev_pwrst(per_pwrdm);
406 if (per_prev_state == PWRDM_POWER_OFF)
407 omap3_per_restore_context();
409 omap2_gpio_resume_after_retention();
412 pwrdm_post_transition();
417 * Check if functional clocks are enabled before entering
418 * sleep. This function could be behind CONFIG_PM_DEBUG
419 * when all drivers are configuring their sysconfig registers
420 * properly and using their clocks properly.
422 static int omap3_fclks_active(void)
424 u32 fck_core1 = 0, fck_core3 = 0, fck_sgx = 0, fck_dss = 0,
425 fck_cam = 0, fck_per = 0, fck_usbhost = 0;
427 fck_core1 = cm_read_mod_reg(CORE_MOD,
429 if (omap_rev() > OMAP3430_REV_ES1_0) {
430 fck_core3 = cm_read_mod_reg(CORE_MOD,
431 OMAP3430ES2_CM_FCLKEN3);
432 fck_sgx = cm_read_mod_reg(OMAP3430ES2_SGX_MOD,
434 fck_usbhost = cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD,
437 fck_sgx = cm_read_mod_reg(GFX_MOD,
438 OMAP3430ES2_CM_FCLKEN3);
439 fck_dss = cm_read_mod_reg(OMAP3430_DSS_MOD,
441 fck_cam = cm_read_mod_reg(OMAP3430_CAM_MOD,
443 fck_per = cm_read_mod_reg(OMAP3430_PER_MOD,
446 /* Ignore UART clocks. These are handled by UART core (serial.c) */
447 fck_core1 &= ~(OMAP3430_EN_UART1 | OMAP3430_EN_UART2);
448 fck_per &= ~OMAP3430_EN_UART3;
450 if (fck_core1 | fck_core3 | fck_sgx | fck_dss |
451 fck_cam | fck_per | fck_usbhost)
456 static int omap3_can_sleep(void)
458 if (!omap_uart_can_sleep())
460 if (omap3_fclks_active())
465 /* This sets pwrdm state (other than mpu & core. Currently only ON &
466 * RET are supported. Function is assuming that clkdm doesn't have
467 * hw_sup mode enabled. */
468 static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
471 int sleep_switch = 0;
474 if (pwrdm == NULL || IS_ERR(pwrdm))
477 while (!(pwrdm->pwrsts & (1 << state))) {
478 if (state == PWRDM_POWER_OFF)
483 cur_state = pwrdm_read_next_pwrst(pwrdm);
484 if (cur_state == state)
487 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
488 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
490 pwrdm_wait_transition(pwrdm);
493 ret = pwrdm_set_next_pwrst(pwrdm, state);
495 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
501 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
502 pwrdm_wait_transition(pwrdm);
503 pwrdm_state_switch(pwrdm);
510 static void omap3_pm_idle(void)
515 if (!omap3_can_sleep())
518 if (omap_irq_pending())
528 #ifdef CONFIG_SUSPEND
529 static suspend_state_t suspend_state;
531 static int omap3_pm_prepare(void)
537 static int omap3_pm_suspend(void)
539 struct power_state *pwrst;
542 /* Read current next_pwrsts */
543 list_for_each_entry(pwrst, &pwrst_list, node)
544 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
545 /* Set ones wanted by suspend */
546 list_for_each_entry(pwrst, &pwrst_list, node) {
547 if (set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
549 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
553 omap_uart_prepare_suspend();
557 /* Restore next_pwrsts */
558 list_for_each_entry(pwrst, &pwrst_list, node) {
559 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
560 if (state > pwrst->next_state) {
561 printk(KERN_INFO "Powerdomain (%s) didn't enter "
563 pwrst->pwrdm->name, pwrst->next_state);
566 set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
569 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
571 printk(KERN_INFO "Successfully put all powerdomains "
572 "to target state\n");
577 static int omap3_pm_enter(suspend_state_t unused)
581 switch (suspend_state) {
582 case PM_SUSPEND_STANDBY:
584 ret = omap3_pm_suspend();
593 static void omap3_pm_finish(void)
598 /* Hooks to enable / disable UART interrupts during suspend */
599 static int omap3_pm_begin(suspend_state_t state)
601 suspend_state = state;
602 omap_uart_enable_irqs(0);
606 static void omap3_pm_end(void)
608 suspend_state = PM_SUSPEND_ON;
609 omap_uart_enable_irqs(1);
613 static struct platform_suspend_ops omap_pm_ops = {
614 .begin = omap3_pm_begin,
616 .prepare = omap3_pm_prepare,
617 .enter = omap3_pm_enter,
618 .finish = omap3_pm_finish,
619 .valid = suspend_valid_only_mem,
621 #endif /* CONFIG_SUSPEND */
625 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
628 * In cases where IVA2 is activated by bootcode, it may prevent
629 * full-chip retention or off-mode because it is not idle. This
630 * function forces the IVA2 into idle state so it can go
631 * into retention/off and thus allow full-chip retention/off.
634 static void __init omap3_iva_idle(void)
636 /* ensure IVA2 clock is disabled */
637 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
639 /* if no clock activity, nothing else to do */
640 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
641 OMAP3430_CLKACTIVITY_IVA2_MASK))
645 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
648 OMAP3430_IVA2_MOD, RM_RSTCTRL);
650 /* Enable IVA2 clock */
651 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2,
652 OMAP3430_IVA2_MOD, CM_FCLKEN);
654 /* Set IVA2 boot mode to 'idle' */
655 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
656 OMAP343X_CONTROL_IVA2_BOOTMOD);
659 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, RM_RSTCTRL);
661 /* Disable IVA2 clock */
662 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
665 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
668 OMAP3430_IVA2_MOD, RM_RSTCTRL);
671 static void __init omap3_d2d_idle(void)
675 /* In a stand alone OMAP3430 where there is not a stacked
676 * modem for the D2D Idle Ack and D2D MStandby must be pulled
677 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
678 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
679 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
680 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
682 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
684 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
686 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
689 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON |
690 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST,
691 CORE_MOD, RM_RSTCTRL);
692 prm_write_mod_reg(0, CORE_MOD, RM_RSTCTRL);
695 static void __init prcm_setup_regs(void)
697 /* XXX Reset all wkdeps. This should be done when initializing
699 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
700 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
701 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
702 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
703 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
704 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
705 if (omap_rev() > OMAP3430_REV_ES1_0) {
706 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
707 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
709 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
712 * Enable interface clock autoidle for all modules.
713 * Note that in the long run this should be done by clockfw
716 OMAP3430_AUTO_MODEM |
717 OMAP3430ES2_AUTO_MMC3 |
718 OMAP3430ES2_AUTO_ICR |
720 OMAP3430_AUTO_SHA12 |
724 OMAP3430_AUTO_MSPRO |
726 OMAP3430_AUTO_MCSPI4 |
727 OMAP3430_AUTO_MCSPI3 |
728 OMAP3430_AUTO_MCSPI2 |
729 OMAP3430_AUTO_MCSPI1 |
733 OMAP3430_AUTO_UART2 |
734 OMAP3430_AUTO_UART1 |
735 OMAP3430_AUTO_GPT11 |
736 OMAP3430_AUTO_GPT10 |
737 OMAP3430_AUTO_MCBSP5 |
738 OMAP3430_AUTO_MCBSP1 |
739 OMAP3430ES1_AUTO_FAC | /* This is es1 only */
740 OMAP3430_AUTO_MAILBOXES |
741 OMAP3430_AUTO_OMAPCTRL |
742 OMAP3430ES1_AUTO_FSHOSTUSB |
743 OMAP3430_AUTO_HSOTGUSB |
744 OMAP3430_AUTO_SAD2D |
746 CORE_MOD, CM_AUTOIDLE1);
752 OMAP3430_AUTO_SHA11 |
754 CORE_MOD, CM_AUTOIDLE2);
756 if (omap_rev() > OMAP3430_REV_ES1_0) {
758 OMAP3430_AUTO_MAD2D |
759 OMAP3430ES2_AUTO_USBTLL,
760 CORE_MOD, CM_AUTOIDLE3);
766 OMAP3430_AUTO_GPIO1 |
767 OMAP3430_AUTO_32KSYNC |
768 OMAP3430_AUTO_GPT12 |
770 WKUP_MOD, CM_AUTOIDLE);
783 OMAP3430_AUTO_GPIO6 |
784 OMAP3430_AUTO_GPIO5 |
785 OMAP3430_AUTO_GPIO4 |
786 OMAP3430_AUTO_GPIO3 |
787 OMAP3430_AUTO_GPIO2 |
789 OMAP3430_AUTO_UART3 |
798 OMAP3430_AUTO_MCBSP4 |
799 OMAP3430_AUTO_MCBSP3 |
800 OMAP3430_AUTO_MCBSP2,
804 if (omap_rev() > OMAP3430_REV_ES1_0) {
806 OMAP3430ES2_AUTO_USBHOST,
807 OMAP3430ES2_USBHOST_MOD,
812 * Set all plls to autoidle. This is needed until autoidle is
815 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
816 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
817 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
820 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
821 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
824 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
829 * Enable control of expternal oscillator through
830 * sys_clkreq. In the long run clock framework should
833 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
834 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
836 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
838 /* setup wakup source */
839 prm_write_mod_reg(OMAP3430_EN_IO | OMAP3430_EN_GPIO1 |
840 OMAP3430_EN_GPT1 | OMAP3430_EN_GPT12,
842 /* No need to write EN_IO, that is always enabled */
843 prm_write_mod_reg(OMAP3430_EN_GPIO1 | OMAP3430_EN_GPT1 |
845 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
846 /* For some reason IO doesn't generate wakeup event even if
847 * it is selected to mpu wakeup goup */
848 prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
849 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
851 /* Enable wakeups in PER */
852 prm_write_mod_reg(OMAP3430_EN_GPIO2 | OMAP3430_EN_GPIO3 |
853 OMAP3430_EN_GPIO4 | OMAP3430_EN_GPIO5 |
854 OMAP3430_EN_GPIO6 | OMAP3430_EN_UART3,
855 OMAP3430_PER_MOD, PM_WKEN);
856 /* and allow them to wake up MPU */
857 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2 | OMAP3430_EN_GPIO3 |
858 OMAP3430_GRPSEL_GPIO4 | OMAP3430_EN_GPIO5 |
859 OMAP3430_GRPSEL_GPIO6 | OMAP3430_EN_UART3,
860 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
862 /* Don't attach IVA interrupts */
863 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
864 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
865 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
866 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
868 /* Clear any pending 'reset' flags */
869 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
870 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
871 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
872 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
873 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
874 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
875 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
877 /* Clear any pending PRCM interrupts */
878 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
880 /* Don't attach IVA interrupts */
881 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
882 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
883 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
884 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
886 /* Clear any pending 'reset' flags */
887 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
888 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
889 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
890 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
891 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
892 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
893 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
895 /* Clear any pending PRCM interrupts */
896 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
902 int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
904 struct power_state *pwrst;
906 list_for_each_entry(pwrst, &pwrst_list, node) {
907 if (pwrst->pwrdm == pwrdm)
908 return pwrst->next_state;
913 int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
915 struct power_state *pwrst;
917 list_for_each_entry(pwrst, &pwrst_list, node) {
918 if (pwrst->pwrdm == pwrdm) {
919 pwrst->next_state = state;
926 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
928 struct power_state *pwrst;
933 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
936 pwrst->pwrdm = pwrdm;
937 pwrst->next_state = PWRDM_POWER_RET;
938 list_add(&pwrst->node, &pwrst_list);
940 if (pwrdm_has_hdwr_sar(pwrdm))
941 pwrdm_enable_hdwr_sar(pwrdm);
943 return set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
947 * Enable hw supervised mode for all clockdomains if it's
948 * supported. Initiate sleep transition for other clockdomains, if
951 static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
953 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
954 omap2_clkdm_allow_idle(clkdm);
955 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
956 atomic_read(&clkdm->usecount) == 0)
957 omap2_clkdm_sleep(clkdm);
961 void omap_push_sram_idle(void)
963 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
964 omap34xx_cpu_suspend_sz);
965 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
966 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
967 save_secure_ram_context_sz);
970 static int __init omap3_pm_init(void)
972 struct power_state *pwrst, *tmp;
975 if (!cpu_is_omap34xx())
978 printk(KERN_ERR "Power Management for TI OMAP3.\n");
980 /* XXX prcm_setup_regs needs to be before enabling hw
981 * supervised mode for powerdomains */
984 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
985 (irq_handler_t)prcm_interrupt_handler,
986 IRQF_DISABLED, "prcm", NULL);
988 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
989 INT_34XX_PRCM_MPU_IRQ);
993 ret = pwrdm_for_each(pwrdms_setup, NULL);
995 printk(KERN_ERR "Failed to setup powerdomains\n");
999 (void) clkdm_for_each(clkdms_setup, NULL);
1001 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
1002 if (mpu_pwrdm == NULL) {
1003 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
1007 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
1008 per_pwrdm = pwrdm_lookup("per_pwrdm");
1009 core_pwrdm = pwrdm_lookup("core_pwrdm");
1011 omap_push_sram_idle();
1012 #ifdef CONFIG_SUSPEND
1013 suspend_set_ops(&omap_pm_ops);
1014 #endif /* CONFIG_SUSPEND */
1016 pm_idle = omap3_pm_idle;
1018 pwrdm_add_wkdep(neon_pwrdm, mpu_pwrdm);
1020 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
1021 * IO-pad wakeup. Otherwise it will unnecessarily waste power
1022 * waking up PER with every CORE wakeup - see
1023 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
1025 pwrdm_add_wkdep(per_pwrdm, core_pwrdm);
1027 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
1028 omap3_secure_ram_storage =
1029 kmalloc(0x803F, GFP_KERNEL);
1030 if (!omap3_secure_ram_storage)
1031 printk(KERN_ERR "Memory allocation failed when"
1032 "allocating for secure sram context\n");
1034 local_irq_disable();
1035 local_fiq_disable();
1037 omap_dma_global_context_save();
1038 omap3_save_secure_ram_context(PWRDM_POWER_ON);
1039 omap_dma_global_context_restore();
1045 omap3_save_scratchpad_contents();
1049 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
1050 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
1051 list_del(&pwrst->node);
1057 late_initcall(omap3_pm_init);