soc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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_CHAIN_OF_TRUST
  15. #include <fsl_validate.h>
  16. #endif
  17. DECLARE_GLOBAL_DATA_PTR;
  18. #if defined(CONFIG_LS2080A) || defined(CONFIG_LS2085A)
  19. /*
  20. * This erratum requires setting a value to eddrtqcr1 to
  21. * optimal the DDR performance.
  22. */
  23. static void erratum_a008336(void)
  24. {
  25. u32 *eddrtqcr1;
  26. #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
  27. #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
  28. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
  29. out_le32(eddrtqcr1, 0x63b30002);
  30. #endif
  31. #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
  32. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
  33. out_le32(eddrtqcr1, 0x63b30002);
  34. #endif
  35. #endif
  36. }
  37. /*
  38. * This erratum requires a register write before being Memory
  39. * controller 3 being enabled.
  40. */
  41. static void erratum_a008514(void)
  42. {
  43. u32 *eddrtqcr1;
  44. #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
  45. #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
  46. eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
  47. out_le32(eddrtqcr1, 0x63b20002);
  48. #endif
  49. #endif
  50. }
  51. #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
  52. #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
  53. static unsigned long get_internval_val_mhz(void)
  54. {
  55. char *interval = getenv(PLATFORM_CYCLE_ENV_VAR);
  56. /*
  57. * interval is the number of platform cycles(MHz) between
  58. * wake up events generated by EPU.
  59. */
  60. ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
  61. if (interval)
  62. interval_mhz = simple_strtoul(interval, NULL, 10);
  63. return interval_mhz;
  64. }
  65. void erratum_a009635(void)
  66. {
  67. u32 val;
  68. unsigned long interval_mhz = get_internval_val_mhz();
  69. if (!interval_mhz)
  70. return;
  71. val = in_le32(DCSR_CGACRE5);
  72. writel(val | 0x00000200, DCSR_CGACRE5);
  73. val = in_le32(EPU_EPCMPR5);
  74. writel(interval_mhz, EPU_EPCMPR5);
  75. val = in_le32(EPU_EPCCR5);
  76. writel(val | 0x82820000, EPU_EPCCR5);
  77. val = in_le32(EPU_EPSMCR5);
  78. writel(val | 0x002f0000, EPU_EPSMCR5);
  79. val = in_le32(EPU_EPECR5);
  80. writel(val | 0x20000000, EPU_EPECR5);
  81. val = in_le32(EPU_EPGCR);
  82. writel(val | 0x80000000, EPU_EPGCR);
  83. }
  84. #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
  85. static void erratum_a008751(void)
  86. {
  87. #ifdef CONFIG_SYS_FSL_ERRATUM_A008751
  88. u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
  89. writel(0x27672b2a, scfg + SCFG_USB3PRM1CR / 4);
  90. #endif
  91. }
  92. static void erratum_rcw_src(void)
  93. {
  94. #if defined(CONFIG_SPL)
  95. u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
  96. u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
  97. u32 val;
  98. val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
  99. val &= ~DCFG_PORSR1_RCW_SRC;
  100. val |= DCFG_PORSR1_RCW_SRC_NOR;
  101. out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
  102. #endif
  103. }
  104. #define I2C_DEBUG_REG 0x6
  105. #define I2C_GLITCH_EN 0x8
  106. /*
  107. * This erratum requires setting glitch_en bit to enable
  108. * digital glitch filter to improve clock stability.
  109. */
  110. static void erratum_a009203(void)
  111. {
  112. u8 __iomem *ptr;
  113. #ifdef CONFIG_SYS_I2C
  114. #ifdef I2C1_BASE_ADDR
  115. ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
  116. writeb(I2C_GLITCH_EN, ptr);
  117. #endif
  118. #ifdef I2C2_BASE_ADDR
  119. ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
  120. writeb(I2C_GLITCH_EN, ptr);
  121. #endif
  122. #ifdef I2C3_BASE_ADDR
  123. ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
  124. writeb(I2C_GLITCH_EN, ptr);
  125. #endif
  126. #ifdef I2C4_BASE_ADDR
  127. ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
  128. writeb(I2C_GLITCH_EN, ptr);
  129. #endif
  130. #endif
  131. }
  132. void fsl_lsch3_early_init_f(void)
  133. {
  134. erratum_a008751();
  135. erratum_rcw_src();
  136. init_early_memctl_regs(); /* tighten IFC timing */
  137. erratum_a009203();
  138. erratum_a008514();
  139. erratum_a008336();
  140. }
  141. #ifdef CONFIG_SCSI_AHCI_PLAT
  142. int sata_init(void)
  143. {
  144. struct ccsr_ahci __iomem *ccsr_ahci;
  145. ccsr_ahci = (void *)CONFIG_SYS_SATA2;
  146. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  147. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  148. ccsr_ahci = (void *)CONFIG_SYS_SATA1;
  149. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  150. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  151. ahci_init((void __iomem *)CONFIG_SYS_SATA1);
  152. scsi_scan(0);
  153. return 0;
  154. }
  155. #endif
  156. #elif defined(CONFIG_LS1043A)
  157. #ifdef CONFIG_SCSI_AHCI_PLAT
  158. int sata_init(void)
  159. {
  160. struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
  161. out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
  162. out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY_2_CFG);
  163. out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY_3_CFG);
  164. out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
  165. ahci_init((void __iomem *)CONFIG_SYS_SATA);
  166. scsi_scan(0);
  167. return 0;
  168. }
  169. #endif
  170. static void erratum_a009929(void)
  171. {
  172. #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
  173. struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  174. u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
  175. u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
  176. rstrqmr1 |= 0x00000400;
  177. gur_out32(&gur->rstrqmr1, rstrqmr1);
  178. writel(0x01000000, dcsr_cop_ccp);
  179. #endif
  180. }
  181. /*
  182. * This erratum requires setting a value to eddrtqcr1 to optimal
  183. * the DDR performance. The eddrtqcr1 register is in SCFG space
  184. * of LS1043A and the offset is 0x157_020c.
  185. */
  186. #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
  187. && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
  188. #error A009660 and A008514 can not be both enabled.
  189. #endif
  190. static void erratum_a009660(void)
  191. {
  192. #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
  193. u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
  194. out_be32(eddrtqcr1, 0x63b20042);
  195. #endif
  196. }
  197. void fsl_lsch2_early_init_f(void)
  198. {
  199. struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
  200. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  201. #ifdef CONFIG_FSL_IFC
  202. init_early_memctl_regs(); /* tighten IFC timing */
  203. #endif
  204. #ifdef CONFIG_FSL_QSPI
  205. out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
  206. #endif
  207. /* Make SEC reads and writes snoopable */
  208. setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
  209. SCFG_SNPCNFGCR_SECWRSNP);
  210. /*
  211. * Enable snoop requests and DVM message requests for
  212. * Slave insterface S4 (A53 core cluster)
  213. */
  214. out_le32(&cci->slave[4].snoop_ctrl,
  215. CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
  216. /* Erratum */
  217. erratum_a009929();
  218. erratum_a009660();
  219. }
  220. #endif
  221. #ifdef CONFIG_BOARD_LATE_INIT
  222. int board_late_init(void)
  223. {
  224. #ifdef CONFIG_SCSI_AHCI_PLAT
  225. sata_init();
  226. #endif
  227. #ifdef CONFIG_CHAIN_OF_TRUST
  228. fsl_setenv_chain_of_trust();
  229. #endif
  230. return 0;
  231. }
  232. #endif