|
| 1 | +// Definitions for gpio-poweroff module |
| 2 | +/dts-v1/; |
| 3 | +/plugin/; |
| 4 | + |
| 5 | +// This overlay sets up an input device that generates KEY_POWER events |
| 6 | +// when a given GPIO pin changes. It defaults to using GPIO3, which can |
| 7 | +// also be used to wake up (start) the Rpi again after shutdown. Since |
| 8 | +// wakeup is active-low, this defaults to active-low with a pullup |
| 9 | +// enabled, but all of this can be changed using overlay parameters (but |
| 10 | +// note that GPIO3 has an external pullup on at least some boards). |
| 11 | + |
| 12 | +/ { |
| 13 | + compatible = "brcm,bcm2708"; |
| 14 | + |
| 15 | + fragment@0 { |
| 16 | + // Configure the gpio pin controller |
| 17 | + target = <&gpio>; |
| 18 | + __overlay__ { |
| 19 | + // Define a pinctrl state, that sets up the gpio |
| 20 | + // as an input with a pullup enabled. This does |
| 21 | + // not take effect by itself, only when referenced |
| 22 | + // by a "pinctrl client", as is done below. See: |
| 23 | + // https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt |
| 24 | + // https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt |
| 25 | + pin_state: shutdown_button_pins { |
| 26 | + brcm,pins = <3>; // gpio number |
| 27 | + brcm,function = <0>; // 0 = input, 1 = output |
| 28 | + brcm,pull = <2>; // 0 = none, 1 = pull down, 2 = pull up |
| 29 | + }; |
| 30 | + }; |
| 31 | + }; |
| 32 | + fragment@1 { |
| 33 | + // Add a new device to the /soc devicetree node |
| 34 | + target-path = "/soc"; |
| 35 | + __overlay__ { |
| 36 | + shutdown_button { |
| 37 | + // Let the gpio-keys driver handle this device. See: |
| 38 | + // https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt |
| 39 | + compatible = "gpio-keys"; |
| 40 | + |
| 41 | + // Declare a single pinctrl state (referencing the one declared above) and name it |
| 42 | + // default, so it is activated automatically. |
| 43 | + pinctrl-names = "default"; |
| 44 | + pinctrl-0 = <&pin_state>; |
| 45 | + |
| 46 | + // Enable this device |
| 47 | + status = "okay"; |
| 48 | + |
| 49 | + // Define a single key, called "shutdown" that monitors the gpio and sends KEY_POWER |
| 50 | + // (keycode 116, see |
| 51 | + // https://github.com/torvalds/linux/blob/v4.12/include/uapi/linux/input-event-codes.h#L190) |
| 52 | + button: shutdown { |
| 53 | + label = "shutdown"; |
| 54 | + linux,code = <116>; // KEY_POWER |
| 55 | + gpios = <&gpio 3 1>; |
| 56 | + }; |
| 57 | + }; |
| 58 | + }; |
| 59 | + }; |
| 60 | + |
| 61 | + // This defines parameters that can be specified when loading |
| 62 | + // the overlay. Each foo = line specifies one parameter, named |
| 63 | + // foo. The rest of the specification gives properties where the |
| 64 | + // parameter value is inserted into (changing the values above |
| 65 | + // or adding new ones). |
| 66 | + __overrides__ { |
| 67 | + // Allow overriding the GPIO number. |
| 68 | + gpio_pin = <&button>,"gpios:4", |
| 69 | + <&pin_state>,"brcm,pins:0"; |
| 70 | + |
| 71 | + // Allow changing the internal pullup/down state. 0 = none, 1 = pulldown, 2 = pullup |
| 72 | + // Note that GPIO3 and GPIO2 are the I2c pins and have an external pullup (at least |
| 73 | + // on some boards). |
| 74 | + gpio_pull = <&pin_state>,"brcm,pull:0"; |
| 75 | + |
| 76 | + // Allow setting the active_low flag. 0 = active high, 1 = active low |
| 77 | + active_low = <&button>,"gpios:8"; |
| 78 | + }; |
| 79 | + |
| 80 | +}; |
0 commit comments