rtc: ds1307: Fix wday settings for rx8130
[sfrench/cifs-2.6.git] / drivers / rtc / rtc-ds1307.c
index 089509d0a3a0e61c926c28a30c7b826cd4244635..336cb9aa5e336d74889343a7e53bcbeb269683fb 100644 (file)
@@ -293,7 +293,11 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
        t->tm_min = bcd2bin(regs[DS1307_REG_MIN] & 0x7f);
        tmp = regs[DS1307_REG_HOUR] & 0x3f;
        t->tm_hour = bcd2bin(tmp);
-       t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
+       /* rx8130 is bit position, not BCD */
+       if (ds1307->type == rx_8130)
+               t->tm_wday = fls(regs[DS1307_REG_WDAY] & 0x7f);
+       else
+               t->tm_wday = bcd2bin(regs[DS1307_REG_WDAY] & 0x07) - 1;
        t->tm_mday = bcd2bin(regs[DS1307_REG_MDAY] & 0x3f);
        tmp = regs[DS1307_REG_MONTH] & 0x1f;
        t->tm_mon = bcd2bin(tmp) - 1;
@@ -340,7 +344,11 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
        regs[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
        regs[DS1307_REG_MIN] = bin2bcd(t->tm_min);
        regs[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
-       regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
+       /* rx8130 is bit position, not BCD */
+       if (ds1307->type == rx_8130)
+               regs[DS1307_REG_WDAY] = 1 << t->tm_wday;
+       else
+               regs[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
        regs[DS1307_REG_MDAY] = bin2bcd(t->tm_mday);
        regs[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);