blob: 907a048fe5e9874183fef2659f44fc0470a521f8 [file] [log] [blame]
Santosh Shilimkarb2b97622010-06-16 22:19:48 +05301/*
2 * OMAP MPUSS low power code
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 *
7 * OMAP4430 MPUSS mainly consists of dual Cortex-A9 with per-CPU
8 * Local timer and Watchdog, GIC, SCU, PL310 L2 cache controller,
9 * CPU0 and CPU1 LPRM modules.
10 * CPU0, CPU1 and MPUSS each have there own power domain and
11 * hence multiple low power combinations of MPUSS are possible.
12 *
13 * The CPU0 and CPU1 can't support Closed switch Retention (CSWR)
14 * because the mode is not supported by hw constraints of dormant
15 * mode. While waking up from the dormant mode, a reset signal
16 * to the Cortex-A9 processor must be asserted by the external
17 * power controller.
18 *
19 * With architectural inputs and hardware recommendations, only
20 * below modes are supported from power gain vs latency point of view.
21 *
22 * CPU0 CPU1 MPUSS
23 * ----------------------------------------------
24 * ON ON ON
25 * ON(Inactive) OFF ON(Inactive)
26 * OFF OFF CSWR
27 * OFF OFF OSWR (*TBD)
28 * OFF OFF OFF* (*TBD)
29 * ----------------------------------------------
30 *
31 * Note: CPU0 is the master core and it is the last CPU to go down
32 * and first to wake-up when MPUSS low power states are excercised
33 *
34 *
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License version 2 as
37 * published by the Free Software Foundation.
38 */
39
40#include <linux/kernel.h>
41#include <linux/io.h>
42#include <linux/errno.h>
43#include <linux/linkage.h>
44#include <linux/smp.h>
45
46#include <asm/cacheflush.h>
47#include <asm/tlbflush.h>
48#include <asm/smp_scu.h>
49#include <asm/system.h>
50#include <asm/pgalloc.h>
51#include <asm/suspend.h>
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +053052#include <asm/hardware/cache-l2x0.h>
Santosh Shilimkarb2b97622010-06-16 22:19:48 +053053
54#include <plat/omap44xx.h>
55
56#include "common.h"
57#include "omap4-sar-layout.h"
58#include "pm.h"
59#include "powerdomain.h"
60
61#ifdef CONFIG_SMP
62
63struct omap4_cpu_pm_info {
64 struct powerdomain *pwrdm;
65 void __iomem *scu_sar_addr;
66 void __iomem *wkup_sar_addr;
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +053067 void __iomem *l2x0_sar_addr;
Santosh Shilimkarb2b97622010-06-16 22:19:48 +053068};
69
70static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053071static struct powerdomain *mpuss_pd;
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +053072static void __iomem *sar_base;
Santosh Shilimkarb2b97622010-06-16 22:19:48 +053073
74/*
75 * Program the wakeup routine address for the CPU0 and CPU1
76 * used for OFF or DORMANT wakeup.
77 */
78static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
79{
80 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
81
82 __raw_writel(addr, pm_info->wkup_sar_addr);
83}
84
85/*
86 * Set the CPUx powerdomain's previous power state
87 */
88static inline void set_cpu_next_pwrst(unsigned int cpu_id,
89 unsigned int power_state)
90{
91 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
92
93 pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
94}
95
96/*
97 * Read CPU's previous power state
98 */
99static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
100{
101 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
102
103 return pwrdm_read_prev_pwrst(pm_info->pwrdm);
104}
105
106/*
107 * Clear the CPUx powerdomain's previous power state
108 */
109static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
110{
111 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
112
113 pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
114}
115
116/*
117 * Store the SCU power status value to scratchpad memory
118 */
119static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
120{
121 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
122 u32 scu_pwr_st;
123
124 switch (cpu_state) {
125 case PWRDM_POWER_RET:
126 scu_pwr_st = SCU_PM_DORMANT;
127 break;
128 case PWRDM_POWER_OFF:
129 scu_pwr_st = SCU_PM_POWEROFF;
130 break;
131 case PWRDM_POWER_ON:
132 case PWRDM_POWER_INACTIVE:
133 default:
134 scu_pwr_st = SCU_PM_NORMAL;
135 break;
136 }
137
138 __raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
139}
140
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530141/*
142 * Store the CPU cluster state for L2X0 low power operations.
143 */
144static void l2x0_pwrst_prepare(unsigned int cpu_id, unsigned int save_state)
145{
146 struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
147
148 __raw_writel(save_state, pm_info->l2x0_sar_addr);
149}
150
151/*
152 * Save the L2X0 AUXCTRL and POR value to SAR memory. Its used to
153 * in every restore MPUSS OFF path.
154 */
155#ifdef CONFIG_CACHE_L2X0
156static void save_l2x0_context(void)
157{
158 u32 val;
159 void __iomem *l2x0_base = omap4_get_l2cache_base();
160
161 val = __raw_readl(l2x0_base + L2X0_AUX_CTRL);
162 __raw_writel(val, sar_base + L2X0_AUXCTRL_OFFSET);
163 val = __raw_readl(l2x0_base + L2X0_PREFETCH_CTRL);
164 __raw_writel(val, sar_base + L2X0_PREFETCH_CTRL_OFFSET);
165}
166#else
167static void save_l2x0_context(void)
168{}
169#endif
170
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530171/**
172 * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
173 * The purpose of this function is to manage low power programming
174 * of OMAP4 MPUSS subsystem
175 * @cpu : CPU ID
176 * @power_state: Low power state.
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530177 *
178 * MPUSS states for the context save:
179 * save_state =
180 * 0 - Nothing lost and no need to save: MPUSS INACTIVE
181 * 1 - CPUx L1 and logic lost: MPUSS CSWR
182 * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
183 * 3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530184 */
185int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
186{
187 unsigned int save_state = 0;
188 unsigned int wakeup_cpu;
189
190 if (omap_rev() == OMAP4430_REV_ES1_0)
191 return -ENXIO;
192
193 switch (power_state) {
194 case PWRDM_POWER_ON:
195 case PWRDM_POWER_INACTIVE:
196 save_state = 0;
197 break;
198 case PWRDM_POWER_OFF:
199 save_state = 1;
200 break;
201 case PWRDM_POWER_RET:
202 default:
203 /*
204 * CPUx CSWR is invalid hardware state. Also CPUx OSWR
205 * doesn't make much scense, since logic is lost and $L1
206 * needs to be cleaned because of coherency. This makes
207 * CPUx OSWR equivalent to CPUX OFF and hence not supported
208 */
209 WARN_ON(1);
210 return -ENXIO;
211 }
212
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530213 pwrdm_clear_all_prev_pwrst(mpuss_pd);
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530214 clear_cpu_prev_pwrst(cpu);
215 set_cpu_next_pwrst(cpu, power_state);
216 set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume));
217 scu_pwrst_prepare(cpu, power_state);
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530218 l2x0_pwrst_prepare(cpu, save_state);
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530219
220 /*
221 * Call low level function with targeted low power state.
222 */
223 cpu_suspend(save_state, omap4_finish_suspend);
224
225 /*
226 * Restore the CPUx power state to ON otherwise CPUx
227 * power domain can transitions to programmed low power
228 * state while doing WFI outside the low powe code. On
229 * secure devices, CPUx does WFI which can result in
230 * domain transition
231 */
232 wakeup_cpu = smp_processor_id();
233 set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON);
234
235 return 0;
236}
237
Santosh Shilimkarb5b4f282010-06-16 22:19:48 +0530238/**
239 * omap4_hotplug_cpu: OMAP4 CPU hotplug entry
240 * @cpu : CPU ID
241 * @power_state: CPU low power state.
242 */
243int omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state)
244{
245 unsigned int cpu_state = 0;
246
247 if (omap_rev() == OMAP4430_REV_ES1_0)
248 return -ENXIO;
249
250 if (power_state == PWRDM_POWER_OFF)
251 cpu_state = 1;
252
253 clear_cpu_prev_pwrst(cpu);
254 set_cpu_next_pwrst(cpu, power_state);
255 set_cpu_wakeup_addr(cpu, virt_to_phys(omap_secondary_startup));
256 scu_pwrst_prepare(cpu, power_state);
257
258 /*
259 * CPU never retuns back if targetted power state is OFF mode.
260 * CPU ONLINE follows normal CPU ONLINE ptah via
261 * omap_secondary_startup().
262 */
263 omap4_finish_suspend(cpu_state);
264
265 set_cpu_next_pwrst(cpu, PWRDM_POWER_ON);
266 return 0;
267}
268
269
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530270/*
271 * Initialise OMAP4 MPUSS
272 */
273int __init omap4_mpuss_init(void)
274{
275 struct omap4_cpu_pm_info *pm_info;
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530276
277 if (omap_rev() == OMAP4430_REV_ES1_0) {
278 WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
279 return -ENODEV;
280 }
281
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530282 sar_base = omap4_get_sar_ram_base();
283
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530284 /* Initilaise per CPU PM information */
285 pm_info = &per_cpu(omap4_pm_info, 0x0);
286 pm_info->scu_sar_addr = sar_base + SCU_OFFSET0;
287 pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET;
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530288 pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET0;
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530289 pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm");
290 if (!pm_info->pwrdm) {
291 pr_err("Lookup failed for CPU0 pwrdm\n");
292 return -ENODEV;
293 }
294
295 /* Clear CPU previous power domain state */
296 pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
297
298 /* Initialise CPU0 power domain state to ON */
299 pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
300
301 pm_info = &per_cpu(omap4_pm_info, 0x1);
302 pm_info->scu_sar_addr = sar_base + SCU_OFFSET1;
303 pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET;
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530304 pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET1;
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530305 pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm");
306 if (!pm_info->pwrdm) {
307 pr_err("Lookup failed for CPU1 pwrdm\n");
308 return -ENODEV;
309 }
310
311 /* Clear CPU previous power domain state */
312 pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
313
314 /* Initialise CPU1 power domain state to ON */
315 pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
316
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530317 mpuss_pd = pwrdm_lookup("mpu_pwrdm");
318 if (!mpuss_pd) {
319 pr_err("Failed to lookup MPUSS power domain\n");
320 return -ENODEV;
321 }
322 pwrdm_clear_all_prev_pwrst(mpuss_pd);
323
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530324 /* Save device type on scratchpad for low level code to use */
325 if (omap_type() != OMAP2_DEVICE_TYPE_GP)
326 __raw_writel(1, sar_base + OMAP_TYPE_OFFSET);
327 else
328 __raw_writel(0, sar_base + OMAP_TYPE_OFFSET);
329
Santosh Shilimkar5e94c6e32011-01-09 02:59:09 +0530330 save_l2x0_context();
331
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530332 return 0;
333}
334
335#endif