Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2 Power Management Routines |
| 3 | * |
| 4 | * Copyright (C) 2005 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2006-2008 Nokia Corporation |
| 6 | * |
| 7 | * Written by: |
| 8 | * Richard Woodruff <r-woodruff2@ti.com> |
| 9 | * Tony Lindgren |
| 10 | * Juha Yrjola |
| 11 | * Amit Kucheria <amit.kucheria@nokia.com> |
| 12 | * Igor Stoppa <igor.stoppa@nokia.com> |
| 13 | * |
| 14 | * Based on pm.c for omap1 |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License version 2 as |
| 18 | * published by the Free Software Foundation. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/suspend.h> |
| 22 | #include <linux/sched.h> |
| 23 | #include <linux/proc_fs.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/sysfs.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/clk.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 29 | #include <linux/irq.h> |
| 30 | #include <linux/time.h> |
| 31 | #include <linux/gpio.h> |
| 32 | |
| 33 | #include <asm/mach/time.h> |
| 34 | #include <asm/mach/irq.h> |
| 35 | #include <asm/mach-types.h> |
| 36 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 37 | #include <plat/clock.h> |
| 38 | #include <plat/sram.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 39 | #include <plat/dma.h> |
| 40 | #include <plat/board.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 41 | |
Tony Lindgren | ee0839c | 2012-02-24 10:34:35 -0800 | [diff] [blame] | 42 | #include <mach/irqs.h> |
| 43 | |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 44 | #include "common.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 45 | #include "prm2xxx_3xxx.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 46 | #include "prm-regbits-24xx.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 47 | #include "cm2xxx_3xxx.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 48 | #include "cm-regbits-24xx.h" |
| 49 | #include "sdrc.h" |
| 50 | #include "pm.h" |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 51 | #include "control.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 52 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 53 | #include "clockdomain.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 54 | |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 55 | #ifdef CONFIG_SUSPEND |
| 56 | static suspend_state_t suspend_state = PM_SUSPEND_ON; |
| 57 | static inline bool is_suspending(void) |
| 58 | { |
| 59 | return (suspend_state != PM_SUSPEND_ON); |
| 60 | } |
| 61 | #else |
| 62 | static inline bool is_suspending(void) |
| 63 | { |
| 64 | return false; |
| 65 | } |
| 66 | #endif |
| 67 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 68 | static void (*omap2_sram_idle)(void); |
| 69 | static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl, |
| 70 | void __iomem *sdrc_power); |
| 71 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 72 | static struct powerdomain *mpu_pwrdm, *core_pwrdm; |
| 73 | static struct clockdomain *dsp_clkdm, *mpu_clkdm, *wkup_clkdm, *gfx_clkdm; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 74 | |
| 75 | static struct clk *osc_ck, *emul_ck; |
| 76 | |
| 77 | static int omap2_fclks_active(void) |
| 78 | { |
| 79 | u32 f1, f2; |
| 80 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 81 | f1 = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1); |
| 82 | f2 = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2); |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 83 | |
Paul Walmsley | 1e056dd | 2012-02-09 18:24:03 -0700 | [diff] [blame] | 84 | return (f1 | f2) ? 1 : 0; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 87 | static void omap2_enter_full_retention(void) |
| 88 | { |
| 89 | u32 l; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 90 | |
| 91 | /* There is 1 reference hold for all children of the oscillator |
| 92 | * clock, the following will remove it. If no one else uses the |
| 93 | * oscillator itself it will be disabled if/when we enter retention |
| 94 | * mode. |
| 95 | */ |
| 96 | clk_disable(osc_ck); |
| 97 | |
| 98 | /* Clear old wake-up events */ |
| 99 | /* REVISIT: These write to reserved bits? */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 100 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1); |
| 101 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2); |
| 102 | omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Set MPU powerdomain's next power state to RETENTION; |
| 106 | * preserve logic state during retention |
| 107 | */ |
| 108 | pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET); |
| 109 | pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET); |
| 110 | |
| 111 | /* Workaround to kill USB */ |
| 112 | l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL; |
| 113 | omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0); |
| 114 | |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 115 | omap2_gpio_prepare_for_idle(0); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 116 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 117 | /* One last check for pending IRQs to avoid extra latency due |
| 118 | * to sleeping unnecessarily. */ |
Jouni Hogander | 9443453 | 2009-02-03 15:49:04 -0800 | [diff] [blame] | 119 | if (omap_irq_pending()) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 120 | goto no_sleep; |
| 121 | |
| 122 | /* Jump to SRAM suspend code */ |
| 123 | omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL), |
| 124 | OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL), |
| 125 | OMAP_SDRC_REGADDR(SDRC_POWER)); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 126 | |
Kevin Hilman | 4af4016 | 2009-02-04 10:51:40 -0800 | [diff] [blame] | 127 | no_sleep: |
Kevin Hilman | 43ffcd9 | 2009-01-27 11:09:24 -0800 | [diff] [blame] | 128 | omap2_gpio_resume_after_idle(); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 129 | |
| 130 | clk_enable(osc_ck); |
| 131 | |
| 132 | /* clear CORE wake-up events */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 133 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1); |
| 134 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 135 | |
| 136 | /* wakeup domain events - bit 1: GPT1, bit5 GPIO */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 137 | omap2_prm_clear_mod_reg_bits(0x4 | 0x1, WKUP_MOD, PM_WKST); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 138 | |
| 139 | /* MPU domain wake events */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 140 | l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 141 | if (l & 0x01) |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 142 | omap2_prm_write_mod_reg(0x01, OCP_MOD, |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 143 | OMAP2_PRCM_IRQSTATUS_MPU_OFFSET); |
| 144 | if (l & 0x20) |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 145 | omap2_prm_write_mod_reg(0x20, OCP_MOD, |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 146 | OMAP2_PRCM_IRQSTATUS_MPU_OFFSET); |
| 147 | |
| 148 | /* Mask future PRCM-to-MPU interrupts */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 149 | omap2_prm_write_mod_reg(0x0, OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static int omap2_i2c_active(void) |
| 153 | { |
| 154 | u32 l; |
| 155 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 156 | l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1); |
Paul Walmsley | f38ca10 | 2010-05-20 12:31:04 -0600 | [diff] [blame] | 157 | return l & (OMAP2420_EN_I2C2_MASK | OMAP2420_EN_I2C1_MASK); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static int sti_console_enabled; |
| 161 | |
| 162 | static int omap2_allow_mpu_retention(void) |
| 163 | { |
| 164 | u32 l; |
| 165 | |
| 166 | /* Check for MMC, UART2, UART1, McSPI2, McSPI1 and DSS1. */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 167 | l = omap2_cm_read_mod_reg(CORE_MOD, CM_FCLKEN1); |
Paul Walmsley | 2fd0f75 | 2010-05-18 18:40:23 -0600 | [diff] [blame] | 168 | if (l & (OMAP2420_EN_MMC_MASK | OMAP24XX_EN_UART2_MASK | |
| 169 | OMAP24XX_EN_UART1_MASK | OMAP24XX_EN_MCSPI2_MASK | |
| 170 | OMAP24XX_EN_MCSPI1_MASK | OMAP24XX_EN_DSS1_MASK)) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 171 | return 0; |
| 172 | /* Check for UART3. */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 173 | l = omap2_cm_read_mod_reg(CORE_MOD, OMAP24XX_CM_FCLKEN2); |
Paul Walmsley | 2fd0f75 | 2010-05-18 18:40:23 -0600 | [diff] [blame] | 174 | if (l & OMAP24XX_EN_UART3_MASK) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 175 | return 0; |
| 176 | if (sti_console_enabled) |
| 177 | return 0; |
| 178 | |
| 179 | return 1; |
| 180 | } |
| 181 | |
| 182 | static void omap2_enter_mpu_retention(void) |
| 183 | { |
| 184 | int only_idle = 0; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 185 | |
| 186 | /* Putting MPU into the WFI state while a transfer is active |
| 187 | * seems to cause the I2C block to timeout. Why? Good question. */ |
| 188 | if (omap2_i2c_active()) |
| 189 | return; |
| 190 | |
| 191 | /* The peripherals seem not to be able to wake up the MPU when |
| 192 | * it is in retention mode. */ |
| 193 | if (omap2_allow_mpu_retention()) { |
| 194 | /* REVISIT: These write to reserved bits? */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 195 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, PM_WKST1); |
| 196 | omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP24XX_PM_WKST2); |
| 197 | omap2_prm_write_mod_reg(0xffffffff, WKUP_MOD, PM_WKST); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 198 | |
| 199 | /* Try to enter MPU retention */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 200 | omap2_prm_write_mod_reg((0x01 << OMAP_POWERSTATE_SHIFT) | |
Paul Walmsley | 2fd0f75 | 2010-05-18 18:40:23 -0600 | [diff] [blame] | 201 | OMAP_LOGICRETSTATE_MASK, |
Abhijit Pagare | 3790300 | 2010-01-26 20:12:51 -0700 | [diff] [blame] | 202 | MPU_MOD, OMAP2_PM_PWSTCTRL); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 203 | } else { |
| 204 | /* Block MPU retention */ |
| 205 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 206 | omap2_prm_write_mod_reg(OMAP_LOGICRETSTATE_MASK, MPU_MOD, |
Abhijit Pagare | 3790300 | 2010-01-26 20:12:51 -0700 | [diff] [blame] | 207 | OMAP2_PM_PWSTCTRL); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 208 | only_idle = 1; |
| 209 | } |
| 210 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 211 | omap2_sram_idle(); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static int omap2_can_sleep(void) |
| 215 | { |
| 216 | if (omap2_fclks_active()) |
| 217 | return 0; |
| 218 | if (osc_ck->usecount > 1) |
| 219 | return 0; |
| 220 | if (omap_dma_running()) |
| 221 | return 0; |
| 222 | |
| 223 | return 1; |
| 224 | } |
| 225 | |
| 226 | static void omap2_pm_idle(void) |
| 227 | { |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 228 | local_fiq_disable(); |
| 229 | |
| 230 | if (!omap2_can_sleep()) { |
Jouni Hogander | 9443453 | 2009-02-03 15:49:04 -0800 | [diff] [blame] | 231 | if (omap_irq_pending()) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 232 | goto out; |
| 233 | omap2_enter_mpu_retention(); |
| 234 | goto out; |
| 235 | } |
| 236 | |
Jouni Hogander | 9443453 | 2009-02-03 15:49:04 -0800 | [diff] [blame] | 237 | if (omap_irq_pending()) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 238 | goto out; |
| 239 | |
| 240 | omap2_enter_full_retention(); |
| 241 | |
| 242 | out: |
| 243 | local_fiq_enable(); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Kevin Hilman | 05fad3e | 2010-12-22 23:04:17 +0000 | [diff] [blame] | 246 | #ifdef CONFIG_SUSPEND |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 247 | static int omap2_pm_begin(suspend_state_t state) |
| 248 | { |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 249 | disable_hlt(); |
Jean Pihet | c166381 | 2010-12-09 18:39:58 +0100 | [diff] [blame] | 250 | suspend_state = state; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 254 | static int omap2_pm_enter(suspend_state_t state) |
| 255 | { |
| 256 | int ret = 0; |
| 257 | |
| 258 | switch (state) { |
| 259 | case PM_SUSPEND_STANDBY: |
| 260 | case PM_SUSPEND_MEM: |
Paul Walmsley | 645c56a | 2012-02-24 10:34:32 -0800 | [diff] [blame] | 261 | omap2_enter_full_retention(); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 262 | break; |
| 263 | default: |
| 264 | ret = -EINVAL; |
| 265 | } |
| 266 | |
| 267 | return ret; |
| 268 | } |
| 269 | |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 270 | static void omap2_pm_end(void) |
| 271 | { |
| 272 | suspend_state = PM_SUSPEND_ON; |
Jean Pihet | c166381 | 2010-12-09 18:39:58 +0100 | [diff] [blame] | 273 | enable_hlt(); |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 276 | static const struct platform_suspend_ops omap_pm_ops = { |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 277 | .begin = omap2_pm_begin, |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 278 | .enter = omap2_pm_enter, |
Kevin Hilman | e83df17 | 2010-12-08 22:40:40 +0000 | [diff] [blame] | 279 | .end = omap2_pm_end, |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 280 | .valid = suspend_valid_only_mem, |
| 281 | }; |
Kevin Hilman | 05fad3e | 2010-12-22 23:04:17 +0000 | [diff] [blame] | 282 | #else |
| 283 | static const struct platform_suspend_ops __initdata omap_pm_ops; |
| 284 | #endif /* CONFIG_SUSPEND */ |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 285 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 286 | static void __init prcm_setup_regs(void) |
| 287 | { |
| 288 | int i, num_mem_banks; |
| 289 | struct powerdomain *pwrdm; |
| 290 | |
Paul Walmsley | 4ef70c0 | 2011-02-25 15:39:30 -0700 | [diff] [blame] | 291 | /* |
| 292 | * Enable autoidle |
| 293 | * XXX This should be handled by hwmod code or PRCM init code |
| 294 | */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 295 | omap2_prm_write_mod_reg(OMAP24XX_AUTOIDLE_MASK, OCP_MOD, |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 296 | OMAP2_PRCM_SYSCONFIG_OFFSET); |
| 297 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 298 | /* |
| 299 | * Set CORE powerdomain memory banks to retain their contents |
| 300 | * during RETENTION |
| 301 | */ |
| 302 | num_mem_banks = pwrdm_get_mem_bank_count(core_pwrdm); |
| 303 | for (i = 0; i < num_mem_banks; i++) |
| 304 | pwrdm_set_mem_retst(core_pwrdm, i, PWRDM_POWER_RET); |
| 305 | |
| 306 | /* Set CORE powerdomain's next power state to RETENTION */ |
| 307 | pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_RET); |
| 308 | |
| 309 | /* |
| 310 | * Set MPU powerdomain's next power state to RETENTION; |
| 311 | * preserve logic state during retention |
| 312 | */ |
| 313 | pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET); |
| 314 | pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET); |
| 315 | |
| 316 | /* Force-power down DSP, GFX powerdomains */ |
| 317 | |
| 318 | pwrdm = clkdm_get_pwrdm(dsp_clkdm); |
| 319 | pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF); |
Rajendra Nayak | 68b921a | 2011-02-25 16:06:47 -0700 | [diff] [blame] | 320 | clkdm_sleep(dsp_clkdm); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 321 | |
| 322 | pwrdm = clkdm_get_pwrdm(gfx_clkdm); |
| 323 | pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF); |
Rajendra Nayak | 68b921a | 2011-02-25 16:06:47 -0700 | [diff] [blame] | 324 | clkdm_sleep(gfx_clkdm); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 325 | |
Paul Walmsley | 51d070a | 2011-01-27 02:52:55 -0700 | [diff] [blame] | 326 | /* Enable hardware-supervised idle for all clkdms */ |
Paul Walmsley | 92206fd | 2012-02-02 02:38:50 -0700 | [diff] [blame^] | 327 | clkdm_for_each(omap_pm_clkdms_setup, NULL); |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 328 | clkdm_add_wkdep(mpu_clkdm, wkup_clkdm); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 329 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 330 | /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk |
| 331 | * stabilisation */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 332 | omap2_prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD, |
| 333 | OMAP2_PRCM_CLKSSETUP_OFFSET); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 334 | |
| 335 | /* Configure automatic voltage transition */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 336 | omap2_prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD, |
| 337 | OMAP2_PRCM_VOLTSETUP_OFFSET); |
| 338 | omap2_prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT_MASK | |
| 339 | (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT) | |
| 340 | OMAP24XX_MEMRETCTRL_MASK | |
| 341 | (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT) | |
| 342 | (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT), |
| 343 | OMAP24XX_GR_MOD, OMAP2_PRCM_VOLTCTRL_OFFSET); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 344 | |
| 345 | /* Enable wake-up events */ |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 346 | omap2_prm_write_mod_reg(OMAP24XX_EN_GPIOS_MASK | OMAP24XX_EN_GPT1_MASK, |
| 347 | WKUP_MOD, PM_WKEN); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Kevin Hilman | 7cc515f | 2009-06-10 09:02:25 -0700 | [diff] [blame] | 350 | static int __init omap2_pm_init(void) |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 351 | { |
| 352 | u32 l; |
| 353 | |
| 354 | if (!cpu_is_omap24xx()) |
| 355 | return -ENODEV; |
| 356 | |
| 357 | printk(KERN_INFO "Power Management for OMAP2 initializing\n"); |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 358 | l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_REVISION_OFFSET); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 359 | printk(KERN_INFO "PRCM revision %d.%d\n", (l >> 4) & 0x0f, l & 0x0f); |
| 360 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 361 | /* Look up important powerdomains */ |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 362 | |
| 363 | mpu_pwrdm = pwrdm_lookup("mpu_pwrdm"); |
| 364 | if (!mpu_pwrdm) |
| 365 | pr_err("PM: mpu_pwrdm not found\n"); |
| 366 | |
| 367 | core_pwrdm = pwrdm_lookup("core_pwrdm"); |
| 368 | if (!core_pwrdm) |
| 369 | pr_err("PM: core_pwrdm not found\n"); |
| 370 | |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 371 | /* Look up important clockdomains */ |
| 372 | |
| 373 | mpu_clkdm = clkdm_lookup("mpu_clkdm"); |
| 374 | if (!mpu_clkdm) |
| 375 | pr_err("PM: mpu_clkdm not found\n"); |
| 376 | |
| 377 | wkup_clkdm = clkdm_lookup("wkup_clkdm"); |
| 378 | if (!wkup_clkdm) |
| 379 | pr_err("PM: wkup_clkdm not found\n"); |
| 380 | |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 381 | dsp_clkdm = clkdm_lookup("dsp_clkdm"); |
| 382 | if (!dsp_clkdm) |
Paul Walmsley | 369d561 | 2010-01-26 20:13:01 -0700 | [diff] [blame] | 383 | pr_err("PM: dsp_clkdm not found\n"); |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 384 | |
| 385 | gfx_clkdm = clkdm_lookup("gfx_clkdm"); |
| 386 | if (!gfx_clkdm) |
| 387 | pr_err("PM: gfx_clkdm not found\n"); |
| 388 | |
| 389 | |
| 390 | osc_ck = clk_get(NULL, "osc_ck"); |
| 391 | if (IS_ERR(osc_ck)) { |
| 392 | printk(KERN_ERR "could not get osc_ck\n"); |
| 393 | return -ENODEV; |
| 394 | } |
| 395 | |
| 396 | if (cpu_is_omap242x()) { |
| 397 | emul_ck = clk_get(NULL, "emul_ck"); |
| 398 | if (IS_ERR(emul_ck)) { |
| 399 | printk(KERN_ERR "could not get emul_ck\n"); |
| 400 | clk_put(osc_ck); |
| 401 | return -ENODEV; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | prcm_setup_regs(); |
| 406 | |
| 407 | /* Hack to prevent MPU retention when STI console is enabled. */ |
| 408 | { |
| 409 | const struct omap_sti_console_config *sti; |
| 410 | |
| 411 | sti = omap_get_config(OMAP_TAG_STI_CONSOLE, |
| 412 | struct omap_sti_console_config); |
| 413 | if (sti != NULL && sti->enable) |
| 414 | sti_console_enabled = 1; |
| 415 | } |
| 416 | |
| 417 | /* |
| 418 | * We copy the assembler sleep/wakeup routines to SRAM. |
| 419 | * These routines need to be in SRAM as that's the only |
| 420 | * memory the MPU can see when it wakes up. |
| 421 | */ |
| 422 | if (cpu_is_omap24xx()) { |
| 423 | omap2_sram_idle = omap_sram_push(omap24xx_idle_loop_suspend, |
| 424 | omap24xx_idle_loop_suspend_sz); |
| 425 | |
| 426 | omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend, |
| 427 | omap24xx_cpu_suspend_sz); |
| 428 | } |
| 429 | |
| 430 | suspend_set_ops(&omap_pm_ops); |
Nicolas Pitre | 0bcd24b | 2012-01-04 16:27:48 -0500 | [diff] [blame] | 431 | arm_pm_idle = omap2_pm_idle; |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | late_initcall(omap2_pm_init); |