blob: 357175895c46bec3bc9e7046d17cac89dc9b2a26 [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch_helpers.h>
32#include <assert.h>
33#include <debug.h>
Varun Wadekar85a90cf2015-07-08 13:46:42 +053034#include <delay_timer.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053035#include <mmio.h>
36#include <pmc.h>
37#include <cortex_a53.h>
38#include <flowctrl.h>
39#include <tegra_def.h>
40
41#define CLK_RST_DEV_L_SET 0x300
42#define CLK_RST_DEV_L_CLR 0x304
43#define CLK_BPMP_RST (1 << 1)
44
45#define EVP_BPMP_RESET_VECTOR 0x200
46
47static const uint64_t flowctrl_offset_cpu_csr[4] = {
48 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU0_CSR),
49 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR),
50 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR + 8),
51 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR + 16)
52};
53
54static const uint64_t flowctrl_offset_halt_cpu[4] = {
55 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU0_EVENTS),
56 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS),
57 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS + 8),
58 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS + 16)
59};
60
61static const uint64_t flowctrl_offset_cc4_ctrl[4] = {
62 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL),
63 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 4),
64 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 8),
65 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 12)
66};
67
68static inline void tegra_fc_cc4_ctrl(int cpu_id, uint32_t val)
69{
70 mmio_write_32(flowctrl_offset_cc4_ctrl[cpu_id], val);
71 val = mmio_read_32(flowctrl_offset_cc4_ctrl[cpu_id]);
72}
73
74static inline void tegra_fc_cpu_csr(int cpu_id, uint32_t val)
75{
76 mmio_write_32(flowctrl_offset_cpu_csr[cpu_id], val);
77 val = mmio_read_32(flowctrl_offset_cpu_csr[cpu_id]);
78}
79
80static inline void tegra_fc_halt_cpu(int cpu_id, uint32_t val)
81{
82 mmio_write_32(flowctrl_offset_halt_cpu[cpu_id], val);
83 val = mmio_read_32(flowctrl_offset_halt_cpu[cpu_id]);
84}
85
86static void tegra_fc_prepare_suspend(int cpu_id, uint32_t csr)
87{
88 uint32_t val;
89
90 val = FLOWCTRL_HALT_GIC_IRQ | FLOWCTRL_HALT_GIC_FIQ |
91 FLOWCTRL_HALT_LIC_IRQ | FLOWCTRL_HALT_LIC_FIQ |
92 FLOWCTRL_WAITEVENT;
93 tegra_fc_halt_cpu(cpu_id, val);
94
95 val = FLOWCTRL_CSR_INTR_FLAG | FLOWCTRL_CSR_EVENT_FLAG |
96 FLOWCTRL_CSR_ENABLE | (FLOWCTRL_WAIT_WFI_BITMAP << cpu_id);
97 tegra_fc_cpu_csr(cpu_id, val | csr);
98}
99
100/*******************************************************************************
Varun Wadekarb2baa892015-08-27 10:25:29 +0530101 * Powerdn the current CPU
Varun Wadekarb316e242015-05-19 16:48:04 +0530102 ******************************************************************************/
Varun Wadekarb2baa892015-08-27 10:25:29 +0530103void tegra_fc_cpu_powerdn(uint32_t mpidr)
Varun Wadekarb316e242015-05-19 16:48:04 +0530104{
105 int cpu = mpidr & MPIDR_CPU_MASK;
106
107 VERBOSE("CPU%d powering down...\n", cpu);
108 tegra_fc_prepare_suspend(cpu, 0);
109}
110
111/*******************************************************************************
112 * Suspend the current CPU cluster
113 ******************************************************************************/
114void tegra_fc_cluster_idle(uint32_t mpidr)
115{
116 int cpu = mpidr & MPIDR_CPU_MASK;
117 uint32_t val;
118
119 VERBOSE("Entering cluster idle state...\n");
120
121 tegra_fc_cc4_ctrl(cpu, 0);
122
123 /* hardware L2 flush is faster for A53 only */
124 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL,
125 !!MPIDR_AFFLVL1_VAL(mpidr));
126
127 /* suspend the CPU cluster */
128 val = FLOWCTRL_PG_CPU_NONCPU << FLOWCTRL_ENABLE_EXT;
129 tegra_fc_prepare_suspend(cpu, val);
130}
131
132/*******************************************************************************
133 * Power down the current CPU cluster
134 ******************************************************************************/
135void tegra_fc_cluster_powerdn(uint32_t mpidr)
136{
137 int cpu = mpidr & MPIDR_CPU_MASK;
138 uint32_t val;
139
140 VERBOSE("Entering cluster powerdn state...\n");
141
142 tegra_fc_cc4_ctrl(cpu, 0);
143
144 /* hardware L2 flush is faster for A53 only */
145 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL,
146 read_midr() == CORTEX_A53_MIDR);
147
148 /* power down the CPU cluster */
149 val = FLOWCTRL_TURNOFF_CPURAIL << FLOWCTRL_ENABLE_EXT;
150 tegra_fc_prepare_suspend(cpu, val);
151}
152
153/*******************************************************************************
154 * Suspend the entire SoC
155 ******************************************************************************/
156void tegra_fc_soc_powerdn(uint32_t mpidr)
157{
158 int cpu = mpidr & MPIDR_CPU_MASK;
159 uint32_t val;
160
161 VERBOSE("Entering SoC powerdn state...\n");
162
163 tegra_fc_cc4_ctrl(cpu, 0);
164
165 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL, 1);
166
167 val = FLOWCTRL_TURNOFF_CPURAIL << FLOWCTRL_ENABLE_EXT;
168 tegra_fc_prepare_suspend(cpu, val);
169
170 /* overwrite HALT register */
171 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT);
172}
173
174/*******************************************************************************
175 * Power up the CPU
176 ******************************************************************************/
177void tegra_fc_cpu_on(int cpu)
178{
179 tegra_fc_cpu_csr(cpu, FLOWCTRL_CSR_ENABLE);
180 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT | FLOWCTRL_HALT_SCLK);
181}
182
183/*******************************************************************************
184 * Power down the CPU
185 ******************************************************************************/
186void tegra_fc_cpu_off(int cpu)
187{
188 uint32_t val;
189
190 /*
191 * Flow controller powers down the CPU during wfi. The CPU would be
192 * powered on when it receives any interrupt.
193 */
194 val = FLOWCTRL_CSR_INTR_FLAG | FLOWCTRL_CSR_EVENT_FLAG |
195 FLOWCTRL_CSR_ENABLE | (FLOWCTRL_WAIT_WFI_BITMAP << cpu);
196 tegra_fc_cpu_csr(cpu, val);
197 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT);
198 tegra_fc_cc4_ctrl(cpu, 0);
199}
200
201/*******************************************************************************
202 * Inform the BPMP that we have completed the cluster power up
203 ******************************************************************************/
204void tegra_fc_lock_active_cluster(void)
205{
206 uint32_t val;
207
208 val = tegra_fc_read_32(FLOWCTRL_BPMP_CLUSTER_CONTROL);
209 val |= FLOWCTRL_BPMP_CLUSTER_PWRON_LOCK;
210 tegra_fc_write_32(FLOWCTRL_BPMP_CLUSTER_CONTROL, val);
211 val = tegra_fc_read_32(FLOWCTRL_BPMP_CLUSTER_CONTROL);
212}
213
214/*******************************************************************************
215 * Reset BPMP processor
216 ******************************************************************************/
217void tegra_fc_reset_bpmp(void)
218{
219 uint32_t val;
220
221 /* halt BPMP */
222 tegra_fc_write_32(FLOWCTRL_HALT_BPMP_EVENTS, FLOWCTRL_WAITEVENT);
223
224 /* Assert BPMP reset */
225 mmio_write_32(TEGRA_CAR_RESET_BASE + CLK_RST_DEV_L_SET, CLK_BPMP_RST);
226
227 /* Restore reset address (stored in PMC_SCRATCH39) */
228 val = tegra_pmc_read_32(PMC_SCRATCH39);
229 mmio_write_32(TEGRA_EVP_BASE + EVP_BPMP_RESET_VECTOR, val);
230 while (val != mmio_read_32(TEGRA_EVP_BASE + EVP_BPMP_RESET_VECTOR))
231 ; /* wait till value reaches EVP_BPMP_RESET_VECTOR */
232
233 /* Wait for 2us before de-asserting the reset signal. */
Varun Wadekar85a90cf2015-07-08 13:46:42 +0530234 udelay(2);
Varun Wadekarb316e242015-05-19 16:48:04 +0530235
236 /* De-assert BPMP reset */
237 mmio_write_32(TEGRA_CAR_RESET_BASE + CLK_RST_DEV_L_CLR, CLK_BPMP_RST);
238
239 /* Un-halt BPMP */
240 tegra_fc_write_32(FLOWCTRL_HALT_BPMP_EVENTS, 0);
241}