Skip to content

Commit eccebd8

Browse files
Villemoesalexandrebelloni
authored andcommitted
rtc: isl12022: implement RTC_VL_READ ioctl
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>
1 parent 2caeb56 commit eccebd8

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

drivers/rtc/rtc-isl12022.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,34 @@ static int isl12022_rtc_set_time(struct device *dev, struct rtc_time *tm)
204204
return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf));
205205
}
206206

207+
static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
208+
{
209+
struct regmap *regmap = dev_get_drvdata(dev);
210+
u32 user, val;
211+
int ret;
212+
213+
switch (cmd) {
214+
case RTC_VL_READ:
215+
ret = regmap_read(regmap, ISL12022_REG_SR, &val);
216+
if (ret)
217+
return ret;
218+
219+
user = 0;
220+
if (val & ISL12022_SR_LBAT85)
221+
user |= RTC_VL_BACKUP_LOW;
222+
223+
if (val & ISL12022_SR_LBAT75)
224+
user |= RTC_VL_BACKUP_EMPTY;
225+
226+
return put_user(user, (u32 __user *)arg);
227+
228+
default:
229+
return -ENOIOCTLCMD;
230+
}
231+
}
232+
207233
static const struct rtc_class_ops isl12022_rtc_ops = {
234+
.ioctl = isl12022_rtc_ioctl,
208235
.read_time = isl12022_rtc_read_time,
209236
.set_time = isl12022_rtc_set_time,
210237
};

0 commit comments

Comments
 (0)