cpu_init.c 9.5 KB

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