Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F168717784
D59188.id185128.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D59188.id185128.diff
View Options
diff --git a/sys/conf/files b/sys/conf/files
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -2440,6 +2440,7 @@
dev/md/md.c optional md
dev/mdio/mdio_if.m optional miiproxy | mdio
dev/mdio/mdio.c optional miiproxy | mdio
+dev/mdio/mdio_fdt.c optional mdio fdt
dev/mem/memdev.c optional mem
dev/mem/memutil.c optional mem
dev/mfi/mfi.c optional mfi
diff --git a/sys/dev/mdio/mdio.h b/sys/dev/mdio/mdio.h
--- a/sys/dev/mdio/mdio.h
+++ b/sys/dev/mdio/mdio.h
@@ -28,6 +28,7 @@
#define __DEV_MDIO_MDIO_H__
extern driver_t mdio_driver;
+DECLARE_CLASS(mdio_fdt_driver);
#define MDIO_DEVADDR_NONE -1 /**< Use clause 22 register access */
diff --git a/sys/dev/mdio/mdio.c b/sys/dev/mdio/mdio.c
--- a/sys/dev/mdio/mdio.c
+++ b/sys/dev/mdio/mdio.c
@@ -24,11 +24,17 @@
* SUCH DAMAGE.
*/
+#include "opt_platform.h"
+
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/systm.h>
#include <sys/module.h>
+#ifdef FDT
+#include <dev/ofw/ofw_bus.h>
+#endif
+
#include <dev/mdio/mdio.h>
#include "mdio_if.h"
@@ -37,6 +43,14 @@
mdio_identify(driver_t *driver, device_t parent)
{
+#ifdef FDT
+ /*
+ * Leave FDT-visible parents to mdio_fdt(4); it will enumerate the
+ * "mdio-bus" DT node's children as first-class newbus devices.
+ */
+ if (ofw_bus_get_node(parent) != -1)
+ return;
+#endif
if (device_find_child(parent, mdio_driver.name, DEVICE_UNIT_ANY) == NULL)
BUS_ADD_CHILD(parent, 0, mdio_driver.name, DEVICE_UNIT_ANY);
}
diff --git a/sys/dev/mdio/mdio_fdt.c b/sys/dev/mdio/mdio_fdt.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/mdio/mdio_fdt.c
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (c) 2026 Justin Hibbits
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * FDT flavour of the generic mdio(4) bus shim.
+ *
+ * To use this, add an attachment to the parent driver.
+ *
+ * MDIO_READREG / MDIO_WRITEREG (and the clause-45 variants) are
+ * inherited from mdio_driver.
+ */
+
+#include "opt_platform.h"
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/mdio/mdio.h>
+
+#include "mdio_if.h"
+#include "ofw_bus_if.h"
+
+struct mdio_fdt_ivars {
+ struct ofw_bus_devinfo obd;
+};
+
+static void
+mdio_fdt_identify(driver_t *driver, device_t parent)
+{
+
+ /* Leave hint-only parents to the base mdio(4) driver. */
+ if (ofw_bus_get_node(parent) == -1)
+ return;
+ if (device_find_child(parent, driver->name, DEVICE_UNIT_ANY) == NULL)
+ BUS_ADD_CHILD(parent, 0, driver->name, DEVICE_UNIT_ANY);
+}
+
+static int
+mdio_fdt_probe(device_t dev)
+{
+
+ if (ofw_bus_get_node(device_get_parent(dev)) == -1)
+ return (ENXIO);
+ device_set_desc(dev, "OFW MDIO");
+ return (BUS_PROBE_SPECIFIC);
+}
+
+static int
+mdio_fdt_attach(device_t dev)
+{
+ struct mdio_fdt_ivars *ivars;
+ phandle_t node, child;
+ device_t cdev;
+
+ /*
+ * The parent controller owns the mdio-bus DT node; its children
+ * (ethernet-phy@N, switch@N, ...) are the mdio devices we hand to
+ * newbus.
+ */
+ node = ofw_bus_get_node(device_get_parent(dev));
+ for (child = OF_child(node); child != 0; child = OF_peer(child)) {
+ if (!OF_hasprop(child, "reg"))
+ continue;
+ ivars = malloc(sizeof(*ivars), M_DEVBUF, M_WAITOK | M_ZERO);
+ if (ofw_bus_gen_setup_devinfo(&ivars->obd, child) != 0) {
+ free(ivars, M_DEVBUF);
+ continue;
+ }
+ cdev = device_add_child(dev, NULL, DEVICE_UNIT_ANY);
+ if (cdev == NULL) {
+ ofw_bus_gen_destroy_devinfo(&ivars->obd);
+ free(ivars, M_DEVBUF);
+ continue;
+ }
+ device_set_ivars(cdev, ivars);
+ }
+
+ bus_identify_children(dev);
+ bus_enumerate_hinted_children(dev);
+ bus_attach_children(dev);
+ return (0);
+}
+
+static const struct ofw_bus_devinfo *
+mdio_fdt_get_devinfo(device_t bus __unused, device_t child)
+{
+ struct mdio_fdt_ivars *ivars;
+
+ ivars = device_get_ivars(child);
+ return (ivars == NULL ? NULL : &ivars->obd);
+}
+
+static device_method_t mdio_fdt_methods[] = {
+ /* Device interface -- override the base's identify/probe/attach. */
+ DEVMETHOD(device_identify, mdio_fdt_identify),
+ DEVMETHOD(device_probe, mdio_fdt_probe),
+ DEVMETHOD(device_attach, mdio_fdt_attach),
+
+ /* ofw_bus interface -- expose devinfo of the FDT children we added. */
+ DEVMETHOD(ofw_bus_get_devinfo, mdio_fdt_get_devinfo),
+ DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
+ DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
+ DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
+ DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
+ DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(mdio, mdio_fdt_driver, mdio_fdt_methods, 0, mdio_driver);
+
+MODULE_VERSION(mdio_fdt, 1);
+MODULE_DEPEND(mdio_fdt, mdio, 1, 1, 1);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 30, 7:18 PM (16 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37499229
Default Alt Text
D59188.id185128.diff (4 KB)
Attached To
Mode
D59188: mdio: Add new mdio FDT driver
Attached
Detach File
Event Timeline
Log In to Comment