diff options
author | Mylène Josserand <mylene.josserand@free-electrons.com> | 2016-05-03 05:54:36 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2016-05-21 11:06:56 -0400 |
commit | dc492e866a997b3df2a551fa772d6887a19e53b8 (patch) | |
tree | 3a91ab494b4129aa92ea1ad5460f47dfe0cd2d6e /drivers/rtc | |
parent | abe2f551efc65760d61668ad6fb511bf834082dc (diff) |
rtc: rv3029: fix alarm support
The RTC RV3029 handles different types of alarms : seconds, minutes, ...
These alarms can be enabled or disabled individually using an AE_x bit
which is the last bit (BIT(7)) on each alarm registers.
To prepare the alarm IRQ support, the current code enables all the alarm
types by setting each AE_x to 1.
It also fixes others alarms issues :
- month and weekday errors : it was performing -1 instead of +1.
- wrong use of bit mask with bin2bcd
Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/rtc-rv3029c2.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c index cf8d4650e15e..88a0c188a6f2 100644 --- a/drivers/rtc/rtc-rv3029c2.c +++ b/drivers/rtc/rtc-rv3029c2.c | |||
@@ -76,6 +76,7 @@ | |||
76 | #define RV3029_A_DW 0x14 | 76 | #define RV3029_A_DW 0x14 |
77 | #define RV3029_A_MO 0x15 | 77 | #define RV3029_A_MO 0x15 |
78 | #define RV3029_A_YR 0x16 | 78 | #define RV3029_A_YR 0x16 |
79 | #define RV3029_A_AE_X BIT(7) | ||
79 | #define RV3029_ALARM_SECTION_LEN 0x07 | 80 | #define RV3029_ALARM_SECTION_LEN 0x07 |
80 | 81 | ||
81 | /* timer section */ | 82 | /* timer section */ |
@@ -436,14 +437,22 @@ static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) | |||
436 | dev_err(dev, "%s: reading SR failed\n", __func__); | 437 | dev_err(dev, "%s: reading SR failed\n", __func__); |
437 | return -EIO; | 438 | return -EIO; |
438 | } | 439 | } |
439 | regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec & 0x7f); | ||
440 | regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min & 0x7f); | ||
441 | regs[RV3029_A_HR - RV3029_A_SC] = bin2bcd(tm->tm_hour & 0x3f); | ||
442 | regs[RV3029_A_DT - RV3029_A_SC] = bin2bcd(tm->tm_mday & 0x3f); | ||
443 | regs[RV3029_A_MO - RV3029_A_SC] = bin2bcd((tm->tm_mon & 0x1f) - 1); | ||
444 | regs[RV3029_A_DW - RV3029_A_SC] = bin2bcd((tm->tm_wday & 7) - 1); | ||
445 | regs[RV3029_A_YR - RV3029_A_SC] = bin2bcd((tm->tm_year & 0x7f) - 100); | ||
446 | 440 | ||
441 | /* Activate all the alarms with AE_x bit */ | ||
442 | regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X; | ||
443 | regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min) | RV3029_A_AE_X; | ||
444 | regs[RV3029_A_HR - RV3029_A_SC] = (bin2bcd(tm->tm_hour) & 0x3f) | ||
445 | | RV3029_A_AE_X; | ||
446 | regs[RV3029_A_DT - RV3029_A_SC] = (bin2bcd(tm->tm_mday) & 0x3f) | ||
447 | | RV3029_A_AE_X; | ||
448 | regs[RV3029_A_MO - RV3029_A_SC] = (bin2bcd(tm->tm_mon + 1) & 0x1f) | ||
449 | | RV3029_A_AE_X; | ||
450 | regs[RV3029_A_DW - RV3029_A_SC] = (bin2bcd(tm->tm_wday + 1) & 0x7) | ||
451 | | RV3029_A_AE_X; | ||
452 | regs[RV3029_A_YR - RV3029_A_SC] = (bin2bcd(tm->tm_year - 100)) | ||
453 | | RV3029_A_AE_X; | ||
454 | |||
455 | /* Write the alarm */ | ||
447 | ret = rv3029_write_regs(dev, RV3029_A_SC, regs, | 456 | ret = rv3029_write_regs(dev, RV3029_A_SC, regs, |
448 | RV3029_ALARM_SECTION_LEN); | 457 | RV3029_ALARM_SECTION_LEN); |
449 | if (ret < 0) | 458 | if (ret < 0) |