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