cpu_init.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_RMDS)
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #endif
  30. #if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
  31. defined(CONFIG_SYS_SMC_UCODE_PATCH)
  32. void cpm_load_patch (volatile immap_t * immr);
  33. #endif
  34. /*
  35. * Breath some life into the CPU...
  36. *
  37. * Set up the memory map,
  38. * initialize a bunch of registers,
  39. * initialize the UPM's
  40. */
  41. void cpu_init_f (volatile immap_t * immr)
  42. {
  43. #ifndef CONFIG_MBX
  44. volatile memctl8xx_t *memctl = &immr->im_memctl;
  45. # ifdef CONFIG_SYS_PLPRCR
  46. ulong mfmask;
  47. # endif
  48. #endif
  49. ulong reg;
  50. /* SYPCR - contains watchdog control (11-9) */
  51. immr->im_siu_conf.sc_sypcr = CONFIG_SYS_SYPCR;
  52. #if defined(CONFIG_WATCHDOG)
  53. reset_8xx_watchdog (immr);
  54. #endif /* CONFIG_WATCHDOG */
  55. /* SIUMCR - contains debug pin configuration (11-6) */
  56. #ifndef CONFIG_SVM_SC8xx
  57. immr->im_siu_conf.sc_siumcr |= CONFIG_SYS_SIUMCR;
  58. #else
  59. immr->im_siu_conf.sc_siumcr = CONFIG_SYS_SIUMCR;
  60. #endif
  61. /* initialize timebase status and control register (11-26) */
  62. /* unlock TBSCRK */
  63. immr->im_sitk.sitk_tbscrk = KAPWR_KEY;
  64. immr->im_sit.sit_tbscr = CONFIG_SYS_TBSCR;
  65. /* initialize the PIT (11-31) */
  66. immr->im_sitk.sitk_piscrk = KAPWR_KEY;
  67. immr->im_sit.sit_piscr = CONFIG_SYS_PISCR;
  68. /* System integration timers. Don't change EBDF! (15-27) */
  69. immr->im_clkrstk.cark_sccrk = KAPWR_KEY;
  70. reg = immr->im_clkrst.car_sccr;
  71. reg &= SCCR_MASK;
  72. reg |= CONFIG_SYS_SCCR;
  73. immr->im_clkrst.car_sccr = reg;
  74. /* PLL (CPU clock) settings (15-30) */
  75. immr->im_clkrstk.cark_plprcrk = KAPWR_KEY;
  76. #ifndef CONFIG_MBX /* MBX board does things different */
  77. /* If CONFIG_SYS_PLPRCR (set in the various *_config.h files) tries to
  78. * set the MF field, then just copy CONFIG_SYS_PLPRCR over car_plprcr,
  79. * otherwise OR in CONFIG_SYS_PLPRCR so we do not change the current MF
  80. * field value.
  81. *
  82. * For newer (starting MPC866) chips PLPRCR layout is different.
  83. */
  84. #ifdef CONFIG_SYS_PLPRCR
  85. if (get_immr(0xFFFF) >= MPC8xx_NEW_CLK)
  86. mfmask = PLPRCR_MFACT_MSK;
  87. else
  88. mfmask = PLPRCR_MF_MSK;
  89. if ((CONFIG_SYS_PLPRCR & mfmask) != 0)
  90. reg = CONFIG_SYS_PLPRCR; /* reset control bits */
  91. else {
  92. reg = immr->im_clkrst.car_plprcr;
  93. reg &= mfmask; /* isolate MF-related fields */
  94. reg |= CONFIG_SYS_PLPRCR; /* reset control bits */
  95. }
  96. immr->im_clkrst.car_plprcr = reg;
  97. #endif
  98. /*
  99. * Memory Controller:
  100. */
  101. /* perform BR0 reset that MPC850 Rev. A can't guarantee */
  102. reg = memctl->memc_br0;
  103. reg &= BR_PS_MSK; /* Clear everything except Port Size bits */
  104. reg |= BR_V; /* then add just the "Bank Valid" bit */
  105. memctl->memc_br0 = reg;
  106. /* Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
  107. * preliminary addresses - these have to be modified later
  108. * when FLASH size has been determined
  109. *
  110. * Depending on the size of the memory region defined by
  111. * CONFIG_SYS_OR0_REMAP some boards (wide address mask) allow to map the
  112. * CONFIG_SYS_MONITOR_BASE, while others (narrower address mask) can't
  113. * map CONFIG_SYS_MONITOR_BASE.
  114. *
  115. * For example, for CONFIG_IVMS8, the CONFIG_SYS_MONITOR_BASE is
  116. * 0xff000000, but CONFIG_SYS_OR0_REMAP's address mask is 0xfff80000.
  117. *
  118. * If BR0 wasn't loaded with address base 0xff000000, then BR0's
  119. * base address remains as 0x00000000. However, the address mask
  120. * have been narrowed to 512Kb, so CONFIG_SYS_MONITOR_BASE wasn't mapped
  121. * into the Bank0.
  122. *
  123. * This is why CONFIG_IVMS8 and similar boards must load BR0 with
  124. * CONFIG_SYS_BR0_PRELIM in advance.
  125. *
  126. * [Thanks to Michael Liao for this explanation.
  127. * I owe him a free beer. - wd]
  128. */
  129. #if defined(CONFIG_HERMES) || \
  130. defined(CONFIG_ICU862) || \
  131. defined(CONFIG_IP860) || \
  132. defined(CONFIG_IVML24) || \
  133. defined(CONFIG_IVMS8) || \
  134. defined(CONFIG_LWMON) || \
  135. defined(CONFIG_MHPC) || \
  136. defined(CONFIG_R360MPI) || \
  137. defined(CONFIG_RMU) || \
  138. defined(CONFIG_RPXCLASSIC) || \
  139. defined(CONFIG_RPXLITE) || \
  140. defined(CONFIG_SPC1920) || \
  141. defined(CONFIG_SPD823TS)
  142. memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
  143. #endif
  144. #if defined(CONFIG_SYS_OR0_REMAP)
  145. memctl->memc_or0 = CONFIG_SYS_OR0_REMAP;
  146. #endif
  147. #if defined(CONFIG_SYS_OR1_REMAP)
  148. memctl->memc_or1 = CONFIG_SYS_OR1_REMAP;
  149. #endif
  150. #if defined(CONFIG_SYS_OR5_REMAP)
  151. memctl->memc_or5 = CONFIG_SYS_OR5_REMAP;
  152. #endif
  153. /* now restrict to preliminary range */
  154. memctl->memc_br0 = CONFIG_SYS_BR0_PRELIM;
  155. memctl->memc_or0 = CONFIG_SYS_OR0_PRELIM;
  156. #if (defined(CONFIG_SYS_OR1_PRELIM) && defined(CONFIG_SYS_BR1_PRELIM))
  157. memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
  158. memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
  159. #endif
  160. #if defined(CONFIG_IP860) /* disable CS0 now that Flash is mapped on CS1 */
  161. memctl->memc_br0 = 0;
  162. #endif
  163. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  164. memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
  165. memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
  166. #endif
  167. #if defined(CONFIG_SYS_OR3_PRELIM) && defined(CONFIG_SYS_BR3_PRELIM)
  168. memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
  169. memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
  170. #endif
  171. #if defined(CONFIG_SYS_OR4_PRELIM) && defined(CONFIG_SYS_BR4_PRELIM)
  172. memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM;
  173. memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM;
  174. #endif
  175. #if defined(CONFIG_SYS_OR5_PRELIM) && defined(CONFIG_SYS_BR5_PRELIM)
  176. memctl->memc_or5 = CONFIG_SYS_OR5_PRELIM;
  177. memctl->memc_br5 = CONFIG_SYS_BR5_PRELIM;
  178. #endif
  179. #if defined(CONFIG_SYS_OR6_PRELIM) && defined(CONFIG_SYS_BR6_PRELIM)
  180. memctl->memc_or6 = CONFIG_SYS_OR6_PRELIM;
  181. memctl->memc_br6 = CONFIG_SYS_BR6_PRELIM;
  182. #endif
  183. #if defined(CONFIG_SYS_OR7_PRELIM) && defined(CONFIG_SYS_BR7_PRELIM)
  184. memctl->memc_or7 = CONFIG_SYS_OR7_PRELIM;
  185. memctl->memc_br7 = CONFIG_SYS_BR7_PRELIM;
  186. #endif
  187. #endif /* ! CONFIG_MBX */
  188. /*
  189. * Reset CPM
  190. */
  191. immr->im_cpm.cp_cpcr = CPM_CR_RST | CPM_CR_FLG;
  192. do { /* Spin until command processed */
  193. __asm__ ("eieio");
  194. } while (immr->im_cpm.cp_cpcr & CPM_CR_FLG);
  195. #ifdef CONFIG_MBX
  196. /*
  197. * on the MBX, things are a little bit different:
  198. * - we need to read the VPD to get board information
  199. * - the plprcr is set up dynamically
  200. * - the memory controller is set up dynamically
  201. */
  202. mbx_init ();
  203. #endif /* CONFIG_MBX */
  204. #ifdef CONFIG_RPXCLASSIC
  205. rpxclassic_init ();
  206. #endif
  207. #if defined(CONFIG_RPXLITE) && defined(CONFIG_ENV_IS_IN_NVRAM)
  208. rpxlite_init ();
  209. #endif
  210. #ifdef CONFIG_SYS_RCCR /* must be done before cpm_load_patch() */
  211. /* write config value */
  212. immr->im_cpm.cp_rccr = CONFIG_SYS_RCCR;
  213. #endif
  214. #if defined(CONFIG_SYS_I2C_UCODE_PATCH) || defined(CONFIG_SYS_SPI_UCODE_PATCH) || \
  215. defined(CONFIG_SYS_SMC_UCODE_PATCH)
  216. cpm_load_patch (immr); /* load mpc8xx microcode patch */
  217. #endif
  218. }
  219. /*
  220. * initialize higher level parts of CPU like timers
  221. */
  222. int cpu_init_r (void)
  223. {
  224. #if defined(CONFIG_SYS_RTCSC) || defined(CONFIG_SYS_RMDS)
  225. bd_t *bd = gd->bd;
  226. volatile immap_t *immr = (volatile immap_t *) (bd->bi_immr_base);
  227. #endif
  228. #ifdef CONFIG_SYS_RTCSC
  229. /* Unlock RTSC register */
  230. immr->im_sitk.sitk_rtcsck = KAPWR_KEY;
  231. /* write config value */
  232. immr->im_sit.sit_rtcsc = CONFIG_SYS_RTCSC;
  233. #endif
  234. #ifdef CONFIG_SYS_RMDS
  235. /* write config value */
  236. immr->im_cpm.cp_rmds = CONFIG_SYS_RMDS;
  237. #endif
  238. return (0);
  239. }