Skip to content

Commit c116bc2

Browse files
Zhao Yakuitorvalds
authored andcommitted
rtc: add the support for alarm time relative to current time in sysfs
In current kernel if we want to set the alarm time, the absolute time the seconds relative to 1970-01-01 00:00:00) should be written into /sys/class/rtc/rtc0/wakealarm. It is not convenient. It is more reasonable to add the support for the alarm time relative to current RTC time.(the unit is second) For example: If the RTC is required to generate alarm after 2 minutes, the following will be OK. echo +120 > /sys/class/rtc/rtc0/wakealarm or echo +0x78 > /sys/class/rtc/rtc0/wakealarm Signed-off-by: Zhao Yakui <yakui.zhao@intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e2bfe34 commit c116bc2

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎drivers/rtc/rtc-sysfs.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
145145
unsigned long now, alarm;
146146
struct rtc_wkalrm alm;
147147
struct rtc_device *rtc = to_rtc_device(dev);
148+
char *buf_ptr;
149+
int adjust = 0;
148150

149151
/* Only request alarms that trigger in the future. Disable them
150152
* by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
@@ -154,7 +156,15 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
154156
return retval;
155157
rtc_tm_to_time(&alm.time, &now);
156158

157-
alarm = simple_strtoul(buf, NULL, 0);
159+
buf_ptr = (char *)buf;
160+
if (*buf_ptr == '+') {
161+
buf_ptr++;
162+
adjust = 1;
163+
}
164+
alarm = simple_strtoul(buf_ptr, NULL, 0);
165+
if (adjust) {
166+
alarm += now;
167+
}
158168
if (alarm > now) {
159169
/* Avoid accidentally clobbering active alarms; we can't
160170
* entirely prevent that here, without even the minimal

0 commit comments

Comments
 (0)