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/bitops.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/compiler.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 /* Generic PHY support and helper functions */
30 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
31 * @phydev: target phy_device struct
33 * Description: Writes MII_ADVERTISE with the appropriate values,
34 * after sanitizing the values to make sure we only advertise
35 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
36 * hasn't changed, and > 0 if it has changed.
38 static int genphy_config_advert(struct phy_device *phydev)
41 int oldadv, adv, bmsr;
44 /* Only allow advertising what this PHY supports */
45 phydev->advertising &= phydev->supported;
46 advertise = phydev->advertising;
48 /* Setup standard advertisement */
49 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
55 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
56 ADVERTISE_PAUSE_ASYM);
57 if (advertise & ADVERTISED_10baseT_Half)
58 adv |= ADVERTISE_10HALF;
59 if (advertise & ADVERTISED_10baseT_Full)
60 adv |= ADVERTISE_10FULL;
61 if (advertise & ADVERTISED_100baseT_Half)
62 adv |= ADVERTISE_100HALF;
63 if (advertise & ADVERTISED_100baseT_Full)
64 adv |= ADVERTISE_100FULL;
65 if (advertise & ADVERTISED_Pause)
66 adv |= ADVERTISE_PAUSE_CAP;
67 if (advertise & ADVERTISED_Asym_Pause)
68 adv |= ADVERTISE_PAUSE_ASYM;
69 if (advertise & ADVERTISED_1000baseX_Half)
70 adv |= ADVERTISE_1000XHALF;
71 if (advertise & ADVERTISED_1000baseX_Full)
72 adv |= ADVERTISE_1000XFULL;
75 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE, adv);
82 bmsr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
86 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all
87 * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a
90 if (!(bmsr & BMSR_ESTATEN))
93 /* Configure gigabit if it's supported */
94 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
100 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
102 if (phydev->supported & (SUPPORTED_1000baseT_Half |
103 SUPPORTED_1000baseT_Full)) {
104 if (advertise & SUPPORTED_1000baseT_Half)
105 adv |= ADVERTISE_1000HALF;
106 if (advertise & SUPPORTED_1000baseT_Full)
107 adv |= ADVERTISE_1000FULL;
113 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, adv);
121 * genphy_setup_forced - configures/forces speed/duplex from @phydev
122 * @phydev: target phy_device struct
124 * Description: Configures MII_BMCR to force speed/duplex
125 * to the values in phydev. Assumes that the values are valid.
127 static int genphy_setup_forced(struct phy_device *phydev)
130 int ctl = BMCR_ANRESTART;
133 phydev->asym_pause = 0;
135 if (phydev->speed == SPEED_1000)
136 ctl |= BMCR_SPEED1000;
137 else if (phydev->speed == SPEED_100)
138 ctl |= BMCR_SPEED100;
140 if (phydev->duplex == DUPLEX_FULL)
141 ctl |= BMCR_FULLDPLX;
143 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
149 * genphy_restart_aneg - Enable and Restart Autonegotiation
150 * @phydev: target phy_device struct
152 int genphy_restart_aneg(struct phy_device *phydev)
156 ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
161 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
163 /* Don't isolate the PHY if we're negotiating */
164 ctl &= ~(BMCR_ISOLATE);
166 ctl = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
172 * genphy_config_aneg - restart auto-negotiation or write BMCR
173 * @phydev: target phy_device struct
175 * Description: If auto-negotiation is enabled, we configure the
176 * advertising, and then restart auto-negotiation. If it is not
177 * enabled, then we write the BMCR.
179 int genphy_config_aneg(struct phy_device *phydev)
183 if (phydev->autoneg != AUTONEG_ENABLE)
184 return genphy_setup_forced(phydev);
186 result = genphy_config_advert(phydev);
188 if (result < 0) /* error */
193 * Advertisment hasn't changed, but maybe aneg was never on to
194 * begin with? Or maybe phy was isolated?
196 int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
201 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
202 result = 1; /* do restart aneg */
206 * Only restart aneg if we are advertising something different
207 * than we were before.
210 result = genphy_restart_aneg(phydev);
216 * genphy_update_link - update link status in @phydev
217 * @phydev: target phy_device struct
219 * Description: Update the value in phydev->link to reflect the
220 * current link value. In order to do this, we need to read
221 * the status register twice, keeping the second value.
223 int genphy_update_link(struct phy_device *phydev)
225 unsigned int mii_reg;
228 * Wait if the link is up, and autonegotiation is in progress
229 * (ie - we're capable and it's not done)
231 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
234 * If we already saw the link up, and it hasn't gone down, then
235 * we don't need to wait for autoneg again
237 if (phydev->link && mii_reg & BMSR_LSTATUS)
240 if ((phydev->autoneg == AUTONEG_ENABLE) &&
241 !(mii_reg & BMSR_ANEGCOMPLETE)) {
244 printf("%s Waiting for PHY auto negotiation to complete",
246 while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
250 if (i > (PHY_ANEG_TIMEOUT / 50)) {
251 printf(" TIMEOUT !\n");
257 puts("user interrupt!\n");
265 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
266 mdelay(50); /* 50 ms */
271 /* Read the link a second time to clear the latched state */
272 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
274 if (mii_reg & BMSR_LSTATUS)
284 * Generic function which updates the speed and duplex. If
285 * autonegotiation is enabled, it uses the AND of the link
286 * partner's advertised capabilities and our advertised
287 * capabilities. If autonegotiation is disabled, we use the
288 * appropriate bits in the control register.
290 * Stolen from Linux's mii.c and phy_device.c
292 int genphy_parse_link(struct phy_device *phydev)
294 int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
296 /* We're using autonegotiation */
297 if (phydev->autoneg == AUTONEG_ENABLE) {
302 /* Check for gigabit capability */
303 if (phydev->supported & (SUPPORTED_1000baseT_Full |
304 SUPPORTED_1000baseT_Half)) {
305 /* We want a list of states supported by
306 * both PHYs in the link
308 gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
310 debug("Could not read MII_STAT1000. ");
311 debug("Ignoring gigabit capability\n");
314 gblpa &= phy_read(phydev,
315 MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
318 /* Set the baseline so we only have to set them
319 * if they're different
321 phydev->speed = SPEED_10;
322 phydev->duplex = DUPLEX_HALF;
324 /* Check the gigabit fields */
325 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
326 phydev->speed = SPEED_1000;
328 if (gblpa & PHY_1000BTSR_1000FD)
329 phydev->duplex = DUPLEX_FULL;
335 lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
336 lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
338 if (lpa & (LPA_100FULL | LPA_100HALF)) {
339 phydev->speed = SPEED_100;
341 if (lpa & LPA_100FULL)
342 phydev->duplex = DUPLEX_FULL;
344 } else if (lpa & LPA_10FULL) {
345 phydev->duplex = DUPLEX_FULL;
349 * Extended status may indicate that the PHY supports
350 * 1000BASE-T/X even though the 1000BASE-T registers
351 * are missing. In this case we can't tell whether the
352 * peer also supports it, so we only check extended
353 * status if the 1000BASE-T registers are actually
356 if ((mii_reg & BMSR_ESTATEN) && !(mii_reg & BMSR_ERCAP))
357 estatus = phy_read(phydev, MDIO_DEVAD_NONE,
360 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_XHALF |
361 ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
362 phydev->speed = SPEED_1000;
363 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_TFULL))
364 phydev->duplex = DUPLEX_FULL;
368 u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
370 phydev->speed = SPEED_10;
371 phydev->duplex = DUPLEX_HALF;
373 if (bmcr & BMCR_FULLDPLX)
374 phydev->duplex = DUPLEX_FULL;
376 if (bmcr & BMCR_SPEED1000)
377 phydev->speed = SPEED_1000;
378 else if (bmcr & BMCR_SPEED100)
379 phydev->speed = SPEED_100;
385 int genphy_config(struct phy_device *phydev)
390 features = (SUPPORTED_TP | SUPPORTED_MII
391 | SUPPORTED_AUI | SUPPORTED_FIBRE |
394 /* Do we support autonegotiation? */
395 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
400 if (val & BMSR_ANEGCAPABLE)
401 features |= SUPPORTED_Autoneg;
403 if (val & BMSR_100FULL)
404 features |= SUPPORTED_100baseT_Full;
405 if (val & BMSR_100HALF)
406 features |= SUPPORTED_100baseT_Half;
407 if (val & BMSR_10FULL)
408 features |= SUPPORTED_10baseT_Full;
409 if (val & BMSR_10HALF)
410 features |= SUPPORTED_10baseT_Half;
412 if (val & BMSR_ESTATEN) {
413 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_ESTATUS);
418 if (val & ESTATUS_1000_TFULL)
419 features |= SUPPORTED_1000baseT_Full;
420 if (val & ESTATUS_1000_THALF)
421 features |= SUPPORTED_1000baseT_Half;
422 if (val & ESTATUS_1000_XFULL)
423 features |= SUPPORTED_1000baseX_Full;
424 if (val & ESTATUS_1000_XHALF)
425 features |= SUPPORTED_1000baseX_Half;
428 phydev->supported &= features;
429 phydev->advertising &= features;
431 genphy_config_aneg(phydev);
436 int genphy_startup(struct phy_device *phydev)
440 ret = genphy_update_link(phydev);
444 return genphy_parse_link(phydev);
447 int genphy_shutdown(struct phy_device *phydev)
452 static struct phy_driver genphy_driver = {
455 .name = "Generic PHY",
456 .features = PHY_GBIT_FEATURES | SUPPORTED_MII |
457 SUPPORTED_AUI | SUPPORTED_FIBRE |
459 .config = genphy_config,
460 .startup = genphy_startup,
461 .shutdown = genphy_shutdown,
464 int genphy_init(void)
466 return phy_register(&genphy_driver);
469 static LIST_HEAD(phy_drivers);
473 #ifdef CONFIG_NEEDS_MANUAL_RELOC
475 * The pointers inside phy_drivers also needs to be updated incase of
476 * manual reloc, without which these points to some invalid
477 * pre reloc address and leads to invalid accesses, hangs.
479 struct list_head *head = &phy_drivers;
481 head->next = (void *)head->next + gd->reloc_off;
482 head->prev = (void *)head->prev + gd->reloc_off;
485 #ifdef CONFIG_B53_SWITCH
488 #ifdef CONFIG_MV88E61XX_SWITCH
489 phy_mv88e61xx_init();
491 #ifdef CONFIG_PHY_AQUANTIA
494 #ifdef CONFIG_PHY_ATHEROS
497 #ifdef CONFIG_PHY_BROADCOM
500 #ifdef CONFIG_PHY_CORTINA
503 #ifdef CONFIG_PHY_DAVICOM
506 #ifdef CONFIG_PHY_ET1011C
509 #ifdef CONFIG_PHY_LXT
512 #ifdef CONFIG_PHY_MARVELL
515 #ifdef CONFIG_PHY_MICREL_KSZ8XXX
516 phy_micrel_ksz8xxx_init();
518 #ifdef CONFIG_PHY_MICREL_KSZ90X1
519 phy_micrel_ksz90x1_init();
521 #ifdef CONFIG_PHY_MESON_GXL
522 phy_meson_gxl_init();
524 #ifdef CONFIG_PHY_NATSEMI
527 #ifdef CONFIG_PHY_REALTEK
530 #ifdef CONFIG_PHY_SMSC
533 #ifdef CONFIG_PHY_TERANETICS
534 phy_teranetics_init();
539 #ifdef CONFIG_PHY_VITESSE
542 #ifdef CONFIG_PHY_XILINX
545 #ifdef CONFIG_PHY_MSCC
548 #ifdef CONFIG_PHY_FIXED
551 #ifdef CONFIG_PHY_NCSI
554 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
555 phy_xilinx_gmii2rgmii_init();
562 int phy_register(struct phy_driver *drv)
564 INIT_LIST_HEAD(&drv->list);
565 list_add_tail(&drv->list, &phy_drivers);
567 #ifdef CONFIG_NEEDS_MANUAL_RELOC
569 drv->probe += gd->reloc_off;
571 drv->config += gd->reloc_off;
573 drv->startup += gd->reloc_off;
575 drv->shutdown += gd->reloc_off;
577 drv->readext += gd->reloc_off;
579 drv->writeext += gd->reloc_off;
581 drv->read_mmd += gd->reloc_off;
583 drv->write_mmd += gd->reloc_off;
588 int phy_set_supported(struct phy_device *phydev, u32 max_speed)
590 /* The default values for phydev->supported are provided by the PHY
591 * driver "features" member, we want to reset to sane defaults first
592 * before supporting higher speeds.
594 phydev->supported &= PHY_DEFAULT_FEATURES;
600 phydev->supported |= PHY_1000BT_FEATURES;
603 phydev->supported |= PHY_100BT_FEATURES;
606 phydev->supported |= PHY_10BT_FEATURES;
612 static int phy_probe(struct phy_device *phydev)
616 phydev->advertising = phydev->drv->features;
617 phydev->supported = phydev->drv->features;
619 phydev->mmds = phydev->drv->mmds;
621 if (phydev->drv->probe)
622 err = phydev->drv->probe(phydev);
627 static struct phy_driver *generic_for_interface(phy_interface_t interface)
629 #ifdef CONFIG_PHYLIB_10G
630 if (is_10g_interface(interface))
631 return &gen10g_driver;
634 return &genphy_driver;
637 static struct phy_driver *get_phy_driver(struct phy_device *phydev,
638 phy_interface_t interface)
640 struct list_head *entry;
641 int phy_id = phydev->phy_id;
642 struct phy_driver *drv = NULL;
644 list_for_each(entry, &phy_drivers) {
645 drv = list_entry(entry, struct phy_driver, list);
646 if ((drv->uid & drv->mask) == (phy_id & drv->mask))
650 /* If we made it here, there's no driver for this PHY */
651 return generic_for_interface(interface);
654 static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
655 u32 phy_id, bool is_c45,
656 phy_interface_t interface)
658 struct phy_device *dev;
661 * We allocate the device, and initialize the
664 dev = malloc(sizeof(*dev));
666 printf("Failed to allocate PHY device for %s:%d\n",
671 memset(dev, 0, sizeof(*dev));
675 dev->interface = interface;
678 dev->node = ofnode_null();
681 dev->autoneg = AUTONEG_ENABLE;
684 dev->phy_id = phy_id;
685 dev->is_c45 = is_c45;
688 dev->drv = get_phy_driver(dev, interface);
690 if (phy_probe(dev)) {
691 printf("%s, PHY probe failed\n", __func__);
695 if (addr >= 0 && addr < PHY_MAX_ADDR)
696 bus->phymap[addr] = dev;
702 * get_phy_id - reads the specified addr for its ID.
703 * @bus: the target MII bus
704 * @addr: PHY address on the MII bus
705 * @phy_id: where to store the ID retrieved.
707 * Description: Reads the ID registers of the PHY at @addr on the
708 * @bus, stores it in @phy_id and returns zero on success.
710 int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
715 * Grab the bits from PHYIR1, and put them
718 phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
723 *phy_id = (phy_reg & 0xffff) << 16;
725 /* Grab the bits from PHYIR2, and put them in the lower half */
726 phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
731 *phy_id |= (phy_reg & 0xffff);
736 static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
737 uint phy_mask, int devad,
738 phy_interface_t interface)
740 u32 phy_id = 0xffffffff;
744 int addr = ffs(phy_mask) - 1;
745 int r = get_phy_id(bus, addr, devad, &phy_id);
748 * If the PHY ID is flat 0 we ignore it. There are C45 PHYs
749 * that return all 0s for C22 reads (like Aquantia AQR112) and
750 * there are C22 PHYs that return all 0s for C45 reads (like
753 if (r == 0 && phy_id == 0)
756 /* If the PHY ID is mostly f's, we didn't find anything */
757 if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) {
758 is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true;
759 return phy_device_create(bus, addr, phy_id, is_c45,
763 phy_mask &= ~(1 << addr);
768 static struct phy_device *search_for_existing_phy(struct mii_dev *bus,
770 phy_interface_t interface)
772 /* If we have one, return the existing device, with new interface */
774 int addr = ffs(phy_mask) - 1;
776 if (bus->phymap[addr]) {
777 bus->phymap[addr]->interface = interface;
778 return bus->phymap[addr];
780 phy_mask &= ~(1 << addr);
785 static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
787 phy_interface_t interface)
790 struct phy_device *phydev;
792 phydev = search_for_existing_phy(bus, phy_mask, interface);
795 /* Try Standard (ie Clause 22) access */
796 /* Otherwise we have to try Clause 45 */
797 for (i = 0; i < 5; i++) {
798 phydev = create_phy_by_mask(bus, phy_mask,
799 i ? i : MDIO_DEVAD_NONE, interface);
806 debug("\n%s PHY: ", bus->name);
808 int addr = ffs(phy_mask) - 1;
811 phy_mask &= ~(1 << addr);
813 debug("not found\n");
819 * get_phy_device - reads the specified PHY device and returns its
821 * @bus: the target MII bus
822 * @addr: PHY address on the MII bus
824 * Description: Reads the ID registers of the PHY at @addr on the
825 * @bus, then allocates and returns the phy_device to represent it.
827 static struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
828 phy_interface_t interface)
830 return get_phy_device_by_mask(bus, 1 << addr, interface);
833 int phy_reset(struct phy_device *phydev)
837 int devad = MDIO_DEVAD_NONE;
839 if (phydev->flags & PHY_FLAG_BROKEN_RESET)
842 #ifdef CONFIG_PHYLIB_10G
843 /* If it's 10G, we need to issue reset through one of the MMDs */
844 if (is_10g_interface(phydev->interface)) {
846 gen10g_discover_mmds(phydev);
848 devad = ffs(phydev->mmds) - 1;
852 if (phy_write(phydev, devad, MII_BMCR, BMCR_RESET) < 0) {
853 debug("PHY reset failed\n");
857 #ifdef CONFIG_PHY_RESET_DELAY
858 udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
861 * Poll the control register for the reset bit to go to 0 (it is
862 * auto-clearing). This should happen within 0.5 seconds per the
865 reg = phy_read(phydev, devad, MII_BMCR);
866 while ((reg & BMCR_RESET) && timeout--) {
867 reg = phy_read(phydev, devad, MII_BMCR);
870 debug("PHY status read failed\n");
876 if (reg & BMCR_RESET) {
877 puts("PHY reset timed out\n");
884 int miiphy_reset(const char *devname, unsigned char addr)
886 struct mii_dev *bus = miiphy_get_dev_by_name(devname);
887 struct phy_device *phydev;
890 * miiphy_reset was only used on standard PHYs, so we'll fake it here.
891 * If later code tries to connect with the right interface, this will
892 * be corrected by get_phy_device in phy_connect()
894 phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
896 return phy_reset(phydev);
899 struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
900 phy_interface_t interface)
906 /* Wait 15ms to make sure the PHY has come out of hard reset */
910 return get_phy_device_by_mask(bus, phy_mask, interface);
914 void phy_connect_dev(struct phy_device *phydev, struct udevice *dev)
916 void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
919 /* Soft Reset the PHY */
921 if (phydev->dev && phydev->dev != dev) {
922 printf("%s:%d is connected to %s. Reconnecting to %s\n",
923 phydev->bus->name, phydev->addr,
924 phydev->dev->name, dev->name);
927 debug("%s connected to %s\n", dev->name, phydev->drv->name);
930 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
932 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
934 phy_interface_t interface)
936 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
937 struct eth_device *dev,
938 phy_interface_t interface)
941 struct phy_device *phydev = NULL;
942 int sn = dev_of_offset(dev);
946 off = fdt_node_offset_by_compatible(gd->fdt_blob, sn,
947 "xlnx,gmii-to-rgmii-1.0");
949 phydev = phy_device_create(bus, off,
950 PHY_GMII2RGMII_ID, false,
954 if (off == -FDT_ERR_NOTFOUND)
955 sn = fdt_first_subnode(gd->fdt_blob, sn);
957 printf("%s: Error finding compat string:%d\n",
965 #ifdef CONFIG_PHY_FIXED
967 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
969 phy_interface_t interface)
971 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
972 struct eth_device *dev,
973 phy_interface_t interface)
976 struct phy_device *phydev = NULL;
980 sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
982 name = fdt_get_name(gd->fdt_blob, sn, NULL);
983 if (name && strcmp(name, "fixed-link") == 0) {
984 phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false,
988 sn = fdt_next_subnode(gd->fdt_blob, sn);
996 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
998 phy_interface_t interface)
1000 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
1001 struct eth_device *dev,
1002 phy_interface_t interface)
1005 struct phy_device *phydev = NULL;
1006 uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
1008 #ifdef CONFIG_PHY_FIXED
1009 phydev = phy_connect_fixed(bus, dev, interface);
1012 #ifdef CONFIG_PHY_NCSI
1014 phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface);
1017 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
1019 phydev = phy_connect_gmii2rgmii(bus, dev, interface);
1023 phydev = phy_find_by_mask(bus, mask, interface);
1026 phy_connect_dev(phydev, dev);
1028 printf("Could not get PHY for %s: addr %d\n", bus->name, addr);
1033 * Start the PHY. Returns 0 on success, or a negative error code.
1035 int phy_startup(struct phy_device *phydev)
1037 if (phydev->drv->startup)
1038 return phydev->drv->startup(phydev);
1043 __weak int board_phy_config(struct phy_device *phydev)
1045 if (phydev->drv->config)
1046 return phydev->drv->config(phydev);
1050 int phy_config(struct phy_device *phydev)
1052 /* Invoke an optional board-specific helper */
1053 return board_phy_config(phydev);
1056 int phy_shutdown(struct phy_device *phydev)
1058 if (phydev->drv->shutdown)
1059 phydev->drv->shutdown(phydev);
1064 int phy_get_interface_by_name(const char *str)
1068 for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
1069 if (!strcmp(str, phy_interface_strings[i]))