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>
38 #include <asm/tlbflush.h>
41 #include "cm-regbits-34xx.h"
42 #include "prm-regbits-34xx.h"
47 /* Scratchpad offsets */
48 #define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
49 #define OMAP343X_TABLE_VALUE_OFFSET 0x30
50 #define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
53 struct powerdomain *pwrdm;
58 struct list_head node;
61 static LIST_HEAD(pwrst_list);
63 static void (*_omap_sram_idle)(u32 *addr, int save_state);
65 static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
66 static struct powerdomain *core_pwrdm, *per_pwrdm;
68 static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state);
70 static inline void omap3_per_save_context(void)
72 omap_gpio_save_context();
75 static inline void omap3_per_restore_context(void)
77 omap_gpio_restore_context();
80 static void omap3_core_save_context(void)
82 u32 control_padconf_off;
84 /* Save the padconf registers */
85 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
86 control_padconf_off |= START_PADCONF_SAVE;
87 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
88 /* wait for the save to complete */
89 while (!omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
92 /* Save the Interrupt controller context */
93 omap_intc_save_context();
94 /* Save the GPMC context */
95 omap3_gpmc_save_context();
96 /* Save the system control module context, padconf already save above*/
97 omap3_control_save_context();
100 static void omap3_core_restore_context(void)
102 /* Restore the control module context, padconf restored by h/w */
103 omap3_control_restore_context();
104 /* Restore the GPMC context */
105 omap3_gpmc_restore_context();
106 /* Restore the interrupt controller context */
107 omap_intc_restore_context();
111 * PRCM Interrupt Handler Helper Function
113 * The purpose of this function is to clear any wake-up events latched
114 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
115 * may occur whilst attempting to clear a PM_WKST_x register and thus
116 * set another bit in this register. A while loop is used to ensure
117 * that any peripheral wake-up events occurring while attempting to
118 * clear the PM_WKST_x are detected and cleared.
120 static int prcm_clear_mod_irqs(s16 module, u8 regs)
122 u32 wkst, fclk, iclk, clken;
123 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
124 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
125 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
126 u16 grpsel_off = (regs == 3) ?
127 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
130 wkst = prm_read_mod_reg(module, wkst_off);
131 wkst &= prm_read_mod_reg(module, grpsel_off);
133 iclk = cm_read_mod_reg(module, iclk_off);
134 fclk = cm_read_mod_reg(module, fclk_off);
137 cm_set_mod_reg_bits(clken, module, iclk_off);
139 * For USBHOST, we don't know whether HOST1 or
140 * HOST2 woke us up, so enable both f-clocks
142 if (module == OMAP3430ES2_USBHOST_MOD)
143 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
144 cm_set_mod_reg_bits(clken, module, fclk_off);
145 prm_write_mod_reg(wkst, module, wkst_off);
146 wkst = prm_read_mod_reg(module, wkst_off);
149 cm_write_mod_reg(iclk, module, iclk_off);
150 cm_write_mod_reg(fclk, module, fclk_off);
156 static int _prcm_int_handle_wakeup(void)
160 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
161 c += prcm_clear_mod_irqs(CORE_MOD, 1);
162 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
163 if (omap_rev() > OMAP3430_REV_ES1_0) {
164 c += prcm_clear_mod_irqs(CORE_MOD, 3);
165 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
172 * PRCM Interrupt Handler
174 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
175 * interrupts from the PRCM for the MPU. These bits must be cleared in
176 * order to clear the PRCM interrupt. The PRCM interrupt handler is
177 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
178 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
179 * register indicates that a wake-up event is pending for the MPU and
180 * this bit can only be cleared if the all the wake-up events latched
181 * in the various PM_WKST_x registers have been cleared. The interrupt
182 * handler is implemented using a do-while loop so that if a wake-up
183 * event occurred during the processing of the prcm interrupt handler
184 * (setting a bit in the corresponding PM_WKST_x register and thus
185 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
186 * this would be handled.
188 static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
194 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
195 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
197 if (irqstatus_mpu & (OMAP3430_WKUP_ST | OMAP3430_IO_ST)) {
198 c = _prcm_int_handle_wakeup();
201 * Is the MPU PRCM interrupt handler racing with the
202 * IVA2 PRCM interrupt handler ?
204 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
205 "but no wakeup sources are marked\n");
207 /* XXX we need to expand our PRCM interrupt handler */
208 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
209 "no code to handle it (%08x)\n", irqstatus_mpu);
212 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
213 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
215 } while (prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET));
220 static void restore_control_register(u32 val)
222 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
225 /* Function to restore the table entry that was modified for enabling MMU */
226 static void restore_table_entry(void)
228 u32 *scratchpad_address;
229 u32 previous_value, control_reg_value;
232 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
234 /* Get address of entry that was modified */
235 address = (u32 *)__raw_readl(scratchpad_address +
236 OMAP343X_TABLE_ADDRESS_OFFSET);
237 /* Get the previous value which needs to be restored */
238 previous_value = __raw_readl(scratchpad_address +
239 OMAP343X_TABLE_VALUE_OFFSET);
240 address = __va(address);
241 *address = previous_value;
243 control_reg_value = __raw_readl(scratchpad_address
244 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
245 /* This will enable caches and prediction */
246 restore_control_register(control_reg_value);
249 static void omap_sram_idle(void)
251 /* Variable to tell what needs to be saved and restored
252 * in omap_sram_idle*/
253 /* save_state = 0 => Nothing to save and restored */
254 /* save_state = 1 => Only L1 and logic lost */
255 /* save_state = 2 => Only L2 lost */
256 /* save_state = 3 => L1, L2 and logic lost */
258 int mpu_next_state = PWRDM_POWER_ON;
259 int per_next_state = PWRDM_POWER_ON;
260 int core_next_state = PWRDM_POWER_ON;
261 int core_prev_state, per_prev_state;
263 if (!_omap_sram_idle)
266 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
267 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
268 pwrdm_clear_all_prev_pwrst(core_pwrdm);
269 pwrdm_clear_all_prev_pwrst(per_pwrdm);
271 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
272 switch (mpu_next_state) {
274 case PWRDM_POWER_RET:
275 /* No need to save context */
278 case PWRDM_POWER_OFF:
283 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
286 pwrdm_pre_transition();
289 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
290 set_pwrdm_state(neon_pwrdm, mpu_next_state);
293 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
294 if (core_next_state < PWRDM_POWER_ON) {
295 omap2_gpio_prepare_for_retention();
296 omap_uart_prepare_idle(0);
297 omap_uart_prepare_idle(1);
298 /* PER changes only with core */
299 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
300 if (per_next_state < PWRDM_POWER_ON) {
301 omap_uart_prepare_idle(2);
302 if (per_next_state == PWRDM_POWER_OFF)
303 omap3_per_save_context();
305 if (core_next_state == PWRDM_POWER_OFF) {
306 omap3_core_save_context();
307 omap3_prcm_save_context();
309 /* Enable IO-PAD wakeup */
310 prm_set_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
314 * omap3_arm_context is the location where ARM registers
315 * get saved. The restore path then reads from this
316 * location and restores them back.
318 _omap_sram_idle(omap3_arm_context, save_state);
321 /* Restore table entry modified during MMU restoration */
322 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
323 restore_table_entry();
325 if (core_next_state < PWRDM_POWER_ON) {
326 if (per_next_state < PWRDM_POWER_ON)
327 omap_uart_resume_idle(2);
328 omap_uart_resume_idle(1);
329 omap_uart_resume_idle(0);
331 /* Disable IO-PAD wakeup */
332 prm_clear_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
333 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
334 if (core_prev_state == PWRDM_POWER_OFF) {
335 omap3_core_restore_context();
336 omap3_prcm_restore_context();
337 omap3_sram_restore_context();
339 if (per_next_state < PWRDM_POWER_ON) {
341 pwrdm_read_prev_pwrst(per_pwrdm);
342 if (per_prev_state == PWRDM_POWER_OFF)
343 omap3_per_restore_context();
345 omap2_gpio_resume_after_retention();
348 pwrdm_post_transition();
353 * Check if functional clocks are enabled before entering
354 * sleep. This function could be behind CONFIG_PM_DEBUG
355 * when all drivers are configuring their sysconfig registers
356 * properly and using their clocks properly.
358 static int omap3_fclks_active(void)
360 u32 fck_core1 = 0, fck_core3 = 0, fck_sgx = 0, fck_dss = 0,
361 fck_cam = 0, fck_per = 0, fck_usbhost = 0;
363 fck_core1 = cm_read_mod_reg(CORE_MOD,
365 if (omap_rev() > OMAP3430_REV_ES1_0) {
366 fck_core3 = cm_read_mod_reg(CORE_MOD,
367 OMAP3430ES2_CM_FCLKEN3);
368 fck_sgx = cm_read_mod_reg(OMAP3430ES2_SGX_MOD,
370 fck_usbhost = cm_read_mod_reg(OMAP3430ES2_USBHOST_MOD,
373 fck_sgx = cm_read_mod_reg(GFX_MOD,
374 OMAP3430ES2_CM_FCLKEN3);
375 fck_dss = cm_read_mod_reg(OMAP3430_DSS_MOD,
377 fck_cam = cm_read_mod_reg(OMAP3430_CAM_MOD,
379 fck_per = cm_read_mod_reg(OMAP3430_PER_MOD,
382 /* Ignore UART clocks. These are handled by UART core (serial.c) */
383 fck_core1 &= ~(OMAP3430_EN_UART1 | OMAP3430_EN_UART2);
384 fck_per &= ~OMAP3430_EN_UART3;
386 if (fck_core1 | fck_core3 | fck_sgx | fck_dss |
387 fck_cam | fck_per | fck_usbhost)
392 static int omap3_can_sleep(void)
394 if (!omap_uart_can_sleep())
396 if (omap3_fclks_active())
401 /* This sets pwrdm state (other than mpu & core. Currently only ON &
402 * RET are supported. Function is assuming that clkdm doesn't have
403 * hw_sup mode enabled. */
404 static int set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
407 int sleep_switch = 0;
410 if (pwrdm == NULL || IS_ERR(pwrdm))
413 while (!(pwrdm->pwrsts & (1 << state))) {
414 if (state == PWRDM_POWER_OFF)
419 cur_state = pwrdm_read_next_pwrst(pwrdm);
420 if (cur_state == state)
423 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
424 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
426 pwrdm_wait_transition(pwrdm);
429 ret = pwrdm_set_next_pwrst(pwrdm, state);
431 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
437 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
438 pwrdm_wait_transition(pwrdm);
439 pwrdm_state_switch(pwrdm);
446 static void omap3_pm_idle(void)
451 if (!omap3_can_sleep())
454 if (omap_irq_pending())
464 #ifdef CONFIG_SUSPEND
465 static suspend_state_t suspend_state;
467 static int omap3_pm_prepare(void)
473 static int omap3_pm_suspend(void)
475 struct power_state *pwrst;
478 /* Read current next_pwrsts */
479 list_for_each_entry(pwrst, &pwrst_list, node)
480 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
481 /* Set ones wanted by suspend */
482 list_for_each_entry(pwrst, &pwrst_list, node) {
483 if (set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
485 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
489 omap_uart_prepare_suspend();
493 /* Restore next_pwrsts */
494 list_for_each_entry(pwrst, &pwrst_list, node) {
495 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
496 if (state > pwrst->next_state) {
497 printk(KERN_INFO "Powerdomain (%s) didn't enter "
499 pwrst->pwrdm->name, pwrst->next_state);
502 set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
505 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
507 printk(KERN_INFO "Successfully put all powerdomains "
508 "to target state\n");
513 static int omap3_pm_enter(suspend_state_t unused)
517 switch (suspend_state) {
518 case PM_SUSPEND_STANDBY:
520 ret = omap3_pm_suspend();
529 static void omap3_pm_finish(void)
534 /* Hooks to enable / disable UART interrupts during suspend */
535 static int omap3_pm_begin(suspend_state_t state)
537 suspend_state = state;
538 omap_uart_enable_irqs(0);
542 static void omap3_pm_end(void)
544 suspend_state = PM_SUSPEND_ON;
545 omap_uart_enable_irqs(1);
549 static struct platform_suspend_ops omap_pm_ops = {
550 .begin = omap3_pm_begin,
552 .prepare = omap3_pm_prepare,
553 .enter = omap3_pm_enter,
554 .finish = omap3_pm_finish,
555 .valid = suspend_valid_only_mem,
557 #endif /* CONFIG_SUSPEND */
561 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
564 * In cases where IVA2 is activated by bootcode, it may prevent
565 * full-chip retention or off-mode because it is not idle. This
566 * function forces the IVA2 into idle state so it can go
567 * into retention/off and thus allow full-chip retention/off.
570 static void __init omap3_iva_idle(void)
572 /* ensure IVA2 clock is disabled */
573 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
575 /* if no clock activity, nothing else to do */
576 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
577 OMAP3430_CLKACTIVITY_IVA2_MASK))
581 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
584 OMAP3430_IVA2_MOD, RM_RSTCTRL);
586 /* Enable IVA2 clock */
587 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2,
588 OMAP3430_IVA2_MOD, CM_FCLKEN);
590 /* Set IVA2 boot mode to 'idle' */
591 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
592 OMAP343X_CONTROL_IVA2_BOOTMOD);
595 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, RM_RSTCTRL);
597 /* Disable IVA2 clock */
598 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
601 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
604 OMAP3430_IVA2_MOD, RM_RSTCTRL);
607 static void __init omap3_d2d_idle(void)
611 /* In a stand alone OMAP3430 where there is not a stacked
612 * modem for the D2D Idle Ack and D2D MStandby must be pulled
613 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
614 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
615 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
616 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
618 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
620 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
622 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
625 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON |
626 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST,
627 CORE_MOD, RM_RSTCTRL);
628 prm_write_mod_reg(0, CORE_MOD, RM_RSTCTRL);
631 static void __init prcm_setup_regs(void)
633 /* XXX Reset all wkdeps. This should be done when initializing
635 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
636 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
637 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
638 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
639 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
640 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
641 if (omap_rev() > OMAP3430_REV_ES1_0) {
642 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
643 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
645 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
648 * Enable interface clock autoidle for all modules.
649 * Note that in the long run this should be done by clockfw
652 OMAP3430_AUTO_MODEM |
653 OMAP3430ES2_AUTO_MMC3 |
654 OMAP3430ES2_AUTO_ICR |
656 OMAP3430_AUTO_SHA12 |
660 OMAP3430_AUTO_MSPRO |
662 OMAP3430_AUTO_MCSPI4 |
663 OMAP3430_AUTO_MCSPI3 |
664 OMAP3430_AUTO_MCSPI2 |
665 OMAP3430_AUTO_MCSPI1 |
669 OMAP3430_AUTO_UART2 |
670 OMAP3430_AUTO_UART1 |
671 OMAP3430_AUTO_GPT11 |
672 OMAP3430_AUTO_GPT10 |
673 OMAP3430_AUTO_MCBSP5 |
674 OMAP3430_AUTO_MCBSP1 |
675 OMAP3430ES1_AUTO_FAC | /* This is es1 only */
676 OMAP3430_AUTO_MAILBOXES |
677 OMAP3430_AUTO_OMAPCTRL |
678 OMAP3430ES1_AUTO_FSHOSTUSB |
679 OMAP3430_AUTO_HSOTGUSB |
680 OMAP3430_AUTO_SAD2D |
682 CORE_MOD, CM_AUTOIDLE1);
688 OMAP3430_AUTO_SHA11 |
690 CORE_MOD, CM_AUTOIDLE2);
692 if (omap_rev() > OMAP3430_REV_ES1_0) {
694 OMAP3430_AUTO_MAD2D |
695 OMAP3430ES2_AUTO_USBTLL,
696 CORE_MOD, CM_AUTOIDLE3);
702 OMAP3430_AUTO_GPIO1 |
703 OMAP3430_AUTO_32KSYNC |
704 OMAP3430_AUTO_GPT12 |
706 WKUP_MOD, CM_AUTOIDLE);
719 OMAP3430_AUTO_GPIO6 |
720 OMAP3430_AUTO_GPIO5 |
721 OMAP3430_AUTO_GPIO4 |
722 OMAP3430_AUTO_GPIO3 |
723 OMAP3430_AUTO_GPIO2 |
725 OMAP3430_AUTO_UART3 |
734 OMAP3430_AUTO_MCBSP4 |
735 OMAP3430_AUTO_MCBSP3 |
736 OMAP3430_AUTO_MCBSP2,
740 if (omap_rev() > OMAP3430_REV_ES1_0) {
742 OMAP3430ES2_AUTO_USBHOST,
743 OMAP3430ES2_USBHOST_MOD,
748 * Set all plls to autoidle. This is needed until autoidle is
751 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
752 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
753 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
756 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
757 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
760 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
765 * Enable control of expternal oscillator through
766 * sys_clkreq. In the long run clock framework should
769 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
770 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
772 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
774 /* setup wakup source */
775 prm_write_mod_reg(OMAP3430_EN_IO | OMAP3430_EN_GPIO1 |
776 OMAP3430_EN_GPT1 | OMAP3430_EN_GPT12,
778 /* No need to write EN_IO, that is always enabled */
779 prm_write_mod_reg(OMAP3430_EN_GPIO1 | OMAP3430_EN_GPT1 |
781 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
782 /* For some reason IO doesn't generate wakeup event even if
783 * it is selected to mpu wakeup goup */
784 prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
785 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
787 /* Enable wakeups in PER */
788 prm_write_mod_reg(OMAP3430_EN_GPIO2 | OMAP3430_EN_GPIO3 |
789 OMAP3430_EN_GPIO4 | OMAP3430_EN_GPIO5 |
790 OMAP3430_EN_GPIO6 | OMAP3430_EN_UART3,
791 OMAP3430_PER_MOD, PM_WKEN);
792 /* and allow them to wake up MPU */
793 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2 | OMAP3430_EN_GPIO3 |
794 OMAP3430_GRPSEL_GPIO4 | OMAP3430_EN_GPIO5 |
795 OMAP3430_GRPSEL_GPIO6 | OMAP3430_EN_UART3,
796 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
798 /* Don't attach IVA interrupts */
799 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
800 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
801 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
802 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
804 /* Clear any pending 'reset' flags */
805 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
806 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
807 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
808 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
809 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
810 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
811 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
813 /* Clear any pending PRCM interrupts */
814 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
816 /* Don't attach IVA interrupts */
817 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
818 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
819 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
820 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
822 /* Clear any pending 'reset' flags */
823 prm_write_mod_reg(0xffffffff, MPU_MOD, RM_RSTST);
824 prm_write_mod_reg(0xffffffff, CORE_MOD, RM_RSTST);
825 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, RM_RSTST);
826 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, RM_RSTST);
827 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, RM_RSTST);
828 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, RM_RSTST);
829 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, RM_RSTST);
831 /* Clear any pending PRCM interrupts */
832 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
838 int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
840 struct power_state *pwrst;
842 list_for_each_entry(pwrst, &pwrst_list, node) {
843 if (pwrst->pwrdm == pwrdm)
844 return pwrst->next_state;
849 int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
851 struct power_state *pwrst;
853 list_for_each_entry(pwrst, &pwrst_list, node) {
854 if (pwrst->pwrdm == pwrdm) {
855 pwrst->next_state = state;
862 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
864 struct power_state *pwrst;
869 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
872 pwrst->pwrdm = pwrdm;
873 pwrst->next_state = PWRDM_POWER_RET;
874 list_add(&pwrst->node, &pwrst_list);
876 if (pwrdm_has_hdwr_sar(pwrdm))
877 pwrdm_enable_hdwr_sar(pwrdm);
879 return set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
883 * Enable hw supervised mode for all clockdomains if it's
884 * supported. Initiate sleep transition for other clockdomains, if
887 static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
889 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
890 omap2_clkdm_allow_idle(clkdm);
891 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
892 atomic_read(&clkdm->usecount) == 0)
893 omap2_clkdm_sleep(clkdm);
897 void omap_push_sram_idle(void)
899 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
900 omap34xx_cpu_suspend_sz);
903 static int __init omap3_pm_init(void)
905 struct power_state *pwrst, *tmp;
908 if (!cpu_is_omap34xx())
911 printk(KERN_ERR "Power Management for TI OMAP3.\n");
913 /* XXX prcm_setup_regs needs to be before enabling hw
914 * supervised mode for powerdomains */
916 omap3_save_scratchpad_contents();
918 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
919 (irq_handler_t)prcm_interrupt_handler,
920 IRQF_DISABLED, "prcm", NULL);
922 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
923 INT_34XX_PRCM_MPU_IRQ);
927 ret = pwrdm_for_each(pwrdms_setup, NULL);
929 printk(KERN_ERR "Failed to setup powerdomains\n");
933 (void) clkdm_for_each(clkdms_setup, NULL);
935 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
936 if (mpu_pwrdm == NULL) {
937 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
941 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
942 per_pwrdm = pwrdm_lookup("per_pwrdm");
943 core_pwrdm = pwrdm_lookup("core_pwrdm");
945 omap_push_sram_idle();
946 #ifdef CONFIG_SUSPEND
947 suspend_set_ops(&omap_pm_ops);
948 #endif /* CONFIG_SUSPEND */
950 pm_idle = omap3_pm_idle;
952 pwrdm_add_wkdep(neon_pwrdm, mpu_pwrdm);
954 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
955 * IO-pad wakeup. Otherwise it will unnecessarily waste power
956 * waking up PER with every CORE wakeup - see
957 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
959 pwrdm_add_wkdep(per_pwrdm, core_pwrdm);
964 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
965 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
966 list_del(&pwrst->node);
972 late_initcall(omap3_pm_init);