soc.c 8.3 KB

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