porter_spl.c 12 KB

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