allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

[SOLVED] gpio-shutdown overlay not working

Wed Jan 08, 2020 7:40 pm

Hi, apologies if this has already been covered but I couldn't find a solution anywhere.

I'm running version 4.19.75-v7l+ on a Pi 4B, and with everything up-to-date. Its main purpose is as a NAS so I'm also running OMV version 5.2.2-1, though I don't suppose that is influencing anything.

I've added:

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,debounce=1500
dtoverlay=gpio-poweroff,gpiopin=27,active_low=1,input=1
...to my /boot/config.txt. My main problem is that applying a logic low to pin 17 does not initiate shutdown - in fact nothing happens. If I use raspi-gpio get 17, I can see that the level changes from 1 to 0 as expected, so the pin is definitely working ok.

Doing "sudo vcdbg log msg" seems to suggest the overlay has been applied ok, in that there are no error messages like perhaps I spelled a parameter incorrectly, etc. I've also tried a few other GPIO pins, including dedicated (rather than multiple-use) GPIOs, but with the same result.

I did have gpio-shutdown working briefly at some point in the past, but something changed (maybe an update) and now it's not working again. When it *did* work, the debounce=1500 part did not seem to do anything; shutdown was triggered immediately rather than after a 1.5sec delay. However the gpio-poweroff overlay *was* working, and pin 27 did indeed switch from input to output and drive a low, so that's ok.

I'm not really keen on starting from scratch with a fresh install, so can anyone help debug the setup I've got please?

Any help much appreciated!
Thanks, Rob.

trejan
Posts: 1112
Joined: Tue Jul 02, 2019 2:28 pm

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:06 pm

gpio-shutdown generates a KEY_POWER event that triggers systemd to initiate a shutdown. Are you running Raspbian or something else? If they're not using systemd or you've modified it then it may not work. If are running Raspbian, what version? Have you done anything else apart from install OMV?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:18 pm

Another factor to consider is that gpio 17 pulls low by default. Run "raspi-gpio get 17" to confirm that the input is low all the time, which will cause the gpio-key driver to ignore that input as a stuck key.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:19 pm

trejan wrote:
Wed Jan 08, 2020 8:06 pm
gpio-shutdown generates a KEY_POWER event that triggers systemd to initiate a shutdown. Are you running Raspbian or something else? If they're not using systemd or you've modified it then it may not work. If are running Raspbian, what version? Have you done anything else apart from install OMV?
Thanks, I'm running Raspbian Buster:
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

I haven't installed anything else IIRC except OMV and, just yesterday for debug I added raspi-gpio. As I mentioned, at one point it did work, so I suspect the problem isn't that fundamental.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:25 pm

allactionrob wrote:
Wed Jan 08, 2020 8:19 pm
trejan wrote:
Wed Jan 08, 2020 8:06 pm
gpio-shutdown generates a KEY_POWER event that triggers systemd to initiate a shutdown. Are you running Raspbian or something else? If they're not using systemd or you've modified it then it may not work. If are running Raspbian, what version? Have you done anything else apart from install OMV?
Thanks, I'm running Raspbian Buster:
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

I haven't installed anything else IIRC except OMV and, just yesterday for debug I added raspi-gpio. As I mentioned, at one point it did work, so I suspect the problem isn't that fundamental.
...oh and folder2ram.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:31 pm

Re: the default pull, the overlay overrides the default behaviour so it pulls up (which wouldn't work well if active_low=0, but it isn't so you are ok).

Does xev show any activity when you ground the pin? Is the gpio-key module loaded? Does gpioinfo show the GPIO as being claimed? (You may need to "sudo apt install gpiod").

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:42 pm

PhilE wrote:
Wed Jan 08, 2020 8:31 pm
Re: the default pull, the overlay overrides the default behaviour so it pulls up (which wouldn't work well if active_low=0, but it isn't so you are ok).

Does xev show any activity when you ground the pin? Is the gpio-key module loaded? Does gpioinfo show the GPIO as being claimed? (You may need to "sudo apt install gpiod").
I'm driving the pin from a logic output, so not relying on pull-ups/pull-downs. In any case, as I say, I can see the pin level changing as it should using raspi-gpio (is that equivalent to your suggestion to use xev?).

