cpu_init.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. *
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * (C) Copyright 2004-2007 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/processor.h>
  31. #include <asm/rtc.h>
  32. #if defined(CONFIG_CMD_NET)
  33. #include <config.h>
  34. #include <net.h>
  35. #include <asm/fec.h>
  36. #endif
  37. /*
  38. * Breath some life into the CPU...
  39. *
  40. * Set up the memory map,
  41. * initialize a bunch of registers,
  42. * initialize the UPM's
  43. */
  44. void cpu_init_f(void)
  45. {
  46. volatile scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  47. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  48. volatile fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  49. scm1->mpr = 0x77777777;
  50. scm1->pacra = 0;
  51. scm1->pacrb = 0;
  52. scm1->pacrc = 0;
  53. scm1->pacrd = 0;
  54. scm1->pacre = 0;
  55. scm1->pacrf = 0;
  56. scm1->pacrg = 0;
  57. /* FlexBus */
  58. gpio->par_be =
  59. GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 | GPIO_PAR_BE_BE1_BE1 |
  60. GPIO_PAR_BE_BE0_BE0;
  61. gpio->par_fbctl =
  62. GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA | GPIO_PAR_FBCTL_RW_RW |
  63. GPIO_PAR_FBCTL_TS_TS;
  64. #if !defined(CONFIG_CF_SBF)
  65. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
  66. fbcs->csar0 = CONFIG_SYS_CS0_BASE;
  67. fbcs->cscr0 = CONFIG_SYS_CS0_CTRL;
  68. fbcs->csmr0 = CONFIG_SYS_CS0_MASK;
  69. #endif
  70. #endif
  71. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
  72. /* Latch chipselect */
  73. fbcs->csar1 = CONFIG_SYS_CS1_BASE;
  74. fbcs->cscr1 = CONFIG_SYS_CS1_CTRL;
  75. fbcs->csmr1 = CONFIG_SYS_CS1_MASK;
  76. #endif
  77. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
  78. fbcs->csar2 = CONFIG_SYS_CS2_BASE;
  79. fbcs->cscr2 = CONFIG_SYS_CS2_CTRL;
  80. fbcs->csmr2 = CONFIG_SYS_CS2_MASK;
  81. #endif
  82. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
  83. fbcs->csar3 = CONFIG_SYS_CS3_BASE;
  84. fbcs->cscr3 = CONFIG_SYS_CS3_CTRL;
  85. fbcs->csmr3 = CONFIG_SYS_CS3_MASK;
  86. #endif
  87. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
  88. fbcs->csar4 = CONFIG_SYS_CS4_BASE;
  89. fbcs->cscr4 = CONFIG_SYS_CS4_CTRL;
  90. fbcs->csmr4 = CONFIG_SYS_CS4_MASK;
  91. #endif
  92. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
  93. fbcs->csar5 = CONFIG_SYS_CS5_BASE;
  94. fbcs->cscr5 = CONFIG_SYS_CS5_CTRL;
  95. fbcs->csmr5 = CONFIG_SYS_CS5_MASK;
  96. #endif
  97. /*
  98. * now the flash base address is no longer at 0 (Newer ColdFire family
  99. * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
  100. * also move to the new location.
  101. */
  102. if (CONFIG_SYS_CS0_BASE != 0)
  103. setvbr(CONFIG_SYS_CS0_BASE);
  104. #ifdef CONFIG_FSL_I2C
  105. gpio->par_feci2c = GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA;
  106. #endif
  107. icache_enable();
  108. }
  109. /*
  110. * initialize higher level parts of CPU like timers
  111. */
  112. int cpu_init_r(void)
  113. {
  114. #ifdef CONFIG_MCFRTC
  115. volatile rtc_t *rtc = (volatile rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
  116. volatile rtcex_t *rtcex = (volatile rtcex_t *)&rtc->extended;
  117. rtcex->gocu = (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xFFFF;
  118. rtcex->gocl = CONFIG_SYS_RTC_OSCILLATOR & 0xFFFF;
  119. #endif
  120. return (0);
  121. }
  122. void uart_port_conf(int port)
  123. {
  124. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  125. /* Setup Ports: */
  126. switch (port) {
  127. case 0:
  128. gpio->par_uart &=
  129. ~(GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
  130. gpio->par_uart |=
  131. (GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
  132. break;
  133. case 1:
  134. #ifdef CONFIG_SYS_UART1_PRI_GPIO
  135. gpio->par_uart &=
  136. ~(GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
  137. gpio->par_uart |=
  138. (GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
  139. #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
  140. gpio->par_ssi &=
  141. (GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK);
  142. gpio->par_ssi |=
  143. (GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
  144. #endif
  145. break;
  146. case 2:
  147. #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
  148. gpio->par_timer &=
  149. (GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK);
  150. gpio->par_timer |=
  151. (GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
  152. #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
  153. gpio->par_timer &=
  154. (GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK);
  155. gpio->par_timer |=
  156. (GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
  157. #endif
  158. break;
  159. }
  160. }
  161. #if defined(CONFIG_CMD_NET)
  162. int fecpin_setclear(struct eth_device *dev, int setclear)
  163. {
  164. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  165. struct fec_info_s *info = (struct fec_info_s *)dev->priv;
  166. if (setclear) {
  167. gpio->par_feci2c |=
  168. (GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  169. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  170. gpio->par_fec |= GPIO_PAR_FEC_FEC0_RMII_GPIO;
  171. else
  172. gpio->par_fec |= GPIO_PAR_FEC_FEC1_RMII_ATA;
  173. } else {
  174. gpio->par_feci2c &=
  175. ~(GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  176. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  177. gpio->par_fec &= GPIO_PAR_FEC_FEC0_UNMASK;
  178. else
  179. gpio->par_fec &= GPIO_PAR_FEC_FEC1_UNMASK;
  180. }
  181. return 0;
  182. }
  183. #endif
  184. #ifdef CONFIG_CF_DSPI
  185. void cfspi_port_conf(void)
  186. {
  187. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  188. gpio->par_dspi = GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
  189. GPIO_PAR_DSPI_SCK_SCK;
  190. }
  191. int cfspi_claim_bus(uint bus, uint cs)
  192. {
  193. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  194. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  195. if ((dspi->sr & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
  196. return -1;
  197. /* Clear FIFO and resume transfer */
  198. dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  199. switch (cs) {
  200. case 0:
  201. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
  202. gpio->par_dspi |= GPIO_PAR_DSPI_PCS0_PCS0;
  203. break;
  204. case 1:
  205. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
  206. gpio->par_dspi |= GPIO_PAR_DSPI_PCS1_PCS1;
  207. break;
  208. case 2:
  209. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
  210. gpio->par_dspi |= GPIO_PAR_DSPI_PCS2_PCS2;
  211. break;
  212. case 5:
  213. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
  214. gpio->par_dspi |= GPIO_PAR_DSPI_PCS5_PCS5;
  215. break;
  216. }
  217. return 0;
  218. }
  219. void cfspi_release_bus(uint bus, uint cs)
  220. {
  221. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  222. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  223. dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF); /* Clear FIFO */
  224. switch (cs) {
  225. case 0:
  226. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
  227. break;
  228. case 1:
  229. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
  230. break;
  231. case 2:
  232. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
  233. break;
  234. case 5:
  235. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
  236. break;
  237. }
  238. }
  239. #endif