blob: 09b52f559f098a5cbfd8291bc88894ea618f9b93 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Warren4040ec12013-01-28 13:32:08 +00002/*
Tom Warren722e0002015-06-25 09:50:44 -07003 * (C) Copyright 2010-2014
4 * NVIDIA Corporation <www.nvidia.com>
Tom Warren4040ec12013-01-28 13:32:08 +00005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/flow.h>
11#include <asm/arch/pinmux.h>
12#include <asm/arch/tegra.h>
13#include <asm/arch-tegra/clk_rst.h>
14#include <asm/arch-tegra/pmc.h>
Masahiro Yamada09f455d2015-02-20 17:04:04 +090015#include "../cpu.h"
Tom Warren4040ec12013-01-28 13:32:08 +000016
17/* Tegra114-specific CPU init code */
18static void enable_cpu_power_rail(void)
19{
20 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
21 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
22 u32 reg;
23
Tom Warren722e0002015-06-25 09:50:44 -070024 debug("%s entry\n", __func__);
Tom Warren4040ec12013-01-28 13:32:08 +000025
26 /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
Stephen Warren1fa3a632014-03-21 12:29:00 -060027 pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SCL_PZ6);
28 pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SDA_PZ7);
Tom Warren4040ec12013-01-28 13:32:08 +000029
30 /*
31 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
32 * set it for 25ms (102MHz * .025)
33 */
34 reg = 0x26E8F0;
35 writel(reg, &pmc->pmc_cpupwrgood_timer);
36
37 /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
38 clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
39 setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
40
41 /*
42 * Set CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2_0_CAR2PMC_CPU_ACK_WIDTH
43 * to 408 to satisfy the requirement of having at least 16 CPU clock
44 * cycles before clamp removal.
45 */
46
47 clrbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 0xFFF);
48 setbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 408);
49}
50
51static void enable_cpu_clocks(void)
52{
53 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Tom Warren722e0002015-06-25 09:50:44 -070054 struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
Tom Warren4040ec12013-01-28 13:32:08 +000055 u32 reg;
56
Tom Warren722e0002015-06-25 09:50:44 -070057 debug("%s entry\n", __func__);
Tom Warren4040ec12013-01-28 13:32:08 +000058
59 /* Wait for PLL-X to lock */
60 do {
61 reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
Tom Warren722e0002015-06-25 09:50:44 -070062 } while ((reg & (1 << pllinfo->lock_det)) == 0);
Tom Warren4040ec12013-01-28 13:32:08 +000063
64 /* Wait until all clocks are stable */
65 udelay(PLL_STABILIZATION_DELAY);
66
67 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
68 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
69
70 /* Always enable the main CPU complex clocks */
71 clock_enable(PERIPH_ID_CPU);
72 clock_enable(PERIPH_ID_CPULP);
73 clock_enable(PERIPH_ID_CPUG);
74}
75
76static void remove_cpu_resets(void)
77{
78 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
79 u32 reg;
80
Tom Warren722e0002015-06-25 09:50:44 -070081 debug("%s entry\n", __func__);
Tom Warren4040ec12013-01-28 13:32:08 +000082 /* Take the slow non-CPU partition out of reset */
83 reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
84 writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpulp_cmplx_clr);
85
86 /* Take the fast non-CPU partition out of reset */
87 reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
88 writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpug_cmplx_clr);
89
90 /* Clear the SW-controlled reset of the slow cluster */
91 reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
92 reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
93 writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
94
95 /* Clear the SW-controlled reset of the fast cluster */
96 reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
97 reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
98 reg |= (CLR_CPURESET1+CLR_DBGRESET1+CLR_CORERESET1+CLR_CXRESET1);
99 reg |= (CLR_CPURESET2+CLR_DBGRESET2+CLR_CORERESET2+CLR_CXRESET2);
100 reg |= (CLR_CPURESET3+CLR_DBGRESET3+CLR_CORERESET3+CLR_CXRESET3);
101 writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
102}
103
104/**
Tom Warren722e0002015-06-25 09:50:44 -0700105 * Tegra114 requires some special clock initialization, including setting up
Tom Warren4040ec12013-01-28 13:32:08 +0000106 * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
107 */
108void t114_init_clocks(void)
109{
110 struct clk_rst_ctlr *clkrst =
111 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
112 struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
113 u32 val;
114
Tom Warren722e0002015-06-25 09:50:44 -0700115 debug("%s entry\n", __func__);
Tom Warren4040ec12013-01-28 13:32:08 +0000116
117 /* Set active CPU cluster to G */
118 clrbits_le32(&flow->cluster_control, 1);
119
Tom Warren4040ec12013-01-28 13:32:08 +0000120 writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
121
122 debug("Setting up PLLX\n");
123 init_pllx();
124
125 val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
126 writel(val, &clkrst->crc_clk_sys_rate);
127
128 /* Enable clocks to required peripherals. TBD - minimize this list */
129 debug("Enabling clocks\n");
130
131 clock_set_enable(PERIPH_ID_CACHE2, 1);
132 clock_set_enable(PERIPH_ID_GPIO, 1);
133 clock_set_enable(PERIPH_ID_TMR, 1);
134 clock_set_enable(PERIPH_ID_RTC, 1);
135 clock_set_enable(PERIPH_ID_CPU, 1);
136 clock_set_enable(PERIPH_ID_EMC, 1);
137 clock_set_enable(PERIPH_ID_I2C5, 1);
138 clock_set_enable(PERIPH_ID_FUSE, 1);
139 clock_set_enable(PERIPH_ID_PMC, 1);
140 clock_set_enable(PERIPH_ID_APBDMA, 1);
141 clock_set_enable(PERIPH_ID_MEM, 1);
142 clock_set_enable(PERIPH_ID_IRAMA, 1);
143 clock_set_enable(PERIPH_ID_IRAMB, 1);
144 clock_set_enable(PERIPH_ID_IRAMC, 1);
145 clock_set_enable(PERIPH_ID_IRAMD, 1);
146 clock_set_enable(PERIPH_ID_CORESIGHT, 1);
147 clock_set_enable(PERIPH_ID_MSELECT, 1);
148 clock_set_enable(PERIPH_ID_EMC1, 1);
149 clock_set_enable(PERIPH_ID_MC1, 1);
150 clock_set_enable(PERIPH_ID_DVFS, 1);
151
Tom Warren4040ec12013-01-28 13:32:08 +0000152 /*
Tom Warrend94c2db2013-04-03 14:39:30 -0700153 * Set MSELECT clock source as PLLP (00), and ask for a clock
154 * divider that would set the MSELECT clock at 102MHz for a
155 * PLLP base of 408MHz.
Tom Warren4040ec12013-01-28 13:32:08 +0000156 */
157 clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
Tom Warrend94c2db2013-04-03 14:39:30 -0700158 CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
Tom Warren4040ec12013-01-28 13:32:08 +0000159
160 /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
161 clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
162
163 /* Give clocks time to stabilize */
164 udelay(1000);
165
166 /* Take required peripherals out of reset */
167 debug("Taking periphs out of reset\n");
168 reset_set_enable(PERIPH_ID_CACHE2, 0);
169 reset_set_enable(PERIPH_ID_GPIO, 0);
170 reset_set_enable(PERIPH_ID_TMR, 0);
171 reset_set_enable(PERIPH_ID_COP, 0);
172 reset_set_enable(PERIPH_ID_EMC, 0);
173 reset_set_enable(PERIPH_ID_I2C5, 0);
174 reset_set_enable(PERIPH_ID_FUSE, 0);
175 reset_set_enable(PERIPH_ID_APBDMA, 0);
176 reset_set_enable(PERIPH_ID_MEM, 0);
177 reset_set_enable(PERIPH_ID_CORESIGHT, 0);
178 reset_set_enable(PERIPH_ID_MSELECT, 0);
179 reset_set_enable(PERIPH_ID_EMC1, 0);
180 reset_set_enable(PERIPH_ID_MC1, 0);
Tom Warren702b8722013-02-27 11:10:01 +0000181 reset_set_enable(PERIPH_ID_DVFS, 0);
Tom Warren4040ec12013-01-28 13:32:08 +0000182
Tom Warren722e0002015-06-25 09:50:44 -0700183 debug("%s exit\n", __func__);
Tom Warren4040ec12013-01-28 13:32:08 +0000184}
185
Stephen Warrencad38a52014-01-24 12:46:08 -0700186static bool is_partition_powered(u32 partid)
Tom Warren4040ec12013-01-28 13:32:08 +0000187{
188 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
189 u32 reg;
190
191 /* Get power gate status */
192 reg = readl(&pmc->pmc_pwrgate_status);
Stephen Warrencad38a52014-01-24 12:46:08 -0700193 return !!(reg & (1 << partid));
Tom Warren4040ec12013-01-28 13:32:08 +0000194}
195
Stephen Warrencad38a52014-01-24 12:46:08 -0700196static bool is_clamp_enabled(u32 partid)
Tom Warren4040ec12013-01-28 13:32:08 +0000197{
198 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
199 u32 reg;
200
Stephen Warren9399e542014-01-24 10:23:02 -0700201 /* Get clamp status. */
202 reg = readl(&pmc->pmc_clamp_status);
Stephen Warrencad38a52014-01-24 12:46:08 -0700203 return !!(reg & (1 << partid));
Tom Warren4040ec12013-01-28 13:32:08 +0000204}
205
Stephen Warrencad38a52014-01-24 12:46:08 -0700206static void power_partition(u32 partid)
Tom Warren4040ec12013-01-28 13:32:08 +0000207{
208 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
209
Stephen Warrencad38a52014-01-24 12:46:08 -0700210 debug("%s: part ID = %08X\n", __func__, partid);
Tom Warren4040ec12013-01-28 13:32:08 +0000211 /* Is the partition already on? */
Stephen Warrencad38a52014-01-24 12:46:08 -0700212 if (!is_partition_powered(partid)) {
Tom Warren4040ec12013-01-28 13:32:08 +0000213 /* No, toggle the partition power state (OFF -> ON) */
214 debug("power_partition, toggling state\n");
Stephen Warren41cd5302014-01-24 12:46:07 -0700215 writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
Tom Warren4040ec12013-01-28 13:32:08 +0000216
217 /* Wait for the power to come up */
Stephen Warrencad38a52014-01-24 12:46:08 -0700218 while (!is_partition_powered(partid))
Tom Warren4040ec12013-01-28 13:32:08 +0000219 ;
220
221 /* Wait for the clamp status to be cleared */
Stephen Warrencad38a52014-01-24 12:46:08 -0700222 while (is_clamp_enabled(partid))
Tom Warren4040ec12013-01-28 13:32:08 +0000223 ;
224
225 /* Give I/O signals time to stabilize */
226 udelay(IO_STABILIZATION_DELAY);
227 }
228}
229
230void powerup_cpus(void)
231{
Tom Warren4040ec12013-01-28 13:32:08 +0000232 /* We boot to the fast cluster */
Tom Warren722e0002015-06-25 09:50:44 -0700233 debug("%s entry: G cluster\n", __func__);
234
Tom Warren4040ec12013-01-28 13:32:08 +0000235 /* Power up the fast cluster rail partition */
Stephen Warrencad38a52014-01-24 12:46:08 -0700236 power_partition(CRAIL);
Tom Warren4040ec12013-01-28 13:32:08 +0000237
238 /* Power up the fast cluster non-CPU partition */
Stephen Warrencad38a52014-01-24 12:46:08 -0700239 power_partition(C0NC);
Tom Warren4040ec12013-01-28 13:32:08 +0000240
241 /* Power up the fast cluster CPU0 partition */
Stephen Warrencad38a52014-01-24 12:46:08 -0700242 power_partition(CE0);
Tom Warren4040ec12013-01-28 13:32:08 +0000243}
244
245void start_cpu(u32 reset_vector)
246{
Stephen Warren16bb08d2013-02-28 12:40:09 +0000247 u32 imme, inst;
248
Tom Warren722e0002015-06-25 09:50:44 -0700249 debug("%s entry, reset_vector = %x\n", __func__, reset_vector);
Tom Warren4040ec12013-01-28 13:32:08 +0000250
251 t114_init_clocks();
252
253 /* Enable VDD_CPU */
254 enable_cpu_power_rail();
255
256 /* Get the CPU(s) running */
257 enable_cpu_clocks();
258
259 /* Enable CoreSight */
260 clock_enable_coresight(1);
261
262 /* Take CPU(s) out of reset */
263 remove_cpu_resets();
264
Stephen Warren16bb08d2013-02-28 12:40:09 +0000265 /* Set the entry point for CPU execution from reset */
266
Tom Warren4040ec12013-01-28 13:32:08 +0000267 /*
Stephen Warren16bb08d2013-02-28 12:40:09 +0000268 * A01P with patched boot ROM; vector hard-coded to 0x4003fffc.
269 * See nvbug 1193357 for details.
Tom Warren4040ec12013-01-28 13:32:08 +0000270 */
Stephen Warren16bb08d2013-02-28 12:40:09 +0000271
272 /* mov r0, #lsb(reset_vector) */
273 imme = reset_vector & 0xffff;
274 inst = imme & 0xfff;
275 inst |= ((imme >> 12) << 16);
276 inst |= 0xe3000000;
277 writel(inst, 0x4003fff0);
278
279 /* movt r0, #msb(reset_vector) */
280 imme = (reset_vector >> 16) & 0xffff;
281 inst = imme & 0xfff;
282 inst |= ((imme >> 12) << 16);
283 inst |= 0xe3400000;
284 writel(inst, 0x4003fff4);
285
286 /* bx r0 */
287 writel(0xe12fff10, 0x4003fff8);
288
289 /* b -12 */
290 imme = (u32)-20;
291 inst = (imme >> 2) & 0xffffff;
292 inst |= 0xea000000;
293 writel(inst, 0x4003fffc);
294
Tom Warren722e0002015-06-25 09:50:44 -0700295 /* Write to original location for compatibility */
Stephen Warren16bb08d2013-02-28 12:40:09 +0000296 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
Tom Warren4040ec12013-01-28 13:32:08 +0000297
298 /* If the CPU(s) don't already have power, power 'em up */
299 powerup_cpus();
300}