acpi_mdio.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ACPI helpers for the MDIO (Ethernet PHY) API
  4. *
  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.
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/acpi_mdio.h>
  10. #include <linux/bits.h>
  11. #include <linux/dev_printk.h>
  12. #include <linux/fwnode_mdio.h>
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>");
  16. MODULE_LICENSE("GPL");
  17. MODULE_DESCRIPTION("ACPI MDIO bus (Ethernet PHY) accessors");
  18. /**
  19. * __acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL.
  20. * @mdio: pointer to mii_bus structure
  21. * @fwnode: pointer to fwnode of MDIO bus. This fwnode is expected to represent
  22. * @owner: module owning this @mdio object.
  23. * an ACPI device object corresponding to the MDIO bus and its children are
  24. * expected to correspond to the PHY devices on that bus.
  25. *
  26. * This function registers the mii_bus structure and registers a phy_device
  27. * for each child node of @fwnode.
  28. */
  29. int __acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode,
  30. struct module *owner)
  31. {
  32. struct fwnode_handle *child;
  33. u32 addr;
  34. int ret;
  35. /* Mask out all PHYs from auto probing. */
  36. mdio->phy_mask = GENMASK(31, 0);
  37. ret = __mdiobus_register(mdio, owner);
  38. if (ret)
  39. return ret;
  40. ACPI_COMPANION_SET(&mdio->dev, to_acpi_device_node(fwnode));
  41. /* Loop over the child nodes and register a phy_device for each PHY */
  42. fwnode_for_each_child_node(fwnode, child) {
  43. ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
  44. if (ret || addr >= PHY_MAX_ADDR)
  45. continue;
  46. ret = fwnode_mdiobus_register_phy(mdio, child, addr);
  47. if (ret == -ENODEV)
  48. dev_err(&mdio->dev,
  49. "MDIO device at address %d is missing.\n",
  50. addr);
  51. }
  52. return 0;
  53. }
  54. EXPORT_SYMBOL(__acpi_mdiobus_register);