7e9d0e66c051e08d80273ebf1a1ef8dc37e9c6ec
[openwrt/staging/ldir.git] / target / linux / generic / pending-5.10 / 191-rtc-rs5c372-let_the_alarm_to_be_used_as_wakeup_source.patch
1 From: Daniel González Cabanelas <dgcbueu@gmail.com>
2 Subject: [PATCH 2/2] rtc: rs5c372: let the alarm to be used as wakeup source
3
4 Currently there is no use for the interrupts on the rs5c372 RTC and the
5 wakealarm isn't enabled. There are some devices like NASes which use this
6 RTC to wake up from the power off state when the INTR pin is activated by
7 the alarm clock.
8
9 Enable the alarm and let to be used as a wakeup source.
10
11 Tested on a Buffalo LS421DE NAS.
12
13 Signed-off-by: Daniel González Cabanelas <dgcbueu@gmail.com>
14 ---
15 drivers/rtc/rtc-rs5c372.c | 16 ++++++++++++++++
16 1 file changed, 16 insertions(+)
17
18 --- a/drivers/rtc/rtc-rs5c372.c
19 +++ b/drivers/rtc/rtc-rs5c372.c
20 @@ -654,6 +654,7 @@ static int rs5c372_probe(struct i2c_clie
21 int err = 0;
22 int smbus_mode = 0;
23 struct rs5c372 *rs5c372;
24 + bool rs5c372_can_wakeup_device = false;
25
26 dev_dbg(&client->dev, "%s\n", __func__);
27
28 @@ -689,6 +690,12 @@ static int rs5c372_probe(struct i2c_clie
29 else
30 rs5c372->type = id->driver_data;
31
32 +#ifdef CONFIG_OF
33 + if(of_property_read_bool(client->dev.of_node,
34 + "wakeup-source"))
35 + rs5c372_can_wakeup_device = true;
36 +#endif
37 +
38 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
39 rs5c372->regs = &rs5c372->buf[1];
40 rs5c372->smbus = smbus_mode;
41 @@ -722,6 +729,8 @@ static int rs5c372_probe(struct i2c_clie
42 goto exit;
43 }
44
45 + rs5c372->has_irq = 1;
46 +
47 /* if the oscillator lost power and no other software (like
48 * the bootloader) set it up, do it here.
49 *
50 @@ -748,6 +757,10 @@ static int rs5c372_probe(struct i2c_clie
51 );
52
53 /* REVISIT use client->irq to register alarm irq ... */
54 + if (rs5c372_can_wakeup_device) {
55 + device_init_wakeup(&client->dev, true);
56 + }
57 +
58 rs5c372->rtc = devm_rtc_device_register(&client->dev,
59 rs5c372_driver.driver.name,
60 &rs5c372_rtc_ops, THIS_MODULE);
61 @@ -761,6 +774,9 @@ static int rs5c372_probe(struct i2c_clie
62 if (err)
63 goto exit;
64
65 + /* the rs5c372 alarm only supports a minute accuracy */
66 + rs5c372->rtc->uie_unsupported = 1;
67 +
68 return 0;
69
70 exit: