i.MX7D GPIO Power/On Off Setup


I’m trying to figure out how to properly setup the GPIO power On\Off functionality in the embedded Linux we are using on our device.

I’ve read through the GPIO (Linux) document that you have available and found a section that gives information on how this should be done: GPIO (Linux).

I setup nodes in our carrier board specific device tree file as follows:

gpio-keys {
		compatible = "gpio-keys";
		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_powerkeys>;

		power {
		 	label = "Power-Key";
			gpios = <&gpio2 29 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
			debounce-interval = <10>;

&iomuxc {
      imx7d-p1100 {
            pinctrl_powerkeys: powerkeys {
			fsl,pins = <
				MX7D_PAD_EPDC_BDR1__GPIO2_IO29  	0X14 /*SODIMM 110*/

and I’ve also setup the contents of the /etc/udev/rules.d/power-key.rules file as specified in the document:

ACTION=="remove", GOTO="power_switch_end"

SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_PATH}=="platform-gpio-keys*", ATTRS{keys}=="*", TAG+="power-switch" 

But when I go to press the power button on our device, power will not latch on. I have to hold the power button constantly. If I let go power is lost. I’ve configured everything the way that is specified in the document linked above, but it’s not working.

What am I doing wrong? Is there something that needs to be configured in U-boot to make this work correctly?

The document also mentions: HandlePowerKey/HandleSuspendKey and HandleHibernateKey in /etc/systemd/logind.conf I’ve looked at this file as it exists in embedded Linux running on our device and here are the contents:

#  This file is part of systemd.
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
# See logind.conf(5) for details.


Is there anything additional that I need to do in this file to make this work?

Thank You.

I don’t quite understand what you expect from the GPIO to trigger. The GPIO is just a key event for the Linux system. It usually triggers a system shutdown (like the power button on a ACPI enabled PC).

After the system is shut down, a second GPIO can be used to trigger an external power controller to actually power off the system (see “GPIO Power-Off” chapter).

It’s not possible to latch a power by software way only. You need to have some kind of HW support. For example LTC2954 Pushbutton On/Off Controller or at least GPIO controlled transistor connected in parallel with your power button.

I have this working now. Our Power button is not part of the keypad matrix so it cannot by assigned a key value in the device tree that embedded Linux will generate. I got this working now by adding code to the board_init() function in the U-boot bootloader colibri_imx7c file. This code latches the correct GPIO line when the Power button is pressed. So, this works now exactly the way we need. Thank you stefan.tx and Alex_Samutin for the information you provided.