blob: 2a1a4180d5d0f5901e8fdbaab5d25339b581be01 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * OMAP2 Power Management Routines
3 *
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
6 *
7 * Written by:
8 * Richard Woodruff <r-woodruff2@ti.com>
9 * Tony Lindgren
10 * Juha Yrjola
11 * Amit Kucheria <amit.kucheria@nokia.com>
12 * Igor Stoppa <igor.stoppa@nokia.com>
13 *
14 * Based on pm.c for omap1
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
19 */
20
21#include <linux/suspend.h>
22#include <linux/sched.h>
23#include <linux/proc_fs.h>
24#include <linux/interrupt.h>
25#include <linux/sysfs.h>
26#include <linux/module.h>
27#include <linux/delay.h>
Stephen Boydf5b00f62015-06-22 17:05:21 -070028#include <linux/clk.h>
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053029#include <linux/clk-provider.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070030#include <linux/irq.h>
31#include <linux/time.h>
32#include <linux/gpio.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070033#include <linux/platform_data/gpio-omap.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070034
Tony Lindgrenbf027ca2012-10-29 13:54:06 -070035#include <asm/fncpy.h>
36
Kevin Hilman8bd22942009-05-28 10:56:16 -070037#include <asm/mach/time.h>
38#include <asm/mach/irq.h>
39#include <asm/mach-types.h>
David Howells9f97da72012-03-28 18:30:01 +010040#include <asm/system_misc.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070041
Tony Lindgren45c3eb72012-11-30 08:41:50 -080042#include <linux/omap-dma.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070043
Tony Lindgrene4c060d2012-10-05 13:25:59 -070044#include "soc.h"
Tony Lindgren4e653312011-11-10 22:45:17 +010045#include "common.h"
Paul Walmsleya135eaa2012-09-27 10:33:34 -060046#include "clock.h"
Paul Walmsley139563a2012-10-21 01:01:10 -060047#include "prm2xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070048#include "prm-regbits-24xx.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -060049#include "cm2xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070050#include "cm-regbits-24xx.h"
51#include "sdrc.h"
Tony Lindgrenbf027ca2012-10-29 13:54:06 -070052#include "sram.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070053#include "pm.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060054#include "control.h"
Paul Walmsley72e06d02010-12-21 21:05:16 -070055#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070056#include "clockdomain.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070057
Kevin Hilman8bd22942009-05-28 10:56:16 -070058static void (*omap2_sram_suspend)(u32 dllctrl, void __iomem *sdrc_dlla_ctrl,
59 void __iomem *sdrc_power);
60
Paul Walmsley369d5612010-01-26 20:13:01 -070061static struct powerdomain *mpu_pwrdm, *core_pwrdm;
62static struct clockdomain *dsp_clkdm, *mpu_clkdm, *wkup_clkdm, *gfx_clkdm;
Kevin Hilman8bd22942009-05-28 10:56:16 -070063
64static struct clk *osc_ck, *emul_ck;
65
Paul Walmsley14164082012-02-02 02:30:50 -070066static int omap2_enter_full_retention(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -070067{
68 u32 l;
Kevin Hilman8bd22942009-05-28 10:56:16 -070069
70 /* There is 1 reference hold for all children of the oscillator
71 * clock, the following will remove it. If no one else uses the
72 * oscillator itself it will be disabled if/when we enter retention
73 * mode.
74 */
75 clk_disable(osc_ck);
76
77 /* Clear old wake-up events */
78 /* REVISIT: These write to reserved bits? */
Tero Kristo9cb6d362014-04-04 12:31:51 +030079 omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
80 omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
81 omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, ~0);
Kevin Hilman8bd22942009-05-28 10:56:16 -070082
Paul Walmsleyf653b292013-01-26 00:58:14 -070083 pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_RET);
Kevin Hilman8bd22942009-05-28 10:56:16 -070084 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
85
86 /* Workaround to kill USB */
87 l = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0) | OMAP24XX_USBSTANDBYCTRL;
88 omap_ctrl_writel(l, OMAP2_CONTROL_DEVCONF0);
89
Paul Walmsley72e06d02010-12-21 21:05:16 -070090 omap2_gpio_prepare_for_idle(0);
Kevin Hilman8bd22942009-05-28 10:56:16 -070091
Kevin Hilman8bd22942009-05-28 10:56:16 -070092 /* One last check for pending IRQs to avoid extra latency due
93 * to sleeping unnecessarily. */
Jouni Hogander94434532009-02-03 15:49:04 -080094 if (omap_irq_pending())
Kevin Hilman8bd22942009-05-28 10:56:16 -070095 goto no_sleep;
96
97 /* Jump to SRAM suspend code */
98 omap2_sram_suspend(sdrc_read_reg(SDRC_DLLA_CTRL),
99 OMAP_SDRC_REGADDR(SDRC_DLLA_CTRL),
100 OMAP_SDRC_REGADDR(SDRC_POWER));
Kevin Hilman8bd22942009-05-28 10:56:16 -0700101
Kevin Hilman4af40162009-02-04 10:51:40 -0800102no_sleep:
Kevin Hilman43ffcd92009-01-27 11:09:24 -0800103 omap2_gpio_resume_after_idle();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700104
105 clk_enable(osc_ck);
106
107 /* clear CORE wake-up events */
Tero Kristo9cb6d362014-04-04 12:31:51 +0300108 omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
109 omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700110
111 /* wakeup domain events - bit 1: GPT1, bit5 GPIO */
Tero Kristo9cb6d362014-04-04 12:31:51 +0300112 omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, 0x4 | 0x1);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700113
114 /* MPU domain wake events */
Tero Kristo9cb6d362014-04-04 12:31:51 +0300115 omap_prm_clear_mod_irqs(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET, 0x1);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700116
Tero Kristo9cb6d362014-04-04 12:31:51 +0300117 omap_prm_clear_mod_irqs(OCP_MOD, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET, 0x20);
Paul Walmsley14164082012-02-02 02:30:50 -0700118
Paul Walmsleyf653b292013-01-26 00:58:14 -0700119 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
120 pwrdm_set_next_pwrst(core_pwrdm, PWRDM_POWER_ON);
121
Paul Walmsley14164082012-02-02 02:30:50 -0700122 return 0;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700123}
124
Kevin Hilman8bd22942009-05-28 10:56:16 -0700125static int sti_console_enabled;
126
127static int omap2_allow_mpu_retention(void)
128{
Tero Kristocd6e9db2013-10-11 19:15:31 +0300129 if (!omap2xxx_cm_mpu_retention_allowed())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700130 return 0;
131 if (sti_console_enabled)
132 return 0;
133
134 return 1;
135}
136
137static void omap2_enter_mpu_retention(void)
138{
Paul Walmsley088e8802012-12-30 10:15:48 -0700139 const int zero = 0;
140
Kevin Hilman8bd22942009-05-28 10:56:16 -0700141 /* The peripherals seem not to be able to wake up the MPU when
142 * it is in retention mode. */
143 if (omap2_allow_mpu_retention()) {
144 /* REVISIT: These write to reserved bits? */
Tero Kristo9cb6d362014-04-04 12:31:51 +0300145 omap_prm_clear_mod_irqs(CORE_MOD, PM_WKST1, ~0);
146 omap_prm_clear_mod_irqs(CORE_MOD, OMAP24XX_PM_WKST2, ~0);
147 omap_prm_clear_mod_irqs(WKUP_MOD, PM_WKST, ~0);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700148
149 /* Try to enter MPU retention */
Paul Walmsleyf653b292013-01-26 00:58:14 -0700150 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_RET);
151
Kevin Hilman8bd22942009-05-28 10:56:16 -0700152 } else {
153 /* Block MPU retention */
Paul Walmsleyf653b292013-01-26 00:58:14 -0700154 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700155 }
156
Paul Walmsley088e8802012-12-30 10:15:48 -0700157 /* WFI */
158 asm("mcr p15, 0, %0, c7, c0, 4" : : "r" (zero) : "memory", "cc");
Paul Walmsleyf653b292013-01-26 00:58:14 -0700159
160 pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700161}
162
163static int omap2_can_sleep(void)
164{
Tero Kristocd6e9db2013-10-11 19:15:31 +0300165 if (omap2xxx_cm_fclks_active())
Kevin Hilman8bd22942009-05-28 10:56:16 -0700166 return 0;
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530167 if (__clk_is_enabled(osc_ck))
Kevin Hilman8bd22942009-05-28 10:56:16 -0700168 return 0;
169 if (omap_dma_running())
170 return 0;
171
172 return 1;
173}
174
175static void omap2_pm_idle(void)
176{
Kevin Hilman8bd22942009-05-28 10:56:16 -0700177 if (!omap2_can_sleep()) {
Jouni Hogander94434532009-02-03 15:49:04 -0800178 if (omap_irq_pending())
Santosh Shilimkar6b856382013-02-11 19:29:45 +0530179 return;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700180 omap2_enter_mpu_retention();
Santosh Shilimkar6b856382013-02-11 19:29:45 +0530181 return;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700182 }
183
Jouni Hogander94434532009-02-03 15:49:04 -0800184 if (omap_irq_pending())
Santosh Shilimkar6b856382013-02-11 19:29:45 +0530185 return;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700186
187 omap2_enter_full_retention();
Kevin Hilman8bd22942009-05-28 10:56:16 -0700188}
189
Kevin Hilman8bd22942009-05-28 10:56:16 -0700190static void __init prcm_setup_regs(void)
191{
192 int i, num_mem_banks;
193 struct powerdomain *pwrdm;
194
Paul Walmsley4ef70c02011-02-25 15:39:30 -0700195 /*
196 * Enable autoidle
197 * XXX This should be handled by hwmod code or PRCM init code
198 */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700199 omap2_prm_write_mod_reg(OMAP24XX_AUTOIDLE_MASK, OCP_MOD,
Kevin Hilman8bd22942009-05-28 10:56:16 -0700200 OMAP2_PRCM_SYSCONFIG_OFFSET);
201
Kevin Hilman8bd22942009-05-28 10:56:16 -0700202 /*
203 * Set CORE powerdomain memory banks to retain their contents
204 * during RETENTION
205 */
206 num_mem_banks = pwrdm_get_mem_bank_count(core_pwrdm);
207 for (i = 0; i < num_mem_banks; i++)
208 pwrdm_set_mem_retst(core_pwrdm, i, PWRDM_POWER_RET);
209
Paul Walmsleyf653b292013-01-26 00:58:14 -0700210 pwrdm_set_logic_retst(core_pwrdm, PWRDM_POWER_RET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700211
Kevin Hilman8bd22942009-05-28 10:56:16 -0700212 pwrdm_set_logic_retst(mpu_pwrdm, PWRDM_POWER_RET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700213
214 /* Force-power down DSP, GFX powerdomains */
215
216 pwrdm = clkdm_get_pwrdm(dsp_clkdm);
217 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700218
219 pwrdm = clkdm_get_pwrdm(gfx_clkdm);
220 pwrdm_set_next_pwrst(pwrdm, PWRDM_POWER_OFF);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700221
Paul Walmsley51d070a2011-01-27 02:52:55 -0700222 /* Enable hardware-supervised idle for all clkdms */
Paul Walmsley92206fd2012-02-02 02:38:50 -0700223 clkdm_for_each(omap_pm_clkdms_setup, NULL);
Paul Walmsley369d5612010-01-26 20:13:01 -0700224 clkdm_add_wkdep(mpu_clkdm, wkup_clkdm);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700225
Dave Gerlach2e4b62d2014-05-12 13:33:21 -0500226 omap_common_suspend_init(omap2_enter_full_retention);
Paul Walmsley14164082012-02-02 02:30:50 -0700227
Kevin Hilman8bd22942009-05-28 10:56:16 -0700228 /* REVISIT: Configure number of 32 kHz clock cycles for sys_clk
229 * stabilisation */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700230 omap2_prm_write_mod_reg(15 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
231 OMAP2_PRCM_CLKSSETUP_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700232
233 /* Configure automatic voltage transition */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700234 omap2_prm_write_mod_reg(2 << OMAP_SETUP_TIME_SHIFT, OMAP24XX_GR_MOD,
235 OMAP2_PRCM_VOLTSETUP_OFFSET);
236 omap2_prm_write_mod_reg(OMAP24XX_AUTO_EXTVOLT_MASK |
237 (0x1 << OMAP24XX_SETOFF_LEVEL_SHIFT) |
238 OMAP24XX_MEMRETCTRL_MASK |
239 (0x1 << OMAP24XX_SETRET_LEVEL_SHIFT) |
240 (0x0 << OMAP24XX_VOLT_LEVEL_SHIFT),
241 OMAP24XX_GR_MOD, OMAP2_PRCM_VOLTCTRL_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700242
243 /* Enable wake-up events */
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700244 omap2_prm_write_mod_reg(OMAP24XX_EN_GPIOS_MASK | OMAP24XX_EN_GPT1_MASK,
245 WKUP_MOD, PM_WKEN);
Tero Kristo944ee5d2014-02-20 19:09:18 +0200246
247 /* Enable SYS_CLKEN control when all domains idle */
248 omap2_prm_set_mod_reg_bits(OMAP_AUTOEXTCLKMODE_MASK, OMAP24XX_GR_MOD,
249 OMAP2_PRCM_CLKSRC_CTRL_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700250}
251
Shawn Guobbd707a2012-04-26 16:06:50 +0800252int __init omap2_pm_init(void)
Kevin Hilman8bd22942009-05-28 10:56:16 -0700253{
254 u32 l;
255
Kevin Hilman8bd22942009-05-28 10:56:16 -0700256 printk(KERN_INFO "Power Management for OMAP2 initializing\n");
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700257 l = omap2_prm_read_mod_reg(OCP_MOD, OMAP2_PRCM_REVISION_OFFSET);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700258 printk(KERN_INFO "PRCM revision %d.%d\n", (l >> 4) & 0x0f, l & 0x0f);
259
Paul Walmsley369d5612010-01-26 20:13:01 -0700260 /* Look up important powerdomains */
Kevin Hilman8bd22942009-05-28 10:56:16 -0700261
262 mpu_pwrdm = pwrdm_lookup("mpu_pwrdm");
263 if (!mpu_pwrdm)
264 pr_err("PM: mpu_pwrdm not found\n");
265
266 core_pwrdm = pwrdm_lookup("core_pwrdm");
267 if (!core_pwrdm)
268 pr_err("PM: core_pwrdm not found\n");
269
Paul Walmsley369d5612010-01-26 20:13:01 -0700270 /* Look up important clockdomains */
271
272 mpu_clkdm = clkdm_lookup("mpu_clkdm");
273 if (!mpu_clkdm)
274 pr_err("PM: mpu_clkdm not found\n");
275
276 wkup_clkdm = clkdm_lookup("wkup_clkdm");
277 if (!wkup_clkdm)
278 pr_err("PM: wkup_clkdm not found\n");
279
Kevin Hilman8bd22942009-05-28 10:56:16 -0700280 dsp_clkdm = clkdm_lookup("dsp_clkdm");
281 if (!dsp_clkdm)
Paul Walmsley369d5612010-01-26 20:13:01 -0700282 pr_err("PM: dsp_clkdm not found\n");
Kevin Hilman8bd22942009-05-28 10:56:16 -0700283
284 gfx_clkdm = clkdm_lookup("gfx_clkdm");
285 if (!gfx_clkdm)
286 pr_err("PM: gfx_clkdm not found\n");
287
288
289 osc_ck = clk_get(NULL, "osc_ck");
290 if (IS_ERR(osc_ck)) {
291 printk(KERN_ERR "could not get osc_ck\n");
292 return -ENODEV;
293 }
294
295 if (cpu_is_omap242x()) {
296 emul_ck = clk_get(NULL, "emul_ck");
297 if (IS_ERR(emul_ck)) {
298 printk(KERN_ERR "could not get emul_ck\n");
299 clk_put(osc_ck);
300 return -ENODEV;
301 }
302 }
303
304 prcm_setup_regs();
305
Kevin Hilman8bd22942009-05-28 10:56:16 -0700306 /*
307 * We copy the assembler sleep/wakeup routines to SRAM.
308 * These routines need to be in SRAM as that's the only
Paul Walmsley088e8802012-12-30 10:15:48 -0700309 * memory the MPU can see when it wakes up after the entire
310 * chip enters idle.
Kevin Hilman8bd22942009-05-28 10:56:16 -0700311 */
Shawn Guobbd707a2012-04-26 16:06:50 +0800312 omap2_sram_suspend = omap_sram_push(omap24xx_cpu_suspend,
313 omap24xx_cpu_suspend_sz);
Kevin Hilman8bd22942009-05-28 10:56:16 -0700314
Nicolas Pitre0bcd24b2012-01-04 16:27:48 -0500315 arm_pm_idle = omap2_pm_idle;
Kevin Hilman8bd22942009-05-28 10:56:16 -0700316
317 return 0;
318}