cpu_init.c 9.6 KB

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