* [PATCH v2 1/8] alarmtimer: Replace alarmtimer_get_rtcdev() with alarmtimer_has_rtcdev()
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 2/8] alarmtimer: Move the wakeup state into struct rtc_wakeup Igor Velkov via B4 Relay
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
alarmtimer_get_rtcdev() returns the wakeup RTC without taking a reference.
Apart from alarmtimer_suspend() and alarmtimer_resume(), its callers only
test the result for NULL: the alarm clock functions to tell whether alarm
clocks are supported, and charger-manager to decide whether to set up its
alarm.
A later patch lets a different RTC wake the system from each suspend
state, so there is no single RTC to return.
Provide alarmtimer_has_rtcdev() for these tests and read rtcdev directly
in alarmtimer_suspend() and alarmtimer_resume().
Signed-off-by: Igor Velkov <iav@iav.lv>
---
drivers/power/supply/charger-manager.c | 2 +-
include/linux/alarmtimer.h | 7 ++-----
kernel/time/alarmtimer.c | 24 ++++++++++++------------
3 files changed, 15 insertions(+), 18 deletions(-)
diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index 8e8c5109401a..754ff4b3de1a 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1456,7 +1456,7 @@ static int charger_manager_probe(struct platform_device *pdev)
psy_cfg.drv_data = cm;
/* Initialize alarm timer */
- if (alarmtimer_get_rtcdev()) {
+ if (alarmtimer_has_rtcdev()) {
cm_timer = devm_kzalloc(cm->dev, sizeof(*cm_timer), GFP_KERNEL);
if (!cm_timer)
return -ENOMEM;
diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 2014288ca2f4..3dd6d8762a73 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -6,8 +6,6 @@
#include <linux/hrtimer.h>
#include <linux/timerqueue.h>
-struct rtc_device;
-
enum alarmtimer_type {
ALARM_REALTIME,
ALARM_BOOTTIME,
@@ -58,10 +56,9 @@ u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
ktime_t alarm_expires_remaining(const struct alarm *alarm);
#ifdef CONFIG_RTC_CLASS
-/* Provide way to access the rtc device being used by alarmtimers */
-struct rtc_device *alarmtimer_get_rtcdev(void);
+bool alarmtimer_has_rtcdev(void);
#else
-static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
+static inline bool alarmtimer_has_rtcdev(void) { return false; }
#endif
#endif
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index ecf8c89f7eaf..6c663f7d93c2 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -63,15 +63,15 @@ static struct rtc_timer rtctimer;
static struct rtc_device *rtcdev;
/**
- * alarmtimer_get_rtcdev - Return selected rtcdevice
+ * alarmtimer_has_rtcdev - Check whether an RTC can wake the system for alarms
*
- * This function returns the rtc device to use for wakealarms.
+ * Return: True when alarmtimer has an RTC to program on suspend
*/
-struct rtc_device *alarmtimer_get_rtcdev(void)
+bool alarmtimer_has_rtcdev(void)
{
- return READ_ONCE(rtcdev);
+ return !!READ_ONCE(rtcdev);
}
-EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
+EXPORT_SYMBOL_GPL(alarmtimer_has_rtcdev);
static int alarmtimer_rtc_add_device(struct device *dev)
{
@@ -221,7 +221,7 @@ static int alarmtimer_suspend(struct device *dev)
freezer_delta = 0;
}
- rtc = alarmtimer_get_rtcdev();
+ rtc = READ_ONCE(rtcdev);
/* If we have no rtcdev, just return */
if (!rtc)
return 0;
@@ -285,7 +285,7 @@ static int alarmtimer_resume(struct device *dev)
{
struct rtc_device *rtc;
- rtc = alarmtimer_get_rtcdev();
+ rtc = READ_ONCE(rtcdev);
if (rtc)
rtc_timer_cancel(rtc, &rtctimer);
return 0;
@@ -591,7 +591,7 @@ static bool alarm_timer_arm(struct k_itimer *timr, ktime_t expires,
*/
static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
{
- if (!alarmtimer_get_rtcdev())
+ if (!alarmtimer_has_rtcdev())
return -EINVAL;
tp->tv_sec = 0;
@@ -610,7 +610,7 @@ static int alarm_clock_get_timespec(clockid_t which_clock, struct timespec64 *tp
{
struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
- if (!alarmtimer_get_rtcdev())
+ if (!alarmtimer_has_rtcdev())
return -EINVAL;
base->get_timespec(tp);
@@ -628,7 +628,7 @@ static ktime_t alarm_clock_get_ktime(clockid_t which_clock)
{
struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
- if (!alarmtimer_get_rtcdev())
+ if (!alarmtimer_has_rtcdev())
return -EINVAL;
return base->get_ktime();
@@ -644,7 +644,7 @@ static int alarm_timer_create(struct k_itimer *new_timer)
{
enum alarmtimer_type type;
- if (!alarmtimer_get_rtcdev())
+ if (!alarmtimer_has_rtcdev())
return -EOPNOTSUPP;
if (!capable(CAP_WAKE_ALARM))
@@ -763,7 +763,7 @@ static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
ktime_t exp;
int ret;
- if (!alarmtimer_get_rtcdev())
+ if (!alarmtimer_has_rtcdev())
return -EOPNOTSUPP;
if (flags & ~TIMER_ABSTIME)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 2/8] alarmtimer: Move the wakeup state into struct rtc_wakeup
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 1/8] alarmtimer: Replace alarmtimer_get_rtcdev() with alarmtimer_has_rtcdev() Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 3/8] alarmtimer: Replace the freezer delta with per type expiry times Igor Velkov via B4 Relay
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
The RTC and the RTC timer which alarmtimer programs on suspend and the
record of the clock_nanosleep() call the freezer interrupted are separate
static variables.
Collect them in one struct to prepare for an RTC per suspend state. No
functional change.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
kernel/time/alarmtimer.c | 60 +++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 24 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 6c663f7d93c2..35630f0ff566 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -50,17 +50,29 @@ static struct alarm_base {
} alarm_bases[ALARM_NUMTYPE];
#if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS)
-/* freezer information to handle clock_nanosleep triggered wakeups */
-static enum alarmtimer_type freezer_alarmtype;
-static ktime_t freezer_expires;
-static ktime_t freezer_delta;
+/**
+ * struct rtc_wakeup - State for waking the system from suspend on alarms
+ * @rtc: RTC programmed on suspend, NULL if none
+ * @timer: RTC timer started on suspend
+ * @freezer_delta: Least remaining time of the clock_nanosleep() calls
+ * which the freezer interrupted, 0 if none
+ * @freezer_expires: Expiry of that call
+ * @freezer_type: Alarm type of that call
+ */
+struct rtc_wakeup {
+ struct rtc_device *rtc;
+ struct rtc_timer timer;
+ ktime_t freezer_delta;
+ ktime_t freezer_expires;
+ enum alarmtimer_type freezer_type;
+};
+
+static struct rtc_wakeup wakeup_ctl;
+
static DEFINE_SPINLOCK(freezer_delta_lock);
#endif
#ifdef CONFIG_RTC_CLASS
-/* rtc timer and device for setting alarm wakeups at suspend */
-static struct rtc_timer rtctimer;
-static struct rtc_device *rtcdev;
/**
* alarmtimer_has_rtcdev - Check whether an RTC can wake the system for alarms
@@ -69,7 +81,7 @@ static struct rtc_device *rtcdev;
*/
bool alarmtimer_has_rtcdev(void)
{
- return !!READ_ONCE(rtcdev);
+ return !!READ_ONCE(wakeup_ctl.rtc);
}
EXPORT_SYMBOL_GPL(alarmtimer_has_rtcdev);
@@ -78,7 +90,7 @@ static int alarmtimer_rtc_add_device(struct device *dev)
struct rtc_device *rtc = to_rtc_device(dev);
struct platform_device *pdev;
- if (rtcdev)
+ if (wakeup_ctl.rtc)
return -EBUSY;
if (!test_bit(RTC_FEATURE_ALARM, rtc->features))
@@ -98,7 +110,7 @@ static int alarmtimer_rtc_add_device(struct device *dev)
return -1;
}
- WRITE_ONCE(rtcdev, rtc);
+ WRITE_ONCE(wakeup_ctl.rtc, rtc);
/* Hold a reference so it doesn't go away */
get_device(dev);
@@ -107,7 +119,7 @@ static int alarmtimer_rtc_add_device(struct device *dev)
static inline void alarmtimer_rtc_timer_init(void)
{
- rtc_timer_init(&rtctimer, NULL, NULL);
+ rtc_timer_init(&wakeup_ctl.timer, NULL, NULL);
}
static struct class_interface alarmtimer_rtc_interface = {
@@ -215,13 +227,13 @@ static int alarmtimer_suspend(struct device *dev)
int i, ret, type;
scoped_guard(spinlock_irqsave, &freezer_delta_lock) {
- min = freezer_delta;
- expires = freezer_expires;
- type = freezer_alarmtype;
- freezer_delta = 0;
+ min = wakeup_ctl.freezer_delta;
+ expires = wakeup_ctl.freezer_expires;
+ type = wakeup_ctl.freezer_type;
+ wakeup_ctl.freezer_delta = 0;
}
- rtc = READ_ONCE(rtcdev);
+ rtc = READ_ONCE(wakeup_ctl.rtc);
/* If we have no rtcdev, just return */
if (!rtc)
return 0;
@@ -258,7 +270,7 @@ static int alarmtimer_suspend(struct device *dev)
trace_alarmtimer_suspend(expires, type);
/* Setup an rtc timer to fire that far in the future */
- rtc_timer_cancel(rtc, &rtctimer);
+ rtc_timer_cancel(rtc, &wakeup_ctl.timer);
rtc_read_time(rtc, &tm);
now = rtc_tm_to_ktime(tm);
@@ -275,7 +287,7 @@ static int alarmtimer_suspend(struct device *dev)
now = ktime_add(now, min);
/* Set alarm, if in the past reject suspend briefly to handle */
- ret = rtc_timer_start(rtc, &rtctimer, now, 0);
+ ret = rtc_timer_start(rtc, &wakeup_ctl.timer, now, 0);
if (ret < 0)
pm_wakeup_event(dev, MSEC_PER_SEC);
return ret;
@@ -285,9 +297,9 @@ static int alarmtimer_resume(struct device *dev)
{
struct rtc_device *rtc;
- rtc = READ_ONCE(rtcdev);
+ rtc = READ_ONCE(wakeup_ctl.rtc);
if (rtc)
- rtc_timer_cancel(rtc, &rtctimer);
+ rtc_timer_cancel(rtc, &wakeup_ctl.timer);
return 0;
}
@@ -462,10 +474,10 @@ static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
delta = ktime_sub(absexp, base->get_ktime());
guard(spinlock_irqsave)(&freezer_delta_lock);
- if (!freezer_delta || (delta < freezer_delta)) {
- freezer_delta = delta;
- freezer_expires = absexp;
- freezer_alarmtype = type;
+ if (!wakeup_ctl.freezer_delta || (delta < wakeup_ctl.freezer_delta)) {
+ wakeup_ctl.freezer_delta = delta;
+ wakeup_ctl.freezer_expires = absexp;
+ wakeup_ctl.freezer_type = type;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 3/8] alarmtimer: Replace the freezer delta with per type expiry times
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 1/8] alarmtimer: Replace alarmtimer_get_rtcdev() with alarmtimer_has_rtcdev() Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 2/8] alarmtimer: Move the wakeup state into struct rtc_wakeup Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 4/8] alarmtimer: Register the platform device without a parent Igor Velkov via B4 Relay
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
When the freezer interrupts an alarm clock_nanosleep(),
alarmtimer_freezerset() records the remaining time, the expiry and the
alarm type and keeps the call with the least remaining time.
alarmtimer_suspend() starts its scan with that.
The remaining time is computed when the task is frozen, so it is stale
when the system suspends, and a clock_settime() in between is not taken
into account for REALTIME. A remaining time of exactly 0 counts as no
timer.
Record the earliest expiry per alarm type instead, KTIME_MAX for none, and
compare it with the queue head of its base in alarmtimer_suspend(), so the
remaining time is computed when it is used. The scan also takes KTIME_MAX
instead of 0 as no timer.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
Unlike your sketch and what I wrote, this keeps the frozen expiry per
type and compares it with the queue head in the suspend scan instead of
queueing alarms: such an alarm would exist only to be read back, and if
it fires in between, alarmtimer_fired() drops it and suspend proceeds
without the wakeup. A version with alarms came out 44 lines longer.
---
kernel/time/alarmtimer.c | 75 ++++++++++++++++++------------------------------
1 file changed, 28 insertions(+), 47 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 35630f0ff566..066d980fa6d5 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -54,22 +54,20 @@ static struct alarm_base {
* struct rtc_wakeup - State for waking the system from suspend on alarms
* @rtc: RTC programmed on suspend, NULL if none
* @timer: RTC timer started on suspend
- * @freezer_delta: Least remaining time of the clock_nanosleep() calls
- * which the freezer interrupted, 0 if none
- * @freezer_expires: Expiry of that call
- * @freezer_type: Alarm type of that call
+ * @freezer_expires: Earliest expiry per alarm type of the clock_nanosleep()
+ * calls which the freezer interrupted, KTIME_MAX if none
*/
struct rtc_wakeup {
struct rtc_device *rtc;
struct rtc_timer timer;
- ktime_t freezer_delta;
- ktime_t freezer_expires;
- enum alarmtimer_type freezer_type;
+ ktime_t freezer_expires[ALARM_NUMTYPE];
};
-static struct rtc_wakeup wakeup_ctl;
+static struct rtc_wakeup wakeup_ctl = {
+ .freezer_expires = { [0 ... ALARM_NUMTYPE - 1] = KTIME_MAX },
+};
-static DEFINE_SPINLOCK(freezer_delta_lock);
+static DEFINE_SPINLOCK(freezer_lock);
#endif
#ifdef CONFIG_RTC_CLASS
@@ -221,28 +219,22 @@ EXPORT_SYMBOL_GPL(alarm_expires_remaining);
*/
static int alarmtimer_suspend(struct device *dev)
{
- ktime_t min, now, expires;
+ ktime_t min = KTIME_MAX, expires = 0, now;
struct rtc_device *rtc;
+ int i, ret, type = 0;
struct rtc_time tm;
- int i, ret, type;
-
- scoped_guard(spinlock_irqsave, &freezer_delta_lock) {
- min = wakeup_ctl.freezer_delta;
- expires = wakeup_ctl.freezer_expires;
- type = wakeup_ctl.freezer_type;
- wakeup_ctl.freezer_delta = 0;
- }
rtc = READ_ONCE(wakeup_ctl.rtc);
/* If we have no rtcdev, just return */
if (!rtc)
return 0;
- /* Find the soonest timer to expire */
+ /* Find the soonest timer to expire, frozen clock_nanosleep() included */
for (i = 0; i < ALARM_NUMTYPE; i++) {
struct alarm_base *base = &alarm_bases[i];
+ ktime_t next_expires = KTIME_MAX;
struct timerqueue_node *next;
- ktime_t next_expires;
+ int next_type = i;
ktime_t delta;
scoped_guard(spinlock_irqsave, &base->lock) {
@@ -250,16 +242,24 @@ static int alarmtimer_suspend(struct device *dev)
if (next)
next_expires = next->expires;
}
- if (!next)
+ scoped_guard(spinlock_irqsave, &freezer_lock) {
+ if (wakeup_ctl.freezer_expires[i] < next_expires) {
+ next_expires = wakeup_ctl.freezer_expires[i];
+ next_type = i == ALARM_REALTIME ?
+ ALARM_REALTIME_FREEZER : ALARM_BOOTTIME_FREEZER;
+ }
+ wakeup_ctl.freezer_expires[i] = KTIME_MAX;
+ }
+ if (next_expires == KTIME_MAX)
continue;
delta = ktime_sub(next_expires, base->get_ktime());
- if (!min || (delta < min)) {
+ if (delta < min) {
expires = next_expires;
min = delta;
- type = i;
+ type = next_type;
}
}
- if (min == 0)
+ if (min == KTIME_MAX)
return 0;
if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
@@ -454,31 +454,12 @@ EXPORT_SYMBOL_GPL(alarm_forward_now);
static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
{
- struct alarm_base *base;
- ktime_t delta;
-
- switch(type) {
- case ALARM_REALTIME:
- base = &alarm_bases[ALARM_REALTIME];
- type = ALARM_REALTIME_FREEZER;
- break;
- case ALARM_BOOTTIME:
- base = &alarm_bases[ALARM_BOOTTIME];
- type = ALARM_BOOTTIME_FREEZER;
- break;
- default:
- WARN_ONCE(1, "Invalid alarm type: %d\n", type);
+ if (WARN_ONCE(type >= ALARM_NUMTYPE, "Invalid alarm type: %d\n", type))
return;
- }
- delta = ktime_sub(absexp, base->get_ktime());
-
- guard(spinlock_irqsave)(&freezer_delta_lock);
- if (!wakeup_ctl.freezer_delta || (delta < wakeup_ctl.freezer_delta)) {
- wakeup_ctl.freezer_delta = delta;
- wakeup_ctl.freezer_expires = absexp;
- wakeup_ctl.freezer_type = type;
- }
+ guard(spinlock_irqsave)(&freezer_lock);
+ if (absexp < wakeup_ctl.freezer_expires[type])
+ wakeup_ctl.freezer_expires[type] = absexp;
}
/**
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 4/8] alarmtimer: Register the platform device without a parent
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
` (2 preceding siblings ...)
2026-11-16 0:25 ` [PATCH v2 3/8] alarmtimer: Replace the freezer delta with per type expiry times Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 5/8] alarmtimer: Keep an RTC per suspend state Igor Velkov via B4 Relay
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
alarmtimer registers its platform device as a child of the wakeup RTC, so
the driver core suspends it before the RTC and alarmtimer_suspend() can
program the RTC. A device with one parent cannot be ordered against a
second RTC.
Register the device without a parent once the RTC is taken and add a
device link to the RTC, which keeps the device after the RTC in dpm_list
also when the RTC is moved there later, so it still suspends first.
Add links named after the suspend states, which point to the RTC that
wakes the system from that state. The names are those of
/sys/power/mem_sleep: in /sys/power/state "mem" stands for whichever
state mem_sleep selects, which can be s2idle.
The device moves from under the RTC to /sys/devices/platform, its name
stays alarmtimer.N.auto.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
kernel/time/alarmtimer.c | 45 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 38 insertions(+), 7 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 066d980fa6d5..4f87df95edcd 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -26,6 +26,7 @@
#include <linux/freezer.h>
#include <linux/compat.h>
#include <linux/module.h>
+#include <linux/suspend.h>
#include <linux/time_namespace.h>
#include "posix-timers.h"
@@ -53,12 +54,14 @@ static struct alarm_base {
/**
* struct rtc_wakeup - State for waking the system from suspend on alarms
* @rtc: RTC programmed on suspend, NULL if none
+ * @pdev: Device whose suspend and resume callbacks program the RTC
* @timer: RTC timer started on suspend
* @freezer_expires: Earliest expiry per alarm type of the clock_nanosleep()
* calls which the freezer interrupted, KTIME_MAX if none
*/
struct rtc_wakeup {
struct rtc_device *rtc;
+ struct platform_device *pdev;
struct rtc_timer timer;
ktime_t freezer_expires[ALARM_NUMTYPE];
};
@@ -71,6 +74,16 @@ static DEFINE_SPINLOCK(freezer_lock);
#endif
#ifdef CONFIG_RTC_CLASS
+/* Suspend state names as in /sys/power/mem_sleep */
+static const char * const alarmtimer_state_names[PM_SUSPEND_MAX] = {
+ [PM_SUSPEND_TO_IDLE] = "s2idle",
+ [PM_SUSPEND_STANDBY] = "shallow",
+ [PM_SUSPEND_MEM] = "deep",
+};
+
+/* Bounds of suspend_state_t as integers for loops, bit masks and indices */
+#define ALARMTIMER_STATE_MIN ((__force int)PM_SUSPEND_MIN)
+#define ALARMTIMER_STATE_MAX ((__force int)PM_SUSPEND_MAX)
/**
* alarmtimer_has_rtcdev - Check whether an RTC can wake the system for alarms
@@ -83,10 +96,20 @@ bool alarmtimer_has_rtcdev(void)
}
EXPORT_SYMBOL_GPL(alarmtimer_has_rtcdev);
+/* Show in sysfs which RTC wakes the system from @state */
+static void alarmtimer_link_state(int state, struct device *dev)
+{
+ const char *name = alarmtimer_state_names[state];
+
+ if (sysfs_create_link(&wakeup_ctl.pdev->dev.kobj, &dev->kobj, name))
+ dev_warn(&wakeup_ctl.pdev->dev, "Cannot link %s to %s\n", name, dev_name(dev));
+}
+
static int alarmtimer_rtc_add_device(struct device *dev)
{
struct rtc_device *rtc = to_rtc_device(dev);
struct platform_device *pdev;
+ int state;
if (wakeup_ctl.rtc)
return -EBUSY;
@@ -96,22 +119,30 @@ static int alarmtimer_rtc_add_device(struct device *dev)
if (!device_may_wakeup(rtc->dev.parent))
return -1;
- pdev = platform_device_register_data(dev, "alarmtimer",
+ if (!try_module_get(rtc->owner))
+ return -1;
+
+ pdev = platform_device_register_data(NULL, "alarmtimer",
PLATFORM_DEVID_AUTO, NULL, 0);
- if (IS_ERR(pdev))
+ if (IS_ERR(pdev)) {
+ module_put(rtc->owner);
return PTR_ERR(pdev);
-
- device_init_wakeup(&pdev->dev, true);
-
- if (!try_module_get(rtc->owner)) {
+ }
+ /* Keep the device after the RTC in dpm_list, so it suspends first */
+ if (!device_link_add(&pdev->dev, dev, DL_FLAG_STATELESS)) {
platform_device_unregister(pdev);
- return -1;
+ module_put(rtc->owner);
+ return -ENODEV;
}
+ device_init_wakeup(&pdev->dev, true);
+ wakeup_ctl.pdev = pdev;
WRITE_ONCE(wakeup_ctl.rtc, rtc);
/* Hold a reference so it doesn't go away */
get_device(dev);
+ for (state = ALARMTIMER_STATE_MIN; state < ALARMTIMER_STATE_MAX; state++)
+ alarmtimer_link_state(state, dev);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 5/8] alarmtimer: Keep an RTC per suspend state
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
` (3 preceding siblings ...)
2026-11-16 0:25 ` [PATCH v2 4/8] alarmtimer: Register the platform device without a parent Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states Igor Velkov via B4 Relay
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
alarmtimer takes the first RTC that has an alarm and a wakeup capable
parent and programs it whatever the suspend state. Which RTC wakes the
system can depend on the state: on ODROID-HC4, meson-vrtc is a register
the firmware reads when the application processors suspend, with no
interrupt in Linux, so it wakes the board from deep sleep only, while the
pcf8563 wakes it from s2idle.
Keep an RTC per suspend state instead. An RTC takes the states from which
its alarm wakes the system, minus those an earlier RTC took, and is
refused when none is left. For now every RTC is taken to wake the system
from all states, so the first RTC takes all of them, as before.
Link the platform device to each RTC taken, so it suspends before all of
them. alarmtimer_suspend() programs the RTC of the target state; once an
RTC can be limited to some states, it rejects the suspend when an alarm
is pending and no RTC wakes the system from that state.
alarmtimer_resume() cancels the timer on the RTC it was started on, so
alarmtimer_suspend() no longer cancels it before starting it.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
kernel/time/alarmtimer.c | 84 +++++++++++++++++++++++++++++++-----------------
1 file changed, 55 insertions(+), 29 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 4f87df95edcd..4153cce182a4 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -53,16 +53,20 @@ static struct alarm_base {
#if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS)
/**
* struct rtc_wakeup - State for waking the system from suspend on alarms
- * @rtc: RTC programmed on suspend, NULL if none
+ * @rtc: RTC per suspend state, NULL if none wakes the system from it
+ * @active_rtc: RTC on which @timer is started, NULL if none
* @pdev: Device whose suspend and resume callbacks program the RTC
* @timer: RTC timer started on suspend
+ * @assigned: Mask of the suspend states which have an RTC
* @freezer_expires: Earliest expiry per alarm type of the clock_nanosleep()
* calls which the freezer interrupted, KTIME_MAX if none
*/
struct rtc_wakeup {
- struct rtc_device *rtc;
+ struct rtc_device *rtc[PM_SUSPEND_MAX];
+ struct rtc_device *active_rtc;
struct platform_device *pdev;
struct rtc_timer timer;
+ unsigned long assigned;
ktime_t freezer_expires[ALARM_NUMTYPE];
};
@@ -85,6 +89,8 @@ static const char * const alarmtimer_state_names[PM_SUSPEND_MAX] = {
#define ALARMTIMER_STATE_MIN ((__force int)PM_SUSPEND_MIN)
#define ALARMTIMER_STATE_MAX ((__force int)PM_SUSPEND_MAX)
+#define ALARMTIMER_STATES_ALL GENMASK(ALARMTIMER_STATE_MAX - 1, ALARMTIMER_STATE_MIN)
+
/**
* alarmtimer_has_rtcdev - Check whether an RTC can wake the system for alarms
*
@@ -92,7 +98,7 @@ static const char * const alarmtimer_state_names[PM_SUSPEND_MAX] = {
*/
bool alarmtimer_has_rtcdev(void)
{
- return !!READ_ONCE(wakeup_ctl.rtc);
+ return !!READ_ONCE(wakeup_ctl.assigned);
}
EXPORT_SYMBOL_GPL(alarmtimer_has_rtcdev);
@@ -105,44 +111,61 @@ static void alarmtimer_link_state(int state, struct device *dev)
dev_warn(&wakeup_ctl.pdev->dev, "Cannot link %s to %s\n", name, dev_name(dev));
}
+/* Suspend states from which an alarm of the RTC on @dev wakes the system */
+static unsigned long alarmtimer_wakeup_states(struct device *dev)
+{
+ return ALARMTIMER_STATES_ALL;
+}
+
static int alarmtimer_rtc_add_device(struct device *dev)
{
struct rtc_device *rtc = to_rtc_device(dev);
struct platform_device *pdev;
+ unsigned long states;
int state;
- if (wakeup_ctl.rtc)
- return -EBUSY;
-
if (!test_bit(RTC_FEATURE_ALARM, rtc->features))
return -1;
if (!device_may_wakeup(rtc->dev.parent))
return -1;
+ /* The first RTC for a suspend state wakes the system from it */
+ states = alarmtimer_wakeup_states(rtc->dev.parent) & ~wakeup_ctl.assigned;
+ if (!states)
+ return -EBUSY;
+
if (!try_module_get(rtc->owner))
return -1;
- pdev = platform_device_register_data(NULL, "alarmtimer",
- PLATFORM_DEVID_AUTO, NULL, 0);
- if (IS_ERR(pdev)) {
- module_put(rtc->owner);
- return PTR_ERR(pdev);
+ pdev = wakeup_ctl.pdev;
+ if (!pdev) {
+ pdev = platform_device_register_data(NULL, "alarmtimer",
+ PLATFORM_DEVID_AUTO, NULL, 0);
+ if (IS_ERR(pdev)) {
+ module_put(rtc->owner);
+ return PTR_ERR(pdev);
+ }
}
/* Keep the device after the RTC in dpm_list, so it suspends first */
if (!device_link_add(&pdev->dev, dev, DL_FLAG_STATELESS)) {
- platform_device_unregister(pdev);
+ if (pdev != wakeup_ctl.pdev)
+ platform_device_unregister(pdev);
module_put(rtc->owner);
return -ENODEV;
}
- device_init_wakeup(&pdev->dev, true);
- wakeup_ctl.pdev = pdev;
+ if (!wakeup_ctl.pdev) {
+ device_init_wakeup(&pdev->dev, true);
+ wakeup_ctl.pdev = pdev;
+ }
- WRITE_ONCE(wakeup_ctl.rtc, rtc);
/* Hold a reference so it doesn't go away */
get_device(dev);
- for (state = ALARMTIMER_STATE_MIN; state < ALARMTIMER_STATE_MAX; state++)
+ for_each_set_bit(state, &states, ALARMTIMER_STATE_MAX) {
+ wakeup_ctl.rtc[state] = rtc;
alarmtimer_link_state(state, dev);
+ }
+ WRITE_ONCE(wakeup_ctl.assigned, wakeup_ctl.assigned | states);
return 0;
}
@@ -255,11 +278,6 @@ static int alarmtimer_suspend(struct device *dev)
int i, ret, type = 0;
struct rtc_time tm;
- rtc = READ_ONCE(wakeup_ctl.rtc);
- /* If we have no rtcdev, just return */
- if (!rtc)
- return 0;
-
/* Find the soonest timer to expire, frozen clock_nanosleep() included */
for (i = 0; i < ALARM_NUMTYPE; i++) {
struct alarm_base *base = &alarm_bases[i];
@@ -293,6 +311,13 @@ static int alarmtimer_suspend(struct device *dev)
if (min == KTIME_MAX)
return 0;
+ /* No RTC wakes the system from this state for the pending alarm */
+ rtc = wakeup_ctl.rtc[(__force int)pm_suspend_target_state];
+ if (!rtc) {
+ pm_wakeup_event(dev, MSEC_PER_SEC);
+ return -EOPNOTSUPP;
+ }
+
if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
pm_wakeup_event(dev, 2 * MSEC_PER_SEC);
return -EBUSY;
@@ -301,7 +326,6 @@ static int alarmtimer_suspend(struct device *dev)
trace_alarmtimer_suspend(expires, type);
/* Setup an rtc timer to fire that far in the future */
- rtc_timer_cancel(rtc, &wakeup_ctl.timer);
rtc_read_time(rtc, &tm);
now = rtc_tm_to_ktime(tm);
@@ -319,18 +343,20 @@ static int alarmtimer_suspend(struct device *dev)
/* Set alarm, if in the past reject suspend briefly to handle */
ret = rtc_timer_start(rtc, &wakeup_ctl.timer, now, 0);
- if (ret < 0)
+ if (ret < 0) {
pm_wakeup_event(dev, MSEC_PER_SEC);
- return ret;
+ return ret;
+ }
+ wakeup_ctl.active_rtc = rtc;
+ return 0;
}
static int alarmtimer_resume(struct device *dev)
{
- struct rtc_device *rtc;
-
- rtc = READ_ONCE(wakeup_ctl.rtc);
- if (rtc)
- rtc_timer_cancel(rtc, &wakeup_ctl.timer);
+ if (wakeup_ctl.active_rtc) {
+ rtc_timer_cancel(wakeup_ctl.active_rtc, &wakeup_ctl.timer);
+ wakeup_ctl.active_rtc = NULL;
+ }
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
` (4 preceding siblings ...)
2026-11-16 0:25 ` [PATCH v2 5/8] alarmtimer: Keep an RTC per suspend state Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:34 ` sashiko-bot
2026-11-16 0:25 ` [PATCH v2 7/8] alarmtimer: Read the wakeup states of an RTC from linux,wakeup-states Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 8/8] arm64: dts: amlogic: meson-sm1-odroid-hc4: Describe which RTC wakes the board Igor Velkov via B4 Relay
7 siblings, 1 reply; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
A board can have more than one RTC with an alarm that wakes the system,
for example an I2C RTC next to an RTC in the PMIC or the SoC firmware.
Which of them wakes the system depends on the sleep state and on the
board's firmware: amlogic,meson-vrtc is a register the firmware reads
when the application processors suspend, so it wakes the system from
deep sleep only, and whether an I2C RTC wakes the system from deep
sleep depends on the firmware handling its interrupt line.
Add linux,wakeup-states to describe this per RTC: the suspend states an
alarm of the RTC wakes the system from, named as in /sys/power/mem_sleep,
or none for an RTC whose alarm wakes the system from no suspend state.
List it in nxp,pcf8563.yaml and amlogic,meson-vrtc.yaml, which do not
allow unlisted properties.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
.../devicetree/bindings/rtc/amlogic,meson-vrtc.yaml | 2 ++
Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml | 2 ++
Documentation/devicetree/bindings/rtc/rtc.yaml | 17 +++++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml b/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
index a89865fa676a..51cce4b2a7ff 100644
--- a/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
@@ -30,6 +30,8 @@ properties:
reg:
maxItems: 1
+ linux,wakeup-states: true
+
required:
- compatible
- reg
diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
index 22909a96123e..e464432e4690 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
+++ b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
@@ -32,6 +32,8 @@ properties:
interrupts:
maxItems: 1
+ linux,wakeup-states: true
+
start-year: true
wakeup-source: true
diff --git a/Documentation/devicetree/bindings/rtc/rtc.yaml b/Documentation/devicetree/bindings/rtc/rtc.yaml
index e46d50b1063e..54f41858dda4 100644
--- a/Documentation/devicetree/bindings/rtc/rtc.yaml
+++ b/Documentation/devicetree/bindings/rtc/rtc.yaml
@@ -26,6 +26,23 @@ properties:
0: not chargeable
1: chargeable
+ linux,wakeup-states:
+ $ref: /schemas/types.yaml#/definitions/string-array
+ description:
+ Suspend states an alarm of this RTC wakes the system from, given
+ the board and its firmware, named as in /sys/power/mem_sleep. none,
+ given alone, means the alarm wakes the system from no suspend
+ state. An RTC without this property is taken to wake the system
+ from every suspend state.
+ oneOf:
+ - items:
+ enum:
+ - s2idle
+ - shallow
+ - deep
+ - items:
+ - const: none
+
quartz-load-femtofarads:
description:
The capacitive load of the quartz(x-tal), expressed in femto
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states
2026-11-16 0:25 ` [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states Igor Velkov via B4 Relay
@ 2026-11-16 0:34 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-16 0:34 UTC (permalink / raw)
To: Igor Velkov
Cc: linux-rtc, devicetree, linux-amlogic, robh, conor+dt,
neil.armstrong, Alexandre Belloni
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dt-bindings: rtc: OS-specific mem_sleep states in
linux,wakeup-states
--
commit 37e39721822efb2f3ac3e76aaec271ff0edbe18b
Author: Igor Velkov <iav@iav.lv>
dt-bindings: rtc: Add linux,wakeup-states
This commit adds a linux,wakeup-states property to the generic RTC binding
schema to specify which suspend states an RTC alarm can wake the system
from, and allows the property in the Amlogic Meson VRTC and NXP PCF8563
bindings.
> diff --git a/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml b/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
> index a89865fa676a6..51cce4b2a7ff3 100644
> --- a/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/amlogic,meson-vrtc.yaml
> @@ -30,6 +30,8 @@ properties:
> reg:
> maxItems: 1
>
> + linux,wakeup-states: true
> +
> required:
> - compatible
> - reg
> diff --git a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
> index 22909a96123e5..e464432e4690f 100644
> --- a/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
> +++ b/Documentation/devicetree/bindings/rtc/nxp,pcf8563.yaml
> @@ -32,6 +32,8 @@ properties:
> interrupts:
> maxItems: 1
>
> + linux,wakeup-states: true
> +
> start-year: true
> wakeup-source: true
>
> diff --git a/Documentation/devicetree/bindings/rtc/rtc.yaml b/Documentation/devicetree/bindings/rtc/rtc.yaml
> index e46d50b1063e4..54f41858dda47 100644
> --- a/Documentation/devicetree/bindings/rtc/rtc.yaml
> +++ b/Documentation/devicetree/bindings/rtc/rtc.yaml
> @@ -26,6 +26,23 @@ properties:
> 0: not chargeable
> 1: chargeable
>
> + linux,wakeup-states:
> + $ref: /schemas/types.yaml#/definitions/string-array
> + description:
> + Suspend states an alarm of this RTC wakes the system from, given
> + the board and its firmware, named as in /sys/power/mem_sleep. none,
> + given alone, means the alarm wakes the system from no suspend
> + state. An RTC without this property is taken to wake the system
> + from every suspend state.
> + oneOf:
> + - items:
> + enum:
> + - s2idle
> + - shallow
> + - deep
> + - items:
> + - const: none
> +
> quartz-load-femtofarads:
> description:
> The capacitive load of the quartz(x-tal), expressed in femto
[Severity: Medium]
Does linux,wakeup-states encode Linux-specific /sys/power/mem_sleep labels
and information already deducible from the hardware description into the
Devicetree ABI?
In particular, s2idle is a Linux software freeze state where wakeup
capability is determined by whether the RTC has an OS interrupt wired via
interrupts, rather than a list of sysfs state names. For
amlogic,meson-vrtc, waking the system only from platform suspend is
inherent to the compatible string because the device is a scratch register
written during meson_vrtc_suspend() for the SCP firmware and has no OS
interrupt line. Finally, allowing none duplicates the absence of the
standard wakeup-source property and permits contradictory combinations such
as setting both wakeup-source and linux,wakeup-states = "none" on the same
node.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-b4-alarmtimer-rtc-priority-v2-0-b2c69721e489@iav.lv?part=6
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 7/8] alarmtimer: Read the wakeup states of an RTC from linux,wakeup-states
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
` (5 preceding siblings ...)
2026-11-16 0:25 ` [PATCH v2 6/8] dt-bindings: rtc: Add linux,wakeup-states Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
2026-11-16 0:25 ` [PATCH v2 8/8] arm64: dts: amlogic: meson-sm1-odroid-hc4: Describe which RTC wakes the board Igor Velkov via B4 Relay
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
Every RTC is taken to wake the system from all suspend states, so the
first RTC with an alarm and a wakeup capable parent takes all of them.
Take the suspend states listed in the linux,wakeup-states property of the
RTC's parent instead, all of them without the property. An RTC with
"none" is not used.
On ODROID-HC4 this lets the pcf8563 wake the board from s2idle and
meson-vrtc from deep sleep.
Signed-off-by: Igor Velkov <iav@iav.lv>
---
kernel/time/alarmtimer.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 4153cce182a4..0770f4b0ca86 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -26,6 +26,7 @@
#include <linux/freezer.h>
#include <linux/compat.h>
#include <linux/module.h>
+#include <linux/property.h>
#include <linux/suspend.h>
#include <linux/time_namespace.h>
@@ -111,10 +112,21 @@ static void alarmtimer_link_state(int state, struct device *dev)
dev_warn(&wakeup_ctl.pdev->dev, "Cannot link %s to %s\n", name, dev_name(dev));
}
-/* Suspend states from which an alarm of the RTC on @dev wakes the system */
+/* Suspend states from linux,wakeup-states, all of them without the property */
static unsigned long alarmtimer_wakeup_states(struct device *dev)
{
- return ALARMTIMER_STATES_ALL;
+ unsigned long states = 0;
+ int state;
+
+ if (!device_property_present(dev, "linux,wakeup-states"))
+ return ALARMTIMER_STATES_ALL;
+
+ for (state = ALARMTIMER_STATE_MIN; state < ALARMTIMER_STATE_MAX; state++) {
+ if (device_property_match_string(dev, "linux,wakeup-states",
+ alarmtimer_state_names[state]) >= 0)
+ states |= BIT(state);
+ }
+ return states;
}
static int alarmtimer_rtc_add_device(struct device *dev)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 8/8] arm64: dts: amlogic: meson-sm1-odroid-hc4: Describe which RTC wakes the board
2026-11-16 0:24 [PATCH v2 0/8] alarmtimer: Pick the wakeup RTC per suspend state Igor Velkov via B4 Relay
` (6 preceding siblings ...)
2026-11-16 0:25 ` [PATCH v2 7/8] alarmtimer: Read the wakeup states of an RTC from linux,wakeup-states Igor Velkov via B4 Relay
@ 2026-11-16 0:25 ` Igor Velkov via B4 Relay
7 siblings, 0 replies; 10+ messages in thread
From: Igor Velkov via B4 Relay @ 2026-11-16 0:25 UTC (permalink / raw)
To: John Stultz, Thomas Gleixner, Alexandre Belloni, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Neil Armstrong, Kevin Hilman
Cc: Stephen Boyd, Miroslav Lichvar, Jerome Brunet,
Martin Blumenstingl, linux-rtc, devicetree, linux-arm-kernel,
linux-amlogic, linux-kernel, Igor Velkov
From: Igor Velkov <iav@iav.lv>
The board has two RTCs with an alarm. The pcf8563 interrupt line goes
to GPIOX_5, so once that interrupt is described [1], its alarm wakes the
board from s2idle. meson-vrtc is a register the SoC firmware reads when
the application processors suspend, so it wakes the board from deep
sleep only, and only with a BL301 that handles its alarm.
List the states per RTC, so that alarmtimer programs the pcf8563 for
s2idle and meson-vrtc for deep sleep.
Link: https://lore.kernel.org/r/20261019-hc4-rtc-alarm-irq-v1-1-078fc79e596f@iav.lv [1]
Signed-off-by: Igor Velkov <iav@iav.lv>
---
arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts b/arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts
index 5f15c2299509..0dd9cd2d8245 100644
--- a/arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts
+++ b/arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts
@@ -106,6 +106,7 @@ rtc: rtc@51 {
compatible = "nxp,pcf8563";
reg = <0x51>;
wakeup-source;
+ linux,wakeup-states = "s2idle";
};
};
@@ -142,3 +143,7 @@ &usb {
phys = <&usb2_phy0>, <&usb2_phy1>;
phy-names = "usb2-phy0", "usb2-phy1";
};
+
+&vrtc {
+ linux,wakeup-states = "deep";
+};
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread