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 <soc/tegra/flowctrl.h>
22 #include <asm/cpuidle.h>
23 #include <asm/smp_plat.h>
24 #include <asm/suspend.h>
33 #ifdef CONFIG_PM_SLEEP
34 static bool abort_flag
;
35 static atomic_t abort_barrier
;
36 static int tegra20_idle_lp2_coupled(struct cpuidle_device
*dev
,
37 struct cpuidle_driver
*drv
,
39 #define TEGRA20_MAX_STATES 2
41 #define TEGRA20_MAX_STATES 1
44 static struct cpuidle_driver tegra_idle_driver
= {
48 ARM_CPUIDLE_WFI_STATE_PWR(600),
49 #ifdef CONFIG_PM_SLEEP
51 .enter
= tegra20_idle_lp2_coupled
,
53 .target_residency
= 10000,
55 .flags
= CPUIDLE_FLAG_COUPLED
|
56 CPUIDLE_FLAG_TIMER_STOP
,
57 .name
= "powered-down",
58 .desc
= "CPU power gated",
62 .state_count
= TEGRA20_MAX_STATES
,
63 .safe_state_index
= 0,
66 #ifdef CONFIG_PM_SLEEP
68 static int tegra20_reset_sleeping_cpu_1(void)
74 if (readb(tegra20_cpu1_resettable_status
) == CPU_RESETTABLE
)
75 tegra20_cpu_shutdown(1);
84 static void tegra20_wake_cpu1_from_reset(void)
88 tegra20_cpu_clear_resettable();
90 /* enable cpu clock on cpu */
91 tegra_enable_cpu_clock(1);
93 /* take the CPU out of reset */
94 tegra_cpu_out_of_reset(1);
97 flowctrl_write_cpu_halt(1, 0);
102 static int tegra20_reset_cpu_1(void)
104 if (!cpu_online(1) || !tegra20_reset_sleeping_cpu_1())
107 tegra20_wake_cpu1_from_reset();
111 static inline void tegra20_wake_cpu1_from_reset(void)
115 static inline int tegra20_reset_cpu_1(void)
121 static bool tegra20_cpu_cluster_power_down(struct cpuidle_device
*dev
,
122 struct cpuidle_driver
*drv
,
125 while (tegra20_cpu_is_resettable_soon())
128 if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
131 tegra_idle_lp2_last();
134 tegra20_wake_cpu1_from_reset();
140 static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device
*dev
,
141 struct cpuidle_driver
*drv
,
144 cpu_suspend(0, tegra20_sleep_cpu_secondary_finish
);
146 tegra20_cpu_clear_resettable();
151 static inline bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device
*dev
,
152 struct cpuidle_driver
*drv
,
159 static int tegra20_idle_lp2_coupled(struct cpuidle_device
*dev
,
160 struct cpuidle_driver
*drv
,
163 bool entered_lp2
= false;
165 if (tegra_pending_sgi())
166 WRITE_ONCE(abort_flag
, true);
168 cpuidle_coupled_parallel_barrier(dev
, &abort_barrier
);
171 cpuidle_coupled_parallel_barrier(dev
, &abort_barrier
);
172 abort_flag
= false; /* clean flag for next coming */
178 tegra_set_cpu_in_lp2();
182 entered_lp2
= tegra20_cpu_cluster_power_down(dev
, drv
, index
);
184 entered_lp2
= tegra20_idle_enter_lp2_cpu_1(dev
, drv
, index
);
187 tegra_clear_cpu_in_lp2();
193 return entered_lp2
? index
: 0;
198 * Tegra20 HW appears to have a bug such that PCIe device interrupts, whether
199 * they are legacy IRQs or MSI, are lost when LP2 is enabled. To work around
200 * this, simply disable LP2 if the PCI driver and DT node are both enabled.
202 void tegra20_cpuidle_pcie_irqs_in_use(void)
205 "Disabling cpuidle LP2 state, since PCIe IRQs are in use\n");
206 cpuidle_driver_state_disabled(&tegra_idle_driver
, 1, true);
209 int __init
tegra20_cpuidle_init(void)
211 return cpuidle_register(&tegra_idle_driver
, cpu_possible_mask
);