arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / arm / mach-tegra / cpuidle-tegra20.c
blob69f3fa270fbe396410c088d82130595aceaa5639
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
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>
26 #include "cpuidle.h"
27 #include "iomap.h"
28 #include "irq.h"
29 #include "pm.h"
30 #include "reset.h"
31 #include "sleep.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,
38 int index);
39 #define TEGRA20_MAX_STATES 2
40 #else
41 #define TEGRA20_MAX_STATES 1
42 #endif
44 static struct cpuidle_driver tegra_idle_driver = {
45 .name = "tegra_idle",
46 .owner = THIS_MODULE,
47 .states = {
48 ARM_CPUIDLE_WFI_STATE_PWR(600),
49 #ifdef CONFIG_PM_SLEEP
51 .enter = tegra20_idle_lp2_coupled,
52 .exit_latency = 5000,
53 .target_residency = 10000,
54 .power_usage = 0,
55 .flags = CPUIDLE_FLAG_COUPLED |
56 CPUIDLE_FLAG_TIMER_STOP,
57 .name = "powered-down",
58 .desc = "CPU power gated",
60 #endif
62 .state_count = TEGRA20_MAX_STATES,
63 .safe_state_index = 0,
66 #ifdef CONFIG_PM_SLEEP
67 #ifdef CONFIG_SMP
68 static int tegra20_reset_sleeping_cpu_1(void)
70 int ret = 0;
72 tegra_pen_lock();
74 if (readb(tegra20_cpu1_resettable_status) == CPU_RESETTABLE)
75 tegra20_cpu_shutdown(1);
76 else
77 ret = -EINVAL;
79 tegra_pen_unlock();
81 return ret;
84 static void tegra20_wake_cpu1_from_reset(void)
86 tegra_pen_lock();
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);
96 /* unhalt the cpu */
97 flowctrl_write_cpu_halt(1, 0);
99 tegra_pen_unlock();
102 static int tegra20_reset_cpu_1(void)
104 if (!cpu_online(1) || !tegra20_reset_sleeping_cpu_1())
105 return 0;
107 tegra20_wake_cpu1_from_reset();
108 return -EBUSY;
110 #else
111 static inline void tegra20_wake_cpu1_from_reset(void)
115 static inline int tegra20_reset_cpu_1(void)
117 return 0;
119 #endif
121 static bool tegra20_cpu_cluster_power_down(struct cpuidle_device *dev,
122 struct cpuidle_driver *drv,
123 int index)
125 while (tegra20_cpu_is_resettable_soon())
126 cpu_relax();
128 if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
129 return false;
131 tegra_idle_lp2_last();
133 if (cpu_online(1))
134 tegra20_wake_cpu1_from_reset();
136 return true;
139 #ifdef CONFIG_SMP
140 static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
141 struct cpuidle_driver *drv,
142 int index)
144 cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
146 tegra20_cpu_clear_resettable();
148 return true;
150 #else
151 static inline bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
152 struct cpuidle_driver *drv,
153 int index)
155 return true;
157 #endif
159 static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
160 struct cpuidle_driver *drv,
161 int index)
163 bool entered_lp2 = false;
165 if (tegra_pending_sgi())
166 WRITE_ONCE(abort_flag, true);
168 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
170 if (abort_flag) {
171 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
172 abort_flag = false; /* clean flag for next coming */
173 return -EINTR;
176 local_fiq_disable();
178 tegra_set_cpu_in_lp2();
179 cpu_pm_enter();
181 if (dev->cpu == 0)
182 entered_lp2 = tegra20_cpu_cluster_power_down(dev, drv, index);
183 else
184 entered_lp2 = tegra20_idle_enter_lp2_cpu_1(dev, drv, index);
186 cpu_pm_exit();
187 tegra_clear_cpu_in_lp2();
189 local_fiq_enable();
191 smp_rmb();
193 return entered_lp2 ? index : 0;
195 #endif
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)
204 pr_info_once(
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);