diff options
author | Ken Chang <kenc@nvidia.com> | 2011-05-27 17:13:23 +0800 |
---|---|---|
committer | Niket Sirsi <nsirsi@nvidia.com> | 2011-05-31 18:12:42 -0700 |
commit | 707a0f7d235427085f8e18d5573e26afee764ede (patch) | |
tree | e57e610254301c7128356655dcc0466dd3ac0bcf /drivers/rtc | |
parent | 1e1967f838f1c9fb56d08a1567ce4f22b7fb58e7 (diff) |
rtc: tps6586x: fix error in setting alarm1
Alarm1 expiration time is set based on rtc value. Should not compare the
absolute rtc value with the valid range of alarm1 directly, expiration
time from now is used instead.
Bug 832563
Change-Id: I338e7ee684b5cad6b2fba99b5ac4ec6cff9b75cd
Reviewed-on: http://git-master/r/34295
Tested-by: Ken Chang <kenc@nvidia.com>
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Bharat Nihalani <bnihalani@nvidia.com>
Reviewed-by: Varun Wadekar <vwadekar@nvidia.com>
Reviewed-by: Yu-Fong (Foster) Cho <ycho@nvidia.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-tps6586x.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c index 5a64b478651a..546b7bfea5ec 100644 --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c @@ -134,6 +134,7 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) struct device *tps_dev = to_tps6586x_dev(dev); unsigned long seconds; unsigned long ticks; + unsigned long rtc_current_time; unsigned long long rticks = 0; u8 buff[3]; u8 rbuff[6]; @@ -160,21 +161,21 @@ static int tps6586x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) seconds -= rtc->epoch_start; - if (seconds > ALM1_VALID_RANGE_IN_SEC) { - err = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(rbuff), rbuff); - if (err < 0) { - dev_err(dev, "failed to read counter\n"); - return err; - } - - for (i = 1; i < sizeof(rbuff); i++) { - rticks <<= 8; - rticks |= rbuff[i]; - } + err = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(rbuff), rbuff); + if (err < 0) { + dev_err(dev, "failed to read counter\n"); + return err; + } - seconds = (rticks >> 10) - 1; + for (i = 1; i < sizeof(rbuff); i++) { + rticks <<= 8; + rticks |= rbuff[i]; } + rtc_current_time = rticks >> 10; + if ((seconds - rtc_current_time) > ALM1_VALID_RANGE_IN_SEC) + seconds = rtc_current_time - 1; + ticks = (unsigned long long)seconds << 10; buff[0] = (ticks >> 16) & 0xff; |