cpu_init.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <watchdog.h>
  25. #include <mpc8xx.h>
  26. #include <commproc.h>
  27. #if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
  28. void cpm_load_patch (volatile immap_t * immr);
  29. #endif
  30. /*
  31. * Breath some life into the CPU...
  32. *
  33. * Set up the memory map,
  34. * initialize a bunch of registers,
  35. * initialize the UPM's
  36. */
  37. void cpu_init_f (volatile immap_t * immr)
  38. {
  39. #ifndef CONFIG_MBX
  40. volatile memctl8xx_t *memctl = &immr->im_memctl;
  41. ulong mfmask;
  42. #endif
  43. ulong reg;
  44. /* SYPCR - contains watchdog control (11-9) */
  45. immr->im_siu_conf.sc_sypcr = CFG_SYPCR;
  46. #if defined(CONFIG_WATCHDOG)
  47. reset_8xx_watchdog (immr);
  48. #endif /* CONFIG_WATCHDOG */
  49. /* SIUMCR - contains debug pin configuration (11-6) */
  50. #ifndef CONFIG_SVM_SC8xx
  51. immr->im_siu_conf.sc_siumcr |= CFG_SIUMCR;
  52. #else
  53. immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
  54. #endif
  55. /* initialize timebase status and control register (11-26) */
  56. /* unlock TBSCRK */
  57. immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
  58. immr->im_sit.sit_tbscr = CFG_TBSCR;
  59. /* initialize the PIT (11-31) */
  60. immr->im_sitk.sitk_piscrk = KAPWR_KEY;
  61. immr->im_sit.sit_piscr = CFG_PISCR;
  62. /* System integration timers. Don't change EBDF! (15-27) */
  63. immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
  64. reg = immr->im_clkrst.car_sccr;
  65. reg &= SCCR_MASK;
  66. reg |= CFG_SCCR;
  67. immr->im_clkrst.car_sccr = reg;
  68. /* PLL (CPU clock) settings (15-30) */
  69. immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
  70. #ifndef CONFIG_MBX /* MBX board does things different */
  71. /* If CFG_PLPRCR (set in the various *_config.h files) tries to
  72. * set the MF field, then just copy CFG_PLPRCR over car_plprcr,
  73. * otherwise OR in CFG_PLPRCR so we do not change the current MF
  74. * field value.
  75. *
  76. * For newer (starting MPC866) chips PLPRCR layout is different.
  77. */
  78. if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
  79. mfmask = PLPRCR_MFACT_MSK;
  80. else
  81. mfmask = PLPRCR_MF_MSK;
  82. if ((CFG_PLPRCR & mfmask) != 0)
  83. reg = CFG_PLPRCR; /* reset control bits */
  84. else {
  85. reg = immr->im_clkrst.car_plprcr;
  86. reg &= mfmask; /* isolate MF-related fields */
  87. reg |= CFG_PLPRCR; /* reset control bits */
  88. }
  89. immr->im_clkrst.car_plprcr = reg;
  90. /*
  91. * Memory Controller:
  92. */
  93. /* perform BR0 reset that MPC850 Rev. A can't guarantee */
  94. reg = memctl->memc_br0;
  95. reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
  96. reg |= BR_V; /* then add just the "Bank Valid" bit */
  97. memctl->memc_br0 = reg;
  98. /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
  99. * preliminary addresses - these have to be modified later
  100. * when FLASH size has been determined
  101. *
  102. * Depending on the size of the memory region defined by
  103. * CFG_OR0_REMAP some boards (wide address mask) allow to map the
  104. * CFG_MONITOR_BASE, while others (narrower address mask) can't
  105. * map CFG_MONITOR_BASE.
  106. *
  107. * For example, for CONFIG_IVMS8, the CFG_MONITOR_BASE is
  108. * 0xff000000, but CFG_OR0_REMAP's address mask is 0xfff80000.
  109. *
  110. * If BR0 wasn't loaded with address base 0xff000000, then BR0's
  111. * base address remains as 0x00000000. However, the address mask
  112. * have been narrowed to 512Kb, so CFG_MONITOR_BASE wasn't mapped
  113. * into the Bank0.
  114. *
  115. * This is why CONFIG_IVMS8 and similar boards must load BR0 with
  116. * CFG_BR0_PRELIM in advance.
  117. *
  118. * [Thanks to Michael Liao for this explanation.
  119. * I owe him a free beer. - wd]
  120. */
  121. #if defined(CONFIG_ADDERII) || \
  122. defined(CONFIG_GTH) || \
  123. defined(CONFIG_HERMES) || \
  124. defined(CONFIG_ICU862) || \
  125. defined(CONFIG_IP860) || \
  126. defined(CONFIG_IVML24) || \
  127. defined(CONFIG_IVMS8) || \
  128. defined(CONFIG_LWMON) || \
  129. defined(CONFIG_MHPC) || \
  130. defined(CONFIG_PCU_E) || \
  131. defined(CONFIG_R360MPI) || \
  132. defined(CONFIG_RPXCLASSIC) || \
  133. defined(CONFIG_RPXLITE) || \
  134. defined(CONFIG_SPD823TS)
  135. memctl->memc_br0 = CFG_BR0_PRELIM;
  136. #endif
  137. #if defined(CFG_OR0_REMAP)
  138. memctl->memc_or0 = CFG_OR0_REMAP;
  139. #endif
  140. #if defined(CFG_OR1_REMAP)
  141. memctl->memc_or1 = CFG_OR1_REMAP;
  142. #endif
  143. #if defined(CFG_OR5_REMAP)
  144. memctl->memc_or5 = CFG_OR5_REMAP;
  145. #endif
  146. /* now restrict to preliminary range */
  147. memctl->memc_br0 = CFG_BR0_PRELIM;
  148. memctl->memc_or0 = CFG_OR0_PRELIM;
  149. #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
  150. memctl->memc_or1 = CFG_OR1_PRELIM;
  151. memctl->memc_br1 = CFG_BR1_PRELIM;
  152. #endif
  153. #if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
  154. memctl->memc_br0 = 0;
  155. #endif
  156. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  157. memctl->memc_or2 = CFG_OR2_PRELIM;
  158. memctl->memc_br2 = CFG_BR2_PRELIM;
  159. #endif
  160. #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
  161. memctl->memc_or3 = CFG_OR3_PRELIM;
  162. memctl->memc_br3 = CFG_BR3_PRELIM;
  163. #endif
  164. #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
  165. memctl->memc_or4 = CFG_OR4_PRELIM;
  166. memctl->memc_br4 = CFG_BR4_PRELIM;
  167. #endif
  168. #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
  169. memctl->memc_or5 = CFG_OR5_PRELIM;
  170. memctl->memc_br5 = CFG_BR5_PRELIM;
  171. #endif
  172. #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
  173. memctl->memc_or6 = CFG_OR6_PRELIM;
  174. memctl->memc_br6 = CFG_BR6_PRELIM;
  175. #endif
  176. #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
  177. memctl->memc_or7 = CFG_OR7_PRELIM;
  178. memctl->memc_br7 = CFG_BR7_PRELIM;
  179. #endif
  180. #endif /* ! CONFIG_MBX */
  181. /*
  182. * Reset CPM
  183. */
  184. immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
  185. do { /* Spin until command processed */
  186. __asm__ ("eieio");
  187. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  188. #ifdef CONFIG_MBX
  189. /*
  190. * on the MBX, things are a little bit different:
  191. * - we need to read the VPD to get board information
  192. * - the plprcr is set up dynamically
  193. * - the memory controller is set up dynamically
  194. */
  195. mbx_init ();
  196. #endif /* CONFIG_MBX */
  197. #ifdef CONFIG_RPXCLASSIC
  198. rpxclassic_init ();
  199. #endif
  200. #ifdef CFG_RCCR /* must be done before cpm_load_patch() */
  201. /* write config value */
  202. immr->im_cpm.cp_rccr = CFG_RCCR;
  203. #endif
  204. #if defined(CFG_I2C_UCODE_PATCH) || defined(CFG_SPI_UCODE_PATCH)
  205. cpm_load_patch (immr); /* load mpc8xx microcode patch */
  206. #endif
  207. }
  208. /*
  209. * initialize higher level parts of CPU like timers
  210. */
  211. int cpu_init_r (void)
  212. {
  213. #if defined(CFG_RTCSC) || defined(CFG_RMDS)
  214. DECLARE_GLOBAL_DATA_PTR;
  215. bd_t *bd = gd->bd;
  216. volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
  217. #endif
  218. #ifdef CFG_RTCSC
  219. /* Unlock RTSC register */
  220. immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
  221. /* write config value */
  222. immr->im_sit.sit_rtcsc = CFG_RTCSC;
  223. #endif
  224. #ifdef CFG_RMDS
  225. /* write config value */
  226. immr->im_cpm.cp_rmds = CFG_RMDS;
  227. #endif
  228. return (0);
  229. }