cpu_init.c 26 KB

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