]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rtc: ds1307: Fix alarm programming for mcp794xx
authorTero Kristo <t-kristo@ti.com>
Fri, 23 Oct 2015 06:29:57 +0000 (09:29 +0300)
committerLuis Henriques <luis.henriques@canonical.com>
Sun, 13 Dec 2015 17:49:45 +0000 (17:49 +0000)
commit 62c8c20af92ea312ecb22cec4e83082e5843076b upstream.

mcp794xx alarm registers must be written in BCD format. However, the
alarm programming logic neglected this by adding one to the value
after bin2bcd conversion has been already done, writing bad values
to month register in case the alarm being set is in October. In this
case, the alarm month value becomes 0x0a instead of the expected 0x10.

Fix by moving the +1 addition within the bin2bcd call also.

Fixes: 1d1945d261a2 ("drivers/rtc/rtc-ds1307.c: add alarm support for mcp7941x chips")
Signed-off-by: Tero Kristo <t-kristo@ti.com>
Acked-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
drivers/rtc/rtc-ds1307.c

index f03d5ba96db1fe3f5e063e15957056604896570b..f182dae3a4b751633c0ae3c838cadd2d9d964630 100644 (file)
@@ -727,9 +727,9 @@ static int mcp7941x_set_alarm(struct device *dev, struct rtc_wkalrm *t)
        regs[3] = bin2bcd(t->time.tm_sec);
        regs[4] = bin2bcd(t->time.tm_min);
        regs[5] = bin2bcd(t->time.tm_hour);
-       regs[6] = bin2bcd(t->time.tm_wday) + 1;
+       regs[6] = bin2bcd(t->time.tm_wday + 1);
        regs[7] = bin2bcd(t->time.tm_mday);
-       regs[8] = bin2bcd(t->time.tm_mon) + 1;
+       regs[8] = bin2bcd(t->time.tm_mon + 1);
 
        /* Clear the alarm 0 interrupt flag. */
        regs[6] &= ~MCP7941X_BIT_ALMX_IF;