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 | 0de4f2c | 2023-05-02 17:05:54 -0700 | [diff] [blame^] | 10 | #include <mmc.h> |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 12 | #include <asm/arch/sys_proto.h> |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 13 | |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 14 | #include "eeprom.h" |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 15 | |
| 16 | int board_phys_sdram_size(phys_size_t *size) |
| 17 | { |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 18 | if (!size) |
Tim Harvey | 195a161 | 2021-07-27 15:19:37 -0700 | [diff] [blame] | 19 | return -EINVAL; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 20 | |
Tim Harvey | 56c5e31 | 2022-03-30 13:39:02 -0700 | [diff] [blame] | 21 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | int board_fit_config_name_match(const char *name) |
| 27 | { |
| 28 | int i = 0; |
| 29 | const char *dtb; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 30 | static char init; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 31 | char buf[32]; |
| 32 | |
| 33 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 34 | dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf)); |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 35 | if (!strcmp(dtb, name)) { |
| 36 | if (!init++) |
| 37 | printf("DTB : %s\n", name); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 38 | return 0; |
Tim Harvey | 637b8b1 | 2021-06-30 17:07:40 -0700 | [diff] [blame] | 39 | } |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 40 | } while (dtb); |
| 41 | |
| 42 | return -1; |
| 43 | } |
| 44 | |
Simon Glass | a2d4210 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 45 | static int __maybe_unused setup_fec(void) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 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 | |
Simon Glass | a2d4210 | 2023-02-22 09:34:24 -0700 | [diff] [blame] | 61 | #if (IS_ENABLED(CONFIG_NET)) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 62 | int board_phy_config(struct phy_device *phydev) |
| 63 | { |
| 64 | unsigned short val; |
| 65 | |
| 66 | switch (phydev->phy_id) { |
| 67 | case 0x2000a231: /* TI DP83867 GbE PHY */ |
| 68 | puts("DP83867 "); |
| 69 | /* LED configuration */ |
| 70 | val = 0; |
| 71 | val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */ |
| 72 | val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */ |
| 73 | phy_write(phydev, MDIO_DEVAD_NONE, 24, val); |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | if (phydev->drv->config) |
| 78 | phydev->drv->config(phydev); |
| 79 | |
| 80 | return 0; |
| 81 | } |
Tim Harvey | 0f5717f | 2022-04-13 11:31:09 -0700 | [diff] [blame] | 82 | #endif // IS_ENABLED(CONFIG_NET) |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 83 | |
| 84 | int board_init(void) |
| 85 | { |
Tim Harvey | 1fec182 | 2022-08-11 12:04:01 -0700 | [diff] [blame] | 86 | venice_eeprom_init(1); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 87 | |
| 88 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 89 | setup_fec(); |
| 90 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | int board_late_init(void) |
| 95 | { |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 96 | const char *str; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 97 | char env[32]; |
| 98 | int ret, i; |
| 99 | u8 enetaddr[6]; |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 100 | char fdt[64]; |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 101 | |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 102 | /* Set board serial/model */ |
Tim Harvey | 62a1319 | 2021-08-18 15:24:28 -0700 | [diff] [blame] | 103 | if (!env_get("serial#")) |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 104 | env_set_ulong("serial#", eeprom_get_serial()); |
| 105 | env_set("model", eeprom_get_model()); |
Tim Harvey | 78b8e07 | 2021-07-27 15:19:39 -0700 | [diff] [blame] | 106 | |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 107 | /* Set fdt_file vars */ |
| 108 | i = 0; |
| 109 | do { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 110 | str = eeprom_get_dtb_name(i, fdt, sizeof(fdt)); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 111 | if (str) { |
| 112 | sprintf(env, "fdt_file%d", i + 1); |
| 113 | strcat(fdt, ".dtb"); |
| 114 | env_set(env, fdt); |
| 115 | } |
| 116 | i++; |
| 117 | } while (str); |
| 118 | |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 119 | /* Set mac addrs */ |
| 120 | i = 0; |
| 121 | do { |
| 122 | if (i) |
| 123 | sprintf(env, "eth%daddr", i); |
| 124 | else |
| 125 | sprintf(env, "ethaddr"); |
Tim Harvey | 6890157 | 2021-06-30 17:07:41 -0700 | [diff] [blame] | 126 | str = env_get(env); |
| 127 | if (!str) { |
Tim Harvey | d4daeaa | 2022-04-13 08:56:40 -0700 | [diff] [blame] | 128 | ret = eeprom_getmac(i, enetaddr); |
Tim Harvey | 256dba0 | 2021-03-02 14:00:21 -0800 | [diff] [blame] | 129 | if (!ret) |
| 130 | eth_env_set_enetaddr(env, enetaddr); |
| 131 | } |
| 132 | i++; |
| 133 | } while (!ret); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int board_mmc_get_env_dev(int devno) |
| 139 | { |
| 140 | return devno; |
| 141 | } |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 142 | |
Tim Harvey | 0de4f2c | 2023-05-02 17:05:54 -0700 | [diff] [blame^] | 143 | uint mmc_get_env_part(struct mmc *mmc) |
| 144 | { |
| 145 | if (!IS_SD(mmc)) { |
| 146 | switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) { |
| 147 | case 1: |
| 148 | return 1; |
| 149 | case 2: |
| 150 | return 2; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 157 | int ft_board_setup(void *fdt, struct bd_info *bd) |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 158 | { |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 159 | const char *base_model = eeprom_get_baseboard_model(); |
| 160 | char pcbrev; |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 161 | int off; |
| 162 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 163 | /* set board model dt prop */ |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 164 | fdt_setprop_string(fdt, 0, "board", eeprom_get_model()); |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 165 | |
Tim Harvey | a6614bb | 2022-08-11 11:55:38 -0700 | [diff] [blame] | 166 | if (!strncmp(base_model, "GW73", 4)) { |
| 167 | pcbrev = get_pcb_rev(base_model); |
| 168 | |
| 169 | if (pcbrev > 'B') { |
| 170 | printf("adjusting dt for %s\n", base_model); |
| 171 | |
| 172 | /* |
| 173 | * revC replaced PCIe 5-port switch with 4-port |
| 174 | * which changed ethernet1 PCIe GbE |
| 175 | * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0 |
| 176 | * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0 |
| 177 | */ |
| 178 | off = fdt_path_offset(fdt, "ethernet1"); |
| 179 | if (off > 0) { |
| 180 | u32 reg[5]; |
| 181 | |
| 182 | fdt_set_name(fdt, off, "pcie@5,0"); |
| 183 | off = fdt_parent_offset(fdt, off); |
| 184 | fdt_set_name(fdt, off, "pcie@2,3"); |
| 185 | memset(reg, 0, sizeof(reg)); |
| 186 | reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0)); |
| 187 | fdt_setprop(fdt, off, "reg", reg, sizeof(reg)); |
| 188 | } |
Tim Harvey | 547f6aa | 2021-08-18 15:24:30 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Tim Harvey | 60c1bfd | 2021-07-27 15:19:40 -0700 | [diff] [blame] | 192 | return 0; |
| 193 | } |