Varun Wadekar | 0f3baa0 | 2015-07-16 11:36:33 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 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 | |
| 59 | int32_t tegra_soc_validate_power_state(unsigned int power_state) |
| 60 | { |
| 61 | /* Sanity check the requested afflvl */ |
| 62 | if (psci_get_pstate_type(power_state) == PSTATE_TYPE_STANDBY) { |
| 63 | /* |
| 64 | * It's possible to enter standby only on affinity level 0 i.e. |
| 65 | * a cpu on Tegra. Ignore any other affinity level. |
| 66 | */ |
| 67 | if (psci_get_pstate_afflvl(power_state) != MPIDR_AFFLVL0) |
| 68 | return PSCI_E_INVALID_PARAMS; |
| 69 | } |
| 70 | |
| 71 | /* Sanity check the requested state id */ |
| 72 | if (psci_get_pstate_id(power_state) != PLAT_SYS_SUSPEND_STATE_ID) { |
| 73 | ERROR("unsupported state id\n"); |
| 74 | return PSCI_E_NOT_SUPPORTED; |
| 75 | } |
| 76 | |
| 77 | return PSCI_E_SUCCESS; |
| 78 | } |
| 79 | |
| 80 | int tegra_soc_prepare_cpu_on(unsigned long mpidr) |
| 81 | { |
| 82 | int cpu = mpidr & MPIDR_CPU_MASK; |
| 83 | uint32_t mask = CPU_CORE_RESET_MASK << cpu; |
| 84 | |
| 85 | if (cpu_powergate_mask[cpu] == 0) { |
| 86 | |
| 87 | /* Deassert CPU reset signals */ |
| 88 | mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask); |
| 89 | |
| 90 | /* Power on CPU using PMC */ |
| 91 | tegra_pmc_cpu_on(cpu); |
| 92 | |
| 93 | /* Fill in the CPU powergate mask */ |
| 94 | cpu_powergate_mask[cpu] = 1; |
| 95 | |
| 96 | } else { |
| 97 | /* Power on CPU using Flow Controller */ |
| 98 | tegra_fc_cpu_on(cpu); |
| 99 | } |
| 100 | |
| 101 | return PSCI_E_SUCCESS; |
| 102 | } |
| 103 | |
| 104 | int tegra_soc_prepare_cpu_off(unsigned long mpidr) |
| 105 | { |
| 106 | tegra_fc_cpu_off(mpidr & MPIDR_CPU_MASK); |
| 107 | return PSCI_E_SUCCESS; |
| 108 | } |
| 109 | |
| 110 | int tegra_soc_prepare_cpu_suspend(unsigned int id, unsigned int afflvl) |
| 111 | { |
| 112 | /* Nothing to be done for lower affinity levels */ |
| 113 | if (afflvl < MPIDR_AFFLVL2) |
| 114 | return PSCI_E_SUCCESS; |
| 115 | |
| 116 | /* Enter system suspend state */ |
| 117 | tegra_pm_system_suspend_entry(); |
| 118 | |
| 119 | /* Allow restarting CPU #1 using PMC on suspend exit */ |
| 120 | cpu_powergate_mask[1] = 0; |
| 121 | |
| 122 | /* Program FC to enter suspend state */ |
| 123 | tegra_fc_cpu_idle(read_mpidr()); |
| 124 | |
| 125 | /* Suspend DCO operations */ |
| 126 | write_actlr_el1(id); |
| 127 | |
| 128 | return PSCI_E_SUCCESS; |
| 129 | } |
Varun Wadekar | 8b82fae | 2015-11-09 17:39:28 -0800 | [diff] [blame] | 130 | |
| 131 | int tegra_soc_prepare_system_reset(void) |
| 132 | { |
| 133 | /* |
| 134 | * Set System Clock (SCLK) to POR default so that the clock source |
| 135 | * for the PMC APB clock would not be changed due to system reset. |
| 136 | */ |
| 137 | mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY, |
| 138 | SCLK_BURST_POLICY_DEFAULT); |
| 139 | mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0); |
| 140 | |
| 141 | /* Wait 1 ms to make sure clock source/device logic is stabilized. */ |
| 142 | mdelay(1); |
| 143 | |
| 144 | return PSCI_E_SUCCESS; |
| 145 | } |