Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2016 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <i2c.h> |
| 8 | #include <fdt_support.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 12 | #ifdef CONFIG_FSL_LS_PPA |
| 13 | #include <asm/arch/ppa.h> |
| 14 | #endif |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 15 | #include <asm/arch/fdt.h> |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 16 | #include <asm/arch/mmu.h> |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 17 | #include <asm/arch/soc.h> |
| 18 | #include <ahci.h> |
| 19 | #include <hwconfig.h> |
| 20 | #include <mmc.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 21 | #include <env_internal.h> |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 22 | #include <scsi.h> |
| 23 | #include <fm_eth.h> |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 24 | #include <fsl_esdhc.h> |
| 25 | #include <fsl_mmdc.h> |
| 26 | #include <spl.h> |
| 27 | #include <netdev.h> |
Rajesh Bhagat | bf39fe6 | 2018-11-05 18:02:59 +0000 | [diff] [blame] | 28 | #include <fsl_sec.h> |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 29 | #include "../common/qixis.h" |
| 30 | #include "ls1012aqds_qixis.h" |
Calvin Johnson | f661502 | 2018-03-08 15:30:28 +0530 | [diff] [blame] | 31 | #include "ls1012aqds_pfe.h" |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 35 | int checkboard(void) |
| 36 | { |
| 37 | char buf[64]; |
| 38 | u8 sw; |
| 39 | |
| 40 | sw = QIXIS_READ(arch); |
| 41 | printf("Board Arch: V%d, ", sw >> 4); |
| 42 | printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1); |
| 43 | |
| 44 | sw = QIXIS_READ(brdcfg[QIXIS_LBMAP_BRDCFG_REG]); |
| 45 | |
| 46 | if (sw & QIXIS_LBMAP_ALTBANK) |
| 47 | printf("flash: 2\n"); |
| 48 | else |
| 49 | printf("flash: 1\n"); |
| 50 | |
| 51 | printf("FPGA: v%d (%s), build %d", |
| 52 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 53 | (int)qixis_read_minor()); |
| 54 | |
| 55 | /* the timestamp string contains "\n" at the end */ |
| 56 | printf(" on %s", qixis_read_time(buf)); |
| 57 | return 0; |
| 58 | } |
| 59 | |
Rajesh Bhagat | 45d8a54 | 2018-11-05 18:03:04 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_TFABOOT |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 61 | int dram_init(void) |
| 62 | { |
Rajesh Bhagat | 45d8a54 | 2018-11-05 18:03:04 +0000 | [diff] [blame] | 63 | gd->ram_size = tfa_get_dram_size(); |
| 64 | if (!gd->ram_size) |
| 65 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | #else |
| 70 | int dram_init(void) |
| 71 | { |
York Sun | c1e979b | 2016-09-26 08:09:25 -0700 | [diff] [blame] | 72 | static const struct fsl_mmdc_info mparam = { |
| 73 | 0x05180000, /* mdctl */ |
| 74 | 0x00030035, /* mdpdc */ |
| 75 | 0x12554000, /* mdotc */ |
| 76 | 0xbabf7954, /* mdcfg0 */ |
| 77 | 0xdb328f64, /* mdcfg1 */ |
| 78 | 0x01ff00db, /* mdcfg2 */ |
| 79 | 0x00001680, /* mdmisc */ |
| 80 | 0x0f3c8000, /* mdref */ |
| 81 | 0x00002000, /* mdrwd */ |
| 82 | 0x00bf1023, /* mdor */ |
| 83 | 0x0000003f, /* mdasp */ |
| 84 | 0x0000022a, /* mpodtctrl */ |
| 85 | 0xa1390003, /* mpzqhwctrl */ |
| 86 | }; |
| 87 | |
| 88 | mmdc_init(&mparam); |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 89 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 90 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 91 | /* This will break-before-make MMU for DDR */ |
| 92 | update_early_mmu_table(); |
| 93 | #endif |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 94 | |
| 95 | return 0; |
| 96 | } |
Rajesh Bhagat | 45d8a54 | 2018-11-05 18:03:04 +0000 | [diff] [blame] | 97 | #endif |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 98 | |
| 99 | int board_early_init_f(void) |
| 100 | { |
| 101 | fsl_lsch2_early_init_f(); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | #ifdef CONFIG_MISC_INIT_R |
| 107 | int misc_init_r(void) |
| 108 | { |
| 109 | u8 mux_sdhc_cd = 0x80; |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 110 | int bus_num = 0; |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 111 | |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 112 | #ifdef CONFIG_DM_I2C |
| 113 | struct udevice *dev; |
| 114 | int ret; |
| 115 | |
| 116 | ret = i2c_get_chip_for_busnum(bus_num, CONFIG_SYS_I2C_FPGA_ADDR, |
| 117 | 1, &dev); |
| 118 | if (ret) { |
| 119 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 120 | bus_num); |
| 121 | return ret; |
| 122 | } |
| 123 | dm_i2c_write(dev, 0x5a, &mux_sdhc_cd, 1); |
| 124 | #else |
| 125 | i2c_set_bus_num(bus_num); |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 126 | |
| 127 | i2c_write(CONFIG_SYS_I2C_FPGA_ADDR, 0x5a, 1, &mux_sdhc_cd, 1); |
Biwen Li | 0a759bb | 2019-12-31 15:33:41 +0800 | [diff] [blame] | 128 | #endif |
| 129 | |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | #endif |
| 133 | |
| 134 | int board_init(void) |
| 135 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 136 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 137 | CONFIG_SYS_CCI400_OFFSET); |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 138 | |
| 139 | /* Set CCI-400 control override register to enable barrier |
| 140 | * transaction */ |
Rajesh Bhagat | 45d8a54 | 2018-11-05 18:03:04 +0000 | [diff] [blame] | 141 | if (current_el() == 3) |
| 142 | out_le32(&cci->ctrl_ord, |
| 143 | CCI400_CTRLORD_EN_BARRIER); |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 144 | |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 145 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 146 | erratum_a010315(); |
| 147 | #endif |
| 148 | |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 149 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 150 | gd->env_addr = (ulong)&default_environment[0]; |
| 151 | #endif |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 152 | |
Rajesh Bhagat | bf39fe6 | 2018-11-05 18:02:59 +0000 | [diff] [blame] | 153 | #ifdef CONFIG_FSL_CAAM |
| 154 | sec_init(); |
| 155 | #endif |
| 156 | |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 157 | #ifdef CONFIG_FSL_LS_PPA |
| 158 | ppa_init(); |
| 159 | #endif |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
Yangbo Lu | 4bb1aee | 2017-01-17 10:43:55 +0800 | [diff] [blame] | 163 | int esdhc_status_fixup(void *blob, const char *compat) |
| 164 | { |
| 165 | char esdhc0_path[] = "/soc/esdhc@1560000"; |
| 166 | char esdhc1_path[] = "/soc/esdhc@1580000"; |
| 167 | u8 card_id; |
| 168 | |
| 169 | do_fixup_by_path(blob, esdhc0_path, "status", "okay", |
| 170 | sizeof("okay"), 1); |
| 171 | |
| 172 | /* |
| 173 | * The Presence Detect 2 register detects the installation |
| 174 | * of cards in various PCI Express or SGMII slots. |
| 175 | * |
| 176 | * STAT_PRS2[7:5]: Specifies the type of card installed in the |
| 177 | * SDHC2 Adapter slot. 0b111 indicates no adapter is installed. |
| 178 | */ |
| 179 | card_id = (QIXIS_READ(present2) & 0xe0) >> 5; |
| 180 | |
| 181 | /* If no adapter is installed in SDHC2, disable SDHC2 */ |
| 182 | if (card_id == 0x7) |
| 183 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 184 | sizeof("disabled"), 1); |
| 185 | else |
| 186 | do_fixup_by_path(blob, esdhc1_path, "status", "okay", |
| 187 | sizeof("okay"), 1); |
| 188 | return 0; |
| 189 | } |
| 190 | |
Calvin Johnson | f661502 | 2018-03-08 15:30:28 +0530 | [diff] [blame] | 191 | static int pfe_set_properties(void *set_blob, struct pfe_prop_val prop_val, |
| 192 | char *enet_path, char *mdio_path) |
| 193 | { |
| 194 | do_fixup_by_path(set_blob, enet_path, "fsl,gemac-bus-id", |
| 195 | &prop_val.busid, PFE_PROP_LEN, 1); |
| 196 | do_fixup_by_path(set_blob, enet_path, "fsl,gemac-phy-id", |
| 197 | &prop_val.phyid, PFE_PROP_LEN, 1); |
| 198 | do_fixup_by_path(set_blob, enet_path, "fsl,mdio-mux-val", |
| 199 | &prop_val.mux_val, PFE_PROP_LEN, 1); |
| 200 | do_fixup_by_path(set_blob, enet_path, "phy-mode", |
| 201 | prop_val.phy_mode, strlen(prop_val.phy_mode) + 1, 1); |
| 202 | do_fixup_by_path(set_blob, mdio_path, "fsl,mdio-phy-mask", |
| 203 | &prop_val.phy_mask, PFE_PROP_LEN, 1); |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static void fdt_fsl_fixup_of_pfe(void *blob) |
| 208 | { |
| 209 | int i = 0; |
| 210 | struct pfe_prop_val prop_val; |
| 211 | void *l_blob = blob; |
| 212 | |
| 213 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 214 | unsigned int srds_s1 = in_be32(&gur->rcwsr[4]) & |
| 215 | FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK; |
| 216 | srds_s1 >>= FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT; |
| 217 | |
| 218 | for (i = 0; i < NUM_ETH_NODE; i++) { |
| 219 | switch (srds_s1) { |
| 220 | case SERDES_1_G_PROTOCOL: |
| 221 | if (i == 0) { |
| 222 | prop_val.busid = cpu_to_fdt32( |
| 223 | ETH_1_1G_BUS_ID); |
| 224 | prop_val.phyid = cpu_to_fdt32( |
| 225 | ETH_1_1G_PHY_ID); |
| 226 | prop_val.mux_val = cpu_to_fdt32( |
| 227 | ETH_1_1G_MDIO_MUX); |
| 228 | prop_val.phy_mask = cpu_to_fdt32( |
| 229 | ETH_1G_MDIO_PHY_MASK); |
| 230 | prop_val.phy_mode = "sgmii"; |
| 231 | pfe_set_properties(l_blob, prop_val, ETH_1_PATH, |
| 232 | ETH_1_MDIO); |
| 233 | } else { |
| 234 | prop_val.busid = cpu_to_fdt32( |
| 235 | ETH_2_1G_BUS_ID); |
| 236 | prop_val.phyid = cpu_to_fdt32( |
| 237 | ETH_2_1G_PHY_ID); |
| 238 | prop_val.mux_val = cpu_to_fdt32( |
| 239 | ETH_2_1G_MDIO_MUX); |
| 240 | prop_val.phy_mask = cpu_to_fdt32( |
| 241 | ETH_1G_MDIO_PHY_MASK); |
| 242 | prop_val.phy_mode = "rgmii"; |
| 243 | pfe_set_properties(l_blob, prop_val, ETH_2_PATH, |
| 244 | ETH_2_MDIO); |
| 245 | } |
| 246 | break; |
| 247 | case SERDES_2_5_G_PROTOCOL: |
| 248 | if (i == 0) { |
| 249 | prop_val.busid = cpu_to_fdt32( |
| 250 | ETH_1_2_5G_BUS_ID); |
| 251 | prop_val.phyid = cpu_to_fdt32( |
| 252 | ETH_1_2_5G_PHY_ID); |
| 253 | prop_val.mux_val = cpu_to_fdt32( |
| 254 | ETH_1_2_5G_MDIO_MUX); |
| 255 | prop_val.phy_mask = cpu_to_fdt32( |
| 256 | ETH_2_5G_MDIO_PHY_MASK); |
| 257 | prop_val.phy_mode = "sgmii-2500"; |
| 258 | pfe_set_properties(l_blob, prop_val, ETH_1_PATH, |
| 259 | ETH_1_MDIO); |
| 260 | } else { |
| 261 | prop_val.busid = cpu_to_fdt32( |
| 262 | ETH_2_2_5G_BUS_ID); |
| 263 | prop_val.phyid = cpu_to_fdt32( |
| 264 | ETH_2_2_5G_PHY_ID); |
| 265 | prop_val.mux_val = cpu_to_fdt32( |
| 266 | ETH_2_2_5G_MDIO_MUX); |
| 267 | prop_val.phy_mask = cpu_to_fdt32( |
| 268 | ETH_2_5G_MDIO_PHY_MASK); |
| 269 | prop_val.phy_mode = "sgmii-2500"; |
| 270 | pfe_set_properties(l_blob, prop_val, ETH_2_PATH, |
| 271 | ETH_2_MDIO); |
| 272 | } |
| 273 | break; |
| 274 | default: |
| 275 | printf("serdes:[%d]\n", srds_s1); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 280 | #ifdef CONFIG_OF_BOARD_SETUP |
| 281 | int ft_board_setup(void *blob, bd_t *bd) |
| 282 | { |
| 283 | arch_fixup_fdt(blob); |
| 284 | |
| 285 | ft_cpu_setup(blob, bd); |
Calvin Johnson | f661502 | 2018-03-08 15:30:28 +0530 | [diff] [blame] | 286 | fdt_fsl_fixup_of_pfe(blob); |
Prabhakar Kushwaha | 5543250 | 2016-06-03 18:41:34 +0530 | [diff] [blame] | 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | #endif |