aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-pcf8563.c
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2019-12-14 23:02:50 +0100
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-12-18 10:37:30 +0100
commit935272aade5ac17f6e6139968799421233c92c33 (patch)
tree200a2ccc9ebfc88e98dfa5c4f01b04db3e755dad /drivers/rtc/rtc-pcf8563.c
parent75d26f5c2388f0fbedceeec98a3dc95cb26ec1c8 (diff)
downloadlinux-935272aade5ac17f6e6139968799421233c92c33.tar.gz
rtc: pcf8563: stop caching voltage_low
voltage_low is only updated when reading the time, this means that using RTC_VL_READ will miss the VL flag if the time has not been read before using the ioctl. Always read the status from the hardware. Link: https://lore.kernel.org/r/20191214220259.621996-9-alexandre.belloni@bootlin.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/rtc-pcf8563.c')
-rw-r--r--drivers/rtc/rtc-pcf8563.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 026192fc0c2aa..7fc43950cf6c9 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -76,7 +76,6 @@ struct pcf8563 {
* 1970...2069.
*/
int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
- int voltage_low; /* incicates if a low_voltage was detected */
struct i2c_client *client;
#ifdef CONFIG_COMMON_CLK
@@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
return err;
if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
- pcf8563->voltage_low = 1;
dev_err(&client->dev,
"low voltage detected, date/time is not reliable.\n");
return -EINVAL;
@@ -278,15 +276,19 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
{
- struct pcf8563 *pcf8563 = i2c_get_clientdata(to_i2c_client(dev));
+ struct i2c_client *client = to_i2c_client(dev);
+ int vl, ret;
switch (cmd) {
case RTC_VL_READ:
- if (pcf8563->voltage_low)
- dev_info(dev, "low voltage detected, date/time is not reliable.\n");
- if (copy_to_user((void __user *)arg, &pcf8563->voltage_low,
- sizeof(int)))
+ ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC);
+ if (ret < 0)
+ return ret;
+
+ vl = ret & PCF8563_SC_LV ? 1 : 0;
+
+ if (copy_to_user((void __user *)arg, &vl, sizeof(int)))
return -EFAULT;
return 0;
default: