Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Zhao Yakui and committed by
Linus Torvalds
c116bc2a e2bfe342

+11 -1
+11 -1
drivers/rtc/rtc-sysfs.c
··· 145 145 unsigned long now, alarm; 146 146 struct rtc_wkalrm alm; 147 147 struct rtc_device *rtc = to_rtc_device(dev); 148 + char *buf_ptr; 149 + int adjust = 0; 148 150 149 151 /* Only request alarms that trigger in the future. Disable them 150 152 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC. ··· 156 154 return retval; 157 155 rtc_tm_to_time(&alm.time, &now); 158 156 159 - alarm = simple_strtoul(buf, NULL, 0); 157 + buf_ptr = (char *)buf; 158 + if (*buf_ptr == '+') { 159 + buf_ptr++; 160 + adjust = 1; 161 + } 162 + alarm = simple_strtoul(buf_ptr, NULL, 0); 163 + if (adjust) { 164 + alarm += now; 165 + } 160 166 if (alarm > now) { 161 167 /* Avoid accidentally clobbering active alarms; we can't 162 168 * entirely prevent that here, without even the minimal