blob: 8ba02d6f5652275900241444d5cfc3c7344b4567 [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
Varun Wadekar84a775e2019-01-03 10:12:55 -08002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Varun Wadekarb316e242015-05-19 16:48:04 +05303 *
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 <platform_def.h>
10
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053014#include <context.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <drivers/console.h>
16#include <lib/el3_runtime/context_mgmt.h>
17#include <lib/mmio.h>
18#include <lib/psci/psci.h>
19#include <plat/common/platform.h>
20
Varun Wadekarb316e242015-05-19 16:48:04 +053021#include <memctrl.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053022#include <pmc.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053023#include <tegra_def.h>
Harvey Hsieh9e083c72017-04-10 16:20:32 +080024#include <tegra_platform.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053025#include <tegra_private.h>
26
27extern uint64_t tegra_bl31_phys_base;
Varun Wadekara78bb1b2015-08-07 10:03:00 +053028extern uint64_t tegra_sec_entry_point;
Varun Wadekarb316e242015-05-19 16:48:04 +053029
30/*
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -080031 * tegra_fake_system_suspend acts as a boolean var controlling whether
32 * we are going to take fake system suspend code or normal system suspend code
33 * path. This variable is set inside the sip call handlers,when the kernel
34 * requests a SIP call to set the suspend debug flags.
35 */
36uint8_t tegra_fake_system_suspend;
37
38/*
Varun Wadekarb316e242015-05-19 16:48:04 +053039 * The following platform setup functions are weakly defined. They
40 * provide typical implementations that will be overridden by a SoC.
41 */
Varun Wadekar99782e82017-07-05 17:44:12 -070042#pragma weak tegra_soc_pwr_domain_suspend_pwrdown_early
Varun Wadekarb3421ce2017-12-27 18:10:12 -080043#pragma weak tegra_soc_cpu_standby
Varun Wadekara78bb1b2015-08-07 10:03:00 +053044#pragma weak tegra_soc_pwr_domain_suspend
45#pragma weak tegra_soc_pwr_domain_on
46#pragma weak tegra_soc_pwr_domain_off
47#pragma weak tegra_soc_pwr_domain_on_finish
Varun Wadekard22429d2016-03-18 14:35:28 -070048#pragma weak tegra_soc_pwr_domain_power_down_wfi
Varun Wadekar8b82fae2015-11-09 17:39:28 -080049#pragma weak tegra_soc_prepare_system_reset
Varun Wadekare5caeed2016-01-07 14:04:21 -080050#pragma weak tegra_soc_prepare_system_off
Varun Wadekarf2aa1be2016-06-07 12:00:06 -070051#pragma weak tegra_soc_get_target_pwr_state
Varun Wadekarb316e242015-05-19 16:48:04 +053052
Anthony Zhou85a8fa02017-03-22 14:42:42 +080053int32_t tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
Varun Wadekar99782e82017-07-05 17:44:12 -070054{
55 return PSCI_E_NOT_SUPPORTED;
56}
57
Varun Wadekarb3421ce2017-12-27 18:10:12 -080058int32_t tegra_soc_cpu_standby(plat_local_state_t cpu_state)
59{
60 (void)cpu_state;
61 return PSCI_E_SUCCESS;
62}
63
Anthony Zhou85a8fa02017-03-22 14:42:42 +080064int32_t tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +053065{
Anthony Zhou85a8fa02017-03-22 14:42:42 +080066 (void)target_state;
Varun Wadekarb316e242015-05-19 16:48:04 +053067 return PSCI_E_NOT_SUPPORTED;
68}
69
Anthony Zhou85a8fa02017-03-22 14:42:42 +080070int32_t tegra_soc_pwr_domain_on(u_register_t mpidr)
Varun Wadekarb316e242015-05-19 16:48:04 +053071{
Anthony Zhou85a8fa02017-03-22 14:42:42 +080072 (void)mpidr;
Varun Wadekarb316e242015-05-19 16:48:04 +053073 return PSCI_E_SUCCESS;
74}
75
Anthony Zhou85a8fa02017-03-22 14:42:42 +080076int32_t tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +053077{
Anthony Zhou85a8fa02017-03-22 14:42:42 +080078 (void)target_state;
Varun Wadekarb316e242015-05-19 16:48:04 +053079 return PSCI_E_SUCCESS;
80}
81
Anthony Zhou85a8fa02017-03-22 14:42:42 +080082int32_t tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +053083{
Anthony Zhou85a8fa02017-03-22 14:42:42 +080084 (void)target_state;
Varun Wadekarb316e242015-05-19 16:48:04 +053085 return PSCI_E_SUCCESS;
86}
87
Anthony Zhou85a8fa02017-03-22 14:42:42 +080088int32_t tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
Varun Wadekard22429d2016-03-18 14:35:28 -070089{
Anthony Zhou85a8fa02017-03-22 14:42:42 +080090 (void)target_state;
Varun Wadekard22429d2016-03-18 14:35:28 -070091 return PSCI_E_SUCCESS;
92}
93
Anthony Zhou85a8fa02017-03-22 14:42:42 +080094int32_t tegra_soc_prepare_system_reset(void)
Varun Wadekar8b82fae2015-11-09 17:39:28 -080095{
96 return PSCI_E_SUCCESS;
97}
98
Varun Wadekare5caeed2016-01-07 14:04:21 -080099__dead2 void tegra_soc_prepare_system_off(void)
100{
101 ERROR("Tegra System Off: operation not handled.\n");
102 panic();
103}
104
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800105plat_local_state_t tegra_soc_get_target_pwr_state(uint32_t lvl,
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700106 const plat_local_state_t *states,
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800107 uint32_t ncpu)
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700108{
Varun Wadekar14eaede2016-09-01 14:51:59 -0700109 plat_local_state_t target = PLAT_MAX_OFF_STATE, temp;
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800110 uint32_t num_cpu = ncpu;
111 const plat_local_state_t *local_state = states;
112
113 (void)lvl;
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700114
Anthony Zhou4408e882017-07-07 14:29:51 +0800115 assert(ncpu != 0U);
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700116
117 do {
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800118 temp = *local_state;
119 if ((temp < target)) {
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700120 target = temp;
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800121 }
122 --num_cpu;
123 local_state++;
124 } while (num_cpu != 0U);
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700125
126 return target;
127}
128
Varun Wadekarb316e242015-05-19 16:48:04 +0530129/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530130 * This handler is called by the PSCI implementation during the `SYSTEM_SUSPEND`
131 * call to get the `power_state` parameter. This allows the platform to encode
132 * the appropriate State-ID field within the `power_state` parameter which can
133 * be utilized in `pwr_domain_suspend()` to suspend to system affinity level.
134******************************************************************************/
135void tegra_get_sys_suspend_power_state(psci_power_state_t *req_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530136{
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700137 /* all affinities use system suspend state id */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800138 for (uint32_t i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) {
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700139 req_state->pwr_domain_state[i] = PSTATE_ID_SOC_POWERDN;
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800140 }
Varun Wadekarb316e242015-05-19 16:48:04 +0530141}
142
143/*******************************************************************************
144 * Handler called when an affinity instance is about to enter standby.
145 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530146void tegra_cpu_standby(plat_local_state_t cpu_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530147{
Vignesh Radhakrishnan16d82ae2018-04-20 14:31:41 -0700148 u_register_t saved_scr_el3;
149
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800150 (void)cpu_state;
151
Varun Wadekarb3421ce2017-12-27 18:10:12 -0800152 /* Tegra SoC specific handler */
153 if (tegra_soc_cpu_standby(cpu_state) != PSCI_E_SUCCESS)
154 ERROR("%s failed\n", __func__);
155
Vignesh Radhakrishnan16d82ae2018-04-20 14:31:41 -0700156 saved_scr_el3 = read_scr_el3();
157
158 /*
159 * As per ARM ARM D1.17.2, any physical IRQ interrupt received by the
160 * PE will be treated as a wake-up event, if SCR_EL3.IRQ is set to '1',
161 * irrespective of the value of the PSTATE.I bit value.
162 */
163 write_scr_el3(saved_scr_el3 | SCR_IRQ_BIT);
164
Varun Wadekarb316e242015-05-19 16:48:04 +0530165 /*
166 * Enter standby state
Vignesh Radhakrishnan16d82ae2018-04-20 14:31:41 -0700167 *
168 * dsb & isb is good practice before using wfi to enter low power states
Varun Wadekarb316e242015-05-19 16:48:04 +0530169 */
170 dsb();
Vignesh Radhakrishnan16d82ae2018-04-20 14:31:41 -0700171 isb();
Varun Wadekarb316e242015-05-19 16:48:04 +0530172 wfi();
Vignesh Radhakrishnan16d82ae2018-04-20 14:31:41 -0700173
174 /*
175 * Restore saved scr_el3 that has IRQ bit cleared as we don't want EL3
176 * handling any further interrupts
177 */
178 write_scr_el3(saved_scr_el3);
Varun Wadekarb316e242015-05-19 16:48:04 +0530179}
180
181/*******************************************************************************
Varun Wadekarb316e242015-05-19 16:48:04 +0530182 * Handler called when an affinity instance is about to be turned on. The
183 * level and mpidr determine the affinity instance.
184 ******************************************************************************/
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800185int32_t tegra_pwr_domain_on(u_register_t mpidr)
Varun Wadekarb316e242015-05-19 16:48:04 +0530186{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530187 return tegra_soc_pwr_domain_on(mpidr);
Varun Wadekarb316e242015-05-19 16:48:04 +0530188}
189
190/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530191 * Handler called when a power domain is about to be turned off. The
192 * target_state encodes the power state that each level should transition to.
Varun Wadekarb316e242015-05-19 16:48:04 +0530193 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530194void tegra_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530195{
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800196 (void)tegra_soc_pwr_domain_off(target_state);
Varun Wadekarb316e242015-05-19 16:48:04 +0530197}
198
199/*******************************************************************************
Varun Wadekard22429d2016-03-18 14:35:28 -0700200 * Handler called when a power domain is about to be suspended. The
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530201 * target_state encodes the power state that each level should transition to.
Varun Wadekar99782e82017-07-05 17:44:12 -0700202 * This handler is called with SMP and data cache enabled, when
203 * HW_ASSISTED_COHERENCY = 0
204 ******************************************************************************/
205void tegra_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
206{
207 tegra_soc_pwr_domain_suspend_pwrdown_early(target_state);
208}
209
210/*******************************************************************************
211 * Handler called when a power domain is about to be suspended. The
212 * target_state encodes the power state that each level should transition to.
Varun Wadekarb316e242015-05-19 16:48:04 +0530213 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530214void tegra_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530215{
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800216 (void)tegra_soc_pwr_domain_suspend(target_state);
Varun Wadekarb316e242015-05-19 16:48:04 +0530217
Varun Wadekara2c6be62016-08-01 22:16:21 -0700218 /* Disable console if we are entering deep sleep. */
219 if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] ==
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800220 PSTATE_ID_SOC_POWERDN) {
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100221 (void)console_flush();
222 console_switch_state(0);
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800223 }
Varun Wadekara2c6be62016-08-01 22:16:21 -0700224
Varun Wadekarb316e242015-05-19 16:48:04 +0530225 /* disable GICC */
226 tegra_gic_cpuif_deactivate();
227}
228
229/*******************************************************************************
Varun Wadekard22429d2016-03-18 14:35:28 -0700230 * Handler called at the end of the power domain suspend sequence. The
231 * target_state encodes the power state that each level should transition to.
232 ******************************************************************************/
233__dead2 void tegra_pwr_domain_power_down_wfi(const psci_power_state_t
234 *target_state)
235{
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800236 uint8_t pwr_state = target_state->pwr_domain_state[PLAT_MAX_PWR_LVL];
237 uint64_t rmr_el3 = 0;
238
Varun Wadekard22429d2016-03-18 14:35:28 -0700239 /* call the chip's power down handler */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800240 (void)tegra_soc_pwr_domain_power_down_wfi(target_state);
Varun Wadekard22429d2016-03-18 14:35:28 -0700241
Vignesh Radhakrishnanb4a72942017-03-03 10:58:05 -0800242 /*
243 * If we are in fake system suspend mode, ensure we start doing
244 * procedures that help in looping back towards system suspend exit
245 * instead of calling WFI by requesting a warm reset.
246 * Else, just call WFI to enter low power state.
247 */
248 if ((tegra_fake_system_suspend != 0U) &&
249 (pwr_state == (uint8_t)PSTATE_ID_SOC_POWERDN)) {
250
251 /* warm reboot */
252 rmr_el3 = read_rmr_el3();
253 write_rmr_el3(rmr_el3 | RMR_WARM_RESET_CPU);
254
255 } else {
256 /* enter power down state */
257 wfi();
258 }
Varun Wadekard22429d2016-03-18 14:35:28 -0700259
260 /* we can never reach here */
Varun Wadekard22429d2016-03-18 14:35:28 -0700261 panic();
262}
263
264/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530265 * Handler called when a power domain has just been powered on after
266 * being turned off earlier. The target_state encodes the low power state that
267 * each level has woken up from.
Varun Wadekarb316e242015-05-19 16:48:04 +0530268 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530269void tegra_pwr_domain_on_finish(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530270{
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800271 const plat_params_from_bl2_t *plat_params;
Varun Wadekarb316e242015-05-19 16:48:04 +0530272
273 /*
Varun Wadekarb316e242015-05-19 16:48:04 +0530274 * Initialize the GIC cpu and distributor interfaces
275 */
Varun Wadekar84a775e2019-01-03 10:12:55 -0800276 tegra_gic_init();
Varun Wadekarb316e242015-05-19 16:48:04 +0530277
278 /*
279 * Check if we are exiting from deep sleep.
280 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530281 if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] ==
282 PSTATE_ID_SOC_POWERDN) {
Varun Wadekarb316e242015-05-19 16:48:04 +0530283
Ambroise Vincent09a22e72019-05-29 14:04:16 +0100284 /* Restart console output. */
285 console_switch_state(CONSOLE_FLAG_RUNTIME);
Varun Wadekara2c6be62016-08-01 22:16:21 -0700286
Varun Wadekarb316e242015-05-19 16:48:04 +0530287 /*
Varun Wadekar6eec6d62016-03-03 13:28:10 -0800288 * Restore Memory Controller settings as it loses state
289 * during system suspend.
Varun Wadekarb316e242015-05-19 16:48:04 +0530290 */
Varun Wadekar6eec6d62016-03-03 13:28:10 -0800291 tegra_memctrl_restore_settings();
Varun Wadekarb316e242015-05-19 16:48:04 +0530292
293 /*
294 * Security configuration to allow DRAM/device access.
295 */
296 plat_params = bl31_get_plat_params();
Varun Wadekar6bb62462015-10-06 12:49:31 +0530297 tegra_memctrl_tzdram_setup(plat_params->tzdram_base,
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800298 (uint32_t)plat_params->tzdram_size);
Varun Wadekard5f578a2016-06-01 19:34:37 -0700299
300 /*
301 * Set up the TZRAM memory aperture to allow only secure world
302 * access
303 */
304 tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE);
Varun Wadekarb316e242015-05-19 16:48:04 +0530305 }
306
307 /*
308 * Reset hardware settings.
309 */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800310 (void)tegra_soc_pwr_domain_on_finish(target_state);
Varun Wadekarb316e242015-05-19 16:48:04 +0530311}
312
313/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530314 * Handler called when a power domain has just been powered on after
315 * having been suspended earlier. The target_state encodes the low power state
316 * that each level has woken up from.
Varun Wadekarb316e242015-05-19 16:48:04 +0530317 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530318void tegra_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
Varun Wadekarb316e242015-05-19 16:48:04 +0530319{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530320 tegra_pwr_domain_on_finish(target_state);
Varun Wadekarb316e242015-05-19 16:48:04 +0530321}
322
323/*******************************************************************************
324 * Handler called when the system wants to be powered off
325 ******************************************************************************/
326__dead2 void tegra_system_off(void)
327{
Varun Wadekare5caeed2016-01-07 14:04:21 -0800328 INFO("Powering down system...\n");
329
330 tegra_soc_prepare_system_off();
Varun Wadekarb316e242015-05-19 16:48:04 +0530331}
332
333/*******************************************************************************
334 * Handler called when the system wants to be restarted.
335 ******************************************************************************/
336__dead2 void tegra_system_reset(void)
337{
Varun Wadekare5caeed2016-01-07 14:04:21 -0800338 INFO("Restarting system...\n");
339
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800340 /* per-SoC system reset handler */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800341 (void)tegra_soc_prepare_system_reset();
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800342
Varun Wadekarb316e242015-05-19 16:48:04 +0530343 /*
344 * Program the PMC in order to restart the system.
345 */
346 tegra_pmc_system_reset();
347}
348
349/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530350 * Handler called to check the validity of the power state parameter.
351 ******************************************************************************/
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800352int32_t tegra_validate_power_state(uint32_t power_state,
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530353 psci_power_state_t *req_state)
354{
Anthony Zhou4408e882017-07-07 14:29:51 +0800355 assert(req_state != NULL);
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530356
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530357 return tegra_soc_validate_power_state(power_state, req_state);
358}
359
360/*******************************************************************************
361 * Platform handler called to check the validity of the non secure entrypoint.
362 ******************************************************************************/
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800363int32_t tegra_validate_ns_entrypoint(uintptr_t entrypoint)
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530364{
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800365 int32_t ret = PSCI_E_INVALID_ADDRESS;
366
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530367 /*
368 * Check if the non secure entrypoint lies within the non
369 * secure DRAM.
370 */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800371 if ((entrypoint >= TEGRA_DRAM_BASE) && (entrypoint <= TEGRA_DRAM_END)) {
372 ret = PSCI_E_SUCCESS;
373 }
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530374
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800375 return ret;
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530376}
377
378/*******************************************************************************
Varun Wadekarb316e242015-05-19 16:48:04 +0530379 * Export the platform handlers to enable psci to invoke them
380 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530381static const plat_psci_ops_t tegra_plat_psci_ops = {
382 .cpu_standby = tegra_cpu_standby,
383 .pwr_domain_on = tegra_pwr_domain_on,
384 .pwr_domain_off = tegra_pwr_domain_off,
Varun Wadekar99782e82017-07-05 17:44:12 -0700385 .pwr_domain_suspend_pwrdown_early = tegra_pwr_domain_suspend_pwrdown_early,
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530386 .pwr_domain_suspend = tegra_pwr_domain_suspend,
387 .pwr_domain_on_finish = tegra_pwr_domain_on_finish,
388 .pwr_domain_suspend_finish = tegra_pwr_domain_suspend_finish,
Varun Wadekard22429d2016-03-18 14:35:28 -0700389 .pwr_domain_pwr_down_wfi = tegra_pwr_domain_power_down_wfi,
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530390 .system_off = tegra_system_off,
391 .system_reset = tegra_system_reset,
392 .validate_power_state = tegra_validate_power_state,
393 .validate_ns_entrypoint = tegra_validate_ns_entrypoint,
394 .get_sys_suspend_power_state = tegra_get_sys_suspend_power_state,
Varun Wadekarb316e242015-05-19 16:48:04 +0530395};
396
397/*******************************************************************************
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530398 * Export the platform specific power ops and initialize Power Controller
Varun Wadekarb316e242015-05-19 16:48:04 +0530399 ******************************************************************************/
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530400int plat_setup_psci_ops(uintptr_t sec_entrypoint,
401 const plat_psci_ops_t **psci_ops)
Varun Wadekarb316e242015-05-19 16:48:04 +0530402{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530403 psci_power_state_t target_state = { { PSCI_LOCAL_STATE_RUN } };
404
405 /*
406 * Flush entrypoint variable to PoC since it will be
407 * accessed after a reset with the caches turned off.
408 */
409 tegra_sec_entry_point = sec_entrypoint;
410 flush_dcache_range((uint64_t)&tegra_sec_entry_point, sizeof(uint64_t));
411
Varun Wadekarb316e242015-05-19 16:48:04 +0530412 /*
413 * Reset hardware settings.
414 */
Anthony Zhou85a8fa02017-03-22 14:42:42 +0800415 (void)tegra_soc_pwr_domain_on_finish(&target_state);
Varun Wadekarb316e242015-05-19 16:48:04 +0530416
417 /*
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530418 * Initialize PSCI ops struct
Varun Wadekarb316e242015-05-19 16:48:04 +0530419 */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530420 *psci_ops = &tegra_plat_psci_ops;
Varun Wadekarb316e242015-05-19 16:48:04 +0530421
422 return 0;
423}
Varun Wadekar24975392016-05-05 14:13:30 -0700424
425/*******************************************************************************
426 * Platform handler to calculate the proper target power level at the
427 * specified affinity level
428 ******************************************************************************/
429plat_local_state_t plat_get_target_pwr_state(unsigned int lvl,
430 const plat_local_state_t *states,
431 unsigned int ncpu)
432{
Varun Wadekarf2aa1be2016-06-07 12:00:06 -0700433 return tegra_soc_get_target_pwr_state(lvl, states, ncpu);
Varun Wadekar24975392016-05-05 14:13:30 -0700434}