soc.c 17 KB

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