mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
184 lines
5.1 KiB
Diff
184 lines
5.1 KiB
Diff
From c9a0a57ced59ce517a44d2dd68c41be8376817d0 Mon Sep 17 00:00:00 2001
|
|
From: Joachim Wiberg <troglobit@gmail.com>
|
|
Date: Sun, 5 Apr 2026 11:33:00 +0200
|
|
Subject: [PATCH 42/50] net/pcs: add standalone PCS registration infrastructure
|
|
|
|
Add a simple registration mechanism that allows platform PCS drivers to
|
|
register their phylink_pcs instances, and consumers (e.g. Ethernet MAC
|
|
drivers) to look them up via a DT phandle using devm_of_pcs_get().
|
|
|
|
When the pcs-handle property is present but the PCS device is not yet
|
|
registered, devm_of_pcs_get() returns -ENODEV to trigger deferred probe
|
|
in the consumer driver.
|
|
|
|
Based on work by Daniel Golle <daniel@makrotopia.org>.
|
|
---
|
|
drivers/net/pcs/Kconfig | 4 ++
|
|
drivers/net/pcs/Makefile | 1 +
|
|
drivers/net/pcs/pcs-standalone.c | 95 ++++++++++++++++++++++++++++++
|
|
include/linux/pcs/pcs-standalone.h | 26 ++++++++
|
|
4 files changed, 126 insertions(+)
|
|
create mode 100644 drivers/net/pcs/pcs-standalone.c
|
|
create mode 100644 include/linux/pcs/pcs-standalone.h
|
|
|
|
diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig
|
|
index ecbc3530e780..f6b4de7f972c 100644
|
|
--- a/drivers/net/pcs/Kconfig
|
|
+++ b/drivers/net/pcs/Kconfig
|
|
@@ -5,6 +5,10 @@
|
|
|
|
menu "PCS device drivers"
|
|
|
|
+config PCS_STANDALONE
|
|
+ tristate
|
|
+ select PHYLINK
|
|
+
|
|
config PCS_XPCS
|
|
tristate "Synopsys DesignWare Ethernet XPCS"
|
|
select PHYLINK
|
|
diff --git a/drivers/net/pcs/Makefile b/drivers/net/pcs/Makefile
|
|
index 4f7920618b90..0cb0057f2b8e 100644
|
|
--- a/drivers/net/pcs/Makefile
|
|
+++ b/drivers/net/pcs/Makefile
|
|
@@ -4,6 +4,7 @@
|
|
pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-plat.o \
|
|
pcs-xpcs-nxp.o pcs-xpcs-wx.o
|
|
|
|
+obj-$(CONFIG_PCS_STANDALONE) += pcs-standalone.o
|
|
obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o
|
|
obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o
|
|
obj-$(CONFIG_PCS_MTK_LYNXI) += pcs-mtk-lynxi.o
|
|
diff --git a/drivers/net/pcs/pcs-standalone.c b/drivers/net/pcs/pcs-standalone.c
|
|
new file mode 100644
|
|
index 000000000000..f7b46de59636
|
|
--- /dev/null
|
|
+++ b/drivers/net/pcs/pcs-standalone.c
|
|
@@ -0,0 +1,95 @@
|
|
+// SPDX-License-Identifier: GPL-2.0-or-later
|
|
+/*
|
|
+ * Helpers for standalone PCS drivers
|
|
+ *
|
|
+ * Copyright (C) 2024 Daniel Golle <daniel@makrotopia.org>
|
|
+ */
|
|
+
|
|
+#include <linux/pcs/pcs-standalone.h>
|
|
+#include <linux/phylink.h>
|
|
+
|
|
+static LIST_HEAD(pcs_list);
|
|
+static DEFINE_MUTEX(pcs_mutex);
|
|
+
|
|
+struct pcs_standalone {
|
|
+ struct device *dev;
|
|
+ struct phylink_pcs *pcs;
|
|
+ struct list_head list;
|
|
+};
|
|
+
|
|
+static void devm_pcs_provider_release(struct device *dev, void *res)
|
|
+{
|
|
+ struct pcs_standalone *pcssa = (struct pcs_standalone *)res;
|
|
+
|
|
+ mutex_lock(&pcs_mutex);
|
|
+ list_del(&pcssa->list);
|
|
+ mutex_unlock(&pcs_mutex);
|
|
+}
|
|
+
|
|
+int devm_pcs_register(struct device *dev, struct phylink_pcs *pcs)
|
|
+{
|
|
+ struct pcs_standalone *pcssa;
|
|
+
|
|
+ pcssa = devres_alloc(devm_pcs_provider_release, sizeof(*pcssa),
|
|
+ GFP_KERNEL);
|
|
+ if (!pcssa)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ devres_add(dev, pcssa);
|
|
+ pcssa->pcs = pcs;
|
|
+ pcssa->dev = dev;
|
|
+
|
|
+ mutex_lock(&pcs_mutex);
|
|
+ list_add_tail(&pcssa->list, &pcs_list);
|
|
+ mutex_unlock(&pcs_mutex);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(devm_pcs_register);
|
|
+
|
|
+static struct pcs_standalone *of_pcs_locate(const struct device_node *_np, u32 index)
|
|
+{
|
|
+ struct device_node *np;
|
|
+ struct pcs_standalone *iter, *pcssa = NULL;
|
|
+
|
|
+ if (!_np)
|
|
+ return NULL;
|
|
+
|
|
+ np = of_parse_phandle(_np, "pcs-handle", index);
|
|
+ if (!np)
|
|
+ return NULL;
|
|
+
|
|
+ mutex_lock(&pcs_mutex);
|
|
+ list_for_each_entry(iter, &pcs_list, list) {
|
|
+ if (iter->dev->of_node != np)
|
|
+ continue;
|
|
+
|
|
+ pcssa = iter;
|
|
+ break;
|
|
+ }
|
|
+ mutex_unlock(&pcs_mutex);
|
|
+
|
|
+ of_node_put(np);
|
|
+
|
|
+ return pcssa ?: ERR_PTR(-ENODEV);
|
|
+}
|
|
+
|
|
+struct phylink_pcs *devm_of_pcs_get(struct device *dev,
|
|
+ const struct device_node *np,
|
|
+ unsigned int index)
|
|
+{
|
|
+ struct pcs_standalone *pcssa;
|
|
+
|
|
+ pcssa = of_pcs_locate(np ?: dev->of_node, index);
|
|
+ if (IS_ERR_OR_NULL(pcssa))
|
|
+ return ERR_PTR(PTR_ERR(pcssa));
|
|
+
|
|
+ device_link_add(dev, pcssa->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
|
|
+
|
|
+ return pcssa->pcs;
|
|
+}
|
|
+EXPORT_SYMBOL_GPL(devm_of_pcs_get);
|
|
+
|
|
+MODULE_DESCRIPTION("Helper for standalone PCS drivers");
|
|
+MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
|
|
+MODULE_LICENSE("GPL");
|
|
diff --git a/include/linux/pcs/pcs-standalone.h b/include/linux/pcs/pcs-standalone.h
|
|
new file mode 100644
|
|
index 000000000000..520835cdeee8
|
|
--- /dev/null
|
|
+++ b/include/linux/pcs/pcs-standalone.h
|
|
@@ -0,0 +1,26 @@
|
|
+/* SPDX-License-Identifier: GPL-2.0 */
|
|
+#ifndef __LINUX_PCS_STANDALONE_H
|
|
+#define __LINUX_PCS_STANDALONE_H
|
|
+
|
|
+#include <linux/device.h>
|
|
+#include <linux/phylink.h>
|
|
+#include <linux/phy/phy.h>
|
|
+#include <linux/of.h>
|
|
+
|
|
+#if IS_ENABLED(CONFIG_PCS_STANDALONE)
|
|
+int devm_pcs_register(struct device *dev, struct phylink_pcs *pcs);
|
|
+struct phylink_pcs *devm_of_pcs_get(struct device *dev,
|
|
+ const struct device_node *np, unsigned int index);
|
|
+#else
|
|
+static inline int devm_pcs_register(struct device *dev, struct phylink_pcs *pcs)
|
|
+{
|
|
+ return -ENOTSUPP;
|
|
+}
|
|
+static inline struct phylink_pcs *devm_of_pcs_get(struct device *dev,
|
|
+ const struct device_node *np,
|
|
+ unsigned int index)
|
|
+{
|
|
+ return ERR_PTR(-ENOTSUPP);
|
|
+}
|
|
+#endif /* CONFIG_PCS_STANDALONE */
|
|
+#endif /* __LINUX_PCS_STANDALONE_H */
|