Skip to content

Commit fb193ab

Browse files
shawajpopcornmix
authored andcommitted
add gpio-key overlay (#2329)
An overlay that allows a Linux key to be bound to a GPIO.
1 parent 2a83f92 commit fb193ab

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
3131
googlevoicehat-soundcard.dtbo \
3232
gpio-ir.dtbo \
3333
gpio-ir-tx.dtbo \
34+
gpio-key.dtbo \
3435
gpio-poweroff.dtbo \
3536
gpio-shutdown.dtbo \
3637
hifiberry-amp.dtbo \

arch/arm/boot/dts/overlays/README

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ Params: gpio_pin Output GPIO (default 18)
515515
Default is "0" (active-high).
516516

517517

518+
Name: gpio-key
519+
Info: This is a generic overlay for activating GPIO keypresses using
520+
the gpio-keys library and this dtoverlay. Multiple keys can be
521+
set up using multiple calls to the overlay for configuring
522+
additional buttons or joysticks. You can see available keycodes
523+
at https://github.com/torvalds/linux/blob/v4.12/include/uapi/
524+
linux/input-event-codes.h#L64
525+
Load: dtoverlay=gpio-key,<param>=<val>
526+
Params: gpio GPIO pin to trigger on (default 3)
527+
active_low When this is 1 (active low), a falling
528+
edge generates a key down event and a
529+
rising edge generates a key up event.
530+
When this is 0 (active high), this is
531+
reversed. The default is 1 (active low)
532+
gpio_pull Desired pull-up/down state (off, down, up)
533+
Default is "up". Note that the default pin
534+
(GPIO3) has an external pullup
535+
label Set a label for the key
536+
keycode Set the key code for the button
537+
538+
518539
Name: gpio-poweroff
519540
Info: Drives a GPIO high or low on poweroff (including halt). Enabling this
520541
overlay will prevent the ability to boot by driving GPIO3 low.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Definitions for gpio-key module
2+
/dts-v1/;
3+
/plugin/;
4+
5+
/ {
6+
compatible = "brcm,bcm2708";
7+
8+
fragment@0 {
9+
// Configure the gpio pin controller
10+
target = <&gpio>;
11+
__overlay__ {
12+
pin_state: button_pins@0 {
13+
brcm,pins = <3>; // gpio number
14+
brcm,function = <0>; // 0 = input, 1 = output
15+
brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up
16+
};
17+
};
18+
};
19+
fragment@1 {
20+
target-path = "/";
21+
__overlay__ {
22+
button: button@0 {
23+
compatible = "gpio-keys";
24+
pinctrl-names = "default";
25+
pinctrl-0 = <&pin_state>;
26+
status = "okay";
27+
28+
key: key {
29+
linux,code = <116>;
30+
gpios = <&gpio 3 1>;
31+
label = "KEY_POWER";
32+
};
33+
};
34+
};
35+
};
36+
37+
__overrides__ {
38+
gpio = <&key>,"gpios:4",
39+
<&button>,"reg:0",
40+
<&pin_state>,"brcm,pins:0",
41+
<&pin_state>,"reg:0";
42+
label = <&key>,"label";
43+
keycode = <&key>,"linux,code:0";
44+
gpio_pull = <&pin_state>,"brcm,pull:0";
45+
active_low = <&key>,"gpios:8";
46+
};
47+
48+
};

0 commit comments

Comments
 (0)