xref: /openbmc/u-boot/board/renesas/stout/stout_spl.c (revision ec7113fbb4b066549ca470b51adc6f45c41e0eef)
1*ec7113fbSMarek Vasut /*
2*ec7113fbSMarek Vasut  * board/renesas/stout/stout_spl.c
3*ec7113fbSMarek Vasut  *
4*ec7113fbSMarek Vasut  * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
5*ec7113fbSMarek Vasut  *
6*ec7113fbSMarek Vasut  * SPDX-License-Identifier: GPL-2.0
7*ec7113fbSMarek Vasut  */
8*ec7113fbSMarek Vasut 
9*ec7113fbSMarek Vasut #include <common.h>
10*ec7113fbSMarek Vasut #include <malloc.h>
11*ec7113fbSMarek Vasut #include <dm/platform_data/serial_sh.h>
12*ec7113fbSMarek Vasut #include <asm/processor.h>
13*ec7113fbSMarek Vasut #include <asm/mach-types.h>
14*ec7113fbSMarek Vasut #include <asm/io.h>
15*ec7113fbSMarek Vasut #include <linux/errno.h>
16*ec7113fbSMarek Vasut #include <asm/arch/sys_proto.h>
17*ec7113fbSMarek Vasut #include <asm/gpio.h>
18*ec7113fbSMarek Vasut #include <asm/arch/rmobile.h>
19*ec7113fbSMarek Vasut #include <asm/arch/rcar-mstp.h>
20*ec7113fbSMarek Vasut 
21*ec7113fbSMarek Vasut #include <spl.h>
22*ec7113fbSMarek Vasut 
23*ec7113fbSMarek Vasut #define TMU0_MSTP125	BIT(25)
24*ec7113fbSMarek Vasut #define SCIFA0_MSTP204	BIT(4)
25*ec7113fbSMarek Vasut #define QSPI_MSTP917	BIT(17)
26*ec7113fbSMarek Vasut 
27*ec7113fbSMarek Vasut #define SD2CKCR		0xE615026C
28*ec7113fbSMarek Vasut #define SD_97500KHZ	0x7
29*ec7113fbSMarek Vasut 
30*ec7113fbSMarek Vasut #ifdef CONFIG_TPL_BUILD
31*ec7113fbSMarek Vasut struct reg_config {
32*ec7113fbSMarek Vasut 	u16	off;
33*ec7113fbSMarek Vasut 	u32	val;
34*ec7113fbSMarek Vasut };
35*ec7113fbSMarek Vasut 
36*ec7113fbSMarek Vasut static void dbsc_wait(u16 reg)
37*ec7113fbSMarek Vasut {
38*ec7113fbSMarek Vasut 	static const u32 dbsc3_0_base = DBSC3_0_BASE;
39*ec7113fbSMarek Vasut 	static const u32 dbsc3_1_base = DBSC3_0_BASE + 0x10000;
40*ec7113fbSMarek Vasut 
41*ec7113fbSMarek Vasut 	while (!(readl(dbsc3_0_base + reg) & BIT(0)))
42*ec7113fbSMarek Vasut 		;
43*ec7113fbSMarek Vasut 
44*ec7113fbSMarek Vasut 	while (!(readl(dbsc3_1_base + reg) & BIT(0)))
45*ec7113fbSMarek Vasut 		;
46*ec7113fbSMarek Vasut }
47*ec7113fbSMarek Vasut 
48*ec7113fbSMarek Vasut static void tpl_init_sys(void)
49*ec7113fbSMarek Vasut {
50*ec7113fbSMarek Vasut 	u32 r0 = 0;
51*ec7113fbSMarek Vasut 
52*ec7113fbSMarek Vasut 	writel(0xa5a5a500, 0xe6020004);
53*ec7113fbSMarek Vasut 	writel(0xa5a5a500, 0xe6030004);
54*ec7113fbSMarek Vasut 
55*ec7113fbSMarek Vasut 	asm volatile(
56*ec7113fbSMarek Vasut 		/* ICIALLU - Invalidate I$ to PoU */
57*ec7113fbSMarek Vasut 		"mcr	15, 0, %0, cr7, cr5, 0	\n"
58*ec7113fbSMarek Vasut 		/* BPIALL - Invalidate branch predictors */
59*ec7113fbSMarek Vasut 		"mcr	15, 0, %0, cr7, cr5, 6	\n"
60*ec7113fbSMarek Vasut 		/* Set SCTLR[IZ] */
61*ec7113fbSMarek Vasut 		"mrc	15, 0, %0, cr1, cr0, 0	\n"
62*ec7113fbSMarek Vasut 		"orr	%0, #0x1800		\n"
63*ec7113fbSMarek Vasut 		"mcr	15, 0, %0, cr1, cr0, 0	\n"
64*ec7113fbSMarek Vasut 		"isb	sy			\n"
65*ec7113fbSMarek Vasut 		:"=r"(r0));
66*ec7113fbSMarek Vasut }
67*ec7113fbSMarek Vasut 
68*ec7113fbSMarek Vasut static void tpl_init_pfc(void)
69*ec7113fbSMarek Vasut {
70*ec7113fbSMarek Vasut 	static const struct reg_config pfc_with_unlock[] = {
71*ec7113fbSMarek Vasut 		{ 0x0090, 0x00140300 },
72*ec7113fbSMarek Vasut 		{ 0x0094, 0x09500000 },
73*ec7113fbSMarek Vasut 		{ 0x0098, 0xc0000084 },
74*ec7113fbSMarek Vasut 		{ 0x0020, 0x01a33492 },
75*ec7113fbSMarek Vasut 		{ 0x0024, 0x10000000 },
76*ec7113fbSMarek Vasut 		{ 0x0028, 0x08449252 },
77*ec7113fbSMarek Vasut 		{ 0x002c, 0x2925b322 },
78*ec7113fbSMarek Vasut 		{ 0x0030, 0x0c311249 },
79*ec7113fbSMarek Vasut 		{ 0x0034, 0x10124000 },
80*ec7113fbSMarek Vasut 		{ 0x0038, 0x00001295 },
81*ec7113fbSMarek Vasut 		{ 0x003c, 0x50890000 },
82*ec7113fbSMarek Vasut 		{ 0x0040, 0x0eaa56aa },
83*ec7113fbSMarek Vasut 		{ 0x0044, 0x55550000 },
84*ec7113fbSMarek Vasut 		{ 0x0048, 0x00000005 },
85*ec7113fbSMarek Vasut 		{ 0x004c, 0x54800000 },
86*ec7113fbSMarek Vasut 		{ 0x0050, 0x3736db55 },
87*ec7113fbSMarek Vasut 		{ 0x0054, 0x29148da3 },
88*ec7113fbSMarek Vasut 		{ 0x0058, 0x48c446e1 },
89*ec7113fbSMarek Vasut 		{ 0x005c, 0x2a3a54dc },
90*ec7113fbSMarek Vasut 		{ 0x0160, 0x00000023 },
91*ec7113fbSMarek Vasut 		{ 0x0004, 0xfca0ffff },
92*ec7113fbSMarek Vasut 		{ 0x0008, 0x3fbffbf0 },
93*ec7113fbSMarek Vasut 		{ 0x000c, 0x3ffdffff },
94*ec7113fbSMarek Vasut 		{ 0x0010, 0x00ffffff },
95*ec7113fbSMarek Vasut 		{ 0x0014, 0xfc3ffff3 },
96*ec7113fbSMarek Vasut 		{ 0x0018, 0xe4fdfff7 },
97*ec7113fbSMarek Vasut 	};
98*ec7113fbSMarek Vasut 
99*ec7113fbSMarek Vasut 	static const struct reg_config pfc_without_unlock[] = {
100*ec7113fbSMarek Vasut 		{ 0x0104, 0xffffbfff },
101*ec7113fbSMarek Vasut 		{ 0x0108, 0xb1ffffe1 },
102*ec7113fbSMarek Vasut 		{ 0x010c, 0xffffffff },
103*ec7113fbSMarek Vasut 		{ 0x0110, 0xffffffff },
104*ec7113fbSMarek Vasut 		{ 0x0114, 0xe047beab },
105*ec7113fbSMarek Vasut 		{ 0x0118, 0x00000203 },
106*ec7113fbSMarek Vasut 	};
107*ec7113fbSMarek Vasut 
108*ec7113fbSMarek Vasut 	static const u32 pfc_base = 0xe6060000;
109*ec7113fbSMarek Vasut 
110*ec7113fbSMarek Vasut 	unsigned int i;
111*ec7113fbSMarek Vasut 
112*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
113*ec7113fbSMarek Vasut 		writel(~pfc_with_unlock[i].val, pfc_base);
114*ec7113fbSMarek Vasut 		writel(pfc_with_unlock[i].val,
115*ec7113fbSMarek Vasut 		       pfc_base | pfc_with_unlock[i].off);
116*ec7113fbSMarek Vasut 	}
117*ec7113fbSMarek Vasut 
118*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
119*ec7113fbSMarek Vasut 		writel(pfc_without_unlock[i].val,
120*ec7113fbSMarek Vasut 		       pfc_base | pfc_without_unlock[i].off);
121*ec7113fbSMarek Vasut }
122*ec7113fbSMarek Vasut 
123*ec7113fbSMarek Vasut static void tpl_init_gpio(void)
124*ec7113fbSMarek Vasut {
125*ec7113fbSMarek Vasut 	static const u16 gpio_offs[] = {
126*ec7113fbSMarek Vasut 		0x1000, 0x3000, 0x4000, 0x5000
127*ec7113fbSMarek Vasut 	};
128*ec7113fbSMarek Vasut 
129*ec7113fbSMarek Vasut 	static const struct reg_config gpio_set[] = {
130*ec7113fbSMarek Vasut 		{ 0x4000, 0x00c00000 },
131*ec7113fbSMarek Vasut 		{ 0x5000, 0x63020000 },
132*ec7113fbSMarek Vasut 	};
133*ec7113fbSMarek Vasut 
134*ec7113fbSMarek Vasut 	static const struct reg_config gpio_clr[] = {
135*ec7113fbSMarek Vasut 		{ 0x1000, 0x00000000 },
136*ec7113fbSMarek Vasut 		{ 0x3000, 0x00000000 },
137*ec7113fbSMarek Vasut 		{ 0x4000, 0x00c00000 },
138*ec7113fbSMarek Vasut 		{ 0x5000, 0xe3020000 },
139*ec7113fbSMarek Vasut 	};
140*ec7113fbSMarek Vasut 
141*ec7113fbSMarek Vasut 	static const u32 gpio_base = 0xe6050000;
142*ec7113fbSMarek Vasut 
143*ec7113fbSMarek Vasut 	unsigned int i;
144*ec7113fbSMarek Vasut 
145*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(gpio_offs); i++)
146*ec7113fbSMarek Vasut 		writel(0, gpio_base | 0x20 | gpio_offs[i]);
147*ec7113fbSMarek Vasut 
148*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(gpio_offs); i++)
149*ec7113fbSMarek Vasut 		writel(0, gpio_base | 0x00 | gpio_offs[i]);
150*ec7113fbSMarek Vasut 
151*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(gpio_set); i++)
152*ec7113fbSMarek Vasut 		writel(gpio_set[i].val, gpio_base | 0x08 | gpio_set[i].off);
153*ec7113fbSMarek Vasut 
154*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(gpio_clr); i++)
155*ec7113fbSMarek Vasut 		writel(gpio_clr[i].val, gpio_base | 0x04 | gpio_clr[i].off);
156*ec7113fbSMarek Vasut }
157*ec7113fbSMarek Vasut 
158*ec7113fbSMarek Vasut static void tpl_init_lbsc(void)
159*ec7113fbSMarek Vasut {
160*ec7113fbSMarek Vasut 	static const struct reg_config lbsc_config[] = {
161*ec7113fbSMarek Vasut 		{ 0x00, 0x00000020 },
162*ec7113fbSMarek Vasut 		{ 0x08, 0x00002020 },
163*ec7113fbSMarek Vasut 		{ 0x30, 0x02150326 },
164*ec7113fbSMarek Vasut 		{ 0x38, 0x077f077f },
165*ec7113fbSMarek Vasut 	};
166*ec7113fbSMarek Vasut 
167*ec7113fbSMarek Vasut 	static const u16 lbsc_offs[] = {
168*ec7113fbSMarek Vasut 		0x80, 0x84, 0x88, 0x8c, 0xa0, 0xc0, 0xc4, 0xc8, 0x180
169*ec7113fbSMarek Vasut 	};
170*ec7113fbSMarek Vasut 
171*ec7113fbSMarek Vasut 	static const u32 lbsc_base = 0xfec00200;
172*ec7113fbSMarek Vasut 
173*ec7113fbSMarek Vasut 	unsigned int i;
174*ec7113fbSMarek Vasut 
175*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
176*ec7113fbSMarek Vasut 		writel(lbsc_config[i].val,
177*ec7113fbSMarek Vasut 		       lbsc_base | lbsc_config[i].off);
178*ec7113fbSMarek Vasut 		writel(lbsc_config[i].val,
179*ec7113fbSMarek Vasut 		       lbsc_base | (lbsc_config[i].off + 4));
180*ec7113fbSMarek Vasut 	}
181*ec7113fbSMarek Vasut 
182*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(lbsc_offs); i++)
183*ec7113fbSMarek Vasut 		writel(0, lbsc_base | lbsc_offs[i]);
184*ec7113fbSMarek Vasut }
185*ec7113fbSMarek Vasut 
186*ec7113fbSMarek Vasut static void tpl_init_dbsc(void)
187*ec7113fbSMarek Vasut {
188*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config1[] = {
189*ec7113fbSMarek Vasut 		{ 0x0280, 0x0000a55a },
190*ec7113fbSMarek Vasut 		{ 0x0018, 0x21000000 },
191*ec7113fbSMarek Vasut 		{ 0x0018, 0x11000000 },
192*ec7113fbSMarek Vasut 		{ 0x0018, 0x10000000 },
193*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000001 },
194*ec7113fbSMarek Vasut 		{ 0x02a0, 0x80000000 },
195*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000004 },
196*ec7113fbSMarek Vasut 	};
197*ec7113fbSMarek Vasut 
198*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config2[] = {
199*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000006 },
200*ec7113fbSMarek Vasut 		{ 0x02a0, 0x0001c000 },
201*ec7113fbSMarek Vasut 	};
202*ec7113fbSMarek Vasut 
203*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config3r0d0[] = {
204*ec7113fbSMarek Vasut 		{ 0x0290, 0x0000000f },
205*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00181885 },
206*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000070 },
207*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
208*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000080 },
209*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
210*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000090 },
211*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
212*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000a0 },
213*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
214*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000b0 },
215*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000880 },
216*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000c0 },
217*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000880 },
218*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000d0 },
219*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000880 },
220*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000e0 },
221*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000880 },
222*ec7113fbSMarek Vasut 	};
223*ec7113fbSMarek Vasut 
224*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config3r0d1[] = {
225*ec7113fbSMarek Vasut 		{ 0x0290, 0x0000000f },
226*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00181885 },
227*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000070 },
228*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
229*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000080 },
230*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
231*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000090 },
232*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
233*ec7113fbSMarek Vasut 		{ 0x0290, 0x000000a0 },
234*ec7113fbSMarek Vasut 		{ 0x02a0, 0x7c000887 },
235*ec7113fbSMarek Vasut 	};
236*ec7113fbSMarek Vasut 
237*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config3r2[] = {
238*ec7113fbSMarek Vasut 		{ 0x0290, 0x0000000f },
239*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00181224 },
240*ec7113fbSMarek Vasut 	};
241*ec7113fbSMarek Vasut 
242*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config4[] = {
243*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000010 },
244*ec7113fbSMarek Vasut 		{ 0x02a0, 0xf004649b },
245*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000061 },
246*ec7113fbSMarek Vasut 		{ 0x02a0, 0x0000006d },
247*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000001 },
248*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00000073 },
249*ec7113fbSMarek Vasut 		{ 0x0020, 0x00000007 },
250*ec7113fbSMarek Vasut 		{ 0x0024, 0x0f030a02 },
251*ec7113fbSMarek Vasut 		{ 0x0030, 0x00000001 },
252*ec7113fbSMarek Vasut 		{ 0x00b0, 0x00000000 },
253*ec7113fbSMarek Vasut 		{ 0x0040, 0x0000000b },
254*ec7113fbSMarek Vasut 		{ 0x0044, 0x00000008 },
255*ec7113fbSMarek Vasut 		{ 0x0048, 0x00000000 },
256*ec7113fbSMarek Vasut 		{ 0x0050, 0x0000000b },
257*ec7113fbSMarek Vasut 		{ 0x0054, 0x000c000b },
258*ec7113fbSMarek Vasut 		{ 0x0058, 0x00000027 },
259*ec7113fbSMarek Vasut 		{ 0x005c, 0x0000001c },
260*ec7113fbSMarek Vasut 		{ 0x0060, 0x00000006 },
261*ec7113fbSMarek Vasut 		{ 0x0064, 0x00000020 },
262*ec7113fbSMarek Vasut 		{ 0x0068, 0x00000008 },
263*ec7113fbSMarek Vasut 		{ 0x006c, 0x0000000c },
264*ec7113fbSMarek Vasut 		{ 0x0070, 0x00000009 },
265*ec7113fbSMarek Vasut 		{ 0x0074, 0x00000012 },
266*ec7113fbSMarek Vasut 		{ 0x0078, 0x000000d0 },
267*ec7113fbSMarek Vasut 		{ 0x007c, 0x00140005 },
268*ec7113fbSMarek Vasut 		{ 0x0080, 0x00050004 },
269*ec7113fbSMarek Vasut 		{ 0x0084, 0x70233005 },
270*ec7113fbSMarek Vasut 		{ 0x0088, 0x000c0000 },
271*ec7113fbSMarek Vasut 		{ 0x008c, 0x00000200 },
272*ec7113fbSMarek Vasut 		{ 0x0090, 0x00000040 },
273*ec7113fbSMarek Vasut 		{ 0x0100, 0x00000001 },
274*ec7113fbSMarek Vasut 		{ 0x00c0, 0x00020001 },
275*ec7113fbSMarek Vasut 		{ 0x00c8, 0x20042004 },
276*ec7113fbSMarek Vasut 		{ 0x0380, 0x00020002 },
277*ec7113fbSMarek Vasut 		{ 0x0390, 0x0000001f },
278*ec7113fbSMarek Vasut 	};
279*ec7113fbSMarek Vasut 
280*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config5[] = {
281*ec7113fbSMarek Vasut 		{ 0x0244, 0x00000011 },
282*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000003 },
283*ec7113fbSMarek Vasut 		{ 0x02a0, 0x0300c4e1 },
284*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000023 },
285*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00fcdb60 },
286*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000011 },
287*ec7113fbSMarek Vasut 		{ 0x02a0, 0x1000040b },
288*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000012 },
289*ec7113fbSMarek Vasut 		{ 0x02a0, 0x9d9cbb66 },
290*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000013 },
291*ec7113fbSMarek Vasut 		{ 0x02a0, 0x1a868400 },
292*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000014 },
293*ec7113fbSMarek Vasut 		{ 0x02a0, 0x300214d8 },
294*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000015 },
295*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00000d70 },
296*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000016 },
297*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00000006 },
298*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000017 },
299*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00000018 },
300*ec7113fbSMarek Vasut 		{ 0x0290, 0x0000001a },
301*ec7113fbSMarek Vasut 		{ 0x02a0, 0x910035c7 },
302*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000004 },
303*ec7113fbSMarek Vasut 	};
304*ec7113fbSMarek Vasut 
305*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config6[] = {
306*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000001 },
307*ec7113fbSMarek Vasut 		{ 0x02a0, 0x00000181 },
308*ec7113fbSMarek Vasut 		{ 0x0018, 0x11000000 },
309*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000004 },
310*ec7113fbSMarek Vasut 	};
311*ec7113fbSMarek Vasut 
312*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config7[] = {
313*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000001 },
314*ec7113fbSMarek Vasut 		{ 0x02a0, 0x0000fe01 },
315*ec7113fbSMarek Vasut 		{ 0x0304, 0x00000000 },
316*ec7113fbSMarek Vasut 		{ 0x00f4, 0x01004c20 },
317*ec7113fbSMarek Vasut 		{ 0x00f8, 0x014000aa },
318*ec7113fbSMarek Vasut 		{ 0x00e0, 0x00000140 },
319*ec7113fbSMarek Vasut 		{ 0x00e4, 0x00081860 },
320*ec7113fbSMarek Vasut 		{ 0x00e8, 0x00010000 },
321*ec7113fbSMarek Vasut 		{ 0x0290, 0x00000004 },
322*ec7113fbSMarek Vasut 	};
323*ec7113fbSMarek Vasut 
324*ec7113fbSMarek Vasut 	static const struct reg_config dbsc_config8[] = {
325*ec7113fbSMarek Vasut 		{ 0x0014, 0x00000001 },
326*ec7113fbSMarek Vasut 		{ 0x0010, 0x00000001 },
327*ec7113fbSMarek Vasut 		{ 0x0280, 0x00000000 },
328*ec7113fbSMarek Vasut 	};
329*ec7113fbSMarek Vasut 
330*ec7113fbSMarek Vasut 	static const u32 dbsc3_0_base = DBSC3_0_BASE;
331*ec7113fbSMarek Vasut 	static const u32 dbsc3_1_base = DBSC3_0_BASE + 0x10000;
332*ec7113fbSMarek Vasut 	static const u32 prr_base = 0xff000044;
333*ec7113fbSMarek Vasut 	const u16 prr_rev = readl(prr_base) & 0x7fff;
334*ec7113fbSMarek Vasut 	unsigned int i;
335*ec7113fbSMarek Vasut 
336*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++) {
337*ec7113fbSMarek Vasut 		writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
338*ec7113fbSMarek Vasut 		writel(dbsc_config1[i].val, dbsc3_1_base | dbsc_config1[i].off);
339*ec7113fbSMarek Vasut 	}
340*ec7113fbSMarek Vasut 
341*ec7113fbSMarek Vasut 	dbsc_wait(0x2a0);
342*ec7113fbSMarek Vasut 
343*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++) {
344*ec7113fbSMarek Vasut 		writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
345*ec7113fbSMarek Vasut 		writel(dbsc_config2[i].val, dbsc3_1_base | dbsc_config2[i].off);
346*ec7113fbSMarek Vasut 	}
347*ec7113fbSMarek Vasut 
348*ec7113fbSMarek Vasut 	if (prr_rev == 0x4500) {
349*ec7113fbSMarek Vasut 		for (i = 0; i < ARRAY_SIZE(dbsc_config3r0d0); i++) {
350*ec7113fbSMarek Vasut 			writel(dbsc_config3r0d0[i].val,
351*ec7113fbSMarek Vasut 				dbsc3_0_base | dbsc_config3r0d0[i].off);
352*ec7113fbSMarek Vasut 		}
353*ec7113fbSMarek Vasut 		for (i = 0; i < ARRAY_SIZE(dbsc_config3r0d1); i++) {
354*ec7113fbSMarek Vasut 			writel(dbsc_config3r0d1[i].val,
355*ec7113fbSMarek Vasut 				dbsc3_1_base | dbsc_config3r0d1[i].off);
356*ec7113fbSMarek Vasut 		}
357*ec7113fbSMarek Vasut 	} else if (prr_rev != 0x4510) {
358*ec7113fbSMarek Vasut 		for (i = 0; i < ARRAY_SIZE(dbsc_config3r2); i++) {
359*ec7113fbSMarek Vasut 			writel(dbsc_config3r2[i].val,
360*ec7113fbSMarek Vasut 				dbsc3_0_base | dbsc_config3r2[i].off);
361*ec7113fbSMarek Vasut 			writel(dbsc_config3r2[i].val,
362*ec7113fbSMarek Vasut 				dbsc3_1_base | dbsc_config3r2[i].off);
363*ec7113fbSMarek Vasut 		}
364*ec7113fbSMarek Vasut 	}
365*ec7113fbSMarek Vasut 
366*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++) {
367*ec7113fbSMarek Vasut 		writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
368*ec7113fbSMarek Vasut 		writel(dbsc_config4[i].val, dbsc3_1_base | dbsc_config4[i].off);
369*ec7113fbSMarek Vasut 	}
370*ec7113fbSMarek Vasut 
371*ec7113fbSMarek Vasut 	dbsc_wait(0x240);
372*ec7113fbSMarek Vasut 
373*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++) {
374*ec7113fbSMarek Vasut 		writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
375*ec7113fbSMarek Vasut 		writel(dbsc_config5[i].val, dbsc3_1_base | dbsc_config5[i].off);
376*ec7113fbSMarek Vasut 	}
377*ec7113fbSMarek Vasut 
378*ec7113fbSMarek Vasut 	dbsc_wait(0x2a0);
379*ec7113fbSMarek Vasut 
380*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++) {
381*ec7113fbSMarek Vasut 		writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
382*ec7113fbSMarek Vasut 		writel(dbsc_config6[i].val, dbsc3_1_base | dbsc_config6[i].off);
383*ec7113fbSMarek Vasut 	}
384*ec7113fbSMarek Vasut 
385*ec7113fbSMarek Vasut 	dbsc_wait(0x2a0);
386*ec7113fbSMarek Vasut 
387*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++) {
388*ec7113fbSMarek Vasut 		writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
389*ec7113fbSMarek Vasut 		writel(dbsc_config7[i].val, dbsc3_1_base | dbsc_config7[i].off);
390*ec7113fbSMarek Vasut 	}
391*ec7113fbSMarek Vasut 
392*ec7113fbSMarek Vasut 	dbsc_wait(0x2a0);
393*ec7113fbSMarek Vasut 
394*ec7113fbSMarek Vasut 	for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++) {
395*ec7113fbSMarek Vasut 		writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
396*ec7113fbSMarek Vasut 		writel(dbsc_config8[i].val, dbsc3_1_base | dbsc_config8[i].off);
397*ec7113fbSMarek Vasut 	}
398*ec7113fbSMarek Vasut 
399*ec7113fbSMarek Vasut }
400*ec7113fbSMarek Vasut 
401*ec7113fbSMarek Vasut static void tpl_init_qspi(void)
402*ec7113fbSMarek Vasut {
403*ec7113fbSMarek Vasut 	mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
404*ec7113fbSMarek Vasut 
405*ec7113fbSMarek Vasut 	static const u32 qspi_base = 0xe6b10000;
406*ec7113fbSMarek Vasut 
407*ec7113fbSMarek Vasut 	writeb(0x08, qspi_base + 0x00);
408*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x01);
409*ec7113fbSMarek Vasut 	writeb(0x06, qspi_base + 0x02);
410*ec7113fbSMarek Vasut 	writeb(0x01, qspi_base + 0x0a);
411*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x0b);
412*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x0c);
413*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x0d);
414*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x0e);
415*ec7113fbSMarek Vasut 
416*ec7113fbSMarek Vasut 	writew(0xe080, qspi_base + 0x10);
417*ec7113fbSMarek Vasut 
418*ec7113fbSMarek Vasut 	writeb(0xc0, qspi_base + 0x18);
419*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x18);
420*ec7113fbSMarek Vasut 	writeb(0x00, qspi_base + 0x08);
421*ec7113fbSMarek Vasut 	writeb(0x48, qspi_base + 0x00);
422*ec7113fbSMarek Vasut }
423*ec7113fbSMarek Vasut 
424*ec7113fbSMarek Vasut void board_init_f(ulong dummy)
425*ec7113fbSMarek Vasut {
426*ec7113fbSMarek Vasut 	mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
427*ec7113fbSMarek Vasut 	mstp_clrbits_le32(MSTPSR2, SMSTPCR2, SCIFA0_MSTP204);
428*ec7113fbSMarek Vasut 
429*ec7113fbSMarek Vasut 	/*
430*ec7113fbSMarek Vasut 	 * SD0 clock is set to 97.5MHz by default.
431*ec7113fbSMarek Vasut 	 * Set SD2 to the 97.5MHz as well.
432*ec7113fbSMarek Vasut 	 */
433*ec7113fbSMarek Vasut 	writel(SD_97500KHZ, SD2CKCR);
434*ec7113fbSMarek Vasut 
435*ec7113fbSMarek Vasut 	tpl_init_sys();
436*ec7113fbSMarek Vasut 	tpl_init_pfc();
437*ec7113fbSMarek Vasut 	tpl_init_gpio();
438*ec7113fbSMarek Vasut 	tpl_init_lbsc();
439*ec7113fbSMarek Vasut 	tpl_init_dbsc();
440*ec7113fbSMarek Vasut 	tpl_init_qspi();
441*ec7113fbSMarek Vasut }
442*ec7113fbSMarek Vasut #endif
443*ec7113fbSMarek Vasut 
444*ec7113fbSMarek Vasut void spl_board_init(void)
445*ec7113fbSMarek Vasut {
446*ec7113fbSMarek Vasut 	/* UART clocks enabled and gd valid - init serial console */
447*ec7113fbSMarek Vasut 	preloader_console_init();
448*ec7113fbSMarek Vasut }
449*ec7113fbSMarek Vasut 
450*ec7113fbSMarek Vasut void board_boot_order(u32 *spl_boot_list)
451*ec7113fbSMarek Vasut {
452*ec7113fbSMarek Vasut #ifdef CONFIG_TPL_BUILD
453*ec7113fbSMarek Vasut 	const u32 jtag_magic = 0x1337c0de;
454*ec7113fbSMarek Vasut 	const u32 load_magic = 0xb33fc0de;
455*ec7113fbSMarek Vasut 
456*ec7113fbSMarek Vasut 	/*
457*ec7113fbSMarek Vasut 	 * If JTAG probe sets special word at 0xe6300020, then it must
458*ec7113fbSMarek Vasut 	 * put U-Boot into RAM and TPL will start it from RAM.
459*ec7113fbSMarek Vasut 	 */
460*ec7113fbSMarek Vasut 	if (readl(CONFIG_TPL_TEXT_BASE + 0x20) == jtag_magic) {
461*ec7113fbSMarek Vasut 		printf("JTAG boot detected!\n");
462*ec7113fbSMarek Vasut 
463*ec7113fbSMarek Vasut 		while (readl(CONFIG_TPL_TEXT_BASE + 0x24) != load_magic)
464*ec7113fbSMarek Vasut 			;
465*ec7113fbSMarek Vasut 
466*ec7113fbSMarek Vasut 		spl_boot_list[0] = BOOT_DEVICE_RAM;
467*ec7113fbSMarek Vasut 		spl_boot_list[1] = BOOT_DEVICE_NONE;
468*ec7113fbSMarek Vasut 
469*ec7113fbSMarek Vasut 		return;
470*ec7113fbSMarek Vasut 	}
471*ec7113fbSMarek Vasut #endif
472*ec7113fbSMarek Vasut 
473*ec7113fbSMarek Vasut 	/* Boot from SPI NOR with YMODEM UART fallback. */
474*ec7113fbSMarek Vasut 	spl_boot_list[0] = BOOT_DEVICE_SPI;
475*ec7113fbSMarek Vasut 	spl_boot_list[1] = BOOT_DEVICE_UART;
476*ec7113fbSMarek Vasut 	spl_boot_list[2] = BOOT_DEVICE_NONE;
477*ec7113fbSMarek Vasut }
478*ec7113fbSMarek Vasut 
479*ec7113fbSMarek Vasut void reset_cpu(ulong addr)
480*ec7113fbSMarek Vasut {
481*ec7113fbSMarek Vasut }
482