Unable to activate rotary encoder on gpio

The following describes my machine:-

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.1.83-rt28-6.6.0-devel+git.c88639fef1f2 #1-TorizonCore SMP PREEMPT_RT Wed Mar 13 13:37:44 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/2a5e5ad555e578e44432c68ebf84bd510fbadf3f3ec9ed6da1b967e2bfcdb7dd/0
Distro name:              NAME="TorizonCore Upstream with PREEMPT_RT"
Distro version:           VERSION_ID=6.6.0-devel-20240918102059-build.0
Distro variant:           VARIANT="Minimal"
Hostname:                 colibri-imx7-emmc-15048509
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Colibri iMX7D 1GB (eMMC) on Colibri Evaluation Board V3
Toradex version:          0039 V1.1B
Serial number:            15048509
Processor arch:           armv7l
------------------------------------------------------------

I want to connect a rotary encoder to SODIMM_100 and SODIMM_102 of Colibri module.
I enabled the linux driver for rotary encoder:-

$ zcat /proc/config.gz | grep ROTARY
CONFIG_INPUT_GPIO_ROTARY_ENCODER=y

I created a device tree
colibri-imx7_rotary_encoder_overlay.dts (497 Bytes)

I applied the overlay which can be seen:-

$ cat /proc/device-tree/chosen/overlays/colibri-imx7_rotary_encoder_overlay.dtbo 
0

However, the device driver doesn’t load:-

$ lsmod
Module                  Size  Used by
cfg80211              851968  0
imx_sdma               24576  2
atmel_mxt_ts           32768  0
mcp251x                24576  0
snd_soc_sgtl5000       28672  1
snd_soc_fsl_sai        24576  2
flexcan                28672  0
can_dev                40960  2 flexcan,mcp251x
imx7d_adc              16384  0
industrialio           90112  1 imx7d_adc
uio_pdrv_genirq        16384  0
uio                    24576  1 uio_pdrv_genirq
libcomposite           61440  0
fuse                  122880  1

and I see no ‘rotary-encoder’ device in /dev also.
Please help.

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Based on the information provided, it seems like you’ve taken the correct steps to enable the rotary encoder driver and apply the device tree overlay. However, the driver is not being loaded, and the device is not appearing in /dev. Here are a few steps to troubleshoot and resolve the issue:

  1. Verify Device Tree Overlay:
    Ensure that your device tree overlay is correctly written and applied. Here is an example of what a typical rotary encoder device tree overlay might look like:

    /dts-v1/;
    /plugin/;
    
    / {
        compatible = "toradex,colibri-imx7-emmc";
    };
    
    &ecspi1 {
        status = "okay";
    };
    
    &gpio1 {
        rotary_encoder {
            compatible = "rotary-encoder";
            gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>, <&gpio1 3 GPIO_ACTIVE_HIGH>;
            linux,axis = <0>;
        };
    };
    

    Make sure the GPIO pins (SODIMM_100 and SODIMM_102) are correctly mapped in the device tree.

  2. Check Kernel Logs:
    Check the kernel logs for any errors or messages related to the rotary encoder driver. You can use the dmesg command to view the kernel logs:

    dmesg | grep rotary
    

    This might give you some clues if there are any issues with loading the driver.

  3. Verify GPIO Configuration:
    Ensure that the GPIO pins you are using for the rotary encoder are not being used by any other peripheral or function. You can check the pin configuration using the pinmux settings in the device tree.

  4. Manually Load the Driver:
    Try manually loading the rotary encoder driver using the modprobe command:

    modprobe rotary_encoder
    

    After running this command, check if the driver is loaded using lsmod and if the device appears in /dev.

  5. Check for Missing Dependencies:
    Ensure that all necessary dependencies for the rotary encoder driver are included in your kernel configuration. Sometimes, additional modules or configurations might be required.

  6. Rebuild and Reapply the Overlay:
    If you made any changes to the device tree overlay, make sure to recompile and reapply it:

    dtc -I dts -O dtb -o colibri-imx7_rotary_encoder_overlay.dtbo colibri-imx7_rotary_encoder_overlay.dts
    cp colibri-imx7_rotary_encoder_overlay.dtbo /boot/overlays/
    

    Then reboot the system to apply the changes.

If you have followed all these steps and the issue persists, there might be a deeper issue with the driver or the device tree configuration. In such cases, it might be helpful to consult the Toradex community or support for further assistance.

Please, also check if these links can help you solve your problem:

Rotary encoder for imx7?.

I changed the device tree overlay to this
colibri-imx7_rotary_encoder_overlay.dts (3.1 KB)
by looking at how “gpio-keys” are configured in the device tree.

The device driver stil doesn’t load and I don’t get anything here:-

$ dmesg | grep rotary

@rudhi.tx can you provide any help here?

@ritesh.tx @sahil.tx please help on this. Iam stuck.

Hi @rajdeepteck123 ,

Please provide output for
a. zcat /proc/config.gz | grep ROTARY
b. dmesg | grep rotary
c. evtest

Hi, thanks for the reply.

dmesg doesn’t have an entry on rotary, I’ll share evtest in sometime

$ dmesg | grep rotary

$ zcat /proc/config.gz | grep ROTARY
CONFIG_INPUT_GPIO_ROTARY_ENCODER=y

root@colibri-imx7-emmc-15048509:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: gpio-keys
Select the device event number [0-0]:

ok finally I solved this myself.

Earlier, I had implemented rotary encoder as a device tree overlay, which didn’t work.

Now, I made changes directly to the device tree and it worked.