Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 6077dce | 2016-01-27 11:31:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 3 | * |
| 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 Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 36 | #include <delay_timer.h> |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 37 | #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 Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 52 | /* 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 Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 57 | static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER]; |
| 58 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 59 | int32_t tegra_soc_validate_power_state(unsigned int power_state, |
| 60 | psci_power_state_t *req_state) |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 61 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 62 | int state_id = psci_get_pstate_id(power_state); |
| 63 | int cpu = read_mpidr() & MPIDR_CPU_MASK; |
| 64 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 65 | /* |
| 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 Wadekar | 6077dce | 2016-01-27 11:31:06 -0800 | [diff] [blame] | 70 | if ((state_id != PSTATE_ID_SOC_POWERDN) || (cpu != 0)) { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 71 | ERROR("unsupported state id @ power level\n"); |
| 72 | return PSCI_E_INVALID_PARAMS; |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 73 | } |
| 74 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 75 | /* 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 Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 83 | return PSCI_E_SUCCESS; |
| 84 | } |
| 85 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 86 | int tegra_soc_pwr_domain_on(u_register_t mpidr) |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 87 | { |
| 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 Wadekar | 6eec6d6 | 2016-03-03 13:28:10 -0800 | [diff] [blame] | 110 | int 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 Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 120 | int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state) |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 121 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 122 | tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK); |
Varun Wadekar | d43583c | 2016-02-22 11:09:41 -0800 | [diff] [blame] | 123 | |
| 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 Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 130 | return PSCI_E_SUCCESS; |
| 131 | } |
| 132 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 133 | int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state) |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 134 | { |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 135 | #if DEBUG |
| 136 | int cpu = read_mpidr() & MPIDR_CPU_MASK; |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 137 | |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 138 | /* SYSTEM_SUSPEND only on CPU0 */ |
| 139 | assert(cpu == 0); |
| 140 | #endif |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 141 | |
| 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 Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 146 | tegra_fc_cpu_powerdn(read_mpidr()); |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 147 | |
Varun Wadekar | d43583c | 2016-02-22 11:09:41 -0800 | [diff] [blame] | 148 | /* Disable DCO operations */ |
| 149 | denver_disable_dco(); |
| 150 | |
| 151 | /* Program the suspend state ID */ |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 152 | write_actlr_el1(target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]); |
Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 153 | |
| 154 | return PSCI_E_SUCCESS; |
| 155 | } |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 156 | |
| 157 | int 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 | } |