xref: /openbmc/linux/arch/arm/mach-omap2/omap-mpuss-lowpower.c (revision ccdeed6281296977f67f57d048fdeec542428ce1)
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
273ba2a739SSantosh Shilimkar  *	OFF		OFF		OSWR
283ba2a739SSantosh Shilimkar  *	OFF		OFF		OFF(Device 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>
525e94c6e3SSantosh Shilimkar #include <asm/hardware/cache-l2x0.h>
53b2b9762fSSantosh Shilimkar 
54b2b9762fSSantosh Shilimkar #include <plat/omap44xx.h>
55b2b9762fSSantosh Shilimkar 
56b2b9762fSSantosh Shilimkar #include "common.h"
57b2b9762fSSantosh Shilimkar #include "omap4-sar-layout.h"
58b2b9762fSSantosh Shilimkar #include "pm.h"
593ba2a739SSantosh Shilimkar #include "prcm_mpu44xx.h"
603ba2a739SSantosh Shilimkar #include "prminst44xx.h"
613ba2a739SSantosh Shilimkar #include "prcm44xx.h"
623ba2a739SSantosh Shilimkar #include "prm44xx.h"
633ba2a739SSantosh Shilimkar #include "prm-regbits-44xx.h"
64b2b9762fSSantosh Shilimkar 
65b2b9762fSSantosh Shilimkar #ifdef CONFIG_SMP
66b2b9762fSSantosh Shilimkar 
67b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info {
68b2b9762fSSantosh Shilimkar 	struct powerdomain *pwrdm;
69b2b9762fSSantosh Shilimkar 	void __iomem *scu_sar_addr;
70b2b9762fSSantosh Shilimkar 	void __iomem *wkup_sar_addr;
715e94c6e3SSantosh Shilimkar 	void __iomem *l2x0_sar_addr;
72b2b9762fSSantosh Shilimkar };
73b2b9762fSSantosh Shilimkar 
74b2b9762fSSantosh Shilimkar static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
75e44f9a77SSantosh Shilimkar static struct powerdomain *mpuss_pd;
765e94c6e3SSantosh Shilimkar static void __iomem *sar_base;
77b2b9762fSSantosh Shilimkar 
78b2b9762fSSantosh Shilimkar /*
79b2b9762fSSantosh Shilimkar  * Program the wakeup routine address for the CPU0 and CPU1
80b2b9762fSSantosh Shilimkar  * used for OFF or DORMANT wakeup.
81b2b9762fSSantosh Shilimkar  */
82b2b9762fSSantosh Shilimkar static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
83b2b9762fSSantosh Shilimkar {
84b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
85b2b9762fSSantosh Shilimkar 
86b2b9762fSSantosh Shilimkar 	__raw_writel(addr, pm_info->wkup_sar_addr);
87b2b9762fSSantosh Shilimkar }
88b2b9762fSSantosh Shilimkar 
89b2b9762fSSantosh Shilimkar /*
90b2b9762fSSantosh Shilimkar  * Set the CPUx powerdomain's previous power state
91b2b9762fSSantosh Shilimkar  */
92b2b9762fSSantosh Shilimkar static inline void set_cpu_next_pwrst(unsigned int cpu_id,
93b2b9762fSSantosh Shilimkar 				unsigned int power_state)
94b2b9762fSSantosh Shilimkar {
95b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
96b2b9762fSSantosh Shilimkar 
97b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
98b2b9762fSSantosh Shilimkar }
99b2b9762fSSantosh Shilimkar 
100b2b9762fSSantosh Shilimkar /*
101b2b9762fSSantosh Shilimkar  * Read CPU's previous power state
102b2b9762fSSantosh Shilimkar  */
103b2b9762fSSantosh Shilimkar static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
104b2b9762fSSantosh Shilimkar {
105b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
106b2b9762fSSantosh Shilimkar 
107b2b9762fSSantosh Shilimkar 	return pwrdm_read_prev_pwrst(pm_info->pwrdm);
108b2b9762fSSantosh Shilimkar }
109b2b9762fSSantosh Shilimkar 
110b2b9762fSSantosh Shilimkar /*
111b2b9762fSSantosh Shilimkar  * Clear the CPUx powerdomain's previous power state
112b2b9762fSSantosh Shilimkar  */
113b2b9762fSSantosh Shilimkar static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
114b2b9762fSSantosh Shilimkar {
115b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
116b2b9762fSSantosh Shilimkar 
117b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
118b2b9762fSSantosh Shilimkar }
119b2b9762fSSantosh Shilimkar 
120b2b9762fSSantosh Shilimkar /*
121b2b9762fSSantosh Shilimkar  * Store the SCU power status value to scratchpad memory
122b2b9762fSSantosh Shilimkar  */
123b2b9762fSSantosh Shilimkar static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
124b2b9762fSSantosh Shilimkar {
125b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
126b2b9762fSSantosh Shilimkar 	u32 scu_pwr_st;
127b2b9762fSSantosh Shilimkar 
128b2b9762fSSantosh Shilimkar 	switch (cpu_state) {
129b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_RET:
130b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_DORMANT;
131b2b9762fSSantosh Shilimkar 		break;
132b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_OFF:
133b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_POWEROFF;
134b2b9762fSSantosh Shilimkar 		break;
135b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_ON:
136b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_INACTIVE:
137b2b9762fSSantosh Shilimkar 	default:
138b2b9762fSSantosh Shilimkar 		scu_pwr_st = SCU_PM_NORMAL;
139b2b9762fSSantosh Shilimkar 		break;
140b2b9762fSSantosh Shilimkar 	}
141b2b9762fSSantosh Shilimkar 
142b2b9762fSSantosh Shilimkar 	__raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
143b2b9762fSSantosh Shilimkar }
144b2b9762fSSantosh Shilimkar 
1453ba2a739SSantosh Shilimkar /* Helper functions for MPUSS OSWR */
1463ba2a739SSantosh Shilimkar static inline void mpuss_clear_prev_logic_pwrst(void)
1473ba2a739SSantosh Shilimkar {
1483ba2a739SSantosh Shilimkar 	u32 reg;
1493ba2a739SSantosh Shilimkar 
1503ba2a739SSantosh Shilimkar 	reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
1513ba2a739SSantosh Shilimkar 		OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
1523ba2a739SSantosh Shilimkar 	omap4_prminst_write_inst_reg(reg, OMAP4430_PRM_PARTITION,
1533ba2a739SSantosh Shilimkar 		OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
1543ba2a739SSantosh Shilimkar }
1553ba2a739SSantosh Shilimkar 
1563ba2a739SSantosh Shilimkar static inline void cpu_clear_prev_logic_pwrst(unsigned int cpu_id)
1573ba2a739SSantosh Shilimkar {
1583ba2a739SSantosh Shilimkar 	u32 reg;
1593ba2a739SSantosh Shilimkar 
1603ba2a739SSantosh Shilimkar 	if (cpu_id) {
1613ba2a739SSantosh Shilimkar 		reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU1_INST,
1623ba2a739SSantosh Shilimkar 					OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
1633ba2a739SSantosh Shilimkar 		omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU1_INST,
1643ba2a739SSantosh Shilimkar 					OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
1653ba2a739SSantosh Shilimkar 	} else {
1663ba2a739SSantosh Shilimkar 		reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU0_INST,
1673ba2a739SSantosh Shilimkar 					OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
1683ba2a739SSantosh Shilimkar 		omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU0_INST,
1693ba2a739SSantosh Shilimkar 					OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
1703ba2a739SSantosh Shilimkar 	}
1713ba2a739SSantosh Shilimkar }
1723ba2a739SSantosh Shilimkar 
1733ba2a739SSantosh Shilimkar /**
1743ba2a739SSantosh Shilimkar  * omap4_mpuss_read_prev_context_state:
1753ba2a739SSantosh Shilimkar  * Function returns the MPUSS previous context state
1763ba2a739SSantosh Shilimkar  */
1773ba2a739SSantosh Shilimkar u32 omap4_mpuss_read_prev_context_state(void)
1783ba2a739SSantosh Shilimkar {
1793ba2a739SSantosh Shilimkar 	u32 reg;
1803ba2a739SSantosh Shilimkar 
1813ba2a739SSantosh Shilimkar 	reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
1823ba2a739SSantosh Shilimkar 		OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
1833ba2a739SSantosh Shilimkar 	reg &= OMAP4430_LOSTCONTEXT_DFF_MASK;
1843ba2a739SSantosh Shilimkar 	return reg;
1853ba2a739SSantosh Shilimkar }
1863ba2a739SSantosh Shilimkar 
1875e94c6e3SSantosh Shilimkar /*
1885e94c6e3SSantosh Shilimkar  * Store the CPU cluster state for L2X0 low power operations.
1895e94c6e3SSantosh Shilimkar  */
1905e94c6e3SSantosh Shilimkar static void l2x0_pwrst_prepare(unsigned int cpu_id, unsigned int save_state)
1915e94c6e3SSantosh Shilimkar {
1925e94c6e3SSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
1935e94c6e3SSantosh Shilimkar 
1945e94c6e3SSantosh Shilimkar 	__raw_writel(save_state, pm_info->l2x0_sar_addr);
1955e94c6e3SSantosh Shilimkar }
1965e94c6e3SSantosh Shilimkar 
1975e94c6e3SSantosh Shilimkar /*
1985e94c6e3SSantosh Shilimkar  * Save the L2X0 AUXCTRL and POR value to SAR memory. Its used to
1995e94c6e3SSantosh Shilimkar  * in every restore MPUSS OFF path.
2005e94c6e3SSantosh Shilimkar  */
2015e94c6e3SSantosh Shilimkar #ifdef CONFIG_CACHE_L2X0
2025e94c6e3SSantosh Shilimkar static void save_l2x0_context(void)
2035e94c6e3SSantosh Shilimkar {
2045e94c6e3SSantosh Shilimkar 	u32 val;
2055e94c6e3SSantosh Shilimkar 	void __iomem *l2x0_base = omap4_get_l2cache_base();
2065e94c6e3SSantosh Shilimkar 
2075e94c6e3SSantosh Shilimkar 	val = __raw_readl(l2x0_base + L2X0_AUX_CTRL);
2085e94c6e3SSantosh Shilimkar 	__raw_writel(val, sar_base + L2X0_AUXCTRL_OFFSET);
2095e94c6e3SSantosh Shilimkar 	val = __raw_readl(l2x0_base + L2X0_PREFETCH_CTRL);
2105e94c6e3SSantosh Shilimkar 	__raw_writel(val, sar_base + L2X0_PREFETCH_CTRL_OFFSET);
2115e94c6e3SSantosh Shilimkar }
2125e94c6e3SSantosh Shilimkar #else
2135e94c6e3SSantosh Shilimkar static void save_l2x0_context(void)
2145e94c6e3SSantosh Shilimkar {}
2155e94c6e3SSantosh Shilimkar #endif
2165e94c6e3SSantosh Shilimkar 
217b2b9762fSSantosh Shilimkar /**
218b2b9762fSSantosh Shilimkar  * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
219b2b9762fSSantosh Shilimkar  * The purpose of this function is to manage low power programming
220b2b9762fSSantosh Shilimkar  * of OMAP4 MPUSS subsystem
221b2b9762fSSantosh Shilimkar  * @cpu : CPU ID
222b2b9762fSSantosh Shilimkar  * @power_state: Low power state.
223e44f9a77SSantosh Shilimkar  *
224e44f9a77SSantosh Shilimkar  * MPUSS states for the context save:
225e44f9a77SSantosh Shilimkar  * save_state =
226e44f9a77SSantosh Shilimkar  *	0 - Nothing lost and no need to save: MPUSS INACTIVE
227e44f9a77SSantosh Shilimkar  *	1 - CPUx L1 and logic lost: MPUSS CSWR
228e44f9a77SSantosh Shilimkar  *	2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
229e44f9a77SSantosh Shilimkar  *	3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF
230b2b9762fSSantosh Shilimkar  */
231b2b9762fSSantosh Shilimkar int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
232b2b9762fSSantosh Shilimkar {
233b2b9762fSSantosh Shilimkar 	unsigned int save_state = 0;
234b2b9762fSSantosh Shilimkar 	unsigned int wakeup_cpu;
235b2b9762fSSantosh Shilimkar 
236b2b9762fSSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0)
237b2b9762fSSantosh Shilimkar 		return -ENXIO;
238b2b9762fSSantosh Shilimkar 
239b2b9762fSSantosh Shilimkar 	switch (power_state) {
240b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_ON:
241b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_INACTIVE:
242b2b9762fSSantosh Shilimkar 		save_state = 0;
243b2b9762fSSantosh Shilimkar 		break;
244b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_OFF:
245b2b9762fSSantosh Shilimkar 		save_state = 1;
246b2b9762fSSantosh Shilimkar 		break;
247b2b9762fSSantosh Shilimkar 	case PWRDM_POWER_RET:
248b2b9762fSSantosh Shilimkar 	default:
249b2b9762fSSantosh Shilimkar 		/*
250b2b9762fSSantosh Shilimkar 		 * CPUx CSWR is invalid hardware state. Also CPUx OSWR
251b2b9762fSSantosh Shilimkar 		 * doesn't make much scense, since logic is lost and $L1
252b2b9762fSSantosh Shilimkar 		 * needs to be cleaned because of coherency. This makes
253b2b9762fSSantosh Shilimkar 		 * CPUx OSWR equivalent to CPUX OFF and hence not supported
254b2b9762fSSantosh Shilimkar 		 */
255b2b9762fSSantosh Shilimkar 		WARN_ON(1);
256b2b9762fSSantosh Shilimkar 		return -ENXIO;
257b2b9762fSSantosh Shilimkar 	}
258b2b9762fSSantosh Shilimkar 
25949404dd0SSantosh Shilimkar 	pwrdm_pre_transition();
26049404dd0SSantosh Shilimkar 
2613ba2a739SSantosh Shilimkar 	/*
2623ba2a739SSantosh Shilimkar 	 * Check MPUSS next state and save interrupt controller if needed.
2633ba2a739SSantosh Shilimkar 	 * In MPUSS OSWR or device OFF, interrupt controller  contest is lost.
2643ba2a739SSantosh Shilimkar 	 */
2653ba2a739SSantosh Shilimkar 	mpuss_clear_prev_logic_pwrst();
266e44f9a77SSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(mpuss_pd);
2673ba2a739SSantosh Shilimkar 	if ((pwrdm_read_next_pwrst(mpuss_pd) == PWRDM_POWER_RET) &&
2683ba2a739SSantosh Shilimkar 		(pwrdm_read_logic_retst(mpuss_pd) == PWRDM_POWER_OFF))
2693ba2a739SSantosh Shilimkar 		save_state = 2;
2703ba2a739SSantosh Shilimkar 
271b2b9762fSSantosh Shilimkar 	clear_cpu_prev_pwrst(cpu);
2723ba2a739SSantosh Shilimkar 	cpu_clear_prev_logic_pwrst(cpu);
273b2b9762fSSantosh Shilimkar 	set_cpu_next_pwrst(cpu, power_state);
274b2b9762fSSantosh Shilimkar 	set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume));
275b2b9762fSSantosh Shilimkar 	scu_pwrst_prepare(cpu, power_state);
2765e94c6e3SSantosh Shilimkar 	l2x0_pwrst_prepare(cpu, save_state);
277b2b9762fSSantosh Shilimkar 
278b2b9762fSSantosh Shilimkar 	/*
279b2b9762fSSantosh Shilimkar 	 * Call low level function  with targeted low power state.
280b2b9762fSSantosh Shilimkar 	 */
281b2b9762fSSantosh Shilimkar 	cpu_suspend(save_state, omap4_finish_suspend);
282b2b9762fSSantosh Shilimkar 
283b2b9762fSSantosh Shilimkar 	/*
284b2b9762fSSantosh Shilimkar 	 * Restore the CPUx power state to ON otherwise CPUx
285b2b9762fSSantosh Shilimkar 	 * power domain can transitions to programmed low power
286b2b9762fSSantosh Shilimkar 	 * state while doing WFI outside the low powe code. On
287b2b9762fSSantosh Shilimkar 	 * secure devices, CPUx does WFI which can result in
288b2b9762fSSantosh Shilimkar 	 * domain transition
289b2b9762fSSantosh Shilimkar 	 */
290b2b9762fSSantosh Shilimkar 	wakeup_cpu = smp_processor_id();
291b2b9762fSSantosh Shilimkar 	set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON);
292b2b9762fSSantosh Shilimkar 
29349404dd0SSantosh Shilimkar 	pwrdm_post_transition();
29449404dd0SSantosh Shilimkar 
295b2b9762fSSantosh Shilimkar 	return 0;
296b2b9762fSSantosh Shilimkar }
297b2b9762fSSantosh Shilimkar 
298b5b4f288SSantosh Shilimkar /**
299b5b4f288SSantosh Shilimkar  * omap4_hotplug_cpu: OMAP4 CPU hotplug entry
300b5b4f288SSantosh Shilimkar  * @cpu : CPU ID
301b5b4f288SSantosh Shilimkar  * @power_state: CPU low power state.
302b5b4f288SSantosh Shilimkar  */
303*ccdeed62SSantosh Shilimkar int __cpuinit omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state)
304b5b4f288SSantosh Shilimkar {
305b5b4f288SSantosh Shilimkar 	unsigned int cpu_state = 0;
306b5b4f288SSantosh Shilimkar 
307b5b4f288SSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0)
308b5b4f288SSantosh Shilimkar 		return -ENXIO;
309b5b4f288SSantosh Shilimkar 
310b5b4f288SSantosh Shilimkar 	if (power_state == PWRDM_POWER_OFF)
311b5b4f288SSantosh Shilimkar 		cpu_state = 1;
312b5b4f288SSantosh Shilimkar 
313b5b4f288SSantosh Shilimkar 	clear_cpu_prev_pwrst(cpu);
314b5b4f288SSantosh Shilimkar 	set_cpu_next_pwrst(cpu, power_state);
315b5b4f288SSantosh Shilimkar 	set_cpu_wakeup_addr(cpu, virt_to_phys(omap_secondary_startup));
316b5b4f288SSantosh Shilimkar 	scu_pwrst_prepare(cpu, power_state);
317b5b4f288SSantosh Shilimkar 
318b5b4f288SSantosh Shilimkar 	/*
319b5b4f288SSantosh Shilimkar 	 * CPU never retuns back if targetted power state is OFF mode.
320b5b4f288SSantosh Shilimkar 	 * CPU ONLINE follows normal CPU ONLINE ptah via
321b5b4f288SSantosh Shilimkar 	 * omap_secondary_startup().
322b5b4f288SSantosh Shilimkar 	 */
323b5b4f288SSantosh Shilimkar 	omap4_finish_suspend(cpu_state);
324b5b4f288SSantosh Shilimkar 
325b5b4f288SSantosh Shilimkar 	set_cpu_next_pwrst(cpu, PWRDM_POWER_ON);
326b5b4f288SSantosh Shilimkar 	return 0;
327b5b4f288SSantosh Shilimkar }
328b5b4f288SSantosh Shilimkar 
329b5b4f288SSantosh Shilimkar 
330b2b9762fSSantosh Shilimkar /*
331b2b9762fSSantosh Shilimkar  * Initialise OMAP4 MPUSS
332b2b9762fSSantosh Shilimkar  */
333b2b9762fSSantosh Shilimkar int __init omap4_mpuss_init(void)
334b2b9762fSSantosh Shilimkar {
335b2b9762fSSantosh Shilimkar 	struct omap4_cpu_pm_info *pm_info;
336b2b9762fSSantosh Shilimkar 
337b2b9762fSSantosh Shilimkar 	if (omap_rev() == OMAP4430_REV_ES1_0) {
338b2b9762fSSantosh Shilimkar 		WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
339b2b9762fSSantosh Shilimkar 		return -ENODEV;
340b2b9762fSSantosh Shilimkar 	}
341b2b9762fSSantosh Shilimkar 
3425e94c6e3SSantosh Shilimkar 	sar_base = omap4_get_sar_ram_base();
3435e94c6e3SSantosh Shilimkar 
344b2b9762fSSantosh Shilimkar 	/* Initilaise per CPU PM information */
345b2b9762fSSantosh Shilimkar 	pm_info = &per_cpu(omap4_pm_info, 0x0);
346b2b9762fSSantosh Shilimkar 	pm_info->scu_sar_addr = sar_base + SCU_OFFSET0;
347b2b9762fSSantosh Shilimkar 	pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET;
3485e94c6e3SSantosh Shilimkar 	pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET0;
349b2b9762fSSantosh Shilimkar 	pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm");
350b2b9762fSSantosh Shilimkar 	if (!pm_info->pwrdm) {
351b2b9762fSSantosh Shilimkar 		pr_err("Lookup failed for CPU0 pwrdm\n");
352b2b9762fSSantosh Shilimkar 		return -ENODEV;
353b2b9762fSSantosh Shilimkar 	}
354b2b9762fSSantosh Shilimkar 
355b2b9762fSSantosh Shilimkar 	/* Clear CPU previous power domain state */
356b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
3573ba2a739SSantosh Shilimkar 	cpu_clear_prev_logic_pwrst(0);
358b2b9762fSSantosh Shilimkar 
359b2b9762fSSantosh Shilimkar 	/* Initialise CPU0 power domain state to ON */
360b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
361b2b9762fSSantosh Shilimkar 
362b2b9762fSSantosh Shilimkar 	pm_info = &per_cpu(omap4_pm_info, 0x1);
363b2b9762fSSantosh Shilimkar 	pm_info->scu_sar_addr = sar_base + SCU_OFFSET1;
364b2b9762fSSantosh Shilimkar 	pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET;
3655e94c6e3SSantosh Shilimkar 	pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET1;
366b2b9762fSSantosh Shilimkar 	pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm");
367b2b9762fSSantosh Shilimkar 	if (!pm_info->pwrdm) {
368b2b9762fSSantosh Shilimkar 		pr_err("Lookup failed for CPU1 pwrdm\n");
369b2b9762fSSantosh Shilimkar 		return -ENODEV;
370b2b9762fSSantosh Shilimkar 	}
371b2b9762fSSantosh Shilimkar 
372b2b9762fSSantosh Shilimkar 	/* Clear CPU previous power domain state */
373b2b9762fSSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
3743ba2a739SSantosh Shilimkar 	cpu_clear_prev_logic_pwrst(1);
375b2b9762fSSantosh Shilimkar 
376b2b9762fSSantosh Shilimkar 	/* Initialise CPU1 power domain state to ON */
377b2b9762fSSantosh Shilimkar 	pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
378b2b9762fSSantosh Shilimkar 
379e44f9a77SSantosh Shilimkar 	mpuss_pd = pwrdm_lookup("mpu_pwrdm");
380e44f9a77SSantosh Shilimkar 	if (!mpuss_pd) {
381e44f9a77SSantosh Shilimkar 		pr_err("Failed to lookup MPUSS power domain\n");
382e44f9a77SSantosh Shilimkar 		return -ENODEV;
383e44f9a77SSantosh Shilimkar 	}
384e44f9a77SSantosh Shilimkar 	pwrdm_clear_all_prev_pwrst(mpuss_pd);
3853ba2a739SSantosh Shilimkar 	mpuss_clear_prev_logic_pwrst();
386e44f9a77SSantosh Shilimkar 
387b2b9762fSSantosh Shilimkar 	/* Save device type on scratchpad for low level code to use */
388b2b9762fSSantosh Shilimkar 	if (omap_type() != OMAP2_DEVICE_TYPE_GP)
389b2b9762fSSantosh Shilimkar 		__raw_writel(1, sar_base + OMAP_TYPE_OFFSET);
390b2b9762fSSantosh Shilimkar 	else
391b2b9762fSSantosh Shilimkar 		__raw_writel(0, sar_base + OMAP_TYPE_OFFSET);
392b2b9762fSSantosh Shilimkar 
3935e94c6e3SSantosh Shilimkar 	save_l2x0_context();
3945e94c6e3SSantosh Shilimkar 
395b2b9762fSSantosh Shilimkar 	return 0;
396b2b9762fSSantosh Shilimkar }
397b2b9762fSSantosh Shilimkar 
398b2b9762fSSantosh Shilimkar #endif
399