2 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
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.
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
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/>.
17 #include <linux/linkage.h>
19 #include <asm/assembler.h>
20 #include <asm/asm-offsets.h>
25 #define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
27 #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
29 * tegra30_hotplug_shutdown(void)
31 * Powergates the current CPU.
32 * Should never return.
34 ENTRY(tegra30_hotplug_shutdown)
35 /* Powergate this CPU */
36 mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
37 bl tegra30_cpu_shutdown
38 mov pc, lr @ should never get here
39 ENDPROC(tegra30_hotplug_shutdown)
42 * tegra30_cpu_shutdown(unsigned long flags)
44 * Puts the current CPU in wait-for-event mode on the flow controller
45 * and powergates it -- flags (in R0) indicate the request type.
46 * Must never be called for CPU 0.
50 ENTRY(tegra30_cpu_shutdown)
53 moveq pc, lr @ Must never be called for CPU 0
55 ldr r12, =TEGRA_FLOW_CTRL_VIRT
57 add r1, r1, r12 @ virtual CSR address for this CPU
58 cpu_to_halt_reg r2, r3
59 add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
62 * Clear this CPU's "event" and "interrupt" flags and power gate
63 * it when halting but not before it is in the "WFE" state.
66 FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
69 ARM( orr r12, r12, r4, lsl r3 )
70 THUMB( lsl r4, r4, r3 )
71 THUMB( orr r12, r12, r4 )
77 subs r3, r3, #1 @ delay as a part of wfe war.
79 cpsid a @ disable imprecise aborts.
80 ldr r3, [r1] @ read CSR
81 str r3, [r1] @ clear CSR
82 tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
83 moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
84 movne r3, #FLOW_CTRL_WAITEVENT @ For hotplug
92 wfe @ CPU should be power gated here
97 * 38 nop's, which fills reset of wfe cache line and
98 * 4 more cachelines with nop
103 b . @ should never get here
105 ENDPROC(tegra30_cpu_shutdown)
108 #ifdef CONFIG_PM_SLEEP
110 * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
112 * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
114 ENTRY(tegra30_sleep_cpu_secondary_finish)
117 /* Flush and disable the L1 data cache */
118 bl tegra_disable_clean_inv_dcache
120 /* Powergate this CPU. */
121 mov r0, #0 @ power mode flags (!hotplug)
122 bl tegra30_cpu_shutdown
123 mov r0, #1 @ never return here
125 ENDPROC(tegra30_sleep_cpu_secondary_finish)
128 * tegra30_tear_down_cpu
130 * Switches the CPU to enter sleep.
132 ENTRY(tegra30_tear_down_cpu)
133 mov32 r6, TEGRA_FLOW_CTRL_BASE
135 b tegra30_enter_sleep
136 ENDPROC(tegra30_tear_down_cpu)
139 * tegra30_enter_sleep
141 * uses flow controller to enter sleep state
142 * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
143 * executes from SDRAM with target state is LP2
144 * r6 = TEGRA_FLOW_CTRL_BASE
149 cpu_to_csr_reg r2, r1
151 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
152 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
155 mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
156 orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
157 cpu_to_halt_reg r2, r1
160 ldr r0, [r6, r2] /* memory barrier */
165 wfi /* CPU should be power gated here */
167 /* !!!FIXME!!! Implement halt failure handler */