soc.c 16 KB

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