Re: [net-next PATCH v2 08/14] net: mdiobus: Introduce fwnode_mdiobus_register()
From: Andy Shevchenko <hidden>
Date: 2020-12-15 17:53:44
Also in:
linux-acpi, linux-arm-kernel, lkml
On Tue, Dec 15, 2020 at 6:44 PM Calvin Johnson [off-list ref] wrote:
Introduce fwnode_mdiobus_register() to register PHYs on the mdiobus.
If the fwnode is DT node, then call of_mdiobus_register().
If it is an ACPI node, then:
- disable auto probing of mdiobus
- register mdiobus
- save fwnode to mdio structure
- loop over child nodes & register a phy_device for each PHY...
+/**
+ * fwnode_mdiobus_register - Register mii_bus and create PHYs from fwnode
+ * @mdio: pointer to mii_bus structure
+ * @fwnode: pointer to fwnode of MDIO bus.
+ *
+ * This function registers the mii_bus structure and registers a phy_device
+ * for each child node of @fwnode.
+ */
+int fwnode_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode)
+{
+ struct fwnode_handle *child;
+ unsigned long long addr;
+ acpi_status status;
+ int ret;
+
+ if (is_of_node(fwnode)) {
+ return of_mdiobus_register(mdio, to_of_node(fwnode));
+ } else if (is_acpi_node(fwnode)) {
I would rather see this as simple as
if (is_of_node(fwnode))
return of_mdiobus_register(mdio, to_of_node(fwnode));
if (is_acpi_node(fwnode))
return acpi_mdiobus_register(mdio, fwnode);
where the latter one is defined somewhere in drivers/acpi/.
+ /* Mask out all PHYs from auto probing. */
+ mdio->phy_mask = ~0;
+ ret = mdiobus_register(mdio);
+ if (ret)
+ return ret;
+
+ mdio->dev.fwnode = fwnode;
+ /* Loop over the child nodes and register a phy_device for each PHY */
+ fwnode_for_each_child_node(fwnode, child) {+ status = acpi_evaluate_integer(ACPI_HANDLE_FWNODE(child),
+ "_ADR", NULL, &addr);
+ if (ACPI_FAILURE(status)) {Isn't it fwnode_get_id() now?
+ pr_debug("_ADR returned %d\n", status);
+ continue;
+ }+ if (addr < 0 || addr >= PHY_MAX_ADDR) + continue;
addr can't be less than 0.
+ ret = fwnode_mdiobus_register_phy(mdio, child, addr); + if (ret == -ENODEV) + dev_err(&mdio->dev, + "MDIO device at address %lld is missing.\n", + addr); + } + return 0; + } + return -EINVAL; +}
-- With Best Regards, Andy Shevchenko