ARM: tegra20: cpuidle: add powered-down state for secondary CPU
Subsystems (3)
PATCH v4 2/5 ARM: tegra20: cpuidle: add powered-down state for secondary CPU
The powered-down state of Tegra20 requires power gating both CPU cores. When the secondary CPU requests to enter powered-down state, it saves its own contexts and then enters WFI. The Tegra20 had a limition to power down both CPU cores. The secondary CPU must waits for CPU0 in powered-down state too. If the secondary CPU be woken up before CPU0 entering powered-down state, then it needs to restore its CPU states and waits for next chance.
Be aware of that, you may see the legacy power state "LP2" in the code which is exactly the same meaning of "CPU power down".
Based on the work by:
Colin Cross <[email protected]>
Gary King <[email protected]>
---
V4:
* remove the for loop to copy idle state
* add a checking in tegra_set_cpu_in_lp2 when it is Tegra20 V3:
* dynamic checking of the number of the state counts
* fix the code sequence for aborting cpu_suspend in tegra20_sleep_cpu_secondary_finish
V2:
* no change
--- arch/arm/mach-tegra/cpuidle-tegra20.c | 90 ++++++++++++++++++++- arch/arm/mach-tegra/pm.c | 3 + arch/arm/mach-tegra/sleep-tegra20.S | 147 ++++++++++++++++++++++++++++++++++ arch/arm/mach-tegra/sleep.h | 23 ++++++ 4 files changed, 259 insertions(+), 4 deletions(-)
arch/arm/mach-tegra/cpuidle-tegra20.c +86 -4
@@ -22,21 +22,99 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/cpuidle.h> +#include <linux/cpu_pm.h> +#include <linux/clockchips.h> #include <asm/cpuidle.h> +#include <asm/proc-fns.h> +#include <asm/suspend.h> +#include <asm/smp_plat.h> + +#include "pm.h" +#include "sleep.h" + +#ifdef CONFIG_PM_SLEEP +static int tegra20_idle_lp2 (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index); +#endif + +static struct cpuidle_state tegra_idle_states[] = { + [0 ] =ARM_CPUIDLE_WFI_STATE_PWR (600 ), +#ifdef CONFIG_PM_SLEEP + [1] = { + .enter = tegra20_idle_lp2, + .exit_latency =5000 , + .target_residency =10000 , + .power_usage =0 , + .flags =CPUIDLE_FLAG_TIME_VALID , + .name ="powered-down" , + .desc ="CPU power gated" , + }, +#endif +};static struct cpuidle_driver tegra_idle_driver = { .name ="tegra_idle" , .owner =THIS_MODULE , .en_core_tk_irqen =1 , - .state_count =1 , - .states = { - [0 ] =ARM_CPUIDLE_WFI_STATE_PWR (600 ), - }, }; static DEFINE_PER_CPU(struct cpuidle_device, tegra_idle_device); +#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_SMP +static bool tegra20_idle_enter_lp2_cpu_1 (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); + +cpu_suspend (0 , tegra20_sleep_cpu_secondary_finish); + +tegra20_cpu_clear_resettable (); + +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); + +return true; +} +#else +static inline bool tegra20_idle_enter_lp2_cpu_1 (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +return true; +} +#endif + +static int tegra20_idle_lp2 (struct cpuidle_device *dev, +struct cpuidle_driver *drv, +int index) +{ +u32 cpu =is_smp () ?cpu_logical_map (dev->cpu) : dev->cpu; +bool entered_lp2 = false; + +local_fiq_disable (); + +tegra_set_cpu_in_lp2 (cpu); +cpu_pm_enter (); + +if (cpu ==0 ) +cpu_do_idle (); +else + entered_lp2 =tegra20_idle_enter_lp2_cpu_1 (dev, drv, index); + +cpu_pm_exit (); +tegra_clear_cpu_in_lp2 (cpu); + +local_fiq_enable (); + +smp_rmb (); + +return entered_lp2 ? index :0 ; +} +#endif +int __init tegra20_cpuidle_init (void ) {int ret;
@@ -44,6 +122,10 @@ int __init tegra20_cpuidle_init(void)struct cpuidle_device *dev;struct cpuidle_driver *drv = &tegra_idle_driver; + drv->state_count =ARRAY_SIZE (tegra_idle_states); +memcpy (drv->states, tegra_idle_states, + drv->state_count *sizeof (drv->states[0 ])); + ret =cpuidle_register_driver (&tegra_idle_driver);if (ret) {pr_err ("CPUidle driver registration failed\n" );
arch/arm/mach-tegra/pm.c +3 -0
@@ -36,6 +36,7 @@#include "iomap.h" #include "reset.h" #include "flowctrl.h" +#include "fuse.h" #include "sleep.h" #define TEGRA_POWER_CPU_PWRREQ_OE (1 << 16)/* CPU pwr req enable */
@@ -173,6 +174,8 @@ bool tegra_set_cpu_in_lp2(int phy_cpu_id)if ((phy_cpu_id ==0 ) &&cpumask_equal (cpu_lp2_mask, cpu_online_mask)) last_cpu = true; +else if (tegra_chip_id ==TEGRA20 && phy_cpu_id ==1 ) +tegra20_cpu_set_resettable_soon ();spin_unlock (&tegra_lp2_lock);return last_cpu;
arch/arm/mach-tegra/sleep-tegra20.S +147 -0
156 lines not on this page · raw message
arch/arm/mach-tegra/sleep.h +23 -0
@@ -25,6 +25,19 @@ + IO_PPSB_VIRT)#define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS \ + IO_PPSB_VIRT) +#define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT) + +/* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */ +#define PMC_SCRATCH37 0x130 +#define PMC_SCRATCH38 0x134 +#define PMC_SCRATCH39 0x138 +#define PMC_SCRATCH41 0x140 + +#ifdef CONFIG_ARCH_TEGRA_2x_SOC +#define CPU_RESETTABLE 2 +#define CPU_RESETTABLE_SOON 1 +#define CPU_NOT_RESETTABLE 0 +#endif #ifdef __ASSEMBLY__/* returns the offset of the flow controller halt register for a cpu */
@@ -104,6 +117,8 @@ exit_l2_resume: .endm#endif /* CONFIG_CACHE_L2X0 */ #else +void tegra_pen_lock (void ); +void tegra_pen_unlock (void );void tegra_resume (void );int tegra_sleep_cpu_finish (unsigned long );void tegra_disable_clean_inv_dcache (void );
@@ -116,6 +131,14 @@ static inline void tegra20_hotplug_init(void) {}static inline void tegra30_hotplug_init (void ) {}#endif +void tegra20_cpu_clear_resettable (void ); +#ifdef CONFIG_ARCH_TEGRA_2x_SOC +void tegra20_cpu_set_resettable_soon (void ); +#else +static inline void tegra20_cpu_set_resettable_soon (void ) {} +#endif + +int tegra20_sleep_cpu_secondary_finish (unsigned long );int tegra30_sleep_cpu_secondary_finish (unsigned long );void tegra30_tear_down_cpu (void );
Signature · 1 line
1.8.0.3