blob: a7f41c101fa33cadb79dc9b42d92aeae8e9fc62f [file] [log] [blame]
Varun Wadekar921b9062015-08-25 17:03:14 +05301/*
Varun Wadekarc2c3a2a2016-01-08 17:38:51 -08002 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
Varun Wadekar921b9062015-08-25 17:03:14 +05303 *
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
Varun Wadekarabd153c2015-09-14 09:31:39 +053031#include <arch.h>
32#include <arch_helpers.h>
Varun Wadekara64806a2016-01-05 15:17:41 -080033#include <assert.h>
34#include <bl_common.h>
35#include <context.h>
36#include <context_mgmt.h>
Varun Wadekarabd153c2015-09-14 09:31:39 +053037#include <debug.h>
Varun Wadekar89645092016-02-09 14:55:44 -080038#include <denver.h>
Varun Wadekarabd153c2015-09-14 09:31:39 +053039#include <mce.h>
Varun Wadekar4a0b37a2016-04-09 00:36:42 -070040#include <platform.h>
Varun Wadekar921b9062015-08-25 17:03:14 +053041#include <psci.h>
Varun Wadekarb8776152016-03-03 13:52:52 -080042#include <smmu.h>
Varun Wadekar93bed2a2016-03-18 13:07:33 -070043#include <string.h>
Varun Wadekar782c83d2017-03-14 14:25:35 -070044#include <t18x_ari.h>
Varun Wadekar921b9062015-08-25 17:03:14 +053045#include <tegra_private.h>
46
Varun Wadekard66ee542016-02-29 10:24:30 -080047extern void prepare_cpu_pwr_dwn(void);
Varun Wadekar93bed2a2016-03-18 13:07:33 -070048extern void tegra186_cpu_reset_handler(void);
Varun Wadekar27155fc2017-04-20 18:56:09 -070049extern uint32_t __tegra186_cpu_reset_handler_end,
50 __tegra186_smmu_context;
Varun Wadekard66ee542016-02-29 10:24:30 -080051
Varun Wadekar42236572016-01-18 19:03:19 -080052/* state id mask */
53#define TEGRA186_STATE_ID_MASK 0xF
54/* constants to get power state's wake time */
Krishna Sitaraman86569d12016-08-18 15:41:21 -070055#define TEGRA186_WAKE_TIME_MASK 0x0FFFFFF0
Varun Wadekar42236572016-01-18 19:03:19 -080056#define TEGRA186_WAKE_TIME_SHIFT 4
Varun Wadekar698e7c62016-03-28 15:05:03 -070057/* default core wake mask for CPU_SUSPEND */
58#define TEGRA186_CORE_WAKE_MASK 0x180c
Varun Wadekarb8776152016-03-03 13:52:52 -080059/* context size to save during system suspend */
Varun Wadekar93bed2a2016-03-18 13:07:33 -070060#define TEGRA186_SE_CONTEXT_SIZE 3
Varun Wadekar42236572016-01-18 19:03:19 -080061
Varun Wadekarb8776152016-03-03 13:52:52 -080062static uint32_t se_regs[TEGRA186_SE_CONTEXT_SIZE];
Mustafa Yigit Bilgenf40bc2c2016-09-02 19:30:22 -070063static struct t18x_psci_percpu_data {
64 unsigned int wake_time;
65} __aligned(CACHE_WRITEBACK_GRANULE) percpu_data[PLATFORM_CORE_COUNT];
Varun Wadekar42236572016-01-18 19:03:19 -080066
Varun Wadekard66ee542016-02-29 10:24:30 -080067/* System power down state */
68uint32_t tegra186_system_powerdn_state = TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF;
69
Varun Wadekarc2c3a2a2016-01-08 17:38:51 -080070int32_t tegra_soc_validate_power_state(unsigned int power_state,
71 psci_power_state_t *req_state)
Varun Wadekar921b9062015-08-25 17:03:14 +053072{
Varun Wadekar42236572016-01-18 19:03:19 -080073 int state_id = psci_get_pstate_id(power_state) & TEGRA186_STATE_ID_MASK;
Varun Wadekar4a0b37a2016-04-09 00:36:42 -070074 int cpu = plat_my_core_pos();
Varun Wadekar89645092016-02-09 14:55:44 -080075
Krishna Sitaraman86569d12016-08-18 15:41:21 -070076 /* save the core wake time (in TSC ticks)*/
77 percpu_data[cpu].wake_time = (power_state & TEGRA186_WAKE_TIME_MASK)
78 << TEGRA186_WAKE_TIME_SHIFT;
Varun Wadekar42236572016-01-18 19:03:19 -080079
Mustafa Yigit Bilgenf40bc2c2016-09-02 19:30:22 -070080 /*
81 * Clean percpu_data[cpu] to DRAM. This needs to be done to ensure that
82 * the correct value is read in tegra_soc_pwr_domain_suspend(), which
83 * is called with caches disabled. It is possible to read a stale value
84 * from DRAM in that function, because the L2 cache is not flushed
85 * unless the cluster is entering CC6/CC7.
86 */
87 clean_dcache_range((uint64_t)&percpu_data[cpu],
88 sizeof(percpu_data[cpu]));
89
Varun Wadekar42236572016-01-18 19:03:19 -080090 /* Sanity check the requested state id */
91 switch (state_id) {
92 case PSTATE_ID_CORE_IDLE:
93 case PSTATE_ID_CORE_POWERDN:
Varun Wadekar4a0b37a2016-04-09 00:36:42 -070094
95 /* Core powerdown request */
Varun Wadekar42236572016-01-18 19:03:19 -080096 req_state->pwr_domain_state[MPIDR_AFFLVL0] = state_id;
Varun Wadekar4a0b37a2016-04-09 00:36:42 -070097 req_state->pwr_domain_state[MPIDR_AFFLVL1] = state_id;
Varun Wadekar42236572016-01-18 19:03:19 -080098
99 break;
100
101 default:
102 ERROR("%s: unsupported state id (%d)\n", __func__, state_id);
103 return PSCI_E_INVALID_PARAMS;
104 }
105
106 return PSCI_E_SUCCESS;
107}
108
109int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
110{
111 const plat_local_state_t *pwr_domain_state;
Varun Wadekarb8776152016-03-03 13:52:52 -0800112 unsigned int stateid_afflvl0, stateid_afflvl2;
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700113 int cpu = plat_my_core_pos();
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700114 plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700115 mce_cstate_info_t cstate_info = { 0 };
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700116 uint64_t smmu_ctx_base;
Varun Wadekarb8776152016-03-03 13:52:52 -0800117 uint32_t val;
118
Varun Wadekar42236572016-01-18 19:03:19 -0800119 /* get the state ID */
120 pwr_domain_state = target_state->pwr_domain_state;
121 stateid_afflvl0 = pwr_domain_state[MPIDR_AFFLVL0] &
122 TEGRA186_STATE_ID_MASK;
Varun Wadekarb8776152016-03-03 13:52:52 -0800123 stateid_afflvl2 = pwr_domain_state[PLAT_MAX_PWR_LVL] &
124 TEGRA186_STATE_ID_MASK;
Varun Wadekar42236572016-01-18 19:03:19 -0800125
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700126 if ((stateid_afflvl0 == PSTATE_ID_CORE_IDLE) ||
127 (stateid_afflvl0 == PSTATE_ID_CORE_POWERDN)) {
Varun Wadekar42236572016-01-18 19:03:19 -0800128
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700129 /* Enter CPU idle/powerdown */
130 val = (stateid_afflvl0 == PSTATE_ID_CORE_IDLE) ?
131 TEGRA_ARI_CORE_C6 : TEGRA_ARI_CORE_C7;
132 (void)mce_command_handler(MCE_CMD_ENTER_CSTATE, val,
Mustafa Yigit Bilgenf40bc2c2016-09-02 19:30:22 -0700133 percpu_data[cpu].wake_time, 0);
Varun Wadekarc2c3a2a2016-01-08 17:38:51 -0800134
Varun Wadekarb8776152016-03-03 13:52:52 -0800135 } else if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
136
Varun Wadekarb8776152016-03-03 13:52:52 -0800137 /* save SE registers */
138 se_regs[0] = mmio_read_32(TEGRA_SE0_BASE +
139 SE_MUTEX_WATCHDOG_NS_LIMIT);
140 se_regs[1] = mmio_read_32(TEGRA_RNG1_BASE +
141 RNG_MUTEX_WATCHDOG_NS_LIMIT);
142 se_regs[2] = mmio_read_32(TEGRA_PKA1_BASE +
143 PKA_MUTEX_WATCHDOG_NS_LIMIT);
144
145 /* save 'Secure Boot' Processor Feature Config Register */
146 val = mmio_read_32(TEGRA_MISC_BASE + MISCREG_PFCFG);
147 mmio_write_32(TEGRA_SCRATCH_BASE + SECURE_SCRATCH_RSV6, val);
148
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700149 /* save SMMU context to TZDRAM */
150 smmu_ctx_base = params_from_bl2->tzdram_base +
Varun Wadekar27155fc2017-04-20 18:56:09 -0700151 ((uintptr_t)&__tegra186_smmu_context -
152 (uintptr_t)tegra186_cpu_reset_handler);
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700153 tegra_smmu_save_context((uintptr_t)smmu_ctx_base);
Varun Wadekarb8776152016-03-03 13:52:52 -0800154
155 /* Prepare for system suspend */
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700156 cstate_info.cluster = TEGRA_ARI_CLUSTER_CC7;
157 cstate_info.system = TEGRA_ARI_SYSTEM_SC7;
158 cstate_info.system_state_force = 1;
159 cstate_info.update_wake_mask = 1;
160 mce_update_cstate_info(&cstate_info);
Varun Wadekarb8776152016-03-03 13:52:52 -0800161
Varun Wadekara9002bb2016-03-28 15:11:43 -0700162 /* Loop until system suspend is allowed */
163 do {
164 val = mce_command_handler(MCE_CMD_IS_SC7_ALLOWED,
165 TEGRA_ARI_CORE_C7,
166 MCE_CORE_SLEEP_TIME_INFINITE,
167 0);
168 } while (val == 0);
169
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700170 /* Instruct the MCE to enter system suspend state */
Varun Wadekarb8776152016-03-03 13:52:52 -0800171 (void)mce_command_handler(MCE_CMD_ENTER_CSTATE,
172 TEGRA_ARI_CORE_C7, MCE_CORE_SLEEP_TIME_INFINITE, 0);
Varun Wadekar921b9062015-08-25 17:03:14 +0530173 }
174
175 return PSCI_E_SUCCESS;
176}
Varun Wadekarabd153c2015-09-14 09:31:39 +0530177
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700178/*******************************************************************************
179 * Platform handler to calculate the proper target power level at the
180 * specified affinity level
181 ******************************************************************************/
182plat_local_state_t tegra_soc_get_target_pwr_state(unsigned int lvl,
183 const plat_local_state_t *states,
184 unsigned int ncpu)
185{
186 plat_local_state_t target = *states;
187 int cpu = plat_my_core_pos(), ret, cluster_powerdn = 1;
188 int core_pos = read_mpidr() & MPIDR_CPU_MASK;
189 mce_cstate_info_t cstate_info = { 0 };
190
Varun Wadekar4e49a7b2017-04-06 17:33:31 -0700191 /* get the power state at this level */
192 if (lvl == MPIDR_AFFLVL1)
193 target = *(states + core_pos);
194 if (lvl == MPIDR_AFFLVL2)
195 target = *(states + cpu);
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700196
197 /* CPU suspend */
198 if (lvl == MPIDR_AFFLVL1 && target == PSTATE_ID_CORE_POWERDN) {
199
200 /* Program default wake mask */
201 cstate_info.wake_mask = TEGRA186_CORE_WAKE_MASK;
202 cstate_info.update_wake_mask = 1;
203 mce_update_cstate_info(&cstate_info);
204
205 /* Check if CCx state is allowed. */
206 ret = mce_command_handler(MCE_CMD_IS_CCX_ALLOWED,
Mustafa Yigit Bilgenf40bc2c2016-09-02 19:30:22 -0700207 TEGRA_ARI_CORE_C7, percpu_data[cpu].wake_time,
208 0);
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700209 if (ret)
210 return PSTATE_ID_CORE_POWERDN;
211 }
212
213 /* CPU off */
214 if (lvl == MPIDR_AFFLVL1 && target == PLAT_MAX_OFF_STATE) {
215
216 /* find out the number of ON cpus in the cluster */
217 do {
218 target = *states++;
219 if (target != PLAT_MAX_OFF_STATE)
220 cluster_powerdn = 0;
221 } while (--ncpu);
222
223 /* Enable cluster powerdn from last CPU in the cluster */
224 if (cluster_powerdn) {
225
226 /* Enable CC7 state and turn off wake mask */
227 cstate_info.cluster = TEGRA_ARI_CLUSTER_CC7;
228 cstate_info.update_wake_mask = 1;
229 mce_update_cstate_info(&cstate_info);
230
231 /* Check if CCx state is allowed. */
232 ret = mce_command_handler(MCE_CMD_IS_CCX_ALLOWED,
233 TEGRA_ARI_CORE_C7,
234 MCE_CORE_SLEEP_TIME_INFINITE,
235 0);
236 if (ret)
237 return PSTATE_ID_CORE_POWERDN;
238
239 } else {
240
241 /* Turn off wake_mask */
242 cstate_info.update_wake_mask = 1;
243 mce_update_cstate_info(&cstate_info);
244 }
245 }
246
247 /* System Suspend */
Varun Wadekar4e49a7b2017-04-06 17:33:31 -0700248 if (((lvl == MPIDR_AFFLVL2) || (lvl == MPIDR_AFFLVL1)) &&
249 (target == PSTATE_ID_SOC_POWERDN))
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700250 return PSTATE_ID_SOC_POWERDN;
251
252 /* default state */
253 return PSCI_LOCAL_STATE_RUN;
254}
255
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700256int tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
257{
258 const plat_local_state_t *pwr_domain_state =
259 target_state->pwr_domain_state;
260 plat_params_from_bl2_t *params_from_bl2 = bl31_get_plat_params();
261 unsigned int stateid_afflvl2 = pwr_domain_state[PLAT_MAX_PWR_LVL] &
262 TEGRA186_STATE_ID_MASK;
Steven Kao235e9c32016-12-23 15:43:17 +0800263 uint64_t val;
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700264
265 if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
266 /*
267 * The TZRAM loses power when we enter system suspend. To
268 * allow graceful exit from system suspend, we need to copy
269 * BL3-1 over to TZDRAM.
270 */
271 val = params_from_bl2->tzdram_base +
272 ((uintptr_t)&__tegra186_cpu_reset_handler_end -
273 (uintptr_t)tegra186_cpu_reset_handler);
274 memcpy16((void *)(uintptr_t)val, (void *)(uintptr_t)BL31_BASE,
275 (uintptr_t)&__BL31_END__ - (uintptr_t)BL31_BASE);
276 }
277
278 return PSCI_E_SUCCESS;
279}
280
Varun Wadekarc2c3a2a2016-01-08 17:38:51 -0800281int tegra_soc_pwr_domain_on(u_register_t mpidr)
Varun Wadekarabd153c2015-09-14 09:31:39 +0530282{
283 int target_cpu = mpidr & MPIDR_CPU_MASK;
284 int target_cluster = (mpidr & MPIDR_CLUSTER_MASK) >>
285 MPIDR_AFFINITY_BITS;
286
287 if (target_cluster > MPIDR_AFFLVL1) {
288 ERROR("%s: unsupported CPU (0x%lx)\n", __func__, mpidr);
289 return PSCI_E_NOT_PRESENT;
290 }
291
292 /* construct the target CPU # */
293 target_cpu |= (target_cluster << 2);
294
295 mce_command_handler(MCE_CMD_ONLINE_CORE, target_cpu, 0, 0);
296
297 return PSCI_E_SUCCESS;
298}
299
Varun Wadekarb8776152016-03-03 13:52:52 -0800300int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
301{
Varun Wadekar5a402562016-04-29 11:25:46 -0700302 int stateid_afflvl2 = target_state->pwr_domain_state[PLAT_MAX_PWR_LVL];
303 int stateid_afflvl0 = target_state->pwr_domain_state[MPIDR_AFFLVL0];
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700304 mce_cstate_info_t cstate_info = { 0 };
Varun Wadekarb8776152016-03-03 13:52:52 -0800305
306 /*
Varun Wadekar5a402562016-04-29 11:25:46 -0700307 * Reset power state info for CPUs when onlining, we set
308 * deepest power when offlining a core but that may not be
309 * requested by non-secure sw which controls idle states. It
310 * will re-init this info from non-secure software when the
311 * core come online.
Varun Wadekard2da47a2016-04-09 00:40:45 -0700312 */
Varun Wadekar5a402562016-04-29 11:25:46 -0700313 if (stateid_afflvl0 == PLAT_MAX_OFF_STATE) {
314
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700315 cstate_info.cluster = TEGRA_ARI_CLUSTER_CC1;
316 cstate_info.update_wake_mask = 1;
317 mce_update_cstate_info(&cstate_info);
Varun Wadekar5a402562016-04-29 11:25:46 -0700318 }
Varun Wadekard2da47a2016-04-09 00:40:45 -0700319
320 /*
Varun Wadekarb8776152016-03-03 13:52:52 -0800321 * Check if we are exiting from deep sleep and restore SE
322 * context if we are.
323 */
Varun Wadekar5a402562016-04-29 11:25:46 -0700324 if (stateid_afflvl2 == PSTATE_ID_SOC_POWERDN) {
325
Varun Wadekarb8776152016-03-03 13:52:52 -0800326 mmio_write_32(TEGRA_SE0_BASE + SE_MUTEX_WATCHDOG_NS_LIMIT,
327 se_regs[0]);
328 mmio_write_32(TEGRA_RNG1_BASE + RNG_MUTEX_WATCHDOG_NS_LIMIT,
329 se_regs[1]);
330 mmio_write_32(TEGRA_PKA1_BASE + PKA_MUTEX_WATCHDOG_NS_LIMIT,
331 se_regs[2]);
332
333 /* Init SMMU */
334 tegra_smmu_init();
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700335
336 /*
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700337 * Reset power state info for the last core doing SC7
338 * entry and exit, we set deepest power state as CC7
339 * and SC7 for SC7 entry which may not be requested by
340 * non-secure SW which controls idle states.
Varun Wadekar93bed2a2016-03-18 13:07:33 -0700341 */
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700342 cstate_info.cluster = TEGRA_ARI_CLUSTER_CC7;
343 cstate_info.system = TEGRA_ARI_SYSTEM_SC1;
344 cstate_info.update_wake_mask = 1;
345 mce_update_cstate_info(&cstate_info);
Varun Wadekarb8776152016-03-03 13:52:52 -0800346 }
347
348 return PSCI_E_SUCCESS;
349}
350
Varun Wadekarc2c3a2a2016-01-08 17:38:51 -0800351int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekarabd153c2015-09-14 09:31:39 +0530352{
Varun Wadekare26a55a2016-02-26 11:09:21 -0800353 int impl = (read_midr() >> MIDR_IMPL_SHIFT) & MIDR_IMPL_MASK;
Varun Wadekara64806a2016-01-05 15:17:41 -0800354
Varun Wadekare26a55a2016-02-26 11:09:21 -0800355 /* Disable Denver's DCO operations */
356 if (impl == DENVER_IMPL)
357 denver_disable_dco();
358
Varun Wadekarabd153c2015-09-14 09:31:39 +0530359 /* Turn off CPU */
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700360 (void)mce_command_handler(MCE_CMD_ENTER_CSTATE, TEGRA_ARI_CORE_C7,
Varun Wadekar89645092016-02-09 14:55:44 -0800361 MCE_CORE_SLEEP_TIME_INFINITE, 0);
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700362
363 return PSCI_E_SUCCESS;
Varun Wadekarabd153c2015-09-14 09:31:39 +0530364}
Varun Wadekar782c83d2017-03-14 14:25:35 -0700365
366__dead2 void tegra_soc_prepare_system_off(void)
367{
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700368 mce_cstate_info_t cstate_info = { 0 };
Varun Wadekard66ee542016-02-29 10:24:30 -0800369 uint32_t val;
370
371 if (tegra186_system_powerdn_state == TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_POWER_OFF) {
372
373 /* power off the entire system */
374 mce_enter_ccplex_state(tegra186_system_powerdn_state);
375
376 } else if (tegra186_system_powerdn_state == TEGRA_ARI_SYSTEM_SC8) {
377
Varun Wadekara9002bb2016-03-28 15:11:43 -0700378 /* Prepare for quasi power down */
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700379 cstate_info.cluster = TEGRA_ARI_CLUSTER_CC7;
380 cstate_info.system = TEGRA_ARI_SYSTEM_SC8;
381 cstate_info.system_state_force = 1;
382 cstate_info.update_wake_mask = 1;
383 mce_update_cstate_info(&cstate_info);
Varun Wadekara9002bb2016-03-28 15:11:43 -0700384
Varun Wadekard66ee542016-02-29 10:24:30 -0800385 /* loop until other CPUs power down */
386 do {
387 val = mce_command_handler(MCE_CMD_IS_SC7_ALLOWED,
388 TEGRA_ARI_CORE_C7,
389 MCE_CORE_SLEEP_TIME_INFINITE,
390 0);
391 } while (val == 0);
392
Varun Wadekard66ee542016-02-29 10:24:30 -0800393 /* Enter quasi power down state */
394 (void)mce_command_handler(MCE_CMD_ENTER_CSTATE,
395 TEGRA_ARI_CORE_C7, MCE_CORE_SLEEP_TIME_INFINITE, 0);
396
397 /* disable GICC */
398 tegra_gic_cpuif_deactivate();
399
400 /* power down core */
401 prepare_cpu_pwr_dwn();
402
Varun Wadekar4a0b37a2016-04-09 00:36:42 -0700403 /* flush L1/L2 data caches */
404 dcsw_op_all(DCCISW);
405
Varun Wadekard66ee542016-02-29 10:24:30 -0800406 } else {
407 ERROR("%s: unsupported power down state (%d)\n", __func__,
408 tegra186_system_powerdn_state);
409 }
410
411 wfi();
412
413 /* wait for the system to power down */
414 for (;;) {
415 ;
416 }
Varun Wadekar782c83d2017-03-14 14:25:35 -0700417}
Varun Wadekar38020c92016-01-07 14:36:12 -0800418
419int tegra_soc_prepare_system_reset(void)
420{
421 mce_enter_ccplex_state(TEGRA_ARI_MISC_CCPLEX_SHUTDOWN_REBOOT);
422
423 return PSCI_E_SUCCESS;
424}