blob: f5f1dbd3c17ae2542f32ee8b8bde931b87649dc5 [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>
Kevin Hilman8bd22942009-05-28 10:56:16 -070031
Tony Lindgrence491cf2009-10-20 09:40:47 -070032#include <plat/sram.h>
33#include <plat/clockdomain.h>
34#include <plat/powerdomain.h>
35#include <plat/control.h>
36#include <plat/serial.h>
Rajendra Nayak61255ab2008-09-26 17:49:56 +053037#include <plat/sdrc.h>
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053038#include <plat/prcm.h>
39#include <plat/gpmc.h>
Tero Kristof2d11852008-08-28 13:13:31 +000040#include <plat/dma.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070041
Rajendra Nayak57f277b2008-09-26 17:49:34 +053042#include <asm/tlbflush.h>
43
Kevin Hilman8bd22942009-05-28 10:56:16 -070044#include "cm.h"
45#include "cm-regbits-34xx.h"
46#include "prm-regbits-34xx.h"
47
48#include "prm.h"
49#include "pm.h"
Tero Kristo13a6fe0f2008-10-13 13:17:06 +030050#include "sdrc.h"
51
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053052/* Scratchpad offsets */
53#define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
54#define OMAP343X_TABLE_VALUE_OFFSET 0x30
55#define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
56
Kevin Hilman8bd22942009-05-28 10:56:16 -070057struct power_state {
58 struct powerdomain *pwrdm;
59 u32 next_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070060#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -070061 u32 saved_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070062#endif
Kevin Hilman8bd22942009-05-28 10:56:16 -070063 struct list_head node;
64};
65
66static LIST_HEAD(pwrst_list);
67
68static void (*_omap_sram_idle)(u32 *addr, int save_state);
69
Tero Kristo27d59a42008-10-13 13:15:00 +030070static int (*_omap_save_secure_sram)(u32 *addr);
71
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053072static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
73static struct powerdomain *core_pwrdm, *per_pwrdm;
Tero Kristoc16c3f62008-12-11 16:46:57 +020074static struct powerdomain *cam_pwrdm;
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053075
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053076static inline void omap3_per_save_context(void)
77{
78 omap_gpio_save_context();
79}
80
81static inline void omap3_per_restore_context(void)
82{
83 omap_gpio_restore_context();
84}
85
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020086static void omap3_enable_io_chain(void)
87{
88 int timeout = 0;
89
90 if (omap_rev() >= OMAP3430_REV_ES3_1) {
Paul Walmsley2bc4ef72010-05-18 18:47:24 -060091 prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
92 PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020093 /* Do a readback to assure write has been done */
94 prm_read_mod_reg(WKUP_MOD, PM_WKEN);
95
Kevin Hilman0b96a3a2010-06-09 13:53:09 +030096 while (!(prm_read_mod_reg(WKUP_MOD, PM_WKEN) &
Paul Walmsley2bc4ef72010-05-18 18:47:24 -060097 OMAP3430_ST_IO_CHAIN_MASK)) {
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020098 timeout++;
99 if (timeout > 1000) {
100 printk(KERN_ERR "Wake up daisy chain "
101 "activation failed.\n");
102 return;
103 }
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600104 prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN_MASK,
Kevin Hilman0b96a3a2010-06-09 13:53:09 +0300105 WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200106 }
107 }
108}
109
110static void omap3_disable_io_chain(void)
111{
112 if (omap_rev() >= OMAP3430_REV_ES3_1)
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600113 prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN_MASK, WKUP_MOD,
114 PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200115}
116
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530117static void omap3_core_save_context(void)
118{
119 u32 control_padconf_off;
120
121 /* Save the padconf registers */
122 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
123 control_padconf_off |= START_PADCONF_SAVE;
124 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
125 /* wait for the save to complete */
Roel Kluin1b6e8212010-01-08 10:29:07 -0800126 while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
127 & PADCONF_SAVE_DONE))
Tero Kristodccaad82009-11-17 18:34:53 +0200128 udelay(1);
129
130 /*
131 * Force write last pad into memory, as this can fail in some
132 * cases according to erratas 1.157, 1.185
133 */
134 omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
135 OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
136
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530137 /* Save the Interrupt controller context */
138 omap_intc_save_context();
139 /* Save the GPMC context */
140 omap3_gpmc_save_context();
141 /* Save the system control module context, padconf already save above*/
142 omap3_control_save_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000143 omap_dma_global_context_save();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530144}
145
146static void omap3_core_restore_context(void)
147{
148 /* Restore the control module context, padconf restored by h/w */
149 omap3_control_restore_context();
150 /* Restore the GPMC context */
151 omap3_gpmc_restore_context();
152 /* Restore the interrupt controller context */
153 omap_intc_restore_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000154 omap_dma_global_context_restore();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530155}
156
Tero Kristo9d971402008-12-12 11:20:05 +0200157/*
158 * FIXME: This function should be called before entering off-mode after
159 * OMAP3 secure services have been accessed. Currently it is only called
160 * once during boot sequence, but this works as we are not using secure
161 * services.
162 */
Tero Kristo27d59a42008-10-13 13:15:00 +0300163static void omap3_save_secure_ram_context(u32 target_mpu_state)
164{
165 u32 ret;
166
167 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
Tero Kristo27d59a42008-10-13 13:15:00 +0300168 /*
169 * MPU next state must be set to POWER_ON temporarily,
170 * otherwise the WFI executed inside the ROM code
171 * will hang the system.
172 */
173 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
174 ret = _omap_save_secure_sram((u32 *)
175 __pa(omap3_secure_ram_storage));
176 pwrdm_set_next_pwrst(mpu_pwrdm, target_mpu_state);
177 /* Following is for error tracking, it should not happen */
178 if (ret) {
179 printk(KERN_ERR "save_secure_sram() returns %08x\n",
180 ret);
181 while (1)
182 ;
183 }
184 }
185}
186
Jon Hunter77da2d92009-06-27 00:07:25 -0500187/*
188 * PRCM Interrupt Handler Helper Function
189 *
190 * The purpose of this function is to clear any wake-up events latched
191 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
192 * may occur whilst attempting to clear a PM_WKST_x register and thus
193 * set another bit in this register. A while loop is used to ensure
194 * that any peripheral wake-up events occurring while attempting to
195 * clear the PM_WKST_x are detected and cleared.
196 */
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700197static int prcm_clear_mod_irqs(s16 module, u8 regs)
Jon Hunter77da2d92009-06-27 00:07:25 -0500198{
Vikram Pandita71a80772009-07-17 19:33:09 -0500199 u32 wkst, fclk, iclk, clken;
Jon Hunter77da2d92009-06-27 00:07:25 -0500200 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
201 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
202 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
Paul Walmsley5d805972009-07-22 10:18:07 -0700203 u16 grpsel_off = (regs == 3) ?
204 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700205 int c = 0;
Jon Hunter77da2d92009-06-27 00:07:25 -0500206
207 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley5d805972009-07-22 10:18:07 -0700208 wkst &= prm_read_mod_reg(module, grpsel_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500209 if (wkst) {
210 iclk = cm_read_mod_reg(module, iclk_off);
211 fclk = cm_read_mod_reg(module, fclk_off);
212 while (wkst) {
Vikram Pandita71a80772009-07-17 19:33:09 -0500213 clken = wkst;
214 cm_set_mod_reg_bits(clken, module, iclk_off);
215 /*
216 * For USBHOST, we don't know whether HOST1 or
217 * HOST2 woke us up, so enable both f-clocks
218 */
219 if (module == OMAP3430ES2_USBHOST_MOD)
220 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
221 cm_set_mod_reg_bits(clken, module, fclk_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500222 prm_write_mod_reg(wkst, module, wkst_off);
223 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700224 c++;
Jon Hunter77da2d92009-06-27 00:07:25 -0500225 }
226 cm_write_mod_reg(iclk, module, iclk_off);
227 cm_write_mod_reg(fclk, module, fclk_off);
228 }
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700229
230 return c;
231}
232
233static int _prcm_int_handle_wakeup(void)
234{
235 int c;
236
237 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
238 c += prcm_clear_mod_irqs(CORE_MOD, 1);
239 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
240 if (omap_rev() > OMAP3430_REV_ES1_0) {
241 c += prcm_clear_mod_irqs(CORE_MOD, 3);
242 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
243 }
244
245 return c;
Jon Hunter77da2d92009-06-27 00:07:25 -0500246}
247
248/*
249 * PRCM Interrupt Handler
250 *
251 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
252 * interrupts from the PRCM for the MPU. These bits must be cleared in
253 * order to clear the PRCM interrupt. The PRCM interrupt handler is
254 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
255 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
256 * register indicates that a wake-up event is pending for the MPU and
257 * this bit can only be cleared if the all the wake-up events latched
258 * in the various PM_WKST_x registers have been cleared. The interrupt
259 * handler is implemented using a do-while loop so that if a wake-up
260 * event occurred during the processing of the prcm interrupt handler
261 * (setting a bit in the corresponding PM_WKST_x register and thus
262 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
263 * this would be handled.
264 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700265static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
266{
Kevin Hilmand6290a32010-04-26 14:59:09 -0700267 u32 irqenable_mpu, irqstatus_mpu;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700268 int c = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700269
Kevin Hilmand6290a32010-04-26 14:59:09 -0700270 irqenable_mpu = prm_read_mod_reg(OCP_MOD,
271 OMAP3_PRM_IRQENABLE_MPU_OFFSET);
272 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
273 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
274 irqstatus_mpu &= irqenable_mpu;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700275
Kevin Hilmand6290a32010-04-26 14:59:09 -0700276 do {
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600277 if (irqstatus_mpu & (OMAP3430_WKUP_ST_MASK |
278 OMAP3430_IO_ST_MASK)) {
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700279 c = _prcm_int_handle_wakeup();
280
281 /*
282 * Is the MPU PRCM interrupt handler racing with the
283 * IVA2 PRCM interrupt handler ?
284 */
285 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
286 "but no wakeup sources are marked\n");
287 } else {
288 /* XXX we need to expand our PRCM interrupt handler */
289 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
290 "no code to handle it (%08x)\n", irqstatus_mpu);
291 }
292
Jon Hunter77da2d92009-06-27 00:07:25 -0500293 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
294 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700295
Kevin Hilmand6290a32010-04-26 14:59:09 -0700296 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
297 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
298 irqstatus_mpu &= irqenable_mpu;
299
300 } while (irqstatus_mpu);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700301
302 return IRQ_HANDLED;
303}
304
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530305static void restore_control_register(u32 val)
306{
307 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
308}
309
310/* Function to restore the table entry that was modified for enabling MMU */
311static void restore_table_entry(void)
312{
313 u32 *scratchpad_address;
314 u32 previous_value, control_reg_value;
315 u32 *address;
316
317 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
318
319 /* Get address of entry that was modified */
320 address = (u32 *)__raw_readl(scratchpad_address +
321 OMAP343X_TABLE_ADDRESS_OFFSET);
322 /* Get the previous value which needs to be restored */
323 previous_value = __raw_readl(scratchpad_address +
324 OMAP343X_TABLE_VALUE_OFFSET);
325 address = __va(address);
326 *address = previous_value;
327 flush_tlb_all();
328 control_reg_value = __raw_readl(scratchpad_address
329 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
330 /* This will enable caches and prediction */
331 restore_control_register(control_reg_value);
332}
333
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530334void omap_sram_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700335{
336 /* Variable to tell what needs to be saved and restored
337 * in omap_sram_idle*/
338 /* save_state = 0 => Nothing to save and restored */
339 /* save_state = 1 => Only L1 and logic lost */
340 /* save_state = 2 => Only L2 lost */
341 /* save_state = 3 => L1, L2 and logic lost */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530342 int save_state = 0;
343 int mpu_next_state = PWRDM_POWER_ON;
344 int per_next_state = PWRDM_POWER_ON;
345 int core_next_state = PWRDM_POWER_ON;
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530346 int core_prev_state, per_prev_state;
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300347 u32 sdrc_pwr = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700348
349 if (!_omap_sram_idle)
350 return;
351
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530352 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
353 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
354 pwrdm_clear_all_prev_pwrst(core_pwrdm);
355 pwrdm_clear_all_prev_pwrst(per_pwrdm);
356
Kevin Hilman8bd22942009-05-28 10:56:16 -0700357 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
358 switch (mpu_next_state) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530359 case PWRDM_POWER_ON:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700360 case PWRDM_POWER_RET:
361 /* No need to save context */
362 save_state = 0;
363 break;
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530364 case PWRDM_POWER_OFF:
365 save_state = 3;
366 break;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700367 default:
368 /* Invalid state */
369 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
370 return;
371 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300372 pwrdm_pre_transition();
373
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530374 /* NEON control */
375 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
Jouni Hogander71391782008-10-28 10:59:05 +0200376 pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530377
Mike Chan40742fa2010-05-03 16:04:06 -0700378 /* Enable IO-PAD and IO-CHAIN wakeups */
Kevin Hilman658ce972008-11-04 20:50:52 -0800379 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
Tero Kristoecf157d2008-12-01 13:17:29 +0200380 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
Kevin Hilmand5c47d72010-08-10 16:04:35 -0700381 if (omap3_has_io_wakeup() &&
382 (per_next_state < PWRDM_POWER_ON ||
383 core_next_state < PWRDM_POWER_ON)) {
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600384 prm_set_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
Mike Chan40742fa2010-05-03 16:04:06 -0700385 omap3_enable_io_chain();
386 }
387
388 /* PER */
Kevin Hilman658ce972008-11-04 20:50:52 -0800389 if (per_next_state < PWRDM_POWER_ON) {
Kevin Hilman658ce972008-11-04 20:50:52 -0800390 omap_uart_prepare_idle(2);
Kevin Hilman43ffcd92009-01-27 11:09:24 -0800391 omap2_gpio_prepare_for_idle(per_next_state);
Kevin Hilmane7410cf2010-09-08 16:37:42 -0700392 if (per_next_state == PWRDM_POWER_OFF)
Tero Kristoecf157d2008-12-01 13:17:29 +0200393 omap3_per_save_context();
Kevin Hilman658ce972008-11-04 20:50:52 -0800394 }
395
396 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530397 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530398 omap_uart_prepare_idle(0);
399 omap_uart_prepare_idle(1);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530400 if (core_next_state == PWRDM_POWER_OFF) {
401 omap3_core_save_context();
402 omap3_prcm_save_context();
403 }
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530404 }
Mike Chan40742fa2010-05-03 16:04:06 -0700405
Tero Kristof18cc2f2009-10-23 19:03:50 +0300406 omap3_intc_prepare_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700407
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530408 /*
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530409 * On EMU/HS devices ROM code restores a SRDC value
410 * from scratchpad which has automatic self refresh on timeout
411 * of AUTO_CNT = 1 enabled. This takes care of errata 1.142.
412 * Hence store/restore the SDRC_POWER register here.
413 */
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300414 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
415 omap_type() != OMAP2_DEVICE_TYPE_GP &&
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530416 core_next_state == PWRDM_POWER_OFF)
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300417 sdrc_pwr = sdrc_read_reg(SDRC_POWER);
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300418
419 /*
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530420 * omap3_arm_context is the location where ARM registers
421 * get saved. The restore path then reads from this
422 * location and restores them back.
423 */
424 _omap_sram_idle(omap3_arm_context, save_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700425 cpu_init();
426
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530427 /* Restore normal SDRC POWER settings */
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300428 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
429 omap_type() != OMAP2_DEVICE_TYPE_GP &&
430 core_next_state == PWRDM_POWER_OFF)
431 sdrc_write_reg(sdrc_pwr, SDRC_POWER);
432
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530433 /* Restore table entry modified during MMU restoration */
434 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
435 restore_table_entry();
436
Kevin Hilman658ce972008-11-04 20:50:52 -0800437 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530438 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530439 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
440 if (core_prev_state == PWRDM_POWER_OFF) {
441 omap3_core_restore_context();
442 omap3_prcm_restore_context();
443 omap3_sram_restore_context();
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +0300444 omap2_sms_restore_context();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530445 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800446 omap_uart_resume_idle(0);
447 omap_uart_resume_idle(1);
448 if (core_next_state == PWRDM_POWER_OFF)
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600449 prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF_MASK,
Kevin Hilman658ce972008-11-04 20:50:52 -0800450 OMAP3430_GR_MOD,
451 OMAP3_PRM_VOLTCTRL_OFFSET);
452 }
Tero Kristof18cc2f2009-10-23 19:03:50 +0300453 omap3_intc_resume_idle();
Kevin Hilman658ce972008-11-04 20:50:52 -0800454
455 /* PER */
456 if (per_next_state < PWRDM_POWER_ON) {
457 per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
Kevin Hilman43ffcd92009-01-27 11:09:24 -0800458 omap2_gpio_resume_after_idle();
459 if (per_prev_state == PWRDM_POWER_OFF)
Kevin Hilman658ce972008-11-04 20:50:52 -0800460 omap3_per_restore_context();
Tero Kristoecf157d2008-12-01 13:17:29 +0200461 omap_uart_resume_idle(2);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530462 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300463
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200464 /* Disable IO-PAD and IO-CHAIN wakeup */
Kevin Hilman58a55592010-08-16 09:21:19 +0300465 if (omap3_has_io_wakeup() &&
466 (per_next_state < PWRDM_POWER_ON ||
467 core_next_state < PWRDM_POWER_ON)) {
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600468 prm_clear_mod_reg_bits(OMAP3430_EN_IO_MASK, WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200469 omap3_disable_io_chain();
470 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800471
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300472 pwrdm_post_transition();
473
Tero Kristoc16c3f62008-12-11 16:46:57 +0200474 omap2_clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700475}
476
Rajendra Nayak20b01662008-10-08 17:31:22 +0530477int omap3_can_sleep(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700478{
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700479 if (!sleep_while_idle)
480 return 0;
Kevin Hilman4af40162009-02-04 10:51:40 -0800481 if (!omap_uart_can_sleep())
482 return 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700483 return 1;
484}
485
Kevin Hilman8bd22942009-05-28 10:56:16 -0700486static void omap3_pm_idle(void)
487{
488 local_irq_disable();
489 local_fiq_disable();
490
491 if (!omap3_can_sleep())
492 goto out;
493
Tero Kristocf228542009-03-20 15:21:02 +0200494 if (omap_irq_pending() || need_resched())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700495 goto out;
496
497 omap_sram_idle();
498
499out:
500 local_fiq_enable();
501 local_irq_enable();
502}
503
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700504#ifdef CONFIG_SUSPEND
Tero Kristo24662112009-03-05 16:32:23 +0200505static suspend_state_t suspend_state;
506
Kevin Hilman8bd22942009-05-28 10:56:16 -0700507static int omap3_pm_prepare(void)
508{
509 disable_hlt();
510 return 0;
511}
512
513static int omap3_pm_suspend(void)
514{
515 struct power_state *pwrst;
516 int state, ret = 0;
517
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200518 if (wakeup_timer_seconds || wakeup_timer_milliseconds)
519 omap2_pm_wakeup_on_timer(wakeup_timer_seconds,
520 wakeup_timer_milliseconds);
Kevin Hilmand7814e42009-10-06 14:30:23 -0700521
Kevin Hilman8bd22942009-05-28 10:56:16 -0700522 /* Read current next_pwrsts */
523 list_for_each_entry(pwrst, &pwrst_list, node)
524 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
525 /* Set ones wanted by suspend */
526 list_for_each_entry(pwrst, &pwrst_list, node) {
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530527 if (omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
Kevin Hilman8bd22942009-05-28 10:56:16 -0700528 goto restore;
529 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
530 goto restore;
531 }
532
Kevin Hilman4af40162009-02-04 10:51:40 -0800533 omap_uart_prepare_suspend();
Tero Kristo2bbe3af2009-10-23 19:03:48 +0300534 omap3_intc_suspend();
535
Kevin Hilman8bd22942009-05-28 10:56:16 -0700536 omap_sram_idle();
537
538restore:
539 /* Restore next_pwrsts */
540 list_for_each_entry(pwrst, &pwrst_list, node) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700541 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
542 if (state > pwrst->next_state) {
543 printk(KERN_INFO "Powerdomain (%s) didn't enter "
544 "target state %d\n",
545 pwrst->pwrdm->name, pwrst->next_state);
546 ret = -1;
547 }
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530548 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700549 }
550 if (ret)
551 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
552 else
553 printk(KERN_INFO "Successfully put all powerdomains "
554 "to target state\n");
555
556 return ret;
557}
558
Tero Kristo24662112009-03-05 16:32:23 +0200559static int omap3_pm_enter(suspend_state_t unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700560{
561 int ret = 0;
562
Tero Kristo24662112009-03-05 16:32:23 +0200563 switch (suspend_state) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700564 case PM_SUSPEND_STANDBY:
565 case PM_SUSPEND_MEM:
566 ret = omap3_pm_suspend();
567 break;
568 default:
569 ret = -EINVAL;
570 }
571
572 return ret;
573}
574
575static void omap3_pm_finish(void)
576{
577 enable_hlt();
578}
579
Tero Kristo24662112009-03-05 16:32:23 +0200580/* Hooks to enable / disable UART interrupts during suspend */
581static int omap3_pm_begin(suspend_state_t state)
582{
583 suspend_state = state;
584 omap_uart_enable_irqs(0);
585 return 0;
586}
587
588static void omap3_pm_end(void)
589{
590 suspend_state = PM_SUSPEND_ON;
591 omap_uart_enable_irqs(1);
592 return;
593}
594
Kevin Hilman8bd22942009-05-28 10:56:16 -0700595static struct platform_suspend_ops omap_pm_ops = {
Tero Kristo24662112009-03-05 16:32:23 +0200596 .begin = omap3_pm_begin,
597 .end = omap3_pm_end,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700598 .prepare = omap3_pm_prepare,
599 .enter = omap3_pm_enter,
600 .finish = omap3_pm_finish,
601 .valid = suspend_valid_only_mem,
602};
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700603#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700604
Kevin Hilman1155e422008-11-25 11:48:24 -0800605
606/**
607 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
608 * retention
609 *
610 * In cases where IVA2 is activated by bootcode, it may prevent
611 * full-chip retention or off-mode because it is not idle. This
612 * function forces the IVA2 into idle state so it can go
613 * into retention/off and thus allow full-chip retention/off.
614 *
615 **/
616static void __init omap3_iva_idle(void)
617{
618 /* ensure IVA2 clock is disabled */
619 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
620
621 /* if no clock activity, nothing else to do */
622 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
623 OMAP3430_CLKACTIVITY_IVA2_MASK))
624 return;
625
626 /* Reset IVA2 */
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600627 prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
628 OMAP3430_RST2_IVA2_MASK |
629 OMAP3430_RST3_IVA2_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700630 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800631
632 /* Enable IVA2 clock */
Kevin Hilmandfa6d6f2010-02-24 12:05:48 -0700633 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
Kevin Hilman1155e422008-11-25 11:48:24 -0800634 OMAP3430_IVA2_MOD, CM_FCLKEN);
635
636 /* Set IVA2 boot mode to 'idle' */
637 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
638 OMAP343X_CONTROL_IVA2_BOOTMOD);
639
640 /* Un-reset IVA2 */
Abhijit Pagare37903002010-01-26 20:12:51 -0700641 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800642
643 /* Disable IVA2 clock */
644 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
645
646 /* Reset IVA2 */
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600647 prm_write_mod_reg(OMAP3430_RST1_IVA2_MASK |
648 OMAP3430_RST2_IVA2_MASK |
649 OMAP3430_RST3_IVA2_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700650 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800651}
652
Kevin Hilman8111b222009-04-28 15:27:44 -0700653static void __init omap3_d2d_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700654{
Kevin Hilman8111b222009-04-28 15:27:44 -0700655 u16 mask, padconf;
656
657 /* In a stand alone OMAP3430 where there is not a stacked
658 * modem for the D2D Idle Ack and D2D MStandby must be pulled
659 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
660 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
661 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
662 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
663 padconf |= mask;
664 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
665
666 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
667 padconf |= mask;
668 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
669
Kevin Hilman8bd22942009-05-28 10:56:16 -0700670 /* reset modem */
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600671 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON_MASK |
672 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST_MASK,
Abhijit Pagare37903002010-01-26 20:12:51 -0700673 CORE_MOD, OMAP2_RM_RSTCTRL);
674 prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman8111b222009-04-28 15:27:44 -0700675}
Kevin Hilman8bd22942009-05-28 10:56:16 -0700676
Kevin Hilman8111b222009-04-28 15:27:44 -0700677static void __init prcm_setup_regs(void)
678{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700679 /* XXX Reset all wkdeps. This should be done when initializing
680 * powerdomains */
681 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
682 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
683 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
684 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
685 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
686 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
687 if (omap_rev() > OMAP3430_REV_ES1_0) {
688 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
689 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
690 } else
691 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
692
693 /*
694 * Enable interface clock autoidle for all modules.
695 * Note that in the long run this should be done by clockfw
696 */
697 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600698 OMAP3430_AUTO_MODEM_MASK |
699 OMAP3430ES2_AUTO_MMC3_MASK |
700 OMAP3430ES2_AUTO_ICR_MASK |
701 OMAP3430_AUTO_AES2_MASK |
702 OMAP3430_AUTO_SHA12_MASK |
703 OMAP3430_AUTO_DES2_MASK |
704 OMAP3430_AUTO_MMC2_MASK |
705 OMAP3430_AUTO_MMC1_MASK |
706 OMAP3430_AUTO_MSPRO_MASK |
707 OMAP3430_AUTO_HDQ_MASK |
708 OMAP3430_AUTO_MCSPI4_MASK |
709 OMAP3430_AUTO_MCSPI3_MASK |
710 OMAP3430_AUTO_MCSPI2_MASK |
711 OMAP3430_AUTO_MCSPI1_MASK |
712 OMAP3430_AUTO_I2C3_MASK |
713 OMAP3430_AUTO_I2C2_MASK |
714 OMAP3430_AUTO_I2C1_MASK |
715 OMAP3430_AUTO_UART2_MASK |
716 OMAP3430_AUTO_UART1_MASK |
717 OMAP3430_AUTO_GPT11_MASK |
718 OMAP3430_AUTO_GPT10_MASK |
719 OMAP3430_AUTO_MCBSP5_MASK |
720 OMAP3430_AUTO_MCBSP1_MASK |
721 OMAP3430ES1_AUTO_FAC_MASK | /* This is es1 only */
722 OMAP3430_AUTO_MAILBOXES_MASK |
723 OMAP3430_AUTO_OMAPCTRL_MASK |
724 OMAP3430ES1_AUTO_FSHOSTUSB_MASK |
725 OMAP3430_AUTO_HSOTGUSB_MASK |
726 OMAP3430_AUTO_SAD2D_MASK |
727 OMAP3430_AUTO_SSI_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700728 CORE_MOD, CM_AUTOIDLE1);
729
730 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600731 OMAP3430_AUTO_PKA_MASK |
732 OMAP3430_AUTO_AES1_MASK |
733 OMAP3430_AUTO_RNG_MASK |
734 OMAP3430_AUTO_SHA11_MASK |
735 OMAP3430_AUTO_DES1_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700736 CORE_MOD, CM_AUTOIDLE2);
737
738 if (omap_rev() > OMAP3430_REV_ES1_0) {
739 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600740 OMAP3430_AUTO_MAD2D_MASK |
741 OMAP3430ES2_AUTO_USBTLL_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700742 CORE_MOD, CM_AUTOIDLE3);
743 }
744
745 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600746 OMAP3430_AUTO_WDT2_MASK |
747 OMAP3430_AUTO_WDT1_MASK |
748 OMAP3430_AUTO_GPIO1_MASK |
749 OMAP3430_AUTO_32KSYNC_MASK |
750 OMAP3430_AUTO_GPT12_MASK |
751 OMAP3430_AUTO_GPT1_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700752 WKUP_MOD, CM_AUTOIDLE);
753
754 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600755 OMAP3430_AUTO_DSS_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700756 OMAP3430_DSS_MOD,
757 CM_AUTOIDLE);
758
759 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600760 OMAP3430_AUTO_CAM_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700761 OMAP3430_CAM_MOD,
762 CM_AUTOIDLE);
763
764 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600765 OMAP3430_AUTO_GPIO6_MASK |
766 OMAP3430_AUTO_GPIO5_MASK |
767 OMAP3430_AUTO_GPIO4_MASK |
768 OMAP3430_AUTO_GPIO3_MASK |
769 OMAP3430_AUTO_GPIO2_MASK |
770 OMAP3430_AUTO_WDT3_MASK |
771 OMAP3430_AUTO_UART3_MASK |
772 OMAP3430_AUTO_GPT9_MASK |
773 OMAP3430_AUTO_GPT8_MASK |
774 OMAP3430_AUTO_GPT7_MASK |
775 OMAP3430_AUTO_GPT6_MASK |
776 OMAP3430_AUTO_GPT5_MASK |
777 OMAP3430_AUTO_GPT4_MASK |
778 OMAP3430_AUTO_GPT3_MASK |
779 OMAP3430_AUTO_GPT2_MASK |
780 OMAP3430_AUTO_MCBSP4_MASK |
781 OMAP3430_AUTO_MCBSP3_MASK |
782 OMAP3430_AUTO_MCBSP2_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700783 OMAP3430_PER_MOD,
784 CM_AUTOIDLE);
785
786 if (omap_rev() > OMAP3430_REV_ES1_0) {
787 cm_write_mod_reg(
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600788 OMAP3430ES2_AUTO_USBHOST_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700789 OMAP3430ES2_USBHOST_MOD,
790 CM_AUTOIDLE);
791 }
792
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600793 omap_ctrl_writel(OMAP3430_AUTOIDLE_MASK, OMAP2_CONTROL_SYSCONFIG);
Tero Kristob296c812009-10-23 19:03:49 +0300794
Kevin Hilman8bd22942009-05-28 10:56:16 -0700795 /*
796 * Set all plls to autoidle. This is needed until autoidle is
797 * enabled by clockfw
798 */
799 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
800 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
801 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
802 MPU_MOD,
803 CM_AUTOIDLE2);
804 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
805 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
806 PLL_MOD,
807 CM_AUTOIDLE);
808 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
809 PLL_MOD,
810 CM_AUTOIDLE2);
811
812 /*
813 * Enable control of expternal oscillator through
814 * sys_clkreq. In the long run clock framework should
815 * take care of this.
816 */
817 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
818 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
819 OMAP3430_GR_MOD,
820 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
821
822 /* setup wakup source */
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600823 prm_write_mod_reg(OMAP3430_EN_IO_MASK | OMAP3430_EN_GPIO1_MASK |
824 OMAP3430_EN_GPT1_MASK | OMAP3430_EN_GPT12_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700825 WKUP_MOD, PM_WKEN);
826 /* No need to write EN_IO, that is always enabled */
Paul Walmsley275f6752010-05-18 18:40:23 -0600827 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO1_MASK |
828 OMAP3430_GRPSEL_GPT1_MASK |
829 OMAP3430_GRPSEL_GPT12_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700830 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
831 /* For some reason IO doesn't generate wakeup event even if
832 * it is selected to mpu wakeup goup */
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600833 prm_write_mod_reg(OMAP3430_IO_EN_MASK | OMAP3430_WKUP_EN_MASK,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700834 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
Kevin Hilman1155e422008-11-25 11:48:24 -0800835
Subramani Venkateshb92c5722009-12-22 15:07:50 +0530836 /* Enable PM_WKEN to support DSS LPR */
Paul Walmsley2bc4ef72010-05-18 18:47:24 -0600837 prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS_MASK,
Subramani Venkateshb92c5722009-12-22 15:07:50 +0530838 OMAP3430_DSS_MOD, PM_WKEN);
839
Kevin Hilmanb427f922009-10-22 14:48:13 -0700840 /* Enable wakeups in PER */
Paul Walmsley2fd0f752010-05-18 18:40:23 -0600841 prm_write_mod_reg(OMAP3430_EN_GPIO2_MASK | OMAP3430_EN_GPIO3_MASK |
842 OMAP3430_EN_GPIO4_MASK | OMAP3430_EN_GPIO5_MASK |
843 OMAP3430_EN_GPIO6_MASK | OMAP3430_EN_UART3_MASK |
844 OMAP3430_EN_MCBSP2_MASK | OMAP3430_EN_MCBSP3_MASK |
845 OMAP3430_EN_MCBSP4_MASK,
Kevin Hilmanb427f922009-10-22 14:48:13 -0700846 OMAP3430_PER_MOD, PM_WKEN);
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000847 /* and allow them to wake up MPU */
Paul Walmsley275f6752010-05-18 18:40:23 -0600848 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2_MASK |
849 OMAP3430_GRPSEL_GPIO3_MASK |
850 OMAP3430_GRPSEL_GPIO4_MASK |
851 OMAP3430_GRPSEL_GPIO5_MASK |
852 OMAP3430_GRPSEL_GPIO6_MASK |
853 OMAP3430_GRPSEL_UART3_MASK |
854 OMAP3430_GRPSEL_MCBSP2_MASK |
855 OMAP3430_GRPSEL_MCBSP3_MASK |
856 OMAP3430_GRPSEL_MCBSP4_MASK,
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000857 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
858
Kevin Hilmand3fd3292009-05-05 16:34:25 -0700859 /* Don't attach IVA interrupts */
860 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
861 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
862 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
863 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
864
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700865 /* Clear any pending 'reset' flags */
Abhijit Pagare37903002010-01-26 20:12:51 -0700866 prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
867 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
868 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
869 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
870 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
871 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
872 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700873
Kevin Hilman014c46d2009-04-27 07:50:23 -0700874 /* Clear any pending PRCM interrupts */
875 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
876
Kevin Hilman1155e422008-11-25 11:48:24 -0800877 omap3_iva_idle();
Kevin Hilman8111b222009-04-28 15:27:44 -0700878 omap3_d2d_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700879}
880
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700881void omap3_pm_off_mode_enable(int enable)
882{
883 struct power_state *pwrst;
884 u32 state;
885
886 if (enable)
887 state = PWRDM_POWER_OFF;
888 else
889 state = PWRDM_POWER_RET;
890
Sanjeev Premi6af83b32010-01-28 23:16:43 +0530891#ifdef CONFIG_CPU_IDLE
892 omap3_cpuidle_update_states();
893#endif
894
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700895 list_for_each_entry(pwrst, &pwrst_list, node) {
896 pwrst->next_state = state;
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530897 omap_set_pwrdm_state(pwrst->pwrdm, state);
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700898 }
899}
900
Tero Kristo68d47782008-11-26 12:26:24 +0200901int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
902{
903 struct power_state *pwrst;
904
905 list_for_each_entry(pwrst, &pwrst_list, node) {
906 if (pwrst->pwrdm == pwrdm)
907 return pwrst->next_state;
908 }
909 return -EINVAL;
910}
911
912int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
913{
914 struct power_state *pwrst;
915
916 list_for_each_entry(pwrst, &pwrst_list, node) {
917 if (pwrst->pwrdm == pwrdm) {
918 pwrst->next_state = state;
919 return 0;
920 }
921 }
922 return -EINVAL;
923}
924
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300925static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700926{
927 struct power_state *pwrst;
928
929 if (!pwrdm->pwrsts)
930 return 0;
931
Ming Leid3d381c2009-08-22 21:20:26 +0800932 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700933 if (!pwrst)
934 return -ENOMEM;
935 pwrst->pwrdm = pwrdm;
936 pwrst->next_state = PWRDM_POWER_RET;
937 list_add(&pwrst->node, &pwrst_list);
938
939 if (pwrdm_has_hdwr_sar(pwrdm))
940 pwrdm_enable_hdwr_sar(pwrdm);
941
Santosh Shilimkareb6a2c72010-09-15 01:04:01 +0530942 return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700943}
944
945/*
946 * Enable hw supervised mode for all clockdomains if it's
947 * supported. Initiate sleep transition for other clockdomains, if
948 * they are not used
949 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300950static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700951{
Paul Walmsley369d5612010-01-26 20:13:01 -0700952 clkdm_clear_all_wkdeps(clkdm);
953 clkdm_clear_all_sleepdeps(clkdm);
954
Kevin Hilman8bd22942009-05-28 10:56:16 -0700955 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
956 omap2_clkdm_allow_idle(clkdm);
957 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
958 atomic_read(&clkdm->usecount) == 0)
959 omap2_clkdm_sleep(clkdm);
960 return 0;
961}
962
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530963void omap_push_sram_idle(void)
964{
965 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
966 omap34xx_cpu_suspend_sz);
Tero Kristo27d59a42008-10-13 13:15:00 +0300967 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
968 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
969 save_secure_ram_context_sz);
Rajendra Nayak3231fc82008-09-26 17:49:14 +0530970}
971
Kevin Hilman7cc515f2009-06-10 09:02:25 -0700972static int __init omap3_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700973{
974 struct power_state *pwrst, *tmp;
Paul Walmsley55ed9692010-01-26 20:12:59 -0700975 struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700976 int ret;
977
978 if (!cpu_is_omap34xx())
979 return -ENODEV;
980
981 printk(KERN_ERR "Power Management for TI OMAP3.\n");
982
983 /* XXX prcm_setup_regs needs to be before enabling hw
984 * supervised mode for powerdomains */
985 prcm_setup_regs();
986
987 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
988 (irq_handler_t)prcm_interrupt_handler,
989 IRQF_DISABLED, "prcm", NULL);
990 if (ret) {
991 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
992 INT_34XX_PRCM_MPU_IRQ);
993 goto err1;
994 }
995
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300996 ret = pwrdm_for_each(pwrdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700997 if (ret) {
998 printk(KERN_ERR "Failed to setup powerdomains\n");
999 goto err2;
1000 }
1001
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +03001002 (void) clkdm_for_each(clkdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -07001003
1004 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
1005 if (mpu_pwrdm == NULL) {
1006 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
1007 goto err2;
1008 }
1009
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301010 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
1011 per_pwrdm = pwrdm_lookup("per_pwrdm");
1012 core_pwrdm = pwrdm_lookup("core_pwrdm");
Tero Kristoc16c3f62008-12-11 16:46:57 +02001013 cam_pwrdm = pwrdm_lookup("cam_pwrdm");
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301014
Paul Walmsley55ed9692010-01-26 20:12:59 -07001015 neon_clkdm = clkdm_lookup("neon_clkdm");
1016 mpu_clkdm = clkdm_lookup("mpu_clkdm");
1017 per_clkdm = clkdm_lookup("per_clkdm");
1018 core_clkdm = clkdm_lookup("core_clkdm");
1019
Rajendra Nayak3231fc82008-09-26 17:49:14 +05301020 omap_push_sram_idle();
Kevin Hilman10f90ed2009-06-24 11:39:18 -07001021#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -07001022 suspend_set_ops(&omap_pm_ops);
Kevin Hilman10f90ed2009-06-24 11:39:18 -07001023#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -07001024
1025 pm_idle = omap3_pm_idle;
Kalle Jokiniemi03433712008-09-26 11:04:20 +03001026 omap3_idle_init();
Kevin Hilman8bd22942009-05-28 10:56:16 -07001027
Paul Walmsley55ed9692010-01-26 20:12:59 -07001028 clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
Tero Kristo27d59a42008-10-13 13:15:00 +03001029 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
1030 omap3_secure_ram_storage =
1031 kmalloc(0x803F, GFP_KERNEL);
1032 if (!omap3_secure_ram_storage)
1033 printk(KERN_ERR "Memory allocation failed when"
1034 "allocating for secure sram context\n");
Tero Kristo27d59a42008-10-13 13:15:00 +03001035
Tero Kristo9d971402008-12-12 11:20:05 +02001036 local_irq_disable();
1037 local_fiq_disable();
1038
1039 omap_dma_global_context_save();
1040 omap3_save_secure_ram_context(PWRDM_POWER_ON);
1041 omap_dma_global_context_restore();
1042
1043 local_irq_enable();
1044 local_fiq_enable();
1045 }
1046
1047 omap3_save_scratchpad_contents();
Kevin Hilman8bd22942009-05-28 10:56:16 -07001048err1:
1049 return ret;
1050err2:
1051 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
1052 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
1053 list_del(&pwrst->node);
1054 kfree(pwrst);
1055 }
1056 return ret;
1057}
1058
1059late_initcall(omap3_pm_init);