Jetson Nano timed-gpios support for different behaviour on power-button

Hey guys,
I’d like to use timed-gpio for having this behaviour:
power-btn short press → suspend
power-btn-long press → poweroff

This should be possible using gpio-timed-keys interface.
I changed tegra210-porg-keys-p3448-0000-a00.dtsi to:

/ {
gpio-keys {
compatible = “gpio-keys”;
gpio-keys,name = “gpio-keys”;
status = “okay”;
disable-on-recovery-kernel;

  /*power {
            			label = "Power";
            			gpios = <&gpio TEGRA_GPIO(X, 5) GPIO_ACTIVE_LOW>;
            			linux,code = <KEY_POWER>;
            			gpio-key,wakeup;
            			debounce-interval = <30>;
            			nvidia,pmc-wakeup = <&tegra_pmc
            				PMC_WAKE_TYPE_GPIO 24 PMC_TRIGGER_TYPE_NONE>;
            		};*/

  forcerecovery {
  	label = "Forcerecovery";
  	gpios = <&gpio TEGRA_GPIO(X, 6) GPIO_ACTIVE_LOW>;
  	linux,code = <KEY_POWER>;
  	gpio-key,wakeup;
  	debounce-interval = <30>;
  };

};

gpio-timed-keys {
compatible = “gpio-timed-keys”;
gpio-keys,name = “gpio-timed-keys”;
status = “okay”;
disable-on-recovery-kernel;

  power {
  	label = "Power";
  	gpios = <&gpio TEGRA_GPIO(X, 5) GPIO_ACTIVE_LOW>;
  	linux,num_codes = <2>;
  	linux,press-time-secs = <1 3>;
  	linux,key-codes = <KEY_SUSPEND KEY_POWER>;
  	gpio-key,wakeup;
  	debounce-interval = <30>;
        nvidia,pmc-wakeup = <&tegra_pmc PMC_WAKE_TYPE_GPIO 24 PMC_TRIGGER_TYPE_NONE>;
  };

};
};

But now it is not working anymore at all. So I figured gpio-timed-keys is not built into the kernel so I changed that, so it gets built, but it’s still not working.
Is this supported? Do I need to change it somewhere else?

Or are there any other options?
Best regards,
jb

EDIT: I get this in dmesg:

[ 1.173320] input: gpio-timed-keys as /devices/gpio-timed-keys/input/input0

hello busch.johannes,

please also check Jetson Nano Product Design Guide,
you should check [Jetson Nano Power and System Pin Descriptions], it’s SHUTDOWN_REQ to issue a power-down.
thanks

But the original file uses KEY_POWER and the original is working. What would be the equivalent for suspend with SHUTDOWN_REQ?

hello busch.johannes,

could you please define the expect behavior of short press and long press, for example 1-sec, and 5-sec?
there’s behavior to power-off by press the powerkey for 6-second.
thanks

I’d like something like a really short press for suspend and 3 second press for shutdown.

I know about 6 second power-off, but this one is a hardware reset, isnt it? Is it recommended to shutdown the jetson like this in a daily manner while software is running?

hello busch.johannes,

please check the kernel driver,
$L4T_Sources/r32.5/Linux_for_Tegra/source/public/kernel/nvidia/drivers/input/keyboard/gpio_timed_keys.c

there’re three different options available for pressing button for 1-sec, 3-sec and 5-sec,
for example,

        gpio-timed-keys {
                compatible = "gpio-timed-keys";
                power {
                        linux,press-time-secs = <1 3 5>;
                        linux,key-codes = <KEY_DOWN KEY_DISPLAYTOGGLE KEY_ENTER>;

so, you may change the 1-sec behavior as KEY_SUSPEND for testing,
please refer to below for the details of keys and buttons,
i.e. $L4T_Sources/r32.5/Linux_for_Tegra/source/public/hardware/nvidia/soc/tegra/kernel-include/dt-bindings/input/linux-event-codes.h

there’s handling for the sudden power loss. so it won’t physically harm your platform.
note, it may have data lose if you’re writing data and also shutdown the board .

Please read my question from the beginning, that is exactly what I am trying to do which is not working for me.

hello busch.johannes,

according to [System Power States and Transitions] from Jetson Nano Module Data Sheet,
are you able to use KEY_SLEEP for entering sleep state?

Hi busch.johannes,

Is it still an issue? Any update?

Hi, sorry for no reply.
Since when using timed-gpio my power_key is also not working anymore, so I knew using KEY_SLEEP would not change that misbehaviour. Since I am short on time, I decided to drop this and just use the gpio for SUSPEND. Users can now power off completly from inside my GUI.