kzm9g.c 11 KB

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