cpu_init.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. *
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2004-2008 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. #if defined(CONFIG_CMD_NET)
  31. #include <config.h>
  32. #include <net.h>
  33. #include <asm/fec.h>
  34. #endif
  35. #ifdef CONFIG_MCF5301x
  36. void cpu_init_f(void)
  37. {
  38. volatile scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  39. volatile scm2_t *scm2 = (scm2_t *) MMAP_SCM2;
  40. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  41. volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  42. /* watchdog is enabled by default - disable the watchdog */
  43. #ifndef CONFIG_WATCHDOG
  44. /*wdog->cr = 0; */
  45. #endif
  46. scm1->mpr = 0x77777777;
  47. scm1->pacra = 0;
  48. scm1->pacrb = 0;
  49. scm1->pacrc = 0;
  50. scm1->pacrd = 0;
  51. scm1->pacre = 0;
  52. scm1->pacrf = 0;
  53. scm1->pacrg = 0;
  54. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
  55. && defined(CONFIG_SYS_CS0_CTRL))
  56. gpio->par_cs |= GPIO_PAR_CS0_CS0;
  57. fbcs->csar0 = CONFIG_SYS_CS0_BASE;
  58. fbcs->cscr0 = CONFIG_SYS_CS0_CTRL;
  59. fbcs->csmr0 = CONFIG_SYS_CS0_MASK;
  60. #endif
  61. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
  62. && defined(CONFIG_SYS_CS1_CTRL))
  63. gpio->par_cs |= GPIO_PAR_CS1_CS1;
  64. fbcs->csar1 = CONFIG_SYS_CS1_BASE;
  65. fbcs->cscr1 = CONFIG_SYS_CS1_CTRL;
  66. fbcs->csmr1 = CONFIG_SYS_CS1_MASK;
  67. #endif
  68. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
  69. && defined(CONFIG_SYS_CS2_CTRL))
  70. fbcs->csar2 = CONFIG_SYS_CS2_BASE;
  71. fbcs->cscr2 = CONFIG_SYS_CS2_CTRL;
  72. fbcs->csmr2 = CONFIG_SYS_CS2_MASK;
  73. #endif
  74. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
  75. && defined(CONFIG_SYS_CS3_CTRL))
  76. fbcs->csar3 = CONFIG_SYS_CS3_BASE;
  77. fbcs->cscr3 = CONFIG_SYS_CS3_CTRL;
  78. fbcs->csmr3 = CONFIG_SYS_CS3_MASK;
  79. #endif
  80. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
  81. && defined(CONFIG_SYS_CS4_CTRL))
  82. gpio->par_cs |= GPIO_PAR_CS4;
  83. fbcs->csar4 = CONFIG_SYS_CS4_BASE;
  84. fbcs->cscr4 = CONFIG_SYS_CS4_CTRL;
  85. fbcs->csmr4 = CONFIG_SYS_CS4_MASK;
  86. #endif
  87. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
  88. && defined(CONFIG_SYS_CS5_CTRL))
  89. gpio->par_cs |= GPIO_PAR_CS5;
  90. fbcs->csar5 = CONFIG_SYS_CS5_BASE;
  91. fbcs->cscr5 = CONFIG_SYS_CS5_CTRL;
  92. fbcs->csmr5 = CONFIG_SYS_CS5_MASK;
  93. #endif
  94. #ifdef CONFIG_FSL_I2C
  95. gpio->par_feci2c = GPIO_PAR_FECI2C_SDA_SDA | GPIO_PAR_FECI2C_SCL_SCL;
  96. #endif
  97. icache_enable();
  98. }
  99. /* initialize higher level parts of CPU like timers */
  100. int cpu_init_r(void)
  101. {
  102. #ifdef CONFIG_MCFFEC
  103. volatile ccm_t *ccm = (ccm_t *) MMAP_CCM;
  104. #endif
  105. #ifdef CONFIG_MCFRTC
  106. volatile rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE);
  107. volatile rtcex_t *rtcex = (rtcex_t *) & rtc->extended;
  108. rtcex->gocu = CONFIG_SYS_RTC_CNT;
  109. rtcex->gocl = CONFIG_SYS_RTC_SETUP;
  110. #endif
  111. #ifdef CONFIG_MCFFEC
  112. if (CONFIG_SYS_FEC0_MIIBASE != CONFIG_SYS_FEC1_MIIBASE)
  113. ccm->misccr |= CCM_MISCCR_FECM;
  114. else
  115. ccm->misccr &= ~CCM_MISCCR_FECM;
  116. #endif
  117. return (0);
  118. }
  119. void uart_port_conf(void)
  120. {
  121. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  122. /* Setup Ports: */
  123. switch (CONFIG_SYS_UART_PORT) {
  124. case 0:
  125. gpio->par_uart = (GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
  126. break;
  127. case 1:
  128. #ifdef CONFIG_SYS_UART1_ALT1_GPIO
  129. gpio->par_simp1h &=
  130. ~(GPIO_PAR_SIMP1H_DATA1_MASK | GPIO_PAR_SIMP1H_VEN1_MASK);
  131. gpio->par_simp1h |=
  132. (GPIO_PAR_SIMP1H_DATA1_U1TXD | GPIO_PAR_SIMP1H_VEN1_U1RXD);
  133. #elif defined(CONFIG_SYS_UART1_ALT2_GPIO)
  134. gpio->par_ssih &=
  135. ~(GPIO_PAR_SSIH_RXD_MASK | GPIO_PAR_SSIH_TXD_MASK);
  136. gpio->par_ssih |=
  137. (GPIO_PAR_SSIH_RXD_U1RXD | GPIO_PAR_SSIH_TXD_U1TXD);
  138. #endif
  139. break;
  140. case 2:
  141. #ifdef CONFIG_SYS_UART2_PRI_GPIO
  142. gpio->par_uart |= (GPIO_PAR_UART_U2TXD | GPIO_PAR_UART_U2RXD);
  143. #elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
  144. gpio->par_dspih &=
  145. ~(GPIO_PAR_DSPIH_SIN_MASK | GPIO_PAR_DSPIH_SOUT_MASK);
  146. gpio->par_dspih |=
  147. (GPIO_PAR_DSPIH_SIN_U2RXD | GPIO_PAR_DSPIH_SOUT_U2TXD);
  148. #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
  149. gpio->par_feci2c &=
  150. ~(GPIO_PAR_FECI2C_SDA_MASK | GPIO_PAR_FECI2C_SCL_MASK);
  151. gpio->par_feci2c |=
  152. (GPIO_PAR_FECI2C_SDA_U2TXD | GPIO_PAR_FECI2C_SCL_U2RXD);
  153. #endif
  154. break;
  155. }
  156. }
  157. #if defined(CONFIG_CMD_NET)
  158. int fecpin_setclear(struct eth_device *dev, int setclear)
  159. {
  160. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  161. struct fec_info_s *info = (struct fec_info_s *)dev->priv;
  162. if (setclear) {
  163. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  164. gpio->par_fec |=
  165. GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC;
  166. gpio->par_feci2c |=
  167. GPIO_PAR_FECI2C_MDC0 | GPIO_PAR_FECI2C_MDIO0;
  168. } else {
  169. gpio->par_fec |=
  170. GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC;
  171. gpio->par_feci2c |=
  172. GPIO_PAR_FECI2C_MDC1 | GPIO_PAR_FECI2C_MDIO1;
  173. }
  174. } else {
  175. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  176. gpio->par_fec &=
  177. ~(GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
  178. gpio->par_feci2c &= GPIO_PAR_FECI2C_RMII0_MASK;
  179. } else {
  180. gpio->par_fec &=
  181. ~(GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
  182. gpio->par_feci2c &= GPIO_PAR_FECI2C_RMII1_MASK;
  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. volatile scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  193. volatile scm2_t *scm2 = (scm2_t *) MMAP_SCM2;
  194. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  195. volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  196. volatile wdog_t *wdog = (wdog_t *) MMAP_WDOG;
  197. /* watchdog is enabled by default - disable the watchdog */
  198. #ifndef CONFIG_WATCHDOG
  199. wdog->cr = 0;
  200. #endif
  201. scm1->mpr0 = 0x77777777;
  202. scm2->pacra = 0;
  203. scm2->pacrb = 0;
  204. scm2->pacrc = 0;
  205. scm2->pacrd = 0;
  206. scm2->pacre = 0;
  207. scm2->pacrf = 0;
  208. scm2->pacrg = 0;
  209. scm1->pacrh = 0;
  210. /* Port configuration */
  211. gpio->par_cs = 0;
  212. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
  213. && defined(CONFIG_SYS_CS0_CTRL))
  214. fbcs->csar0 = CONFIG_SYS_CS0_BASE;
  215. fbcs->cscr0 = CONFIG_SYS_CS0_CTRL;
  216. 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. gpio->par_cs |= GPIO_PAR_CS1;
  222. fbcs->csar1 = CONFIG_SYS_CS1_BASE;
  223. fbcs->cscr1 = CONFIG_SYS_CS1_CTRL;
  224. 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. gpio->par_cs |= GPIO_PAR_CS2;
  229. fbcs->csar2 = CONFIG_SYS_CS2_BASE;
  230. fbcs->cscr2 = CONFIG_SYS_CS2_CTRL;
  231. 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. gpio->par_cs |= GPIO_PAR_CS3;
  236. fbcs->csar3 = CONFIG_SYS_CS3_BASE;
  237. fbcs->cscr3 = CONFIG_SYS_CS3_CTRL;
  238. 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. gpio->par_cs |= GPIO_PAR_CS4;
  243. fbcs->csar4 = CONFIG_SYS_CS4_BASE;
  244. fbcs->cscr4 = CONFIG_SYS_CS4_CTRL;
  245. 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. gpio->par_cs |= GPIO_PAR_CS5;
  250. fbcs->csar5 = CONFIG_SYS_CS5_BASE;
  251. fbcs->cscr5 = CONFIG_SYS_CS5_CTRL;
  252. fbcs->csmr5 = CONFIG_SYS_CS5_MASK;
  253. #endif
  254. #ifdef CONFIG_FSL_I2C
  255. gpio->par_feci2c = GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA;
  256. #endif
  257. icache_enable();
  258. }
  259. /*
  260. * initialize higher level parts of CPU like timers
  261. */
  262. int cpu_init_r(void)
  263. {
  264. return (0);
  265. }
  266. void uart_port_conf(void)
  267. {
  268. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  269. /* Setup Ports: */
  270. switch (CONFIG_SYS_UART_PORT) {
  271. case 0:
  272. gpio->par_uart = (GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
  273. break;
  274. case 1:
  275. gpio->par_uart =
  276. (GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
  277. break;
  278. case 2:
  279. gpio->par_timer &= 0x0F;
  280. gpio->par_timer |= (GPIO_PAR_TIN3_URXD2 | GPIO_PAR_TIN2_UTXD2);
  281. break;
  282. }
  283. }
  284. #if defined(CONFIG_CMD_NET)
  285. int fecpin_setclear(struct eth_device *dev, int setclear)
  286. {
  287. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  288. if (setclear) {
  289. gpio->par_fec |= GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC;
  290. gpio->par_feci2c |=
  291. GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO;
  292. } else {
  293. gpio->par_fec &= ~(GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
  294. gpio->par_feci2c &=
  295. ~(GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
  296. }
  297. return 0;
  298. }
  299. #endif
  300. #endif /* CONFIG_MCF532x */