rtc: isl12022: implement RTC_VL_READ ioctl
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Thu, 15 Jun 2023 10:58:23 +0000 (12:58 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 15 Aug 2023 23:27:01 +0000 (01:27 +0200)
Hook up support for reading the values of the SR_LBAT85 and SR_LBAT75
bits. Translate the former to "battery low", and the latter to
"battery empty or not-present".

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Link: https://lore.kernel.org/r/20230615105826.411953-6-linux@rasmusvillemoes.dk
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-isl12022.c

index a50eed4e40281add1ff24fd7608ffc3869bf652d..0ed28b57bcd898678ed9c86545030db4e7a751f6 100644 (file)
@@ -204,7 +204,34 @@ static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
        return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf));
 }
 
+static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+       struct regmap *regmap = dev_get_drvdata(dev);
+       u32 user, val;
+       int ret;
+
+       switch (cmd) {
+       case RTC_VL_READ:
+               ret = regmap_read(regmap, ISL12022_REG_SR, &val);
+               if (ret)
+                       return ret;
+
+               user = 0;
+               if (val & ISL12022_SR_LBAT85)
+                       user |= RTC_VL_BACKUP_LOW;
+
+               if (val & ISL12022_SR_LBAT75)
+                       user |= RTC_VL_BACKUP_EMPTY;
+
+               return put_user(user, (u32 __user *)arg);
+
+       default:
+               return -ENOIOCTLCMD;
+       }
+}
+
 static const struct rtc_class_ops isl12022_rtc_ops = {
+       .ioctl          = isl12022_rtc_ioctl,
        .read_time      = isl12022_rtc_read_time,
        .set_time       = isl12022_rtc_set_time,
 };