Kernel Configuration for dip switches and push buttons

Linux Drivers

Release Date
2023-07-22
Build Kernel
  • Device Drivers
    • GPIO Support
      • Memory Mapped GPIO Drivers
        • Xilinx GPIO support
        • Xilinx Zynq GPIO support
    • Input device support
      • Keyboards
        • GPIO Buttons
        • Polled GPIO buttons
CONFIG_KEYBOARD_GPIO=y
CONFIG_KEYBOARD_GPIO_POLLED=y
 
Dip Switches to the device tree
    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;
        };
        GPIO_DIP_SW0 {
            label = "GPIO_DIP_SW0";
            gpios = <&axi_gpio_0 0x0 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW1 {
            label = "GPIO_DIP_SW1";
            gpios = <&axi_gpio_0 0x1 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW2 {
            label = "GPIO_DIP_SW2";
            gpios = <&axi_gpio_0 0x2 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW3 {
            label = "GPIO_DIP_SW3";
            gpios = <&axi_gpio_0 0x3 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW4 {
            label = "GPIO_DIP_SW4";
            gpios = <&axi_gpio_0 0x4 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW5 {
            label = "GPIO_DIP_SW5";
            gpios = <&axi_gpio_0 0x5 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW6 {
            label = "GPIO_DIP_SW6";
            gpios = <&axi_gpio_0 0x6 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
        GPIO_DIP_SW7 {
            label = "GPIO_DIP_SW7";
            gpios = <&axi_gpio_0 0x7 0x0 0x0>;
            linux,code = <108>;
            gpio-key,wakeup;
            autorepeat;
        };
     };
 
  • The Label refers to the descriptive name of the dip switch.
  • The string <& axi_gpio_0 0x0 0x0 0x0> references the AXI GPIO 0 controller and states that GPIO_DIP_SW0 is on pin 0, GPIO_DIP_SW1 is on pin 1 and same for remaining dip switches;  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