This change exposes the needed interfaces to configure wake alarms to
userspace, but it doesn't let a SoC resume from a wakealarm by itself
(that depends on how interrupts are handled). However, it is still
useful for generating interrupts, it allows users to test the wakealarm
setting codepath of the sun6i RTC driver, and it will allow developers
to test wakeup from suspend more easily.

I've tested this on a Pine H64 model B, which contains an Allwinner H6
SoC, with the help of the test_suspend kernel parameter. I got these
results:

[    1.092823] PM: test RTC wakeup from 'freeze' suspend
[    1.098391] PM: suspend entry (s2idle)
[    1.102543] Filesystems sync: 0.000 seconds
[    1.107333] Freezing user space processes ... (elapsed 0.000 seconds) 
done.
[    1.115061] OOM killer disabled.
[    1.118621] Freezing remaining freezable tasks ... (elapsed 0.002 
seconds) done.
[    1.204986] PM: suspend devices took 0.076 seconds
** The kernel doesn't resume from freeze until reset. **

[    1.092812] PM: test RTC wakeup from 'mem' suspend
[    1.098089] PM: suspend entry (deep)
[    1.102033] PM: suspend exit
[    1.105205] PM: suspend test failed, error -22

$ echo +5 > /sys/class/rtc/rtc0/wakealarm && sleep 5 && grep rtc 
/proc/interrupts
 29:          1          0          0          0     GICv2 133 Level     
7000000.rtc

Signed-off-by: Alejandro González <[email protected]>
---
 drivers/rtc/rtc-sun6i.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index c0e75c373605..1ecca0ae3f68 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -650,6 +650,12 @@ static int sun6i_rtc_probe(struct platform_device 
*pdev)
 
     clk_prepare_enable(chip->losc);
 
+    /*
+     * Init as wakeup source. This alone won't let resume
+     * from suspend work, but still generates an interrupt.
+     */
+    device_init_wakeup(&pdev->dev, 1);
+
     chip->rtc = devm_rtc_device_register(&pdev->dev, "rtc-sun6i",
                          &sun6i_rtc_ops, THIS_MODULE);
     if (IS_ERR(chip->rtc)) {
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/linux-sunxi/b5086f94-2e73-483a-ba03-bd81f7cd175f%40googlegroups.com.

Reply via email to