blob: cdaa04e4f4ca44629607ce5de94ca49471f450bf [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Marek Vasut37381a22018-04-23 20:24:16 +02002/*
3 * board/renesas/alt/alt_spl.c
4 *
5 * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
Marek Vasut37381a22018-04-23 20:24:16 +02006 */
7
8#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Marek Vasut37381a22018-04-23 20:24:16 +020011#include <malloc.h>
12#include <dm/platform_data/serial_sh.h>
13#include <asm/processor.h>
14#include <asm/mach-types.h>
15#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060016#include <linux/bitops.h>
Marek Vasut37381a22018-04-23 20:24:16 +020017#include <linux/errno.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/gpio.h>
20#include <asm/arch/rmobile.h>
21#include <asm/arch/rcar-mstp.h>
22
23#include <spl.h>
24
25#define TMU0_MSTP125 BIT(25)
26#define SCIF2_MSTP719 BIT(19)
27#define QSPI_MSTP917 BIT(17)
28
29#define SD1CKCR 0xE6150078
30#define SD_97500KHZ 0x7
31
32struct reg_config {
33 u16 off;
34 u32 val;
35};
36
37static void dbsc_wait(u16 reg)
38{
39 static const u32 dbsc3_0_base = DBSC3_0_BASE;
40
41 while (!(readl(dbsc3_0_base + reg) & BIT(0)))
42 ;
43}
44
45static void spl_init_sys(void)
46{
47 u32 r0 = 0;
48
49 writel(0xa5a5a500, 0xe6020004);
50 writel(0xa5a5a500, 0xe6030004);
51
52 asm volatile(
53 /* ICIALLU - Invalidate I$ to PoU */
54 "mcr 15, 0, %0, cr7, cr5, 0 \n"
55 /* BPIALL - Invalidate branch predictors */
56 "mcr 15, 0, %0, cr7, cr5, 6 \n"
57 /* Set SCTLR[IZ] */
58 "mrc 15, 0, %0, cr1, cr0, 0 \n"
59 "orr %0, #0x1800 \n"
60 "mcr 15, 0, %0, cr1, cr0, 0 \n"
61 "isb sy \n"
62 :"=r"(r0));
63}
64
65static void spl_init_pfc(void)
66{
67 static const struct reg_config pfc_with_unlock[] = {
68 { 0x0090, 0x00000000 },
69 { 0x0094, 0x00000000 },
70 { 0x0098, 0x00000000 },
71 { 0x0020, 0x00000000 },
72 { 0x0024, 0x00000000 },
73 { 0x0028, 0x40000000 },
74 { 0x002c, 0x00000155 },
75 { 0x0030, 0x00000002 },
76 { 0x0034, 0x00000000 },
77 { 0x0038, 0x00000000 },
78 { 0x003c, 0x00000000 },
79 { 0x0040, 0x60000000 },
80 { 0x0044, 0x36dab6db },
81 { 0x0048, 0x926da012 },
82 { 0x004c, 0x0008c383 },
83 { 0x0050, 0x00000000 },
84 { 0x0054, 0x00000140 },
85 { 0x0004, 0xffffffff },
86 { 0x0008, 0x00ec3fff },
87 { 0x000c, 0x5bffffff },
88 { 0x0010, 0x01bfe1ff },
89 { 0x0014, 0x5bffffff },
90 { 0x0018, 0x0f4b200f },
91 { 0x001c, 0x03ffffff },
92 };
93
94 static const struct reg_config pfc_without_unlock[] = {
95 { 0x0100, 0x00000000 },
96 { 0x0104, 0x4203fc00 },
97 { 0x0108, 0x00000000 },
98 { 0x010c, 0x159007ff },
99 { 0x0110, 0x80000000 },
100 { 0x0114, 0x00de481f },
101 { 0x0118, 0x00000000 },
102 };
103
104 static const struct reg_config pfc_with_unlock2[] = {
105 { 0x0060, 0xffffffff },
106 { 0x0064, 0xfffff000 },
107 { 0x0068, 0x55555500 },
108 { 0x006c, 0xffffff00 },
109 { 0x0070, 0x00000000 },
110 };
111
112 static const u32 pfc_base = 0xe6060000;
113
114 unsigned int i;
115
116 for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
117 writel(~pfc_with_unlock[i].val, pfc_base);
118 writel(pfc_with_unlock[i].val,
119 pfc_base | pfc_with_unlock[i].off);
120 }
121
122 for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
123 writel(pfc_without_unlock[i].val,
124 pfc_base | pfc_without_unlock[i].off);
125
126 for (i = 0; i < ARRAY_SIZE(pfc_with_unlock2); i++) {
127 writel(~pfc_with_unlock2[i].val, pfc_base);
128 writel(pfc_with_unlock2[i].val,
129 pfc_base | pfc_with_unlock2[i].off);
130 }
131}
132
133static void spl_init_gpio(void)
134{
135 static const u16 gpio_offs[] = {
136 0x1000, 0x2000, 0x3000, 0x4000, 0x5000
137 };
138
139 static const struct reg_config gpio_set[] = {
140 { 0x2000, 0x24000000 },
141 { 0x4000, 0xa4000000 },
142 { 0x5000, 0x0004c000 },
143 };
144
145 static const struct reg_config gpio_clr[] = {
146 { 0x1000, 0x01000000 },
147 { 0x2000, 0x24000000 },
148 { 0x3000, 0x00000000 },
149 { 0x4000, 0xa4000000 },
150 { 0x5000, 0x0084c380 },
151 };
152
153 static const u32 gpio_base = 0xe6050000;
154
155 unsigned int i;
156
157 for (i = 0; i < ARRAY_SIZE(gpio_offs); i++)
158 writel(0, gpio_base | 0x20 | gpio_offs[i]);
159
160 for (i = 0; i < ARRAY_SIZE(gpio_offs); i++)
161 writel(0, gpio_base | 0x00 | gpio_offs[i]);
162
163 for (i = 0; i < ARRAY_SIZE(gpio_set); i++)
164 writel(gpio_set[i].val, gpio_base | 0x08 | gpio_set[i].off);
165
166 for (i = 0; i < ARRAY_SIZE(gpio_clr); i++)
167 writel(gpio_clr[i].val, gpio_base | 0x04 | gpio_clr[i].off);
168}
169
170static void spl_init_lbsc(void)
171{
172 static const struct reg_config lbsc_config[] = {
173 { 0x00, 0x00000020 },
174 { 0x08, 0x00002020 },
175 { 0x30, 0x2a103320 },
176 { 0x38, 0xff70ff70 },
177 };
178
179 static const u16 lbsc_offs[] = {
180 0x80, 0x84, 0x88, 0x8c, 0xa0, 0xc0, 0xc4, 0xc8
181 };
182
183 static const u32 lbsc_base = 0xfec00200;
184
185 unsigned int i;
186
187 for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
188 writel(lbsc_config[i].val,
189 lbsc_base | lbsc_config[i].off);
190 writel(lbsc_config[i].val,
191 lbsc_base | (lbsc_config[i].off + 4));
192 }
193
194 for (i = 0; i < ARRAY_SIZE(lbsc_offs); i++)
195 writel(0, lbsc_base | lbsc_offs[i]);
196}
197
198static void spl_init_dbsc(void)
199{
200 static const struct reg_config dbsc_config1[] = {
201 { 0x0018, 0x21000000 },
202 { 0x0018, 0x11000000 },
203 { 0x0018, 0x10000000 },
204 { 0x0280, 0x0000a55a },
205 { 0x0290, 0x00000001 },
206 { 0x02a0, 0x80000000 },
207 { 0x0290, 0x00000004 },
208 };
209
210 static const struct reg_config dbsc_config2[] = {
211 { 0x0290, 0x00000006 },
212 { 0x02a0, 0x0005c000 },
213 };
214
215 static const struct reg_config dbsc_config4[] = {
216 { 0x0290, 0x00000010 },
217 { 0x02a0, 0xf00464db },
218 { 0x0290, 0x00000061 },
219 { 0x02a0, 0x0000006d },
220 { 0x0290, 0x00000001 },
221 { 0x02a0, 0x00000073 },
222 { 0x0020, 0x00000007 },
223 { 0x0024, 0x0f030a02 },
224 { 0x0030, 0x00000001 },
225 { 0x00b0, 0x00000000 },
226 { 0x0040, 0x00000009 },
227 { 0x0044, 0x00000007 },
228 { 0x0048, 0x00000000 },
229 { 0x0050, 0x00000009 },
230 { 0x0054, 0x000a0009 },
231 { 0x0058, 0x00000021 },
232 { 0x005c, 0x00000018 },
233 { 0x0060, 0x00000005 },
234 { 0x0064, 0x0000001b },
235 { 0x0068, 0x00000007 },
236 { 0x006c, 0x0000000a },
237 { 0x0070, 0x00000009 },
238 { 0x0074, 0x00000010 },
239 { 0x0078, 0x000000ae },
240 { 0x007c, 0x00140005 },
241 { 0x0080, 0x00050004 },
242 { 0x0084, 0x50213005 },
243 { 0x0088, 0x000c0000 },
244 { 0x008c, 0x00000200 },
245 { 0x0090, 0x00000040 },
246 { 0x0100, 0x00000001 },
247 { 0x00c0, 0x00020001 },
248 { 0x00c8, 0x20082008 },
249 { 0x0380, 0x00020003 },
250 { 0x0390, 0x0000001f },
251 };
252
253 static const struct reg_config dbsc_config5[] = {
254 { 0x0244, 0x00000011 },
255 { 0x0290, 0x00000003 },
256 { 0x02a0, 0x0300c4e1 },
257 { 0x0290, 0x00000023 },
258 { 0x02a0, 0x00fcb6d0 },
259 { 0x0290, 0x00000011 },
260 { 0x02a0, 0x1000040b },
261 { 0x0290, 0x00000012 },
262 { 0x02a0, 0x85589955 },
263 { 0x0290, 0x00000013 },
264 { 0x02a0, 0x1a852400 },
265 { 0x0290, 0x00000014 },
266 { 0x02a0, 0x300210b4 },
267 { 0x0290, 0x00000015 },
268 { 0x02a0, 0x00000b50 },
269 { 0x0290, 0x00000016 },
270 { 0x02a0, 0x00000006 },
271 { 0x0290, 0x00000017 },
272 { 0x02a0, 0x00000010 },
273 { 0x0290, 0x0000001a },
274 { 0x02a0, 0x910035c7 },
275 { 0x0290, 0x00000004 },
276 };
277
278 static const struct reg_config dbsc_config6[] = {
279 { 0x0290, 0x00000001 },
280 { 0x02a0, 0x00000181 },
281 { 0x0018, 0x11000000 },
282 { 0x0290, 0x00000004 },
283 };
284
285 static const struct reg_config dbsc_config7[] = {
286 { 0x0290, 0x00000001 },
287 { 0x02a0, 0x0000fe01 },
288 { 0x0304, 0x00000000 },
289 { 0x00f4, 0x01004c20 },
290 { 0x00f8, 0x014000aa },
291 { 0x00e0, 0x00000140 },
292 { 0x00e4, 0x00081450 },
293 { 0x00e8, 0x00010000 },
294 { 0x0290, 0x00000004 },
295 };
296
297 static const struct reg_config dbsc_config8[] = {
298 { 0x0014, 0x00000001 },
299 { 0x0010, 0x00000001 },
300 { 0x0280, 0x00000000 },
301 };
302
303 static const u32 dbsc3_0_base = DBSC3_0_BASE;
304 unsigned int i;
305
306 for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++)
307 writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
308
309 dbsc_wait(0x2a0);
310
311 for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++)
312 writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
313
314 for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++)
315 writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
316
317 dbsc_wait(0x240);
318
319 for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++)
320 writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
321
322 dbsc_wait(0x2a0);
323
324 for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++)
325 writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
326
327 dbsc_wait(0x2a0);
328
329 for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++)
330 writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
331
332 dbsc_wait(0x2a0);
333
334 for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++)
335 writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
336
337}
338
339static void spl_init_qspi(void)
340{
341 mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
342
343 static const u32 qspi_base = 0xe6b10000;
344
345 writeb(0x08, qspi_base + 0x00);
346 writeb(0x00, qspi_base + 0x01);
347 writeb(0x06, qspi_base + 0x02);
348 writeb(0x01, qspi_base + 0x0a);
349 writeb(0x00, qspi_base + 0x0b);
350 writeb(0x00, qspi_base + 0x0c);
351 writeb(0x00, qspi_base + 0x0d);
352 writeb(0x00, qspi_base + 0x0e);
353
354 writew(0xe080, qspi_base + 0x10);
355
356 writeb(0xc0, qspi_base + 0x18);
357 writeb(0x00, qspi_base + 0x18);
358 writeb(0x00, qspi_base + 0x08);
359 writeb(0x48, qspi_base + 0x00);
360}
361
362void board_init_f(ulong dummy)
363{
364 mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
365 mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719);
366
367 /* Set SD1 to the 97.5MHz */
368 writel(SD_97500KHZ, SD1CKCR);
369
370 spl_init_sys();
371 spl_init_pfc();
372 spl_init_gpio();
373 spl_init_lbsc();
374 spl_init_dbsc();
375 spl_init_qspi();
376}
377
378void spl_board_init(void)
379{
380 /* UART clocks enabled and gd valid - init serial console */
381 preloader_console_init();
382}
383
384void board_boot_order(u32 *spl_boot_list)
385{
386 const u32 jtag_magic = 0x1337c0de;
387 const u32 load_magic = 0xb33fc0de;
388
389 /*
390 * If JTAG probe sets special word at 0xe6300020, then it must
391 * put U-Boot into RAM and SPL will start it from RAM.
392 */
393 if (readl(CONFIG_SPL_TEXT_BASE + 0x20) == jtag_magic) {
394 printf("JTAG boot detected!\n");
395
396 while (readl(CONFIG_SPL_TEXT_BASE + 0x24) != load_magic)
397 ;
398
399 spl_boot_list[0] = BOOT_DEVICE_RAM;
400 spl_boot_list[1] = BOOT_DEVICE_NONE;
401
402 return;
403 }
404
405 /* Boot from SPI NOR with YMODEM UART fallback. */
406 spl_boot_list[0] = BOOT_DEVICE_SPI;
407 spl_boot_list[1] = BOOT_DEVICE_UART;
408 spl_boot_list[2] = BOOT_DEVICE_NONE;
409}
410
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100411void reset_cpu(void)
Marek Vasut37381a22018-04-23 20:24:16 +0200412{
413}