blob: 3fe2d2d73246584b2a3777093b4ae6de96536641 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Warrend034d1b2013-01-28 13:32:08 +00002/*
Tom Warrena8480ef2015-06-25 09:50:44 -07003 * (C) Copyright 2010-2014
4 * NVIDIA Corporation <www.nvidia.com>
Tom Warrend034d1b2013-01-28 13:32:08 +00005 */
6
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Tom Warrend034d1b2013-01-28 13:32:08 +00008#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>
Svyatoslav Ryhel1fb30512023-10-03 09:36:43 +030015#include <asm/arch-tegra/tegra_i2c.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Masahiro Yamadaed1632a2015-02-20 17:04:04 +090017#include "../cpu.h"
Tom Warrend034d1b2013-01-28 13:32:08 +000018
Svyatoslav Ryhel1fb30512023-10-03 09:36:43 +030019/* In case this function is not defined */
20__weak void pmic_enable_cpu_vdd(void) {}
21
Tom Warrend034d1b2013-01-28 13:32:08 +000022/* Tegra114-specific CPU init code */
23static void enable_cpu_power_rail(void)
24{
25 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
26 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
27 u32 reg;
28
Tom Warrena8480ef2015-06-25 09:50:44 -070029 debug("%s entry\n", __func__);
Tom Warrend034d1b2013-01-28 13:32:08 +000030
31 /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
Stephen Warren05617092014-03-21 12:29:00 -060032 pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SCL_PZ6);
33 pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SDA_PZ7);
Tom Warrend034d1b2013-01-28 13:32:08 +000034
35 /*
36 * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
37 * set it for 25ms (102MHz * .025)
38 */
39 reg = 0x26E8F0;
40 writel(reg, &pmc->pmc_cpupwrgood_timer);
41
42 /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
43 clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
44 setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
45
46 /*
47 * Set CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2_0_CAR2PMC_CPU_ACK_WIDTH
48 * to 408 to satisfy the requirement of having at least 16 CPU clock
49 * cycles before clamp removal.
50 */
51
52 clrbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 0xFFF);
53 setbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 408);
54}
55
56static void enable_cpu_clocks(void)
57{
58 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
Tom Warrena8480ef2015-06-25 09:50:44 -070059 struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
Tom Warrend034d1b2013-01-28 13:32:08 +000060 u32 reg;
61
Tom Warrena8480ef2015-06-25 09:50:44 -070062 debug("%s entry\n", __func__);
Tom Warrend034d1b2013-01-28 13:32:08 +000063
64 /* Wait for PLL-X to lock */
65 do {
66 reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
Tom Warrena8480ef2015-06-25 09:50:44 -070067 } while ((reg & (1 << pllinfo->lock_det)) == 0);
Tom Warrend034d1b2013-01-28 13:32:08 +000068
69 /* Wait until all clocks are stable */
70 udelay(PLL_STABILIZATION_DELAY);
71
72 writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
73 writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
74
75 /* Always enable the main CPU complex clocks */
76 clock_enable(PERIPH_ID_CPU);
77 clock_enable(PERIPH_ID_CPULP);
78 clock_enable(PERIPH_ID_CPUG);
79}
80
81static void remove_cpu_resets(void)
82{
83 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
84 u32 reg;
85
Tom Warrena8480ef2015-06-25 09:50:44 -070086 debug("%s entry\n", __func__);
Tom Warrend034d1b2013-01-28 13:32:08 +000087 /* Take the slow non-CPU partition out of reset */
88 reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
89 writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpulp_cmplx_clr);
90
91 /* Take the fast non-CPU partition out of reset */
92 reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
93 writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpug_cmplx_clr);
94
95 /* Clear the SW-controlled reset of the slow cluster */
96 reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
97 reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
98 writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
99
100 /* Clear the SW-controlled reset of the fast cluster */
101 reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
102 reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
103 reg |= (CLR_CPURESET1+CLR_DBGRESET1+CLR_CORERESET1+CLR_CXRESET1);
104 reg |= (CLR_CPURESET2+CLR_DBGRESET2+CLR_CORERESET2+CLR_CXRESET2);
105 reg |= (CLR_CPURESET3+CLR_DBGRESET3+CLR_CORERESET3+CLR_CXRESET3);
106 writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
107}
108
109/**
Tom Warrena8480ef2015-06-25 09:50:44 -0700110 * Tegra114 requires some special clock initialization, including setting up
Tom Warrend034d1b2013-01-28 13:32:08 +0000111 * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
112 */
113void t114_init_clocks(void)
114{
115 struct clk_rst_ctlr *clkrst =
116 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
117 struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
118 u32 val;
119
Tom Warrena8480ef2015-06-25 09:50:44 -0700120 debug("%s entry\n", __func__);
Tom Warrend034d1b2013-01-28 13:32:08 +0000121
122 /* Set active CPU cluster to G */
123 clrbits_le32(&flow->cluster_control, 1);
124
Tom Warrend034d1b2013-01-28 13:32:08 +0000125 writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
126
127 debug("Setting up PLLX\n");
128 init_pllx();
129
130 val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
131 writel(val, &clkrst->crc_clk_sys_rate);
132
133 /* Enable clocks to required peripherals. TBD - minimize this list */
134 debug("Enabling clocks\n");
135
136 clock_set_enable(PERIPH_ID_CACHE2, 1);
137 clock_set_enable(PERIPH_ID_GPIO, 1);
138 clock_set_enable(PERIPH_ID_TMR, 1);
139 clock_set_enable(PERIPH_ID_RTC, 1);
140 clock_set_enable(PERIPH_ID_CPU, 1);
141 clock_set_enable(PERIPH_ID_EMC, 1);
142 clock_set_enable(PERIPH_ID_I2C5, 1);
143 clock_set_enable(PERIPH_ID_FUSE, 1);
144 clock_set_enable(PERIPH_ID_PMC, 1);
145 clock_set_enable(PERIPH_ID_APBDMA, 1);
146 clock_set_enable(PERIPH_ID_MEM, 1);
147 clock_set_enable(PERIPH_ID_IRAMA, 1);
148 clock_set_enable(PERIPH_ID_IRAMB, 1);
149 clock_set_enable(PERIPH_ID_IRAMC, 1);
150 clock_set_enable(PERIPH_ID_IRAMD, 1);
151 clock_set_enable(PERIPH_ID_CORESIGHT, 1);
152 clock_set_enable(PERIPH_ID_MSELECT, 1);
153 clock_set_enable(PERIPH_ID_EMC1, 1);
154 clock_set_enable(PERIPH_ID_MC1, 1);
155 clock_set_enable(PERIPH_ID_DVFS, 1);
156
Tom Warrend034d1b2013-01-28 13:32:08 +0000157 /*
Tom Warren4dae96b2013-04-03 14:39:30 -0700158 * Set MSELECT clock source as PLLP (00), and ask for a clock
159 * divider that would set the MSELECT clock at 102MHz for a
160 * PLLP base of 408MHz.
Tom Warrend034d1b2013-01-28 13:32:08 +0000161 */
162 clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
Tom Warren4dae96b2013-04-03 14:39:30 -0700163 CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
Tom Warrend034d1b2013-01-28 13:32:08 +0000164
165 /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
166 clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
167
168 /* Give clocks time to stabilize */
169 udelay(1000);
170
171 /* Take required peripherals out of reset */
172 debug("Taking periphs out of reset\n");
173 reset_set_enable(PERIPH_ID_CACHE2, 0);
174 reset_set_enable(PERIPH_ID_GPIO, 0);
175 reset_set_enable(PERIPH_ID_TMR, 0);
176 reset_set_enable(PERIPH_ID_COP, 0);
177 reset_set_enable(PERIPH_ID_EMC, 0);
178 reset_set_enable(PERIPH_ID_I2C5, 0);
179 reset_set_enable(PERIPH_ID_FUSE, 0);
180 reset_set_enable(PERIPH_ID_APBDMA, 0);
181 reset_set_enable(PERIPH_ID_MEM, 0);
182 reset_set_enable(PERIPH_ID_CORESIGHT, 0);
183 reset_set_enable(PERIPH_ID_MSELECT, 0);
184 reset_set_enable(PERIPH_ID_EMC1, 0);
185 reset_set_enable(PERIPH_ID_MC1, 0);
Tom Warrene88e84b2013-02-27 11:10:01 +0000186 reset_set_enable(PERIPH_ID_DVFS, 0);
Tom Warrend034d1b2013-01-28 13:32:08 +0000187
Tom Warrena8480ef2015-06-25 09:50:44 -0700188 debug("%s exit\n", __func__);
Tom Warrend034d1b2013-01-28 13:32:08 +0000189}
190
Stephen Warren45917e12014-01-24 12:46:08 -0700191static bool is_partition_powered(u32 partid)
Tom Warrend034d1b2013-01-28 13:32:08 +0000192{
193 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
194 u32 reg;
195
196 /* Get power gate status */
197 reg = readl(&pmc->pmc_pwrgate_status);
Stephen Warren45917e12014-01-24 12:46:08 -0700198 return !!(reg & (1 << partid));
Tom Warrend034d1b2013-01-28 13:32:08 +0000199}
200
Stephen Warren45917e12014-01-24 12:46:08 -0700201static bool is_clamp_enabled(u32 partid)
Tom Warrend034d1b2013-01-28 13:32:08 +0000202{
203 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
204 u32 reg;
205
Stephen Warren78452c32014-01-24 10:23:02 -0700206 /* Get clamp status. */
207 reg = readl(&pmc->pmc_clamp_status);
Stephen Warren45917e12014-01-24 12:46:08 -0700208 return !!(reg & (1 << partid));
Tom Warrend034d1b2013-01-28 13:32:08 +0000209}
210
Stephen Warren45917e12014-01-24 12:46:08 -0700211static void power_partition(u32 partid)
Tom Warrend034d1b2013-01-28 13:32:08 +0000212{
213 struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
214
Stephen Warren45917e12014-01-24 12:46:08 -0700215 debug("%s: part ID = %08X\n", __func__, partid);
Tom Warrend034d1b2013-01-28 13:32:08 +0000216 /* Is the partition already on? */
Stephen Warren45917e12014-01-24 12:46:08 -0700217 if (!is_partition_powered(partid)) {
Tom Warrend034d1b2013-01-28 13:32:08 +0000218 /* No, toggle the partition power state (OFF -> ON) */
219 debug("power_partition, toggling state\n");
Stephen Warren757aeaa2014-01-24 12:46:07 -0700220 writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
Tom Warrend034d1b2013-01-28 13:32:08 +0000221
222 /* Wait for the power to come up */
Stephen Warren45917e12014-01-24 12:46:08 -0700223 while (!is_partition_powered(partid))
Tom Warrend034d1b2013-01-28 13:32:08 +0000224 ;
225
226 /* Wait for the clamp status to be cleared */
Stephen Warren45917e12014-01-24 12:46:08 -0700227 while (is_clamp_enabled(partid))
Tom Warrend034d1b2013-01-28 13:32:08 +0000228 ;
229
230 /* Give I/O signals time to stabilize */
231 udelay(IO_STABILIZATION_DELAY);
232 }
233}
234
235void powerup_cpus(void)
236{
Tom Warrend034d1b2013-01-28 13:32:08 +0000237 /* We boot to the fast cluster */
Tom Warrena8480ef2015-06-25 09:50:44 -0700238 debug("%s entry: G cluster\n", __func__);
239
Tom Warrend034d1b2013-01-28 13:32:08 +0000240 /* Power up the fast cluster rail partition */
Stephen Warren45917e12014-01-24 12:46:08 -0700241 power_partition(CRAIL);
Tom Warrend034d1b2013-01-28 13:32:08 +0000242
243 /* Power up the fast cluster non-CPU partition */
Stephen Warren45917e12014-01-24 12:46:08 -0700244 power_partition(C0NC);
Tom Warrend034d1b2013-01-28 13:32:08 +0000245
246 /* Power up the fast cluster CPU0 partition */
Stephen Warren45917e12014-01-24 12:46:08 -0700247 power_partition(CE0);
Tom Warrend034d1b2013-01-28 13:32:08 +0000248}
249
250void start_cpu(u32 reset_vector)
251{
Stephen Warren2b276772013-02-28 12:40:09 +0000252 u32 imme, inst;
253
Tom Warrena8480ef2015-06-25 09:50:44 -0700254 debug("%s entry, reset_vector = %x\n", __func__, reset_vector);
Tom Warrend034d1b2013-01-28 13:32:08 +0000255
256 t114_init_clocks();
257
258 /* Enable VDD_CPU */
259 enable_cpu_power_rail();
Svyatoslav Ryhel1fb30512023-10-03 09:36:43 +0300260 pmic_enable_cpu_vdd();
Tom Warrend034d1b2013-01-28 13:32:08 +0000261
262 /* Get the CPU(s) running */
263 enable_cpu_clocks();
264
265 /* Enable CoreSight */
266 clock_enable_coresight(1);
267
268 /* Take CPU(s) out of reset */
269 remove_cpu_resets();
270
Stephen Warren2b276772013-02-28 12:40:09 +0000271 /* Set the entry point for CPU execution from reset */
272
Tom Warrend034d1b2013-01-28 13:32:08 +0000273 /*
Stephen Warren2b276772013-02-28 12:40:09 +0000274 * A01P with patched boot ROM; vector hard-coded to 0x4003fffc.
275 * See nvbug 1193357 for details.
Tom Warrend034d1b2013-01-28 13:32:08 +0000276 */
Stephen Warren2b276772013-02-28 12:40:09 +0000277
278 /* mov r0, #lsb(reset_vector) */
279 imme = reset_vector & 0xffff;
280 inst = imme & 0xfff;
281 inst |= ((imme >> 12) << 16);
282 inst |= 0xe3000000;
283 writel(inst, 0x4003fff0);
284
285 /* movt r0, #msb(reset_vector) */
286 imme = (reset_vector >> 16) & 0xffff;
287 inst = imme & 0xfff;
288 inst |= ((imme >> 12) << 16);
289 inst |= 0xe3400000;
290 writel(inst, 0x4003fff4);
291
292 /* bx r0 */
293 writel(0xe12fff10, 0x4003fff8);
294
295 /* b -12 */
296 imme = (u32)-20;
297 inst = (imme >> 2) & 0xffffff;
298 inst |= 0xea000000;
299 writel(inst, 0x4003fffc);
300
Tom Warrena8480ef2015-06-25 09:50:44 -0700301 /* Write to original location for compatibility */
Stephen Warren2b276772013-02-28 12:40:09 +0000302 writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
Tom Warrend034d1b2013-01-28 13:32:08 +0000303
304 /* If the CPU(s) don't already have power, power 'em up */
305 powerup_cpus();
306}