[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210317081936.26583-1-l.stelmach@samsung.com>
Date: Wed, 17 Mar 2021 09:19:35 +0100
From: Łukasz Stelmach <l.stelmach@...sung.com>
To: alexandre.belloni@...tlin.com
Cc: l.stelmach@...sung.com, a.zummo@...ertech.it,
b.zolnierkie@...sung.com, linux-kernel@...r.kernel.org,
linux-rtc@...r.kernel.org, m.szyprowski@...sung.com
Subject: [PATCH 1/2] WIP: Introduce has_alarm method for rtc devices
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@...sung.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
Powered by blists - more mailing lists