Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 2 | /* |
| 3 | * drivers/net/ravb.c |
| 4 | * This file is driver for Renesas Ethernet AVB. |
| 5 | * |
| 6 | * Copyright (C) 2015-2017 Renesas Electronics Corporation |
| 7 | * |
| 8 | * Based on the SuperH Ethernet driver. |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 11 | #include <clk.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 12 | #include <cpu_func.h> |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 13 | #include <dm.h> |
| 14 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 16 | #include <miiphy.h> |
| 17 | #include <malloc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <asm/cache.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 21 | #include <linux/mii.h> |
| 22 | #include <wait_bit.h> |
| 23 | #include <asm/io.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 24 | #include <asm/global_data.h> |
Marek Vasut | 58f49d6 | 2017-09-15 21:11:15 +0200 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 26 | #include <reset.h> |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 27 | |
| 28 | /* Registers */ |
| 29 | #define RAVB_REG_CCC 0x000 |
| 30 | #define RAVB_REG_DBAT 0x004 |
| 31 | #define RAVB_REG_CSR 0x00C |
| 32 | #define RAVB_REG_APSR 0x08C |
| 33 | #define RAVB_REG_RCR 0x090 |
| 34 | #define RAVB_REG_TGC 0x300 |
| 35 | #define RAVB_REG_TCCR 0x304 |
| 36 | #define RAVB_REG_RIC0 0x360 |
| 37 | #define RAVB_REG_RIC1 0x368 |
| 38 | #define RAVB_REG_RIC2 0x370 |
| 39 | #define RAVB_REG_TIC 0x378 |
| 40 | #define RAVB_REG_ECMR 0x500 |
| 41 | #define RAVB_REG_RFLR 0x508 |
| 42 | #define RAVB_REG_ECSIPR 0x518 |
| 43 | #define RAVB_REG_PIR 0x520 |
| 44 | #define RAVB_REG_GECMR 0x5b0 |
| 45 | #define RAVB_REG_MAHR 0x5c0 |
| 46 | #define RAVB_REG_MALR 0x5c8 |
| 47 | |
| 48 | #define CCC_OPC_CONFIG BIT(0) |
| 49 | #define CCC_OPC_OPERATION BIT(1) |
| 50 | #define CCC_BOC BIT(20) |
| 51 | |
| 52 | #define CSR_OPS 0x0000000F |
| 53 | #define CSR_OPS_CONFIG BIT(1) |
| 54 | |
Adam Ford | 2541837 | 2022-02-25 14:32:52 -0600 | [diff] [blame] | 55 | #define APSR_RDM BIT(13) |
Marek Vasut | 4185512 | 2019-04-13 11:42:34 +0200 | [diff] [blame] | 56 | #define APSR_TDM BIT(14) |
| 57 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 58 | #define TCCR_TSRQ0 BIT(0) |
| 59 | |
| 60 | #define RFLR_RFL_MIN 0x05EE |
| 61 | |
| 62 | #define PIR_MDI BIT(3) |
| 63 | #define PIR_MDO BIT(2) |
| 64 | #define PIR_MMD BIT(1) |
| 65 | #define PIR_MDC BIT(0) |
| 66 | |
| 67 | #define ECMR_TRCCM BIT(26) |
| 68 | #define ECMR_RZPF BIT(20) |
| 69 | #define ECMR_PFR BIT(18) |
| 70 | #define ECMR_RXF BIT(17) |
| 71 | #define ECMR_RE BIT(6) |
| 72 | #define ECMR_TE BIT(5) |
| 73 | #define ECMR_DM BIT(1) |
| 74 | #define ECMR_CHG_DM (ECMR_TRCCM | ECMR_RZPF | ECMR_PFR | ECMR_RXF) |
| 75 | |
| 76 | /* DMA Descriptors */ |
| 77 | #define RAVB_NUM_BASE_DESC 16 |
| 78 | #define RAVB_NUM_TX_DESC 8 |
| 79 | #define RAVB_NUM_RX_DESC 8 |
| 80 | |
| 81 | #define RAVB_TX_QUEUE_OFFSET 0 |
| 82 | #define RAVB_RX_QUEUE_OFFSET 4 |
| 83 | |
| 84 | #define RAVB_DESC_DT(n) ((n) << 28) |
| 85 | #define RAVB_DESC_DT_FSINGLE RAVB_DESC_DT(0x7) |
| 86 | #define RAVB_DESC_DT_LINKFIX RAVB_DESC_DT(0x9) |
| 87 | #define RAVB_DESC_DT_EOS RAVB_DESC_DT(0xa) |
| 88 | #define RAVB_DESC_DT_FEMPTY RAVB_DESC_DT(0xc) |
| 89 | #define RAVB_DESC_DT_EEMPTY RAVB_DESC_DT(0x3) |
| 90 | #define RAVB_DESC_DT_MASK RAVB_DESC_DT(0xf) |
| 91 | |
| 92 | #define RAVB_DESC_DS(n) (((n) & 0xfff) << 0) |
| 93 | #define RAVB_DESC_DS_MASK 0xfff |
| 94 | |
| 95 | #define RAVB_RX_DESC_MSC_MC BIT(23) |
| 96 | #define RAVB_RX_DESC_MSC_CEEF BIT(22) |
| 97 | #define RAVB_RX_DESC_MSC_CRL BIT(21) |
| 98 | #define RAVB_RX_DESC_MSC_FRE BIT(20) |
| 99 | #define RAVB_RX_DESC_MSC_RTLF BIT(19) |
| 100 | #define RAVB_RX_DESC_MSC_RTSF BIT(18) |
| 101 | #define RAVB_RX_DESC_MSC_RFE BIT(17) |
| 102 | #define RAVB_RX_DESC_MSC_CRC BIT(16) |
| 103 | #define RAVB_RX_DESC_MSC_MASK (0xff << 16) |
| 104 | |
| 105 | #define RAVB_RX_DESC_MSC_RX_ERR_MASK \ |
| 106 | (RAVB_RX_DESC_MSC_CRC | RAVB_RX_DESC_MSC_RFE | RAVB_RX_DESC_MSC_RTLF | \ |
| 107 | RAVB_RX_DESC_MSC_RTSF | RAVB_RX_DESC_MSC_CEEF) |
| 108 | |
| 109 | #define RAVB_TX_TIMEOUT_MS 1000 |
| 110 | |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 111 | struct ravb_device_ops { |
| 112 | void (*mac_init)(struct udevice *dev); |
| 113 | void (*dmac_init)(struct udevice *dev); |
| 114 | void (*config)(struct udevice *dev); |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 115 | bool has_reset; |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 118 | struct ravb_desc { |
| 119 | u32 ctrl; |
| 120 | u32 dptr; |
| 121 | }; |
| 122 | |
| 123 | struct ravb_rxdesc { |
| 124 | struct ravb_desc data; |
| 125 | struct ravb_desc link; |
| 126 | u8 __pad[48]; |
| 127 | u8 packet[PKTSIZE_ALIGN]; |
| 128 | }; |
| 129 | |
| 130 | struct ravb_priv { |
| 131 | struct ravb_desc base_desc[RAVB_NUM_BASE_DESC]; |
| 132 | struct ravb_desc tx_desc[RAVB_NUM_TX_DESC]; |
| 133 | struct ravb_rxdesc rx_desc[RAVB_NUM_RX_DESC]; |
| 134 | u32 rx_desc_idx; |
| 135 | u32 tx_desc_idx; |
| 136 | |
| 137 | struct phy_device *phydev; |
| 138 | struct mii_dev *bus; |
| 139 | void __iomem *iobase; |
Adam Ford | a4ba7ff | 2021-12-06 10:29:26 -0600 | [diff] [blame] | 140 | struct clk_bulk clks; |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 141 | struct reset_ctl rst; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static inline void ravb_flush_dcache(u32 addr, u32 len) |
| 145 | { |
| 146 | flush_dcache_range(addr, addr + len); |
| 147 | } |
| 148 | |
| 149 | static inline void ravb_invalidate_dcache(u32 addr, u32 len) |
| 150 | { |
| 151 | u32 start = addr & ~((uintptr_t)ARCH_DMA_MINALIGN - 1); |
| 152 | u32 end = roundup(addr + len, ARCH_DMA_MINALIGN); |
| 153 | invalidate_dcache_range(start, end); |
| 154 | } |
| 155 | |
| 156 | static int ravb_send(struct udevice *dev, void *packet, int len) |
| 157 | { |
| 158 | struct ravb_priv *eth = dev_get_priv(dev); |
| 159 | struct ravb_desc *desc = ð->tx_desc[eth->tx_desc_idx]; |
| 160 | unsigned int start; |
| 161 | |
| 162 | /* Update TX descriptor */ |
| 163 | ravb_flush_dcache((uintptr_t)packet, len); |
| 164 | memset(desc, 0x0, sizeof(*desc)); |
| 165 | desc->ctrl = RAVB_DESC_DT_FSINGLE | RAVB_DESC_DS(len); |
| 166 | desc->dptr = (uintptr_t)packet; |
| 167 | ravb_flush_dcache((uintptr_t)desc, sizeof(*desc)); |
| 168 | |
| 169 | /* Restart the transmitter if disabled */ |
| 170 | if (!(readl(eth->iobase + RAVB_REG_TCCR) & TCCR_TSRQ0)) |
| 171 | setbits_le32(eth->iobase + RAVB_REG_TCCR, TCCR_TSRQ0); |
| 172 | |
| 173 | /* Wait until packet is transmitted */ |
| 174 | start = get_timer(0); |
| 175 | while (get_timer(start) < RAVB_TX_TIMEOUT_MS) { |
| 176 | ravb_invalidate_dcache((uintptr_t)desc, sizeof(*desc)); |
| 177 | if ((desc->ctrl & RAVB_DESC_DT_MASK) != RAVB_DESC_DT_FSINGLE) |
| 178 | break; |
| 179 | udelay(10); |
| 180 | }; |
| 181 | |
| 182 | if (get_timer(start) >= RAVB_TX_TIMEOUT_MS) |
| 183 | return -ETIMEDOUT; |
| 184 | |
| 185 | eth->tx_desc_idx = (eth->tx_desc_idx + 1) % (RAVB_NUM_TX_DESC - 1); |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static int ravb_recv(struct udevice *dev, int flags, uchar **packetp) |
| 190 | { |
| 191 | struct ravb_priv *eth = dev_get_priv(dev); |
| 192 | struct ravb_rxdesc *desc = ð->rx_desc[eth->rx_desc_idx]; |
Marek Vasut | 45550c8 | 2025-04-20 18:35:33 +0200 | [diff] [blame] | 193 | int len = 0; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 194 | u8 *packet; |
| 195 | |
| 196 | /* Check if the rx descriptor is ready */ |
| 197 | ravb_invalidate_dcache((uintptr_t)desc, sizeof(*desc)); |
| 198 | if ((desc->data.ctrl & RAVB_DESC_DT_MASK) == RAVB_DESC_DT_FEMPTY) |
| 199 | return -EAGAIN; |
| 200 | |
| 201 | /* Check for errors */ |
Marek Vasut | 45550c8 | 2025-04-20 18:35:33 +0200 | [diff] [blame] | 202 | if (desc->data.ctrl & RAVB_RX_DESC_MSC_RX_ERR_MASK) |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 203 | desc->data.ctrl &= ~RAVB_RX_DESC_MSC_MASK; |
Marek Vasut | 45550c8 | 2025-04-20 18:35:33 +0200 | [diff] [blame] | 204 | else |
| 205 | len = desc->data.ctrl & RAVB_DESC_DS_MASK; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 206 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 207 | packet = (u8 *)(uintptr_t)desc->data.dptr; |
| 208 | ravb_invalidate_dcache((uintptr_t)packet, len); |
| 209 | |
| 210 | *packetp = packet; |
| 211 | return len; |
| 212 | } |
| 213 | |
| 214 | static int ravb_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 215 | { |
| 216 | struct ravb_priv *eth = dev_get_priv(dev); |
| 217 | struct ravb_rxdesc *desc = ð->rx_desc[eth->rx_desc_idx]; |
| 218 | |
| 219 | /* Make current descriptor available again */ |
| 220 | desc->data.ctrl = RAVB_DESC_DT_FEMPTY | RAVB_DESC_DS(PKTSIZE_ALIGN); |
| 221 | ravb_flush_dcache((uintptr_t)desc, sizeof(*desc)); |
| 222 | |
| 223 | /* Point to the next descriptor */ |
| 224 | eth->rx_desc_idx = (eth->rx_desc_idx + 1) % RAVB_NUM_RX_DESC; |
| 225 | desc = ð->rx_desc[eth->rx_desc_idx]; |
| 226 | ravb_invalidate_dcache((uintptr_t)desc, sizeof(*desc)); |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int ravb_reset(struct udevice *dev) |
| 232 | { |
| 233 | struct ravb_priv *eth = dev_get_priv(dev); |
| 234 | |
| 235 | /* Set config mode */ |
| 236 | writel(CCC_OPC_CONFIG, eth->iobase + RAVB_REG_CCC); |
| 237 | |
| 238 | /* Check the operating mode is changed to the config mode. */ |
Álvaro Fernández Rojas | 918de03 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 239 | return wait_for_bit_le32(eth->iobase + RAVB_REG_CSR, |
| 240 | CSR_OPS_CONFIG, true, 100, true); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static void ravb_base_desc_init(struct ravb_priv *eth) |
| 244 | { |
| 245 | const u32 desc_size = RAVB_NUM_BASE_DESC * sizeof(struct ravb_desc); |
| 246 | int i; |
| 247 | |
| 248 | /* Initialize all descriptors */ |
| 249 | memset(eth->base_desc, 0x0, desc_size); |
| 250 | |
| 251 | for (i = 0; i < RAVB_NUM_BASE_DESC; i++) |
| 252 | eth->base_desc[i].ctrl = RAVB_DESC_DT_EOS; |
| 253 | |
| 254 | ravb_flush_dcache((uintptr_t)eth->base_desc, desc_size); |
| 255 | |
| 256 | /* Register the descriptor base address table */ |
| 257 | writel((uintptr_t)eth->base_desc, eth->iobase + RAVB_REG_DBAT); |
| 258 | } |
| 259 | |
| 260 | static void ravb_tx_desc_init(struct ravb_priv *eth) |
| 261 | { |
| 262 | const u32 desc_size = RAVB_NUM_TX_DESC * sizeof(struct ravb_desc); |
| 263 | int i; |
| 264 | |
| 265 | /* Initialize all descriptors */ |
| 266 | memset(eth->tx_desc, 0x0, desc_size); |
| 267 | eth->tx_desc_idx = 0; |
| 268 | |
| 269 | for (i = 0; i < RAVB_NUM_TX_DESC; i++) |
| 270 | eth->tx_desc[i].ctrl = RAVB_DESC_DT_EEMPTY; |
| 271 | |
| 272 | /* Mark the end of the descriptors */ |
| 273 | eth->tx_desc[RAVB_NUM_TX_DESC - 1].ctrl = RAVB_DESC_DT_LINKFIX; |
| 274 | eth->tx_desc[RAVB_NUM_TX_DESC - 1].dptr = (uintptr_t)eth->tx_desc; |
| 275 | ravb_flush_dcache((uintptr_t)eth->tx_desc, desc_size); |
| 276 | |
| 277 | /* Point the controller to the TX descriptor list. */ |
| 278 | eth->base_desc[RAVB_TX_QUEUE_OFFSET].ctrl = RAVB_DESC_DT_LINKFIX; |
| 279 | eth->base_desc[RAVB_TX_QUEUE_OFFSET].dptr = (uintptr_t)eth->tx_desc; |
| 280 | ravb_flush_dcache((uintptr_t)ð->base_desc[RAVB_TX_QUEUE_OFFSET], |
| 281 | sizeof(struct ravb_desc)); |
| 282 | } |
| 283 | |
| 284 | static void ravb_rx_desc_init(struct ravb_priv *eth) |
| 285 | { |
| 286 | const u32 desc_size = RAVB_NUM_RX_DESC * sizeof(struct ravb_rxdesc); |
| 287 | int i; |
| 288 | |
| 289 | /* Initialize all descriptors */ |
| 290 | memset(eth->rx_desc, 0x0, desc_size); |
| 291 | eth->rx_desc_idx = 0; |
| 292 | |
| 293 | for (i = 0; i < RAVB_NUM_RX_DESC; i++) { |
| 294 | eth->rx_desc[i].data.ctrl = RAVB_DESC_DT_EEMPTY | |
| 295 | RAVB_DESC_DS(PKTSIZE_ALIGN); |
| 296 | eth->rx_desc[i].data.dptr = (uintptr_t)eth->rx_desc[i].packet; |
| 297 | |
| 298 | eth->rx_desc[i].link.ctrl = RAVB_DESC_DT_LINKFIX; |
| 299 | eth->rx_desc[i].link.dptr = (uintptr_t)ð->rx_desc[i + 1]; |
| 300 | } |
| 301 | |
| 302 | /* Mark the end of the descriptors */ |
| 303 | eth->rx_desc[RAVB_NUM_RX_DESC - 1].link.ctrl = RAVB_DESC_DT_LINKFIX; |
| 304 | eth->rx_desc[RAVB_NUM_RX_DESC - 1].link.dptr = (uintptr_t)eth->rx_desc; |
| 305 | ravb_flush_dcache((uintptr_t)eth->rx_desc, desc_size); |
| 306 | |
| 307 | /* Point the controller to the rx descriptor list */ |
| 308 | eth->base_desc[RAVB_RX_QUEUE_OFFSET].ctrl = RAVB_DESC_DT_LINKFIX; |
| 309 | eth->base_desc[RAVB_RX_QUEUE_OFFSET].dptr = (uintptr_t)eth->rx_desc; |
| 310 | ravb_flush_dcache((uintptr_t)ð->base_desc[RAVB_RX_QUEUE_OFFSET], |
| 311 | sizeof(struct ravb_desc)); |
| 312 | } |
| 313 | |
| 314 | static int ravb_phy_config(struct udevice *dev) |
| 315 | { |
| 316 | struct ravb_priv *eth = dev_get_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 317 | struct eth_pdata *pdata = dev_get_plat(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 318 | struct phy_device *phydev; |
Mikhail Lappo | 8d819f6 | 2023-02-28 00:04:11 +0100 | [diff] [blame] | 319 | int reg; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 320 | |
Mikhail Lappo | 8d819f6 | 2023-02-28 00:04:11 +0100 | [diff] [blame] | 321 | phydev = phy_connect(eth->bus, -1, dev, pdata->phy_interface); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 322 | if (!phydev) |
| 323 | return -ENODEV; |
| 324 | |
| 325 | eth->phydev = phydev; |
| 326 | |
Marek Vasut | 882294d | 2018-06-18 05:44:53 +0200 | [diff] [blame] | 327 | phydev->supported &= SUPPORTED_100baseT_Full | |
| 328 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | |
| 329 | SUPPORTED_TP | SUPPORTED_MII | SUPPORTED_Pause | |
| 330 | SUPPORTED_Asym_Pause; |
| 331 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 332 | if (pdata->max_speed != 1000) { |
Marek Vasut | 882294d | 2018-06-18 05:44:53 +0200 | [diff] [blame] | 333 | phydev->supported &= ~SUPPORTED_1000baseT_Full; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 334 | reg = phy_read(phydev, -1, MII_CTRL1000); |
| 335 | reg &= ~(BIT(9) | BIT(8)); |
| 336 | phy_write(phydev, -1, MII_CTRL1000, reg); |
| 337 | } |
| 338 | |
| 339 | phy_config(phydev); |
| 340 | |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | /* Set Mac address */ |
| 345 | static int ravb_write_hwaddr(struct udevice *dev) |
| 346 | { |
| 347 | struct ravb_priv *eth = dev_get_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 348 | struct eth_pdata *pdata = dev_get_plat(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 349 | unsigned char *mac = pdata->enetaddr; |
| 350 | |
| 351 | writel((mac[0] << 24) | (mac[1] << 16) | (mac[2] << 8) | mac[3], |
| 352 | eth->iobase + RAVB_REG_MAHR); |
| 353 | |
| 354 | writel((mac[4] << 8) | mac[5], eth->iobase + RAVB_REG_MALR); |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | /* E-MAC init function */ |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 360 | static void ravb_mac_init(struct udevice *dev) |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 361 | { |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 362 | struct ravb_device_ops *device_ops = |
| 363 | (struct ravb_device_ops *)dev_get_driver_data(dev); |
| 364 | struct ravb_priv *eth = dev_get_priv(dev); |
| 365 | |
| 366 | device_ops->mac_init(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 367 | |
Paul Barker | d813420 | 2025-03-04 20:07:08 +0000 | [diff] [blame] | 368 | /* |
| 369 | * Set receive frame length |
| 370 | * |
| 371 | * The length set here describes the frame from the destination address |
| 372 | * up to and including the CRC data. However only the frame data, |
| 373 | * excluding the CRC, are transferred to memory. To allow for the |
| 374 | * largest frames add the CRC length to the maximum Rx descriptor size. |
| 375 | */ |
| 376 | writel(RFLR_RFL_MIN + ETH_FCS_LEN, eth->iobase + RAVB_REG_RFLR); |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 377 | } |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 378 | |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 379 | static void ravb_mac_init_rcar(struct udevice *dev) |
| 380 | { |
| 381 | struct ravb_priv *eth = dev_get_priv(dev); |
| 382 | |
| 383 | /* Disable MAC Interrupt */ |
| 384 | writel(0, eth->iobase + RAVB_REG_ECSIPR); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* AVB-DMAC init function */ |
| 388 | static int ravb_dmac_init(struct udevice *dev) |
| 389 | { |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 390 | struct ravb_device_ops *device_ops = |
| 391 | (struct ravb_device_ops *)dev_get_driver_data(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 392 | struct ravb_priv *eth = dev_get_priv(dev); |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 393 | int ret; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 394 | |
| 395 | /* Set CONFIG mode */ |
| 396 | ret = ravb_reset(dev); |
| 397 | if (ret) |
| 398 | return ret; |
| 399 | |
| 400 | /* Disable all interrupts */ |
| 401 | writel(0, eth->iobase + RAVB_REG_RIC0); |
| 402 | writel(0, eth->iobase + RAVB_REG_RIC1); |
| 403 | writel(0, eth->iobase + RAVB_REG_RIC2); |
| 404 | writel(0, eth->iobase + RAVB_REG_TIC); |
| 405 | |
| 406 | /* Set little endian */ |
| 407 | clrbits_le32(eth->iobase + RAVB_REG_CCC, CCC_BOC); |
| 408 | |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 409 | device_ops->dmac_init(dev); |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static void ravb_dmac_init_rcar(struct udevice *dev) |
| 414 | { |
| 415 | struct ravb_priv *eth = dev_get_priv(dev); |
| 416 | struct eth_pdata *pdata = dev_get_plat(dev); |
| 417 | int mode = 0; |
| 418 | unsigned int delay; |
| 419 | bool explicit_delay = false; |
| 420 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 421 | /* AVB rx set */ |
| 422 | writel(0x18000001, eth->iobase + RAVB_REG_RCR); |
| 423 | |
| 424 | /* FIFO size set */ |
| 425 | writel(0x00222210, eth->iobase + RAVB_REG_TGC); |
| 426 | |
Marek Vasut | 4185512 | 2019-04-13 11:42:34 +0200 | [diff] [blame] | 427 | /* Delay CLK: 2ns (not applicable on R-Car E3/D3) */ |
Marek Vasut | f972661 | 2024-02-27 17:05:47 +0100 | [diff] [blame] | 428 | if ((renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77990) || |
| 429 | (renesas_get_cpu_type() == RENESAS_CPU_TYPE_R8A77995)) |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 430 | return; |
Marek Vasut | 4185512 | 2019-04-13 11:42:34 +0200 | [diff] [blame] | 431 | |
Adam Ford | 2541837 | 2022-02-25 14:32:52 -0600 | [diff] [blame] | 432 | if (!dev_read_u32(dev, "rx-internal-delay-ps", &delay)) { |
| 433 | /* Valid values are 0 and 1800, according to DT bindings */ |
| 434 | if (delay) { |
| 435 | mode |= APSR_RDM; |
| 436 | explicit_delay = true; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (!dev_read_u32(dev, "tx-internal-delay-ps", &delay)) { |
| 441 | /* Valid values are 0 and 2000, according to DT bindings */ |
| 442 | if (delay) { |
| 443 | mode |= APSR_TDM; |
| 444 | explicit_delay = true; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if (!explicit_delay) { |
| 449 | if (pdata->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 450 | pdata->phy_interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 451 | mode |= APSR_RDM; |
| 452 | |
| 453 | if (pdata->phy_interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 454 | pdata->phy_interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 455 | mode |= APSR_TDM; |
| 456 | } |
| 457 | |
| 458 | writel(mode, eth->iobase + RAVB_REG_APSR); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static int ravb_config(struct udevice *dev) |
| 462 | { |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 463 | struct ravb_device_ops *device_ops = |
| 464 | (struct ravb_device_ops *)dev_get_driver_data(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 465 | struct ravb_priv *eth = dev_get_priv(dev); |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 466 | struct phy_device *phy = eth->phydev; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 467 | int ret; |
| 468 | |
| 469 | /* Configure AVB-DMAC register */ |
| 470 | ravb_dmac_init(dev); |
| 471 | |
| 472 | /* Configure E-MAC registers */ |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 473 | ravb_mac_init(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 474 | ravb_write_hwaddr(dev); |
| 475 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 476 | ret = phy_startup(phy); |
| 477 | if (ret) |
| 478 | return ret; |
| 479 | |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 480 | device_ops->config(dev); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static void ravb_config_rcar(struct udevice *dev) |
| 485 | { |
| 486 | struct ravb_priv *eth = dev_get_priv(dev); |
| 487 | struct phy_device *phy = eth->phydev; |
| 488 | u32 mask = ECMR_CHG_DM | ECMR_RE | ECMR_TE; |
| 489 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 490 | /* Set the transfer speed */ |
| 491 | if (phy->speed == 100) |
| 492 | writel(0, eth->iobase + RAVB_REG_GECMR); |
| 493 | else if (phy->speed == 1000) |
| 494 | writel(1, eth->iobase + RAVB_REG_GECMR); |
| 495 | |
| 496 | /* Check if full duplex mode is supported by the phy */ |
| 497 | if (phy->duplex) |
| 498 | mask |= ECMR_DM; |
| 499 | |
| 500 | writel(mask, eth->iobase + RAVB_REG_ECMR); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Marek Vasut | 7457ce9 | 2018-01-19 23:58:32 +0100 | [diff] [blame] | 503 | static int ravb_start(struct udevice *dev) |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 504 | { |
| 505 | struct ravb_priv *eth = dev_get_priv(dev); |
| 506 | int ret; |
| 507 | |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 508 | ret = ravb_reset(dev); |
| 509 | if (ret) |
Marek Vasut | 597e007 | 2018-06-18 09:35:45 +0200 | [diff] [blame] | 510 | return ret; |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 511 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 512 | ravb_base_desc_init(eth); |
| 513 | ravb_tx_desc_init(eth); |
| 514 | ravb_rx_desc_init(eth); |
| 515 | |
| 516 | ret = ravb_config(dev); |
| 517 | if (ret) |
Marek Vasut | 597e007 | 2018-06-18 09:35:45 +0200 | [diff] [blame] | 518 | return ret; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 519 | |
| 520 | /* Setting the control will start the AVB-DMAC process. */ |
| 521 | writel(CCC_OPC_OPERATION, eth->iobase + RAVB_REG_CCC); |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | static void ravb_stop(struct udevice *dev) |
| 527 | { |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 528 | struct ravb_priv *eth = dev_get_priv(dev); |
| 529 | |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 530 | phy_shutdown(eth->phydev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 531 | ravb_reset(dev); |
| 532 | } |
| 533 | |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 534 | /* Bitbang MDIO access */ |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 535 | static int ravb_bb_mdio_active(struct mii_dev *miidev) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 536 | { |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 537 | struct ravb_priv *eth = miidev->priv; |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 538 | |
| 539 | setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 544 | static int ravb_bb_mdio_tristate(struct mii_dev *miidev) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 545 | { |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 546 | struct ravb_priv *eth = miidev->priv; |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 547 | |
| 548 | clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 553 | static int ravb_bb_set_mdio(struct mii_dev *miidev, int v) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 554 | { |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 555 | struct ravb_priv *eth = miidev->priv; |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 556 | |
| 557 | if (v) |
| 558 | setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); |
| 559 | else |
| 560 | clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 565 | static int ravb_bb_get_mdio(struct mii_dev *miidev, int *v) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 566 | { |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 567 | struct ravb_priv *eth = miidev->priv; |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 568 | |
| 569 | *v = (readl(eth->iobase + RAVB_REG_PIR) & PIR_MDI) >> 3; |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 574 | static int ravb_bb_set_mdc(struct mii_dev *miidev, int v) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 575 | { |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 576 | struct ravb_priv *eth = miidev->priv; |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 577 | |
| 578 | if (v) |
| 579 | setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); |
| 580 | else |
| 581 | clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 586 | static int ravb_bb_delay(struct mii_dev *miidev) |
Marek Vasut | 980a3c5 | 2025-02-22 21:33:14 +0100 | [diff] [blame] | 587 | { |
| 588 | udelay(10); |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
Marek Vasut | 3d5149c | 2025-03-02 02:24:42 +0100 | [diff] [blame] | 593 | static const struct bb_miiphy_bus_ops ravb_bb_miiphy_bus_ops = { |
| 594 | .mdio_active = ravb_bb_mdio_active, |
| 595 | .mdio_tristate = ravb_bb_mdio_tristate, |
| 596 | .set_mdio = ravb_bb_set_mdio, |
| 597 | .get_mdio = ravb_bb_get_mdio, |
| 598 | .set_mdc = ravb_bb_set_mdc, |
| 599 | .delay = ravb_bb_delay, |
| 600 | }; |
| 601 | |
Marek Vasut | 5814ed4 | 2025-03-02 02:24:43 +0100 | [diff] [blame] | 602 | static int ravb_bb_miiphy_read(struct mii_dev *miidev, int addr, |
| 603 | int devad, int reg) |
| 604 | { |
Marek Vasut | 65867d3 | 2025-03-02 02:24:44 +0100 | [diff] [blame] | 605 | return bb_miiphy_read(miidev, &ravb_bb_miiphy_bus_ops, |
| 606 | addr, devad, reg); |
Marek Vasut | 5814ed4 | 2025-03-02 02:24:43 +0100 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static int ravb_bb_miiphy_write(struct mii_dev *miidev, int addr, |
| 610 | int devad, int reg, u16 value) |
| 611 | { |
Marek Vasut | 65867d3 | 2025-03-02 02:24:44 +0100 | [diff] [blame] | 612 | return bb_miiphy_write(miidev, &ravb_bb_miiphy_bus_ops, |
| 613 | addr, devad, reg, value); |
Marek Vasut | 5814ed4 | 2025-03-02 02:24:43 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 616 | static int ravb_probe(struct udevice *dev) |
| 617 | { |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 618 | struct ravb_device_ops *device_ops = |
| 619 | (struct ravb_device_ops *)dev_get_driver_data(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 620 | struct eth_pdata *pdata = dev_get_plat(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 621 | struct ravb_priv *eth = dev_get_priv(dev); |
| 622 | struct mii_dev *mdiodev; |
| 623 | void __iomem *iobase; |
| 624 | int ret; |
| 625 | |
| 626 | iobase = map_physmem(pdata->iobase, 0x1000, MAP_NOCACHE); |
| 627 | eth->iobase = iobase; |
| 628 | |
Adam Ford | a4ba7ff | 2021-12-06 10:29:26 -0600 | [diff] [blame] | 629 | ret = clk_get_bulk(dev, ð->clks); |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 630 | if (ret < 0) |
Paul Barker | 433863a | 2025-03-04 20:07:09 +0000 | [diff] [blame] | 631 | goto err_clk_get; |
Marek Vasut | c9746c6 | 2017-07-21 23:20:35 +0200 | [diff] [blame] | 632 | |
Marek Vasut | 89b02fd | 2025-03-02 02:24:48 +0100 | [diff] [blame] | 633 | mdiodev = mdio_alloc(); |
| 634 | if (!mdiodev) { |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 635 | ret = -ENOMEM; |
| 636 | goto err_mdio_alloc; |
| 637 | } |
| 638 | |
Marek Vasut | 5814ed4 | 2025-03-02 02:24:43 +0100 | [diff] [blame] | 639 | mdiodev->read = ravb_bb_miiphy_read; |
| 640 | mdiodev->write = ravb_bb_miiphy_write; |
Marek Vasut | 183c10a | 2025-03-02 02:24:45 +0100 | [diff] [blame] | 641 | mdiodev->priv = eth; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 642 | snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name); |
| 643 | |
| 644 | ret = mdio_register(mdiodev); |
| 645 | if (ret < 0) |
| 646 | goto err_mdio_register; |
| 647 | |
Marek Vasut | 89b02fd | 2025-03-02 02:24:48 +0100 | [diff] [blame] | 648 | eth->bus = mdiodev; |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 649 | |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 650 | /* Bring up PHY */ |
Adam Ford | a4ba7ff | 2021-12-06 10:29:26 -0600 | [diff] [blame] | 651 | ret = clk_enable_bulk(ð->clks); |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 652 | if (ret) |
Paul Barker | 433863a | 2025-03-04 20:07:09 +0000 | [diff] [blame] | 653 | goto err_clk_enable; |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 654 | |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 655 | if (device_ops->has_reset) { |
| 656 | ret = reset_get_by_index(dev, 0, ð->rst); |
| 657 | if (ret < 0) |
| 658 | goto err_clk_enable; |
| 659 | |
| 660 | ret = reset_deassert(ð->rst); |
| 661 | if (ret < 0) |
| 662 | goto err_reset_deassert; |
| 663 | } |
| 664 | |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 665 | ret = ravb_reset(dev); |
| 666 | if (ret) |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 667 | goto err_ravb_reset; |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 668 | |
| 669 | ret = ravb_phy_config(dev); |
| 670 | if (ret) |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 671 | goto err_ravb_reset; |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 672 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 673 | return 0; |
| 674 | |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 675 | err_ravb_reset: |
| 676 | if (device_ops->has_reset) |
| 677 | reset_assert(ð->rst); |
| 678 | err_reset_deassert: |
| 679 | if (device_ops->has_reset) |
| 680 | reset_free(ð->rst); |
Paul Barker | 433863a | 2025-03-04 20:07:09 +0000 | [diff] [blame] | 681 | err_clk_enable: |
| 682 | mdio_unregister(mdiodev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 683 | err_mdio_register: |
Marek Vasut | 89b02fd | 2025-03-02 02:24:48 +0100 | [diff] [blame] | 684 | mdio_free(mdiodev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 685 | err_mdio_alloc: |
Paul Barker | 433863a | 2025-03-04 20:07:09 +0000 | [diff] [blame] | 686 | clk_release_bulk(ð->clks); |
| 687 | err_clk_get: |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 688 | unmap_physmem(eth->iobase, MAP_NOCACHE); |
| 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | static int ravb_remove(struct udevice *dev) |
| 693 | { |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 694 | struct ravb_device_ops *device_ops = |
| 695 | (struct ravb_device_ops *)dev_get_driver_data(dev); |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 696 | struct ravb_priv *eth = dev_get_priv(dev); |
| 697 | |
Paul Barker | 637bdaa | 2025-03-19 12:03:58 +0000 | [diff] [blame^] | 698 | if (device_ops->has_reset) { |
| 699 | reset_assert(ð->rst); |
| 700 | reset_free(ð->rst); |
| 701 | } |
Adam Ford | a4ba7ff | 2021-12-06 10:29:26 -0600 | [diff] [blame] | 702 | clk_release_bulk(ð->clks); |
Marek Vasut | 3364d7a | 2018-02-13 17:21:15 +0100 | [diff] [blame] | 703 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 704 | free(eth->phydev); |
| 705 | mdio_unregister(eth->bus); |
| 706 | mdio_free(eth->bus); |
| 707 | unmap_physmem(eth->iobase, MAP_NOCACHE); |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 712 | static const struct eth_ops ravb_ops = { |
| 713 | .start = ravb_start, |
| 714 | .send = ravb_send, |
| 715 | .recv = ravb_recv, |
| 716 | .free_pkt = ravb_free_pkt, |
| 717 | .stop = ravb_stop, |
| 718 | .write_hwaddr = ravb_write_hwaddr, |
| 719 | }; |
| 720 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 721 | int ravb_of_to_plat(struct udevice *dev) |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 722 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 723 | struct eth_pdata *pdata = dev_get_plat(dev); |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 724 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 725 | pdata->iobase = dev_read_addr(dev); |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 726 | |
| 727 | pdata->phy_interface = dev_read_phy_mode(dev); |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 728 | if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 729 | return -EINVAL; |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 730 | |
Paul Barker | 150f441 | 2024-11-20 09:49:39 +0000 | [diff] [blame] | 731 | pdata->max_speed = dev_read_u32_default(dev, "max-speed", 1000); |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 732 | |
Marek Behún | bc19477 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 733 | return 0; |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 734 | } |
| 735 | |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 736 | static const struct ravb_device_ops ravb_device_ops_rcar = { |
| 737 | .mac_init = ravb_mac_init_rcar, |
| 738 | .dmac_init = ravb_dmac_init_rcar, |
| 739 | .config = ravb_config_rcar, |
| 740 | }; |
| 741 | |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 742 | static const struct udevice_id ravb_ids[] = { |
Paul Barker | 110218d | 2025-03-19 12:03:57 +0000 | [diff] [blame] | 743 | { |
| 744 | .compatible = "renesas,etheravb-rcar-gen3", |
| 745 | .data = (ulong)&ravb_device_ops_rcar, |
| 746 | }, |
| 747 | { |
| 748 | .compatible = "renesas,etheravb-rcar-gen4", |
| 749 | .data = (ulong)&ravb_device_ops_rcar, |
| 750 | }, |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 751 | { } |
| 752 | }; |
| 753 | |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 754 | U_BOOT_DRIVER(eth_ravb) = { |
| 755 | .name = "ravb", |
| 756 | .id = UCLASS_ETH, |
Marek Vasut | 934fd3b | 2017-07-21 23:20:33 +0200 | [diff] [blame] | 757 | .of_match = ravb_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 758 | .of_to_plat = ravb_of_to_plat, |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 759 | .probe = ravb_probe, |
| 760 | .remove = ravb_remove, |
| 761 | .ops = &ravb_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 762 | .priv_auto = sizeof(struct ravb_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 763 | .plat_auto = sizeof(struct eth_pdata), |
Marek Vasut | 17714cb | 2017-05-13 15:54:28 +0200 | [diff] [blame] | 764 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 765 | }; |