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
61 cpu_to_halt_reg r1, r0
62 ldr r3, =TEGRA_FLOW_CTRL_VIRT
63 mov r2, #FLOW_CTRL_WAITEVENT | FLOW_CTRL_JTAG_RESUME
64 str r2, [r3, r1] @ put flow controller in wait event mode
70 ldr r3, =TEGRA_CLK_RESET_VIRT
71 str r1, [r3, #0x340] @ put slave CPU in reset
78 ENDPROC(tegra20_cpu_shutdown)
81 #ifdef CONFIG_PM_SLEEP
85 * spinlock implementation with no atomic test-and-set and no coherence
86 * using Peterson's algorithm on strongly-ordered registers
87 * used to synchronize a cpu waking up from wfi with entering lp2 on idle
89 * The reference link of Peterson's algorithm:
90 * http://en.wikipedia.org/wiki/Peterson's_algorithm
92 * SCRATCH37 = r1 = !turn (inverted from Peterson's algorithm)
94 * r2 = flag[0] (in SCRATCH38)
95 * r3 = flag[1] (in SCRATCH39)
97 * r2 = flag[1] (in SCRATCH39)
98 * r3 = flag[0] (in SCRATCH38)
100 * must be called with MMU on
101 * corrupts r0-r3, r12
103 ENTRY(tegra_pen_lock)
104 mov32 r3, TEGRA_PMC_VIRT
106 add r1, r3, #PMC_SCRATCH37
108 addeq r2, r3, #PMC_SCRATCH38
109 addeq r3, r3, #PMC_SCRATCH39
110 addne r2, r3, #PMC_SCRATCH39
111 addne r3, r3, #PMC_SCRATCH38
114 str r12, [r2] @ flag[cpu] = 1
116 str r12, [r1] @ !turn = cpu
119 cmp r12, #1 @ flag[!cpu] == 1?
121 cmpeq r12, r0 @ !turn == cpu?
122 beq 1b @ while !turn == cpu && flag[!cpu] == 1
125 ENDPROC(tegra_pen_lock)
127 ENTRY(tegra_pen_unlock)
129 mov32 r3, TEGRA_PMC_VIRT
132 addeq r2, r3, #PMC_SCRATCH38
133 addne r2, r3, #PMC_SCRATCH39
137 ENDPROC(tegra_pen_unlock)
140 * tegra20_cpu_clear_resettable(void)
142 * Called to clear the "resettable soon" flag in PMC_SCRATCH41 when
143 * it is expected that the secondary CPU will be idle soon.
145 ENTRY(tegra20_cpu_clear_resettable)
146 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
147 mov r12, #CPU_NOT_RESETTABLE
150 ENDPROC(tegra20_cpu_clear_resettable)
153 * tegra20_cpu_set_resettable_soon(void)
155 * Called to set the "resettable soon" flag in PMC_SCRATCH41 when
156 * it is expected that the secondary CPU will be idle soon.
158 ENTRY(tegra20_cpu_set_resettable_soon)
159 mov32 r1, TEGRA_PMC_VIRT + PMC_SCRATCH41
160 mov r12, #CPU_RESETTABLE_SOON
163 ENDPROC(tegra20_cpu_set_resettable_soon)
166 * tegra20_sleep_cpu_secondary_finish(unsigned long v2p)
168 * Enters WFI on secondary CPU by exiting coherency.
170 ENTRY(tegra20_sleep_cpu_secondary_finish)
171 stmfd sp!, {r4-r11, lr}
173 mrc p15, 0, r11, c1, c0, 1 @ save actlr before exiting coherency
175 /* Flush and disable the L1 data cache */
176 bl tegra_disable_clean_inv_dcache
178 mov32 r0, TEGRA_PMC_VIRT + PMC_SCRATCH41
179 mov r3, #CPU_RESETTABLE
185 * cpu may be reset while in wfi, which will return through
186 * tegra_resume to cpu_resume
187 * or interrupt may wake wfi, which will return here
188 * cpu state is unchanged - MMU is on, cache is on, coherency
189 * is off, and the data cache is off
191 * r11 contains the original actlr
196 mov32 r3, TEGRA_PMC_VIRT
197 add r0, r3, #PMC_SCRATCH41
198 mov r3, #CPU_NOT_RESETTABLE
203 /* Re-enable the data cache */
204 mrc p15, 0, r10, c1, c0, 0
206 mcr p15, 0, r10, c1, c0, 0
209 mcr p15, 0, r11, c1, c0, 1 @ reenable coherency
211 /* Invalidate the TLBs & BTAC */
213 mcr p15, 0, r1, c8, c3, 0 @ invalidate shared TLBs
214 mcr p15, 0, r1, c7, c1, 6 @ invalidate shared BTAC
218 /* the cpu was running with coherency disabled,
219 * caches may be out of date */
220 bl v7_flush_kern_cache_louis
222 ldmfd sp!, {r4 - r11, pc}
223 ENDPROC(tegra20_sleep_cpu_secondary_finish)