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