blob: 0e2edf0969e7b1f6de349564d9a1683be067e8a9 [file] [log] [blame]
Varun Wadekar0f3baa02015-07-16 11:36:33 +05301/*
Antonio Nino Diaz7a4ff682017-03-28 13:56:21 +01002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Varun Wadekarb5b15b22018-05-17 10:10:25 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar0f3baa02015-07-16 11:36:33 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar0f3baa02015-07-16 11:36:33 +05306 */
7
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <assert.h>
9
10#include <platform_def.h>
11
Varun Wadekar0f3baa02015-07-16 11:36:33 +053012#include <arch.h>
13#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <common/debug.h>
15#include <drivers/delay_timer.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010016#include <denver.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <lib/mmio.h>
18#include <lib/psci/psci.h>
19
Varun Wadekar0f3baa02015-07-16 11:36:33 +053020#include <flowctrl.h>
Varun Wadekar0f3baa02015-07-16 11:36:33 +053021#include <pmc.h>
Varun Wadekar0f3baa02015-07-16 11:36:33 +053022#include <tegra_def.h>
23#include <tegra_private.h>
24
25/*
26 * Register used to clear CPU reset signals. Each CPU has two reset
27 * signals: CPU reset (3:0) and Core reset (19:16)
28 */
29#define CPU_CMPLX_RESET_CLR 0x344
30#define CPU_CORE_RESET_MASK 0x10001
31
Varun Wadekar8b82fae2015-11-09 17:39:28 -080032/* Clock and Reset controller registers for system clock's settings */
33#define SCLK_RATE 0x30
34#define SCLK_BURST_POLICY 0x28
35#define SCLK_BURST_POLICY_DEFAULT 0x10000000
36
Varun Wadekar0f3baa02015-07-16 11:36:33 +053037static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER];
38
Varun Wadekarb5b15b22018-05-17 10:10:25 -070039plat_local_state_t tegra_soc_get_target_pwr_state(uint32_t lvl,
40 const plat_local_state_t *states,
41 uint32_t ncpu)
42{
43 plat_local_state_t target = PLAT_MAX_OFF_STATE, temp;
44 uint32_t num_cpu = ncpu;
45 const plat_local_state_t *local_state = states;
46
47 (void)lvl;
48
49 assert(ncpu != 0U);
50
51 do {
52 temp = *local_state;
53 if ((temp < target)) {
54 target = temp;
55 }
56 --num_cpu;
57 local_state++;
58 } while (num_cpu != 0U);
59
60 return target;
61}
62
Varun Wadekara78bb1b2015-08-07 10:03:00 +053063int32_t tegra_soc_validate_power_state(unsigned int power_state,
64 psci_power_state_t *req_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053065{
Varun Wadekara78bb1b2015-08-07 10:03:00 +053066 int state_id = psci_get_pstate_id(power_state);
67 int cpu = read_mpidr() & MPIDR_CPU_MASK;
68
Varun Wadekara78bb1b2015-08-07 10:03:00 +053069 /*
70 * Sanity check the requested state id, power level and CPU number.
71 * Currently T132 only supports SYSTEM_SUSPEND on last standing CPU
72 * i.e. CPU 0
73 */
Varun Wadekar6077dce2016-01-27 11:31:06 -080074 if ((state_id != PSTATE_ID_SOC_POWERDN) || (cpu != 0)) {
Varun Wadekara78bb1b2015-08-07 10:03:00 +053075 ERROR("unsupported state id @ power level\n");
76 return PSCI_E_INVALID_PARAMS;
Varun Wadekar0f3baa02015-07-16 11:36:33 +053077 }
78
Varun Wadekara78bb1b2015-08-07 10:03:00 +053079 /* Set lower power states to PLAT_MAX_OFF_STATE */
Varun Wadekar66231d12017-06-07 09:57:42 -070080 for (uint32_t i = MPIDR_AFFLVL0; i < PLAT_MAX_PWR_LVL; i++)
Varun Wadekara78bb1b2015-08-07 10:03:00 +053081 req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
82
83 /* Set the SYSTEM_SUSPEND state-id */
84 req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] =
85 PSTATE_ID_SOC_POWERDN;
86
Varun Wadekar0f3baa02015-07-16 11:36:33 +053087 return PSCI_E_SUCCESS;
88}
89
Varun Wadekara78bb1b2015-08-07 10:03:00 +053090int tegra_soc_pwr_domain_on(u_register_t mpidr)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053091{
92 int cpu = mpidr & MPIDR_CPU_MASK;
93 uint32_t mask = CPU_CORE_RESET_MASK << cpu;
94
95 if (cpu_powergate_mask[cpu] == 0) {
96
97 /* Deassert CPU reset signals */
98 mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask);
99
100 /* Power on CPU using PMC */
101 tegra_pmc_cpu_on(cpu);
102
103 /* Fill in the CPU powergate mask */
104 cpu_powergate_mask[cpu] = 1;
105
106 } else {
107 /* Power on CPU using Flow Controller */
108 tegra_fc_cpu_on(cpu);
109 }
110
111 return PSCI_E_SUCCESS;
112}
113
Varun Wadekar6eec6d62016-03-03 13:28:10 -0800114int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
115{
116 /*
117 * Lock scratch registers which hold the CPU vectors
118 */
119 tegra_pmc_lock_cpu_vectors();
120
121 return PSCI_E_SUCCESS;
122}
123
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530124int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530125{
Steven Kaod417cea2017-06-14 14:02:23 +0800126 uint64_t val;
127
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530128 tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
Varun Wadekard43583c2016-02-22 11:09:41 -0800129
130 /* Disable DCO operations */
131 denver_disable_dco();
132
133 /* Power down the CPU */
Steven Kaod417cea2017-06-14 14:02:23 +0800134 val = read_actlr_el1() & ~ACTLR_EL1_PMSTATE_MASK;
135 write_actlr_el1(val | DENVER_CPU_STATE_POWER_DOWN);
Varun Wadekard43583c2016-02-22 11:09:41 -0800136
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530137 return PSCI_E_SUCCESS;
138}
139
Varun Wadekarb5b15b22018-05-17 10:10:25 -0700140int32_t tegra_soc_cpu_standby(plat_local_state_t cpu_state)
141{
142 (void)cpu_state;
143 return PSCI_E_SUCCESS;
144}
145
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530146int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530147{
Steven Kaod417cea2017-06-14 14:02:23 +0800148 uint64_t val;
149
Antonio Nino Diaz7a4ff682017-03-28 13:56:21 +0100150#if ENABLE_ASSERTIONS
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530151 int cpu = read_mpidr() & MPIDR_CPU_MASK;
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530152
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530153 /* SYSTEM_SUSPEND only on CPU0 */
154 assert(cpu == 0);
155#endif
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530156
157 /* Allow restarting CPU #1 using PMC on suspend exit */
158 cpu_powergate_mask[1] = 0;
159
160 /* Program FC to enter suspend state */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530161 tegra_fc_cpu_powerdn(read_mpidr());
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530162
Varun Wadekard43583c2016-02-22 11:09:41 -0800163 /* Disable DCO operations */
164 denver_disable_dco();
165
166 /* Program the suspend state ID */
Steven Kaod417cea2017-06-14 14:02:23 +0800167 val = read_actlr_el1() & ~ACTLR_EL1_PMSTATE_MASK;
168 write_actlr_el1(val | target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530169
170 return PSCI_E_SUCCESS;
171}
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800172
Varun Wadekarb5b15b22018-05-17 10:10:25 -0700173int32_t tegra_soc_pwr_domain_suspend_pwrdown_early(const psci_power_state_t *target_state)
174{
175 return PSCI_E_NOT_SUPPORTED;
176}
177
178int tegra_soc_pwr_domain_power_down_wfi(const psci_power_state_t *target_state)
179{
180 return PSCI_E_SUCCESS;
181}
182
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800183int tegra_soc_prepare_system_reset(void)
184{
185 /*
186 * Set System Clock (SCLK) to POR default so that the clock source
187 * for the PMC APB clock would not be changed due to system reset.
188 */
189 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
190 SCLK_BURST_POLICY_DEFAULT);
191 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
192
193 /* Wait 1 ms to make sure clock source/device logic is stabilized. */
194 mdelay(1);
195
Varun Wadekar29b46652018-05-17 11:10:13 -0700196 /*
197 * Program the PMC in order to restart the system.
198 */
199 tegra_pmc_system_reset();
200
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800201 return PSCI_E_SUCCESS;
202}
Varun Wadekarb5b15b22018-05-17 10:10:25 -0700203
204__dead2 void tegra_soc_prepare_system_off(void)
205{
206 ERROR("Tegra System Off: operation not handled.\n");
207 panic();
208}