drivers/net/mdio/of_mdio.c

Source file repositories/reference/linux-study-clean/drivers/net/mdio/of_mdio.c

File Facts

System
Linux kernel
Corpus path
drivers/net/mdio/of_mdio.c
Extension
.c
Size
13297 bytes
Lines
477
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (of_node_name_eq(child, "ethernet-phy-package")) {
			/* Ignore invalid ethernet-phy-package node */
			if (!of_property_present(child, "reg"))
				continue;

			rc = __of_mdiobus_parse_phys(mdio, child, NULL);
			if (rc && rc != -ENODEV)
				goto exit;

			continue;
		}

		addr = of_mdio_parse_addr(&mdio->dev, child);
		if (addr < 0) {
			/* Skip scanning for invalid ethernet-phy-package node */
			if (scanphys)
				*scanphys = true;
			continue;
		}

		if (of_mdiobus_child_is_phy(child))
			rc = of_mdiobus_register_phy(mdio, child, addr);
		else
			rc = of_mdiobus_register_device(mdio, child, addr);

		if (rc == -ENODEV)
			dev_err(&mdio->dev,
				"MDIO device at address %d is missing.\n",
				addr);
		else if (rc)
			goto exit;
	}

	return 0;
exit:
	of_node_put(child);
	return rc;
}

/**
 * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree
 * @mdio: pointer to mii_bus structure
 * @np: pointer to device_node of MDIO bus.
 * @owner: module owning the @mdio object.
 *
 * This function registers the mii_bus structure and registers a phy_device
 * for each child node of @np.
 */
int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np,
			  struct module *owner)
{
	struct device_node *child;
	bool scanphys = false;
	int addr, rc;

	if (!np)
		return __mdiobus_register(mdio, owner);

	/* Do not continue if the node is disabled */
	if (!of_device_is_available(np))
		return -ENODEV;

	/* Mask out all PHYs from auto probing.  Instead the PHYs listed in
	 * the device tree are populated after the bus has been registered */
	mdio->phy_mask = ~0;

	device_set_node(&mdio->dev, of_fwnode_handle(np));

	/* Get bus level PHY reset GPIO details */
	mdio->reset_delay_us = DEFAULT_GPIO_RESET_DELAY;
	of_property_read_u32(np, "reset-delay-us", &mdio->reset_delay_us);
	mdio->reset_post_delay_us = 0;
	of_property_read_u32(np, "reset-post-delay-us", &mdio->reset_post_delay_us);

	/* Register the MDIO bus */
	rc = __mdiobus_register(mdio, owner);
	if (rc)
		return rc;

	/* Loop over the child nodes and register a phy_device for each phy */
	rc = __of_mdiobus_parse_phys(mdio, np, &scanphys);
	if (rc)
		goto unregister;

	if (!scanphys)
		return 0;

	/* auto scan for PHYs with empty reg property */
	for_each_available_child_of_node(np, child) {
		/* Skip PHYs with reg property set or ethernet-phy-package node */

Annotation

Implementation Notes