cpu_init.c 26 KB

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