Hi Detlev,
thanks for the reply. I got an e-mail notification for your post yesterday, but it didn't show up for some reason.
Your proposal sounds reasonable and it might be enough for some applications. Still it would be nice to be able to detect the "real" wakeup cause.
I had a closer look at the kernel docs and code and I think I actually found two other possible solutions. I haven't tested them closely so far, but it looks promising.
1. Enable CONFIG_PM_DEBUG
This will add an additional property under /sys/power/pm_wakeup_irq. After a suspend/resume cycle I can read the index of the IRQ that triggered the wakeup. In my case I tested resume from the SNVS RTC alarm (IRQ 21) and from GPIO01_IO6 (IRQ51). I don't really know why I get a GPT interrupt for the GPIO. To match the IRQ indices with the device, I use the information from /proc/interrupts.
2. Use the wakeup_count of the wakeup source
The reason why wakeup_count isn't updated seems to be that it needs to be enabled first. The explanation in https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-power is not really self-explanatory but the commands below seem to work for me and I get an updated value for the wakeup_count of the correct source.
I think with one of the three options in total we can achieve what we want and I will propose this to our customer.
Thanks a lot for your help!
Best regards
Frieder
~# cat /sys/kernel/debug/wakeup_sources
name active_count event_count wakeup_count expire_count active_since total_time max_time last_change prevent_suspend_time
3-0028 0 0 0 0 0 0 0 0 0
gpio-keys 0 0 0 0 0 0 0 0 0
30370000.snvs:snvs-rtc-lp 0 0 0 0 0 0 0 0 0
alarmtimer 0 0 0 0 0 0 0 0 0
3-0032 2 2 2 0 0 14 7 6451 0
deleted 0 0 0 0 0 0 0 0 0
~# cat /sys/power/wakeup_count
2
~# echo 2 > /sys/power/wakeup_count
~# echo mem > /sys/power/state
[ 62.279247] PM: suspend entry (deep)
[ 62.282920] Filesystems sync: 0.000 seconds
[ 62.290218] Freezing user space processes ... (elapsed 0.001 seconds) done.
[ 62.298606] OOM killer disabled.
[ 62.301844] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[ 62.311109] mwifiex_sdio mmc2:0001:1: None of the WOWLAN triggers enabled
[ 62.447461] Disabling non-boot CPUs ...
[ 62.451798] CPU1: shutdown
[ 62.454531] psci: CPU1 killed (polled 0 ms)
[ 62.459785] CPU2: shutdown
[ 62.462520] psci: CPU2 killed (polled 0 ms)
[ 62.467624] CPU3: shutdown
[ 62.470352] psci: CPU3 killed (polled 0 ms)
[ 62.475192] Enabling non-boot CPUs ...
[ 62.479233] Detected VIPT I-cache on CPU1
[ 62.479255] GICv3: CPU1: found redistributor 1 region 0:0x00000000388a0000
[ 62.479295] CPU1: Booted secondary processor 0x0000000001 [0x410fd034]
[ 62.479775] CPU1 is up
[ 62.499728] Detected VIPT I-cache on CPU2
[ 62.499739] GICv3: CPU2: found redistributor 2 region 0:0x00000000388c0000
[ 62.499760] CPU2: Booted secondary processor 0x0000000002 [0x410fd034]
[ 62.500063] CPU2 is up
[ 62.519995] Detected VIPT I-cache on CPU3
[ 62.520008] GICv3: CPU3: found redistributor 3 region 0:0x00000000388e0000
[ 62.520028] CPU3: Booted secondary processor 0x0000000003 [0x410fd034]
[ 62.520377] CPU3 is up
[ 62.606753] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[ 62.613419] [drm] No driver support for vblank timestamp query.
[ 62.619355] OOM killer enabled.
[ 62.622508] Restarting tasks ... done.
[ 62.661659] PM: suspend exit
~# cat /sys/power/wakeup_count
4
~# cat /sys/kernel/debug/wakeup_sources
name active_count event_count wakeup_count expire_count active_since total_time max_time last_change prevent_suspend_time
3-0028 0 0 0 0 0 0 0 0 0
gpio-keys 2 8 8 0 0 21 11 62696 0
30370000.snvs:snvs-rtc-lp 0 0 0 0 0 0 0 0 0
alarmtimer 0 0 0 0 0 0 0 0 0
3-0032 2 2 2 0 0 14 7 6451 0
deleted 0 0 0 0 0 0 0 0 0