Thread (7 messages) 7 messages, 2 authors, 2021-03-30
STALE1900d

[PATCH 1/2] WIP: Introduce has_alarm method for rtc devices

From: Łukasz Stelmach <l.stelmach@samsung.com>
Date: 2021-03-17 08:20:30
Also in: lkml
Subsystem: real time clock (rtc) subsystem, the rest · Maintainers: Alexandre Belloni, Linus Torvalds

The method enables determining whether a device supports
setting alarms or not before checking if the alarm to be
set is in the past; thus, provides clear indication of
support for alarms in a given configuration.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
How about has_alarm() method. It can be checked at the beginning of
__rtc_set_alarm() like RTC_HAS_ALARM flag I proposed above, but doesn't
need to be introduced in all drivers at once.

See the following message for the implementation in the ds1307 driver.

The first uie_unsupported patch should be kept regardless of these two.

 drivers/rtc/interface.c | 6 ++++++
 include/linux/rtc.h     | 1 +
 2 files changed, 7 insertions(+)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 794a4f036b99..1eb180370d9b 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -412,6 +412,12 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
 	time64_t now, scheduled;
 	int err;
 
+	if (!rtc->ops)
+		err = -ENODEV;
+	else if (rtc->ops->has_alarm &&
+		 !rtc->ops->has_alarm(rtc->dev.parent))
+		return -EINVAL;
+
 	err = rtc_valid_tm(&alarm->time);
 	if (err)
 		return err;
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 22d1575e4991..ce9fc77ccd02 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -66,6 +66,7 @@ struct rtc_class_ops {
 	int (*alarm_irq_enable)(struct device *, unsigned int enabled);
 	int (*read_offset)(struct device *, long *offset);
 	int (*set_offset)(struct device *, long offset);
+	int (*has_alarm)(struct device *);
 };
 
 struct rtc_device;
-- 
2.26.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help