linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Łukasz Stelmach" <l.stelmach@samsung.com>
To: alexandre.belloni@bootlin.com
Cc: l.stelmach@samsung.com, a.zummo@towertech.it,
	b.zolnierkie@samsung.com, linux-kernel@vger.kernel.org,
	linux-rtc@vger.kernel.org, m.szyprowski@samsung.com
Subject: [PATCH 1/2] WIP: Introduce has_alarm method for rtc devices
Date: Wed, 17 Mar 2021 09:19:35 +0100	[thread overview]
Message-ID: <20210317081936.26583-1-l.stelmach@samsung.com> (raw)
In-Reply-To: <dleftjblbjc6w1.fsf%l.stelmach@samsung.com>

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

  parent reply	other threads:[~2021-03-17  8:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210305174419eucas1p1639ed3bbcbc37ab3e3619e9c5d1e1629@eucas1p1.samsung.com>
2021-03-05 17:44 ` [PATCH] rtc: ds1307: set uie_unsupported if no interrupt is available Łukasz Stelmach
2021-03-15 22:01   ` Alexandre Belloni
     [not found]   ` <CGME20210316121218eucas1p1f74d6e6cec7fc897051902a7da478fd0@eucas1p1.samsung.com>
2021-03-16 12:12     ` Lukasz Stelmach
2021-03-16 12:32       ` Alexandre Belloni
     [not found]         ` <CGME20210316180430eucas1p1a3cb26f40772b0af75782ff84908d731@eucas1p1.samsung.com>
2021-03-16 18:04           ` Lukasz Stelmach
     [not found]             ` <CGME20210317081944eucas1p123bd27f3203c937d2969a66fb06d6d9e@eucas1p1.samsung.com>
2021-03-17  8:19               ` Łukasz Stelmach [this message]
     [not found]                 ` <CGME20210317081947eucas1p15a31b346977fba94bf154716c3d89cb0@eucas1p1.samsung.com>
2021-03-17  8:19                   ` [PATCH 2/2] WIP: Provide has_alarm method Łukasz Stelmach
2021-03-30  0:02             ` [PATCH] rtc: ds1307: set uie_unsupported if no interrupt is available Alexandre Belloni
2021-03-30  0:03               ` [PATCH 1/3] rtc: ds1307: replace HAS_ALARM by RTC_FEATURE_ALARM Alexandre Belloni
2021-03-30  0:03                 ` [PATCH 2/3] rtc: ds1307: remove flags Alexandre Belloni
     [not found]                   ` <CGME20210402102743eucas1p23690e0df642a10fa0326a84fac6c0ed3@eucas1p2.samsung.com>
2021-04-02 10:27                     ` Łukasz Stelmach
2021-03-30  0:03                 ` [PATCH 3/3] rtc: rtc_update_irq_enable: rework UIE emulation Alexandre Belloni
     [not found]                   ` <CGME20210402102813eucas1p1bae7ec57559fa8df622118275bf6fae0@eucas1p1.samsung.com>
2021-04-02 10:28                     ` Łukasz Stelmach
     [not found]                 ` <CGME20210402102655eucas1p24ee7e879816089921bf9752c3c483122@eucas1p2.samsung.com>
2021-04-02 10:26                   ` [PATCH 1/3] rtc: ds1307: replace HAS_ALARM by RTC_FEATURE_ALARM Łukasz Stelmach
     [not found]               ` <CGME20210330065217eucas1p2c50a100bf0101e72dd753f37257f6a57@eucas1p2.samsung.com>
2021-03-30  6:52                 ` [PATCH] rtc: ds1307: set uie_unsupported if no interrupt is available Lukasz Stelmach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210317081936.26583-1-l.stelmach@samsung.com \
    --to=l.stelmach@samsung.com \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).