GPIO matrix keypad

Viewing 6 reply threads
  • Author
    Posts
    • #11421
      coloradocarlos
      Participant

        I have a GPIO matrix keypad that I would like to get working with the RED board.

        The basic instructions are here: https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-matrix-keypad.txt

        I have compiled a custom DTB and can successfully apply it to the base DT in U-Boot (fdt apply). I also know the keypad works using a Python script that drives the cols and reads the rows. The hardware uses pull down resistors so the inputs default to 0 and a keypress is 1.

        The keypad shows up in /proc/device-tree, but it does not show up anywhere else (lsinput, dmesg). I don’t have any error messages and realize that silent failures are the hardest to troubleshoot. What do I need to do to debug and get a GPIO matrix keypad working using the kernel input driver?

        Here is the hand made DTS for a 2×2 matrix:

        /dts-v1/;

        / {
        fragment@0 {
        target-path = “/”;

        __overlay__ {

        keypad: MYMATRIX {
        compatible = “gpio-matrix-keypad”;
        debounce-delay-ms = <0x05>;
        col-scan-delay-us = <0x02>;
        wakeup-source = <0x01>;
        drive-inactive-cols = <0x01>;
        row-gpios = <0x45 0x0b 0x00 0x1a 0x08 0x00>;
        col-gpios = <0x45 0x05 0x00 0x45 0x06 0x00>;
        linux,keymap = <0x30 0x1000031 0x10032 0x1010033>;
        };
        };
        };
        };

        Thank you, Carlos

      • #11429
        Neeraj Dantu
        Moderator

          Carlos,

          – It would be cleaner to edit the device tree you are booting instead of applying an overlay

          – Please make sure that you have proper pinmux defined in pinctrl node

          – Make sure you have kernel config that enables the matrix keypad(CONFIG_KEYPAD_MATRIX)

          Best,

          Neeraj

          • #11431
            coloradocarlos
            Participant

              Neeraj,

              Thanks, I will give this try.

              This is the config from /proc/config.gz:

              CONFIG_INPUT_MATRIXKMAP=y

              No CONFIG_KEYPAD_MATRIX config setting. Do I need to rebuild the kernel or is there a boot parameter that will do the trick with the stock Octavo kernel?

              Also, grep -i matrix /lib/modules/4.19.94/modules.builtin:

              kernel/drivers/input/matrix-keymap.ko

              Thank you, Carlos

          • #11433
            Neeraj Dantu
            Moderator

              Carlos,

              Looks like your device tree might be a little out of date. Please take a look at device tree bindings corresponding to CONFIG_INPUT_MATRIXKMAP here: https://www.kernel.org/doc/Documentation/devicetree/bindings/input/matrix-keymap.yaml. CONFIG_KEYMAP_MATRIX is from an older version of the kernel.

              If CONFIG_INPUT_MATRIXKMAP option if a ‘y’, you should not have to recompile the kernel. Here is the driver that is compiled: https://github.com/STMicroelectronics/linux/blob/v5.10-stm32mp/drivers/input/matrix-keymap.c.

              Best,

              Neeraj

            • #11434
              coloradocarlos
              Participant

                I am a little confused as to matrix keypads. Is a “GPIO matrix keypad” the same as a regular “matrix keypad”? It was my understanding they are different types of hardware.

                What I have is a GPIO driven keypad where the cols are outputs and rows are inputs.

                Thx, Carlos

              • #11440
                Neeraj Dantu
                Moderator

                  Carlos,

                  You are right. matrix-keymap is used to define function keys rather than setup a GPIO matrix keypad. CONFIG_INPUT_MATRIXKMAP should also be set to use the function mapping tool for the matrix keymap.

                  Coming to your implementation, please try and simplify your declaration:

                  – Get rid of all unnecessary configuration like drive-inactive-cols and wakeup-source. You can add them later after you get the base device tree working for the keymap.

                  – Make use of proper node referencing as shown in https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/input/gpio-matrix-keypad.txt. I am unsure whether your hex codes reference the correct GPIO nodes in the device tree.

                  – A good example I found: https://blog.gegg.us/2017/08/a-matrix-keypad-on-a-raspberry-pi-done-right/ but note the difference in GPIO node notation for MP1(example: https://github.com/STMicroelectronics/linux/blob/v5.10-stm32mp/arch/arm/boot/dts/stm32mp157c-dk2.dts#L92).

                  Best,

                  Neeraj

                   

                • #11451
                  Carel BoschCarel
                  Participant

                    Hi,

                    Ive come across a similar issue.

                    Excerpt form my device tree to describe the keypad:

                    Full dts file attached to this post.

                    My issue come is when the driver loads, I get the following errors:
                    [ 8.856437] stm32mp157-pinctrl soc:pin-controller@50002000: pin PA4 already requested by keypad; cannot claim for GPIOA:4
                    [ 8.890675] stm32mp157-pinctrl soc:pin-controller@50002000: pin-4 (GPIOA:4) status -22
                    [ 8.897324] matrix-keypad keypad: failed to request GPIO4 for COL0
                    [ 8.929520] matrix-keypad keypad: failed to init gpio
                    [ 8.958196] matrix-keypad: probe of keypad failed with error -22

                    The error is always on the first gpio in the columns section.

                    Any ideas?

                    Regards,

                    Carel

                    • #11452
                      Carel BoschCarel
                      Participant

                        My file upload failed (Sorry, this file type is not permitted for security reasons.).

                        Uploading entire device tree file.

                         

                    • #11454
                      coloradocarlos
                      Participant

                        PGA4 is used by the digital camera interface. I suggest using a different pin.

                        Also I solved my problem with loading the device driver by recompiling the kernel with the CONFIG_KEYBOARD_MATRIX=y option. The stock kernel from Octavo does not work with GPIO matrix keypads. Docs: https://www.kernelconfig.io/config_keyboard_matrix

                    Viewing 6 reply threads
                    • You must be logged in to reply to this topic.