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