Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <i2c.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/immap_ls102xa.h> |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/fsl_serdes.h> |
Minghuan Lian | da41902 | 2014-10-31 13:43:44 +0800 | [diff] [blame] | 13 | #include <asm/pcie_layerscape.h> |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 14 | #include <mmc.h> |
| 15 | #include <fsl_esdhc.h> |
| 16 | #include <fsl_ifc.h> |
Ruchika Gupta | 4ba4a09 | 2014-10-15 11:39:06 +0530 | [diff] [blame] | 17 | #include <fsl_sec.h> |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 18 | |
| 19 | #include "../common/qixis.h" |
| 20 | #include "ls1021aqds_qixis.h" |
Zhao Qiang | 63e75fd | 2014-09-26 16:25:32 +0800 | [diff] [blame] | 21 | #ifdef CONFIG_U_QE |
| 22 | #include "../../../drivers/qe/qe.h" |
| 23 | #endif |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | enum { |
| 28 | MUX_TYPE_SD_PCI4, |
| 29 | MUX_TYPE_SD_PC_SA_SG_SG, |
| 30 | MUX_TYPE_SD_PC_SA_PC_SG, |
| 31 | MUX_TYPE_SD_PC_SG_SG, |
| 32 | }; |
| 33 | |
| 34 | int checkboard(void) |
| 35 | { |
| 36 | char buf[64]; |
| 37 | u8 sw; |
| 38 | |
| 39 | puts("Board: LS1021AQDS\n"); |
| 40 | |
| 41 | sw = QIXIS_READ(brdcfg[0]); |
| 42 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 43 | |
| 44 | if (sw < 0x8) |
| 45 | printf("vBank: %d\n", sw); |
| 46 | else if (sw == 0x8) |
| 47 | puts("PromJet\n"); |
| 48 | else if (sw == 0x9) |
| 49 | puts("NAND\n"); |
| 50 | else if (sw == 0x15) |
| 51 | printf("IFCCard\n"); |
| 52 | else |
| 53 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 54 | |
| 55 | printf("Sys ID:0x%02x, Sys Ver: 0x%02x\n", |
| 56 | QIXIS_READ(id), QIXIS_READ(arch)); |
| 57 | |
| 58 | printf("FPGA: v%d (%s), build %d\n", |
| 59 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 60 | (int)qixis_read_minor()); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | unsigned long get_board_sys_clk(void) |
| 66 | { |
| 67 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 68 | |
| 69 | switch (sysclk_conf & 0x0f) { |
| 70 | case QIXIS_SYSCLK_64: |
| 71 | return 64000000; |
| 72 | case QIXIS_SYSCLK_83: |
| 73 | return 83333333; |
| 74 | case QIXIS_SYSCLK_100: |
| 75 | return 100000000; |
| 76 | case QIXIS_SYSCLK_125: |
| 77 | return 125000000; |
| 78 | case QIXIS_SYSCLK_133: |
| 79 | return 133333333; |
| 80 | case QIXIS_SYSCLK_150: |
| 81 | return 150000000; |
| 82 | case QIXIS_SYSCLK_160: |
| 83 | return 160000000; |
| 84 | case QIXIS_SYSCLK_166: |
| 85 | return 166666666; |
| 86 | } |
| 87 | return 66666666; |
| 88 | } |
| 89 | |
| 90 | unsigned long get_board_ddr_clk(void) |
| 91 | { |
| 92 | u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); |
| 93 | |
| 94 | switch ((ddrclk_conf & 0x30) >> 4) { |
| 95 | case QIXIS_DDRCLK_100: |
| 96 | return 100000000; |
| 97 | case QIXIS_DDRCLK_125: |
| 98 | return 125000000; |
| 99 | case QIXIS_DDRCLK_133: |
| 100 | return 133333333; |
| 101 | } |
| 102 | return 66666666; |
| 103 | } |
| 104 | |
Chenhui Zhao | afff137 | 2014-11-06 10:51:59 +0800 | [diff] [blame] | 105 | int select_i2c_ch_pca9547(u8 ch) |
| 106 | { |
| 107 | int ret; |
| 108 | |
| 109 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
| 110 | if (ret) { |
| 111 | puts("PCA: failed to select proper channel\n"); |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 118 | int dram_init(void) |
| 119 | { |
Chenhui Zhao | afff137 | 2014-11-06 10:51:59 +0800 | [diff] [blame] | 120 | /* |
| 121 | * When resuming from deep sleep, the I2C channel may not be |
| 122 | * in the default channel. So, switch to the default channel |
| 123 | * before accessing DDR SPD. |
| 124 | */ |
| 125 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 126 | gd->ram_size = initdram(0); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | #ifdef CONFIG_FSL_ESDHC |
| 132 | struct fsl_esdhc_cfg esdhc_cfg[1] = { |
| 133 | {CONFIG_SYS_FSL_ESDHC_ADDR}, |
| 134 | }; |
| 135 | |
| 136 | int board_mmc_init(bd_t *bis) |
| 137 | { |
| 138 | esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 139 | |
| 140 | return fsl_esdhc_initialize(bis, &esdhc_cfg[0]); |
| 141 | } |
| 142 | #endif |
| 143 | |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 144 | int board_early_init_f(void) |
| 145 | { |
| 146 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 147 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR; |
| 148 | |
| 149 | #ifdef CONFIG_TSEC_ENET |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 150 | out_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR); |
Alison Wang | 0ab1723 | 2014-10-17 15:26:36 +0800 | [diff] [blame] | 151 | out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125); |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 152 | #endif |
| 153 | |
| 154 | #ifdef CONFIG_FSL_IFC |
| 155 | init_early_memctl_regs(); |
| 156 | #endif |
| 157 | |
| 158 | /* Workaround for the issue that DDR could not respond to |
| 159 | * barrier transaction which is generated by executing DSB/ISB |
| 160 | * instruction. Set CCI-400 control override register to |
| 161 | * terminate the barrier transaction. After DDR is initialized, |
| 162 | * allow barrier transaction to DDR again */ |
| 163 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | int config_board_mux(int ctrl_type) |
| 169 | { |
| 170 | u8 reg12; |
| 171 | |
| 172 | reg12 = QIXIS_READ(brdcfg[12]); |
| 173 | |
| 174 | switch (ctrl_type) { |
| 175 | case MUX_TYPE_SD_PCI4: |
| 176 | reg12 = 0x38; |
| 177 | break; |
| 178 | case MUX_TYPE_SD_PC_SA_SG_SG: |
| 179 | reg12 = 0x01; |
| 180 | break; |
| 181 | case MUX_TYPE_SD_PC_SA_PC_SG: |
| 182 | reg12 = 0x01; |
| 183 | break; |
| 184 | case MUX_TYPE_SD_PC_SG_SG: |
| 185 | reg12 = 0x21; |
| 186 | break; |
| 187 | default: |
| 188 | printf("Wrong mux interface type\n"); |
| 189 | return -1; |
| 190 | } |
| 191 | |
| 192 | QIXIS_WRITE(brdcfg[12], reg12); |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | int config_serdes_mux(void) |
| 198 | { |
| 199 | struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 200 | u32 cfg; |
| 201 | |
| 202 | cfg = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK; |
| 203 | cfg >>= RCWSR4_SRDS1_PRTCL_SHIFT; |
| 204 | |
| 205 | switch (cfg) { |
| 206 | case 0x0: |
| 207 | config_board_mux(MUX_TYPE_SD_PCI4); |
| 208 | break; |
| 209 | case 0x30: |
| 210 | config_board_mux(MUX_TYPE_SD_PC_SA_SG_SG); |
| 211 | break; |
| 212 | case 0x60: |
| 213 | config_board_mux(MUX_TYPE_SD_PC_SG_SG); |
| 214 | break; |
| 215 | case 0x70: |
| 216 | config_board_mux(MUX_TYPE_SD_PC_SA_PC_SG); |
| 217 | break; |
| 218 | default: |
| 219 | printf("SRDS1 prtcl:0x%x\n", cfg); |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Ruchika Gupta | 4ba4a09 | 2014-10-15 11:39:06 +0530 | [diff] [blame] | 226 | #if defined(CONFIG_MISC_INIT_R) |
| 227 | int misc_init_r(void) |
| 228 | { |
| 229 | #ifdef CONFIG_FSL_CAAM |
| 230 | return sec_init(); |
| 231 | #endif |
| 232 | } |
| 233 | #endif |
| 234 | |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 235 | int board_init(void) |
| 236 | { |
| 237 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR; |
| 238 | |
| 239 | /* Set CCI-400 control override register to |
| 240 | * enable barrier transaction */ |
| 241 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
Jason Jin | 644bc7e | 2014-10-17 15:26:32 +0800 | [diff] [blame] | 242 | /* |
| 243 | * Set CCI-400 Slave interface S0, S1, S2 Shareable Override Register |
| 244 | * All transactions are treated as non-shareable |
| 245 | */ |
| 246 | out_le32(&cci->slave[0].sha_ord, CCI400_SHAORD_NON_SHAREABLE); |
| 247 | out_le32(&cci->slave[1].sha_ord, CCI400_SHAORD_NON_SHAREABLE); |
| 248 | out_le32(&cci->slave[2].sha_ord, CCI400_SHAORD_NON_SHAREABLE); |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 249 | |
| 250 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 251 | |
| 252 | #ifndef CONFIG_SYS_FSL_NO_SERDES |
| 253 | fsl_serdes_init(); |
| 254 | config_serdes_mux(); |
| 255 | #endif |
Zhao Qiang | 63e75fd | 2014-09-26 16:25:32 +0800 | [diff] [blame] | 256 | |
| 257 | #ifdef CONFIG_U_QE |
| 258 | u_qe_init(); |
| 259 | #endif |
| 260 | |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 264 | int ft_board_setup(void *blob, bd_t *bd) |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 265 | { |
| 266 | ft_cpu_setup(blob, bd); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 267 | |
Minghuan Lian | da41902 | 2014-10-31 13:43:44 +0800 | [diff] [blame] | 268 | #ifdef CONFIG_PCIE_LAYERSCAPE |
| 269 | ft_pcie_setup(blob, bd); |
| 270 | #endif |
| 271 | |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 272 | return 0; |
Wang Huan | 550e3dc | 2014-09-05 13:52:44 +0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | u8 flash_read8(void *addr) |
| 276 | { |
| 277 | return __raw_readb(addr + 1); |
| 278 | } |
| 279 | |
| 280 | void flash_write16(u16 val, void *addr) |
| 281 | { |
| 282 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 283 | |
| 284 | __raw_writew(shftval, addr); |
| 285 | } |
| 286 | |
| 287 | u16 flash_read16(void *addr) |
| 288 | { |
| 289 | u16 val = __raw_readw(addr); |
| 290 | |
| 291 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 292 | } |