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