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