blob: e8569e6fef5fefdd36e874e7efc2689e559871ff [file] [log] [blame]
Vipin KUMAR1f873122010-06-29 10:53:34 +05301/*
2 * (C) Copyright 2010
3 * Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Vipin KUMAR1f873122010-06-29 10:53:34 +05306 */
7
8/*
Simon Glasse50c4d12015-04-05 16:07:40 -06009 * Designware ethernet IP driver for U-Boot
Vipin KUMAR1f873122010-06-29 10:53:34 +053010 */
11
12#include <common.h>
Simon Glass90e627b2015-04-05 16:07:41 -060013#include <dm.h>
Simon Glasse50c4d12015-04-05 16:07:40 -060014#include <errno.h>
Vipin KUMAR1f873122010-06-29 10:53:34 +053015#include <miiphy.h>
16#include <malloc.h>
Bin Menged89bd72015-09-11 03:24:35 -070017#include <pci.h>
Stefan Roesed27e86c2012-05-07 12:04:25 +020018#include <linux/compiler.h>
Vipin KUMAR1f873122010-06-29 10:53:34 +053019#include <linux/err.h>
20#include <asm/io.h>
Jacob Chen7ceacea2017-03-27 16:54:17 +080021#include <power/regulator.h>
Vipin KUMAR1f873122010-06-29 10:53:34 +053022#include "designware.h"
23
Simon Glass90e627b2015-04-05 16:07:41 -060024DECLARE_GLOBAL_DATA_PTR;
25
Alexey Brodkin9a0b1302014-01-22 20:54:06 +040026static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
27{
Sjoerd Simons6eb44622016-02-28 22:24:55 +010028#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 Brodkin9a0b1302014-01-22 20:54:06 +040032 struct eth_mac_regs *mac_p = bus->priv;
Sjoerd Simons6eb44622016-02-28 22:24:55 +010033#endif
Alexey Brodkin9a0b1302014-01-22 20:54:06 +040034 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 Glasse50c4d12015-04-05 16:07:40 -060050 return -ETIMEDOUT;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +040051}
52
53static int dw_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
54 u16 val)
55{
Sjoerd Simons6eb44622016-02-28 22:24:55 +010056#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 Brodkin9a0b1302014-01-22 20:54:06 +040060 struct eth_mac_regs *mac_p = bus->priv;
Sjoerd Simons6eb44622016-02-28 22:24:55 +010061#endif
Alexey Brodkin9a0b1302014-01-22 20:54:06 +040062 ulong start;
63 u16 miiaddr;
Simon Glasse50c4d12015-04-05 16:07:40 -060064 int ret = -ETIMEDOUT, timeout = CONFIG_MDIO_TIMEOUT;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +040065
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 Brodkin57a37bc2016-06-27 13:17:51 +030084#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO)
Sjoerd Simons6eb44622016-02-28 22:24:55 +010085static 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
118static int dw_mdio_init(const char *name, void *priv)
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400119{
120 struct mii_dev *bus = mdio_alloc();
121
122 if (!bus) {
123 printf("Failed to allocate MDIO bus\n");
Simon Glasse50c4d12015-04-05 16:07:40 -0600124 return -ENOMEM;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400125 }
126
127 bus->read = dw_mdio_read;
128 bus->write = dw_mdio_write;
Ben Whitten34fd6c92015-12-30 13:05:58 +0000129 snprintf(bus->name, sizeof(bus->name), "%s", name);
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300130#if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_GPIO)
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100131 bus->reset = dw_mdio_reset;
132#endif
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400133
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100134 bus->priv = priv;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400135
136 return mdio_register(bus);
137}
Vipin Kumarb6c59992012-03-26 00:09:56 +0000138
Simon Glasse50c4d12015-04-05 16:07:40 -0600139static void tx_descs_init(struct dw_eth_dev *priv)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530140{
Vipin KUMAR1f873122010-06-29 10:53:34 +0530141 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 Galvani3bfa65c2016-05-08 08:30:15 +0200149 desc_p->dmamac_addr = (ulong)&txbuffs[idx * CONFIG_ETH_BUFSIZE];
150 desc_p->dmamac_next = (ulong)&desc_table_p[idx + 1];
Vipin KUMAR1f873122010-06-29 10:53:34 +0530151
152#if defined(CONFIG_DW_ALTDESCRIPTOR)
153 desc_p->txrx_status &= ~(DESC_TXSTS_TXINT | DESC_TXSTS_TXLAST |
Marek Vasut4ab539a2015-12-20 03:59:23 +0100154 DESC_TXSTS_TXFIRST | DESC_TXSTS_TXCRCDIS |
155 DESC_TXSTS_TXCHECKINSCTRL |
Vipin KUMAR1f873122010-06-29 10:53:34 +0530156 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 Galvani3bfa65c2016-05-08 08:30:15 +0200168 desc_p->dmamac_next = (ulong)&desc_table_p[0];
Vipin KUMAR1f873122010-06-29 10:53:34 +0530169
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400170 /* Flush all Tx buffer descriptors at once */
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200171 flush_dcache_range((ulong)priv->tx_mac_descrtable,
172 (ulong)priv->tx_mac_descrtable +
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400173 sizeof(priv->tx_mac_descrtable));
174
Vipin KUMAR1f873122010-06-29 10:53:34 +0530175 writel((ulong)&desc_table_p[0], &dma_p->txdesclistaddr);
Alexey Brodkin4695ddd2014-01-13 13:28:38 +0400176 priv->tx_currdescnum = 0;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530177}
178
Simon Glasse50c4d12015-04-05 16:07:40 -0600179static void rx_descs_init(struct dw_eth_dev *priv)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530180{
Vipin KUMAR1f873122010-06-29 10:53:34 +0530181 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 Brodkin0d3b22e2014-01-22 20:49:09 +0400187 /* 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 Galvani3bfa65c2016-05-08 08:30:15 +0200193 flush_dcache_range((ulong)rxbuffs, (ulong)rxbuffs + RX_TOTAL_BUFSIZE);
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400194
Vipin KUMAR1f873122010-06-29 10:53:34 +0530195 for (idx = 0; idx < CONFIG_RX_DESCR_NUM; idx++) {
196 desc_p = &desc_table_p[idx];
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200197 desc_p->dmamac_addr = (ulong)&rxbuffs[idx * CONFIG_ETH_BUFSIZE];
198 desc_p->dmamac_next = (ulong)&desc_table_p[idx + 1];
Vipin KUMAR1f873122010-06-29 10:53:34 +0530199
200 desc_p->dmamac_cntl =
Marek Vasut4ab539a2015-12-20 03:59:23 +0100201 (MAC_MAX_FRAME_SZ & DESC_RXCTRL_SIZE1MASK) |
Vipin KUMAR1f873122010-06-29 10:53:34 +0530202 DESC_RXCTRL_RXCHAIN;
203
204 desc_p->txrx_status = DESC_RXSTS_OWNBYDMA;
205 }
206
207 /* Correcting the last pointer of the chain */
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200208 desc_p->dmamac_next = (ulong)&desc_table_p[0];
Vipin KUMAR1f873122010-06-29 10:53:34 +0530209
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400210 /* Flush all Rx buffer descriptors at once */
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200211 flush_dcache_range((ulong)priv->rx_mac_descrtable,
212 (ulong)priv->rx_mac_descrtable +
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400213 sizeof(priv->rx_mac_descrtable));
214
Vipin KUMAR1f873122010-06-29 10:53:34 +0530215 writel((ulong)&desc_table_p[0], &dma_p->rxdesclistaddr);
Alexey Brodkin4695ddd2014-01-13 13:28:38 +0400216 priv->rx_currdescnum = 0;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530217}
218
Simon Glasse50c4d12015-04-05 16:07:40 -0600219static int _dw_write_hwaddr(struct dw_eth_dev *priv, u8 *mac_id)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530220{
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400221 struct eth_mac_regs *mac_p = priv->mac_regs_p;
222 u32 macid_lo, macid_hi;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400223
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 KUMAR1f873122010-06-29 10:53:34 +0530232}
233
Simon Glass4afa85e2017-01-11 11:46:08 +0100234static int dw_adjust_link(struct dw_eth_dev *priv, struct eth_mac_regs *mac_p,
235 struct phy_device *phydev)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530236{
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400237 u32 conf = readl(&mac_p->conf) | FRAMEBURSTENABLE | DISABLERXOWN;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530238
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400239 if (!phydev->link) {
240 printf("%s: No link.\n", phydev->dev->name);
Simon Glass4afa85e2017-01-11 11:46:08 +0100241 return 0;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400242 }
Vipin KUMAR1f873122010-06-29 10:53:34 +0530243
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400244 if (phydev->speed != 1000)
245 conf |= MII_PORTSELECT;
Alexey Brodkina5e88192016-01-13 16:59:36 +0300246 else
247 conf &= ~MII_PORTSELECT;
Vipin Kumarf567e412012-12-13 17:22:51 +0530248
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400249 if (phydev->speed == 100)
250 conf |= FES_100;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530251
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400252 if (phydev->duplex)
253 conf |= FULLDPLXMODE;
Amit Virdi470e8842012-03-26 00:09:59 +0000254
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400255 writel(conf, &mac_p->conf);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530256
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400257 printf("Speed: %d, %s duplex%s\n", phydev->speed,
258 (phydev->duplex) ? "full" : "half",
259 (phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
Simon Glass4afa85e2017-01-11 11:46:08 +0100260
261 return 0;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530262}
263
Simon Glasse50c4d12015-04-05 16:07:40 -0600264static void _dw_eth_halt(struct dw_eth_dev *priv)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530265{
Vipin KUMAR1f873122010-06-29 10:53:34 +0530266 struct eth_mac_regs *mac_p = priv->mac_regs_p;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400267 struct eth_dma_regs *dma_p = priv->dma_regs_p;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530268
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400269 writel(readl(&mac_p->conf) & ~(RXENABLE | TXENABLE), &mac_p->conf);
270 writel(readl(&dma_p->opmode) & ~(RXSTART | TXSTART), &dma_p->opmode);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530271
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400272 phy_shutdown(priv->phydev);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530273}
274
Simon Glassc154fc02017-01-11 11:46:10 +0100275int designware_eth_init(struct dw_eth_dev *priv, u8 *enetaddr)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530276{
Vipin KUMAR1f873122010-06-29 10:53:34 +0530277 struct eth_mac_regs *mac_p = priv->mac_regs_p;
278 struct eth_dma_regs *dma_p = priv->dma_regs_p;
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400279 unsigned int start;
Simon Glasse50c4d12015-04-05 16:07:40 -0600280 int ret;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530281
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400282 writel(readl(&dma_p->busmode) | DMAMAC_SRST, &dma_p->busmode);
Vipin Kumarb6c59992012-03-26 00:09:56 +0000283
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400284 start = get_timer(0);
285 while (readl(&dma_p->busmode) & DMAMAC_SRST) {
Alexey Brodkin71eccc32015-01-13 17:10:24 +0300286 if (get_timer(start) >= CONFIG_MACRESET_TIMEOUT) {
287 printf("DMA reset timeout\n");
Simon Glasse50c4d12015-04-05 16:07:40 -0600288 return -ETIMEDOUT;
Alexey Brodkin71eccc32015-01-13 17:10:24 +0300289 }
Stefan Roesed27e86c2012-05-07 12:04:25 +0200290
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400291 mdelay(100);
292 };
Vipin KUMAR1f873122010-06-29 10:53:34 +0530293
Bin Meng2ddfa2a2015-06-15 18:40:19 +0800294 /*
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 Glasse50c4d12015-04-05 16:07:40 -0600300 rx_descs_init(priv);
301 tx_descs_init(priv);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530302
Ian Campbell4164b742014-05-08 22:26:35 +0100303 writel(FIXEDBURST | PRIORXTX_41 | DMA_PBL, &dma_p->busmode);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530304
Sonic Zhangb917b622015-01-29 14:38:50 +0800305#ifndef CONFIG_DW_MAC_FORCE_THRESHOLD_MODE
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400306 writel(readl(&dma_p->opmode) | FLUSHTXFIFO | STOREFORWARD,
307 &dma_p->opmode);
Sonic Zhangb917b622015-01-29 14:38:50 +0800308#else
309 writel(readl(&dma_p->opmode) | FLUSHTXFIFO,
310 &dma_p->opmode);
311#endif
Vipin KUMAR1f873122010-06-29 10:53:34 +0530312
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400313 writel(readl(&dma_p->opmode) | RXSTART | TXSTART, &dma_p->opmode);
Vipin Kumar7443d602012-05-07 13:06:44 +0530314
Sonic Zhang962c95c2015-01-29 13:37:31 +0800315#ifdef CONFIG_DW_AXI_BURST_LEN
316 writel((CONFIG_DW_AXI_BURST_LEN & 0x1FF >> 1), &dma_p->axibus);
317#endif
318
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400319 /* Start up the PHY */
Simon Glasse50c4d12015-04-05 16:07:40 -0600320 ret = phy_startup(priv->phydev);
321 if (ret) {
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400322 printf("Could not initialize PHY %s\n",
323 priv->phydev->dev->name);
Simon Glasse50c4d12015-04-05 16:07:40 -0600324 return ret;
Vipin Kumar7443d602012-05-07 13:06:44 +0530325 }
326
Simon Glass4afa85e2017-01-11 11:46:08 +0100327 ret = dw_adjust_link(priv, mac_p, priv->phydev);
328 if (ret)
329 return ret;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530330
Simon Glass3240e942017-01-11 11:46:09 +0100331 return 0;
332}
333
Simon Glassc154fc02017-01-11 11:46:10 +0100334int designware_eth_enable(struct dw_eth_dev *priv)
Simon Glass3240e942017-01-11 11:46:09 +0100335{
336 struct eth_mac_regs *mac_p = priv->mac_regs_p;
337
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400338 if (!priv->phydev->link)
Simon Glasse50c4d12015-04-05 16:07:40 -0600339 return -EIO;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530340
Armando Visconti038c9d52012-03-26 00:09:55 +0000341 writel(readl(&mac_p->conf) | RXENABLE | TXENABLE, &mac_p->conf);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530342
343 return 0;
344}
345
Simon Glasse50c4d12015-04-05 16:07:40 -0600346static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530347{
Vipin KUMAR1f873122010-06-29 10:53:34 +0530348 struct eth_dma_regs *dma_p = priv->dma_regs_p;
349 u32 desc_num = priv->tx_currdescnum;
350 struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num];
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200351 ulong desc_start = (ulong)desc_p;
352 ulong desc_end = desc_start +
Marek Vasut15193042014-09-15 01:05:23 +0200353 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200354 ulong data_start = desc_p->dmamac_addr;
355 ulong data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
Ian Campbell0e690fd2014-05-08 22:26:33 +0100356 /*
357 * Strictly we only need to invalidate the "txrx_status" field
358 * for the following check, but on some platforms we cannot
Marek Vasut15193042014-09-15 01:05:23 +0200359 * invalidate only 4 bytes, so we flush the entire descriptor,
360 * which is 16 bytes in total. This is safe because the
361 * individual descriptors in the array are each aligned to
362 * ARCH_DMA_MINALIGN and padded appropriately.
Ian Campbell0e690fd2014-05-08 22:26:33 +0100363 */
Marek Vasut15193042014-09-15 01:05:23 +0200364 invalidate_dcache_range(desc_start, desc_end);
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400365
Vipin KUMAR1f873122010-06-29 10:53:34 +0530366 /* Check if the descriptor is owned by CPU */
367 if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) {
368 printf("CPU not owner of tx frame\n");
Simon Glasse50c4d12015-04-05 16:07:40 -0600369 return -EPERM;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530370 }
371
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200372 memcpy((void *)data_start, packet, length);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530373
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400374 /* Flush data to be sent */
Marek Vasut15193042014-09-15 01:05:23 +0200375 flush_dcache_range(data_start, data_end);
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400376
Vipin KUMAR1f873122010-06-29 10:53:34 +0530377#if defined(CONFIG_DW_ALTDESCRIPTOR)
378 desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST;
Marek Vasut4ab539a2015-12-20 03:59:23 +0100379 desc_p->dmamac_cntl |= (length << DESC_TXCTRL_SIZE1SHFT) &
Vipin KUMAR1f873122010-06-29 10:53:34 +0530380 DESC_TXCTRL_SIZE1MASK;
381
382 desc_p->txrx_status &= ~(DESC_TXSTS_MSK);
383 desc_p->txrx_status |= DESC_TXSTS_OWNBYDMA;
384#else
Marek Vasut4ab539a2015-12-20 03:59:23 +0100385 desc_p->dmamac_cntl |= ((length << DESC_TXCTRL_SIZE1SHFT) &
386 DESC_TXCTRL_SIZE1MASK) | DESC_TXCTRL_TXLAST |
Vipin KUMAR1f873122010-06-29 10:53:34 +0530387 DESC_TXCTRL_TXFIRST;
388
389 desc_p->txrx_status = DESC_TXSTS_OWNBYDMA;
390#endif
391
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400392 /* Flush modified buffer descriptor */
Marek Vasut15193042014-09-15 01:05:23 +0200393 flush_dcache_range(desc_start, desc_end);
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400394
Vipin KUMAR1f873122010-06-29 10:53:34 +0530395 /* Test the wrap-around condition. */
396 if (++desc_num >= CONFIG_TX_DESCR_NUM)
397 desc_num = 0;
398
399 priv->tx_currdescnum = desc_num;
400
401 /* Start the transmission */
402 writel(POLL_DATA, &dma_p->txpolldemand);
403
404 return 0;
405}
406
Simon Glass90e627b2015-04-05 16:07:41 -0600407static int _dw_eth_recv(struct dw_eth_dev *priv, uchar **packetp)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530408{
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400409 u32 status, desc_num = priv->rx_currdescnum;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530410 struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
Simon Glass90e627b2015-04-05 16:07:41 -0600411 int length = -EAGAIN;
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200412 ulong desc_start = (ulong)desc_p;
413 ulong desc_end = desc_start +
Marek Vasut15193042014-09-15 01:05:23 +0200414 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200415 ulong data_start = desc_p->dmamac_addr;
416 ulong data_end;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530417
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400418 /* Invalidate entire buffer descriptor */
Marek Vasut15193042014-09-15 01:05:23 +0200419 invalidate_dcache_range(desc_start, desc_end);
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400420
421 status = desc_p->txrx_status;
422
Vipin KUMAR1f873122010-06-29 10:53:34 +0530423 /* Check if the owner is the CPU */
424 if (!(status & DESC_RXSTS_OWNBYDMA)) {
425
Marek Vasut4ab539a2015-12-20 03:59:23 +0100426 length = (status & DESC_RXSTS_FRMLENMSK) >>
Vipin KUMAR1f873122010-06-29 10:53:34 +0530427 DESC_RXSTS_FRMLENSHFT;
428
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400429 /* Invalidate received data */
Marek Vasut15193042014-09-15 01:05:23 +0200430 data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
431 invalidate_dcache_range(data_start, data_end);
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200432 *packetp = (uchar *)(ulong)desc_p->dmamac_addr;
Simon Glass90e627b2015-04-05 16:07:41 -0600433 }
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400434
Simon Glass90e627b2015-04-05 16:07:41 -0600435 return length;
436}
Vipin KUMAR1f873122010-06-29 10:53:34 +0530437
Simon Glass90e627b2015-04-05 16:07:41 -0600438static int _dw_free_pkt(struct dw_eth_dev *priv)
439{
440 u32 desc_num = priv->rx_currdescnum;
441 struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200442 ulong desc_start = (ulong)desc_p;
443 ulong desc_end = desc_start +
Simon Glass90e627b2015-04-05 16:07:41 -0600444 roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530445
Simon Glass90e627b2015-04-05 16:07:41 -0600446 /*
447 * Make the current descriptor valid again and go to
448 * the next one
449 */
450 desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
Alexey Brodkin0d3b22e2014-01-22 20:49:09 +0400451
Simon Glass90e627b2015-04-05 16:07:41 -0600452 /* Flush only status field - others weren't changed */
453 flush_dcache_range(desc_start, desc_end);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530454
Simon Glass90e627b2015-04-05 16:07:41 -0600455 /* Test the wrap-around condition. */
456 if (++desc_num >= CONFIG_RX_DESCR_NUM)
457 desc_num = 0;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530458 priv->rx_currdescnum = desc_num;
459
Simon Glass90e627b2015-04-05 16:07:41 -0600460 return 0;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530461}
462
Simon Glasse50c4d12015-04-05 16:07:40 -0600463static int dw_phy_init(struct dw_eth_dev *priv, void *dev)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530464{
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400465 struct phy_device *phydev;
Alexey Brodkina3d38742016-01-13 16:59:37 +0300466 int mask = 0xffffffff, ret;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530467
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400468#ifdef CONFIG_PHY_ADDR
469 mask = 1 << CONFIG_PHY_ADDR;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530470#endif
471
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400472 phydev = phy_find_by_mask(priv->bus, mask, priv->interface);
473 if (!phydev)
Simon Glasse50c4d12015-04-05 16:07:40 -0600474 return -ENODEV;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530475
Ian Campbell7d555502014-04-28 20:14:05 +0100476 phy_connect_dev(phydev, dev);
477
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400478 phydev->supported &= PHY_GBIT_FEATURES;
Alexey Brodkina3d38742016-01-13 16:59:37 +0300479 if (priv->max_speed) {
480 ret = phy_set_supported(phydev, priv->max_speed);
481 if (ret)
482 return ret;
483 }
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400484 phydev->advertising = phydev->supported;
Vipin KUMAR1f873122010-06-29 10:53:34 +0530485
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400486 priv->phydev = phydev;
487 phy_config(phydev);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530488
Simon Glasse50c4d12015-04-05 16:07:40 -0600489 return 0;
490}
491
Simon Glass90e627b2015-04-05 16:07:41 -0600492#ifndef CONFIG_DM_ETH
Simon Glasse50c4d12015-04-05 16:07:40 -0600493static int dw_eth_init(struct eth_device *dev, bd_t *bis)
494{
Simon Glass3240e942017-01-11 11:46:09 +0100495 int ret;
496
Simon Glassc154fc02017-01-11 11:46:10 +0100497 ret = designware_eth_init(dev->priv, dev->enetaddr);
Simon Glass3240e942017-01-11 11:46:09 +0100498 if (!ret)
499 ret = designware_eth_enable(dev->priv);
500
501 return ret;
Simon Glasse50c4d12015-04-05 16:07:40 -0600502}
503
504static int dw_eth_send(struct eth_device *dev, void *packet, int length)
505{
506 return _dw_eth_send(dev->priv, packet, length);
507}
508
509static int dw_eth_recv(struct eth_device *dev)
510{
Simon Glass90e627b2015-04-05 16:07:41 -0600511 uchar *packet;
512 int length;
513
514 length = _dw_eth_recv(dev->priv, &packet);
515 if (length == -EAGAIN)
516 return 0;
517 net_process_received_packet(packet, length);
518
519 _dw_free_pkt(dev->priv);
520
521 return 0;
Simon Glasse50c4d12015-04-05 16:07:40 -0600522}
523
524static void dw_eth_halt(struct eth_device *dev)
525{
526 return _dw_eth_halt(dev->priv);
527}
528
529static int dw_write_hwaddr(struct eth_device *dev)
530{
531 return _dw_write_hwaddr(dev->priv, dev->enetaddr);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530532}
Vipin KUMAR1f873122010-06-29 10:53:34 +0530533
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400534int designware_initialize(ulong base_addr, u32 interface)
Vipin KUMAR1f873122010-06-29 10:53:34 +0530535{
536 struct eth_device *dev;
537 struct dw_eth_dev *priv;
538
539 dev = (struct eth_device *) malloc(sizeof(struct eth_device));
540 if (!dev)
541 return -ENOMEM;
542
543 /*
544 * Since the priv structure contains the descriptors which need a strict
545 * buswidth alignment, memalign is used to allocate memory
546 */
Ian Campbell07c92fc2014-05-08 22:26:32 +0100547 priv = (struct dw_eth_dev *) memalign(ARCH_DMA_MINALIGN,
548 sizeof(struct dw_eth_dev));
Vipin KUMAR1f873122010-06-29 10:53:34 +0530549 if (!priv) {
550 free(dev);
551 return -ENOMEM;
552 }
553
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200554 if ((phys_addr_t)priv + sizeof(*priv) > (1ULL << 32)) {
555 printf("designware: buffers are outside DMA memory\n");
556 return -EINVAL;
557 }
558
Vipin KUMAR1f873122010-06-29 10:53:34 +0530559 memset(dev, 0, sizeof(struct eth_device));
560 memset(priv, 0, sizeof(struct dw_eth_dev));
561
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400562 sprintf(dev->name, "dwmac.%lx", base_addr);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530563 dev->iobase = (int)base_addr;
564 dev->priv = priv;
565
Vipin KUMAR1f873122010-06-29 10:53:34 +0530566 priv->dev = dev;
567 priv->mac_regs_p = (struct eth_mac_regs *)base_addr;
568 priv->dma_regs_p = (struct eth_dma_regs *)(base_addr +
569 DW_DMA_BASE_OFFSET);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530570
Vipin KUMAR1f873122010-06-29 10:53:34 +0530571 dev->init = dw_eth_init;
572 dev->send = dw_eth_send;
573 dev->recv = dw_eth_recv;
574 dev->halt = dw_eth_halt;
575 dev->write_hwaddr = dw_write_hwaddr;
576
577 eth_register(dev);
578
Alexey Brodkin9a0b1302014-01-22 20:54:06 +0400579 priv->interface = interface;
580
581 dw_mdio_init(dev->name, priv->mac_regs_p);
582 priv->bus = miiphy_get_dev_by_name(dev->name);
583
Simon Glasse50c4d12015-04-05 16:07:40 -0600584 return dw_phy_init(priv, dev);
Vipin KUMAR1f873122010-06-29 10:53:34 +0530585}
Simon Glass90e627b2015-04-05 16:07:41 -0600586#endif
587
588#ifdef CONFIG_DM_ETH
589static int designware_eth_start(struct udevice *dev)
590{
591 struct eth_pdata *pdata = dev_get_platdata(dev);
Simon Glass3240e942017-01-11 11:46:09 +0100592 struct dw_eth_dev *priv = dev_get_priv(dev);
593 int ret;
Simon Glass90e627b2015-04-05 16:07:41 -0600594
Simon Glassc154fc02017-01-11 11:46:10 +0100595 ret = designware_eth_init(priv, pdata->enetaddr);
Simon Glass3240e942017-01-11 11:46:09 +0100596 if (ret)
597 return ret;
598 ret = designware_eth_enable(priv);
599 if (ret)
600 return ret;
601
602 return 0;
Simon Glass90e627b2015-04-05 16:07:41 -0600603}
604
Simon Glassc154fc02017-01-11 11:46:10 +0100605int designware_eth_send(struct udevice *dev, void *packet, int length)
Simon Glass90e627b2015-04-05 16:07:41 -0600606{
607 struct dw_eth_dev *priv = dev_get_priv(dev);
608
609 return _dw_eth_send(priv, packet, length);
610}
611
Simon Glassc154fc02017-01-11 11:46:10 +0100612int designware_eth_recv(struct udevice *dev, int flags, uchar **packetp)
Simon Glass90e627b2015-04-05 16:07:41 -0600613{
614 struct dw_eth_dev *priv = dev_get_priv(dev);
615
616 return _dw_eth_recv(priv, packetp);
617}
618
Simon Glassc154fc02017-01-11 11:46:10 +0100619int designware_eth_free_pkt(struct udevice *dev, uchar *packet, int length)
Simon Glass90e627b2015-04-05 16:07:41 -0600620{
621 struct dw_eth_dev *priv = dev_get_priv(dev);
622
623 return _dw_free_pkt(priv);
624}
625
Simon Glassc154fc02017-01-11 11:46:10 +0100626void designware_eth_stop(struct udevice *dev)
Simon Glass90e627b2015-04-05 16:07:41 -0600627{
628 struct dw_eth_dev *priv = dev_get_priv(dev);
629
630 return _dw_eth_halt(priv);
631}
632
Simon Glassc154fc02017-01-11 11:46:10 +0100633int designware_eth_write_hwaddr(struct udevice *dev)
Simon Glass90e627b2015-04-05 16:07:41 -0600634{
635 struct eth_pdata *pdata = dev_get_platdata(dev);
636 struct dw_eth_dev *priv = dev_get_priv(dev);
637
638 return _dw_write_hwaddr(priv, pdata->enetaddr);
639}
640
Bin Menged89bd72015-09-11 03:24:35 -0700641static int designware_eth_bind(struct udevice *dev)
642{
643#ifdef CONFIG_DM_PCI
644 static int num_cards;
645 char name[20];
646
647 /* Create a unique device name for PCI type devices */
648 if (device_is_on_pci_bus(dev)) {
649 sprintf(name, "eth_designware#%u", num_cards++);
650 device_set_name(dev, name);
651 }
652#endif
653
654 return 0;
655}
656
Sjoerd Simons9cf8fd02017-01-11 11:46:07 +0100657int designware_eth_probe(struct udevice *dev)
Simon Glass90e627b2015-04-05 16:07:41 -0600658{
659 struct eth_pdata *pdata = dev_get_platdata(dev);
660 struct dw_eth_dev *priv = dev_get_priv(dev);
Bin Mengdfc90f52015-09-03 05:37:29 -0700661 u32 iobase = pdata->iobase;
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200662 ulong ioaddr;
Simon Glass90e627b2015-04-05 16:07:41 -0600663 int ret;
664
Jacob Chen7ceacea2017-03-27 16:54:17 +0800665#if defined(CONFIG_DM_REGULATOR)
666 struct udevice *phy_supply;
667
668 ret = device_get_supply_regulator(dev, "phy-supply",
669 &phy_supply);
670 if (ret) {
671 debug("%s: No phy supply\n", dev->name);
672 } else {
673 ret = regulator_set_enable(phy_supply, true);
674 if (ret) {
675 puts("Error enabling phy supply\n");
676 return ret;
677 }
678 }
679#endif
680
Bin Menged89bd72015-09-11 03:24:35 -0700681#ifdef CONFIG_DM_PCI
682 /*
683 * If we are on PCI bus, either directly attached to a PCI root port,
684 * or via a PCI bridge, fill in platdata before we probe the hardware.
685 */
686 if (device_is_on_pci_bus(dev)) {
Bin Menged89bd72015-09-11 03:24:35 -0700687 dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
688 iobase &= PCI_BASE_ADDRESS_MEM_MASK;
Bin Meng6c3300c2016-02-02 05:58:00 -0800689 iobase = dm_pci_mem_to_phys(dev, iobase);
Bin Menged89bd72015-09-11 03:24:35 -0700690
691 pdata->iobase = iobase;
692 pdata->phy_interface = PHY_INTERFACE_MODE_RMII;
693 }
694#endif
695
Bin Mengdfc90f52015-09-03 05:37:29 -0700696 debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
Beniamino Galvani3bfa65c2016-05-08 08:30:15 +0200697 ioaddr = iobase;
698 priv->mac_regs_p = (struct eth_mac_regs *)ioaddr;
699 priv->dma_regs_p = (struct eth_dma_regs *)(ioaddr + DW_DMA_BASE_OFFSET);
Simon Glass90e627b2015-04-05 16:07:41 -0600700 priv->interface = pdata->phy_interface;
Alexey Brodkina3d38742016-01-13 16:59:37 +0300701 priv->max_speed = pdata->max_speed;
Simon Glass90e627b2015-04-05 16:07:41 -0600702
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100703 dw_mdio_init(dev->name, dev);
Simon Glass90e627b2015-04-05 16:07:41 -0600704 priv->bus = miiphy_get_dev_by_name(dev->name);
705
706 ret = dw_phy_init(priv, dev);
707 debug("%s, ret=%d\n", __func__, ret);
708
709 return ret;
710}
711
Bin Mengf0f02772015-10-07 21:32:38 -0700712static int designware_eth_remove(struct udevice *dev)
713{
714 struct dw_eth_dev *priv = dev_get_priv(dev);
715
716 free(priv->phydev);
717 mdio_unregister(priv->bus);
718 mdio_free(priv->bus);
719
720 return 0;
721}
722
Sjoerd Simons9cf8fd02017-01-11 11:46:07 +0100723const struct eth_ops designware_eth_ops = {
Simon Glass90e627b2015-04-05 16:07:41 -0600724 .start = designware_eth_start,
725 .send = designware_eth_send,
726 .recv = designware_eth_recv,
727 .free_pkt = designware_eth_free_pkt,
728 .stop = designware_eth_stop,
729 .write_hwaddr = designware_eth_write_hwaddr,
730};
731
Sjoerd Simons9cf8fd02017-01-11 11:46:07 +0100732int designware_eth_ofdata_to_platdata(struct udevice *dev)
Simon Glass90e627b2015-04-05 16:07:41 -0600733{
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100734 struct dw_eth_pdata *dw_pdata = dev_get_platdata(dev);
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300735#ifdef CONFIG_DM_GPIO
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100736 struct dw_eth_dev *priv = dev_get_priv(dev);
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300737#endif
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100738 struct eth_pdata *pdata = &dw_pdata->eth_pdata;
Simon Glass90e627b2015-04-05 16:07:41 -0600739 const char *phy_mode;
Alexey Brodkina3d38742016-01-13 16:59:37 +0300740 const fdt32_t *cell;
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300741#ifdef CONFIG_DM_GPIO
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100742 int reset_flags = GPIOD_IS_OUT;
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300743#endif
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100744 int ret = 0;
Simon Glass90e627b2015-04-05 16:07:41 -0600745
Simon Glassba1dea42017-05-17 17:18:05 -0600746 pdata->iobase = devfdt_get_addr(dev);
Simon Glass90e627b2015-04-05 16:07:41 -0600747 pdata->phy_interface = -1;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700748 phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
749 NULL);
Simon Glass90e627b2015-04-05 16:07:41 -0600750 if (phy_mode)
751 pdata->phy_interface = phy_get_interface_by_name(phy_mode);
752 if (pdata->phy_interface == -1) {
753 debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
754 return -EINVAL;
755 }
756
Alexey Brodkina3d38742016-01-13 16:59:37 +0300757 pdata->max_speed = 0;
Simon Glassdd79d6e2017-01-17 16:52:55 -0700758 cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL);
Alexey Brodkina3d38742016-01-13 16:59:37 +0300759 if (cell)
760 pdata->max_speed = fdt32_to_cpu(*cell);
761
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300762#ifdef CONFIG_DM_GPIO
Simon Glassdd79d6e2017-01-17 16:52:55 -0700763 if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev),
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100764 "snps,reset-active-low"))
765 reset_flags |= GPIOD_ACTIVE_LOW;
766
767 ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
768 &priv->reset_gpio, reset_flags);
769 if (ret == 0) {
Simon Glassdd79d6e2017-01-17 16:52:55 -0700770 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100771 "snps,reset-delays-us", dw_pdata->reset_delays, 3);
772 } else if (ret == -ENOENT) {
773 ret = 0;
774 }
Alexey Brodkin57a37bc2016-06-27 13:17:51 +0300775#endif
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100776
777 return ret;
Simon Glass90e627b2015-04-05 16:07:41 -0600778}
779
780static const struct udevice_id designware_eth_ids[] = {
781 { .compatible = "allwinner,sun7i-a20-gmac" },
Marek Vasutfcab73c2015-07-25 18:38:44 +0200782 { .compatible = "altr,socfpga-stmmac" },
Beniamino Galvani2fc2ef52016-08-16 11:49:50 +0200783 { .compatible = "amlogic,meson6-dwmac" },
Heiner Kallweit83fdbe42017-01-27 21:25:59 +0100784 { .compatible = "amlogic,meson-gx-dwmac" },
Michael Kurz812962b2017-01-22 16:04:27 +0100785 { .compatible = "st,stm32-dwmac" },
Simon Glass90e627b2015-04-05 16:07:41 -0600786 { }
787};
788
Marek Vasut7e7e6172015-07-25 18:42:34 +0200789U_BOOT_DRIVER(eth_designware) = {
Simon Glass90e627b2015-04-05 16:07:41 -0600790 .name = "eth_designware",
791 .id = UCLASS_ETH,
792 .of_match = designware_eth_ids,
793 .ofdata_to_platdata = designware_eth_ofdata_to_platdata,
Bin Menged89bd72015-09-11 03:24:35 -0700794 .bind = designware_eth_bind,
Simon Glass90e627b2015-04-05 16:07:41 -0600795 .probe = designware_eth_probe,
Bin Mengf0f02772015-10-07 21:32:38 -0700796 .remove = designware_eth_remove,
Simon Glass90e627b2015-04-05 16:07:41 -0600797 .ops = &designware_eth_ops,
798 .priv_auto_alloc_size = sizeof(struct dw_eth_dev),
Sjoerd Simons6eb44622016-02-28 22:24:55 +0100799 .platdata_auto_alloc_size = sizeof(struct dw_eth_pdata),
Simon Glass90e627b2015-04-05 16:07:41 -0600800 .flags = DM_FLAG_ALLOC_PRIV_DMA,
801};
Bin Menged89bd72015-09-11 03:24:35 -0700802
803static struct pci_device_id supported[] = {
804 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) },
805 { }
806};
807
808U_BOOT_PCI_DEVICE(eth_designware, supported);
Simon Glass90e627b2015-04-05 16:07:41 -0600809#endif