* [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled
@ 2024-07-16 12:03 Ahmad Fatoum
2024-07-16 12:03 ` [PATCH 2/2] rtc: return first RTC when rtc_lookup(NULL) is called Ahmad Fatoum
2024-07-19 6:35 ` [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 12:03 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
To allow using the RTC API in files that may optionally be
compiled with RTC support disabled, add dummy stubs.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/rtc.h | 13 +++++++++++++
include/rtc.h | 10 ++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 3c5bb8c8dfc1..4fa999723de1 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -19,6 +19,8 @@
#include <linux/nvmem-provider.h>
#include <rtc.h>
+struct rtc_time;
+
extern int rtc_month_days(unsigned int month, unsigned int year);
extern int rtc_valid_tm(struct rtc_time *tm);
extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
@@ -40,8 +42,19 @@ struct rtc_class_ops {
extern int rtc_register(struct rtc_device *rtcdev);
+#ifdef CONFIG_RTC_CLASS
extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
+#else
+static inline int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
+{
+ return -ENOSYS;
+}
+static inline int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
+{
+ return -ENOSYS;
+}
+#endif
static inline bool is_leap_year(unsigned int year)
{
diff --git a/include/rtc.h b/include/rtc.h
index d7e103d163bc..0766f0408216 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -10,6 +10,8 @@
#ifndef _RTC_H_
#define _RTC_H_
+#include <linux/err.h>
+
/*
* The struct used to pass data from the generic interface code to
* the hardware dependend low-level code ande vice versa. Identical
@@ -40,7 +42,15 @@ void to_tm (int, struct rtc_time *);
unsigned long mktime (unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int);
+struct rtc_device;
+#ifdef CONFIG_RTC_CLASS
extern struct rtc_device *rtc_lookup(const char *name);
+#else
+static inline struct rtc_device *rtc_lookup(const char *name)
+{
+ return ERR_PTR(-ENODEV);
+}
+#endif
const char *time_str(struct rtc_time *tm);
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] rtc: return first RTC when rtc_lookup(NULL) is called
2024-07-16 12:03 [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Ahmad Fatoum
@ 2024-07-16 12:03 ` Ahmad Fatoum
2024-07-19 6:35 ` [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-07-16 12:03 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We assume e.g. in hwclock, that we will have a rtc0 if we have any RTCs
at all. Instead of hardcoding specific names, let's just have
rtc_lookup(NULL) return the first best RTC.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/rtc/class.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 3d6cfd6197a7..c09ec3f61ea2 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -18,11 +18,8 @@ struct rtc_device *rtc_lookup(const char *name)
{
struct rtc_device *r;
- if (!name)
- return ERR_PTR(-ENODEV);
-
for_each_rtc(r) {
- if (!strcmp(dev_name(&r->class_dev), name))
+ if (!name || !strcmp(dev_name(&r->class_dev), name))
return r;
}
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled
2024-07-16 12:03 [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Ahmad Fatoum
2024-07-16 12:03 ` [PATCH 2/2] rtc: return first RTC when rtc_lookup(NULL) is called Ahmad Fatoum
@ 2024-07-19 6:35 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-07-19 6:35 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Tue, 16 Jul 2024 14:03:29 +0200, Ahmad Fatoum wrote:
> To allow using the RTC API in files that may optionally be
> compiled with RTC support disabled, add dummy stubs.
>
>
Applied, thanks!
[1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled
https://git.pengutronix.de/cgit/barebox/commit/?id=7355b2e392e3 (link may not be stable)
[2/2] rtc: return first RTC when rtc_lookup(NULL) is called
https://git.pengutronix.de/cgit/barebox/commit/?id=5e1c582171c8 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-19 6:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 12:03 [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Ahmad Fatoum
2024-07-16 12:03 ` [PATCH 2/2] rtc: return first RTC when rtc_lookup(NULL) is called Ahmad Fatoum
2024-07-19 6:35 ` [PATCH 1/2] rtc: add stubs for when CONFIG_RTC_CLASS is disabled Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox