cpu_init.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  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. #if defined(T1040_TDM_QUIRK_CCSR_BASE)
  199. #ifdef CONFIG_POST
  200. #error POST memory test cannot be enabled with TDM
  201. #endif
  202. static void enable_tdm_law(void)
  203. {
  204. int ret;
  205. char buffer[HWCONFIG_BUFFER_SIZE] = {0};
  206. int tdm_hwconfig_enabled = 0;
  207. /*
  208. * Extract hwconfig from environment since environment
  209. * is not setup properly yet. Search for tdm entry in
  210. * hwconfig.
  211. */
  212. ret = getenv_f("hwconfig", buffer, sizeof(buffer));
  213. if (ret > 0) {
  214. tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
  215. /* If tdm is defined in hwconfig, set law for tdm workaround */
  216. if (tdm_hwconfig_enabled)
  217. set_next_law(T1040_TDM_QUIRK_CCSR_BASE, LAW_SIZE_16M,
  218. LAW_TRGT_IF_CCSR);
  219. }
  220. }
  221. #endif
  222. static void enable_cpc(void)
  223. {
  224. int i;
  225. u32 size = 0;
  226. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  227. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  228. u32 cpccfg0 = in_be32(&cpc->cpccfg0);
  229. size += CPC_CFG0_SZ_K(cpccfg0);
  230. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
  231. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
  232. #endif
  233. #ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
  234. setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
  235. #endif
  236. #ifdef CONFIG_SYS_FSL_ERRATUM_A006593
  237. setbits_be32(&cpc->cpchdbcr0, 1 << (31 - 21));
  238. #endif
  239. #ifdef CONFIG_SYS_FSL_ERRATUM_A006379
  240. if (has_erratum_a006379()) {
  241. setbits_be32(&cpc->cpchdbcr0,
  242. CPC_HDBCR0_SPLRU_LEVEL_EN);
  243. }
  244. #endif
  245. out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
  246. /* Read back to sync write */
  247. in_be32(&cpc->cpccsr0);
  248. }
  249. puts("Corenet Platform Cache: ");
  250. print_size(size * 1024, " enabled\n");
  251. }
  252. static void invalidate_cpc(void)
  253. {
  254. int i;
  255. cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
  256. for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
  257. /* skip CPC when it used as all SRAM */
  258. if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
  259. continue;
  260. /* Flash invalidate the CPC and clear all the locks */
  261. out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
  262. while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
  263. ;
  264. }
  265. }
  266. #else
  267. #define enable_cpc()
  268. #define invalidate_cpc()
  269. #endif /* CONFIG_SYS_FSL_CPC */
  270. /*
  271. * Breathe some life into the CPU...
  272. *
  273. * Set up the memory map
  274. * initialize a bunch of registers
  275. */
  276. #ifdef CONFIG_FSL_CORENET
  277. static void corenet_tb_init(void)
  278. {
  279. volatile ccsr_rcpm_t *rcpm =
  280. (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
  281. volatile ccsr_pic_t *pic =
  282. (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
  283. u32 whoami = in_be32(&pic->whoami);
  284. /* Enable the timebase register for this core */
  285. out_be32(&rcpm->ctbenrl, (1 << whoami));
  286. }
  287. #endif
  288. #ifdef CONFIG_SYS_FSL_ERRATUM_A007212
  289. void fsl_erratum_a007212_workaround(void)
  290. {
  291. ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  292. u32 ddr_pll_ratio;
  293. u32 __iomem *plldgdcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c20);
  294. u32 __iomem *plldadcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c28);
  295. u32 __iomem *dpdovrcr4 = (void *)(CONFIG_SYS_DCSRBAR + 0x21e80);
  296. #if (CONFIG_NUM_DDR_CONTROLLERS >= 2)
  297. u32 __iomem *plldgdcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c40);
  298. u32 __iomem *plldadcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c48);
  299. #if (CONFIG_NUM_DDR_CONTROLLERS >= 3)
  300. u32 __iomem *plldgdcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c60);
  301. u32 __iomem *plldadcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c68);
  302. #endif
  303. #endif
  304. /*
  305. * Even this workaround applies to selected version of SoCs, it is
  306. * safe to apply to all versions, with the limitation of odd ratios.
  307. * If RCW has disabled DDR PLL, we have to apply this workaround,
  308. * otherwise DDR will not work.
  309. */
  310. ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
  311. FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT) &
  312. FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
  313. /* check if RCW sets ratio to 0, required by this workaround */
  314. if (ddr_pll_ratio != 0)
  315. return;
  316. ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
  317. FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
  318. FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
  319. /* check if reserved bits have the desired ratio */
  320. if (ddr_pll_ratio == 0) {
  321. printf("Error: Unknown DDR PLL ratio!\n");
  322. return;
  323. }
  324. ddr_pll_ratio >>= 1;
  325. setbits_be32(plldadcr1, 0x02000001);
  326. #if (CONFIG_NUM_DDR_CONTROLLERS >= 2)
  327. setbits_be32(plldadcr2, 0x02000001);
  328. #if (CONFIG_NUM_DDR_CONTROLLERS >= 3)
  329. setbits_be32(plldadcr3, 0x02000001);
  330. #endif
  331. #endif
  332. setbits_be32(dpdovrcr4, 0xe0000000);
  333. out_be32(plldgdcr1, 0x08000001 | (ddr_pll_ratio << 1));
  334. #if (CONFIG_NUM_DDR_CONTROLLERS >= 2)
  335. out_be32(plldgdcr2, 0x08000001 | (ddr_pll_ratio << 1));
  336. #if (CONFIG_NUM_DDR_CONTROLLERS >= 3)
  337. out_be32(plldgdcr3, 0x08000001 | (ddr_pll_ratio << 1));
  338. #endif
  339. #endif
  340. udelay(100);
  341. clrbits_be32(plldadcr1, 0x02000001);
  342. #if (CONFIG_NUM_DDR_CONTROLLERS >= 2)
  343. clrbits_be32(plldadcr2, 0x02000001);
  344. #if (CONFIG_NUM_DDR_CONTROLLERS >= 3)
  345. clrbits_be32(plldadcr3, 0x02000001);
  346. #endif
  347. #endif
  348. clrbits_be32(dpdovrcr4, 0xe0000000);
  349. }
  350. #endif
  351. ulong cpu_init_f(void)
  352. {
  353. ulong flag = 0;
  354. extern void m8560_cpm_reset (void);
  355. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  356. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  357. #endif
  358. #if defined(CONFIG_SECURE_BOOT)
  359. struct law_entry law;
  360. #endif
  361. #ifdef CONFIG_MPC8548
  362. ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  363. uint svr = get_svr();
  364. /*
  365. * CPU2 errata workaround: A core hang possible while executing
  366. * a msync instruction and a snoopable transaction from an I/O
  367. * master tagged to make quick forward progress is present.
  368. * Fixed in silicon rev 2.1.
  369. */
  370. if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
  371. out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
  372. #endif
  373. disable_tlb(14);
  374. disable_tlb(15);
  375. #if defined(CONFIG_SECURE_BOOT)
  376. /* Disable the LAW created for NOR flash by the PBI commands */
  377. law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
  378. if (law.index != -1)
  379. disable_law(law.index);
  380. #if defined(CONFIG_SYS_CPC_REINIT_F)
  381. disable_cpc_sram();
  382. #endif
  383. #endif
  384. #ifdef CONFIG_CPM2
  385. config_8560_ioports((ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR);
  386. #endif
  387. init_early_memctl_regs();
  388. #if defined(CONFIG_CPM2)
  389. m8560_cpm_reset();
  390. #endif
  391. #if defined(CONFIG_QE) && !defined(CONFIG_U_QE)
  392. /* Config QE ioports */
  393. config_qe_ioports();
  394. #endif
  395. #if defined(CONFIG_FSL_DMA)
  396. dma_init();
  397. #endif
  398. #ifdef CONFIG_FSL_CORENET
  399. corenet_tb_init();
  400. #endif
  401. init_used_tlb_cams();
  402. /* Invalidate the CPC before DDR gets enabled */
  403. invalidate_cpc();
  404. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  405. /* set DCSRCR so that DCSR space is 1G */
  406. setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
  407. in_be32(&gur->dcsrcr);
  408. #endif
  409. #ifdef CONFIG_SYS_DCSRBAR_PHYS
  410. #ifdef CONFIG_DEEP_SLEEP
  411. /* disable the console if boot from deep sleep */
  412. if (in_be32(&gur->scrtsr[0]) & (1 << 3))
  413. flag = GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
  414. #endif
  415. #endif
  416. #ifdef CONFIG_SYS_FSL_ERRATUM_A007212
  417. fsl_erratum_a007212_workaround();
  418. #endif
  419. return flag;
  420. }
  421. /* Implement a dummy function for those platforms w/o SERDES */
  422. static void __fsl_serdes__init(void)
  423. {
  424. return ;
  425. }
  426. __attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
  427. #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  428. int enable_cluster_l2(void)
  429. {
  430. int i = 0;
  431. u32 cluster, svr = get_svr();
  432. ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  433. struct ccsr_cluster_l2 __iomem *l2cache;
  434. /* only the L2 of first cluster should be enabled as expected on T4080,
  435. * but there is no EOC in the first cluster as HW sake, so return here
  436. * to skip enabling L2 cache of the 2nd cluster.
  437. */
  438. if (SVR_SOC_VER(svr) == SVR_T4080)
  439. return 0;
  440. cluster = in_be32(&gur->tp_cluster[i].lower);
  441. if (cluster & TP_CLUSTER_EOC)
  442. return 0;
  443. /* The first cache has already been set up, so skip it */
  444. i++;
  445. /* Look through the remaining clusters, and set up their caches */
  446. do {
  447. int j, cluster_valid = 0;
  448. l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000);
  449. cluster = in_be32(&gur->tp_cluster[i].lower);
  450. /* check that at least one core/accel is enabled in cluster */
  451. for (j = 0; j < 4; j++) {
  452. u32 idx = (cluster >> (j*8)) & TP_CLUSTER_INIT_MASK;
  453. u32 type = in_be32(&gur->tp_ityp[idx]);
  454. if (type & TP_ITYP_AV)
  455. cluster_valid = 1;
  456. }
  457. if (cluster_valid) {
  458. /* set stash ID to (cluster) * 2 + 32 + 1 */
  459. clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1);
  460. printf("enable l2 for cluster %d %p\n", i, l2cache);
  461. out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC);
  462. while ((in_be32(&l2cache->l2csr0)
  463. & (L2CSR0_L2FI|L2CSR0_L2LFC)) != 0)
  464. ;
  465. out_be32(&l2cache->l2csr0, L2CSR0_L2E|L2CSR0_L2PE|L2CSR0_L2REP_MODE);
  466. }
  467. i++;
  468. } while (!(cluster & TP_CLUSTER_EOC));
  469. return 0;
  470. }
  471. #endif
  472. /*
  473. * Initialize L2 as cache.
  474. *
  475. * The newer 8548, etc, parts have twice as much cache, but
  476. * use the same bit-encoding as the older 8555, etc, parts.
  477. *
  478. */
  479. int cpu_init_r(void)
  480. {
  481. __maybe_unused u32 svr = get_svr();
  482. #ifdef CONFIG_SYS_LBC_LCRR
  483. fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR;
  484. #endif
  485. #ifdef CONFIG_L2_CACHE
  486. ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR;
  487. #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  488. struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2;
  489. #endif
  490. #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
  491. extern int spin_table_compat;
  492. const char *spin;
  493. #endif
  494. #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
  495. ccsr_sec_t __iomem *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
  496. #endif
  497. #if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
  498. defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
  499. /*
  500. * CPU22 and NMG_CPU_A011 share the same workaround.
  501. * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  502. * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
  503. * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both
  504. * fixed in 2.0. NMG_CPU_A011 is activated by default and can
  505. * be disabled by hwconfig with syntax:
  506. *
  507. * fsl_cpu_a011:disable
  508. */
  509. extern int enable_cpu_a011_workaround;
  510. #ifdef CONFIG_SYS_P4080_ERRATUM_CPU22
  511. enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3);
  512. #else
  513. char buffer[HWCONFIG_BUFFER_SIZE];
  514. char *buf = NULL;
  515. int n, res;
  516. n = getenv_f("hwconfig", buffer, sizeof(buffer));
  517. if (n > 0)
  518. buf = buffer;
  519. res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf);
  520. if (res > 0)
  521. enable_cpu_a011_workaround = 0;
  522. else {
  523. if (n >= HWCONFIG_BUFFER_SIZE) {
  524. printf("fsl_cpu_a011 was not found. hwconfig variable "
  525. "may be too long\n");
  526. }
  527. enable_cpu_a011_workaround =
  528. (SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) ||
  529. (SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2);
  530. }
  531. #endif
  532. if (enable_cpu_a011_workaround) {
  533. flush_dcache();
  534. mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
  535. sync();
  536. }
  537. #endif
  538. #ifdef CONFIG_SYS_FSL_ERRATUM_A005812
  539. /*
  540. * A-005812 workaround sets bit 32 of SPR 976 for SoCs running
  541. * in write shadow mode. Checking DCWS before setting SPR 976.
  542. */
  543. if (mfspr(L1CSR2) & L1CSR2_DCWS)
  544. mtspr(SPRN_HDBCR0, (mfspr(SPRN_HDBCR0) | 0x80000000));
  545. #endif
  546. #if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
  547. spin = getenv("spin_table_compat");
  548. if (spin && (*spin == 'n'))
  549. spin_table_compat = 0;
  550. else
  551. spin_table_compat = 1;
  552. #endif
  553. puts ("L2: ");
  554. #if defined(CONFIG_L2_CACHE)
  555. volatile uint cache_ctl;
  556. uint ver;
  557. u32 l2siz_field;
  558. ver = SVR_SOC_VER(svr);
  559. asm("msync;isync");
  560. cache_ctl = l2cache->l2ctl;
  561. #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
  562. if (cache_ctl & MPC85xx_L2CTL_L2E) {
  563. /* Clear L2 SRAM memory-mapped base address */
  564. out_be32(&l2cache->l2srbar0, 0x0);
  565. out_be32(&l2cache->l2srbar1, 0x0);
  566. /* set MBECCDIS=0, SBECCDIS=0 */
  567. clrbits_be32(&l2cache->l2errdis,
  568. (MPC85xx_L2ERRDIS_MBECC |
  569. MPC85xx_L2ERRDIS_SBECC));
  570. /* set L2E=0, L2SRAM=0 */
  571. clrbits_be32(&l2cache->l2ctl,
  572. (MPC85xx_L2CTL_L2E |
  573. MPC85xx_L2CTL_L2SRAM_ENTIRE));
  574. }
  575. #endif
  576. l2siz_field = (cache_ctl >> 28) & 0x3;
  577. switch (l2siz_field) {
  578. case 0x0:
  579. printf(" unknown size (0x%08x)\n", cache_ctl);
  580. return -1;
  581. break;
  582. case 0x1:
  583. if (ver == SVR_8540 || ver == SVR_8560 ||
  584. ver == SVR_8541 || ver == SVR_8555) {
  585. puts("128 KiB ");
  586. /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 KiBibyte) */
  587. cache_ctl = 0xc4000000;
  588. } else {
  589. puts("256 KiB ");
  590. cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
  591. }
  592. break;
  593. case 0x2:
  594. if (ver == SVR_8540 || ver == SVR_8560 ||
  595. ver == SVR_8541 || ver == SVR_8555) {
  596. puts("256 KiB ");
  597. /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 KiBibyte) */
  598. cache_ctl = 0xc8000000;
  599. } else {
  600. puts("512 KiB ");
  601. /* set L2E=1, L2I=1, & L2SRAM=0 */
  602. cache_ctl = 0xc0000000;
  603. }
  604. break;
  605. case 0x3:
  606. puts("1024 KiB ");
  607. /* set L2E=1, L2I=1, & L2SRAM=0 */
  608. cache_ctl = 0xc0000000;
  609. break;
  610. }
  611. if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
  612. puts("already enabled");
  613. #if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
  614. u32 l2srbar = l2cache->l2srbar0;
  615. if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
  616. && l2srbar >= CONFIG_SYS_FLASH_BASE) {
  617. l2srbar = CONFIG_SYS_INIT_L2_ADDR;
  618. l2cache->l2srbar0 = l2srbar;
  619. printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
  620. }
  621. #endif /* CONFIG_SYS_INIT_L2_ADDR */
  622. puts("\n");
  623. } else {
  624. asm("msync;isync");
  625. l2cache->l2ctl = cache_ctl; /* invalidate & enable */
  626. asm("msync;isync");
  627. puts("enabled\n");
  628. }
  629. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  630. if (SVR_SOC_VER(svr) == SVR_P2040) {
  631. puts("N/A\n");
  632. goto skip_l2;
  633. }
  634. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  635. /* invalidate the L2 cache */
  636. mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
  637. while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
  638. ;
  639. #ifdef CONFIG_SYS_CACHE_STASHING
  640. /* set stash id to (coreID) * 2 + 32 + L2 (1) */
  641. mtspr(SPRN_L2CSR1, (32 + 1));
  642. #endif
  643. /* enable the cache */
  644. mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
  645. if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
  646. while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
  647. ;
  648. print_size((l2cfg0 & 0x3fff) * 64 * 1024, " enabled\n");
  649. }
  650. skip_l2:
  651. #elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
  652. if (l2cache->l2csr0 & L2CSR0_L2E)
  653. print_size((l2cache->l2cfg0 & 0x3fff) * 64 * 1024,
  654. " enabled\n");
  655. enable_cluster_l2();
  656. #else
  657. puts("disabled\n");
  658. #endif
  659. #if defined(CONFIG_RAMBOOT_PBL)
  660. disable_cpc_sram();
  661. #endif
  662. enable_cpc();
  663. #if defined(T1040_TDM_QUIRK_CCSR_BASE)
  664. enable_tdm_law();
  665. #endif
  666. #ifndef CONFIG_SYS_FSL_NO_SERDES
  667. /* needs to be in ram since code uses global static vars */
  668. fsl_serdes_init();
  669. #endif
  670. #ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
  671. #define MCFGR_AXIPIPE 0x000000f0
  672. if (IS_SVR_REV(svr, 1, 0))
  673. clrbits_be32(&sec->mcfgr, MCFGR_AXIPIPE);
  674. #endif
  675. #ifdef CONFIG_SYS_FSL_ERRATUM_A005871
  676. if (IS_SVR_REV(svr, 1, 0)) {
  677. int i;
  678. __be32 *p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb004c;
  679. for (i = 0; i < 12; i++) {
  680. p += i + (i > 5 ? 11 : 0);
  681. out_be32(p, 0x2);
  682. }
  683. p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb0108;
  684. out_be32(p, 0x34);
  685. }
  686. #endif
  687. #ifdef CONFIG_SYS_SRIO
  688. srio_init();
  689. #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
  690. char *s = getenv("bootmaster");
  691. if (s) {
  692. if (!strcmp(s, "SRIO1")) {
  693. srio_boot_master(1);
  694. srio_boot_master_release_slave(1);
  695. }
  696. if (!strcmp(s, "SRIO2")) {
  697. srio_boot_master(2);
  698. srio_boot_master_release_slave(2);
  699. }
  700. }
  701. #endif
  702. #endif
  703. #if defined(CONFIG_MP)
  704. setup_mp();
  705. #endif
  706. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13
  707. {
  708. if (SVR_MAJ(svr) < 3) {
  709. void *p;
  710. p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
  711. setbits_be32(p, 1 << (31 - 14));
  712. }
  713. }
  714. #endif
  715. #ifdef CONFIG_SYS_LBC_LCRR
  716. /*
  717. * Modify the CLKDIV field of LCRR register to improve the writing
  718. * speed for NOR flash.
  719. */
  720. clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
  721. __raw_readl(&lbc->lcrr);
  722. isync();
  723. #ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
  724. udelay(100);
  725. #endif
  726. #endif
  727. #ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
  728. {
  729. struct ccsr_usb_phy __iomem *usb_phy1 =
  730. (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
  731. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  732. if (has_erratum_a006261())
  733. fsl_erratum_a006261_workaround(usb_phy1);
  734. #endif
  735. out_be32(&usb_phy1->usb_enable_override,
  736. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  737. }
  738. #endif
  739. #ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
  740. {
  741. struct ccsr_usb_phy __iomem *usb_phy2 =
  742. (void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
  743. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  744. if (has_erratum_a006261())
  745. fsl_erratum_a006261_workaround(usb_phy2);
  746. #endif
  747. out_be32(&usb_phy2->usb_enable_override,
  748. CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
  749. }
  750. #endif
  751. #ifdef CONFIG_SYS_FSL_ERRATUM_USB14
  752. /* On P204x/P304x/P50x0 Rev1.0, USB transmit will result internal
  753. * multi-bit ECC errors which has impact on performance, so software
  754. * should disable all ECC reporting from USB1 and USB2.
  755. */
  756. if (IS_SVR_REV(get_svr(), 1, 0)) {
  757. struct dcsr_dcfg_regs *dcfg = (struct dcsr_dcfg_regs *)
  758. (CONFIG_SYS_DCSRBAR + CONFIG_SYS_DCSR_DCFG_OFFSET);
  759. setbits_be32(&dcfg->ecccr1,
  760. (DCSR_DCFG_ECC_DISABLE_USB1 |
  761. DCSR_DCFG_ECC_DISABLE_USB2));
  762. }
  763. #endif
  764. #if defined(CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE)
  765. struct ccsr_usb_phy __iomem *usb_phy =
  766. (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
  767. setbits_be32(&usb_phy->pllprg[1],
  768. CONFIG_SYS_FSL_USB_PLLPRG2_PHY2_CLK_EN |
  769. CONFIG_SYS_FSL_USB_PLLPRG2_PHY1_CLK_EN |
  770. CONFIG_SYS_FSL_USB_PLLPRG2_MFI |
  771. CONFIG_SYS_FSL_USB_PLLPRG2_PLL_EN);
  772. #ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
  773. usb_single_source_clk_configure(usb_phy);
  774. #endif
  775. setbits_be32(&usb_phy->port1.ctrl,
  776. CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
  777. setbits_be32(&usb_phy->port1.drvvbuscfg,
  778. CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
  779. setbits_be32(&usb_phy->port1.pwrfltcfg,
  780. CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
  781. setbits_be32(&usb_phy->port2.ctrl,
  782. CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
  783. setbits_be32(&usb_phy->port2.drvvbuscfg,
  784. CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
  785. setbits_be32(&usb_phy->port2.pwrfltcfg,
  786. CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
  787. #ifdef CONFIG_SYS_FSL_ERRATUM_A006261
  788. if (has_erratum_a006261())
  789. fsl_erratum_a006261_workaround(usb_phy);
  790. #endif
  791. #endif /* CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE */
  792. #ifdef CONFIG_FMAN_ENET
  793. fman_enet_init();
  794. #endif
  795. #if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_FSL_SATA_ERRATUM_A001)
  796. /*
  797. * For P1022/1013 Rev1.0 silicon, after power on SATA host
  798. * controller is configured in legacy mode instead of the
  799. * expected enterprise mode. Software needs to clear bit[28]
  800. * of HControl register to change to enterprise mode from
  801. * legacy mode. We assume that the controller is offline.
  802. */
  803. if (IS_SVR_REV(svr, 1, 0) &&
  804. ((SVR_SOC_VER(svr) == SVR_P1022) ||
  805. (SVR_SOC_VER(svr) == SVR_P1013))) {
  806. fsl_sata_reg_t *reg;
  807. /* first SATA controller */
  808. reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR;
  809. clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
  810. /* second SATA controller */
  811. reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR;
  812. clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
  813. }
  814. #endif
  815. init_used_tlb_cams();
  816. return 0;
  817. }
  818. void arch_preboot_os(void)
  819. {
  820. u32 msr;
  821. /*
  822. * We are changing interrupt offsets and are about to boot the OS so
  823. * we need to make sure we disable all async interrupts. EE is already
  824. * disabled by the time we get called.
  825. */
  826. msr = mfmsr();
  827. msr &= ~(MSR_ME|MSR_CE);
  828. mtmsr(msr);
  829. }
  830. #if defined(CONFIG_CMD_SATA) && defined(CONFIG_FSL_SATA)
  831. int sata_initialize(void)
  832. {
  833. if (is_serdes_configured(SATA1) || is_serdes_configured(SATA2))
  834. return __sata_initialize();
  835. return 1;
  836. }
  837. #endif
  838. void cpu_secondary_init_r(void)
  839. {
  840. #ifdef CONFIG_U_QE
  841. uint qe_base = CONFIG_SYS_IMMR + 0x00140000; /* QE immr base */
  842. #elif defined CONFIG_QE
  843. uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
  844. #endif
  845. #ifdef CONFIG_QE
  846. qe_init(qe_base);
  847. qe_reset();
  848. #endif
  849. }