blob: e76af5b532a01a692a99c99e45a86a62e1f1d542 [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 Hilmand7814e42009-10-06 14:30:23 -070041#include <plat/dmtimer.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070042
Rajendra Nayak57f277b2008-09-26 17:49:34 +053043#include <asm/tlbflush.h>
44
Kevin Hilman8bd22942009-05-28 10:56:16 -070045#include "cm.h"
46#include "cm-regbits-34xx.h"
47#include "prm-regbits-34xx.h"
48
49#include "prm.h"
50#include "pm.h"
Tero Kristo13a6fe0f2008-10-13 13:17:06 +030051#include "sdrc.h"
52
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053053/* Scratchpad offsets */
54#define OMAP343X_TABLE_ADDRESS_OFFSET 0x31
55#define OMAP343X_TABLE_VALUE_OFFSET 0x30
56#define OMAP343X_CONTROL_REG_VALUE_OFFSET 0x32
57
Kevin Hilmanc40552b2009-10-06 14:25:09 -070058u32 enable_off_mode;
59u32 sleep_while_idle;
Kevin Hilmand7814e42009-10-06 14:30:23 -070060u32 wakeup_timer_seconds;
Ari Kauppi8e2efde2010-03-23 09:04:59 +020061u32 wakeup_timer_milliseconds;
Kevin Hilmanc40552b2009-10-06 14:25:09 -070062
Kevin Hilman8bd22942009-05-28 10:56:16 -070063struct power_state {
64 struct powerdomain *pwrdm;
65 u32 next_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070066#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -070067 u32 saved_state;
Kevin Hilman10f90ed2009-06-24 11:39:18 -070068#endif
Kevin Hilman8bd22942009-05-28 10:56:16 -070069 struct list_head node;
70};
71
72static LIST_HEAD(pwrst_list);
73
74static void (*_omap_sram_idle)(u32 *addr, int save_state);
75
Tero Kristo27d59a42008-10-13 13:15:00 +030076static int (*_omap_save_secure_sram)(u32 *addr);
77
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053078static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
79static struct powerdomain *core_pwrdm, *per_pwrdm;
Tero Kristoc16c3f62008-12-11 16:46:57 +020080static struct powerdomain *cam_pwrdm;
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +053081
Rajendra Nayak2f5939c2008-09-26 17:50:07 +053082static inline void omap3_per_save_context(void)
83{
84 omap_gpio_save_context();
85}
86
87static inline void omap3_per_restore_context(void)
88{
89 omap_gpio_restore_context();
90}
91
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +020092static void omap3_enable_io_chain(void)
93{
94 int timeout = 0;
95
96 if (omap_rev() >= OMAP3430_REV_ES3_1) {
97 prm_set_mod_reg_bits(OMAP3430_EN_IO_CHAIN, WKUP_MOD, PM_WKEN);
98 /* Do a readback to assure write has been done */
99 prm_read_mod_reg(WKUP_MOD, PM_WKEN);
100
101 while (!(prm_read_mod_reg(WKUP_MOD, PM_WKST) &
102 OMAP3430_ST_IO_CHAIN)) {
103 timeout++;
104 if (timeout > 1000) {
105 printk(KERN_ERR "Wake up daisy chain "
106 "activation failed.\n");
107 return;
108 }
109 prm_set_mod_reg_bits(OMAP3430_ST_IO_CHAIN,
110 WKUP_MOD, PM_WKST);
111 }
112 }
113}
114
115static void omap3_disable_io_chain(void)
116{
117 if (omap_rev() >= OMAP3430_REV_ES3_1)
118 prm_clear_mod_reg_bits(OMAP3430_EN_IO_CHAIN, WKUP_MOD, PM_WKEN);
119}
120
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530121static void omap3_core_save_context(void)
122{
123 u32 control_padconf_off;
124
125 /* Save the padconf registers */
126 control_padconf_off = omap_ctrl_readl(OMAP343X_CONTROL_PADCONF_OFF);
127 control_padconf_off |= START_PADCONF_SAVE;
128 omap_ctrl_writel(control_padconf_off, OMAP343X_CONTROL_PADCONF_OFF);
129 /* wait for the save to complete */
Roel Kluin1b6e8212010-01-08 10:29:07 -0800130 while (!(omap_ctrl_readl(OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS)
131 & PADCONF_SAVE_DONE))
Tero Kristodccaad82009-11-17 18:34:53 +0200132 udelay(1);
133
134 /*
135 * Force write last pad into memory, as this can fail in some
136 * cases according to erratas 1.157, 1.185
137 */
138 omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
139 OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
140
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530141 /* Save the Interrupt controller context */
142 omap_intc_save_context();
143 /* Save the GPMC context */
144 omap3_gpmc_save_context();
145 /* Save the system control module context, padconf already save above*/
146 omap3_control_save_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000147 omap_dma_global_context_save();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530148}
149
150static void omap3_core_restore_context(void)
151{
152 /* Restore the control module context, padconf restored by h/w */
153 omap3_control_restore_context();
154 /* Restore the GPMC context */
155 omap3_gpmc_restore_context();
156 /* Restore the interrupt controller context */
157 omap_intc_restore_context();
Tero Kristof2d11852008-08-28 13:13:31 +0000158 omap_dma_global_context_restore();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530159}
160
Tero Kristo9d971402008-12-12 11:20:05 +0200161/*
162 * FIXME: This function should be called before entering off-mode after
163 * OMAP3 secure services have been accessed. Currently it is only called
164 * once during boot sequence, but this works as we are not using secure
165 * services.
166 */
Tero Kristo27d59a42008-10-13 13:15:00 +0300167static void omap3_save_secure_ram_context(u32 target_mpu_state)
168{
169 u32 ret;
170
171 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
Tero Kristo27d59a42008-10-13 13:15:00 +0300172 /*
173 * MPU next state must be set to POWER_ON temporarily,
174 * otherwise the WFI executed inside the ROM code
175 * will hang the system.
176 */
177 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
178 ret = _omap_save_secure_sram((u32 *)
179 __pa(omap3_secure_ram_storage));
180 pwrdm_set_next_pwrst(mpu_pwrdm, target_mpu_state);
181 /* Following is for error tracking, it should not happen */
182 if (ret) {
183 printk(KERN_ERR "save_secure_sram() returns %08x\n",
184 ret);
185 while (1)
186 ;
187 }
188 }
189}
190
Jon Hunter77da2d92009-06-27 00:07:25 -0500191/*
192 * PRCM Interrupt Handler Helper Function
193 *
194 * The purpose of this function is to clear any wake-up events latched
195 * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
196 * may occur whilst attempting to clear a PM_WKST_x register and thus
197 * set another bit in this register. A while loop is used to ensure
198 * that any peripheral wake-up events occurring while attempting to
199 * clear the PM_WKST_x are detected and cleared.
200 */
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700201static int prcm_clear_mod_irqs(s16 module, u8 regs)
Jon Hunter77da2d92009-06-27 00:07:25 -0500202{
Vikram Pandita71a80772009-07-17 19:33:09 -0500203 u32 wkst, fclk, iclk, clken;
Jon Hunter77da2d92009-06-27 00:07:25 -0500204 u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
205 u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
206 u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
Paul Walmsley5d805972009-07-22 10:18:07 -0700207 u16 grpsel_off = (regs == 3) ?
208 OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700209 int c = 0;
Jon Hunter77da2d92009-06-27 00:07:25 -0500210
211 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley5d805972009-07-22 10:18:07 -0700212 wkst &= prm_read_mod_reg(module, grpsel_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500213 if (wkst) {
214 iclk = cm_read_mod_reg(module, iclk_off);
215 fclk = cm_read_mod_reg(module, fclk_off);
216 while (wkst) {
Vikram Pandita71a80772009-07-17 19:33:09 -0500217 clken = wkst;
218 cm_set_mod_reg_bits(clken, module, iclk_off);
219 /*
220 * For USBHOST, we don't know whether HOST1 or
221 * HOST2 woke us up, so enable both f-clocks
222 */
223 if (module == OMAP3430ES2_USBHOST_MOD)
224 clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
225 cm_set_mod_reg_bits(clken, module, fclk_off);
Jon Hunter77da2d92009-06-27 00:07:25 -0500226 prm_write_mod_reg(wkst, module, wkst_off);
227 wkst = prm_read_mod_reg(module, wkst_off);
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700228 c++;
Jon Hunter77da2d92009-06-27 00:07:25 -0500229 }
230 cm_write_mod_reg(iclk, module, iclk_off);
231 cm_write_mod_reg(fclk, module, fclk_off);
232 }
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700233
234 return c;
235}
236
237static int _prcm_int_handle_wakeup(void)
238{
239 int c;
240
241 c = prcm_clear_mod_irqs(WKUP_MOD, 1);
242 c += prcm_clear_mod_irqs(CORE_MOD, 1);
243 c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1);
244 if (omap_rev() > OMAP3430_REV_ES1_0) {
245 c += prcm_clear_mod_irqs(CORE_MOD, 3);
246 c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1);
247 }
248
249 return c;
Jon Hunter77da2d92009-06-27 00:07:25 -0500250}
251
252/*
253 * PRCM Interrupt Handler
254 *
255 * The PRM_IRQSTATUS_MPU register indicates if there are any pending
256 * interrupts from the PRCM for the MPU. These bits must be cleared in
257 * order to clear the PRCM interrupt. The PRCM interrupt handler is
258 * implemented to simply clear the PRM_IRQSTATUS_MPU in order to clear
259 * the PRCM interrupt. Please note that bit 0 of the PRM_IRQSTATUS_MPU
260 * register indicates that a wake-up event is pending for the MPU and
261 * this bit can only be cleared if the all the wake-up events latched
262 * in the various PM_WKST_x registers have been cleared. The interrupt
263 * handler is implemented using a do-while loop so that if a wake-up
264 * event occurred during the processing of the prcm interrupt handler
265 * (setting a bit in the corresponding PM_WKST_x register and thus
266 * preventing us from clearing bit 0 of the PRM_IRQSTATUS_MPU register)
267 * this would be handled.
268 */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700269static irqreturn_t prcm_interrupt_handler (int irq, void *dev_id)
270{
Kevin Hilmand6290a32010-04-26 14:59:09 -0700271 u32 irqenable_mpu, irqstatus_mpu;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700272 int c = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700273
Kevin Hilmand6290a32010-04-26 14:59:09 -0700274 irqenable_mpu = prm_read_mod_reg(OCP_MOD,
275 OMAP3_PRM_IRQENABLE_MPU_OFFSET);
276 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
277 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
278 irqstatus_mpu &= irqenable_mpu;
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700279
Kevin Hilmand6290a32010-04-26 14:59:09 -0700280 do {
Paul Walmsley8cb0ac92009-07-22 10:29:02 -0700281 if (irqstatus_mpu & (OMAP3430_WKUP_ST | OMAP3430_IO_ST)) {
282 c = _prcm_int_handle_wakeup();
283
284 /*
285 * Is the MPU PRCM interrupt handler racing with the
286 * IVA2 PRCM interrupt handler ?
287 */
288 WARN(c == 0, "prcm: WARNING: PRCM indicated MPU wakeup "
289 "but no wakeup sources are marked\n");
290 } else {
291 /* XXX we need to expand our PRCM interrupt handler */
292 WARN(1, "prcm: WARNING: PRCM interrupt received, but "
293 "no code to handle it (%08x)\n", irqstatus_mpu);
294 }
295
Jon Hunter77da2d92009-06-27 00:07:25 -0500296 prm_write_mod_reg(irqstatus_mpu, OCP_MOD,
297 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700298
Kevin Hilmand6290a32010-04-26 14:59:09 -0700299 irqstatus_mpu = prm_read_mod_reg(OCP_MOD,
300 OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
301 irqstatus_mpu &= irqenable_mpu;
302
303 } while (irqstatus_mpu);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700304
305 return IRQ_HANDLED;
306}
307
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530308static void restore_control_register(u32 val)
309{
310 __asm__ __volatile__ ("mcr p15, 0, %0, c1, c0, 0" : : "r" (val));
311}
312
313/* Function to restore the table entry that was modified for enabling MMU */
314static void restore_table_entry(void)
315{
316 u32 *scratchpad_address;
317 u32 previous_value, control_reg_value;
318 u32 *address;
319
320 scratchpad_address = OMAP2_L4_IO_ADDRESS(OMAP343X_SCRATCHPAD);
321
322 /* Get address of entry that was modified */
323 address = (u32 *)__raw_readl(scratchpad_address +
324 OMAP343X_TABLE_ADDRESS_OFFSET);
325 /* Get the previous value which needs to be restored */
326 previous_value = __raw_readl(scratchpad_address +
327 OMAP343X_TABLE_VALUE_OFFSET);
328 address = __va(address);
329 *address = previous_value;
330 flush_tlb_all();
331 control_reg_value = __raw_readl(scratchpad_address
332 + OMAP343X_CONTROL_REG_VALUE_OFFSET);
333 /* This will enable caches and prediction */
334 restore_control_register(control_reg_value);
335}
336
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530337void omap_sram_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700338{
339 /* Variable to tell what needs to be saved and restored
340 * in omap_sram_idle*/
341 /* save_state = 0 => Nothing to save and restored */
342 /* save_state = 1 => Only L1 and logic lost */
343 /* save_state = 2 => Only L2 lost */
344 /* save_state = 3 => L1, L2 and logic lost */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530345 int save_state = 0;
346 int mpu_next_state = PWRDM_POWER_ON;
347 int per_next_state = PWRDM_POWER_ON;
348 int core_next_state = PWRDM_POWER_ON;
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530349 int core_prev_state, per_prev_state;
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300350 u32 sdrc_pwr = 0;
Tero Kristoecf157d2008-12-01 13:17:29 +0200351 int per_state_modified = 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700352
353 if (!_omap_sram_idle)
354 return;
355
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530356 pwrdm_clear_all_prev_pwrst(mpu_pwrdm);
357 pwrdm_clear_all_prev_pwrst(neon_pwrdm);
358 pwrdm_clear_all_prev_pwrst(core_pwrdm);
359 pwrdm_clear_all_prev_pwrst(per_pwrdm);
360
Kevin Hilman8bd22942009-05-28 10:56:16 -0700361 mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
362 switch (mpu_next_state) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530363 case PWRDM_POWER_ON:
Kevin Hilman8bd22942009-05-28 10:56:16 -0700364 case PWRDM_POWER_RET:
365 /* No need to save context */
366 save_state = 0;
367 break;
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530368 case PWRDM_POWER_OFF:
369 save_state = 3;
370 break;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700371 default:
372 /* Invalid state */
373 printk(KERN_ERR "Invalid mpu state in sram_idle\n");
374 return;
375 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300376 pwrdm_pre_transition();
377
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530378 /* NEON control */
379 if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
Jouni Hogander71391782008-10-28 10:59:05 +0200380 pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530381
Kevin Hilman658ce972008-11-04 20:50:52 -0800382 /* PER */
383 per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
Tero Kristoecf157d2008-12-01 13:17:29 +0200384 core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
Kevin Hilman658ce972008-11-04 20:50:52 -0800385 if (per_next_state < PWRDM_POWER_ON) {
Kevin Hilman658ce972008-11-04 20:50:52 -0800386 omap_uart_prepare_idle(2);
Tero Kristoecf157d2008-12-01 13:17:29 +0200387 omap2_gpio_prepare_for_retention();
388 if (per_next_state == PWRDM_POWER_OFF) {
389 if (core_next_state == PWRDM_POWER_ON) {
390 per_next_state = PWRDM_POWER_RET;
391 pwrdm_set_next_pwrst(per_pwrdm, per_next_state);
392 per_state_modified = 1;
393 } else
394 omap3_per_save_context();
395 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800396 }
397
Tero Kristoc16c3f62008-12-11 16:46:57 +0200398 if (pwrdm_read_pwrst(cam_pwrdm) == PWRDM_POWER_ON)
399 omap2_clkdm_deny_idle(mpu_pwrdm->pwrdm_clkdms[0]);
400
Kevin Hilman658ce972008-11-04 20:50:52 -0800401 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530402 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530403 omap_uart_prepare_idle(0);
404 omap_uart_prepare_idle(1);
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530405 if (core_next_state == PWRDM_POWER_OFF) {
406 omap3_core_save_context();
407 omap3_prcm_save_context();
408 }
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200409 /* Enable IO-PAD and IO-CHAIN wakeups */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530410 prm_set_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200411 omap3_enable_io_chain();
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530412 }
Tero Kristof18cc2f2009-10-23 19:03:50 +0300413 omap3_intc_prepare_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700414
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530415 /*
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530416 * On EMU/HS devices ROM code restores a SRDC value
417 * from scratchpad which has automatic self refresh on timeout
418 * of AUTO_CNT = 1 enabled. This takes care of errata 1.142.
419 * Hence store/restore the SDRC_POWER register here.
420 */
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300421 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
422 omap_type() != OMAP2_DEVICE_TYPE_GP &&
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530423 core_next_state == PWRDM_POWER_OFF)
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300424 sdrc_pwr = sdrc_read_reg(SDRC_POWER);
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300425
426 /*
Rajendra Nayak61255ab2008-09-26 17:49:56 +0530427 * omap3_arm_context is the location where ARM registers
428 * get saved. The restore path then reads from this
429 * location and restores them back.
430 */
431 _omap_sram_idle(omap3_arm_context, save_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700432 cpu_init();
433
Rajendra Nayakf265dc42009-06-09 22:30:41 +0530434 /* Restore normal SDRC POWER settings */
Tero Kristo13a6fe0f2008-10-13 13:17:06 +0300435 if (omap_rev() >= OMAP3430_REV_ES3_0 &&
436 omap_type() != OMAP2_DEVICE_TYPE_GP &&
437 core_next_state == PWRDM_POWER_OFF)
438 sdrc_write_reg(sdrc_pwr, SDRC_POWER);
439
Rajendra Nayak57f277b2008-09-26 17:49:34 +0530440 /* Restore table entry modified during MMU restoration */
441 if (pwrdm_read_prev_pwrst(mpu_pwrdm) == PWRDM_POWER_OFF)
442 restore_table_entry();
443
Kevin Hilman658ce972008-11-04 20:50:52 -0800444 /* CORE */
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530445 if (core_next_state < PWRDM_POWER_ON) {
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530446 core_prev_state = pwrdm_read_prev_pwrst(core_pwrdm);
447 if (core_prev_state == PWRDM_POWER_OFF) {
448 omap3_core_restore_context();
449 omap3_prcm_restore_context();
450 omap3_sram_restore_context();
Kalle Jokiniemi8a917d22009-05-13 13:32:11 +0300451 omap2_sms_restore_context();
Rajendra Nayak2f5939c2008-09-26 17:50:07 +0530452 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800453 omap_uart_resume_idle(0);
454 omap_uart_resume_idle(1);
455 if (core_next_state == PWRDM_POWER_OFF)
456 prm_clear_mod_reg_bits(OMAP3430_AUTO_OFF,
457 OMAP3430_GR_MOD,
458 OMAP3_PRM_VOLTCTRL_OFFSET);
459 }
Tero Kristof18cc2f2009-10-23 19:03:50 +0300460 omap3_intc_resume_idle();
Kevin Hilman658ce972008-11-04 20:50:52 -0800461
462 /* PER */
463 if (per_next_state < PWRDM_POWER_ON) {
464 per_prev_state = pwrdm_read_prev_pwrst(per_pwrdm);
Kevin Hilman658ce972008-11-04 20:50:52 -0800465 if (per_prev_state == PWRDM_POWER_OFF)
466 omap3_per_restore_context();
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530467 omap2_gpio_resume_after_retention();
Tero Kristoecf157d2008-12-01 13:17:29 +0200468 omap_uart_resume_idle(2);
469 if (per_state_modified)
470 pwrdm_set_next_pwrst(per_pwrdm, PWRDM_POWER_OFF);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +0530471 }
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300472
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200473 /* Disable IO-PAD and IO-CHAIN wakeup */
474 if (core_next_state < PWRDM_POWER_ON) {
Kevin Hilman658ce972008-11-04 20:50:52 -0800475 prm_clear_mod_reg_bits(OMAP3430_EN_IO, WKUP_MOD, PM_WKEN);
Kalle Jokiniemi3a7ec262009-03-26 15:59:01 +0200476 omap3_disable_io_chain();
477 }
Kevin Hilman658ce972008-11-04 20:50:52 -0800478
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300479 pwrdm_post_transition();
480
Tero Kristoc16c3f62008-12-11 16:46:57 +0200481 omap2_clkdm_allow_idle(mpu_pwrdm->pwrdm_clkdms[0]);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700482}
483
Rajendra Nayak20b01662008-10-08 17:31:22 +0530484int omap3_can_sleep(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700485{
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700486 if (!sleep_while_idle)
487 return 0;
Kevin Hilman4af40162009-02-04 10:51:40 -0800488 if (!omap_uart_can_sleep())
489 return 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700490 return 1;
491}
492
493/* This sets pwrdm state (other than mpu & core. Currently only ON &
494 * RET are supported. Function is assuming that clkdm doesn't have
495 * hw_sup mode enabled. */
Rajendra Nayak20b01662008-10-08 17:31:22 +0530496int set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700497{
498 u32 cur_state;
499 int sleep_switch = 0;
500 int ret = 0;
501
502 if (pwrdm == NULL || IS_ERR(pwrdm))
503 return -EINVAL;
504
505 while (!(pwrdm->pwrsts & (1 << state))) {
506 if (state == PWRDM_POWER_OFF)
507 return ret;
508 state--;
509 }
510
511 cur_state = pwrdm_read_next_pwrst(pwrdm);
512 if (cur_state == state)
513 return ret;
514
515 if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
516 omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
517 sleep_switch = 1;
518 pwrdm_wait_transition(pwrdm);
519 }
520
521 ret = pwrdm_set_next_pwrst(pwrdm, state);
522 if (ret) {
523 printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
524 pwrdm->name);
525 goto err;
526 }
527
528 if (sleep_switch) {
529 omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
530 pwrdm_wait_transition(pwrdm);
Peter 'p2' De Schrijverfe617af2008-10-15 17:48:44 +0300531 pwrdm_state_switch(pwrdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700532 }
533
534err:
535 return ret;
536}
537
538static void omap3_pm_idle(void)
539{
540 local_irq_disable();
541 local_fiq_disable();
542
543 if (!omap3_can_sleep())
544 goto out;
545
Tero Kristocf228542009-03-20 15:21:02 +0200546 if (omap_irq_pending() || need_resched())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700547 goto out;
548
549 omap_sram_idle();
550
551out:
552 local_fiq_enable();
553 local_irq_enable();
554}
555
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700556#ifdef CONFIG_SUSPEND
Tero Kristo24662112009-03-05 16:32:23 +0200557static suspend_state_t suspend_state;
558
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200559static void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
Kevin Hilmand7814e42009-10-06 14:30:23 -0700560{
561 u32 tick_rate, cycles;
562
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200563 if (!seconds && !milliseconds)
Kevin Hilmand7814e42009-10-06 14:30:23 -0700564 return;
565
566 tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200567 cycles = tick_rate * seconds + tick_rate * milliseconds / 1000;
Kevin Hilmand7814e42009-10-06 14:30:23 -0700568 omap_dm_timer_stop(gptimer_wakeup);
569 omap_dm_timer_set_load_start(gptimer_wakeup, 0, 0xffffffff - cycles);
570
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200571 pr_info("PM: Resume timer in %u.%03u secs"
572 " (%d ticks at %d ticks/sec.)\n",
573 seconds, milliseconds, cycles, tick_rate);
Kevin Hilmand7814e42009-10-06 14:30:23 -0700574}
575
Kevin Hilman8bd22942009-05-28 10:56:16 -0700576static int omap3_pm_prepare(void)
577{
578 disable_hlt();
579 return 0;
580}
581
582static int omap3_pm_suspend(void)
583{
584 struct power_state *pwrst;
585 int state, ret = 0;
586
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200587 if (wakeup_timer_seconds || wakeup_timer_milliseconds)
588 omap2_pm_wakeup_on_timer(wakeup_timer_seconds,
589 wakeup_timer_milliseconds);
Kevin Hilmand7814e42009-10-06 14:30:23 -0700590
Kevin Hilman8bd22942009-05-28 10:56:16 -0700591 /* Read current next_pwrsts */
592 list_for_each_entry(pwrst, &pwrst_list, node)
593 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
594 /* Set ones wanted by suspend */
595 list_for_each_entry(pwrst, &pwrst_list, node) {
596 if (set_pwrdm_state(pwrst->pwrdm, pwrst->next_state))
597 goto restore;
598 if (pwrdm_clear_all_prev_pwrst(pwrst->pwrdm))
599 goto restore;
600 }
601
Kevin Hilman4af40162009-02-04 10:51:40 -0800602 omap_uart_prepare_suspend();
Tero Kristo2bbe3af2009-10-23 19:03:48 +0300603 omap3_intc_suspend();
604
Kevin Hilman8bd22942009-05-28 10:56:16 -0700605 omap_sram_idle();
606
607restore:
608 /* Restore next_pwrsts */
609 list_for_each_entry(pwrst, &pwrst_list, node) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700610 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
611 if (state > pwrst->next_state) {
612 printk(KERN_INFO "Powerdomain (%s) didn't enter "
613 "target state %d\n",
614 pwrst->pwrdm->name, pwrst->next_state);
615 ret = -1;
616 }
Jouni Hogander6c5f8032008-10-29 12:06:04 +0200617 set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700618 }
619 if (ret)
620 printk(KERN_ERR "Could not enter target state in pm_suspend\n");
621 else
622 printk(KERN_INFO "Successfully put all powerdomains "
623 "to target state\n");
624
625 return ret;
626}
627
Tero Kristo24662112009-03-05 16:32:23 +0200628static int omap3_pm_enter(suspend_state_t unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700629{
630 int ret = 0;
631
Tero Kristo24662112009-03-05 16:32:23 +0200632 switch (suspend_state) {
Kevin Hilman8bd22942009-05-28 10:56:16 -0700633 case PM_SUSPEND_STANDBY:
634 case PM_SUSPEND_MEM:
635 ret = omap3_pm_suspend();
636 break;
637 default:
638 ret = -EINVAL;
639 }
640
641 return ret;
642}
643
644static void omap3_pm_finish(void)
645{
646 enable_hlt();
647}
648
Tero Kristo24662112009-03-05 16:32:23 +0200649/* Hooks to enable / disable UART interrupts during suspend */
650static int omap3_pm_begin(suspend_state_t state)
651{
652 suspend_state = state;
653 omap_uart_enable_irqs(0);
654 return 0;
655}
656
657static void omap3_pm_end(void)
658{
659 suspend_state = PM_SUSPEND_ON;
660 omap_uart_enable_irqs(1);
661 return;
662}
663
Kevin Hilman8bd22942009-05-28 10:56:16 -0700664static struct platform_suspend_ops omap_pm_ops = {
Tero Kristo24662112009-03-05 16:32:23 +0200665 .begin = omap3_pm_begin,
666 .end = omap3_pm_end,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700667 .prepare = omap3_pm_prepare,
668 .enter = omap3_pm_enter,
669 .finish = omap3_pm_finish,
670 .valid = suspend_valid_only_mem,
671};
Kevin Hilman10f90ed2009-06-24 11:39:18 -0700672#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700673
Kevin Hilman1155e422008-11-25 11:48:24 -0800674
675/**
676 * omap3_iva_idle(): ensure IVA is in idle so it can be put into
677 * retention
678 *
679 * In cases where IVA2 is activated by bootcode, it may prevent
680 * full-chip retention or off-mode because it is not idle. This
681 * function forces the IVA2 into idle state so it can go
682 * into retention/off and thus allow full-chip retention/off.
683 *
684 **/
685static void __init omap3_iva_idle(void)
686{
687 /* ensure IVA2 clock is disabled */
688 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
689
690 /* if no clock activity, nothing else to do */
691 if (!(cm_read_mod_reg(OMAP3430_IVA2_MOD, OMAP3430_CM_CLKSTST) &
692 OMAP3430_CLKACTIVITY_IVA2_MASK))
693 return;
694
695 /* Reset IVA2 */
696 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
697 OMAP3430_RST2_IVA2 |
698 OMAP3430_RST3_IVA2,
Abhijit Pagare37903002010-01-26 20:12:51 -0700699 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800700
701 /* Enable IVA2 clock */
Kevin Hilmandfa6d6f2010-02-24 12:05:48 -0700702 cm_write_mod_reg(OMAP3430_CM_FCLKEN_IVA2_EN_IVA2_MASK,
Kevin Hilman1155e422008-11-25 11:48:24 -0800703 OMAP3430_IVA2_MOD, CM_FCLKEN);
704
705 /* Set IVA2 boot mode to 'idle' */
706 omap_ctrl_writel(OMAP3_IVA2_BOOTMOD_IDLE,
707 OMAP343X_CONTROL_IVA2_BOOTMOD);
708
709 /* Un-reset IVA2 */
Abhijit Pagare37903002010-01-26 20:12:51 -0700710 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800711
712 /* Disable IVA2 clock */
713 cm_write_mod_reg(0, OMAP3430_IVA2_MOD, CM_FCLKEN);
714
715 /* Reset IVA2 */
716 prm_write_mod_reg(OMAP3430_RST1_IVA2 |
717 OMAP3430_RST2_IVA2 |
718 OMAP3430_RST3_IVA2,
Abhijit Pagare37903002010-01-26 20:12:51 -0700719 OMAP3430_IVA2_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman1155e422008-11-25 11:48:24 -0800720}
721
Kevin Hilman8111b222009-04-28 15:27:44 -0700722static void __init omap3_d2d_idle(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700723{
Kevin Hilman8111b222009-04-28 15:27:44 -0700724 u16 mask, padconf;
725
726 /* In a stand alone OMAP3430 where there is not a stacked
727 * modem for the D2D Idle Ack and D2D MStandby must be pulled
728 * high. S CONTROL_PADCONF_SAD2D_IDLEACK and
729 * CONTROL_PADCONF_SAD2D_MSTDBY to have a pull up. */
730 mask = (1 << 4) | (1 << 3); /* pull-up, enabled */
731 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_MSTANDBY);
732 padconf |= mask;
733 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_MSTANDBY);
734
735 padconf = omap_ctrl_readw(OMAP3_PADCONF_SAD2D_IDLEACK);
736 padconf |= mask;
737 omap_ctrl_writew(padconf, OMAP3_PADCONF_SAD2D_IDLEACK);
738
Kevin Hilman8bd22942009-05-28 10:56:16 -0700739 /* reset modem */
740 prm_write_mod_reg(OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RSTPWRON |
741 OMAP3430_RM_RSTCTRL_CORE_MODEM_SW_RST,
Abhijit Pagare37903002010-01-26 20:12:51 -0700742 CORE_MOD, OMAP2_RM_RSTCTRL);
743 prm_write_mod_reg(0, CORE_MOD, OMAP2_RM_RSTCTRL);
Kevin Hilman8111b222009-04-28 15:27:44 -0700744}
Kevin Hilman8bd22942009-05-28 10:56:16 -0700745
Kevin Hilman8111b222009-04-28 15:27:44 -0700746static void __init prcm_setup_regs(void)
747{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700748 /* XXX Reset all wkdeps. This should be done when initializing
749 * powerdomains */
750 prm_write_mod_reg(0, OMAP3430_IVA2_MOD, PM_WKDEP);
751 prm_write_mod_reg(0, MPU_MOD, PM_WKDEP);
752 prm_write_mod_reg(0, OMAP3430_DSS_MOD, PM_WKDEP);
753 prm_write_mod_reg(0, OMAP3430_NEON_MOD, PM_WKDEP);
754 prm_write_mod_reg(0, OMAP3430_CAM_MOD, PM_WKDEP);
755 prm_write_mod_reg(0, OMAP3430_PER_MOD, PM_WKDEP);
756 if (omap_rev() > OMAP3430_REV_ES1_0) {
757 prm_write_mod_reg(0, OMAP3430ES2_SGX_MOD, PM_WKDEP);
758 prm_write_mod_reg(0, OMAP3430ES2_USBHOST_MOD, PM_WKDEP);
759 } else
760 prm_write_mod_reg(0, GFX_MOD, PM_WKDEP);
761
762 /*
763 * Enable interface clock autoidle for all modules.
764 * Note that in the long run this should be done by clockfw
765 */
766 cm_write_mod_reg(
Kevin Hilman8111b222009-04-28 15:27:44 -0700767 OMAP3430_AUTO_MODEM |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700768 OMAP3430ES2_AUTO_MMC3 |
769 OMAP3430ES2_AUTO_ICR |
770 OMAP3430_AUTO_AES2 |
771 OMAP3430_AUTO_SHA12 |
772 OMAP3430_AUTO_DES2 |
773 OMAP3430_AUTO_MMC2 |
774 OMAP3430_AUTO_MMC1 |
775 OMAP3430_AUTO_MSPRO |
776 OMAP3430_AUTO_HDQ |
777 OMAP3430_AUTO_MCSPI4 |
778 OMAP3430_AUTO_MCSPI3 |
779 OMAP3430_AUTO_MCSPI2 |
780 OMAP3430_AUTO_MCSPI1 |
781 OMAP3430_AUTO_I2C3 |
782 OMAP3430_AUTO_I2C2 |
783 OMAP3430_AUTO_I2C1 |
784 OMAP3430_AUTO_UART2 |
785 OMAP3430_AUTO_UART1 |
786 OMAP3430_AUTO_GPT11 |
787 OMAP3430_AUTO_GPT10 |
788 OMAP3430_AUTO_MCBSP5 |
789 OMAP3430_AUTO_MCBSP1 |
790 OMAP3430ES1_AUTO_FAC | /* This is es1 only */
791 OMAP3430_AUTO_MAILBOXES |
792 OMAP3430_AUTO_OMAPCTRL |
793 OMAP3430ES1_AUTO_FSHOSTUSB |
794 OMAP3430_AUTO_HSOTGUSB |
Kevin Hilman8111b222009-04-28 15:27:44 -0700795 OMAP3430_AUTO_SAD2D |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700796 OMAP3430_AUTO_SSI,
797 CORE_MOD, CM_AUTOIDLE1);
798
799 cm_write_mod_reg(
800 OMAP3430_AUTO_PKA |
801 OMAP3430_AUTO_AES1 |
802 OMAP3430_AUTO_RNG |
803 OMAP3430_AUTO_SHA11 |
804 OMAP3430_AUTO_DES1,
805 CORE_MOD, CM_AUTOIDLE2);
806
807 if (omap_rev() > OMAP3430_REV_ES1_0) {
808 cm_write_mod_reg(
Kevin Hilman8111b222009-04-28 15:27:44 -0700809 OMAP3430_AUTO_MAD2D |
Kevin Hilman8bd22942009-05-28 10:56:16 -0700810 OMAP3430ES2_AUTO_USBTLL,
811 CORE_MOD, CM_AUTOIDLE3);
812 }
813
814 cm_write_mod_reg(
815 OMAP3430_AUTO_WDT2 |
816 OMAP3430_AUTO_WDT1 |
817 OMAP3430_AUTO_GPIO1 |
818 OMAP3430_AUTO_32KSYNC |
819 OMAP3430_AUTO_GPT12 |
820 OMAP3430_AUTO_GPT1 ,
821 WKUP_MOD, CM_AUTOIDLE);
822
823 cm_write_mod_reg(
824 OMAP3430_AUTO_DSS,
825 OMAP3430_DSS_MOD,
826 CM_AUTOIDLE);
827
828 cm_write_mod_reg(
829 OMAP3430_AUTO_CAM,
830 OMAP3430_CAM_MOD,
831 CM_AUTOIDLE);
832
833 cm_write_mod_reg(
834 OMAP3430_AUTO_GPIO6 |
835 OMAP3430_AUTO_GPIO5 |
836 OMAP3430_AUTO_GPIO4 |
837 OMAP3430_AUTO_GPIO3 |
838 OMAP3430_AUTO_GPIO2 |
839 OMAP3430_AUTO_WDT3 |
840 OMAP3430_AUTO_UART3 |
841 OMAP3430_AUTO_GPT9 |
842 OMAP3430_AUTO_GPT8 |
843 OMAP3430_AUTO_GPT7 |
844 OMAP3430_AUTO_GPT6 |
845 OMAP3430_AUTO_GPT5 |
846 OMAP3430_AUTO_GPT4 |
847 OMAP3430_AUTO_GPT3 |
848 OMAP3430_AUTO_GPT2 |
849 OMAP3430_AUTO_MCBSP4 |
850 OMAP3430_AUTO_MCBSP3 |
851 OMAP3430_AUTO_MCBSP2,
852 OMAP3430_PER_MOD,
853 CM_AUTOIDLE);
854
855 if (omap_rev() > OMAP3430_REV_ES1_0) {
856 cm_write_mod_reg(
857 OMAP3430ES2_AUTO_USBHOST,
858 OMAP3430ES2_USBHOST_MOD,
859 CM_AUTOIDLE);
860 }
861
Tero Kristob296c812009-10-23 19:03:49 +0300862 omap_ctrl_writel(OMAP3430_AUTOIDLE, OMAP2_CONTROL_SYSCONFIG);
863
Kevin Hilman8bd22942009-05-28 10:56:16 -0700864 /*
865 * Set all plls to autoidle. This is needed until autoidle is
866 * enabled by clockfw
867 */
868 cm_write_mod_reg(1 << OMAP3430_AUTO_IVA2_DPLL_SHIFT,
869 OMAP3430_IVA2_MOD, CM_AUTOIDLE2);
870 cm_write_mod_reg(1 << OMAP3430_AUTO_MPU_DPLL_SHIFT,
871 MPU_MOD,
872 CM_AUTOIDLE2);
873 cm_write_mod_reg((1 << OMAP3430_AUTO_PERIPH_DPLL_SHIFT) |
874 (1 << OMAP3430_AUTO_CORE_DPLL_SHIFT),
875 PLL_MOD,
876 CM_AUTOIDLE);
877 cm_write_mod_reg(1 << OMAP3430ES2_AUTO_PERIPH2_DPLL_SHIFT,
878 PLL_MOD,
879 CM_AUTOIDLE2);
880
881 /*
882 * Enable control of expternal oscillator through
883 * sys_clkreq. In the long run clock framework should
884 * take care of this.
885 */
886 prm_rmw_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK,
887 1 << OMAP_AUTOEXTCLKMODE_SHIFT,
888 OMAP3430_GR_MOD,
889 OMAP3_PRM_CLKSRC_CTRL_OFFSET);
890
891 /* setup wakup source */
892 prm_write_mod_reg(OMAP3430_EN_IO | OMAP3430_EN_GPIO1 |
893 OMAP3430_EN_GPT1 | OMAP3430_EN_GPT12,
894 WKUP_MOD, PM_WKEN);
895 /* No need to write EN_IO, that is always enabled */
896 prm_write_mod_reg(OMAP3430_EN_GPIO1 | OMAP3430_EN_GPT1 |
897 OMAP3430_EN_GPT12,
898 WKUP_MOD, OMAP3430_PM_MPUGRPSEL);
899 /* For some reason IO doesn't generate wakeup event even if
900 * it is selected to mpu wakeup goup */
901 prm_write_mod_reg(OMAP3430_IO_EN | OMAP3430_WKUP_EN,
902 OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
Kevin Hilman1155e422008-11-25 11:48:24 -0800903
Subramani Venkateshb92c5722009-12-22 15:07:50 +0530904 /* Enable PM_WKEN to support DSS LPR */
905 prm_write_mod_reg(OMAP3430_PM_WKEN_DSS_EN_DSS,
906 OMAP3430_DSS_MOD, PM_WKEN);
907
Kevin Hilmanb427f922009-10-22 14:48:13 -0700908 /* Enable wakeups in PER */
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000909 prm_write_mod_reg(OMAP3430_EN_GPIO2 | OMAP3430_EN_GPIO3 |
910 OMAP3430_EN_GPIO4 | OMAP3430_EN_GPIO5 |
Peter Ujfalusie3d93292009-11-26 15:18:50 +0200911 OMAP3430_EN_GPIO6 | OMAP3430_EN_UART3 |
912 OMAP3430_EN_MCBSP2 | OMAP3430_EN_MCBSP3 |
913 OMAP3430_EN_MCBSP4,
Kevin Hilmanb427f922009-10-22 14:48:13 -0700914 OMAP3430_PER_MOD, PM_WKEN);
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000915 /* and allow them to wake up MPU */
916 prm_write_mod_reg(OMAP3430_GRPSEL_GPIO2 | OMAP3430_EN_GPIO3 |
917 OMAP3430_GRPSEL_GPIO4 | OMAP3430_EN_GPIO5 |
Peter Ujfalusie3d93292009-11-26 15:18:50 +0200918 OMAP3430_GRPSEL_GPIO6 | OMAP3430_EN_UART3 |
919 OMAP3430_EN_MCBSP2 | OMAP3430_EN_MCBSP3 |
920 OMAP3430_EN_MCBSP4,
Kevin Hilmaneb350f72009-09-10 15:53:08 +0000921 OMAP3430_PER_MOD, OMAP3430_PM_MPUGRPSEL);
922
Kevin Hilmand3fd3292009-05-05 16:34:25 -0700923 /* Don't attach IVA interrupts */
924 prm_write_mod_reg(0, WKUP_MOD, OMAP3430_PM_IVAGRPSEL);
925 prm_write_mod_reg(0, CORE_MOD, OMAP3430_PM_IVAGRPSEL1);
926 prm_write_mod_reg(0, CORE_MOD, OMAP3430ES2_PM_IVAGRPSEL3);
927 prm_write_mod_reg(0, OMAP3430_PER_MOD, OMAP3430_PM_IVAGRPSEL);
928
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700929 /* Clear any pending 'reset' flags */
Abhijit Pagare37903002010-01-26 20:12:51 -0700930 prm_write_mod_reg(0xffffffff, MPU_MOD, OMAP2_RM_RSTST);
931 prm_write_mod_reg(0xffffffff, CORE_MOD, OMAP2_RM_RSTST);
932 prm_write_mod_reg(0xffffffff, OMAP3430_PER_MOD, OMAP2_RM_RSTST);
933 prm_write_mod_reg(0xffffffff, OMAP3430_EMU_MOD, OMAP2_RM_RSTST);
934 prm_write_mod_reg(0xffffffff, OMAP3430_NEON_MOD, OMAP2_RM_RSTST);
935 prm_write_mod_reg(0xffffffff, OMAP3430_DSS_MOD, OMAP2_RM_RSTST);
936 prm_write_mod_reg(0xffffffff, OMAP3430ES2_USBHOST_MOD, OMAP2_RM_RSTST);
Kevin Hilmanb1340d12009-04-27 16:14:54 -0700937
Kevin Hilman014c46d2009-04-27 07:50:23 -0700938 /* Clear any pending PRCM interrupts */
939 prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
940
Kevin Hilman1155e422008-11-25 11:48:24 -0800941 omap3_iva_idle();
Kevin Hilman8111b222009-04-28 15:27:44 -0700942 omap3_d2d_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700943}
944
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700945void omap3_pm_off_mode_enable(int enable)
946{
947 struct power_state *pwrst;
948 u32 state;
949
950 if (enable)
951 state = PWRDM_POWER_OFF;
952 else
953 state = PWRDM_POWER_RET;
954
Sanjeev Premi6af83b32010-01-28 23:16:43 +0530955#ifdef CONFIG_CPU_IDLE
956 omap3_cpuidle_update_states();
957#endif
958
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700959 list_for_each_entry(pwrst, &pwrst_list, node) {
960 pwrst->next_state = state;
961 set_pwrdm_state(pwrst->pwrdm, state);
962 }
963}
964
Tero Kristo68d47782008-11-26 12:26:24 +0200965int omap3_pm_get_suspend_state(struct powerdomain *pwrdm)
966{
967 struct power_state *pwrst;
968
969 list_for_each_entry(pwrst, &pwrst_list, node) {
970 if (pwrst->pwrdm == pwrdm)
971 return pwrst->next_state;
972 }
973 return -EINVAL;
974}
975
976int omap3_pm_set_suspend_state(struct powerdomain *pwrdm, int state)
977{
978 struct power_state *pwrst;
979
980 list_for_each_entry(pwrst, &pwrst_list, node) {
981 if (pwrst->pwrdm == pwrdm) {
982 pwrst->next_state = state;
983 return 0;
984 }
985 }
986 return -EINVAL;
987}
988
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300989static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700990{
991 struct power_state *pwrst;
992
993 if (!pwrdm->pwrsts)
994 return 0;
995
Ming Leid3d381c2009-08-22 21:20:26 +0800996 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700997 if (!pwrst)
998 return -ENOMEM;
999 pwrst->pwrdm = pwrdm;
1000 pwrst->next_state = PWRDM_POWER_RET;
1001 list_add(&pwrst->node, &pwrst_list);
1002
1003 if (pwrdm_has_hdwr_sar(pwrdm))
1004 pwrdm_enable_hdwr_sar(pwrdm);
1005
1006 return set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
1007}
1008
1009/*
1010 * Enable hw supervised mode for all clockdomains if it's
1011 * supported. Initiate sleep transition for other clockdomains, if
1012 * they are not used
1013 */
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +03001014static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
Kevin Hilman8bd22942009-05-28 10:56:16 -07001015{
Paul Walmsley369d5612010-01-26 20:13:01 -07001016 clkdm_clear_all_wkdeps(clkdm);
1017 clkdm_clear_all_sleepdeps(clkdm);
1018
Kevin Hilman8bd22942009-05-28 10:56:16 -07001019 if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
1020 omap2_clkdm_allow_idle(clkdm);
1021 else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
1022 atomic_read(&clkdm->usecount) == 0)
1023 omap2_clkdm_sleep(clkdm);
1024 return 0;
1025}
1026
Rajendra Nayak3231fc82008-09-26 17:49:14 +05301027void omap_push_sram_idle(void)
1028{
1029 _omap_sram_idle = omap_sram_push(omap34xx_cpu_suspend,
1030 omap34xx_cpu_suspend_sz);
Tero Kristo27d59a42008-10-13 13:15:00 +03001031 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
1032 _omap_save_secure_sram = omap_sram_push(save_secure_ram_context,
1033 save_secure_ram_context_sz);
Rajendra Nayak3231fc82008-09-26 17:49:14 +05301034}
1035
Kevin Hilman7cc515f2009-06-10 09:02:25 -07001036static int __init omap3_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -07001037{
1038 struct power_state *pwrst, *tmp;
Paul Walmsley55ed9692010-01-26 20:12:59 -07001039 struct clockdomain *neon_clkdm, *per_clkdm, *mpu_clkdm, *core_clkdm;
Kevin Hilman8bd22942009-05-28 10:56:16 -07001040 int ret;
1041
1042 if (!cpu_is_omap34xx())
1043 return -ENODEV;
1044
1045 printk(KERN_ERR "Power Management for TI OMAP3.\n");
1046
1047 /* XXX prcm_setup_regs needs to be before enabling hw
1048 * supervised mode for powerdomains */
1049 prcm_setup_regs();
1050
1051 ret = request_irq(INT_34XX_PRCM_MPU_IRQ,
1052 (irq_handler_t)prcm_interrupt_handler,
1053 IRQF_DISABLED, "prcm", NULL);
1054 if (ret) {
1055 printk(KERN_ERR "request_irq failed to register for 0x%x\n",
1056 INT_34XX_PRCM_MPU_IRQ);
1057 goto err1;
1058 }
1059
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +03001060 ret = pwrdm_for_each(pwrdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -07001061 if (ret) {
1062 printk(KERN_ERR "Failed to setup powerdomains\n");
1063 goto err2;
1064 }
1065
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +03001066 (void) clkdm_for_each(clkdms_setup, NULL);
Kevin Hilman8bd22942009-05-28 10:56:16 -07001067
1068 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
1069 if (mpu_pwrdm == NULL) {
1070 printk(KERN_ERR "Failed to get mpu_pwrdm\n");
1071 goto err2;
1072 }
1073
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301074 neon_pwrdm = pwrdm_lookup("neon_pwrdm");
1075 per_pwrdm = pwrdm_lookup("per_pwrdm");
1076 core_pwrdm = pwrdm_lookup("core_pwrdm");
Tero Kristoc16c3f62008-12-11 16:46:57 +02001077 cam_pwrdm = pwrdm_lookup("cam_pwrdm");
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301078
Paul Walmsley55ed9692010-01-26 20:12:59 -07001079 neon_clkdm = clkdm_lookup("neon_clkdm");
1080 mpu_clkdm = clkdm_lookup("mpu_clkdm");
1081 per_clkdm = clkdm_lookup("per_clkdm");
1082 core_clkdm = clkdm_lookup("core_clkdm");
1083
Rajendra Nayak3231fc82008-09-26 17:49:14 +05301084 omap_push_sram_idle();
Kevin Hilman10f90ed2009-06-24 11:39:18 -07001085#ifdef CONFIG_SUSPEND
Kevin Hilman8bd22942009-05-28 10:56:16 -07001086 suspend_set_ops(&omap_pm_ops);
Kevin Hilman10f90ed2009-06-24 11:39:18 -07001087#endif /* CONFIG_SUSPEND */
Kevin Hilman8bd22942009-05-28 10:56:16 -07001088
1089 pm_idle = omap3_pm_idle;
Kalle Jokiniemi03433712008-09-26 11:04:20 +03001090 omap3_idle_init();
Kevin Hilman8bd22942009-05-28 10:56:16 -07001091
Paul Walmsley55ed9692010-01-26 20:12:59 -07001092 clkdm_add_wkdep(neon_clkdm, mpu_clkdm);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301093 /*
1094 * REVISIT: This wkdep is only necessary when GPIO2-6 are enabled for
1095 * IO-pad wakeup. Otherwise it will unnecessarily waste power
1096 * waking up PER with every CORE wakeup - see
1097 * http://marc.info/?l=linux-omap&m=121852150710062&w=2
1098 */
Paul Walmsley55ed9692010-01-26 20:12:59 -07001099 clkdm_add_wkdep(per_clkdm, core_clkdm);
Rajendra Nayakfa3c2a42008-09-26 17:49:22 +05301100
Tero Kristo27d59a42008-10-13 13:15:00 +03001101 if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
1102 omap3_secure_ram_storage =
1103 kmalloc(0x803F, GFP_KERNEL);
1104 if (!omap3_secure_ram_storage)
1105 printk(KERN_ERR "Memory allocation failed when"
1106 "allocating for secure sram context\n");
Tero Kristo27d59a42008-10-13 13:15:00 +03001107
Tero Kristo9d971402008-12-12 11:20:05 +02001108 local_irq_disable();
1109 local_fiq_disable();
1110
1111 omap_dma_global_context_save();
1112 omap3_save_secure_ram_context(PWRDM_POWER_ON);
1113 omap_dma_global_context_restore();
1114
1115 local_irq_enable();
1116 local_fiq_enable();
1117 }
1118
1119 omap3_save_scratchpad_contents();
Kevin Hilman8bd22942009-05-28 10:56:16 -07001120err1:
1121 return ret;
1122err2:
1123 free_irq(INT_34XX_PRCM_MPU_IRQ, NULL);
1124 list_for_each_entry_safe(pwrst, tmp, &pwrst_list, node) {
1125 list_del(&pwrst->node);
1126 kfree(pwrst);
1127 }
1128 return ret;
1129}
1130
1131late_initcall(omap3_pm_init);