1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * (C) Copyright 2010-2014
3*4882a593Smuzhiyun * NVIDIA Corporation <www.nvidia.com>
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <common.h>
9*4882a593Smuzhiyun #include <asm/io.h>
10*4882a593Smuzhiyun #include <asm/arch/clock.h>
11*4882a593Smuzhiyun #include <asm/arch/flow.h>
12*4882a593Smuzhiyun #include <asm/arch/pinmux.h>
13*4882a593Smuzhiyun #include <asm/arch/tegra.h>
14*4882a593Smuzhiyun #include <asm/arch-tegra/clk_rst.h>
15*4882a593Smuzhiyun #include <asm/arch-tegra/pmc.h>
16*4882a593Smuzhiyun #include "../cpu.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun /* Tegra114-specific CPU init code */
enable_cpu_power_rail(void)19*4882a593Smuzhiyun static void enable_cpu_power_rail(void)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
22*4882a593Smuzhiyun struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
23*4882a593Smuzhiyun u32 reg;
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun debug("%s entry\n", __func__);
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /* un-tristate PWR_I2C SCL/SDA, rest of the defaults are correct */
28*4882a593Smuzhiyun pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SCL_PZ6);
29*4882a593Smuzhiyun pinmux_tristate_disable(PMUX_PINGRP_PWR_I2C_SDA_PZ7);
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun * Set CPUPWRGOOD_TIMER - APB clock is 1/2 of SCLK (102MHz),
33*4882a593Smuzhiyun * set it for 25ms (102MHz * .025)
34*4882a593Smuzhiyun */
35*4882a593Smuzhiyun reg = 0x26E8F0;
36*4882a593Smuzhiyun writel(reg, &pmc->pmc_cpupwrgood_timer);
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* Set polarity to 0 (normal) and enable CPUPWRREQ_OE */
39*4882a593Smuzhiyun clrbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_POL);
40*4882a593Smuzhiyun setbits_le32(&pmc->pmc_cntrl, CPUPWRREQ_OE);
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun * Set CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2_0_CAR2PMC_CPU_ACK_WIDTH
44*4882a593Smuzhiyun * to 408 to satisfy the requirement of having at least 16 CPU clock
45*4882a593Smuzhiyun * cycles before clamp removal.
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun clrbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 0xFFF);
49*4882a593Smuzhiyun setbits_le32(&clkrst->crc_cpu_softrst_ctrl2, 408);
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun
enable_cpu_clocks(void)52*4882a593Smuzhiyun static void enable_cpu_clocks(void)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
55*4882a593Smuzhiyun struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU];
56*4882a593Smuzhiyun u32 reg;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun debug("%s entry\n", __func__);
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /* Wait for PLL-X to lock */
61*4882a593Smuzhiyun do {
62*4882a593Smuzhiyun reg = readl(&clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
63*4882a593Smuzhiyun } while ((reg & (1 << pllinfo->lock_det)) == 0);
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* Wait until all clocks are stable */
66*4882a593Smuzhiyun udelay(PLL_STABILIZATION_DELAY);
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
69*4882a593Smuzhiyun writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* Always enable the main CPU complex clocks */
72*4882a593Smuzhiyun clock_enable(PERIPH_ID_CPU);
73*4882a593Smuzhiyun clock_enable(PERIPH_ID_CPULP);
74*4882a593Smuzhiyun clock_enable(PERIPH_ID_CPUG);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
remove_cpu_resets(void)77*4882a593Smuzhiyun static void remove_cpu_resets(void)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
80*4882a593Smuzhiyun u32 reg;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun debug("%s entry\n", __func__);
83*4882a593Smuzhiyun /* Take the slow non-CPU partition out of reset */
84*4882a593Smuzhiyun reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
85*4882a593Smuzhiyun writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpulp_cmplx_clr);
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun /* Take the fast non-CPU partition out of reset */
88*4882a593Smuzhiyun reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
89*4882a593Smuzhiyun writel((reg | CLR_NONCPURESET), &clkrst->crc_rst_cpug_cmplx_clr);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun /* Clear the SW-controlled reset of the slow cluster */
92*4882a593Smuzhiyun reg = readl(&clkrst->crc_rst_cpulp_cmplx_clr);
93*4882a593Smuzhiyun reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
94*4882a593Smuzhiyun writel(reg, &clkrst->crc_rst_cpulp_cmplx_clr);
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* Clear the SW-controlled reset of the fast cluster */
97*4882a593Smuzhiyun reg = readl(&clkrst->crc_rst_cpug_cmplx_clr);
98*4882a593Smuzhiyun reg |= (CLR_CPURESET0+CLR_DBGRESET0+CLR_CORERESET0+CLR_CXRESET0);
99*4882a593Smuzhiyun reg |= (CLR_CPURESET1+CLR_DBGRESET1+CLR_CORERESET1+CLR_CXRESET1);
100*4882a593Smuzhiyun reg |= (CLR_CPURESET2+CLR_DBGRESET2+CLR_CORERESET2+CLR_CXRESET2);
101*4882a593Smuzhiyun reg |= (CLR_CPURESET3+CLR_DBGRESET3+CLR_CORERESET3+CLR_CXRESET3);
102*4882a593Smuzhiyun writel(reg, &clkrst->crc_rst_cpug_cmplx_clr);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun * Tegra114 requires some special clock initialization, including setting up
107*4882a593Smuzhiyun * the DVC I2C, turning on MSELECT and selecting the G CPU cluster
108*4882a593Smuzhiyun */
t114_init_clocks(void)109*4882a593Smuzhiyun void t114_init_clocks(void)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun struct clk_rst_ctlr *clkrst =
112*4882a593Smuzhiyun (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
113*4882a593Smuzhiyun struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
114*4882a593Smuzhiyun u32 val;
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun debug("%s entry\n", __func__);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun /* Set active CPU cluster to G */
119*4882a593Smuzhiyun clrbits_le32(&flow->cluster_control, 1);
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun debug("Setting up PLLX\n");
124*4882a593Smuzhiyun init_pllx();
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun val = (1 << CLK_SYS_RATE_AHB_RATE_SHIFT);
127*4882a593Smuzhiyun writel(val, &clkrst->crc_clk_sys_rate);
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /* Enable clocks to required peripherals. TBD - minimize this list */
130*4882a593Smuzhiyun debug("Enabling clocks\n");
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_CACHE2, 1);
133*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_GPIO, 1);
134*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_TMR, 1);
135*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_RTC, 1);
136*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_CPU, 1);
137*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_EMC, 1);
138*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_I2C5, 1);
139*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_FUSE, 1);
140*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_PMC, 1);
141*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_APBDMA, 1);
142*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_MEM, 1);
143*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_IRAMA, 1);
144*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_IRAMB, 1);
145*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_IRAMC, 1);
146*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_IRAMD, 1);
147*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_CORESIGHT, 1);
148*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_MSELECT, 1);
149*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_EMC1, 1);
150*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_MC1, 1);
151*4882a593Smuzhiyun clock_set_enable(PERIPH_ID_DVFS, 1);
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun * Set MSELECT clock source as PLLP (00), and ask for a clock
155*4882a593Smuzhiyun * divider that would set the MSELECT clock at 102MHz for a
156*4882a593Smuzhiyun * PLLP base of 408MHz.
157*4882a593Smuzhiyun */
158*4882a593Smuzhiyun clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0,
159*4882a593Smuzhiyun CLK_DIVIDER(NVBL_PLLP_KHZ, 102000));
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /* I2C5 (DVC) gets CLK_M and a divisor of 17 */
162*4882a593Smuzhiyun clock_ll_set_source_divisor(PERIPH_ID_I2C5, 3, 16);
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun /* Give clocks time to stabilize */
165*4882a593Smuzhiyun udelay(1000);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* Take required peripherals out of reset */
168*4882a593Smuzhiyun debug("Taking periphs out of reset\n");
169*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_CACHE2, 0);
170*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_GPIO, 0);
171*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_TMR, 0);
172*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_COP, 0);
173*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_EMC, 0);
174*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_I2C5, 0);
175*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_FUSE, 0);
176*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_APBDMA, 0);
177*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_MEM, 0);
178*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_CORESIGHT, 0);
179*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_MSELECT, 0);
180*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_EMC1, 0);
181*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_MC1, 0);
182*4882a593Smuzhiyun reset_set_enable(PERIPH_ID_DVFS, 0);
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun debug("%s exit\n", __func__);
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun
is_partition_powered(u32 partid)187*4882a593Smuzhiyun static bool is_partition_powered(u32 partid)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
190*4882a593Smuzhiyun u32 reg;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Get power gate status */
193*4882a593Smuzhiyun reg = readl(&pmc->pmc_pwrgate_status);
194*4882a593Smuzhiyun return !!(reg & (1 << partid));
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
is_clamp_enabled(u32 partid)197*4882a593Smuzhiyun static bool is_clamp_enabled(u32 partid)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
200*4882a593Smuzhiyun u32 reg;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /* Get clamp status. */
203*4882a593Smuzhiyun reg = readl(&pmc->pmc_clamp_status);
204*4882a593Smuzhiyun return !!(reg & (1 << partid));
205*4882a593Smuzhiyun }
206*4882a593Smuzhiyun
power_partition(u32 partid)207*4882a593Smuzhiyun static void power_partition(u32 partid)
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun debug("%s: part ID = %08X\n", __func__, partid);
212*4882a593Smuzhiyun /* Is the partition already on? */
213*4882a593Smuzhiyun if (!is_partition_powered(partid)) {
214*4882a593Smuzhiyun /* No, toggle the partition power state (OFF -> ON) */
215*4882a593Smuzhiyun debug("power_partition, toggling state\n");
216*4882a593Smuzhiyun writel(START_CP | partid, &pmc->pmc_pwrgate_toggle);
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun /* Wait for the power to come up */
219*4882a593Smuzhiyun while (!is_partition_powered(partid))
220*4882a593Smuzhiyun ;
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun /* Wait for the clamp status to be cleared */
223*4882a593Smuzhiyun while (is_clamp_enabled(partid))
224*4882a593Smuzhiyun ;
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /* Give I/O signals time to stabilize */
227*4882a593Smuzhiyun udelay(IO_STABILIZATION_DELAY);
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun
powerup_cpus(void)231*4882a593Smuzhiyun void powerup_cpus(void)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun /* We boot to the fast cluster */
234*4882a593Smuzhiyun debug("%s entry: G cluster\n", __func__);
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /* Power up the fast cluster rail partition */
237*4882a593Smuzhiyun power_partition(CRAIL);
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun /* Power up the fast cluster non-CPU partition */
240*4882a593Smuzhiyun power_partition(C0NC);
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun /* Power up the fast cluster CPU0 partition */
243*4882a593Smuzhiyun power_partition(CE0);
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
start_cpu(u32 reset_vector)246*4882a593Smuzhiyun void start_cpu(u32 reset_vector)
247*4882a593Smuzhiyun {
248*4882a593Smuzhiyun u32 imme, inst;
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun debug("%s entry, reset_vector = %x\n", __func__, reset_vector);
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun t114_init_clocks();
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun /* Enable VDD_CPU */
255*4882a593Smuzhiyun enable_cpu_power_rail();
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun /* Get the CPU(s) running */
258*4882a593Smuzhiyun enable_cpu_clocks();
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /* Enable CoreSight */
261*4882a593Smuzhiyun clock_enable_coresight(1);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /* Take CPU(s) out of reset */
264*4882a593Smuzhiyun remove_cpu_resets();
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun /* Set the entry point for CPU execution from reset */
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun /*
269*4882a593Smuzhiyun * A01P with patched boot ROM; vector hard-coded to 0x4003fffc.
270*4882a593Smuzhiyun * See nvbug 1193357 for details.
271*4882a593Smuzhiyun */
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun /* mov r0, #lsb(reset_vector) */
274*4882a593Smuzhiyun imme = reset_vector & 0xffff;
275*4882a593Smuzhiyun inst = imme & 0xfff;
276*4882a593Smuzhiyun inst |= ((imme >> 12) << 16);
277*4882a593Smuzhiyun inst |= 0xe3000000;
278*4882a593Smuzhiyun writel(inst, 0x4003fff0);
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /* movt r0, #msb(reset_vector) */
281*4882a593Smuzhiyun imme = (reset_vector >> 16) & 0xffff;
282*4882a593Smuzhiyun inst = imme & 0xfff;
283*4882a593Smuzhiyun inst |= ((imme >> 12) << 16);
284*4882a593Smuzhiyun inst |= 0xe3400000;
285*4882a593Smuzhiyun writel(inst, 0x4003fff4);
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun /* bx r0 */
288*4882a593Smuzhiyun writel(0xe12fff10, 0x4003fff8);
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun /* b -12 */
291*4882a593Smuzhiyun imme = (u32)-20;
292*4882a593Smuzhiyun inst = (imme >> 2) & 0xffffff;
293*4882a593Smuzhiyun inst |= 0xea000000;
294*4882a593Smuzhiyun writel(inst, 0x4003fffc);
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun /* Write to original location for compatibility */
297*4882a593Smuzhiyun writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun /* If the CPU(s) don't already have power, power 'em up */
300*4882a593Smuzhiyun powerup_cpus();
301*4882a593Smuzhiyun }
302