aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/dev.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-11-12 11:44:31 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2021-11-12 11:44:31 -0800
commit3b81bf78b7338bcc66581593e604e95addc546cc (patch)
tree25cd9891cfd32dafe8cfb83470bf05cd78bbf2b1 /drivers/rtc/dev.c
parentMerge tag 'libata-5.16-rc1-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/dlemoal/libata (diff)
parentrtc: rx8025: use .set_offset/.read_offset (diff)
downloadlinux-dev-3b81bf78b7338bcc66581593e604e95addc546cc.tar.xz
linux-dev-3b81bf78b7338bcc66581593e604e95addc546cc.zip
Merge tag 'rtc-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "This includes new ioctls to get and set parameters and in particular the backup switch mode that is needed for some RTCs to actually enable the backup voltage (and have a useful RTC). The same interface can also be used to get the actual features supported by the RTC so userspace has a better way than trying and failing. Summary: Subsystem: - Add new ioctl to get and set extra RTC parameters, this includes backup switch mode - Expose available features to userspace, in particular, when alarmas have a resolution of one minute instead of a second. - Let the core handle those alarms with a minute resolution New driver: - MSTAR MSC313 RTC Drivers: - Add SPI ID table where necessary - Add BSM support for rv3028, rv3032 and pcf8523 - s3c: set RTC range - rx8025: set range, implement .set_offset and .read_offset" * tag 'rtc-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (50 commits) rtc: rx8025: use .set_offset/.read_offset rtc: rx8025: use rtc_add_group rtc: rx8025: clear RTC_FEATURE_ALARM when alarm are not supported rtc: rx8025: set range rtc: rx8025: let the core handle the alarm resolution rtc: rx8025: switch to devm_rtc_allocate_device rtc: ab8500: let the core handle the alarm resolution rtc: ab-eoz9: support UIE when available rtc: ab-eoz9: use RTC_FEATURE_UPDATE_INTERRUPT rtc: rv3032: let the core handle the alarm resolution rtc: s35390a: let the core handle the alarm resolution rtc: handle alarms with a minute resolution rtc: pcf85063: silence cppcheck warning rtc: rv8803: fix writing back ctrl in flag register rtc: s3c: Add time range rtc: s3c: Extract read/write IO into separate functions rtc: s3c: Remove usage of devm_rtc_device_register() rtc: tps80031: Remove driver rtc: sun6i: Allow probing without an early clock provider rtc: pcf8523: add BSM support ...
Diffstat (limited to 'drivers/rtc/dev.c')
-rw-r--r--drivers/rtc/dev.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/rtc/dev.c b/drivers/rtc/dev.c
index 5b8ebe86124a..e104972a28fd 100644
--- a/drivers/rtc/dev.c
+++ b/drivers/rtc/dev.c
@@ -208,6 +208,7 @@ static long rtc_dev_ioctl(struct file *file,
const struct rtc_class_ops *ops = rtc->ops;
struct rtc_time tm;
struct rtc_wkalrm alarm;
+ struct rtc_param param;
void __user *uarg = (void __user *)arg;
err = mutex_lock_interruptible(&rtc->ops_lock);
@@ -221,6 +222,7 @@ static long rtc_dev_ioctl(struct file *file,
switch (cmd) {
case RTC_EPOCH_SET:
case RTC_SET_TIME:
+ case RTC_PARAM_SET:
if (!capable(CAP_SYS_TIME))
err = -EACCES;
break;
@@ -382,6 +384,69 @@ static long rtc_dev_ioctl(struct file *file,
err = -EFAULT;
return err;
+ case RTC_PARAM_GET:
+ if (copy_from_user(&param, uarg, sizeof(param))) {
+ mutex_unlock(&rtc->ops_lock);
+ return -EFAULT;
+ }
+
+ switch(param.param) {
+ long offset;
+ case RTC_PARAM_FEATURES:
+ if (param.index != 0)
+ err = -EINVAL;
+ param.uvalue = rtc->features[0];
+ break;
+
+ case RTC_PARAM_CORRECTION:
+ mutex_unlock(&rtc->ops_lock);
+ if (param.index != 0)
+ return -EINVAL;
+ err = rtc_read_offset(rtc, &offset);
+ mutex_lock(&rtc->ops_lock);
+ if (err == 0)
+ param.svalue = offset;
+ break;
+
+ default:
+ if (rtc->ops->param_get)
+ err = rtc->ops->param_get(rtc->dev.parent, &param);
+ else
+ err = -EINVAL;
+ }
+
+ if (!err)
+ if (copy_to_user(uarg, &param, sizeof(param)))
+ err = -EFAULT;
+
+ break;
+
+ case RTC_PARAM_SET:
+ if (copy_from_user(&param, uarg, sizeof(param))) {
+ mutex_unlock(&rtc->ops_lock);
+ return -EFAULT;
+ }
+
+ switch(param.param) {
+ case RTC_PARAM_FEATURES:
+ err = -EINVAL;
+ break;
+
+ case RTC_PARAM_CORRECTION:
+ mutex_unlock(&rtc->ops_lock);
+ if (param.index != 0)
+ return -EINVAL;
+ return rtc_set_offset(rtc, param.svalue);
+
+ default:
+ if (rtc->ops->param_set)
+ err = rtc->ops->param_set(rtc->dev.parent, &param);
+ else
+ err = -EINVAL;
+ }
+
+ break;
+
default:
/* Finally try the driver's ioctl interface */
if (ops->ioctl) {