cpu_init.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright 2007 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2003 Motorola Inc.
  5. * Modified by Xianghua Xiao, X.Xiao@motorola.com
  6. *
  7. * (C) Copyright 2000
  8. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <watchdog.h>
  30. #include <asm/processor.h>
  31. #include <ioports.h>
  32. #include <asm/io.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. #ifdef CONFIG_CPM2
  35. static void config_8560_ioports (volatile immap_t * immr)
  36. {
  37. int portnum;
  38. for (portnum = 0; portnum < 4; portnum++) {
  39. uint pmsk = 0,
  40. ppar = 0,
  41. psor = 0,
  42. pdir = 0,
  43. podr = 0,
  44. pdat = 0;
  45. iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
  46. iop_conf_t *eiopc = iopc + 32;
  47. uint msk = 1;
  48. /*
  49. * NOTE:
  50. * index 0 refers to pin 31,
  51. * index 31 refers to pin 0
  52. */
  53. while (iopc < eiopc) {
  54. if (iopc->conf) {
  55. pmsk |= msk;
  56. if (iopc->ppar)
  57. ppar |= msk;
  58. if (iopc->psor)
  59. psor |= msk;
  60. if (iopc->pdir)
  61. pdir |= msk;
  62. if (iopc->podr)
  63. podr |= msk;
  64. if (iopc->pdat)
  65. pdat |= msk;
  66. }
  67. msk <<= 1;
  68. iopc++;
  69. }
  70. if (pmsk != 0) {
  71. volatile ioport_t *iop = ioport_addr (immr, portnum);
  72. uint tpmsk = ~pmsk;
  73. /*
  74. * the (somewhat confused) paragraph at the
  75. * bottom of page 35-5 warns that there might
  76. * be "unknown behaviour" when programming
  77. * PSORx and PDIRx, if PPARx = 1, so I
  78. * decided this meant I had to disable the
  79. * dedicated function first, and enable it
  80. * last.
  81. */
  82. iop->ppar &= tpmsk;
  83. iop->psor = (iop->psor & tpmsk) | psor;
  84. iop->podr = (iop->podr & tpmsk) | podr;
  85. iop->pdat = (iop->pdat & tpmsk) | pdat;
  86. iop->pdir = (iop->pdir & tpmsk) | pdir;
  87. iop->ppar |= ppar;
  88. }
  89. }
  90. }
  91. #endif
  92. /*
  93. * Breathe some life into the CPU...
  94. *
  95. * Set up the memory map
  96. * initialize a bunch of registers
  97. */
  98. void cpu_init_f (void)
  99. {
  100. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  101. volatile ccsr_lbc_t *memctl = &immap->im_lbc;
  102. extern void m8560_cpm_reset (void);
  103. /* Pointer is writable since we allocated a register for it */
  104. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  105. /* Clear initial global data */
  106. memset ((void *) gd, 0, sizeof (gd_t));
  107. #ifdef CONFIG_CPM2
  108. config_8560_ioports(immap);
  109. #endif
  110. /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
  111. * addresses - these have to be modified later when FLASH size
  112. * has been determined
  113. */
  114. #if defined(CFG_OR0_REMAP)
  115. memctl->or0 = CFG_OR0_REMAP;
  116. #endif
  117. #if defined(CFG_OR1_REMAP)
  118. memctl->or1 = CFG_OR1_REMAP;
  119. #endif
  120. /* now restrict to preliminary range */
  121. /* if cs1 is already set via debugger, leave cs0/cs1 alone */
  122. if (! memctl->br1 & 1) {
  123. #if defined(CFG_BR0_PRELIM) && defined(CFG_OR0_PRELIM)
  124. memctl->br0 = CFG_BR0_PRELIM;
  125. memctl->or0 = CFG_OR0_PRELIM;
  126. #endif
  127. #if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
  128. memctl->or1 = CFG_OR1_PRELIM;
  129. memctl->br1 = CFG_BR1_PRELIM;
  130. #endif
  131. }
  132. #if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
  133. memctl->or2 = CFG_OR2_PRELIM;
  134. memctl->br2 = CFG_BR2_PRELIM;
  135. #endif
  136. #if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
  137. memctl->or3 = CFG_OR3_PRELIM;
  138. memctl->br3 = CFG_BR3_PRELIM;
  139. #endif
  140. #if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
  141. memctl->or4 = CFG_OR4_PRELIM;
  142. memctl->br4 = CFG_BR4_PRELIM;
  143. #endif
  144. #if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
  145. memctl->or5 = CFG_OR5_PRELIM;
  146. memctl->br5 = CFG_BR5_PRELIM;
  147. #endif
  148. #if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
  149. memctl->or6 = CFG_OR6_PRELIM;
  150. memctl->br6 = CFG_BR6_PRELIM;
  151. #endif
  152. #if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
  153. memctl->or7 = CFG_OR7_PRELIM;
  154. memctl->br7 = CFG_BR7_PRELIM;
  155. #endif
  156. #if defined(CONFIG_CPM2)
  157. m8560_cpm_reset();
  158. #endif
  159. }
  160. /*
  161. * Initialize L2 as cache.
  162. *
  163. * The newer 8548, etc, parts have twice as much cache, but
  164. * use the same bit-encoding as the older 8555, etc, parts.
  165. *
  166. */
  167. int cpu_init_r(void)
  168. {
  169. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  170. volatile ccsr_local_ecm_t *ecm = &immap->im_local_ecm;
  171. #ifdef CONFIG_CLEAR_LAW0
  172. /* clear alternate boot location LAW (used for sdram, or ddr bank) */
  173. ecm->lawar0 = 0;
  174. #endif
  175. #if defined(CONFIG_L2_CACHE)
  176. volatile ccsr_l2cache_t *l2cache = &immap->im_l2cache;
  177. volatile uint cache_ctl;
  178. uint svr, ver;
  179. uint l2srbar;
  180. svr = get_svr();
  181. ver = SVR_VER(svr);
  182. asm("msync;isync");
  183. cache_ctl = l2cache->l2ctl;
  184. switch (cache_ctl & 0x30000000) {
  185. case 0x20000000:
  186. if (ver == SVR_8548 || ver == SVR_8548_E ||
  187. ver == SVR_8544) {
  188. printf ("L2 cache 512KB:");
  189. /* set L2E=1, L2I=1, & L2SRAM=0 */
  190. cache_ctl = 0xc0000000;
  191. } else {
  192. printf ("L2 cache 256KB:");
  193. /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */
  194. cache_ctl = 0xc8000000;
  195. }
  196. break;
  197. case 0x10000000:
  198. printf ("L2 cache 256KB:");
  199. if (ver == SVR_8544 || ver == SVR_8544_E) {
  200. cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
  201. }
  202. break;
  203. case 0x30000000:
  204. case 0x00000000:
  205. default:
  206. printf ("L2 cache unknown size (0x%08x)\n", cache_ctl);
  207. return -1;
  208. }
  209. if (l2cache->l2ctl & 0x80000000) {
  210. printf(" already enabled.");
  211. l2srbar = l2cache->l2srbar0;
  212. #ifdef CFG_INIT_L2_ADDR
  213. if (l2cache->l2ctl & 0x00010000 && l2srbar >= CFG_FLASH_BASE) {
  214. l2srbar = CFG_INIT_L2_ADDR;
  215. l2cache->l2srbar0 = l2srbar;
  216. printf(" Moving to 0x%08x", CFG_INIT_L2_ADDR);
  217. }
  218. #endif /* CFG_INIT_L2_ADDR */
  219. puts("\n");
  220. } else {
  221. asm("msync;isync");
  222. l2cache->l2ctl = cache_ctl; /* invalidate & enable */
  223. asm("msync;isync");
  224. printf(" enabled\n");
  225. }
  226. #else
  227. printf("L2 cache: disabled\n");
  228. #endif
  229. return 0;
  230. }