cpu_init.c 5.6 KB

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