cpu_init.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. #include <asm/mmu.h>
  34. #include <asm/fsl_law.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #ifdef CONFIG_QE
  37. extern qe_iop_conf_t qe_iop_conf_tab[];
  38. extern void qe_config_iopin(u8 port, u8 pin, int dir,
  39. int open_drain, int assign);
  40. extern void qe_init(uint qe_base);
  41. extern void qe_reset(void);
  42. static void config_qe_ioports(void)
  43. {
  44. u8 port, pin;
  45. int dir, open_drain, assign;
  46. int i;
  47. for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
  48. port = qe_iop_conf_tab[i].port;
  49. pin = qe_iop_conf_tab[i].pin;
  50. dir = qe_iop_conf_tab[i].dir;
  51. open_drain = qe_iop_conf_tab[i].open_drain;
  52. assign = qe_iop_conf_tab[i].assign;
  53. qe_config_iopin(port, pin, dir, open_drain, assign);
  54. }
  55. }
  56. #endif
  57. #ifdef CONFIG_CPM2
  58. void config_8560_ioports (volatile ccsr_cpm_t * cpm)
  59. {
  60. int portnum;
  61. for (portnum = 0; portnum < 4; portnum++) {
  62. uint pmsk = 0,
  63. ppar = 0,
  64. psor = 0,
  65. pdir = 0,
  66. podr = 0,
  67. pdat = 0;
  68. iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
  69. iop_conf_t *eiopc = iopc + 32;
  70. uint msk = 1;
  71. /*
  72. * NOTE:
  73. * index 0 refers to pin 31,
  74. * index 31 refers to pin 0
  75. */
  76. while (iopc < eiopc) {
  77. if (iopc->conf) {
  78. pmsk |= msk;
  79. if (iopc->ppar)
  80. ppar |= msk;
  81. if (iopc->psor)
  82. psor |= msk;
  83. if (iopc->pdir)
  84. pdir |= msk;
  85. if (iopc->podr)
  86. podr |= msk;
  87. if (iopc->pdat)
  88. pdat |= msk;
  89. }
  90. msk <<= 1;
  91. iopc++;
  92. }
  93. if (pmsk != 0) {
  94. volatile ioport_t *iop = ioport_addr (cpm, portnum);
  95. uint tpmsk = ~pmsk;
  96. /*
  97. * the (somewhat confused) paragraph at the
  98. * bottom of page 35-5 warns that there might
  99. * be "unknown behaviour" when programming
  100. * PSORx and PDIRx, if PPARx = 1, so I
  101. * decided this meant I had to disable the
  102. * dedicated function first, and enable it
  103. * last.
  104. */
  105. iop->ppar &= tpmsk;
  106. iop->psor = (iop->psor & tpmsk) | psor;
  107. iop->podr = (iop->podr & tpmsk) | podr;
  108. iop->pdat = (iop->pdat & tpmsk) | pdat;
  109. iop->pdir = (iop->pdir & tpmsk) | pdir;
  110. iop->ppar |= ppar;
  111. }
  112. }
  113. }
  114. #endif
  115. /* We run cpu_init_early_f in AS = 1 */
  116. void cpu_init_early_f(void)
  117. {
  118. set_tlb(0, CFG_CCSRBAR, CFG_CCSRBAR,
  119. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  120. 1, 0, BOOKE_PAGESZ_4K, 0);
  121. /* set up CCSR if we want it moved */
  122. #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
  123. {
  124. u32 temp;
  125. set_tlb(0, CFG_CCSRBAR_DEFAULT, CFG_CCSRBAR_DEFAULT,
  126. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  127. 1, 1, BOOKE_PAGESZ_4K, 0);
  128. temp = in_be32((volatile u32 *)CFG_CCSRBAR_DEFAULT);
  129. out_be32((volatile u32 *)CFG_CCSRBAR_DEFAULT, CFG_CCSRBAR >> 12);
  130. temp = in_be32((volatile u32 *)CFG_CCSRBAR);
  131. }
  132. #endif
  133. init_laws();
  134. invalidate_tlb(0);
  135. init_tlbs();
  136. }
  137. /*
  138. * Breathe some life into the CPU...
  139. *
  140. * Set up the memory map
  141. * initialize a bunch of registers
  142. */
  143. void cpu_init_f (void)
  144. {
  145. volatile ccsr_lbc_t *memctl = (void *)(CFG_MPC85xx_LBC_ADDR);
  146. extern void m8560_cpm_reset (void);
  147. disable_tlb(14);
  148. disable_tlb(15);
  149. /* Pointer is writable since we allocated a register for it */
  150. gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
  151. /* Clear initial global data */
  152. memset ((void *) gd, 0, sizeof (gd_t));
  153. #ifdef CONFIG_CPM2
  154. config_8560_ioports((ccsr_cpm_t *)CFG_MPC85xx_CPM_ADDR);
  155. #endif
  156. /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
  157. * addresses - these have to be modified later when FLASH size
  158. * has been determined
  159. */
  160. #if defined(CFG_OR0_REMAP)
  161. memctl->or0 = CFG_OR0_REMAP;
  162. #endif
  163. #if defined(CFG_OR1_REMAP)
  164. memctl->or1 = CFG_OR1_REMAP;
  165. #endif
  166. /* now restrict to preliminary range */
  167. /* if cs1 is already set via debugger, leave cs0/cs1 alone */
  168. if (! memctl->br1 & 1) {
  169. #if defined(CFG_BR0_PRELIM) && defined(CFG_OR0_PRELIM)
  170. memctl->br0 = CFG_BR0_PRELIM;
  171. memctl->or0 = CFG_OR0_PRELIM;
  172. #endif
  173. #if defined(CFG_BR1_PRELIM) && defined(CFG_OR1_PRELIM)
  174. memctl->or1 = CFG_OR1_PRELIM;
  175. memctl->br1 = CFG_BR1_PRELIM;
  176. #endif
  177. }
  178. #if defined(CFG_BR2_PRELIM) && defined(CFG_OR2_PRELIM)
  179. memctl->or2 = CFG_OR2_PRELIM;
  180. memctl->br2 = CFG_BR2_PRELIM;
  181. #endif
  182. #if defined(CFG_BR3_PRELIM) && defined(CFG_OR3_PRELIM)
  183. memctl->or3 = CFG_OR3_PRELIM;
  184. memctl->br3 = CFG_BR3_PRELIM;
  185. #endif
  186. #if defined(CFG_BR4_PRELIM) && defined(CFG_OR4_PRELIM)
  187. memctl->or4 = CFG_OR4_PRELIM;
  188. memctl->br4 = CFG_BR4_PRELIM;
  189. #endif
  190. #if defined(CFG_BR5_PRELIM) && defined(CFG_OR5_PRELIM)
  191. memctl->or5 = CFG_OR5_PRELIM;
  192. memctl->br5 = CFG_BR5_PRELIM;
  193. #endif
  194. #if defined(CFG_BR6_PRELIM) && defined(CFG_OR6_PRELIM)
  195. memctl->or6 = CFG_OR6_PRELIM;
  196. memctl->br6 = CFG_BR6_PRELIM;
  197. #endif
  198. #if defined(CFG_BR7_PRELIM) && defined(CFG_OR7_PRELIM)
  199. memctl->or7 = CFG_OR7_PRELIM;
  200. memctl->br7 = CFG_BR7_PRELIM;
  201. #endif
  202. #if defined(CONFIG_CPM2)
  203. m8560_cpm_reset();
  204. #endif
  205. #ifdef CONFIG_QE
  206. /* Config QE ioports */
  207. config_qe_ioports();
  208. #endif
  209. }
  210. /*
  211. * Initialize L2 as cache.
  212. *
  213. * The newer 8548, etc, parts have twice as much cache, but
  214. * use the same bit-encoding as the older 8555, etc, parts.
  215. *
  216. */
  217. int cpu_init_r(void)
  218. {
  219. #ifdef CONFIG_CLEAR_LAW0
  220. #ifdef CONFIG_FSL_LAW
  221. disable_law(0);
  222. #else
  223. volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
  224. /* clear alternate boot location LAW (used for sdram, or ddr bank) */
  225. ecm->lawar0 = 0;
  226. #endif
  227. #endif
  228. #if defined(CONFIG_L2_CACHE)
  229. volatile ccsr_l2cache_t *l2cache = (void *)CFG_MPC85xx_L2_ADDR;
  230. volatile uint cache_ctl;
  231. uint svr, ver;
  232. uint l2srbar;
  233. svr = get_svr();
  234. ver = SVR_VER(svr);
  235. asm("msync;isync");
  236. cache_ctl = l2cache->l2ctl;
  237. switch (cache_ctl & 0x30000000) {
  238. case 0x20000000:
  239. if (ver == SVR_8548 || ver == SVR_8548_E ||
  240. ver == SVR_8544 || ver == SVR_8568_E) {
  241. printf ("L2 cache 512KB:");
  242. /* set L2E=1, L2I=1, & L2SRAM=0 */
  243. cache_ctl = 0xc0000000;
  244. } else {
  245. printf ("L2 cache 256KB:");
  246. /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */
  247. cache_ctl = 0xc8000000;
  248. }
  249. break;
  250. case 0x10000000:
  251. printf ("L2 cache 256KB:");
  252. if (ver == SVR_8544 || ver == SVR_8544_E) {
  253. cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
  254. }
  255. break;
  256. case 0x30000000:
  257. case 0x00000000:
  258. default:
  259. printf ("L2 cache unknown size (0x%08x)\n", cache_ctl);
  260. return -1;
  261. }
  262. if (l2cache->l2ctl & 0x80000000) {
  263. printf(" already enabled.");
  264. l2srbar = l2cache->l2srbar0;
  265. #ifdef CFG_INIT_L2_ADDR
  266. if (l2cache->l2ctl & 0x00010000 && l2srbar >= CFG_FLASH_BASE) {
  267. l2srbar = CFG_INIT_L2_ADDR;
  268. l2cache->l2srbar0 = l2srbar;
  269. printf(" Moving to 0x%08x", CFG_INIT_L2_ADDR);
  270. }
  271. #endif /* CFG_INIT_L2_ADDR */
  272. puts("\n");
  273. } else {
  274. asm("msync;isync");
  275. l2cache->l2ctl = cache_ctl; /* invalidate & enable */
  276. asm("msync;isync");
  277. printf(" enabled\n");
  278. }
  279. #else
  280. printf("L2 cache: disabled\n");
  281. #endif
  282. #ifdef CONFIG_QE
  283. uint qe_base = CFG_IMMR + 0x00080000; /* QE immr base */
  284. qe_init(qe_base);
  285. qe_reset();
  286. #endif
  287. return 0;
  288. }