soc.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 has DP_DDR */
  31. if (SVR_SOC_VER(svr) == SVR_LS2085A)
  32. return true;
  33. return false;
  34. }
  35. bool soc_has_aiop(void)
  36. {
  37. struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
  38. u32 svr = gur_in32(&gur->svr);
  39. /* LS2085A has AIOP */
  40. if (SVR_SOC_VER(svr) == SVR_LS2085A)
  41. return true;
  42. return false;
  43. }
  44. #ifdef CONFIG_LS2080A
  45. /*
  46. * This erratum requires setting a value to eddrtqcr1 to
  47. * optimal the DDR performance.
  48. */
  49. static void erratum_a008336(void)
  50. {
  51. u32 *eddrtqcr1;
  52. #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
  53. #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
  54. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
  55. if (fsl_ddr_get_version(0) == 0x50200)
  56. out_le32(eddrtqcr1, 0x63b30002);
  57. #endif
  58. #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
  59. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
  60. if (fsl_ddr_get_version(0) == 0x50200)
  61. out_le32(eddrtqcr1, 0x63b30002);
  62. #endif
  63. #endif
  64. }
  65. /*
  66. * This erratum requires a register write before being Memory
  67. * controller 3 being enabled.
  68. */
  69. static void erratum_a008514(void)
  70. {
  71. u32 *eddrtqcr1;
  72. #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
  73. #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
  74. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
  75. out_le32(eddrtqcr1, 0x63b20002);
  76. #endif
  77. #endif
  78. }
  79. #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
  80. #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
  81. static unsigned long get_internval_val_mhz(void)
  82. {
  83. char *interval = getenv(PLATFORM_CYCLE_ENV_VAR);
  84. /*
  85. * interval is the number of platform cycles(MHz) between
  86. * wake up events generated by EPU.
  87. */
  88. ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
  89. if (interval)
  90. interval_mhz = simple_strtoul(interval, NULL, 10);
  91. return interval_mhz;
  92. }
  93. void erratum_a009635(void)
  94. {
  95. u32 val;
  96. unsigned long interval_mhz = get_internval_val_mhz();
  97. if (!interval_mhz)
  98. return;
  99. val = in_le32(DCSR_CGACRE5);
  100. writel(val | 0x00000200, DCSR_CGACRE5);
  101. val = in_le32(EPU_EPCMPR5);
  102. writel(interval_mhz, EPU_EPCMPR5);
  103. val = in_le32(EPU_EPCCR5);
  104. writel(val | 0x82820000, EPU_EPCCR5);
  105. val = in_le32(EPU_EPSMCR5);
  106. writel(val | 0x002f0000, EPU_EPSMCR5);
  107. val = in_le32(EPU_EPECR5);
  108. writel(val | 0x20000000, EPU_EPECR5);
  109. val = in_le32(EPU_EPGCR);
  110. writel(val | 0x80000000, EPU_EPGCR);
  111. }
  112. #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
  113. static void erratum_rcw_src(void)
  114. {
  115. #if defined(CONFIG_SPL)
  116. u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
  117. u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
  118. u32 val;
  119. val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
  120. val &= ~DCFG_PORSR1_RCW_SRC;
  121. val |= DCFG_PORSR1_RCW_SRC_NOR;
  122. out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
  123. #endif
  124. }
  125. #define I2C_DEBUG_REG 0x6
  126. #define I2C_GLITCH_EN 0x8
  127. /*
  128. * This erratum requires setting glitch_en bit to enable
  129. * digital glitch filter to improve clock stability.
  130. */
  131. static void erratum_a009203(void)
  132. {
  133. u8 __iomem *ptr;
  134. #ifdef CONFIG_SYS_I2C
  135. #ifdef I2C1_BASE_ADDR
  136. ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
  137. writeb(I2C_GLITCH_EN, ptr);
  138. #endif
  139. #ifdef I2C2_BASE_ADDR
  140. ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
  141. writeb(I2C_GLITCH_EN, ptr);
  142. #endif
  143. #ifdef I2C3_BASE_ADDR
  144. ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
  145. writeb(I2C_GLITCH_EN, ptr);
  146. #endif
  147. #ifdef I2C4_BASE_ADDR
  148. ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
  149. writeb(I2C_GLITCH_EN, ptr);
  150. #endif
  151. #endif
  152. }
  153. void bypass_smmu(void)
  154. {
  155. u32 val;
  156. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  157. out_le32(SMMU_SCR0, val);
  158. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  159. out_le32(SMMU_NSCR0, val);
  160. }
  161. void fsl_lsch3_early_init_f(void)
  162. {
  163. erratum_rcw_src();
  164. init_early_memctl_regs(); /* tighten IFC timing */
  165. erratum_a009203();
  166. erratum_a008514();
  167. erratum_a008336();
  168. #ifdef CONFIG_CHAIN_OF_TRUST
  169. /* In case of Secure Boot, the IBR configures the SMMU
  170. * to allow only Secure transactions.
  171. * SMMU must be reset in bypass mode.
  172. * Set the ClientPD bit and Clear the USFCFG Bit
  173. */
  174. if (fsl_check_boot_mode_secure() == 1)
  175. bypass_smmu();
  176. #endif
  177. }
  178. #ifdef CONFIG_SCSI_AHCI_PLAT
  179. int sata_init(void)
  180. {
  181. struct ccsr_ahci __iomem *ccsr_ahci;
  182. ccsr_ahci = (void *)CONFIG_SYS_SATA2;
  183. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  184. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  185. ccsr_ahci = (void *)CONFIG_SYS_SATA1;
  186. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  187. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  188. ahci_init((void __iomem *)CONFIG_SYS_SATA1);
  189. scsi_scan(0);
  190. return 0;
  191. }
  192. #endif
  193. #elif defined(CONFIG_FSL_LSCH2)
  194. #ifdef CONFIG_SCSI_AHCI_PLAT
  195. int sata_init(void)
  196. {
  197. struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
  198. #ifdef CONFIG_ARCH_LS1046A
  199. /* Disable SATA ECC */
  200. out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
  201. #endif
  202. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  203. out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY_2_CFG);
  204. out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY_3_CFG);
  205. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  206. ahci_init((void __iomem *)CONFIG_SYS_SATA);
  207. scsi_scan(0);
  208. return 0;
  209. }
  210. #endif
  211. static void erratum_a009929(void)
  212. {
  213. #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
  214. struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  215. u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
  216. u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
  217. rstrqmr1 |= 0x00000400;
  218. gur_out32(&gur->rstrqmr1, rstrqmr1);
  219. writel(0x01000000, dcsr_cop_ccp);
  220. #endif
  221. }
  222. /*
  223. * This erratum requires setting a value to eddrtqcr1 to optimal
  224. * the DDR performance. The eddrtqcr1 register is in SCFG space
  225. * of LS1043A and the offset is 0x157_020c.
  226. */
  227. #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
  228. && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
  229. #error A009660 and A008514 can not be both enabled.
  230. #endif
  231. static void erratum_a009660(void)
  232. {
  233. #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
  234. u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
  235. out_be32(eddrtqcr1, 0x63b20042);
  236. #endif
  237. }
  238. static void erratum_a008850_early(void)
  239. {
  240. #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
  241. /* part 1 of 2 */
  242. struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
  243. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  244. /* disables propagation of barrier transactions to DDRC from CCI400 */
  245. out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
  246. /* disable the re-ordering in DDRC */
  247. ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
  248. #endif
  249. }
  250. void erratum_a008850_post(void)
  251. {
  252. #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
  253. /* part 2 of 2 */
  254. struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
  255. struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
  256. u32 tmp;
  257. /* enable propagation of barrier transactions to DDRC from CCI400 */
  258. out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
  259. /* enable the re-ordering in DDRC */
  260. tmp = ddr_in32(&ddr->eor);
  261. tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
  262. ddr_out32(&ddr->eor, tmp);
  263. #endif
  264. }
  265. #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
  266. void erratum_a010315(void)
  267. {
  268. int i;
  269. for (i = PCIE1; i <= PCIE4; i++)
  270. if (!is_serdes_configured(i)) {
  271. debug("PCIe%d: disabled all R/W permission!\n", i);
  272. set_pcie_ns_access(i, 0);
  273. }
  274. }
  275. #endif
  276. void fsl_lsch2_early_init_f(void)
  277. {
  278. struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
  279. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  280. #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
  281. enable_layerscape_ns_access();
  282. #endif
  283. #ifdef CONFIG_FSL_IFC
  284. init_early_memctl_regs(); /* tighten IFC timing */
  285. #endif
  286. #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
  287. out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
  288. #endif
  289. /* Make SEC reads and writes snoopable */
  290. setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
  291. SCFG_SNPCNFGCR_SECWRSNP);
  292. /*
  293. * Enable snoop requests and DVM message requests for
  294. * Slave insterface S4 (A53 core cluster)
  295. */
  296. out_le32(&cci->slave[4].snoop_ctrl,
  297. CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
  298. /* Erratum */
  299. erratum_a008850_early(); /* part 1 of 2 */
  300. erratum_a009929();
  301. erratum_a009660();
  302. }
  303. #endif
  304. #ifdef CONFIG_BOARD_LATE_INIT
  305. int board_late_init(void)
  306. {
  307. #ifdef CONFIG_SCSI_AHCI_PLAT
  308. sata_init();
  309. #endif
  310. #ifdef CONFIG_CHAIN_OF_TRUST
  311. fsl_setenv_chain_of_trust();
  312. #endif
  313. return 0;
  314. }
  315. #endif