Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: mdio: Add ACPI support code for mdio

Define acpi_mdiobus_register() to Register mii_bus and create PHYs for
each ACPI child node.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Grant Likely <grant.likely@arm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Calvin Johnson and committed by
David S. Miller
803ca24d 7ec16433

+93
+1
MAINTAINERS
··· 6811 6811 F: Documentation/devicetree/bindings/net/qca,ar803x.yaml 6812 6812 F: Documentation/networking/phy.rst 6813 6813 F: drivers/net/mdio/ 6814 + F: drivers/net/mdio/acpi_mdio.c 6814 6815 F: drivers/net/mdio/fwnode_mdio.c 6815 6816 F: drivers/net/mdio/of_mdio.c 6816 6817 F: drivers/net/pcs/
+7
drivers/net/mdio/Kconfig
··· 34 34 help 35 35 OpenFirmware MDIO bus (Ethernet PHY) accessors 36 36 37 + config ACPI_MDIO 38 + def_tristate PHYLIB 39 + depends on ACPI 40 + depends on PHYLIB 41 + help 42 + ACPI MDIO bus (Ethernet PHY) accessors 43 + 37 44 if MDIO_BUS 38 45 39 46 config MDIO_DEVRES
+1
drivers/net/mdio/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for Linux MDIO bus drivers 3 3 4 + obj-$(CONFIG_ACPI_MDIO) += acpi_mdio.o 4 5 obj-$(CONFIG_FWNODE_MDIO) += fwnode_mdio.o 5 6 obj-$(CONFIG_OF_MDIO) += of_mdio.o 6 7
+58
drivers/net/mdio/acpi_mdio.c
··· 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 + 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> 16 + 17 + MODULE_AUTHOR("Calvin Johnson <calvin.johnson@oss.nxp.com>"); 18 + MODULE_LICENSE("GPL"); 19 + 20 + /** 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 + * an ACPI device object corresponding to the MDIO bus and its children are 25 + * expected to correspond to the PHY devices on that bus. 26 + * 27 + * This function registers the mii_bus structure and registers a phy_device 28 + * for each child node of @fwnode. 29 + */ 30 + int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) 31 + { 32 + struct fwnode_handle *child; 33 + u32 addr; 34 + int ret; 35 + 36 + /* Mask out all PHYs from auto probing. */ 37 + mdio->phy_mask = GENMASK(31, 0); 38 + ret = mdiobus_register(mdio); 39 + if (ret) 40 + return ret; 41 + 42 + ACPI_COMPANION_SET(&mdio->dev, to_acpi_device_node(fwnode)); 43 + 44 + /* Loop over the child nodes and register a phy_device for each PHY */ 45 + fwnode_for_each_child_node(fwnode, child) { 46 + ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr); 47 + if (ret || addr >= PHY_MAX_ADDR) 48 + continue; 49 + 50 + ret = fwnode_mdiobus_register_phy(mdio, child, addr); 51 + if (ret == -ENODEV) 52 + dev_err(&mdio->dev, 53 + "MDIO device at address %d is missing.\n", 54 + addr); 55 + } 56 + return 0; 57 + } 58 + EXPORT_SYMBOL(acpi_mdiobus_register);
+26
include/linux/acpi_mdio.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * ACPI helper for the MDIO (Ethernet PHY) API 4 + */ 5 + 6 + #ifndef __LINUX_ACPI_MDIO_H 7 + #define __LINUX_ACPI_MDIO_H 8 + 9 + #include <linux/phy.h> 10 + 11 + #if IS_ENABLED(CONFIG_ACPI_MDIO) 12 + int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode); 13 + #else /* CONFIG_ACPI_MDIO */ 14 + static inline int 15 + acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) 16 + { 17 + /* 18 + * Fall back to mdiobus_register() function to register a bus. 19 + * This way, we don't have to keep compat bits around in drivers. 20 + */ 21 + 22 + return mdiobus_register(mdio); 23 + } 24 + #endif 25 + 26 + #endif /* __LINUX_ACPI_MDIO_H */