108438e24SVarun Wadekar /* 2a9e0260cSVignesh Radhakrishnan * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. 308438e24SVarun Wadekar * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 508438e24SVarun Wadekar */ 608438e24SVarun Wadekar 708438e24SVarun Wadekar #include <assert.h> 809d40e0eSAntonio Nino Diaz 908438e24SVarun Wadekar #include <platform_def.h> 1009d40e0eSAntonio Nino Diaz 1109d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 1209d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1309d40e0eSAntonio Nino Diaz #include <common/debug.h> 1409d40e0eSAntonio Nino Diaz #include <context.h> 1509d40e0eSAntonio Nino Diaz #include <drivers/console.h> 1609d40e0eSAntonio Nino Diaz #include <lib/el3_runtime/context_mgmt.h> 1709d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 1809d40e0eSAntonio Nino Diaz #include <lib/psci/psci.h> 1909d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 2009d40e0eSAntonio Nino Diaz 2109d40e0eSAntonio Nino Diaz #include <memctrl.h> 2208438e24SVarun Wadekar #include <pmc.h> 2308438e24SVarun Wadekar #include <tegra_def.h> 24322e7c3eSHarvey Hsieh #include <tegra_platform.h> 2508438e24SVarun Wadekar #include <tegra_private.h> 2608438e24SVarun Wadekar 2708438e24SVarun Wadekar extern uint64_t tegra_bl31_phys_base; 2871cb26eaSVarun Wadekar extern uint64_t tegra_sec_entry_point; 295b5928e8SVarun Wadekar extern uint64_t tegra_console_base; 3008438e24SVarun Wadekar 3108438e24SVarun Wadekar /* 32a9e0260cSVignesh Radhakrishnan * tegra_fake_system_suspend acts as a boolean var controlling whether 33a9e0260cSVignesh Radhakrishnan * we are going to take fake system suspend code or normal system suspend code 34a9e0260cSVignesh Radhakrishnan * path. This variable is set inside the sip call handlers,when the kernel 35a9e0260cSVignesh Radhakrishnan * requests a SIP call to set the suspend debug flags. 36a9e0260cSVignesh Radhakrishnan */ 37a9e0260cSVignesh Radhakrishnan uint8_t tegra_fake_system_suspend; 38a9e0260cSVignesh Radhakrishnan 39a9e0260cSVignesh Radhakrishnan /* 4008438e24SVarun Wadekar * The following platform setup functions are weakly defined. They 4108438e24SVarun Wadekar * provide typical implementations that will be overridden by a SoC. 4208438e24SVarun Wadekar */ 43cb95a19aSVarun Wadekar #pragma weak tegra_soc_pwr_domain_suspend_pwrdown_early 44*0887026eSVarun Wadekar #pragma weak tegra_soc_cpu_standby 4571cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_suspend 4671cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_on 4771cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_off 4871cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_on_finish 4926c0d9b2SVarun Wadekar #pragma weak tegra_soc_pwr_domain_power_down_wfi 503b40f993SVarun Wadekar #pragma weak tegra_soc_prepare_system_reset 5131a4957cSVarun Wadekar #pragma weak tegra_soc_prepare_system_off 52a7cd0953SVarun Wadekar #pragma weak tegra_soc_get_target_pwr_state 5308438e24SVarun Wadekar 54b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state) 55cb95a19aSVarun Wadekar { 56cb95a19aSVarun Wadekar return PSCI_E_NOT_SUPPORTED; 57cb95a19aSVarun Wadekar } 58cb95a19aSVarun Wadekar 59*0887026eSVarun Wadekar int32_t tegra_soc_cpu_standby(plat_local_state_t cpu_state) 60*0887026eSVarun Wadekar { 61*0887026eSVarun Wadekar (void)cpu_state; 62*0887026eSVarun Wadekar return PSCI_E_SUCCESS; 63*0887026eSVarun Wadekar } 64*0887026eSVarun Wadekar 65b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state) 6608438e24SVarun Wadekar { 67b36aea5aSAnthony Zhou (void)target_state; 6808438e24SVarun Wadekar return PSCI_E_NOT_SUPPORTED; 6908438e24SVarun Wadekar } 7008438e24SVarun Wadekar 71b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_on(u_register_t mpidr) 7208438e24SVarun Wadekar { 73b36aea5aSAnthony Zhou (void)mpidr; 7408438e24SVarun Wadekar return PSCI_E_SUCCESS; 7508438e24SVarun Wadekar } 7608438e24SVarun Wadekar 77b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_off(const psci_power_state_t *target_state) 7808438e24SVarun Wadekar { 79b36aea5aSAnthony Zhou (void)target_state; 8008438e24SVarun Wadekar return PSCI_E_SUCCESS; 8108438e24SVarun Wadekar } 8208438e24SVarun Wadekar 83b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state) 8408438e24SVarun Wadekar { 85b36aea5aSAnthony Zhou (void)target_state; 8608438e24SVarun Wadekar return PSCI_E_SUCCESS; 8708438e24SVarun Wadekar } 8808438e24SVarun Wadekar 89b36aea5aSAnthony Zhou int32_t tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state) 9026c0d9b2SVarun Wadekar { 91b36aea5aSAnthony Zhou (void)target_state; 9226c0d9b2SVarun Wadekar return PSCI_E_SUCCESS; 9326c0d9b2SVarun Wadekar } 9426c0d9b2SVarun Wadekar 95b36aea5aSAnthony Zhou int32_t tegra_soc_prepare_system_reset(void) 963b40f993SVarun Wadekar { 973b40f993SVarun Wadekar return PSCI_E_SUCCESS; 983b40f993SVarun Wadekar } 993b40f993SVarun Wadekar 10031a4957cSVarun Wadekar __dead2 void tegra_soc_prepare_system_off(void) 10131a4957cSVarun Wadekar { 10231a4957cSVarun Wadekar ERROR("Tegra System Off: operation not handled.\n"); 10331a4957cSVarun Wadekar panic(); 10431a4957cSVarun Wadekar } 10531a4957cSVarun Wadekar 106b36aea5aSAnthony Zhou plat_local_state_t tegra_soc_get_target_pwr_state(uint32_t lvl, 107a7cd0953SVarun Wadekar const plat_local_state_t *states, 108b36aea5aSAnthony Zhou uint32_t ncpu) 109a7cd0953SVarun Wadekar { 1108539f45dSVarun Wadekar plat_local_state_t target = PLAT_MAX_OFF_STATE, temp; 111b36aea5aSAnthony Zhou uint32_t num_cpu = ncpu; 112b36aea5aSAnthony Zhou const plat_local_state_t *local_state = states; 113b36aea5aSAnthony Zhou 114b36aea5aSAnthony Zhou (void)lvl; 115a7cd0953SVarun Wadekar 1164c994002SAnthony Zhou assert(ncpu != 0U); 117a7cd0953SVarun Wadekar 118a7cd0953SVarun Wadekar do { 119b36aea5aSAnthony Zhou temp = *local_state; 120b36aea5aSAnthony Zhou if ((temp < target)) { 121a7cd0953SVarun Wadekar target = temp; 122b36aea5aSAnthony Zhou } 123b36aea5aSAnthony Zhou --num_cpu; 124b36aea5aSAnthony Zhou local_state++; 125b36aea5aSAnthony Zhou } while (num_cpu != 0U); 126a7cd0953SVarun Wadekar 127a7cd0953SVarun Wadekar return target; 128a7cd0953SVarun Wadekar } 129a7cd0953SVarun Wadekar 13008438e24SVarun Wadekar /******************************************************************************* 13171cb26eaSVarun Wadekar * This handler is called by the PSCI implementation during the `SYSTEM_SUSPEND` 13271cb26eaSVarun Wadekar * call to get the `power_state` parameter. This allows the platform to encode 13371cb26eaSVarun Wadekar * the appropriate State-ID field within the `power_state` parameter which can 13471cb26eaSVarun Wadekar * be utilized in `pwr_domain_suspend()` to suspend to system affinity level. 13508438e24SVarun Wadekar ******************************************************************************/ 13671cb26eaSVarun Wadekar void tegra_get_sys_suspend_power_state(psci_power_state_t *req_state) 13708438e24SVarun Wadekar { 138a7cd0953SVarun Wadekar /* all affinities use system suspend state id */ 139b36aea5aSAnthony Zhou for (uint32_t i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++) { 140a7cd0953SVarun Wadekar req_state->pwr_domain_state[i] = PSTATE_ID_SOC_POWERDN; 14108438e24SVarun Wadekar } 142b36aea5aSAnthony Zhou } 14308438e24SVarun Wadekar 14408438e24SVarun Wadekar /******************************************************************************* 14508438e24SVarun Wadekar * Handler called when an affinity instance is about to enter standby. 14608438e24SVarun Wadekar ******************************************************************************/ 14771cb26eaSVarun Wadekar void tegra_cpu_standby(plat_local_state_t cpu_state) 14808438e24SVarun Wadekar { 149b36aea5aSAnthony Zhou (void)cpu_state; 150b36aea5aSAnthony Zhou 151*0887026eSVarun Wadekar /* Tegra SoC specific handler */ 152*0887026eSVarun Wadekar if (tegra_soc_cpu_standby(cpu_state) != PSCI_E_SUCCESS) 153*0887026eSVarun Wadekar ERROR("%s failed\n", __func__); 154*0887026eSVarun Wadekar 15508438e24SVarun Wadekar /* 15608438e24SVarun Wadekar * Enter standby state 15708438e24SVarun Wadekar * dsb is good practice before using wfi to enter low power states 15808438e24SVarun Wadekar */ 15908438e24SVarun Wadekar dsb(); 16008438e24SVarun Wadekar wfi(); 16108438e24SVarun Wadekar } 16208438e24SVarun Wadekar 16308438e24SVarun Wadekar /******************************************************************************* 16408438e24SVarun Wadekar * Handler called when an affinity instance is about to be turned on. The 16508438e24SVarun Wadekar * level and mpidr determine the affinity instance. 16608438e24SVarun Wadekar ******************************************************************************/ 167b36aea5aSAnthony Zhou int32_t tegra_pwr_domain_on(u_register_t mpidr) 16808438e24SVarun Wadekar { 16971cb26eaSVarun Wadekar return tegra_soc_pwr_domain_on(mpidr); 17008438e24SVarun Wadekar } 17108438e24SVarun Wadekar 17208438e24SVarun Wadekar /******************************************************************************* 17371cb26eaSVarun Wadekar * Handler called when a power domain is about to be turned off. The 17471cb26eaSVarun Wadekar * target_state encodes the power state that each level should transition to. 17508438e24SVarun Wadekar ******************************************************************************/ 17671cb26eaSVarun Wadekar void tegra_pwr_domain_off(const psci_power_state_t *target_state) 17708438e24SVarun Wadekar { 178b36aea5aSAnthony Zhou (void)tegra_soc_pwr_domain_off(target_state); 17908438e24SVarun Wadekar } 18008438e24SVarun Wadekar 18108438e24SVarun Wadekar /******************************************************************************* 18226c0d9b2SVarun Wadekar * Handler called when a power domain is about to be suspended. The 18371cb26eaSVarun Wadekar * target_state encodes the power state that each level should transition to. 184cb95a19aSVarun Wadekar * This handler is called with SMP and data cache enabled, when 185cb95a19aSVarun Wadekar * HW_ASSISTED_COHERENCY = 0 186cb95a19aSVarun Wadekar ******************************************************************************/ 187cb95a19aSVarun Wadekar void tegra_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state) 188cb95a19aSVarun Wadekar { 189cb95a19aSVarun Wadekar tegra_soc_pwr_domain_suspend_pwrdown_early(target_state); 190cb95a19aSVarun Wadekar } 191cb95a19aSVarun Wadekar 192cb95a19aSVarun Wadekar /******************************************************************************* 193cb95a19aSVarun Wadekar * Handler called when a power domain is about to be suspended. The 194cb95a19aSVarun Wadekar * target_state encodes the power state that each level should transition to. 19508438e24SVarun Wadekar ******************************************************************************/ 19671cb26eaSVarun Wadekar void tegra_pwr_domain_suspend(const psci_power_state_t *target_state) 19708438e24SVarun Wadekar { 198b36aea5aSAnthony Zhou (void)tegra_soc_pwr_domain_suspend(target_state); 19908438e24SVarun Wadekar 2005b5928e8SVarun Wadekar /* Disable console if we are entering deep sleep. */ 2015b5928e8SVarun Wadekar if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] == 202b36aea5aSAnthony Zhou PSTATE_ID_SOC_POWERDN) { 203b36aea5aSAnthony Zhou (void)console_uninit(); 204b36aea5aSAnthony Zhou } 2055b5928e8SVarun Wadekar 20608438e24SVarun Wadekar /* disable GICC */ 20708438e24SVarun Wadekar tegra_gic_cpuif_deactivate(); 20808438e24SVarun Wadekar } 20908438e24SVarun Wadekar 21008438e24SVarun Wadekar /******************************************************************************* 21126c0d9b2SVarun Wadekar * Handler called at the end of the power domain suspend sequence. The 21226c0d9b2SVarun Wadekar * target_state encodes the power state that each level should transition to. 21326c0d9b2SVarun Wadekar ******************************************************************************/ 21426c0d9b2SVarun Wadekar __dead2 void tegra_pwr_domain_power_down_wfi(const psci_power_state_t 21526c0d9b2SVarun Wadekar *target_state) 21626c0d9b2SVarun Wadekar { 217a9e0260cSVignesh Radhakrishnan uint8_t pwr_state = target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]; 218a9e0260cSVignesh Radhakrishnan uint64_t rmr_el3 = 0; 219a9e0260cSVignesh Radhakrishnan 22026c0d9b2SVarun Wadekar /* call the chip's power down handler */ 221b36aea5aSAnthony Zhou (void)tegra_soc_pwr_domain_power_down_wfi(target_state); 22226c0d9b2SVarun Wadekar 223a9e0260cSVignesh Radhakrishnan /* 224a9e0260cSVignesh Radhakrishnan * If we are in fake system suspend mode, ensure we start doing 225a9e0260cSVignesh Radhakrishnan * procedures that help in looping back towards system suspend exit 226a9e0260cSVignesh Radhakrishnan * instead of calling WFI by requesting a warm reset. 227a9e0260cSVignesh Radhakrishnan * Else, just call WFI to enter low power state. 228a9e0260cSVignesh Radhakrishnan */ 229a9e0260cSVignesh Radhakrishnan if ((tegra_fake_system_suspend != 0U) && 230a9e0260cSVignesh Radhakrishnan (pwr_state == (uint8_t)PSTATE_ID_SOC_POWERDN)) { 231a9e0260cSVignesh Radhakrishnan 232a9e0260cSVignesh Radhakrishnan /* warm reboot */ 233a9e0260cSVignesh Radhakrishnan rmr_el3 = read_rmr_el3(); 234a9e0260cSVignesh Radhakrishnan write_rmr_el3(rmr_el3 | RMR_WARM_RESET_CPU); 235a9e0260cSVignesh Radhakrishnan 236a9e0260cSVignesh Radhakrishnan } else { 23726c0d9b2SVarun Wadekar /* enter power down state */ 23826c0d9b2SVarun Wadekar wfi(); 239a9e0260cSVignesh Radhakrishnan } 24026c0d9b2SVarun Wadekar 24126c0d9b2SVarun Wadekar /* we can never reach here */ 24226c0d9b2SVarun Wadekar panic(); 24326c0d9b2SVarun Wadekar } 24426c0d9b2SVarun Wadekar 24526c0d9b2SVarun Wadekar /******************************************************************************* 24671cb26eaSVarun Wadekar * Handler called when a power domain has just been powered on after 24771cb26eaSVarun Wadekar * being turned off earlier. The target_state encodes the low power state that 24871cb26eaSVarun Wadekar * each level has woken up from. 24908438e24SVarun Wadekar ******************************************************************************/ 25071cb26eaSVarun Wadekar void tegra_pwr_domain_on_finish(const psci_power_state_t *target_state) 25108438e24SVarun Wadekar { 252b36aea5aSAnthony Zhou const plat_params_from_bl2_t *plat_params; 253322e7c3eSHarvey Hsieh uint32_t console_clock; 25408438e24SVarun Wadekar 25508438e24SVarun Wadekar /* 25608438e24SVarun Wadekar * Initialize the GIC cpu and distributor interfaces 25708438e24SVarun Wadekar */ 258d3360301SVarun Wadekar plat_gic_setup(); 25908438e24SVarun Wadekar 26008438e24SVarun Wadekar /* 26108438e24SVarun Wadekar * Check if we are exiting from deep sleep. 26208438e24SVarun Wadekar */ 26371cb26eaSVarun Wadekar if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] == 26471cb26eaSVarun Wadekar PSTATE_ID_SOC_POWERDN) { 26508438e24SVarun Wadekar 266322e7c3eSHarvey Hsieh /* 267322e7c3eSHarvey Hsieh * Reference clock used by the FPGAs is a lot slower. 268322e7c3eSHarvey Hsieh */ 269b36aea5aSAnthony Zhou if (tegra_platform_is_fpga()) { 270322e7c3eSHarvey Hsieh console_clock = TEGRA_BOOT_UART_CLK_13_MHZ; 271322e7c3eSHarvey Hsieh } else { 272322e7c3eSHarvey Hsieh console_clock = TEGRA_BOOT_UART_CLK_408_MHZ; 273322e7c3eSHarvey Hsieh } 274322e7c3eSHarvey Hsieh 2755b5928e8SVarun Wadekar /* Initialize the runtime console */ 276b36aea5aSAnthony Zhou if (tegra_console_base != 0ULL) { 277b36aea5aSAnthony Zhou (void)console_init(tegra_console_base, console_clock, 2785b5928e8SVarun Wadekar TEGRA_CONSOLE_BAUDRATE); 2799b514f83SDamon Duan } 2805b5928e8SVarun Wadekar 28108438e24SVarun Wadekar /* 282102e4087SVarun Wadekar * Restore Memory Controller settings as it loses state 283102e4087SVarun Wadekar * during system suspend. 28408438e24SVarun Wadekar */ 285102e4087SVarun Wadekar tegra_memctrl_restore_settings(); 28608438e24SVarun Wadekar 28708438e24SVarun Wadekar /* 28808438e24SVarun Wadekar * Security configuration to allow DRAM/device access. 28908438e24SVarun Wadekar */ 29008438e24SVarun Wadekar plat_params = bl31_get_plat_params(); 291e0d4158cSVarun Wadekar tegra_memctrl_tzdram_setup(plat_params->tzdram_base, 292b36aea5aSAnthony Zhou (uint32_t)plat_params->tzdram_size); 293207680c6SVarun Wadekar 294207680c6SVarun Wadekar /* 295207680c6SVarun Wadekar * Set up the TZRAM memory aperture to allow only secure world 296207680c6SVarun Wadekar * access 297207680c6SVarun Wadekar */ 298207680c6SVarun Wadekar tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE); 29908438e24SVarun Wadekar } 30008438e24SVarun Wadekar 30108438e24SVarun Wadekar /* 30208438e24SVarun Wadekar * Reset hardware settings. 30308438e24SVarun Wadekar */ 304b36aea5aSAnthony Zhou (void)tegra_soc_pwr_domain_on_finish(target_state); 30508438e24SVarun Wadekar } 30608438e24SVarun Wadekar 30708438e24SVarun Wadekar /******************************************************************************* 30871cb26eaSVarun Wadekar * Handler called when a power domain has just been powered on after 30971cb26eaSVarun Wadekar * having been suspended earlier. The target_state encodes the low power state 31071cb26eaSVarun Wadekar * that each level has woken up from. 31108438e24SVarun Wadekar ******************************************************************************/ 31271cb26eaSVarun Wadekar void tegra_pwr_domain_suspend_finish(const psci_power_state_t *target_state) 31308438e24SVarun Wadekar { 31471cb26eaSVarun Wadekar tegra_pwr_domain_on_finish(target_state); 31508438e24SVarun Wadekar } 31608438e24SVarun Wadekar 31708438e24SVarun Wadekar /******************************************************************************* 31808438e24SVarun Wadekar * Handler called when the system wants to be powered off 31908438e24SVarun Wadekar ******************************************************************************/ 32008438e24SVarun Wadekar __dead2 void tegra_system_off(void) 32108438e24SVarun Wadekar { 32231a4957cSVarun Wadekar INFO("Powering down system...\n"); 32331a4957cSVarun Wadekar 32431a4957cSVarun Wadekar tegra_soc_prepare_system_off(); 32508438e24SVarun Wadekar } 32608438e24SVarun Wadekar 32708438e24SVarun Wadekar /******************************************************************************* 32808438e24SVarun Wadekar * Handler called when the system wants to be restarted. 32908438e24SVarun Wadekar ******************************************************************************/ 33008438e24SVarun Wadekar __dead2 void tegra_system_reset(void) 33108438e24SVarun Wadekar { 33231a4957cSVarun Wadekar INFO("Restarting system...\n"); 33331a4957cSVarun Wadekar 3343b40f993SVarun Wadekar /* per-SoC system reset handler */ 335b36aea5aSAnthony Zhou (void)tegra_soc_prepare_system_reset(); 3363b40f993SVarun Wadekar 33708438e24SVarun Wadekar /* 33808438e24SVarun Wadekar * Program the PMC in order to restart the system. 33908438e24SVarun Wadekar */ 34008438e24SVarun Wadekar tegra_pmc_system_reset(); 34108438e24SVarun Wadekar } 34208438e24SVarun Wadekar 34308438e24SVarun Wadekar /******************************************************************************* 34471cb26eaSVarun Wadekar * Handler called to check the validity of the power state parameter. 34571cb26eaSVarun Wadekar ******************************************************************************/ 346b36aea5aSAnthony Zhou int32_t tegra_validate_power_state(uint32_t power_state, 34771cb26eaSVarun Wadekar psci_power_state_t *req_state) 34871cb26eaSVarun Wadekar { 3494c994002SAnthony Zhou assert(req_state != NULL); 35071cb26eaSVarun Wadekar 35171cb26eaSVarun Wadekar return tegra_soc_validate_power_state(power_state, req_state); 35271cb26eaSVarun Wadekar } 35371cb26eaSVarun Wadekar 35471cb26eaSVarun Wadekar /******************************************************************************* 35571cb26eaSVarun Wadekar * Platform handler called to check the validity of the non secure entrypoint. 35671cb26eaSVarun Wadekar ******************************************************************************/ 357b36aea5aSAnthony Zhou int32_t tegra_validate_ns_entrypoint(uintptr_t entrypoint) 35871cb26eaSVarun Wadekar { 359b36aea5aSAnthony Zhou int32_t ret = PSCI_E_INVALID_ADDRESS; 360b36aea5aSAnthony Zhou 36171cb26eaSVarun Wadekar /* 36271cb26eaSVarun Wadekar * Check if the non secure entrypoint lies within the non 36371cb26eaSVarun Wadekar * secure DRAM. 36471cb26eaSVarun Wadekar */ 365b36aea5aSAnthony Zhou if ((entrypoint >= TEGRA_DRAM_BASE) && (entrypoint <= TEGRA_DRAM_END)) { 366b36aea5aSAnthony Zhou ret = PSCI_E_SUCCESS; 367b36aea5aSAnthony Zhou } 36871cb26eaSVarun Wadekar 369b36aea5aSAnthony Zhou return ret; 37071cb26eaSVarun Wadekar } 37171cb26eaSVarun Wadekar 37271cb26eaSVarun Wadekar /******************************************************************************* 37308438e24SVarun Wadekar * Export the platform handlers to enable psci to invoke them 37408438e24SVarun Wadekar ******************************************************************************/ 37571cb26eaSVarun Wadekar static const plat_psci_ops_t tegra_plat_psci_ops = { 37671cb26eaSVarun Wadekar .cpu_standby = tegra_cpu_standby, 37771cb26eaSVarun Wadekar .pwr_domain_on = tegra_pwr_domain_on, 37871cb26eaSVarun Wadekar .pwr_domain_off = tegra_pwr_domain_off, 379cb95a19aSVarun Wadekar .pwr_domain_suspend_pwrdown_early = tegra_pwr_domain_suspend_pwrdown_early, 38071cb26eaSVarun Wadekar .pwr_domain_suspend = tegra_pwr_domain_suspend, 38171cb26eaSVarun Wadekar .pwr_domain_on_finish = tegra_pwr_domain_on_finish, 38271cb26eaSVarun Wadekar .pwr_domain_suspend_finish = tegra_pwr_domain_suspend_finish, 38326c0d9b2SVarun Wadekar .pwr_domain_pwr_down_wfi = tegra_pwr_domain_power_down_wfi, 38408438e24SVarun Wadekar .system_off = tegra_system_off, 38508438e24SVarun Wadekar .system_reset = tegra_system_reset, 38694c672e7SVarun Wadekar .validate_power_state = tegra_validate_power_state, 38771cb26eaSVarun Wadekar .validate_ns_entrypoint = tegra_validate_ns_entrypoint, 38871cb26eaSVarun Wadekar .get_sys_suspend_power_state = tegra_get_sys_suspend_power_state, 38908438e24SVarun Wadekar }; 39008438e24SVarun Wadekar 39108438e24SVarun Wadekar /******************************************************************************* 39271cb26eaSVarun Wadekar * Export the platform specific power ops and initialize Power Controller 39308438e24SVarun Wadekar ******************************************************************************/ 39471cb26eaSVarun Wadekar int plat_setup_psci_ops(uintptr_t sec_entrypoint, 39571cb26eaSVarun Wadekar const plat_psci_ops_t **psci_ops) 39608438e24SVarun Wadekar { 39771cb26eaSVarun Wadekar psci_power_state_t target_state = { { PSCI_LOCAL_STATE_RUN } }; 39871cb26eaSVarun Wadekar 39971cb26eaSVarun Wadekar /* 40071cb26eaSVarun Wadekar * Flush entrypoint variable to PoC since it will be 40171cb26eaSVarun Wadekar * accessed after a reset with the caches turned off. 40271cb26eaSVarun Wadekar */ 40371cb26eaSVarun Wadekar tegra_sec_entry_point = sec_entrypoint; 40471cb26eaSVarun Wadekar flush_dcache_range((uint64_t)&tegra_sec_entry_point, sizeof(uint64_t)); 40571cb26eaSVarun Wadekar 40608438e24SVarun Wadekar /* 40708438e24SVarun Wadekar * Reset hardware settings. 40808438e24SVarun Wadekar */ 409b36aea5aSAnthony Zhou (void)tegra_soc_pwr_domain_on_finish(&target_state); 41008438e24SVarun Wadekar 41108438e24SVarun Wadekar /* 41271cb26eaSVarun Wadekar * Initialize PSCI ops struct 41308438e24SVarun Wadekar */ 41471cb26eaSVarun Wadekar *psci_ops = &tegra_plat_psci_ops; 41508438e24SVarun Wadekar 41608438e24SVarun Wadekar return 0; 41708438e24SVarun Wadekar } 4182693f1dbSVarun Wadekar 4192693f1dbSVarun Wadekar /******************************************************************************* 4202693f1dbSVarun Wadekar * Platform handler to calculate the proper target power level at the 4212693f1dbSVarun Wadekar * specified affinity level 4222693f1dbSVarun Wadekar ******************************************************************************/ 4232693f1dbSVarun Wadekar plat_local_state_t plat_get_target_pwr_state(unsigned int lvl, 4242693f1dbSVarun Wadekar const plat_local_state_t *states, 4252693f1dbSVarun Wadekar unsigned int ncpu) 4262693f1dbSVarun Wadekar { 427a7cd0953SVarun Wadekar return tegra_soc_get_target_pwr_state(lvl, states, ncpu); 4282693f1dbSVarun Wadekar } 429