cpu_init.c 6.5 KB

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