cpu_init.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. *
  4. * (C) Copyright 2000-2003
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * (C) Copyright 2004-2008, 2012 Freescale Semiconductor, Inc.
  8. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  9. */
  10. #include <common.h>
  11. #include <watchdog.h>
  12. #include <asm/immap.h>
  13. #include <asm/io.h>
  14. #if defined(CONFIG_CMD_NET)
  15. #include <config.h>
  16. #include <net.h>
  17. #include <asm/fec.h>
  18. #endif
  19. #ifdef CONFIG_MCF5301x
  20. void cpu_init_f(void)
  21. {
  22. scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  23. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  24. fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  25. out_be32(&scm1->mpr, 0x77777777);
  26. out_be32(&scm1->pacra, 0);
  27. out_be32(&scm1->pacrb, 0);
  28. out_be32(&scm1->pacrc, 0);
  29. out_be32(&scm1->pacrd, 0);
  30. out_be32(&scm1->pacre, 0);
  31. out_be32(&scm1->pacrf, 0);
  32. out_be32(&scm1->pacrg, 0);
  33. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
  34. && defined(CONFIG_SYS_CS0_CTRL))
  35. setbits_8(&gpio->par_cs, GPIO_PAR_CS0_CS0);
  36. out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
  37. out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
  38. out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
  39. #endif
  40. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
  41. && defined(CONFIG_SYS_CS1_CTRL))
  42. setbits_8(&gpio->par_cs, GPIO_PAR_CS1_CS1);
  43. out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
  44. out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
  45. out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
  46. #endif
  47. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
  48. && defined(CONFIG_SYS_CS2_CTRL))
  49. out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
  50. out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
  51. out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
  52. #endif
  53. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
  54. && defined(CONFIG_SYS_CS3_CTRL))
  55. out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
  56. out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
  57. out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
  58. #endif
  59. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
  60. && defined(CONFIG_SYS_CS4_CTRL))
  61. setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
  62. out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
  63. out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
  64. out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
  65. #endif
  66. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
  67. && defined(CONFIG_SYS_CS5_CTRL))
  68. setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
  69. out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
  70. out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
  71. out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
  72. #endif
  73. #ifdef CONFIG_SYS_I2C_FSL
  74. out_8(&gpio->par_feci2c,
  75. GPIO_PAR_FECI2C_SDA_SDA | GPIO_PAR_FECI2C_SCL_SCL);
  76. #endif
  77. icache_enable();
  78. }
  79. /* initialize higher level parts of CPU like timers */
  80. int cpu_init_r(void)
  81. {
  82. #ifdef CONFIG_MCFFEC
  83. ccm_t *ccm = (ccm_t *) MMAP_CCM;
  84. #endif
  85. #ifdef CONFIG_MCFRTC
  86. rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE);
  87. rtcex_t *rtcex = (rtcex_t *) &rtc->extended;
  88. out_be32(&rtcex->gocu, CONFIG_SYS_RTC_CNT);
  89. out_be32(&rtcex->gocl, CONFIG_SYS_RTC_SETUP);
  90. #endif
  91. #ifdef CONFIG_MCFFEC
  92. if (CONFIG_SYS_FEC0_MIIBASE != CONFIG_SYS_FEC1_MIIBASE)
  93. setbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
  94. else
  95. clrbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
  96. #endif
  97. return (0);
  98. }
  99. void uart_port_conf(int port)
  100. {
  101. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  102. /* Setup Ports: */
  103. switch (port) {
  104. case 0:
  105. clrbits_8(&gpio->par_uart,
  106. GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
  107. setbits_8(&gpio->par_uart,
  108. GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
  109. break;
  110. case 1:
  111. #ifdef CONFIG_SYS_UART1_ALT1_GPIO
  112. clrbits_8(&gpio->par_simp1h,
  113. GPIO_PAR_SIMP1H_DATA1_UNMASK |
  114. GPIO_PAR_SIMP1H_VEN1_UNMASK);
  115. setbits_8(&gpio->par_simp1h,
  116. GPIO_PAR_SIMP1H_DATA1_U1TXD |
  117. GPIO_PAR_SIMP1H_VEN1_U1RXD);
  118. #elif defined(CONFIG_SYS_UART1_ALT2_GPIO)
  119. clrbits_8(&gpio->par_ssih,
  120. GPIO_PAR_SSIH_RXD_UNMASK |
  121. GPIO_PAR_SSIH_TXD_UNMASK);
  122. setbits_8(&gpio->par_ssih,
  123. GPIO_PAR_SSIH_RXD_U1RXD |
  124. GPIO_PAR_SSIH_TXD_U1TXD);
  125. #endif
  126. break;
  127. case 2:
  128. #ifdef CONFIG_SYS_UART2_PRI_GPIO
  129. setbits_8(&gpio->par_uart,
  130. GPIO_PAR_UART_U2TXD |
  131. GPIO_PAR_UART_U2RXD);
  132. #elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
  133. clrbits_8(&gpio->par_dspih,
  134. GPIO_PAR_DSPIH_SIN_UNMASK |
  135. GPIO_PAR_DSPIH_SOUT_UNMASK);
  136. setbits_8(&gpio->par_dspih,
  137. GPIO_PAR_DSPIH_SIN_U2RXD |
  138. GPIO_PAR_DSPIH_SOUT_U2TXD);
  139. #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
  140. clrbits_8(&gpio->par_feci2c,
  141. GPIO_PAR_FECI2C_SDA_UNMASK |
  142. GPIO_PAR_FECI2C_SCL_UNMASK);
  143. setbits_8(&gpio->par_feci2c,
  144. GPIO_PAR_FECI2C_SDA_U2TXD |
  145. GPIO_PAR_FECI2C_SCL_U2RXD);
  146. #endif
  147. break;
  148. }
  149. }
  150. #if defined(CONFIG_CMD_NET)
  151. int fecpin_setclear(struct eth_device *dev, int setclear)
  152. {
  153. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  154. struct fec_info_s *info = (struct fec_info_s *)dev->priv;
  155. if (setclear) {
  156. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  157. setbits_8(&gpio->par_fec,
  158. GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
  159. setbits_8(&gpio->par_feci2c,
  160. GPIO_PAR_FECI2C_MDC0 | GPIO_PAR_FECI2C_MDIO0);
  161. } else {
  162. setbits_8(&gpio->par_fec,
  163. GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
  164. setbits_8(&gpio->par_feci2c,
  165. GPIO_PAR_FECI2C_MDC1 | GPIO_PAR_FECI2C_MDIO1);
  166. }
  167. } else {
  168. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  169. clrbits_8(&gpio->par_fec,
  170. GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
  171. clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII0_UNMASK);
  172. } else {
  173. clrbits_8(&gpio->par_fec,
  174. GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
  175. clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII1_UNMASK);
  176. }
  177. }
  178. return 0;
  179. }
  180. #endif /* CONFIG_CMD_NET */
  181. #endif /* CONFIG_MCF5301x */
  182. #ifdef CONFIG_MCF532x
  183. void cpu_init_f(void)
  184. {
  185. scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  186. scm2_t *scm2 = (scm2_t *) MMAP_SCM2;
  187. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  188. fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  189. #ifndef CONFIG_WATCHDOG
  190. wdog_t *wdog = (wdog_t *) MMAP_WDOG;
  191. /* watchdog is enabled by default - disable the watchdog */
  192. out_be16(&wdog->cr, 0);
  193. #endif
  194. out_be32(&scm1->mpr0, 0x77777777);
  195. out_be32(&scm2->pacra, 0);
  196. out_be32(&scm2->pacrb, 0);
  197. out_be32(&scm2->pacrc, 0);
  198. out_be32(&scm2->pacrd, 0);
  199. out_be32(&scm2->pacre, 0);
  200. out_be32(&scm2->pacrf, 0);
  201. out_be32(&scm2->pacrg, 0);
  202. out_be32(&scm1->pacrh, 0);
  203. /* Port configuration */
  204. out_8(&gpio->par_cs, 0);
  205. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
  206. && defined(CONFIG_SYS_CS0_CTRL))
  207. out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
  208. out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
  209. out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
  210. #endif
  211. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
  212. && defined(CONFIG_SYS_CS1_CTRL))
  213. /* Latch chipselect */
  214. setbits_8(&gpio->par_cs, GPIO_PAR_CS1);
  215. out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
  216. out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
  217. out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
  218. #endif
  219. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
  220. && defined(CONFIG_SYS_CS2_CTRL))
  221. setbits_8(&gpio->par_cs, GPIO_PAR_CS2);
  222. out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
  223. out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
  224. out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
  225. #endif
  226. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
  227. && defined(CONFIG_SYS_CS3_CTRL))
  228. setbits_8(&gpio->par_cs, GPIO_PAR_CS3);
  229. out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
  230. out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
  231. out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
  232. #endif
  233. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
  234. && defined(CONFIG_SYS_CS4_CTRL))
  235. setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
  236. out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
  237. out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
  238. out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
  239. #endif
  240. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
  241. && defined(CONFIG_SYS_CS5_CTRL))
  242. setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
  243. out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
  244. out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
  245. out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
  246. #endif
  247. #ifdef CONFIG_SYS_I2C_FSL
  248. out_8(&gpio->par_feci2c,
  249. GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
  250. #endif
  251. icache_enable();
  252. }
  253. /*
  254. * initialize higher level parts of CPU like timers
  255. */
  256. int cpu_init_r(void)
  257. {
  258. return (0);
  259. }
  260. void uart_port_conf(int port)
  261. {
  262. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  263. /* Setup Ports: */
  264. switch (port) {
  265. case 0:
  266. clrbits_be16(&gpio->par_uart,
  267. GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
  268. setbits_be16(&gpio->par_uart,
  269. GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
  270. break;
  271. case 1:
  272. clrbits_be16(&gpio->par_uart,
  273. GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
  274. setbits_be16(&gpio->par_uart,
  275. GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
  276. break;
  277. case 2:
  278. #ifdef CONFIG_SYS_UART2_ALT1_GPIO
  279. clrbits_8(&gpio->par_timer, 0xf0);
  280. setbits_8(&gpio->par_timer,
  281. GPIO_PAR_TIN3_URXD2 | GPIO_PAR_TIN2_UTXD2);
  282. #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
  283. clrbits_8(&gpio->par_feci2c, 0x00ff);
  284. setbits_8(&gpio->par_feci2c,
  285. GPIO_PAR_FECI2C_SCL_UTXD2 | GPIO_PAR_FECI2C_SDA_URXD2);
  286. #elif defined(CONFIG_SYS_UART2_ALT3_GPIO)
  287. clrbits_be16(&gpio->par_ssi, 0x0f00);
  288. setbits_be16(&gpio->par_ssi,
  289. GPIO_PAR_SSI_RXD(2) | GPIO_PAR_SSI_TXD(2));
  290. #endif
  291. break;
  292. }
  293. }
  294. #if defined(CONFIG_CMD_NET)
  295. int fecpin_setclear(struct eth_device *dev, int setclear)
  296. {
  297. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  298. if (setclear) {
  299. setbits_8(&gpio->par_fec,
  300. GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
  301. setbits_8(&gpio->par_feci2c,
  302. GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
  303. } else {
  304. clrbits_8(&gpio->par_fec,
  305. GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
  306. clrbits_8(&gpio->par_feci2c,
  307. GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
  308. }
  309. return 0;
  310. }
  311. #endif
  312. #endif /* CONFIG_MCF532x */