cpu_init.c 6.5 KB

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