Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overlays: Add gpio-shutdown overlay #2103

Merged
merged 2 commits into from
Jul 9, 2017

Conversation

matthijskooijman
Copy link
Contributor

This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

The overlay was separately tested on:

I tested manually using dtc -@ -I dts -O dtb -o gpio-shutdown.dtbo gpio-shutdown-overlay.dts. I did not test compilation inside the kernel tree, for I have not got the environment set up for that.

For some more background, see the comments in the overlay source file and this blogpost: http://www.stderr.nl/Blog/Hardware/RaspberryPi/PowerButton.html

matthijskooijman and others added 2 commits July 7, 2017 09:56
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
@pelwell pelwell merged commit 91aa495 into raspberrypi:rpi-4.9.y Jul 9, 2017
@pelwell
Copy link
Contributor

pelwell commented Jul 9, 2017

The kernel patches build the overlay as expected. Nice job, especially on the comments.

@matthijskooijman
Copy link
Contributor Author

Thanks, great to have it merged so fast :-D

pelwell pushed a commit that referenced this pull request Jul 10, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
pelwell pushed a commit that referenced this pull request Jul 10, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 12, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jul 13, 2017
kernel: usb: gadget: f_hid: fix: Move IN request allocation to set_alt()
See: raspberrypi/linux#1943

kernel: overlays: Add gpio-shutdown overlay
See: raspberrypi/linux#2103

kernel: config: enable generic S/PDIF codec drivers
See: raspberrypi/linux#2104

kernel: drm/vc4: firmwarekms DPMS support
See: raspberrypi/linux#2102
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jul 13, 2017
kernel: usb: gadget: f_hid: fix: Move IN request allocation to set_alt()
See: raspberrypi/linux#1943

kernel: overlays: Add gpio-shutdown overlay
See: raspberrypi/linux#2103

kernel: config: enable generic S/PDIF codec drivers
See: raspberrypi/linux#2104

kernel: drm/vc4: firmwarekms DPMS support
See: raspberrypi/linux#2102
popcornmix pushed a commit that referenced this pull request Jul 16, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 16, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 17, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 21, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 21, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
macmpi referenced this pull request in volumio/Build Jul 26, 2017
popcornmix pushed a commit that referenced this pull request Jul 27, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Jul 29, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 1, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 8, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 8, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 10, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 14, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 23, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 23, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 25, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 30, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 1, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 4, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 8, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 13, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 14, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 14, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 22, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
popcornmix pushed a commit that referenced this pull request Oct 29, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
ryncsn pushed a commit to ryncsn/linux-rasp that referenced this pull request Nov 21, 2017
This overlay facilitates the addition of a powerbutton by converting
GPIO edges into KEY_POWER keypresses, which can be handled by
systemd-logind to shut down the system.

Signed-off-by: Matthijs Kooijman <[email protected]>
@pali
Copy link
Contributor

pali commented Jun 15, 2019

Overlay in this pull request does not work for RPI 1 rev 1. RPI 1 rev 1 uses GPIO1 instead of GPIO3.

I modified original overlay for RPI 1 rev 1 by applying following diff and then it start working on RPI 1 rev 1 too:

--- gpio-shutdown-overlay.dts	2017-07-07 02:09:12.000000000 +0200
+++ gpio-shutdown-rpi1-overlay.dts	2018-12-25 14:58:42.000000000 +0100
@@ -1,13 +1,14 @@
 // Definitions for gpio-poweroff module
+// Modified for RPI 1 rev 1 (changed GPIO3 to gpio GPIO1)
 /dts-v1/;
 /plugin/;
 
 // This overlay sets up an input device that generates KEY_POWER events
-// when a given GPIO pin changes. It defaults to using GPIO3, which can
+// when a given GPIO pin changes. It defaults to using GPIO1, which can
 // also be used to wake up (start) the Rpi again after shutdown. Since
 // wakeup is active-low, this defaults to active-low with a pullup
 // enabled, but all of this can be changed using overlay parameters (but
-// note that GPIO3 has an external pullup on at least some boards).
+// note that GPIO1 has an external pullup on at least some boards).
 
 / {
 	compatible = "brcm,bcm2708";
@@ -22,8 +23,8 @@
 			// by a "pinctrl client", as is done below. See:
 			//   https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt
 			//   https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt
-			pin_state: shutdown_button_pins {
-				brcm,pins = <3>; // gpio number
+			pin_state: shutdown_button_rpi1_pins {
+				brcm,pins = <1>; // gpio number
 				brcm,function = <0>; // 0 = input, 1 = output
 				brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up
 			};
@@ -33,7 +34,7 @@
 		// Add a new device to the /soc devicetree node
 		target-path = "/soc";
 		__overlay__ {
-			shutdown_button {
+			shutdown_button_rpi1 {
 				// Let the gpio-keys driver handle this device. See:
 				// https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
 				compatible = "gpio-keys";
@@ -49,10 +50,10 @@
 				// Define a single key, called "shutdown" that monitors the gpio and sends KEY_POWER
 				// (keycode 116, see
 				// https://github.com/torvalds/linux/blob/v4.12/include/uapi/linux/input-event-codes.h#L190)
-				button: shutdown {
-					label = "shutdown";
+				button: shutdown_rpi1 {
+					label = "shutdown_rpi1";
 					linux,code = <116>; // KEY_POWER
-					gpios = <&gpio 3 1>;
+					gpios = <&gpio 1 1>;
 				};
 			};
 		};
@@ -69,7 +70,7 @@
 		           <&pin_state>,"brcm,pins:0";
 
 		// Allow changing the internal pullup/down state. 0 = none, 1 = pulldown, 2 = pullup
-		// Note that GPIO3 and GPIO2 are the I2c pins and have an external pullup (at least
+		// Note that GPIO1 and GPIO0 are the I2c pins and have an external pullup (at least
                 // on some boards).
 		gpio_pull = <&pin_state>,"brcm,pull:0";
 

@matthijskooijman
Copy link
Contributor Author

Rather than modifying the overlay, you can just specify a different GPIO as an argument. E.g.

dtoverlay=gpio-shutdown,gpio_pin=1

Or did you try this and did it not work? It might be good to add this to the documentation somewhere (i.e. that this version needs gpio1 rather than 3).

@pelwell
Copy link
Contributor

pelwell commented Jun 15, 2019

@matthijskooijman Thank you for saving me the typing!

@pali
Copy link
Contributor

pali commented Jun 15, 2019

@matthijskooijman I have not know that it is possible to specify different GPIO... Where to write that line? Directly to config.txt, replacing my current dtoverlay=gpio-shutdown-rpi1 line? Or it is argument for kernel via cmdline?

@matthijskooijman
Copy link
Contributor Author

The former. See also the docs

@pali
Copy link
Contributor

pali commented Dec 19, 2019

@matthijskooijman Now I tested dtoverlay=gpio-shutdown,gpio_pin=1 and it is working fine without need to modification of gpio-shutdown-overlay.dts like I used to use it til now.

So thanks for simplification of setup for my RPI 1 rev 1.

What about updating that README file by adding a note that for RPI 1 rev 1 it is needed to change gpio_pin parameter from default value to 1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants