soc.c 13 KB

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