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