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