cpu_init.c 7.8 KB

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