Putting it all together
So far, we have described the structures used when writing drivers for input devices, and how they can be managed from the user space:
- Allocate a new input device, according to its type (polled, or not), using
input_allocate_polled_device()
orinput_allocate_device()
. - Fill in the mandatory fields (if necessary):
- Specify the type of event the device supports by using the
set_bit()
helper macro on theinput_dev.evbit
field. - Depending on the event type,
EV_REL
,EV_ABS
,EV_KEY
, or other, indicate the code this device can report, using eitherinput_dev.relbit
,input_dev.absbit
,input_dev.keybit
, or other. - Specify
input_dev.dev
, in order to set up a proper device tree. - Fill
abs_info
if necessary. - For polled devices, indicate at which interval the
poll()
function should be called.
- Specify the type of event the device supports by using the
- Write the
open()
function, if necessary, in which you should prepare and set up the resources used by the device. This function is called only once. In this function, set up GPIO, request an interrupt...