2 * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
3 * Copyright (c) 2011, Google, Inc.
5 * Author: Colin Cross <ccross@android.com>
6 * Gary King <gking@nvidia.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <linux/linkage.h>
23 #include <asm/assembler.h>
24 #include <asm/proc-fns.h>
30 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
32 * tegra20_hotplug_shutdown(void)
34 * puts the current cpu in reset
37 ENTRY(tegra20_hotplug_shutdown)
38 /* Put this CPU down */
40 bl tegra20_cpu_shutdown
41 mov pc, lr @ should never get here
42 ENDPROC(tegra20_hotplug_shutdown)
45 * tegra20_cpu_shutdown(int cpu)
49 * puts the specified CPU in wait-for-event mode on the flow controller
50 * and puts the CPU in reset
51 * can be called on the current cpu or another cpu
52 * if called on the current cpu, does not return
53 * MUST NOT BE CALLED FOR CPU 0.
57 ENTRY(tegra20_cpu_shutdown)
59 moveq pc, lr @ must not be called for CPU 0
60 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
61 mov r12, #CPU_RESETTABLE
64 cpu_to_halt_reg r1, r0
65 ldr r3, =TEGRA_FLOW_CTRL_VIRT
66 mov r2, #FLOW_CTRL_WAITEVENT | FLOW_CTRL_JTAG_RESUME
67 str r2, [r3, r1] @ put flow controller in wait event mode
73 ldr r3, =TEGRA_CLK_RESET_VIRT
74 str r1, [r3, #0x340] @ put slave CPU in reset
81 ENDPROC(tegra20_cpu_shutdown)
84 #ifdef CONFIG_PM_SLEEP
88 * spinlock implementation with no atomic test-and-set and no coherence
89 * using Peterson's algorithm on strongly-ordered registers
90 * used to synchronize a cpu waking up from wfi with entering lp2 on idle
92 * The reference link of Peterson's algorithm:
93 * http://en.wikipedia.org/wiki/Peterson's_algorithm
95 * SCRATCH37 = r1 = !turn (inverted from Peterson's algorithm)
97 * r2 = flag[0] (in SCRATCH38)
98 * r3 = flag[1] (in SCRATCH39)
100 * r2 = flag[1] (in SCRATCH39)
101 * r3 = flag[0] (in SCRATCH38)
103 * must be called with MMU on
104 * corrupts r0-r3, r12
106 ENTRY(tegra_pen_lock)
107 mov32 r3, TEGRA_PMC_VIRT
109 add r1, r3, #PMC_SCRATCH37
111 addeq r2, r3, #PMC_SCRATCH38
112 addeq r3, r3, #PMC_SCRATCH39
113 addne r2, r3, #PMC_SCRATCH39
114 addne r3, r3, #PMC_SCRATCH38
117 str r12, [r2] @ flag[cpu] = 1
119 str r12, [r1] @ !turn = cpu
122 cmp r12, #1 @ flag[!cpu] == 1?
124 cmpeq r12, r0 @ !turn == cpu?
125 beq 1b @ while !turn == cpu && flag[!cpu] == 1
128 ENDPROC(tegra_pen_lock)
130 ENTRY(tegra_pen_unlock)
132 mov32 r3, TEGRA_PMC_VIRT
135 addeq r2, r3, #PMC_SCRATCH38
136 addne r2, r3, #PMC_SCRATCH39
140 ENDPROC(tegra_pen_unlock)
143 * tegra20_cpu_clear_resettable(void)
145 * Called to clear the "resettable soon" flag in PMC_SCRATCH41 when
146 * it is expected that the secondary CPU will be idle soon.
148 ENTRY(tegra20_cpu_clear_resettable)
149 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
150 mov r12, #CPU_NOT_RESETTABLE
153 ENDPROC(tegra20_cpu_clear_resettable)
156 * tegra20_cpu_set_resettable_soon(void)
158 * Called to set the "resettable soon" flag in PMC_SCRATCH41 when
159 * it is expected that the secondary CPU will be idle soon.
161 ENTRY(tegra20_cpu_set_resettable_soon)
162 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
163 mov r12, #CPU_RESETTABLE_SOON
166 ENDPROC(tegra20_cpu_set_resettable_soon)
169 * tegra20_cpu_is_resettable_soon(void)
171 * Returns true if the "resettable soon" flag in PMC_SCRATCH41 has been
172 * set because it is expected that the secondary CPU will be idle soon.
174 ENTRY(tegra20_cpu_is_resettable_soon)
175 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
177 cmp r12, #CPU_RESETTABLE_SOON
181 ENDPROC(tegra20_cpu_is_resettable_soon)
184 * tegra20_sleep_cpu_secondary_finish(unsigned long v2p)
186 * Enters WFI on secondary CPU by exiting coherency.
188 ENTRY(tegra20_sleep_cpu_secondary_finish)
189 stmfd sp!, {r4-r11, lr}
191 mrc p15, 0, r11, c1, c0, 1 @ save actlr before exiting coherency
193 /* Flush and disable the L1 data cache */
194 bl tegra_disable_clean_inv_dcache
196 mov32 r0, TEGRA_PMC_VIRT + PMC_SCRATCH41
197 mov r3, #CPU_RESETTABLE
203 * cpu may be reset while in wfi, which will return through
204 * tegra_resume to cpu_resume
205 * or interrupt may wake wfi, which will return here
206 * cpu state is unchanged - MMU is on, cache is on, coherency
207 * is off, and the data cache is off
209 * r11 contains the original actlr
214 mov32 r3, TEGRA_PMC_VIRT
215 add r0, r3, #PMC_SCRATCH41
216 mov r3, #CPU_NOT_RESETTABLE
221 /* Re-enable the data cache */
222 mrc p15, 0, r10, c1, c0, 0
224 mcr p15, 0, r10, c1, c0, 0
227 mcr p15, 0, r11, c1, c0, 1 @ reenable coherency
229 /* Invalidate the TLBs & BTAC */
231 mcr p15, 0, r1, c8, c3, 0 @ invalidate shared TLBs
232 mcr p15, 0, r1, c7, c1, 6 @ invalidate shared BTAC
236 /* the cpu was running with coherency disabled,
237 * caches may be out of date */
238 bl v7_flush_kern_cache_louis
240 ldmfd sp!, {r4 - r11, pc}
241 ENDPROC(tegra20_sleep_cpu_secondary_finish)
244 * tegra20_tear_down_cpu
246 * Switches the CPU cluster to PLL-P and enters sleep.
248 ENTRY(tegra20_tear_down_cpu)
249 bl tegra_switch_cpu_to_pllp
250 b tegra20_enter_sleep
251 ENDPROC(tegra20_tear_down_cpu)
254 * tegra20_enter_sleep
256 * uses flow controller to enter sleep state
257 * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
258 * executes from SDRAM with target state is LP2
261 mov32 r6, TEGRA_FLOW_CTRL_BASE
263 mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
264 orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
266 cpu_to_halt_reg r1, r1
269 ldr r0, [r6, r1] /* memory barrier */
273 wfe /* CPU should be power gated here */