From bd13786e7e7b635cea7454c125113b5aa6617564 Mon Sep 17 00:00:00 2001 From: Giampiero Baggiani Date: Tue, 26 Mar 2024 17:58:59 +0100 Subject: [PATCH] rtc: pcf2127: added battery_low sysfs file --- drivers/rtc/rtc-pcf2127.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c index 9c04c4e1a49c37..4f127b82f34049 100644 --- a/drivers/rtc/rtc-pcf2127.c +++ b/drivers/rtc/rtc-pcf2127.c @@ -900,10 +900,25 @@ static ssize_t timestamp3_show(struct device *dev, return timestamp_show(dev, attr, buf, 3); }; +static ssize_t battery_low_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); + unsigned int ctrl3; + int ret; + + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL3, &ctrl3); + if (ret) + return ret; + + return sprintf(buf, "%d\n", (ctrl3 & PCF2127_BIT_CTRL3_BLF) ? 1 : 0); +}; + static DEVICE_ATTR_RW(timestamp0); static DEVICE_ATTR_RW(timestamp1); static DEVICE_ATTR_RW(timestamp2); static DEVICE_ATTR_RW(timestamp3); +static DEVICE_ATTR_RO(battery_low); static struct attribute *pcf2127_attrs[] = { &dev_attr_timestamp0.attr, @@ -915,6 +930,7 @@ static struct attribute *pcf2131_attrs[] = { &dev_attr_timestamp1.attr, &dev_attr_timestamp2.attr, &dev_attr_timestamp3.attr, + &dev_attr_battery_low.attr, NULL };