porter_spl.c 12 KB

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