rtc: add correction parameter
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 18 Oct 2021 15:19:30 +0000 (17:19 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 18 Oct 2021 15:20:50 +0000 (17:20 +0200)
Add a new parameter allowing the get and set the correction using ioctls
instead of just sysfs.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211018151933.76865-5-alexandre.belloni@bootlin.com
drivers/rtc/dev.c
include/uapi/linux/rtc.h

index 143c097..abee1fc 100644 (file)
@@ -398,6 +398,16 @@ static long rtc_dev_ioctl(struct file *file,
                        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:
                        err = -EINVAL;
                }
@@ -416,6 +426,15 @@ static long rtc_dev_ioctl(struct file *file,
 
                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:
                        err = -EINVAL;
                }
index c83bb9a..5debe82 100644 (file)
@@ -136,6 +136,7 @@ struct rtc_param {
 
 /* parameter list */
 #define RTC_PARAM_FEATURES             0
+#define RTC_PARAM_CORRECTION           1
 
 #define RTC_MAX_FREQ   8192