PageRenderTime 29ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/powerpc/cpu/mpc85xx/cpu_init.c

https://bitbucket.org/hldspb/uboot-sbc8600
C | 1060 lines | 787 code | 131 blank | 142 comment | 132 complexity | df1c717140b65e7233c0af3a19481931 MD5 | raw file
  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. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <common.h>
  13. #include <watchdog.h>
  14. #include <asm/processor.h>
  15. #include <ioports.h>
  16. #include <sata.h>
  17. #include <fm_eth.h>
  18. #include <asm/io.h>
  19. #include <asm/cache.h>
  20. #include <asm/mmu.h>
  21. #include <fsl_errata.h>
  22. #include <asm/fsl_law.h>
  23. #include <asm/fsl_serdes.h>
  24. #include <asm/fsl_srio.h>
  25. #ifdef CONFIG_FSL_CORENET
  26. #include <asm/fsl_portals.h>
  27. #include <asm/fsl_liodn.h>
  28. #endif
  29. #include <fsl_usb.h>
  30. #include <hwconfig.h>
  31. #include <linux/compiler.h>
  32. #include "mp.h"
  33. #ifdef CONFIG_CHAIN_OF_TRUST
  34. #include <fsl_validate.h>
  35. #endif
  36. #ifdef CONFIG_FSL_CAAM
  37. #include <fsl_sec.h>
  38. #endif
  39. #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_CORENET)
  40. #include <asm/fsl_pamu.h>
  41. #include <fsl_secboot_err.h>
  42. #endif
  43. #ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND
  44. #include <nand.h>
  45. #include <errno.h>
  46. #endif
  47. #ifndef CONFIG_ARCH_QEMU_E500
  48. #include <fsl_ddr.h>
  49. #endif
  50. #include "../../../../drivers/ata/fsl_sata.h"
  51. #ifdef CONFIG_U_QE
  52. #include <fsl_qe.h>
  53. #endif
  54. DECLARE_GLOBAL_DATA_PTR;
  55. #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
  56. /*
  57. * For deriving usb clock from 100MHz sysclk, reference divisor is set
  58. * to a value of 5, which gives an intermediate value 20(100/5). The
  59. * multiplication factor integer is set to 24, which when multiplied to
  60. * above intermediate value provides clock for usb ip.
  61. */
  62. void usb_single_source_clk_configure(struct ccsr_usb_phy *usb_phy)
  63. {
  64. sys_info_t sysinfo;
  65. get_sys_info(&sysinfo);
  66. if (sysinfo.diff_sysclk == 1) {
  67. clrbits_be32(&usb_phy->pllprg[1],
  68. CONFIG_SYS_FSL_USB_PLLPRG2_MFI);
  69. setbits_be32(&usb_phy->pllprg[1],
  70. CONFIG_SYS_FSL_USB_PLLPRG2_REF_DIV_INTERNAL_CLK |
  71. CONFIG_SYS_FSL_USB_PLLPRG2_MFI_INTERNAL_CLK |
  72. CONFIG_SYS_FSL_USB_INTERNAL_SOC_CLK_EN);
  73. }
  74. }
  75. #endif
  76. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  77. void fsl_erratum_a006261_workaround(struct ccsr_usb_phy __iomem *usb_phy)
  78. {
  79. #ifdef CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE
  80. u32 xcvrprg = in_be32(&usb_phy->port1.xcvrprg);
  81. /* Increase Disconnect Threshold by 50mV */
  82. xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
  83. INC_DCNT_THRESHOLD_50MV;
  84. /* Enable programming of USB High speed Disconnect threshold */
  85. xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
  86. out_be32(&usb_phy->port1.xcvrprg, xcvrprg);
  87. xcvrprg = in_be32(&usb_phy->port2.xcvrprg);
  88. /* Increase Disconnect Threshold by 50mV */
  89. xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
  90. INC_DCNT_THRESHOLD_50MV;
  91. /* Enable programming of USB High speed Disconnect threshold */
  92. xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
  93. out_be32(&usb_phy->port2.xcvrprg, xcvrprg);
  94. #else
  95. u32 temp = 0;
  96. u32 status = in_be32(&usb_phy->status1);
  97. u32 squelch_prog_rd_0_2 =
  98. (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_0)
  99. & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
  100. u32 squelch_prog_rd_3_5 =
  101. (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_3)
  102. & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
  103. setbits_be32(&usb_phy->config1,
  104. CONFIG_SYS_FSL_USB_HS_DISCNCT_INC);
  105. setbits_be32(&usb_phy->config2,
  106. CONFIG_SYS_FSL_USB_RX_AUTO_CAL_RD_WR_SEL);
  107. temp = squelch_prog_rd_0_2 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_3;
  108. out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
  109. temp = squelch_prog_rd_3_5 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_0;
  110. out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
  111. #endif
  112. }
  113. #endif
  114. #if defined(CONFIG_QE) && !defined(CONFIG_U_QE)
  115. extern qe_iop_conf_t qe_iop_conf_tab[];
  116. extern void qe_config_iopin(u8 port, u8 pin, int dir,
  117. int open_drain, int assign);
  118. extern void qe_init(uint qe_base);
  119. extern void qe_reset(void);
  120. static void config_qe_ioports(void)
  121. {
  122. u8 port, pin;
  123. int dir, open_drain, assign;
  124. int i;
  125. for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
  126. port = qe_iop_conf_tab[i].port;
  127. pin = qe_iop_conf_tab[i].pin;
  128. dir = qe_iop_conf_tab[i].dir;
  129. open_drain = qe_iop_conf_tab[i].open_drain;
  130. assign = qe_iop_conf_tab[i].assign;
  131. qe_config_iopin(port, pin, dir, open_drain, assign);
  132. }
  133. }
  134. #endif
  135. #ifdef CONFIG_CPM2
  136. void config_8560_ioports (volatile ccsr_cpm_t * cpm)
  137. {
  138. int portnum;
  139. for (portnum = 0; portnum < 4; portnum++) {
  140. uint pmsk = 0,
  141. ppar = 0,
  142. psor = 0,
  143. pdir = 0,
  144. podr = 0,
  145. pdat = 0;
  146. iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
  147. iop_conf_t *eiopc = iopc + 32;
  148. uint msk = 1;
  149. /*
  150. * NOTE:
  151. * index 0 refers to pin 31,
  152. * index 31 refers to pin 0
  153. */
  154. while (iopc < eiopc) {
  155. if (iopc->conf) {
  156. pmsk |= msk;
  157. if (iopc->ppar)
  158. ppar |= msk;
  159. if (iopc->psor)
  160. psor |= msk;
  161. if (iopc->pdir)
  162. pdir |= msk;
  163. if (iopc->podr)
  164. podr |= msk;
  165. if (iopc->pdat)
  166. pdat |= msk;
  167. }
  168. msk <<= 1;
  169. iopc++;
  170. }
  171. if (pmsk != 0) {
  172. volatile ioport_t *iop = ioport_addr (cpm, portnum);
  173. uint tpmsk = ~pmsk;
  174. /*
  175. * the (somewhat confused) paragraph at the
  176. * bottom of page 35-5 warns that there might
  177. * be "unknown behaviour" when programming
  178. * PSORx and PDIRx, if PPARx = 1, so I
  179. * decided this meant I had to disable the
  180. * dedicated function first, and enable it
  181. * last.
  182. */
  183. iop->ppar &= tpmsk;
  184. iop->psor = (iop->psor & tpmsk) | psor;
  185. iop->podr = (iop->podr & tpmsk) | podr;
  186. iop->pdat = (iop->pdat & tpmsk) | pdat;
  187. iop->pdir = (iop->pdir & tpmsk) | pdir;
  188. iop->ppar |= ppar;
  189. }
  190. }
  191. }
  192. #endif
  193. #ifdef CONFIG_SYS_FSL_CPC
  194. #if defined(CONFIG_RAMBOOT_PBL) || defined(CONFIG_SYS_CPC_REINIT_F)
  195. void disable_cpc_sram(void)
  196. {
  197. int i;
  198. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  199. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  200. if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) {
  201. /* find and disable LAW of SRAM */
  202. struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR);
  203. if (law.index == -1) {
  204. printf("\nFatal error happened\n");
  205. return;
  206. }
  207. disable_law(law.index);
  208. clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS);
  209. out_be32(&cpc->cpccsr0, 0);
  210. out_be32(&cpc->cpcsrcr0, 0);
  211. }
  212. }
  213. }
  214. #endif
  215. #if defined(T1040_TDM_QUIRK_CCSR_BASE)
  216. #ifdef CONFIG_POST
  217. #error POST memory test cannot be enabled with TDM
  218. #endif
  219. static void enable_tdm_law(void)
  220. {
  221. int ret;
  222. char buffer[HWCONFIG_BUFFER_SIZE] = {0};
  223. int tdm_hwconfig_enabled = 0;
  224. /*
  225. * Extract hwconfig from environment since environment
  226. * is not setup properly yet. Search for tdm entry in
  227. * hwconfig.
  228. */
  229. ret = env_get_f("hwconfig", buffer, sizeof(buffer));
  230. if (ret > 0) {
  231. tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
  232. /* If tdm is defined in hwconfig, set law for tdm workaround */
  233. if (tdm_hwconfig_enabled)
  234. set_next_law(T1040_TDM_QUIRK_CCSR_BASE, LAW_SIZE_16M,
  235. LAW_TRGT_IF_CCSR);
  236. }
  237. }
  238. #endif
  239. void enable_cpc(void)
  240. {
  241. int i;
  242. int ret;
  243. u32 size = 0;
  244. u32 cpccfg0;
  245. char buffer[HWCONFIG_BUFFER_SIZE];
  246. char cpc_subarg[16];
  247. bool have_hwconfig = false;
  248. int cpc_args = 0;
  249. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  250. /* Extract hwconfig from environment */
  251. ret = env_get_f("hwconfig", buffer, sizeof(buffer));
  252. if (ret > 0) {
  253. /*
  254. * If "en_cpc" is not defined in hwconfig then by default all
  255. * cpcs are enable. If this config is defined then individual
  256. * cpcs which have to be enabled should also be defined.
  257. * e.g en_cpc:cpc1,cpc2;
  258. */
  259. if (hwconfig_f("en_cpc", buffer))
  260. have_hwconfig = true;
  261. }
  262. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  263. if (have_hwconfig) {
  264. sprintf(cpc_subarg, "cpc%u", i + 1);
  265. cpc_args = hwconfig_sub_f("en_cpc", cpc_subarg, buffer);
  266. if (cpc_args == 0)
  267. continue;
  268. }
  269. cpccfg0 = in_be32(&cpc->cpccfg0);
  270. size += CPC_CFG0_SZ_K(cpccfg0);
  271. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
  272. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
  273. #endif
  274. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
  275. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
  276. #endif
  277. #ifdef CONFIG_SYS_FSL_ERRATUM_A006593
  278. setbits_be32(&cpc->cpchdbcr0, 1 << (31 - 21));
  279. #endif
  280. #ifdef CONFIG_SYS_FSL_ERRATUM_A006379
  281. if (has_erratum_a006379()) {
  282. setbits_be32(&cpc->cpchdbcr0,
  283. CPC_HDBCR0_SPLRU_LEVEL_EN);
  284. }
  285. #endif
  286. out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
  287. /* Read back to sync write */
  288. in_be32(&cpc->cpccsr0);
  289. }
  290. puts("Corenet Platform Cache: ");
  291. print_size(size * 1024, " enabled\n");
  292. }
  293. static void invalidate_cpc(void)
  294. {
  295. int i;
  296. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  297. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  298. /* skip CPC when it used as all SRAM */
  299. if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
  300. continue;
  301. /* Flash invalidate the CPC and clear all the locks */
  302. out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
  303. while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
  304. ;
  305. }
  306. }
  307. #else
  308. #define enable_cpc()
  309. #define invalidate_cpc()
  310. #define disable_cpc_sram()
  311. #endif /* CONFIG_SYS_FSL_CPC */
  312. /*
  313. * Breathe some life into the CPU...
  314. *
  315. * Set up the memory map
  316. * initialize a bunch of registers
  317. */
  318. #ifdef CONFIG_FSL_CORENET
  319. static void corenet_tb_init(void)
  320. {
  321. volatile ccsr_rcpm_t *rcpm =
  322. (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  323. volatile ccsr_pic_t *pic =
  324. (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  325. u32 whoami = in_be32(&pic->whoami);
  326. /* Enable the timebase register for this core */
  327. out_be32(&rcpm->ctbenrl, (1 << whoami));
  328. }
  329. #endif
  330. #ifdef CONFIG_SYS_FSL_ERRATUM_A007212
  331. void fsl_erratum_a007212_workaround(void)
  332. {
  333. ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  334. u32 ddr_pll_ratio;
  335. u32 __iomem *plldgdcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c20);
  336. u32 __iomem *plldadcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c28);
  337. u32 __iomem *dpdovrcr4 = (void *)(CONFIG_SYS_DCSRBAR + 0x21e80);
  338. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
  339. u32 __iomem *plldgdcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c40);
  340. u32 __iomem *plldadcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c48);
  341. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
  342. u32 __iomem *plldgdcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c60);
  343. u32 __iomem *plldadcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c68);
  344. #endif
  345. #endif
  346. /*
  347. * Even this workaround applies to selected version of SoCs, it is
  348. * safe to apply to all versions, with the limitation of odd ratios.
  349. * If RCW has disabled DDR PLL, we have to apply this workaround,
  350. * otherwise DDR will not work.
  351. */
  352. ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
  353. FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT) &
  354. FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
  355. /* check if RCW sets ratio to 0, required by this workaround */
  356. if (ddr_pll_ratio != 0)
  357. return;
  358. ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
  359. FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
  360. FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
  361. /* check if reserved bits have the desired ratio */
  362. if (ddr_pll_ratio == 0) {
  363. printf("Error: Unknown DDR PLL ratio!\n");
  364. return;
  365. }
  366. ddr_pll_ratio >>= 1;
  367. setbits_be32(plldadcr1, 0x02000001);
  368. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
  369. setbits_be32(plldadcr2, 0x02000001);
  370. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
  371. setbits_be32(plldadcr3, 0x02000001);
  372. #endif
  373. #endif
  374. setbits_be32(dpdovrcr4, 0xe0000000);
  375. out_be32(plldgdcr1, 0x08000001 | (ddr_pll_ratio << 1));
  376. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
  377. out_be32(plldgdcr2, 0x08000001 | (ddr_pll_ratio << 1));
  378. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
  379. out_be32(plldgdcr3, 0x08000001 | (ddr_pll_ratio << 1));
  380. #endif
  381. #endif
  382. udelay(100);
  383. clrbits_be32(plldadcr1, 0x02000001);
  384. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
  385. clrbits_be32(plldadcr2, 0x02000001);
  386. #if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
  387. clrbits_be32(plldadcr3, 0x02000001);
  388. #endif
  389. #endif
  390. clrbits_be32(dpdovrcr4, 0xe0000000);
  391. }
  392. #endif
  393. ulong cpu_init_f(void)
  394. {
  395. extern void m8560_cpm_reset (void);
  396. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  397. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  398. #endif
  399. #if defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SYS_RAMBOOT)
  400. struct law_entry law;
  401. #endif
  402. #ifdef CONFIG_ARCH_MPC8548
  403. ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  404. uint svr = get_svr();
  405. /*
  406. * CPU2 errata workaround: A core hang possible while executing
  407. * a msync instruction and a snoopable transaction from an I/O
  408. * master tagged to make quick forward progress is present.
  409. * Fixed in silicon rev 2.1.
  410. */
  411. if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
  412. out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
  413. #endif
  414. disable_tlb(14);
  415. disable_tlb(15);
  416. #if defined(CONFIG_SECURE_BOOT) && !defined(CONFIG_SYS_RAMBOOT)
  417. /* Disable the LAW created for NOR flash by the PBI commands */
  418. law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
  419. if (law.index != -1)
  420. disable_law(law.index);
  421. #if defined(CONFIG_SYS_CPC_REINIT_F)
  422. disable_cpc_sram();
  423. #endif
  424. #endif
  425. #ifdef CONFIG_CPM2
  426. config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
  427. #endif
  428. init_early_memctl_regs();
  429. #if defined(CONFIG_CPM2)
  430. m8560_cpm_reset();
  431. #endif
  432. #if defined(CONFIG_QE) && !defined(CONFIG_U_QE)
  433. /* Config QE ioports */
  434. config_qe_ioports();
  435. #endif
  436. #if defined(CONFIG_FSL_DMA)
  437. dma_init();
  438. #endif
  439. #ifdef CONFIG_FSL_CORENET
  440. corenet_tb_init();
  441. #endif
  442. init_used_tlb_cams();
  443. /* Invalidate the CPC before DDR gets enabled */
  444. invalidate_cpc();
  445. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  446. /* set DCSRCR so that DCSR space is 1G */
  447. setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
  448. in_be32(&gur->dcsrcr);
  449. #endif
  450. #ifdef CONFIG_SYS_FSL_ERRATUM_A007212
  451. fsl_erratum_a007212_workaround();
  452. #endif
  453. return 0;
  454. }
  455. /* Implement a dummy function for those platforms w/o SERDES */
  456. static void __fsl_serdes__init(void)
  457. {
  458. return ;
  459. }
  460. __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
  461. #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  462. int enable_cluster_l2(void)
  463. {
  464. int i = 0;
  465. u32 cluster, svr = get_svr();
  466. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  467. struct ccsr_cluster_l2 __iomem *l2cache;
  468. /* only the L2 of first cluster should be enabled as expected on T4080,
  469. * but there is no EOC in the first cluster as HW sake, so return here
  470. * to skip enabling L2 cache of the 2nd cluster.
  471. */
  472. if (SVR_SOC_VER(svr) == SVR_T4080)
  473. return 0;
  474. cluster = in_be32(&gur->tp_cluster[i].lower);
  475. if (cluster & TP_CLUSTER_EOC)
  476. return 0;
  477. /* The first cache has already been set up, so skip it */
  478. i++;
  479. /* Look through the remaining clusters, and set up their caches */
  480. do {
  481. int j, cluster_valid = 0;
  482. l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000);
  483. cluster = in_be32(&gur->tp_cluster[i].lower);
  484. /* check that at least one core/accel is enabled in cluster */
  485. for (j = 0; j < 4; j++) {
  486. u32 idx = (cluster >> (j*8)) & TP_CLUSTER_INIT_MASK;
  487. u32 type = in_be32(&gur->tp_ityp[idx]);
  488. if ((type & TP_ITYP_AV) &&
  489. TP_ITYP_TYPE(type) == TP_ITYP_TYPE_PPC)
  490. cluster_valid = 1;
  491. }
  492. if (cluster_valid) {
  493. /* set stash ID to (cluster) * 2 + 32 + 1 */
  494. clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1);
  495. printf("enable l2 for cluster %d %p\n", i, l2cache);
  496. out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC);
  497. while ((in_be32(&l2cache->l2csr0)
  498. & (L2CSR0_L2FI|L2CSR0_L2LFC)) != 0)
  499. ;
  500. out_be32(&l2cache->l2csr0, L2CSR0_L2E|L2CSR0_L2PE|L2CSR0_L2REP_MODE);
  501. }
  502. i++;
  503. } while (!(cluster & TP_CLUSTER_EOC));
  504. return 0;
  505. }
  506. #endif
  507. /*
  508. * Initialize L2 as cache.
  509. */
  510. int l2cache_init(void)
  511. {
  512. __maybe_unused u32 svr = get_svr();
  513. #ifdef CONFIG_L2_CACHE
  514. ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR;
  515. #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  516. struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2;
  517. #endif
  518. puts ("L2: ");
  519. #if defined(CONFIG_L2_CACHE)
  520. volatile uint cache_ctl;
  521. uint ver;
  522. u32 l2siz_field;
  523. ver = SVR_SOC_VER(svr);
  524. asm("msync;isync");
  525. cache_ctl = l2cache->l2ctl;
  526. #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
  527. if (cache_ctl & MPC85xx_L2CTL_L2E) {
  528. /* Clear L2 SRAM memory-mapped base address */
  529. out_be32(&l2cache->l2srbar0, 0x0);
  530. out_be32(&l2cache->l2srbar1, 0x0);
  531. /* set MBECCDIS=0, SBECCDIS=0 */
  532. clrbits_be32(&l2cache->l2errdis,
  533. (MPC85xx_L2ERRDIS_MBECC |
  534. MPC85xx_L2ERRDIS_SBECC));
  535. /* set L2E=0, L2SRAM=0 */
  536. clrbits_be32(&l2cache->l2ctl,
  537. (MPC85xx_L2CTL_L2E |
  538. MPC85xx_L2CTL_L2SRAM_ENTIRE));
  539. }
  540. #endif
  541. l2siz_field = (cache_ctl >> 28) & 0x3;
  542. switch (l2siz_field) {
  543. case 0x0:
  544. printf(" unknown size (0x%08x)\n", cache_ctl);
  545. return -1;
  546. break;
  547. case 0x1:
  548. if (ver == SVR_8540 || ver == SVR_8560 ||
  549. ver == SVR_8541 || ver == SVR_8555) {
  550. puts("128 KiB ");
  551. /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 KiBibyte) */
  552. cache_ctl = 0xc4000000;
  553. } else {
  554. puts("256 KiB ");
  555. cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
  556. }
  557. break;
  558. case 0x2:
  559. if (ver == SVR_8540 || ver == SVR_8560 ||
  560. ver == SVR_8541 || ver == SVR_8555) {
  561. puts("256 KiB ");
  562. /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 KiBibyte) */
  563. cache_ctl = 0xc8000000;
  564. } else {
  565. puts("512 KiB ");
  566. /* set L2E=1, L2I=1, & L2SRAM=0 */
  567. cache_ctl = 0xc0000000;
  568. }
  569. break;
  570. case 0x3:
  571. puts("1024 KiB ");
  572. /* set L2E=1, L2I=1, & L2SRAM=0 */
  573. cache_ctl = 0xc0000000;
  574. break;
  575. }
  576. if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
  577. puts("already enabled");
  578. #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
  579. u32 l2srbar = l2cache->l2srbar0;
  580. if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
  581. && l2srbar >= CONFIG_SYS_FLASH_BASE) {
  582. l2srbar = CONFIG_SYS_INIT_L2_ADDR;
  583. l2cache->l2srbar0 = l2srbar;
  584. printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
  585. }
  586. #endif /* CONFIG_SYS_INIT_L2_ADDR */
  587. puts("\n");
  588. } else {
  589. asm("msync;isync");
  590. l2cache->l2ctl = cache_ctl; /* invalidate & enable */
  591. asm("msync;isync");
  592. puts("enabled\n");
  593. }
  594. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  595. if (SVR_SOC_VER(svr) == SVR_P2040) {
  596. puts("N/A\n");
  597. goto skip_l2;
  598. }
  599. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  600. /* invalidate the L2 cache */
  601. mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
  602. while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
  603. ;
  604. #ifdef CONFIG_SYS_CACHE_STASHING
  605. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  606. mtspr(SPRN_L2CSR1, (32 + 1));
  607. #endif
  608. /* enable the cache */
  609. mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
  610. if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
  611. while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
  612. ;
  613. print_size((l2cfg0 & 0x3fff) * 64 * 1024, " enabled\n");
  614. }
  615. skip_l2:
  616. #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  617. if (l2cache->l2csr0 & L2CSR0_L2E)
  618. print_size((l2cache->l2cfg0 & 0x3fff) * 64 * 1024,
  619. " enabled\n");
  620. enable_cluster_l2();
  621. #else
  622. puts("disabled\n");
  623. #endif
  624. return 0;
  625. }
  626. /*
  627. *
  628. * The newer 8548, etc, parts have twice as much cache, but
  629. * use the same bit-encoding as the older 8555, etc, parts.
  630. *
  631. */
  632. int cpu_init_r(void)
  633. {
  634. __maybe_unused u32 svr = get_svr();
  635. #ifdef CONFIG_SYS_LBC_LCRR
  636. fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR;
  637. #endif
  638. #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
  639. extern int spin_table_compat;
  640. const char *spin;
  641. #endif
  642. #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
  643. ccsr_sec_t __iomem *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
  644. #endif
  645. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
  646. defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
  647. /*
  648. * CPU22 and NMG_CPU_A011 share the same workaround.
  649. * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  650. * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  651. * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both
  652. * fixed in 2.0. NMG_CPU_A011 is activated by default and can
  653. * be disabled by hwconfig with syntax:
  654. *
  655. * fsl_cpu_a011:disable
  656. */
  657. extern int enable_cpu_a011_workaround;
  658. #ifdef CONFIG_SYS_P4080_ERRATUM_CPU22
  659. enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3);
  660. #else
  661. char buffer[HWCONFIG_BUFFER_SIZE];
  662. char *buf = NULL;
  663. int n, res;
  664. n = env_get_f("hwconfig", buffer, sizeof(buffer));
  665. if (n > 0)
  666. buf = buffer;
  667. res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf);
  668. if (res > 0) {
  669. enable_cpu_a011_workaround = 0;
  670. } else {
  671. if (n >= HWCONFIG_BUFFER_SIZE) {
  672. printf("fsl_cpu_a011 was not found. hwconfig variable "
  673. "may be too long\n");
  674. }
  675. enable_cpu_a011_workaround =
  676. (SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) ||
  677. (SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2);
  678. }
  679. #endif
  680. if (enable_cpu_a011_workaround) {
  681. flush_dcache();
  682. mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
  683. sync();
  684. }
  685. #endif
  686. #ifdef CONFIG_SYS_FSL_ERRATUM_A007907
  687. flush_dcache();
  688. mtspr(L1CSR2, (mfspr(L1CSR2) & ~L1CSR2_DCSTASHID));
  689. sync();
  690. #endif
  691. #ifdef CONFIG_SYS_FSL_ERRATUM_A005812
  692. /*
  693. * A-005812 workaround sets bit 32 of SPR 976 for SoCs running
  694. * in write shadow mode. Checking DCWS before setting SPR 976.
  695. */
  696. if (mfspr(L1CSR2) & L1CSR2_DCWS)
  697. mtspr(SPRN_HDBCR0, (mfspr(SPRN_HDBCR0) | 0x80000000));
  698. #endif
  699. #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
  700. spin = env_get("spin_table_compat");
  701. if (spin && (*spin == 'n'))
  702. spin_table_compat = 0;
  703. else
  704. spin_table_compat = 1;
  705. #endif
  706. #ifdef CONFIG_FSL_CORENET
  707. set_liodns();
  708. #ifdef CONFIG_SYS_DPAA_QBMAN
  709. setup_portals();
  710. #endif
  711. #endif
  712. l2cache_init();
  713. #if defined(CONFIG_RAMBOOT_PBL)
  714. disable_cpc_sram();
  715. #endif
  716. enable_cpc();
  717. #if defined(T1040_TDM_QUIRK_CCSR_BASE)
  718. enable_tdm_law();
  719. #endif
  720. #ifndef CONFIG_SYS_FSL_NO_SERDES
  721. /* needs to be in ram since code uses global static vars */
  722. fsl_serdes_init();
  723. #endif
  724. #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
  725. #define MCFGR_AXIPIPE 0x000000f0
  726. if (IS_SVR_REV(svr, 1, 0))
  727. sec_clrbits32(&sec->mcfgr, MCFGR_AXIPIPE);
  728. #endif
  729. #ifdef CONFIG_SYS_FSL_ERRATUM_A005871
  730. if (IS_SVR_REV(svr, 1, 0)) {
  731. int i;
  732. __be32 *p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb004c;
  733. for (i = 0; i < 12; i++) {
  734. p += i + (i > 5 ? 11 : 0);
  735. out_be32(p, 0x2);
  736. }
  737. p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb0108;
  738. out_be32(p, 0x34);
  739. }
  740. #endif
  741. #ifdef CONFIG_SYS_SRIO
  742. srio_init();
  743. #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
  744. char *s = env_get("bootmaster");
  745. if (s) {
  746. if (!strcmp(s, "SRIO1")) {
  747. srio_boot_master(1);
  748. srio_boot_master_release_slave(1);
  749. }
  750. if (!strcmp(s, "SRIO2")) {
  751. srio_boot_master(2);
  752. srio_boot_master_release_slave(2);
  753. }
  754. }
  755. #endif
  756. #endif
  757. #if defined(CONFIG_MP)
  758. setup_mp();
  759. #endif
  760. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13
  761. {
  762. if (SVR_MAJ(svr) < 3) {
  763. void *p;
  764. p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
  765. setbits_be32(p, 1 << (31 - 14));
  766. }
  767. }
  768. #endif
  769. #ifdef CONFIG_SYS_LBC_LCRR
  770. /*
  771. * Modify the CLKDIV field of LCRR register to improve the writing
  772. * speed for NOR flash.
  773. */
  774. clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
  775. __raw_readl(&lbc->lcrr);
  776. isync();
  777. #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
  778. udelay(100);
  779. #endif
  780. #endif
  781. #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
  782. {
  783. struct ccsr_usb_phy __iomem *usb_phy1 =
  784. (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
  785. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  786. if (has_erratum_a006261())
  787. fsl_erratum_a006261_workaround(usb_phy1);
  788. #endif
  789. out_be32(&usb_phy1->usb_enable_override,
  790. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  791. }
  792. #endif
  793. #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
  794. {
  795. struct ccsr_usb_phy __iomem *usb_phy2 =
  796. (void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
  797. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  798. if (has_erratum_a006261())
  799. fsl_erratum_a006261_workaround(usb_phy2);
  800. #endif
  801. out_be32(&usb_phy2->usb_enable_override,
  802. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  803. }
  804. #endif
  805. #ifdef CONFIG_SYS_FSL_ERRATUM_USB14
  806. /* On P204x/P304x/P50x0 Rev1.0, USB transmit will result internal
  807. * multi-bit ECC errors which has impact on performance, so software
  808. * should disable all ECC reporting from USB1 and USB2.
  809. */
  810. if (IS_SVR_REV(get_svr(), 1, 0)) {
  811. struct dcsr_dcfg_regs *dcfg = (struct dcsr_dcfg_regs *)
  812. (CONFIG_SYS_DCSRBAR + CONFIG_SYS_DCSR_DCFG_OFFSET);
  813. setbits_be32(&dcfg->ecccr1,
  814. (DCSR_DCFG_ECC_DISABLE_USB1 |
  815. DCSR_DCFG_ECC_DISABLE_USB2));
  816. }
  817. #endif
  818. #if defined(CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE)
  819. struct ccsr_usb_phy __iomem *usb_phy =
  820. (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
  821. setbits_be32(&usb_phy->pllprg[1],
  822. CONFIG_SYS_FSL_USB_PLLPRG2_PHY2_CLK_EN |
  823. CONFIG_SYS_FSL_USB_PLLPRG2_PHY1_CLK_EN |
  824. CONFIG_SYS_FSL_USB_PLLPRG2_MFI |
  825. CONFIG_SYS_FSL_USB_PLLPRG2_PLL_EN);
  826. #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
  827. usb_single_source_clk_configure(usb_phy);
  828. #endif
  829. setbits_be32(&usb_phy->port1.ctrl,
  830. CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
  831. setbits_be32(&usb_phy->port1.drvvbuscfg,
  832. CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
  833. setbits_be32(&usb_phy->port1.pwrfltcfg,
  834. CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
  835. setbits_be32(&usb_phy->port2.ctrl,
  836. CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
  837. setbits_be32(&usb_phy->port2.drvvbuscfg,
  838. CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
  839. setbits_be32(&usb_phy->port2.pwrfltcfg,
  840. CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
  841. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  842. if (has_erratum_a006261())
  843. fsl_erratum_a006261_workaround(usb_phy);
  844. #endif
  845. #endif /* CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE */
  846. #ifdef CONFIG_SYS_FSL_ERRATUM_A009942
  847. erratum_a009942_check_cpo();
  848. #endif
  849. #ifdef CONFIG_FMAN_ENET
  850. fman_enet_init();
  851. #endif
  852. #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_CORENET)
  853. if (pamu_init() < 0)
  854. fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT);
  855. #endif
  856. #ifdef CONFIG_FSL_CAAM
  857. sec_init();
  858. #if defined(CONFIG_ARCH_C29X)
  859. if ((SVR_SOC_VER(svr) == SVR_C292) ||
  860. (SVR_SOC_VER(svr) == SVR_C293))
  861. sec_init_idx(1);
  862. if (SVR_SOC_VER(svr) == SVR_C293)
  863. sec_init_idx(2);
  864. #endif
  865. #endif
  866. #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_SYS_FSL_ERRATUM_SATA_A001)
  867. /*
  868. * For P1022/1013 Rev1.0 silicon, after power on SATA host
  869. * controller is configured in legacy mode instead of the
  870. * expected enterprise mode. Software needs to clear bit[28]
  871. * of HControl register to change to enterprise mode from
  872. * legacy mode. We assume that the controller is offline.
  873. */
  874. if (IS_SVR_REV(svr, 1, 0) &&
  875. ((SVR_SOC_VER(svr) == SVR_P1022) ||
  876. (SVR_SOC_VER(svr) == SVR_P1013))) {
  877. fsl_sata_reg_t *reg;
  878. /* first SATA controller */
  879. reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR;
  880. clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
  881. /* second SATA controller */
  882. reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR;
  883. clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
  884. }
  885. #endif
  886. init_used_tlb_cams();
  887. return 0;
  888. }
  889. void arch_preboot_os(void)
  890. {
  891. u32 msr;
  892. /*
  893. * We are changing interrupt offsets and are about to boot the OS so
  894. * we need to make sure we disable all async interrupts. EE is already
  895. * disabled by the time we get called.
  896. */
  897. msr = mfmsr();
  898. msr &= ~(MSR_ME|MSR_CE);
  899. mtmsr(msr);
  900. }
  901. #if defined(CONFIG_SATA) && defined(CONFIG_FSL_SATA)
  902. int sata_initialize(void)
  903. {
  904. if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
  905. return __sata_initialize();
  906. return 1;
  907. }
  908. #endif
  909. void cpu_secondary_init_r(void)
  910. {
  911. #ifdef CONFIG_U_QE
  912. uint qe_base = CONFIG_SYS_IMMR + 0x00140000; /* QE immr base */
  913. #elif defined CONFIG_QE
  914. uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
  915. #endif
  916. #ifdef CONFIG_QE
  917. qe_init(qe_base);
  918. qe_reset();
  919. #endif
  920. }
  921. #ifdef CONFIG_BOARD_LATE_INIT
  922. int board_late_init(void)
  923. {
  924. #ifdef CONFIG_CHAIN_OF_TRUST
  925. fsl_setenv_chain_of_trust();
  926. #endif
  927. return 0;
  928. }
  929. #endif