1 // SPDX-License-Identifier: GPL-2.0+
4 * Marvell Semiconductor <www.marvell.com>
10 * based on - Driver for MV64360X ethernet ports
20 #include <asm/global_data.h>
22 #include <linux/delay.h>
23 #include <linux/errno.h>
24 #include <asm/types.h>
25 #include <asm/system.h>
26 #include <asm/byteorder.h>
27 #include <asm/arch/cpu.h>
29 #if defined(CONFIG_ARCH_KIRKWOOD)
30 #include <asm/arch/soc.h>
31 #elif defined(CONFIG_ARCH_ORION5X)
32 #include <asm/arch/orion5x.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 #define MV_PHY_ADR_REQUEST 0xee
40 #define MVGBE_SMI_REG (((struct mvgbe_registers *)MVGBE0_BASE)->smi)
41 #define MVGBE_PGADR_REG 22
43 #if defined(CONFIG_PHYLIB) || defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
44 static int smi_wait_ready(struct mvgbe_device *dmvgbe)
48 ret = wait_for_bit_le32(&MVGBE_SMI_REG, MVGBE_PHY_SMI_BUSY_MASK, false,
49 MVGBE_PHY_SMI_TIMEOUT_MS, false);
51 printf("Error: SMI busy timeout\n");
58 static int __mvgbe_mdio_read(struct mvgbe_device *dmvgbe, int phy_adr,
59 int devad, int reg_ofs)
61 struct mvgbe_registers *regs = dmvgbe->regs;
66 /* Phyadr read request */
67 if (phy_adr == MV_PHY_ADR_REQUEST &&
68 reg_ofs == MV_PHY_ADR_REQUEST) {
70 data = (u16) (MVGBE_REG_RD(regs->phyadr) & PHYADR_MASK);
73 /* check parameters */
74 if (phy_adr > PHYADR_MASK) {
75 printf("Err..(%s) Invalid PHY address %d\n",
79 if (reg_ofs > PHYREG_MASK) {
80 printf("Err..(%s) Invalid register offset %d\n",
85 /* wait till the SMI is not busy */
86 if (smi_wait_ready(dmvgbe) < 0)
89 /* fill the phy address and regiser offset and read opcode */
90 smi_reg = (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS)
91 | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS)
92 | MVGBE_PHY_SMI_OPCODE_READ;
94 /* write the smi register */
95 MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg);
97 /*wait till read value is ready */
98 timeout = MVGBE_PHY_SMI_TIMEOUT;
101 /* read smi register */
102 smi_reg = MVGBE_REG_RD(MVGBE_SMI_REG);
103 if (timeout-- == 0) {
104 printf("Err..(%s) SMI read ready timeout\n",
108 } while (!(smi_reg & MVGBE_PHY_SMI_READ_VALID_MASK));
110 /* Wait for the data to update in the SMI register */
111 for (timeout = 0; timeout < MVGBE_PHY_SMI_TIMEOUT; timeout++)
114 data = (u16) (MVGBE_REG_RD(MVGBE_SMI_REG) & MVGBE_PHY_SMI_DATA_MASK);
116 debug("%s:(adr %d, off %d) value= %04x\n", __func__, phy_adr, reg_ofs,
123 * smi_reg_read - miiphy_read callback function.
125 * Returns 16bit phy register value, or -EFAULT on error
127 static int smi_reg_read(struct mii_dev *bus, int phy_adr, int devad,
130 struct mvgbe_device *dmvgbe = bus->priv;
132 return __mvgbe_mdio_read(dmvgbe, phy_adr, devad, reg_ofs);
135 static int __mvgbe_mdio_write(struct mvgbe_device *dmvgbe, int phy_adr,
136 int devad, int reg_ofs, u16 data)
138 struct mvgbe_registers *regs = dmvgbe->regs;
141 /* Phyadr write request*/
142 if (phy_adr == MV_PHY_ADR_REQUEST &&
143 reg_ofs == MV_PHY_ADR_REQUEST) {
144 MVGBE_REG_WR(regs->phyadr, data);
148 /* check parameters */
149 if (phy_adr > PHYADR_MASK) {
150 printf("Err..(%s) Invalid phy address\n", __func__);
153 if (reg_ofs > PHYREG_MASK) {
154 printf("Err..(%s) Invalid register offset\n", __func__);
158 /* wait till the SMI is not busy */
159 if (smi_wait_ready(dmvgbe) < 0)
162 /* fill the phy addr and reg offset and write opcode and data */
163 smi_reg = (data << MVGBE_PHY_SMI_DATA_OFFS);
164 smi_reg |= (phy_adr << MVGBE_PHY_SMI_DEV_ADDR_OFFS)
165 | (reg_ofs << MVGBE_SMI_REG_ADDR_OFFS);
166 smi_reg &= ~MVGBE_PHY_SMI_OPCODE_READ;
168 /* write the smi register */
169 MVGBE_REG_WR(MVGBE_SMI_REG, smi_reg);
175 * smi_reg_write - miiphy_write callback function.
177 * Returns 0 if write succeed, -EFAULT on error
179 static int smi_reg_write(struct mii_dev *bus, int phy_adr, int devad,
180 int reg_ofs, u16 data)
182 struct mvgbe_device *dmvgbe = bus->priv;
184 return __mvgbe_mdio_write(dmvgbe, phy_adr, devad, reg_ofs, data);
188 /* Stop and checks all queues */
189 static void stop_queue(u32 * qreg)
193 reg_data = readl(qreg);
195 if (reg_data & 0xFF) {
196 /* Issue stop command for active channels only */
197 writel((reg_data << 8), qreg);
199 /* Wait for all queue activity to terminate. */
202 * Check port cause register that all queues
205 reg_data = readl(qreg);
207 while (reg_data & 0xFF);
212 * set_access_control - Config address decode parameters for Ethernet unit
214 * This function configures the address decode parameters for the Gigabit
215 * Ethernet Controller according the given parameters struct.
217 * @regs Register struct pointer.
218 * @param Address decode parameter struct.
220 static void set_access_control(struct mvgbe_registers *regs,
221 struct mvgbe_winparam *param)
225 /* Set access control register */
226 access_prot_reg = MVGBE_REG_RD(regs->epap);
227 /* clear window permission */
228 access_prot_reg &= (~(3 << (param->win * 2)));
229 access_prot_reg |= (param->access_ctrl << (param->win * 2));
230 MVGBE_REG_WR(regs->epap, access_prot_reg);
232 /* Set window Size reg (SR) */
233 MVGBE_REG_WR(regs->barsz[param->win].size,
234 (((param->size / 0x10000) - 1) << 16));
236 /* Set window Base address reg (BA) */
237 MVGBE_REG_WR(regs->barsz[param->win].bar,
238 (param->target | param->attrib | param->base_addr));
239 /* High address remap reg (HARR) */
241 MVGBE_REG_WR(regs->ha_remap[param->win], param->high_addr);
243 /* Base address enable reg (BARER) */
244 if (param->enable == 1)
245 MVGBE_REG_BITS_RESET(regs->bare, (1 << param->win));
247 MVGBE_REG_BITS_SET(regs->bare, (1 << param->win));
250 static void set_dram_access(struct mvgbe_registers *regs)
252 struct mvgbe_winparam win_param;
255 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
256 /* Set access parameters for DRAM bank i */
257 win_param.win = i; /* Use Ethernet window i */
258 /* Window target - DDR */
259 win_param.target = MVGBE_TARGET_DRAM;
260 /* Enable full access */
261 win_param.access_ctrl = EWIN_ACCESS_FULL;
262 win_param.high_addr = 0;
263 /* Get bank base and size */
264 win_param.base_addr = gd->bd->bi_dram[i].start;
265 win_param.size = gd->bd->bi_dram[i].size;
266 if (win_param.size == 0)
267 win_param.enable = 0;
269 win_param.enable = 1; /* Enable the access */
271 /* Enable DRAM bank */
274 win_param.attrib = EBAR_DRAM_CS0;
277 win_param.attrib = EBAR_DRAM_CS1;
280 win_param.attrib = EBAR_DRAM_CS2;
283 win_param.attrib = EBAR_DRAM_CS3;
286 /* invalid bank, disable access */
287 win_param.enable = 0;
288 win_param.attrib = 0;
291 /* Set the access control for address window(EPAPR) RD/WR */
292 set_access_control(regs, &win_param);
297 * port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
299 * Go through all the DA filter tables (Unicast, Special Multicast & Other
300 * Multicast) and set each entry to 0.
302 static void port_init_mac_tables(struct mvgbe_registers *regs)
306 /* Clear DA filter unicast table (Ex_dFUT) */
307 for (table_index = 0; table_index < 4; ++table_index)
308 MVGBE_REG_WR(regs->dfut[table_index], 0);
310 for (table_index = 0; table_index < 64; ++table_index) {
311 /* Clear DA filter special multicast table (Ex_dFSMT) */
312 MVGBE_REG_WR(regs->dfsmt[table_index], 0);
313 /* Clear DA filter other multicast table (Ex_dFOMT) */
314 MVGBE_REG_WR(regs->dfomt[table_index], 0);
319 * port_uc_addr - This function Set the port unicast address table
321 * This function locates the proper entry in the Unicast table for the
322 * specified MAC nibble and sets its properties according to function
324 * This function add/removes MAC addresses from the port unicast address
327 * @uc_nibble Unicast MAC Address last nibble.
328 * @option 0 = Add, 1 = remove address.
330 * RETURN: 1 if output succeeded. 0 if option parameter is invalid.
332 static int port_uc_addr(struct mvgbe_registers *regs, u8 uc_nibble,
339 /* Locate the Unicast table entry */
340 uc_nibble = (0xf & uc_nibble);
341 /* Register offset from unicast table base */
342 tbl_offset = (uc_nibble / 4);
343 /* Entry offset within the above register */
344 reg_offset = uc_nibble % 4;
347 case REJECT_MAC_ADDR:
349 * Clear accepts frame bit at specified unicast
352 unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]);
353 unicast_reg &= (0xFF << (8 * reg_offset));
354 MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg);
356 case ACCEPT_MAC_ADDR:
357 /* Set accepts frame bit at unicast DA filter table entry */
358 unicast_reg = MVGBE_REG_RD(regs->dfut[tbl_offset]);
359 unicast_reg &= (0xFF << (8 * reg_offset));
360 unicast_reg |= ((0x01 | (RXUQ << 1)) << (8 * reg_offset));
361 MVGBE_REG_WR(regs->dfut[tbl_offset], unicast_reg);
370 * port_uc_addr_set - This function Set the port Unicast address.
372 static void port_uc_addr_set(struct mvgbe_device *dmvgbe, u8 *p_addr)
374 struct mvgbe_registers *regs = dmvgbe->regs;
378 mac_l = (p_addr[4] << 8) | (p_addr[5]);
379 mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
382 MVGBE_REG_WR(regs->macal, mac_l);
383 MVGBE_REG_WR(regs->macah, mac_h);
385 /* Accept frames of this address */
386 port_uc_addr(regs, p_addr[5], ACCEPT_MAC_ADDR);
390 * mvgbe_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
392 static void mvgbe_init_rx_desc_ring(struct mvgbe_device *dmvgbe)
394 struct mvgbe_rxdesc *p_rx_desc;
397 /* initialize the Rx descriptors ring */
398 p_rx_desc = dmvgbe->p_rxdesc;
399 for (i = 0; i < RINGSZ; i++) {
401 MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT;
402 p_rx_desc->buf_size = PKTSIZE_ALIGN;
403 p_rx_desc->byte_cnt = 0;
404 p_rx_desc->buf_ptr = dmvgbe->p_rxbuf + i * PKTSIZE_ALIGN;
405 if (i == (RINGSZ - 1))
406 p_rx_desc->nxtdesc_p = dmvgbe->p_rxdesc;
408 p_rx_desc->nxtdesc_p = (struct mvgbe_rxdesc *)
409 ((u32) p_rx_desc + MV_RXQ_DESC_ALIGNED_SIZE);
410 p_rx_desc = p_rx_desc->nxtdesc_p;
413 dmvgbe->p_rxdesc_curr = dmvgbe->p_rxdesc;
416 static int __mvgbe_init(struct mvgbe_device *dmvgbe, u8 *enetaddr,
419 struct mvgbe_registers *regs = dmvgbe->regs;
421 mvgbe_init_rx_desc_ring(dmvgbe);
423 /* Clear the ethernet port interrupts */
424 MVGBE_REG_WR(regs->ic, 0);
425 MVGBE_REG_WR(regs->ice, 0);
426 /* Unmask RX buffer and TX end interrupt */
427 MVGBE_REG_WR(regs->pim, INT_CAUSE_UNMASK_ALL);
428 /* Unmask phy and link status changes interrupts */
429 MVGBE_REG_WR(regs->peim, INT_CAUSE_UNMASK_ALL_EXT);
431 set_dram_access(regs);
432 port_init_mac_tables(regs);
433 port_uc_addr_set(dmvgbe, enetaddr);
435 /* Assign port configuration and command. */
436 MVGBE_REG_WR(regs->pxc, PRT_CFG_VAL);
437 MVGBE_REG_WR(regs->pxcx, PORT_CFG_EXTEND_VALUE);
438 MVGBE_REG_WR(regs->psc0, PORT_SERIAL_CONTROL_VALUE);
440 /* Assign port SDMA configuration */
441 MVGBE_REG_WR(regs->sdc, PORT_SDMA_CFG_VALUE);
442 MVGBE_REG_WR(regs->tqx[0].qxttbc, QTKNBKT_DEF_VAL);
443 MVGBE_REG_WR(regs->tqx[0].tqxtbc,
444 (QMTBS_DEF_VAL << 16) | QTKNRT_DEF_VAL);
445 /* Turn off the port/RXUQ bandwidth limitation */
446 MVGBE_REG_WR(regs->pmtu, 0);
448 /* Set maximum receive buffer to 9700 bytes */
449 MVGBE_REG_WR(regs->psc0, MVGBE_MAX_RX_PACKET_9700BYTE
450 | (MVGBE_REG_RD(regs->psc0) & MRU_MASK));
452 /* Enable port initially */
453 MVGBE_REG_BITS_SET(regs->psc0, MVGBE_SERIAL_PORT_EN);
456 * Set ethernet MTU for leaky bucket mechanism to 0 - this will
457 * disable the leaky bucket mechanism .
459 MVGBE_REG_WR(regs->pmtu, 0);
461 /* Assignment of Rx CRDB of given RXUQ */
462 MVGBE_REG_WR(regs->rxcdp[RXUQ], (u32) dmvgbe->p_rxdesc_curr);
463 /* ensure previous write is done before enabling Rx DMA */
465 /* Enable port Rx. */
466 MVGBE_REG_WR(regs->rqc, (1 << RXUQ));
471 static void __mvgbe_halt(struct mvgbe_device *dmvgbe)
473 struct mvgbe_registers *regs = dmvgbe->regs;
475 /* Disable all gigE address decoder */
476 MVGBE_REG_WR(regs->bare, 0x3f);
478 stop_queue(®s->tqc);
479 stop_queue(®s->rqc);
482 MVGBE_REG_BITS_RESET(regs->psc0, MVGBE_SERIAL_PORT_EN);
483 /* Set port is not reset */
484 MVGBE_REG_BITS_RESET(regs->psc1, 1 << 4);
485 #ifdef CONFIG_SYS_MII_MODE
486 /* Set MMI interface up */
487 MVGBE_REG_BITS_RESET(regs->psc1, 1 << 3);
489 /* Disable & mask ethernet port interrupts */
490 MVGBE_REG_WR(regs->ic, 0);
491 MVGBE_REG_WR(regs->ice, 0);
492 MVGBE_REG_WR(regs->pim, 0);
493 MVGBE_REG_WR(regs->peim, 0);
496 static int mvgbe_write_hwaddr(struct udevice *dev)
498 struct eth_pdata *pdata = dev_get_plat(dev);
500 port_uc_addr_set(dev_get_priv(dev), pdata->enetaddr);
505 static int __mvgbe_send(struct mvgbe_device *dmvgbe, void *dataptr,
508 struct mvgbe_registers *regs = dmvgbe->regs;
509 struct mvgbe_txdesc *p_txdesc = dmvgbe->p_txdesc;
510 void *p = (void *)dataptr;
514 /* Copy buffer if it's misaligned */
515 if ((u32) dataptr & 0x07) {
516 if (datasize > PKTSIZE_ALIGN) {
517 printf("Non-aligned data too large (%d)\n",
522 memcpy(dmvgbe->p_aligned_txbuf, p, datasize);
523 p = dmvgbe->p_aligned_txbuf;
526 p_txdesc->cmd_sts = MVGBE_ZERO_PADDING | MVGBE_GEN_CRC;
527 p_txdesc->cmd_sts |= MVGBE_TX_FIRST_DESC | MVGBE_TX_LAST_DESC;
528 p_txdesc->cmd_sts |= MVGBE_BUFFER_OWNED_BY_DMA;
529 p_txdesc->cmd_sts |= MVGBE_TX_EN_INTERRUPT;
530 p_txdesc->buf_ptr = (u8 *) p;
531 p_txdesc->byte_cnt = datasize;
533 /* Set this tc desc as zeroth TXUQ */
534 txuq0_reg_addr = (u32)®s->tcqdp[TXUQ];
535 writel((u32) p_txdesc, txuq0_reg_addr);
537 /* ensure tx desc writes above are performed before we start Tx DMA */
540 /* Apply send command using zeroth TXUQ */
541 MVGBE_REG_WR(regs->tqc, (1 << TXUQ));
544 * wait for packet xmit completion
546 cmd_sts = readl(&p_txdesc->cmd_sts);
547 while (cmd_sts & MVGBE_BUFFER_OWNED_BY_DMA) {
548 /* return fail if error is detected */
549 if ((cmd_sts & (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME)) ==
550 (MVGBE_ERROR_SUMMARY | MVGBE_TX_LAST_FRAME) &&
551 cmd_sts & (MVGBE_UR_ERROR | MVGBE_RL_ERROR)) {
552 printf("Err..(%s) in xmit packet\n", __func__);
555 cmd_sts = readl(&p_txdesc->cmd_sts);
560 static int __mvgbe_recv(struct mvgbe_device *dmvgbe, uchar **packetp)
562 struct mvgbe_rxdesc *p_rxdesc_curr = dmvgbe->p_rxdesc_curr;
565 u32 rxdesc_curr_addr;
571 /* wait untill rx packet available or timeout */
573 if (timeout < MVGBE_PHY_SMI_TIMEOUT)
576 debug("%s time out...\n", __func__);
579 } while (readl(&p_rxdesc_curr->cmd_sts) & MVGBE_BUFFER_OWNED_BY_DMA);
581 if (p_rxdesc_curr->byte_cnt != 0) {
582 debug("%s: Received %d byte Packet @ 0x%x (cmd_sts= %08x)\n",
583 __func__, (u32) p_rxdesc_curr->byte_cnt,
584 (u32) p_rxdesc_curr->buf_ptr,
585 (u32) p_rxdesc_curr->cmd_sts);
589 * In case received a packet without first/last bits on
590 * OR the error summary bit is on,
591 * the packets needs to be dropeed.
593 cmd_sts = readl(&p_rxdesc_curr->cmd_sts);
596 (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC))
597 != (MVGBE_RX_FIRST_DESC | MVGBE_RX_LAST_DESC)) {
599 printf("Err..(%s) Dropping packet spread on"
600 " multiple descriptors\n", __func__);
602 } else if (cmd_sts & MVGBE_ERROR_SUMMARY) {
604 printf("Err..(%s) Dropping packet with errors\n",
608 /* !!! call higher layer processing */
609 debug("%s: Sending Received packet to"
610 " upper layer (net_process_received_packet)\n",
613 data = (p_rxdesc_curr->buf_ptr + RX_BUF_OFFSET);
614 rx_bytes = (int)(p_rxdesc_curr->byte_cnt -
620 * free these descriptors and point next in the ring
622 p_rxdesc_curr->cmd_sts =
623 MVGBE_BUFFER_OWNED_BY_DMA | MVGBE_RX_EN_INTERRUPT;
624 p_rxdesc_curr->buf_size = PKTSIZE_ALIGN;
625 p_rxdesc_curr->byte_cnt = 0;
627 rxdesc_curr_addr = (u32)&dmvgbe->p_rxdesc_curr;
628 writel((unsigned)p_rxdesc_curr->nxtdesc_p, rxdesc_curr_addr);
633 #if defined(CONFIG_PHYLIB)
634 static struct phy_device *__mvgbe_phy_init(struct udevice *dev,
636 phy_interface_t phy_interface,
639 struct phy_device *phydev;
641 /* Set phy address of the port */
642 miiphy_write(dev->name, MV_PHY_ADR_REQUEST, MV_PHY_ADR_REQUEST,
645 /* Make sure the selected PHY page is 0 before connecting */
646 miiphy_write(dev->name, phyid, MVGBE_PGADR_REG, 0);
648 phydev = phy_connect(bus, phyid, dev, phy_interface);
650 printf("phy_connect failed\n");
659 #endif /* CONFIG_PHYLIB */
661 static int mvgbe_alloc_buffers(struct mvgbe_device *dmvgbe)
663 dmvgbe->p_rxdesc = memalign(PKTALIGN,
664 MV_RXQ_DESC_ALIGNED_SIZE * RINGSZ + 1);
665 if (!dmvgbe->p_rxdesc)
668 dmvgbe->p_rxbuf = memalign(PKTALIGN,
669 RINGSZ * PKTSIZE_ALIGN + 1);
670 if (!dmvgbe->p_rxbuf)
673 dmvgbe->p_aligned_txbuf = memalign(8, PKTSIZE_ALIGN);
674 if (!dmvgbe->p_aligned_txbuf)
677 dmvgbe->p_txdesc = memalign(PKTALIGN, sizeof(struct mvgbe_txdesc) + 1);
678 if (!dmvgbe->p_txdesc)
684 free(dmvgbe->p_aligned_txbuf);
686 free(dmvgbe->p_rxbuf);
688 free(dmvgbe->p_rxdesc);
693 static int mvgbe_port_is_fixed_link(struct mvgbe_device *dmvgbe)
695 return dmvgbe->phyaddr > PHY_MAX_ADDR;
698 static int mvgbe_start(struct udevice *dev)
700 struct eth_pdata *pdata = dev_get_plat(dev);
701 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
704 ret = __mvgbe_init(dmvgbe, pdata->enetaddr, dev->name);
708 if (!mvgbe_port_is_fixed_link(dmvgbe)) {
709 dmvgbe->phydev = __mvgbe_phy_init(dev, dmvgbe->bus,
710 dmvgbe->phy_interface,
719 static int mvgbe_send(struct udevice *dev, void *packet, int length)
721 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
723 return __mvgbe_send(dmvgbe, packet, length);
726 static int mvgbe_recv(struct udevice *dev, int flags, uchar **packetp)
728 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
730 return __mvgbe_recv(dmvgbe, packetp);
733 static void mvgbe_stop(struct udevice *dev)
735 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
737 __mvgbe_halt(dmvgbe);
740 static int mvgbe_probe(struct udevice *dev)
742 struct eth_pdata *pdata = dev_get_plat(dev);
743 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
747 ret = mvgbe_alloc_buffers(dmvgbe);
751 dmvgbe->regs = (void __iomem *)pdata->iobase;
755 printf("Failed to allocate MDIO bus\n");
759 bus->read = smi_reg_read;
760 bus->write = smi_reg_write;
761 snprintf(bus->name, sizeof(bus->name), dev->name);
765 ret = mdio_register(bus);
772 static const struct eth_ops mvgbe_ops = {
773 .start = mvgbe_start,
777 .write_hwaddr = mvgbe_write_hwaddr,
780 static int mvgbe_of_to_plat(struct udevice *dev)
782 struct eth_pdata *pdata = dev_get_plat(dev);
783 struct mvgbe_device *dmvgbe = dev_get_priv(dev);
784 void *blob = (void *)gd->fdt_blob;
785 int node = dev_of_offset(dev);
790 pdata->iobase = dev_read_addr(dev);
791 pdata->phy_interface = -1;
793 pnode = fdt_node_offset_by_compatible(blob, node,
794 "marvell,kirkwood-eth-port");
796 /* Get phy-mode / phy_interface from DT */
797 pdata->phy_interface = dev_read_phy_mode(dev);
798 if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
799 pdata->phy_interface = PHY_INTERFACE_MODE_GMII;
801 dmvgbe->phy_interface = pdata->phy_interface;
803 /* fetch 'fixed-link' property */
804 fl_node = fdt_subnode_offset(blob, pnode, "fixed-link");
805 if (fl_node != -FDT_ERR_NOTFOUND) {
806 /* set phy_addr to invalid value for fixed link */
807 dmvgbe->phyaddr = PHY_MAX_ADDR + 1;
808 dmvgbe->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");
809 dmvgbe->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
811 /* Now read phyaddr from DT */
812 addr = fdtdec_lookup_phandle(blob, pnode, "phy-handle");
814 dmvgbe->phyaddr = fdtdec_get_int(blob, addr, "reg", 0);
820 static const struct udevice_id mvgbe_ids[] = {
821 { .compatible = "marvell,kirkwood-eth" },
825 U_BOOT_DRIVER(mvgbe) = {
828 .of_match = mvgbe_ids,
829 .of_to_plat = mvgbe_of_to_plat,
830 .probe = mvgbe_probe,
832 .priv_auto = sizeof(struct mvgbe_device),
833 .plat_auto = sizeof(struct eth_pdata),