blob: da054370f83750600df3cfb0961d501336c83de3 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * OMAP3 Power Management Routines
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation
5 * Tony Lindgren <tony@atomide.com>
6 * Jouni Hogander
7 *
Rajendra Nayak2f5939c2008-09-26 17:50:07 +05308 * Copyright (C) 2007 Texas Instruments, Inc.
9 * Rajendra Nayak <rnayak@ti.com>
10 *
Kevin Hilman8bd22942009-05-28 10:56:16 -070011 * Copyright (C) 2005 Texas Instruments, Inc.
12 * Richard Woodruff <r-woodruff2@ti.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/pm.h>
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>
Kevin Hilmanc40552b2009-10-06 14:25:09 -070028#include <linux/clk.h>
Tero Kristodccaad82009-11-17 18:34:53 +020029#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Jean Pihet5e7c58d2011-03-03 11:25:43 +010031#include <trace/events/power.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070032
Russell King2c74a0c2011-06-22 17:41:48 +010033#include <asm/suspend.h>
34
Tony Lindgrence491cf2009-10-20 09:40:47 -070035#include <plat/sram.h>
Paul Walmsley1540f2142010-12-21 21:05:15 -070036#include "clockdomain.h"
Paul Walmsley72e06d02010-12-21 21:05:16 -070037#include "powerdomain.h"
Rajendra Nayak61255ab2008-09-26 17:49:56 +053038#include <plat/sdrc.h>
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053039#include <plat/prcm.h>
40#include <plat/gpmc.h>
Tero Kristof2d11852008-08-28 13:13:31 +000041#include <plat/dma.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070042
Tony Lindgren4e653312011-11-10 22:45:17 +010043#include "common.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070044#include "cm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070045#include "cm-regbits-34xx.h"
46#include "prm-regbits-34xx.h"
47
Paul Walmsley59fb6592010-12-21 15:30:55 -070048#include "prm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070049#include "pm.h"
Tero Kristo13a6fe0f2008-10-13 13:17:06 +030050#include "sdrc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060051#include "control.h"
Tero Kristo13a6fe0f2008-10-13 13:17:06 +030052
Nishanth Menon8cdfd832010-12-20 14:05:05 -060053/* pm34xx errata defined in pm.h */
54u16 pm34xx_errata;
55
Kevin Hilman8bd22942009-05-28 10:56:16 -070056struct power_state {
57 struct powerdomain *pwrdm;
58 u32 next_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070059#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -070060 u32 saved_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070061#endif
Kevin Hilman8bd22942009-05-28 10:56:16 -070062 struct list_head node;
63};
64
65static LIST_HEAD(pwrst_list);
66
Tero Kristo27d59a42008-10-13 13:15:00 +030067static int (*_omap_save_secure_sram)(u32 *addr);
Jean Pihet46e130d2011-06-29 18:40:23 +020068void (*omap3_do_wfi_sram)(void);
Tero Kristo27d59a42008-10-13 13:15:00 +030069
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053070static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
71static struct powerdomain *core_pwrdm, *per_pwrdm;
Tero Kristoc16c3f62008-12-11 16:46:57 +020072static struct powerdomain *cam_pwrdm;
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053073
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053074static inline void omap3_per_save_context(void)
75{
76 omap_gpio_save_context();
77}
78
79static inline void omap3_per_restore_context(void)
80{
81 omap_gpio_restore_context();
82}
83
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020084static void omap3_enable_io_chain(void)
85{
86 int timeout = 0;
87
Paul Walmsleyb02b9172011-10-06 17:18:45 -060088 omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
89 PM_WKEN);
90 /* Do a readback to assure write has been done */
91 omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020092
Paul Walmsleyb02b9172011-10-06 17:18:45 -060093 while (!(omap2_prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
94 OMAP3430_ST_IO_CHAIN_MASK)) {
95 timeout++;
96 if (timeout > 1000) {
97 pr_err("Wake up daisy chain activation failed.\n");
98 return;
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020099 }
Paul Walmsleyb02b9172011-10-06 17:18:45 -0600100 omap2_prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
101 WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200102 }
103}
104
105static void omap3_disable_io_chain(void)
106{
Paul Walmsleyb02b9172011-10-06 17:18:45 -0600107 omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
108 PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200109}
110
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530111static void omap3_core_save_context(void)
112{
Paul Walmsley596efe42010-12-21 21:05:16 -0700113 omap3_ctrl_save_padconf();
Tero Kristodccaad82009-11-17 18:34:53 +0200114
115 /*
116 * Force write last pad into memory, as this can fail in some
Jean Pihet83521292010-12-18 16:44:46 +0100117 * cases according to errata 1.157, 1.185
Tero Kristodccaad82009-11-17 18:34:53 +0200118 */
119 omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
120 OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
121
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530122 /* Save the Interrupt controller context */
123 omap_intc_save_context();
124 /* Save the GPMC context */
125 omap3_gpmc_save_context();
126 /* Save the system control module context, padconf already save above*/
127 omap3_control_save_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000128 omap_dma_global_context_save();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530129}
130
131static void omap3_core_restore_context(void)
132{
133 /* Restore the control module context, padconf restored by h/w */
134 omap3_control_restore_context();
135 /* Restore the GPMC context */
136 omap3_gpmc_restore_context();
137 /* Restore the interrupt controller context */
138 omap_intc_restore_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000139 omap_dma_global_context_restore();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530140}
141
Tero Kristo9d971402008-12-12 11:20:05 +0200142/*
143 * FIXME: This function should be called before entering off-mode after
144 * OMAP3 secure services have been accessed. Currently it is only called
145 * once during boot sequence, but this works as we are not using secure
146 * services.
147 */
Kevin Hilman617fcc92011-01-25 16:40:01 -0800148static void omap3_save_secure_ram_context(void)
Tero Kristo27d59a42008-10-13 13:15:00 +0300149{
150 u32 ret;
Kevin Hilman617fcc92011-01-25 16:40:01 -0800151 int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
Tero Kristo27d59a42008-10-13 13:15:00 +0300152
153 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
Tero Kristo27d59a42008-10-13 13:15:00 +0300154 /*
155 * MPU next state must be set to POWER_ON temporarily,
156 * otherwise the WFI executed inside the ROM code
157 * will hang the system.
158 */
159 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
160 ret = _omap_save_secure_sram((u32 *)
161 __pa(omap3_secure_ram_storage));
Kevin Hilman617fcc92011-01-25 16:40:01 -0800162 pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
Tero Kristo27d59a42008-10-13 13:15:00 +0300163 /* Following is for error tracking, it should not happen */
164 if (ret) {
165 printk(KERN_ERR "save_secure_sram() returns %08x\n",
166 ret);
167 while (1)
168 ;
169 }
170 }
171}
172
Jon Hunter77da2d92009-06-27 00:07:25 -0500173/*
174 * PRCM Interrupt Handler Helper Function
175 *
176 * The purpose of this function is to clear any wake-up events latched
177 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
178 * may occur whilst attempting to clear a PM_WKST_x register and thus
179 * set another bit in this register. A while loop is used to ensure
180 * that any peripheral wake-up events occurring while attempting to
181 * clear the PM_WKST_x are detected and cleared.
182 */
Tero Kristo22f51372011-12-16 14:36:59 -0700183static int prcm_clear_mod_irqs(s16 module, u8 regs, u32 ignore_bits)
Jon Hunter77da2d92009-06-27 00:07:25 -0500184{
Vikram Pandita71a80772009-07-17 19:33:09 -0500185 u32 wkst, fclk, iclk, clken;
Jon Hunter77da2d92009-06-27 00:07:25 -0500186 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
187 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
188 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
Paul Walmsley5d805972009-07-22 10:18:07 -0700189 u16 grpsel_off = (regs == 3) ?
190 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700191 int c = 0;
Jon Hunter77da2d92009-06-27 00:07:25 -0500192
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700193 wkst = omap2_prm_read_mod_reg(module, wkst_off);
194 wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
Tero Kristo22f51372011-12-16 14:36:59 -0700195 wkst &= ~ignore_bits;
Jon Hunter77da2d92009-06-27 00:07:25 -0500196 if (wkst) {
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700197 iclk = omap2_cm_read_mod_reg(module, iclk_off);
198 fclk = omap2_cm_read_mod_reg(module, fclk_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500199 while (wkst) {
Vikram Pandita71a80772009-07-17 19:33:09 -0500200 clken = wkst;
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700201 omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
Vikram Pandita71a80772009-07-17 19:33:09 -0500202 /*
203 * For USBHOST, we don't know whether HOST1 or
204 * HOST2 woke us up, so enable both f-clocks
205 */
206 if (module == OMAP3430ES2_USBHOST_MOD)
207 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700208 omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
209 omap2_prm_write_mod_reg(wkst, module, wkst_off);
210 wkst = omap2_prm_read_mod_reg(module, wkst_off);
Tero Kristo22f51372011-12-16 14:36:59 -0700211 wkst &= ~ignore_bits;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700212 c++;
Jon Hunter77da2d92009-06-27 00:07:25 -0500213 }
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700214 omap2_cm_write_mod_reg(iclk, module, iclk_off);
215 omap2_cm_write_mod_reg(fclk, module, fclk_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500216 }
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700217
218 return c;
219}
220
Tero Kristo22f51372011-12-16 14:36:59 -0700221static irqreturn_t _prcm_int_handle_io(int irq, void *unused)
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700222{
223 int c;
224
Tero Kristo22f51372011-12-16 14:36:59 -0700225 c = prcm_clear_mod_irqs(WKUP_MOD, 1,
226 ~(OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK));
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700227
Tero Kristo22f51372011-12-16 14:36:59 -0700228 return c ? IRQ_HANDLED : IRQ_NONE;
Jon Hunter77da2d92009-06-27 00:07:25 -0500229}
230
Tero Kristo22f51372011-12-16 14:36:59 -0700231static irqreturn_t _prcm_int_handle_wakeup(int irq, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700232{
Tero Kristo22f51372011-12-16 14:36:59 -0700233 int c;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700234
Tero Kristo22f51372011-12-16 14:36:59 -0700235 /*
236 * Clear all except ST_IO and ST_IO_CHAIN for wkup module,
237 * these are handled in a separate handler to avoid acking
238 * IO events before parsing in mux code
239 */
240 c = prcm_clear_mod_irqs(WKUP_MOD, 1,
241 OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK);
242 c += prcm_clear_mod_irqs(CORE_MOD, 1, 0);
243 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1, 0);
244 if (omap_rev() > OMAP3430_REV_ES1_0) {
245 c += prcm_clear_mod_irqs(CORE_MOD, 3, 0);
246 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1, 0);
247 }
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700248
Tero Kristo22f51372011-12-16 14:36:59 -0700249 return c ? IRQ_HANDLED : IRQ_NONE;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700250}
251
Russell Kingcbe26342011-06-30 08:45:49 +0100252static void omap34xx_save_context(u32 *save)
253{
254 u32 val;
255
256 /* Read Auxiliary Control Register */
257 asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (val));
258 *save++ = 1;
259 *save++ = val;
260
261 /* Read L2 AUX ctrl register */
262 asm("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
263 *save++ = 1;
264 *save++ = val;
265}
266
Russell King29cb3cd2011-07-02 09:54:01 +0100267static int omap34xx_do_sram_idle(unsigned long save_state)
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530268{
Russell Kingcbe26342011-06-30 08:45:49 +0100269 omap34xx_cpu_suspend(save_state);
Russell King29cb3cd2011-07-02 09:54:01 +0100270 return 0;
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530271}
272
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530273void omap_sram_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700274{
275 /* Variable to tell what needs to be saved and restored
276 * in omap_sram_idle*/
277 /* save_state = 0 => Nothing to save and restored */
278 /* save_state = 1 => Only L1 and logic lost */
279 /* save_state = 2 => Only L2 lost */
280 /* save_state = 3 => L1, L2 and logic lost */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530281 int save_state = 0;
282 int mpu_next_state = PWRDM_POWER_ON;
283 int per_next_state = PWRDM_POWER_ON;
284 int core_next_state = PWRDM_POWER_ON;
Paul Walmsley72e06d02010-12-21 21:05:16 -0700285 int per_going_off;
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530286 int core_prev_state, per_prev_state;
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300287 u32 sdrc_pwr = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700288
Kevin Hilman8bd22942009-05-28 10:56:16 -0700289 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
290 switch (mpu_next_state) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530291 case PWRDM_POWER_ON:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700292 case PWRDM_POWER_RET:
293 /* No need to save context */
294 save_state = 0;
295 break;
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530296 case PWRDM_POWER_OFF:
297 save_state = 3;
298 break;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700299 default:
300 /* Invalid state */
301 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
302 return;
303 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300304
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530305 /* NEON control */
306 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
Jouni Hogander71391782008-10-28 10:59:05 +0200307 pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530308
Mike Chan40742fa2010-05-03 16:04:06 -0700309 /* Enable IO-PAD and IO-CHAIN wakeups */
Kevin Hilman658ce972008-11-04 20:50:52 -0800310 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
Tero Kristoecf157d2008-12-01 13:17:29 +0200311 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
Kevin Hilmand5c47d72010-08-10 16:04:35 -0700312 if (omap3_has_io_wakeup() &&
313 (per_next_state < PWRDM_POWER_ON ||
314 core_next_state < PWRDM_POWER_ON)) {
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700315 omap2_prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
Paul Walmsleyb02b9172011-10-06 17:18:45 -0600316 if (omap3_has_io_chain_ctrl())
317 omap3_enable_io_chain();
Mike Chan40742fa2010-05-03 16:04:06 -0700318 }
319
Charulatha Vff2f8e52011-09-13 18:32:37 +0530320 pwrdm_pre_transition();
321
Mike Chan40742fa2010-05-03 16:04:06 -0700322 /* PER */
Kevin Hilman658ce972008-11-04 20:50:52 -0800323 if (per_next_state < PWRDM_POWER_ON) {
Paul Walmsley72e06d02010-12-21 21:05:16 -0700324 per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
Paul Walmsley72e06d02010-12-21 21:05:16 -0700325 omap2_gpio_prepare_for_idle(per_going_off);
Kevin Hilmane7410cf2010-09-08 16:37:42 -0700326 if (per_next_state == PWRDM_POWER_OFF)
Tero Kristoecf157d2008-12-01 13:17:29 +0200327 omap3_per_save_context();
Kevin Hilman658ce972008-11-04 20:50:52 -0800328 }
329
330 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530331 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530332 if (core_next_state == PWRDM_POWER_OFF) {
333 omap3_core_save_context();
Paul Walmsleyf0611a52010-12-21 15:30:56 -0700334 omap3_cm_save_context();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530335 }
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530336 }
Mike Chan40742fa2010-05-03 16:04:06 -0700337
Tero Kristof18cc2f2009-10-23 19:03:50 +0300338 omap3_intc_prepare_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700339
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530340 /*
Paul Walmsley30474542011-10-06 13:43:23 -0600341 * On EMU/HS devices ROM code restores a SRDC value
342 * from scratchpad which has automatic self refresh on timeout
343 * of AUTO_CNT = 1 enabled. This takes care of erratum ID i443.
344 * Hence store/restore the SDRC_POWER register here.
345 */
346 if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
347 (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
348 omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530349 core_next_state == PWRDM_POWER_OFF)
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300350 sdrc_pwr = sdrc_read_reg(SDRC_POWER);
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300351
352 /*
Russell King076f2cc2011-06-22 15:42:54 +0100353 * omap3_arm_context is the location where some ARM context
354 * get saved. The rest is placed on the stack, and restored
355 * from there before resuming.
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530356 */
Russell Kingcbe26342011-06-30 08:45:49 +0100357 if (save_state)
358 omap34xx_save_context(omap3_arm_context);
Russell King076f2cc2011-06-22 15:42:54 +0100359 if (save_state == 1 || save_state == 3)
Russell King2c74a0c2011-06-22 17:41:48 +0100360 cpu_suspend(save_state, omap34xx_do_sram_idle);
Russell King076f2cc2011-06-22 15:42:54 +0100361 else
362 omap34xx_do_sram_idle(save_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700363
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530364 /* Restore normal SDRC POWER settings */
Paul Walmsley30474542011-10-06 13:43:23 -0600365 if (cpu_is_omap3430() && omap_rev() >= OMAP3430_REV_ES3_0 &&
366 (omap_type() == OMAP2_DEVICE_TYPE_EMU ||
367 omap_type() == OMAP2_DEVICE_TYPE_SEC) &&
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300368 core_next_state == PWRDM_POWER_OFF)
369 sdrc_write_reg(sdrc_pwr, SDRC_POWER);
370
Kevin Hilman658ce972008-11-04 20:50:52 -0800371 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530372 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530373 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
374 if (core_prev_state == PWRDM_POWER_OFF) {
375 omap3_core_restore_context();
Paul Walmsleyf0611a52010-12-21 15:30:56 -0700376 omap3_cm_restore_context();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530377 omap3_sram_restore_context();
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +0300378 omap2_sms_restore_context();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530379 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800380 if (core_next_state == PWRDM_POWER_OFF)
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700381 omap2_prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
Kevin Hilman658ce972008-11-04 20:50:52 -0800382 OMAP3430_GR_MOD,
383 OMAP3_PRM_VOLTCTRL_OFFSET);
384 }
Tero Kristof18cc2f2009-10-23 19:03:50 +0300385 omap3_intc_resume_idle();
Kevin Hilman658ce972008-11-04 20:50:52 -0800386
Charulatha Vff2f8e52011-09-13 18:32:37 +0530387 pwrdm_post_transition();
388
Kevin Hilman658ce972008-11-04 20:50:52 -0800389 /* PER */
390 if (per_next_state < PWRDM_POWER_ON) {
391 per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
Kevin Hilman43ffcd92009-01-27 11:09:24 -0800392 omap2_gpio_resume_after_idle();
393 if (per_prev_state == PWRDM_POWER_OFF)
Kevin Hilman658ce972008-11-04 20:50:52 -0800394 omap3_per_restore_context();
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530395 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300396
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200397 /* Disable IO-PAD and IO-CHAIN wakeup */
Kevin Hilman58a55592010-08-16 09:21:19 +0300398 if (omap3_has_io_wakeup() &&
399 (per_next_state < PWRDM_POWER_ON ||
400 core_next_state < PWRDM_POWER_ON)) {
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700401 omap2_prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD,
402 PM_WKEN);
Paul Walmsleyb02b9172011-10-06 17:18:45 -0600403 if (omap3_has_io_chain_ctrl())
404 omap3_disable_io_chain();
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200405 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800406
Rajendra Nayak5cd19372011-02-25 16:06:48 -0700407 clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700408}
409
Kevin Hilman8bd22942009-05-28 10:56:16 -0700410static void omap3_pm_idle(void)
411{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700412 local_fiq_disable();
413
Nicolas Pitre0bcd24b2012-01-04 16:27:48 -0500414 if (omap_irq_pending())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700415 goto out;
416
Jean Pihet5e7c58d2011-03-03 11:25:43 +0100417 trace_power_start(POWER_CSTATE, 1, smp_processor_id());
418 trace_cpu_idle(1, smp_processor_id());
419
Kevin Hilman8bd22942009-05-28 10:56:16 -0700420 omap_sram_idle();
421
Jean Pihet5e7c58d2011-03-03 11:25:43 +0100422 trace_power_end(smp_processor_id());
423 trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id());
424
Kevin Hilman8bd22942009-05-28 10:56:16 -0700425out:
426 local_fiq_enable();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700427}
428
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700429#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -0700430static int omap3_pm_suspend(void)
431{
432 struct power_state *pwrst;
433 int state, ret = 0;
434
435 /* Read current next_pwrsts */
436 list_for_each_entry(pwrst, &pwrst_list, node)
437 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
438 /* Set ones wanted by suspend */
439 list_for_each_entry(pwrst, &pwrst_list, node) {
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530440 if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
Kevin Hilman8bd22942009-05-28 10:56:16 -0700441 goto restore;
442 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
443 goto restore;
444 }
445
Tero Kristo2bbe3af2009-10-23 19:03:48 +0300446 omap3_intc_suspend();
447
Kevin Hilman8bd22942009-05-28 10:56:16 -0700448 omap_sram_idle();
449
450restore:
451 /* Restore next_pwrsts */
452 list_for_each_entry(pwrst, &pwrst_list, node) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700453 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
454 if (state > pwrst->next_state) {
455 printk(KERN_INFO "Powerdomain (%s) didn't enter "
456 "target state %d\n",
457 pwrst->pwrdm->name, pwrst->next_state);
458 ret = -1;
459 }
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530460 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700461 }
462 if (ret)
463 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
464 else
465 printk(KERN_INFO "Successfully put all powerdomains "
466 "to target state\n");
467
468 return ret;
469}
470
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700471#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700472
Kevin Hilman1155e422008-11-25 11:48:24 -0800473
474/**
475 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
476 * retention
477 *
478 * In cases where IVA2 is activated by bootcode, it may prevent
479 * full-chip retention or off-mode because it is not idle. This
480 * function forces the IVA2 into idle state so it can go
481 * into retention/off and thus allow full-chip retention/off.
482 *
483 **/
484static void __init omap3_iva_idle(void)
485{
486 /* ensure IVA2 clock is disabled */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700487 omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
Kevin Hilman1155e422008-11-25 11:48:24 -0800488
489 /* if no clock activity, nothing else to do */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700490 if (!(omap2_cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
Kevin Hilman1155e422008-11-25 11:48:24 -0800491 OMAP3430_CLKACTIVITY_IVA2_MASK))
492 return;
493
494 /* Reset IVA2 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700495 omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600496 OMAP3430_RST2_IVA2_MASK |
497 OMAP3430_RST3_IVA2_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700498 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800499
500 /* Enable IVA2 clock */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700501 omap2_cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
Kevin Hilman1155e422008-11-25 11:48:24 -0800502 OMAP3430_IVA2_MOD, CM_FCLKEN);
503
504 /* Set IVA2 boot mode to 'idle' */
505 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
506 OMAP343X_CONTROL_IVA2_BOOTMOD);
507
508 /* Un-reset IVA2 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700509 omap2_prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800510
511 /* Disable IVA2 clock */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700512 omap2_cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
Kevin Hilman1155e422008-11-25 11:48:24 -0800513
514 /* Reset IVA2 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700515 omap2_prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600516 OMAP3430_RST2_IVA2_MASK |
517 OMAP3430_RST3_IVA2_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700518 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800519}
520
Kevin Hilman8111b222009-04-28 15:27:44 -0700521static void __init omap3_d2d_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700522{
Kevin Hilman8111b222009-04-28 15:27:44 -0700523 u16 mask, padconf;
524
525 /* In a stand alone OMAP3430 where there is not a stacked
526 * modem for the D2D Idle Ack and D2D MStandby must be pulled
527 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
528 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
529 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
530 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
531 padconf |= mask;
532 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
533
534 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
535 padconf |= mask;
536 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
537
Kevin Hilman8bd22942009-05-28 10:56:16 -0700538 /* reset modem */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700539 omap2_prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600540 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700541 CORE_MOD, OMAP2_RM_RSTCTRL);
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700542 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman8111b222009-04-28 15:27:44 -0700543}
Kevin Hilman8bd22942009-05-28 10:56:16 -0700544
Kevin Hilman8111b222009-04-28 15:27:44 -0700545static void __init prcm_setup_regs(void)
546{
Govindraj.Re5863682010-09-27 20:20:25 +0530547 u32 omap3630_en_uart4_mask = cpu_is_omap3630() ?
548 OMAP3630_EN_UART4_MASK : 0;
549 u32 omap3630_grpsel_uart4_mask = cpu_is_omap3630() ?
550 OMAP3630_GRPSEL_UART4_MASK : 0;
551
Paul Walmsley4ef70c02011-02-25 15:39:30 -0700552 /* XXX This should be handled by hwmod code or SCM init code */
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600553 omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
Tero Kristob296c812009-10-23 19:03:49 +0300554
Kevin Hilman8bd22942009-05-28 10:56:16 -0700555 /*
Kevin Hilman8bd22942009-05-28 10:56:16 -0700556 * Enable control of expternal oscillator through
557 * sys_clkreq. In the long run clock framework should
558 * take care of this.
559 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700560 omap2_prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700561 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
562 OMAP3430_GR_MOD,
563 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
564
565 /* setup wakup source */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700566 omap2_prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600567 OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700568 WKUP_MOD, PM_WKEN);
569 /* No need to write EN_IO, that is always enabled */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700570 omap2_prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
Paul Walmsley275f6752010-05-18 18:40:23 -0600571 OMAP3430_GRPSEL_GPT1_MASK |
572 OMAP3430_GRPSEL_GPT12_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700573 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800574
Subramani Venkateshb92c5722009-12-22 15:07:50 +0530575 /* Enable PM_WKEN to support DSS LPR */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700576 omap2_prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
Subramani Venkateshb92c5722009-12-22 15:07:50 +0530577 OMAP3430_DSS_MOD, PM_WKEN);
578
Kevin Hilmanb427f922009-10-22 14:48:13 -0700579 /* Enable wakeups in PER */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700580 omap2_prm_write_mod_reg(omap3630_en_uart4_mask |
Govindraj.Re5863682010-09-27 20:20:25 +0530581 OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600582 OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
583 OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
584 OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
585 OMAP3430_EN_MCBSP4_MASK,
Kevin Hilmanb427f922009-10-22 14:48:13 -0700586 OMAP3430_PER_MOD, PM_WKEN);
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000587 /* and allow them to wake up MPU */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700588 omap2_prm_write_mod_reg(omap3630_grpsel_uart4_mask |
Govindraj.Re5863682010-09-27 20:20:25 +0530589 OMAP3430_GRPSEL_GPIO2_MASK |
Paul Walmsley275f6752010-05-18 18:40:23 -0600590 OMAP3430_GRPSEL_GPIO3_MASK |
591 OMAP3430_GRPSEL_GPIO4_MASK |
592 OMAP3430_GRPSEL_GPIO5_MASK |
593 OMAP3430_GRPSEL_GPIO6_MASK |
594 OMAP3430_GRPSEL_UART3_MASK |
595 OMAP3430_GRPSEL_MCBSP2_MASK |
596 OMAP3430_GRPSEL_MCBSP3_MASK |
597 OMAP3430_GRPSEL_MCBSP4_MASK,
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000598 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
599
Kevin Hilmand3fd3292009-05-05 16:34:25 -0700600 /* Don't attach IVA interrupts */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700601 omap2_prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
602 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
603 omap2_prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
604 omap2_prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
Kevin Hilmand3fd3292009-05-05 16:34:25 -0700605
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700606 /* Clear any pending 'reset' flags */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700607 omap2_prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
608 omap2_prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
609 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
610 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
611 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
612 omap2_prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
613 omap2_prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700614
Kevin Hilman014c46d2009-04-27 07:50:23 -0700615 /* Clear any pending PRCM interrupts */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700616 omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman014c46d2009-04-27 07:50:23 -0700617
Kevin Hilman1155e422008-11-25 11:48:24 -0800618 omap3_iva_idle();
Kevin Hilman8111b222009-04-28 15:27:44 -0700619 omap3_d2d_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700620}
621
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700622void omap3_pm_off_mode_enable(int enable)
623{
624 struct power_state *pwrst;
625 u32 state;
626
627 if (enable)
628 state = PWRDM_POWER_OFF;
629 else
630 state = PWRDM_POWER_RET;
631
632 list_for_each_entry(pwrst, &pwrst_list, node) {
Eduardo Valentincc1b6022010-12-20 14:05:09 -0600633 if (IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583) &&
634 pwrst->pwrdm == core_pwrdm &&
635 state == PWRDM_POWER_OFF) {
636 pwrst->next_state = PWRDM_POWER_RET;
Ricardo Salveti de Araujoe16b41b2011-01-31 11:35:25 -0200637 pr_warn("%s: Core OFF disabled due to errata i583\n",
Eduardo Valentincc1b6022010-12-20 14:05:09 -0600638 __func__);
639 } else {
640 pwrst->next_state = state;
641 }
642 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700643 }
644}
645
Tero Kristo68d47782008-11-26 12:26:24 +0200646int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
647{
648 struct power_state *pwrst;
649
650 list_for_each_entry(pwrst, &pwrst_list, node) {
651 if (pwrst->pwrdm == pwrdm)
652 return pwrst->next_state;
653 }
654 return -EINVAL;
655}
656
657int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
658{
659 struct power_state *pwrst;
660
661 list_for_each_entry(pwrst, &pwrst_list, node) {
662 if (pwrst->pwrdm == pwrdm) {
663 pwrst->next_state = state;
664 return 0;
665 }
666 }
667 return -EINVAL;
668}
669
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300670static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700671{
672 struct power_state *pwrst;
673
674 if (!pwrdm->pwrsts)
675 return 0;
676
Ming Leid3d381c2009-08-22 21:20:26 +0800677 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700678 if (!pwrst)
679 return -ENOMEM;
680 pwrst->pwrdm = pwrdm;
681 pwrst->next_state = PWRDM_POWER_RET;
682 list_add(&pwrst->node, &pwrst_list);
683
684 if (pwrdm_has_hdwr_sar(pwrdm))
685 pwrdm_enable_hdwr_sar(pwrdm);
686
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530687 return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700688}
689
690/*
Jean Pihet46e130d2011-06-29 18:40:23 +0200691 * Push functions to SRAM
692 *
693 * The minimum set of functions is pushed to SRAM for execution:
694 * - omap3_do_wfi for erratum i581 WA,
695 * - save_secure_ram_context for security extensions.
696 */
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530697void omap_push_sram_idle(void)
698{
Jean Pihet46e130d2011-06-29 18:40:23 +0200699 omap3_do_wfi_sram = omap_sram_push(omap3_do_wfi, omap3_do_wfi_sz);
700
Tero Kristo27d59a42008-10-13 13:15:00 +0300701 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
702 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
703 save_secure_ram_context_sz);
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530704}
705
Nishanth Menon8cdfd832010-12-20 14:05:05 -0600706static void __init pm_errata_configure(void)
707{
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600708 if (cpu_is_omap3630()) {
Nishanth Menon458e9992010-12-20 14:05:06 -0600709 pm34xx_errata |= PM_RTA_ERRATUM_i608;
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600710 /* Enable the l2 cache toggling in sleep logic */
711 enable_omap3630_toggle_l2_on_restore();
Eduardo Valentincc1b6022010-12-20 14:05:09 -0600712 if (omap_rev() < OMAP3630_REV_ES1_2)
713 pm34xx_errata |= PM_SDRC_WAKEUP_ERRATUM_i583;
Peter 'p2' De Schrijverc4236d22010-12-20 14:05:07 -0600714 }
Nishanth Menon8cdfd832010-12-20 14:05:05 -0600715}
716
Kevin Hilman7cc515f2009-06-10 09:02:25 -0700717static int __init omap3_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700718{
719 struct power_state *pwrst, *tmp;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700720 struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700721 int ret;
722
723 if (!cpu_is_omap34xx())
724 return -ENODEV;
725
Paul Walmsleyb02b9172011-10-06 17:18:45 -0600726 if (!omap3_has_io_chain_ctrl())
727 pr_warning("PM: no software I/O chain control; some wakeups may be lost\n");
728
Nishanth Menon8cdfd832010-12-20 14:05:05 -0600729 pm_errata_configure();
730
Kevin Hilman8bd22942009-05-28 10:56:16 -0700731 /* XXX prcm_setup_regs needs to be before enabling hw
732 * supervised mode for powerdomains */
733 prcm_setup_regs();
734
Tero Kristo22f51372011-12-16 14:36:59 -0700735 ret = request_irq(omap_prcm_event_to_irq("wkup"),
736 _prcm_int_handle_wakeup, IRQF_NO_SUSPEND, "pm_wkup", NULL);
737
Kevin Hilman8bd22942009-05-28 10:56:16 -0700738 if (ret) {
Tero Kristo22f51372011-12-16 14:36:59 -0700739 pr_err("pm: Failed to request pm_wkup irq\n");
740 goto err1;
741 }
742
743 /* IO interrupt is shared with mux code */
744 ret = request_irq(omap_prcm_event_to_irq("io"),
745 _prcm_int_handle_io, IRQF_SHARED | IRQF_NO_SUSPEND, "pm_io",
746 omap3_pm_init);
747
748 if (ret) {
749 pr_err("pm: Failed to request pm_io irq\n");
Kevin Hilman8bd22942009-05-28 10:56:16 -0700750 goto err1;
751 }
752
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300753 ret = pwrdm_for_each(pwrdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700754 if (ret) {
755 printk(KERN_ERR "Failed to setup powerdomains\n");
756 goto err2;
757 }
758
Paul Walmsley92206fd2012-02-02 02:38:50 -0700759 (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700760
761 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
762 if (mpu_pwrdm == NULL) {
763 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
764 goto err2;
765 }
766
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530767 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
768 per_pwrdm = pwrdm_lookup("per_pwrdm");
769 core_pwrdm = pwrdm_lookup("core_pwrdm");
Tero Kristoc16c3f62008-12-11 16:46:57 +0200770 cam_pwrdm = pwrdm_lookup("cam_pwrdm");
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530771
Paul Walmsley55ed9692010-01-26 20:12:59 -0700772 neon_clkdm = clkdm_lookup("neon_clkdm");
773 mpu_clkdm = clkdm_lookup("mpu_clkdm");
774 per_clkdm = clkdm_lookup("per_clkdm");
775 core_clkdm = clkdm_lookup("core_clkdm");
776
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700777#ifdef CONFIG_SUSPEND
Paul Walmsley14164082012-02-02 02:30:50 -0700778 omap_pm_suspend = omap3_pm_suspend;
779#endif
Kevin Hilman8bd22942009-05-28 10:56:16 -0700780
Nicolas Pitre0bcd24b2012-01-04 16:27:48 -0500781 arm_pm_idle = omap3_pm_idle;
Kalle Jokiniemi03433712008-09-26 11:04:20 +0300782 omap3_idle_init();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700783
Nishanth Menon458e9992010-12-20 14:05:06 -0600784 /*
785 * RTA is disabled during initialization as per erratum i608
786 * it is safer to disable RTA by the bootloader, but we would like
787 * to be doubly sure here and prevent any mishaps.
788 */
789 if (IS_PM34XX_ERRATUM(PM_RTA_ERRATUM_i608))
790 omap3630_ctrl_disable_rta();
791
Paul Walmsley55ed9692010-01-26 20:12:59 -0700792 clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
Tero Kristo27d59a42008-10-13 13:15:00 +0300793 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
794 omap3_secure_ram_storage =
795 kmalloc(0x803F, GFP_KERNEL);
796 if (!omap3_secure_ram_storage)
797 printk(KERN_ERR "Memory allocation failed when"
798 "allocating for secure sram context\n");
Tero Kristo27d59a42008-10-13 13:15:00 +0300799
Tero Kristo9d971402008-12-12 11:20:05 +0200800 local_irq_disable();
801 local_fiq_disable();
802
803 omap_dma_global_context_save();
Kevin Hilman617fcc92011-01-25 16:40:01 -0800804 omap3_save_secure_ram_context();
Tero Kristo9d971402008-12-12 11:20:05 +0200805 omap_dma_global_context_restore();
806
807 local_irq_enable();
808 local_fiq_enable();
809 }
810
811 omap3_save_scratchpad_contents();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700812err1:
813 return ret;
814err2:
815 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
816 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
817 list_del(&pwrst->node);
818 kfree(pwrst);
819 }
820 return ret;
821}
822
823late_initcall(omap3_pm_init);