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