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