1 // SPDX-License-Identifier: GPL-2.0+
3 * Generic PHY Management code
5 * Copyright 2011 Freescale Semiconductor, Inc.
8 * Based loosely off of Linux's PHY Lib
20 #include <linux/err.h>
21 #include <linux/compiler.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 /* Generic PHY support and helper functions */
28 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
29 * @phydev: target phy_device struct
31 * Description: Writes MII_ADVERTISE with the appropriate values,
32 * after sanitizing the values to make sure we only advertise
33 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
34 * hasn't changed, and > 0 if it has changed.
36 static int genphy_config_advert(struct phy_device *phydev)
39 int oldadv, adv, bmsr;
42 /* Only allow advertising what this PHY supports */
43 phydev->advertising &= phydev->supported;
44 advertise = phydev->advertising;
46 /* Setup standard advertisement */
47 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
53 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
54 ADVERTISE_PAUSE_ASYM);
55 if (advertise & ADVERTISED_10baseT_Half)
56 adv |= ADVERTISE_10HALF;
57 if (advertise & ADVERTISED_10baseT_Full)
58 adv |= ADVERTISE_10FULL;
59 if (advertise & ADVERTISED_100baseT_Half)
60 adv |= ADVERTISE_100HALF;
61 if (advertise & ADVERTISED_100baseT_Full)
62 adv |= ADVERTISE_100FULL;
63 if (advertise & ADVERTISED_Pause)
64 adv |= ADVERTISE_PAUSE_CAP;
65 if (advertise & ADVERTISED_Asym_Pause)
66 adv |= ADVERTISE_PAUSE_ASYM;
67 if (advertise & ADVERTISED_1000baseX_Half)
68 adv |= ADVERTISE_1000XHALF;
69 if (advertise & ADVERTISED_1000baseX_Full)
70 adv |= ADVERTISE_1000XFULL;
73 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE, adv);
80 bmsr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
84 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all
85 * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a
88 if (!(bmsr & BMSR_ESTATEN))
91 /* Configure gigabit if it's supported */
92 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
98 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
100 if (phydev->supported & (SUPPORTED_1000baseT_Half |
101 SUPPORTED_1000baseT_Full)) {
102 if (advertise & SUPPORTED_1000baseT_Half)
103 adv |= ADVERTISE_1000HALF;
104 if (advertise & SUPPORTED_1000baseT_Full)
105 adv |= ADVERTISE_1000FULL;
111 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, adv);
119 * genphy_setup_forced - configures/forces speed/duplex from @phydev
120 * @phydev: target phy_device struct
122 * Description: Configures MII_BMCR to force speed/duplex
123 * to the values in phydev. Assumes that the values are valid.
125 static int genphy_setup_forced(struct phy_device *phydev)
128 int ctl = BMCR_ANRESTART;
131 phydev->asym_pause = 0;
133 if (phydev->speed == SPEED_1000)
134 ctl |= BMCR_SPEED1000;
135 else if (phydev->speed == SPEED_100)
136 ctl |= BMCR_SPEED100;
138 if (phydev->duplex == DUPLEX_FULL)
139 ctl |= BMCR_FULLDPLX;
141 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
147 * genphy_restart_aneg - Enable and Restart Autonegotiation
148 * @phydev: target phy_device struct
150 int genphy_restart_aneg(struct phy_device *phydev)
154 ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
159 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
161 /* Don't isolate the PHY if we're negotiating */
162 ctl &= ~(BMCR_ISOLATE);
164 ctl = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
170 * genphy_config_aneg - restart auto-negotiation or write BMCR
171 * @phydev: target phy_device struct
173 * Description: If auto-negotiation is enabled, we configure the
174 * advertising, and then restart auto-negotiation. If it is not
175 * enabled, then we write the BMCR.
177 int genphy_config_aneg(struct phy_device *phydev)
181 if (phydev->autoneg != AUTONEG_ENABLE)
182 return genphy_setup_forced(phydev);
184 result = genphy_config_advert(phydev);
186 if (result < 0) /* error */
191 * Advertisment hasn't changed, but maybe aneg was never on to
192 * begin with? Or maybe phy was isolated?
194 int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
199 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
200 result = 1; /* do restart aneg */
204 * Only restart aneg if we are advertising something different
205 * than we were before.
208 result = genphy_restart_aneg(phydev);
214 * genphy_update_link - update link status in @phydev
215 * @phydev: target phy_device struct
217 * Description: Update the value in phydev->link to reflect the
218 * current link value. In order to do this, we need to read
219 * the status register twice, keeping the second value.
221 int genphy_update_link(struct phy_device *phydev)
223 unsigned int mii_reg;
226 * Wait if the link is up, and autonegotiation is in progress
227 * (ie - we're capable and it's not done)
229 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
232 * If we already saw the link up, and it hasn't gone down, then
233 * we don't need to wait for autoneg again
235 if (phydev->link && mii_reg & BMSR_LSTATUS)
238 if ((phydev->autoneg == AUTONEG_ENABLE) &&
239 !(mii_reg & BMSR_ANEGCOMPLETE)) {
242 printf("%s Waiting for PHY auto negotiation to complete",
244 while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
248 if (i > (PHY_ANEG_TIMEOUT / 50)) {
249 printf(" TIMEOUT !\n");
255 puts("user interrupt!\n");
263 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
264 mdelay(50); /* 50 ms */
269 /* Read the link a second time to clear the latched state */
270 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
272 if (mii_reg & BMSR_LSTATUS)
282 * Generic function which updates the speed and duplex. If
283 * autonegotiation is enabled, it uses the AND of the link
284 * partner's advertised capabilities and our advertised
285 * capabilities. If autonegotiation is disabled, we use the
286 * appropriate bits in the control register.
288 * Stolen from Linux's mii.c and phy_device.c
290 int genphy_parse_link(struct phy_device *phydev)
292 int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
294 /* We're using autonegotiation */
295 if (phydev->autoneg == AUTONEG_ENABLE) {
300 /* Check for gigabit capability */
301 if (phydev->supported & (SUPPORTED_1000baseT_Full |
302 SUPPORTED_1000baseT_Half)) {
303 /* We want a list of states supported by
304 * both PHYs in the link
306 gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
308 debug("Could not read MII_STAT1000. ");
309 debug("Ignoring gigabit capability\n");
312 gblpa &= phy_read(phydev,
313 MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
316 /* Set the baseline so we only have to set them
317 * if they're different
319 phydev->speed = SPEED_10;
320 phydev->duplex = DUPLEX_HALF;
322 /* Check the gigabit fields */
323 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
324 phydev->speed = SPEED_1000;
326 if (gblpa & PHY_1000BTSR_1000FD)
327 phydev->duplex = DUPLEX_FULL;
333 lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
334 lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
336 if (lpa & (LPA_100FULL | LPA_100HALF)) {
337 phydev->speed = SPEED_100;
339 if (lpa & LPA_100FULL)
340 phydev->duplex = DUPLEX_FULL;
342 } else if (lpa & LPA_10FULL) {
343 phydev->duplex = DUPLEX_FULL;
347 * Extended status may indicate that the PHY supports
348 * 1000BASE-T/X even though the 1000BASE-T registers
349 * are missing. In this case we can't tell whether the
350 * peer also supports it, so we only check extended
351 * status if the 1000BASE-T registers are actually
354 if ((mii_reg & BMSR_ESTATEN) && !(mii_reg & BMSR_ERCAP))
355 estatus = phy_read(phydev, MDIO_DEVAD_NONE,
358 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_XHALF |
359 ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
360 phydev->speed = SPEED_1000;
361 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_TFULL))
362 phydev->duplex = DUPLEX_FULL;
366 u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
368 phydev->speed = SPEED_10;
369 phydev->duplex = DUPLEX_HALF;
371 if (bmcr & BMCR_FULLDPLX)
372 phydev->duplex = DUPLEX_FULL;
374 if (bmcr & BMCR_SPEED1000)
375 phydev->speed = SPEED_1000;
376 else if (bmcr & BMCR_SPEED100)
377 phydev->speed = SPEED_100;
383 int genphy_config(struct phy_device *phydev)
388 features = (SUPPORTED_TP | SUPPORTED_MII
389 | SUPPORTED_AUI | SUPPORTED_FIBRE |
392 /* Do we support autonegotiation? */
393 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
398 if (val & BMSR_ANEGCAPABLE)
399 features |= SUPPORTED_Autoneg;
401 if (val & BMSR_100FULL)
402 features |= SUPPORTED_100baseT_Full;
403 if (val & BMSR_100HALF)
404 features |= SUPPORTED_100baseT_Half;
405 if (val & BMSR_10FULL)
406 features |= SUPPORTED_10baseT_Full;
407 if (val & BMSR_10HALF)
408 features |= SUPPORTED_10baseT_Half;
410 if (val & BMSR_ESTATEN) {
411 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_ESTATUS);
416 if (val & ESTATUS_1000_TFULL)
417 features |= SUPPORTED_1000baseT_Full;
418 if (val & ESTATUS_1000_THALF)
419 features |= SUPPORTED_1000baseT_Half;
420 if (val & ESTATUS_1000_XFULL)
421 features |= SUPPORTED_1000baseX_Full;
422 if (val & ESTATUS_1000_XHALF)
423 features |= SUPPORTED_1000baseX_Half;
426 phydev->supported &= features;
427 phydev->advertising &= features;
429 genphy_config_aneg(phydev);
434 int genphy_startup(struct phy_device *phydev)
438 ret = genphy_update_link(phydev);
442 return genphy_parse_link(phydev);
445 int genphy_shutdown(struct phy_device *phydev)
450 static struct phy_driver genphy_driver = {
453 .name = "Generic PHY",
454 .features = PHY_GBIT_FEATURES | SUPPORTED_MII |
455 SUPPORTED_AUI | SUPPORTED_FIBRE |
457 .config = genphy_config,
458 .startup = genphy_startup,
459 .shutdown = genphy_shutdown,
462 int genphy_init(void)
464 return phy_register(&genphy_driver);
467 static LIST_HEAD(phy_drivers);
471 #ifdef CONFIG_NEEDS_MANUAL_RELOC
473 * The pointers inside phy_drivers also needs to be updated incase of
474 * manual reloc, without which these points to some invalid
475 * pre reloc address and leads to invalid accesses, hangs.
477 struct list_head *head = &phy_drivers;
479 head->next = (void *)head->next + gd->reloc_off;
480 head->prev = (void *)head->prev + gd->reloc_off;
483 #ifdef CONFIG_B53_SWITCH
486 #ifdef CONFIG_MV88E61XX_SWITCH
487 phy_mv88e61xx_init();
489 #ifdef CONFIG_PHY_AQUANTIA
492 #ifdef CONFIG_PHY_ATHEROS
495 #ifdef CONFIG_PHY_BROADCOM
498 #ifdef CONFIG_PHY_CORTINA
501 #ifdef CONFIG_PHY_DAVICOM
504 #ifdef CONFIG_PHY_ET1011C
507 #ifdef CONFIG_PHY_LXT
510 #ifdef CONFIG_PHY_MARVELL
513 #ifdef CONFIG_PHY_MICREL_KSZ8XXX
514 phy_micrel_ksz8xxx_init();
516 #ifdef CONFIG_PHY_MICREL_KSZ90X1
517 phy_micrel_ksz90x1_init();
519 #ifdef CONFIG_PHY_MESON_GXL
520 phy_meson_gxl_init();
522 #ifdef CONFIG_PHY_NATSEMI
525 #ifdef CONFIG_PHY_REALTEK
528 #ifdef CONFIG_PHY_SMSC
531 #ifdef CONFIG_PHY_TERANETICS
532 phy_teranetics_init();
537 #ifdef CONFIG_PHY_VITESSE
540 #ifdef CONFIG_PHY_XILINX
543 #ifdef CONFIG_PHY_MSCC
546 #ifdef CONFIG_PHY_FIXED
549 #ifdef CONFIG_PHY_NCSI
552 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
553 phy_xilinx_gmii2rgmii_init();
560 int phy_register(struct phy_driver *drv)
562 INIT_LIST_HEAD(&drv->list);
563 list_add_tail(&drv->list, &phy_drivers);
565 #ifdef CONFIG_NEEDS_MANUAL_RELOC
567 drv->probe += gd->reloc_off;
569 drv->config += gd->reloc_off;
571 drv->startup += gd->reloc_off;
573 drv->shutdown += gd->reloc_off;
575 drv->readext += gd->reloc_off;
577 drv->writeext += gd->reloc_off;
579 drv->read_mmd += gd->reloc_off;
581 drv->write_mmd += gd->reloc_off;
586 int phy_set_supported(struct phy_device *phydev, u32 max_speed)
588 /* The default values for phydev->supported are provided by the PHY
589 * driver "features" member, we want to reset to sane defaults first
590 * before supporting higher speeds.
592 phydev->supported &= PHY_DEFAULT_FEATURES;
598 phydev->supported |= PHY_1000BT_FEATURES;
601 phydev->supported |= PHY_100BT_FEATURES;
604 phydev->supported |= PHY_10BT_FEATURES;
610 static int phy_probe(struct phy_device *phydev)
614 phydev->advertising = phydev->drv->features;
615 phydev->supported = phydev->drv->features;
617 phydev->mmds = phydev->drv->mmds;
619 if (phydev->drv->probe)
620 err = phydev->drv->probe(phydev);
625 static struct phy_driver *generic_for_interface(phy_interface_t interface)
627 #ifdef CONFIG_PHYLIB_10G
628 if (is_10g_interface(interface))
629 return &gen10g_driver;
632 return &genphy_driver;
635 static struct phy_driver *get_phy_driver(struct phy_device *phydev,
636 phy_interface_t interface)
638 struct list_head *entry;
639 int phy_id = phydev->phy_id;
640 struct phy_driver *drv = NULL;
642 list_for_each(entry, &phy_drivers) {
643 drv = list_entry(entry, struct phy_driver, list);
644 if ((drv->uid & drv->mask) == (phy_id & drv->mask))
648 /* If we made it here, there's no driver for this PHY */
649 return generic_for_interface(interface);
652 static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
653 u32 phy_id, bool is_c45,
654 phy_interface_t interface)
656 struct phy_device *dev;
659 * We allocate the device, and initialize the
662 dev = malloc(sizeof(*dev));
664 printf("Failed to allocate PHY device for %s:%d\n",
669 memset(dev, 0, sizeof(*dev));
673 dev->interface = interface;
676 dev->node = ofnode_null();
679 dev->autoneg = AUTONEG_ENABLE;
682 dev->phy_id = phy_id;
683 dev->is_c45 = is_c45;
686 dev->drv = get_phy_driver(dev, interface);
688 if (phy_probe(dev)) {
689 printf("%s, PHY probe failed\n", __func__);
693 if (addr >= 0 && addr < PHY_MAX_ADDR)
694 bus->phymap[addr] = dev;
700 * get_phy_id - reads the specified addr for its ID.
701 * @bus: the target MII bus
702 * @addr: PHY address on the MII bus
703 * @phy_id: where to store the ID retrieved.
705 * Description: Reads the ID registers of the PHY at @addr on the
706 * @bus, stores it in @phy_id and returns zero on success.
708 int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
713 * Grab the bits from PHYIR1, and put them
716 phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
721 *phy_id = (phy_reg & 0xffff) << 16;
723 /* Grab the bits from PHYIR2, and put them in the lower half */
724 phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
729 *phy_id |= (phy_reg & 0xffff);
734 static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
735 uint phy_mask, int devad,
736 phy_interface_t interface)
738 u32 phy_id = 0xffffffff;
742 int addr = ffs(phy_mask) - 1;
743 int r = get_phy_id(bus, addr, devad, &phy_id);
746 * If the PHY ID is flat 0 we ignore it. There are C45 PHYs
747 * that return all 0s for C22 reads (like Aquantia AQR112) and
748 * there are C22 PHYs that return all 0s for C45 reads (like
751 if (r == 0 && phy_id == 0)
754 /* If the PHY ID is mostly f's, we didn't find anything */
755 if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) {
756 is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true;
757 return phy_device_create(bus, addr, phy_id, is_c45,
761 phy_mask &= ~(1 << addr);
766 static struct phy_device *search_for_existing_phy(struct mii_dev *bus,
768 phy_interface_t interface)
770 /* If we have one, return the existing device, with new interface */
772 int addr = ffs(phy_mask) - 1;
774 if (bus->phymap[addr]) {
775 bus->phymap[addr]->interface = interface;
776 return bus->phymap[addr];
778 phy_mask &= ~(1 << addr);
783 static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
785 phy_interface_t interface)
788 struct phy_device *phydev;
790 phydev = search_for_existing_phy(bus, phy_mask, interface);
793 /* Try Standard (ie Clause 22) access */
794 /* Otherwise we have to try Clause 45 */
795 for (i = 0; i < 5; i++) {
796 phydev = create_phy_by_mask(bus, phy_mask,
797 i ? i : MDIO_DEVAD_NONE, interface);
804 debug("\n%s PHY: ", bus->name);
806 int addr = ffs(phy_mask) - 1;
809 phy_mask &= ~(1 << addr);
811 debug("not found\n");
817 * get_phy_device - reads the specified PHY device and returns its
819 * @bus: the target MII bus
820 * @addr: PHY address on the MII bus
822 * Description: Reads the ID registers of the PHY at @addr on the
823 * @bus, then allocates and returns the phy_device to represent it.
825 static struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
826 phy_interface_t interface)
828 return get_phy_device_by_mask(bus, 1 << addr, interface);
831 int phy_reset(struct phy_device *phydev)
835 int devad = MDIO_DEVAD_NONE;
837 if (phydev->flags & PHY_FLAG_BROKEN_RESET)
840 #ifdef CONFIG_PHYLIB_10G
841 /* If it's 10G, we need to issue reset through one of the MMDs */
842 if (is_10g_interface(phydev->interface)) {
844 gen10g_discover_mmds(phydev);
846 devad = ffs(phydev->mmds) - 1;
850 if (phy_write(phydev, devad, MII_BMCR, BMCR_RESET) < 0) {
851 debug("PHY reset failed\n");
855 #ifdef CONFIG_PHY_RESET_DELAY
856 udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
859 * Poll the control register for the reset bit to go to 0 (it is
860 * auto-clearing). This should happen within 0.5 seconds per the
863 reg = phy_read(phydev, devad, MII_BMCR);
864 while ((reg & BMCR_RESET) && timeout--) {
865 reg = phy_read(phydev, devad, MII_BMCR);
868 debug("PHY status read failed\n");
874 if (reg & BMCR_RESET) {
875 puts("PHY reset timed out\n");
882 int miiphy_reset(const char *devname, unsigned char addr)
884 struct mii_dev *bus = miiphy_get_dev_by_name(devname);
885 struct phy_device *phydev;
888 * miiphy_reset was only used on standard PHYs, so we'll fake it here.
889 * If later code tries to connect with the right interface, this will
890 * be corrected by get_phy_device in phy_connect()
892 phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
894 return phy_reset(phydev);
897 struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
898 phy_interface_t interface)
904 /* Wait 15ms to make sure the PHY has come out of hard reset */
908 return get_phy_device_by_mask(bus, phy_mask, interface);
912 void phy_connect_dev(struct phy_device *phydev, struct udevice *dev)
914 void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
917 /* Soft Reset the PHY */
919 if (phydev->dev && phydev->dev != dev) {
920 printf("%s:%d is connected to %s. Reconnecting to %s\n",
921 phydev->bus->name, phydev->addr,
922 phydev->dev->name, dev->name);
925 debug("%s connected to %s\n", dev->name, phydev->drv->name);
928 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
930 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
932 phy_interface_t interface)
934 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
935 struct eth_device *dev,
936 phy_interface_t interface)
939 struct phy_device *phydev = NULL;
940 int sn = dev_of_offset(dev);
944 off = fdt_node_offset_by_compatible(gd->fdt_blob, sn,
945 "xlnx,gmii-to-rgmii-1.0");
947 phydev = phy_device_create(bus, off,
948 PHY_GMII2RGMII_ID, false,
952 if (off == -FDT_ERR_NOTFOUND)
953 sn = fdt_first_subnode(gd->fdt_blob, sn);
955 printf("%s: Error finding compat string:%d\n",
963 #ifdef CONFIG_PHY_FIXED
965 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
967 phy_interface_t interface)
969 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
970 struct eth_device *dev,
971 phy_interface_t interface)
974 struct phy_device *phydev = NULL;
978 sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
980 name = fdt_get_name(gd->fdt_blob, sn, NULL);
981 if (name && strcmp(name, "fixed-link") == 0) {
982 phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false,
986 sn = fdt_next_subnode(gd->fdt_blob, sn);
994 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
996 phy_interface_t interface)
998 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
999 struct eth_device *dev,
1000 phy_interface_t interface)
1003 struct phy_device *phydev = NULL;
1004 uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
1006 #ifdef CONFIG_PHY_FIXED
1007 phydev = phy_connect_fixed(bus, dev, interface);
1010 #ifdef CONFIG_PHY_NCSI
1012 phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface);
1015 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
1017 phydev = phy_connect_gmii2rgmii(bus, dev, interface);
1021 phydev = phy_find_by_mask(bus, mask, interface);
1024 phy_connect_dev(phydev, dev);
1026 printf("Could not get PHY for %s: addr %d\n", bus->name, addr);
1031 * Start the PHY. Returns 0 on success, or a negative error code.
1033 int phy_startup(struct phy_device *phydev)
1035 if (phydev->drv->startup)
1036 return phydev->drv->startup(phydev);
1041 __weak int board_phy_config(struct phy_device *phydev)
1043 if (phydev->drv->config)
1044 return phydev->drv->config(phydev);
1048 int phy_config(struct phy_device *phydev)
1050 /* Invoke an optional board-specific helper */
1051 return board_phy_config(phydev);
1054 int phy_shutdown(struct phy_device *phydev)
1056 if (phydev->drv->shutdown)
1057 phydev->drv->shutdown(phydev);
1062 int phy_get_interface_by_name(const char *str)
1066 for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
1067 if (!strcmp(str, phy_interface_strings[i]))