diff mbox series

[net-next,RFC,05/14] net: phy: add support for named global PHY in DT PHY package

Message ID 20231120135041.15259-6-ansuelsmth@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: phy: Support DT PHY package | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/codegen success Generated files up to date
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1577 this patch: 1577
netdev/cc_maintainers success CCed 11 of 11 maintainers
netdev/build_clang success Errors and warnings before: 1173 this patch: 1173
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1614 this patch: 1614
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0

Commit Message

Christian Marangi Nov. 20, 2023, 1:50 p.m. UTC
Add support for named global PHY in DT PHY package definition.
A phy-package node can provide the property "global-phy-names" to
provide named global PHY to correctly reference the phandle defined in
the global-phys list.

Each PHY driver has to define the .phy_package_global_phy_names list
to verify correct order of named PHY phandle defined in DT with the
expected order in the PHY driver.

If the list is not defined or "global-phy-names" is not defined in
DT, global phy addresses are insered in order defined in the "global-phys"
property.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/phy/phy_device.c | 13 +++++++++++++
 include/linux/phy.h          |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 9ff76d84dca0..452fd69e8924 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -3198,6 +3198,7 @@  static int of_phy_package(struct phy_device *phydev)
 	struct device_node *node = phydev->mdio.dev.of_node;
 	struct of_phandle_args phy_phandle;
 	struct device_node *package_node;
+	const char *global_phy_name;
 	int i, global_phys_num, ret;
 	int *global_phy_addrs;
 
@@ -3236,6 +3237,18 @@  static int of_phy_package(struct phy_device *phydev)
 		if (ret)
 			goto exit;
 
+		ret = of_property_read_string_index(package_node, "global-phy-names",
+						    i, &global_phy_name);
+		if (!ret && phydev->drv->phy_package_global_phy_names) {
+			const char *name;
+
+			name = phydev->drv->phy_package_global_phy_names[i];
+			if (strcmp(global_phy_name, name)) {
+				ret = -EINVAL;
+				goto exit;
+			}
+		}
+
 		global_phy_addrs[i] = addr;
 	}
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 5bf90c49e5bd..5e595a0a43b6 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -892,6 +892,10 @@  struct phy_led {
  * @driver_data: Static driver data
  * @phy_package_global_phy_num: Num of the required global phy
  *   for PHY package global configuration.
+ * @phy_package_global_phy_names: List of global PHY names used
+ *   for PHY package global init. If defined, list is compared
+ *   with DT values to match correct PHY phandle order. List
+ *   last element MUST BE an empty string.
  *
  * All functions are optional. If config_aneg or read_status
  * are not implemented, the phy core uses the genphy versions.
@@ -910,6 +914,7 @@  struct phy_driver {
 	u32 flags;
 	const void *driver_data;
 	unsigned int phy_package_global_phy_num;
+	const char * const *phy_package_global_phy_names;
 
 	/**
 	 * @soft_reset: Called to issue a PHY software reset
@@ -1154,7 +1159,6 @@  struct phy_driver {
 	 */
 	int (*led_hw_control_get)(struct phy_device *dev, u8 index,
 				  unsigned long *rules);
-
 };
 #define to_phy_driver(d) container_of(to_mdio_common_driver(d),		\
 				      struct phy_driver, mdiodrv)