rtc: pcf8563: handle consequeces of lacking second alarm reg
authorJan Kardell <jan.kardell@telliq.com>
Wed, 10 Dec 2014 23:53:40 +0000 (15:53 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 11 Dec 2014 01:41:15 +0000 (17:41 -0800)
To guarantee that a set alarm occurs in the future, the set alarm time
is rounded up to the nearest minute.  Also we cannot handle UIE as it
requires second precision.

Signed-off-by: Jan Kardell <jan.kardell@telliq.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Vincent Donnefort <vdonnefort@gmail.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/rtc-pcf8563.c

index 78f76d99bd355ef55e2771f47bcdd6db2b85fb31..ce6a11bc0fd79e9bbe99c49caee6eefebdb6df02 100644 (file)
@@ -361,6 +361,14 @@ static int pcf8563_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm)
        struct i2c_client *client = to_i2c_client(dev);
        unsigned char buf[4];
        int err;
+       unsigned long alarm_time;
+
+       /* The alarm has no seconds, round up to nearest minute */
+       if (tm->time.tm_sec) {
+               rtc_tm_to_time(&tm->time, &alarm_time);
+               alarm_time += 60-tm->time.tm_sec;
+               rtc_time_to_tm(alarm_time, &tm->time);
+       }
 
        dev_dbg(dev, "%s, min=%d hour=%d wday=%d mday=%d "
                "enabled=%d pending=%d\n", __func__,
@@ -435,6 +443,9 @@ static int pcf8563_probe(struct i2c_client *client,
 
        }
 
+       /* the pcf8563 alarm only supports a minute accuracy */
+       pcf8563->rtc->uie_unsupported = 1;
+
        return 0;
 }