0357-rtc-ds1307-ensure-that-any-pending-alarm-is-cleared-.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 0d311e4c6e701192c62668665ae1ba25d2219f28 Mon Sep 17 00:00:00 2001
  2. From: Nicolas Boullis <nboullis@debian.org>
  3. Date: Sun, 10 Apr 2016 13:23:05 +0200
  4. Subject: [PATCH 357/381] rtc: ds1307: ensure that any pending alarm is cleared
  5. before a new alarm is enabled
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. If a previously-set alarm was disabled and then triggered, it may still
  10. be pending when a new alarm is configured.
  11. Then, if the alarm is enabled before the pending alarm is cleared, then
  12. an interrupt is immediately raised.
  13. Unfortunately, when the alarm is cleared and enabled during the same I²C
  14. block write, the chip (at least the DS1339 I have) considers that the
  15. alarm is enabled before it is cleared, and raises an interrupt.
  16. This patch ensures that the pending alarm is cleared before the alarm is
  17. enabled.
  18. Signed-off-by: Nicolas Boullis <nboullis@debian.org>
  19. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
  20. ---
  21. drivers/rtc/rtc-ds1307.c | 13 ++++++++-----
  22. 1 file changed, 8 insertions(+), 5 deletions(-)
  23. --- a/drivers/rtc/rtc-ds1307.c
  24. +++ b/drivers/rtc/rtc-ds1307.c
  25. @@ -540,12 +540,8 @@ static int ds1337_set_alarm(struct devic
  26. buf[5] = 0;
  27. buf[6] = 0;
  28. - /* optionally enable ALARM1 */
  29. + /* disable alarms */
  30. buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE);
  31. - if (t->enabled) {
  32. - dev_dbg(dev, "alarm IRQ armed\n");
  33. - buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
  34. - }
  35. buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I);
  36. ret = ds1307->write_block_data(client,
  37. @@ -555,6 +551,13 @@ static int ds1337_set_alarm(struct devic
  38. return ret;
  39. }
  40. + /* optionally enable ALARM1 */
  41. + if (t->enabled) {
  42. + dev_dbg(dev, "alarm IRQ armed\n");
  43. + buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
  44. + i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, buf[7]);
  45. + }
  46. +
  47. return 0;
  48. }