Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Faraday FTGMAC100 Ethernet |
| 4 | * |
| 5 | * (C) Copyright 2009 Faraday Technology |
| 6 | * Po-Yu Chuang <ratbert@faraday-tech.com> |
| 7 | * |
| 8 | * (C) Copyright 2010 Andes Technology |
| 9 | * Macpaul Lin <macpaul@andestech.com> |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 10 | * |
| 11 | * Copyright (C) 2018, IBM Corporation. |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 12 | */ |
| 13 | |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 14 | #include <clk.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 15 | #include <cpu_func.h> |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 16 | #include <dm.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 17 | #include <malloc.h> |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 18 | #include <miiphy.h> |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 19 | #include <net.h> |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 20 | #include <wait_bit.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 21 | #include <dm/device_compat.h> |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 22 | #include <linux/io.h> |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 23 | #include <linux/iopoll.h> |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 24 | |
| 25 | #include "ftgmac100.h" |
| 26 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 27 | /* Min frame ethernet frame size without FCS */ |
| 28 | #define ETH_ZLEN 60 |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 29 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 30 | /* Receive Buffer Size Register - HW default is 0x640 */ |
| 31 | #define FTGMAC100_RBSR_DEFAULT 0x640 |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 32 | |
| 33 | /* PKTBUFSTX/PKTBUFSRX must both be power of 2 */ |
| 34 | #define PKTBUFSTX 4 /* must be power of 2 */ |
| 35 | |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 36 | /* Timeout for transmit */ |
| 37 | #define FTGMAC100_TX_TIMEOUT_MS 1000 |
| 38 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 39 | /* Timeout for a mdio read/write operation */ |
| 40 | #define FTGMAC100_MDIO_TIMEOUT_USEC 10000 |
| 41 | |
| 42 | /* |
| 43 | * MDC clock cycle threshold |
| 44 | * |
| 45 | * 20us * 100 = 2ms > (1 / 2.5Mhz) * 0x34 |
| 46 | */ |
| 47 | #define MDC_CYCTHR 0x34 |
| 48 | |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 49 | /* |
| 50 | * ftgmac100 model variants |
| 51 | */ |
| 52 | enum ftgmac100_model { |
| 53 | FTGMAC100_MODEL_FARADAY, |
| 54 | FTGMAC100_MODEL_ASPEED, |
| 55 | }; |
| 56 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 57 | /** |
| 58 | * struct ftgmac100_data - private data for the FTGMAC100 driver |
| 59 | * |
| 60 | * @iobase: The base address of the hardware registers |
| 61 | * @txdes: The array of transmit descriptors |
| 62 | * @rxdes: The array of receive descriptors |
| 63 | * @tx_index: Transmit descriptor index in @txdes |
| 64 | * @rx_index: Receive descriptor index in @rxdes |
| 65 | * @phy_addr: The PHY interface address to use |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 66 | * @phydev: The PHY device backing the MAC |
| 67 | * @bus: The mdio bus |
| 68 | * @phy_mode: The mode of the PHY interface (rgmii, rmii, ...) |
| 69 | * @max_speed: Maximum speed of Ethernet connection supported by MAC |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 70 | * @clks: The bulk of clocks assigned to the device in the DT |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 71 | * @rxdes0_edorr_mask: The bit number identifying the end of the RX ring buffer |
| 72 | * @txdes0_edotr_mask: The bit number identifying the end of the TX ring buffer |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 73 | */ |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 74 | struct ftgmac100_data { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 75 | struct ftgmac100 *iobase; |
| 76 | |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 77 | struct ftgmac100_txdes txdes[PKTBUFSTX] __aligned(ARCH_DMA_MINALIGN); |
| 78 | struct ftgmac100_rxdes rxdes[PKTBUFSRX] __aligned(ARCH_DMA_MINALIGN); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 79 | int tx_index; |
| 80 | int rx_index; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 81 | |
| 82 | u32 phy_addr; |
| 83 | struct phy_device *phydev; |
| 84 | struct mii_dev *bus; |
| 85 | u32 phy_mode; |
| 86 | u32 max_speed; |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 87 | |
| 88 | struct clk_bulk clks; |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 89 | |
| 90 | /* End of RX/TX ring buffer bits. Depend on model */ |
| 91 | u32 rxdes0_edorr_mask; |
| 92 | u32 txdes0_edotr_mask; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* |
| 96 | * struct mii_bus functions |
| 97 | */ |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 98 | static int ftgmac100_mdio_read(struct mii_dev *bus, int phy_addr, int dev_addr, |
| 99 | int reg_addr) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 100 | { |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 101 | struct ftgmac100_data *priv = bus->priv; |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 102 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 103 | int phycr; |
| 104 | int data; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 105 | int ret; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 106 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 107 | phycr = FTGMAC100_PHYCR_MDC_CYCTHR(MDC_CYCTHR) | |
| 108 | FTGMAC100_PHYCR_PHYAD(phy_addr) | |
| 109 | FTGMAC100_PHYCR_REGAD(reg_addr) | |
| 110 | FTGMAC100_PHYCR_MIIRD; |
| 111 | writel(phycr, &ftgmac100->phycr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 112 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 113 | ret = readl_poll_timeout(&ftgmac100->phycr, phycr, |
| 114 | !(phycr & FTGMAC100_PHYCR_MIIRD), |
| 115 | FTGMAC100_MDIO_TIMEOUT_USEC); |
| 116 | if (ret) { |
| 117 | pr_err("%s: mdio read failed (phy:%d reg:%x)\n", |
| 118 | priv->phydev->dev->name, phy_addr, reg_addr); |
| 119 | return ret; |
| 120 | } |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 121 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 122 | data = readl(&ftgmac100->phydata); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 123 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 124 | return FTGMAC100_PHYDATA_MIIRDATA(data); |
| 125 | } |
| 126 | |
| 127 | static int ftgmac100_mdio_write(struct mii_dev *bus, int phy_addr, int dev_addr, |
| 128 | int reg_addr, u16 value) |
| 129 | { |
| 130 | struct ftgmac100_data *priv = bus->priv; |
| 131 | struct ftgmac100 *ftgmac100 = priv->iobase; |
| 132 | int phycr; |
| 133 | int data; |
| 134 | int ret; |
| 135 | |
| 136 | phycr = FTGMAC100_PHYCR_MDC_CYCTHR(MDC_CYCTHR) | |
| 137 | FTGMAC100_PHYCR_PHYAD(phy_addr) | |
| 138 | FTGMAC100_PHYCR_REGAD(reg_addr) | |
| 139 | FTGMAC100_PHYCR_MIIWR; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 140 | data = FTGMAC100_PHYDATA_MIIWDATA(value); |
| 141 | |
| 142 | writel(data, &ftgmac100->phydata); |
| 143 | writel(phycr, &ftgmac100->phycr); |
| 144 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 145 | ret = readl_poll_timeout(&ftgmac100->phycr, phycr, |
| 146 | !(phycr & FTGMAC100_PHYCR_MIIWR), |
| 147 | FTGMAC100_MDIO_TIMEOUT_USEC); |
| 148 | if (ret) { |
| 149 | pr_err("%s: mdio write failed (phy:%d reg:%x)\n", |
| 150 | priv->phydev->dev->name, phy_addr, reg_addr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 151 | } |
| 152 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 153 | return ret; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 154 | } |
| 155 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 156 | static int ftgmac100_mdio_init(struct udevice *dev) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 157 | { |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 158 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 159 | struct mii_dev *bus; |
| 160 | int ret; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 161 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 162 | bus = mdio_alloc(); |
| 163 | if (!bus) |
| 164 | return -ENOMEM; |
| 165 | |
| 166 | bus->read = ftgmac100_mdio_read; |
| 167 | bus->write = ftgmac100_mdio_write; |
| 168 | bus->priv = priv; |
| 169 | |
| 170 | ret = mdio_register_seq(bus, dev->seq); |
| 171 | if (ret) { |
| 172 | free(bus); |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | priv->bus = bus; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 181 | static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 182 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 183 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 184 | struct phy_device *phydev = priv->phydev; |
| 185 | u32 maccr; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 186 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 187 | if (!phydev->link) { |
| 188 | dev_err(phydev->dev, "No link\n"); |
| 189 | return -EREMOTEIO; |
| 190 | } |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 191 | |
| 192 | /* read MAC control register and clear related bits */ |
| 193 | maccr = readl(&ftgmac100->maccr) & |
| 194 | ~(FTGMAC100_MACCR_GIGA_MODE | |
| 195 | FTGMAC100_MACCR_FAST_MODE | |
| 196 | FTGMAC100_MACCR_FULLDUP); |
| 197 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 198 | if (phy_interface_is_rgmii(phydev) && phydev->speed == 1000) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 199 | maccr |= FTGMAC100_MACCR_GIGA_MODE; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 200 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 201 | if (phydev->speed == 100) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 202 | maccr |= FTGMAC100_MACCR_FAST_MODE; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 203 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 204 | if (phydev->duplex) |
| 205 | maccr |= FTGMAC100_MACCR_FULLDUP; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 206 | |
| 207 | /* update MII config into maccr */ |
| 208 | writel(maccr, &ftgmac100->maccr); |
| 209 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static int ftgmac100_phy_init(struct udevice *dev) |
| 214 | { |
| 215 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 216 | struct phy_device *phydev; |
| 217 | int ret; |
| 218 | |
| 219 | phydev = phy_connect(priv->bus, priv->phy_addr, dev, priv->phy_mode); |
| 220 | if (!phydev) |
| 221 | return -ENODEV; |
| 222 | |
| 223 | phydev->supported &= PHY_GBIT_FEATURES; |
| 224 | if (priv->max_speed) { |
| 225 | ret = phy_set_supported(phydev, priv->max_speed); |
| 226 | if (ret) |
| 227 | return ret; |
| 228 | } |
| 229 | phydev->advertising = phydev->supported; |
| 230 | priv->phydev = phydev; |
| 231 | phy_config(phydev); |
| 232 | |
| 233 | return 0; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Reset MAC |
| 238 | */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 239 | static void ftgmac100_reset(struct ftgmac100_data *priv) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 240 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 241 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 242 | |
| 243 | debug("%s()\n", __func__); |
| 244 | |
Cédric Le Goater | 591ffd9 | 2018-10-29 07:06:32 +0100 | [diff] [blame] | 245 | setbits_le32(&ftgmac100->maccr, FTGMAC100_MACCR_SW_RST); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 246 | |
| 247 | while (readl(&ftgmac100->maccr) & FTGMAC100_MACCR_SW_RST) |
| 248 | ; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Set MAC address |
| 253 | */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 254 | static int ftgmac100_set_mac(struct ftgmac100_data *priv, |
| 255 | const unsigned char *mac) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 256 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 257 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 258 | unsigned int maddr = mac[0] << 8 | mac[1]; |
| 259 | unsigned int laddr = mac[2] << 24 | mac[3] << 16 | mac[4] << 8 | mac[5]; |
| 260 | |
| 261 | debug("%s(%x %x)\n", __func__, maddr, laddr); |
| 262 | |
| 263 | writel(maddr, &ftgmac100->mac_madr); |
| 264 | writel(laddr, &ftgmac100->mac_ladr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 265 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 266 | return 0; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | * disable transmitter, receiver |
| 271 | */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 272 | static void ftgmac100_stop(struct udevice *dev) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 273 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 274 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 275 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 276 | |
| 277 | debug("%s()\n", __func__); |
| 278 | |
| 279 | writel(0, &ftgmac100->maccr); |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 280 | |
| 281 | phy_shutdown(priv->phydev); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 282 | } |
| 283 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 284 | static int ftgmac100_start(struct udevice *dev) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 285 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 286 | struct eth_pdata *plat = dev_get_platdata(dev); |
| 287 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 288 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 289 | struct phy_device *phydev = priv->phydev; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 290 | unsigned int maccr; |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 291 | ulong start, end; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 292 | int ret; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 293 | int i; |
| 294 | |
| 295 | debug("%s()\n", __func__); |
| 296 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 297 | ftgmac100_reset(priv); |
| 298 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 299 | /* set the ethernet address */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 300 | ftgmac100_set_mac(priv, plat->enetaddr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 301 | |
| 302 | /* disable all interrupts */ |
| 303 | writel(0, &ftgmac100->ier); |
| 304 | |
| 305 | /* initialize descriptors */ |
| 306 | priv->tx_index = 0; |
| 307 | priv->rx_index = 0; |
| 308 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 309 | for (i = 0; i < PKTBUFSTX; i++) { |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 310 | priv->txdes[i].txdes3 = 0; |
| 311 | priv->txdes[i].txdes0 = 0; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 312 | } |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 313 | priv->txdes[PKTBUFSTX - 1].txdes0 = priv->txdes0_edotr_mask; |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 314 | |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 315 | start = ((ulong)&priv->txdes[0]) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 316 | end = start + roundup(sizeof(priv->txdes), ARCH_DMA_MINALIGN); |
| 317 | flush_dcache_range(start, end); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 318 | |
| 319 | for (i = 0; i < PKTBUFSRX; i++) { |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 320 | priv->rxdes[i].rxdes3 = (unsigned int)net_rx_packets[i]; |
| 321 | priv->rxdes[i].rxdes0 = 0; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 322 | } |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 323 | priv->rxdes[PKTBUFSRX - 1].rxdes0 = priv->rxdes0_edorr_mask; |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 324 | |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 325 | start = ((ulong)&priv->rxdes[0]) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 326 | end = start + roundup(sizeof(priv->rxdes), ARCH_DMA_MINALIGN); |
| 327 | flush_dcache_range(start, end); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 328 | |
| 329 | /* transmit ring */ |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 330 | writel((u32)priv->txdes, &ftgmac100->txr_badr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 331 | |
| 332 | /* receive ring */ |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 333 | writel((u32)priv->rxdes, &ftgmac100->rxr_badr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 334 | |
| 335 | /* poll receive descriptor automatically */ |
| 336 | writel(FTGMAC100_APTC_RXPOLL_CNT(1), &ftgmac100->aptc); |
| 337 | |
| 338 | /* config receive buffer size register */ |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 339 | writel(FTGMAC100_RBSR_SIZE(FTGMAC100_RBSR_DEFAULT), &ftgmac100->rbsr); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 340 | |
| 341 | /* enable transmitter, receiver */ |
| 342 | maccr = FTGMAC100_MACCR_TXMAC_EN | |
| 343 | FTGMAC100_MACCR_RXMAC_EN | |
| 344 | FTGMAC100_MACCR_TXDMA_EN | |
| 345 | FTGMAC100_MACCR_RXDMA_EN | |
| 346 | FTGMAC100_MACCR_CRC_APD | |
| 347 | FTGMAC100_MACCR_FULLDUP | |
| 348 | FTGMAC100_MACCR_RX_RUNT | |
| 349 | FTGMAC100_MACCR_RX_BROADPKT; |
| 350 | |
| 351 | writel(maccr, &ftgmac100->maccr); |
| 352 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 353 | ret = phy_startup(phydev); |
| 354 | if (ret) { |
| 355 | dev_err(phydev->dev, "Could not start PHY\n"); |
| 356 | return ret; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 357 | } |
| 358 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 359 | ret = ftgmac100_phy_adjust_link(priv); |
| 360 | if (ret) { |
| 361 | dev_err(phydev->dev, "Could not adjust link\n"); |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | printf("%s: link up, %d Mbps %s-duplex mac:%pM\n", phydev->dev->name, |
| 366 | phydev->speed, phydev->duplex ? "full" : "half", plat->enetaddr); |
| 367 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 368 | return 0; |
| 369 | } |
| 370 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 371 | static int ftgmac100_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 372 | { |
| 373 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 374 | struct ftgmac100_rxdes *curr_des = &priv->rxdes[priv->rx_index]; |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 375 | ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 376 | ulong des_end = des_start + |
| 377 | roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN); |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 378 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 379 | /* Release buffer to DMA and flush descriptor */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 380 | curr_des->rxdes0 &= ~FTGMAC100_RXDES0_RXPKT_RDY; |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 381 | flush_dcache_range(des_start, des_end); |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 382 | |
| 383 | /* Move to next descriptor */ |
| 384 | priv->rx_index = (priv->rx_index + 1) % PKTBUFSRX; |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 389 | /* |
| 390 | * Get a data block via Ethernet |
| 391 | */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 392 | static int ftgmac100_recv(struct udevice *dev, int flags, uchar **packetp) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 393 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 394 | struct ftgmac100_data *priv = dev_get_priv(dev); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 395 | struct ftgmac100_rxdes *curr_des = &priv->rxdes[priv->rx_index]; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 396 | unsigned short rxlen; |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 397 | ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 398 | ulong des_end = des_start + |
| 399 | roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN); |
| 400 | ulong data_start = curr_des->rxdes3; |
| 401 | ulong data_end; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 402 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 403 | invalidate_dcache_range(des_start, des_end); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 404 | |
| 405 | if (!(curr_des->rxdes0 & FTGMAC100_RXDES0_RXPKT_RDY)) |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 406 | return -EAGAIN; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 407 | |
| 408 | if (curr_des->rxdes0 & (FTGMAC100_RXDES0_RX_ERR | |
| 409 | FTGMAC100_RXDES0_CRC_ERR | |
| 410 | FTGMAC100_RXDES0_FTL | |
| 411 | FTGMAC100_RXDES0_RUNT | |
| 412 | FTGMAC100_RXDES0_RX_ODD_NB)) { |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 413 | return -EAGAIN; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | rxlen = FTGMAC100_RXDES0_VDBC(curr_des->rxdes0); |
| 417 | |
| 418 | debug("%s(): RX buffer %d, %x received\n", |
| 419 | __func__, priv->rx_index, rxlen); |
| 420 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 421 | /* Invalidate received data */ |
| 422 | data_end = data_start + roundup(rxlen, ARCH_DMA_MINALIGN); |
| 423 | invalidate_dcache_range(data_start, data_end); |
| 424 | *packetp = (uchar *)data_start; |
Kuo-Jung Su | a8f9cd1 | 2013-05-07 14:33:51 +0800 | [diff] [blame] | 425 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 426 | return rxlen; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 427 | } |
| 428 | |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 429 | static u32 ftgmac100_read_txdesc(const void *desc) |
| 430 | { |
| 431 | const struct ftgmac100_txdes *txdes = desc; |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 432 | ulong des_start = ((ulong)txdes) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 433 | ulong des_end = des_start + roundup(sizeof(*txdes), ARCH_DMA_MINALIGN); |
| 434 | |
| 435 | invalidate_dcache_range(des_start, des_end); |
| 436 | |
| 437 | return txdes->txdes0; |
| 438 | } |
| 439 | |
| 440 | BUILD_WAIT_FOR_BIT(ftgmac100_txdone, u32, ftgmac100_read_txdesc) |
| 441 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 442 | /* |
| 443 | * Send a data block via Ethernet |
| 444 | */ |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 445 | static int ftgmac100_send(struct udevice *dev, void *packet, int length) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 446 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 447 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 448 | struct ftgmac100 *ftgmac100 = priv->iobase; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 449 | struct ftgmac100_txdes *curr_des = &priv->txdes[priv->tx_index]; |
Cédric Le Goater | 08b3e90 | 2019-11-28 13:37:04 +0100 | [diff] [blame] | 450 | ulong des_start = ((ulong)curr_des) & ~(ARCH_DMA_MINALIGN - 1); |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 451 | ulong des_end = des_start + |
| 452 | roundup(sizeof(*curr_des), ARCH_DMA_MINALIGN); |
| 453 | ulong data_start; |
| 454 | ulong data_end; |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 455 | int rc; |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 456 | |
| 457 | invalidate_dcache_range(des_start, des_end); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 458 | |
| 459 | if (curr_des->txdes0 & FTGMAC100_TXDES0_TXDMA_OWN) { |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 460 | dev_err(dev, "no TX descriptor available\n"); |
| 461 | return -EPERM; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | debug("%s(%x, %x)\n", __func__, (int)packet, length); |
| 465 | |
| 466 | length = (length < ETH_ZLEN) ? ETH_ZLEN : length; |
| 467 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 468 | curr_des->txdes3 = (unsigned int)packet; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 469 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 470 | /* Flush data to be sent */ |
| 471 | data_start = curr_des->txdes3; |
| 472 | data_end = data_start + roundup(length, ARCH_DMA_MINALIGN); |
| 473 | flush_dcache_range(data_start, data_end); |
| 474 | |
| 475 | /* Only one segment on TXBUF */ |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 476 | curr_des->txdes0 &= priv->txdes0_edotr_mask; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 477 | curr_des->txdes0 |= FTGMAC100_TXDES0_FTS | |
| 478 | FTGMAC100_TXDES0_LTS | |
| 479 | FTGMAC100_TXDES0_TXBUF_SIZE(length) | |
| 480 | FTGMAC100_TXDES0_TXDMA_OWN ; |
| 481 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 482 | /* Flush modified buffer descriptor */ |
| 483 | flush_dcache_range(des_start, des_end); |
| 484 | |
| 485 | /* Start transmit */ |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 486 | writel(1, &ftgmac100->txpd); |
| 487 | |
Cédric Le Goater | d0e0b84 | 2018-10-29 07:06:35 +0100 | [diff] [blame] | 488 | rc = wait_for_bit_ftgmac100_txdone(curr_des, |
| 489 | FTGMAC100_TXDES0_TXDMA_OWN, false, |
| 490 | FTGMAC100_TX_TIMEOUT_MS, true); |
| 491 | if (rc) |
| 492 | return rc; |
| 493 | |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 494 | debug("%s(): packet sent\n", __func__); |
| 495 | |
Cédric Le Goater | e766849 | 2018-10-29 07:06:34 +0100 | [diff] [blame] | 496 | /* Move to next descriptor */ |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 497 | priv->tx_index = (priv->tx_index + 1) % PKTBUFSTX; |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 502 | static int ftgmac100_write_hwaddr(struct udevice *dev) |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 503 | { |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 504 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 505 | struct ftgmac100_data *priv = dev_get_priv(dev); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 506 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 507 | return ftgmac100_set_mac(priv, pdata->enetaddr); |
| 508 | } |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 509 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 510 | static int ftgmac100_ofdata_to_platdata(struct udevice *dev) |
| 511 | { |
| 512 | struct eth_pdata *pdata = dev_get_platdata(dev); |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 513 | struct ftgmac100_data *priv = dev_get_priv(dev); |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 514 | const char *phy_mode; |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 515 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 516 | pdata->iobase = devfdt_get_addr(dev); |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 517 | pdata->phy_interface = -1; |
| 518 | phy_mode = dev_read_string(dev, "phy-mode"); |
| 519 | if (phy_mode) |
| 520 | pdata->phy_interface = phy_get_interface_by_name(phy_mode); |
| 521 | if (pdata->phy_interface == -1) { |
| 522 | dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
| 526 | pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
| 527 | |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 528 | if (dev_get_driver_data(dev) == FTGMAC100_MODEL_ASPEED) { |
| 529 | priv->rxdes0_edorr_mask = BIT(30); |
| 530 | priv->txdes0_edotr_mask = BIT(30); |
| 531 | } else { |
| 532 | priv->rxdes0_edorr_mask = BIT(15); |
| 533 | priv->txdes0_edotr_mask = BIT(15); |
| 534 | } |
| 535 | |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 536 | return clk_get_bulk(dev, &priv->clks); |
Macpaul Lin | b3dbf4a5 | 2010-12-21 16:59:46 +0800 | [diff] [blame] | 537 | } |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 538 | |
| 539 | static int ftgmac100_probe(struct udevice *dev) |
| 540 | { |
| 541 | struct eth_pdata *pdata = dev_get_platdata(dev); |
| 542 | struct ftgmac100_data *priv = dev_get_priv(dev); |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 543 | int ret; |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 544 | |
| 545 | priv->iobase = (struct ftgmac100 *)pdata->iobase; |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 546 | priv->phy_mode = pdata->phy_interface; |
| 547 | priv->max_speed = pdata->max_speed; |
| 548 | priv->phy_addr = 0; |
| 549 | |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 550 | ret = clk_enable_bulk(&priv->clks); |
| 551 | if (ret) |
| 552 | goto out; |
| 553 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 554 | ret = ftgmac100_mdio_init(dev); |
| 555 | if (ret) { |
| 556 | dev_err(dev, "Failed to initialize mdiobus: %d\n", ret); |
| 557 | goto out; |
| 558 | } |
| 559 | |
| 560 | ret = ftgmac100_phy_init(dev); |
| 561 | if (ret) { |
| 562 | dev_err(dev, "Failed to initialize PHY: %d\n", ret); |
| 563 | goto out; |
| 564 | } |
| 565 | |
| 566 | out: |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 567 | if (ret) |
| 568 | clk_release_bulk(&priv->clks); |
| 569 | |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 570 | return ret; |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static int ftgmac100_remove(struct udevice *dev) |
| 574 | { |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 575 | struct ftgmac100_data *priv = dev_get_priv(dev); |
| 576 | |
| 577 | free(priv->phydev); |
| 578 | mdio_unregister(priv->bus); |
| 579 | mdio_free(priv->bus); |
Cédric Le Goater | 1c0c61e | 2018-10-29 07:06:36 +0100 | [diff] [blame] | 580 | clk_release_bulk(&priv->clks); |
Cédric Le Goater | 538e75d | 2018-10-29 07:06:33 +0100 | [diff] [blame] | 581 | |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static const struct eth_ops ftgmac100_ops = { |
| 586 | .start = ftgmac100_start, |
| 587 | .send = ftgmac100_send, |
| 588 | .recv = ftgmac100_recv, |
| 589 | .stop = ftgmac100_stop, |
| 590 | .free_pkt = ftgmac100_free_pkt, |
| 591 | .write_hwaddr = ftgmac100_write_hwaddr, |
| 592 | }; |
| 593 | |
| 594 | static const struct udevice_id ftgmac100_ids[] = { |
Cédric Le Goater | e6ddacc | 2018-10-29 07:06:38 +0100 | [diff] [blame] | 595 | { .compatible = "faraday,ftgmac100", .data = FTGMAC100_MODEL_FARADAY }, |
| 596 | { .compatible = "aspeed,ast2500-mac", .data = FTGMAC100_MODEL_ASPEED }, |
Cédric Le Goater | f95de0b | 2018-10-29 07:06:31 +0100 | [diff] [blame] | 597 | { } |
| 598 | }; |
| 599 | |
| 600 | U_BOOT_DRIVER(ftgmac100) = { |
| 601 | .name = "ftgmac100", |
| 602 | .id = UCLASS_ETH, |
| 603 | .of_match = ftgmac100_ids, |
| 604 | .ofdata_to_platdata = ftgmac100_ofdata_to_platdata, |
| 605 | .probe = ftgmac100_probe, |
| 606 | .remove = ftgmac100_remove, |
| 607 | .ops = &ftgmac100_ops, |
| 608 | .priv_auto_alloc_size = sizeof(struct ftgmac100_data), |
| 609 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 610 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 611 | }; |