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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 37 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 38 | #include <malloc.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 39 | #include <memalign.h> |
| 40 | #include <miiphy.h> |
| 41 | #include <net.h> |
| 42 | #include <netdev.h> |
| 43 | #include <phy.h> |
| 44 | #include <reset.h> |
| 45 | #include <wait_bit.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 46 | #include <asm/cache.h> |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 47 | #include <asm/gpio.h> |
| 48 | #include <asm/io.h> |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 49 | #include <eth_phy.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 | |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 509 | __weak u32 imx_get_eqos_csr_clk(void) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 510 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 511 | return 100 * 1000000; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 512 | } |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 513 | __weak int imx_eqos_txclk_set_rate(unsigned long rate) |
| 514 | { |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static ulong eqos_get_tick_clk_rate_imx(struct udevice *dev) |
| 519 | { |
| 520 | return imx_get_eqos_csr_clk(); |
| 521 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 522 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 523 | static int eqos_set_full_duplex(struct udevice *dev) |
| 524 | { |
| 525 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 526 | |
| 527 | debug("%s(dev=%p):\n", __func__, dev); |
| 528 | |
| 529 | setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int eqos_set_half_duplex(struct udevice *dev) |
| 535 | { |
| 536 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 537 | |
| 538 | debug("%s(dev=%p):\n", __func__, dev); |
| 539 | |
| 540 | clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 541 | |
| 542 | /* WAR: Flush TX queue when switching to half-duplex */ |
| 543 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 544 | EQOS_MTL_TXQ0_OPERATION_MODE_FTQ); |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static int eqos_set_gmii_speed(struct udevice *dev) |
| 550 | { |
| 551 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 552 | |
| 553 | debug("%s(dev=%p):\n", __func__, dev); |
| 554 | |
| 555 | clrbits_le32(&eqos->mac_regs->configuration, |
| 556 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int eqos_set_mii_speed_100(struct udevice *dev) |
| 562 | { |
| 563 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 564 | |
| 565 | debug("%s(dev=%p):\n", __func__, dev); |
| 566 | |
| 567 | setbits_le32(&eqos->mac_regs->configuration, |
| 568 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | static int eqos_set_mii_speed_10(struct udevice *dev) |
| 574 | { |
| 575 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 576 | |
| 577 | debug("%s(dev=%p):\n", __func__, dev); |
| 578 | |
| 579 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 580 | EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS); |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev) |
| 586 | { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 587 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 588 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 589 | ulong rate; |
| 590 | int ret; |
| 591 | |
| 592 | debug("%s(dev=%p):\n", __func__, dev); |
| 593 | |
| 594 | switch (eqos->phy->speed) { |
| 595 | case SPEED_1000: |
| 596 | rate = 125 * 1000 * 1000; |
| 597 | break; |
| 598 | case SPEED_100: |
| 599 | rate = 25 * 1000 * 1000; |
| 600 | break; |
| 601 | case SPEED_10: |
| 602 | rate = 2.5 * 1000 * 1000; |
| 603 | break; |
| 604 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 605 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | ret = clk_set_rate(&eqos->clk_tx, rate); |
| 610 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 611 | pr_err("clk_set_rate(tx_clk, %lu) failed: %d", rate, ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 612 | return ret; |
| 613 | } |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 614 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 619 | static int eqos_set_tx_clk_speed_imx(struct udevice *dev) |
| 620 | { |
Fugang Duan | dd455e6 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 621 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 622 | ulong rate; |
| 623 | int ret; |
| 624 | |
| 625 | debug("%s(dev=%p):\n", __func__, dev); |
| 626 | |
| 627 | switch (eqos->phy->speed) { |
| 628 | case SPEED_1000: |
| 629 | rate = 125 * 1000 * 1000; |
| 630 | break; |
| 631 | case SPEED_100: |
| 632 | rate = 25 * 1000 * 1000; |
| 633 | break; |
| 634 | case SPEED_10: |
| 635 | rate = 2.5 * 1000 * 1000; |
| 636 | break; |
| 637 | default: |
| 638 | pr_err("invalid speed %d", eqos->phy->speed); |
| 639 | return -EINVAL; |
| 640 | } |
| 641 | |
| 642 | ret = imx_eqos_txclk_set_rate(rate); |
| 643 | if (ret < 0) { |
| 644 | pr_err("imx (tx_clk, %lu) failed: %d", rate, ret); |
| 645 | return ret; |
| 646 | } |
| 647 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 651 | static int eqos_adjust_link(struct udevice *dev) |
| 652 | { |
| 653 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 654 | int ret; |
| 655 | bool en_calibration; |
| 656 | |
| 657 | debug("%s(dev=%p):\n", __func__, dev); |
| 658 | |
| 659 | if (eqos->phy->duplex) |
| 660 | ret = eqos_set_full_duplex(dev); |
| 661 | else |
| 662 | ret = eqos_set_half_duplex(dev); |
| 663 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 664 | pr_err("eqos_set_*_duplex() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | switch (eqos->phy->speed) { |
| 669 | case SPEED_1000: |
| 670 | en_calibration = true; |
| 671 | ret = eqos_set_gmii_speed(dev); |
| 672 | break; |
| 673 | case SPEED_100: |
| 674 | en_calibration = true; |
| 675 | ret = eqos_set_mii_speed_100(dev); |
| 676 | break; |
| 677 | case SPEED_10: |
| 678 | en_calibration = false; |
| 679 | ret = eqos_set_mii_speed_10(dev); |
| 680 | break; |
| 681 | default: |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 682 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 683 | return -EINVAL; |
| 684 | } |
| 685 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 686 | pr_err("eqos_set_*mii_speed*() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | if (en_calibration) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 691 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 692 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 693 | pr_err("eqos_calibrate_pads() failed: %d", |
| 694 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 695 | return ret; |
| 696 | } |
| 697 | } else { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 698 | ret = eqos->config->ops->eqos_disable_calibration(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 699 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 700 | pr_err("eqos_disable_calibration() failed: %d", |
| 701 | ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 702 | return ret; |
| 703 | } |
| 704 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 705 | ret = eqos->config->ops->eqos_set_tx_clk_speed(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 706 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 707 | pr_err("eqos_set_tx_clk_speed() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static int eqos_write_hwaddr(struct udevice *dev) |
| 715 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 716 | struct eth_pdata *plat = dev_get_plat(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 717 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 718 | uint32_t val; |
| 719 | |
| 720 | /* |
| 721 | * This function may be called before start() or after stop(). At that |
| 722 | * time, on at least some configurations of the EQoS HW, all clocks to |
| 723 | * the EQoS HW block will be stopped, and a reset signal applied. If |
| 724 | * any register access is attempted in this state, bus timeouts or CPU |
| 725 | * hangs may occur. This check prevents that. |
| 726 | * |
| 727 | * A simple solution to this problem would be to not implement |
| 728 | * write_hwaddr(), since start() always writes the MAC address into HW |
| 729 | * anyway. However, it is desirable to implement write_hwaddr() to |
| 730 | * support the case of SW that runs subsequent to U-Boot which expects |
| 731 | * the MAC address to already be programmed into the EQoS registers, |
| 732 | * which must happen irrespective of whether the U-Boot user (or |
| 733 | * scripts) actually made use of the EQoS device, and hence |
| 734 | * irrespective of whether start() was ever called. |
| 735 | * |
| 736 | * Note that this requirement by subsequent SW is not valid for |
| 737 | * Tegra186, and is likely not valid for any non-PCI instantiation of |
| 738 | * the EQoS HW block. This function is implemented solely as |
| 739 | * future-proofing with the expectation the driver will eventually be |
| 740 | * ported to some system where the expectation above is true. |
| 741 | */ |
| 742 | if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok) |
| 743 | return 0; |
| 744 | |
| 745 | /* Update the MAC address */ |
| 746 | val = (plat->enetaddr[5] << 8) | |
| 747 | (plat->enetaddr[4]); |
| 748 | writel(val, &eqos->mac_regs->address0_high); |
| 749 | val = (plat->enetaddr[3] << 24) | |
| 750 | (plat->enetaddr[2] << 16) | |
| 751 | (plat->enetaddr[1] << 8) | |
| 752 | (plat->enetaddr[0]); |
| 753 | writel(val, &eqos->mac_regs->address0_low); |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 758 | static int eqos_read_rom_hwaddr(struct udevice *dev) |
| 759 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 760 | struct eth_pdata *pdata = dev_get_plat(dev); |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 761 | |
| 762 | #ifdef CONFIG_ARCH_IMX8M |
Simon Glass | 3e14a22 | 2020-12-16 21:20:16 -0700 | [diff] [blame] | 763 | imx_get_mac_from_fuse(dev_seq(dev), pdata->enetaddr); |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 764 | #endif |
| 765 | return !is_valid_ethaddr(pdata->enetaddr); |
| 766 | } |
| 767 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 768 | static int eqos_start(struct udevice *dev) |
| 769 | { |
| 770 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 771 | int ret, i; |
| 772 | ulong rate; |
| 773 | u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl; |
| 774 | ulong last_rx_desc; |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 775 | ulong desc_pad; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 776 | |
| 777 | debug("%s(dev=%p):\n", __func__, dev); |
| 778 | |
| 779 | eqos->tx_desc_idx = 0; |
| 780 | eqos->rx_desc_idx = 0; |
| 781 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 782 | ret = eqos->config->ops->eqos_start_resets(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 783 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 784 | pr_err("eqos_start_resets() failed: %d", ret); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 785 | goto err; |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | udelay(10); |
| 789 | |
| 790 | eqos->reg_access_ok = true; |
| 791 | |
Ălvaro FernĂĄndez Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 792 | ret = wait_for_bit_le32(&eqos->dma_regs->mode, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 793 | EQOS_DMA_MODE_SWR, false, |
| 794 | eqos->config->swr_wait, false); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 795 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 796 | pr_err("EQOS_DMA_MODE_SWR stuck"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 797 | goto err_stop_resets; |
| 798 | } |
| 799 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 800 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 801 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 802 | pr_err("eqos_calibrate_pads() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 803 | goto err_stop_resets; |
| 804 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 805 | rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 806 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 807 | val = (rate / 1000000) - 1; |
| 808 | writel(val, &eqos->mac_regs->us_tic_counter); |
| 809 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 810 | /* |
| 811 | * if PHY was already connected and configured, |
| 812 | * don't need to reconnect/reconfigure again |
| 813 | */ |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 814 | if (!eqos->phy) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 815 | int addr = -1; |
| 816 | #ifdef CONFIG_DM_ETH_PHY |
| 817 | addr = eth_phy_get_addr(dev); |
| 818 | #endif |
| 819 | #ifdef DWC_NET_PHYADDR |
| 820 | addr = DWC_NET_PHYADDR; |
| 821 | #endif |
| 822 | eqos->phy = phy_connect(eqos->mii, addr, dev, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 823 | eqos->config->interface(dev)); |
| 824 | if (!eqos->phy) { |
| 825 | pr_err("phy_connect() failed"); |
| 826 | goto err_stop_resets; |
| 827 | } |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 828 | |
| 829 | if (eqos->max_speed) { |
| 830 | ret = phy_set_supported(eqos->phy, eqos->max_speed); |
| 831 | if (ret) { |
| 832 | pr_err("phy_set_supported() failed: %d", ret); |
| 833 | goto err_shutdown_phy; |
| 834 | } |
| 835 | } |
| 836 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 837 | ret = phy_config(eqos->phy); |
| 838 | if (ret < 0) { |
| 839 | pr_err("phy_config() failed: %d", ret); |
| 840 | goto err_shutdown_phy; |
| 841 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 842 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 843 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 844 | ret = phy_startup(eqos->phy); |
| 845 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 846 | pr_err("phy_startup() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 847 | goto err_shutdown_phy; |
| 848 | } |
| 849 | |
| 850 | if (!eqos->phy->link) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 851 | pr_err("No link"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 852 | goto err_shutdown_phy; |
| 853 | } |
| 854 | |
| 855 | ret = eqos_adjust_link(dev); |
| 856 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 857 | pr_err("eqos_adjust_link() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 858 | goto err_shutdown_phy; |
| 859 | } |
| 860 | |
| 861 | /* Configure MTL */ |
| 862 | |
| 863 | /* Enable Store and Forward mode for TX */ |
| 864 | /* Program Tx operating mode */ |
| 865 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 866 | EQOS_MTL_TXQ0_OPERATION_MODE_TSF | |
| 867 | (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED << |
| 868 | EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT)); |
| 869 | |
| 870 | /* Transmit Queue weight */ |
| 871 | writel(0x10, &eqos->mtl_regs->txq0_quantum_weight); |
| 872 | |
| 873 | /* Enable Store and Forward mode for RX, since no jumbo frame */ |
| 874 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
Daniil Stas | 470c06c | 2021-05-30 13:34:09 +0000 | [diff] [blame] | 875 | EQOS_MTL_RXQ0_OPERATION_MODE_RSF); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 876 | |
| 877 | /* Transmit/Receive queue fifo size; use all RAM for 1 queue */ |
| 878 | val = readl(&eqos->mac_regs->hw_feature1); |
| 879 | tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) & |
| 880 | EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK; |
| 881 | rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) & |
| 882 | EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK; |
| 883 | |
| 884 | /* |
| 885 | * r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting. |
| 886 | * r/tqs is encoded as (n / 256) - 1. |
| 887 | */ |
| 888 | tqs = (128 << tx_fifo_sz) / 256 - 1; |
| 889 | rqs = (128 << rx_fifo_sz) / 256 - 1; |
| 890 | |
| 891 | clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 892 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK << |
| 893 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT, |
| 894 | tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT); |
| 895 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 896 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK << |
| 897 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT, |
| 898 | rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT); |
| 899 | |
| 900 | /* Flow control used only if each channel gets 4KB or more FIFO */ |
| 901 | if (rqs >= ((4096 / 256) - 1)) { |
| 902 | u32 rfd, rfa; |
| 903 | |
| 904 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 905 | EQOS_MTL_RXQ0_OPERATION_MODE_EHFC); |
| 906 | |
| 907 | /* |
| 908 | * Set Threshold for Activating Flow Contol space for min 2 |
| 909 | * frames ie, (1500 * 1) = 1500 bytes. |
| 910 | * |
| 911 | * Set Threshold for Deactivating Flow Contol for space of |
| 912 | * min 1 frame (frame size 1500bytes) in receive fifo |
| 913 | */ |
| 914 | if (rqs == ((4096 / 256) - 1)) { |
| 915 | /* |
| 916 | * This violates the above formula because of FIFO size |
| 917 | * limit therefore overflow may occur inspite of this. |
| 918 | */ |
| 919 | rfd = 0x3; /* Full-3K */ |
| 920 | rfa = 0x1; /* Full-1.5K */ |
| 921 | } else if (rqs == ((8192 / 256) - 1)) { |
| 922 | rfd = 0x6; /* Full-4K */ |
| 923 | rfa = 0xa; /* Full-6K */ |
| 924 | } else if (rqs == ((16384 / 256) - 1)) { |
| 925 | rfd = 0x6; /* Full-4K */ |
| 926 | rfa = 0x12; /* Full-10K */ |
| 927 | } else { |
| 928 | rfd = 0x6; /* Full-4K */ |
| 929 | rfa = 0x1E; /* Full-16K */ |
| 930 | } |
| 931 | |
| 932 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 933 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK << |
| 934 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 935 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK << |
| 936 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT), |
| 937 | (rfd << |
| 938 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 939 | (rfa << |
| 940 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT)); |
| 941 | } |
| 942 | |
| 943 | /* Configure MAC */ |
| 944 | |
| 945 | clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0, |
| 946 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK << |
| 947 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 948 | eqos->config->config_mac << |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 949 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT); |
| 950 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 951 | /* Multicast and Broadcast Queue Enable */ |
| 952 | setbits_le32(&eqos->mac_regs->unused_0a4, |
| 953 | 0x00100000); |
| 954 | /* enable promise mode */ |
| 955 | setbits_le32(&eqos->mac_regs->unused_004[1], |
| 956 | 0x1); |
| 957 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 958 | /* Set TX flow control parameters */ |
| 959 | /* Set Pause Time */ |
| 960 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 961 | 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT); |
| 962 | /* Assign priority for TX flow control */ |
| 963 | clrbits_le32(&eqos->mac_regs->txq_prty_map0, |
| 964 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK << |
| 965 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT); |
| 966 | /* Assign priority for RX flow control */ |
| 967 | clrbits_le32(&eqos->mac_regs->rxq_ctrl2, |
| 968 | EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK << |
| 969 | EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT); |
| 970 | /* Enable flow control */ |
| 971 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 972 | EQOS_MAC_Q0_TX_FLOW_CTRL_TFE); |
| 973 | setbits_le32(&eqos->mac_regs->rx_flow_ctrl, |
| 974 | EQOS_MAC_RX_FLOW_CTRL_RFE); |
| 975 | |
| 976 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 977 | EQOS_MAC_CONFIGURATION_GPSLCE | |
| 978 | EQOS_MAC_CONFIGURATION_WD | |
| 979 | EQOS_MAC_CONFIGURATION_JD | |
| 980 | EQOS_MAC_CONFIGURATION_JE, |
| 981 | EQOS_MAC_CONFIGURATION_CST | |
| 982 | EQOS_MAC_CONFIGURATION_ACS); |
| 983 | |
| 984 | eqos_write_hwaddr(dev); |
| 985 | |
| 986 | /* Configure DMA */ |
| 987 | |
| 988 | /* Enable OSP mode */ |
| 989 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 990 | EQOS_DMA_CH0_TX_CONTROL_OSP); |
| 991 | |
| 992 | /* RX buffer size. Must be a multiple of bus width */ |
| 993 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 994 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK << |
| 995 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT, |
| 996 | EQOS_MAX_PACKET_SIZE << |
| 997 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT); |
| 998 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 999 | desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) / |
| 1000 | eqos->config->axi_bus_width; |
| 1001 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1002 | setbits_le32(&eqos->dma_regs->ch0_control, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1003 | EQOS_DMA_CH0_CONTROL_PBLX8 | |
| 1004 | (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT)); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1005 | |
| 1006 | /* |
| 1007 | * Burst length must be < 1/2 FIFO size. |
| 1008 | * FIFO size in tqs is encoded as (n / 256) - 1. |
| 1009 | * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes. |
| 1010 | * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1. |
| 1011 | */ |
| 1012 | pbl = tqs + 1; |
| 1013 | if (pbl > 32) |
| 1014 | pbl = 32; |
| 1015 | clrsetbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1016 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK << |
| 1017 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT, |
| 1018 | pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT); |
| 1019 | |
| 1020 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1021 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK << |
| 1022 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT, |
| 1023 | 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT); |
| 1024 | |
| 1025 | /* DMA performance configuration */ |
| 1026 | val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) | |
| 1027 | EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 | |
| 1028 | EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4; |
| 1029 | writel(val, &eqos->dma_regs->sysbus_mode); |
| 1030 | |
| 1031 | /* Set up descriptors */ |
| 1032 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1033 | memset(eqos->descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_NUM); |
| 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); |
| 1219 | uchar *packet_expected; |
| 1220 | struct eqos_desc *rx_desc; |
| 1221 | |
| 1222 | debug("%s(packet=%p, length=%d)\n", __func__, packet, length); |
| 1223 | |
| 1224 | packet_expected = eqos->rx_dma_buf + |
| 1225 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1226 | if (packet != packet_expected) { |
| 1227 | debug("%s: Unexpected packet (expected %p)\n", __func__, |
| 1228 | packet_expected); |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1232 | eqos->config->ops->eqos_inval_buffer(packet, length); |
| 1233 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1234 | rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true); |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1235 | |
Marek Vasut | 091b6db | 2020-03-23 02:11:46 +0100 | [diff] [blame] | 1236 | rx_desc->des0 = 0; |
| 1237 | mb(); |
| 1238 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1239 | eqos->config->ops->eqos_inval_buffer(packet, length); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1240 | rx_desc->des0 = (u32)(ulong)packet; |
| 1241 | rx_desc->des1 = 0; |
| 1242 | rx_desc->des2 = 0; |
| 1243 | /* |
| 1244 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1245 | * writes to the rest of the descriptor too. |
| 1246 | */ |
| 1247 | mb(); |
Marek Vasut | d54c98e | 2020-03-23 02:02:57 +0100 | [diff] [blame] | 1248 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1249 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1250 | |
| 1251 | writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1252 | |
| 1253 | eqos->rx_desc_idx++; |
| 1254 | eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX; |
| 1255 | |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | static int eqos_probe_resources_core(struct udevice *dev) |
| 1260 | { |
| 1261 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1262 | int ret; |
| 1263 | |
| 1264 | debug("%s(dev=%p):\n", __func__, dev); |
| 1265 | |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1266 | eqos->descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_NUM); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1267 | if (!eqos->descs) { |
| 1268 | debug("%s: eqos_alloc_descs() failed\n", __func__); |
| 1269 | ret = -ENOMEM; |
| 1270 | goto err; |
| 1271 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1272 | |
| 1273 | eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE); |
| 1274 | if (!eqos->tx_dma_buf) { |
| 1275 | debug("%s: memalign(tx_dma_buf) failed\n", __func__); |
| 1276 | ret = -ENOMEM; |
| 1277 | goto err_free_descs; |
| 1278 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1279 | debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1280 | |
| 1281 | eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE); |
| 1282 | if (!eqos->rx_dma_buf) { |
| 1283 | debug("%s: memalign(rx_dma_buf) failed\n", __func__); |
| 1284 | ret = -ENOMEM; |
| 1285 | goto err_free_tx_dma_buf; |
| 1286 | } |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1287 | debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1288 | |
| 1289 | eqos->rx_pkt = malloc(EQOS_MAX_PACKET_SIZE); |
| 1290 | if (!eqos->rx_pkt) { |
| 1291 | debug("%s: malloc(rx_pkt) failed\n", __func__); |
| 1292 | ret = -ENOMEM; |
| 1293 | goto err_free_rx_dma_buf; |
| 1294 | } |
| 1295 | debug("%s: rx_pkt=%p\n", __func__, eqos->rx_pkt); |
| 1296 | |
Marek Vasut | e8e5c2b | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1297 | eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf, |
| 1298 | EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX); |
| 1299 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1300 | debug("%s: OK\n", __func__); |
| 1301 | return 0; |
| 1302 | |
| 1303 | err_free_rx_dma_buf: |
| 1304 | free(eqos->rx_dma_buf); |
| 1305 | err_free_tx_dma_buf: |
| 1306 | free(eqos->tx_dma_buf); |
| 1307 | err_free_descs: |
| 1308 | eqos_free_descs(eqos->descs); |
| 1309 | err: |
| 1310 | |
| 1311 | debug("%s: returns %d\n", __func__, ret); |
| 1312 | return ret; |
| 1313 | } |
| 1314 | |
| 1315 | static int eqos_remove_resources_core(struct udevice *dev) |
| 1316 | { |
| 1317 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1318 | |
| 1319 | debug("%s(dev=%p):\n", __func__, dev); |
| 1320 | |
| 1321 | free(eqos->rx_pkt); |
| 1322 | free(eqos->rx_dma_buf); |
| 1323 | free(eqos->tx_dma_buf); |
| 1324 | eqos_free_descs(eqos->descs); |
| 1325 | |
| 1326 | debug("%s: OK\n", __func__); |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
| 1330 | static int eqos_probe_resources_tegra186(struct udevice *dev) |
| 1331 | { |
| 1332 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1333 | int ret; |
| 1334 | |
| 1335 | debug("%s(dev=%p):\n", __func__, dev); |
| 1336 | |
| 1337 | ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); |
| 1338 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1339 | pr_err("reset_get_by_name(rst) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1340 | return ret; |
| 1341 | } |
| 1342 | |
| 1343 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 1344 | &eqos->phy_reset_gpio, |
| 1345 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 1346 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1347 | pr_err("gpio_request_by_name(phy reset) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1348 | goto err_free_reset_eqos; |
| 1349 | } |
| 1350 | |
| 1351 | ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus); |
| 1352 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1353 | pr_err("clk_get_by_name(slave_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1354 | goto err_free_gpio_phy_reset; |
| 1355 | } |
| 1356 | |
| 1357 | ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus); |
| 1358 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1359 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1360 | goto err_free_clk_slave_bus; |
| 1361 | } |
| 1362 | |
| 1363 | ret = clk_get_by_name(dev, "rx", &eqos->clk_rx); |
| 1364 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1365 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1366 | goto err_free_clk_master_bus; |
| 1367 | } |
| 1368 | |
| 1369 | ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref); |
| 1370 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1371 | pr_err("clk_get_by_name(ptp_ref) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1372 | goto err_free_clk_rx; |
| 1373 | return ret; |
| 1374 | } |
| 1375 | |
| 1376 | ret = clk_get_by_name(dev, "tx", &eqos->clk_tx); |
| 1377 | if (ret) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1378 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1379 | goto err_free_clk_ptp_ref; |
| 1380 | } |
| 1381 | |
| 1382 | debug("%s: OK\n", __func__); |
| 1383 | return 0; |
| 1384 | |
| 1385 | err_free_clk_ptp_ref: |
| 1386 | clk_free(&eqos->clk_ptp_ref); |
| 1387 | err_free_clk_rx: |
| 1388 | clk_free(&eqos->clk_rx); |
| 1389 | err_free_clk_master_bus: |
| 1390 | clk_free(&eqos->clk_master_bus); |
| 1391 | err_free_clk_slave_bus: |
| 1392 | clk_free(&eqos->clk_slave_bus); |
| 1393 | err_free_gpio_phy_reset: |
| 1394 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1395 | err_free_reset_eqos: |
| 1396 | reset_free(&eqos->reset_ctl); |
| 1397 | |
| 1398 | debug("%s: returns %d\n", __func__, ret); |
| 1399 | return ret; |
| 1400 | } |
| 1401 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1402 | /* board-specific Ethernet Interface initializations. */ |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1403 | __weak int board_interface_eth_init(struct udevice *dev, |
| 1404 | phy_interface_t interface_type) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1405 | { |
| 1406 | return 0; |
| 1407 | } |
| 1408 | |
| 1409 | static int eqos_probe_resources_stm32(struct udevice *dev) |
| 1410 | { |
| 1411 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1412 | int ret; |
| 1413 | phy_interface_t interface; |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1414 | |
| 1415 | debug("%s(dev=%p):\n", __func__, dev); |
| 1416 | |
| 1417 | interface = eqos->config->interface(dev); |
| 1418 | |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 1419 | if (interface == PHY_INTERFACE_MODE_NA) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1420 | pr_err("Invalid PHY interface\n"); |
| 1421 | return -EINVAL; |
| 1422 | } |
| 1423 | |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1424 | ret = board_interface_eth_init(dev, interface); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1425 | if (ret) |
| 1426 | return -EINVAL; |
| 1427 | |
Patrick Delaunay | 5c8db37 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 1428 | eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
| 1429 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1430 | ret = clk_get_by_name(dev, "stmmaceth", &eqos->clk_master_bus); |
| 1431 | if (ret) { |
| 1432 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
| 1433 | goto err_probe; |
| 1434 | } |
| 1435 | |
| 1436 | ret = clk_get_by_name(dev, "mac-clk-rx", &eqos->clk_rx); |
| 1437 | if (ret) { |
| 1438 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
| 1439 | goto err_free_clk_master_bus; |
| 1440 | } |
| 1441 | |
| 1442 | ret = clk_get_by_name(dev, "mac-clk-tx", &eqos->clk_tx); |
| 1443 | if (ret) { |
| 1444 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
| 1445 | goto err_free_clk_rx; |
| 1446 | } |
| 1447 | |
| 1448 | /* Get ETH_CLK clocks (optional) */ |
| 1449 | ret = clk_get_by_name(dev, "eth-ck", &eqos->clk_ck); |
| 1450 | if (ret) |
| 1451 | pr_warn("No phy clock provided %d", ret); |
| 1452 | |
| 1453 | debug("%s: OK\n", __func__); |
| 1454 | return 0; |
| 1455 | |
| 1456 | err_free_clk_rx: |
| 1457 | clk_free(&eqos->clk_rx); |
| 1458 | err_free_clk_master_bus: |
| 1459 | clk_free(&eqos->clk_master_bus); |
| 1460 | err_probe: |
| 1461 | |
| 1462 | debug("%s: returns %d\n", __func__, ret); |
| 1463 | return ret; |
| 1464 | } |
| 1465 | |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1466 | static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1467 | { |
| 1468 | return PHY_INTERFACE_MODE_MII; |
| 1469 | } |
| 1470 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1471 | static int eqos_probe_resources_imx(struct udevice *dev) |
| 1472 | { |
| 1473 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1474 | phy_interface_t interface; |
| 1475 | |
| 1476 | debug("%s(dev=%p):\n", __func__, dev); |
| 1477 | |
| 1478 | interface = eqos->config->interface(dev); |
| 1479 | |
Marek BehĂșn | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 1480 | if (interface == PHY_INTERFACE_MODE_NA) { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1481 | pr_err("Invalid PHY interface\n"); |
| 1482 | return -EINVAL; |
| 1483 | } |
| 1484 | |
| 1485 | debug("%s: OK\n", __func__); |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1489 | static int eqos_remove_resources_tegra186(struct udevice *dev) |
| 1490 | { |
| 1491 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1492 | |
| 1493 | debug("%s(dev=%p):\n", __func__, dev); |
| 1494 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1495 | #ifdef CONFIG_CLK |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1496 | clk_free(&eqos->clk_tx); |
| 1497 | clk_free(&eqos->clk_ptp_ref); |
| 1498 | clk_free(&eqos->clk_rx); |
| 1499 | clk_free(&eqos->clk_slave_bus); |
| 1500 | clk_free(&eqos->clk_master_bus); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1501 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1502 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1503 | reset_free(&eqos->reset_ctl); |
| 1504 | |
| 1505 | debug("%s: OK\n", __func__); |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1509 | static int eqos_remove_resources_stm32(struct udevice *dev) |
| 1510 | { |
| 1511 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1512 | |
| 1513 | debug("%s(dev=%p):\n", __func__, dev); |
| 1514 | |
Peng Fan | 809993f | 2022-07-26 16:41:13 +0800 | [diff] [blame] | 1515 | #ifdef CONFIG_CLK |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1516 | clk_free(&eqos->clk_tx); |
| 1517 | clk_free(&eqos->clk_rx); |
| 1518 | clk_free(&eqos->clk_master_bus); |
| 1519 | if (clk_valid(&eqos->clk_ck)) |
| 1520 | clk_free(&eqos->clk_ck); |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1521 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1522 | |
Christophe Roullier | 104dab5 | 2020-03-18 10:50:15 +0100 | [diff] [blame] | 1523 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) |
| 1524 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1525 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1526 | debug("%s: OK\n", __func__); |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1530 | static int eqos_probe(struct udevice *dev) |
| 1531 | { |
| 1532 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1533 | int ret; |
| 1534 | |
| 1535 | debug("%s(dev=%p):\n", __func__, dev); |
| 1536 | |
| 1537 | eqos->dev = dev; |
| 1538 | eqos->config = (void *)dev_get_driver_data(dev); |
| 1539 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1540 | eqos->regs = dev_read_addr(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1541 | if (eqos->regs == FDT_ADDR_T_NONE) { |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1542 | pr_err("dev_read_addr() failed"); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1543 | return -ENODEV; |
| 1544 | } |
| 1545 | eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE); |
| 1546 | eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE); |
| 1547 | eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE); |
| 1548 | eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE); |
| 1549 | |
| 1550 | ret = eqos_probe_resources_core(dev); |
| 1551 | if (ret < 0) { |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1552 | pr_err("eqos_probe_resources_core() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1553 | return ret; |
| 1554 | } |
| 1555 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1556 | ret = eqos->config->ops->eqos_probe_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1557 | if (ret < 0) { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1558 | pr_err("eqos_probe_resources() failed: %d", ret); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1559 | goto err_remove_resources_core; |
| 1560 | } |
| 1561 | |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1562 | ret = eqos->config->ops->eqos_start_clks(dev); |
| 1563 | if (ret < 0) { |
| 1564 | pr_err("eqos_start_clks() failed: %d", ret); |
| 1565 | goto err_remove_resources_tegra; |
| 1566 | } |
| 1567 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1568 | #ifdef CONFIG_DM_ETH_PHY |
| 1569 | eqos->mii = eth_phy_get_mdio_bus(dev); |
| 1570 | #endif |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1571 | if (!eqos->mii) { |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1572 | eqos->mii = mdio_alloc(); |
| 1573 | if (!eqos->mii) { |
| 1574 | pr_err("mdio_alloc() failed"); |
| 1575 | ret = -ENOMEM; |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1576 | goto err_stop_clks; |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1577 | } |
| 1578 | eqos->mii->read = eqos_mdio_read; |
| 1579 | eqos->mii->write = eqos_mdio_write; |
| 1580 | eqos->mii->priv = eqos; |
| 1581 | strcpy(eqos->mii->name, dev->name); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1582 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1583 | ret = mdio_register(eqos->mii); |
| 1584 | if (ret < 0) { |
| 1585 | pr_err("mdio_register() failed: %d", ret); |
| 1586 | goto err_free_mdio; |
| 1587 | } |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1588 | } |
| 1589 | |
Ye Li | ad122b7 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1590 | #ifdef CONFIG_DM_ETH_PHY |
| 1591 | eth_phy_set_mdio_bus(dev, eqos->mii); |
| 1592 | #endif |
| 1593 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1594 | debug("%s: OK\n", __func__); |
| 1595 | return 0; |
| 1596 | |
| 1597 | err_free_mdio: |
| 1598 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1599 | err_stop_clks: |
| 1600 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1601 | err_remove_resources_tegra: |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1602 | eqos->config->ops->eqos_remove_resources(dev); |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1603 | err_remove_resources_core: |
| 1604 | eqos_remove_resources_core(dev); |
| 1605 | |
| 1606 | debug("%s: returns %d\n", __func__, ret); |
| 1607 | return ret; |
| 1608 | } |
| 1609 | |
| 1610 | static int eqos_remove(struct udevice *dev) |
| 1611 | { |
| 1612 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1613 | |
| 1614 | debug("%s(dev=%p):\n", __func__, dev); |
| 1615 | |
| 1616 | mdio_unregister(eqos->mii); |
| 1617 | mdio_free(eqos->mii); |
Marek Vasut | 30b28c4 | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1618 | eqos->config->ops->eqos_stop_clks(dev); |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1619 | eqos->config->ops->eqos_remove_resources(dev); |
| 1620 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1621 | eqos_probe_resources_core(dev); |
| 1622 | |
| 1623 | debug("%s: OK\n", __func__); |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
Peng Fan | c0a5995 | 2022-07-26 16:41:14 +0800 | [diff] [blame^] | 1627 | int eqos_null_ops(struct udevice *dev) |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1628 | { |
| 1629 | return 0; |
| 1630 | } |
| 1631 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1632 | static const struct eth_ops eqos_ops = { |
| 1633 | .start = eqos_start, |
| 1634 | .stop = eqos_stop, |
| 1635 | .send = eqos_send, |
| 1636 | .recv = eqos_recv, |
| 1637 | .free_pkt = eqos_free_pkt, |
| 1638 | .write_hwaddr = eqos_write_hwaddr, |
Ye Li | 3fb1a0e | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1639 | .read_rom_hwaddr = eqos_read_rom_hwaddr, |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1640 | }; |
| 1641 | |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1642 | static struct eqos_ops eqos_tegra186_ops = { |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1643 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1644 | .eqos_flush_desc = eqos_flush_desc_generic, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1645 | .eqos_inval_buffer = eqos_inval_buffer_tegra186, |
| 1646 | .eqos_flush_buffer = eqos_flush_buffer_tegra186, |
| 1647 | .eqos_probe_resources = eqos_probe_resources_tegra186, |
| 1648 | .eqos_remove_resources = eqos_remove_resources_tegra186, |
| 1649 | .eqos_stop_resets = eqos_stop_resets_tegra186, |
| 1650 | .eqos_start_resets = eqos_start_resets_tegra186, |
| 1651 | .eqos_stop_clks = eqos_stop_clks_tegra186, |
| 1652 | .eqos_start_clks = eqos_start_clks_tegra186, |
| 1653 | .eqos_calibrate_pads = eqos_calibrate_pads_tegra186, |
| 1654 | .eqos_disable_calibration = eqos_disable_calibration_tegra186, |
| 1655 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186, |
| 1656 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186 |
| 1657 | }; |
| 1658 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1659 | static const struct eqos_config __maybe_unused eqos_tegra186_config = { |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1660 | .reg_access_always_ok = false, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1661 | .mdio_wait = 10, |
| 1662 | .swr_wait = 10, |
| 1663 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1664 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1665 | .axi_bus_width = EQOS_AXI_WIDTH_128, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1666 | .interface = eqos_get_interface_tegra186, |
| 1667 | .ops = &eqos_tegra186_ops |
| 1668 | }; |
| 1669 | |
| 1670 | static struct eqos_ops eqos_stm32_ops = { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1671 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1672 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 1673 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 1674 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1675 | .eqos_probe_resources = eqos_probe_resources_stm32, |
| 1676 | .eqos_remove_resources = eqos_remove_resources_stm32, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1677 | .eqos_stop_resets = eqos_null_ops, |
| 1678 | .eqos_start_resets = eqos_null_ops, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1679 | .eqos_stop_clks = eqos_stop_clks_stm32, |
| 1680 | .eqos_start_clks = eqos_start_clks_stm32, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1681 | .eqos_calibrate_pads = eqos_null_ops, |
| 1682 | .eqos_disable_calibration = eqos_null_ops, |
| 1683 | .eqos_set_tx_clk_speed = eqos_null_ops, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1684 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_stm32 |
| 1685 | }; |
| 1686 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1687 | static const struct eqos_config __maybe_unused eqos_stm32_config = { |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1688 | .reg_access_always_ok = false, |
| 1689 | .mdio_wait = 10000, |
| 1690 | .swr_wait = 50, |
| 1691 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, |
| 1692 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1693 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1694 | .interface = dev_read_phy_mode, |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1695 | .ops = &eqos_stm32_ops |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1696 | }; |
| 1697 | |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1698 | static struct eqos_ops eqos_imx_ops = { |
| 1699 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1700 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 1701 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 1702 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
| 1703 | .eqos_probe_resources = eqos_probe_resources_imx, |
Patrick Delaunay | 1bc6ce7 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1704 | .eqos_remove_resources = eqos_null_ops, |
| 1705 | .eqos_stop_resets = eqos_null_ops, |
| 1706 | .eqos_start_resets = eqos_null_ops, |
| 1707 | .eqos_stop_clks = eqos_null_ops, |
| 1708 | .eqos_start_clks = eqos_null_ops, |
| 1709 | .eqos_calibrate_pads = eqos_null_ops, |
| 1710 | .eqos_disable_calibration = eqos_null_ops, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1711 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_imx, |
| 1712 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_imx |
| 1713 | }; |
| 1714 | |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1715 | struct eqos_config __maybe_unused eqos_imx_config = { |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1716 | .reg_access_always_ok = false, |
Ye Li | f369e69 | 2020-12-28 20:15:10 +0800 | [diff] [blame] | 1717 | .mdio_wait = 10, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1718 | .swr_wait = 50, |
| 1719 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1720 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
Marek Vasut | 8907773 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1721 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
Marek BehĂșn | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1722 | .interface = dev_read_phy_mode, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1723 | .ops = &eqos_imx_ops |
| 1724 | }; |
| 1725 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1726 | static const struct udevice_id eqos_ids[] = { |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1727 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186) |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1728 | { |
| 1729 | .compatible = "nvidia,tegra186-eqos", |
| 1730 | .data = (ulong)&eqos_tegra186_config |
| 1731 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1732 | #endif |
| 1733 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32) |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1734 | { |
Patrick Delaunay | a0466f6 | 2020-05-14 15:00:23 +0200 | [diff] [blame] | 1735 | .compatible = "st,stm32mp1-dwmac", |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1736 | .data = (ulong)&eqos_stm32_config |
| 1737 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1738 | #endif |
| 1739 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX) |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1740 | { |
Marek Vasut | 7af1138 | 2022-02-26 04:36:37 +0100 | [diff] [blame] | 1741 | .compatible = "nxp,imx8mp-dwmac-eqos", |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1742 | .data = (ulong)&eqos_imx_config |
| 1743 | }, |
Patrick Delaunay | 6808390 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1744 | #endif |
Christophe Roullier | 6beb780 | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1745 | |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1746 | { } |
| 1747 | }; |
| 1748 | |
| 1749 | U_BOOT_DRIVER(eth_eqos) = { |
| 1750 | .name = "eth_eqos", |
| 1751 | .id = UCLASS_ETH, |
Fugang Duan | 37aae5f | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1752 | .of_match = of_match_ptr(eqos_ids), |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1753 | .probe = eqos_probe, |
| 1754 | .remove = eqos_remove, |
| 1755 | .ops = &eqos_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1756 | .priv_auto = sizeof(struct eqos_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1757 | .plat_auto = sizeof(struct eth_pdata), |
Stephen Warren | 5070960 | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1758 | }; |