soc.c 13 KB

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