kzm9g.c 10 KB

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