cpu_init.c 10 KB

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