kzm9g.c 10 KB

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