[PATCH v2 03/16] driver: factor out bus definitions into separate header
Ahmad Fatoum
a.fatoum at barebox.org
Thu Jun 5 22:57:35 PDT 2025
driver.h combines a lot of driver model related definitions making it
inconvenient to include from other headers. Let's split out the bus type
parts.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
include/driver.h | 32 +----------------------------
include/linux/device/bus.h | 42 ++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 31 deletions(-)
create mode 100644 include/linux/device/bus.h
diff --git a/include/driver.h b/include/driver.h
index 581f59754bab..a2337f2f4f95 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -12,6 +12,7 @@
#include <linux/printk.h>
#include <linux/module.h>
#include <device.h>
+#include <linux/device/bus.h>
#include <of.h>
#include <init.h>
#include <errno.h>
@@ -352,43 +353,12 @@ ssize_t mem_copy(struct device *dev, void *dst, const void *src,
int generic_memmap_ro(struct cdev *dev, void **map, int flags);
int generic_memmap_rw(struct cdev *dev, void **map, int flags);
-struct bus_type {
- char *name;
- int (*match)(struct device *dev, const struct driver *drv);
- int (*probe)(struct device *dev);
- void (*remove)(struct device *dev);
-
- struct device dev;
-
- struct list_head device_list;
- struct list_head driver_list;
-};
-
-int bus_register(struct bus_type *bus);
-int device_match(struct device *dev, const struct driver *drv);
-
static inline int driver_match_device(const struct driver *drv,
struct device *dev)
{
return drv->bus->match ? drv->bus->match(dev, drv) : true;
}
-extern struct class bus_class;
-
-/* Iterate over all buses
- */
-#define for_each_bus(bus) class_for_each_container_of_device(&bus_class, bus, dev)
-
-/* Iterate over all devices of a bus
- */
-#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &(bus)->device_list, bus_list)
-
-/* Iterate over all drivers of a bus
- */
-#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &(bus)->driver_list, bus_list)
-
-extern struct bus_type platform_bus;
-
int platform_driver_register(struct driver *drv);
/* register_driver_macro() - Helper macro for drivers that don't do
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
new file mode 100644
index 000000000000..8837ce3c2ed2
--- /dev/null
+++ b/include/linux/device/bus.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * (C) 2007 Pengutronix, Sascha Hauer <s.hauer at pengutronix.de>
+ */
+
+#ifndef __BUS_H
+#define __BUS_H
+
+#include <device.h>
+
+struct bus_type {
+ char *name;
+ int (*match)(struct device *dev, const struct driver *drv);
+ int (*probe)(struct device *dev);
+ void (*remove)(struct device *dev);
+
+ struct device dev;
+
+ struct list_head device_list;
+ struct list_head driver_list;
+};
+
+int bus_register(struct bus_type *bus);
+int device_match(struct device *dev, const struct driver *drv);
+
+extern struct class bus_class;
+
+/* Iterate over all buses
+ */
+#define for_each_bus(bus) class_for_each_container_of_device(&bus_class, bus, dev)
+
+/* Iterate over all devices of a bus
+ */
+#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &(bus)->device_list, bus_list)
+
+/* Iterate over all drivers of a bus
+ */
+#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &(bus)->driver_list, bus_list)
+
+extern struct bus_type platform_bus;
+
+#endif
--
2.39.5
More information about the barebox
mailing list