Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fd5f812 authored by Lennert Buytenhek's avatar Lennert Buytenhek Committed by Lennert Buytenhek
Browse files

phylib: allow incremental scanning of an mii bus



This patch splits the bus scanning code in mdiobus_register() off
into a separate function, and makes this function available for
calling from external code.  This allows incrementally scanning an
mii bus, e.g. as information about which addresses are 'safe' to
scan becomes available.

Signed-off-by: default avatarLennert Buytenhek <buytenh@marvell.com>
Acked-by: default avatarAndy Fleming <afleming@freescale.com>
parent 4ff3495a
Loading
Loading
Loading
Loading
+48 −41
Original line number Diff line number Diff line
@@ -60,17 +60,41 @@ int mdiobus_register(struct mii_bus *bus)
		bus->reset(bus);

	for (i = 0; i < PHY_MAX_ADDR; i++) {
		bus->phy_map[i] = NULL;
		if ((bus->phy_mask & (1 << i)) == 0) {
			struct phy_device *phydev;

		if (bus->phy_mask & (1 << i)) {
			bus->phy_map[i] = NULL;
			continue;
			phydev = mdiobus_scan(bus, i);
			if (IS_ERR(phydev))
				err = PTR_ERR(phydev);
		}
	}

		phydev = get_phy_device(bus, i);
	pr_info("%s: probed\n", bus->name);

		if (IS_ERR(phydev))
			return PTR_ERR(phydev);
	return err;
}
EXPORT_SYMBOL(mdiobus_register);

void mdiobus_unregister(struct mii_bus *bus)
{
	int i;

	for (i = 0; i < PHY_MAX_ADDR; i++) {
		if (bus->phy_map[i])
			device_unregister(&bus->phy_map[i]->dev);
	}
}
EXPORT_SYMBOL(mdiobus_unregister);

struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
{
	struct phy_device *phydev;
	int err;

	phydev = get_phy_device(bus, addr);
	if (IS_ERR(phydev) || phydev == NULL)
		return phydev;

	/* There's a PHY at this address
	 * We need to set:
@@ -80,12 +104,12 @@ int mdiobus_register(struct mii_bus *bus)
	 * 4) bus
	 * 5) mii_bus
	 * And, we need to register it */
		if (phydev) {
			phydev->irq = bus->irq[i];

	phydev->irq = bus->irq != NULL ? bus->irq[addr] : PHY_POLL;

	phydev->dev.parent = bus->dev;
	phydev->dev.bus = &mdio_bus_type;
			snprintf(phydev->dev.bus_id, BUS_ID_SIZE, PHY_ID_FMT, bus->id, i);
	snprintf(phydev->dev.bus_id, BUS_ID_SIZE, PHY_ID_FMT, bus->id, addr);

	phydev->bus = bus;

@@ -93,34 +117,17 @@ int mdiobus_register(struct mii_bus *bus)
	phy_scan_fixups(phydev);

	err = device_register(&phydev->dev);

	if (err) {
				printk(KERN_ERR "phy %d failed to register\n",
						i);
		printk(KERN_ERR "phy %d failed to register\n", addr);
		phy_device_free(phydev);
		phydev = NULL;
	}
		}

		bus->phy_map[i] = phydev;
	}
	bus->phy_map[addr] = phydev;

	pr_info("%s: probed\n", bus->name);

	return err;
	return phydev;
}
EXPORT_SYMBOL(mdiobus_register);

void mdiobus_unregister(struct mii_bus *bus)
{
	int i;

	for (i = 0; i < PHY_MAX_ADDR; i++) {
		if (bus->phy_map[i])
			device_unregister(&bus->phy_map[i]->dev);
	}
}
EXPORT_SYMBOL(mdiobus_unregister);
EXPORT_SYMBOL(mdiobus_scan);

/**
 * mdio_bus_match - determine if given PHY driver supports the given PHY device
+2 −0
Original line number Diff line number Diff line
@@ -410,6 +410,8 @@ int phy_start_aneg(struct phy_device *phydev);

int mdiobus_register(struct mii_bus *bus);
void mdiobus_unregister(struct mii_bus *bus);
struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);

void phy_sanitize_settings(struct phy_device *phydev);
int phy_stop_interrupts(struct phy_device *phydev);
int phy_enable_interrupts(struct phy_device *phydev);