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); 69*e44f9a77SSantosh Shilimkar static struct powerdomain *mpuss_pd; 70b2b9762fSSantosh Shilimkar 71b2b9762fSSantosh Shilimkar /* 72b2b9762fSSantosh Shilimkar * Program the wakeup routine address for the CPU0 and CPU1 73b2b9762fSSantosh Shilimkar * used for OFF or DORMANT wakeup. 74b2b9762fSSantosh Shilimkar */ 75b2b9762fSSantosh Shilimkar static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr) 76b2b9762fSSantosh Shilimkar { 77b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 78b2b9762fSSantosh Shilimkar 79b2b9762fSSantosh Shilimkar __raw_writel(addr, pm_info->wkup_sar_addr); 80b2b9762fSSantosh Shilimkar } 81b2b9762fSSantosh Shilimkar 82b2b9762fSSantosh Shilimkar /* 83b2b9762fSSantosh Shilimkar * Set the CPUx powerdomain's previous power state 84b2b9762fSSantosh Shilimkar */ 85b2b9762fSSantosh Shilimkar static inline void set_cpu_next_pwrst(unsigned int cpu_id, 86b2b9762fSSantosh Shilimkar unsigned int power_state) 87b2b9762fSSantosh Shilimkar { 88b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 89b2b9762fSSantosh Shilimkar 90b2b9762fSSantosh Shilimkar pwrdm_set_next_pwrst(pm_info->pwrdm, power_state); 91b2b9762fSSantosh Shilimkar } 92b2b9762fSSantosh Shilimkar 93b2b9762fSSantosh Shilimkar /* 94b2b9762fSSantosh Shilimkar * Read CPU's previous power state 95b2b9762fSSantosh Shilimkar */ 96b2b9762fSSantosh Shilimkar static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id) 97b2b9762fSSantosh Shilimkar { 98b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 99b2b9762fSSantosh Shilimkar 100b2b9762fSSantosh Shilimkar return pwrdm_read_prev_pwrst(pm_info->pwrdm); 101b2b9762fSSantosh Shilimkar } 102b2b9762fSSantosh Shilimkar 103b2b9762fSSantosh Shilimkar /* 104b2b9762fSSantosh Shilimkar * Clear the CPUx powerdomain's previous power state 105b2b9762fSSantosh Shilimkar */ 106b2b9762fSSantosh Shilimkar static inline void clear_cpu_prev_pwrst(unsigned int cpu_id) 107b2b9762fSSantosh Shilimkar { 108b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 109b2b9762fSSantosh Shilimkar 110b2b9762fSSantosh Shilimkar pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 111b2b9762fSSantosh Shilimkar } 112b2b9762fSSantosh Shilimkar 113b2b9762fSSantosh Shilimkar /* 114b2b9762fSSantosh Shilimkar * Store the SCU power status value to scratchpad memory 115b2b9762fSSantosh Shilimkar */ 116b2b9762fSSantosh Shilimkar static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state) 117b2b9762fSSantosh Shilimkar { 118b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id); 119b2b9762fSSantosh Shilimkar u32 scu_pwr_st; 120b2b9762fSSantosh Shilimkar 121b2b9762fSSantosh Shilimkar switch (cpu_state) { 122b2b9762fSSantosh Shilimkar case PWRDM_POWER_RET: 123b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_DORMANT; 124b2b9762fSSantosh Shilimkar break; 125b2b9762fSSantosh Shilimkar case PWRDM_POWER_OFF: 126b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_POWEROFF; 127b2b9762fSSantosh Shilimkar break; 128b2b9762fSSantosh Shilimkar case PWRDM_POWER_ON: 129b2b9762fSSantosh Shilimkar case PWRDM_POWER_INACTIVE: 130b2b9762fSSantosh Shilimkar default: 131b2b9762fSSantosh Shilimkar scu_pwr_st = SCU_PM_NORMAL; 132b2b9762fSSantosh Shilimkar break; 133b2b9762fSSantosh Shilimkar } 134b2b9762fSSantosh Shilimkar 135b2b9762fSSantosh Shilimkar __raw_writel(scu_pwr_st, pm_info->scu_sar_addr); 136b2b9762fSSantosh Shilimkar } 137b2b9762fSSantosh Shilimkar 138b2b9762fSSantosh Shilimkar /** 139b2b9762fSSantosh Shilimkar * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function 140b2b9762fSSantosh Shilimkar * The purpose of this function is to manage low power programming 141b2b9762fSSantosh Shilimkar * of OMAP4 MPUSS subsystem 142b2b9762fSSantosh Shilimkar * @cpu : CPU ID 143b2b9762fSSantosh Shilimkar * @power_state: Low power state. 144*e44f9a77SSantosh Shilimkar * 145*e44f9a77SSantosh Shilimkar * MPUSS states for the context save: 146*e44f9a77SSantosh Shilimkar * save_state = 147*e44f9a77SSantosh Shilimkar * 0 - Nothing lost and no need to save: MPUSS INACTIVE 148*e44f9a77SSantosh Shilimkar * 1 - CPUx L1 and logic lost: MPUSS CSWR 149*e44f9a77SSantosh Shilimkar * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR 150*e44f9a77SSantosh Shilimkar * 3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF 151b2b9762fSSantosh Shilimkar */ 152b2b9762fSSantosh Shilimkar int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state) 153b2b9762fSSantosh Shilimkar { 154b2b9762fSSantosh Shilimkar unsigned int save_state = 0; 155b2b9762fSSantosh Shilimkar unsigned int wakeup_cpu; 156b2b9762fSSantosh Shilimkar 157b2b9762fSSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) 158b2b9762fSSantosh Shilimkar return -ENXIO; 159b2b9762fSSantosh Shilimkar 160b2b9762fSSantosh Shilimkar switch (power_state) { 161b2b9762fSSantosh Shilimkar case PWRDM_POWER_ON: 162b2b9762fSSantosh Shilimkar case PWRDM_POWER_INACTIVE: 163b2b9762fSSantosh Shilimkar save_state = 0; 164b2b9762fSSantosh Shilimkar break; 165b2b9762fSSantosh Shilimkar case PWRDM_POWER_OFF: 166b2b9762fSSantosh Shilimkar save_state = 1; 167b2b9762fSSantosh Shilimkar break; 168b2b9762fSSantosh Shilimkar case PWRDM_POWER_RET: 169b2b9762fSSantosh Shilimkar default: 170b2b9762fSSantosh Shilimkar /* 171b2b9762fSSantosh Shilimkar * CPUx CSWR is invalid hardware state. Also CPUx OSWR 172b2b9762fSSantosh Shilimkar * doesn't make much scense, since logic is lost and $L1 173b2b9762fSSantosh Shilimkar * needs to be cleaned because of coherency. This makes 174b2b9762fSSantosh Shilimkar * CPUx OSWR equivalent to CPUX OFF and hence not supported 175b2b9762fSSantosh Shilimkar */ 176b2b9762fSSantosh Shilimkar WARN_ON(1); 177b2b9762fSSantosh Shilimkar return -ENXIO; 178b2b9762fSSantosh Shilimkar } 179b2b9762fSSantosh Shilimkar 180*e44f9a77SSantosh Shilimkar pwrdm_clear_all_prev_pwrst(mpuss_pd); 181b2b9762fSSantosh Shilimkar clear_cpu_prev_pwrst(cpu); 182b2b9762fSSantosh Shilimkar set_cpu_next_pwrst(cpu, power_state); 183b2b9762fSSantosh Shilimkar set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume)); 184b2b9762fSSantosh Shilimkar scu_pwrst_prepare(cpu, power_state); 185b2b9762fSSantosh Shilimkar 186b2b9762fSSantosh Shilimkar /* 187b2b9762fSSantosh Shilimkar * Call low level function with targeted low power state. 188b2b9762fSSantosh Shilimkar */ 189b2b9762fSSantosh Shilimkar cpu_suspend(save_state, omap4_finish_suspend); 190b2b9762fSSantosh Shilimkar 191b2b9762fSSantosh Shilimkar /* 192b2b9762fSSantosh Shilimkar * Restore the CPUx power state to ON otherwise CPUx 193b2b9762fSSantosh Shilimkar * power domain can transitions to programmed low power 194b2b9762fSSantosh Shilimkar * state while doing WFI outside the low powe code. On 195b2b9762fSSantosh Shilimkar * secure devices, CPUx does WFI which can result in 196b2b9762fSSantosh Shilimkar * domain transition 197b2b9762fSSantosh Shilimkar */ 198b2b9762fSSantosh Shilimkar wakeup_cpu = smp_processor_id(); 199b2b9762fSSantosh Shilimkar set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON); 200b2b9762fSSantosh Shilimkar 201b2b9762fSSantosh Shilimkar return 0; 202b2b9762fSSantosh Shilimkar } 203b2b9762fSSantosh Shilimkar 204b5b4f288SSantosh Shilimkar /** 205b5b4f288SSantosh Shilimkar * omap4_hotplug_cpu: OMAP4 CPU hotplug entry 206b5b4f288SSantosh Shilimkar * @cpu : CPU ID 207b5b4f288SSantosh Shilimkar * @power_state: CPU low power state. 208b5b4f288SSantosh Shilimkar */ 209b5b4f288SSantosh Shilimkar int omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state) 210b5b4f288SSantosh Shilimkar { 211b5b4f288SSantosh Shilimkar unsigned int cpu_state = 0; 212b5b4f288SSantosh Shilimkar 213b5b4f288SSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) 214b5b4f288SSantosh Shilimkar return -ENXIO; 215b5b4f288SSantosh Shilimkar 216b5b4f288SSantosh Shilimkar if (power_state == PWRDM_POWER_OFF) 217b5b4f288SSantosh Shilimkar cpu_state = 1; 218b5b4f288SSantosh Shilimkar 219b5b4f288SSantosh Shilimkar clear_cpu_prev_pwrst(cpu); 220b5b4f288SSantosh Shilimkar set_cpu_next_pwrst(cpu, power_state); 221b5b4f288SSantosh Shilimkar set_cpu_wakeup_addr(cpu, virt_to_phys(omap_secondary_startup)); 222b5b4f288SSantosh Shilimkar scu_pwrst_prepare(cpu, power_state); 223b5b4f288SSantosh Shilimkar 224b5b4f288SSantosh Shilimkar /* 225b5b4f288SSantosh Shilimkar * CPU never retuns back if targetted power state is OFF mode. 226b5b4f288SSantosh Shilimkar * CPU ONLINE follows normal CPU ONLINE ptah via 227b5b4f288SSantosh Shilimkar * omap_secondary_startup(). 228b5b4f288SSantosh Shilimkar */ 229b5b4f288SSantosh Shilimkar omap4_finish_suspend(cpu_state); 230b5b4f288SSantosh Shilimkar 231b5b4f288SSantosh Shilimkar set_cpu_next_pwrst(cpu, PWRDM_POWER_ON); 232b5b4f288SSantosh Shilimkar return 0; 233b5b4f288SSantosh Shilimkar } 234b5b4f288SSantosh Shilimkar 235b5b4f288SSantosh Shilimkar 236b2b9762fSSantosh Shilimkar /* 237b2b9762fSSantosh Shilimkar * Initialise OMAP4 MPUSS 238b2b9762fSSantosh Shilimkar */ 239b2b9762fSSantosh Shilimkar int __init omap4_mpuss_init(void) 240b2b9762fSSantosh Shilimkar { 241b2b9762fSSantosh Shilimkar struct omap4_cpu_pm_info *pm_info; 242b2b9762fSSantosh Shilimkar void __iomem *sar_base = omap4_get_sar_ram_base(); 243b2b9762fSSantosh Shilimkar 244b2b9762fSSantosh Shilimkar if (omap_rev() == OMAP4430_REV_ES1_0) { 245b2b9762fSSantosh Shilimkar WARN(1, "Power Management not supported on OMAP4430 ES1.0\n"); 246b2b9762fSSantosh Shilimkar return -ENODEV; 247b2b9762fSSantosh Shilimkar } 248b2b9762fSSantosh Shilimkar 249b2b9762fSSantosh Shilimkar /* Initilaise per CPU PM information */ 250b2b9762fSSantosh Shilimkar pm_info = &per_cpu(omap4_pm_info, 0x0); 251b2b9762fSSantosh Shilimkar pm_info->scu_sar_addr = sar_base + SCU_OFFSET0; 252b2b9762fSSantosh Shilimkar pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET; 253b2b9762fSSantosh Shilimkar pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm"); 254b2b9762fSSantosh Shilimkar if (!pm_info->pwrdm) { 255b2b9762fSSantosh Shilimkar pr_err("Lookup failed for CPU0 pwrdm\n"); 256b2b9762fSSantosh Shilimkar return -ENODEV; 257b2b9762fSSantosh Shilimkar } 258b2b9762fSSantosh Shilimkar 259b2b9762fSSantosh Shilimkar /* Clear CPU previous power domain state */ 260b2b9762fSSantosh Shilimkar pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 261b2b9762fSSantosh Shilimkar 262b2b9762fSSantosh Shilimkar /* Initialise CPU0 power domain state to ON */ 263b2b9762fSSantosh Shilimkar pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 264b2b9762fSSantosh Shilimkar 265b2b9762fSSantosh Shilimkar pm_info = &per_cpu(omap4_pm_info, 0x1); 266b2b9762fSSantosh Shilimkar pm_info->scu_sar_addr = sar_base + SCU_OFFSET1; 267b2b9762fSSantosh Shilimkar pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET; 268b2b9762fSSantosh Shilimkar pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm"); 269b2b9762fSSantosh Shilimkar if (!pm_info->pwrdm) { 270b2b9762fSSantosh Shilimkar pr_err("Lookup failed for CPU1 pwrdm\n"); 271b2b9762fSSantosh Shilimkar return -ENODEV; 272b2b9762fSSantosh Shilimkar } 273b2b9762fSSantosh Shilimkar 274b2b9762fSSantosh Shilimkar /* Clear CPU previous power domain state */ 275b2b9762fSSantosh Shilimkar pwrdm_clear_all_prev_pwrst(pm_info->pwrdm); 276b2b9762fSSantosh Shilimkar 277b2b9762fSSantosh Shilimkar /* Initialise CPU1 power domain state to ON */ 278b2b9762fSSantosh Shilimkar pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON); 279b2b9762fSSantosh Shilimkar 280*e44f9a77SSantosh Shilimkar mpuss_pd = pwrdm_lookup("mpu_pwrdm"); 281*e44f9a77SSantosh Shilimkar if (!mpuss_pd) { 282*e44f9a77SSantosh Shilimkar pr_err("Failed to lookup MPUSS power domain\n"); 283*e44f9a77SSantosh Shilimkar return -ENODEV; 284*e44f9a77SSantosh Shilimkar } 285*e44f9a77SSantosh Shilimkar pwrdm_clear_all_prev_pwrst(mpuss_pd); 286*e44f9a77SSantosh Shilimkar 287b2b9762fSSantosh Shilimkar /* Save device type on scratchpad for low level code to use */ 288b2b9762fSSantosh Shilimkar if (omap_type() != OMAP2_DEVICE_TYPE_GP) 289b2b9762fSSantosh Shilimkar __raw_writel(1, sar_base + OMAP_TYPE_OFFSET); 290b2b9762fSSantosh Shilimkar else 291b2b9762fSSantosh Shilimkar __raw_writel(0, sar_base + OMAP_TYPE_OFFSET); 292b2b9762fSSantosh Shilimkar 293b2b9762fSSantosh Shilimkar return 0; 294b2b9762fSSantosh Shilimkar } 295b2b9762fSSantosh Shilimkar 296b2b9762fSSantosh Shilimkar #endif 297