1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2b2b9762fSSantosh Shilimkar /* 3b2b9762fSSantosh Shilimkar * OMAP MPUSS low power code 4b2b9762fSSantosh Shilimkar * 5b2b9762fSSantosh Shilimkar * Copyright (C) 2011 Texas Instruments, Inc. 6b2b9762fSSantosh Shilimkar * Santosh Shilimkar <santosh.shilimkar@ti.com> 7b2b9762fSSantosh Shilimkar * 8b2b9762fSSantosh Shilimkar * OMAP4430 MPUSS mainly consists of dual Cortex-A9 with per-CPU 9b2b9762fSSantosh Shilimkar * Local timer and Watchdog, GIC, SCU, PL310 L2 cache controller, 10b2b9762fSSantosh Shilimkar * CPU0 and CPU1 LPRM modules. 11b2b9762fSSantosh Shilimkar * CPU0, CPU1 and MPUSS each have there own power domain and 12b2b9762fSSantosh Shilimkar * hence multiple low power combinations of MPUSS are possible. 13b2b9762fSSantosh Shilimkar * 14b2b9762fSSantosh Shilimkar * The CPU0 and CPU1 can't support Closed switch Retention (CSWR) 15b2b9762fSSantosh Shilimkar * because the mode is not supported by hw constraints of dormant 16b2b9762fSSantosh Shilimkar * mode. While waking up from the dormant mode, a reset signal 17b2b9762fSSantosh Shilimkar * to the Cortex-A9 processor must be asserted by the external 18b2b9762fSSantosh Shilimkar * power controller. 19b2b9762fSSantosh Shilimkar * 20b2b9762fSSantosh Shilimkar * With architectural inputs and hardware recommendations, only 21b2b9762fSSantosh Shilimkar * below modes are supported from power gain vs latency point of view. 22b2b9762fSSantosh Shilimkar * 23b2b9762fSSantosh Shilimkar * CPU0 CPU1 MPUSS 24b2b9762fSSantosh Shilimkar * ---------------------------------------------- 25b2b9762fSSantosh Shilimkar * ON ON ON 26b2b9762fSSantosh Shilimkar * ON(Inactive) OFF ON(Inactive) 27b2b9762fSSantosh Shilimkar * OFF OFF CSWR 283ba2a739SSantosh Shilimkar * OFF OFF OSWR 293ba2a739SSantosh Shilimkar * OFF OFF OFF(Device OFF *TBD) 30b2b9762fSSantosh Shilimkar * ---------------------------------------------- 31b2b9762fSSantosh Shilimkar * 32b2b9762fSSantosh Shilimkar * Note: CPU0 is the master core and it is the last CPU to go down 33b2b9762fSSantosh Shilimkar * and first to wake-up when MPUSS low power states are excercised 34b2b9762fSSantosh Shilimkar */ 35b2b9762fSSantosh Shilimkar 36a282e5efSTony Lindgren #include <linux/cpuidle.h> 37b2b9762fSSantosh Shilimkar #include <linux/kernel.h> 38b2b9762fSSantosh Shilimkar #include <linux/io.h> 39b2b9762fSSantosh Shilimkar #include <linux/errno.h> 40b2b9762fSSantosh Shilimkar #include <linux/linkage.h> 41b2b9762fSSantosh Shilimkar #include <linux/smp.h> 42b2b9762fSSantosh Shilimkar 43b2b9762fSSantosh Shilimkar #include <asm/cacheflush.h> 44b2b9762fSSantosh Shilimkar #include <asm/tlbflush.h> 45b2b9762fSSantosh Shilimkar #include <asm/smp_scu.h> 46b2b9762fSSantosh Shilimkar #include <asm/suspend.h> 478a8be46aSTony Lindgren #include <asm/virt.h> 485e94c6e3SSantosh Shilimkar #include <asm/hardware/cache-l2x0.h> 49b2b9762fSSantosh Shilimkar 50e4c060dbSTony Lindgren #include "soc.h" 51b2b9762fSSantosh Shilimkar #include "common.h" 52c49f34bcSTony Lindgren #include "omap44xx.h" 53b2b9762fSSantosh Shilimkar #include "omap4-sar-layout.h" 54b2b9762fSSantosh Shilimkar #include "pm.h" 553ba2a739SSantosh Shilimkar #include "prcm_mpu44xx.h" 56a89726d3SSantosh Shilimkar #include "prcm_mpu54xx.h" 573ba2a739SSantosh Shilimkar #include "prminst44xx.h" 583ba2a739SSantosh Shilimkar #include "prcm44xx.h" 593ba2a739SSantosh Shilimkar #include "prm44xx.h" 603ba2a739SSantosh Shilimkar #include "prm-regbits-44xx.h" 61b2b9762fSSantosh Shilimkar 620573b957STony Lindgren static void __iomem *sar_base; 63351b7c49STony Lindgren static u32 old_cpu1_ns_pa_addr; 640573b957STony Lindgren 65b3bf289cSTony Lindgren #if defined(CONFIG_PM) && defined(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 749f192cf7SSantosh Shilimkar /** 759f192cf7SSantosh Shilimkar * struct cpu_pm_ops - CPU pm operations 769f192cf7SSantosh Shilimkar * @finish_suspend: CPU suspend finisher function pointer 779f192cf7SSantosh Shilimkar * @resume: CPU resume function pointer 789f192cf7SSantosh Shilimkar * @scu_prepare: CPU Snoop Control program function pointer 79e97c4eb3SSantosh Shilimkar * @hotplug_restart: CPU restart function pointer 809f192cf7SSantosh Shilimkar * 819f192cf7SSantosh Shilimkar * Structure holds functions pointer for CPU low power operations like 829f192cf7SSantosh Shilimkar * suspend, resume and scu programming. 839f192cf7SSantosh Shilimkar */ 849f192cf7SSantosh Shilimkar struct cpu_pm_ops { 859f192cf7SSantosh Shilimkar int (*finish_suspend)(unsigned long cpu_state); 869f192cf7SSantosh Shilimkar void (*resume)(void); 879f192cf7SSantosh Shilimkar void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state); 88e97c4eb3SSantosh Shilimkar void (*hotplug_restart)(void); 899f192cf7SSantosh Shilimkar }; 909f192cf7SSantosh Shilimkar 91b2b9762fSSantosh Shilimkar static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info); 92e44f9a77SSantosh Shilimkar static struct powerdomain *mpuss_pd; 93a89726d3SSantosh Shilimkar static u32 cpu_context_offset; 94b2b9762fSSantosh Shilimkar 959f192cf7SSantosh Shilimkar static int default_finish_suspend(unsigned long cpu_state) 969f192cf7SSantosh Shilimkar { 979f192cf7SSantosh Shilimkar omap_do_wfi(); 989f192cf7SSantosh Shilimkar return 0; 999f192cf7SSantosh Shilimkar } 1009f192cf7SSantosh Shilimkar 1019f192cf7SSantosh Shilimkar static void dummy_cpu_resume(void) 1029f192cf7SSantosh Shilimkar {} 1039f192cf7SSantosh Shilimkar 1049f192cf7SSantosh Shilimkar static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state) 1059f192cf7SSantosh Shilimkar {} 1069f192cf7SSantosh Shilimkar 107f734a9b3SSekhar Nori static struct cpu_pm_ops omap_pm_ops = { 1089f192cf7SSantosh Shilimkar .finish_suspend = default_finish_suspend, 1099f192cf7SSantosh Shilimkar .resume = dummy_cpu_resume, 1109f192cf7SSantosh Shilimkar .scu_prepare = dummy_scu_prepare, 111e97c4eb3SSantosh Shilimkar .hotplug_restart = dummy_cpu_resume, 1129f192cf7SSantosh Shilimkar }; 1139f192cf7SSantosh Shilimkar 114b2b9762fSSantosh Shilimkar /* 115b2b9762fSSantosh Shilimkar * Program the wakeup routine address for the CPU0 and CPU1 116b2b9762fSSantosh Shilimkar * used for OFF or DORMANT wakeup. 117b2b9762fSSantosh Shilimkar */ 118b2b9762fSSantosh Shilimkar static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr) 119b2b9762fSSantosh Shilimkar { 120b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 121b2b9762fSSantosh Shilimkar 122325f29daSRajendra Nayak if (pm_info->wkup_sar_addr) 123edfaf05cSVictor Kamensky writel_relaxed(addr, pm_info->wkup_sar_addr); 124b2b9762fSSantosh Shilimkar } 125b2b9762fSSantosh Shilimkar 126b2b9762fSSantosh Shilimkar /* 127b2b9762fSSantosh Shilimkar * Store the SCU power status value to scratchpad memory 128b2b9762fSSantosh Shilimkar */ 129b2b9762fSSantosh Shilimkar static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state) 130b2b9762fSSantosh Shilimkar { 131b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 132b2b9762fSSantosh Shilimkar u32 scu_pwr_st; 133b2b9762fSSantosh Shilimkar 134b2b9762fSSantosh Shilimkar switch (cpu_state) { 135b2b9762fSSantosh Shilimkar case PWRDM_POWER_RET: 136b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_DORMANT; 137b2b9762fSSantosh Shilimkar break; 138b2b9762fSSantosh Shilimkar case PWRDM_POWER_OFF: 139b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_POWEROFF; 140b2b9762fSSantosh Shilimkar break; 141b2b9762fSSantosh Shilimkar case PWRDM_POWER_ON: 142b2b9762fSSantosh Shilimkar case PWRDM_POWER_INACTIVE: 143b2b9762fSSantosh Shilimkar default: 144b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_NORMAL; 145b2b9762fSSantosh Shilimkar break; 146b2b9762fSSantosh Shilimkar } 147b2b9762fSSantosh Shilimkar 148325f29daSRajendra Nayak if (pm_info->scu_sar_addr) 149edfaf05cSVictor Kamensky writel_relaxed(scu_pwr_st, pm_info->scu_sar_addr); 150b2b9762fSSantosh Shilimkar } 151b2b9762fSSantosh Shilimkar 1523ba2a739SSantosh Shilimkar /* Helper functions for MPUSS OSWR */ 1533ba2a739SSantosh Shilimkar static inline void mpuss_clear_prev_logic_pwrst(void) 1543ba2a739SSantosh Shilimkar { 1553ba2a739SSantosh Shilimkar u32 reg; 1563ba2a739SSantosh Shilimkar 1573ba2a739SSantosh Shilimkar reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION, 1583ba2a739SSantosh Shilimkar OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET); 1593ba2a739SSantosh Shilimkar omap4_prminst_write_inst_reg(reg, OMAP4430_PRM_PARTITION, 1603ba2a739SSantosh Shilimkar OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET); 1613ba2a739SSantosh Shilimkar } 1623ba2a739SSantosh Shilimkar 1633ba2a739SSantosh Shilimkar static inline void cpu_clear_prev_logic_pwrst(unsigned int cpu_id) 1643ba2a739SSantosh Shilimkar { 1653ba2a739SSantosh Shilimkar u32 reg; 1663ba2a739SSantosh Shilimkar 1673ba2a739SSantosh Shilimkar if (cpu_id) { 1683ba2a739SSantosh Shilimkar reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU1_INST, 169a89726d3SSantosh Shilimkar cpu_context_offset); 1703ba2a739SSantosh Shilimkar omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU1_INST, 171a89726d3SSantosh Shilimkar cpu_context_offset); 1723ba2a739SSantosh Shilimkar } else { 1733ba2a739SSantosh Shilimkar reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU0_INST, 174a89726d3SSantosh Shilimkar cpu_context_offset); 1753ba2a739SSantosh Shilimkar omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU0_INST, 176a89726d3SSantosh Shilimkar cpu_context_offset); 1773ba2a739SSantosh Shilimkar } 1783ba2a739SSantosh Shilimkar } 1793ba2a739SSantosh Shilimkar 1805e94c6e3SSantosh Shilimkar /* 1815e94c6e3SSantosh Shilimkar * Store the CPU cluster state for L2X0 low power operations. 1825e94c6e3SSantosh Shilimkar */ 1835e94c6e3SSantosh Shilimkar static void l2x0_pwrst_prepare(unsigned int cpu_id, unsigned int save_state) 1845e94c6e3SSantosh Shilimkar { 1855e94c6e3SSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 1865e94c6e3SSantosh Shilimkar 187325f29daSRajendra Nayak if (pm_info->l2x0_sar_addr) 188edfaf05cSVictor Kamensky writel_relaxed(save_state, pm_info->l2x0_sar_addr); 1895e94c6e3SSantosh Shilimkar } 1905e94c6e3SSantosh Shilimkar 1915e94c6e3SSantosh Shilimkar /* 1925e94c6e3SSantosh Shilimkar * Save the L2X0 AUXCTRL and POR value to SAR memory. Its used to 1935e94c6e3SSantosh Shilimkar * in every restore MPUSS OFF path. 1945e94c6e3SSantosh Shilimkar */ 1955e94c6e3SSantosh Shilimkar #ifdef CONFIG_CACHE_L2X0 1967a09b28eSRussell King static void __init save_l2x0_context(void) 1975e94c6e3SSantosh Shilimkar { 198325f29daSRajendra Nayak void __iomem *l2x0_base = omap4_get_l2cache_base(); 199325f29daSRajendra Nayak 200325f29daSRajendra Nayak if (l2x0_base && sar_base) { 201eb3d3ec5SLinus Torvalds writel_relaxed(l2x0_saved_regs.aux_ctrl, 2027a09b28eSRussell King sar_base + L2X0_AUXCTRL_OFFSET); 203eb3d3ec5SLinus Torvalds writel_relaxed(l2x0_saved_regs.prefetch_ctrl, 2047a09b28eSRussell King sar_base + L2X0_PREFETCH_CTRL_OFFSET); 2059f192cf7SSantosh Shilimkar } 206325f29daSRajendra Nayak } 2075e94c6e3SSantosh Shilimkar #else 2087a09b28eSRussell King static void __init save_l2x0_context(void) 2095e94c6e3SSantosh Shilimkar {} 2105e94c6e3SSantosh Shilimkar #endif 2115e94c6e3SSantosh Shilimkar 212b2b9762fSSantosh Shilimkar /** 213b2b9762fSSantosh Shilimkar * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function 214b2b9762fSSantosh Shilimkar * The purpose of this function is to manage low power programming 215b2b9762fSSantosh Shilimkar * of OMAP4 MPUSS subsystem 216b2b9762fSSantosh Shilimkar * @cpu : CPU ID 217b2b9762fSSantosh Shilimkar * @power_state: Low power state. 218a282e5efSTony Lindgren * @rcuidle: RCU needs to be idled 219e44f9a77SSantosh Shilimkar * 220e44f9a77SSantosh Shilimkar * MPUSS states for the context save: 221e44f9a77SSantosh Shilimkar * save_state = 222e44f9a77SSantosh Shilimkar * 0 - Nothing lost and no need to save: MPUSS INACTIVE 223e44f9a77SSantosh Shilimkar * 1 - CPUx L1 and logic lost: MPUSS CSWR 224e44f9a77SSantosh Shilimkar * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR 225e44f9a77SSantosh Shilimkar * 3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF 226b2b9762fSSantosh Shilimkar */ 227*69e26b4fSPeter Zijlstra __cpuidle int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state, 228a282e5efSTony Lindgren bool rcuidle) 229b2b9762fSSantosh Shilimkar { 23032d174edSPaul Walmsley struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu); 231a30d81b9SNishanth Menon unsigned int save_state = 0, cpu_logic_state = PWRDM_POWER_RET; 232b2b9762fSSantosh Shilimkar 233b2b9762fSSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) 234b2b9762fSSantosh Shilimkar return -ENXIO; 235b2b9762fSSantosh Shilimkar 236b2b9762fSSantosh Shilimkar switch (power_state) { 237b2b9762fSSantosh Shilimkar case PWRDM_POWER_ON: 238b2b9762fSSantosh Shilimkar case PWRDM_POWER_INACTIVE: 239b2b9762fSSantosh Shilimkar save_state = 0; 240b2b9762fSSantosh Shilimkar break; 241b2b9762fSSantosh Shilimkar case PWRDM_POWER_OFF: 242a30d81b9SNishanth Menon cpu_logic_state = PWRDM_POWER_OFF; 243b2b9762fSSantosh Shilimkar save_state = 1; 244b2b9762fSSantosh Shilimkar break; 245b2b9762fSSantosh Shilimkar case PWRDM_POWER_RET: 246cbf26428STony Lindgren if (IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE)) 2476099dd37SRajendra Nayak save_state = 0; 2486099dd37SRajendra Nayak break; 249b2b9762fSSantosh Shilimkar default: 250b2b9762fSSantosh Shilimkar /* 251b2b9762fSSantosh Shilimkar * CPUx CSWR is invalid hardware state. Also CPUx OSWR 252b2b9762fSSantosh Shilimkar * doesn't make much scense, since logic is lost and $L1 253b2b9762fSSantosh Shilimkar * needs to be cleaned because of coherency. This makes 254b2b9762fSSantosh Shilimkar * CPUx OSWR equivalent to CPUX OFF and hence not supported 255b2b9762fSSantosh Shilimkar */ 256b2b9762fSSantosh Shilimkar WARN_ON(1); 257b2b9762fSSantosh Shilimkar return -ENXIO; 258b2b9762fSSantosh Shilimkar } 259b2b9762fSSantosh Shilimkar 260e0555489SKevin Hilman pwrdm_pre_transition(NULL); 26149404dd0SSantosh Shilimkar 2623ba2a739SSantosh Shilimkar /* 2633ba2a739SSantosh Shilimkar * Check MPUSS next state and save interrupt controller if needed. 2643ba2a739SSantosh Shilimkar * In MPUSS OSWR or device OFF, interrupt controller contest is lost. 2653ba2a739SSantosh Shilimkar */ 2663ba2a739SSantosh Shilimkar mpuss_clear_prev_logic_pwrst(); 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 2713ba2a739SSantosh Shilimkar cpu_clear_prev_logic_pwrst(cpu); 27232d174edSPaul Walmsley pwrdm_set_next_pwrst(pm_info->pwrdm, power_state); 273a30d81b9SNishanth Menon pwrdm_set_logic_retst(pm_info->pwrdm, cpu_logic_state); 274a282e5efSTony Lindgren 275a282e5efSTony Lindgren if (rcuidle) 276a282e5efSTony Lindgren ct_cpuidle_enter(); 277a282e5efSTony Lindgren 27864fc2a94SFlorian Fainelli set_cpu_wakeup_addr(cpu, __pa_symbol(omap_pm_ops.resume)); 2799f192cf7SSantosh Shilimkar omap_pm_ops.scu_prepare(cpu, power_state); 2805e94c6e3SSantosh Shilimkar l2x0_pwrst_prepare(cpu, save_state); 281b2b9762fSSantosh Shilimkar 282b2b9762fSSantosh Shilimkar /* 283b2b9762fSSantosh Shilimkar * Call low level function with targeted low power state. 284b2b9762fSSantosh Shilimkar */ 28572433ebaSSantosh Shilimkar if (save_state) 2869f192cf7SSantosh Shilimkar cpu_suspend(save_state, omap_pm_ops.finish_suspend); 28772433ebaSSantosh Shilimkar else 2889f192cf7SSantosh Shilimkar omap_pm_ops.finish_suspend(save_state); 289b2b9762fSSantosh Shilimkar 29074ed7bdcSStrashko, Grygorii if (IS_PM44XX_ERRATUM(PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD) && cpu) 29174ed7bdcSStrashko, Grygorii gic_dist_enable(); 29274ed7bdcSStrashko, Grygorii 293a282e5efSTony Lindgren if (rcuidle) 294a282e5efSTony Lindgren ct_cpuidle_exit(); 295a282e5efSTony Lindgren 296b2b9762fSSantosh Shilimkar /* 297b2b9762fSSantosh Shilimkar * Restore the CPUx power state to ON otherwise CPUx 298b2b9762fSSantosh Shilimkar * power domain can transitions to programmed low power 299b2b9762fSSantosh Shilimkar * state while doing WFI outside the low powe code. On 300b2b9762fSSantosh Shilimkar * secure devices, CPUx does WFI which can result in 301b2b9762fSSantosh Shilimkar * domain transition 302b2b9762fSSantosh Shilimkar */ 30332d174edSPaul Walmsley pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 304b2b9762fSSantosh Shilimkar 305e0555489SKevin Hilman pwrdm_post_transition(NULL); 30649404dd0SSantosh Shilimkar 307b2b9762fSSantosh Shilimkar return 0; 308b2b9762fSSantosh Shilimkar } 309b2b9762fSSantosh Shilimkar 310b5b4f288SSantosh Shilimkar /** 311b5b4f288SSantosh Shilimkar * omap4_hotplug_cpu: OMAP4 CPU hotplug entry 312b5b4f288SSantosh Shilimkar * @cpu : CPU ID 313b5b4f288SSantosh Shilimkar * @power_state: CPU low power state. 314b5b4f288SSantosh Shilimkar */ 3158bd26e3aSPaul Gortmaker int omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state) 316b5b4f288SSantosh Shilimkar { 317ff999b8aSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu); 31832d174edSPaul Walmsley unsigned int cpu_state = 0; 319b5b4f288SSantosh Shilimkar 320b5b4f288SSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) 321b5b4f288SSantosh Shilimkar return -ENXIO; 322b5b4f288SSantosh Shilimkar 3233e6a1c94SNishanth Menon /* Use the achievable power state for the domain */ 3243e6a1c94SNishanth Menon power_state = pwrdm_get_valid_lp_state(pm_info->pwrdm, 3253e6a1c94SNishanth Menon false, power_state); 3263e6a1c94SNishanth Menon 327b5b4f288SSantosh Shilimkar if (power_state == PWRDM_POWER_OFF) 328b5b4f288SSantosh Shilimkar cpu_state = 1; 329b5b4f288SSantosh Shilimkar 33032d174edSPaul Walmsley pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 33132d174edSPaul Walmsley pwrdm_set_next_pwrst(pm_info->pwrdm, power_state); 33264fc2a94SFlorian Fainelli set_cpu_wakeup_addr(cpu, __pa_symbol(omap_pm_ops.hotplug_restart)); 3339f192cf7SSantosh Shilimkar omap_pm_ops.scu_prepare(cpu, power_state); 334b5b4f288SSantosh Shilimkar 335b5b4f288SSantosh Shilimkar /* 336260db902SMasanari Iida * CPU never retuns back if targeted power state is OFF mode. 337b5b4f288SSantosh Shilimkar * CPU ONLINE follows normal CPU ONLINE ptah via 338baf4b7d3SSantosh Shilimkar * omap4_secondary_startup(). 339b5b4f288SSantosh Shilimkar */ 3409f192cf7SSantosh Shilimkar omap_pm_ops.finish_suspend(cpu_state); 341b5b4f288SSantosh Shilimkar 34232d174edSPaul Walmsley pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 343b5b4f288SSantosh Shilimkar return 0; 344b5b4f288SSantosh Shilimkar } 345b5b4f288SSantosh Shilimkar 346b5b4f288SSantosh Shilimkar 347b2b9762fSSantosh Shilimkar /* 3486d846c46SSantosh Shilimkar * Enable Mercury Fast HG retention mode by default. 3496d846c46SSantosh Shilimkar */ 3506d846c46SSantosh Shilimkar static void enable_mercury_retention_mode(void) 3516d846c46SSantosh Shilimkar { 3526d846c46SSantosh Shilimkar u32 reg; 3536d846c46SSantosh Shilimkar 3546d846c46SSantosh Shilimkar reg = omap4_prcm_mpu_read_inst_reg(OMAP54XX_PRCM_MPU_DEVICE_INST, 3556d846c46SSantosh Shilimkar OMAP54XX_PRCM_MPU_PRM_PSCON_COUNT_OFFSET); 3566d846c46SSantosh Shilimkar /* Enable HG_EN, HG_RAMPUP = fast mode */ 3576d846c46SSantosh Shilimkar reg |= BIT(24) | BIT(25); 3586d846c46SSantosh Shilimkar omap4_prcm_mpu_write_inst_reg(reg, OMAP54XX_PRCM_MPU_DEVICE_INST, 3596d846c46SSantosh Shilimkar OMAP54XX_PRCM_MPU_PRM_PSCON_COUNT_OFFSET); 3606d846c46SSantosh Shilimkar } 3616d846c46SSantosh Shilimkar 3626d846c46SSantosh Shilimkar /* 363b2b9762fSSantosh Shilimkar * Initialise OMAP4 MPUSS 364b2b9762fSSantosh Shilimkar */ 365b2b9762fSSantosh Shilimkar int __init omap4_mpuss_init(void) 366b2b9762fSSantosh Shilimkar { 367b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info; 368b2b9762fSSantosh Shilimkar 369b2b9762fSSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) { 370b2b9762fSSantosh Shilimkar WARN(1, "Power Management not supported on OMAP4430 ES1.0\n"); 371b2b9762fSSantosh Shilimkar return -ENODEV; 372b2b9762fSSantosh Shilimkar } 373b2b9762fSSantosh Shilimkar 374b2b9762fSSantosh Shilimkar /* Initilaise per CPU PM information */ 375b2b9762fSSantosh Shilimkar pm_info = &per_cpu(omap4_pm_info, 0x0); 376325f29daSRajendra Nayak if (sar_base) { 377b2b9762fSSantosh Shilimkar pm_info->scu_sar_addr = sar_base + SCU_OFFSET0; 3788a8be46aSTony Lindgren if (cpu_is_omap44xx()) 379325f29daSRajendra Nayak pm_info->wkup_sar_addr = sar_base + 380325f29daSRajendra Nayak CPU0_WAKEUP_NS_PA_ADDR_OFFSET; 3818a8be46aSTony Lindgren else 3828a8be46aSTony Lindgren pm_info->wkup_sar_addr = sar_base + 3838a8be46aSTony Lindgren OMAP5_CPU0_WAKEUP_NS_PA_ADDR_OFFSET; 3845e94c6e3SSantosh Shilimkar pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET0; 385325f29daSRajendra Nayak } 386b2b9762fSSantosh Shilimkar pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm"); 387b2b9762fSSantosh Shilimkar if (!pm_info->pwrdm) { 388b2b9762fSSantosh Shilimkar pr_err("Lookup failed for CPU0 pwrdm\n"); 389b2b9762fSSantosh Shilimkar return -ENODEV; 390b2b9762fSSantosh Shilimkar } 391b2b9762fSSantosh Shilimkar 392b2b9762fSSantosh Shilimkar /* Clear CPU previous power domain state */ 393b2b9762fSSantosh Shilimkar pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 3943ba2a739SSantosh Shilimkar cpu_clear_prev_logic_pwrst(0); 395b2b9762fSSantosh Shilimkar 396b2b9762fSSantosh Shilimkar /* Initialise CPU0 power domain state to ON */ 397b2b9762fSSantosh Shilimkar pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 398b2b9762fSSantosh Shilimkar 399b2b9762fSSantosh Shilimkar pm_info = &per_cpu(omap4_pm_info, 0x1); 400325f29daSRajendra Nayak if (sar_base) { 401b2b9762fSSantosh Shilimkar pm_info->scu_sar_addr = sar_base + SCU_OFFSET1; 4028a8be46aSTony Lindgren if (cpu_is_omap44xx()) 403325f29daSRajendra Nayak pm_info->wkup_sar_addr = sar_base + 404325f29daSRajendra Nayak CPU1_WAKEUP_NS_PA_ADDR_OFFSET; 4058a8be46aSTony Lindgren else 4068a8be46aSTony Lindgren pm_info->wkup_sar_addr = sar_base + 4078a8be46aSTony Lindgren OMAP5_CPU1_WAKEUP_NS_PA_ADDR_OFFSET; 4085e94c6e3SSantosh Shilimkar pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET1; 409325f29daSRajendra Nayak } 410ff999b8aSSantosh Shilimkar 411b2b9762fSSantosh Shilimkar pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm"); 412b2b9762fSSantosh Shilimkar if (!pm_info->pwrdm) { 413b2b9762fSSantosh Shilimkar pr_err("Lookup failed for CPU1 pwrdm\n"); 414b2b9762fSSantosh Shilimkar return -ENODEV; 415b2b9762fSSantosh Shilimkar } 416b2b9762fSSantosh Shilimkar 417b2b9762fSSantosh Shilimkar /* Clear CPU previous power domain state */ 418b2b9762fSSantosh Shilimkar pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 4193ba2a739SSantosh Shilimkar cpu_clear_prev_logic_pwrst(1); 420b2b9762fSSantosh Shilimkar 421b2b9762fSSantosh Shilimkar /* Initialise CPU1 power domain state to ON */ 422b2b9762fSSantosh Shilimkar pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 423b2b9762fSSantosh Shilimkar 424e44f9a77SSantosh Shilimkar mpuss_pd = pwrdm_lookup("mpu_pwrdm"); 425e44f9a77SSantosh Shilimkar if (!mpuss_pd) { 426e44f9a77SSantosh Shilimkar pr_err("Failed to lookup MPUSS power domain\n"); 427e44f9a77SSantosh Shilimkar return -ENODEV; 428e44f9a77SSantosh Shilimkar } 429e44f9a77SSantosh Shilimkar pwrdm_clear_all_prev_pwrst(mpuss_pd); 4303ba2a739SSantosh Shilimkar mpuss_clear_prev_logic_pwrst(); 431e44f9a77SSantosh Shilimkar 432325f29daSRajendra Nayak if (sar_base) { 433b2b9762fSSantosh Shilimkar /* Save device type on scratchpad for low level code to use */ 434325f29daSRajendra Nayak writel_relaxed((omap_type() != OMAP2_DEVICE_TYPE_GP) ? 1 : 0, 435325f29daSRajendra Nayak sar_base + OMAP_TYPE_OFFSET); 4365e94c6e3SSantosh Shilimkar save_l2x0_context(); 437325f29daSRajendra Nayak } 4385e94c6e3SSantosh Shilimkar 4399f192cf7SSantosh Shilimkar if (cpu_is_omap44xx()) { 4409f192cf7SSantosh Shilimkar omap_pm_ops.finish_suspend = omap4_finish_suspend; 4419f192cf7SSantosh Shilimkar omap_pm_ops.resume = omap4_cpu_resume; 4429f192cf7SSantosh Shilimkar omap_pm_ops.scu_prepare = scu_pwrst_prepare; 443e97c4eb3SSantosh Shilimkar omap_pm_ops.hotplug_restart = omap4_secondary_startup; 444a89726d3SSantosh Shilimkar cpu_context_offset = OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET; 445a89726d3SSantosh Shilimkar } else if (soc_is_omap54xx() || soc_is_dra7xx()) { 446a89726d3SSantosh Shilimkar cpu_context_offset = OMAP54XX_RM_CPU0_CPU0_CONTEXT_OFFSET; 4476d846c46SSantosh Shilimkar enable_mercury_retention_mode(); 4489f192cf7SSantosh Shilimkar } 4499f192cf7SSantosh Shilimkar 450e97c4eb3SSantosh Shilimkar if (cpu_is_omap446x()) 451e97c4eb3SSantosh Shilimkar omap_pm_ops.hotplug_restart = omap4460_secondary_startup; 452e97c4eb3SSantosh Shilimkar 453b2b9762fSSantosh Shilimkar return 0; 454b2b9762fSSantosh Shilimkar } 455b2b9762fSSantosh Shilimkar 456b2b9762fSSantosh Shilimkar #endif 4570573b957STony Lindgren 4586f921208SArnd Bergmann u32 omap4_get_cpu1_ns_pa_addr(void) 4596f921208SArnd Bergmann { 4606f921208SArnd Bergmann return old_cpu1_ns_pa_addr; 4616f921208SArnd Bergmann } 4626f921208SArnd Bergmann 4630573b957STony Lindgren /* 4640573b957STony Lindgren * For kexec, we must set CPU1_WAKEUP_NS_PA_ADDR to point to 4650573b957STony Lindgren * current kernel's secondary_startup() early before 4660573b957STony Lindgren * clockdomains_init(). Otherwise clockdomain_init() can 4670573b957STony Lindgren * wake CPU1 and cause a hang. 4680573b957STony Lindgren */ 4690573b957STony Lindgren void __init omap4_mpuss_early_init(void) 4700573b957STony Lindgren { 4710573b957STony Lindgren unsigned long startup_pa; 472351b7c49STony Lindgren void __iomem *ns_pa_addr; 4730573b957STony Lindgren 474351b7c49STony Lindgren if (!(soc_is_omap44xx() || soc_is_omap54xx())) 4750573b957STony Lindgren return; 4760573b957STony Lindgren 4770573b957STony Lindgren sar_base = omap4_get_sar_ram_base(); 4780573b957STony Lindgren 479351b7c49STony Lindgren /* Save old NS_PA_ADDR for validity checks later on */ 480351b7c49STony Lindgren if (soc_is_omap44xx()) 481351b7c49STony Lindgren ns_pa_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET; 482351b7c49STony Lindgren else 483351b7c49STony Lindgren ns_pa_addr = sar_base + OMAP5_CPU1_WAKEUP_NS_PA_ADDR_OFFSET; 484351b7c49STony Lindgren old_cpu1_ns_pa_addr = readl_relaxed(ns_pa_addr); 485351b7c49STony Lindgren 486351b7c49STony Lindgren if (soc_is_omap443x()) 48764fc2a94SFlorian Fainelli startup_pa = __pa_symbol(omap4_secondary_startup); 488351b7c49STony Lindgren else if (soc_is_omap446x()) 48964fc2a94SFlorian Fainelli startup_pa = __pa_symbol(omap4460_secondary_startup); 4908a8be46aSTony Lindgren else if ((__boot_cpu_mode & MODE_MASK) == HYP_MODE) 49164fc2a94SFlorian Fainelli startup_pa = __pa_symbol(omap5_secondary_hyp_startup); 4928a8be46aSTony Lindgren else 49364fc2a94SFlorian Fainelli startup_pa = __pa_symbol(omap5_secondary_startup); 4940573b957STony Lindgren 495351b7c49STony Lindgren if (soc_is_omap44xx()) 4968a8be46aSTony Lindgren writel_relaxed(startup_pa, sar_base + 4978a8be46aSTony Lindgren CPU1_WAKEUP_NS_PA_ADDR_OFFSET); 4988a8be46aSTony Lindgren else 4998a8be46aSTony Lindgren writel_relaxed(startup_pa, sar_base + 5008a8be46aSTony Lindgren OMAP5_CPU1_WAKEUP_NS_PA_ADDR_OFFSET); 5010573b957STony Lindgren } 502