cpu_init.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <watchdog.h>
  9. #include <mpc8xx.h>
  10. #include <asm/cpm_8xx.h>
  11. #include <asm/io.h>
  12. /*
  13. * Breath some life into the CPU...
  14. *
  15. * Set up the memory map,
  16. * initialize a bunch of registers,
  17. * initialize the UPM's
  18. */
  19. void cpu_init_f(immap_t __iomem *immr)
  20. {
  21. memctl8xx_t __iomem *memctl = &immr->im_memctl;
  22. ulong reg;
  23. /* SYPCR - contains watchdog control (11-9) */
  24. out_be32(&immr->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR);
  25. #if defined(CONFIG_WATCHDOG)
  26. reset_8xx_watchdog(immr);
  27. #endif /* CONFIG_WATCHDOG */
  28. /* SIUMCR - contains debug pin configuration (11-6) */
  29. setbits_be32(&immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR);
  30. /* initialize timebase status and control register (11-26) */
  31. /* unlock TBSCRK */
  32. out_be32(&immr->im_sitk.sitk_tbscrk, KAPWR_KEY);
  33. out_be16(&immr->im_sit.sit_tbscr, CONFIG_SYS_TBSCR | TBSCR_TBE);
  34. /* Unlock timebase register */
  35. out_be32(&immr->im_sitk.sitk_tbk, KAPWR_KEY);
  36. /* initialize the PIT (11-31) */
  37. out_be32(&immr->im_sitk.sitk_piscrk, KAPWR_KEY);
  38. out_be16(&immr->im_sit.sit_piscr, CONFIG_SYS_PISCR);
  39. /* System integration timers. Don't change EBDF! (15-27) */
  40. out_be32(&immr->im_clkrstk.cark_sccrk, KAPWR_KEY);
  41. clrsetbits_be32(&immr->im_clkrst.car_sccr, ~CONFIG_SYS_SCCR_MASK,
  42. CONFIG_SYS_SCCR);
  43. /*
  44. * MPC866/885 ERRATA GLL2
  45. * Description:
  46. * In 1:2:1 mode, when HRESET is detected at the positive edge of
  47. * EXTCLK, then there will be a loss of phase between
  48. * EXTCLK and CLKOUT.
  49. *
  50. * Workaround:
  51. * Reprogram the SCCR:
  52. * 1. Write 1'b00 to SCCR[EBDF].
  53. * 2. Write 1'b01 to SCCR[EBDF].
  54. * 3. Rewrite the desired value to the PLPRCR register.
  55. */
  56. reg = in_be32(&immr->im_clkrst.car_sccr);
  57. /* Are we in mode 1:2:1 ? */
  58. if ((reg & SCCR_EBDF11) == SCCR_EBDF01) {
  59. clrbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF11);
  60. setbits_be32(&immr->im_clkrst.car_sccr, SCCR_EBDF01);
  61. }
  62. /* PLL (CPU clock) settings (15-30) */
  63. out_be32(&immr->im_clkrstk.cark_plprcrk, KAPWR_KEY);
  64. /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
  65. * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
  66. * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
  67. * field value.
  68. *
  69. * For newer (starting MPC866) chips PLPRCR layout is different.
  70. */
  71. #ifdef CONFIG_SYS_PLPRCR
  72. if ((CONFIG_SYS_PLPRCR & PLPRCR_MFACT_MSK) != 0) /* reset control bits*/
  73. out_be32(&immr->im_clkrst.car_plprcr, CONFIG_SYS_PLPRCR);
  74. else /* isolate MF-related fields and reset control bits */
  75. clrsetbits_be32(&immr->im_clkrst.car_plprcr, ~PLPRCR_MFACT_MSK,
  76. CONFIG_SYS_PLPRCR);
  77. #endif
  78. /*
  79. * Memory Controller:
  80. */
  81. /* Clear everything except Port Size bits & add the "Bank Valid" bit */
  82. clrsetbits_be32(&memctl->memc_br0, ~BR_PS_MSK, BR_V);
  83. /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
  84. * preliminary addresses - these have to be modified later
  85. * when FLASH size has been determined
  86. *
  87. * Depending on the size of the memory region defined by
  88. * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
  89. * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
  90. * map CONFIG_SYS_MONITOR_BASE.
  91. *
  92. * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
  93. * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
  94. *
  95. * If BR0 wasn't loaded with address base 0xff000000, then BR0's
  96. * base address remains as 0x00000000. However, the address mask
  97. * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
  98. * into the Bank0.
  99. *
  100. * This is why CONFIG_IVMS8 and similar boards must load BR0 with
  101. * CONFIG_SYS_BR0_PRELIM in advance.
  102. *
  103. * [Thanks to Michael Liao for this explanation.
  104. * I owe him a free beer. - wd]
  105. */
  106. #if defined(CONFIG_SYS_OR0_REMAP)
  107. out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_REMAP);
  108. #endif
  109. #if defined(CONFIG_SYS_OR1_REMAP)
  110. out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_REMAP);
  111. #endif
  112. #if defined(CONFIG_SYS_OR5_REMAP)
  113. out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_REMAP);
  114. #endif
  115. /* now restrict to preliminary range */
  116. out_be32(&memctl->memc_br0, CONFIG_SYS_BR0_PRELIM);
  117. out_be32(&memctl->memc_or0, CONFIG_SYS_OR0_PRELIM);
  118. #if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
  119. out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
  120. out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
  121. #endif
  122. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  123. out_be32(&memctl->memc_or2, CONFIG_SYS_OR2_PRELIM);
  124. out_be32(&memctl->memc_br2, CONFIG_SYS_BR2_PRELIM);
  125. #endif
  126. #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
  127. out_be32(&memctl->memc_or3, CONFIG_SYS_OR3_PRELIM);
  128. out_be32(&memctl->memc_br3, CONFIG_SYS_BR3_PRELIM);
  129. #endif
  130. #if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
  131. out_be32(&memctl->memc_or4, CONFIG_SYS_OR4_PRELIM);
  132. out_be32(&memctl->memc_br4, CONFIG_SYS_BR4_PRELIM);
  133. #endif
  134. #if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
  135. out_be32(&memctl->memc_or5, CONFIG_SYS_OR5_PRELIM);
  136. out_be32(&memctl->memc_br5, CONFIG_SYS_BR5_PRELIM);
  137. #endif
  138. #if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
  139. out_be32(&memctl->memc_or6, CONFIG_SYS_OR6_PRELIM);
  140. out_be32(&memctl->memc_br6, CONFIG_SYS_BR6_PRELIM);
  141. #endif
  142. #if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
  143. out_be32(&memctl->memc_or7, CONFIG_SYS_OR7_PRELIM);
  144. out_be32(&memctl->memc_br7, CONFIG_SYS_BR7_PRELIM);
  145. #endif
  146. /*
  147. * Reset CPM
  148. */
  149. out_be16(&immr->im_cpm.cp_cpcr, CPM_CR_RST | CPM_CR_FLG);
  150. /* Spin until command processed */
  151. while (in_be16(&immr->im_cpm.cp_cpcr) & CPM_CR_FLG)
  152. ;
  153. }
  154. /*
  155. * initialize higher level parts of CPU like timers
  156. */
  157. int cpu_init_r(void)
  158. {
  159. return 0;
  160. }