Apalis imx6 gpio power-off

Hi,

I wanted to use gpio-poweroff from the device tree to power-off the system. But before power-off the application on the image need to be intimated that power-off button is pressed. and then the shutdown is initiated. and then the total power-off should take place. how to proceed on this ?

Please have a look at the two subsequent sections of the following article:

https://developer.toradex.com/knowledge-base/gpio-(linux)#GPIO_Power_Management_Keys

Hi,
I have followed the link but this does not completely power-off. So i need how to use both gpio- power management keys and gpio-poweroff.

It should really all be explained right there. Remember that you also need to wire resp. GPIOs to the Power Control Header for any of this to work.

Hi marcel,

The requirement here is before the dc-dc power is off the image shutdown needs to be initiated with proper closing of application by saving the data. we can directly use force_off on the board but it wont help in saving the data before the application is closed. so we want the image to know when the power-off process is initiated.

Yes, did you actually read the part about “GPIO Power Management Keys”? That’s exactly what that describes.

Hi marcel,

you mean to say to make a udev rule to add the power switch and tag to the GPIO key event source. I have followed and added a power-key.rules and copied the file to /etc/udev/rules.d/power-keys.rules

Power-keys.rules consists of below

ACTION==“remove”, GOTO=“power_switch_end”

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

LABEL=“power_switch_end”

but the above procedure i followed but the force-off is not working. any changes need to be done in power-keys.ruleslink text

And you did create a udev rule to tag the GPIO input device for the power off key?

yes i did created the udev rule which was given under the link
https://developer.toradex.com/knowledge-base/gpio-(linux)#GPIO_Power_Management_Keys

and i have customized the device tree with

gpio-keys {
compatible = “gpio-keys”;
pinctrl-names = “default”;
pinctrl-0 = <&pinctrl_gpio-keys>;
power {
label = “Power-Key”;
gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
linux,code = <KEY_POWER>;
debounce-interval = <10>;
};
};

WHEN I MAKE THE gpio1 io04 PIN LOW THE SYSTEM IS SHUTTING DOWN but before shutting down i need to save the data. will that happen automatically?. after shutdown of the system FORCEOFF that is complete power off to dc-dc board does not happen. i need that to happen

WHEN I MAKE THE gpio1 io04 PIN LOW THE SYSTEM IS SHUTTING DOWN but before shutting down i need to save the data. will that happen automatically?

Yes, if your application properly handles the termination signal SIGTERM.

BTW: No reason to start shouting.

After shutdown of the system FORCEOFF that is complete power off to dc-dc board does not happen. i need that to happen

And you also specified a gpio-poweroff? Which one did you use and how did you wire it up?

Hi marcel,

Till now i didn’t use gpio-poweroff.
I have used gpio-keys and customized the device tree

gpio-keys
{
compatible = “gpio-keys”;
pinctrl-names = “default”;
pinctrl-0 = <&pinctrl_gpio-keys>;
power
{
label = “Power-Key”;
gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
linux,code = ;
debounce-interval = <10>;
};
};

Then when i make the pin low it is shutting down.
sorry it does not indicate shouting, i wanted to highlight the process

Hi marcel,

can you insight how does udev rule work and how it is linked with systemd/logind

To actually have the system physically powering off you will need to use a gpio-poweroff as well and also wire it up just as mentioned in the article.

can you insight how does udev rule work and how it is linked with systemd/logind

That just makes sure the power-switch input event actually gets properly forwarded to the init daemon being systemd in your case. But you mentioned this is already working just fine, isn’t it?

HI marcel,

without the udev rule and with only customizing the device tree it was shutting down.

and my main question is
how does gpio-keys and gpio-poweroff interact each other if we are using both in the device tree or can we use same pin for both the functions ?

without the udev rule and with only customizing the device tree it was shutting down.

Sorry, but it is not clear to me what exactly you mean here now by “was shutting down”. You mean you used a gpio-poweroff and that worked? Or do you just mean the software shutdown part?

and my main question is how does gpio-keys and gpio-poweroff interact each other if we are using both in the device tree

I am not exactly sure what you mean by this. They do not interact at all. Those are two completely separate things. One is a GPIO key which is an input generating input events which using that udev rule may cause the init daemon e.g. systemd to initiate a software shutdown. The other is a GPIO poweroff being an output to physically cut the power at the end of such a software shutdown sequence.

or can we use same pin for both the functions?

I don’t think so as one is an input while the other is an output.

i didnt add the udev rule and just customized the imx6q-apalis-eval.dtsi and compiled. the newly generated .dtb file is copied to the uboot and the image is loaded. then i made the gpio1 io04 pin low then the system starts shutdown without adding the udev rule.

Hi marcel,

Im using linux image ver 2.7 in the https://developer.toradex.com/knowledge-base/gpio-(linux)#GPIO_PowerOff section for imx6 modules there CONFIG_POWER_RESET_GPIO must be set in kernel configuration. for ver 2.7 linux-toradex branch is toradex_4.1-2.0.x-imx. but it is mentioned to use toradex_imx_3.10.17_1.0.0_ga-next.

For toradex_4.1-2.0.x-imx branch what needs to be edited or any commit to use gpio-poweroff?

OK, I guess later systemd/udev may already configure this by default.

Yes, 2.7 uses toradex_4.1-2.0.x-imx as can be seen from here and it still requires the same kernel configuration to be enabled and device tree changes to be made:

Symbol: POWER_RESET_GPIO [=n]
 Type  : boolean
 Prompt: GPIO power-off driver
   Location:
     -> Device Drivers
       -> Power supply class support (POWER_SUPPLY [=y])
         -> Board level reset or power off (POWER_RESET [=n])
   Defined at drivers/power/reset/Kconfig:52
   Depends on: POWER_SUPPLY [=y] && POWER_RESET [=n] && OF_GPIO [=y]