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/delay.h>
21 #include <linux/err.h>
22 #include <linux/compiler.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 /* Generic PHY support and helper functions */
29 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
30 * @phydev: target phy_device struct
32 * Description: Writes MII_ADVERTISE with the appropriate values,
33 * after sanitizing the values to make sure we only advertise
34 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
35 * hasn't changed, and > 0 if it has changed.
37 static int genphy_config_advert(struct phy_device *phydev)
40 int oldadv, adv, bmsr;
43 /* Only allow advertising what this PHY supports */
44 phydev->advertising &= phydev->supported;
45 advertise = phydev->advertising;
47 /* Setup standard advertisement */
48 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
54 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP |
55 ADVERTISE_PAUSE_ASYM);
56 if (advertise & ADVERTISED_10baseT_Half)
57 adv |= ADVERTISE_10HALF;
58 if (advertise & ADVERTISED_10baseT_Full)
59 adv |= ADVERTISE_10FULL;
60 if (advertise & ADVERTISED_100baseT_Half)
61 adv |= ADVERTISE_100HALF;
62 if (advertise & ADVERTISED_100baseT_Full)
63 adv |= ADVERTISE_100FULL;
64 if (advertise & ADVERTISED_Pause)
65 adv |= ADVERTISE_PAUSE_CAP;
66 if (advertise & ADVERTISED_Asym_Pause)
67 adv |= ADVERTISE_PAUSE_ASYM;
68 if (advertise & ADVERTISED_1000baseX_Half)
69 adv |= ADVERTISE_1000XHALF;
70 if (advertise & ADVERTISED_1000baseX_Full)
71 adv |= ADVERTISE_1000XFULL;
74 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE, adv);
81 bmsr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
85 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all
86 * 1000Mbits/sec capable PHYs shall have the BMSR_ESTATEN bit set to a
89 if (!(bmsr & BMSR_ESTATEN))
92 /* Configure gigabit if it's supported */
93 adv = phy_read(phydev, MDIO_DEVAD_NONE, MII_CTRL1000);
99 adv &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
101 if (phydev->supported & (SUPPORTED_1000baseT_Half |
102 SUPPORTED_1000baseT_Full)) {
103 if (advertise & SUPPORTED_1000baseT_Half)
104 adv |= ADVERTISE_1000HALF;
105 if (advertise & SUPPORTED_1000baseT_Full)
106 adv |= ADVERTISE_1000FULL;
112 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, adv);
120 * genphy_setup_forced - configures/forces speed/duplex from @phydev
121 * @phydev: target phy_device struct
123 * Description: Configures MII_BMCR to force speed/duplex
124 * to the values in phydev. Assumes that the values are valid.
126 static int genphy_setup_forced(struct phy_device *phydev)
129 int ctl = BMCR_ANRESTART;
132 phydev->asym_pause = 0;
134 if (phydev->speed == SPEED_1000)
135 ctl |= BMCR_SPEED1000;
136 else if (phydev->speed == SPEED_100)
137 ctl |= BMCR_SPEED100;
139 if (phydev->duplex == DUPLEX_FULL)
140 ctl |= BMCR_FULLDPLX;
142 err = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
148 * genphy_restart_aneg - Enable and Restart Autonegotiation
149 * @phydev: target phy_device struct
151 int genphy_restart_aneg(struct phy_device *phydev)
155 ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
160 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
162 /* Don't isolate the PHY if we're negotiating */
163 ctl &= ~(BMCR_ISOLATE);
165 ctl = phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, ctl);
171 * genphy_config_aneg - restart auto-negotiation or write BMCR
172 * @phydev: target phy_device struct
174 * Description: If auto-negotiation is enabled, we configure the
175 * advertising, and then restart auto-negotiation. If it is not
176 * enabled, then we write the BMCR.
178 int genphy_config_aneg(struct phy_device *phydev)
182 if (phydev->autoneg != AUTONEG_ENABLE)
183 return genphy_setup_forced(phydev);
185 result = genphy_config_advert(phydev);
187 if (result < 0) /* error */
192 * Advertisment hasn't changed, but maybe aneg was never on to
193 * begin with? Or maybe phy was isolated?
195 int ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
200 if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
201 result = 1; /* do restart aneg */
205 * Only restart aneg if we are advertising something different
206 * than we were before.
209 result = genphy_restart_aneg(phydev);
215 * genphy_update_link - update link status in @phydev
216 * @phydev: target phy_device struct
218 * Description: Update the value in phydev->link to reflect the
219 * current link value. In order to do this, we need to read
220 * the status register twice, keeping the second value.
222 int genphy_update_link(struct phy_device *phydev)
224 unsigned int mii_reg;
227 * Wait if the link is up, and autonegotiation is in progress
228 * (ie - we're capable and it's not done)
230 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
233 * If we already saw the link up, and it hasn't gone down, then
234 * we don't need to wait for autoneg again
236 if (phydev->link && mii_reg & BMSR_LSTATUS)
239 if ((phydev->autoneg == AUTONEG_ENABLE) &&
240 !(mii_reg & BMSR_ANEGCOMPLETE)) {
243 printf("%s Waiting for PHY auto negotiation to complete",
245 while (!(mii_reg & BMSR_ANEGCOMPLETE)) {
249 if (i > (PHY_ANEG_TIMEOUT / 50)) {
250 printf(" TIMEOUT !\n");
256 puts("user interrupt!\n");
264 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
265 mdelay(50); /* 50 ms */
270 /* Read the link a second time to clear the latched state */
271 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
273 if (mii_reg & BMSR_LSTATUS)
283 * Generic function which updates the speed and duplex. If
284 * autonegotiation is enabled, it uses the AND of the link
285 * partner's advertised capabilities and our advertised
286 * capabilities. If autonegotiation is disabled, we use the
287 * appropriate bits in the control register.
289 * Stolen from Linux's mii.c and phy_device.c
291 int genphy_parse_link(struct phy_device *phydev)
293 int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
295 /* We're using autonegotiation */
296 if (phydev->autoneg == AUTONEG_ENABLE) {
301 /* Check for gigabit capability */
302 if (phydev->supported & (SUPPORTED_1000baseT_Full |
303 SUPPORTED_1000baseT_Half)) {
304 /* We want a list of states supported by
305 * both PHYs in the link
307 gblpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_STAT1000);
309 debug("Could not read MII_STAT1000. ");
310 debug("Ignoring gigabit capability\n");
313 gblpa &= phy_read(phydev,
314 MDIO_DEVAD_NONE, MII_CTRL1000) << 2;
317 /* Set the baseline so we only have to set them
318 * if they're different
320 phydev->speed = SPEED_10;
321 phydev->duplex = DUPLEX_HALF;
323 /* Check the gigabit fields */
324 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
325 phydev->speed = SPEED_1000;
327 if (gblpa & PHY_1000BTSR_1000FD)
328 phydev->duplex = DUPLEX_FULL;
334 lpa = phy_read(phydev, MDIO_DEVAD_NONE, MII_ADVERTISE);
335 lpa &= phy_read(phydev, MDIO_DEVAD_NONE, MII_LPA);
337 if (lpa & (LPA_100FULL | LPA_100HALF)) {
338 phydev->speed = SPEED_100;
340 if (lpa & LPA_100FULL)
341 phydev->duplex = DUPLEX_FULL;
343 } else if (lpa & LPA_10FULL) {
344 phydev->duplex = DUPLEX_FULL;
348 * Extended status may indicate that the PHY supports
349 * 1000BASE-T/X even though the 1000BASE-T registers
350 * are missing. In this case we can't tell whether the
351 * peer also supports it, so we only check extended
352 * status if the 1000BASE-T registers are actually
355 if ((mii_reg & BMSR_ESTATEN) && !(mii_reg & BMSR_ERCAP))
356 estatus = phy_read(phydev, MDIO_DEVAD_NONE,
359 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_XHALF |
360 ESTATUS_1000_TFULL | ESTATUS_1000_THALF)) {
361 phydev->speed = SPEED_1000;
362 if (estatus & (ESTATUS_1000_XFULL | ESTATUS_1000_TFULL))
363 phydev->duplex = DUPLEX_FULL;
367 u32 bmcr = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
369 phydev->speed = SPEED_10;
370 phydev->duplex = DUPLEX_HALF;
372 if (bmcr & BMCR_FULLDPLX)
373 phydev->duplex = DUPLEX_FULL;
375 if (bmcr & BMCR_SPEED1000)
376 phydev->speed = SPEED_1000;
377 else if (bmcr & BMCR_SPEED100)
378 phydev->speed = SPEED_100;
384 int genphy_config(struct phy_device *phydev)
389 features = (SUPPORTED_TP | SUPPORTED_MII
390 | SUPPORTED_AUI | SUPPORTED_FIBRE |
393 /* Do we support autonegotiation? */
394 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
399 if (val & BMSR_ANEGCAPABLE)
400 features |= SUPPORTED_Autoneg;
402 if (val & BMSR_100FULL)
403 features |= SUPPORTED_100baseT_Full;
404 if (val & BMSR_100HALF)
405 features |= SUPPORTED_100baseT_Half;
406 if (val & BMSR_10FULL)
407 features |= SUPPORTED_10baseT_Full;
408 if (val & BMSR_10HALF)
409 features |= SUPPORTED_10baseT_Half;
411 if (val & BMSR_ESTATEN) {
412 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_ESTATUS);
417 if (val & ESTATUS_1000_TFULL)
418 features |= SUPPORTED_1000baseT_Full;
419 if (val & ESTATUS_1000_THALF)
420 features |= SUPPORTED_1000baseT_Half;
421 if (val & ESTATUS_1000_XFULL)
422 features |= SUPPORTED_1000baseX_Full;
423 if (val & ESTATUS_1000_XHALF)
424 features |= SUPPORTED_1000baseX_Half;
427 phydev->supported &= features;
428 phydev->advertising &= features;
430 genphy_config_aneg(phydev);
435 int genphy_startup(struct phy_device *phydev)
439 ret = genphy_update_link(phydev);
443 return genphy_parse_link(phydev);
446 int genphy_shutdown(struct phy_device *phydev)
451 static struct phy_driver genphy_driver = {
454 .name = "Generic PHY",
455 .features = PHY_GBIT_FEATURES | SUPPORTED_MII |
456 SUPPORTED_AUI | SUPPORTED_FIBRE |
458 .config = genphy_config,
459 .startup = genphy_startup,
460 .shutdown = genphy_shutdown,
463 int genphy_init(void)
465 return phy_register(&genphy_driver);
468 static LIST_HEAD(phy_drivers);
472 #ifdef CONFIG_NEEDS_MANUAL_RELOC
474 * The pointers inside phy_drivers also needs to be updated incase of
475 * manual reloc, without which these points to some invalid
476 * pre reloc address and leads to invalid accesses, hangs.
478 struct list_head *head = &phy_drivers;
480 head->next = (void *)head->next + gd->reloc_off;
481 head->prev = (void *)head->prev + gd->reloc_off;
484 #ifdef CONFIG_B53_SWITCH
487 #ifdef CONFIG_MV88E61XX_SWITCH
488 phy_mv88e61xx_init();
490 #ifdef CONFIG_PHY_AQUANTIA
493 #ifdef CONFIG_PHY_ATHEROS
496 #ifdef CONFIG_PHY_BROADCOM
499 #ifdef CONFIG_PHY_CORTINA
502 #ifdef CONFIG_PHY_DAVICOM
505 #ifdef CONFIG_PHY_ET1011C
508 #ifdef CONFIG_PHY_LXT
511 #ifdef CONFIG_PHY_MARVELL
514 #ifdef CONFIG_PHY_MICREL_KSZ8XXX
515 phy_micrel_ksz8xxx_init();
517 #ifdef CONFIG_PHY_MICREL_KSZ90X1
518 phy_micrel_ksz90x1_init();
520 #ifdef CONFIG_PHY_MESON_GXL
521 phy_meson_gxl_init();
523 #ifdef CONFIG_PHY_NATSEMI
526 #ifdef CONFIG_PHY_REALTEK
529 #ifdef CONFIG_PHY_SMSC
532 #ifdef CONFIG_PHY_TERANETICS
533 phy_teranetics_init();
538 #ifdef CONFIG_PHY_VITESSE
541 #ifdef CONFIG_PHY_XILINX
544 #ifdef CONFIG_PHY_MSCC
547 #ifdef CONFIG_PHY_FIXED
550 #ifdef CONFIG_PHY_NCSI
553 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
554 phy_xilinx_gmii2rgmii_init();
561 int phy_register(struct phy_driver *drv)
563 INIT_LIST_HEAD(&drv->list);
564 list_add_tail(&drv->list, &phy_drivers);
566 #ifdef CONFIG_NEEDS_MANUAL_RELOC
568 drv->probe += gd->reloc_off;
570 drv->config += gd->reloc_off;
572 drv->startup += gd->reloc_off;
574 drv->shutdown += gd->reloc_off;
576 drv->readext += gd->reloc_off;
578 drv->writeext += gd->reloc_off;
580 drv->read_mmd += gd->reloc_off;
582 drv->write_mmd += gd->reloc_off;
587 int phy_set_supported(struct phy_device *phydev, u32 max_speed)
589 /* The default values for phydev->supported are provided by the PHY
590 * driver "features" member, we want to reset to sane defaults first
591 * before supporting higher speeds.
593 phydev->supported &= PHY_DEFAULT_FEATURES;
599 phydev->supported |= PHY_1000BT_FEATURES;
602 phydev->supported |= PHY_100BT_FEATURES;
605 phydev->supported |= PHY_10BT_FEATURES;
611 static int phy_probe(struct phy_device *phydev)
615 phydev->advertising = phydev->drv->features;
616 phydev->supported = phydev->drv->features;
618 phydev->mmds = phydev->drv->mmds;
620 if (phydev->drv->probe)
621 err = phydev->drv->probe(phydev);
626 static struct phy_driver *generic_for_interface(phy_interface_t interface)
628 #ifdef CONFIG_PHYLIB_10G
629 if (is_10g_interface(interface))
630 return &gen10g_driver;
633 return &genphy_driver;
636 static struct phy_driver *get_phy_driver(struct phy_device *phydev,
637 phy_interface_t interface)
639 struct list_head *entry;
640 int phy_id = phydev->phy_id;
641 struct phy_driver *drv = NULL;
643 list_for_each(entry, &phy_drivers) {
644 drv = list_entry(entry, struct phy_driver, list);
645 if ((drv->uid & drv->mask) == (phy_id & drv->mask))
649 /* If we made it here, there's no driver for this PHY */
650 return generic_for_interface(interface);
653 static struct phy_device *phy_device_create(struct mii_dev *bus, int addr,
654 u32 phy_id, bool is_c45,
655 phy_interface_t interface)
657 struct phy_device *dev;
660 * We allocate the device, and initialize the
663 dev = malloc(sizeof(*dev));
665 printf("Failed to allocate PHY device for %s:%d\n",
670 memset(dev, 0, sizeof(*dev));
674 dev->interface = interface;
677 dev->node = ofnode_null();
680 dev->autoneg = AUTONEG_ENABLE;
683 dev->phy_id = phy_id;
684 dev->is_c45 = is_c45;
687 dev->drv = get_phy_driver(dev, interface);
689 if (phy_probe(dev)) {
690 printf("%s, PHY probe failed\n", __func__);
694 if (addr >= 0 && addr < PHY_MAX_ADDR)
695 bus->phymap[addr] = dev;
701 * get_phy_id - reads the specified addr for its ID.
702 * @bus: the target MII bus
703 * @addr: PHY address on the MII bus
704 * @phy_id: where to store the ID retrieved.
706 * Description: Reads the ID registers of the PHY at @addr on the
707 * @bus, stores it in @phy_id and returns zero on success.
709 int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
714 * Grab the bits from PHYIR1, and put them
717 phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
722 *phy_id = (phy_reg & 0xffff) << 16;
724 /* Grab the bits from PHYIR2, and put them in the lower half */
725 phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
730 *phy_id |= (phy_reg & 0xffff);
735 static struct phy_device *create_phy_by_mask(struct mii_dev *bus,
736 uint phy_mask, int devad,
737 phy_interface_t interface)
739 u32 phy_id = 0xffffffff;
743 int addr = ffs(phy_mask) - 1;
744 int r = get_phy_id(bus, addr, devad, &phy_id);
747 * If the PHY ID is flat 0 we ignore it. There are C45 PHYs
748 * that return all 0s for C22 reads (like Aquantia AQR112) and
749 * there are C22 PHYs that return all 0s for C45 reads (like
752 if (r == 0 && phy_id == 0)
755 /* If the PHY ID is mostly f's, we didn't find anything */
756 if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) {
757 is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true;
758 return phy_device_create(bus, addr, phy_id, is_c45,
762 phy_mask &= ~(1 << addr);
767 static struct phy_device *search_for_existing_phy(struct mii_dev *bus,
769 phy_interface_t interface)
771 /* If we have one, return the existing device, with new interface */
773 int addr = ffs(phy_mask) - 1;
775 if (bus->phymap[addr]) {
776 bus->phymap[addr]->interface = interface;
777 return bus->phymap[addr];
779 phy_mask &= ~(1 << addr);
784 static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus,
786 phy_interface_t interface)
789 struct phy_device *phydev;
791 phydev = search_for_existing_phy(bus, phy_mask, interface);
794 /* Try Standard (ie Clause 22) access */
795 /* Otherwise we have to try Clause 45 */
796 for (i = 0; i < 5; i++) {
797 phydev = create_phy_by_mask(bus, phy_mask,
798 i ? i : MDIO_DEVAD_NONE, interface);
805 debug("\n%s PHY: ", bus->name);
807 int addr = ffs(phy_mask) - 1;
810 phy_mask &= ~(1 << addr);
812 debug("not found\n");
818 * get_phy_device - reads the specified PHY device and returns its
820 * @bus: the target MII bus
821 * @addr: PHY address on the MII bus
823 * Description: Reads the ID registers of the PHY at @addr on the
824 * @bus, then allocates and returns the phy_device to represent it.
826 static struct phy_device *get_phy_device(struct mii_dev *bus, int addr,
827 phy_interface_t interface)
829 return get_phy_device_by_mask(bus, 1 << addr, interface);
832 int phy_reset(struct phy_device *phydev)
836 int devad = MDIO_DEVAD_NONE;
838 if (phydev->flags & PHY_FLAG_BROKEN_RESET)
841 #ifdef CONFIG_PHYLIB_10G
842 /* If it's 10G, we need to issue reset through one of the MMDs */
843 if (is_10g_interface(phydev->interface)) {
845 gen10g_discover_mmds(phydev);
847 devad = ffs(phydev->mmds) - 1;
851 if (phy_write(phydev, devad, MII_BMCR, BMCR_RESET) < 0) {
852 debug("PHY reset failed\n");
856 #ifdef CONFIG_PHY_RESET_DELAY
857 udelay(CONFIG_PHY_RESET_DELAY); /* Intel LXT971A needs this */
860 * Poll the control register for the reset bit to go to 0 (it is
861 * auto-clearing). This should happen within 0.5 seconds per the
864 reg = phy_read(phydev, devad, MII_BMCR);
865 while ((reg & BMCR_RESET) && timeout--) {
866 reg = phy_read(phydev, devad, MII_BMCR);
869 debug("PHY status read failed\n");
875 if (reg & BMCR_RESET) {
876 puts("PHY reset timed out\n");
883 int miiphy_reset(const char *devname, unsigned char addr)
885 struct mii_dev *bus = miiphy_get_dev_by_name(devname);
886 struct phy_device *phydev;
889 * miiphy_reset was only used on standard PHYs, so we'll fake it here.
890 * If later code tries to connect with the right interface, this will
891 * be corrected by get_phy_device in phy_connect()
893 phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII);
895 return phy_reset(phydev);
898 struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask,
899 phy_interface_t interface)
905 /* Wait 15ms to make sure the PHY has come out of hard reset */
909 return get_phy_device_by_mask(bus, phy_mask, interface);
913 void phy_connect_dev(struct phy_device *phydev, struct udevice *dev)
915 void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev)
918 /* Soft Reset the PHY */
920 if (phydev->dev && phydev->dev != dev) {
921 printf("%s:%d is connected to %s. Reconnecting to %s\n",
922 phydev->bus->name, phydev->addr,
923 phydev->dev->name, dev->name);
926 debug("%s connected to %s\n", dev->name, phydev->drv->name);
929 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
931 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
933 phy_interface_t interface)
935 static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
936 struct eth_device *dev,
937 phy_interface_t interface)
940 struct phy_device *phydev = NULL;
941 int sn = dev_of_offset(dev);
945 off = fdt_node_offset_by_compatible(gd->fdt_blob, sn,
946 "xlnx,gmii-to-rgmii-1.0");
948 phydev = phy_device_create(bus, off,
949 PHY_GMII2RGMII_ID, false,
953 if (off == -FDT_ERR_NOTFOUND)
954 sn = fdt_first_subnode(gd->fdt_blob, sn);
956 printf("%s: Error finding compat string:%d\n",
964 #ifdef CONFIG_PHY_FIXED
966 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
968 phy_interface_t interface)
970 static struct phy_device *phy_connect_fixed(struct mii_dev *bus,
971 struct eth_device *dev,
972 phy_interface_t interface)
975 struct phy_device *phydev = NULL;
979 sn = fdt_first_subnode(gd->fdt_blob, dev_of_offset(dev));
981 name = fdt_get_name(gd->fdt_blob, sn, NULL);
982 if (name && strcmp(name, "fixed-link") == 0) {
983 phydev = phy_device_create(bus, sn, PHY_FIXED_ID, false,
987 sn = fdt_next_subnode(gd->fdt_blob, sn);
995 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
997 phy_interface_t interface)
999 struct phy_device *phy_connect(struct mii_dev *bus, int addr,
1000 struct eth_device *dev,
1001 phy_interface_t interface)
1004 struct phy_device *phydev = NULL;
1005 uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff;
1007 #ifdef CONFIG_PHY_FIXED
1008 phydev = phy_connect_fixed(bus, dev, interface);
1011 #ifdef CONFIG_PHY_NCSI
1013 phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface);
1016 #ifdef CONFIG_PHY_XILINX_GMII2RGMII
1018 phydev = phy_connect_gmii2rgmii(bus, dev, interface);
1022 phydev = phy_find_by_mask(bus, mask, interface);
1025 phy_connect_dev(phydev, dev);
1027 printf("Could not get PHY for %s: addr %d\n", bus->name, addr);
1032 * Start the PHY. Returns 0 on success, or a negative error code.
1034 int phy_startup(struct phy_device *phydev)
1036 if (phydev->drv->startup)
1037 return phydev->drv->startup(phydev);
1042 __weak int board_phy_config(struct phy_device *phydev)
1044 if (phydev->drv->config)
1045 return phydev->drv->config(phydev);
1049 int phy_config(struct phy_device *phydev)
1051 /* Invoke an optional board-specific helper */
1052 return board_phy_config(phydev);
1055 int phy_shutdown(struct phy_device *phydev)
1057 if (phydev->drv->shutdown)
1058 phydev->drv->shutdown(phydev);
1063 int phy_get_interface_by_name(const char *str)
1067 for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
1068 if (!strcmp(str, phy_interface_strings[i]))