Add GPIO-Keys to the Device Tree

Linux Drivers

Release Date
2023-07-22

Under the AXI interconnect, create a node named “gpio-keys”, like in the example below:

gpio-keys {
    compatible = "gpio-keys";
    #address-cells = <1>;
    #size-cells = <0>;
    autorepeat;
    sw14 {
        label = "sw14";
        gpios = <&ps7_gpio_0 12 0>;
        linux,code = <108>; /* down */
        gpio-key,wakeup;
        autorepeat;
    };
    sw13 {
        label = "sw13";
        gpios = <&ps7_gpio_0 14 0>;
        linux,code = <103>; /* up */
        gpio-key,wakeup;
        autorepeat;
    };
};

  • The string <&ps7_gpio_0 12 0> references the GPIO controller and states that sw14 device is on pin 12, while sw13 is on pin 14; the 0 states that the device is active high.
  • The linux,code property determines which key will show up in the event.
  • The autorepeat property allows holding the key to continuously generate events.
  • Using gpio-key,wakeup will enable the GPIO to wake the system from suspend.

Full documentation can be found here Documentation/devicetree/bindings/input/gpio-keys.txt .