cpu_init.c 4.8 KB

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