xref: /openbmc/linux/arch/arm/mach-omap2/omap-mpuss-lowpower.c (revision b5b4f2881f619460fdb165111bac10a3dd8eebee)
1b2b9762fSSantosh Shilimkar /*
2b2b9762fSSantosh Shilimkar  * OMAP MPUSS low power code
3b2b9762fSSantosh Shilimkar  *
4b2b9762fSSantosh Shilimkar  * Copyright (C) 2011 Texas Instruments, Inc.
5b2b9762fSSantosh Shilimkar  *	Santosh Shilimkar <santosh.shilimkar@ti.com>
6b2b9762fSSantosh Shilimkar  *
7b2b9762fSSantosh Shilimkar  * OMAP4430 MPUSS mainly consists of dual Cortex-A9 with per-CPU
8b2b9762fSSantosh Shilimkar  * Local timer and Watchdog, GIC, SCU, PL310 L2 cache controller,
9b2b9762fSSantosh Shilimkar  * CPU0 and CPU1 LPRM modules.
10b2b9762fSSantosh Shilimkar  * CPU0, CPU1 and MPUSS each have there own power domain and
11b2b9762fSSantosh Shilimkar  * hence multiple low power combinations of MPUSS are possible.
12b2b9762fSSantosh Shilimkar  *
13b2b9762fSSantosh Shilimkar  * The CPU0 and CPU1 can't support Closed switch Retention (CSWR)
14b2b9762fSSantosh Shilimkar  * because the mode is not supported by hw constraints of dormant
15b2b9762fSSantosh Shilimkar  * mode. While waking up from the dormant mode, a reset  signal
16b2b9762fSSantosh Shilimkar  * to the Cortex-A9 processor must be asserted by the external
17b2b9762fSSantosh Shilimkar  * power controller.
18b2b9762fSSantosh Shilimkar  *
19b2b9762fSSantosh Shilimkar  * With architectural inputs and hardware recommendations, only
20b2b9762fSSantosh Shilimkar  * below modes are supported from power gain vs latency point of view.
21b2b9762fSSantosh Shilimkar  *
22b2b9762fSSantosh Shilimkar  *	CPU0		CPU1		MPUSS
23b2b9762fSSantosh Shilimkar  *	----------------------------------------------
24b2b9762fSSantosh Shilimkar  *	ON		ON		ON
25b2b9762fSSantosh Shilimkar  *	ON(Inactive)	OFF		ON(Inactive)
26b2b9762fSSantosh Shilimkar  *	OFF		OFF		CSWR
27b2b9762fSSantosh Shilimkar  *	OFF		OFF		OSWR (*TBD)
28b2b9762fSSantosh Shilimkar  *	OFF		OFF		OFF* (*TBD)
29b2b9762fSSantosh Shilimkar  *	----------------------------------------------
30b2b9762fSSantosh Shilimkar  *
31b2b9762fSSantosh Shilimkar  * Note: CPU0 is the master core and it is the last CPU to go down
32b2b9762fSSantosh Shilimkar  * and first to wake-up when MPUSS low power states are excercised
33b2b9762fSSantosh Shilimkar  *
34b2b9762fSSantosh Shilimkar  *
35b2b9762fSSantosh Shilimkar  * This program is free software; you can redistribute it and/or modify
36b2b9762fSSantosh Shilimkar  * it under the terms of the GNU General Public License version 2 as
37b2b9762fSSantosh Shilimkar  * published by the Free Software Foundation.
38b2b9762fSSantosh Shilimkar  */
39b2b9762fSSantosh Shilimkar 
40b2b9762fSSantosh Shilimkar #include <linux/kernel.h>
41b2b9762fSSantosh Shilimkar #include <linux/io.h>
42b2b9762fSSantosh Shilimkar #include <linux/errno.h>
43b2b9762fSSantosh Shilimkar #include <linux/linkage.h>
44b2b9762fSSantosh Shilimkar #include <linux/smp.h>
45b2b9762fSSantosh Shilimkar 
46b2b9762fSSantosh Shilimkar #include <asm/cacheflush.h>
47b2b9762fSSantosh Shilimkar #include <asm/tlbflush.h>
48b2b9762fSSantosh Shilimkar #include <asm/smp_scu.h>
49b2b9762fSSantosh Shilimkar #include <asm/system.h>
50b2b9762fSSantosh Shilimkar #include <asm/pgalloc.h>
51b2b9762fSSantosh Shilimkar #include <asm/suspend.h>
52b2b9762fSSantosh Shilimkar 
53b2b9762fSSantosh Shilimkar #include <plat/omap44xx.h>
54b2b9762fSSantosh Shilimkar 
55b2b9762fSSantosh Shilimkar #include "common.h"
56b2b9762fSSantosh Shilimkar #include "omap4-sar-layout.h"
57b2b9762fSSantosh Shilimkar #include "pm.h"
58b2b9762fSSantosh Shilimkar #include "powerdomain.h"
59b2b9762fSSantosh Shilimkar 
60b2b9762fSSantosh Shilimkar #ifdef CONFIG_SMP
61b2b9762fSSantosh Shilimkar 
62b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info {
63b2b9762fSSantosh Shilimkar 	struct powerdomain *pwrdm;
64b2b9762fSSantosh Shilimkar 	void __iomem *scu_sar_addr;
65b2b9762fSSantosh Shilimkar 	void __iomem *wkup_sar_addr;
66b2b9762fSSantosh Shilimkar };
67b2b9762fSSantosh Shilimkar 
68b2b9762fSSantosh Shilimkar static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
69b2b9762fSSantosh Shilimkar 
70b2b9762fSSantosh Shilimkar /*
71b2b9762fSSantosh Shilimkar  * Program the wakeup routine address for the CPU0 and CPU1
72b2b9762fSSantosh Shilimkar  * used for OFF or DORMANT wakeup.
73b2b9762fSSantosh Shilimkar  */
74b2b9762fSSantosh Shilimkar static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
75b2b9762fSSantosh Shilimkar {
76b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
77b2b9762fSSantosh Shilimkar 
78b2b9762fSSantosh Shilimkar 	__raw_writel(addr, pm_info->wkup_sar_addr);
79b2b9762fSSantosh Shilimkar }
80b2b9762fSSantosh Shilimkar 
81b2b9762fSSantosh Shilimkar /*
82b2b9762fSSantosh Shilimkar  * Set the CPUx powerdomain's previous power state
83b2b9762fSSantosh Shilimkar  */
84b2b9762fSSantosh Shilimkar static inline void set_cpu_next_pwrst(unsigned int cpu_id,
85b2b9762fSSantosh Shilimkar 				unsigned int power_state)
86b2b9762fSSantosh Shilimkar {
87b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
88b2b9762fSSantosh Shilimkar 
89b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
90b2b9762fSSantosh Shilimkar }
91b2b9762fSSantosh Shilimkar 
92b2b9762fSSantosh Shilimkar /*
93b2b9762fSSantosh Shilimkar  * Read CPU's previous power state
94b2b9762fSSantosh Shilimkar  */
95b2b9762fSSantosh Shilimkar static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
96b2b9762fSSantosh Shilimkar {
97b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
98b2b9762fSSantosh Shilimkar 
99b2b9762fSSantosh Shilimkar 	return pwrdm_read_prev_pwrst(pm_info->pwrdm);
100b2b9762fSSantosh Shilimkar }
101b2b9762fSSantosh Shilimkar 
102b2b9762fSSantosh Shilimkar /*
103b2b9762fSSantosh Shilimkar  * Clear the CPUx powerdomain's previous power state
104b2b9762fSSantosh Shilimkar  */
105b2b9762fSSantosh Shilimkar static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
106b2b9762fSSantosh Shilimkar {
107b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
108b2b9762fSSantosh Shilimkar 
109b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
110b2b9762fSSantosh Shilimkar }
111b2b9762fSSantosh Shilimkar 
112b2b9762fSSantosh Shilimkar /*
113b2b9762fSSantosh Shilimkar  * Store the SCU power status value to scratchpad memory
114b2b9762fSSantosh Shilimkar  */
115b2b9762fSSantosh Shilimkar static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
116b2b9762fSSantosh Shilimkar {
117b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
118b2b9762fSSantosh Shilimkar 	u32 scu_pwr_st;
119b2b9762fSSantosh Shilimkar 
120b2b9762fSSantosh Shilimkar 	switch (cpu_state) {
121b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_RET:
122b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_DORMANT;
123b2b9762fSSantosh Shilimkar 		break;
124b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_OFF:
125b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_POWEROFF;
126b2b9762fSSantosh Shilimkar 		break;
127b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_ON:
128b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_INACTIVE:
129b2b9762fSSantosh Shilimkar 	default:
130b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_NORMAL;
131b2b9762fSSantosh Shilimkar 		break;
132b2b9762fSSantosh Shilimkar 	}
133b2b9762fSSantosh Shilimkar 
134b2b9762fSSantosh Shilimkar 	__raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
135b2b9762fSSantosh Shilimkar }
136b2b9762fSSantosh Shilimkar 
137b2b9762fSSantosh Shilimkar /**
138b2b9762fSSantosh Shilimkar  * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
139b2b9762fSSantosh Shilimkar  * The purpose of this function is to manage low power programming
140b2b9762fSSantosh Shilimkar  * of OMAP4 MPUSS subsystem
141b2b9762fSSantosh Shilimkar  * @cpu : CPU ID
142b2b9762fSSantosh Shilimkar  * @power_state: Low power state.
143b2b9762fSSantosh Shilimkar  */
144b2b9762fSSantosh Shilimkar int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
145b2b9762fSSantosh Shilimkar {
146b2b9762fSSantosh Shilimkar 	unsigned int save_state = 0;
147b2b9762fSSantosh Shilimkar 	unsigned int wakeup_cpu;
148b2b9762fSSantosh Shilimkar 
149b2b9762fSSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0)
150b2b9762fSSantosh Shilimkar 		return -ENXIO;
151b2b9762fSSantosh Shilimkar 
152b2b9762fSSantosh Shilimkar 	switch (power_state) {
153b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_ON:
154b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_INACTIVE:
155b2b9762fSSantosh Shilimkar 		save_state = 0;
156b2b9762fSSantosh Shilimkar 		break;
157b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_OFF:
158b2b9762fSSantosh Shilimkar 		save_state = 1;
159b2b9762fSSantosh Shilimkar 		break;
160b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_RET:
161b2b9762fSSantosh Shilimkar 	default:
162b2b9762fSSantosh Shilimkar 		/*
163b2b9762fSSantosh Shilimkar 		 * CPUx CSWR is invalid hardware state. Also CPUx OSWR
164b2b9762fSSantosh Shilimkar 		 * doesn't make much scense, since logic is lost and $L1
165b2b9762fSSantosh Shilimkar 		 * needs to be cleaned because of coherency. This makes
166b2b9762fSSantosh Shilimkar 		 * CPUx OSWR equivalent to CPUX OFF and hence not supported
167b2b9762fSSantosh Shilimkar 		 */
168b2b9762fSSantosh Shilimkar 		WARN_ON(1);
169b2b9762fSSantosh Shilimkar 		return -ENXIO;
170b2b9762fSSantosh Shilimkar 	}
171b2b9762fSSantosh Shilimkar 
172b2b9762fSSantosh Shilimkar 	clear_cpu_prev_pwrst(cpu);
173b2b9762fSSantosh Shilimkar 	set_cpu_next_pwrst(cpu, power_state);
174b2b9762fSSantosh Shilimkar 	set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume));
175b2b9762fSSantosh Shilimkar 	scu_pwrst_prepare(cpu, power_state);
176b2b9762fSSantosh Shilimkar 
177b2b9762fSSantosh Shilimkar 	/*
178b2b9762fSSantosh Shilimkar 	 * Call low level function  with targeted low power state.
179b2b9762fSSantosh Shilimkar 	 */
180b2b9762fSSantosh Shilimkar 	cpu_suspend(save_state, omap4_finish_suspend);
181b2b9762fSSantosh Shilimkar 
182b2b9762fSSantosh Shilimkar 	/*
183b2b9762fSSantosh Shilimkar 	 * Restore the CPUx power state to ON otherwise CPUx
184b2b9762fSSantosh Shilimkar 	 * power domain can transitions to programmed low power
185b2b9762fSSantosh Shilimkar 	 * state while doing WFI outside the low powe code. On
186b2b9762fSSantosh Shilimkar 	 * secure devices, CPUx does WFI which can result in
187b2b9762fSSantosh Shilimkar 	 * domain transition
188b2b9762fSSantosh Shilimkar 	 */
189b2b9762fSSantosh Shilimkar 	wakeup_cpu = smp_processor_id();
190b2b9762fSSantosh Shilimkar 	set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON);
191b2b9762fSSantosh Shilimkar 
192b2b9762fSSantosh Shilimkar 	return 0;
193b2b9762fSSantosh Shilimkar }
194b2b9762fSSantosh Shilimkar 
195*b5b4f288SSantosh Shilimkar /**
196*b5b4f288SSantosh Shilimkar  * omap4_hotplug_cpu: OMAP4 CPU hotplug entry
197*b5b4f288SSantosh Shilimkar  * @cpu : CPU ID
198*b5b4f288SSantosh Shilimkar  * @power_state: CPU low power state.
199*b5b4f288SSantosh Shilimkar  */
200*b5b4f288SSantosh Shilimkar int omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state)
201*b5b4f288SSantosh Shilimkar {
202*b5b4f288SSantosh Shilimkar 	unsigned int cpu_state = 0;
203*b5b4f288SSantosh Shilimkar 
204*b5b4f288SSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0)
205*b5b4f288SSantosh Shilimkar 		return -ENXIO;
206*b5b4f288SSantosh Shilimkar 
207*b5b4f288SSantosh Shilimkar 	if (power_state == PWRDM_POWER_OFF)
208*b5b4f288SSantosh Shilimkar 		cpu_state = 1;
209*b5b4f288SSantosh Shilimkar 
210*b5b4f288SSantosh Shilimkar 	clear_cpu_prev_pwrst(cpu);
211*b5b4f288SSantosh Shilimkar 	set_cpu_next_pwrst(cpu, power_state);
212*b5b4f288SSantosh Shilimkar 	set_cpu_wakeup_addr(cpu, virt_to_phys(omap_secondary_startup));
213*b5b4f288SSantosh Shilimkar 	scu_pwrst_prepare(cpu, power_state);
214*b5b4f288SSantosh Shilimkar 
215*b5b4f288SSantosh Shilimkar 	/*
216*b5b4f288SSantosh Shilimkar 	 * CPU never retuns back if targetted power state is OFF mode.
217*b5b4f288SSantosh Shilimkar 	 * CPU ONLINE follows normal CPU ONLINE ptah via
218*b5b4f288SSantosh Shilimkar 	 * omap_secondary_startup().
219*b5b4f288SSantosh Shilimkar 	 */
220*b5b4f288SSantosh Shilimkar 	omap4_finish_suspend(cpu_state);
221*b5b4f288SSantosh Shilimkar 
222*b5b4f288SSantosh Shilimkar 	set_cpu_next_pwrst(cpu, PWRDM_POWER_ON);
223*b5b4f288SSantosh Shilimkar 	return 0;
224*b5b4f288SSantosh Shilimkar }
225*b5b4f288SSantosh Shilimkar 
226*b5b4f288SSantosh Shilimkar 
227b2b9762fSSantosh Shilimkar /*
228b2b9762fSSantosh Shilimkar  * Initialise OMAP4 MPUSS
229b2b9762fSSantosh Shilimkar  */
230b2b9762fSSantosh Shilimkar int __init omap4_mpuss_init(void)
231b2b9762fSSantosh Shilimkar {
232b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info;
233b2b9762fSSantosh Shilimkar 	void __iomem *sar_base = omap4_get_sar_ram_base();
234b2b9762fSSantosh Shilimkar 
235b2b9762fSSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0) {
236b2b9762fSSantosh Shilimkar 		WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
237b2b9762fSSantosh Shilimkar 		return -ENODEV;
238b2b9762fSSantosh Shilimkar 	}
239b2b9762fSSantosh Shilimkar 
240b2b9762fSSantosh Shilimkar 	/* Initilaise per CPU PM information */
241b2b9762fSSantosh Shilimkar 	pm_info = &per_cpu(omap4_pm_info, 0x0);
242b2b9762fSSantosh Shilimkar 	pm_info->scu_sar_addr = sar_base + SCU_OFFSET0;
243b2b9762fSSantosh Shilimkar 	pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET;
244b2b9762fSSantosh Shilimkar 	pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm");
245b2b9762fSSantosh Shilimkar 	if (!pm_info->pwrdm) {
246b2b9762fSSantosh Shilimkar 		pr_err("Lookup failed for CPU0 pwrdm\n");
247b2b9762fSSantosh Shilimkar 		return -ENODEV;
248b2b9762fSSantosh Shilimkar 	}
249b2b9762fSSantosh Shilimkar 
250b2b9762fSSantosh Shilimkar 	/* Clear CPU previous power domain state */
251b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
252b2b9762fSSantosh Shilimkar 
253b2b9762fSSantosh Shilimkar 	/* Initialise CPU0 power domain state to ON */
254b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
255b2b9762fSSantosh Shilimkar 
256b2b9762fSSantosh Shilimkar 	pm_info = &per_cpu(omap4_pm_info, 0x1);
257b2b9762fSSantosh Shilimkar 	pm_info->scu_sar_addr = sar_base + SCU_OFFSET1;
258b2b9762fSSantosh Shilimkar 	pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET;
259b2b9762fSSantosh Shilimkar 	pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm");
260b2b9762fSSantosh Shilimkar 	if (!pm_info->pwrdm) {
261b2b9762fSSantosh Shilimkar 		pr_err("Lookup failed for CPU1 pwrdm\n");
262b2b9762fSSantosh Shilimkar 		return -ENODEV;
263b2b9762fSSantosh Shilimkar 	}
264b2b9762fSSantosh Shilimkar 
265b2b9762fSSantosh Shilimkar 	/* Clear CPU previous power domain state */
266b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
267b2b9762fSSantosh Shilimkar 
268b2b9762fSSantosh Shilimkar 	/* Initialise CPU1 power domain state to ON */
269b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
270b2b9762fSSantosh Shilimkar 
271b2b9762fSSantosh Shilimkar 	/* Save device type on scratchpad for low level code to use */
272b2b9762fSSantosh Shilimkar 	if (omap_type() != OMAP2_DEVICE_TYPE_GP)
273b2b9762fSSantosh Shilimkar 		__raw_writel(1, sar_base + OMAP_TYPE_OFFSET);
274b2b9762fSSantosh Shilimkar 	else
275b2b9762fSSantosh Shilimkar 		__raw_writel(0, sar_base + OMAP_TYPE_OFFSET);
276b2b9762fSSantosh Shilimkar 
277b2b9762fSSantosh Shilimkar 	return 0;
278b2b9762fSSantosh Shilimkar }
279b2b9762fSSantosh Shilimkar 
280b2b9762fSSantosh Shilimkar #endif
281