cpu_init.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
  168. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  169. gpio->par_feci2c |=
  170. (GPIO_PAR_FECI2C_MDC0_MDC0 |
  171. GPIO_PAR_FECI2C_MDIO0_MDIO0);
  172. else
  173. gpio->par_feci2c |=
  174. (GPIO_PAR_FECI2C_MDC1_MDC1 |
  175. GPIO_PAR_FECI2C_MDIO1_MDIO1);
  176. #else
  177. gpio->par_feci2c |=
  178. (GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  179. #endif
  180. if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
  181. gpio->par_fec |= GPIO_PAR_FEC_FEC0_RMII_GPIO;
  182. else
  183. gpio->par_fec |= GPIO_PAR_FEC_FEC1_RMII_ATA;
  184. } else {
  185. gpio->par_feci2c &=
  186. ~(GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
  187. if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
  188. #ifdef CONFIG_SYS_FEC_FULL_MII
  189. gpio->par_fec |= GPIO_PAR_FEC_FEC0_MII;
  190. #else
  191. gpio->par_fec &= GPIO_PAR_FEC_FEC0_UNMASK;
  192. #endif
  193. } else {
  194. #ifdef CONFIG_SYS_FEC_FULL_MII
  195. gpio->par_fec |= GPIO_PAR_FEC_FEC1_MII;
  196. #else
  197. gpio->par_fec &= GPIO_PAR_FEC_FEC1_UNMASK;
  198. #endif
  199. }
  200. }
  201. return 0;
  202. }
  203. #endif
  204. #ifdef CONFIG_CF_DSPI
  205. void cfspi_port_conf(void)
  206. {
  207. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  208. gpio->par_dspi = GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
  209. GPIO_PAR_DSPI_SCK_SCK;
  210. }
  211. int cfspi_claim_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. if ((dspi->sr & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
  216. return -1;
  217. /* Clear FIFO and resume transfer */
  218. dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  219. switch (cs) {
  220. case 0:
  221. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
  222. gpio->par_dspi |= GPIO_PAR_DSPI_PCS0_PCS0;
  223. break;
  224. case 1:
  225. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
  226. gpio->par_dspi |= GPIO_PAR_DSPI_PCS1_PCS1;
  227. break;
  228. case 2:
  229. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
  230. gpio->par_dspi |= GPIO_PAR_DSPI_PCS2_PCS2;
  231. break;
  232. case 3:
  233. gpio->par_dma &= GPIO_PAR_DMA_DACK0_UNMASK;
  234. gpio->par_dma |= GPIO_PAR_DMA_DACK0_PCS3;
  235. break;
  236. case 5:
  237. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
  238. gpio->par_dspi |= GPIO_PAR_DSPI_PCS5_PCS5;
  239. break;
  240. }
  241. return 0;
  242. }
  243. void cfspi_release_bus(uint bus, uint cs)
  244. {
  245. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  246. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  247. dspi->mcr &= ~(DSPI_MCR_CTXF | DSPI_MCR_CRXF); /* Clear FIFO */
  248. switch (cs) {
  249. case 0:
  250. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS0_PCS0;
  251. break;
  252. case 1:
  253. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS1_PCS1;
  254. break;
  255. case 2:
  256. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS2_PCS2;
  257. break;
  258. case 3:
  259. gpio->par_dma &= GPIO_PAR_DMA_DACK0_UNMASK;
  260. break;
  261. case 5:
  262. gpio->par_dspi &= ~GPIO_PAR_DSPI_PCS5_PCS5;
  263. break;
  264. }
  265. }
  266. #endif