blob: b9ff5116d67ae99fe4ffedf9ac34043cebf7dd60 [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarb316e242015-05-19 16:48:04 +05305 */
6
Varun Wadekarb316e242015-05-19 16:48:04 +05307#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch_helpers.h>
10#include <common/debug.h>
11#include <lib/mmio.h>
12
Varun Wadekarb316e242015-05-19 16:48:04 +053013#include <pmc.h>
14#include <tegra_def.h>
15
Anthony Zhouc33c1e32017-03-13 16:47:58 +080016#define RESET_ENABLE 0x10U
17
Varun Wadekarb316e242015-05-19 16:48:04 +053018/* Module IDs used during power ungate procedure */
Anthony Zhouc33c1e32017-03-13 16:47:58 +080019static const uint32_t pmc_cpu_powergate_id[4] = {
Varun Wadekarb316e242015-05-19 16:48:04 +053020 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 Zhouc33c1e32017-03-13 16:47:58 +080030void tegra_pmc_cpu_on(int32_t cpu)
Varun Wadekarb316e242015-05-19 16:48:04 +053031{
32 uint32_t val;
33
34 /*
Varun Wadekarfccf8e02015-07-16 10:35:12 +053035 * Check if CPU is already power ungated
36 */
37 val = tegra_pmc_read_32(PMC_PWRGATE_STATUS);
Anthony Zhouc33c1e32017-03-13 16:47:58 +080038 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 Wadekarb316e242015-05-19 16:48:04 +053046
Anthony Zhouc33c1e32017-03-13 16:47:58 +080047 /*
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 Wadekarb316e242015-05-19 16:48:04 +053052
Anthony Zhouc33c1e32017-03-13 16:47:58 +080053 /*
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 Wadekarb316e242015-05-19 16:48:04 +053060
Anthony Zhouc33c1e32017-03-13 16:47:58 +080061 /* 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 Wadekarb316e242015-05-19 16:48:04 +053066}
67
68/*******************************************************************************
69 * Setup CPU vectors for resume from deep sleep
70 ******************************************************************************/
71void tegra_pmc_cpu_setup(uint64_t reset_addr)
72{
73 uint32_t val;
74
Anthony Zhouc33c1e32017-03-13 16:47:58 +080075 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 Wadekarb316e242015-05-19 16:48:04 +053079}
80
81/*******************************************************************************
82 * Lock CPU vectors to restrict further writes
83 ******************************************************************************/
84void tegra_pmc_lock_cpu_vectors(void)
85{
86 uint32_t val;
87
Varun Wadekar30d89772015-07-16 10:38:11 +053088 /* 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 Wadekarb316e242015-05-19 16:48:04 +053093 /* 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 Zhouc33c1e32017-03-13 16:47:58 +0800108 reg |= RESET_ENABLE; /* restart */
Varun Wadekarb316e242015-05-19 16:48:04 +0530109 tegra_pmc_write_32(PMC_CONFIG, reg);
110 wfi();
111
112 ERROR("Tegra System Reset: operation not handled.\n");
113 panic();
114}