0137-rtc-ds1307-add-support-for-the-DT-property-wakeup-so.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From cc252ee4f3948d12a878c93cbdb0505a9ee7bc03 Mon Sep 17 00:00:00 2001
  2. From: Michael Lange <linuxstuff@milaw.biz>
  3. Date: Thu, 21 Jan 2016 18:10:16 +0100
  4. Subject: [PATCH] rtc: ds1307: add support for the DT property 'wakeup-source'
  5. For RTC chips with no IRQ directly connected to the SoC, the RTC chip
  6. can be forced as a wakeup source by stating that explicitly in
  7. the device's .dts file using the "wakeup-source" boolean property.
  8. This will guarantee the 'wakealarm' sysfs entry is available on the
  9. device, if supported by the RTC.
  10. With these changes to the driver rtc-ds1307 and the necessary entries
  11. in the .dts file, I get an working ds1337 RTC on the Witty Pi extension
  12. board by UUGear for the Raspberry Pi.
  13. An example for the entry in the .dts file:
  14. rtc: ds1337@68 {
  15. compatible = "dallas,ds1337";
  16. reg = <0x68>;
  17. wakeup-source;
  18. If the "wakeup-source" property is set, do not request an IRQ.
  19. Set also UIE mode to unsupported, to get a working 'hwclock' binary.
  20. Signed-off-by: Michael Lange <linuxstuff@milaw.biz>
  21. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
  22. ---
  23. drivers/rtc/rtc-ds1307.c | 29 +++++++++++++++++++++++++++--
  24. 1 file changed, 27 insertions(+), 2 deletions(-)
  25. --- a/drivers/rtc/rtc-ds1307.c
  26. +++ b/drivers/rtc/rtc-ds1307.c
  27. @@ -860,6 +860,7 @@ static int ds1307_probe(struct i2c_clien
  28. struct chip_desc *chip = &chips[id->driver_data];
  29. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  30. bool want_irq = false;
  31. + bool ds1307_can_wakeup_device = false;
  32. unsigned char *buf;
  33. struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
  34. irq_handler_t irq_handler = ds1307_irq;
  35. @@ -907,6 +908,20 @@ static int ds1307_probe(struct i2c_clien
  36. ds1307->write_block_data = ds1307_write_block_data;
  37. }
  38. +#ifdef CONFIG_OF
  39. +/*
  40. + * For devices with no IRQ directly connected to the SoC, the RTC chip
  41. + * can be forced as a wakeup source by stating that explicitly in
  42. + * the device's .dts file using the "wakeup-source" boolean property.
  43. + * If the "wakeup-source" property is set, don't request an IRQ.
  44. + * This will guarantee the 'wakealarm' sysfs entry is available on the device,
  45. + * if supported by the RTC.
  46. + */
  47. + if (of_property_read_bool(client->dev.of_node, "wakeup-source")) {
  48. + ds1307_can_wakeup_device = true;
  49. + }
  50. +#endif
  51. +
  52. switch (ds1307->type) {
  53. case ds_1337:
  54. case ds_1339:
  55. @@ -925,11 +940,13 @@ static int ds1307_probe(struct i2c_clien
  56. ds1307->regs[0] &= ~DS1337_BIT_nEOSC;
  57. /*
  58. - * Using IRQ? Disable the square wave and both alarms.
  59. + * Using IRQ or defined as wakeup-source?
  60. + * Disable the square wave and both alarms.
  61. * For some variants, be sure alarms can trigger when we're
  62. * running on Vbackup (BBSQI/BBSQW)
  63. */
  64. - if (ds1307->client->irq > 0 && chip->alarm) {
  65. + if (chip->alarm && (ds1307->client->irq > 0 ||
  66. + ds1307_can_wakeup_device)) {
  67. ds1307->regs[0] |= DS1337_BIT_INTCN
  68. | bbsqi_bitpos[ds1307->type];
  69. ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
  70. @@ -1144,6 +1161,14 @@ read_rtc:
  71. return PTR_ERR(ds1307->rtc);
  72. }
  73. + if (ds1307_can_wakeup_device) {
  74. + /* Disable request for an IRQ */
  75. + want_irq = false;
  76. + dev_info(&client->dev, "'wakeup-source' is set, request for an IRQ is disabled!\n");
  77. + /* We cannot support UIE mode if we do not have an IRQ line */
  78. + ds1307->rtc->uie_unsupported = 1;
  79. + }
  80. +
  81. if (want_irq) {
  82. err = devm_request_threaded_irq(&client->dev,
  83. client->irq, NULL, irq_handler,