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