cpu_init.c 6.9 KB

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