xref: /rk3399_ARM-atf/plat/nvidia/tegra/common/tegra_pm.c (revision cb95a19a61cb7a9ad30d7c5b4b9a6c8dbd6840a1)
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 <arch_helpers.h>
808438e24SVarun Wadekar #include <assert.h>
908438e24SVarun Wadekar #include <bl_common.h>
10ee1ebbd1SIsla Mitchell #include <console.h>
1108438e24SVarun Wadekar #include <context.h>
1208438e24SVarun Wadekar #include <context_mgmt.h>
1308438e24SVarun Wadekar #include <debug.h>
1408438e24SVarun Wadekar #include <memctrl.h>
1508438e24SVarun Wadekar #include <mmio.h>
1608438e24SVarun Wadekar #include <platform.h>
1708438e24SVarun Wadekar #include <platform_def.h>
1808438e24SVarun Wadekar #include <pmc.h>
1908438e24SVarun Wadekar #include <psci.h>
2008438e24SVarun Wadekar #include <tegra_def.h>
2108438e24SVarun Wadekar #include <tegra_private.h>
2208438e24SVarun Wadekar 
2308438e24SVarun Wadekar extern uint64_t tegra_bl31_phys_base;
2471cb26eaSVarun Wadekar extern uint64_t tegra_sec_entry_point;
255b5928e8SVarun Wadekar extern uint64_t tegra_console_base;
2608438e24SVarun Wadekar 
2708438e24SVarun Wadekar /*
28a9e0260cSVignesh Radhakrishnan  * tegra_fake_system_suspend acts as a boolean var controlling whether
29a9e0260cSVignesh Radhakrishnan  * we are going to take fake system suspend code or normal system suspend code
30a9e0260cSVignesh Radhakrishnan  * path. This variable is set inside the sip call handlers,when the kernel
31a9e0260cSVignesh Radhakrishnan  * requests a SIP call to set the suspend debug flags.
32a9e0260cSVignesh Radhakrishnan  */
33a9e0260cSVignesh Radhakrishnan uint8_t tegra_fake_system_suspend;
34a9e0260cSVignesh Radhakrishnan 
35a9e0260cSVignesh Radhakrishnan /*
3608438e24SVarun Wadekar  * The following platform setup functions are weakly defined. They
3708438e24SVarun Wadekar  * provide typical implementations that will be overridden by a SoC.
3808438e24SVarun Wadekar  */
39*cb95a19aSVarun Wadekar #pragma weak tegra_soc_pwr_domain_suspend_pwrdown_early
4071cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_suspend
4171cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_on
4271cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_off
4371cb26eaSVarun Wadekar #pragma weak tegra_soc_pwr_domain_on_finish
4426c0d9b2SVarun Wadekar #pragma weak tegra_soc_pwr_domain_power_down_wfi
453b40f993SVarun Wadekar #pragma weak tegra_soc_prepare_system_reset
4631a4957cSVarun Wadekar #pragma weak tegra_soc_prepare_system_off
47a7cd0953SVarun Wadekar #pragma weak tegra_soc_get_target_pwr_state
4808438e24SVarun Wadekar 
49*cb95a19aSVarun Wadekar int tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
50*cb95a19aSVarun Wadekar {
51*cb95a19aSVarun Wadekar 	return PSCI_E_NOT_SUPPORTED;
52*cb95a19aSVarun Wadekar }
53*cb95a19aSVarun Wadekar 
5471cb26eaSVarun Wadekar int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
5508438e24SVarun Wadekar {
5608438e24SVarun Wadekar 	return PSCI_E_NOT_SUPPORTED;
5708438e24SVarun Wadekar }
5808438e24SVarun Wadekar 
5971cb26eaSVarun Wadekar int tegra_soc_pwr_domain_on(u_register_t mpidr)
6008438e24SVarun Wadekar {
6108438e24SVarun Wadekar 	return PSCI_E_SUCCESS;
6208438e24SVarun Wadekar }
6308438e24SVarun Wadekar 
6471cb26eaSVarun Wadekar int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
6508438e24SVarun Wadekar {
6608438e24SVarun Wadekar 	return PSCI_E_SUCCESS;
6708438e24SVarun Wadekar }
6808438e24SVarun Wadekar 
6971cb26eaSVarun Wadekar int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
7008438e24SVarun Wadekar {
7108438e24SVarun Wadekar 	return PSCI_E_SUCCESS;
7208438e24SVarun Wadekar }
7308438e24SVarun Wadekar 
7426c0d9b2SVarun Wadekar int tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
7526c0d9b2SVarun Wadekar {
7626c0d9b2SVarun Wadekar 	return PSCI_E_SUCCESS;
7726c0d9b2SVarun Wadekar }
7826c0d9b2SVarun Wadekar 
793b40f993SVarun Wadekar int tegra_soc_prepare_system_reset(void)
803b40f993SVarun Wadekar {
813b40f993SVarun Wadekar 	return PSCI_E_SUCCESS;
823b40f993SVarun Wadekar }
833b40f993SVarun Wadekar 
8431a4957cSVarun Wadekar __dead2 void tegra_soc_prepare_system_off(void)
8531a4957cSVarun Wadekar {
8631a4957cSVarun Wadekar 	ERROR("Tegra System Off: operation not handled.\n");
8731a4957cSVarun Wadekar 	panic();
8831a4957cSVarun Wadekar }
8931a4957cSVarun Wadekar 
90a7cd0953SVarun Wadekar plat_local_state_t tegra_soc_get_target_pwr_state(unsigned int lvl,
91a7cd0953SVarun Wadekar 					     const plat_local_state_t *states,
92a7cd0953SVarun Wadekar 					     unsigned int ncpu)
93a7cd0953SVarun Wadekar {
948539f45dSVarun Wadekar 	plat_local_state_t target = PLAT_MAX_OFF_STATE, temp;
95a7cd0953SVarun Wadekar 
96a7cd0953SVarun Wadekar 	assert(ncpu);
97a7cd0953SVarun Wadekar 
98a7cd0953SVarun Wadekar 	do {
99a7cd0953SVarun Wadekar 		temp = *states++;
1008539f45dSVarun Wadekar 		if ((temp < target))
101a7cd0953SVarun Wadekar 			target = temp;
102a7cd0953SVarun Wadekar 	} while (--ncpu);
103a7cd0953SVarun Wadekar 
104a7cd0953SVarun Wadekar 	return target;
105a7cd0953SVarun Wadekar }
106a7cd0953SVarun Wadekar 
10708438e24SVarun Wadekar /*******************************************************************************
10871cb26eaSVarun Wadekar  * This handler is called by the PSCI implementation during the `SYSTEM_SUSPEND`
10971cb26eaSVarun Wadekar  * call to get the `power_state` parameter. This allows the platform to encode
11071cb26eaSVarun Wadekar  * the appropriate State-ID field within the `power_state` parameter which can
11171cb26eaSVarun Wadekar  * be utilized in `pwr_domain_suspend()` to suspend to system affinity level.
11208438e24SVarun Wadekar ******************************************************************************/
11371cb26eaSVarun Wadekar void tegra_get_sys_suspend_power_state(psci_power_state_t *req_state)
11408438e24SVarun Wadekar {
115a7cd0953SVarun Wadekar 	/* all affinities use system suspend state id */
1166311f63dSVarun Wadekar 	for (uint32_t i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++)
117a7cd0953SVarun Wadekar 		req_state->pwr_domain_state[i] = PSTATE_ID_SOC_POWERDN;
11808438e24SVarun Wadekar }
11908438e24SVarun Wadekar 
12008438e24SVarun Wadekar /*******************************************************************************
12108438e24SVarun Wadekar  * Handler called when an affinity instance is about to enter standby.
12208438e24SVarun Wadekar  ******************************************************************************/
12371cb26eaSVarun Wadekar void tegra_cpu_standby(plat_local_state_t cpu_state)
12408438e24SVarun Wadekar {
12508438e24SVarun Wadekar 	/*
12608438e24SVarun Wadekar 	 * Enter standby state
12708438e24SVarun Wadekar 	 * dsb is good practice before using wfi to enter low power states
12808438e24SVarun Wadekar 	 */
12908438e24SVarun Wadekar 	dsb();
13008438e24SVarun Wadekar 	wfi();
13108438e24SVarun Wadekar }
13208438e24SVarun Wadekar 
13308438e24SVarun Wadekar /*******************************************************************************
13408438e24SVarun Wadekar  * Handler called when an affinity instance is about to be turned on. The
13508438e24SVarun Wadekar  * level and mpidr determine the affinity instance.
13608438e24SVarun Wadekar  ******************************************************************************/
13771cb26eaSVarun Wadekar int tegra_pwr_domain_on(u_register_t mpidr)
13808438e24SVarun Wadekar {
13971cb26eaSVarun Wadekar 	return tegra_soc_pwr_domain_on(mpidr);
14008438e24SVarun Wadekar }
14108438e24SVarun Wadekar 
14208438e24SVarun Wadekar /*******************************************************************************
14371cb26eaSVarun Wadekar  * Handler called when a power domain is about to be turned off. The
14471cb26eaSVarun Wadekar  * target_state encodes the power state that each level should transition to.
14508438e24SVarun Wadekar  ******************************************************************************/
14671cb26eaSVarun Wadekar void tegra_pwr_domain_off(const psci_power_state_t *target_state)
14708438e24SVarun Wadekar {
14871cb26eaSVarun Wadekar 	tegra_soc_pwr_domain_off(target_state);
14908438e24SVarun Wadekar }
15008438e24SVarun Wadekar 
15108438e24SVarun Wadekar /*******************************************************************************
15226c0d9b2SVarun Wadekar  * Handler called when a power domain is about to be suspended. The
15371cb26eaSVarun Wadekar  * target_state encodes the power state that each level should transition to.
154*cb95a19aSVarun Wadekar  * This handler is called with SMP and data cache enabled, when
155*cb95a19aSVarun Wadekar  * HW_ASSISTED_COHERENCY = 0
156*cb95a19aSVarun Wadekar  ******************************************************************************/
157*cb95a19aSVarun Wadekar void tegra_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
158*cb95a19aSVarun Wadekar {
159*cb95a19aSVarun Wadekar 	tegra_soc_pwr_domain_suspend_pwrdown_early(target_state);
160*cb95a19aSVarun Wadekar }
161*cb95a19aSVarun Wadekar 
162*cb95a19aSVarun Wadekar /*******************************************************************************
163*cb95a19aSVarun Wadekar  * Handler called when a power domain is about to be suspended. The
164*cb95a19aSVarun Wadekar  * target_state encodes the power state that each level should transition to.
16508438e24SVarun Wadekar  ******************************************************************************/
16671cb26eaSVarun Wadekar void tegra_pwr_domain_suspend(const psci_power_state_t *target_state)
16708438e24SVarun Wadekar {
16871cb26eaSVarun Wadekar 	tegra_soc_pwr_domain_suspend(target_state);
16908438e24SVarun Wadekar 
1705b5928e8SVarun Wadekar 	/* Disable console if we are entering deep sleep. */
1715b5928e8SVarun Wadekar 	if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] ==
1725b5928e8SVarun Wadekar 			PSTATE_ID_SOC_POWERDN)
1735b5928e8SVarun Wadekar 		console_uninit();
1745b5928e8SVarun Wadekar 
17508438e24SVarun Wadekar 	/* disable GICC */
17608438e24SVarun Wadekar 	tegra_gic_cpuif_deactivate();
17708438e24SVarun Wadekar }
17808438e24SVarun Wadekar 
17908438e24SVarun Wadekar /*******************************************************************************
18026c0d9b2SVarun Wadekar  * Handler called at the end of the power domain suspend sequence. The
18126c0d9b2SVarun Wadekar  * target_state encodes the power state that each level should transition to.
18226c0d9b2SVarun Wadekar  ******************************************************************************/
18326c0d9b2SVarun Wadekar __dead2 void tegra_pwr_domain_power_down_wfi(const psci_power_state_t
18426c0d9b2SVarun Wadekar 					     *target_state)
18526c0d9b2SVarun Wadekar {
186a9e0260cSVignesh Radhakrishnan 	uint8_t pwr_state = target_state->pwr_domain_state[PLAT_MAX_PWR_LVL];
187a9e0260cSVignesh Radhakrishnan 	uint64_t rmr_el3 = 0;
188a9e0260cSVignesh Radhakrishnan 
18926c0d9b2SVarun Wadekar 	/* call the chip's power down handler */
19026c0d9b2SVarun Wadekar 	tegra_soc_pwr_domain_power_down_wfi(target_state);
19126c0d9b2SVarun Wadekar 
192a9e0260cSVignesh Radhakrishnan 	/*
193a9e0260cSVignesh Radhakrishnan 	 * If we are in fake system suspend mode, ensure we start doing
194a9e0260cSVignesh Radhakrishnan 	 * procedures that help in looping back towards system suspend exit
195a9e0260cSVignesh Radhakrishnan 	 * instead of calling WFI by requesting a warm reset.
196a9e0260cSVignesh Radhakrishnan 	 * Else, just call WFI to enter low power state.
197a9e0260cSVignesh Radhakrishnan 	 */
198a9e0260cSVignesh Radhakrishnan 	if ((tegra_fake_system_suspend != 0U) &&
199a9e0260cSVignesh Radhakrishnan 	    (pwr_state == (uint8_t)PSTATE_ID_SOC_POWERDN)) {
200a9e0260cSVignesh Radhakrishnan 
201a9e0260cSVignesh Radhakrishnan 		/* warm reboot */
202a9e0260cSVignesh Radhakrishnan 		rmr_el3 = read_rmr_el3();
203a9e0260cSVignesh Radhakrishnan 		write_rmr_el3(rmr_el3 | RMR_WARM_RESET_CPU);
204a9e0260cSVignesh Radhakrishnan 
205a9e0260cSVignesh Radhakrishnan 	} else {
20626c0d9b2SVarun Wadekar 		/* enter power down state */
20726c0d9b2SVarun Wadekar 		wfi();
208a9e0260cSVignesh Radhakrishnan 	}
20926c0d9b2SVarun Wadekar 
21026c0d9b2SVarun Wadekar 	/* we can never reach here */
21126c0d9b2SVarun Wadekar 	panic();
21226c0d9b2SVarun Wadekar }
21326c0d9b2SVarun Wadekar 
21426c0d9b2SVarun Wadekar /*******************************************************************************
21571cb26eaSVarun Wadekar  * Handler called when a power domain has just been powered on after
21671cb26eaSVarun Wadekar  * being turned off earlier. The target_state encodes the low power state that
21771cb26eaSVarun Wadekar  * each level has woken up from.
21808438e24SVarun Wadekar  ******************************************************************************/
21971cb26eaSVarun Wadekar void tegra_pwr_domain_on_finish(const psci_power_state_t *target_state)
22008438e24SVarun Wadekar {
22108438e24SVarun Wadekar 	plat_params_from_bl2_t *plat_params;
22208438e24SVarun Wadekar 
22308438e24SVarun Wadekar 	/*
22408438e24SVarun Wadekar 	 * Initialize the GIC cpu and distributor interfaces
22508438e24SVarun Wadekar 	 */
226d3360301SVarun Wadekar 	plat_gic_setup();
22708438e24SVarun Wadekar 
22808438e24SVarun Wadekar 	/*
22908438e24SVarun Wadekar 	 * Check if we are exiting from deep sleep.
23008438e24SVarun Wadekar 	 */
23171cb26eaSVarun Wadekar 	if (target_state->pwr_domain_state[PLAT_MAX_PWR_LVL] ==
23271cb26eaSVarun Wadekar 			PSTATE_ID_SOC_POWERDN) {
23308438e24SVarun Wadekar 
2345b5928e8SVarun Wadekar 		/* Initialize the runtime console */
2359b514f83SDamon Duan 		if (tegra_console_base != (uint64_t)0) {
2365b5928e8SVarun Wadekar 			console_init(tegra_console_base, TEGRA_BOOT_UART_CLK_IN_HZ,
2375b5928e8SVarun Wadekar 				TEGRA_CONSOLE_BAUDRATE);
2389b514f83SDamon Duan 		}
2395b5928e8SVarun Wadekar 
24008438e24SVarun Wadekar 		/*
241102e4087SVarun Wadekar 		 * Restore Memory Controller settings as it loses state
242102e4087SVarun Wadekar 		 * during system suspend.
24308438e24SVarun Wadekar 		 */
244102e4087SVarun Wadekar 		tegra_memctrl_restore_settings();
24508438e24SVarun Wadekar 
24608438e24SVarun Wadekar 		/*
24708438e24SVarun Wadekar 		 * Security configuration to allow DRAM/device access.
24808438e24SVarun Wadekar 		 */
24908438e24SVarun Wadekar 		plat_params = bl31_get_plat_params();
250e0d4158cSVarun Wadekar 		tegra_memctrl_tzdram_setup(plat_params->tzdram_base,
25108438e24SVarun Wadekar 			plat_params->tzdram_size);
252207680c6SVarun Wadekar 
253207680c6SVarun Wadekar 		/*
254207680c6SVarun Wadekar 		 * Set up the TZRAM memory aperture to allow only secure world
255207680c6SVarun Wadekar 		 * access
256207680c6SVarun Wadekar 		 */
257207680c6SVarun Wadekar 		tegra_memctrl_tzram_setup(TEGRA_TZRAM_BASE, TEGRA_TZRAM_SIZE);
25808438e24SVarun Wadekar 	}
25908438e24SVarun Wadekar 
26008438e24SVarun Wadekar 	/*
26108438e24SVarun Wadekar 	 * Reset hardware settings.
26208438e24SVarun Wadekar 	 */
26371cb26eaSVarun Wadekar 	tegra_soc_pwr_domain_on_finish(target_state);
26408438e24SVarun Wadekar }
26508438e24SVarun Wadekar 
26608438e24SVarun Wadekar /*******************************************************************************
26771cb26eaSVarun Wadekar  * Handler called when a power domain has just been powered on after
26871cb26eaSVarun Wadekar  * having been suspended earlier. The target_state encodes the low power state
26971cb26eaSVarun Wadekar  * that each level has woken up from.
27008438e24SVarun Wadekar  ******************************************************************************/
27171cb26eaSVarun Wadekar void tegra_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
27208438e24SVarun Wadekar {
27371cb26eaSVarun Wadekar 	tegra_pwr_domain_on_finish(target_state);
27408438e24SVarun Wadekar }
27508438e24SVarun Wadekar 
27608438e24SVarun Wadekar /*******************************************************************************
27708438e24SVarun Wadekar  * Handler called when the system wants to be powered off
27808438e24SVarun Wadekar  ******************************************************************************/
27908438e24SVarun Wadekar __dead2 void tegra_system_off(void)
28008438e24SVarun Wadekar {
28131a4957cSVarun Wadekar 	INFO("Powering down system...\n");
28231a4957cSVarun Wadekar 
28331a4957cSVarun Wadekar 	tegra_soc_prepare_system_off();
28408438e24SVarun Wadekar }
28508438e24SVarun Wadekar 
28608438e24SVarun Wadekar /*******************************************************************************
28708438e24SVarun Wadekar  * Handler called when the system wants to be restarted.
28808438e24SVarun Wadekar  ******************************************************************************/
28908438e24SVarun Wadekar __dead2 void tegra_system_reset(void)
29008438e24SVarun Wadekar {
29131a4957cSVarun Wadekar 	INFO("Restarting system...\n");
29231a4957cSVarun Wadekar 
2933b40f993SVarun Wadekar 	/* per-SoC system reset handler */
2943b40f993SVarun Wadekar 	tegra_soc_prepare_system_reset();
2953b40f993SVarun Wadekar 
29608438e24SVarun Wadekar 	/*
29708438e24SVarun Wadekar 	 * Program the PMC in order to restart the system.
29808438e24SVarun Wadekar 	 */
29908438e24SVarun Wadekar 	tegra_pmc_system_reset();
30008438e24SVarun Wadekar }
30108438e24SVarun Wadekar 
30208438e24SVarun Wadekar /*******************************************************************************
30371cb26eaSVarun Wadekar  * Handler called to check the validity of the power state parameter.
30471cb26eaSVarun Wadekar  ******************************************************************************/
30571cb26eaSVarun Wadekar int32_t tegra_validate_power_state(unsigned int power_state,
30671cb26eaSVarun Wadekar 				   psci_power_state_t *req_state)
30771cb26eaSVarun Wadekar {
30871cb26eaSVarun Wadekar 	assert(req_state);
30971cb26eaSVarun Wadekar 
31071cb26eaSVarun Wadekar 	return tegra_soc_validate_power_state(power_state, req_state);
31171cb26eaSVarun Wadekar }
31271cb26eaSVarun Wadekar 
31371cb26eaSVarun Wadekar /*******************************************************************************
31471cb26eaSVarun Wadekar  * Platform handler called to check the validity of the non secure entrypoint.
31571cb26eaSVarun Wadekar  ******************************************************************************/
31671cb26eaSVarun Wadekar int tegra_validate_ns_entrypoint(uintptr_t entrypoint)
31771cb26eaSVarun Wadekar {
31871cb26eaSVarun Wadekar 	/*
31971cb26eaSVarun Wadekar 	 * Check if the non secure entrypoint lies within the non
32071cb26eaSVarun Wadekar 	 * secure DRAM.
32171cb26eaSVarun Wadekar 	 */
32271cb26eaSVarun Wadekar 	if ((entrypoint >= TEGRA_DRAM_BASE) && (entrypoint <= TEGRA_DRAM_END))
32371cb26eaSVarun Wadekar 		return PSCI_E_SUCCESS;
32471cb26eaSVarun Wadekar 
32571cb26eaSVarun Wadekar 	return PSCI_E_INVALID_ADDRESS;
32671cb26eaSVarun Wadekar }
32771cb26eaSVarun Wadekar 
32871cb26eaSVarun Wadekar /*******************************************************************************
32908438e24SVarun Wadekar  * Export the platform handlers to enable psci to invoke them
33008438e24SVarun Wadekar  ******************************************************************************/
33171cb26eaSVarun Wadekar static const plat_psci_ops_t tegra_plat_psci_ops = {
33271cb26eaSVarun Wadekar 	.cpu_standby			= tegra_cpu_standby,
33371cb26eaSVarun Wadekar 	.pwr_domain_on			= tegra_pwr_domain_on,
33471cb26eaSVarun Wadekar 	.pwr_domain_off			= tegra_pwr_domain_off,
335*cb95a19aSVarun Wadekar 	.pwr_domain_suspend_pwrdown_early = tegra_pwr_domain_suspend_pwrdown_early,
33671cb26eaSVarun Wadekar 	.pwr_domain_suspend		= tegra_pwr_domain_suspend,
33771cb26eaSVarun Wadekar 	.pwr_domain_on_finish		= tegra_pwr_domain_on_finish,
33871cb26eaSVarun Wadekar 	.pwr_domain_suspend_finish	= tegra_pwr_domain_suspend_finish,
33926c0d9b2SVarun Wadekar 	.pwr_domain_pwr_down_wfi	= tegra_pwr_domain_power_down_wfi,
34008438e24SVarun Wadekar 	.system_off			= tegra_system_off,
34108438e24SVarun Wadekar 	.system_reset			= tegra_system_reset,
34294c672e7SVarun Wadekar 	.validate_power_state		= tegra_validate_power_state,
34371cb26eaSVarun Wadekar 	.validate_ns_entrypoint		= tegra_validate_ns_entrypoint,
34471cb26eaSVarun Wadekar 	.get_sys_suspend_power_state	= tegra_get_sys_suspend_power_state,
34508438e24SVarun Wadekar };
34608438e24SVarun Wadekar 
34708438e24SVarun Wadekar /*******************************************************************************
34871cb26eaSVarun Wadekar  * Export the platform specific power ops and initialize Power Controller
34908438e24SVarun Wadekar  ******************************************************************************/
35071cb26eaSVarun Wadekar int plat_setup_psci_ops(uintptr_t sec_entrypoint,
35171cb26eaSVarun Wadekar 			const plat_psci_ops_t **psci_ops)
35208438e24SVarun Wadekar {
35371cb26eaSVarun Wadekar 	psci_power_state_t target_state = { { PSCI_LOCAL_STATE_RUN } };
35471cb26eaSVarun Wadekar 
35571cb26eaSVarun Wadekar 	/*
35671cb26eaSVarun Wadekar 	 * Flush entrypoint variable to PoC since it will be
35771cb26eaSVarun Wadekar 	 * accessed after a reset with the caches turned off.
35871cb26eaSVarun Wadekar 	 */
35971cb26eaSVarun Wadekar 	tegra_sec_entry_point = sec_entrypoint;
36071cb26eaSVarun Wadekar 	flush_dcache_range((uint64_t)&tegra_sec_entry_point, sizeof(uint64_t));
36171cb26eaSVarun Wadekar 
36208438e24SVarun Wadekar 	/*
36308438e24SVarun Wadekar 	 * Reset hardware settings.
36408438e24SVarun Wadekar 	 */
36571cb26eaSVarun Wadekar 	tegra_soc_pwr_domain_on_finish(&target_state);
36608438e24SVarun Wadekar 
36708438e24SVarun Wadekar 	/*
36871cb26eaSVarun Wadekar 	 * Initialize PSCI ops struct
36908438e24SVarun Wadekar 	 */
37071cb26eaSVarun Wadekar 	*psci_ops = &tegra_plat_psci_ops;
37108438e24SVarun Wadekar 
37208438e24SVarun Wadekar 	return 0;
37308438e24SVarun Wadekar }
3742693f1dbSVarun Wadekar 
3752693f1dbSVarun Wadekar /*******************************************************************************
3762693f1dbSVarun Wadekar  * Platform handler to calculate the proper target power level at the
3772693f1dbSVarun Wadekar  * specified affinity level
3782693f1dbSVarun Wadekar  ******************************************************************************/
3792693f1dbSVarun Wadekar plat_local_state_t plat_get_target_pwr_state(unsigned int lvl,
3802693f1dbSVarun Wadekar 					     const plat_local_state_t *states,
3812693f1dbSVarun Wadekar 					     unsigned int ncpu)
3822693f1dbSVarun Wadekar {
383a7cd0953SVarun Wadekar 	return tegra_soc_get_target_pwr_state(lvl, states, ncpu);
3842693f1dbSVarun Wadekar }
385