silk_spl.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * board/renesas/silk/silk_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 SCIF2_MSTP719 BIT(19)
  21. #define QSPI_MSTP917 BIT(17)
  22. #define SD1CKCR 0xE6150078
  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. while (!(readl(dbsc3_0_base + reg) & BIT(0)))
  32. ;
  33. }
  34. static void spl_init_sys(void)
  35. {
  36. u32 r0 = 0;
  37. writel(0xa5a5a500, 0xe6020004);
  38. writel(0xa5a5a500, 0xe6030004);
  39. asm volatile(
  40. /* ICIALLU - Invalidate I$ to PoU */
  41. "mcr 15, 0, %0, cr7, cr5, 0 \n"
  42. /* BPIALL - Invalidate branch predictors */
  43. "mcr 15, 0, %0, cr7, cr5, 6 \n"
  44. /* Set SCTLR[IZ] */
  45. "mrc 15, 0, %0, cr1, cr0, 0 \n"
  46. "orr %0, #0x1800 \n"
  47. "mcr 15, 0, %0, cr1, cr0, 0 \n"
  48. "isb sy \n"
  49. :"=r"(r0));
  50. }
  51. static void spl_init_pfc(void)
  52. {
  53. static const struct reg_config pfc_with_unlock[] = {
  54. { 0x0090, 0x00018040 },
  55. { 0x0094, 0x00000000 },
  56. { 0x0098, 0x00000000 },
  57. { 0x0020, 0x94000000 },
  58. { 0x0024, 0x00000006 },
  59. { 0x0028, 0x40000000 },
  60. { 0x002c, 0x00000155 },
  61. { 0x0030, 0x00000002 },
  62. { 0x0034, 0x00000000 },
  63. { 0x0038, 0x00000000 },
  64. { 0x003c, 0x00000000 },
  65. { 0x0040, 0x60000000 },
  66. { 0x0044, 0x36dab6db },
  67. { 0x0048, 0x926da012 },
  68. { 0x004c, 0x0008c383 },
  69. { 0x0050, 0x00000000 },
  70. { 0x0054, 0x00000140 },
  71. { 0x0004, 0xffffffff },
  72. { 0x0008, 0x00ec3fff },
  73. { 0x000c, 0x5bffffff },
  74. { 0x0010, 0x01bfe1ff },
  75. { 0x0014, 0x5bffffff },
  76. { 0x0018, 0x0f4b200f },
  77. { 0x001c, 0x03ffffff },
  78. };
  79. static const struct reg_config pfc_without_unlock[] = {
  80. { 0x0100, 0x00000000 },
  81. { 0x0104, 0x4203fdf0 },
  82. { 0x0108, 0x00000000 },
  83. { 0x010c, 0x159007ff },
  84. { 0x0110, 0x80000000 },
  85. { 0x0114, 0x00de481f },
  86. { 0x0118, 0x00000000 },
  87. };
  88. static const struct reg_config pfc_with_unlock2[] = {
  89. { 0x0060, 0xffffffff },
  90. { 0x0064, 0xfffff000 },
  91. { 0x0068, 0x55555500 },
  92. { 0x006c, 0xffffff00 },
  93. { 0x0070, 0x00000000 },
  94. };
  95. static const u32 pfc_base = 0xe6060000;
  96. unsigned int i;
  97. for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
  98. writel(~pfc_with_unlock[i].val, pfc_base);
  99. writel(pfc_with_unlock[i].val,
  100. pfc_base | pfc_with_unlock[i].off);
  101. }
  102. for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
  103. writel(pfc_without_unlock[i].val,
  104. pfc_base | pfc_without_unlock[i].off);
  105. for (i = 0; i < ARRAY_SIZE(pfc_with_unlock2); i++) {
  106. writel(~pfc_with_unlock2[i].val, pfc_base);
  107. writel(pfc_with_unlock2[i].val,
  108. pfc_base | pfc_with_unlock2[i].off);
  109. }
  110. }
  111. static void spl_init_gpio(void)
  112. {
  113. static const u16 gpio_offs[] = {
  114. 0x1000, 0x2000, 0x3000, 0x4000
  115. };
  116. static const struct reg_config gpio_set[] = {
  117. { 0x2000, 0x24000000 },
  118. { 0x4000, 0xa4000000 },
  119. { 0x5000, 0x0084c000 },
  120. };
  121. static const struct reg_config gpio_clr[] = {
  122. { 0x1000, 0x01000000 },
  123. { 0x2000, 0x24000000 },
  124. { 0x3000, 0x00000000 },
  125. { 0x4000, 0xa4000000 },
  126. { 0x5000, 0x00044380 },
  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. writel(BIT(23), gpio_base | 0x5020);
  133. for (i = 0; i < ARRAY_SIZE(gpio_offs); i++)
  134. writel(0, gpio_base | 0x00 | gpio_offs[i]);
  135. writel(BIT(23), gpio_base | 0x5000);
  136. for (i = 0; i < ARRAY_SIZE(gpio_set); i++)
  137. writel(gpio_set[i].val, gpio_base | 0x08 | gpio_set[i].off);
  138. for (i = 0; i < ARRAY_SIZE(gpio_clr); i++)
  139. writel(gpio_clr[i].val, gpio_base | 0x04 | gpio_clr[i].off);
  140. }
  141. static void spl_init_lbsc(void)
  142. {
  143. static const struct reg_config lbsc_config[] = {
  144. { 0x00, 0x00000020 },
  145. { 0x08, 0x00002020 },
  146. { 0x30, 0x2a103320 },
  147. { 0x38, 0xff70ff70 },
  148. };
  149. static const u16 lbsc_offs[] = {
  150. 0x80, 0x84, 0x88, 0x8c, 0xa0, 0xc0, 0xc4, 0xc8
  151. };
  152. static const u32 lbsc_base = 0xfec00200;
  153. unsigned int i;
  154. for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
  155. writel(lbsc_config[i].val,
  156. lbsc_base | lbsc_config[i].off);
  157. writel(lbsc_config[i].val,
  158. lbsc_base | (lbsc_config[i].off + 4));
  159. }
  160. for (i = 0; i < ARRAY_SIZE(lbsc_offs); i++)
  161. writel(0, lbsc_base | lbsc_offs[i]);
  162. }
  163. static void spl_init_dbsc(void)
  164. {
  165. static const struct reg_config dbsc_config1[] = {
  166. { 0x0018, 0x21000000 },
  167. { 0x0018, 0x11000000 },
  168. { 0x0018, 0x10000000 },
  169. { 0x0280, 0x0000a55a },
  170. { 0x0290, 0x00000001 },
  171. { 0x02a0, 0x80000000 },
  172. { 0x0290, 0x00000004 },
  173. };
  174. static const struct reg_config dbsc_config2[] = {
  175. { 0x0290, 0x00000006 },
  176. { 0x02a0, 0x0005c000 },
  177. };
  178. static const struct reg_config dbsc_config3r2[] = {
  179. { 0x0290, 0x0000000f },
  180. { 0x02a0, 0x00181224 },
  181. };
  182. static const struct reg_config dbsc_config4[] = {
  183. { 0x0290, 0x00000010 },
  184. { 0x02a0, 0xf004649b },
  185. { 0x0290, 0x00000061 },
  186. { 0x02a0, 0x0000006d },
  187. { 0x0290, 0x00000001 },
  188. { 0x02a0, 0x00000073 },
  189. { 0x0020, 0x00000007 },
  190. { 0x0024, 0x0f030a02 },
  191. { 0x0030, 0x00000001 },
  192. { 0x00b0, 0x00000000 },
  193. { 0x0040, 0x00000009 },
  194. { 0x0044, 0x00000007 },
  195. { 0x0048, 0x00000000 },
  196. { 0x0050, 0x00000009 },
  197. { 0x0054, 0x000a0009 },
  198. { 0x0058, 0x00000021 },
  199. { 0x005c, 0x00000018 },
  200. { 0x0060, 0x00000005 },
  201. { 0x0064, 0x00000020 },
  202. { 0x0068, 0x00000007 },
  203. { 0x006c, 0x0000000a },
  204. { 0x0070, 0x00000009 },
  205. { 0x0074, 0x00000010 },
  206. { 0x0078, 0x000000ae },
  207. { 0x007c, 0x00140005 },
  208. { 0x0080, 0x00050004 },
  209. { 0x0084, 0x50213005 },
  210. { 0x0088, 0x000c0000 },
  211. { 0x008c, 0x00000200 },
  212. { 0x0090, 0x00000040 },
  213. { 0x0100, 0x00000001 },
  214. { 0x00c0, 0x00020001 },
  215. { 0x00c8, 0x20042004 },
  216. { 0x0380, 0x00020003 },
  217. { 0x0390, 0x0000001f },
  218. };
  219. static const struct reg_config dbsc_config5[] = {
  220. { 0x0244, 0x00000011 },
  221. { 0x0290, 0x00000003 },
  222. { 0x02a0, 0x0300c4e1 },
  223. { 0x0290, 0x00000023 },
  224. { 0x02a0, 0x00fcb6d0 },
  225. { 0x0290, 0x00000011 },
  226. { 0x02a0, 0x1000040b },
  227. { 0x0290, 0x00000012 },
  228. { 0x02a0, 0x85589955 },
  229. { 0x0290, 0x00000013 },
  230. { 0x02a0, 0x1a852400 },
  231. { 0x0290, 0x00000014 },
  232. { 0x02a0, 0x300210b4 },
  233. { 0x0290, 0x00000015 },
  234. { 0x02a0, 0x00000b50 },
  235. { 0x0290, 0x00000016 },
  236. { 0x02a0, 0x00000006 },
  237. { 0x0290, 0x00000017 },
  238. { 0x02a0, 0x00000010 },
  239. { 0x0290, 0x0000001a },
  240. { 0x02a0, 0x910035c7 },
  241. { 0x0290, 0x00000004 },
  242. };
  243. static const struct reg_config dbsc_config6[] = {
  244. { 0x0290, 0x00000001 },
  245. { 0x02a0, 0x00000181 },
  246. { 0x0018, 0x11000000 },
  247. { 0x0290, 0x00000004 },
  248. };
  249. static const struct reg_config dbsc_config7[] = {
  250. { 0x0290, 0x00000001 },
  251. { 0x02a0, 0x0000fe01 },
  252. { 0x0304, 0x00000000 },
  253. { 0x00f4, 0x01004c20 },
  254. { 0x00f8, 0x012c00be },
  255. { 0x00e0, 0x00000140 },
  256. { 0x00e4, 0x00081450 },
  257. { 0x00e8, 0x00010000 },
  258. { 0x0290, 0x00000004 },
  259. };
  260. static const struct reg_config dbsc_config8[] = {
  261. { 0x0014, 0x00000001 },
  262. { 0x0290, 0x00000010 },
  263. { 0x02a0, 0xf00464db },
  264. { 0x0010, 0x00000001 },
  265. { 0x0280, 0x00000000 },
  266. };
  267. static const u32 dbsc3_0_base = DBSC3_0_BASE;
  268. unsigned int i;
  269. for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++)
  270. writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
  271. dbsc_wait(0x2a0);
  272. for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++)
  273. writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
  274. for (i = 0; i < ARRAY_SIZE(dbsc_config3r2); i++) {
  275. writel(dbsc_config3r2[i].val,
  276. dbsc3_0_base | dbsc_config3r2[i].off);
  277. }
  278. for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++)
  279. writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
  280. dbsc_wait(0x240);
  281. for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++)
  282. writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
  283. dbsc_wait(0x2a0);
  284. for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++)
  285. writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
  286. dbsc_wait(0x2a0);
  287. for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++)
  288. writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
  289. dbsc_wait(0x2a0);
  290. for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++)
  291. writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
  292. }
  293. static void spl_init_qspi(void)
  294. {
  295. mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
  296. static const u32 qspi_base = 0xe6b10000;
  297. writeb(0x08, qspi_base + 0x00);
  298. writeb(0x00, qspi_base + 0x01);
  299. writeb(0x06, qspi_base + 0x02);
  300. writeb(0x01, qspi_base + 0x0a);
  301. writeb(0x00, qspi_base + 0x0b);
  302. writeb(0x00, qspi_base + 0x0c);
  303. writeb(0x00, qspi_base + 0x0d);
  304. writeb(0x00, qspi_base + 0x0e);
  305. writew(0xe080, qspi_base + 0x10);
  306. writeb(0xc0, qspi_base + 0x18);
  307. writeb(0x00, qspi_base + 0x18);
  308. writeb(0x00, qspi_base + 0x08);
  309. writeb(0x48, qspi_base + 0x00);
  310. }
  311. void board_init_f(ulong dummy)
  312. {
  313. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  314. mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF2_MSTP719);
  315. /* Set SD1 to the 97.5MHz */
  316. writel(SD_97500KHZ, SD1CKCR);
  317. spl_init_sys();
  318. spl_init_pfc();
  319. spl_init_gpio();
  320. spl_init_lbsc();
  321. spl_init_dbsc();
  322. spl_init_qspi();
  323. }
  324. void spl_board_init(void)
  325. {
  326. /* UART clocks enabled and gd valid - init serial console */
  327. preloader_console_init();
  328. }
  329. void board_boot_order(u32 *spl_boot_list)
  330. {
  331. const u32 jtag_magic = 0x1337c0de;
  332. const u32 load_magic = 0xb33fc0de;
  333. /*
  334. * If JTAG probe sets special word at 0xe6300020, then it must
  335. * put U-Boot into RAM and SPL will start it from RAM.
  336. */
  337. if (readl(CONFIG_SPL_TEXT_BASE + 0x20) == jtag_magic) {
  338. printf("JTAG boot detected!\n");
  339. while (readl(CONFIG_SPL_TEXT_BASE + 0x24) != load_magic)
  340. ;
  341. spl_boot_list[0] = BOOT_DEVICE_RAM;
  342. spl_boot_list[1] = BOOT_DEVICE_NONE;
  343. return;
  344. }
  345. /* Boot from SPI NOR with YMODEM UART fallback. */
  346. spl_boot_list[0] = BOOT_DEVICE_SPI;
  347. spl_boot_list[1] = BOOT_DEVICE_UART;
  348. spl_boot_list[2] = BOOT_DEVICE_NONE;
  349. }
  350. void reset_cpu(ulong addr)
  351. {
  352. }