Re your other suggestions, can you explain what I need to do to check these things? Thanks.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:55 pm

PhilE wrote:
Wed Jan 08, 2020 8:31 pm
Re: the default pull, the overlay overrides the default behaviour so it pulls up (which wouldn't work well if active_low=0, but it isn't so you are ok).

Does xev show any activity when you ground the pin? Is the gpio-key module loaded? Does gpioinfo show the GPIO as being claimed? (You may need to "sudo apt install gpiod").
Ah, figured out one thing:

Code: Select all

/sbin/lsmod
Module                  Size  Used by
...
gpio_keys              20480  0
...
Does that help?

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 8:58 pm

allactionrob wrote:
Wed Jan 08, 2020 8:42 pm
PhilE wrote:
Wed Jan 08, 2020 8:31 pm
Re: the default pull, the overlay overrides the default behaviour so it pulls up (which wouldn't work well if active_low=0, but it isn't so you are ok).

Does xev show any activity when you ground the pin? Is the gpio-key module loaded? Does gpioinfo show the GPIO as being claimed? (You may need to "sudo apt install gpiod").
I'm driving the pin from a logic output, so not relying on pull-ups/pull-downs. In any case, as I say, I can see the pin level changing as it should using raspi-gpio (is that equivalent to your suggestion to use xev?).

Re your other suggestions, can you explain what I need to do to check these things? Thanks.
And also:

Code: Select all

sudo gpioinfo
gpiochip0 - 54 lines:
...
        line  17:      unnamed   "shutdown"   input   active-low [used]
...
        line  27:      unnamed "power_ctrl"   input   active-low [used]
...
So that looks ok, right?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 9:06 pm

Yes, that all looks as expected.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 9:10 pm

PhilE wrote:
Wed Jan 08, 2020 9:06 pm
Yes, that all looks as expected.
One other thing I just noticed: something does happen when I assert GPIO17 - the red LED goes off. But that's it. Nothing else appears to change, and the Pi stays up and running.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 9:24 pm

One other thing I just noticed: something does happen when I assert GPIO17 - the red LED goes off. But that's it.
That could be an indication that the voltage is dropping too low, briefly. Do you have a too-small resistor in there somewhere?

I don't have a Pi to hand, so this is a bit vague, but there should be either a /dev/input or a /dev/input/input0, etc. Try running "hexdump /dev/input" etc. and pushing keys on the normal keyboard. Then grounding GPIO17 and see if anything is generated.

Another thought - the gpio-key driver should be requesting interrupts when the GPIO level changes. Does "grep gpio /proc/interrupts" return anything? If so, repeated ground the GPIO and see if the grep returns changing results. If not, post the complete output of "cat /proc/interrupts".

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 9:43 pm

PhilE wrote:
Wed Jan 08, 2020 9:24 pm
One other thing I just noticed: something does happen when I assert GPIO17 - the red LED goes off. But that's it.
That could be an indication that the voltage is dropping too low, briefly. Do you have a too-small resistor in there somewhere?

I don't have a Pi to hand, so this is a bit vague, but there should be either a /dev/input or a /dev/input/input0, etc. Try running "hexdump /dev/input" etc. and pushing keys on the normal keyboard. Then grounding GPIO17 and see if anything is generated.

Another thought - the gpio-key driver should be requesting interrupts when the GPIO level changes. Does "grep gpio /proc/interrupts" return anything? If so, repeated ground the GPIO and see if the grep returns changing results. If not, post the complete output of "cat /proc/interrupts".
Ok, the red LED thing is a red herring. It probably is undervolting slightly, but I know why that is (long story, due to power management circuit). I've changed to using GPIO26 with a pull-up enabled, so that I can simply short it to ground without affecting the power supply at all. Behaviour now is identical to before, but without the red LED going out.

Code: Select all

sudo hexdump /dev/input/event0
...does indeed result in a bunch of lines appearing whenever I ground GPIO26.

Code: Select all

cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3
 17:          0          0          0          0     GICv2  29 Level     arch_timer
 18:       7395       9544      11567      12119     GICv2  30 Level     arch_timer
 21:          0          0          0          0     GICv2 112 Level     bcm2708_fb DMA
 23:        339          0          0          0     GICv2 114 Level     DMA IRQ
 31:        218          0          0          0     GICv2  65 Level     fe00b880.mailbox
 34:       6548          0          0          0     GICv2 153 Level     uart-pl011
 37:          0          0          0          0     GICv2  72 Level     dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb3
 38:          0          0          0          0     GICv2 169 Level     brcmstb_thermal
 39:      29861          0          0          0     GICv2 158 Level     mmc1, mmc0
 45:       2856          0          0          0     GICv2 189 Level     eth0
 46:        344          0          0          0     GICv2 190 Level     eth0
 52:         51          0          0          0     GICv2  66 Level     VCHIQ doorbell
 53:          0          0          0          0     GICv2 175 Level     PCIe PME, aerdrv
 54:      10693          0          0          0  Brcm_MSI 524288 Edge      xhci_hcd
 55:        302          0          0          0  pinctrl-bcm2835  26 Edge      shutdown
FIQ:              usb_fiq
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:       4098       7248       7311      13226  Rescheduling interrupts
IPI3:       1318       5812       1467       4425  Function call interrupts
IPI4:          0          0          0          0  CPU stop interrupts
IPI5:        736        400        851        652  IRQ work interrupts
IPI6:          0          0          0          0  completion interrupts
Note the line starting 55. Looks like it should be working!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 9:58 pm

Indeed - it seems that the KEY_POWER is being generated but that nothing is responding to it. Strange.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Wed Jan 08, 2020 10:03 pm

PhilE wrote:
Wed Jan 08, 2020 9:58 pm
Indeed - it seems that the KEY_POWER is being generated but that nothing is responding to it. Strange.
I'm glad you think so too :D This stuff is way beyond me, I'm calling it a night. Thanks for your help so far - I don't want to give up yet!
Rob.

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Thu Jan 09, 2020 5:45 pm

A few more details:

Code: Select all

dmesg | grep -i shutdown
[    4.205917] input: soc:shutdown_button as /devices/platform/soc/soc:shutdown_button/input/input0
...so is that the shutdown button getting registered at startup? There are no other mentions of shutdown in the messages (having asserted the GPIO a few times) so the shutdown isn't getting requested.

However:

Code: Select all

sudo journalctl | grep -i power
...
Jan 09 17:38:29 NAS systemd-logind[675]: Power key pressed.
Jan 09 17:38:31 NAS systemd-logind[675]: Power key pressed.
...seems to show the power key events occurring. Any ideas?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2579
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: gpio-shutdown overlay not working

Thu Jan 09, 2020 5:53 pm

Have a look in /etc/systemd/logind.conf for HandlePowerKey. The default value (if nothing is specified) is "poweroff", but it might have been changed by something. This page explains the options: https://www.freedesktop.org/software/sy ... .conf.html

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Thu Jan 09, 2020 6:03 pm

PhilE wrote:
Thu Jan 09, 2020 5:53 pm
Have a look in /etc/systemd/logind.conf for HandlePowerKey. The default value (if nothing is specified) is "poweroff", but it might have been changed by something. This page explains the options: https://www.freedesktop.org/software/sy ... .conf.html

Code: Select all

 cat /etc/systemd/logind.conf

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
HandlePowerKey = ignore
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
Ha! Set to ignore. Maybe that's the problem...

allactionrob
Posts: 21
Joined: Tue Jun 26, 2012 7:39 am

Re: gpio-shutdown overlay not working

Thu Jan 09, 2020 6:14 pm

Yup - that was it. Setting it back to "poweroff" has fixed it. And I've reverted back to my original GPIO pin and everything's behaving as expected now. Thanks PhilE! :D

Highlander88
Posts: 21
Joined: Fri Aug 22, 2014 4:20 pm

Re: gpio-shutdown overlay not working

Tue Feb 11, 2020 4:53 pm

It appears that the issue is exactly OMV because I have installed it and after the installation the button wasn't working, the I've found this post and I've remembered that there was an option inside OMV Web interface regarding shutdown. Under System > Power Management > Power Button choose "Shutdown" and if you check HandlePowerKey in logind.conf is changed from ignore to poweroff

Return to “Device Tree”