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 | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 9 | #include <miiphy.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 11 | #include <asm/arch/sys_proto.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 12 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 13 | #include "eeprom.h" |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 14 | |
| 15 | int board_phys_sdram_size(phys_size_t *size) |
| 16 | { |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 17 | if (!size) |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 18 | return -EINVAL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 19 | |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 20 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
Tim Harvey | 256dba0 | 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 | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 29 | static char init; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 30 | char buf[32]; |
| 31 | |
| 32 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 33 | dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 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 | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 37 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 38 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 39 | } while (dtb); |
| 40 | |
| 41 | return -1; |
| 42 | } |
| 43 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 44 | #if (IS_ENABLED(CONFIG_NET)) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 45 | static int setup_fec(void) |
| 46 | { |
| 47 | struct iomuxc_gpr_base_regs *gpr = |
| 48 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 49 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 50 | #ifndef CONFIG_IMX8MP |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 51 | /* Use 125M anatop REF_CLK1 for ENET1, not from external */ |
| 52 | clrsetbits_le32(&gpr->gpr[1], 0x2000, 0); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 53 | #else |
| 54 | /* Enable RGMII TX clk output */ |
| 55 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 56 | #endif |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 61 | static int setup_eqos(void) |
| 62 | { |
| 63 | struct iomuxc_gpr_base_regs *gpr = |
| 64 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 65 | |
| 66 | /* set INTF as RGMII, enable RGMII TXC clock */ |
| 67 | clrsetbits_le32(&gpr->gpr[1], |
| 68 | IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16)); |
| 69 | setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21)); |
| 70 | |
| 71 | return set_clk_eqos(ENET_125MHZ); |
| 72 | } |
| 73 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 74 | int board_phy_config(struct phy_device *phydev) |
| 75 | { |
| 76 | unsigned short val; |
Tim Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame] | 77 | ofnode node; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 78 | |
| 79 | switch (phydev->phy_id) { |
| 80 | case 0x2000a231: /* TI DP83867 GbE PHY */ |
| 81 | puts("DP83867 "); |
| 82 | /* LED configuration */ |
| 83 | val = 0; |
| 84 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 85 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 86 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 87 | break; |
Tim Harvey | a82c8ff | 2022-03-08 10:47:44 -0800 | [diff] [blame] | 88 | case 0xd565a401: /* MaxLinear GPY111 */ |
| 89 | puts("GPY111 "); |
| 90 | node = phy_get_ofnode(phydev); |
| 91 | if (ofnode_valid(node)) { |
| 92 | u32 rx_delay, tx_delay; |
| 93 | |
| 94 | rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000); |
| 95 | tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000); |
| 96 | val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17); |
| 97 | val &= ~((0x7 << 12) | (0x7 << 8)); |
| 98 | val |= (rx_delay / 500) << 12; |
| 99 | val |= (tx_delay / 500) << 8; |
| 100 | phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val); |
| 101 | } |
| 102 | break; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | if (phydev->drv->config) |
| 106 | phydev->drv->config(phydev); |
| 107 | |
| 108 | return 0; |
| 109 | } |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 110 | #endif // IS_ENABLED(CONFIG_NET) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 111 | |
| 112 | int board_init(void) |
| 113 | { |
Tim Harvey | 1fec182 | 2022-08-11 12:04:01 -0700 | [diff] [blame] | 114 | venice_eeprom_init(1); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 115 | |
| 116 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 117 | setup_fec(); |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 118 | if (IS_ENABLED(CONFIG_DWC_ETH_QOS)) |
| 119 | setup_eqos(); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 120 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int board_late_init(void) |
| 125 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 126 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 127 | char env[32]; |
| 128 | int ret, i; |
| 129 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 130 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 131 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 132 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 133 | if (!env_get("serial#")) |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 134 | env_set_ulong("serial#", eeprom_get_serial()); |
| 135 | env_set("model", eeprom_get_model()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 136 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 137 | /* Set fdt_file vars */ |
| 138 | i = 0; |
| 139 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 140 | str = eeprom_get_dtb_name(i, fdt, sizeof(fdt)); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 141 | if (str) { |
| 142 | sprintf(env, "fdt_file%d", i + 1); |
| 143 | strcat(fdt, ".dtb"); |
| 144 | env_set(env, fdt); |
| 145 | } |
| 146 | i++; |
| 147 | } while (str); |
| 148 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 149 | /* Set mac addrs */ |
| 150 | i = 0; |
| 151 | do { |
| 152 | if (i) |
| 153 | sprintf(env, "eth%daddr", i); |
| 154 | else |
| 155 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 156 | str = env_get(env); |
| 157 | if (!str) { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 158 | ret = eeprom_getmac(i, enetaddr); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 159 | if (!ret) |
| 160 | eth_env_set_enetaddr(env, enetaddr); |
| 161 | } |
| 162 | i++; |
| 163 | } while (!ret); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | int board_mmc_get_env_dev(int devno) |
| 169 | { |
| 170 | return devno; |
| 171 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 172 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 173 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 174 | { |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 175 | const char *base_model = eeprom_get_baseboard_model(); |
| 176 | char pcbrev; |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 177 | int off; |
| 178 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 179 | /* set board model dt prop */ |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 180 | fdt_setprop_string(fdt, 0, "board", eeprom_get_model()); |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 181 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 182 | if (!strncmp(base_model, "GW73", 4)) { |
| 183 | pcbrev = get_pcb_rev(base_model); |
| 184 | |
| 185 | if (pcbrev > 'B') { |
| 186 | printf("adjusting dt for %s\n", base_model); |
| 187 | |
| 188 | /* |
| 189 | * revC replaced PCIe 5-port switch with 4-port |
| 190 | * which changed ethernet1 PCIe GbE |
| 191 | * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0 |
| 192 | * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0 |
| 193 | */ |
| 194 | off = fdt_path_offset(fdt, "ethernet1"); |
| 195 | if (off > 0) { |
| 196 | u32 reg[5]; |
| 197 | |
| 198 | fdt_set_name(fdt, off, "pcie@5,0"); |
| 199 | off = fdt_parent_offset(fdt, off); |
| 200 | fdt_set_name(fdt, off, "pcie@2,3"); |
| 201 | memset(reg, 0, sizeof(reg)); |
| 202 | reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0)); |
| 203 | fdt_setprop(fdt, off, "reg", reg, sizeof(reg)); |
| 204 | } |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 208 | return 0; |
| 209 | } |