1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * CPU idle driver for Tegra CPUs
5 * Copyright (c) 2010-2012, NVIDIA Corporation.
6 * Copyright (c) 2011 Google, Inc.
7 * Author: Colin Cross <ccross@android.com>
8 * Gary King <gking@nvidia.com>
10 * Rework for 3.3 by Peter De Schrijver <pdeschrijver@nvidia.com>
13 #include <linux/clk/tegra.h>
14 #include <linux/tick.h>
15 #include <linux/cpuidle.h>
16 #include <linux/cpu_pm.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <asm/cpuidle.h>
21 #include <asm/smp_plat.h>
22 #include <asm/suspend.h>
28 #ifdef CONFIG_PM_SLEEP
29 static int tegra30_idle_lp2(struct cpuidle_device
*dev
,
30 struct cpuidle_driver
*drv
,
34 static struct cpuidle_driver tegra_idle_driver
= {
37 #ifdef CONFIG_PM_SLEEP
43 [0] = ARM_CPUIDLE_WFI_STATE_PWR(600),
44 #ifdef CONFIG_PM_SLEEP
46 .enter
= tegra30_idle_lp2
,
48 .target_residency
= 2200,
50 .flags
= CPUIDLE_FLAG_TIMER_STOP
,
51 .name
= "powered-down",
52 .desc
= "CPU power gated",
58 #ifdef CONFIG_PM_SLEEP
59 static bool tegra30_cpu_cluster_power_down(struct cpuidle_device
*dev
,
60 struct cpuidle_driver
*drv
,
63 /* All CPUs entering LP2 is not working.
64 * Don't let CPU0 enter LP2 when any secondary CPU is online.
66 if (num_online_cpus() > 1 || !tegra_cpu_rail_off_ready()) {
71 tegra_idle_lp2_last();
77 static bool tegra30_cpu_core_power_down(struct cpuidle_device
*dev
,
78 struct cpuidle_driver
*drv
,
83 cpu_suspend(0, tegra30_sleep_cpu_secondary_finish
);
88 static inline bool tegra30_cpu_core_power_down(struct cpuidle_device
*dev
,
89 struct cpuidle_driver
*drv
,
96 static int tegra30_idle_lp2(struct cpuidle_device
*dev
,
97 struct cpuidle_driver
*drv
,
100 bool entered_lp2
= false;
105 last_cpu
= tegra_set_cpu_in_lp2();
110 entered_lp2
= tegra30_cpu_cluster_power_down(dev
, drv
,
115 entered_lp2
= tegra30_cpu_core_power_down(dev
, drv
, index
);
119 tegra_clear_cpu_in_lp2();
125 return (entered_lp2
) ? index
: 0;
129 int __init
tegra30_cpuidle_init(void)
131 return cpuidle_register(&tegra_idle_driver
, NULL
);