blob: bd3f46fcca8260abe7075215c51b410af2fc6b02 [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 Wadekar0f3baa02015-07-16 11:36:33 +05303 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar0f3baa02015-07-16 11:36:33 +05305 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <assert.h>
8
9#include <platform_def.h>
10
Varun Wadekar0f3baa02015-07-16 11:36:33 +053011#include <arch.h>
12#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <common/debug.h>
14#include <drivers/delay_timer.h>
Isla Mitchelle3631462017-07-14 10:46:32 +010015#include <denver.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <lib/mmio.h>
17#include <lib/psci/psci.h>
18
Varun Wadekar0f3baa02015-07-16 11:36:33 +053019#include <flowctrl.h>
Varun Wadekar0f3baa02015-07-16 11:36:33 +053020#include <pmc.h>
Varun Wadekar0f3baa02015-07-16 11:36:33 +053021#include <tegra_def.h>
22#include <tegra_private.h>
23
24/*
25 * Register used to clear CPU reset signals. Each CPU has two reset
26 * signals: CPU reset (3:0) and Core reset (19:16)
27 */
28#define CPU_CMPLX_RESET_CLR 0x344
29#define CPU_CORE_RESET_MASK 0x10001
30
Varun Wadekar8b82fae2015-11-09 17:39:28 -080031/* Clock and Reset controller registers for system clock's settings */
32#define SCLK_RATE 0x30
33#define SCLK_BURST_POLICY 0x28
34#define SCLK_BURST_POLICY_DEFAULT 0x10000000
35
Varun Wadekar0f3baa02015-07-16 11:36:33 +053036static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER];
37
Varun Wadekara78bb1b2015-08-07 10:03:00 +053038int32_t tegra_soc_validate_power_state(unsigned int power_state,
39 psci_power_state_t *req_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053040{
Varun Wadekara78bb1b2015-08-07 10:03:00 +053041 int state_id = psci_get_pstate_id(power_state);
42 int cpu = read_mpidr() & MPIDR_CPU_MASK;
43
Varun Wadekara78bb1b2015-08-07 10:03:00 +053044 /*
45 * Sanity check the requested state id, power level and CPU number.
46 * Currently T132 only supports SYSTEM_SUSPEND on last standing CPU
47 * i.e. CPU 0
48 */
Varun Wadekar6077dce2016-01-27 11:31:06 -080049 if ((state_id != PSTATE_ID_SOC_POWERDN) || (cpu != 0)) {
Varun Wadekara78bb1b2015-08-07 10:03:00 +053050 ERROR("unsupported state id @ power level\n");
51 return PSCI_E_INVALID_PARAMS;
Varun Wadekar0f3baa02015-07-16 11:36:33 +053052 }
53
Varun Wadekara78bb1b2015-08-07 10:03:00 +053054 /* Set lower power states to PLAT_MAX_OFF_STATE */
Varun Wadekar66231d12017-06-07 09:57:42 -070055 for (uint32_t i = MPIDR_AFFLVL0; i < PLAT_MAX_PWR_LVL; i++)
Varun Wadekara78bb1b2015-08-07 10:03:00 +053056 req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
57
58 /* Set the SYSTEM_SUSPEND state-id */
59 req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] =
60 PSTATE_ID_SOC_POWERDN;
61
Varun Wadekar0f3baa02015-07-16 11:36:33 +053062 return PSCI_E_SUCCESS;
63}
64
Varun Wadekara78bb1b2015-08-07 10:03:00 +053065int tegra_soc_pwr_domain_on(u_register_t mpidr)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053066{
67 int cpu = mpidr & MPIDR_CPU_MASK;
68 uint32_t mask = CPU_CORE_RESET_MASK << cpu;
69
70 if (cpu_powergate_mask[cpu] == 0) {
71
72 /* Deassert CPU reset signals */
73 mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask);
74
75 /* Power on CPU using PMC */
76 tegra_pmc_cpu_on(cpu);
77
78 /* Fill in the CPU powergate mask */
79 cpu_powergate_mask[cpu] = 1;
80
81 } else {
82 /* Power on CPU using Flow Controller */
83 tegra_fc_cpu_on(cpu);
84 }
85
86 return PSCI_E_SUCCESS;
87}
88
Varun Wadekar6eec6d62016-03-03 13:28:10 -080089int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
90{
91 /*
92 * Lock scratch registers which hold the CPU vectors
93 */
94 tegra_pmc_lock_cpu_vectors();
95
96 return PSCI_E_SUCCESS;
97}
98
Varun Wadekara78bb1b2015-08-07 10:03:00 +053099int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530100{
Steven Kaod417cea2017-06-14 14:02:23 +0800101 uint64_t val;
102
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530103 tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
Varun Wadekard43583c2016-02-22 11:09:41 -0800104
105 /* Disable DCO operations */
106 denver_disable_dco();
107
108 /* Power down the CPU */
Steven Kaod417cea2017-06-14 14:02:23 +0800109 val = read_actlr_el1() & ~ACTLR_EL1_PMSTATE_MASK;
110 write_actlr_el1(val | DENVER_CPU_STATE_POWER_DOWN);
Varun Wadekard43583c2016-02-22 11:09:41 -0800111
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530112 return PSCI_E_SUCCESS;
113}
114
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530115int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530116{
Steven Kaod417cea2017-06-14 14:02:23 +0800117 uint64_t val;
118
Antonio Nino Diaz7a4ff682017-03-28 13:56:21 +0100119#if ENABLE_ASSERTIONS
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530120 int cpu = read_mpidr() & MPIDR_CPU_MASK;
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530121
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530122 /* SYSTEM_SUSPEND only on CPU0 */
123 assert(cpu == 0);
124#endif
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530125
126 /* Allow restarting CPU #1 using PMC on suspend exit */
127 cpu_powergate_mask[1] = 0;
128
129 /* Program FC to enter suspend state */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530130 tegra_fc_cpu_powerdn(read_mpidr());
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530131
Varun Wadekard43583c2016-02-22 11:09:41 -0800132 /* Disable DCO operations */
133 denver_disable_dco();
134
135 /* Program the suspend state ID */
Steven Kaod417cea2017-06-14 14:02:23 +0800136 val = read_actlr_el1() & ~ACTLR_EL1_PMSTATE_MASK;
137 write_actlr_el1(val | target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530138
139 return PSCI_E_SUCCESS;
140}
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800141
142int tegra_soc_prepare_system_reset(void)
143{
144 /*
145 * Set System Clock (SCLK) to POR default so that the clock source
146 * for the PMC APB clock would not be changed due to system reset.
147 */
148 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
149 SCLK_BURST_POLICY_DEFAULT);
150 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
151
152 /* Wait 1 ms to make sure clock source/device logic is stabilized. */
153 mdelay(1);
154
155 return PSCI_E_SUCCESS;
156}