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