cpu_init.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * Copyright 2007-2011 Freescale Semiconductor, Inc.
  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 <sata.h>
  33. #include <fm_eth.h>
  34. #include <asm/io.h>
  35. #include <asm/cache.h>
  36. #include <asm/mmu.h>
  37. #include <asm/fsl_law.h>
  38. #include <asm/fsl_serdes.h>
  39. #include "mp.h"
  40. #ifdef CONFIG_SYS_QE_FW_IN_NAND
  41. #include <nand.h>
  42. #include <errno.h>
  43. #endif
  44. DECLARE_GLOBAL_DATA_PTR;
  45. extern void srio_init(void);
  46. #ifdef CONFIG_QE
  47. extern qe_iop_conf_t qe_iop_conf_tab[];
  48. extern void qe_config_iopin(u8 port, u8 pin, int dir,
  49. int open_drain, int assign);
  50. extern void qe_init(uint qe_base);
  51. extern void qe_reset(void);
  52. static void config_qe_ioports(void)
  53. {
  54. u8 port, pin;
  55. int dir, open_drain, assign;
  56. int i;
  57. for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
  58. port = qe_iop_conf_tab[i].port;
  59. pin = qe_iop_conf_tab[i].pin;
  60. dir = qe_iop_conf_tab[i].dir;
  61. open_drain = qe_iop_conf_tab[i].open_drain;
  62. assign = qe_iop_conf_tab[i].assign;
  63. qe_config_iopin(port, pin, dir, open_drain, assign);
  64. }
  65. }
  66. #endif
  67. #ifdef CONFIG_CPM2
  68. void config_8560_ioports (volatile ccsr_cpm_t * cpm)
  69. {
  70. int portnum;
  71. for (portnum = 0; portnum < 4; portnum++) {
  72. uint pmsk = 0,
  73. ppar = 0,
  74. psor = 0,
  75. pdir = 0,
  76. podr = 0,
  77. pdat = 0;
  78. iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
  79. iop_conf_t *eiopc = iopc + 32;
  80. uint msk = 1;
  81. /*
  82. * NOTE:
  83. * index 0 refers to pin 31,
  84. * index 31 refers to pin 0
  85. */
  86. while (iopc < eiopc) {
  87. if (iopc->conf) {
  88. pmsk |= msk;
  89. if (iopc->ppar)
  90. ppar |= msk;
  91. if (iopc->psor)
  92. psor |= msk;
  93. if (iopc->pdir)
  94. pdir |= msk;
  95. if (iopc->podr)
  96. podr |= msk;
  97. if (iopc->pdat)
  98. pdat |= msk;
  99. }
  100. msk <<= 1;
  101. iopc++;
  102. }
  103. if (pmsk != 0) {
  104. volatile ioport_t *iop = ioport_addr (cpm, portnum);
  105. uint tpmsk = ~pmsk;
  106. /*
  107. * the (somewhat confused) paragraph at the
  108. * bottom of page 35-5 warns that there might
  109. * be "unknown behaviour" when programming
  110. * PSORx and PDIRx, if PPARx = 1, so I
  111. * decided this meant I had to disable the
  112. * dedicated function first, and enable it
  113. * last.
  114. */
  115. iop->ppar &= tpmsk;
  116. iop->psor = (iop->psor & tpmsk) | psor;
  117. iop->podr = (iop->podr & tpmsk) | podr;
  118. iop->pdat = (iop->pdat & tpmsk) | pdat;
  119. iop->pdir = (iop->pdir & tpmsk) | pdir;
  120. iop->ppar |= ppar;
  121. }
  122. }
  123. }
  124. #endif
  125. #ifdef CONFIG_SYS_FSL_CPC
  126. static void enable_cpc(void)
  127. {
  128. int i;
  129. u32 size = 0;
  130. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  131. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  132. u32 cpccfg0 = in_be32(&cpc->cpccfg0);
  133. size += CPC_CFG0_SZ_K(cpccfg0);
  134. #ifdef CONFIG_RAMBOOT_PBL
  135. if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) {
  136. /* find and disable LAW of SRAM */
  137. struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR);
  138. if (law.index == -1) {
  139. printf("\nFatal error happened\n");
  140. return;
  141. }
  142. disable_law(law.index);
  143. clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS);
  144. out_be32(&cpc->cpccsr0, 0);
  145. out_be32(&cpc->cpcsrcr0, 0);
  146. }
  147. #endif
  148. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
  149. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
  150. #endif
  151. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
  152. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
  153. #endif
  154. out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
  155. /* Read back to sync write */
  156. in_be32(&cpc->cpccsr0);
  157. }
  158. printf("Corenet Platform Cache: %d KB enabled\n", size);
  159. }
  160. void invalidate_cpc(void)
  161. {
  162. int i;
  163. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  164. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  165. /* skip CPC when it used as all SRAM */
  166. if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
  167. continue;
  168. /* Flash invalidate the CPC and clear all the locks */
  169. out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
  170. while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
  171. ;
  172. }
  173. }
  174. #else
  175. #define enable_cpc()
  176. #define invalidate_cpc()
  177. #endif /* CONFIG_SYS_FSL_CPC */
  178. /*
  179. * Breathe some life into the CPU...
  180. *
  181. * Set up the memory map
  182. * initialize a bunch of registers
  183. */
  184. #ifdef CONFIG_FSL_CORENET
  185. static void corenet_tb_init(void)
  186. {
  187. volatile ccsr_rcpm_t *rcpm =
  188. (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  189. volatile ccsr_pic_t *pic =
  190. (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  191. u32 whoami = in_be32(&pic->whoami);
  192. /* Enable the timebase register for this core */
  193. out_be32(&rcpm->ctbenrl, (1 << whoami));
  194. }
  195. #endif
  196. void cpu_init_f (void)
  197. {
  198. extern void m8560_cpm_reset (void);
  199. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  200. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  201. #endif
  202. #if defined(CONFIG_SECURE_BOOT)
  203. struct law_entry law;
  204. #endif
  205. #ifdef CONFIG_MPC8548
  206. ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  207. uint svr = get_svr();
  208. /*
  209. * CPU2 errata workaround: A core hang possible while executing
  210. * a msync instruction and a snoopable transaction from an I/O
  211. * master tagged to make quick forward progress is present.
  212. * Fixed in silicon rev 2.1.
  213. */
  214. if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
  215. out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
  216. #endif
  217. disable_tlb(14);
  218. disable_tlb(15);
  219. #if defined(CONFIG_SECURE_BOOT)
  220. /* Disable the LAW created for NOR flash by the PBI commands */
  221. law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
  222. if (law.index != -1)
  223. disable_law(law.index);
  224. #endif
  225. #ifdef CONFIG_CPM2
  226. config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
  227. #endif
  228. init_early_memctl_regs();
  229. #if defined(CONFIG_CPM2)
  230. m8560_cpm_reset();
  231. #endif
  232. #ifdef CONFIG_QE
  233. /* Config QE ioports */
  234. config_qe_ioports();
  235. #endif
  236. #if defined(CONFIG_FSL_DMA)
  237. dma_init();
  238. #endif
  239. #ifdef CONFIG_FSL_CORENET
  240. corenet_tb_init();
  241. #endif
  242. init_used_tlb_cams();
  243. /* Invalidate the CPC before DDR gets enabled */
  244. invalidate_cpc();
  245. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  246. /* set DCSRCR so that DCSR space is 1G */
  247. setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
  248. in_be32(&gur->dcsrcr);
  249. #endif
  250. }
  251. /* Implement a dummy function for those platforms w/o SERDES */
  252. static void __fsl_serdes__init(void)
  253. {
  254. return ;
  255. }
  256. __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
  257. /*
  258. * Initialize L2 as cache.
  259. *
  260. * The newer 8548, etc, parts have twice as much cache, but
  261. * use the same bit-encoding as the older 8555, etc, parts.
  262. *
  263. */
  264. int cpu_init_r(void)
  265. {
  266. #ifdef CONFIG_SYS_LBC_LCRR
  267. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  268. #endif
  269. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22)
  270. flush_dcache();
  271. mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
  272. sync();
  273. #endif
  274. puts ("L2: ");
  275. #if defined(CONFIG_L2_CACHE)
  276. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  277. volatile uint cache_ctl;
  278. uint svr, ver;
  279. u32 l2siz_field;
  280. svr = get_svr();
  281. ver = SVR_SOC_VER(svr);
  282. asm("msync;isync");
  283. cache_ctl = l2cache->l2ctl;
  284. #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
  285. if (cache_ctl & MPC85xx_L2CTL_L2E) {
  286. /* Clear L2 SRAM memory-mapped base address */
  287. out_be32(&l2cache->l2srbar0, 0x0);
  288. out_be32(&l2cache->l2srbar1, 0x0);
  289. /* set MBECCDIS=0, SBECCDIS=0 */
  290. clrbits_be32(&l2cache->l2errdis,
  291. (MPC85xx_L2ERRDIS_MBECC |
  292. MPC85xx_L2ERRDIS_SBECC));
  293. /* set L2E=0, L2SRAM=0 */
  294. clrbits_be32(&l2cache->l2ctl,
  295. (MPC85xx_L2CTL_L2E |
  296. MPC85xx_L2CTL_L2SRAM_ENTIRE));
  297. }
  298. #endif
  299. l2siz_field = (cache_ctl >> 28) & 0x3;
  300. switch (l2siz_field) {
  301. case 0x0:
  302. printf(" unknown size (0x%08x)\n", cache_ctl);
  303. return -1;
  304. break;
  305. case 0x1:
  306. if (ver == SVR_8540 || ver == SVR_8560 ||
  307. ver == SVR_8541 || ver == SVR_8541_E ||
  308. ver == SVR_8555 || ver == SVR_8555_E) {
  309. puts("128 KB ");
  310. /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 Kbyte) */
  311. cache_ctl = 0xc4000000;
  312. } else {
  313. puts("256 KB ");
  314. cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
  315. }
  316. break;
  317. case 0x2:
  318. if (ver == SVR_8540 || ver == SVR_8560 ||
  319. ver == SVR_8541 || ver == SVR_8541_E ||
  320. ver == SVR_8555 || ver == SVR_8555_E) {
  321. puts("256 KB ");
  322. /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 Kbyte) */
  323. cache_ctl = 0xc8000000;
  324. } else {
  325. puts ("512 KB ");
  326. /* set L2E=1, L2I=1, & L2SRAM=0 */
  327. cache_ctl = 0xc0000000;
  328. }
  329. break;
  330. case 0x3:
  331. puts("1024 KB ");
  332. /* set L2E=1, L2I=1, & L2SRAM=0 */
  333. cache_ctl = 0xc0000000;
  334. break;
  335. }
  336. if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
  337. puts("already enabled");
  338. #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
  339. u32 l2srbar = l2cache->l2srbar0;
  340. if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
  341. && l2srbar >= CONFIG_SYS_FLASH_BASE) {
  342. l2srbar = CONFIG_SYS_INIT_L2_ADDR;
  343. l2cache->l2srbar0 = l2srbar;
  344. printf("moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
  345. }
  346. #endif /* CONFIG_SYS_INIT_L2_ADDR */
  347. puts("\n");
  348. } else {
  349. asm("msync;isync");
  350. l2cache->l2ctl = cache_ctl; /* invalidate & enable */
  351. asm("msync;isync");
  352. puts("enabled\n");
  353. }
  354. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  355. if ((SVR_SOC_VER(get_svr()) == SVR_P2040) ||
  356. (SVR_SOC_VER(get_svr()) == SVR_P2040_E)) {
  357. puts("N/A\n");
  358. goto skip_l2;
  359. }
  360. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  361. /* invalidate the L2 cache */
  362. mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
  363. while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
  364. ;
  365. #ifdef CONFIG_SYS_CACHE_STASHING
  366. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  367. mtspr(SPRN_L2CSR1, (32 + 1));
  368. #endif
  369. /* enable the cache */
  370. mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
  371. if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
  372. while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
  373. ;
  374. printf("%d KB enabled\n", (l2cfg0 & 0x3fff) * 64);
  375. }
  376. skip_l2:
  377. #else
  378. puts("disabled\n");
  379. #endif
  380. enable_cpc();
  381. /* needs to be in ram since code uses global static vars */
  382. fsl_serdes_init();
  383. #ifdef CONFIG_SYS_SRIO
  384. srio_init();
  385. #endif
  386. #if defined(CONFIG_MP)
  387. setup_mp();
  388. #endif
  389. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC136
  390. {
  391. void *p;
  392. p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
  393. setbits_be32(p, 1 << (31 - 14));
  394. }
  395. #endif
  396. #ifdef CONFIG_SYS_LBC_LCRR
  397. /*
  398. * Modify the CLKDIV field of LCRR register to improve the writing
  399. * speed for NOR flash.
  400. */
  401. clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
  402. __raw_readl(&lbc->lcrr);
  403. isync();
  404. #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
  405. udelay(100);
  406. #endif
  407. #endif
  408. #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
  409. {
  410. ccsr_usb_phy_t *usb_phy1 =
  411. (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
  412. out_be32(&usb_phy1->usb_enable_override,
  413. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  414. }
  415. #endif
  416. #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
  417. {
  418. ccsr_usb_phy_t *usb_phy2 =
  419. (void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
  420. out_be32(&usb_phy2->usb_enable_override,
  421. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  422. }
  423. #endif
  424. #ifdef CONFIG_FMAN_ENET
  425. fman_enet_init();
  426. #endif
  427. return 0;
  428. }
  429. extern void setup_ivors(void);
  430. void arch_preboot_os(void)
  431. {
  432. u32 msr;
  433. /*
  434. * We are changing interrupt offsets and are about to boot the OS so
  435. * we need to make sure we disable all async interrupts. EE is already
  436. * disabled by the time we get called.
  437. */
  438. msr = mfmsr();
  439. msr &= ~(MSR_ME|MSR_CE|MSR_DE);
  440. mtmsr(msr);
  441. setup_ivors();
  442. }
  443. #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA)
  444. int sata_initialize(void)
  445. {
  446. if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
  447. return __sata_initialize();
  448. return 1;
  449. }
  450. #endif
  451. void cpu_secondary_init_r(void)
  452. {
  453. #ifdef CONFIG_QE
  454. uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
  455. #ifdef CONFIG_SYS_QE_FW_IN_NAND
  456. int ret;
  457. size_t fw_length = CONFIG_SYS_QE_FW_LENGTH;
  458. /* load QE firmware from NAND flash to DDR first */
  459. ret = nand_read(&nand_info[0], (loff_t)CONFIG_SYS_QE_FW_IN_NAND,
  460. &fw_length, (u_char *)CONFIG_SYS_QE_FW_ADDR);
  461. if (ret && ret == -EUCLEAN) {
  462. printf ("NAND read for QE firmware at offset %x failed %d\n",
  463. CONFIG_SYS_QE_FW_IN_NAND, ret);
  464. }
  465. #endif
  466. qe_init(qe_base);
  467. qe_reset();
  468. #endif
  469. }