1 // SPDX-License-Identifier: GPL-2.0-only
3 * ACPI helpers for the MDIO (Ethernet PHY) API
5 * This file provides helper functions for extracting PHY device information
6 * out of the ACPI ASL and using it to populate an mii_bus.
9 #include <linux/acpi.h>
10 #include <linux/acpi_mdio.h>
11 #include <linux/bits.h>
12 #include <linux/dev_printk.h>
13 #include <linux/fwnode_mdio.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
17 MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
18 MODULE_LICENSE("GPL");
21 * __acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL.
22 * @mdio: pointer to mii_bus structure
23 * @fwnode: pointer to fwnode of MDIO bus. This fwnode is expected to represent
24 * @owner: module owning this @mdio object.
25 * an ACPI device object corresponding to the MDIO bus and its children are
26 * expected to correspond to the PHY devices on that bus.
28 * This function registers the mii_bus structure and registers a phy_device
29 * for each child node of @fwnode.
31 int __acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode,
34 struct fwnode_handle *child;
38 /* Mask out all PHYs from auto probing. */
39 mdio->phy_mask = GENMASK(31, 0);
40 ret = __mdiobus_register(mdio, owner);
44 ACPI_COMPANION_SET(&mdio->dev, to_acpi_device_node(fwnode));
46 /* Loop over the child nodes and register a phy_device for each PHY */
47 fwnode_for_each_child_node(fwnode, child) {
48 ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
49 if (ret || addr >= PHY_MAX_ADDR)
52 ret = fwnode_mdiobus_register_phy(mdio, child, addr);
55 "MDIO device at address %d is missing.\n",
60 EXPORT_SYMBOL(__acpi_mdiobus_register);