Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 1 | /* |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 2 | * Copyright 2014-2015 Freescale Semiconductor |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <fsl_ifc.h> |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 9 | #include <ahci.h> |
| 10 | #include <scsi.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 11 | #include <asm/arch/soc.h> |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 12 | #include <asm/io.h> |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 14 | #include <asm/arch-fsl-layerscape/config.h> |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 17 | |
Prabhakar Kushwaha | 77f7ded | 2015-11-09 16:42:20 +0530 | [diff] [blame] | 18 | #if defined(CONFIG_LS2080A) || defined(CONFIG_LS2085A) |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 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 | |
| 27 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008336 |
| 28 | #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR |
| 29 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800; |
| 30 | out_le32(eddrtqcr1, 0x63b30002); |
| 31 | #endif |
| 32 | #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR |
| 33 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800; |
| 34 | out_le32(eddrtqcr1, 0x63b30002); |
| 35 | #endif |
| 36 | #endif |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * This erratum requires a register write before being Memory |
| 41 | * controller 3 being enabled. |
| 42 | */ |
| 43 | static void erratum_a008514(void) |
| 44 | { |
| 45 | u32 *eddrtqcr1; |
| 46 | |
| 47 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008514 |
| 48 | #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR |
| 49 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800; |
| 50 | out_le32(eddrtqcr1, 0x63b20002); |
| 51 | #endif |
| 52 | #endif |
| 53 | } |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 54 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
| 55 | #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val" |
| 56 | |
| 57 | static unsigned long get_internval_val_mhz(void) |
| 58 | { |
| 59 | char *interval = getenv(PLATFORM_CYCLE_ENV_VAR); |
| 60 | /* |
| 61 | * interval is the number of platform cycles(MHz) between |
| 62 | * wake up events generated by EPU. |
| 63 | */ |
| 64 | ulong interval_mhz = get_bus_freq(0) / (1000 * 1000); |
| 65 | |
| 66 | if (interval) |
| 67 | interval_mhz = simple_strtoul(interval, NULL, 10); |
| 68 | |
| 69 | return interval_mhz; |
| 70 | } |
| 71 | |
| 72 | void erratum_a009635(void) |
| 73 | { |
| 74 | u32 val; |
| 75 | unsigned long interval_mhz = get_internval_val_mhz(); |
| 76 | |
| 77 | if (!interval_mhz) |
| 78 | return; |
| 79 | |
| 80 | val = in_le32(DCSR_CGACRE5); |
| 81 | writel(val | 0x00000200, DCSR_CGACRE5); |
| 82 | |
| 83 | val = in_le32(EPU_EPCMPR5); |
| 84 | writel(interval_mhz, EPU_EPCMPR5); |
| 85 | val = in_le32(EPU_EPCCR5); |
| 86 | writel(val | 0x82820000, EPU_EPCCR5); |
| 87 | val = in_le32(EPU_EPSMCR5); |
| 88 | writel(val | 0x002f0000, EPU_EPSMCR5); |
| 89 | val = in_le32(EPU_EPECR5); |
| 90 | writel(val | 0x20000000, EPU_EPECR5); |
| 91 | val = in_le32(EPU_EPGCR); |
| 92 | writel(val | 0x80000000, EPU_EPGCR); |
| 93 | } |
| 94 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */ |
| 95 | |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 96 | static void erratum_a008751(void) |
| 97 | { |
| 98 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008751 |
| 99 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
| 100 | |
| 101 | writel(0x27672b2a, scfg + SCFG_USB3PRM1CR / 4); |
| 102 | #endif |
| 103 | } |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 104 | |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 105 | static void erratum_rcw_src(void) |
| 106 | { |
| 107 | #if defined(CONFIG_SPL) |
| 108 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
| 109 | u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE; |
| 110 | u32 val; |
| 111 | |
| 112 | val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4); |
| 113 | val &= ~DCFG_PORSR1_RCW_SRC; |
| 114 | val |= DCFG_PORSR1_RCW_SRC_NOR; |
| 115 | out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val); |
| 116 | #endif |
| 117 | } |
| 118 | |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 119 | #define I2C_DEBUG_REG 0x6 |
| 120 | #define I2C_GLITCH_EN 0x8 |
| 121 | /* |
| 122 | * This erratum requires setting glitch_en bit to enable |
| 123 | * digital glitch filter to improve clock stability. |
| 124 | */ |
| 125 | static void erratum_a009203(void) |
| 126 | { |
| 127 | u8 __iomem *ptr; |
| 128 | #ifdef CONFIG_SYS_I2C |
| 129 | #ifdef I2C1_BASE_ADDR |
| 130 | ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG); |
| 131 | |
| 132 | writeb(I2C_GLITCH_EN, ptr); |
| 133 | #endif |
| 134 | #ifdef I2C2_BASE_ADDR |
| 135 | ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG); |
| 136 | |
| 137 | writeb(I2C_GLITCH_EN, ptr); |
| 138 | #endif |
| 139 | #ifdef I2C3_BASE_ADDR |
| 140 | ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG); |
| 141 | |
| 142 | writeb(I2C_GLITCH_EN, ptr); |
| 143 | #endif |
| 144 | #ifdef I2C4_BASE_ADDR |
| 145 | ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG); |
| 146 | |
| 147 | writeb(I2C_GLITCH_EN, ptr); |
| 148 | #endif |
| 149 | #endif |
| 150 | } |
| 151 | |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 152 | void fsl_lsch3_early_init_f(void) |
| 153 | { |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 154 | erratum_a008751(); |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 155 | erratum_rcw_src(); |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 156 | init_early_memctl_regs(); /* tighten IFC timing */ |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 157 | erratum_a009203(); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 158 | erratum_a008514(); |
| 159 | erratum_a008336(); |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 160 | } |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 161 | |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 162 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 163 | int sata_init(void) |
| 164 | { |
| 165 | struct ccsr_ahci __iomem *ccsr_ahci; |
| 166 | |
| 167 | ccsr_ahci = (void *)CONFIG_SYS_SATA2; |
| 168 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 169 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 170 | |
| 171 | ccsr_ahci = (void *)CONFIG_SYS_SATA1; |
| 172 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 173 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 174 | |
| 175 | ahci_init((void __iomem *)CONFIG_SYS_SATA1); |
| 176 | scsi_scan(0); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | #endif |
| 181 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 182 | #elif defined(CONFIG_LS1043A) |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 183 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 184 | int sata_init(void) |
| 185 | { |
| 186 | struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA; |
| 187 | |
| 188 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 189 | out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY_2_CFG); |
| 190 | out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY_3_CFG); |
| 191 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 192 | |
| 193 | ahci_init((void __iomem *)CONFIG_SYS_SATA); |
| 194 | scsi_scan(0); |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | #endif |
| 199 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 200 | void fsl_lsch2_early_init_f(void) |
| 201 | { |
| 202 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR; |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 203 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 204 | |
| 205 | #ifdef CONFIG_FSL_IFC |
| 206 | init_early_memctl_regs(); /* tighten IFC timing */ |
| 207 | #endif |
| 208 | |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 209 | /* Make SEC reads and writes snoopable */ |
| 210 | setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP | |
| 211 | SCFG_SNPCNFGCR_SECWRSNP); |
| 212 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 213 | /* |
| 214 | * Enable snoop requests and DVM message requests for |
| 215 | * Slave insterface S4 (A53 core cluster) |
| 216 | */ |
| 217 | out_le32(&cci->slave[4].snoop_ctrl, |
| 218 | CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN); |
| 219 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 220 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 221 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 222 | #ifdef CONFIG_BOARD_LATE_INIT |
| 223 | int board_late_init(void) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 224 | { |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 225 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 226 | sata_init(); |
| 227 | #endif |
| 228 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 229 | return 0; |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 230 | } |
| 231 | #endif |