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