cpu_init.c 8.3 KB

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