blob: d8827e101fe38bf4634366f41e9b7a15a6209554 [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
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 Zhouc33c1e32017-03-13 16:47:58 +080014#define RESET_ENABLE 0x10U
15
Varun Wadekarb316e242015-05-19 16:48:04 +053016/* Module IDs used during power ungate procedure */
Anthony Zhouc33c1e32017-03-13 16:47:58 +080017static const uint32_t pmc_cpu_powergate_id[4] = {
Varun Wadekarb316e242015-05-19 16:48:04 +053018 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 Zhouc33c1e32017-03-13 16:47:58 +080028void tegra_pmc_cpu_on(int32_t cpu)
Varun Wadekarb316e242015-05-19 16:48:04 +053029{
30 uint32_t val;
31
32 /*
Varun Wadekarfccf8e02015-07-16 10:35:12 +053033 * Check if CPU is already power ungated
34 */
35 val = tegra_pmc_read_32(PMC_PWRGATE_STATUS);
Anthony Zhouc33c1e32017-03-13 16:47:58 +080036 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 Wadekarb316e242015-05-19 16:48:04 +053044
Anthony Zhouc33c1e32017-03-13 16:47:58 +080045 /*
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 Wadekarb316e242015-05-19 16:48:04 +053050
Anthony Zhouc33c1e32017-03-13 16:47:58 +080051 /*
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 Wadekarb316e242015-05-19 16:48:04 +053058
Anthony Zhouc33c1e32017-03-13 16:47:58 +080059 /* 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 Wadekarb316e242015-05-19 16:48:04 +053064}
65
66/*******************************************************************************
67 * Setup CPU vectors for resume from deep sleep
68 ******************************************************************************/
69void tegra_pmc_cpu_setup(uint64_t reset_addr)
70{
71 uint32_t val;
72
Anthony Zhouc33c1e32017-03-13 16:47:58 +080073 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 Wadekarb316e242015-05-19 16:48:04 +053077}
78
79/*******************************************************************************
80 * Lock CPU vectors to restrict further writes
81 ******************************************************************************/
82void tegra_pmc_lock_cpu_vectors(void)
83{
84 uint32_t val;
85
Varun Wadekar30d89772015-07-16 10:38:11 +053086 /* 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 Wadekarb316e242015-05-19 16:48:04 +053091 /* 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 Zhouc33c1e32017-03-13 16:47:58 +0800106 reg |= RESET_ENABLE; /* restart */
Varun Wadekarb316e242015-05-19 16:48:04 +0530107 tegra_pmc_write_32(PMC_CONFIG, reg);
108 wfi();
109
110 ERROR("Tegra System Reset: operation not handled.\n");
111 panic();
112}