[PATCH] rtc: register RTC class to collect devices

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jul 1 00:43:25 PDT 2024


We already have an RTC class device, so by using struct class, we can
drop the list member in struct rtc_device and make it possible to list
the device using the class command.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/rtc/class.c | 10 ++++++----
 include/linux/rtc.h |  1 -
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 3edb294ed772..3d6cfd6197a7 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -8,9 +8,11 @@
 #include <linux/err.h>
 #include <rtc.h>
 #include <linux/rtc.h>
+#include <device.h>
 
-LIST_HEAD(rtc_list);
-EXPORT_SYMBOL(rtc_list);
+#define for_each_rtc(rtc) list_for_each_entry(rtc, &rtc_class.devices, class_dev.class_list)
+
+DEFINE_DEV_CLASS(rtc_class, "rtc");
 
 struct rtc_device *rtc_lookup(const char *name)
 {
@@ -19,7 +21,7 @@ struct rtc_device *rtc_lookup(const char *name)
 	if (!name)
 		return ERR_PTR(-ENODEV);
 
-	list_for_each_entry(r, &rtc_list, list) {
+	for_each_rtc(r) {
 		if (!strcmp(dev_name(&r->class_dev), name))
 			return r;
 	}
@@ -62,7 +64,7 @@ int rtc_register(struct rtc_device *rtcdev)
 		dev->parent = rtcdev->dev;
 	platform_device_register(dev);
 
-	list_add_tail(&rtcdev->list, &rtc_list);
+	class_add_device(&rtc_class, &rtcdev->class_dev);
 
 	return 0;
 }
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index def07548c554..82a82ce61682 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -26,7 +26,6 @@ struct rtc_class_ops;
 struct rtc_device {
 	struct device *dev;
 	struct device class_dev;
-	struct list_head list;
 
 	const struct rtc_class_ops *ops;
 };
-- 
2.39.2




More information about the barebox mailing list