]> Git Repo - linux.git/blame - arch/arm/mach-tegra/cpuidle-tegra20.c
cpuidle: Invert CPUIDLE_FLAG_TIME_VALID logic
[linux.git] / arch / arm / mach-tegra / cpuidle-tegra20.c
CommitLineData
0b25e25b
JL
1/*
2 * CPU idle driver for Tegra CPUs
3 *
4 * Copyright (c) 2010-2012, NVIDIA Corporation.
5 * Copyright (c) 2011 Google, Inc.
6 * Author: Colin Cross <[email protected]>
7 * Gary King <[email protected]>
8 *
9 * Rework for 3.3 by Peter De Schrijver <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * more details.
20 */
21
a0524acc
TR
22#include <linux/clk/tegra.h>
23#include <linux/clockchips.h>
0b25e25b 24#include <linux/cpuidle.h>
5c1350bd 25#include <linux/cpu_pm.h>
a0524acc
TR
26#include <linux/kernel.h>
27#include <linux/module.h>
0b25e25b
JL
28
29#include <asm/cpuidle.h>
5c1350bd 30#include <asm/proc-fns.h>
5c1350bd 31#include <asm/smp_plat.h>
a0524acc 32#include <asm/suspend.h>
5c1350bd 33
a0524acc 34#include "flowctrl.h"
1d328606
JL
35#include "iomap.h"
36#include "irq.h"
a0524acc
TR
37#include "pm.h"
38#include "sleep.h"
5c1350bd
JL
39
40#ifdef CONFIG_PM_SLEEP
1d328606
JL
41static bool abort_flag;
42static atomic_t abort_barrier;
43static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
44 struct cpuidle_driver *drv,
45 int index);
14ad7a11
DL
46#define TEGRA20_MAX_STATES 2
47#else
48#define TEGRA20_MAX_STATES 1
5c1350bd
JL
49#endif
50
0b25e25b
JL
51static struct cpuidle_driver tegra_idle_driver = {
52 .name = "tegra_idle",
53 .owner = THIS_MODULE,
14ad7a11
DL
54 .states = {
55 ARM_CPUIDLE_WFI_STATE_PWR(600),
56#ifdef CONFIG_PM_SLEEP
57 {
58 .enter = tegra20_idle_lp2_coupled,
59 .exit_latency = 5000,
60 .target_residency = 10000,
61 .power_usage = 0,
b82b6cca 62 .flags = CPUIDLE_FLAG_COUPLED,
14ad7a11
DL
63 .name = "powered-down",
64 .desc = "CPU power gated",
65 },
66#endif
67 },
68 .state_count = TEGRA20_MAX_STATES,
69 .safe_state_index = 0,
0b25e25b
JL
70};
71
5c1350bd 72#ifdef CONFIG_PM_SLEEP
1d328606
JL
73#ifdef CONFIG_SMP
74static void __iomem *pmc = IO_ADDRESS(TEGRA_PMC_BASE);
75
76static int tegra20_reset_sleeping_cpu_1(void)
77{
78 int ret = 0;
79
80 tegra_pen_lock();
81
82 if (readl(pmc + PMC_SCRATCH41) == CPU_RESETTABLE)
83 tegra20_cpu_shutdown(1);
84 else
85 ret = -EINVAL;
86
87 tegra_pen_unlock();
88
89 return ret;
90}
91
92static void tegra20_wake_cpu1_from_reset(void)
93{
94 tegra_pen_lock();
95
96 tegra20_cpu_clear_resettable();
97
98 /* enable cpu clock on cpu */
99 tegra_enable_cpu_clock(1);
100
101 /* take the CPU out of reset */
102 tegra_cpu_out_of_reset(1);
103
104 /* unhalt the cpu */
105 flowctrl_write_cpu_halt(1, 0);
106
107 tegra_pen_unlock();
108}
109
110static int tegra20_reset_cpu_1(void)
111{
112 if (!cpu_online(1) || !tegra20_reset_sleeping_cpu_1())
113 return 0;
114
115 tegra20_wake_cpu1_from_reset();
116 return -EBUSY;
117}
118#else
119static inline void tegra20_wake_cpu1_from_reset(void)
120{
121}
122
123static inline int tegra20_reset_cpu_1(void)
124{
125 return 0;
126}
127#endif
128
129static bool tegra20_cpu_cluster_power_down(struct cpuidle_device *dev,
130 struct cpuidle_driver *drv,
131 int index)
132{
1d328606
JL
133 while (tegra20_cpu_is_resettable_soon())
134 cpu_relax();
135
136 if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
137 return false;
138
139 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
140
4d82d058 141 tegra_idle_lp2_last();
1d328606
JL
142
143 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
144
145 if (cpu_online(1))
146 tegra20_wake_cpu1_from_reset();
147
148 return true;
149}
150
5c1350bd
JL
151#ifdef CONFIG_SMP
152static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
153 struct cpuidle_driver *drv,
154 int index)
155{
156 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
157
158 cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
159
160 tegra20_cpu_clear_resettable();
161
162 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
163
164 return true;
165}
166#else
167static inline bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
168 struct cpuidle_driver *drv,
169 int index)
170{
171 return true;
172}
173#endif
174
1d328606
JL
175static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
176 struct cpuidle_driver *drv,
177 int index)
5c1350bd 178{
5c1350bd
JL
179 bool entered_lp2 = false;
180
1d328606
JL
181 if (tegra_pending_sgi())
182 ACCESS_ONCE(abort_flag) = true;
183
184 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
185
186 if (abort_flag) {
187 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
188 abort_flag = false; /* clean flag for next coming */
189 return -EINTR;
190 }
191
5c1350bd
JL
192 local_fiq_disable();
193
8f6a0b65 194 tegra_set_cpu_in_lp2();
5c1350bd
JL
195 cpu_pm_enter();
196
8f6a0b65 197 if (dev->cpu == 0)
1d328606 198 entered_lp2 = tegra20_cpu_cluster_power_down(dev, drv, index);
5c1350bd
JL
199 else
200 entered_lp2 = tegra20_idle_enter_lp2_cpu_1(dev, drv, index);
201
202 cpu_pm_exit();
8f6a0b65 203 tegra_clear_cpu_in_lp2();
5c1350bd
JL
204
205 local_fiq_enable();
206
207 smp_rmb();
208
209 return entered_lp2 ? index : 0;
210}
211#endif
212
b4f17375
SW
213/*
214 * Tegra20 HW appears to have a bug such that PCIe device interrupts, whether
215 * they are legacy IRQs or MSI, are lost when LP2 is enabled. To work around
216 * this, simply disable LP2 if the PCI driver and DT node are both enabled.
217 */
218void tegra20_cpuidle_pcie_irqs_in_use(void)
219{
220 pr_info_once(
221 "Disabling cpuidle LP2 state, since PCIe IRQs are in use\n");
222 tegra_idle_driver.states[1].disabled = true;
223}
224
0b25e25b
JL
225int __init tegra20_cpuidle_init(void)
226{
c5106c9d 227 return cpuidle_register(&tegra_idle_driver, cpu_possible_mask);
0b25e25b 228}
This page took 0.253044 seconds and 4 git commands to generate.