All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	John Stultz <jstultz@google.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>,
	Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Brian Norris <briannorris@chromium.org>,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v2 1/2] rtc: Add API function to return alarm time bound by rtc limit
Date: Fri, 15 Sep 2023 08:22:37 -0700	[thread overview]
Message-ID: <20230915152238.1144706-2-linux@roeck-us.net> (raw)
In-Reply-To: <20230915152238.1144706-1-linux@roeck-us.net>

Add rtc_bound_alarmtime() to return the requested alarm timeout
bound by the maxmum alarm timeout that is supported by a given rtc.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Added patch to provide API function

 include/linux/rtc.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 4c0bcbeb1f00..5f8e438a0312 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -225,6 +225,23 @@ static inline bool is_leap_year(unsigned int year)
 	return (!(year % 4) && (year % 100)) || !(year % 400);
 }
 
+/**
+ * rtc_bound_alarmtime() - Return alarm time bound by rtc limit
+ * @rtc: Pointer to rtc device structure
+ * @requested: Requested alarm timeout
+ *
+ * Return: Alarm timeout bound by maximum alarm time supported by rtc.
+ */
+static inline ktime_t rtc_bound_alarmtime(struct rtc_device *rtc,
+					  ktime_t requested)
+{
+	if (rtc->alarm_offset_max &&
+	    rtc->alarm_offset_max * MSEC_PER_SEC < ktime_to_ms(requested))
+		return ms_to_ktime(rtc->alarm_offset_max * MSEC_PER_SEC);
+
+	return requested;
+}
+
 #define devm_rtc_register_device(device) \
 	__devm_rtc_register_device(THIS_MODULE, device)
 
-- 
2.39.2


  reply	other threads:[~2023-09-15 15:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15 15:22 [PATCH v2 0/2] rtc: alarmtimer: Use maximum alarm time offset Guenter Roeck
2023-09-15 15:22 ` Guenter Roeck [this message]
2023-10-09 13:08   ` [tip: timers/core] rtc: Add API function to return alarm time bound by hardware limit tip-bot2 for Guenter Roeck
2023-09-15 15:22 ` [PATCH 2/2] rtc: alarmtimer: Use maximum alarm time offset Guenter Roeck
2023-09-15 17:42   ` John Stultz
2023-10-09 13:08   ` [tip: timers/core] alarmtimer: Use maximum alarm time for suspend tip-bot2 for Guenter Roeck
2023-10-30  0:44 ` [PATCH v2 0/2] rtc: alarmtimer: Use maximum alarm time offset Alexandre Belloni
2023-10-30  1:00   ` Alexandre Belloni

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=20230915152238.1144706-2-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@bootlin.com \
    --cc=briannorris@chromium.org \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.