cpu_init.c 26 KB

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