cpu_init.c 26 KB

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