Skip to content

Commit 204756f

Browse files
iwamatsu-talexandrebelloni
authored andcommitted
rtc: ds1307: Fix wday settings for rx8130
rx8130 wday specifies the bit position, not BCD. Fixes: ee0981b ("rtc: ds1307: Add support for Epson RX8130CE") Signed-off-by: Nobuhiro Iwamatsu <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a1cfe7c commit 204756f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/rtc/rtc-ds1307.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
293293
t->tm_min = bcd2bin(regs[DS1307_REG_MIN] & 0x7f);
294294
tmp = regs[DS1307_REG_HOUR] & 0x3f;
295295
t->tm_hour = bcd2bin(tmp);
296-
t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
296+
/* rx8130 is bit position, not BCD */
297+
if (ds1307->type == rx_8130)
298+
t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
299+
else
300+
t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
297301
t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
298302
tmp = regs[DS1307_REG_MONTH] & 0x1f;
299303
t->tm_mon = bcd2bin(tmp) - 1;
@@ -340,7 +344,11 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
340344
regs[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
341345
regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
342346
regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
343-
regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
347+
/* rx8130 is bit position, not BCD */
348+
if (ds1307->type == rx_8130)
349+
regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
350+
else
351+
regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
344352
regs[DS1307_REG_MDAY] = bin2bcd(t->tm_mday);
345353
regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);
346354

0 commit comments

Comments
 (0)