Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame^] | 8 | |
| 9 | #include <arch_helpers.h> |
| 10 | #include <common/debug.h> |
| 11 | #include <lib/mmio.h> |
| 12 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 13 | #include <pmc.h> |
| 14 | #include <tegra_def.h> |
| 15 | |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 16 | #define RESET_ENABLE 0x10U |
| 17 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 18 | /* Module IDs used during power ungate procedure */ |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 19 | static const uint32_t pmc_cpu_powergate_id[4] = { |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 20 | 0, /* CPU 0 */ |
| 21 | 9, /* CPU 1 */ |
| 22 | 10, /* CPU 2 */ |
| 23 | 11 /* CPU 3 */ |
| 24 | }; |
| 25 | |
| 26 | /******************************************************************************* |
| 27 | * Power ungate CPU to start the boot process. CPU reset vectors must be |
| 28 | * populated before calling this function. |
| 29 | ******************************************************************************/ |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 30 | void tegra_pmc_cpu_on(int32_t cpu) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 31 | { |
| 32 | uint32_t val; |
| 33 | |
| 34 | /* |
Varun Wadekar | fccf8e0 | 2015-07-16 10:35:12 +0530 | [diff] [blame] | 35 | * Check if CPU is already power ungated |
| 36 | */ |
| 37 | val = tegra_pmc_read_32(PMC_PWRGATE_STATUS); |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 38 | if ((val & (1U << pmc_cpu_powergate_id[cpu])) == 0U) { |
| 39 | /* |
| 40 | * The PMC deasserts the START bit when it starts the power |
| 41 | * ungate process. Loop till no power toggle is in progress. |
| 42 | */ |
| 43 | do { |
| 44 | val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE); |
| 45 | } while ((val & PMC_TOGGLE_START) != 0U); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 46 | |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 47 | /* |
| 48 | * Start the power ungate procedure |
| 49 | */ |
| 50 | val = pmc_cpu_powergate_id[cpu] | PMC_TOGGLE_START; |
| 51 | tegra_pmc_write_32(PMC_PWRGATE_TOGGLE, val); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 52 | |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 53 | /* |
| 54 | * The PMC deasserts the START bit when it starts the power |
| 55 | * ungate process. Loop till powergate START bit is asserted. |
| 56 | */ |
| 57 | do { |
| 58 | val = tegra_pmc_read_32(PMC_PWRGATE_TOGGLE); |
| 59 | } while ((val & (1U << 8)) != 0U); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 60 | |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 61 | /* loop till the CPU is power ungated */ |
| 62 | do { |
| 63 | val = tegra_pmc_read_32(PMC_PWRGATE_STATUS); |
| 64 | } while ((val & (1U << pmc_cpu_powergate_id[cpu])) == 0U); |
| 65 | } |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /******************************************************************************* |
| 69 | * Setup CPU vectors for resume from deep sleep |
| 70 | ******************************************************************************/ |
| 71 | void tegra_pmc_cpu_setup(uint64_t reset_addr) |
| 72 | { |
| 73 | uint32_t val; |
| 74 | |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 75 | tegra_pmc_write_32(PMC_SECURE_SCRATCH34, |
| 76 | ((uint32_t)reset_addr & 0xFFFFFFFFU) | 1U); |
| 77 | val = (uint32_t)(reset_addr >> 32U); |
| 78 | tegra_pmc_write_32(PMC_SECURE_SCRATCH35, val & 0x7FFU); |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /******************************************************************************* |
| 82 | * Lock CPU vectors to restrict further writes |
| 83 | ******************************************************************************/ |
| 84 | void tegra_pmc_lock_cpu_vectors(void) |
| 85 | { |
| 86 | uint32_t val; |
| 87 | |
Varun Wadekar | 30d8977 | 2015-07-16 10:38:11 +0530 | [diff] [blame] | 88 | /* lock PMC_SECURE_SCRATCH22 */ |
| 89 | val = tegra_pmc_read_32(PMC_SECURE_DISABLE2); |
| 90 | val |= PMC_SECURE_DISABLE2_WRITE22_ON; |
| 91 | tegra_pmc_write_32(PMC_SECURE_DISABLE2, val); |
| 92 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 93 | /* lock PMC_SECURE_SCRATCH34/35 */ |
| 94 | val = tegra_pmc_read_32(PMC_SECURE_DISABLE3); |
| 95 | val |= (PMC_SECURE_DISABLE3_WRITE34_ON | |
| 96 | PMC_SECURE_DISABLE3_WRITE35_ON); |
| 97 | tegra_pmc_write_32(PMC_SECURE_DISABLE3, val); |
| 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | * Restart the system |
| 102 | ******************************************************************************/ |
| 103 | __dead2 void tegra_pmc_system_reset(void) |
| 104 | { |
| 105 | uint32_t reg; |
| 106 | |
| 107 | reg = tegra_pmc_read_32(PMC_CONFIG); |
Anthony Zhou | c33c1e3 | 2017-03-13 16:47:58 +0800 | [diff] [blame] | 108 | reg |= RESET_ENABLE; /* restart */ |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 109 | tegra_pmc_write_32(PMC_CONFIG, reg); |
| 110 | wfi(); |
| 111 | |
| 112 | ERROR("Tegra System Reset: operation not handled.\n"); |
| 113 | panic(); |
| 114 | } |