cpu_init.c 26 KB

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