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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/err.hlinux/fwnode_mdio.hlinux/kernel.hlinux/module.hlinux/netdevice.hlinux/of.hlinux/of_irq.hlinux/of_mdio.hlinux/of_net.hlinux/phy.hlinux/phy_fixed.h
Detected Declarations
function of_get_phy_idfunction of_mdiobus_phy_device_registerfunction of_mdiobus_register_phyfunction of_mdiobus_register_devicefunction abovefunction __of_mdiobus_parse_physfunction __of_mdiobus_registerfunction put_devicefunction phy_disconnectfunction phy_disconnectfunction of_phy_is_fixed_linkfunction of_phy_register_fixed_linkfunction ARRAY_SIZEfunction of_phy_deregister_fixed_linkexport of_mdiobus_phy_device_registerexport of_mdiobus_child_is_phyexport __of_mdiobus_registerexport of_mdio_find_deviceexport of_phy_find_deviceexport of_phy_connectexport of_phy_get_and_connectexport of_phy_is_fixed_linkexport of_phy_register_fixed_linkexport of_phy_deregister_fixed_link
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
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/fwnode_mdio.h`, `linux/kernel.h`, `linux/module.h`, `linux/netdevice.h`, `linux/of.h`, `linux/of_irq.h`.
- Detected declarations: `function of_get_phy_id`, `function of_mdiobus_phy_device_register`, `function of_mdiobus_register_phy`, `function of_mdiobus_register_device`, `function above`, `function __of_mdiobus_parse_phys`, `function __of_mdiobus_register`, `function put_device`, `function phy_disconnect`, `function phy_disconnect`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.