1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2021 Waymo LLC
4 * Copyright (C) 2011 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2011 PetaLogix
6 * Copyright (C) 2010 Xilinx, Inc. All rights reserved.
16 #include <asm/global_data.h>
21 #include <linux/delay.h>
23 DECLARE_GLOBAL_DATA_PTR;
26 #define XAE_EMMC_LINKSPEED_MASK 0xC0000000 /* Link speed */
27 #define XAE_EMMC_LINKSPD_10 0x00000000 /* Link Speed mask for 10 Mbit */
28 #define XAE_EMMC_LINKSPD_100 0x40000000 /* Link Speed mask for 100 Mbit */
29 #define XAE_EMMC_LINKSPD_1000 0x80000000 /* Link Speed mask for 1000 Mbit */
31 /* Interrupt Status/Enable/Mask Registers bit definitions */
32 #define XAE_INT_RXRJECT_MASK 0x00000008 /* Rx frame rejected */
33 #define XAE_INT_MGTRDY_MASK 0x00000080 /* MGT clock Lock */
35 /* Receive Configuration Word 1 (RCW1) Register bit definitions */
36 #define XAE_RCW1_RX_MASK 0x10000000 /* Receiver enable */
38 /* Transmitter Configuration (TC) Register bit definitions */
39 #define XAE_TC_TX_MASK 0x10000000 /* Transmitter enable */
41 #define XAE_UAW1_UNICASTADDR_MASK 0x0000FFFF
43 /* MDIO Management Configuration (MC) Register bit definitions */
44 #define XAE_MDIO_MC_MDIOEN_MASK 0x00000040 /* MII management enable*/
46 /* MDIO Management Control Register (MCR) Register bit definitions */
47 #define XAE_MDIO_MCR_PHYAD_MASK 0x1F000000 /* Phy Address Mask */
48 #define XAE_MDIO_MCR_PHYAD_SHIFT 24 /* Phy Address Shift */
49 #define XAE_MDIO_MCR_REGAD_MASK 0x001F0000 /* Reg Address Mask */
50 #define XAE_MDIO_MCR_REGAD_SHIFT 16 /* Reg Address Shift */
51 #define XAE_MDIO_MCR_OP_READ_MASK 0x00008000 /* Op Code Read Mask */
52 #define XAE_MDIO_MCR_OP_WRITE_MASK 0x00004000 /* Op Code Write Mask */
53 #define XAE_MDIO_MCR_INITIATE_MASK 0x00000800 /* Ready Mask */
54 #define XAE_MDIO_MCR_READY_MASK 0x00000080 /* Ready Mask */
56 #define XAE_MDIO_DIV_DFT 29 /* Default MDIO clock divisor */
58 #define XAXIDMA_BD_STS_ACTUAL_LEN_MASK 0x007FFFFF /* Actual len */
61 /* Bitmasks of XAXIDMA_CR_OFFSET register */
62 #define XAXIDMA_CR_RUNSTOP_MASK 0x00000001 /* Start/stop DMA channel */
63 #define XAXIDMA_CR_RESET_MASK 0x00000004 /* Reset DMA engine */
65 /* Bitmasks of XAXIDMA_SR_OFFSET register */
66 #define XAXIDMA_HALTED_MASK 0x00000001 /* DMA channel halted */
68 /* Bitmask for interrupts */
69 #define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion intr */
70 #define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay interrupt */
71 #define XAXIDMA_IRQ_ALL_MASK 0x00007000 /* All interrupts */
73 /* Bitmasks of XAXIDMA_BD_CTRL_OFFSET register */
74 #define XAXIDMA_BD_CTRL_TXSOF_MASK 0x08000000 /* First tx packet */
75 #define XAXIDMA_BD_CTRL_TXEOF_MASK 0x04000000 /* Last tx packet */
77 /* Bitmasks for XXV Ethernet MAC */
78 #define XXV_TC_TX_MASK 0x00000001
79 #define XXV_TC_FCS_MASK 0x00000002
80 #define XXV_RCW1_RX_MASK 0x00000001
81 #define XXV_RCW1_FCS_MASK 0x00000002
84 #define XXV_MIN_PKT_SIZE 60
86 static u8 rxframe[PKTSIZE_ALIGN] __attribute((aligned(DMAALIGN)));
87 static u8 txminframe[XXV_MIN_PKT_SIZE] __attribute((aligned(DMAALIGN)));
94 /* Reflect dma offsets */
96 u32 control; /* DMACR */
97 u32 status; /* DMASR */
98 u32 current; /* CURDESC low 32 bit */
99 u32 current_hi; /* CURDESC high 32 bit */
100 u32 tail; /* TAILDESC low 32 bit */
101 u32 tail_hi; /* TAILDESC high 32 bit */
104 /* Platform data structures */
106 struct eth_pdata eth_pdata;
107 struct axidma_reg *dmatx;
108 struct axidma_reg *dmarx;
112 enum emac_variant mactype;
115 /* Private driver structures */
117 struct axidma_reg *dmatx;
118 struct axidma_reg *dmarx;
120 struct axi_regs *iobase;
121 phy_interface_t interface;
122 struct phy_device *phydev;
126 enum emac_variant mactype;
131 u32 next_desc; /* Next descriptor pointer */
133 u32 buf_addr; /* Buffer address */
137 u32 cntrl; /* Control */
138 u32 status; /* Status */
140 u32 app1; /* TX start << 16 | insert */
141 u32 app2; /* TX csum seed */
149 /* Static BDs - driver uses only one BD */
150 static struct axidma_bd tx_bd __attribute((aligned(DMAALIGN)));
151 static struct axidma_bd rx_bd __attribute((aligned(DMAALIGN)));
155 u32 is; /* 0xC: Interrupt status */
157 u32 ie; /* 0x14: Interrupt enable */
159 u32 rcw1; /* 0x404: Rx Configuration Word 1 */
160 u32 tc; /* 0x408: Tx Configuration */
162 u32 emmc; /* 0x410: EMAC mode configuration */
164 u32 mdio_mc; /* 0x500: MII Management Config */
165 u32 mdio_mcr; /* 0x504: MII Management Control */
166 u32 mdio_mwd; /* 0x508: MII Management Write Data */
167 u32 mdio_mrd; /* 0x50C: MII Management Read Data */
169 u32 uaw0; /* 0x700: Unicast address word 0 */
170 u32 uaw1; /* 0x704: Unicast address word 1 */
173 struct xxv_axi_regs {
174 u32 gt_reset; /* 0x0 */
176 u32 tc; /* 0xC: Tx Configuration */
178 u32 rcw1; /* 0x14: Rx Configuration Word 1 */
181 /* Use MII register 1 (MII status register) to detect PHY */
182 #define PHY_DETECT_REG 1
185 * Mask used to verify certain PHY features (or register contents)
186 * in the register above:
187 * 0x1000: 10Mbps full duplex support
188 * 0x0800: 10Mbps half duplex support
189 * 0x0008: Auto-negotiation support
191 #define PHY_DETECT_MASK 0x1808
193 static inline int mdio_wait(struct axi_regs *regs)
197 /* Wait till MDIO interface is ready to accept a new transaction. */
198 while (timeout && (!(readl(®s->mdio_mcr)
199 & XAE_MDIO_MCR_READY_MASK))) {
204 printf("%s: Timeout\n", __func__);
211 * axienet_dma_write - Memory mapped Axi DMA register Buffer Descriptor write.
212 * @bd: pointer to BD descriptor structure
213 * @desc: Address offset of DMA descriptors
215 * This function writes the value into the corresponding Axi DMA register.
217 static inline void axienet_dma_write(struct axidma_bd *bd, u32 *desc)
219 #if defined(CONFIG_PHYS_64BIT)
220 writeq((unsigned long)bd, desc);
222 writel((u32)bd, desc);
226 static u32 phyread(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
229 struct axi_regs *regs = priv->iobase;
235 mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) &
236 XAE_MDIO_MCR_PHYAD_MASK) |
237 ((registernum << XAE_MDIO_MCR_REGAD_SHIFT)
238 & XAE_MDIO_MCR_REGAD_MASK) |
239 XAE_MDIO_MCR_INITIATE_MASK |
240 XAE_MDIO_MCR_OP_READ_MASK;
242 writel(mdioctrlreg, ®s->mdio_mcr);
248 *val = readl(®s->mdio_mrd);
252 static u32 phywrite(struct axidma_priv *priv, u32 phyaddress, u32 registernum,
255 struct axi_regs *regs = priv->iobase;
261 mdioctrlreg = ((phyaddress << XAE_MDIO_MCR_PHYAD_SHIFT) &
262 XAE_MDIO_MCR_PHYAD_MASK) |
263 ((registernum << XAE_MDIO_MCR_REGAD_SHIFT)
264 & XAE_MDIO_MCR_REGAD_MASK) |
265 XAE_MDIO_MCR_INITIATE_MASK |
266 XAE_MDIO_MCR_OP_WRITE_MASK;
269 writel(data, ®s->mdio_mwd);
271 writel(mdioctrlreg, ®s->mdio_mcr);
279 static int axiemac_phy_init(struct udevice *dev)
284 struct axidma_priv *priv = dev_get_priv(dev);
285 struct axi_regs *regs = priv->iobase;
286 struct phy_device *phydev;
288 u32 supported = SUPPORTED_10baseT_Half |
289 SUPPORTED_10baseT_Full |
290 SUPPORTED_100baseT_Half |
291 SUPPORTED_100baseT_Full |
292 SUPPORTED_1000baseT_Half |
293 SUPPORTED_1000baseT_Full;
295 /* Set default MDIO divisor */
296 writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc);
298 if (priv->phyaddr == -1) {
299 /* Detect the PHY address */
300 for (i = 31; i >= 0; i--) {
301 ret = phyread(priv, i, PHY_DETECT_REG, &phyreg);
302 if (!ret && (phyreg != 0xFFFF) &&
303 ((phyreg & PHY_DETECT_MASK) == PHY_DETECT_MASK)) {
304 /* Found a valid PHY address */
306 debug("axiemac: Found valid phy address, %x\n",
313 /* Interface - look at tsec */
314 phydev = phy_connect(priv->bus, priv->phyaddr, dev, priv->interface);
316 phydev->supported &= supported;
317 phydev->advertising = phydev->supported;
318 priv->phydev = phydev;
319 if (priv->phy_of_handle)
320 priv->phydev->node = offset_to_ofnode(priv->phy_of_handle);
326 /* Setting axi emac and phy to proper setting */
327 static int setup_phy(struct udevice *dev)
330 u32 speed, emmc_reg, ret;
331 struct axidma_priv *priv = dev_get_priv(dev);
332 struct axi_regs *regs = priv->iobase;
333 struct phy_device *phydev = priv->phydev;
335 if (priv->interface == PHY_INTERFACE_MODE_SGMII) {
337 * In SGMII cases the isolate bit might set
338 * after DMA and ethernet resets and hence
339 * check and clear if set.
341 ret = phyread(priv, priv->phyaddr, MII_BMCR, &temp);
344 if (temp & BMCR_ISOLATE) {
345 temp &= ~BMCR_ISOLATE;
346 ret = phywrite(priv, priv->phyaddr, MII_BMCR, temp);
352 if (phy_startup(phydev)) {
353 printf("axiemac: could not initialize PHY %s\n",
358 printf("%s: No link.\n", phydev->dev->name);
362 switch (phydev->speed) {
364 speed = XAE_EMMC_LINKSPD_1000;
367 speed = XAE_EMMC_LINKSPD_100;
370 speed = XAE_EMMC_LINKSPD_10;
376 /* Setup the emac for the phy speed */
377 emmc_reg = readl(®s->emmc);
378 emmc_reg &= ~XAE_EMMC_LINKSPEED_MASK;
381 /* Write new speed setting out to Axi Ethernet */
382 writel(emmc_reg, ®s->emmc);
385 * Setting the operating speed of the MAC needs a delay. There
386 * doesn't seem to be register to poll, so please consider this
387 * during your application design.
394 /* STOP DMA transfers */
395 static void axiemac_stop(struct udevice *dev)
397 struct axidma_priv *priv = dev_get_priv(dev);
400 /* Stop the hardware */
401 temp = readl(&priv->dmatx->control);
402 temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
403 writel(temp, &priv->dmatx->control);
405 temp = readl(&priv->dmarx->control);
406 temp &= ~XAXIDMA_CR_RUNSTOP_MASK;
407 writel(temp, &priv->dmarx->control);
409 debug("axiemac: Halted\n");
412 static int xxv_axi_ethernet_init(struct axidma_priv *priv)
414 struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase;
416 writel(readl(®s->rcw1) | XXV_RCW1_FCS_MASK, ®s->rcw1);
417 writel(readl(®s->tc) | XXV_TC_FCS_MASK, ®s->tc);
418 writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc);
419 writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1);
424 static int axi_ethernet_init(struct axidma_priv *priv)
426 struct axi_regs *regs = priv->iobase;
430 * Check the status of the MgtRdy bit in the interrupt status
431 * registers. This must be done to allow the MGT clock to become stable
432 * for the Sgmii and 1000BaseX PHY interfaces. No other register reads
433 * will be valid until this bit is valid.
434 * The bit is always a 1 for all other PHY interfaces.
435 * Interrupt status and enable registers are not available in non
436 * processor mode and hence bypass in this mode
438 if (!priv->eth_hasnobuf) {
439 err = wait_for_bit_le32(®s->is, XAE_INT_MGTRDY_MASK,
442 printf("%s: Timeout\n", __func__);
447 * Stop the device and reset HW
450 writel(0, ®s->ie);
453 /* Disable the receiver */
454 writel(readl(®s->rcw1) & ~XAE_RCW1_RX_MASK, ®s->rcw1);
457 * Stopping the receiver in mid-packet causes a dropped packet
458 * indication from HW. Clear it.
460 if (!priv->eth_hasnobuf) {
461 /* Set the interrupt status register to clear the interrupt */
462 writel(XAE_INT_RXRJECT_MASK, ®s->is);
466 /* Set default MDIO divisor */
467 writel(XAE_MDIO_DIV_DFT | XAE_MDIO_MC_MDIOEN_MASK, ®s->mdio_mc);
469 debug("axiemac: InitHw done\n");
473 static int axiemac_write_hwaddr(struct udevice *dev)
475 struct eth_pdata *pdata = dev_get_plat(dev);
476 struct axidma_priv *priv = dev_get_priv(dev);
477 struct axi_regs *regs = priv->iobase;
479 if (priv->mactype != EMAC_1G)
482 /* Set the MAC address */
483 int val = ((pdata->enetaddr[3] << 24) | (pdata->enetaddr[2] << 16) |
484 (pdata->enetaddr[1] << 8) | (pdata->enetaddr[0]));
485 writel(val, ®s->uaw0);
487 val = (pdata->enetaddr[5] << 8) | pdata->enetaddr[4];
488 val |= readl(®s->uaw1) & ~XAE_UAW1_UNICASTADDR_MASK;
489 writel(val, ®s->uaw1);
493 /* Reset DMA engine */
494 static void axi_dma_init(struct axidma_priv *priv)
498 /* Reset the engine so the hardware starts from a known state */
499 writel(XAXIDMA_CR_RESET_MASK, &priv->dmatx->control);
500 writel(XAXIDMA_CR_RESET_MASK, &priv->dmarx->control);
502 /* At the initialization time, hardware should finish reset quickly */
504 /* Check transmit/receive channel */
505 /* Reset is done when the reset bit is low */
506 if (!((readl(&priv->dmatx->control) |
507 readl(&priv->dmarx->control))
508 & XAXIDMA_CR_RESET_MASK)) {
513 printf("%s: Timeout\n", __func__);
516 static int axiemac_start(struct udevice *dev)
518 struct axidma_priv *priv = dev_get_priv(dev);
521 debug("axiemac: Init started\n");
523 * Initialize AXIDMA engine. AXIDMA engine must be initialized before
524 * AxiEthernet. During AXIDMA engine initialization, AXIDMA hardware is
525 * reset, and since AXIDMA reset line is connected to AxiEthernet, this
526 * would ensure a reset of AxiEthernet.
530 /* Initialize AxiEthernet hardware. */
531 if (priv->mactype == EMAC_1G) {
532 if (axi_ethernet_init(priv))
535 if (xxv_axi_ethernet_init(priv))
539 /* Disable all RX interrupts before RxBD space setup */
540 temp = readl(&priv->dmarx->control);
541 temp &= ~XAXIDMA_IRQ_ALL_MASK;
542 writel(temp, &priv->dmarx->control);
544 /* Start DMA RX channel. Now it's ready to receive data.*/
545 axienet_dma_write(&rx_bd, &priv->dmarx->current);
548 memset(&rx_bd, 0, sizeof(rx_bd));
549 rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
550 rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
551 #if defined(CONFIG_PHYS_64BIT)
552 rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
553 rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
555 rx_bd.cntrl = sizeof(rxframe);
556 /* Flush the last BD so DMA core could see the updates */
557 flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
559 /* It is necessary to flush rxframe because if you don't do it
560 * then cache can contain uninitialized data */
561 flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
563 /* Start the hardware */
564 temp = readl(&priv->dmarx->control);
565 temp |= XAXIDMA_CR_RUNSTOP_MASK;
566 writel(temp, &priv->dmarx->control);
568 /* Rx BD is ready - start */
569 axienet_dma_write(&rx_bd, &priv->dmarx->tail);
571 if (priv->mactype == EMAC_1G) {
572 struct axi_regs *regs = priv->iobase;
574 writel(XAE_TC_TX_MASK, ®s->tc);
576 writel(XAE_RCW1_RX_MASK, ®s->rcw1);
579 if (!setup_phy(dev)) {
584 struct xxv_axi_regs *regs = (struct xxv_axi_regs *)priv->iobase;
586 writel(readl(®s->tc) | XXV_TC_TX_MASK, ®s->tc);
589 writel(readl(®s->rcw1) | XXV_RCW1_RX_MASK, ®s->rcw1);
592 debug("axiemac: Init complete\n");
596 static int axiemac_send(struct udevice *dev, void *ptr, int len)
598 struct axidma_priv *priv = dev_get_priv(dev);
601 if (len > PKTSIZE_ALIGN)
604 /* If size is less than min packet size, pad to min size */
605 if (priv->mactype == EMAC_10G_25G && len < XXV_MIN_PKT_SIZE) {
606 memset(txminframe, 0, XXV_MIN_PKT_SIZE);
607 memcpy(txminframe, ptr, len);
608 len = XXV_MIN_PKT_SIZE;
612 /* Flush packet to main memory to be trasfered by DMA */
613 flush_cache((phys_addr_t)ptr, len);
616 memset(&tx_bd, 0, sizeof(tx_bd));
617 /* At the end of the ring, link the last BD back to the top */
618 tx_bd.next_desc = lower_32_bits((unsigned long)&tx_bd);
619 tx_bd.buf_addr = lower_32_bits((unsigned long)ptr);
620 #if defined(CONFIG_PHYS_64BIT)
621 tx_bd.next_desc_msb = upper_32_bits((unsigned long)&tx_bd);
622 tx_bd.buf_addr_msb = upper_32_bits((unsigned long)ptr);
625 tx_bd.cntrl = len | XAXIDMA_BD_CTRL_TXSOF_MASK |
626 XAXIDMA_BD_CTRL_TXEOF_MASK;
628 /* Flush the last BD so DMA core could see the updates */
629 flush_cache((phys_addr_t)&tx_bd, sizeof(tx_bd));
631 if (readl(&priv->dmatx->status) & XAXIDMA_HALTED_MASK) {
633 axienet_dma_write(&tx_bd, &priv->dmatx->current);
634 /* Start the hardware */
635 temp = readl(&priv->dmatx->control);
636 temp |= XAXIDMA_CR_RUNSTOP_MASK;
637 writel(temp, &priv->dmatx->control);
641 axienet_dma_write(&tx_bd, &priv->dmatx->tail);
643 /* Wait for transmission to complete */
644 debug("axiemac: Waiting for tx to be done\n");
646 while (timeout && (!(readl(&priv->dmatx->status) &
647 (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))) {
652 printf("%s: Timeout\n", __func__);
656 debug("axiemac: Sending complete\n");
660 static int isrxready(struct axidma_priv *priv)
664 /* Read pending interrupts */
665 status = readl(&priv->dmarx->status);
667 /* Acknowledge pending interrupts */
668 writel(status & XAXIDMA_IRQ_ALL_MASK, &priv->dmarx->status);
671 * If Reception done interrupt is asserted, call RX call back function
672 * to handle the processed BDs and then raise the according flag.
674 if ((status & (XAXIDMA_IRQ_DELAY_MASK | XAXIDMA_IRQ_IOC_MASK)))
680 static int axiemac_recv(struct udevice *dev, int flags, uchar **packetp)
683 struct axidma_priv *priv = dev_get_priv(dev);
686 /* Wait for an incoming packet */
687 if (!isrxready(priv))
690 debug("axiemac: RX data ready\n");
692 /* Disable IRQ for a moment till packet is handled */
693 temp = readl(&priv->dmarx->control);
694 temp &= ~XAXIDMA_IRQ_ALL_MASK;
695 writel(temp, &priv->dmarx->control);
696 if (!priv->eth_hasnobuf && priv->mactype == EMAC_1G)
697 length = rx_bd.app4 & 0xFFFF; /* max length mask */
699 length = rx_bd.status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
702 print_buffer(&rxframe, &rxframe[0], 1, length, 16);
709 static int axiemac_free_pkt(struct udevice *dev, uchar *packet, int length)
711 struct axidma_priv *priv = dev_get_priv(dev);
714 /* It is useful to clear buffer to be sure that it is consistent */
715 memset(rxframe, 0, sizeof(rxframe));
718 /* Clear the whole buffer and setup it again - all flags are cleared */
719 memset(&rx_bd, 0, sizeof(rx_bd));
720 rx_bd.next_desc = lower_32_bits((unsigned long)&rx_bd);
721 rx_bd.buf_addr = lower_32_bits((unsigned long)&rxframe);
722 #if defined(CONFIG_PHYS_64BIT)
723 rx_bd.next_desc_msb = upper_32_bits((unsigned long)&rx_bd);
724 rx_bd.buf_addr_msb = upper_32_bits((unsigned long)&rxframe);
726 rx_bd.cntrl = sizeof(rxframe);
729 flush_cache((phys_addr_t)&rx_bd, sizeof(rx_bd));
731 /* It is necessary to flush rxframe because if you don't do it
732 * then cache will contain previous packet */
733 flush_cache((phys_addr_t)&rxframe, sizeof(rxframe));
735 /* Rx BD is ready - start again */
736 axienet_dma_write(&rx_bd, &priv->dmarx->tail);
738 debug("axiemac: RX completed, framelength = %d\n", length);
743 static int axiemac_miiphy_read(struct mii_dev *bus, int addr,
749 ret = phyread(bus->priv, addr, reg, &value);
750 debug("axiemac: Read MII 0x%x, 0x%x, 0x%x, %d\n", addr, reg,
755 static int axiemac_miiphy_write(struct mii_dev *bus, int addr, int devad,
758 debug("axiemac: Write MII 0x%x, 0x%x, 0x%x\n", addr, reg, value);
759 return phywrite(bus->priv, addr, reg, value);
762 static int axi_emac_probe(struct udevice *dev)
764 struct axidma_plat *plat = dev_get_plat(dev);
765 struct eth_pdata *pdata = &plat->eth_pdata;
766 struct axidma_priv *priv = dev_get_priv(dev);
769 priv->iobase = (struct axi_regs *)pdata->iobase;
770 priv->dmatx = plat->dmatx;
771 /* RX channel offset is 0x30 */
772 priv->dmarx = (struct axidma_reg *)((phys_addr_t)priv->dmatx + 0x30);
773 priv->mactype = plat->mactype;
775 if (priv->mactype == EMAC_1G) {
776 priv->eth_hasnobuf = plat->eth_hasnobuf;
777 priv->phyaddr = plat->phyaddr;
778 priv->phy_of_handle = plat->phy_of_handle;
779 priv->interface = pdata->phy_interface;
781 priv->bus = mdio_alloc();
782 priv->bus->read = axiemac_miiphy_read;
783 priv->bus->write = axiemac_miiphy_write;
784 priv->bus->priv = priv;
786 ret = mdio_register_seq(priv->bus, dev_seq(dev));
790 axiemac_phy_init(dev);
796 static int axi_emac_remove(struct udevice *dev)
798 struct axidma_priv *priv = dev_get_priv(dev);
800 if (priv->mactype == EMAC_1G) {
802 mdio_unregister(priv->bus);
803 mdio_free(priv->bus);
809 static const struct eth_ops axi_emac_ops = {
810 .start = axiemac_start,
811 .send = axiemac_send,
812 .recv = axiemac_recv,
813 .free_pkt = axiemac_free_pkt,
814 .stop = axiemac_stop,
815 .write_hwaddr = axiemac_write_hwaddr,
818 static int axi_emac_of_to_plat(struct udevice *dev)
820 struct axidma_plat *plat = dev_get_plat(dev);
821 struct eth_pdata *pdata = &plat->eth_pdata;
822 int node = dev_of_offset(dev);
825 pdata->iobase = dev_read_addr(dev);
826 plat->mactype = dev_get_driver_data(dev);
828 offset = fdtdec_lookup_phandle(gd->fdt_blob, node,
829 "axistream-connected");
831 printf("%s: axistream is not found\n", __func__);
834 plat->dmatx = (struct axidma_reg *)fdtdec_get_addr_size_auto_parent
835 (gd->fdt_blob, 0, offset, "reg", 0, NULL, false);
837 printf("%s: axi_dma register space not found\n", __func__);
841 if (plat->mactype == EMAC_1G) {
844 offset = fdtdec_lookup_phandle(gd->fdt_blob, node,
847 plat->phyaddr = fdtdec_get_int(gd->fdt_blob, offset,
849 plat->phy_of_handle = offset;
852 pdata->phy_interface = dev_read_phy_mode(dev);
853 if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
856 plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node,
857 "xlnx,eth-hasnobuf");
860 printf("AXI EMAC: %lx, phyaddr %d, interface %s\n", (ulong)pdata->iobase,
861 plat->phyaddr, phy_string_for_interface(pdata->phy_interface));
866 static const struct udevice_id axi_emac_ids[] = {
867 { .compatible = "xlnx,axi-ethernet-1.00.a", .data = (uintptr_t)EMAC_1G },
868 { .compatible = "xlnx,xxv-ethernet-1.0", .data = (uintptr_t)EMAC_10G_25G },
872 U_BOOT_DRIVER(axi_emac) = {
875 .of_match = axi_emac_ids,
876 .of_to_plat = axi_emac_of_to_plat,
877 .probe = axi_emac_probe,
878 .remove = axi_emac_remove,
879 .ops = &axi_emac_ops,
880 .priv_auto = sizeof(struct axidma_priv),
881 .plat_auto = sizeof(struct axidma_plat),