soc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014-2015 Freescale Semiconductor
  4. */
  5. #include <common.h>
  6. #include <fsl_immap.h>
  7. #include <fsl_ifc.h>
  8. #include <ahci.h>
  9. #include <scsi.h>
  10. #include <asm/arch/fsl_serdes.h>
  11. #include <asm/arch/soc.h>
  12. #include <asm/io.h>
  13. #include <asm/global_data.h>
  14. #include <asm/arch-fsl-layerscape/config.h>
  15. #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
  16. #include <fsl_csu.h>
  17. #endif
  18. #ifdef CONFIG_SYS_FSL_DDR
  19. #include <fsl_ddr_sdram.h>
  20. #include <fsl_ddr.h>
  21. #endif
  22. #ifdef CONFIG_CHAIN_OF_TRUST
  23. #include <fsl_validate.h>
  24. #endif
  25. #include <fsl_immap.h>
  26. bool soc_has_dp_ddr(void)
  27. {
  28. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  29. u32 svr = gur_in32(&gur->svr);
  30. /* LS2085A, LS2088A, LS2048A has DP_DDR */
  31. if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
  32. (SVR_SOC_VER(svr) == SVR_LS2088A) ||
  33. (SVR_SOC_VER(svr) == SVR_LS2048A))
  34. return true;
  35. return false;
  36. }
  37. bool soc_has_aiop(void)
  38. {
  39. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  40. u32 svr = gur_in32(&gur->svr);
  41. /* LS2085A has AIOP */
  42. if (SVR_SOC_VER(svr) == SVR_LS2085A)
  43. return true;
  44. return false;
  45. }
  46. static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
  47. {
  48. scfg_clrsetbits32(scfg + offset / 4,
  49. 0xF << 6,
  50. SCFG_USB_TXVREFTUNE << 6);
  51. }
  52. static void erratum_a009008(void)
  53. {
  54. #ifdef CONFIG_SYS_FSL_ERRATUM_A009008
  55. u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
  56. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  57. defined(CONFIG_ARCH_LS1012A)
  58. set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
  59. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
  60. set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
  61. set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
  62. #endif
  63. #elif defined(CONFIG_ARCH_LS2080A)
  64. set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
  65. #endif
  66. #endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
  67. }
  68. static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
  69. {
  70. scfg_clrbits32(scfg + offset / 4,
  71. SCFG_USB_SQRXTUNE_MASK << 23);
  72. }
  73. static void erratum_a009798(void)
  74. {
  75. #ifdef CONFIG_SYS_FSL_ERRATUM_A009798
  76. u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
  77. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  78. defined(CONFIG_ARCH_LS1012A)
  79. set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
  80. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
  81. set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
  82. set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
  83. #endif
  84. #elif defined(CONFIG_ARCH_LS2080A)
  85. set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
  86. #endif
  87. #endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
  88. }
  89. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  90. defined(CONFIG_ARCH_LS1012A)
  91. static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
  92. {
  93. scfg_clrsetbits32(scfg + offset / 4,
  94. 0x7F << 9,
  95. SCFG_USB_PCSTXSWINGFULL << 9);
  96. }
  97. #endif
  98. static void erratum_a008997(void)
  99. {
  100. #ifdef CONFIG_SYS_FSL_ERRATUM_A008997
  101. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  102. defined(CONFIG_ARCH_LS1012A)
  103. u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
  104. set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
  105. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
  106. set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
  107. set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
  108. #endif
  109. #endif
  110. #endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
  111. }
  112. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  113. defined(CONFIG_ARCH_LS1012A)
  114. #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
  115. out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
  116. out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
  117. out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
  118. out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
  119. #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
  120. #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
  121. out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
  122. out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
  123. out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
  124. out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
  125. #endif
  126. static void erratum_a009007(void)
  127. {
  128. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
  129. defined(CONFIG_ARCH_LS1012A)
  130. void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
  131. PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
  132. #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
  133. usb_phy = (void __iomem *)SCFG_USB_PHY2;
  134. PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
  135. usb_phy = (void __iomem *)SCFG_USB_PHY3;
  136. PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
  137. #endif
  138. #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
  139. void __iomem *dcsr = (void __iomem *)DCSR_BASE;
  140. PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
  141. PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
  142. #endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
  143. }
  144. #if defined(CONFIG_FSL_LSCH3)
  145. /*
  146. * This erratum requires setting a value to eddrtqcr1 to
  147. * optimal the DDR performance.
  148. */
  149. static void erratum_a008336(void)
  150. {
  151. #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
  152. u32 *eddrtqcr1;
  153. #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
  154. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
  155. if (fsl_ddr_get_version(0) == 0x50200)
  156. out_le32(eddrtqcr1, 0x63b30002);
  157. #endif
  158. #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
  159. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
  160. if (fsl_ddr_get_version(0) == 0x50200)
  161. out_le32(eddrtqcr1, 0x63b30002);
  162. #endif
  163. #endif
  164. }
  165. /*
  166. * This erratum requires a register write before being Memory
  167. * controller 3 being enabled.
  168. */
  169. static void erratum_a008514(void)
  170. {
  171. #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
  172. u32 *eddrtqcr1;
  173. #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
  174. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
  175. out_le32(eddrtqcr1, 0x63b20002);
  176. #endif
  177. #endif
  178. }
  179. #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
  180. #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
  181. static unsigned long get_internval_val_mhz(void)
  182. {
  183. char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
  184. /*
  185. * interval is the number of platform cycles(MHz) between
  186. * wake up events generated by EPU.
  187. */
  188. ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
  189. if (interval)
  190. interval_mhz = simple_strtoul(interval, NULL, 10);
  191. return interval_mhz;
  192. }
  193. void erratum_a009635(void)
  194. {
  195. u32 val;
  196. unsigned long interval_mhz = get_internval_val_mhz();
  197. if (!interval_mhz)
  198. return;
  199. val = in_le32(DCSR_CGACRE5);
  200. writel(val | 0x00000200, DCSR_CGACRE5);
  201. val = in_le32(EPU_EPCMPR5);
  202. writel(interval_mhz, EPU_EPCMPR5);
  203. val = in_le32(EPU_EPCCR5);
  204. writel(val | 0x82820000, EPU_EPCCR5);
  205. val = in_le32(EPU_EPSMCR5);
  206. writel(val | 0x002f0000, EPU_EPSMCR5);
  207. val = in_le32(EPU_EPECR5);
  208. writel(val | 0x20000000, EPU_EPECR5);
  209. val = in_le32(EPU_EPGCR);
  210. writel(val | 0x80000000, EPU_EPGCR);
  211. }
  212. #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
  213. static void erratum_rcw_src(void)
  214. {
  215. #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
  216. u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
  217. u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
  218. u32 val;
  219. val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
  220. val &= ~DCFG_PORSR1_RCW_SRC;
  221. val |= DCFG_PORSR1_RCW_SRC_NOR;
  222. out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
  223. #endif
  224. }
  225. #define I2C_DEBUG_REG 0x6
  226. #define I2C_GLITCH_EN 0x8
  227. /*
  228. * This erratum requires setting glitch_en bit to enable
  229. * digital glitch filter to improve clock stability.
  230. */
  231. #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
  232. static void erratum_a009203(void)
  233. {
  234. #ifdef CONFIG_SYS_I2C
  235. u8 __iomem *ptr;
  236. #ifdef I2C1_BASE_ADDR
  237. ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
  238. writeb(I2C_GLITCH_EN, ptr);
  239. #endif
  240. #ifdef I2C2_BASE_ADDR
  241. ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
  242. writeb(I2C_GLITCH_EN, ptr);
  243. #endif
  244. #ifdef I2C3_BASE_ADDR
  245. ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
  246. writeb(I2C_GLITCH_EN, ptr);
  247. #endif
  248. #ifdef I2C4_BASE_ADDR
  249. ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
  250. writeb(I2C_GLITCH_EN, ptr);
  251. #endif
  252. #endif
  253. }
  254. #endif
  255. void bypass_smmu(void)
  256. {
  257. u32 val;
  258. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  259. out_le32(SMMU_SCR0, val);
  260. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  261. out_le32(SMMU_NSCR0, val);
  262. }
  263. void fsl_lsch3_early_init_f(void)
  264. {
  265. erratum_rcw_src();
  266. #ifdef CONFIG_FSL_IFC
  267. init_early_memctl_regs(); /* tighten IFC timing */
  268. #endif
  269. #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
  270. erratum_a009203();
  271. #endif
  272. erratum_a008514();
  273. erratum_a008336();
  274. erratum_a009008();
  275. erratum_a009798();
  276. erratum_a008997();
  277. erratum_a009007();
  278. #ifdef CONFIG_CHAIN_OF_TRUST
  279. /* In case of Secure Boot, the IBR configures the SMMU
  280. * to allow only Secure transactions.
  281. * SMMU must be reset in bypass mode.
  282. * Set the ClientPD bit and Clear the USFCFG Bit
  283. */
  284. if (fsl_check_boot_mode_secure() == 1)
  285. bypass_smmu();
  286. #endif
  287. }
  288. #ifdef CONFIG_SCSI_AHCI_PLAT
  289. int sata_init(void)
  290. {
  291. struct ccsr_ahci __iomem *ccsr_ahci;
  292. #ifdef CONFIG_SYS_SATA2
  293. ccsr_ahci = (void *)CONFIG_SYS_SATA2;
  294. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  295. out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY2_CFG);
  296. out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY3_CFG);
  297. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  298. out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
  299. #endif
  300. #ifdef CONFIG_SYS_SATA1
  301. ccsr_ahci = (void *)CONFIG_SYS_SATA1;
  302. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  303. out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY2_CFG);
  304. out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY3_CFG);
  305. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  306. out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
  307. ahci_init((void __iomem *)CONFIG_SYS_SATA1);
  308. scsi_scan(false);
  309. #endif
  310. return 0;
  311. }
  312. #endif
  313. /* Get VDD in the unit mV from voltage ID */
  314. int get_core_volt_from_fuse(void)
  315. {
  316. struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  317. int vdd;
  318. u32 fusesr;
  319. u8 vid;
  320. /* get the voltage ID from fuse status register */
  321. fusesr = in_le32(&gur->dcfg_fusesr);
  322. debug("%s: fusesr = 0x%x\n", __func__, fusesr);
  323. vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) &
  324. FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK;
  325. if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) {
  326. vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) &
  327. FSL_CHASSIS3_DCFG_FUSESR_VID_MASK;
  328. }
  329. debug("%s: VID = 0x%x\n", __func__, vid);
  330. switch (vid) {
  331. case 0x00: /* VID isn't supported */
  332. vdd = -EINVAL;
  333. debug("%s: The VID feature is not supported\n", __func__);
  334. break;
  335. case 0x08: /* 0.9V silicon */
  336. vdd = 900;
  337. break;
  338. case 0x10: /* 1.0V silicon */
  339. vdd = 1000;
  340. break;
  341. default: /* Other core voltage */
  342. vdd = -EINVAL;
  343. debug("%s: The VID(%x) isn't supported\n", __func__, vid);
  344. break;
  345. }
  346. debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
  347. return vdd;
  348. }
  349. #elif defined(CONFIG_FSL_LSCH2)
  350. #ifdef CONFIG_SCSI_AHCI_PLAT
  351. int sata_init(void)
  352. {
  353. struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
  354. /* Disable SATA ECC */
  355. out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
  356. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  357. out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY2_CFG);
  358. out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY3_CFG);
  359. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  360. out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
  361. ahci_init((void __iomem *)CONFIG_SYS_SATA);
  362. scsi_scan(false);
  363. return 0;
  364. }
  365. #endif
  366. static void erratum_a009929(void)
  367. {
  368. #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
  369. struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  370. u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
  371. u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
  372. rstrqmr1 |= 0x00000400;
  373. gur_out32(&gur->rstrqmr1, rstrqmr1);
  374. writel(0x01000000, dcsr_cop_ccp);
  375. #endif
  376. }
  377. /*
  378. * This erratum requires setting a value to eddrtqcr1 to optimal
  379. * the DDR performance. The eddrtqcr1 register is in SCFG space
  380. * of LS1043A and the offset is 0x157_020c.
  381. */
  382. #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
  383. && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
  384. #error A009660 and A008514 can not be both enabled.
  385. #endif
  386. static void erratum_a009660(void)
  387. {
  388. #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
  389. u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
  390. out_be32(eddrtqcr1, 0x63b20042);
  391. #endif
  392. }
  393. static void erratum_a008850_early(void)
  394. {
  395. #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
  396. /* part 1 of 2 */
  397. struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
  398. CONFIG_SYS_CCI400_OFFSET);
  399. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  400. /* Skip if running at lower exception level */
  401. if (current_el() < 3)
  402. return;
  403. /* disables propagation of barrier transactions to DDRC from CCI400 */
  404. out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
  405. /* disable the re-ordering in DDRC */
  406. ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
  407. #endif
  408. }
  409. void erratum_a008850_post(void)
  410. {
  411. #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
  412. /* part 2 of 2 */
  413. struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
  414. CONFIG_SYS_CCI400_OFFSET);
  415. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  416. u32 tmp;
  417. /* Skip if running at lower exception level */
  418. if (current_el() < 3)
  419. return;
  420. /* enable propagation of barrier transactions to DDRC from CCI400 */
  421. out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
  422. /* enable the re-ordering in DDRC */
  423. tmp = ddr_in32(&ddr->eor);
  424. tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
  425. ddr_out32(&ddr->eor, tmp);
  426. #endif
  427. }
  428. #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
  429. void erratum_a010315(void)
  430. {
  431. int i;
  432. for (i = PCIE1; i <= PCIE4; i++)
  433. if (!is_serdes_configured(i)) {
  434. debug("PCIe%d: disabled all R/W permission!\n", i);
  435. set_pcie_ns_access(i, 0);
  436. }
  437. }
  438. #endif
  439. static void erratum_a010539(void)
  440. {
  441. #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
  442. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  443. u32 porsr1;
  444. porsr1 = in_be32(&gur->porsr1);
  445. porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
  446. out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
  447. porsr1);
  448. out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff);
  449. #endif
  450. }
  451. /* Get VDD in the unit mV from voltage ID */
  452. int get_core_volt_from_fuse(void)
  453. {
  454. struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  455. int vdd;
  456. u32 fusesr;
  457. u8 vid;
  458. fusesr = in_be32(&gur->dcfg_fusesr);
  459. debug("%s: fusesr = 0x%x\n", __func__, fusesr);
  460. vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
  461. FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
  462. if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
  463. vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
  464. FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
  465. }
  466. debug("%s: VID = 0x%x\n", __func__, vid);
  467. switch (vid) {
  468. case 0x00: /* VID isn't supported */
  469. vdd = -EINVAL;
  470. debug("%s: The VID feature is not supported\n", __func__);
  471. break;
  472. case 0x08: /* 0.9V silicon */
  473. vdd = 900;
  474. break;
  475. case 0x10: /* 1.0V silicon */
  476. vdd = 1000;
  477. break;
  478. default: /* Other core voltage */
  479. vdd = -EINVAL;
  480. printf("%s: The VID(%x) isn't supported\n", __func__, vid);
  481. break;
  482. }
  483. debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
  484. return vdd;
  485. }
  486. __weak int board_switch_core_volt(u32 vdd)
  487. {
  488. return 0;
  489. }
  490. static int setup_core_volt(u32 vdd)
  491. {
  492. return board_setup_core_volt(vdd);
  493. }
  494. #ifdef CONFIG_SYS_FSL_DDR
  495. static void ddr_enable_0v9_volt(bool en)
  496. {
  497. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  498. u32 tmp;
  499. tmp = ddr_in32(&ddr->ddr_cdr1);
  500. if (en)
  501. tmp |= DDR_CDR1_V0PT9_EN;
  502. else
  503. tmp &= ~DDR_CDR1_V0PT9_EN;
  504. ddr_out32(&ddr->ddr_cdr1, tmp);
  505. }
  506. #endif
  507. int setup_chip_volt(void)
  508. {
  509. int vdd;
  510. vdd = get_core_volt_from_fuse();
  511. /* Nothing to do for silicons doesn't support VID */
  512. if (vdd < 0)
  513. return vdd;
  514. if (setup_core_volt(vdd))
  515. printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
  516. #ifdef CONFIG_SYS_HAS_SERDES
  517. if (setup_serdes_volt(vdd))
  518. printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
  519. #endif
  520. #ifdef CONFIG_SYS_FSL_DDR
  521. if (vdd == 900)
  522. ddr_enable_0v9_volt(true);
  523. #endif
  524. return 0;
  525. }
  526. #ifdef CONFIG_FSL_PFE
  527. void init_pfe_scfg_dcfg_regs(void)
  528. {
  529. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  530. u32 ecccr2;
  531. out_be32(&scfg->pfeasbcr,
  532. in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0);
  533. out_be32(&scfg->pfebsbcr,
  534. in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0);
  535. /* CCI-400 QoS settings for PFE */
  536. out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS
  537. | SCFG_WR_QOS1_PFE2_QOS));
  538. out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS
  539. | SCFG_RD_QOS1_PFE2_QOS));
  540. ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2);
  541. out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2,
  542. ecccr2 | (unsigned int)DISABLE_PFE_ECC);
  543. }
  544. #endif
  545. void fsl_lsch2_early_init_f(void)
  546. {
  547. struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
  548. CONFIG_SYS_CCI400_OFFSET);
  549. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  550. #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
  551. enable_layerscape_ns_access();
  552. #endif
  553. #ifdef CONFIG_FSL_IFC
  554. init_early_memctl_regs(); /* tighten IFC timing */
  555. #endif
  556. #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
  557. out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
  558. #endif
  559. /* Make SEC reads and writes snoopable */
  560. setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
  561. SCFG_SNPCNFGCR_SECWRSNP |
  562. SCFG_SNPCNFGCR_SATARDSNP |
  563. SCFG_SNPCNFGCR_SATAWRSNP);
  564. /*
  565. * Enable snoop requests and DVM message requests for
  566. * Slave insterface S4 (A53 core cluster)
  567. */
  568. if (current_el() == 3) {
  569. out_le32(&cci->slave[4].snoop_ctrl,
  570. CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
  571. }
  572. /* Erratum */
  573. erratum_a008850_early(); /* part 1 of 2 */
  574. erratum_a009929();
  575. erratum_a009660();
  576. erratum_a010539();
  577. erratum_a009008();
  578. erratum_a009798();
  579. erratum_a008997();
  580. erratum_a009007();
  581. }
  582. #endif
  583. #ifdef CONFIG_QSPI_AHB_INIT
  584. /* Enable 4bytes address support and fast read */
  585. int qspi_ahb_init(void)
  586. {
  587. u32 *qspi_lut, lut_key, *qspi_key;
  588. qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
  589. qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
  590. lut_key = in_be32(qspi_key);
  591. if (lut_key == 0x5af05af0) {
  592. /* That means the register is BE */
  593. out_be32(qspi_key, 0x5af05af0);
  594. /* Unlock the lut table */
  595. out_be32(qspi_key + 1, 0x00000002);
  596. out_be32(qspi_lut, 0x0820040c);
  597. out_be32(qspi_lut + 1, 0x1c080c08);
  598. out_be32(qspi_lut + 2, 0x00002400);
  599. /* Lock the lut table */
  600. out_be32(qspi_key, 0x5af05af0);
  601. out_be32(qspi_key + 1, 0x00000001);
  602. } else {
  603. /* That means the register is LE */
  604. out_le32(qspi_key, 0x5af05af0);
  605. /* Unlock the lut table */
  606. out_le32(qspi_key + 1, 0x00000002);
  607. out_le32(qspi_lut, 0x0820040c);
  608. out_le32(qspi_lut + 1, 0x1c080c08);
  609. out_le32(qspi_lut + 2, 0x00002400);
  610. /* Lock the lut table */
  611. out_le32(qspi_key, 0x5af05af0);
  612. out_le32(qspi_key + 1, 0x00000001);
  613. }
  614. return 0;
  615. }
  616. #endif
  617. #ifdef CONFIG_BOARD_LATE_INIT
  618. int board_late_init(void)
  619. {
  620. #ifdef CONFIG_SCSI_AHCI_PLAT
  621. sata_init();
  622. #endif
  623. #ifdef CONFIG_CHAIN_OF_TRUST
  624. fsl_setenv_chain_of_trust();
  625. #endif
  626. #ifdef CONFIG_QSPI_AHB_INIT
  627. qspi_ahb_init();
  628. #endif
  629. return 0;
  630. }
  631. #endif