kzm9g.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
  4. * (C) Copyright 2012 Renesas Solutions Corp.
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/sys_proto.h>
  9. #include <asm/gpio.h>
  10. #include <netdev.h>
  11. #include <i2c.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. #define CS0BCR_D (0x06C00400)
  14. #define CS4BCR_D (0x16c90400)
  15. #define CS0WCR_D (0x55062C42)
  16. #define CS4WCR_D (0x1e071dc3)
  17. #define CMNCR_BROMMD0 (1 << 21)
  18. #define CMNCR_BROMMD1 (1 << 22)
  19. #define CMNCR_BROMMD (CMNCR_BROMMD0|CMNCR_BROMMD1)
  20. #define VCLKCR1_D (0x27)
  21. #define SMSTPCR1_CMT0 (1 << 24)
  22. #define SMSTPCR1_I2C0 (1 << 16)
  23. #define SMSTPCR3_USB (1 << 22)
  24. #define SMSTPCR3_I2C1 (1 << 23)
  25. #define PORT32CR (0xE6051020)
  26. #define PORT33CR (0xE6051021)
  27. #define PORT34CR (0xE6051022)
  28. #define PORT35CR (0xE6051023)
  29. static int cmp_loop(u32 *addr, u32 data, u32 cmp)
  30. {
  31. int err = -1;
  32. int timeout = 100;
  33. u32 value;
  34. while (timeout > 0) {
  35. value = readl(addr);
  36. if ((value & data) == cmp) {
  37. err = 0;
  38. break;
  39. }
  40. timeout--;
  41. }
  42. return err;
  43. }
  44. /* SBSC Init function */
  45. static void sbsc_init(struct sh73a0_sbsc *sbsc)
  46. {
  47. writel(readl(&sbsc->dllcnt0)|0x2, &sbsc->dllcnt0);
  48. writel(0x5, &sbsc->sdgencnt);
  49. cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
  50. writel(0xacc90159, &sbsc->sdcr0);
  51. writel(0x00010059, &sbsc->sdcr1);
  52. writel(0x50874114, &sbsc->sdwcrc0);
  53. writel(0x33199b37, &sbsc->sdwcrc1);
  54. writel(0x008f2313, &sbsc->sdwcrc2);
  55. writel(0x31020707, &sbsc->sdwcr00);
  56. writel(0x0017040a, &sbsc->sdwcr01);
  57. writel(0x31020707, &sbsc->sdwcr10);
  58. writel(0x0017040a, &sbsc->sdwcr11);
  59. writel(0x055557ff, &sbsc->sddrvcr0); /* Enlarge drivability of LPDQS0-3, LPCLK */
  60. writel(0x30000000, &sbsc->sdwcr2);
  61. writel(readl(&sbsc->sdpcr) | 0x80, &sbsc->sdpcr);
  62. cmp_loop(&sbsc->sdpcr, 0x80, 0x80);
  63. writel(0x00002710, &sbsc->sdgencnt);
  64. cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
  65. writel(0x0000003f, &sbsc->sdmracr0);
  66. writel(0x0, SDMRA1A);
  67. writel(0x000001f4, &sbsc->sdgencnt);
  68. cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
  69. writel(0x0000ff0a, &sbsc->sdmracr0);
  70. if (sbsc == (struct sh73a0_sbsc *)SBSC1_BASE)
  71. writel(0x0, SDMRA3A);
  72. else
  73. writel(0x0, SDMRA3B);
  74. writel(0x00000032, &sbsc->sdgencnt);
  75. cmp_loop(&sbsc->sdgencnt, 0xffffffff, 0x0);
  76. if (sbsc == (struct sh73a0_sbsc *)SBSC1_BASE) {
  77. writel(0x00002201, &sbsc->sdmracr0);
  78. writel(0x0, SDMRA1A);
  79. writel(0x00000402, &sbsc->sdmracr0);
  80. writel(0x0, SDMRA1A);
  81. writel(0x00000203, &sbsc->sdmracr0); /* MR3 register DS=2 */
  82. writel(0x0, SDMRA1A);
  83. writel(0x0, SDMRA2A);
  84. } else {
  85. writel(0x00002201, &sbsc->sdmracr0);
  86. writel(0x0, SDMRA1B);
  87. writel(0x00000402, &sbsc->sdmracr0);
  88. writel(0x0, SDMRA1B);
  89. writel(0x00000203, &sbsc->sdmracr0); /* MR3 register DS=2 */
  90. writel(0x0, SDMRA1B);
  91. writel(0x0, SDMRA2B);
  92. }
  93. writel(0x88800004, &sbsc->sdmrtmpcr);
  94. writel(0x00000004, &sbsc->sdmrtmpmsk);
  95. writel(0xa55a0032, &sbsc->rtcor);
  96. writel(0xa55a000c, &sbsc->rtcorh);
  97. writel(0xa55a2048, &sbsc->rtcsr);
  98. writel(readl(&sbsc->sdcr0)|0x800, &sbsc->sdcr0);
  99. writel(readl(&sbsc->sdcr1)|0x400, &sbsc->sdcr1);
  100. writel(0xfff20000, &sbsc->zqccr);
  101. /* SCBS2 only */
  102. if (sbsc == (struct sh73a0_sbsc *)SBSC2_BASE) {
  103. writel(readl(&sbsc->sdpdcr0)|0x00030000, &sbsc->sdpdcr0);
  104. writel(0xa5390000, &sbsc->dphycnt1);
  105. writel(0x00001200, &sbsc->dphycnt0);
  106. writel(0x07ce0000, &sbsc->dphycnt1);
  107. writel(0x00001247, &sbsc->dphycnt0);
  108. cmp_loop(&sbsc->dphycnt2, 0xffffffff, 0x07ce0000);
  109. writel(readl(&sbsc->sdpdcr0) & 0xfffcffff, &sbsc->sdpdcr0);
  110. }
  111. }
  112. void s_init(void)
  113. {
  114. struct sh73a0_rwdt *rwdt = (struct sh73a0_rwdt *)RWDT_BASE;
  115. struct sh73a0_sbsc_cpg *cpg = (struct sh73a0_sbsc_cpg *)CPG_BASE;
  116. struct sh73a0_sbsc_cpg_srcr *cpg_srcr =
  117. (struct sh73a0_sbsc_cpg_srcr *)CPG_SRCR_BASE;
  118. struct sh73a0_sbsc *sbsc1 = (struct sh73a0_sbsc *)SBSC1_BASE;
  119. struct sh73a0_sbsc *sbsc2 = (struct sh73a0_sbsc *)SBSC2_BASE;
  120. struct sh73a0_hpb *hpb = (struct sh73a0_hpb *)HPB_BASE;
  121. struct sh73a0_hpb_bscr *hpb_bscr =
  122. (struct sh73a0_hpb_bscr *)HPBSCR_BASE;
  123. /* Watchdog init */
  124. writew(0xA507, &rwdt->rwtcsra0);
  125. /* Secure control register Init */
  126. #define LIFEC_SEC_SRC_BIT (1 << 15)
  127. writel(readl(LIFEC_SEC_SRC) & ~LIFEC_SEC_SRC_BIT, LIFEC_SEC_SRC);
  128. clrbits_le32(&cpg->smstpcr3, (1 << 15));
  129. clrbits_le32(&cpg_srcr->srcr3, (1 << 15));
  130. clrbits_le32(&cpg->smstpcr2, (1 << 18));
  131. clrbits_le32(&cpg_srcr->srcr2, (1 << 18));
  132. writel(0x0, &cpg->pllecr);
  133. cmp_loop(&cpg->pllecr, 0x00000F00, 0x0);
  134. cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
  135. writel(0x2D000000, &cpg->pll0cr);
  136. writel(0x17100000, &cpg->pll1cr);
  137. writel(0x96235880, &cpg->frqcrb);
  138. cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
  139. writel(0xB, &cpg->flckcr);
  140. clrbits_le32(&cpg->smstpcr0, (1 << 1));
  141. clrbits_le32(&cpg_srcr->srcr0, (1 << 1));
  142. writel(0x0514, &hpb_bscr->smgpiotime);
  143. writel(0x0514, &hpb_bscr->smcmt2time);
  144. writel(0x0514, &hpb_bscr->smcpgtime);
  145. writel(0x0514, &hpb_bscr->smsysctime);
  146. writel(0x00092000, &cpg->dvfscr4);
  147. writel(0x000000DC, &cpg->dvfscr5);
  148. writel(0x0, &cpg->pllecr);
  149. cmp_loop(&cpg->pllecr, 0x00000F00, 0x0);
  150. /* FRQCR Init */
  151. writel(0x0012453C, &cpg->frqcra);
  152. writel(0x80431350, &cpg->frqcrb); /* ETM TRCLK 78MHz */
  153. cmp_loop(&cpg->frqcrb, 0x80000000, 0x0);
  154. writel(0x00000B0B, &cpg->frqcrd);
  155. cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
  156. /* Clock Init */
  157. writel(0x00000003, PCLKCR);
  158. writel(0x0000012F, &cpg->vclkcr1);
  159. writel(0x00000119, &cpg->vclkcr2);
  160. writel(0x00000119, &cpg->vclkcr3);
  161. writel(0x00000002, &cpg->zbckcr);
  162. writel(0x00000005, &cpg->flckcr);
  163. writel(0x00000080, &cpg->sd0ckcr);
  164. writel(0x00000080, &cpg->sd1ckcr);
  165. writel(0x00000080, &cpg->sd2ckcr);
  166. writel(0x0000003F, &cpg->fsiackcr);
  167. writel(0x0000003F, &cpg->fsibckcr);
  168. writel(0x00000080, &cpg->subckcr);
  169. writel(0x0000000B, &cpg->spuackcr);
  170. writel(0x0000000B, &cpg->spuvckcr);
  171. writel(0x0000013F, &cpg->msuckcr);
  172. writel(0x00000080, &cpg->hsickcr);
  173. writel(0x0000003F, &cpg->mfck1cr);
  174. writel(0x0000003F, &cpg->mfck2cr);
  175. writel(0x00000107, &cpg->dsitckcr);
  176. writel(0x00000313, &cpg->dsi0pckcr);
  177. writel(0x0000130D, &cpg->dsi1pckcr);
  178. writel(0x2A800E0E, &cpg->dsi0phycr);
  179. writel(0x1E000000, &cpg->pll0cr);
  180. writel(0x2D000000, &cpg->pll0cr);
  181. writel(0x17100000, &cpg->pll1cr);
  182. writel(0x27000080, &cpg->pll2cr);
  183. writel(0x1D000000, &cpg->pll3cr);
  184. writel(0x00080000, &cpg->pll0stpcr);
  185. writel(0x000120C0, &cpg->pll1stpcr);
  186. writel(0x00012000, &cpg->pll2stpcr);
  187. writel(0x00000030, &cpg->pll3stpcr);
  188. writel(0x0000000B, &cpg->pllecr);
  189. cmp_loop(&cpg->pllecr, 0x00000B00, 0x00000B00);
  190. writel(0x000120F0, &cpg->dvfscr3);
  191. writel(0x00000020, &cpg->mpmode);
  192. writel(0x0000028A, &cpg->vrefcr);
  193. writel(0xE4628087, &cpg->rmstpcr0);
  194. writel(0xFFFFFFFF, &cpg->rmstpcr1);
  195. writel(0x53FFFFFF, &cpg->rmstpcr2);
  196. writel(0xFFFFFFFF, &cpg->rmstpcr3);
  197. writel(0x00800D3D, &cpg->rmstpcr4);
  198. writel(0xFFFFF3FF, &cpg->rmstpcr5);
  199. writel(0x00000000, &cpg->smstpcr2);
  200. writel(0x00040000, &cpg_srcr->srcr2);
  201. clrbits_le32(&cpg->pllecr, (1 << 3));
  202. cmp_loop(&cpg->pllecr, 0x00000800, 0x0);
  203. writel(0x00000001, &hpb->hpbctrl6);
  204. cmp_loop(&hpb->hpbctrl6, 0x1, 0x1);
  205. writel(0x00001414, &cpg->frqcrd);
  206. cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
  207. writel(0x1d000000, &cpg->pll3cr);
  208. setbits_le32(&cpg->pllecr, (1 << 3));
  209. cmp_loop(&cpg->pllecr, 0x800, 0x800);
  210. /* SBSC1 Init*/
  211. sbsc_init(sbsc1);
  212. /* SBSC2 Init*/
  213. sbsc_init(sbsc2);
  214. writel(0x00000b0b, &cpg->frqcrd);
  215. cmp_loop(&cpg->frqcrd, 0x80000000, 0x0);
  216. writel(0xfffffffc, &cpg->cpgxxcs4);
  217. }
  218. int board_early_init_f(void)
  219. {
  220. struct sh73a0_sbsc_cpg *cpg = (struct sh73a0_sbsc_cpg *)CPG_BASE;
  221. struct sh73a0_bsc *bsc = (struct sh73a0_bsc *)BSC_BASE;
  222. struct sh73a0_sbsc_cpg_srcr *cpg_srcr =
  223. (struct sh73a0_sbsc_cpg_srcr *)CPG_SRCR_BASE;
  224. writel(CS0BCR_D, &bsc->cs0bcr);
  225. writel(CS4BCR_D, &bsc->cs4bcr);
  226. writel(CS0WCR_D, &bsc->cs0wcr);
  227. writel(CS4WCR_D, &bsc->cs4wcr);
  228. clrsetbits_le32(&bsc->cmncr, ~CMNCR_BROMMD, CMNCR_BROMMD);
  229. clrbits_le32(&cpg->smstpcr1, (SMSTPCR1_CMT0|SMSTPCR1_I2C0));
  230. clrbits_le32(&cpg_srcr->srcr1, (SMSTPCR1_CMT0|SMSTPCR1_I2C0));
  231. clrbits_le32(&cpg->smstpcr3, (SMSTPCR3_USB|SMSTPCR3_I2C1));
  232. clrbits_le32(&cpg_srcr->srcr3, (SMSTPCR3_USB|SMSTPCR3_I2C1));
  233. writel(VCLKCR1_D, &cpg->vclkcr1);
  234. /* Setup SCIF4 / workaround */
  235. writeb(0x12, PORT32CR);
  236. writeb(0x22, PORT33CR);
  237. writeb(0x12, PORT34CR);
  238. writeb(0x22, PORT35CR);
  239. return 0;
  240. }
  241. void adjust_core_voltage(void)
  242. {
  243. u8 data;
  244. data = 0x35;
  245. i2c_set_bus_num(0);
  246. i2c_write(0x40, 3, 1, &data, 1);
  247. }
  248. int board_init(void)
  249. {
  250. adjust_core_voltage();
  251. sh73a0_pinmux_init();
  252. /* SCIFA 4 */
  253. gpio_request(GPIO_FN_SCIFA4_TXD, NULL);
  254. gpio_request(GPIO_FN_SCIFA4_RXD, NULL);
  255. gpio_request(GPIO_FN_SCIFA4_RTS_, NULL);
  256. gpio_request(GPIO_FN_SCIFA4_CTS_, NULL);
  257. /* Ethernet/SMSC */
  258. gpio_request(GPIO_PORT224, NULL);
  259. gpio_direction_input(GPIO_PORT224);
  260. /* SMSC/USB */
  261. gpio_request(GPIO_FN_CS4_, NULL);
  262. /* MMCIF */
  263. gpio_request(GPIO_FN_MMCCLK0, NULL);
  264. gpio_request(GPIO_FN_MMCCMD0_PU, NULL);
  265. gpio_request(GPIO_FN_MMCD0_0_PU, NULL);
  266. gpio_request(GPIO_FN_MMCD0_1_PU, NULL);
  267. gpio_request(GPIO_FN_MMCD0_2_PU, NULL);
  268. gpio_request(GPIO_FN_MMCD0_3_PU, NULL);
  269. gpio_request(GPIO_FN_MMCD0_4_PU, NULL);
  270. gpio_request(GPIO_FN_MMCD0_5_PU, NULL);
  271. gpio_request(GPIO_FN_MMCD0_6_PU, NULL);
  272. gpio_request(GPIO_FN_MMCD0_7_PU, NULL);
  273. /* SDHI */
  274. gpio_request(GPIO_FN_SDHIWP0, NULL);
  275. gpio_request(GPIO_FN_SDHICD0, NULL);
  276. gpio_request(GPIO_FN_SDHICMD0, NULL);
  277. gpio_request(GPIO_FN_SDHICLK0, NULL);
  278. gpio_request(GPIO_FN_SDHID0_3, NULL);
  279. gpio_request(GPIO_FN_SDHID0_2, NULL);
  280. gpio_request(GPIO_FN_SDHID0_1, NULL);
  281. gpio_request(GPIO_FN_SDHID0_0, NULL);
  282. gpio_request(GPIO_FN_SDHI0_VCCQ_MC0_ON, NULL);
  283. gpio_request(GPIO_PORT15, NULL);
  284. gpio_direction_output(GPIO_PORT15, 1);
  285. /* I2C */
  286. gpio_request(GPIO_FN_PORT237_I2C_SCL2, NULL);
  287. gpio_request(GPIO_FN_PORT236_I2C_SDA2, NULL);
  288. gpio_request(GPIO_FN_PORT27_I2C_SCL3, NULL);
  289. gpio_request(GPIO_FN_PORT28_I2C_SDA3, NULL);
  290. gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
  291. return 0;
  292. }
  293. int dram_init(void)
  294. {
  295. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  296. return 0;
  297. }
  298. int board_eth_init(bd_t *bis)
  299. {
  300. int ret = 0;
  301. #ifdef CONFIG_SMC911X
  302. ret = smc911x_initialize(0, CONFIG_SMC911X_BASE);
  303. #endif
  304. return ret;
  305. }
  306. void reset_cpu(ulong addr)
  307. {
  308. /* Soft Power On Reset */
  309. writel((1 << 31), RESCNT2);
  310. }