Skip to content
Advertisement

Linux input driver not working properly

I have written a small linux input driver which reads the state of a gpio. The driver registers OK and also the interrupt gets fired, however the events are not always displayed. Driver runs on Beagleboneblack with Android and kernel version 3.8.13 To test it I do either:

cat /dev/input/event2

Or run an user space app that I wrote. The app is able to retrieve the events properly from other input devices. To mention that “event2” is the right event in /dev/input, checked already.

The driver code:

JavaScript

I stripped out some lines, to make it smaller. It matches against an entry in DTS where I defined the GPIO number. The OF_ related stuff is removed here.

The app code:

JavaScript

When doing cat /dev/input/event2 sometimes I get some characters, most of the times I don’t. This matches with the output of my app when reading the input device:

JavaScript

I placed a dev_info in my irq routine to see whenever the input_report_key is called. Sometimes I get more events sometimes more IRQs, and sometimes I get only IRQs messages.

So I’m not missing any IRQ, seems to be something with the key report event. I’m thinking maybe the IRQs are overlapping if they are fired close to each other when button is pressed and this can affect input flow..?

Will try to change the code to force reporting the key once each 10ms, just to see if it makes any difference. I have no other idea. Any help much appreciated.

Update: so, i changed the code to report 1 time each 10ms and 1 time per second, no difference, must be something else.

Any idea?

Thank you, Daniel

Advertisement

Answer

Seems I found the issue. When setting up the interrupt, it should be triggered on both edges, as the linux input system reports only the change of event value, therefore when the same edge triggers the IRQ, most of the time the event will be the same, which in my case was “low”. That means switch released, but with actual code the switch was never seen as pressed (unless the level on that gpio was not yet stable and could read high instead of low). Seems those were the only cases when I was getting an event reported.

With following changes the driver works as expected:

In btn_probe replace:

JavaScript

with

JavaScript

And the IRQ rewritten to avoid multiple IRQs within short period of time:

JavaScript

With:

#define SCAN_DELTA∙ msecs_to_jiffies(100)∙ //msecs

And new_time and scan_disc new entries in btn_drv struct.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement