mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
rtc: Add RTC range
Add a way for drivers to inform the core of the supported date/time range. The core can then check whether the date/time or alarm is in the range before calling ->set_time, ->set_mmss or ->set_alarm. It returns -ERANGE when the time is out of range. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
236b718703
commit
71db049e73
4 changed files with 37 additions and 0 deletions
|
@ -43,6 +43,14 @@ Contact: linux-rtc@vger.kernel.org
|
||||||
Description:
|
Description:
|
||||||
(RO) The name of the RTC corresponding to this sysfs directory
|
(RO) The name of the RTC corresponding to this sysfs directory
|
||||||
|
|
||||||
|
What: /sys/class/rtc/rtcX/range
|
||||||
|
Date: January 2018
|
||||||
|
KernelVersion: 4.16
|
||||||
|
Contact: linux-rtc@vger.kernel.org
|
||||||
|
Description:
|
||||||
|
Valid time range for the RTC, as seconds from epoch, formatted
|
||||||
|
as [min, max]
|
||||||
|
|
||||||
What: /sys/class/rtc/rtcX/since_epoch
|
What: /sys/class/rtc/rtcX/since_epoch
|
||||||
Date: March 2006
|
Date: March 2006
|
||||||
KernelVersion: 2.6.17
|
KernelVersion: 2.6.17
|
||||||
|
|
|
@ -70,6 +70,13 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
if (rtc->range_min != rtc->range_max) {
|
||||||
|
time64_t time = rtc_tm_to_time64(tm);
|
||||||
|
|
||||||
|
if (time < rtc->range_min || time > rtc->range_max)
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
err = mutex_lock_interruptible(&rtc->ops_lock);
|
err = mutex_lock_interruptible(&rtc->ops_lock);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
@ -374,6 +381,13 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
if (rtc->range_min != rtc->range_max) {
|
||||||
|
time64_t time = rtc_tm_to_time64(&alarm->time);
|
||||||
|
|
||||||
|
if (time < rtc->range_min || time > rtc->range_max)
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
err = mutex_lock_interruptible(&rtc->ops_lock);
|
err = mutex_lock_interruptible(&rtc->ops_lock);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -248,6 +248,14 @@ offset_store(struct device *dev, struct device_attribute *attr,
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(offset);
|
static DEVICE_ATTR_RW(offset);
|
||||||
|
|
||||||
|
static ssize_t
|
||||||
|
range_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
|
{
|
||||||
|
return sprintf(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min,
|
||||||
|
to_rtc_device(dev)->range_max);
|
||||||
|
}
|
||||||
|
static DEVICE_ATTR_RO(range);
|
||||||
|
|
||||||
static struct attribute *rtc_attrs[] = {
|
static struct attribute *rtc_attrs[] = {
|
||||||
&dev_attr_name.attr,
|
&dev_attr_name.attr,
|
||||||
&dev_attr_date.attr,
|
&dev_attr_date.attr,
|
||||||
|
@ -257,6 +265,7 @@ static struct attribute *rtc_attrs[] = {
|
||||||
&dev_attr_hctosys.attr,
|
&dev_attr_hctosys.attr,
|
||||||
&dev_attr_wakealarm.attr,
|
&dev_attr_wakealarm.attr,
|
||||||
&dev_attr_offset.attr,
|
&dev_attr_offset.attr,
|
||||||
|
&dev_attr_range.attr,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -286,6 +295,9 @@ static umode_t rtc_attr_is_visible(struct kobject *kobj,
|
||||||
} else if (attr == &dev_attr_offset.attr) {
|
} else if (attr == &dev_attr_offset.attr) {
|
||||||
if (!rtc->ops->set_offset)
|
if (!rtc->ops->set_offset)
|
||||||
mode = 0;
|
mode = 0;
|
||||||
|
} else if (attr == &dev_attr_range.attr) {
|
||||||
|
if (!(rtc->range_max - rtc->range_min))
|
||||||
|
mode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
|
|
|
@ -150,6 +150,9 @@ struct rtc_device {
|
||||||
bool nvram_old_abi;
|
bool nvram_old_abi;
|
||||||
struct bin_attribute *nvram;
|
struct bin_attribute *nvram;
|
||||||
|
|
||||||
|
time64_t range_min;
|
||||||
|
timeu64_t range_max;
|
||||||
|
|
||||||
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
|
#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
|
||||||
struct work_struct uie_task;
|
struct work_struct uie_task;
|
||||||
struct timer_list uie_timer;
|
struct timer_list uie_timer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue