cpu_init.c 27 KB

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