Skip to content

Commit 7f43020

Browse files
baxenoalexandrebelloni
authored andcommitted
rtc: pcf2127: bugfix: read rtc disables watchdog
The previous fix listed bulk read of registers as root cause of accendential disabling of watchdog, since the watchdog counter register (WD_VAL) was zeroed. Fixes: 3769a37 rtc: pcf2127: bulk read only date and time registers. Tested with the same PCF2127 chip as Sean reveled root cause of WD_VAL register value zeroing was caused by reading CTRL2 register which is one of the watchdog feature control registers. So the solution is to not read the first two control registers (CTRL1 and CTRL2) in pcf2127_rtc_read_time as they are not needed anyway. Size of local buf variable is kept to allow easy usage of register defines to improve readability of code. Debug trace line was updated after CTRL1 and CTRL2 are no longer read from the chip. Also replaced magic numbers in buf access with register defines. Signed-off-by: Bruno Thomsen <bruno.thomsen@gmail.com> Link: https://lore.kernel.org/r/20190822131936.18772-3-bruno.thomsen@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent bbfe3a7 commit 7f43020

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

drivers/rtc/rtc-pcf2127.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,14 @@ static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
6060
struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
6161
unsigned char buf[10];
6262
int ret;
63-
int i;
6463

65-
for (i = 0; i <= PCF2127_REG_CTRL3; i++) {
66-
ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1 + i,
67-
(unsigned int *)(buf + i));
68-
if (ret) {
69-
dev_err(dev, "%s: read error\n", __func__);
70-
return ret;
71-
}
72-
}
73-
74-
ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_SC,
75-
(buf + PCF2127_REG_SC),
76-
ARRAY_SIZE(buf) - PCF2127_REG_SC);
64+
/*
65+
* Avoid reading CTRL2 register as it causes WD_VAL register
66+
* value to reset to 0 which means watchdog is stopped.
67+
*/
68+
ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL3,
69+
(buf + PCF2127_REG_CTRL3),
70+
ARRAY_SIZE(buf) - PCF2127_REG_CTRL3);
7771
if (ret) {
7872
dev_err(dev, "%s: read error\n", __func__);
7973
return ret;
@@ -95,14 +89,12 @@ static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
9589
}
9690

9791
dev_dbg(dev,
98-
"%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, "
99-
"sec=%02x, min=%02x, hr=%02x, "
92+
"%s: raw data is cr3=%02x, sec=%02x, min=%02x, hr=%02x, "
10093
"mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
101-
__func__,
102-
buf[0], buf[1], buf[2],
103-
buf[3], buf[4], buf[5],
104-
buf[6], buf[7], buf[8], buf[9]);
105-
94+
__func__, buf[PCF2127_REG_CTRL3], buf[PCF2127_REG_SC],
95+
buf[PCF2127_REG_MN], buf[PCF2127_REG_HR],
96+
buf[PCF2127_REG_DM], buf[PCF2127_REG_DW],
97+
buf[PCF2127_REG_MO], buf[PCF2127_REG_YR]);
10698

10799
tm->tm_sec = bcd2bin(buf[PCF2127_REG_SC] & 0x7F);
108100
tm->tm_min = bcd2bin(buf[PCF2127_REG_MN] & 0x7F);

0 commit comments

Comments
 (0)