cpu_init.c 24 KB

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