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