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