rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

[SOLVED] Multiple dtoverlay=gpio-shutdown line in config.txt

Fri Apr 23, 2021 8:24 am

Hi,

Is it possible to use multiple GPIO pin to trigger shutdown event via config.txt? I got a button connected to GPIO 3 that act as standard shutdown and power button. In addition, I use another pin GPIO 5 that connect to a sensor. When sensor output state fall from one to zero, I want to trigger shutdown event as well.

Here is what i add to my config.txt

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,debounce=4000
dtoverlay=gpio-shutdown,gpio_pin=5,active_low=1

It seems like only the last line work as intended. I'm guessing it only works on single pin? Is there any other way to achieve what i want via config.txt? I prefer not to add additional service to poll the pin state if possible, and due to hardware limitation, I cannot add any component or wiring on the board to share the pin.

Thanks in advance.

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Fri Apr 23, 2021 9:13 am

Multiple instances of the gpio-shutdown overlay won't work because they end up occupying the same area in the Device Tree.

However, since all you are trying to do is detect a pull-to-ground, why not use the "Wired-AND" configuration and attach the button to the same GPIO as the sensor?

rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sat Apr 24, 2021 1:19 am

PhilE wrote:
Fri Apr 23, 2021 9:13 am
Multiple instances of the gpio-shutdown overlay won't work because they end up occupying the same area in the Device Tree.

However, since all you are trying to do is detect a pull-to-ground, why not use the "Wired-AND" configuration and attach the button to the same GPIO as the sensor?
Well, i know i can share the gpio but as mentioned in my op, i can't add anything on board due to hardware limitation.

Is it possible to add this feature in future? I think it is neater to be able to put multiple gpio-shutdown line in config.txt so I don't have to write a special service just to deal with this additional gpio. I don't even have to add anything on board as well which can save time and cost.

cleverca22
Posts: 3778
Joined: Sat Aug 18, 2012 2:33 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sat Apr 24, 2021 9:21 am

rasp14 wrote:
Sat Apr 24, 2021 1:19 am
Is it possible to add this feature in future? I think it is neater to be able to put multiple gpio-shutdown line in config.txt so I don't have to write a special service just to deal with this additional gpio. I don't even have to add anything on board as well which can save time and cost.
it should be possible to just write your own overlay to handle that

https://github.com/raspberrypi/linux/bl ... verlay.dts

the names for shutdown_button_pins, pin_state, shutdown_button, and maybe button and shutdown, must all be unique

you could probably skip the __overrides__ section (that lets you configure it further), and just make a single overlay, that does both pins at once

looking closer, i think you just want to
  • add 2 pins to the brcm,pins array
  • double up the entries in brcm,function and brcm,pull
  • duplicate the "button: shutdown {" region, making the gpios= of each point to a different pin, and giving them unique names
https://www.raspberrypi.org/documentati ... ce-tree.md
then you can follow these directions to compile your custom overlay to /boot/overlays/custom-shtudown-pins.dtbo, and load it with dtoverlay=custom-shutdown-pins

rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sun Apr 25, 2021 5:23 pm

cleverca22 wrote:
Sat Apr 24, 2021 9:21 am
rasp14 wrote:
Sat Apr 24, 2021 1:19 am
Is it possible to add this feature in future? I think it is neater to be able to put multiple gpio-shutdown line in config.txt so I don't have to write a special service just to deal with this additional gpio. I don't even have to add anything on board as well which can save time and cost.
it should be possible to just write your own overlay to handle that

https://github.com/raspberrypi/linux/bl ... verlay.dts

the names for shutdown_button_pins, pin_state, shutdown_button, and maybe button and shutdown, must all be unique

you could probably skip the __overrides__ section (that lets you configure it further), and just make a single overlay, that does both pins at once

looking closer, i think you just want to
  • add 2 pins to the brcm,pins array
  • double up the entries in brcm,function and brcm,pull
  • duplicate the "button: shutdown {" region, making the gpios= of each point to a different pin, and giving them unique names
https://www.raspberrypi.org/documentati ... ce-tree.md
then you can follow these directions to compile your custom overlay to /boot/overlays/custom-shtudown-pins.dtbo, and load it with dtoverlay=custom-shutdown-pins
Thanks for this. Learned something new today. It's beyond my capability for now, I'll try it when i have the time.

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sun Apr 25, 2021 7:41 pm

I've taken another approach and used the gpio_pin parameter to rename the shutdown_button and shutdown_button_pins nodes so that they don't clash with other instances. There's a test build of the updated overlay here: https://drive.google.com/file/d/1ly_tPl ... sp=sharing

cleverca22
Posts: 3778
Joined: Sat Aug 18, 2012 2:33 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sun Apr 25, 2021 8:27 pm

PhilE wrote:
Sun Apr 25, 2021 7:41 pm
I've taken another approach and used the gpio_pin parameter to rename the shutdown_button and shutdown_button_pins nodes so that they don't clash with other instances. There's a test build of the updated overlay here: https://drive.google.com/file/d/1ly_tPl ... sp=sharing
ah, that sounds much better, but i'm not familiar with how to implement that auto-rename, i should check your diff on git to learn how!

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sun Apr 25, 2021 9:21 pm

The same technique is used in gpio-key. In fact, gpio-shutdown is just a special case of gpio-key.

rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Thu May 13, 2021 5:02 am

PhilE wrote:
Sun Apr 25, 2021 7:41 pm
I've taken another approach and used the gpio_pin parameter to rename the shutdown_button and shutdown_button_pins nodes so that they don't clash with other instances. There's a test build of the updated overlay here: https://drive.google.com/file/d/1ly_tPl ... sp=sharing
Can you provide an example on how to use this file?

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Thu May 13, 2021 7:37 am

Install it with:

Code: Select all

$ sudo cp gpio-shutdown.dtbo /boot/overlays
(although the updated version is now part of standard kernel builds)

Use it with:

Code: Select all

# Use the defaults - GPIO 3, active-low
dtoverlay=gpio-shutdown
# Add a second GPIO - 20 - and make it active-high
dtoverlay=gpio-shutdown,gpio_pin=20,active_low=0

rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Fri May 14, 2021 1:53 pm

PhilE wrote:
Thu May 13, 2021 7:37 am
Install it with:

Code: Select all

$ sudo cp gpio-shutdown.dtbo /boot/overlays
(although the updated version is now part of standard kernel builds)

Use it with:

Code: Select all

# Use the defaults - GPIO 3, active-low
dtoverlay=gpio-shutdown
# Add a second GPIO - 20 - and make it active-high
dtoverlay=gpio-shutdown,gpio_pin=20,active_low=0
I see. Thank you very much! If i use back the code in my original post, by right it should work as separate instance that monitor pin3 and pin5 right?

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Fri May 14, 2021 2:53 pm

Yes, provided you have the latest version of the overlay.

rasp14
Posts: 70
Joined: Sun Jun 22, 2014 2:49 pm

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sat May 15, 2021 2:24 am

PhilE wrote:
Fri May 14, 2021 2:53 pm
Yes, provided you have the latest version of the overlay.
I've tested it and confirm the new overlay is working as expected. Thank you very much!

This overlay will available in next kernal update right? I just need to run apt-get update && apt-get upgrade to get the latest overlay file?

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

Re: Multiple dtoverlay=gpio-shutdown line in config.txt

Sat May 15, 2021 7:40 am

This overlay will available in next kernal update right? I just need to run apt-get update && apt-get upgrade to get the latest overlay file?
That's correct.

Return to “Device Tree”