cpu_init.c 4.8 KB

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