Push buttons to the device tree

Linux Drivers

Release Date
2023-07-22
    gpio-keys {
        compatible = "gpio-keys";
        #address-cells = <1>;
        #size-cells = <0>;
        autorepeat;
        sw19 {
            label = "sw19";
            gpios = <&gpio 22 0>;
            linux,code = <108>; /* down */
            gpio-key,wakeup;
            autorepeat;
        };
        SW15 {
            label = "SW15";
            gpios = <&axi_gpio_1 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        SW14 {
            label = "SW14";
            gpios = <&axi_gpio_1 0x1 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        SW16 {
            label = "SW16";
            gpios = <&axi_gpio_1 0x2 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        SW17 {
            label = "SW17";
            gpios = <&axi_gpio_1 0x3 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        SW18 {
            label = "SW18";
            gpios = <&axi_gpio_1 0x4 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
    };
 
  • The Label refers to the descriptive name of the Push button.
  • The string <& axi_gpio_1 0x0 0x0> references the AXI GPIO 1 controller and states that SW15 is on pin 0, SW14 is on pin 1 and same for remaining Push buttons; the 0 states that the device is active high.
  • The linux,code property determines which key will show up in the event.
  • gpio-key,wakeup will enable the GPIO to wake the system from suspend.
  • The autorepeat property allows holding the key to continuously generate events.
Documentation/devicetree/bindings/input/gpio-keys.txt