Tim Harvey | 03bf843 | 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 | 77f6dab | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 6 | #include <fdt_support.h> |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 7 | #include <init.h> |
| 8 | #include <led.h> |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 9 | #include <miiphy.h> |
Tim Harvey | 2395625 | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 11 | #include <asm/arch/sys_proto.h> |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 12 | |
Tim Harvey | fb9ec33 | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 13 | #include "eeprom.h" |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 14 | |
| 15 | int board_phys_sdram_size(phys_size_t *size) |
| 16 | { |
Tim Harvey | 52ae8d6 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 17 | if (!size) |
Tim Harvey | 692c25e | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 18 | return -EINVAL; |
| 19 | |
Tim Harvey | 52ae8d6 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 20 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | int board_fit_config_name_match(const char *name) |
| 26 | { |
| 27 | int i = 0; |
| 28 | const char *dtb; |
Tim Harvey | 9d2e639 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 29 | static char init; |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 30 | char buf[32]; |
| 31 | |
| 32 | do { |
Tim Harvey | fb9ec33 | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 33 | dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 9d2e639 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 34 | if (!strcmp(dtb, name)) { |
| 35 | if (!init++) |
| 36 | printf("DTB : %s\n", name); |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 37 | return 0; |
Tim Harvey | 9d2e639 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 38 | } |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 39 | } while (dtb); |
| 40 | |
| 41 | return -1; |
| 42 | } |
| 43 | |
Simon Glass | 9c097f8 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 44 | static int __maybe_unused setup_fec(void) |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 45 | { |
| 46 | struct iomuxc_gpr_base_regs *gpr = |
| 47 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 48 | |
Tim Harvey | 2395625 | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 49 | #ifndef CONFIG_IMX8MP |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 50 | /* Use 125M anatop REF_CLK1 for ENET1, not from external */ |
| 51 | clrsetbits_le32(&gpr->gpr[1], 0x2000, 0); |
Tim Harvey | 2395625 | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 52 | #else |
| 53 | /* Enable RGMII TX clk output */ |
| 54 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 55 | #endif |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Simon Glass | 9c097f8 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 60 | #if (IS_ENABLED(CONFIG_NET)) |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 61 | int board_phy_config(struct phy_device *phydev) |
| 62 | { |
| 63 | unsigned short val; |
| 64 | |
| 65 | switch (phydev->phy_id) { |
| 66 | case 0x2000a231: /* TI DP83867 GbE PHY */ |
| 67 | puts("DP83867 "); |
| 68 | /* LED configuration */ |
| 69 | val = 0; |
| 70 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 71 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 72 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | if (phydev->drv->config) |
| 77 | phydev->drv->config(phydev); |
| 78 | |
| 79 | return 0; |
| 80 | } |
Tim Harvey | 2395625 | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 81 | #endif // IS_ENABLED(CONFIG_NET) |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 82 | |
| 83 | int board_init(void) |
| 84 | { |
Tim Harvey | 37d5bf4 | 2022-08-11 12:04:01 -0700 | [diff] [blame] | 85 | venice_eeprom_init(1); |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 86 | |
| 87 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 88 | setup_fec(); |
| 89 | |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int board_late_init(void) |
| 94 | { |
Tim Harvey | 0f3f6e6 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 95 | const char *str; |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 96 | char env[32]; |
| 97 | int ret, i; |
| 98 | u8 enetaddr[6]; |
Tim Harvey | 0f3f6e6 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 99 | char fdt[64]; |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 100 | |
Tim Harvey | 57d27aa | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 101 | /* Set board serial/model */ |
Tim Harvey | 45e82c3 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 102 | if (!env_get("serial#")) |
Tim Harvey | fb9ec33 | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 103 | env_set_ulong("serial#", eeprom_get_serial()); |
| 104 | env_set("model", eeprom_get_model()); |
Tim Harvey | 57d27aa | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 105 | |
Tim Harvey | 0f3f6e6 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 106 | /* Set fdt_file vars */ |
| 107 | i = 0; |
| 108 | do { |
Tim Harvey | fb9ec33 | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 109 | str = eeprom_get_dtb_name(i, fdt, sizeof(fdt)); |
Tim Harvey | 0f3f6e6 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 110 | if (str) { |
| 111 | sprintf(env, "fdt_file%d", i + 1); |
| 112 | strcat(fdt, ".dtb"); |
| 113 | env_set(env, fdt); |
| 114 | } |
| 115 | i++; |
| 116 | } while (str); |
| 117 | |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 118 | /* Set mac addrs */ |
| 119 | i = 0; |
| 120 | do { |
| 121 | if (i) |
| 122 | sprintf(env, "eth%daddr", i); |
| 123 | else |
| 124 | sprintf(env, "ethaddr"); |
Tim Harvey | 0f3f6e6 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 125 | str = env_get(env); |
| 126 | if (!str) { |
Tim Harvey | fb9ec33 | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 127 | ret = eeprom_getmac(i, enetaddr); |
Tim Harvey | 03bf843 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 128 | if (!ret) |
| 129 | eth_env_set_enetaddr(env, enetaddr); |
| 130 | } |
| 131 | i++; |
| 132 | } while (!ret); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int board_mmc_get_env_dev(int devno) |
| 138 | { |
| 139 | return devno; |
| 140 | } |
Tim Harvey | 2eb8564 | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 141 | |
Tim Harvey | 77f6dab | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 142 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Tim Harvey | 2eb8564 | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 143 | { |
Tim Harvey | 77f6dab | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 144 | const char *base_model = eeprom_get_baseboard_model(); |
| 145 | char pcbrev; |
Tim Harvey | f8a792e | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 146 | int off; |
| 147 | |
Tim Harvey | 2eb8564 | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 148 | /* set board model dt prop */ |
Tim Harvey | 77f6dab | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 149 | fdt_setprop_string(fdt, 0, "board", eeprom_get_model()); |
Tim Harvey | 2eb8564 | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 150 | |
Tim Harvey | 77f6dab | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 151 | if (!strncmp(base_model, "GW73", 4)) { |
| 152 | pcbrev = get_pcb_rev(base_model); |
| 153 | |
| 154 | if (pcbrev > 'B') { |
| 155 | printf("adjusting dt for %s\n", base_model); |
| 156 | |
| 157 | /* |
| 158 | * revC replaced PCIe 5-port switch with 4-port |
| 159 | * which changed ethernet1 PCIe GbE |
| 160 | * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0 |
| 161 | * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0 |
| 162 | */ |
| 163 | off = fdt_path_offset(fdt, "ethernet1"); |
| 164 | if (off > 0) { |
| 165 | u32 reg[5]; |
| 166 | |
| 167 | fdt_set_name(fdt, off, "pcie@5,0"); |
| 168 | off = fdt_parent_offset(fdt, off); |
| 169 | fdt_set_name(fdt, off, "pcie@2,3"); |
| 170 | memset(reg, 0, sizeof(reg)); |
| 171 | reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0)); |
| 172 | fdt_setprop(fdt, off, "reg", reg, sizeof(reg)); |
| 173 | } |
Tim Harvey | f8a792e | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
Tim Harvey | 2eb8564 | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 177 | return 0; |
| 178 | } |