Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 9 | * Designware ethernet IP driver for U-Boot |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 13 | #include <clk.h> |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 14 | #include <dm.h> |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 15 | #include <errno.h> |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 16 | #include <miiphy.h> |
| 17 | #include <malloc.h> |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 18 | #include <pci.h> |
Stefan Roese | d27e86c | 2012-05-07 12:04:25 +0200 | [diff] [blame] | 19 | #include <linux/compiler.h> |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 20 | #include <linux/err.h> |
Florian Fainelli | 65f686b | 2017-12-09 14:59:55 -0800 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 22 | #include <asm/io.h> |
Jacob Chen | 7ceacea | 2017-03-27 16:54:17 +0800 | [diff] [blame] | 23 | #include <power/regulator.h> |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 24 | #include "designware.h" |
| 25 | |
Alexey Brodkin | 9a0b130 | 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 | 6eb4462 | 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 | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 32 | struct eth_mac_regs *mac_p = bus->priv; |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 33 | #endif |
Alexey Brodkin | 9a0b130 | 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 | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 50 | return -ETIMEDOUT; |
Alexey Brodkin | 9a0b130 | 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 | 6eb4462 | 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 | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 60 | struct eth_mac_regs *mac_p = bus->priv; |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 61 | #endif |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 62 | ulong start; |
| 63 | u16 miiaddr; |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 64 | int ret = -ETIMEDOUT, timeout = CONFIG_MDIO_TIMEOUT; |
Alexey Brodkin | 9a0b130 | 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 | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 84 | #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO) |
Sjoerd Simons | 6eb4462 | 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 | 9a0b130 | 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 | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 124 | return -ENOMEM; |
Alexey Brodkin | 9a0b130 | 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 | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 129 | snprintf(bus->name, sizeof(bus->name), "%s", name); |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 130 | #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO) |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 131 | bus->reset = dw_mdio_reset; |
| 132 | #endif |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 133 | |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 134 | bus->priv = priv; |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 135 | |
| 136 | return mdio_register(bus); |
| 137 | } |
Vipin Kumar | b6c5999 | 2012-03-26 00:09:56 +0000 | [diff] [blame] | 138 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 139 | static void tx_descs_init(struct dw_eth_dev *priv) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 140 | { |
Vipin KUMAR | 1f87312 | 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 | 3bfa65c | 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 | 1f87312 | 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 | 4ab539a | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 154 | DESC_TXSTS_TXFIRST | DESC_TXSTS_TXCRCDIS | |
| 155 | DESC_TXSTS_TXCHECKINSCTRL | |
Vipin KUMAR | 1f87312 | 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 | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 168 | desc_p->dmamac_next = (ulong)&desc_table_p[0]; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 169 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 170 | /* Flush all Tx buffer descriptors at once */ |
Beniamino Galvani | 3bfa65c | 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 | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 173 | sizeof(priv->tx_mac_descrtable)); |
| 174 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 175 | writel((ulong)&desc_table_p[0], &dma_p->txdesclistaddr); |
Alexey Brodkin | 4695ddd | 2014-01-13 13:28:38 +0400 | [diff] [blame] | 176 | priv->tx_currdescnum = 0; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 177 | } |
| 178 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 179 | static void rx_descs_init(struct dw_eth_dev *priv) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 180 | { |
Vipin KUMAR | 1f87312 | 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 | 0d3b22e | 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 | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 193 | flush_dcache_range((ulong)rxbuffs, (ulong)rxbuffs + RX_TOTAL_BUFSIZE); |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 194 | |
Vipin KUMAR | 1f87312 | 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 | 3bfa65c | 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 | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 199 | |
| 200 | desc_p->dmamac_cntl = |
Marek Vasut | 4ab539a | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 201 | (MAC_MAX_FRAME_SZ & DESC_RXCTRL_SIZE1MASK) | |
Vipin KUMAR | 1f87312 | 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 | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 208 | desc_p->dmamac_next = (ulong)&desc_table_p[0]; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 209 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 210 | /* Flush all Rx buffer descriptors at once */ |
Beniamino Galvani | 3bfa65c | 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 | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 213 | sizeof(priv->rx_mac_descrtable)); |
| 214 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 215 | writel((ulong)&desc_table_p[0], &dma_p->rxdesclistaddr); |
Alexey Brodkin | 4695ddd | 2014-01-13 13:28:38 +0400 | [diff] [blame] | 216 | priv->rx_currdescnum = 0; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 217 | } |
| 218 | |
Simon Glass | e50c4d1 | 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 | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 220 | { |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 221 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 222 | u32 macid_lo, macid_hi; |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 223 | |
| 224 | macid_lo = mac_id[0] + (mac_id[1] << 8) + (mac_id[2] << 16) + |
| 225 | (mac_id[3] << 24); |
| 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; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 232 | } |
| 233 | |
Simon Glass | 4afa85e | 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) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 236 | { |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 237 | u32 conf = readl(&mac_p->conf) | FRAMEBURSTENABLE | DISABLERXOWN; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 238 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 239 | if (!phydev->link) { |
| 240 | printf("%s: No link.\n", phydev->dev->name); |
Simon Glass | 4afa85e | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 241 | return 0; |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 242 | } |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 243 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 244 | if (phydev->speed != 1000) |
| 245 | conf |= MII_PORTSELECT; |
Alexey Brodkin | a5e8819 | 2016-01-13 16:59:36 +0300 | [diff] [blame] | 246 | else |
| 247 | conf &= ~MII_PORTSELECT; |
Vipin Kumar | f567e41 | 2012-12-13 17:22:51 +0530 | [diff] [blame] | 248 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 249 | if (phydev->speed == 100) |
| 250 | conf |= FES_100; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 251 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 252 | if (phydev->duplex) |
| 253 | conf |= FULLDPLXMODE; |
Amit Virdi | 470e884 | 2012-03-26 00:09:59 +0000 | [diff] [blame] | 254 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 255 | writel(conf, &mac_p->conf); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 256 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 257 | printf("Speed: %d, %s duplex%s\n", phydev->speed, |
| 258 | (phydev->duplex) ? "full" : "half", |
| 259 | (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); |
Simon Glass | 4afa85e | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 260 | |
| 261 | return 0; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 262 | } |
| 263 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 264 | static void _dw_eth_halt(struct dw_eth_dev *priv) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 265 | { |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 266 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 267 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 268 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 269 | writel(readl(&mac_p->conf) & ~(RXENABLE | TXENABLE), &mac_p->conf); |
| 270 | writel(readl(&dma_p->opmode) & ~(RXSTART | TXSTART), &dma_p->opmode); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 271 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 272 | phy_shutdown(priv->phydev); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 273 | } |
| 274 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 275 | int designware_eth_init(struct dw_eth_dev *priv, u8 *enetaddr) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 276 | { |
Vipin KUMAR | 1f87312 | 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 | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 279 | unsigned int start; |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 280 | int ret; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 281 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 282 | writel(readl(&dma_p->busmode) | DMAMAC_SRST, &dma_p->busmode); |
Vipin Kumar | b6c5999 | 2012-03-26 00:09:56 +0000 | [diff] [blame] | 283 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 284 | start = get_timer(0); |
| 285 | while (readl(&dma_p->busmode) & DMAMAC_SRST) { |
Alexey Brodkin | 71eccc3 | 2015-01-13 17:10:24 +0300 | [diff] [blame] | 286 | if (get_timer(start) >= CONFIG_MACRESET_TIMEOUT) { |
| 287 | printf("DMA reset timeout\n"); |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 288 | return -ETIMEDOUT; |
Alexey Brodkin | 71eccc3 | 2015-01-13 17:10:24 +0300 | [diff] [blame] | 289 | } |
Stefan Roese | d27e86c | 2012-05-07 12:04:25 +0200 | [diff] [blame] | 290 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 291 | mdelay(100); |
| 292 | }; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 293 | |
Bin Meng | 2ddfa2a | 2015-06-15 18:40:19 +0800 | [diff] [blame] | 294 | /* |
| 295 | * Soft reset above clears HW address registers. |
| 296 | * So we have to set it here once again. |
| 297 | */ |
| 298 | _dw_write_hwaddr(priv, enetaddr); |
| 299 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 300 | rx_descs_init(priv); |
| 301 | tx_descs_init(priv); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 302 | |
Ian Campbell | 4164b74 | 2014-05-08 22:26:35 +0100 | [diff] [blame] | 303 | writel(FIXEDBURST | PRIORXTX_41 | DMA_PBL, &dma_p->busmode); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 304 | |
Sonic Zhang | b917b62 | 2015-01-29 14:38:50 +0800 | [diff] [blame] | 305 | #ifndef CONFIG_DW_MAC_FORCE_THRESHOLD_MODE |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 306 | writel(readl(&dma_p->opmode) | FLUSHTXFIFO | STOREFORWARD, |
| 307 | &dma_p->opmode); |
Sonic Zhang | b917b62 | 2015-01-29 14:38:50 +0800 | [diff] [blame] | 308 | #else |
| 309 | writel(readl(&dma_p->opmode) | FLUSHTXFIFO, |
| 310 | &dma_p->opmode); |
| 311 | #endif |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 312 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 313 | writel(readl(&dma_p->opmode) | RXSTART | TXSTART, &dma_p->opmode); |
Vipin Kumar | 7443d60 | 2012-05-07 13:06:44 +0530 | [diff] [blame] | 314 | |
Sonic Zhang | 962c95c | 2015-01-29 13:37:31 +0800 | [diff] [blame] | 315 | #ifdef CONFIG_DW_AXI_BURST_LEN |
| 316 | writel((CONFIG_DW_AXI_BURST_LEN & 0x1FF >> 1), &dma_p->axibus); |
| 317 | #endif |
| 318 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 319 | /* Start up the PHY */ |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 320 | ret = phy_startup(priv->phydev); |
| 321 | if (ret) { |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 322 | printf("Could not initialize PHY %s\n", |
| 323 | priv->phydev->dev->name); |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 324 | return ret; |
Vipin Kumar | 7443d60 | 2012-05-07 13:06:44 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Simon Glass | 4afa85e | 2017-01-11 11:46:08 +0100 | [diff] [blame] | 327 | ret = dw_adjust_link(priv, mac_p, priv->phydev); |
| 328 | if (ret) |
| 329 | return ret; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 330 | |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 334 | int designware_eth_enable(struct dw_eth_dev *priv) |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 335 | { |
| 336 | struct eth_mac_regs *mac_p = priv->mac_regs_p; |
| 337 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 338 | if (!priv->phydev->link) |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 339 | return -EIO; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 340 | |
Armando Visconti | 038c9d5 | 2012-03-26 00:09:55 +0000 | [diff] [blame] | 341 | writel(readl(&mac_p->conf) | RXENABLE | TXENABLE, &mac_p->conf); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
Florian Fainelli | 65f686b | 2017-12-09 14:59:55 -0800 | [diff] [blame] | 346 | #define ETH_ZLEN 60 |
| 347 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 348 | static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 349 | { |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 350 | struct eth_dma_regs *dma_p = priv->dma_regs_p; |
| 351 | u32 desc_num = priv->tx_currdescnum; |
| 352 | struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num]; |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 353 | ulong desc_start = (ulong)desc_p; |
| 354 | ulong desc_end = desc_start + |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 355 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 356 | ulong data_start = desc_p->dmamac_addr; |
| 357 | ulong data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); |
Ian Campbell | 0e690fd | 2014-05-08 22:26:33 +0100 | [diff] [blame] | 358 | /* |
| 359 | * Strictly we only need to invalidate the "txrx_status" field |
| 360 | * for the following check, but on some platforms we cannot |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 361 | * invalidate only 4 bytes, so we flush the entire descriptor, |
| 362 | * which is 16 bytes in total. This is safe because the |
| 363 | * individual descriptors in the array are each aligned to |
| 364 | * ARCH_DMA_MINALIGN and padded appropriately. |
Ian Campbell | 0e690fd | 2014-05-08 22:26:33 +0100 | [diff] [blame] | 365 | */ |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 366 | invalidate_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 367 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 368 | /* Check if the descriptor is owned by CPU */ |
| 369 | if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) { |
| 370 | printf("CPU not owner of tx frame\n"); |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 371 | return -EPERM; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 372 | } |
| 373 | |
Florian Fainelli | 65f686b | 2017-12-09 14:59:55 -0800 | [diff] [blame] | 374 | length = max(length, ETH_ZLEN); |
| 375 | |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 376 | memcpy((void *)data_start, packet, length); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 377 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 378 | /* Flush data to be sent */ |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 379 | flush_dcache_range(data_start, data_end); |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 380 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 381 | #if defined(CONFIG_DW_ALTDESCRIPTOR) |
| 382 | desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST; |
Marek Vasut | 4ab539a | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 383 | desc_p->dmamac_cntl |= (length << DESC_TXCTRL_SIZE1SHFT) & |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 384 | DESC_TXCTRL_SIZE1MASK; |
| 385 | |
| 386 | desc_p->txrx_status &= ~(DESC_TXSTS_MSK); |
| 387 | desc_p->txrx_status |= DESC_TXSTS_OWNBYDMA; |
| 388 | #else |
Marek Vasut | 4ab539a | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 389 | desc_p->dmamac_cntl |= ((length << DESC_TXCTRL_SIZE1SHFT) & |
| 390 | DESC_TXCTRL_SIZE1MASK) | DESC_TXCTRL_TXLAST | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 391 | DESC_TXCTRL_TXFIRST; |
| 392 | |
| 393 | desc_p->txrx_status = DESC_TXSTS_OWNBYDMA; |
| 394 | #endif |
| 395 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 396 | /* Flush modified buffer descriptor */ |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 397 | flush_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 398 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 399 | /* Test the wrap-around condition. */ |
| 400 | if (++desc_num >= CONFIG_TX_DESCR_NUM) |
| 401 | desc_num = 0; |
| 402 | |
| 403 | priv->tx_currdescnum = desc_num; |
| 404 | |
| 405 | /* Start the transmission */ |
| 406 | writel(POLL_DATA, &dma_p->txpolldemand); |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 411 | static int _dw_eth_recv(struct dw_eth_dev *priv, uchar **packetp) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 412 | { |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 413 | u32 status, desc_num = priv->rx_currdescnum; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 414 | struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num]; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 415 | int length = -EAGAIN; |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 416 | ulong desc_start = (ulong)desc_p; |
| 417 | ulong desc_end = desc_start + |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 418 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 419 | ulong data_start = desc_p->dmamac_addr; |
| 420 | ulong data_end; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 421 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 422 | /* Invalidate entire buffer descriptor */ |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 423 | invalidate_dcache_range(desc_start, desc_end); |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 424 | |
| 425 | status = desc_p->txrx_status; |
| 426 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 427 | /* Check if the owner is the CPU */ |
| 428 | if (!(status & DESC_RXSTS_OWNBYDMA)) { |
| 429 | |
Marek Vasut | 4ab539a | 2015-12-20 03:59:23 +0100 | [diff] [blame] | 430 | length = (status & DESC_RXSTS_FRMLENMSK) >> |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 431 | DESC_RXSTS_FRMLENSHFT; |
| 432 | |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 433 | /* Invalidate received data */ |
Marek Vasut | 1519304 | 2014-09-15 01:05:23 +0200 | [diff] [blame] | 434 | data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); |
| 435 | invalidate_dcache_range(data_start, data_end); |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 436 | *packetp = (uchar *)(ulong)desc_p->dmamac_addr; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 437 | } |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 438 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 439 | return length; |
| 440 | } |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 441 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 442 | static int _dw_free_pkt(struct dw_eth_dev *priv) |
| 443 | { |
| 444 | u32 desc_num = priv->rx_currdescnum; |
| 445 | struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num]; |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 446 | ulong desc_start = (ulong)desc_p; |
| 447 | ulong desc_end = desc_start + |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 448 | roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 449 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 450 | /* |
| 451 | * Make the current descriptor valid again and go to |
| 452 | * the next one |
| 453 | */ |
| 454 | desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA; |
Alexey Brodkin | 0d3b22e | 2014-01-22 20:49:09 +0400 | [diff] [blame] | 455 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 456 | /* Flush only status field - others weren't changed */ |
| 457 | flush_dcache_range(desc_start, desc_end); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 458 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 459 | /* Test the wrap-around condition. */ |
| 460 | if (++desc_num >= CONFIG_RX_DESCR_NUM) |
| 461 | desc_num = 0; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 462 | priv->rx_currdescnum = desc_num; |
| 463 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 464 | return 0; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 465 | } |
| 466 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 467 | static int dw_phy_init(struct dw_eth_dev *priv, void *dev) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 468 | { |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 469 | struct phy_device *phydev; |
Alexey Brodkin | a3d3874 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 470 | int mask = 0xffffffff, ret; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 471 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 472 | #ifdef CONFIG_PHY_ADDR |
| 473 | mask = 1 << CONFIG_PHY_ADDR; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 474 | #endif |
| 475 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 476 | phydev = phy_find_by_mask(priv->bus, mask, priv->interface); |
| 477 | if (!phydev) |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 478 | return -ENODEV; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 479 | |
Ian Campbell | 7d55550 | 2014-04-28 20:14:05 +0100 | [diff] [blame] | 480 | phy_connect_dev(phydev, dev); |
| 481 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 482 | phydev->supported &= PHY_GBIT_FEATURES; |
Alexey Brodkin | a3d3874 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 483 | if (priv->max_speed) { |
| 484 | ret = phy_set_supported(phydev, priv->max_speed); |
| 485 | if (ret) |
| 486 | return ret; |
| 487 | } |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 488 | phydev->advertising = phydev->supported; |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 489 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 490 | priv->phydev = phydev; |
| 491 | phy_config(phydev); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 492 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 496 | #ifndef CONFIG_DM_ETH |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 497 | static int dw_eth_init(struct eth_device *dev, bd_t *bis) |
| 498 | { |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 499 | int ret; |
| 500 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 501 | ret = designware_eth_init(dev->priv, dev->enetaddr); |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 502 | if (!ret) |
| 503 | ret = designware_eth_enable(dev->priv); |
| 504 | |
| 505 | return ret; |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static int dw_eth_send(struct eth_device *dev, void *packet, int length) |
| 509 | { |
| 510 | return _dw_eth_send(dev->priv, packet, length); |
| 511 | } |
| 512 | |
| 513 | static int dw_eth_recv(struct eth_device *dev) |
| 514 | { |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 515 | uchar *packet; |
| 516 | int length; |
| 517 | |
| 518 | length = _dw_eth_recv(dev->priv, &packet); |
| 519 | if (length == -EAGAIN) |
| 520 | return 0; |
| 521 | net_process_received_packet(packet, length); |
| 522 | |
| 523 | _dw_free_pkt(dev->priv); |
| 524 | |
| 525 | return 0; |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static void dw_eth_halt(struct eth_device *dev) |
| 529 | { |
| 530 | return _dw_eth_halt(dev->priv); |
| 531 | } |
| 532 | |
| 533 | static int dw_write_hwaddr(struct eth_device *dev) |
| 534 | { |
| 535 | return _dw_write_hwaddr(dev->priv, dev->enetaddr); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 536 | } |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 537 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 538 | int designware_initialize(ulong base_addr, u32 interface) |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 539 | { |
| 540 | struct eth_device *dev; |
| 541 | struct dw_eth_dev *priv; |
| 542 | |
| 543 | dev = (struct eth_device *) malloc(sizeof(struct eth_device)); |
| 544 | if (!dev) |
| 545 | return -ENOMEM; |
| 546 | |
| 547 | /* |
| 548 | * Since the priv structure contains the descriptors which need a strict |
| 549 | * buswidth alignment, memalign is used to allocate memory |
| 550 | */ |
Ian Campbell | 07c92fc | 2014-05-08 22:26:32 +0100 | [diff] [blame] | 551 | priv = (struct dw_eth_dev *) memalign(ARCH_DMA_MINALIGN, |
| 552 | sizeof(struct dw_eth_dev)); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 553 | if (!priv) { |
| 554 | free(dev); |
| 555 | return -ENOMEM; |
| 556 | } |
| 557 | |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 558 | if ((phys_addr_t)priv + sizeof(*priv) > (1ULL << 32)) { |
| 559 | printf("designware: buffers are outside DMA memory\n"); |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 563 | memset(dev, 0, sizeof(struct eth_device)); |
| 564 | memset(priv, 0, sizeof(struct dw_eth_dev)); |
| 565 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 566 | sprintf(dev->name, "dwmac.%lx", base_addr); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 567 | dev->iobase = (int)base_addr; |
| 568 | dev->priv = priv; |
| 569 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 570 | priv->dev = dev; |
| 571 | priv->mac_regs_p = (struct eth_mac_regs *)base_addr; |
| 572 | priv->dma_regs_p = (struct eth_dma_regs *)(base_addr + |
| 573 | DW_DMA_BASE_OFFSET); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 574 | |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 575 | dev->init = dw_eth_init; |
| 576 | dev->send = dw_eth_send; |
| 577 | dev->recv = dw_eth_recv; |
| 578 | dev->halt = dw_eth_halt; |
| 579 | dev->write_hwaddr = dw_write_hwaddr; |
| 580 | |
| 581 | eth_register(dev); |
| 582 | |
Alexey Brodkin | 9a0b130 | 2014-01-22 20:54:06 +0400 | [diff] [blame] | 583 | priv->interface = interface; |
| 584 | |
| 585 | dw_mdio_init(dev->name, priv->mac_regs_p); |
| 586 | priv->bus = miiphy_get_dev_by_name(dev->name); |
| 587 | |
Simon Glass | e50c4d1 | 2015-04-05 16:07:40 -0600 | [diff] [blame] | 588 | return dw_phy_init(priv, dev); |
Vipin KUMAR | 1f87312 | 2010-06-29 10:53:34 +0530 | [diff] [blame] | 589 | } |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 590 | #endif |
| 591 | |
| 592 | #ifdef CONFIG_DM_ETH |
| 593 | static int designware_eth_start(struct udevice *dev) |
| 594 | { |
| 595 | struct eth_pdata *pdata = dev_get_platdata(dev); |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 596 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 597 | int ret; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 598 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 599 | ret = designware_eth_init(priv, pdata->enetaddr); |
Simon Glass | 3240e94 | 2017-01-11 11:46:09 +0100 | [diff] [blame] | 600 | if (ret) |
| 601 | return ret; |
| 602 | ret = designware_eth_enable(priv); |
| 603 | if (ret) |
| 604 | return ret; |
| 605 | |
| 606 | return 0; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 607 | } |
| 608 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 609 | int designware_eth_send(struct udevice *dev, void *packet, int length) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 610 | { |
| 611 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 612 | |
| 613 | return _dw_eth_send(priv, packet, length); |
| 614 | } |
| 615 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 616 | int designware_eth_recv(struct udevice *dev, int flags, uchar **packetp) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 617 | { |
| 618 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 619 | |
| 620 | return _dw_eth_recv(priv, packetp); |
| 621 | } |
| 622 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 623 | int designware_eth_free_pkt(struct udevice *dev, uchar *packet, int length) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 624 | { |
| 625 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 626 | |
| 627 | return _dw_free_pkt(priv); |
| 628 | } |
| 629 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 630 | void designware_eth_stop(struct udevice *dev) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 631 | { |
| 632 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 633 | |
| 634 | return _dw_eth_halt(priv); |
| 635 | } |
| 636 | |
Simon Glass | c154fc0 | 2017-01-11 11:46:10 +0100 | [diff] [blame] | 637 | int designware_eth_write_hwaddr(struct udevice *dev) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 638 | { |
| 639 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 640 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 641 | |
| 642 | return _dw_write_hwaddr(priv, pdata->enetaddr); |
| 643 | } |
| 644 | |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 645 | static int designware_eth_bind(struct udevice *dev) |
| 646 | { |
| 647 | #ifdef CONFIG_DM_PCI |
| 648 | static int num_cards; |
| 649 | char name[20]; |
| 650 | |
| 651 | /* Create a unique device name for PCI type devices */ |
| 652 | if (device_is_on_pci_bus(dev)) { |
| 653 | sprintf(name, "eth_designware#%u", num_cards++); |
| 654 | device_set_name(dev, name); |
| 655 | } |
| 656 | #endif |
| 657 | |
| 658 | return 0; |
| 659 | } |
| 660 | |
Sjoerd Simons | 9cf8fd0 | 2017-01-11 11:46:07 +0100 | [diff] [blame] | 661 | int designware_eth_probe(struct udevice *dev) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 662 | { |
| 663 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 664 | struct dw_eth_dev *priv = dev_get_priv(dev); |
Bin Meng | dfc90f5 | 2015-09-03 05:37:29 -0700 | [diff] [blame] | 665 | u32 iobase = pdata->iobase; |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 666 | ulong ioaddr; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 667 | int ret; |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 668 | #ifdef CONFIG_CLK |
| 669 | int i, err, clock_nb; |
| 670 | |
| 671 | priv->clock_count = 0; |
| 672 | clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells"); |
| 673 | if (clock_nb > 0) { |
| 674 | priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk), |
| 675 | GFP_KERNEL); |
| 676 | if (!priv->clocks) |
| 677 | return -ENOMEM; |
| 678 | |
| 679 | for (i = 0; i < clock_nb; i++) { |
| 680 | err = clk_get_by_index(dev, i, &priv->clocks[i]); |
| 681 | if (err < 0) |
| 682 | break; |
| 683 | |
| 684 | err = clk_enable(&priv->clocks[i]); |
Eugeniy Paltsev | 11e754e | 2018-02-06 17:12:09 +0300 | [diff] [blame] | 685 | if (err && err != -ENOSYS && err != -ENOTSUPP) { |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 686 | pr_err("failed to enable clock %d\n", i); |
| 687 | clk_free(&priv->clocks[i]); |
| 688 | goto clk_err; |
| 689 | } |
| 690 | priv->clock_count++; |
| 691 | } |
| 692 | } else if (clock_nb != -ENOENT) { |
| 693 | pr_err("failed to get clock phandle(%d)\n", clock_nb); |
| 694 | return clock_nb; |
| 695 | } |
| 696 | #endif |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 697 | |
Jacob Chen | 7ceacea | 2017-03-27 16:54:17 +0800 | [diff] [blame] | 698 | #if defined(CONFIG_DM_REGULATOR) |
| 699 | struct udevice *phy_supply; |
| 700 | |
| 701 | ret = device_get_supply_regulator(dev, "phy-supply", |
| 702 | &phy_supply); |
| 703 | if (ret) { |
| 704 | debug("%s: No phy supply\n", dev->name); |
| 705 | } else { |
| 706 | ret = regulator_set_enable(phy_supply, true); |
| 707 | if (ret) { |
| 708 | puts("Error enabling phy supply\n"); |
| 709 | return ret; |
| 710 | } |
| 711 | } |
| 712 | #endif |
| 713 | |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 714 | #ifdef CONFIG_DM_PCI |
| 715 | /* |
| 716 | * If we are on PCI bus, either directly attached to a PCI root port, |
| 717 | * or via a PCI bridge, fill in platdata before we probe the hardware. |
| 718 | */ |
| 719 | if (device_is_on_pci_bus(dev)) { |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 720 | dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase); |
| 721 | iobase &= PCI_BASE_ADDRESS_MEM_MASK; |
Bin Meng | 6c3300c | 2016-02-02 05:58:00 -0800 | [diff] [blame] | 722 | iobase = dm_pci_mem_to_phys(dev, iobase); |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 723 | |
| 724 | pdata->iobase = iobase; |
| 725 | pdata->phy_interface = PHY_INTERFACE_MODE_RMII; |
| 726 | } |
| 727 | #endif |
| 728 | |
Bin Meng | dfc90f5 | 2015-09-03 05:37:29 -0700 | [diff] [blame] | 729 | debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv); |
Beniamino Galvani | 3bfa65c | 2016-05-08 08:30:15 +0200 | [diff] [blame] | 730 | ioaddr = iobase; |
| 731 | priv->mac_regs_p = (struct eth_mac_regs *)ioaddr; |
| 732 | priv->dma_regs_p = (struct eth_dma_regs *)(ioaddr + DW_DMA_BASE_OFFSET); |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 733 | priv->interface = pdata->phy_interface; |
Alexey Brodkin | a3d3874 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 734 | priv->max_speed = pdata->max_speed; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 735 | |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 736 | dw_mdio_init(dev->name, dev); |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 737 | priv->bus = miiphy_get_dev_by_name(dev->name); |
| 738 | |
| 739 | ret = dw_phy_init(priv, dev); |
| 740 | debug("%s, ret=%d\n", __func__, ret); |
| 741 | |
| 742 | return ret; |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 743 | |
| 744 | #ifdef CONFIG_CLK |
| 745 | clk_err: |
| 746 | ret = clk_release_all(priv->clocks, priv->clock_count); |
| 747 | if (ret) |
| 748 | pr_err("failed to disable all clocks\n"); |
| 749 | |
| 750 | return err; |
| 751 | #endif |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 752 | } |
| 753 | |
Bin Meng | f0f0277 | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 754 | static int designware_eth_remove(struct udevice *dev) |
| 755 | { |
| 756 | struct dw_eth_dev *priv = dev_get_priv(dev); |
| 757 | |
| 758 | free(priv->phydev); |
| 759 | mdio_unregister(priv->bus); |
| 760 | mdio_free(priv->bus); |
| 761 | |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 762 | #ifdef CONFIG_CLK |
| 763 | return clk_release_all(priv->clocks, priv->clock_count); |
| 764 | #else |
Bin Meng | f0f0277 | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 765 | return 0; |
Patrice Chotard | eebcf8c | 2017-11-29 09:06:11 +0100 | [diff] [blame] | 766 | #endif |
Bin Meng | f0f0277 | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Sjoerd Simons | 9cf8fd0 | 2017-01-11 11:46:07 +0100 | [diff] [blame] | 769 | const struct eth_ops designware_eth_ops = { |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 770 | .start = designware_eth_start, |
| 771 | .send = designware_eth_send, |
| 772 | .recv = designware_eth_recv, |
| 773 | .free_pkt = designware_eth_free_pkt, |
| 774 | .stop = designware_eth_stop, |
| 775 | .write_hwaddr = designware_eth_write_hwaddr, |
| 776 | }; |
| 777 | |
Sjoerd Simons | 9cf8fd0 | 2017-01-11 11:46:07 +0100 | [diff] [blame] | 778 | int designware_eth_ofdata_to_platdata(struct udevice *dev) |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 779 | { |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 780 | struct dw_eth_pdata *dw_pdata = dev_get_platdata(dev); |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 781 | #ifdef CONFIG_DM_GPIO |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 782 | struct dw_eth_dev *priv = dev_get_priv(dev); |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 783 | #endif |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 784 | struct eth_pdata *pdata = &dw_pdata->eth_pdata; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 785 | const char *phy_mode; |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 786 | #ifdef CONFIG_DM_GPIO |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 787 | int reset_flags = GPIOD_IS_OUT; |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 788 | #endif |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 789 | int ret = 0; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 790 | |
Philipp Tomsich | dcf8763 | 2017-09-11 22:04:13 +0200 | [diff] [blame] | 791 | pdata->iobase = dev_read_addr(dev); |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 792 | pdata->phy_interface = -1; |
Philipp Tomsich | dcf8763 | 2017-09-11 22:04:13 +0200 | [diff] [blame] | 793 | phy_mode = dev_read_string(dev, "phy-mode"); |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 794 | if (phy_mode) |
| 795 | pdata->phy_interface = phy_get_interface_by_name(phy_mode); |
| 796 | if (pdata->phy_interface == -1) { |
| 797 | debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | |
Philipp Tomsich | dcf8763 | 2017-09-11 22:04:13 +0200 | [diff] [blame] | 801 | pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
Alexey Brodkin | a3d3874 | 2016-01-13 16:59:37 +0300 | [diff] [blame] | 802 | |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 803 | #ifdef CONFIG_DM_GPIO |
Philipp Tomsich | 150005b | 2017-06-07 18:46:01 +0200 | [diff] [blame] | 804 | if (dev_read_bool(dev, "snps,reset-active-low")) |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 805 | reset_flags |= GPIOD_ACTIVE_LOW; |
| 806 | |
| 807 | ret = gpio_request_by_name(dev, "snps,reset-gpio", 0, |
| 808 | &priv->reset_gpio, reset_flags); |
| 809 | if (ret == 0) { |
Philipp Tomsich | 150005b | 2017-06-07 18:46:01 +0200 | [diff] [blame] | 810 | ret = dev_read_u32_array(dev, "snps,reset-delays-us", |
| 811 | dw_pdata->reset_delays, 3); |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 812 | } else if (ret == -ENOENT) { |
| 813 | ret = 0; |
| 814 | } |
Alexey Brodkin | 57a37bc | 2016-06-27 13:17:51 +0300 | [diff] [blame] | 815 | #endif |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 816 | |
| 817 | return ret; |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static const struct udevice_id designware_eth_ids[] = { |
| 821 | { .compatible = "allwinner,sun7i-a20-gmac" }, |
Marek Vasut | fcab73c | 2015-07-25 18:38:44 +0200 | [diff] [blame] | 822 | { .compatible = "altr,socfpga-stmmac" }, |
Beniamino Galvani | 2fc2ef5 | 2016-08-16 11:49:50 +0200 | [diff] [blame] | 823 | { .compatible = "amlogic,meson6-dwmac" }, |
Heiner Kallweit | 83fdbe4 | 2017-01-27 21:25:59 +0100 | [diff] [blame] | 824 | { .compatible = "amlogic,meson-gx-dwmac" }, |
Michael Kurz | 812962b | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 825 | { .compatible = "st,stm32-dwmac" }, |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 826 | { } |
| 827 | }; |
| 828 | |
Marek Vasut | 7e7e617 | 2015-07-25 18:42:34 +0200 | [diff] [blame] | 829 | U_BOOT_DRIVER(eth_designware) = { |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 830 | .name = "eth_designware", |
| 831 | .id = UCLASS_ETH, |
| 832 | .of_match = designware_eth_ids, |
| 833 | .ofdata_to_platdata = designware_eth_ofdata_to_platdata, |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 834 | .bind = designware_eth_bind, |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 835 | .probe = designware_eth_probe, |
Bin Meng | f0f0277 | 2015-10-07 21:32:38 -0700 | [diff] [blame] | 836 | .remove = designware_eth_remove, |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 837 | .ops = &designware_eth_ops, |
| 838 | .priv_auto_alloc_size = sizeof(struct dw_eth_dev), |
Sjoerd Simons | 6eb4462 | 2016-02-28 22:24:55 +0100 | [diff] [blame] | 839 | .platdata_auto_alloc_size = sizeof(struct dw_eth_pdata), |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 840 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 841 | }; |
Bin Meng | ed89bd7 | 2015-09-11 03:24:35 -0700 | [diff] [blame] | 842 | |
| 843 | static struct pci_device_id supported[] = { |
| 844 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) }, |
| 845 | { } |
| 846 | }; |
| 847 | |
| 848 | U_BOOT_PCI_DEVICE(eth_designware, supported); |
Simon Glass | 90e627b | 2015-04-05 16:07:41 -0600 | [diff] [blame] | 849 | #endif |