armadillo-800eva.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (C) 2012 Renesas Solutions Corp.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <init.h>
  24. #include <malloc.h>
  25. #include <asm/processor.h>
  26. #include <asm/mach-types.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/sys_proto.h>
  29. #include <asm/gpio.h>
  30. #include <asm/arch/rmobile.h>
  31. #define s_init_wait(cnt) \
  32. ({ \
  33. volatile u32 i = 0x10000 * cnt; \
  34. while (i > 0) \
  35. i--; \
  36. })
  37. #define USBCR1 0xE605810A
  38. void s_init(void)
  39. {
  40. struct r8a7740_rwdt *rwdt0 = (struct r8a7740_rwdt *)RWDT0_BASE;
  41. struct r8a7740_rwdt *rwdt1 = (struct r8a7740_rwdt *)RWDT1_BASE;
  42. struct r8a7740_cpg *cpg = (struct r8a7740_cpg *)CPG_BASE;
  43. struct r8a7740_bsc *bsc = (struct r8a7740_bsc *)BSC_BASE;
  44. struct r8a7740_ddrp *ddrp = (struct r8a7740_ddrp *)DDRP_BASE;
  45. struct r8a7740_dbsc *dbsc = (struct r8a7740_dbsc *)DBSC_BASE;
  46. /* Watchdog init */
  47. writew(0xA500, &rwdt0->rwtcsra0);
  48. writew(0xA500, &rwdt1->rwtcsra0);
  49. /* CPG */
  50. writel(0xFF800080, &cpg->rmstpcr4);
  51. writel(0xFF800080, &cpg->smstpcr4);
  52. /* USB clock */
  53. writel(0x00000080, &cpg->usbckcr);
  54. s_init_wait(1);
  55. /* USBCR1 */
  56. writew(0x0710, USBCR1);
  57. /* FRQCR */
  58. writel(0x00000000, &cpg->frqcrb);
  59. writel(0x62030533, &cpg->frqcra);
  60. writel(0x208A354E, &cpg->frqcrc);
  61. writel(0x80331050, &cpg->frqcrb);
  62. s_init_wait(1);
  63. writel(0x00000000, &cpg->frqcrd);
  64. s_init_wait(1);
  65. /* SUBClk */
  66. writel(0x0000010B, &cpg->subckcr);
  67. /* PLL */
  68. writel(0x00004004, &cpg->pllc01cr);
  69. s_init_wait(1);
  70. writel(0xa0000000, &cpg->pllc2cr);
  71. s_init_wait(2);
  72. /* BSC */
  73. writel(0x0000001B, &bsc->cmncr);
  74. writel(0x20000000, &dbsc->dbcmd);
  75. writel(0x10009C40, &dbsc->dbcmd);
  76. s_init_wait(1);
  77. writel(0x00000007, &dbsc->dbkind);
  78. writel(0x0E030A02, &dbsc->dbconf0);
  79. writel(0x00000001, &dbsc->dbphytype);
  80. writel(0x00000000, &dbsc->dbbl);
  81. writel(0x00000006, &dbsc->dbtr0);
  82. writel(0x00000005, &dbsc->dbtr1);
  83. writel(0x00000000, &dbsc->dbtr2);
  84. writel(0x00000006, &dbsc->dbtr3);
  85. writel(0x00080006, &dbsc->dbtr4);
  86. writel(0x00000015, &dbsc->dbtr5);
  87. writel(0x0000000f, &dbsc->dbtr6);
  88. writel(0x00000004, &dbsc->dbtr7);
  89. writel(0x00000018, &dbsc->dbtr8);
  90. writel(0x00000006, &dbsc->dbtr9);
  91. writel(0x00000006, &dbsc->dbtr10);
  92. writel(0x0000000F, &dbsc->dbtr11);
  93. writel(0x0000000D, &dbsc->dbtr12);
  94. writel(0x000000A0, &dbsc->dbtr13);
  95. writel(0x000A0003, &dbsc->dbtr14);
  96. writel(0x00000003, &dbsc->dbtr15);
  97. writel(0x40005005, &dbsc->dbtr16);
  98. writel(0x0C0C0000, &dbsc->dbtr17);
  99. writel(0x00000200, &dbsc->dbtr18);
  100. writel(0x00000040, &dbsc->dbtr19);
  101. writel(0x00000001, &dbsc->dbrnk0);
  102. writel(0x00000110, &dbsc->dbdficnt);
  103. writel(0x00000101, &ddrp->funcctrl);
  104. writel(0x00000001, &ddrp->dllctrl);
  105. writel(0x00000186, &ddrp->zqcalctrl);
  106. writel(0xB3440051, &ddrp->zqodtctrl);
  107. writel(0x94449443, &ddrp->rdctrl);
  108. writel(0x000000C0, &ddrp->rdtmg);
  109. writel(0x00000101, &ddrp->fifoinit);
  110. writel(0x02060506, &ddrp->outctrl);
  111. writel(0x00004646, &ddrp->dqcalofs1);
  112. writel(0x00004646, &ddrp->dqcalofs2);
  113. writel(0x800000aa, &ddrp->dqcalexp);
  114. writel(0x00000000, &ddrp->dllctrl);
  115. writel(0x00000000, DDRPNCNT);
  116. writel(0x0000000C, &dbsc->dbcmd);
  117. readl(&dbsc->dbwait);
  118. s_init_wait(1);
  119. writel(0x00000002, DDRPNCNT);
  120. writel(0x0000000C, &dbsc->dbcmd);
  121. readl(&dbsc->dbwait);
  122. s_init_wait(1);
  123. writel(0x00000187, &ddrp->zqcalctrl);
  124. writel(0x00009C40, &dbsc->dbcmd);
  125. readl(&dbsc->dbwait);
  126. s_init_wait(1);
  127. writel(0x00009C40, &dbsc->dbcmd);
  128. readl(&dbsc->dbwait);
  129. s_init_wait(1);
  130. writel(0x00000010, &dbsc->dbdficnt);
  131. writel(0x02060507, &ddrp->outctrl);
  132. writel(0x00009C40, &dbsc->dbcmd);
  133. readl(&dbsc->dbwait);
  134. s_init_wait(1);
  135. writel(0x21009C40, &dbsc->dbcmd);
  136. readl(&dbsc->dbwait);
  137. s_init_wait(1);
  138. writel(0x00009C40, &dbsc->dbcmd);
  139. readl(&dbsc->dbwait);
  140. s_init_wait(1);
  141. writel(0x00009C40, &dbsc->dbcmd);
  142. readl(&dbsc->dbwait);
  143. s_init_wait(1);
  144. writel(0x00009C40, &dbsc->dbcmd);
  145. readl(&dbsc->dbwait);
  146. s_init_wait(1);
  147. writel(0x00009C40, &dbsc->dbcmd);
  148. readl(&dbsc->dbwait);
  149. s_init_wait(1);
  150. writel(0x11000044, &dbsc->dbcmd);
  151. readl(&dbsc->dbwait);
  152. s_init_wait(1);
  153. writel(0x2A000000, &dbsc->dbcmd);
  154. readl(&dbsc->dbwait);
  155. s_init_wait(1);
  156. writel(0x2B000000, &dbsc->dbcmd);
  157. readl(&dbsc->dbwait);
  158. writel(0x29000004, &dbsc->dbcmd);
  159. readl(&dbsc->dbwait);
  160. writel(0x28001520, &dbsc->dbcmd);
  161. readl(&dbsc->dbwait);
  162. s_init_wait(1);
  163. writel(0x03000200, &dbsc->dbcmd);
  164. readl(&dbsc->dbwait);
  165. s_init_wait(1);
  166. writel(0x000001FF, &dbsc->dbrfcnf0);
  167. writel(0x00010C30, &dbsc->dbrfcnf1);
  168. writel(0x00000000, &dbsc->dbrfcnf2);
  169. writel(0x00000001, &dbsc->dbrfen);
  170. writel(0x00000001, &dbsc->dbacen);
  171. /* BSC */
  172. writel(0x00410400, &bsc->cs0bcr);
  173. writel(0x00410400, &bsc->cs2bcr);
  174. writel(0x00410400, &bsc->cs5bbcr);
  175. writel(0x02CB0400, &bsc->cs6abcr);
  176. writel(0x00000440, &bsc->cs0wcr);
  177. writel(0x00000440, &bsc->cs2wcr);
  178. writel(0x00000240, &bsc->cs5bwcr);
  179. writel(0x00000240, &bsc->cs6awcr);
  180. writel(0x00000005, &bsc->rbwtcnt);
  181. writel(0x00000002, &bsc->cs0wcr2);
  182. writel(0x00000002, &bsc->cs2wcr2);
  183. writel(0x00000002, &bsc->cs4wcr2);
  184. }
  185. #define GPIO_ICCR (0xE60581A0)
  186. #define ICCR_15BIT (1 << 15) /* any time 1 */
  187. #define IIC0_CONTA (1 << 7)
  188. #define IIC0_CONTB (1 << 6)
  189. #define IIC1_CONTA (1 << 5)
  190. #define IIC1_CONTB (1 << 4)
  191. #define IIC0_PS33E (1 << 1)
  192. #define IIC1_PS33E (1 << 0)
  193. #define GPIO_ICCR_DATA \
  194. (ICCR_15BIT | \
  195. IIC0_CONTA | IIC0_CONTB | IIC1_CONTA | \
  196. IIC1_CONTB | IIC0_PS33E | IIC1_PS33E)
  197. #define MSTPCR1 0xE6150134
  198. #define TMU0_MSTP125 (1 << 25)
  199. #define I2C0_MSTP116 (1 << 16)
  200. #define MSTPCR3 0xE615013C
  201. #define I2C1_MSTP323 (1 << 23)
  202. #define GETHER_MSTP309 (1 << 9)
  203. #define GPIO_SCIFA1_TXD (0xE60520C4)
  204. #define GPIO_SCIFA1_RXD (0xE60520C3)
  205. int board_early_init_f(void)
  206. {
  207. /* TMU */
  208. clrbits_le32(MSTPCR1, TMU0_MSTP125);
  209. /* GETHER */
  210. clrbits_le32(MSTPCR3, GETHER_MSTP309);
  211. /* I2C 0/1 */
  212. clrbits_le32(MSTPCR1, I2C0_MSTP116);
  213. clrbits_le32(MSTPCR3, I2C1_MSTP323);
  214. /* SCIFA1 */
  215. writeb(1, GPIO_SCIFA1_TXD); /* SCIFA1_TXD */
  216. writeb(1, GPIO_SCIFA1_RXD); /* SCIFA1_RXD */
  217. /* IICCR */
  218. writew(GPIO_ICCR_DATA, GPIO_ICCR);
  219. return 0;
  220. }
  221. DECLARE_GLOBAL_DATA_PTR;
  222. int board_init(void)
  223. {
  224. /* board id for linux */
  225. gd->bd->bi_arch_number = MACH_TYPE_ARMADILLO800EVA;
  226. /* adress of boot parameters */
  227. gd->bd->bi_boot_params = ARMADILLO_800EVA_SDRAM_BASE + 0x100;
  228. /* Init PFC controller */
  229. r8a7740_pinmux_init();
  230. /* GETHER Enable */
  231. gpio_request(GPIO_FN_ET_CRS, NULL);
  232. gpio_request(GPIO_FN_ET_MDC, NULL);
  233. gpio_request(GPIO_FN_ET_MDIO, NULL);
  234. gpio_request(GPIO_FN_ET_TX_ER, NULL);
  235. gpio_request(GPIO_FN_ET_RX_ER, NULL);
  236. gpio_request(GPIO_FN_ET_ERXD0, NULL);
  237. gpio_request(GPIO_FN_ET_ERXD1, NULL);
  238. gpio_request(GPIO_FN_ET_ERXD2, NULL);
  239. gpio_request(GPIO_FN_ET_ERXD3, NULL);
  240. gpio_request(GPIO_FN_ET_TX_CLK, NULL);
  241. gpio_request(GPIO_FN_ET_TX_EN, NULL);
  242. gpio_request(GPIO_FN_ET_ETXD0, NULL);
  243. gpio_request(GPIO_FN_ET_ETXD1, NULL);
  244. gpio_request(GPIO_FN_ET_ETXD2, NULL);
  245. gpio_request(GPIO_FN_ET_ETXD3, NULL);
  246. gpio_request(GPIO_FN_ET_PHY_INT, NULL);
  247. gpio_request(GPIO_FN_ET_COL, NULL);
  248. gpio_request(GPIO_FN_ET_RX_DV, NULL);
  249. gpio_request(GPIO_FN_ET_RX_CLK, NULL);
  250. gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
  251. gpio_direction_output(GPIO_PORT18, 1);
  252. return 0;
  253. }
  254. int dram_init(void)
  255. {
  256. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  257. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  258. return 0;
  259. }
  260. int board_late_init(void)
  261. {
  262. return 0;
  263. }
  264. void reset_cpu(ulong addr)
  265. {
  266. }