ARM: tegra: do v7_invalidate_l1 only when CPU is Cortex-A9
[linux-2.6-block.git] / arch / arm / mach-tegra / sleep-tegra30.S
CommitLineData
59b0f682
JL
1/*
2 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/linkage.h>
18
19#include <asm/assembler.h>
d457ef35 20#include <asm/asm-offsets.h>
59b0f682 21
33d5c019 22#include "fuse.h"
59b0f682
JL
23#include "sleep.h"
24#include "flowctrl.h"
25
26#define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
27
28#if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
29/*
30 * tegra30_hotplug_shutdown(void)
31 *
32 * Powergates the current CPU.
33 * Should never return.
34 */
35ENTRY(tegra30_hotplug_shutdown)
59b0f682
JL
36 /* Powergate this CPU */
37 mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
38 bl tegra30_cpu_shutdown
39 mov pc, lr @ should never get here
40ENDPROC(tegra30_hotplug_shutdown)
41
42/*
43 * tegra30_cpu_shutdown(unsigned long flags)
44 *
45 * Puts the current CPU in wait-for-event mode on the flow controller
46 * and powergates it -- flags (in R0) indicate the request type.
59b0f682 47 *
33d5c019
JL
48 * r10 = SoC ID
49 * corrupts r0-r4, r10-r12
59b0f682
JL
50 */
51ENTRY(tegra30_cpu_shutdown)
52 cpu_id r3
33d5c019
JL
53 tegra_get_soc_id TEGRA_APB_MISC_VIRT, r10
54 cmp r10, #TEGRA30
55 bne _no_cpu0_chk @ It's not Tegra30
56
59b0f682
JL
57 cmp r3, #0
58 moveq pc, lr @ Must never be called for CPU 0
33d5c019 59_no_cpu0_chk:
59b0f682
JL
60
61 ldr r12, =TEGRA_FLOW_CTRL_VIRT
62 cpu_to_csr_reg r1, r3
63 add r1, r1, r12 @ virtual CSR address for this CPU
64 cpu_to_halt_reg r2, r3
65 add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
66
67 /*
68 * Clear this CPU's "event" and "interrupt" flags and power gate
69 * it when halting but not before it is in the "WFE" state.
70 */
71 movw r12, \
72 FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
73 FLOW_CTRL_CSR_ENABLE
33d5c019
JL
74 cmp r10, #TEGRA30
75 moveq r4, #(1 << 4) @ wfe bitmap
76 movne r4, #(1 << 8) @ wfi bitmap
5777b4b5
JL
77 ARM( orr r12, r12, r4, lsl r3 )
78 THUMB( lsl r4, r4, r3 )
79 THUMB( orr r12, r12, r4 )
59b0f682
JL
80 str r12, [r1]
81
82 /* Halt this CPU. */
83 mov r3, #0x400
84delay_1:
85 subs r3, r3, #1 @ delay as a part of wfe war.
86 bge delay_1;
87 cpsid a @ disable imprecise aborts.
88 ldr r3, [r1] @ read CSR
89 str r3, [r1] @ clear CSR
33d5c019 90
59b0f682 91 tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
33d5c019
JL
92 beq flow_ctrl_setting_for_lp2
93
94 /* flow controller set up for hotplug */
95 mov r3, #FLOW_CTRL_WAITEVENT @ For hotplug
96 b flow_ctrl_done
97flow_ctrl_setting_for_lp2:
98 /* flow controller set up for LP2 */
99 cmp r10, #TEGRA30
d457ef35 100 moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
33d5c019 101 movne r3, #FLOW_CTRL_WAITEVENT
1b9e6b27
JL
102 orrne r3, r3, #FLOW_CTRL_HALT_GIC_IRQ
103 orrne r3, r3, #FLOW_CTRL_HALT_GIC_FIQ
33d5c019
JL
104flow_ctrl_done:
105 cmp r10, #TEGRA30
59b0f682
JL
106 str r3, [r2]
107 ldr r0, [r2]
108 b wfe_war
109
110__cpu_reset_again:
111 dsb
112 .align 5
33d5c019
JL
113 wfeeq @ CPU should be power gated here
114 wfine
59b0f682
JL
115wfe_war:
116 b __cpu_reset_again
117
118 /*
119 * 38 nop's, which fills reset of wfe cache line and
120 * 4 more cachelines with nop
121 */
122 .rept 38
123 nop
124 .endr
125 b . @ should never get here
126
127ENDPROC(tegra30_cpu_shutdown)
128#endif
d457ef35
JL
129
130#ifdef CONFIG_PM_SLEEP
131/*
132 * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
133 *
134 * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
135 */
136ENTRY(tegra30_sleep_cpu_secondary_finish)
137 mov r7, lr
138
139 /* Flush and disable the L1 data cache */
140 bl tegra_disable_clean_inv_dcache
141
142 /* Powergate this CPU. */
143 mov r0, #0 @ power mode flags (!hotplug)
144 bl tegra30_cpu_shutdown
145 mov r0, #1 @ never return here
146 mov pc, r7
147ENDPROC(tegra30_sleep_cpu_secondary_finish)
d552920a
JL
148
149/*
150 * tegra30_tear_down_cpu
151 *
152 * Switches the CPU to enter sleep.
153 */
154ENTRY(tegra30_tear_down_cpu)
155 mov32 r6, TEGRA_FLOW_CTRL_BASE
156
157 b tegra30_enter_sleep
158ENDPROC(tegra30_tear_down_cpu)
159
160/*
161 * tegra30_enter_sleep
162 *
163 * uses flow controller to enter sleep state
164 * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
165 * executes from SDRAM with target state is LP2
166 * r6 = TEGRA_FLOW_CTRL_BASE
167 */
168tegra30_enter_sleep:
169 cpu_id r1
170
171 cpu_to_csr_reg r2, r1
172 ldr r0, [r6, r2]
173 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
174 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
175 str r0, [r6, r2]
176
177 mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
178 orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
179 cpu_to_halt_reg r2, r1
180 str r0, [r6, r2]
181 dsb
182 ldr r0, [r6, r2] /* memory barrier */
183
184halted:
185 isb
186 dsb
187 wfi /* CPU should be power gated here */
188
189 /* !!!FIXME!!! Implement halt failure handler */
190 b halted
191
d457ef35 192#endif