Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
| 4 | * |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 5 | * Portions based on U-Boot's rtl8169.c. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * This driver supports the Synopsys Designware Ethernet QOS (Quality Of |
| 10 | * Service) IP block. The IP supports multiple options for bus type, clocking/ |
| 11 | * reset structure, and feature list. |
| 12 | * |
| 13 | * The driver is written such that generic core logic is kept separate from |
| 14 | * configuration-specific logic. Code that interacts with configuration- |
| 15 | * specific resources is split out into separate functions to avoid polluting |
| 16 | * common code. If/when this driver is enhanced to support multiple |
| 17 | * configurations, the core code should be adapted to call all configuration- |
| 18 | * specific functions through function pointers, with the definition of those |
| 19 | * function pointers being supplied by struct udevice_id eqos_ids[]'s .data |
| 20 | * field. |
| 21 | * |
| 22 | * The following configurations are currently supported: |
| 23 | * tegra186: |
| 24 | * NVIDIA's Tegra186 chip. This configuration uses an AXI master/DMA bus, an |
| 25 | * AHB slave/register bus, contains the DMA, MTL, and MAC sub-blocks, and |
| 26 | * supports a single RGMII PHY. This configuration also has SW control over |
| 27 | * all clock and reset signals to the HW block. |
| 28 | */ |
Patrick Delaunay | 9e6ed38 | 2020-09-09 18:30:06 +0200 | [diff] [blame] | 29 | |
Patrick Delaunay | 5787284 | 2021-07-20 20:15:29 +0200 | [diff] [blame] | 30 | #define LOG_CATEGORY UCLASS_ETH |
| 31 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 32 | #include <clk.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 33 | #include <cpu_func.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 34 | #include <dm.h> |
Philip Oberfichtner | d6d22da | 2024-08-02 11:25:37 +0200 | [diff] [blame] | 35 | #include <dm/device_compat.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 36 | #include <errno.h> |
Patrick Delaunay | 4172927 | 2022-06-30 11:09:41 +0200 | [diff] [blame] | 37 | #include <eth_phy.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 38 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 39 | #include <malloc.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 40 | #include <memalign.h> |
| 41 | #include <miiphy.h> |
| 42 | #include <net.h> |
| 43 | #include <netdev.h> |
| 44 | #include <phy.h> |
| 45 | #include <reset.h> |
| 46 | #include <wait_bit.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 47 | #include <asm/cache.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 48 | #include <asm/gpio.h> |
| 49 | #include <asm/io.h> |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 50 | #ifdef CONFIG_ARCH_IMX8M |
| 51 | #include <asm/arch/clock.h> |
| 52 | #include <asm/mach-imx/sys_proto.h> |
| 53 | #endif |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 54 | #include <linux/bitfield.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 55 | #include <linux/delay.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 56 | #include <linux/printk.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 57 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 58 | #include "dwc_eth_qos.h" |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * TX and RX descriptors are 16 bytes. This causes problems with the cache |
| 62 | * maintenance on CPUs where the cache-line size exceeds the size of these |
| 63 | * descriptors. What will happen is that when the driver receives a packet |
| 64 | * it will be immediately requeued for the hardware to reuse. The CPU will |
| 65 | * therefore need to flush the cache-line containing the descriptor, which |
| 66 | * will cause all other descriptors in the same cache-line to be flushed |
| 67 | * along with it. If one of those descriptors had been written to by the |
| 68 | * device those changes (and the associated packet) will be lost. |
| 69 | * |
| 70 | * To work around this, we make use of non-cached memory if available. If |
| 71 | * descriptors are mapped uncached there's no need to manually flush them |
| 72 | * or invalidate them. |
| 73 | * |
| 74 | * Note that this only applies to descriptors. The packet data buffers do |
| 75 | * not have the same constraints since they are 1536 bytes large, so they |
| 76 | * are unlikely to share cache-lines. |
| 77 | */ |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 78 | static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 79 | { |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 80 | return memalign(ARCH_DMA_MINALIGN, num * eqos->desc_size); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void eqos_free_descs(void *descs) |
| 84 | { |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 85 | free(descs); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 86 | } |
| 87 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 88 | static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos, |
| 89 | unsigned int num, bool rx) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 90 | { |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 91 | return (rx ? eqos->rx_descs : eqos->tx_descs) + |
| 92 | (num * eqos->desc_size); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 95 | void eqos_inval_desc_generic(void *desc) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 96 | { |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 97 | unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 98 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 99 | ARCH_DMA_MINALIGN); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 100 | |
| 101 | invalidate_dcache_range(start, end); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 102 | } |
| 103 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 104 | void eqos_flush_desc_generic(void *desc) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 105 | { |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 106 | unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 107 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 108 | ARCH_DMA_MINALIGN); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 109 | |
| 110 | flush_dcache_range(start, end); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Marek Vasut | 7b6fec2 | 2023-03-06 15:53:45 +0100 | [diff] [blame] | 113 | static void eqos_inval_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 114 | { |
| 115 | unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1); |
| 116 | unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN); |
| 117 | |
| 118 | invalidate_dcache_range(start, end); |
| 119 | } |
| 120 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 121 | void eqos_inval_buffer_generic(void *buf, size_t size) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 122 | { |
| 123 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 124 | unsigned long end = roundup((unsigned long)buf + size, |
| 125 | ARCH_DMA_MINALIGN); |
| 126 | |
| 127 | invalidate_dcache_range(start, end); |
| 128 | } |
| 129 | |
| 130 | static void eqos_flush_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 131 | { |
| 132 | flush_cache((unsigned long)buf, size); |
| 133 | } |
| 134 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 135 | void eqos_flush_buffer_generic(void *buf, size_t size) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 136 | { |
| 137 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 138 | unsigned long end = roundup((unsigned long)buf + size, |
| 139 | ARCH_DMA_MINALIGN); |
| 140 | |
| 141 | flush_dcache_range(start, end); |
| 142 | } |
| 143 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 144 | static int eqos_mdio_wait_idle(struct eqos_priv *eqos) |
| 145 | { |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 146 | return wait_for_bit_le32(&eqos->mac_regs->mdio_address, |
| 147 | EQOS_MAC_MDIO_ADDRESS_GB, false, |
| 148 | 1000000, true); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 149 | } |
| 150 | |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 151 | /* Bitmask common for mdio_read and mdio_write */ |
| 152 | #define EQOS_MDIO_BITFIELD(pa, rda, cr) \ |
| 153 | FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_PA_MASK, pa) | \ |
| 154 | FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_RDA_MASK, rda) | \ |
| 155 | FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_CR_MASK, cr) | \ |
| 156 | EQOS_MAC_MDIO_ADDRESS_GB |
| 157 | |
| 158 | static u32 eqos_mdio_bitfield(struct eqos_priv *eqos, int addr, int devad, int reg) |
| 159 | { |
| 160 | int cr = eqos->config->config_mac_mdio; |
| 161 | bool c22 = devad == MDIO_DEVAD_NONE ? true : false; |
| 162 | |
| 163 | if (c22) |
| 164 | return EQOS_MDIO_BITFIELD(addr, reg, cr); |
| 165 | else |
| 166 | return EQOS_MDIO_BITFIELD(addr, devad, cr) | |
| 167 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 168 | } |
| 169 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 170 | static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 171 | int mdio_reg) |
| 172 | { |
| 173 | struct eqos_priv *eqos = bus->priv; |
| 174 | u32 val; |
| 175 | int ret; |
| 176 | |
| 177 | debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr, |
| 178 | mdio_reg); |
| 179 | |
| 180 | ret = eqos_mdio_wait_idle(eqos); |
| 181 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 182 | pr_err("MDIO not idle at entry\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | val = readl(&eqos->mac_regs->mdio_address); |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 187 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP; |
| 188 | |
| 189 | val |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) | |
| 190 | FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK, |
| 191 | EQOS_MAC_MDIO_ADDRESS_GOC_READ); |
| 192 | |
| 193 | if (val & EQOS_MAC_MDIO_ADDRESS_C45E) { |
| 194 | writel(FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg), |
| 195 | &eqos->mac_regs->mdio_data); |
| 196 | } |
| 197 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 198 | writel(val, &eqos->mac_regs->mdio_address); |
| 199 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 200 | udelay(eqos->config->mdio_wait); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 201 | |
| 202 | ret = eqos_mdio_wait_idle(eqos); |
| 203 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 204 | pr_err("MDIO read didn't complete\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | val = readl(&eqos->mac_regs->mdio_data); |
| 209 | val &= EQOS_MAC_MDIO_DATA_GD_MASK; |
| 210 | |
| 211 | debug("%s: val=%x\n", __func__, val); |
| 212 | |
| 213 | return val; |
| 214 | } |
| 215 | |
| 216 | static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 217 | int mdio_reg, u16 mdio_val) |
| 218 | { |
| 219 | struct eqos_priv *eqos = bus->priv; |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 220 | u32 v_addr; |
| 221 | u32 v_data; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 222 | int ret; |
| 223 | |
| 224 | debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev, |
| 225 | mdio_addr, mdio_reg, mdio_val); |
| 226 | |
| 227 | ret = eqos_mdio_wait_idle(eqos); |
| 228 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 229 | pr_err("MDIO not idle at entry\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 230 | return ret; |
| 231 | } |
| 232 | |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 233 | v_addr = readl(&eqos->mac_regs->mdio_address); |
| 234 | v_addr &= EQOS_MAC_MDIO_ADDRESS_SKAP; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 235 | |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 236 | v_addr |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) | |
| 237 | FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK, |
| 238 | EQOS_MAC_MDIO_ADDRESS_GOC_WRITE); |
| 239 | |
| 240 | v_data = mdio_val; |
| 241 | if (v_addr & EQOS_MAC_MDIO_ADDRESS_C45E) |
| 242 | v_data |= FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 243 | |
Philip Oberfichtner | abed372 | 2024-05-07 11:42:37 +0200 | [diff] [blame] | 244 | writel(v_data, &eqos->mac_regs->mdio_data); |
| 245 | writel(v_addr, &eqos->mac_regs->mdio_address); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 246 | udelay(eqos->config->mdio_wait); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 247 | |
| 248 | ret = eqos_mdio_wait_idle(eqos); |
| 249 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 250 | pr_err("MDIO read didn't complete\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 251 | return ret; |
| 252 | } |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int eqos_start_clks_tegra186(struct udevice *dev) |
| 258 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 259 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 260 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 261 | int ret; |
| 262 | |
| 263 | debug("%s(dev=%p):\n", __func__, dev); |
| 264 | |
| 265 | ret = clk_enable(&eqos->clk_slave_bus); |
| 266 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 267 | pr_err("clk_enable(clk_slave_bus) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 268 | goto err; |
| 269 | } |
| 270 | |
| 271 | ret = clk_enable(&eqos->clk_master_bus); |
| 272 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 273 | pr_err("clk_enable(clk_master_bus) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 274 | goto err_disable_clk_slave_bus; |
| 275 | } |
| 276 | |
| 277 | ret = clk_enable(&eqos->clk_rx); |
| 278 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 279 | pr_err("clk_enable(clk_rx) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 280 | goto err_disable_clk_master_bus; |
| 281 | } |
| 282 | |
| 283 | ret = clk_enable(&eqos->clk_ptp_ref); |
| 284 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 285 | pr_err("clk_enable(clk_ptp_ref) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 286 | goto err_disable_clk_rx; |
| 287 | } |
| 288 | |
| 289 | ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000); |
| 290 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 291 | pr_err("clk_set_rate(clk_ptp_ref) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 292 | goto err_disable_clk_ptp_ref; |
| 293 | } |
| 294 | |
| 295 | ret = clk_enable(&eqos->clk_tx); |
| 296 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 297 | pr_err("clk_enable(clk_tx) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 298 | goto err_disable_clk_ptp_ref; |
| 299 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 300 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 301 | |
| 302 | debug("%s: OK\n", __func__); |
| 303 | return 0; |
| 304 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 305 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 306 | err_disable_clk_ptp_ref: |
| 307 | clk_disable(&eqos->clk_ptp_ref); |
| 308 | err_disable_clk_rx: |
| 309 | clk_disable(&eqos->clk_rx); |
| 310 | err_disable_clk_master_bus: |
| 311 | clk_disable(&eqos->clk_master_bus); |
| 312 | err_disable_clk_slave_bus: |
| 313 | clk_disable(&eqos->clk_slave_bus); |
| 314 | err: |
| 315 | debug("%s: FAILED: %d\n", __func__, ret); |
| 316 | return ret; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 317 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 318 | } |
| 319 | |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 320 | static int eqos_stop_clks_tegra186(struct udevice *dev) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 321 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 322 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 323 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 324 | |
| 325 | debug("%s(dev=%p):\n", __func__, dev); |
| 326 | |
| 327 | clk_disable(&eqos->clk_tx); |
| 328 | clk_disable(&eqos->clk_ptp_ref); |
| 329 | clk_disable(&eqos->clk_rx); |
| 330 | clk_disable(&eqos->clk_master_bus); |
| 331 | clk_disable(&eqos->clk_slave_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 332 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 333 | |
| 334 | debug("%s: OK\n", __func__); |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 335 | return 0; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static int eqos_start_resets_tegra186(struct udevice *dev) |
| 339 | { |
| 340 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 341 | int ret; |
| 342 | |
| 343 | debug("%s(dev=%p):\n", __func__, dev); |
| 344 | |
| 345 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 346 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 347 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | udelay(2); |
| 352 | |
| 353 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 354 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 355 | pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | ret = reset_assert(&eqos->reset_ctl); |
| 360 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 361 | pr_err("reset_assert() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | udelay(2); |
| 366 | |
| 367 | ret = reset_deassert(&eqos->reset_ctl); |
| 368 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 369 | pr_err("reset_deassert() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | debug("%s: OK\n", __func__); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int eqos_stop_resets_tegra186(struct udevice *dev) |
| 378 | { |
| 379 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 380 | |
| 381 | reset_assert(&eqos->reset_ctl); |
| 382 | dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 383 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 387 | static int eqos_calibrate_pads_tegra186(struct udevice *dev) |
| 388 | { |
| 389 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 390 | int ret; |
| 391 | |
| 392 | debug("%s(dev=%p):\n", __func__, dev); |
| 393 | |
| 394 | setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 395 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 396 | |
| 397 | udelay(1); |
| 398 | |
| 399 | setbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 400 | EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 401 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 402 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 403 | EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 404 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 405 | pr_err("calibrate didn't start\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 406 | goto failed; |
| 407 | } |
| 408 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 409 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 410 | EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 411 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 412 | pr_err("calibrate didn't finish\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 413 | goto failed; |
| 414 | } |
| 415 | |
| 416 | ret = 0; |
| 417 | |
| 418 | failed: |
| 419 | clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 420 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 421 | |
| 422 | debug("%s: returns %d\n", __func__, ret); |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | static int eqos_disable_calibration_tegra186(struct udevice *dev) |
| 428 | { |
| 429 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 430 | |
| 431 | debug("%s(dev=%p):\n", __func__, dev); |
| 432 | |
| 433 | clrbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 434 | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev) |
| 440 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 441 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 442 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 443 | |
| 444 | return clk_get_rate(&eqos->clk_slave_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 445 | #else |
| 446 | return 0; |
| 447 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static int eqos_set_full_duplex(struct udevice *dev) |
| 451 | { |
| 452 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 453 | |
| 454 | debug("%s(dev=%p):\n", __func__, dev); |
| 455 | |
| 456 | setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int eqos_set_half_duplex(struct udevice *dev) |
| 462 | { |
| 463 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 464 | |
| 465 | debug("%s(dev=%p):\n", __func__, dev); |
| 466 | |
| 467 | clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 468 | |
| 469 | /* WAR: Flush TX queue when switching to half-duplex */ |
| 470 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 471 | EQOS_MTL_TXQ0_OPERATION_MODE_FTQ); |
| 472 | |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static int eqos_set_gmii_speed(struct udevice *dev) |
| 477 | { |
| 478 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 479 | |
| 480 | debug("%s(dev=%p):\n", __func__, dev); |
| 481 | |
| 482 | clrbits_le32(&eqos->mac_regs->configuration, |
| 483 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int eqos_set_mii_speed_100(struct udevice *dev) |
| 489 | { |
| 490 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 491 | |
| 492 | debug("%s(dev=%p):\n", __func__, dev); |
| 493 | |
| 494 | setbits_le32(&eqos->mac_regs->configuration, |
| 495 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int eqos_set_mii_speed_10(struct udevice *dev) |
| 501 | { |
| 502 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 503 | |
| 504 | debug("%s(dev=%p):\n", __func__, dev); |
| 505 | |
| 506 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 507 | EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS); |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev) |
| 513 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 514 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 515 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 516 | ulong rate; |
| 517 | int ret; |
| 518 | |
| 519 | debug("%s(dev=%p):\n", __func__, dev); |
| 520 | |
| 521 | switch (eqos->phy->speed) { |
| 522 | case SPEED_1000: |
| 523 | rate = 125 * 1000 * 1000; |
| 524 | break; |
| 525 | case SPEED_100: |
| 526 | rate = 25 * 1000 * 1000; |
| 527 | break; |
| 528 | case SPEED_10: |
| 529 | rate = 2.5 * 1000 * 1000; |
| 530 | break; |
| 531 | default: |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 532 | pr_err("invalid speed %d\n", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 533 | return -EINVAL; |
| 534 | } |
| 535 | |
| 536 | ret = clk_set_rate(&eqos->clk_tx, rate); |
| 537 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 538 | pr_err("clk_set_rate(tx_clk, %lu) failed: %d\n", rate, ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 539 | return ret; |
| 540 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 541 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | static int eqos_adjust_link(struct udevice *dev) |
| 547 | { |
| 548 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 549 | int ret; |
| 550 | bool en_calibration; |
| 551 | |
| 552 | debug("%s(dev=%p):\n", __func__, dev); |
| 553 | |
| 554 | if (eqos->phy->duplex) |
| 555 | ret = eqos_set_full_duplex(dev); |
| 556 | else |
| 557 | ret = eqos_set_half_duplex(dev); |
| 558 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 559 | pr_err("eqos_set_*_duplex() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | switch (eqos->phy->speed) { |
| 564 | case SPEED_1000: |
| 565 | en_calibration = true; |
| 566 | ret = eqos_set_gmii_speed(dev); |
| 567 | break; |
| 568 | case SPEED_100: |
| 569 | en_calibration = true; |
| 570 | ret = eqos_set_mii_speed_100(dev); |
| 571 | break; |
| 572 | case SPEED_10: |
| 573 | en_calibration = false; |
| 574 | ret = eqos_set_mii_speed_10(dev); |
| 575 | break; |
| 576 | default: |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 577 | pr_err("invalid speed %d\n", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 578 | return -EINVAL; |
| 579 | } |
| 580 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 581 | pr_err("eqos_set_*mii_speed*() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | if (en_calibration) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 586 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 587 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 588 | pr_err("eqos_calibrate_pads() failed: %d\n", |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 589 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | } else { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 593 | ret = eqos->config->ops->eqos_disable_calibration(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 594 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 595 | pr_err("eqos_disable_calibration() failed: %d\n", |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 596 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 597 | return ret; |
| 598 | } |
| 599 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 600 | ret = eqos->config->ops->eqos_set_tx_clk_speed(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 601 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 602 | pr_err("eqos_set_tx_clk_speed() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int eqos_write_hwaddr(struct udevice *dev) |
| 610 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 611 | struct eth_pdata *plat = dev_get_plat(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 612 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 613 | uint32_t val; |
| 614 | |
| 615 | /* |
| 616 | * This function may be called before start() or after stop(). At that |
| 617 | * time, on at least some configurations of the EQoS HW, all clocks to |
| 618 | * the EQoS HW block will be stopped, and a reset signal applied. If |
| 619 | * any register access is attempted in this state, bus timeouts or CPU |
| 620 | * hangs may occur. This check prevents that. |
| 621 | * |
| 622 | * A simple solution to this problem would be to not implement |
| 623 | * write_hwaddr(), since start() always writes the MAC address into HW |
| 624 | * anyway. However, it is desirable to implement write_hwaddr() to |
| 625 | * support the case of SW that runs subsequent to U-Boot which expects |
| 626 | * the MAC address to already be programmed into the EQoS registers, |
| 627 | * which must happen irrespective of whether the U-Boot user (or |
| 628 | * scripts) actually made use of the EQoS device, and hence |
| 629 | * irrespective of whether start() was ever called. |
| 630 | * |
| 631 | * Note that this requirement by subsequent SW is not valid for |
| 632 | * Tegra186, and is likely not valid for any non-PCI instantiation of |
| 633 | * the EQoS HW block. This function is implemented solely as |
| 634 | * future-proofing with the expectation the driver will eventually be |
| 635 | * ported to some system where the expectation above is true. |
| 636 | */ |
| 637 | if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok) |
| 638 | return 0; |
| 639 | |
| 640 | /* Update the MAC address */ |
| 641 | val = (plat->enetaddr[5] << 8) | |
| 642 | (plat->enetaddr[4]); |
| 643 | writel(val, &eqos->mac_regs->address0_high); |
| 644 | val = (plat->enetaddr[3] << 24) | |
| 645 | (plat->enetaddr[2] << 16) | |
| 646 | (plat->enetaddr[1] << 8) | |
| 647 | (plat->enetaddr[0]); |
| 648 | writel(val, &eqos->mac_regs->address0_low); |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 653 | static int eqos_read_rom_hwaddr(struct udevice *dev) |
| 654 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 655 | struct eth_pdata *pdata = dev_get_plat(dev); |
Peng Fan | bf69a7b9 | 2022-07-26 16:41:17 +0800 | [diff] [blame] | 656 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 657 | int ret; |
| 658 | |
| 659 | ret = eqos->config->ops->eqos_get_enetaddr(dev); |
| 660 | if (ret < 0) |
| 661 | return ret; |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 662 | |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 663 | return !is_valid_ethaddr(pdata->enetaddr); |
| 664 | } |
| 665 | |
Ye Li | 2f2aa48 | 2022-07-26 16:41:16 +0800 | [diff] [blame] | 666 | static int eqos_get_phy_addr(struct eqos_priv *priv, struct udevice *dev) |
| 667 | { |
| 668 | struct ofnode_phandle_args phandle_args; |
| 669 | int reg; |
| 670 | |
| 671 | if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, |
| 672 | &phandle_args)) { |
| 673 | debug("Failed to find phy-handle"); |
| 674 | return -ENODEV; |
| 675 | } |
| 676 | |
| 677 | priv->phy_of_node = phandle_args.node; |
| 678 | |
| 679 | reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); |
| 680 | |
| 681 | return reg; |
| 682 | } |
| 683 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 684 | static int eqos_start(struct udevice *dev) |
| 685 | { |
| 686 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 687 | int ret, i; |
| 688 | ulong rate; |
| 689 | u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl; |
| 690 | ulong last_rx_desc; |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 691 | ulong desc_pad; |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 692 | ulong addr64; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 693 | |
| 694 | debug("%s(dev=%p):\n", __func__, dev); |
| 695 | |
| 696 | eqos->tx_desc_idx = 0; |
| 697 | eqos->rx_desc_idx = 0; |
| 698 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 699 | ret = eqos->config->ops->eqos_start_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 700 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 701 | pr_err("eqos_start_resets() failed: %d\n", ret); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 702 | goto err; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | udelay(10); |
| 706 | |
| 707 | eqos->reg_access_ok = true; |
| 708 | |
Marek Vasut | e66825a | 2023-03-06 15:53:46 +0100 | [diff] [blame] | 709 | /* |
| 710 | * Assert the SWR first, the actually reset the MAC and to latch in |
| 711 | * e.g. i.MX8M Plus GPR[1] content, which selects interface mode. |
| 712 | */ |
| 713 | setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR); |
| 714 | |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 715 | ret = wait_for_bit_le32(&eqos->dma_regs->mode, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 716 | EQOS_DMA_MODE_SWR, false, |
| 717 | eqos->config->swr_wait, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 718 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 719 | pr_err("EQOS_DMA_MODE_SWR stuck\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 720 | goto err_stop_resets; |
| 721 | } |
| 722 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 723 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 724 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 725 | pr_err("eqos_calibrate_pads() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 726 | goto err_stop_resets; |
| 727 | } |
Sumit Garg | ab973c9 | 2023-02-01 19:28:53 +0530 | [diff] [blame] | 728 | |
| 729 | if (eqos->config->ops->eqos_get_tick_clk_rate) { |
| 730 | rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 731 | |
Sumit Garg | ab973c9 | 2023-02-01 19:28:53 +0530 | [diff] [blame] | 732 | val = (rate / 1000000) - 1; |
| 733 | writel(val, &eqos->mac_regs->us_tic_counter); |
| 734 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 735 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 736 | /* |
| 737 | * if PHY was already connected and configured, |
| 738 | * don't need to reconnect/reconfigure again |
| 739 | */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 740 | if (!eqos->phy) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 741 | int addr = -1; |
Elmar Psilog | dd65ba2 | 2023-02-20 16:03:15 +0100 | [diff] [blame] | 742 | ofnode fixed_node; |
| 743 | |
| 744 | if (IS_ENABLED(CONFIG_PHY_FIXED)) { |
| 745 | fixed_node = ofnode_find_subnode(dev_ofnode(dev), |
| 746 | "fixed-link"); |
| 747 | if (ofnode_valid(fixed_node)) |
| 748 | eqos->phy = fixed_phy_create(dev_ofnode(dev)); |
| 749 | } |
| 750 | |
| 751 | if (!eqos->phy) { |
| 752 | addr = eqos_get_phy_addr(eqos, dev); |
| 753 | eqos->phy = phy_connect(eqos->mii, addr, dev, |
| 754 | eqos->config->interface(dev)); |
| 755 | } |
| 756 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 757 | if (!eqos->phy) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 758 | pr_err("phy_connect() failed\n"); |
Jonas Karlman | 3c0a544 | 2023-10-01 19:17:17 +0000 | [diff] [blame] | 759 | ret = -ENODEV; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 760 | goto err_stop_resets; |
| 761 | } |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 762 | |
| 763 | if (eqos->max_speed) { |
| 764 | ret = phy_set_supported(eqos->phy, eqos->max_speed); |
| 765 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 766 | pr_err("phy_set_supported() failed: %d\n", ret); |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 767 | goto err_shutdown_phy; |
| 768 | } |
| 769 | } |
| 770 | |
Ye Li | 2f2aa48 | 2022-07-26 16:41:16 +0800 | [diff] [blame] | 771 | eqos->phy->node = eqos->phy_of_node; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 772 | ret = phy_config(eqos->phy); |
| 773 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 774 | pr_err("phy_config() failed: %d\n", ret); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 775 | goto err_shutdown_phy; |
| 776 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 777 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 778 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 779 | ret = phy_startup(eqos->phy); |
| 780 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 781 | pr_err("phy_startup() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 782 | goto err_shutdown_phy; |
| 783 | } |
| 784 | |
| 785 | if (!eqos->phy->link) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 786 | pr_err("No link\n"); |
Jonas Karlman | 3c0a544 | 2023-10-01 19:17:17 +0000 | [diff] [blame] | 787 | ret = -EAGAIN; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 788 | goto err_shutdown_phy; |
| 789 | } |
| 790 | |
| 791 | ret = eqos_adjust_link(dev); |
| 792 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 793 | pr_err("eqos_adjust_link() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 794 | goto err_shutdown_phy; |
| 795 | } |
| 796 | |
| 797 | /* Configure MTL */ |
| 798 | |
| 799 | /* Enable Store and Forward mode for TX */ |
| 800 | /* Program Tx operating mode */ |
| 801 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 802 | EQOS_MTL_TXQ0_OPERATION_MODE_TSF | |
| 803 | (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED << |
| 804 | EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT)); |
| 805 | |
| 806 | /* Transmit Queue weight */ |
| 807 | writel(0x10, &eqos->mtl_regs->txq0_quantum_weight); |
| 808 | |
| 809 | /* Enable Store and Forward mode for RX, since no jumbo frame */ |
| 810 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
Daniil Stas | 470c06c | 2021-05-30 13:34:09 +0000 | [diff] [blame] | 811 | EQOS_MTL_RXQ0_OPERATION_MODE_RSF); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 812 | |
| 813 | /* Transmit/Receive queue fifo size; use all RAM for 1 queue */ |
| 814 | val = readl(&eqos->mac_regs->hw_feature1); |
| 815 | tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) & |
| 816 | EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK; |
| 817 | rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) & |
| 818 | EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK; |
| 819 | |
Sumit Garg | 4d5c965 | 2023-02-01 19:28:54 +0530 | [diff] [blame] | 820 | /* r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting */ |
| 821 | tx_fifo_sz = 128 << tx_fifo_sz; |
| 822 | rx_fifo_sz = 128 << rx_fifo_sz; |
| 823 | |
| 824 | /* Allow platform to override TX/RX fifo size */ |
| 825 | if (eqos->tx_fifo_sz) |
| 826 | tx_fifo_sz = eqos->tx_fifo_sz; |
| 827 | if (eqos->rx_fifo_sz) |
| 828 | rx_fifo_sz = eqos->rx_fifo_sz; |
| 829 | |
| 830 | /* r/tqs is encoded as (n / 256) - 1 */ |
| 831 | tqs = tx_fifo_sz / 256 - 1; |
| 832 | rqs = rx_fifo_sz / 256 - 1; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 833 | |
| 834 | clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 835 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK << |
| 836 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT, |
| 837 | tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT); |
| 838 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 839 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK << |
| 840 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT, |
| 841 | rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT); |
| 842 | |
| 843 | /* Flow control used only if each channel gets 4KB or more FIFO */ |
| 844 | if (rqs >= ((4096 / 256) - 1)) { |
| 845 | u32 rfd, rfa; |
| 846 | |
| 847 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 848 | EQOS_MTL_RXQ0_OPERATION_MODE_EHFC); |
| 849 | |
| 850 | /* |
| 851 | * Set Threshold for Activating Flow Contol space for min 2 |
| 852 | * frames ie, (1500 * 1) = 1500 bytes. |
| 853 | * |
| 854 | * Set Threshold for Deactivating Flow Contol for space of |
| 855 | * min 1 frame (frame size 1500bytes) in receive fifo |
| 856 | */ |
| 857 | if (rqs == ((4096 / 256) - 1)) { |
| 858 | /* |
| 859 | * This violates the above formula because of FIFO size |
| 860 | * limit therefore overflow may occur inspite of this. |
| 861 | */ |
| 862 | rfd = 0x3; /* Full-3K */ |
| 863 | rfa = 0x1; /* Full-1.5K */ |
| 864 | } else if (rqs == ((8192 / 256) - 1)) { |
| 865 | rfd = 0x6; /* Full-4K */ |
| 866 | rfa = 0xa; /* Full-6K */ |
| 867 | } else if (rqs == ((16384 / 256) - 1)) { |
| 868 | rfd = 0x6; /* Full-4K */ |
| 869 | rfa = 0x12; /* Full-10K */ |
| 870 | } else { |
| 871 | rfd = 0x6; /* Full-4K */ |
| 872 | rfa = 0x1E; /* Full-16K */ |
| 873 | } |
| 874 | |
| 875 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 876 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK << |
| 877 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 878 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK << |
| 879 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT), |
| 880 | (rfd << |
| 881 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 882 | (rfa << |
| 883 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT)); |
| 884 | } |
| 885 | |
| 886 | /* Configure MAC */ |
| 887 | |
| 888 | clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0, |
| 889 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK << |
| 890 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 891 | eqos->config->config_mac << |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 892 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT); |
| 893 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 894 | /* Multicast and Broadcast Queue Enable */ |
| 895 | setbits_le32(&eqos->mac_regs->unused_0a4, |
| 896 | 0x00100000); |
| 897 | /* enable promise mode */ |
| 898 | setbits_le32(&eqos->mac_regs->unused_004[1], |
| 899 | 0x1); |
| 900 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 901 | /* Set TX flow control parameters */ |
| 902 | /* Set Pause Time */ |
| 903 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 904 | 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT); |
| 905 | /* Assign priority for TX flow control */ |
| 906 | clrbits_le32(&eqos->mac_regs->txq_prty_map0, |
| 907 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK << |
| 908 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT); |
| 909 | /* Assign priority for RX flow control */ |
| 910 | clrbits_le32(&eqos->mac_regs->rxq_ctrl2, |
| 911 | EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK << |
| 912 | EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT); |
| 913 | /* Enable flow control */ |
| 914 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 915 | EQOS_MAC_Q0_TX_FLOW_CTRL_TFE); |
| 916 | setbits_le32(&eqos->mac_regs->rx_flow_ctrl, |
| 917 | EQOS_MAC_RX_FLOW_CTRL_RFE); |
| 918 | |
| 919 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 920 | EQOS_MAC_CONFIGURATION_GPSLCE | |
| 921 | EQOS_MAC_CONFIGURATION_WD | |
| 922 | EQOS_MAC_CONFIGURATION_JD | |
| 923 | EQOS_MAC_CONFIGURATION_JE, |
| 924 | EQOS_MAC_CONFIGURATION_CST | |
| 925 | EQOS_MAC_CONFIGURATION_ACS); |
| 926 | |
| 927 | eqos_write_hwaddr(dev); |
| 928 | |
| 929 | /* Configure DMA */ |
| 930 | |
| 931 | /* Enable OSP mode */ |
| 932 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 933 | EQOS_DMA_CH0_TX_CONTROL_OSP); |
| 934 | |
| 935 | /* RX buffer size. Must be a multiple of bus width */ |
| 936 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 937 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK << |
| 938 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT, |
| 939 | EQOS_MAX_PACKET_SIZE << |
| 940 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT); |
| 941 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 942 | desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) / |
| 943 | eqos->config->axi_bus_width; |
| 944 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 945 | setbits_le32(&eqos->dma_regs->ch0_control, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 946 | EQOS_DMA_CH0_CONTROL_PBLX8 | |
| 947 | (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT)); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 948 | |
| 949 | /* |
| 950 | * Burst length must be < 1/2 FIFO size. |
| 951 | * FIFO size in tqs is encoded as (n / 256) - 1. |
| 952 | * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes. |
| 953 | * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1. |
| 954 | */ |
| 955 | pbl = tqs + 1; |
| 956 | if (pbl > 32) |
| 957 | pbl = 32; |
| 958 | clrsetbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 959 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK << |
| 960 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT, |
| 961 | pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT); |
| 962 | |
| 963 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 964 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK << |
| 965 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT, |
| 966 | 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT); |
| 967 | |
| 968 | /* DMA performance configuration */ |
| 969 | val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) | |
| 970 | EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 | |
| 971 | EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4; |
| 972 | writel(val, &eqos->dma_regs->sysbus_mode); |
| 973 | |
| 974 | /* Set up descriptors */ |
| 975 | |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 976 | memset(eqos->tx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_TX); |
| 977 | memset(eqos->rx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_RX); |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 978 | |
| 979 | for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) { |
| 980 | struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false); |
| 981 | eqos->config->ops->eqos_flush_desc(tx_desc); |
| 982 | } |
| 983 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 984 | for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 985 | struct eqos_desc *rx_desc = eqos_get_desc(eqos, i, true); |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 986 | |
| 987 | addr64 = (ulong)(eqos->rx_dma_buf + (i * EQOS_MAX_PACKET_SIZE)); |
| 988 | rx_desc->des0 = lower_32_bits(addr64); |
| 989 | rx_desc->des1 = upper_32_bits(addr64); |
Marek Vasut | d54c98e | 2020-03-23 02:02:57 +0100 | [diff] [blame] | 990 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 991 | mb(); |
Marek Vasut | 873f8e4 | 2020-03-23 02:09:01 +0100 | [diff] [blame] | 992 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 993 | eqos->config->ops->eqos_inval_buffer((void *)addr64, EQOS_MAX_PACKET_SIZE); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 994 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 995 | |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 996 | addr64 = (ulong)eqos_get_desc(eqos, 0, false); |
| 997 | writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_haddress); |
| 998 | writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_address); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 999 | writel(EQOS_DESCRIPTORS_TX - 1, |
| 1000 | &eqos->dma_regs->ch0_txdesc_ring_length); |
| 1001 | |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1002 | addr64 = (ulong)eqos_get_desc(eqos, 0, true); |
| 1003 | writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_haddress); |
| 1004 | writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_address); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1005 | writel(EQOS_DESCRIPTORS_RX - 1, |
| 1006 | &eqos->dma_regs->ch0_rxdesc_ring_length); |
| 1007 | |
| 1008 | /* Enable everything */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1009 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1010 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1011 | setbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1012 | EQOS_DMA_CH0_RX_CONTROL_SR); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1013 | setbits_le32(&eqos->mac_regs->configuration, |
| 1014 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1015 | |
| 1016 | /* TX tail pointer not written until we need to TX a packet */ |
| 1017 | /* |
| 1018 | * Point RX tail pointer at last descriptor. Ideally, we'd point at the |
| 1019 | * first descriptor, implying all descriptors were available. However, |
| 1020 | * that's not distinguishable from none of the descriptors being |
| 1021 | * available. |
| 1022 | */ |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1023 | last_rx_desc = (ulong)eqos_get_desc(eqos, EQOS_DESCRIPTORS_RX - 1, true); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1024 | writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1025 | |
| 1026 | eqos->started = true; |
| 1027 | |
| 1028 | debug("%s: OK\n", __func__); |
| 1029 | return 0; |
| 1030 | |
| 1031 | err_shutdown_phy: |
| 1032 | phy_shutdown(eqos->phy); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1033 | err_stop_resets: |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1034 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1035 | err: |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1036 | pr_err("FAILED: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1037 | return ret; |
| 1038 | } |
| 1039 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1040 | static void eqos_stop(struct udevice *dev) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1041 | { |
| 1042 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1043 | int i; |
| 1044 | |
| 1045 | debug("%s(dev=%p):\n", __func__, dev); |
| 1046 | |
| 1047 | if (!eqos->started) |
| 1048 | return; |
| 1049 | eqos->started = false; |
| 1050 | eqos->reg_access_ok = false; |
| 1051 | |
| 1052 | /* Disable TX DMA */ |
| 1053 | clrbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1054 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1055 | |
| 1056 | /* Wait for TX all packets to drain out of MTL */ |
| 1057 | for (i = 0; i < 1000000; i++) { |
| 1058 | u32 val = readl(&eqos->mtl_regs->txq0_debug); |
| 1059 | u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) & |
| 1060 | EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK; |
| 1061 | u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS; |
| 1062 | if ((trcsts != 1) && (!txqsts)) |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | /* Turn off MAC TX and RX */ |
| 1067 | clrbits_le32(&eqos->mac_regs->configuration, |
| 1068 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
| 1069 | |
| 1070 | /* Wait for all RX packets to drain out of MTL */ |
| 1071 | for (i = 0; i < 1000000; i++) { |
| 1072 | u32 val = readl(&eqos->mtl_regs->rxq0_debug); |
| 1073 | u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) & |
| 1074 | EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK; |
| 1075 | u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) & |
| 1076 | EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK; |
| 1077 | if ((!prxq) && (!rxqsts)) |
| 1078 | break; |
| 1079 | } |
| 1080 | |
| 1081 | /* Turn off RX DMA */ |
| 1082 | clrbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1083 | EQOS_DMA_CH0_RX_CONTROL_SR); |
| 1084 | |
| 1085 | if (eqos->phy) { |
| 1086 | phy_shutdown(eqos->phy); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1087 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1088 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1089 | |
| 1090 | debug("%s: OK\n", __func__); |
| 1091 | } |
| 1092 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1093 | static int eqos_send(struct udevice *dev, void *packet, int length) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1094 | { |
| 1095 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1096 | struct eqos_desc *tx_desc; |
| 1097 | int i; |
| 1098 | |
| 1099 | debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet, |
| 1100 | length); |
| 1101 | |
| 1102 | memcpy(eqos->tx_dma_buf, packet, length); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1103 | eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1104 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1105 | tx_desc = eqos_get_desc(eqos, eqos->tx_desc_idx, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1106 | eqos->tx_desc_idx++; |
| 1107 | eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX; |
| 1108 | |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1109 | tx_desc->des0 = lower_32_bits((ulong)eqos->tx_dma_buf); |
| 1110 | tx_desc->des1 = upper_32_bits((ulong)eqos->tx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1111 | tx_desc->des2 = length; |
| 1112 | /* |
| 1113 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1114 | * writes to the rest of the descriptor too. |
| 1115 | */ |
| 1116 | mb(); |
| 1117 | tx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_FD | EQOS_DESC3_LD | length; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1118 | eqos->config->ops->eqos_flush_desc(tx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1119 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1120 | writel((ulong)eqos_get_desc(eqos, eqos->tx_desc_idx, false), |
Marek Vasut | f4f1f4d | 2020-03-23 02:03:50 +0100 | [diff] [blame] | 1121 | &eqos->dma_regs->ch0_txdesc_tail_pointer); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1122 | |
| 1123 | for (i = 0; i < 1000000; i++) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1124 | eqos->config->ops->eqos_inval_desc(tx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1125 | if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN)) |
| 1126 | return 0; |
| 1127 | udelay(1); |
| 1128 | } |
| 1129 | |
| 1130 | debug("%s: TX timeout\n", __func__); |
| 1131 | |
| 1132 | return -ETIMEDOUT; |
| 1133 | } |
| 1134 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1135 | static int eqos_recv(struct udevice *dev, int flags, uchar **packetp) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1136 | { |
| 1137 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1138 | struct eqos_desc *rx_desc; |
| 1139 | int length; |
| 1140 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1141 | rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true); |
Marek Vasut | c4db844 | 2020-03-23 02:09:21 +0100 | [diff] [blame] | 1142 | eqos->config->ops->eqos_inval_desc(rx_desc); |
Jonas Karlman | e2c4546 | 2023-10-01 19:17:18 +0000 | [diff] [blame] | 1143 | if (rx_desc->des3 & EQOS_DESC3_OWN) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1144 | return -EAGAIN; |
Jonas Karlman | e2c4546 | 2023-10-01 19:17:18 +0000 | [diff] [blame] | 1145 | |
| 1146 | debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1147 | |
| 1148 | *packetp = eqos->rx_dma_buf + |
| 1149 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1150 | length = rx_desc->des3 & 0x7fff; |
| 1151 | debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length); |
| 1152 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1153 | eqos->config->ops->eqos_inval_buffer(*packetp, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1154 | |
| 1155 | return length; |
| 1156 | } |
| 1157 | |
Patrick Delaunay | 6864a599 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1158 | static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1159 | { |
| 1160 | struct eqos_priv *eqos = dev_get_priv(dev); |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1161 | u32 idx, idx_mask = eqos->desc_per_cacheline - 1; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1162 | uchar *packet_expected; |
Patrice Chotard | 7b1baf3 | 2024-04-05 18:15:29 +0200 | [diff] [blame] | 1163 | struct eqos_desc *rx_desc = NULL; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1164 | |
| 1165 | debug("%s(packet=%p, length=%d)\n", __func__, packet, length); |
| 1166 | |
| 1167 | packet_expected = eqos->rx_dma_buf + |
| 1168 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1169 | if (packet != packet_expected) { |
| 1170 | debug("%s: Unexpected packet (expected %p)\n", __func__, |
| 1171 | packet_expected); |
| 1172 | return -EINVAL; |
| 1173 | } |
| 1174 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1175 | eqos->config->ops->eqos_inval_buffer(packet, length); |
| 1176 | |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1177 | if ((eqos->rx_desc_idx & idx_mask) == idx_mask) { |
| 1178 | for (idx = eqos->rx_desc_idx - idx_mask; |
| 1179 | idx <= eqos->rx_desc_idx; |
| 1180 | idx++) { |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1181 | ulong addr64; |
| 1182 | |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1183 | rx_desc = eqos_get_desc(eqos, idx, true); |
| 1184 | rx_desc->des0 = 0; |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1185 | rx_desc->des1 = 0; |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1186 | mb(); |
| 1187 | eqos->config->ops->eqos_flush_desc(rx_desc); |
| 1188 | eqos->config->ops->eqos_inval_buffer(packet, length); |
Ley Foon Tan | 963db38 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1189 | addr64 = (ulong)(eqos->rx_dma_buf + (idx * EQOS_MAX_PACKET_SIZE)); |
| 1190 | rx_desc->des0 = lower_32_bits(addr64); |
| 1191 | rx_desc->des1 = upper_32_bits(addr64); |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1192 | rx_desc->des2 = 0; |
| 1193 | /* |
| 1194 | * Make sure that if HW sees the _OWN write below, |
| 1195 | * it will see all the writes to the rest of the |
| 1196 | * descriptor too. |
| 1197 | */ |
| 1198 | mb(); |
| 1199 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
| 1200 | eqos->config->ops->eqos_flush_desc(rx_desc); |
| 1201 | } |
| 1202 | writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1203 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1204 | |
| 1205 | eqos->rx_desc_idx++; |
| 1206 | eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX; |
| 1207 | |
| 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | static int eqos_probe_resources_core(struct udevice *dev) |
| 1212 | { |
| 1213 | struct eqos_priv *eqos = dev_get_priv(dev); |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1214 | unsigned int desc_step; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1215 | int ret; |
| 1216 | |
| 1217 | debug("%s(dev=%p):\n", __func__, dev); |
| 1218 | |
Marek Vasut | 3e8a1be | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1219 | /* Maximum distance between neighboring descriptors, in Bytes. */ |
| 1220 | desc_step = sizeof(struct eqos_desc) + |
| 1221 | EQOS_DMA_CH0_CONTROL_DSL_MASK * eqos->config->axi_bus_width; |
| 1222 | if (desc_step < ARCH_DMA_MINALIGN) { |
| 1223 | /* |
| 1224 | * The EQoS hardware implementation cannot place one descriptor |
| 1225 | * per cacheline, it is necessary to place multiple descriptors |
| 1226 | * per cacheline in memory and do cache management carefully. |
| 1227 | */ |
| 1228 | eqos->desc_size = BIT(fls(desc_step) - 1); |
| 1229 | } else { |
| 1230 | eqos->desc_size = ALIGN(sizeof(struct eqos_desc), |
| 1231 | (unsigned int)ARCH_DMA_MINALIGN); |
| 1232 | } |
| 1233 | eqos->desc_per_cacheline = ARCH_DMA_MINALIGN / eqos->desc_size; |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1234 | |
| 1235 | eqos->tx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_TX); |
| 1236 | if (!eqos->tx_descs) { |
| 1237 | debug("%s: eqos_alloc_descs(tx) failed\n", __func__); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1238 | ret = -ENOMEM; |
| 1239 | goto err; |
| 1240 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1241 | |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1242 | eqos->rx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_RX); |
| 1243 | if (!eqos->rx_descs) { |
| 1244 | debug("%s: eqos_alloc_descs(rx) failed\n", __func__); |
| 1245 | ret = -ENOMEM; |
| 1246 | goto err_free_tx_descs; |
| 1247 | } |
| 1248 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1249 | eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE); |
| 1250 | if (!eqos->tx_dma_buf) { |
| 1251 | debug("%s: memalign(tx_dma_buf) failed\n", __func__); |
| 1252 | ret = -ENOMEM; |
| 1253 | goto err_free_descs; |
| 1254 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1255 | debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1256 | |
| 1257 | eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE); |
| 1258 | if (!eqos->rx_dma_buf) { |
| 1259 | debug("%s: memalign(rx_dma_buf) failed\n", __func__); |
| 1260 | ret = -ENOMEM; |
| 1261 | goto err_free_tx_dma_buf; |
| 1262 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1263 | debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1264 | |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1265 | eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf, |
| 1266 | EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX); |
| 1267 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1268 | debug("%s: OK\n", __func__); |
| 1269 | return 0; |
| 1270 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1271 | err_free_tx_dma_buf: |
| 1272 | free(eqos->tx_dma_buf); |
| 1273 | err_free_descs: |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1274 | eqos_free_descs(eqos->rx_descs); |
| 1275 | err_free_tx_descs: |
| 1276 | eqos_free_descs(eqos->tx_descs); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1277 | err: |
| 1278 | |
| 1279 | debug("%s: returns %d\n", __func__, ret); |
| 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | static int eqos_remove_resources_core(struct udevice *dev) |
| 1284 | { |
| 1285 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1286 | |
| 1287 | debug("%s(dev=%p):\n", __func__, dev); |
| 1288 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1289 | free(eqos->rx_dma_buf); |
| 1290 | free(eqos->tx_dma_buf); |
Marek Vasut | 90cc13a | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1291 | eqos_free_descs(eqos->rx_descs); |
| 1292 | eqos_free_descs(eqos->tx_descs); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1293 | |
| 1294 | debug("%s: OK\n", __func__); |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | static int eqos_probe_resources_tegra186(struct udevice *dev) |
| 1299 | { |
| 1300 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1301 | int ret; |
| 1302 | |
| 1303 | debug("%s(dev=%p):\n", __func__, dev); |
| 1304 | |
Philip Oberfichtner | d6d22da | 2024-08-02 11:25:37 +0200 | [diff] [blame] | 1305 | ret = eqos_get_base_addr_dt(dev); |
| 1306 | if (ret) { |
| 1307 | pr_err("eqos_get_base_addr_dt failed: %d\n", ret); |
| 1308 | return ret; |
| 1309 | } |
| 1310 | eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE); |
| 1311 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1312 | ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); |
| 1313 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1314 | pr_err("reset_get_by_name(rst) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1315 | return ret; |
| 1316 | } |
| 1317 | |
| 1318 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 1319 | &eqos->phy_reset_gpio, |
| 1320 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 1321 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1322 | pr_err("gpio_request_by_name(phy reset) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1323 | goto err_free_reset_eqos; |
| 1324 | } |
| 1325 | |
| 1326 | ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus); |
| 1327 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1328 | pr_err("clk_get_by_name(slave_bus) failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1329 | goto err_free_gpio_phy_reset; |
| 1330 | } |
| 1331 | |
| 1332 | ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus); |
| 1333 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1334 | pr_err("clk_get_by_name(master_bus) failed: %d\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1335 | goto err_free_gpio_phy_reset; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | ret = clk_get_by_name(dev, "rx", &eqos->clk_rx); |
| 1339 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1340 | pr_err("clk_get_by_name(rx) failed: %d\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1341 | goto err_free_gpio_phy_reset; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref); |
| 1345 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1346 | pr_err("clk_get_by_name(ptp_ref) failed: %d\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1347 | goto err_free_gpio_phy_reset; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | ret = clk_get_by_name(dev, "tx", &eqos->clk_tx); |
| 1351 | if (ret) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1352 | pr_err("clk_get_by_name(tx) failed: %d\n", ret); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1353 | goto err_free_gpio_phy_reset; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | debug("%s: OK\n", __func__); |
| 1357 | return 0; |
| 1358 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1359 | err_free_gpio_phy_reset: |
| 1360 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1361 | err_free_reset_eqos: |
| 1362 | reset_free(&eqos->reset_ctl); |
| 1363 | |
| 1364 | debug("%s: returns %d\n", __func__, ret); |
| 1365 | return ret; |
| 1366 | } |
| 1367 | |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1368 | static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1369 | { |
| 1370 | return PHY_INTERFACE_MODE_MII; |
| 1371 | } |
| 1372 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1373 | static int eqos_remove_resources_tegra186(struct udevice *dev) |
| 1374 | { |
| 1375 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1376 | |
| 1377 | debug("%s(dev=%p):\n", __func__, dev); |
| 1378 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1379 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1380 | reset_free(&eqos->reset_ctl); |
| 1381 | |
| 1382 | debug("%s: OK\n", __func__); |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
Philip Oberfichtner | 6f47364 | 2024-08-02 11:25:38 +0200 | [diff] [blame] | 1386 | static int eqos_bind(struct udevice *dev) |
| 1387 | { |
| 1388 | static int dev_num; |
| 1389 | const size_t name_sz = 16; |
| 1390 | char name[name_sz]; |
| 1391 | |
| 1392 | /* Device name defaults to DT node name. */ |
| 1393 | if (ofnode_valid(dev_ofnode(dev))) |
| 1394 | return 0; |
| 1395 | |
| 1396 | /* Assign unique names in case there is no DT node. */ |
| 1397 | snprintf(name, name_sz, "eth_eqos#%d", dev_num++); |
| 1398 | return device_set_name(dev, name); |
| 1399 | } |
| 1400 | |
Philip Oberfichtner | d6d22da | 2024-08-02 11:25:37 +0200 | [diff] [blame] | 1401 | /* |
| 1402 | * Get driver data based on the device tree. Boards not using a device tree can |
| 1403 | * overwrite this function. |
| 1404 | */ |
| 1405 | __weak void *eqos_get_driver_data(struct udevice *dev) |
| 1406 | { |
| 1407 | return (void *)dev_get_driver_data(dev); |
| 1408 | } |
| 1409 | |
| 1410 | static fdt_addr_t eqos_get_base_addr_common(struct udevice *dev, fdt_addr_t addr) |
| 1411 | { |
| 1412 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1413 | |
| 1414 | if (addr == FDT_ADDR_T_NONE) { |
| 1415 | #if CONFIG_IS_ENABLED(FDT_64BIT) |
| 1416 | dev_err(dev, "addr=0x%llx is invalid.\n", addr); |
| 1417 | #else |
| 1418 | dev_err(dev, "addr=0x%x is invalid.\n", addr); |
| 1419 | #endif |
| 1420 | return -EINVAL; |
| 1421 | } |
| 1422 | |
| 1423 | eqos->regs = addr; |
| 1424 | eqos->mac_regs = (void *)(addr + EQOS_MAC_REGS_BASE); |
| 1425 | eqos->mtl_regs = (void *)(addr + EQOS_MTL_REGS_BASE); |
| 1426 | eqos->dma_regs = (void *)(addr + EQOS_DMA_REGS_BASE); |
| 1427 | |
| 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | int eqos_get_base_addr_dt(struct udevice *dev) |
| 1432 | { |
| 1433 | fdt_addr_t addr = dev_read_addr(dev); |
| 1434 | return eqos_get_base_addr_common(dev, addr); |
| 1435 | } |
| 1436 | |
Philip Oberfichtner | 4246035 | 2024-08-02 11:25:39 +0200 | [diff] [blame^] | 1437 | int eqos_get_base_addr_pci(struct udevice *dev) |
| 1438 | { |
| 1439 | fdt_addr_t addr; |
| 1440 | void *paddr; |
| 1441 | |
| 1442 | paddr = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, 0, 0, PCI_REGION_TYPE, |
| 1443 | PCI_REGION_MEM); |
| 1444 | addr = paddr ? (fdt_addr_t)paddr : FDT_ADDR_T_NONE; |
| 1445 | |
| 1446 | return eqos_get_base_addr_common(dev, addr); |
| 1447 | } |
| 1448 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1449 | static int eqos_probe(struct udevice *dev) |
| 1450 | { |
| 1451 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1452 | int ret; |
| 1453 | |
| 1454 | debug("%s(dev=%p):\n", __func__, dev); |
| 1455 | |
| 1456 | eqos->dev = dev; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1457 | |
Philip Oberfichtner | d6d22da | 2024-08-02 11:25:37 +0200 | [diff] [blame] | 1458 | eqos->config = eqos_get_driver_data(dev); |
| 1459 | if (!eqos->config) { |
| 1460 | pr_err("Failed to get driver data.\n"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1461 | return -ENODEV; |
| 1462 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1463 | |
Rasmus Villemoes | 2a9e76d | 2022-05-11 16:58:41 +0200 | [diff] [blame] | 1464 | eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
| 1465 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1466 | ret = eqos_probe_resources_core(dev); |
| 1467 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1468 | pr_err("eqos_probe_resources_core() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1469 | return ret; |
| 1470 | } |
| 1471 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1472 | ret = eqos->config->ops->eqos_probe_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1473 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1474 | pr_err("eqos_probe_resources() failed: %d\n", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1475 | goto err_remove_resources_core; |
| 1476 | } |
| 1477 | |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1478 | ret = eqos->config->ops->eqos_start_clks(dev); |
| 1479 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1480 | pr_err("eqos_start_clks() failed: %d\n", ret); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1481 | goto err_remove_resources_tegra; |
| 1482 | } |
| 1483 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1484 | #ifdef CONFIG_DM_ETH_PHY |
| 1485 | eqos->mii = eth_phy_get_mdio_bus(dev); |
| 1486 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1487 | if (!eqos->mii) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1488 | eqos->mii = mdio_alloc(); |
| 1489 | if (!eqos->mii) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1490 | pr_err("mdio_alloc() failed\n"); |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1491 | ret = -ENOMEM; |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1492 | goto err_stop_clks; |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1493 | } |
| 1494 | eqos->mii->read = eqos_mdio_read; |
| 1495 | eqos->mii->write = eqos_mdio_write; |
| 1496 | eqos->mii->priv = eqos; |
| 1497 | strcpy(eqos->mii->name, dev->name); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1498 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1499 | ret = mdio_register(eqos->mii); |
| 1500 | if (ret < 0) { |
Heinrich Schuchardt | ccb51b4 | 2024-04-02 10:39:34 +0200 | [diff] [blame] | 1501 | pr_err("mdio_register() failed: %d\n", ret); |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1502 | goto err_free_mdio; |
| 1503 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1504 | } |
| 1505 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1506 | #ifdef CONFIG_DM_ETH_PHY |
| 1507 | eth_phy_set_mdio_bus(dev, eqos->mii); |
| 1508 | #endif |
| 1509 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1510 | debug("%s: OK\n", __func__); |
| 1511 | return 0; |
| 1512 | |
| 1513 | err_free_mdio: |
| 1514 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1515 | err_stop_clks: |
| 1516 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1517 | err_remove_resources_tegra: |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1518 | eqos->config->ops->eqos_remove_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1519 | err_remove_resources_core: |
| 1520 | eqos_remove_resources_core(dev); |
| 1521 | |
| 1522 | debug("%s: returns %d\n", __func__, ret); |
| 1523 | return ret; |
| 1524 | } |
| 1525 | |
| 1526 | static int eqos_remove(struct udevice *dev) |
| 1527 | { |
| 1528 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1529 | |
| 1530 | debug("%s(dev=%p):\n", __func__, dev); |
| 1531 | |
| 1532 | mdio_unregister(eqos->mii); |
| 1533 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1534 | eqos->config->ops->eqos_stop_clks(dev); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1535 | eqos->config->ops->eqos_remove_resources(dev); |
| 1536 | |
Rasmus Villemoes | 50fe526 | 2022-05-11 16:12:50 +0200 | [diff] [blame] | 1537 | eqos_remove_resources_core(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1538 | |
| 1539 | debug("%s: OK\n", __func__); |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 1543 | int eqos_null_ops(struct udevice *dev) |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1544 | { |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1548 | static const struct eth_ops eqos_ops = { |
| 1549 | .start = eqos_start, |
| 1550 | .stop = eqos_stop, |
| 1551 | .send = eqos_send, |
| 1552 | .recv = eqos_recv, |
| 1553 | .free_pkt = eqos_free_pkt, |
| 1554 | .write_hwaddr = eqos_write_hwaddr, |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1555 | .read_rom_hwaddr = eqos_read_rom_hwaddr, |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1556 | }; |
| 1557 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1558 | static struct eqos_ops eqos_tegra186_ops = { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1559 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1560 | .eqos_flush_desc = eqos_flush_desc_generic, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1561 | .eqos_inval_buffer = eqos_inval_buffer_tegra186, |
| 1562 | .eqos_flush_buffer = eqos_flush_buffer_tegra186, |
| 1563 | .eqos_probe_resources = eqos_probe_resources_tegra186, |
| 1564 | .eqos_remove_resources = eqos_remove_resources_tegra186, |
| 1565 | .eqos_stop_resets = eqos_stop_resets_tegra186, |
| 1566 | .eqos_start_resets = eqos_start_resets_tegra186, |
| 1567 | .eqos_stop_clks = eqos_stop_clks_tegra186, |
| 1568 | .eqos_start_clks = eqos_start_clks_tegra186, |
| 1569 | .eqos_calibrate_pads = eqos_calibrate_pads_tegra186, |
| 1570 | .eqos_disable_calibration = eqos_disable_calibration_tegra186, |
| 1571 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186, |
Patrice Chotard | 088d3ca | 2022-08-02 10:55:25 +0200 | [diff] [blame] | 1572 | .eqos_get_enetaddr = eqos_null_ops, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1573 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186 |
| 1574 | }; |
| 1575 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1576 | static const struct eqos_config __maybe_unused eqos_tegra186_config = { |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1577 | .reg_access_always_ok = false, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1578 | .mdio_wait = 10, |
| 1579 | .swr_wait = 10, |
| 1580 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1581 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1582 | .axi_bus_width = EQOS_AXI_WIDTH_128, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1583 | .interface = eqos_get_interface_tegra186, |
| 1584 | .ops = &eqos_tegra186_ops |
| 1585 | }; |
| 1586 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1587 | static const struct udevice_id eqos_ids[] = { |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1588 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1589 | { |
| 1590 | .compatible = "nvidia,tegra186-eqos", |
| 1591 | .data = (ulong)&eqos_tegra186_config |
| 1592 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1593 | #endif |
| 1594 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1595 | { |
Christophe Roullier | 25a1686 | 2024-03-26 13:07:31 +0100 | [diff] [blame] | 1596 | .compatible = "st,stm32mp13-dwmac", |
| 1597 | .data = (ulong)&eqos_stm32mp13_config |
| 1598 | }, |
| 1599 | { |
Patrick Delaunay | a0466f6 | 2020-05-14 15:00:23 +0200 | [diff] [blame] | 1600 | .compatible = "st,stm32mp1-dwmac", |
Marek Vasut | 944ba37 | 2024-03-26 13:07:23 +0100 | [diff] [blame] | 1601 | .data = (ulong)&eqos_stm32mp15_config |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1602 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1603 | #endif |
| 1604 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1605 | { |
Marek Vasut | 7af1138 | 2022-02-26 04:36:37 +0100 | [diff] [blame] | 1606 | .compatible = "nxp,imx8mp-dwmac-eqos", |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1607 | .data = (ulong)&eqos_imx_config |
| 1608 | }, |
Sébastien Szymanski | 28b7fc4 | 2023-10-17 11:44:58 +0200 | [diff] [blame] | 1609 | { |
| 1610 | .compatible = "nxp,imx93-dwmac-eqos", |
| 1611 | .data = (ulong)&eqos_imx_config |
| 1612 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1613 | #endif |
Jonas Karlman | 098ee4f | 2023-10-01 19:17:19 +0000 | [diff] [blame] | 1614 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP) |
| 1615 | { |
| 1616 | .compatible = "rockchip,rk3568-gmac", |
| 1617 | .data = (ulong)&eqos_rockchip_config |
| 1618 | }, |
Jonas Karlman | 1b61570 | 2023-10-01 19:17:20 +0000 | [diff] [blame] | 1619 | { |
| 1620 | .compatible = "rockchip,rk3588-gmac", |
| 1621 | .data = (ulong)&eqos_rockchip_config |
| 1622 | }, |
Jonas Karlman | 098ee4f | 2023-10-01 19:17:19 +0000 | [diff] [blame] | 1623 | #endif |
Sumit Garg | 7c3be94 | 2023-02-01 19:28:55 +0530 | [diff] [blame] | 1624 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM) |
| 1625 | { |
| 1626 | .compatible = "qcom,qcs404-ethqos", |
| 1627 | .data = (ulong)&eqos_qcom_config |
| 1628 | }, |
| 1629 | #endif |
Yanhong Wang | 1f502ee | 2023-06-15 17:36:43 +0800 | [diff] [blame] | 1630 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STARFIVE) |
| 1631 | { |
| 1632 | .compatible = "starfive,jh7110-dwmac", |
| 1633 | .data = (ulong)&eqos_jh7110_config |
| 1634 | }, |
| 1635 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1636 | { } |
| 1637 | }; |
| 1638 | |
| 1639 | U_BOOT_DRIVER(eth_eqos) = { |
| 1640 | .name = "eth_eqos", |
| 1641 | .id = UCLASS_ETH, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1642 | .of_match = of_match_ptr(eqos_ids), |
Philip Oberfichtner | 6f47364 | 2024-08-02 11:25:38 +0200 | [diff] [blame] | 1643 | .bind = eqos_bind, |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1644 | .probe = eqos_probe, |
| 1645 | .remove = eqos_remove, |
| 1646 | .ops = &eqos_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1647 | .priv_auto = sizeof(struct eqos_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1648 | .plat_auto = sizeof(struct eth_pdata), |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1649 | }; |