cpu_init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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/io.h>
  31. #include <asm/rtc.h>
  32. /*
  33. * Breath some life into the CPU...
  34. *
  35. * Set up the memory map,
  36. * initialize a bunch of registers,
  37. * initialize the UPM's
  38. */
  39. void cpu_init_f(void)
  40. {
  41. scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
  42. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  43. fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  44. pll_t *pll = (pll_t *)MMAP_PLL;
  45. #if !defined(CONFIG_CF_SBF)
  46. /* Workaround, must place before fbcs */
  47. out_be32(&pll->psr, 0x12);
  48. out_be32(&scm1->mpr, 0x77777777);
  49. out_be32(&scm1->pacra, 0);
  50. out_be32(&scm1->pacrb, 0);
  51. out_be32(&scm1->pacrc, 0);
  52. out_be32(&scm1->pacrd, 0);
  53. out_be32(&scm1->pacre, 0);
  54. out_be32(&scm1->pacrf, 0);
  55. out_be32(&scm1->pacrg, 0);
  56. out_be32(&scm1->pacri, 0);
  57. #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
  58. && defined(CONFIG_SYS_CS0_CTRL))
  59. out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
  60. out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
  61. out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
  62. #endif
  63. #endif /* CONFIG_CF_SBF */
  64. #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
  65. && defined(CONFIG_SYS_CS1_CTRL))
  66. out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
  67. out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
  68. out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
  69. #endif
  70. #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
  71. && defined(CONFIG_SYS_CS2_CTRL))
  72. out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
  73. out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
  74. out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
  75. #endif
  76. #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
  77. && defined(CONFIG_SYS_CS3_CTRL))
  78. out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
  79. out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
  80. out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
  81. #endif
  82. #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
  83. && defined(CONFIG_SYS_CS4_CTRL))
  84. out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
  85. out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
  86. out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
  87. #endif
  88. #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
  89. && defined(CONFIG_SYS_CS5_CTRL))
  90. out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
  91. out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
  92. out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
  93. #endif
  94. #ifdef CONFIG_FSL_I2C
  95. out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA);
  96. #endif
  97. icache_enable();
  98. }
  99. /*
  100. * initialize higher level parts of CPU like timers
  101. */
  102. int cpu_init_r(void)
  103. {
  104. #ifdef CONFIG_MCFRTC
  105. rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
  106. rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
  107. out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
  108. out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
  109. #endif
  110. return (0);
  111. }
  112. void uart_port_conf(int port)
  113. {
  114. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  115. /* Setup Ports: */
  116. switch (port) {
  117. case 0:
  118. clrbits_be16(&gpio->par_uart,
  119. ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK));
  120. setbits_be16(&gpio->par_uart,
  121. GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
  122. break;
  123. case 1:
  124. clrbits_be16(&gpio->par_uart,
  125. ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK));
  126. setbits_be16(&gpio->par_uart,
  127. GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
  128. break;
  129. case 2:
  130. clrbits_8(&gpio->par_dspi,
  131. ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK));
  132. out_8(&gpio->par_dspi,
  133. GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD);
  134. break;
  135. }
  136. }
  137. #ifdef CONFIG_CF_DSPI
  138. void cfspi_port_conf(void)
  139. {
  140. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  141. out_8(&gpio->par_dspi,
  142. GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
  143. GPIO_PAR_DSPI_SCK_SCK);
  144. }
  145. int cfspi_claim_bus(uint bus, uint cs)
  146. {
  147. dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  148. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  149. if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
  150. return -1;
  151. /* Clear FIFO and resume transfer */
  152. clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  153. switch (cs) {
  154. case 0:
  155. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK);
  156. setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
  157. break;
  158. case 2:
  159. clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
  160. setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2);
  161. break;
  162. }
  163. return 0;
  164. }
  165. void cfspi_release_bus(uint bus, uint cs)
  166. {
  167. dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  168. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  169. /* Clear FIFO */
  170. clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
  171. switch (cs) {
  172. case 0:
  173. clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
  174. break;
  175. case 2:
  176. clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK);
  177. break;
  178. }
  179. }
  180. #endif