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