Skip to content

Commit

Permalink
rtc: add the support for alarm time relative to current time in sysfs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zhao Yakui authored and Linus Torvalds committed Apr 28, 2008
1 parent e2bfe34 commit c116bc2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/rtc/rtc-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
unsigned long now, alarm;
struct rtc_wkalrm alm;
struct rtc_device *rtc = to_rtc_device(dev);
char *buf_ptr;
int adjust = 0;

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

alarm = simple_strtoul(buf, NULL, 0);
buf_ptr = (char *)buf;
if (*buf_ptr == '+') {
buf_ptr++;
adjust = 1;
}
alarm = simple_strtoul(buf_ptr, NULL, 0);
if (adjust) {
alarm += now;
}
if (alarm > now) {
/* Avoid accidentally clobbering active alarms; we can't
* entirely prevent that here, without even the minimal
Expand Down

0 comments on commit c116bc2

Please sign in to comment.