Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2021 Gateworks Corporation |
| 4 | */ |
| 5 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 6 | #include <fdt_support.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 7 | #include <init.h> |
| 8 | #include <led.h> |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 9 | #include <mmc.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 10 | #include <miiphy.h> |
Tim Harvey | 0de4f2c | 2023-05-02 17:05:54 -0700 | [diff] [blame] | 11 | #include <mmc.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 14 | #include <asm/mach-imx/boot_mode.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 15 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 16 | #include "eeprom.h" |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 17 | |
| 18 | int board_phys_sdram_size(phys_size_t *size) |
| 19 | { |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 20 | if (!size) |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 21 | return -EINVAL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 22 | |
Tim Harvey | 5547529 | 2023-06-23 09:44:17 -0700 | [diff] [blame] | 23 | *size = get_ram_size((void *)PHYS_SDRAM, (long)PHYS_SDRAM_SIZE + (long)PHYS_SDRAM_2_SIZE); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
Tim Harvey | b326d46 | 2024-03-12 12:05:43 -0700 | [diff] [blame] | 28 | int board_fit_config_name_match(const char *path) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 29 | { |
Tim Harvey | b326d46 | 2024-03-12 12:05:43 -0700 | [diff] [blame] | 30 | const char *name = path + strlen("freescale/"); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 31 | static char init; |
Tim Harvey | b326d46 | 2024-03-12 12:05:43 -0700 | [diff] [blame] | 32 | const char *dtb; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 33 | char buf[32]; |
Tim Harvey | b326d46 | 2024-03-12 12:05:43 -0700 | [diff] [blame] | 34 | int i = 0; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 35 | |
| 36 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 37 | dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 38 | if (!strcmp(dtb, name)) { |
| 39 | if (!init++) |
| 40 | printf("DTB : %s\n", name); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 41 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 42 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 43 | } while (dtb); |
| 44 | |
| 45 | return -1; |
| 46 | } |
| 47 | |
Simon Glass | a2d4210 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 48 | static int __maybe_unused setup_fec(void) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 49 | { |
| 50 | struct iomuxc_gpr_base_regs *gpr = |
| 51 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 52 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 53 | #ifndef CONFIG_IMX8MP |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 54 | /* Use 125M anatop REF_CLK1 for ENET1, not from external */ |
| 55 | clrsetbits_le32(&gpr->gpr[1], 0x2000, 0); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 56 | #else |
| 57 | /* Enable RGMII TX clk output */ |
| 58 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 59 | #endif |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
Simon Glass | a2d4210 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 64 | #if (IS_ENABLED(CONFIG_NET)) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 65 | int board_phy_config(struct phy_device *phydev) |
| 66 | { |
| 67 | unsigned short val; |
| 68 | |
| 69 | switch (phydev->phy_id) { |
| 70 | case 0x2000a231: /* TI DP83867 GbE PHY */ |
| 71 | puts("DP83867 "); |
| 72 | /* LED configuration */ |
| 73 | val = 0; |
| 74 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 75 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 76 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | if (phydev->drv->config) |
| 81 | phydev->drv->config(phydev); |
| 82 | |
| 83 | return 0; |
| 84 | } |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 85 | #endif // IS_ENABLED(CONFIG_NET) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 86 | |
| 87 | int board_init(void) |
| 88 | { |
Tim Harvey | 1fec182 | 2022-08-11 12:04:01 -0700 | [diff] [blame] | 89 | venice_eeprom_init(1); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 90 | |
| 91 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 92 | setup_fec(); |
| 93 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | int board_late_init(void) |
| 98 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 99 | const char *str; |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 100 | struct mmc *mmc = NULL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 101 | char env[32]; |
| 102 | int ret, i; |
| 103 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 104 | char fdt[64]; |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 105 | int bootdev; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 106 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 107 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 108 | if (!env_get("serial#")) |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 109 | env_set_ulong("serial#", eeprom_get_serial()); |
| 110 | env_set("model", eeprom_get_model()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 111 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 112 | /* Set fdt_file vars */ |
| 113 | i = 0; |
| 114 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 115 | str = eeprom_get_dtb_name(i, fdt, sizeof(fdt)); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 116 | if (str) { |
| 117 | sprintf(env, "fdt_file%d", i + 1); |
| 118 | strcat(fdt, ".dtb"); |
| 119 | env_set(env, fdt); |
| 120 | } |
| 121 | i++; |
| 122 | } while (str); |
| 123 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 124 | /* Set mac addrs */ |
| 125 | i = 0; |
| 126 | do { |
| 127 | if (i) |
| 128 | sprintf(env, "eth%daddr", i); |
| 129 | else |
| 130 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 131 | str = env_get(env); |
| 132 | if (!str) { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 133 | ret = eeprom_getmac(i, enetaddr); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 134 | if (!ret) |
| 135 | eth_env_set_enetaddr(env, enetaddr); |
| 136 | } |
| 137 | i++; |
| 138 | } while (!ret); |
| 139 | |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 140 | /* |
| 141 | * set bootdev/bootblk/bootpart (used in firmware_update script) |
| 142 | * dynamically depending on boot device and SoC |
| 143 | */ |
| 144 | bootdev = -1; |
| 145 | switch (get_boot_device()) { |
| 146 | case SD1_BOOT: |
| 147 | case MMC1_BOOT: /* SDHC1 */ |
| 148 | bootdev = 0; |
| 149 | break; |
| 150 | case SD2_BOOT: |
| 151 | case MMC2_BOOT: /* SDHC2 */ |
| 152 | bootdev = 1; |
| 153 | break; |
| 154 | case SD3_BOOT: |
| 155 | case MMC3_BOOT: /* SDHC3 */ |
| 156 | bootdev = 2; |
| 157 | break; |
| 158 | default: |
Tim Harvey | 8bdb05d | 2023-06-09 09:51:46 -0700 | [diff] [blame] | 159 | bootdev = 2; /* assume SDHC3 (eMMC) if booting over SDP */ |
Tim Harvey | a32dd71 | 2023-05-02 17:05:55 -0700 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | if (bootdev != -1) |
| 163 | mmc = find_mmc_device(bootdev); |
| 164 | if (mmc) { |
| 165 | int bootblk; |
| 166 | |
| 167 | if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) |
| 168 | bootblk = 32 * SZ_1K / 512; |
| 169 | else |
| 170 | bootblk = 33 * SZ_1K / 512; |
| 171 | mmc_init(mmc); |
| 172 | if (!IS_SD(mmc)) { |
| 173 | int bootpart; |
| 174 | |
| 175 | switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) { |
| 176 | case 1: /* boot0 */ |
| 177 | bootpart = 1; |
| 178 | break; |
| 179 | case 2: /* boot1 */ |
| 180 | bootpart = 2; |
| 181 | break; |
| 182 | case 7: /* user */ |
| 183 | default: |
| 184 | bootpart = 0; |
| 185 | break; |
| 186 | } |
| 187 | /* IMX8MP/IMX8MN BOOTROM v2 uses offset=0 for boot parts */ |
| 188 | if ((IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) && |
| 189 | (bootpart == 1 || bootpart == 2)) |
| 190 | bootblk = 0; |
| 191 | env_set_hex("bootpart", bootpart); |
| 192 | env_set_hex("bootblk", bootblk); |
| 193 | } else { /* SD */ |
| 194 | env_set("bootpart", ""); |
| 195 | env_set_hex("bootblk", bootblk); |
| 196 | } |
| 197 | env_set_hex("dev", bootdev); |
| 198 | } |
| 199 | |
| 200 | /* override soc=imx8m to provide a more specific soc name */ |
| 201 | if (IS_ENABLED(CONFIG_IMX8MN)) |
| 202 | env_set("soc", "imx8mn"); |
| 203 | else if (IS_ENABLED(CONFIG_IMX8MP)) |
| 204 | env_set("soc", "imx8mp"); |
| 205 | else if (IS_ENABLED(CONFIG_IMX8MM)) |
| 206 | env_set("soc", "imx8mm"); |
| 207 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | int board_mmc_get_env_dev(int devno) |
| 212 | { |
| 213 | return devno; |
| 214 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 215 | |
Tim Harvey | 0de4f2c | 2023-05-02 17:05:54 -0700 | [diff] [blame] | 216 | uint mmc_get_env_part(struct mmc *mmc) |
| 217 | { |
| 218 | if (!IS_SD(mmc)) { |
| 219 | switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) { |
| 220 | case 1: |
| 221 | return 1; |
| 222 | case 2: |
| 223 | return 2; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 230 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 231 | { |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 232 | const char *base_model = eeprom_get_baseboard_model(); |
Tim Harvey | 9fbf12b | 2024-04-17 13:01:53 -0700 | [diff] [blame] | 233 | const char *path; |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 234 | char pcbrev; |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 235 | int off; |
| 236 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 237 | /* set board model dt prop */ |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 238 | fdt_setprop_string(fdt, 0, "board", eeprom_get_model()); |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 239 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 240 | if (!strncmp(base_model, "GW73", 4)) { |
| 241 | pcbrev = get_pcb_rev(base_model); |
Tim Harvey | 9fbf12b | 2024-04-17 13:01:53 -0700 | [diff] [blame] | 242 | path = fdt_get_alias(fdt, "ethernet1"); |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 243 | |
Tim Harvey | 9fbf12b | 2024-04-17 13:01:53 -0700 | [diff] [blame] | 244 | if (pcbrev > 'B' && pcbrev < 'E' && path && !strncmp(path, "/soc@0/pcie@", 12)) { |
| 245 | printf("adjusting %s pcie\n", base_model); |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 246 | /* |
Tim Harvey | 3dfc10b | 2023-10-18 11:33:06 -0700 | [diff] [blame] | 247 | * revC/D/E has PCIe 4-port switch which changes |
| 248 | * ethernet1 PCIe GbE: |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 249 | * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0 |
| 250 | * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0 |
| 251 | */ |
| 252 | off = fdt_path_offset(fdt, "ethernet1"); |
| 253 | if (off > 0) { |
| 254 | u32 reg[5]; |
| 255 | |
| 256 | fdt_set_name(fdt, off, "pcie@5,0"); |
| 257 | off = fdt_parent_offset(fdt, off); |
| 258 | fdt_set_name(fdt, off, "pcie@2,3"); |
| 259 | memset(reg, 0, sizeof(reg)); |
| 260 | reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0)); |
| 261 | fdt_setprop(fdt, off, "reg", reg, sizeof(reg)); |
| 262 | } |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 266 | return 0; |
| 267 | } |