Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2010 |
Patrick Delaunay | eae488b | 2022-05-20 18:38:10 +0200 | [diff] [blame] | 4 | * Vipin Kumar, STMicroelectronics, vipin.kumar@st.com. |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 8 | * Designware ethernet IP driver for U-Boot |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 12 | #include <clk.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 13 | #include <cpu_func.h> |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 17 | #include <miiphy.h> |
| 18 | #include <malloc.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 19 | #include <net.h> |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 20 | #include <pci.h> |
Ley Foon Tan | 495c70f | 2018-06-14 18:45:23 +0800 | [diff] [blame] | 21 | #include <reset.h> |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 22 | #include <phys2bus.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 23 | #include <asm/cache.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 24 | #include <dm/device_compat.h> |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 25 | #include <dm/device-internal.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 26 | #include <dm/devres.h> |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 27 | #include <dm/lists.h> |
Stefan Roese | ef76025 | 2012-05-07 12:04:25 +0200 | [diff] [blame] | 28 | #include <linux/compiler.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 29 | #include <linux/delay.h> |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 30 | #include <linux/err.h> |
Florian Fainelli | 7a9ca9d | 2017-12-09 14:59:55 -0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 32 | #include <asm/io.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 33 | #include <linux/printk.h> |
Jacob Chen | 6ec922f | 2017-03-27 16:54:17 +0800 | [diff] [blame] | 34 | #include <power/regulator.h> |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 35 | #include "designware.h" |
| 36 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 37 | static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) |
| 38 | { |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 39 | struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv); |
| 40 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 41 | ulong start; |
| 42 | u16 miiaddr; |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 43 | int timeout = CFG_MDIO_TIMEOUT; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 44 | |
| 45 | miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) | |
| 46 | ((reg << MIIREGSHIFT) & MII_REGMSK); |
| 47 | |
| 48 | writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr); |
| 49 | |
| 50 | start = get_timer(0); |
| 51 | while (get_timer(start) < timeout) { |
| 52 | if (!(readl(&mac_p->miiaddr) & MII_BUSY)) |
| 53 | return readl(&mac_p->miidata); |
| 54 | udelay(10); |
| 55 | }; |
| 56 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 57 | return -ETIMEDOUT; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static int dw_mdio_write(struct mii_dev *bus, int addr, int devad, int reg, |
| 61 | u16 val) |
| 62 | { |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 63 | struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv); |
| 64 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 65 | ulong start; |
| 66 | u16 miiaddr; |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 67 | int ret = -ETIMEDOUT, timeout = CFG_MDIO_TIMEOUT; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 68 | |
| 69 | writel(val, &mac_p->miidata); |
| 70 | miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) | |
| 71 | ((reg << MIIREGSHIFT) & MII_REGMSK) | MII_WRITE; |
| 72 | |
| 73 | writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr); |
| 74 | |
| 75 | start = get_timer(0); |
| 76 | while (get_timer(start) < timeout) { |
| 77 | if (!(readl(&mac_p->miiaddr) & MII_BUSY)) { |
| 78 | ret = 0; |
| 79 | break; |
| 80 | } |
| 81 | udelay(10); |
| 82 | }; |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
Tom Rini | acb30cc | 2022-11-27 10:25:07 -0500 | [diff] [blame] | 87 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Neil Armstrong | 98b8204 | 2021-04-21 10:58:01 +0200 | [diff] [blame] | 88 | static int __dw_mdio_reset(struct udevice *dev) |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 89 | { |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 90 | struct dw_eth_dev *priv = dev_get_priv(dev); |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 91 | struct dw_eth_pdata *pdata = dev_get_plat(dev); |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 92 | int ret; |
| 93 | |
| 94 | if (!dm_gpio_is_valid(&priv->reset_gpio)) |
| 95 | return 0; |
| 96 | |
| 97 | /* reset the phy */ |
| 98 | ret = dm_gpio_set_value(&priv->reset_gpio, 0); |
| 99 | if (ret) |
| 100 | return ret; |
| 101 | |
| 102 | udelay(pdata->reset_delays[0]); |
| 103 | |
| 104 | ret = dm_gpio_set_value(&priv->reset_gpio, 1); |
| 105 | if (ret) |
| 106 | return ret; |
| 107 | |
| 108 | udelay(pdata->reset_delays[1]); |
| 109 | |
| 110 | ret = dm_gpio_set_value(&priv->reset_gpio, 0); |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | |
| 114 | udelay(pdata->reset_delays[2]); |
| 115 | |
| 116 | return 0; |
| 117 | } |
Neil Armstrong | 98b8204 | 2021-04-21 10:58:01 +0200 | [diff] [blame] | 118 | |
| 119 | static int dw_mdio_reset(struct mii_dev *bus) |
| 120 | { |
| 121 | struct udevice *dev = bus->priv; |
| 122 | |
| 123 | return __dw_mdio_reset(dev); |
| 124 | } |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 125 | #endif |
| 126 | |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 127 | #if IS_ENABLED(CONFIG_DM_MDIO) |
| 128 | int designware_eth_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg) |
| 129 | { |
| 130 | struct mdio_perdev_priv *pdata = dev_get_uclass_priv(mdio_dev); |
| 131 | |
| 132 | return dw_mdio_read(pdata->mii_bus, addr, devad, reg); |
| 133 | } |
| 134 | |
| 135 | int designware_eth_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 val) |
| 136 | { |
| 137 | struct mdio_perdev_priv *pdata = dev_get_uclass_priv(mdio_dev); |
| 138 | |
| 139 | return dw_mdio_write(pdata->mii_bus, addr, devad, reg, val); |
| 140 | } |
| 141 | |
| 142 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 143 | int designware_eth_mdio_reset(struct udevice *mdio_dev) |
| 144 | { |
Neil Armstrong | 98b8204 | 2021-04-21 10:58:01 +0200 | [diff] [blame] | 145 | struct mdio_perdev_priv *mdio_pdata = dev_get_uclass_priv(mdio_dev); |
| 146 | struct udevice *dev = mdio_pdata->mii_bus->priv; |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 147 | |
Neil Armstrong | 98b8204 | 2021-04-21 10:58:01 +0200 | [diff] [blame] | 148 | return __dw_mdio_reset(dev->parent); |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 149 | } |
| 150 | #endif |
| 151 | |
| 152 | static const struct mdio_ops designware_eth_mdio_ops = { |
| 153 | .read = designware_eth_mdio_read, |
| 154 | .write = designware_eth_mdio_write, |
| 155 | #if CONFIG_IS_ENABLED(DM_GPIO) |
| 156 | .reset = designware_eth_mdio_reset, |
| 157 | #endif |
| 158 | }; |
| 159 | |
| 160 | static int designware_eth_mdio_probe(struct udevice *dev) |
| 161 | { |
| 162 | /* Use the priv data of parent */ |
| 163 | dev_set_priv(dev, dev_get_priv(dev->parent)); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | U_BOOT_DRIVER(designware_eth_mdio) = { |
| 169 | .name = "eth_designware_mdio", |
| 170 | .id = UCLASS_MDIO, |
| 171 | .probe = designware_eth_mdio_probe, |
| 172 | .ops = &designware_eth_mdio_ops, |
| 173 | .plat_auto = sizeof(struct mdio_perdev_priv), |
| 174 | }; |
| 175 | #endif |
| 176 | |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 177 | static int dw_mdio_init(const char *name, void *priv) |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 178 | { |
| 179 | struct mii_dev *bus = mdio_alloc(); |
| 180 | |
| 181 | if (!bus) { |
| 182 | printf("Failed to allocate MDIO bus\n"); |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 183 | return -ENOMEM; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | bus->read = dw_mdio_read; |
| 187 | bus->write = dw_mdio_write; |
Ben Whitten | 192bc69 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 188 | snprintf(bus->name, sizeof(bus->name), "%s", name); |
Tom Rini | acb30cc | 2022-11-27 10:25:07 -0500 | [diff] [blame] | 189 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 190 | bus->reset = dw_mdio_reset; |
| 191 | #endif |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 192 | |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 193 | bus->priv = priv; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 194 | |
| 195 | return mdio_register(bus); |
| 196 | } |
Vipin Kumar | 13edd17 | 2012-03-26 00:09:56 +0000 | [diff] [blame] | 197 | |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 198 | #if IS_ENABLED(CONFIG_DM_MDIO) |
| 199 | static int dw_dm_mdio_init(const char *name, void *priv) |
| 200 | { |
| 201 | struct udevice *dev = priv; |
| 202 | ofnode node; |
| 203 | int ret; |
| 204 | |
| 205 | ofnode_for_each_subnode(node, dev_ofnode(dev)) { |
| 206 | const char *subnode_name = ofnode_get_name(node); |
| 207 | struct udevice *mdiodev; |
| 208 | |
| 209 | if (strcmp(subnode_name, "mdio")) |
| 210 | continue; |
| 211 | |
| 212 | ret = device_bind_driver_to_node(dev, "eth_designware_mdio", |
| 213 | subnode_name, node, &mdiodev); |
| 214 | if (ret) |
| 215 | debug("%s: not able to bind mdio device node\n", __func__); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | printf("%s: mdio node is missing, registering legacy mdio bus", __func__); |
| 221 | |
| 222 | return dw_mdio_init(name, priv); |
| 223 | } |
| 224 | #endif |
| 225 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 226 | static void tx_descs_init(struct dw_eth_dev *priv) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 227 | { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 228 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
| 229 | struct dmamacdescr *desc_table_p = &priv->tx_mac_descrtable[0]; |
| 230 | char *txbuffs = &priv->txbuffs[0]; |
| 231 | struct dmamacdescr *desc_p; |
| 232 | u32 idx; |
| 233 | |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 234 | for (idx = 0; idx < CFG_TX_DESCR_NUM; idx++) { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 235 | desc_p = &desc_table_p[idx]; |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 236 | desc_p->dmamac_addr = dev_phys_to_bus(priv->dev, |
| 237 | (ulong)&txbuffs[idx * CFG_ETH_BUFSIZE]); |
| 238 | desc_p->dmamac_next = dev_phys_to_bus(priv->dev, |
| 239 | (ulong)&desc_table_p[idx + 1]); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 240 | |
| 241 | #if defined(CONFIG_DW_ALTDESCRIPTOR) |
| 242 | desc_p->txrx_status &= ~(DESC_TXSTS_TXINT | DESC_TXSTS_TXLAST | |
Marek Vasut | 2b26109 | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 243 | DESC_TXSTS_TXFIRST | DESC_TXSTS_TXCRCDIS | |
| 244 | DESC_TXSTS_TXCHECKINSCTRL | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 245 | DESC_TXSTS_TXRINGEND | DESC_TXSTS_TXPADDIS); |
| 246 | |
| 247 | desc_p->txrx_status |= DESC_TXSTS_TXCHAIN; |
| 248 | desc_p->dmamac_cntl = 0; |
| 249 | desc_p->txrx_status &= ~(DESC_TXSTS_MSK | DESC_TXSTS_OWNBYDMA); |
| 250 | #else |
| 251 | desc_p->dmamac_cntl = DESC_TXCTRL_TXCHAIN; |
| 252 | desc_p->txrx_status = 0; |
| 253 | #endif |
| 254 | } |
| 255 | |
| 256 | /* Correcting the last pointer of the chain */ |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 257 | desc_p->dmamac_next = dev_phys_to_bus(priv->dev, (ulong)&desc_table_p[0]); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 258 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 259 | /* Flush all Tx buffer descriptors at once */ |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 260 | flush_dcache_range((ulong)priv->tx_mac_descrtable, |
| 261 | (ulong)priv->tx_mac_descrtable + |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 262 | sizeof(priv->tx_mac_descrtable)); |
| 263 | |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 264 | writel(dev_phys_to_bus(priv->dev, (ulong)&desc_table_p[0]), |
| 265 | &dma_p->txdesclistaddr); |
Alexey Brodkin | 74cb708 | 2014-01-13 13:28:38 +0400 | [diff] [blame] | 266 | priv->tx_currdescnum = 0; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 267 | } |
| 268 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 269 | static void rx_descs_init(struct dw_eth_dev *priv) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 270 | { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 271 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
| 272 | struct dmamacdescr *desc_table_p = &priv->rx_mac_descrtable[0]; |
| 273 | char *rxbuffs = &priv->rxbuffs[0]; |
| 274 | struct dmamacdescr *desc_p; |
| 275 | u32 idx; |
| 276 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 277 | /* Before passing buffers to GMAC we need to make sure zeros |
| 278 | * written there right after "priv" structure allocation were |
| 279 | * flushed into RAM. |
| 280 | * Otherwise there's a chance to get some of them flushed in RAM when |
| 281 | * GMAC is already pushing data to RAM via DMA. This way incoming from |
| 282 | * GMAC data will be corrupted. */ |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 283 | flush_dcache_range((ulong)rxbuffs, (ulong)rxbuffs + RX_TOTAL_BUFSIZE); |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 284 | |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 285 | for (idx = 0; idx < CFG_RX_DESCR_NUM; idx++) { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 286 | desc_p = &desc_table_p[idx]; |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 287 | desc_p->dmamac_addr = dev_phys_to_bus(priv->dev, |
| 288 | (ulong)&rxbuffs[idx * CFG_ETH_BUFSIZE]); |
| 289 | desc_p->dmamac_next = dev_phys_to_bus(priv->dev, |
| 290 | (ulong)&desc_table_p[idx + 1]); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 291 | |
| 292 | desc_p->dmamac_cntl = |
Marek Vasut | 2b26109 | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 293 | (MAC_MAX_FRAME_SZ & DESC_RXCTRL_SIZE1MASK) | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 294 | DESC_RXCTRL_RXCHAIN; |
| 295 | |
| 296 | desc_p->txrx_status = DESC_RXSTS_OWNBYDMA; |
| 297 | } |
| 298 | |
| 299 | /* Correcting the last pointer of the chain */ |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 300 | desc_p->dmamac_next = dev_phys_to_bus(priv->dev, (ulong)&desc_table_p[0]); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 301 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 302 | /* Flush all Rx buffer descriptors at once */ |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 303 | flush_dcache_range((ulong)priv->rx_mac_descrtable, |
| 304 | (ulong)priv->rx_mac_descrtable + |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 305 | sizeof(priv->rx_mac_descrtable)); |
| 306 | |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 307 | writel(dev_phys_to_bus(priv->dev, (ulong)&desc_table_p[0]), |
| 308 | &dma_p->rxdesclistaddr); |
Alexey Brodkin | 74cb708 | 2014-01-13 13:28:38 +0400 | [diff] [blame] | 309 | priv->rx_currdescnum = 0; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 312 | static int _dw_write_hwaddr(struct dw_eth_dev *priv, u8 *mac_id) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 313 | { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 314 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 315 | u32 macid_lo, macid_hi; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 316 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 317 | macid_lo = mac_id[0] + (mac_id[1] << 8) + (mac_id[2] << 16) + |
| 318 | (mac_id[3] << 24); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 319 | macid_hi = mac_id[4] + (mac_id[5] << 8); |
| 320 | |
| 321 | writel(macid_hi, &mac_p->macaddr0hi); |
| 322 | writel(macid_lo, &mac_p->macaddr0lo); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Simon Glass | 0ea38db | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 327 | static int dw_adjust_link(struct dw_eth_dev *priv, struct eth_mac_regs *mac_p, |
| 328 | struct phy_device *phydev) |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 329 | { |
| 330 | u32 conf = readl(&mac_p->conf) | FRAMEBURSTENABLE | DISABLERXOWN; |
| 331 | |
| 332 | if (!phydev->link) { |
| 333 | printf("%s: No link.\n", phydev->dev->name); |
Simon Glass | 0ea38db | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 334 | return 0; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | if (phydev->speed != 1000) |
| 338 | conf |= MII_PORTSELECT; |
Alexey Brodkin | b884c3f | 2016-01-13 16:59:36 +0300 | [diff] [blame] | 339 | else |
| 340 | conf &= ~MII_PORTSELECT; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 341 | |
| 342 | if (phydev->speed == 100) |
| 343 | conf |= FES_100; |
| 344 | |
| 345 | if (phydev->duplex) |
| 346 | conf |= FULLDPLXMODE; |
| 347 | |
| 348 | writel(conf, &mac_p->conf); |
| 349 | |
| 350 | printf("Speed: %d, %s duplex%s\n", phydev->speed, |
| 351 | (phydev->duplex) ? "full" : "half", |
| 352 | (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); |
Simon Glass | 0ea38db | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 353 | |
| 354 | return 0; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 355 | } |
| 356 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 357 | static void _dw_eth_halt(struct dw_eth_dev *priv) |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 358 | { |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 359 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 360 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
| 361 | |
| 362 | writel(readl(&mac_p->conf) & ~(RXENABLE | TXENABLE), &mac_p->conf); |
| 363 | writel(readl(&dma_p->opmode) & ~(RXSTART | TXSTART), &dma_p->opmode); |
| 364 | |
| 365 | phy_shutdown(priv->phydev); |
| 366 | } |
| 367 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 368 | int designware_eth_init(struct dw_eth_dev *priv, u8 *enetaddr) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 369 | { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 370 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 371 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 372 | unsigned int start; |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 373 | int ret; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 374 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 375 | writel(readl(&dma_p->busmode) | DMAMAC_SRST, &dma_p->busmode); |
Vipin Kumar | 13edd17 | 2012-03-26 00:09:56 +0000 | [diff] [blame] | 376 | |
Quentin Schulz | c612219 | 2018-06-04 12:17:33 +0200 | [diff] [blame] | 377 | /* |
| 378 | * When a MII PHY is used, we must set the PS bit for the DMA |
| 379 | * reset to succeed. |
| 380 | */ |
| 381 | if (priv->phydev->interface == PHY_INTERFACE_MODE_MII) |
| 382 | writel(readl(&mac_p->conf) | MII_PORTSELECT, &mac_p->conf); |
| 383 | else |
| 384 | writel(readl(&mac_p->conf) & ~MII_PORTSELECT, &mac_p->conf); |
| 385 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 386 | start = get_timer(0); |
| 387 | while (readl(&dma_p->busmode) & DMAMAC_SRST) { |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 388 | if (get_timer(start) >= CFG_MACRESET_TIMEOUT) { |
Alexey Brodkin | 875143f | 2015-01-13 17:10:24 +0300 | [diff] [blame] | 389 | printf("DMA reset timeout\n"); |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 390 | return -ETIMEDOUT; |
Alexey Brodkin | 875143f | 2015-01-13 17:10:24 +0300 | [diff] [blame] | 391 | } |
Stefan Roese | ef76025 | 2012-05-07 12:04:25 +0200 | [diff] [blame] | 392 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 393 | mdelay(100); |
| 394 | }; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 395 | |
Bin Meng | f3edfd3 | 2015-06-15 18:40:19 +0800 | [diff] [blame] | 396 | /* |
| 397 | * Soft reset above clears HW address registers. |
| 398 | * So we have to set it here once again. |
| 399 | */ |
| 400 | _dw_write_hwaddr(priv, enetaddr); |
| 401 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 402 | rx_descs_init(priv); |
| 403 | tx_descs_init(priv); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 404 | |
Ian Campbell | 49692c5 | 2014-05-08 22:26:35 +0100 | [diff] [blame] | 405 | writel(FIXEDBURST | PRIORXTX_41 | DMA_PBL, &dma_p->busmode); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 406 | |
Sonic Zhang | d227922 | 2015-01-29 14:38:50 +0800 | [diff] [blame] | 407 | #ifndef CONFIG_DW_MAC_FORCE_THRESHOLD_MODE |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 408 | writel(readl(&dma_p->opmode) | FLUSHTXFIFO | STOREFORWARD, |
| 409 | &dma_p->opmode); |
Sonic Zhang | d227922 | 2015-01-29 14:38:50 +0800 | [diff] [blame] | 410 | #else |
| 411 | writel(readl(&dma_p->opmode) | FLUSHTXFIFO, |
| 412 | &dma_p->opmode); |
| 413 | #endif |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 414 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 415 | writel(readl(&dma_p->opmode) | RXSTART | TXSTART, &dma_p->opmode); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 416 | |
Sonic Zhang | 2ddaf13 | 2015-01-29 13:37:31 +0800 | [diff] [blame] | 417 | #ifdef CONFIG_DW_AXI_BURST_LEN |
| 418 | writel((CONFIG_DW_AXI_BURST_LEN & 0x1FF >> 1), &dma_p->axibus); |
| 419 | #endif |
| 420 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 421 | /* Start up the PHY */ |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 422 | ret = phy_startup(priv->phydev); |
| 423 | if (ret) { |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 424 | printf("Could not initialize PHY %s\n", |
| 425 | priv->phydev->dev->name); |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 426 | return ret; |
Vipin Kumar | 9afc1af | 2012-05-07 13:06:44 +0530 | [diff] [blame] | 427 | } |
| 428 | |
Simon Glass | 0ea38db | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 429 | ret = dw_adjust_link(priv, mac_p, priv->phydev); |
| 430 | if (ret) |
| 431 | return ret; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 432 | |
Simon Glass | f63f28e | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 436 | int designware_eth_enable(struct dw_eth_dev *priv) |
Simon Glass | f63f28e | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 437 | { |
| 438 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 439 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 440 | if (!priv->phydev->link) |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 441 | return -EIO; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 442 | |
Armando Visconti | aa51005 | 2012-03-26 00:09:55 +0000 | [diff] [blame] | 443 | writel(readl(&mac_p->conf) | RXENABLE | TXENABLE, &mac_p->conf); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
Florian Fainelli | 7a9ca9d | 2017-12-09 14:59:55 -0800 | [diff] [blame] | 448 | #define ETH_ZLEN 60 |
| 449 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 450 | static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 451 | { |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 452 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
| 453 | u32 desc_num = priv->tx_currdescnum; |
| 454 | struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num]; |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 455 | ulong desc_start = (ulong)desc_p; |
| 456 | ulong desc_end = desc_start + |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 457 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 458 | ulong data_start = dev_bus_to_phys(priv->dev, desc_p->dmamac_addr); |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 459 | ulong data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); |
Ian Campbell | 964ea7c | 2014-05-08 22:26:33 +0100 | [diff] [blame] | 460 | /* |
| 461 | * Strictly we only need to invalidate the "txrx_status" field |
| 462 | * for the following check, but on some platforms we cannot |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 463 | * invalidate only 4 bytes, so we flush the entire descriptor, |
| 464 | * which is 16 bytes in total. This is safe because the |
| 465 | * individual descriptors in the array are each aligned to |
| 466 | * ARCH_DMA_MINALIGN and padded appropriately. |
Ian Campbell | 964ea7c | 2014-05-08 22:26:33 +0100 | [diff] [blame] | 467 | */ |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 468 | invalidate_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 469 | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 470 | /* Check if the descriptor is owned by CPU */ |
| 471 | if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) { |
| 472 | printf("CPU not owner of tx frame\n"); |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 473 | return -EPERM; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 474 | } |
| 475 | |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 476 | memcpy((void *)data_start, packet, length); |
Simon Goldschmidt | 7efb75b | 2018-11-17 10:24:42 +0100 | [diff] [blame] | 477 | if (length < ETH_ZLEN) { |
| 478 | memset(&((char *)data_start)[length], 0, ETH_ZLEN - length); |
| 479 | length = ETH_ZLEN; |
| 480 | } |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 481 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 482 | /* Flush data to be sent */ |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 483 | flush_dcache_range(data_start, data_end); |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 484 | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 485 | #if defined(CONFIG_DW_ALTDESCRIPTOR) |
| 486 | desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST; |
Simon Goldschmidt | ae8ac8d | 2018-11-17 10:24:41 +0100 | [diff] [blame] | 487 | desc_p->dmamac_cntl = (desc_p->dmamac_cntl & ~DESC_TXCTRL_SIZE1MASK) | |
| 488 | ((length << DESC_TXCTRL_SIZE1SHFT) & |
| 489 | DESC_TXCTRL_SIZE1MASK); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 490 | |
| 491 | desc_p->txrx_status &= ~(DESC_TXSTS_MSK); |
| 492 | desc_p->txrx_status |= DESC_TXSTS_OWNBYDMA; |
| 493 | #else |
Simon Goldschmidt | ae8ac8d | 2018-11-17 10:24:41 +0100 | [diff] [blame] | 494 | desc_p->dmamac_cntl = (desc_p->dmamac_cntl & ~DESC_TXCTRL_SIZE1MASK) | |
| 495 | ((length << DESC_TXCTRL_SIZE1SHFT) & |
| 496 | DESC_TXCTRL_SIZE1MASK) | DESC_TXCTRL_TXLAST | |
| 497 | DESC_TXCTRL_TXFIRST; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 498 | |
| 499 | desc_p->txrx_status = DESC_TXSTS_OWNBYDMA; |
| 500 | #endif |
| 501 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 502 | /* Flush modified buffer descriptor */ |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 503 | flush_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 504 | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 505 | /* Test the wrap-around condition. */ |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 506 | if (++desc_num >= CFG_TX_DESCR_NUM) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 507 | desc_num = 0; |
| 508 | |
| 509 | priv->tx_currdescnum = desc_num; |
| 510 | |
| 511 | /* Start the transmission */ |
| 512 | writel(POLL_DATA, &dma_p->txpolldemand); |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 517 | static int _dw_eth_recv(struct dw_eth_dev *priv, uchar **packetp) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 518 | { |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 519 | u32 status, desc_num = priv->rx_currdescnum; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 520 | struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num]; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 521 | int length = -EAGAIN; |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 522 | ulong desc_start = (ulong)desc_p; |
| 523 | ulong desc_end = desc_start + |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 524 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 525 | ulong data_start = dev_bus_to_phys(priv->dev, desc_p->dmamac_addr); |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 526 | ulong data_end; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 527 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 528 | /* Invalidate entire buffer descriptor */ |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 529 | invalidate_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 530 | |
| 531 | status = desc_p->txrx_status; |
| 532 | |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 533 | /* Check if the owner is the CPU */ |
| 534 | if (!(status & DESC_RXSTS_OWNBYDMA)) { |
| 535 | |
Marek Vasut | 2b26109 | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 536 | length = (status & DESC_RXSTS_FRMLENMSK) >> |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 537 | DESC_RXSTS_FRMLENSHFT; |
| 538 | |
Alexey Brodkin | 50b0df8 | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 539 | /* Invalidate received data */ |
Marek Vasut | 96cec17 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 540 | data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); |
| 541 | invalidate_dcache_range(data_start, data_end); |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 542 | *packetp = (uchar *)(ulong)dev_bus_to_phys(priv->dev, |
| 543 | desc_p->dmamac_addr); |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 544 | } |
| 545 | |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 546 | return length; |
| 547 | } |
| 548 | |
| 549 | static int _dw_free_pkt(struct dw_eth_dev *priv) |
| 550 | { |
| 551 | u32 desc_num = priv->rx_currdescnum; |
| 552 | struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num]; |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 553 | ulong desc_start = (ulong)desc_p; |
| 554 | ulong desc_end = desc_start + |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 555 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
| 556 | |
| 557 | /* |
| 558 | * Make the current descriptor valid again and go to |
| 559 | * the next one |
| 560 | */ |
| 561 | desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA; |
| 562 | |
| 563 | /* Flush only status field - others weren't changed */ |
| 564 | flush_dcache_range(desc_start, desc_end); |
| 565 | |
| 566 | /* Test the wrap-around condition. */ |
Tom Rini | 6e7df1d | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 567 | if (++desc_num >= CFG_RX_DESCR_NUM) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 568 | desc_num = 0; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 569 | priv->rx_currdescnum = desc_num; |
| 570 | |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 571 | return 0; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 572 | } |
| 573 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 574 | static int dw_phy_init(struct dw_eth_dev *priv, void *dev) |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 575 | { |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 576 | struct phy_device *phydev; |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 577 | int ret; |
| 578 | |
Tom Rini | acb30cc | 2022-11-27 10:25:07 -0500 | [diff] [blame] | 579 | #if IS_ENABLED(CONFIG_DM_MDIO) |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 580 | phydev = dm_eth_phy_connect(dev); |
| 581 | if (!phydev) |
| 582 | return -ENODEV; |
| 583 | #else |
| 584 | int phy_addr = -1; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 585 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 586 | #ifdef CONFIG_PHY_ADDR |
Simon Goldschmidt | 5dce9df | 2019-07-15 21:53:05 +0200 | [diff] [blame] | 587 | phy_addr = CONFIG_PHY_ADDR; |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 588 | #endif |
| 589 | |
Simon Goldschmidt | 5dce9df | 2019-07-15 21:53:05 +0200 | [diff] [blame] | 590 | phydev = phy_connect(priv->bus, phy_addr, dev, priv->interface); |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 591 | if (!phydev) |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 592 | return -ENODEV; |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 593 | #endif |
Vipin KUMAR | 5b1b188 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 594 | |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 595 | phydev->supported &= PHY_GBIT_FEATURES; |
Alexey Brodkin | 6968ec9 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 596 | if (priv->max_speed) { |
| 597 | ret = phy_set_supported(phydev, priv->max_speed); |
| 598 | if (ret) |
| 599 | return ret; |
| 600 | } |
Alexey Brodkin | 92a190a | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 601 | phydev->advertising = phydev->supported; |
| 602 | |
| 603 | priv->phydev = phydev; |
| 604 | phy_config(phydev); |
| 605 | |
Simon Glass | 64dcd25 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 606 | return 0; |
| 607 | } |
| 608 | |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 609 | static int designware_eth_start(struct udevice *dev) |
| 610 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 611 | struct eth_pdata *pdata = dev_get_plat(dev); |
Simon Glass | f63f28e | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 612 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 613 | int ret; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 614 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 615 | ret = designware_eth_init(priv, pdata->enetaddr); |
Simon Glass | f63f28e | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 616 | if (ret) |
| 617 | return ret; |
| 618 | ret = designware_eth_enable(priv); |
| 619 | if (ret) |
| 620 | return ret; |
| 621 | |
| 622 | return 0; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 623 | } |
| 624 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 625 | int designware_eth_send(struct udevice *dev, void *packet, int length) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 626 | { |
| 627 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 628 | |
| 629 | return _dw_eth_send(priv, packet, length); |
| 630 | } |
| 631 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 632 | int designware_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 633 | { |
| 634 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 635 | |
| 636 | return _dw_eth_recv(priv, packetp); |
| 637 | } |
| 638 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 639 | int designware_eth_free_pkt(struct udevice *dev, uchar *packet, int length) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 640 | { |
| 641 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 642 | |
| 643 | return _dw_free_pkt(priv); |
| 644 | } |
| 645 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 646 | void designware_eth_stop(struct udevice *dev) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 647 | { |
| 648 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 649 | |
| 650 | return _dw_eth_halt(priv); |
| 651 | } |
| 652 | |
Simon Glass | e72ced2 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 653 | int designware_eth_write_hwaddr(struct udevice *dev) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 654 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 655 | struct eth_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 656 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 657 | |
| 658 | return _dw_write_hwaddr(priv, pdata->enetaddr); |
| 659 | } |
| 660 | |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 661 | static int designware_eth_bind(struct udevice *dev) |
| 662 | { |
Simon Glass | e882a59 | 2021-08-01 18:54:34 -0600 | [diff] [blame] | 663 | if (IS_ENABLED(CONFIG_PCI)) { |
| 664 | static int num_cards; |
| 665 | char name[20]; |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 666 | |
Simon Glass | e882a59 | 2021-08-01 18:54:34 -0600 | [diff] [blame] | 667 | /* Create a unique device name for PCI type devices */ |
| 668 | if (device_is_on_pci_bus(dev)) { |
| 669 | sprintf(name, "eth_designware#%u", num_cards++); |
| 670 | device_set_name(dev, name); |
| 671 | } |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 672 | } |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
Sjoerd Simons | b9e08d0 | 2017-01-11 11:46:07 +0100 | [diff] [blame] | 677 | int designware_eth_probe(struct udevice *dev) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 678 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 679 | struct eth_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 680 | struct dw_eth_dev *priv = dev_get_priv(dev); |
Bin Meng | f0dc73c | 2015-09-03 05:37:29 -0700 | [diff] [blame] | 681 | u32 iobase = pdata->iobase; |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 682 | ulong ioaddr; |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 683 | int ret, err; |
Ley Foon Tan | 495c70f | 2018-06-14 18:45:23 +0800 | [diff] [blame] | 684 | struct reset_ctl_bulk reset_bulk; |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 685 | #ifdef CONFIG_CLK |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 686 | int i, clock_nb; |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 687 | |
| 688 | priv->clock_count = 0; |
Patrick Delaunay | 89f6830 | 2020-09-25 09:41:14 +0200 | [diff] [blame] | 689 | clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells", |
| 690 | 0); |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 691 | if (clock_nb > 0) { |
| 692 | priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), |
| 693 | GFP_KERNEL); |
| 694 | if (!priv->clocks) |
| 695 | return -ENOMEM; |
| 696 | |
| 697 | for (i = 0; i < clock_nb; i++) { |
| 698 | err = clk_get_by_index(dev, i, &priv->clocks[i]); |
| 699 | if (err < 0) |
| 700 | break; |
| 701 | |
| 702 | err = clk_enable(&priv->clocks[i]); |
Eugeniy Paltsev | 1693a57 | 2018-02-06 17:12:09 +0300 | [diff] [blame] | 703 | if (err && err != -ENOSYS && err != -ENOTSUPP) { |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 704 | pr_err("failed to enable clock %d\n", i); |
| 705 | clk_free(&priv->clocks[i]); |
| 706 | goto clk_err; |
| 707 | } |
| 708 | priv->clock_count++; |
| 709 | } |
| 710 | } else if (clock_nb != -ENOENT) { |
| 711 | pr_err("failed to get clock phandle(%d)\n", clock_nb); |
| 712 | return clock_nb; |
| 713 | } |
| 714 | #endif |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 715 | |
Jacob Chen | 6ec922f | 2017-03-27 16:54:17 +0800 | [diff] [blame] | 716 | #if defined(CONFIG_DM_REGULATOR) |
| 717 | struct udevice *phy_supply; |
| 718 | |
| 719 | ret = device_get_supply_regulator(dev, "phy-supply", |
| 720 | &phy_supply); |
| 721 | if (ret) { |
| 722 | debug("%s: No phy supply\n", dev->name); |
| 723 | } else { |
| 724 | ret = regulator_set_enable(phy_supply, true); |
| 725 | if (ret) { |
| 726 | puts("Error enabling phy supply\n"); |
| 727 | return ret; |
| 728 | } |
| 729 | } |
| 730 | #endif |
| 731 | |
Ley Foon Tan | 495c70f | 2018-06-14 18:45:23 +0800 | [diff] [blame] | 732 | ret = reset_get_bulk(dev, &reset_bulk); |
| 733 | if (ret) |
| 734 | dev_warn(dev, "Can't get reset: %d\n", ret); |
| 735 | else |
| 736 | reset_deassert_bulk(&reset_bulk); |
| 737 | |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 738 | /* |
| 739 | * If we are on PCI bus, either directly attached to a PCI root port, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 740 | * or via a PCI bridge, fill in plat before we probe the hardware. |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 741 | */ |
Simon Glass | e882a59 | 2021-08-01 18:54:34 -0600 | [diff] [blame] | 742 | if (IS_ENABLED(CONFIG_PCI) && device_is_on_pci_bus(dev)) { |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 743 | dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); |
| 744 | iobase &= PCI_BASE_ADDRESS_MEM_MASK; |
Bin Meng | 6758a6c | 2016-02-02 05:58:00 -0800 | [diff] [blame] | 745 | iobase = dm_pci_mem_to_phys(dev, iobase); |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 746 | |
| 747 | pdata->iobase = iobase; |
| 748 | pdata->phy_interface = PHY_INTERFACE_MODE_RMII; |
| 749 | } |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 750 | |
Bin Meng | f0dc73c | 2015-09-03 05:37:29 -0700 | [diff] [blame] | 751 | debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv); |
Beniamino Galvani | 0e1a3e3 | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 752 | ioaddr = iobase; |
| 753 | priv->mac_regs_p = (struct eth_mac_regs *)ioaddr; |
| 754 | priv->dma_regs_p = (struct eth_dma_regs *)(ioaddr + DW_DMA_BASE_OFFSET); |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 755 | priv->interface = pdata->phy_interface; |
Alexey Brodkin | 6968ec9 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 756 | priv->max_speed = pdata->max_speed; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 757 | |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 758 | #if IS_ENABLED(CONFIG_DM_MDIO) |
| 759 | ret = dw_dm_mdio_init(dev->name, dev); |
| 760 | #else |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 761 | ret = dw_mdio_init(dev->name, dev); |
Neil Armstrong | 5160b45 | 2021-02-24 15:02:39 +0100 | [diff] [blame] | 762 | #endif |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 763 | if (ret) { |
| 764 | err = ret; |
| 765 | goto mdio_err; |
| 766 | } |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 767 | priv->bus = miiphy_get_dev_by_name(dev->name); |
Baruch Siach | d44f3d2 | 2023-10-25 11:08:44 +0300 | [diff] [blame] | 768 | priv->dev = dev; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 769 | |
| 770 | ret = dw_phy_init(priv, dev); |
| 771 | debug("%s, ret=%d\n", __func__, ret); |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 772 | if (!ret) |
| 773 | return 0; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 774 | |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 775 | /* continue here for cleanup if no PHY found */ |
| 776 | err = ret; |
| 777 | mdio_unregister(priv->bus); |
| 778 | mdio_free(priv->bus); |
| 779 | mdio_err: |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 780 | |
| 781 | #ifdef CONFIG_CLK |
| 782 | clk_err: |
| 783 | ret = clk_release_all(priv->clocks, priv->clock_count); |
| 784 | if (ret) |
| 785 | pr_err("failed to disable all clocks\n"); |
| 786 | |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 787 | #endif |
Simon Goldschmidt | 4ee587e | 2019-07-12 21:07:03 +0200 | [diff] [blame] | 788 | return err; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 789 | } |
| 790 | |
Bin Meng | 5d2459f | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 791 | static int designware_eth_remove(struct udevice *dev) |
| 792 | { |
| 793 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 794 | |
| 795 | free(priv->phydev); |
| 796 | mdio_unregister(priv->bus); |
| 797 | mdio_free(priv->bus); |
| 798 | |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 799 | #ifdef CONFIG_CLK |
| 800 | return clk_release_all(priv->clocks, priv->clock_count); |
| 801 | #else |
Bin Meng | 5d2459f | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 802 | return 0; |
Patrice Chotard | ba1f966 | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 803 | #endif |
Bin Meng | 5d2459f | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Sjoerd Simons | b9e08d0 | 2017-01-11 11:46:07 +0100 | [diff] [blame] | 806 | const struct eth_ops designware_eth_ops = { |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 807 | .start = designware_eth_start, |
| 808 | .send = designware_eth_send, |
| 809 | .recv = designware_eth_recv, |
| 810 | .free_pkt = designware_eth_free_pkt, |
| 811 | .stop = designware_eth_stop, |
| 812 | .write_hwaddr = designware_eth_write_hwaddr, |
| 813 | }; |
| 814 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 815 | int designware_eth_of_to_plat(struct udevice *dev) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 816 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 817 | struct dw_eth_pdata *dw_pdata = dev_get_plat(dev); |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 818 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 819 | struct dw_eth_dev *priv = dev_get_priv(dev); |
Alexey Brodkin | 66d027e | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 820 | #endif |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 821 | struct eth_pdata *pdata = &dw_pdata->eth_pdata; |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 822 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 823 | int reset_flags = GPIOD_IS_OUT; |
Alexey Brodkin | 66d027e | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 824 | #endif |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 825 | int ret = 0; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 826 | |
Philipp Tomsich | 15050f1 | 2017-09-11 22:04:13 +0200 | [diff] [blame] | 827 | pdata->iobase = dev_read_addr(dev); |
Marek BehĂșn | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 828 | pdata->phy_interface = dev_read_phy_mode(dev); |
Marek BehĂșn | ffb0f6f | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 829 | if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 830 | return -EINVAL; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 831 | |
Philipp Tomsich | 15050f1 | 2017-09-11 22:04:13 +0200 | [diff] [blame] | 832 | pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
Alexey Brodkin | 6968ec9 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 833 | |
Simon Glass | bcee8d6 | 2019-12-06 21:41:35 -0700 | [diff] [blame] | 834 | #if CONFIG_IS_ENABLED(DM_GPIO) |
Philipp Tomsich | 7ad326a | 2017-06-07 18:46:01 +0200 | [diff] [blame] | 835 | if (dev_read_bool(dev, "snps,reset-active-low")) |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 836 | reset_flags |= GPIOD_ACTIVE_LOW; |
| 837 | |
| 838 | ret = gpio_request_by_name(dev, "snps,reset-gpio", 0, |
| 839 | &priv->reset_gpio, reset_flags); |
| 840 | if (ret == 0) { |
Philipp Tomsich | 7ad326a | 2017-06-07 18:46:01 +0200 | [diff] [blame] | 841 | ret = dev_read_u32_array(dev, "snps,reset-delays-us", |
| 842 | dw_pdata->reset_delays, 3); |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 843 | } else if (ret == -ENOENT) { |
| 844 | ret = 0; |
| 845 | } |
Alexey Brodkin | 66d027e | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 846 | #endif |
Sjoerd Simons | 90b7fc9 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 847 | |
| 848 | return ret; |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static const struct udevice_id designware_eth_ids[] = { |
| 852 | { .compatible = "allwinner,sun7i-a20-gmac" }, |
Beniamino Galvani | cfe2556 | 2016-08-16 11:49:50 +0200 | [diff] [blame] | 853 | { .compatible = "amlogic,meson6-dwmac" }, |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 854 | { .compatible = "st,stm32-dwmac" }, |
Eugeniy Paltsev | 2a72323 | 2019-10-07 19:10:50 +0300 | [diff] [blame] | 855 | { .compatible = "snps,arc-dwmac-3.70a" }, |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 856 | { } |
| 857 | }; |
| 858 | |
Marek Vasut | 9f76f10 | 2015-07-25 18:42:34 +0200 | [diff] [blame] | 859 | U_BOOT_DRIVER(eth_designware) = { |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 860 | .name = "eth_designware", |
| 861 | .id = UCLASS_ETH, |
| 862 | .of_match = designware_eth_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 863 | .of_to_plat = designware_eth_of_to_plat, |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 864 | .bind = designware_eth_bind, |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 865 | .probe = designware_eth_probe, |
Bin Meng | 5d2459f | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 866 | .remove = designware_eth_remove, |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 867 | .ops = &designware_eth_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 868 | .priv_auto = sizeof(struct dw_eth_dev), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 869 | .plat_auto = sizeof(struct dw_eth_pdata), |
Simon Glass | 75577ba | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 870 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 871 | }; |
Bin Meng | 8b7ee66 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 872 | |
| 873 | static struct pci_device_id supported[] = { |
| 874 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) }, |
| 875 | { } |
| 876 | }; |
| 877 | |
| 878 | U_BOOT_PCI_DEVICE(eth_designware, supported); |