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

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