koelsch_spl.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * board/renesas/koelsch/koelsch_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, 0x001800f0 },
  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. { 0x0018, 0x21000000 },
  164. { 0x0018, 0x11000000 },
  165. { 0x0018, 0x10000000 },
  166. { 0x0280, 0x0000a55a },
  167. { 0x0290, 0x00000010 },
  168. { 0x02a0, 0xf004649b },
  169. { 0x0020, 0x00000007 },
  170. { 0x0024, 0x0f030a02 },
  171. { 0x0030, 0x00000001 },
  172. { 0x00b0, 0x00000000 },
  173. { 0x0040, 0x0000000b },
  174. { 0x0044, 0x00000008 },
  175. { 0x0048, 0x00000000 },
  176. { 0x0050, 0x0000000b },
  177. { 0x0054, 0x000c000b },
  178. { 0x0058, 0x00000027 },
  179. { 0x005c, 0x0000001c },
  180. { 0x0060, 0x00000006 },
  181. { 0x0064, 0x00000020 },
  182. { 0x0068, 0x00000008 },
  183. { 0x006c, 0x0000000c },
  184. { 0x0070, 0x00000009 },
  185. { 0x0074, 0x00000012 },
  186. { 0x0078, 0x000000d0 },
  187. { 0x007c, 0x00140005 },
  188. { 0x0080, 0x00050004 },
  189. { 0x0084, 0x70233005 },
  190. { 0x0088, 0x000c0000 },
  191. { 0x008c, 0x00000300 },
  192. { 0x0090, 0x00000040 },
  193. { 0x0100, 0x00000001 },
  194. { 0x00c0, 0x00020001 },
  195. { 0x00c8, 0x20082008 },
  196. { 0x0380, 0x00020002 },
  197. { 0x0390, 0x0000001f },
  198. };
  199. static const struct reg_config dbsc_config5[] = {
  200. { 0x0244, 0x00000011 },
  201. { 0x0290, 0x00000006 },
  202. { 0x02a0, 0x0005c000 },
  203. { 0x0290, 0x00000003 },
  204. { 0x02a0, 0x0300c481 },
  205. { 0x0290, 0x00000023 },
  206. { 0x02a0, 0x00fdb6c0 },
  207. { 0x0290, 0x00000011 },
  208. { 0x02a0, 0x1000040b },
  209. { 0x0290, 0x00000012 },
  210. { 0x02a0, 0x9d9cbb66 },
  211. { 0x0290, 0x00000013 },
  212. { 0x02a0, 0x1a868400 },
  213. { 0x0290, 0x00000014 },
  214. { 0x02a0, 0x300214d8 },
  215. { 0x0290, 0x00000015 },
  216. { 0x02a0, 0x00000d70 },
  217. { 0x0290, 0x00000016 },
  218. { 0x02a0, 0x00000006 },
  219. { 0x0290, 0x00000017 },
  220. { 0x02a0, 0x00000018 },
  221. { 0x0290, 0x0000001a },
  222. { 0x02a0, 0x910035c7 },
  223. { 0x0290, 0x00000004 },
  224. };
  225. static const struct reg_config dbsc_config6[] = {
  226. { 0x0290, 0x00000001 },
  227. { 0x02a0, 0x00000181 },
  228. { 0x0018, 0x11000000 },
  229. { 0x0290, 0x00000004 },
  230. };
  231. static const struct reg_config dbsc_config7[] = {
  232. { 0x0290, 0x00000001 },
  233. { 0x02a0, 0x0000fe01 },
  234. { 0x0290, 0x00000004 },
  235. };
  236. static const struct reg_config dbsc_config8[] = {
  237. { 0x0304, 0x00000000 },
  238. { 0x00f4, 0x01004c20 },
  239. { 0x00f8, 0x014000aa },
  240. { 0x00e0, 0x00000140 },
  241. { 0x00e4, 0x00081860 },
  242. { 0x00e8, 0x00010000 },
  243. { 0x0014, 0x00000001 },
  244. { 0x0010, 0x00000001 },
  245. { 0x0280, 0x00000000 },
  246. };
  247. static const u32 dbsc3_0_base = DBSC3_0_BASE;
  248. static const u32 dbsc3_1_base = DBSC3_0_BASE + 0x10000;
  249. unsigned int i;
  250. for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++) {
  251. writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
  252. writel(dbsc_config1[i].val, dbsc3_1_base | dbsc_config1[i].off);
  253. }
  254. dbsc_wait(0x240);
  255. for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++) {
  256. writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
  257. writel(dbsc_config5[i].val, dbsc3_1_base | dbsc_config5[i].off);
  258. }
  259. dbsc_wait(0x2a0);
  260. for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++) {
  261. writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
  262. writel(dbsc_config6[i].val, dbsc3_1_base | dbsc_config6[i].off);
  263. }
  264. dbsc_wait(0x2a0);
  265. for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++) {
  266. writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
  267. writel(dbsc_config7[i].val, dbsc3_1_base | dbsc_config7[i].off);
  268. }
  269. dbsc_wait(0x2a0);
  270. for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++) {
  271. writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
  272. writel(dbsc_config8[i].val, dbsc3_1_base | dbsc_config8[i].off);
  273. }
  274. }
  275. static void spl_init_qspi(void)
  276. {
  277. mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
  278. static const u32 qspi_base = 0xe6b10000;
  279. writeb(0x08, qspi_base + 0x00);
  280. writeb(0x00, qspi_base + 0x01);
  281. writeb(0x06, qspi_base + 0x02);
  282. writeb(0x01, qspi_base + 0x0a);
  283. writeb(0x00, qspi_base + 0x0b);
  284. writeb(0x00, qspi_base + 0x0c);
  285. writeb(0x00, qspi_base + 0x0d);
  286. writeb(0x00, qspi_base + 0x0e);
  287. writew(0xe080, qspi_base + 0x10);
  288. writeb(0xc0, qspi_base + 0x18);
  289. writeb(0x00, qspi_base + 0x18);
  290. writeb(0x00, qspi_base + 0x08);
  291. writeb(0x48, qspi_base + 0x00);
  292. }
  293. void board_init_f(ulong dummy)
  294. {
  295. int i;
  296. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  297. mstp_clrbits_le32(MSTPSR7, SMSTPCR7, SCIF0_MSTP721);
  298. /*
  299. * SD0 clock is set to 97.5MHz by default.
  300. * Set SD2 to the 97.5MHz as well.
  301. */
  302. writel(SD_97500KHZ, SD2CKCR);
  303. spl_init_sys();
  304. spl_init_pfc();
  305. spl_init_gpio();
  306. spl_init_lbsc();
  307. /* Unknown, likely ES1.0-specific delay */
  308. for (i = 0; i < 100000; i++)
  309. asm volatile("nop");
  310. spl_init_dbsc();
  311. spl_init_qspi();
  312. }
  313. void spl_board_init(void)
  314. {
  315. /* UART clocks enabled and gd valid - init serial console */
  316. preloader_console_init();
  317. }
  318. void board_boot_order(u32 *spl_boot_list)
  319. {
  320. const u32 jtag_magic = 0x1337c0de;
  321. const u32 load_magic = 0xb33fc0de;
  322. /*
  323. * If JTAG probe sets special word at 0xe6300020, then it must
  324. * put U-Boot into RAM and SPL will start it from RAM.
  325. */
  326. if (readl(CONFIG_SPL_TEXT_BASE + 0x20) == jtag_magic) {
  327. printf("JTAG boot detected!\n");
  328. while (readl(CONFIG_SPL_TEXT_BASE + 0x24) != load_magic)
  329. ;
  330. spl_boot_list[0] = BOOT_DEVICE_RAM;
  331. spl_boot_list[1] = BOOT_DEVICE_NONE;
  332. return;
  333. }
  334. /* Boot from SPI NOR with YMODEM UART fallback. */
  335. spl_boot_list[0] = BOOT_DEVICE_SPI;
  336. spl_boot_list[1] = BOOT_DEVICE_UART;
  337. spl_boot_list[2] = BOOT_DEVICE_NONE;
  338. }
  339. void reset_cpu(ulong addr)
  340. {
  341. }