cpu_init.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 <mpc8260.h>
  25. #include <asm/cpm_8260.h>
  26. #include <ioports.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  29. extern unsigned long board_get_cpu_clk_f (void);
  30. #endif
  31. static void config_8260_ioports (volatile immap_t * immr)
  32. {
  33. int portnum;
  34. for (portnum = 0; portnum < 4; portnum++) {
  35. uint pmsk = 0,
  36. ppar = 0,
  37. psor = 0,
  38. pdir = 0,
  39. podr = 0,
  40. pdat = 0;
  41. iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
  42. iop_conf_t *eiopc = iopc + 32;
  43. uint msk = 1;
  44. /*
  45. * NOTE:
  46. * index 0 refers to pin 31,
  47. * index 31 refers to pin 0
  48. */
  49. while (iopc < eiopc) {
  50. if (iopc->conf) {
  51. pmsk |= msk;
  52. if (iopc->ppar)
  53. ppar |= msk;
  54. if (iopc->psor)
  55. psor |= msk;
  56. if (iopc->pdir)
  57. pdir |= msk;
  58. if (iopc->podr)
  59. podr |= msk;
  60. if (iopc->pdat)
  61. pdat |= msk;
  62. }
  63. msk <<= 1;
  64. iopc++;
  65. }
  66. if (pmsk != 0) {
  67. volatile ioport_t *iop = ioport_addr (immr, portnum);
  68. uint tpmsk = ~pmsk;
  69. /*
  70. * the (somewhat confused) paragraph at the
  71. * bottom of page 35-5 warns that there might
  72. * be "unknown behaviour" when programming
  73. * PSORx and PDIRx, if PPARx = 1, so I
  74. * decided this meant I had to disable the
  75. * dedicated function first, and enable it
  76. * last.
  77. */
  78. iop->ppar &= tpmsk;
  79. iop->psor = (iop->psor & tpmsk) | psor;
  80. iop->podr = (iop->podr & tpmsk) | podr;
  81. iop->pdat = (iop->pdat & tpmsk) | pdat;
  82. iop->pdir = (iop->pdir & tpmsk) | pdir;
  83. iop->ppar |= ppar;
  84. }
  85. }
  86. }
  87. #define SET_VAL_MASK(a, b, mask) ((a & mask) | (b & ~mask))
  88. /*
  89. * Breath some life into the CPU...
  90. *
  91. * Set up the memory map,
  92. * initialize a bunch of registers,
  93. * initialize the UPM's
  94. */
  95. void cpu_init_f (volatile immap_t * immr)
  96. {
  97. #if !defined(CONFIG_COGENT) /* done in start.S for the cogent */
  98. uint sccr;
  99. #endif
  100. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  101. unsigned long cpu_clk;
  102. #endif
  103. volatile memctl8260_t *memctl = &immr->im_memctl;
  104. extern void m8260_cpm_reset (void);
  105. /* Pointer is writable since we allocated a register for it */
  106. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  107. /* Clear initial global data */
  108. memset ((void *) gd, 0, sizeof (gd_t));
  109. /* RSR - Reset Status Register - clear all status (5-4) */
  110. gd->reset_status = immr->im_clkrst.car_rsr;
  111. immr->im_clkrst.car_rsr = RSR_ALLBITS;
  112. /* RMR - Reset Mode Register - contains checkstop reset enable (5-5) */
  113. immr->im_clkrst.car_rmr = CFG_RMR;
  114. /* BCR - Bus Configuration Register (4-25) */
  115. #if defined(CFG_BCR_60x) && (CFG_BCR_SINGLE)
  116. if (immr->im_siu_conf.sc_bcr & BCR_EBM) {
  117. immr->im_siu_conf.sc_bcr = SET_VAL_MASK(immr->im_siu_conf.sc_bcr, CFG_BCR_60x, 0x80000010);
  118. } else {
  119. immr->im_siu_conf.sc_bcr = SET_VAL_MASK(immr->im_siu_conf.sc_bcr, CFG_BCR_SINGLE, 0x80000010);
  120. }
  121. #else
  122. immr->im_siu_conf.sc_bcr = CFG_BCR;
  123. #endif
  124. /* SIUMCR - contains debug pin configuration (4-31) */
  125. #if defined(CFG_SIUMCR_LOW) && (CFG_SIUMCR_HIGH)
  126. cpu_clk = board_get_cpu_clk_f ();
  127. if (cpu_clk >= 100000000) {
  128. immr->im_siu_conf.sc_siumcr = SET_VAL_MASK(immr->im_siu_conf.sc_siumcr, CFG_SIUMCR_HIGH, 0x9f3cc000);
  129. } else {
  130. immr->im_siu_conf.sc_siumcr = SET_VAL_MASK(immr->im_siu_conf.sc_siumcr, CFG_SIUMCR_LOW, 0x9f3cc000);
  131. }
  132. #else
  133. immr->im_siu_conf.sc_siumcr = CFG_SIUMCR;
  134. #endif
  135. config_8260_ioports (immr);
  136. /* initialize time counter status and control register (4-40) */
  137. immr->im_sit.sit_tmcntsc = CFG_TMCNTSC;
  138. /* initialize the PIT (4-42) */
  139. immr->im_sit.sit_piscr = CFG_PISCR;
  140. #if !defined(CONFIG_COGENT) /* done in start.S for the cogent */
  141. /* System clock control register (9-8) */
  142. sccr = immr->im_clkrst.car_sccr &
  143. (SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK);
  144. immr->im_clkrst.car_sccr = sccr |
  145. (CFG_SCCR & ~(SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK) );
  146. #endif /* !CONFIG_COGENT */
  147. /*
  148. * Memory Controller:
  149. */
  150. /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
  151. * addresses - these have to be modified later when FLASH size
  152. * has been determined
  153. */
  154. #if defined(CFG_OR0_REMAP)
  155. memctl->memc_or0 = CFG_OR0_REMAP;
  156. #endif
  157. #if defined(CFG_OR1_REMAP)
  158. memctl->memc_or1 = CFG_OR1_REMAP;
  159. #endif
  160. /* now restrict to preliminary range */
  161. /* the PS came from the HRCW, don´t change it */
  162. memctl->memc_br0 = SET_VAL_MASK(memctl->memc_br0 , CFG_BR0_PRELIM, BRx_PS_MSK);
  163. memctl->memc_or0 = CFG_OR0_PRELIM;
  164. #if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
  165. memctl->memc_or1 = CFG_OR1_PRELIM;
  166. memctl->memc_br1 = CFG_BR1_PRELIM;
  167. #endif
  168. #if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
  169. memctl->memc_or2 = CFG_OR2_PRELIM;
  170. memctl->memc_br2 = CFG_BR2_PRELIM;
  171. #endif
  172. #if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
  173. memctl->memc_or3 = CFG_OR3_PRELIM;
  174. memctl->memc_br3 = CFG_BR3_PRELIM;
  175. #endif
  176. #if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
  177. memctl->memc_or4 = CFG_OR4_PRELIM;
  178. memctl->memc_br4 = CFG_BR4_PRELIM;
  179. #endif
  180. #if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
  181. memctl->memc_or5 = CFG_OR5_PRELIM;
  182. memctl->memc_br5 = CFG_BR5_PRELIM;
  183. #endif
  184. #if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
  185. memctl->memc_or6 = CFG_OR6_PRELIM;
  186. memctl->memc_br6 = CFG_BR6_PRELIM;
  187. #endif
  188. #if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
  189. memctl->memc_or7 = CFG_OR7_PRELIM;
  190. memctl->memc_br7 = CFG_BR7_PRELIM;
  191. #endif
  192. #if defined(CFG_BR8_PRELIM) && defined(CFG_OR8_PRELIM)
  193. memctl->memc_or8 = CFG_OR8_PRELIM;
  194. memctl->memc_br8 = CFG_BR8_PRELIM;
  195. #endif
  196. #if defined(CFG_BR9_PRELIM) && defined(CFG_OR9_PRELIM)
  197. memctl->memc_or9 = CFG_OR9_PRELIM;
  198. memctl->memc_br9 = CFG_BR9_PRELIM;
  199. #endif
  200. #if defined(CFG_BR10_PRELIM) && defined(CFG_OR10_PRELIM)
  201. memctl->memc_or10 = CFG_OR10_PRELIM;
  202. memctl->memc_br10 = CFG_BR10_PRELIM;
  203. #endif
  204. #if defined(CFG_BR11_PRELIM) && defined(CFG_OR11_PRELIM)
  205. memctl->memc_or11 = CFG_OR11_PRELIM;
  206. memctl->memc_br11 = CFG_BR11_PRELIM;
  207. #endif
  208. m8260_cpm_reset ();
  209. }
  210. /*
  211. * initialize higher level parts of CPU like time base and timers
  212. */
  213. int cpu_init_r (void)
  214. {
  215. volatile immap_t *immr = (immap_t *) gd->bd->bi_immr_base;
  216. immr->im_cpm.cp_rccr = CFG_RCCR;
  217. return (0);
  218. }
  219. /*
  220. * print out the reason for the reset
  221. */
  222. int prt_8260_rsr (void)
  223. {
  224. static struct {
  225. ulong mask;
  226. char *desc;
  227. } bits[] = {
  228. {
  229. RSR_JTRS, "JTAG"}, {
  230. RSR_CSRS, "Check Stop"}, {
  231. RSR_SWRS, "Software Watchdog"}, {
  232. RSR_BMRS, "Bus Monitor"}, {
  233. RSR_ESRS, "External Soft"}, {
  234. RSR_EHRS, "External Hard"}
  235. };
  236. static int n = sizeof bits / sizeof bits[0];
  237. ulong rsr = gd->reset_status;
  238. int i;
  239. char *sep;
  240. puts (CPU_ID_STR " Reset Status:");
  241. sep = " ";
  242. for (i = 0; i < n; i++)
  243. if (rsr & bits[i].mask) {
  244. printf ("%s%s", sep, bits[i].desc);
  245. sep = ", ";
  246. }
  247. puts ("\n\n");
  248. return (0);
  249. }