xref: /OK3568_Linux_fs/u-boot/arch/arm/mach-tegra/tegra20/warmboot_avp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2010 - 2011
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/ap.h>
15*4882a593Smuzhiyun #include <asm/arch-tegra/apb_misc.h>
16*4882a593Smuzhiyun #include <asm/arch-tegra/clk_rst.h>
17*4882a593Smuzhiyun #include <asm/arch-tegra/pmc.h>
18*4882a593Smuzhiyun #include <asm/arch-tegra/warmboot.h>
19*4882a593Smuzhiyun #include "warmboot_avp.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define DEBUG_RESET_CORESIGHT
22*4882a593Smuzhiyun 
wb_start(void)23*4882a593Smuzhiyun void wb_start(void)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	struct apb_misc_pp_ctlr *apb_misc =
26*4882a593Smuzhiyun 				(struct apb_misc_pp_ctlr *)NV_PA_APB_MISC_BASE;
27*4882a593Smuzhiyun 	struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
28*4882a593Smuzhiyun 	struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
29*4882a593Smuzhiyun 	struct clk_rst_ctlr *clkrst =
30*4882a593Smuzhiyun 			(struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
31*4882a593Smuzhiyun 	union osc_ctrl_reg osc_ctrl;
32*4882a593Smuzhiyun 	union pllx_base_reg pllx_base;
33*4882a593Smuzhiyun 	union pllx_misc_reg pllx_misc;
34*4882a593Smuzhiyun 	union scratch3_reg scratch3;
35*4882a593Smuzhiyun 	u32 reg;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	/* enable JTAG & TBE */
38*4882a593Smuzhiyun 	writel(CONFIG_CTL_TBE | CONFIG_CTL_JTAG, &apb_misc->cfg_ctl);
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 	/* Are we running where we're supposed to be? */
41*4882a593Smuzhiyun 	asm volatile (
42*4882a593Smuzhiyun 		"adr	%0, wb_start;"	/* reg: wb_start address */
43*4882a593Smuzhiyun 		: "=r"(reg)		/* output */
44*4882a593Smuzhiyun 					/* no input, no clobber list */
45*4882a593Smuzhiyun 	);
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	if (reg != NV_WB_RUN_ADDRESS)
48*4882a593Smuzhiyun 		goto do_reset;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	/* Are we running with AVP? */
51*4882a593Smuzhiyun 	if (readl(NV_PA_PG_UP_BASE + PG_UP_TAG_0) != PG_UP_TAG_AVP)
52*4882a593Smuzhiyun 		goto do_reset;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifdef DEBUG_RESET_CORESIGHT
55*4882a593Smuzhiyun 	/* Assert CoreSight reset */
56*4882a593Smuzhiyun 	reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
57*4882a593Smuzhiyun 	reg |= SWR_CSITE_RST;
58*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
59*4882a593Smuzhiyun #endif
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	/* TODO: Set the drive strength - maybe make this a board parameter? */
62*4882a593Smuzhiyun 	osc_ctrl.word = readl(&clkrst->crc_osc_ctrl);
63*4882a593Smuzhiyun 	osc_ctrl.xofs = 4;
64*4882a593Smuzhiyun 	osc_ctrl.xoe = 1;
65*4882a593Smuzhiyun 	writel(osc_ctrl.word, &clkrst->crc_osc_ctrl);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	/* Power up the CPU complex if necessary */
68*4882a593Smuzhiyun 	if (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU)) {
69*4882a593Smuzhiyun 		reg = PWRGATE_TOGGLE_PARTID_CPU | PWRGATE_TOGGLE_START;
70*4882a593Smuzhiyun 		writel(reg, &pmc->pmc_pwrgate_toggle);
71*4882a593Smuzhiyun 		while (!(readl(&pmc->pmc_pwrgate_status) & PWRGATE_STATUS_CPU))
72*4882a593Smuzhiyun 			;
73*4882a593Smuzhiyun 	}
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/* Remove the I/O clamps from the CPU power partition. */
76*4882a593Smuzhiyun 	reg = readl(&pmc->pmc_remove_clamping);
77*4882a593Smuzhiyun 	reg |= CPU_CLMP;
78*4882a593Smuzhiyun 	writel(reg, &pmc->pmc_remove_clamping);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	reg = EVENT_ZERO_VAL_20 | EVENT_MSEC | EVENT_MODE_STOP;
81*4882a593Smuzhiyun 	writel(reg, &flow->halt_cop_events);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	/* Assert CPU complex reset */
84*4882a593Smuzhiyun 	reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
85*4882a593Smuzhiyun 	reg |= CPU_RST;
86*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	/* Hold both CPUs in reset */
89*4882a593Smuzhiyun 	reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_CPURESET1 | CPU_CMPLX_DERESET0 |
90*4882a593Smuzhiyun 	      CPU_CMPLX_DERESET1 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DBGRESET1;
91*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_cpu_cmplx_set);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* Halt CPU1 at the flow controller for uni-processor configurations */
94*4882a593Smuzhiyun 	writel(EVENT_MODE_STOP, &flow->halt_cpu1_events);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	/*
97*4882a593Smuzhiyun 	 * Set the CPU reset vector. SCRATCH41 contains the physical
98*4882a593Smuzhiyun 	 * address of the CPU-side restoration code.
99*4882a593Smuzhiyun 	 */
100*4882a593Smuzhiyun 	reg = readl(&pmc->pmc_scratch41);
101*4882a593Smuzhiyun 	writel(reg, EXCEP_VECTOR_CPU_RESET_VECTOR);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	/* Select CPU complex clock source */
104*4882a593Smuzhiyun 	writel(CCLK_PLLP_BURST_POLICY, &clkrst->crc_cclk_brst_pol);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun 	/* Start the CPU0 clock and stop the CPU1 clock */
107*4882a593Smuzhiyun 	reg = CPU_CMPLX_CPU_BRIDGE_CLKDIV_4 | CPU_CMPLX_CPU0_CLK_STP_RUN |
108*4882a593Smuzhiyun 	      CPU_CMPLX_CPU1_CLK_STP_STOP;
109*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_clk_cpu_cmplx);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	/* Enable the CPU complex clock */
112*4882a593Smuzhiyun 	reg = readl(&clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
113*4882a593Smuzhiyun 	reg |= CLK_ENB_CPU;
114*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_clk_out_enb[TEGRA_DEV_L]);
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	/* Make sure the resets were held for at least 2 microseconds */
117*4882a593Smuzhiyun 	reg = readl(TIMER_USEC_CNTR);
118*4882a593Smuzhiyun 	while (readl(TIMER_USEC_CNTR) <= (reg + 2))
119*4882a593Smuzhiyun 		;
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun #ifdef DEBUG_RESET_CORESIGHT
122*4882a593Smuzhiyun 	/*
123*4882a593Smuzhiyun 	 * De-assert CoreSight reset.
124*4882a593Smuzhiyun 	 * NOTE: We're leaving the CoreSight clock on the oscillator for
125*4882a593Smuzhiyun 	 *	now. It will be restored to its original clock source
126*4882a593Smuzhiyun 	 *	when the CPU-side restoration code runs.
127*4882a593Smuzhiyun 	 */
128*4882a593Smuzhiyun 	reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_U]);
129*4882a593Smuzhiyun 	reg &= ~SWR_CSITE_RST;
130*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_U]);
131*4882a593Smuzhiyun #endif
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	/* Unlock the CPU CoreSight interfaces */
134*4882a593Smuzhiyun 	reg = 0xC5ACCE55;
135*4882a593Smuzhiyun 	writel(reg, CSITE_CPU_DBG0_LAR);
136*4882a593Smuzhiyun 	writel(reg, CSITE_CPU_DBG1_LAR);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	/*
139*4882a593Smuzhiyun 	 * Sample the microsecond timestamp again. This is the time we must
140*4882a593Smuzhiyun 	 * use when returning from LP0 for PLL stabilization delays.
141*4882a593Smuzhiyun 	 */
142*4882a593Smuzhiyun 	reg = readl(TIMER_USEC_CNTR);
143*4882a593Smuzhiyun 	writel(reg, &pmc->pmc_scratch1);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	pllx_base.word = 0;
146*4882a593Smuzhiyun 	pllx_misc.word = 0;
147*4882a593Smuzhiyun 	scratch3.word = readl(&pmc->pmc_scratch3);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	/* Get the OSC. For 19.2 MHz, use 19 to make the calculations easier */
150*4882a593Smuzhiyun 	reg = (readl(TIMER_USEC_CFG) & USEC_CFG_DIVISOR_MASK) + 1;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	/*
153*4882a593Smuzhiyun 	 * According to the TRM, for 19.2MHz OSC, the USEC_DIVISOR is 0x5f, and
154*4882a593Smuzhiyun 	 * USEC_DIVIDEND is 0x04. So, if USEC_DIVISOR > 26, OSC is 19.2 MHz.
155*4882a593Smuzhiyun 	 *
156*4882a593Smuzhiyun 	 * reg is used to calculate the pllx freq, which is used to determine if
157*4882a593Smuzhiyun 	 * to set dccon or not.
158*4882a593Smuzhiyun 	 */
159*4882a593Smuzhiyun 	if (reg > 26)
160*4882a593Smuzhiyun 		reg = 19;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* PLLX_BASE.PLLX_DIVM */
163*4882a593Smuzhiyun 	if (scratch3.pllx_base_divm == reg)
164*4882a593Smuzhiyun 		reg = 0;
165*4882a593Smuzhiyun 	else
166*4882a593Smuzhiyun 		reg = 1;
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	/* PLLX_BASE.PLLX_DIVN */
169*4882a593Smuzhiyun 	pllx_base.divn = scratch3.pllx_base_divn;
170*4882a593Smuzhiyun 	reg = scratch3.pllx_base_divn << reg;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	/* PLLX_BASE.PLLX_DIVP */
173*4882a593Smuzhiyun 	pllx_base.divp = scratch3.pllx_base_divp;
174*4882a593Smuzhiyun 	reg = reg >> scratch3.pllx_base_divp;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	pllx_base.bypass = 1;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	/* PLLX_MISC_DCCON must be set for pllx frequency > 600 MHz. */
179*4882a593Smuzhiyun 	if (reg > 600)
180*4882a593Smuzhiyun 		pllx_misc.dccon = 1;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/* PLLX_MISC_LFCON */
183*4882a593Smuzhiyun 	pllx_misc.lfcon = scratch3.pllx_misc_lfcon;
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	/* PLLX_MISC_CPCON */
186*4882a593Smuzhiyun 	pllx_misc.cpcon = scratch3.pllx_misc_cpcon;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	writel(pllx_misc.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_misc);
189*4882a593Smuzhiyun 	writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun 	pllx_base.enable = 1;
192*4882a593Smuzhiyun 	writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
193*4882a593Smuzhiyun 	pllx_base.bypass = 0;
194*4882a593Smuzhiyun 	writel(pllx_base.word, &clkrst->crc_pll_simple[SIMPLE_PLLX].pll_base);
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	writel(0, flow->halt_cpu_events);
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	reg = CPU_CMPLX_CPURESET0 | CPU_CMPLX_DBGRESET0 | CPU_CMPLX_DERESET0;
199*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_cpu_cmplx_clr);
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	reg = PLLM_OUT1_RSTN_RESET_DISABLE | PLLM_OUT1_CLKEN_ENABLE |
202*4882a593Smuzhiyun 	      PLLM_OUT1_RATIO_VAL_8;
203*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_pll[CLOCK_ID_MEMORY].pll_out[0]);
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	reg = SCLK_SWAKE_FIQ_SRC_PLLM_OUT1 | SCLK_SWAKE_IRQ_SRC_PLLM_OUT1 |
206*4882a593Smuzhiyun 	      SCLK_SWAKE_RUN_SRC_PLLM_OUT1 | SCLK_SWAKE_IDLE_SRC_PLLM_OUT1 |
207*4882a593Smuzhiyun 	      SCLK_SYS_STATE_IDLE;
208*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_sclk_brst_pol);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	/* avp_resume: no return after the write */
211*4882a593Smuzhiyun 	reg = readl(&clkrst->crc_rst_dev[TEGRA_DEV_L]);
212*4882a593Smuzhiyun 	reg &= ~CPU_RST;
213*4882a593Smuzhiyun 	writel(reg, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun 	/* avp_halt: */
216*4882a593Smuzhiyun avp_halt:
217*4882a593Smuzhiyun 	reg = EVENT_MODE_STOP | EVENT_JTAG;
218*4882a593Smuzhiyun 	writel(reg, flow->halt_cop_events);
219*4882a593Smuzhiyun 	goto avp_halt;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun do_reset:
222*4882a593Smuzhiyun 	/*
223*4882a593Smuzhiyun 	 * Execution comes here if something goes wrong. The chip is reset and
224*4882a593Smuzhiyun 	 * a cold boot is performed.
225*4882a593Smuzhiyun 	 */
226*4882a593Smuzhiyun 	writel(SWR_TRIG_SYS_RST, &clkrst->crc_rst_dev[TEGRA_DEV_L]);
227*4882a593Smuzhiyun 	goto do_reset;
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /*
231*4882a593Smuzhiyun  * wb_end() is a dummy function, and must be directly following wb_start(),
232*4882a593Smuzhiyun  * and is used to calculate the size of wb_start().
233*4882a593Smuzhiyun  */
wb_end(void)234*4882a593Smuzhiyun void wb_end(void)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun }
237