blob: 775ad30f6b9d59b2515069ddf3938975c4a7aebb [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarb316e242015-05-19 16:48:04 +05305 */
6
Varun Wadekarb316e242015-05-19 16:48:04 +05307#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010010#include <cortex_a53.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <common/debug.h>
12#include <drivers/delay_timer.h>
13#include <lib/mmio.h>
14
Isla Mitchelle3631462017-07-14 10:46:32 +010015#include <flowctrl.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053016#include <pmc.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053017#include <tegra_def.h>
18
19#define CLK_RST_DEV_L_SET 0x300
20#define CLK_RST_DEV_L_CLR 0x304
21#define CLK_BPMP_RST (1 << 1)
22
23#define EVP_BPMP_RESET_VECTOR 0x200
24
25static const uint64_t flowctrl_offset_cpu_csr[4] = {
26 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU0_CSR),
27 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR),
28 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR + 8),
29 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CPU1_CSR + 16)
30};
31
32static const uint64_t flowctrl_offset_halt_cpu[4] = {
33 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU0_EVENTS),
34 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS),
35 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS + 8),
36 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_HALT_CPU1_EVENTS + 16)
37};
38
39static const uint64_t flowctrl_offset_cc4_ctrl[4] = {
40 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL),
41 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 4),
42 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 8),
43 (TEGRA_FLOWCTRL_BASE + FLOWCTRL_CC4_CORE0_CTRL + 12)
44};
45
46static inline void tegra_fc_cc4_ctrl(int cpu_id, uint32_t val)
47{
48 mmio_write_32(flowctrl_offset_cc4_ctrl[cpu_id], val);
49 val = mmio_read_32(flowctrl_offset_cc4_ctrl[cpu_id]);
50}
51
52static inline void tegra_fc_cpu_csr(int cpu_id, uint32_t val)
53{
54 mmio_write_32(flowctrl_offset_cpu_csr[cpu_id], val);
55 val = mmio_read_32(flowctrl_offset_cpu_csr[cpu_id]);
56}
57
58static inline void tegra_fc_halt_cpu(int cpu_id, uint32_t val)
59{
60 mmio_write_32(flowctrl_offset_halt_cpu[cpu_id], val);
61 val = mmio_read_32(flowctrl_offset_halt_cpu[cpu_id]);
62}
63
64static void tegra_fc_prepare_suspend(int cpu_id, uint32_t csr)
65{
66 uint32_t val;
67
68 val = FLOWCTRL_HALT_GIC_IRQ | FLOWCTRL_HALT_GIC_FIQ |
69 FLOWCTRL_HALT_LIC_IRQ | FLOWCTRL_HALT_LIC_FIQ |
70 FLOWCTRL_WAITEVENT;
71 tegra_fc_halt_cpu(cpu_id, val);
72
73 val = FLOWCTRL_CSR_INTR_FLAG | FLOWCTRL_CSR_EVENT_FLAG |
74 FLOWCTRL_CSR_ENABLE | (FLOWCTRL_WAIT_WFI_BITMAP << cpu_id);
75 tegra_fc_cpu_csr(cpu_id, val | csr);
76}
77
78/*******************************************************************************
Varun Wadekarb2baa892015-08-27 10:25:29 +053079 * Powerdn the current CPU
Varun Wadekarb316e242015-05-19 16:48:04 +053080 ******************************************************************************/
Varun Wadekarb2baa892015-08-27 10:25:29 +053081void tegra_fc_cpu_powerdn(uint32_t mpidr)
Varun Wadekarb316e242015-05-19 16:48:04 +053082{
83 int cpu = mpidr & MPIDR_CPU_MASK;
84
85 VERBOSE("CPU%d powering down...\n", cpu);
86 tegra_fc_prepare_suspend(cpu, 0);
87}
88
89/*******************************************************************************
90 * Suspend the current CPU cluster
91 ******************************************************************************/
92void tegra_fc_cluster_idle(uint32_t mpidr)
93{
94 int cpu = mpidr & MPIDR_CPU_MASK;
95 uint32_t val;
96
97 VERBOSE("Entering cluster idle state...\n");
98
99 tegra_fc_cc4_ctrl(cpu, 0);
100
101 /* hardware L2 flush is faster for A53 only */
102 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL,
103 !!MPIDR_AFFLVL1_VAL(mpidr));
104
105 /* suspend the CPU cluster */
106 val = FLOWCTRL_PG_CPU_NONCPU << FLOWCTRL_ENABLE_EXT;
107 tegra_fc_prepare_suspend(cpu, val);
108}
109
110/*******************************************************************************
111 * Power down the current CPU cluster
112 ******************************************************************************/
113void tegra_fc_cluster_powerdn(uint32_t mpidr)
114{
115 int cpu = mpidr & MPIDR_CPU_MASK;
116 uint32_t val;
117
118 VERBOSE("Entering cluster powerdn state...\n");
119
120 tegra_fc_cc4_ctrl(cpu, 0);
121
122 /* hardware L2 flush is faster for A53 only */
123 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL,
124 read_midr() == CORTEX_A53_MIDR);
125
126 /* power down the CPU cluster */
127 val = FLOWCTRL_TURNOFF_CPURAIL << FLOWCTRL_ENABLE_EXT;
128 tegra_fc_prepare_suspend(cpu, val);
129}
130
131/*******************************************************************************
132 * Suspend the entire SoC
133 ******************************************************************************/
134void tegra_fc_soc_powerdn(uint32_t mpidr)
135{
136 int cpu = mpidr & MPIDR_CPU_MASK;
137 uint32_t val;
138
139 VERBOSE("Entering SoC powerdn state...\n");
140
141 tegra_fc_cc4_ctrl(cpu, 0);
142
143 tegra_fc_write_32(FLOWCTRL_L2_FLUSH_CONTROL, 1);
144
145 val = FLOWCTRL_TURNOFF_CPURAIL << FLOWCTRL_ENABLE_EXT;
146 tegra_fc_prepare_suspend(cpu, val);
147
148 /* overwrite HALT register */
149 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT);
150}
151
152/*******************************************************************************
153 * Power up the CPU
154 ******************************************************************************/
155void tegra_fc_cpu_on(int cpu)
156{
157 tegra_fc_cpu_csr(cpu, FLOWCTRL_CSR_ENABLE);
158 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT | FLOWCTRL_HALT_SCLK);
159}
160
161/*******************************************************************************
162 * Power down the CPU
163 ******************************************************************************/
164void tegra_fc_cpu_off(int cpu)
165{
166 uint32_t val;
167
168 /*
169 * Flow controller powers down the CPU during wfi. The CPU would be
170 * powered on when it receives any interrupt.
171 */
172 val = FLOWCTRL_CSR_INTR_FLAG | FLOWCTRL_CSR_EVENT_FLAG |
173 FLOWCTRL_CSR_ENABLE | (FLOWCTRL_WAIT_WFI_BITMAP << cpu);
174 tegra_fc_cpu_csr(cpu, val);
175 tegra_fc_halt_cpu(cpu, FLOWCTRL_WAITEVENT);
176 tegra_fc_cc4_ctrl(cpu, 0);
177}
178
179/*******************************************************************************
180 * Inform the BPMP that we have completed the cluster power up
181 ******************************************************************************/
182void tegra_fc_lock_active_cluster(void)
183{
184 uint32_t val;
185
186 val = tegra_fc_read_32(FLOWCTRL_BPMP_CLUSTER_CONTROL);
187 val |= FLOWCTRL_BPMP_CLUSTER_PWRON_LOCK;
188 tegra_fc_write_32(FLOWCTRL_BPMP_CLUSTER_CONTROL, val);
189 val = tegra_fc_read_32(FLOWCTRL_BPMP_CLUSTER_CONTROL);
190}
191
192/*******************************************************************************
193 * Reset BPMP processor
194 ******************************************************************************/
195void tegra_fc_reset_bpmp(void)
196{
197 uint32_t val;
198
199 /* halt BPMP */
200 tegra_fc_write_32(FLOWCTRL_HALT_BPMP_EVENTS, FLOWCTRL_WAITEVENT);
201
202 /* Assert BPMP reset */
203 mmio_write_32(TEGRA_CAR_RESET_BASE + CLK_RST_DEV_L_SET, CLK_BPMP_RST);
204
205 /* Restore reset address (stored in PMC_SCRATCH39) */
206 val = tegra_pmc_read_32(PMC_SCRATCH39);
207 mmio_write_32(TEGRA_EVP_BASE + EVP_BPMP_RESET_VECTOR, val);
208 while (val != mmio_read_32(TEGRA_EVP_BASE + EVP_BPMP_RESET_VECTOR))
209 ; /* wait till value reaches EVP_BPMP_RESET_VECTOR */
210
211 /* Wait for 2us before de-asserting the reset signal. */
Varun Wadekar85a90cf2015-07-08 13:46:42 +0530212 udelay(2);
Varun Wadekarb316e242015-05-19 16:48:04 +0530213
214 /* De-assert BPMP reset */
215 mmio_write_32(TEGRA_CAR_RESET_BASE + CLK_RST_DEV_L_CLR, CLK_BPMP_RST);
216
217 /* Un-halt BPMP */
218 tegra_fc_write_32(FLOWCTRL_HALT_BPMP_EVENTS, 0);
219}