blob: f05f3d0e9f85c5f1cef3fd646d13990bcc19253c [file] [log] [blame]
Varun Wadekar0f3baa02015-07-16 11:36:33 +05301/*
Varun Wadekar6077dce2016-01-27 11:31:06 -08002 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
Varun Wadekar0f3baa02015-07-16 11:36:33 +05303 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <arch.h>
32#include <arch_helpers.h>
33#include <assert.h>
34#include <denver.h>
35#include <debug.h>
Varun Wadekar8b82fae2015-11-09 17:39:28 -080036#include <delay_timer.h>
Varun Wadekar0f3baa02015-07-16 11:36:33 +053037#include <flowctrl.h>
38#include <mmio.h>
39#include <platform_def.h>
40#include <pmc.h>
41#include <psci.h>
42#include <tegra_def.h>
43#include <tegra_private.h>
44
45/*
46 * Register used to clear CPU reset signals. Each CPU has two reset
47 * signals: CPU reset (3:0) and Core reset (19:16)
48 */
49#define CPU_CMPLX_RESET_CLR 0x344
50#define CPU_CORE_RESET_MASK 0x10001
51
Varun Wadekar8b82fae2015-11-09 17:39:28 -080052/* Clock and Reset controller registers for system clock's settings */
53#define SCLK_RATE 0x30
54#define SCLK_BURST_POLICY 0x28
55#define SCLK_BURST_POLICY_DEFAULT 0x10000000
56
Varun Wadekar0f3baa02015-07-16 11:36:33 +053057static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER];
58
Varun Wadekara78bb1b2015-08-07 10:03:00 +053059int32_t tegra_soc_validate_power_state(unsigned int power_state,
60 psci_power_state_t *req_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053061{
Varun Wadekara78bb1b2015-08-07 10:03:00 +053062 int state_id = psci_get_pstate_id(power_state);
63 int cpu = read_mpidr() & MPIDR_CPU_MASK;
64
Varun Wadekara78bb1b2015-08-07 10:03:00 +053065 /*
66 * Sanity check the requested state id, power level and CPU number.
67 * Currently T132 only supports SYSTEM_SUSPEND on last standing CPU
68 * i.e. CPU 0
69 */
Varun Wadekar6077dce2016-01-27 11:31:06 -080070 if ((state_id != PSTATE_ID_SOC_POWERDN) || (cpu != 0)) {
Varun Wadekara78bb1b2015-08-07 10:03:00 +053071 ERROR("unsupported state id @ power level\n");
72 return PSCI_E_INVALID_PARAMS;
Varun Wadekar0f3baa02015-07-16 11:36:33 +053073 }
74
Varun Wadekara78bb1b2015-08-07 10:03:00 +053075 /* Set lower power states to PLAT_MAX_OFF_STATE */
76 for (int i = MPIDR_AFFLVL0; i < PLAT_MAX_PWR_LVL; i++)
77 req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
78
79 /* Set the SYSTEM_SUSPEND state-id */
80 req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] =
81 PSTATE_ID_SOC_POWERDN;
82
Varun Wadekar0f3baa02015-07-16 11:36:33 +053083 return PSCI_E_SUCCESS;
84}
85
Varun Wadekara78bb1b2015-08-07 10:03:00 +053086int tegra_soc_pwr_domain_on(u_register_t mpidr)
Varun Wadekar0f3baa02015-07-16 11:36:33 +053087{
88 int cpu = mpidr & MPIDR_CPU_MASK;
89 uint32_t mask = CPU_CORE_RESET_MASK << cpu;
90
91 if (cpu_powergate_mask[cpu] == 0) {
92
93 /* Deassert CPU reset signals */
94 mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask);
95
96 /* Power on CPU using PMC */
97 tegra_pmc_cpu_on(cpu);
98
99 /* Fill in the CPU powergate mask */
100 cpu_powergate_mask[cpu] = 1;
101
102 } else {
103 /* Power on CPU using Flow Controller */
104 tegra_fc_cpu_on(cpu);
105 }
106
107 return PSCI_E_SUCCESS;
108}
109
Varun Wadekar6eec6d62016-03-03 13:28:10 -0800110int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
111{
112 /*
113 * Lock scratch registers which hold the CPU vectors
114 */
115 tegra_pmc_lock_cpu_vectors();
116
117 return PSCI_E_SUCCESS;
118}
119
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530120int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530121{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530122 tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
Varun Wadekard43583c2016-02-22 11:09:41 -0800123
124 /* Disable DCO operations */
125 denver_disable_dco();
126
127 /* Power down the CPU */
128 write_actlr_el1(DENVER_CPU_STATE_POWER_DOWN);
129
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530130 return PSCI_E_SUCCESS;
131}
132
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530133int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530134{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530135#if DEBUG
136 int cpu = read_mpidr() & MPIDR_CPU_MASK;
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530137
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530138 /* SYSTEM_SUSPEND only on CPU0 */
139 assert(cpu == 0);
140#endif
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530141
142 /* Allow restarting CPU #1 using PMC on suspend exit */
143 cpu_powergate_mask[1] = 0;
144
145 /* Program FC to enter suspend state */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530146 tegra_fc_cpu_powerdn(read_mpidr());
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530147
Varun Wadekard43583c2016-02-22 11:09:41 -0800148 /* Disable DCO operations */
149 denver_disable_dco();
150
151 /* Program the suspend state ID */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530152 write_actlr_el1(target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530153
154 return PSCI_E_SUCCESS;
155}
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800156
157int tegra_soc_prepare_system_reset(void)
158{
159 /*
160 * Set System Clock (SCLK) to POR default so that the clock source
161 * for the PMC APB clock would not be changed due to system reset.
162 */
163 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
164 SCLK_BURST_POLICY_DEFAULT);
165 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
166
167 /* Wait 1 ms to make sure clock source/device logic is stabilized. */
168 mdelay(1);
169
170 return PSCI_E_SUCCESS;
171}