This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/BEAGLEBK: Wakeup on GPIO event

Part Number: BEAGLEBK

Tool/software: Linux

Hello,

I am using a Beaglebone Black running the latest Debian Stretch on it.

debian@beaglebone:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

debian@beaglebone:~$ uname -a
Linux beaglebone 4.4.91-ti-r133 #1 SMP Tue Oct 10 05:18:08 UTC 2017 armv7l GNU/Linux

I have downloaded the Linux kernel source from below to compile and use custom device trees.
https://github.com/beagleboard/linux.git

diff --git a/arch/arm/boot/dts/am335x-boneblack-custom.dts b/arch/arm/boot/dts/am335x-boneblack-custom.dts
index 0c68a88..a85990d 100644
--- a/arch/arm/boot/dts/am335x-boneblack-custom.dts
+++ b/arch/arm/boot/dts/am335x-boneblack-custom.dts
@@ -10,10 +10,49 @@
 #include "am33xx.dtsi"
 #include "am335x-bone-common-no-capemgr.dtsi"
 #include <dt-bindings/board/am335x-bbw-bbb-base.h>
+#include <dt-bindings/input/input.h>
 
 / {
        model = "TI AM335x BeagleBone Black";
        compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
+
+    gpio-keys {
+        compatible = "gpio-keys";
+        pinctrl-names = "default";
+        pinctrl-0 =  <&wakeup_gpio_pins>;
+
+        power1 {
+            label = "CAN1_WakeB";
+            gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>;
+            linux,code = <KEY_WAKEUP>;
+            debounce-interval = <10>;
+            wakeup-source;
+        };
+
+        power2 {
+            label = "CAN1_WakeA";
+            gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>;
+            linux,code = <KEY_WAKEUP>;
+            debounce-interval = <10>;
+            wakeup-source;
+        };
+
+        power3 {
+            label = "CAN0_WakeB";
+            gpios = <&gpio1 15 GPIO_ACTIVE_HIGH>;
+            linux,code = <KEY_WAKEUP>;
+            debounce-interval = <10>;
+            wakeup-source;
+        };
+
+        power4 {
+            label = "CAN0_WakeA";
+            gpios = <&gpio2 22 GPIO_ACTIVE_HIGH>;
+            linux,code = <KEY_WAKEUP>;
+            debounce-interval = <10>;
+            wakeup-source;
+        };
+    };
 };
 
 &ldo3_reg {
@@ -52,6 +91,15 @@
             BONE_P9_17 (SLEWCTRL_SLOW | PIN_INPUT_PULLUP | MUX_MODE3)
         >;
     };
+
+    wakeup_gpio_pins: pinmux_wakeup {
+        pinctrl-single,pins = <
+            BONE_P8_07 (SLEWCTRL_SLOW | PIN_INPUT_PULLUP | MUX_MODE7)
+            BONE_P8_11 (SLEWCTRL_SLOW | PIN_INPUT_PULLUP | MUX_MODE7)
+            BONE_P8_15 (SLEWCTRL_SLOW | PIN_INPUT_PULLUP | MUX_MODE7)
+            BONE_P8_27 (SLEWCTRL_SLOW | PIN_INPUT_PULLUP | MUX_MODE7)
+        >;
+    };
 };

I can see that the events are generated using "evtest".

root@beaglebone:/home/debian# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      tps65217_pwr_but
/dev/input/event1:      gpio-keys
Select the device event number [0-1]: 1
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 143 (KEY_WAKEUP)
Properties:
Testing ... (interrupt to exit)
Event: time 1517970542.951410, type 1 (EV_KEY), code 143 (KEY_WAKEUP), value 0
Event: time 1517970542.951410, -------------- SYN_REPORT ------------
Event: time 1517970544.088480, type 1 (EV_KEY), code 143 (KEY_WAKEUP), value 1
Event: time 1517970544.088480, -------------- SYN_REPORT ------------
Event: time 1517970544.163876, type 1 (EV_KEY), code 143 (KEY_WAKEUP), value 0
Event: time 1517970544.163876, -------------- SYN_REPORT ------------
Event: time 1517970546.154112, type 1 (EV_KEY), code 143 (KEY_WAKEUP), value 1
Event: time 1517970546.154112, -------------- SYN_REPORT ------------
Event: time 1517970546.217212, type 1 (EV_KEY), code 143 (KEY_WAKEUP), value 0
Event: time 1517970546.217212, -------------- SYN_REPORT ------------

However on going into memory suspend, by doing "echo mem > /sys/power/state", wake up does not occur upon any activity on the pins.

root@beaglebone:/home/debian# echo mem > /sys/power/state
[  377.767576] PM: Syncing filesystems ... done.
[  379.788251] Freezing user space processes ... (elapsed 0.001 seconds) done.
[  379.797231] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[  379.929843] PM: suspend of devices complete after 122.411 msecs
[  379.940029] PM: late suspend of devices complete after 3.962 msecs
[  379.950444] PM: noirq suspend of devices complete after 3.970 msecs
[  379.957124] Disabling non-boot CPUs ...

Wake up from RTC works however

root@beaglebone:/home/debian# echo +15 > /sys/class/rtc/rtc0/wakealarm; echo mem > /sys/power/state
[   75.428962] PM: Syncing filesystems ... done.
[   86.901348] Freezing user space processes ... (elapsed 0.001 seconds) done.
[   86.910330] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
[   87.042805] PM: suspend of devices complete after 122.277 msecs
[   87.053071] PM: late suspend of devices complete after 4.023 msecs
[   87.063483] PM: noirq suspend of devices complete after 3.947 msecs
[   87.070025] Disabling non-boot CPUs ...
[   87.073988] PM: Successfully put all powerdomains to target state
[   87.093775] PM: noirq resume of devices complete after 19.523 msecs
[   87.103980] PM: early resume of devices complete after 2.689 msecs
[   87.280782] net eth0: initializing cpsw version 1.12 (0)
[   87.286247] net eth0: initialized cpsw ale version 1.4
[   87.291537] net eth0: ALE Table size 1024
[   87.298751] net eth0: phy found : id is : 0x7c0f1
[   87.424691] PM: resume of devices complete after 314.316 msecs
[   87.435170] Restarting tasks ... done.


Is this a known issue? Has anybody tried this? Do I need to try with a mainline kernel or a kernel for TI's gitorious? Also does any one know if wake up on CAN works?


Thanks & Regards,
Sanchayan Maity.