blob: bc7a7cced9e6054eb79268b5b875738af6bfe803 [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 Wadekara78bb1b2015-08-07 10:03:00 +0530110int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530111{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530112 tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530113 return PSCI_E_SUCCESS;
114}
115
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530116int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530117{
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530118#if DEBUG
119 int cpu = read_mpidr() & MPIDR_CPU_MASK;
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530120
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530121 /* SYSTEM_SUSPEND only on CPU0 */
122 assert(cpu == 0);
123#endif
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530124
125 /* Allow restarting CPU #1 using PMC on suspend exit */
126 cpu_powergate_mask[1] = 0;
127
128 /* Program FC to enter suspend state */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530129 tegra_fc_cpu_powerdn(read_mpidr());
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530130
131 /* Suspend DCO operations */
Varun Wadekara78bb1b2015-08-07 10:03:00 +0530132 write_actlr_el1(target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]);
Varun Wadekar0f3baa02015-07-16 11:36:33 +0530133
134 return PSCI_E_SUCCESS;
135}
Varun Wadekar8b82fae2015-11-09 17:39:28 -0800136
137int tegra_soc_prepare_system_reset(void)
138{
139 /*
140 * Set System Clock (SCLK) to POR default so that the clock source
141 * for the PMC APB clock would not be changed due to system reset.
142 */
143 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
144 SCLK_BURST_POLICY_DEFAULT);
145 mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
146
147 /* Wait 1 ms to make sure clock source/device logic is stabilized. */
148 mdelay(1);
149
150 return PSCI_E_SUCCESS;
151}