Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ACPI helpers for the MDIO (Ethernet PHY) API
0004  *
0005  * This file provides helper functions for extracting PHY device information
0006  * out of the ACPI ASL and using it to populate an mii_bus.
0007  */
0008 
0009 #include <linux/acpi.h>
0010 #include <linux/acpi_mdio.h>
0011 #include <linux/bits.h>
0012 #include <linux/dev_printk.h>
0013 #include <linux/fwnode_mdio.h>
0014 #include <linux/module.h>
0015 #include <linux/types.h>
0016 
0017 MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
0018 MODULE_LICENSE("GPL");
0019 
0020 /**
0021  * acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL.
0022  * @mdio: pointer to mii_bus structure
0023  * @fwnode: pointer to fwnode of MDIO bus. This fwnode is expected to represent
0024  * an ACPI device object corresponding to the MDIO bus and its children are
0025  * expected to correspond to the PHY devices on that bus.
0026  *
0027  * This function registers the mii_bus structure and registers a phy_device
0028  * for each child node of @fwnode.
0029  */
0030 int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode)
0031 {
0032     struct fwnode_handle *child;
0033     u32 addr;
0034     int ret;
0035 
0036     /* Mask out all PHYs from auto probing. */
0037     mdio->phy_mask = GENMASK(31, 0);
0038     ret = mdiobus_register(mdio);
0039     if (ret)
0040         return ret;
0041 
0042     ACPI_COMPANION_SET(&mdio->dev, to_acpi_device_node(fwnode));
0043 
0044     /* Loop over the child nodes and register a phy_device for each PHY */
0045     fwnode_for_each_child_node(fwnode, child) {
0046         ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
0047         if (ret || addr >= PHY_MAX_ADDR)
0048             continue;
0049 
0050         ret = fwnode_mdiobus_register_phy(mdio, child, addr);
0051         if (ret == -ENODEV)
0052             dev_err(&mdio->dev,
0053                 "MDIO device at address %d is missing.\n",
0054                 addr);
0055     }
0056     return 0;
0057 }
0058 EXPORT_SYMBOL(acpi_mdiobus_register);