123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- /*
- * OMAP MPUSS low power code
- *
- * Copyright (C) 2011 Texas Instruments, Inc.
- * Santosh Shilimkar <santosh.shilimkar@ti.com>
- *
- * OMAP4430 MPUSS mainly consists of dual Cortex-A9 with per-CPU
- * Local timer and Watchdog, GIC, SCU, PL310 L2 cache controller,
- * CPU0 and CPU1 LPRM modules.
- * CPU0, CPU1 and MPUSS each have there own power domain and
- * hence multiple low power combinations of MPUSS are possible.
- *
- * The CPU0 and CPU1 can't support Closed switch Retention (CSWR)
- * because the mode is not supported by hw constraints of dormant
- * mode. While waking up from the dormant mode, a reset signal
- * to the Cortex-A9 processor must be asserted by the external
- * power controller.
- *
- * With architectural inputs and hardware recommendations, only
- * below modes are supported from power gain vs latency point of view.
- *
- * CPU0 CPU1 MPUSS
- * ----------------------------------------------
- * ON ON ON
- * ON(Inactive) OFF ON(Inactive)
- * OFF OFF CSWR
- * OFF OFF OSWR
- * OFF OFF OFF(Device OFF *TBD)
- * ----------------------------------------------
- *
- * Note: CPU0 is the master core and it is the last CPU to go down
- * and first to wake-up when MPUSS low power states are excercised
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
- #include <linux/kernel.h>
- #include <linux/io.h>
- #include <linux/errno.h>
- #include <linux/linkage.h>
- #include <linux/smp.h>
- #include <asm/cacheflush.h>
- #include <asm/tlbflush.h>
- #include <asm/smp_scu.h>
- #include <asm/pgalloc.h>
- #include <asm/suspend.h>
- #include <asm/hardware/cache-l2x0.h>
- #include "soc.h"
- #include "common.h"
- #include "omap44xx.h"
- #include "omap4-sar-layout.h"
- #include "pm.h"
- #include "prcm_mpu44xx.h"
- #include "prminst44xx.h"
- #include "prcm44xx.h"
- #include "prm44xx.h"
- #include "prm-regbits-44xx.h"
- #ifdef CONFIG_SMP
- struct omap4_cpu_pm_info {
- struct powerdomain *pwrdm;
- void __iomem *scu_sar_addr;
- void __iomem *wkup_sar_addr;
- void __iomem *l2x0_sar_addr;
- void (*secondary_startup)(void);
- };
- static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
- static struct powerdomain *mpuss_pd;
- static void __iomem *sar_base;
- /*
- * Program the wakeup routine address for the CPU0 and CPU1
- * used for OFF or DORMANT wakeup.
- */
- static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- __raw_writel(addr, pm_info->wkup_sar_addr);
- }
- /*
- * Set the CPUx powerdomain's previous power state
- */
- static inline void set_cpu_next_pwrst(unsigned int cpu_id,
- unsigned int power_state)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
- }
- /*
- * Read CPU's previous power state
- */
- static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- return pwrdm_read_prev_pwrst(pm_info->pwrdm);
- }
- /*
- * Clear the CPUx powerdomain's previous power state
- */
- static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
- }
- /*
- * Store the SCU power status value to scratchpad memory
- */
- static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- u32 scu_pwr_st;
- switch (cpu_state) {
- case PWRDM_POWER_RET:
- scu_pwr_st = SCU_PM_DORMANT;
- break;
- case PWRDM_POWER_OFF:
- scu_pwr_st = SCU_PM_POWEROFF;
- break;
- case PWRDM_POWER_ON:
- case PWRDM_POWER_INACTIVE:
- default:
- scu_pwr_st = SCU_PM_NORMAL;
- break;
- }
- __raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
- }
- /* Helper functions for MPUSS OSWR */
- static inline void mpuss_clear_prev_logic_pwrst(void)
- {
- u32 reg;
- reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
- OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
- omap4_prminst_write_inst_reg(reg, OMAP4430_PRM_PARTITION,
- OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
- }
- static inline void cpu_clear_prev_logic_pwrst(unsigned int cpu_id)
- {
- u32 reg;
- if (cpu_id) {
- reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU1_INST,
- OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
- omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU1_INST,
- OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
- } else {
- reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU0_INST,
- OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
- omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU0_INST,
- OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
- }
- }
- /**
- * omap4_mpuss_read_prev_context_state:
- * Function returns the MPUSS previous context state
- */
- u32 omap4_mpuss_read_prev_context_state(void)
- {
- u32 reg;
- reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
- OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
- reg &= OMAP4430_LOSTCONTEXT_DFF_MASK;
- return reg;
- }
- /*
- * Store the CPU cluster state for L2X0 low power operations.
- */
- static void l2x0_pwrst_prepare(unsigned int cpu_id, unsigned int save_state)
- {
- struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
- __raw_writel(save_state, pm_info->l2x0_sar_addr);
- }
- /*
- * Save the L2X0 AUXCTRL and POR value to SAR memory. Its used to
- * in every restore MPUSS OFF path.
- */
- #ifdef CONFIG_CACHE_L2X0
- static void save_l2x0_context(void)
- {
- u32 val;
- void __iomem *l2x0_base = omap4_get_l2cache_base();
- val = __raw_readl(l2x0_base + L2X0_AUX_CTRL);
- __raw_writel(val, sar_base + L2X0_AUXCTRL_OFFSET);
- val = __raw_readl(l2x0_base + L2X0_PREFETCH_CTRL);
- __raw_writel(val, sar_base + L2X0_PREFETCH_CTRL_OFFSET);
- }
- #else
- static void save_l2x0_context(void)
- {}
- #endif
- /**
- * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
- * The purpose of this function is to manage low power programming
- * of OMAP4 MPUSS subsystem
- * @cpu : CPU ID
- * @power_state: Low power state.
- *
- * MPUSS states for the context save:
- * save_state =
- * 0 - Nothing lost and no need to save: MPUSS INACTIVE
- * 1 - CPUx L1 and logic lost: MPUSS CSWR
- * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
- * 3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF
- */
- int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
- {
- unsigned int save_state = 0;
|