blanche.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * board/renesas/blanche/blanche.c
  4. * This file is blanche board support.
  5. *
  6. * Copyright (C) 2016 Renesas Electronics Corporation
  7. */
  8. #include <common.h>
  9. #include <asm/arch/mmc.h>
  10. #include <asm/arch/rcar-mstp.h>
  11. #include <asm/arch/rmobile.h>
  12. #include <asm/arch/sh_sdhi.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <asm/gpio.h>
  15. #include <asm/io.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/processor.h>
  18. #include <dm.h>
  19. #include <dm/platform_data/serial_sh.h>
  20. #include <environment.h>
  21. #include <i2c.h>
  22. #include <linux/errno.h>
  23. #include <malloc.h>
  24. #include <miiphy.h>
  25. #include <mmc.h>
  26. #include <netdev.h>
  27. #include "qos.h"
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #define CPG_PLL1CR 0xE6150028
  30. #define CPG_PLL3CR 0xE61500DC
  31. #define TMU0_MSTP125 BIT(25)
  32. #define QSPI_MSTP917 BIT(17)
  33. struct reg_config {
  34. u16 off;
  35. u32 val;
  36. };
  37. static void blanche_init_sys(void)
  38. {
  39. struct rcar_rwdt *rwdt = (struct rcar_rwdt *)RWDT_BASE;
  40. struct rcar_swdt *swdt = (struct rcar_swdt *)SWDT_BASE;
  41. u32 cpu_type;
  42. cpu_type = rmobile_get_cpu_type();
  43. if (cpu_type == 0x4A) {
  44. writel(0x4D000000, CPG_PLL1CR);
  45. writel(0x4F000000, CPG_PLL3CR);
  46. }
  47. /* Watchdog init */
  48. writel(0xA5A5A500, &rwdt->rwtcsra);
  49. writel(0xA5A5A500, &swdt->swtcsra);
  50. }
  51. static void blanche_init_pfc(void)
  52. {
  53. static const struct reg_config pfc_with_unlock[] = {
  54. { 0x0004, 0x0bffffff },
  55. { 0x0008, 0x002fffff },
  56. { 0x0014, 0x00000fff },
  57. { 0x0018, 0x00010fff },
  58. { 0x001c, 0x00010fff },
  59. { 0x0020, 0x00010fff },
  60. { 0x0024, 0x00010fff },
  61. { 0x0028, 0x00010fff },
  62. { 0x002c, 0x04006000 },
  63. { 0x0030, 0x303fefe0 },
  64. { 0x0058, 0x0002000e },
  65. };
  66. static const struct reg_config pfc_without_unlock[] = {
  67. { 0x0108, 0x00000000 },
  68. { 0x010c, 0x0803FF40 },
  69. { 0x0110, 0x0000FFFF },
  70. { 0x0114, 0x00010FFF },
  71. { 0x011c, 0x0001AFFF },
  72. { 0x0124, 0x0001CFFF },
  73. { 0x0128, 0xC0438001 },
  74. { 0x012c, 0x0FC00007 },
  75. };
  76. static const u32 pfc_base = 0xe6060000;
  77. unsigned int i;
  78. for (i = 0; i < ARRAY_SIZE(pfc_with_unlock); i++) {
  79. writel(~pfc_with_unlock[i].val, pfc_base);
  80. writel(pfc_with_unlock[i].val,
  81. pfc_base | pfc_with_unlock[i].off);
  82. }
  83. for (i = 0; i < ARRAY_SIZE(pfc_without_unlock); i++)
  84. writel(pfc_without_unlock[i].val,
  85. pfc_base | pfc_without_unlock[i].off);
  86. }
  87. static void blanche_init_lbsc(void)
  88. {
  89. static const struct reg_config lbsc_config[] = {
  90. { 0x00, 0x00000020 },
  91. { 0x08, 0x00002020 },
  92. { 0x30, 0x2a103320 },
  93. { 0x38, 0x19102110 },
  94. };
  95. static const u32 lbsc_base = 0xfec00200;
  96. unsigned int i;
  97. for (i = 0; i < ARRAY_SIZE(lbsc_config); i++) {
  98. writel(lbsc_config[i].val,
  99. lbsc_base | lbsc_config[i].off);
  100. writel(lbsc_config[i].val,
  101. lbsc_base | (lbsc_config[i].off + 4));
  102. }
  103. }
  104. #if defined(CONFIG_MTD_NOR_FLASH)
  105. static void dbsc_wait(u16 reg)
  106. {
  107. static const u32 dbsc3_0_base = DBSC3_0_BASE;
  108. while (!(readl(dbsc3_0_base + reg) & BIT(0)))
  109. ;
  110. }
  111. static void blanche_init_dbsc(void)
  112. {
  113. static const struct reg_config dbsc_config1[] = {
  114. { 0x0280, 0x0000a55a },
  115. { 0x0018, 0x21000000 },
  116. { 0x0018, 0x11000000 },
  117. { 0x0018, 0x10000000 },
  118. { 0x0290, 0x00000001 },
  119. { 0x02a0, 0x80000000 },
  120. { 0x0290, 0x00000004 },
  121. };
  122. static const struct reg_config dbsc_config2[] = {
  123. { 0x0290, 0x00000006 },
  124. { 0x02a0, 0x0001c000 },
  125. };
  126. static const struct reg_config dbsc_config4[] = {
  127. { 0x0290, 0x0000000f },
  128. { 0x02a0, 0x00181ee4 },
  129. { 0x0290, 0x00000010 },
  130. { 0x02a0, 0xf00464db },
  131. { 0x0290, 0x00000061 },
  132. { 0x02a0, 0x0000008d },
  133. { 0x0290, 0x00000001 },
  134. { 0x02a0, 0x00000073 },
  135. { 0x0020, 0x00000007 },
  136. { 0x0024, 0x0f030a02 },
  137. { 0x0030, 0x00000001 },
  138. { 0x00b0, 0x00000000 },
  139. { 0x0040, 0x0000000b },
  140. { 0x0044, 0x00000008 },
  141. { 0x0048, 0x00000000 },
  142. { 0x0050, 0x0000000b },
  143. { 0x0054, 0x000c000b },
  144. { 0x0058, 0x00000027 },
  145. { 0x005c, 0x0000001c },
  146. { 0x0060, 0x00000006 },
  147. { 0x0064, 0x00000020 },
  148. { 0x0068, 0x00000008 },
  149. { 0x006c, 0x0000000c },
  150. { 0x0070, 0x00000009 },
  151. { 0x0074, 0x00000012 },
  152. { 0x0078, 0x000000d0 },
  153. { 0x007c, 0x00140005 },
  154. { 0x0080, 0x00050004 },
  155. { 0x0084, 0x70233005 },
  156. { 0x0088, 0x000c0000 },
  157. { 0x008c, 0x00000300 },
  158. { 0x0090, 0x00000040 },
  159. { 0x0100, 0x00000001 },
  160. { 0x00c0, 0x00020001 },
  161. { 0x00c8, 0x20082004 },
  162. { 0x0380, 0x00020002 },
  163. { 0x0390, 0x0000001f },
  164. };
  165. static const struct reg_config dbsc_config5[] = {
  166. { 0x0244, 0x00000011 },
  167. { 0x0290, 0x00000003 },
  168. { 0x02a0, 0x0300c4e1 },
  169. { 0x0290, 0x00000023 },
  170. { 0x02a0, 0x00fcdb60 },
  171. { 0x0290, 0x00000011 },
  172. { 0x02a0, 0x1000040b },
  173. { 0x0290, 0x00000012 },
  174. { 0x02a0, 0x9d9cbb66 },
  175. { 0x0290, 0x00000013 },
  176. { 0x02a0, 0x1a868400 },
  177. { 0x0290, 0x00000014 },
  178. { 0x02a0, 0x300214d8 },
  179. { 0x0290, 0x00000015 },
  180. { 0x02a0, 0x00000d70 },
  181. { 0x0290, 0x00000016 },
  182. { 0x02a0, 0x00000004 },
  183. { 0x0290, 0x00000017 },
  184. { 0x02a0, 0x00000018 },
  185. { 0x0290, 0x0000001a },
  186. { 0x02a0, 0x910035c7 },
  187. { 0x0290, 0x00000004 },
  188. };
  189. static const struct reg_config dbsc_config6[] = {
  190. { 0x0290, 0x00000001 },
  191. { 0x02a0, 0x00000181 },
  192. { 0x0018, 0x11000000 },
  193. { 0x0290, 0x00000004 },
  194. };
  195. static const struct reg_config dbsc_config7[] = {
  196. { 0x0290, 0x00000001 },
  197. { 0x02a0, 0x0000fe01 },
  198. { 0x0304, 0x00000000 },
  199. { 0x00f4, 0x01004c20 },
  200. { 0x00f8, 0x014000aa },
  201. { 0x00e0, 0x00000140 },
  202. { 0x00e4, 0x00081860 },
  203. { 0x00e8, 0x00010000 },
  204. { 0x0290, 0x00000004 },
  205. };
  206. static const struct reg_config dbsc_config8[] = {
  207. { 0x0014, 0x00000001 },
  208. { 0x0010, 0x00000001 },
  209. { 0x0280, 0x00000000 },
  210. };
  211. static const u32 dbsc3_0_base = DBSC3_0_BASE;
  212. unsigned int i;
  213. for (i = 0; i < ARRAY_SIZE(dbsc_config1); i++)
  214. writel(dbsc_config1[i].val, dbsc3_0_base | dbsc_config1[i].off);
  215. dbsc_wait(0x2a0);
  216. for (i = 0; i < ARRAY_SIZE(dbsc_config2); i++)
  217. writel(dbsc_config2[i].val, dbsc3_0_base | dbsc_config2[i].off);
  218. for (i = 0; i < ARRAY_SIZE(dbsc_config4); i++)
  219. writel(dbsc_config4[i].val, dbsc3_0_base | dbsc_config4[i].off);
  220. dbsc_wait(0x240);
  221. for (i = 0; i < ARRAY_SIZE(dbsc_config5); i++)
  222. writel(dbsc_config5[i].val, dbsc3_0_base | dbsc_config5[i].off);
  223. dbsc_wait(0x2a0);
  224. for (i = 0; i < ARRAY_SIZE(dbsc_config6); i++)
  225. writel(dbsc_config6[i].val, dbsc3_0_base | dbsc_config6[i].off);
  226. dbsc_wait(0x2a0);
  227. for (i = 0; i < ARRAY_SIZE(dbsc_config7); i++)
  228. writel(dbsc_config7[i].val, dbsc3_0_base | dbsc_config7[i].off);
  229. dbsc_wait(0x2a0);
  230. for (i = 0; i < ARRAY_SIZE(dbsc_config8); i++)
  231. writel(dbsc_config8[i].val, dbsc3_0_base | dbsc_config8[i].off);
  232. }
  233. static void s_init_wait(volatile unsigned int cnt)
  234. {
  235. volatile u32 i = cnt * 0x10000;
  236. while (i-- > 0)
  237. ;
  238. }
  239. #endif
  240. void s_init(void)
  241. {
  242. blanche_init_sys();
  243. qos_init();
  244. blanche_init_pfc();
  245. blanche_init_lbsc();
  246. #if defined(CONFIG_MTD_NOR_FLASH)
  247. s_init_wait(10);
  248. blanche_init_dbsc();
  249. #endif /* CONFIG_MTD_NOR_FLASH */
  250. }
  251. int board_early_init_f(void)
  252. {
  253. /* TMU0 */
  254. mstp_clrbits_le32(MSTPSR1, SMSTPCR1, TMU0_MSTP125);
  255. /* QSPI */
  256. mstp_clrbits_le32(MSTPSR9, SMSTPCR9, QSPI_MSTP917);
  257. return 0;
  258. }
  259. int board_init(void)
  260. {
  261. /* adress of boot parameters */
  262. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  263. return 0;
  264. }
  265. /* Added for BLANCHE(R-CarV2H board) */
  266. int board_eth_init(bd_t *bis)
  267. {
  268. int rc = 0;
  269. #ifdef CONFIG_SMC911X
  270. struct eth_device *dev;
  271. uchar eth_addr[6];
  272. rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  273. if (!eth_env_get_enetaddr("ethaddr", eth_addr)) {
  274. dev = eth_get_dev_by_index(0);
  275. if (dev) {
  276. eth_env_set_enetaddr("ethaddr", dev->enetaddr);
  277. } else {
  278. printf("blanche: Couldn't get eth device\n");
  279. rc = -1;
  280. }
  281. }
  282. #endif
  283. return rc;
  284. }
  285. int dram_init(void)
  286. {
  287. if (fdtdec_setup_memory_size() != 0)
  288. return -EINVAL;
  289. return 0;
  290. }
  291. int dram_init_banksize(void)
  292. {
  293. fdtdec_setup_memory_banksize();
  294. return 0;
  295. }
  296. void reset_cpu(ulong addr)
  297. {
  298. }