Input Subsystem¶
Input core¶
- structinput_value¶
input value representation
Definition:
struct input_value { __u16 type; __u16 code; __s32 value;};Members
typetype of value (EV_KEY, EV_ABS, etc)
codethe value code
valuethe value
- structinput_dev¶
represents an input device
Definition:
struct input_dev { const char *name; const char *phys; const char *uniq; struct input_id id; unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)]; unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)]; unsigned long ledbit[BITS_TO_LONGS(LED_CNT)]; unsigned long sndbit[BITS_TO_LONGS(SND_CNT)]; unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; unsigned long swbit[BITS_TO_LONGS(SW_CNT)]; unsigned int hint_events_per_packet; unsigned int keycodemax; unsigned int keycodesize; void *keycode; int (*setkeycode)(struct input_dev *dev, const struct input_keymap_entry *ke, unsigned int *old_keycode); int (*getkeycode)(struct input_dev *dev, struct input_keymap_entry *ke); struct ff_device *ff; struct input_dev_poller *poller; unsigned int repeat_key; struct timer_list timer; int rep[REP_CNT]; struct input_mt *mt; struct input_absinfo *absinfo; unsigned long key[BITS_TO_LONGS(KEY_CNT)]; unsigned long led[BITS_TO_LONGS(LED_CNT)]; unsigned long snd[BITS_TO_LONGS(SND_CNT)]; unsigned long sw[BITS_TO_LONGS(SW_CNT)]; int (*open)(struct input_dev *dev); void (*close)(struct input_dev *dev); int (*flush)(struct input_dev *dev, struct file *file); int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); struct input_handle *grab; spinlock_t event_lock; struct mutex mutex; unsigned int users; bool going_away; struct device dev; struct list_head h_list; struct list_head node; unsigned int num_vals; unsigned int max_vals; struct input_value *vals; bool devres_managed; ktime_t timestamp[INPUT_CLK_MAX]; bool inhibited;};Members
namename of the device
physphysical path to the device in the system hierarchy
uniqunique identification code for the device (if device has it)
idid of the device (
structinput_id)propbitbitmap of device properties and quirks
evbitbitmap of types of events supported by the device (EV_KEY,EV_REL, etc.)
keybitbitmap of keys/buttons this device has
relbitbitmap of relative axes for the device
absbitbitmap of absolute axes for the device
mscbitbitmap of miscellaneous events supported by the device
ledbitbitmap of leds present on the device
sndbitbitmap of sound effects supported by the device
ffbitbitmap of force feedback effects supported by the device
swbitbitmap of switches present on the device
hint_events_per_packetaverage number of events generated by thedevice in a packet (between EV_SYN/SYN_REPORT events). Used byevent handlers to estimate size of the buffer needed to holdevents.
keycodemaxsize of keycode table
keycodesizesize of elements in keycode table
keycodemap of scancodes to keycodes for this device
setkeycodeoptional method to alter current keymap, used to implementsparse keymaps. If not supplied default mechanism will be used.The method is being called while holding event_lock and thus mustnot sleep
getkeycodeoptional legacy method to retrieve current keymap.
ffforce feedback structure associated with the device if devicesupports force feedback effects
pollerpoller structure associated with the device if device isset up to use polling mode
repeat_keystores key code of the last key pressed; used to implementsoftware autorepeat
timertimer for software autorepeat
repcurrent values for autorepeat parameters (delay, rate)
mtpointer to multitouch state
absinfoarray of
structinput_absinfoelements holding informationabout absolute axes (current value, min, max, flat, fuzz,resolution)keyreflects current state of device’s keys/buttons
ledreflects current state of device’s LEDs
sndreflects current state of sound effects
swreflects current state of device’s switches
openthis method is called when the very first user calls
input_open_device(). The driver must prepare the deviceto start generating events (start polling thread,request an IRQ, submit URB, etc.). The meaning of open() isto start providing events to the input core.closethis method is called when the very last user calls
input_close_device(). The meaning of close() is to stopproviding events to the input core.flushpurges the device. Most commonly used to get rid of forcefeedback effects loaded into the device when disconnectingfrom it
eventevent handler for events sent _to_ the device, like EV_LEDor EV_SND. The device is expected to carry out the requestedaction (turn on a LED, play sound, etc.) The call is protectedbyevent_lock and must not sleep
grabinput handle that currently has the device grabbed (viaEVIOCGRAB ioctl). When a handle grabs a device it becomes solerecipient for all input events coming from the device
event_lockthis spinlock is taken when input core receivesand processes a new event for the device (in
input_event()).Code that accesses and/or modifies parameters of a device(such as keymap or absmin, absmax, absfuzz, etc.) after devicehas been registered with input core must take this lock.mutexserializes calls to open(), close() and
flush()methodsusersstores number of users (input handlers) that opened thisdevice. It is used by
input_open_device()andinput_close_device()to make sure that dev->open() is only called when the firstuser opens device and dev->close() is called when the verylast user closes the devicegoing_awaymarks devices that are in a middle of unregistering andcauses input_open_device*() fail with -ENODEV.
devdriver model’s view of this device
h_listlist of input handles associated with the device. Whenaccessing the list dev->mutex must be held
nodeused to place the device onto input_dev_list
num_valsnumber of values queued in the current frame
max_valsmaximum number of values queued in a frame
valsarray of values queued in the current frame
devres_managedindicates that devices is managed with devres frameworkand needs not be explicitly unregistered or freed.
timestampstorage for a timestamp set by input_set_timestamp calledby a driver
inhibitedindicates that the input device is inhibited. If that isthe case then input core ignores any events generated by the device.Device’s close() is called when it is being inhibited and its open()is called when it is being uninhibited.
- structinput_handler¶
implements one of interfaces for input devices
Definition:
struct input_handler { void *private; void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); unsigned int (*events)(struct input_handle *handle, struct input_value *vals, unsigned int count); bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); bool (*match)(struct input_handler *handler, struct input_dev *dev); int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); void (*disconnect)(struct input_handle *handle); void (*start)(struct input_handle *handle); bool passive_observer; bool legacy_minors; int minor; const char *name; const struct input_device_id *id_table; struct list_head h_list; struct list_head node;};Members
privatedriver-specific data
eventevent handler. This method is being called by input core withinterrupts disabled and dev->event_lock spinlock held and soit may not sleep
eventsevent sequence handler. This method is being called byinput core with interrupts disabled and dev->event_lockspinlock held and so it may not sleep. The method must returnnumber of events passed to it.
filtersimilar toevent; separates normal event handlers from“filters”.
matchcalled after comparing device’s id with handler’s id_tableto perform fine-grained matching between device and handler
connectcalled when attaching a handler to an input device
disconnectdisconnects a handler from input device
startstarts handler for given handle. This function is called byinput core right after
connect()method and also when a processthat “grabbed” a device releases itpassive_observerset to
trueby drivers only interested in observingdata stream from devices if there are other users present. Suchdrivers will not result in starting underlying hardware devicewheninput_open_device()is called for their handleslegacy_minorsset to
trueby drivers using legacy minor rangesminorbeginning of range of 32 legacy minors for devices this drivercan provide
namename of the handler, to be shown in /proc/bus/input/handlers
id_tablepointer to a table of input_device_ids this driver canhandle
h_listlist of input handles associated with the handler
nodefor placing the driver onto input_handler_list
Description
Input handlers attach to input devices and create input handles. Thereare likely several handlers attached to any given input device at thesame time. All of them will get their copy of input event generated bythe device.
The very same structure is used to implement input filters. Input coreallows filters to run first and will not pass event to regular handlersif any of the filters indicate that the event should be filtered (byreturningtrue from theirfilter() method).
Note that input core serializes calls toconnect() anddisconnect()methods.
- structinput_handle¶
links input device with an input handler
Definition:
struct input_handle { void *private; int open; const char *name; struct input_dev *dev; struct input_handler *handler; unsigned int (*handle_events)(struct input_handle *handle, struct input_value *vals, unsigned int count); struct list_head d_node; struct list_head h_node;};Members
privatehandler-specific data
opencounter showing whether the handle is ‘open’, i.e. should deliverevents from its device
namename given to the handle by handler that created it
devinput device the handle is attached to
handlerhandler that works with the device through this handle
handle_eventsevent sequence handler. It is set up by the input coreaccording to event handling method specified in thehandler. See
input_handle_setup_event_handler().This method is being called by the input core with interrupts disabledand dev->event_lock spinlock held and so it may not sleep.d_nodeused to put the handle on device’s list of attached handles
h_nodeused to put the handle on handler’s list of handles from whichit gets events
- voidinput_set_events_per_packet(structinput_dev*dev,intn_events)¶
tell handlers about the driver event rate
Parameters
structinput_dev*devthe input device used by the driver
intn_eventsthe average number of events between calls to
input_sync()
Description
If the event rate sent from a device is unusually large, use thisfunction to set the expected event rate. This will allow handlersto set up an appropriate buffer size for the event stream, in orderto minimize information loss.
- structff_device¶
force-feedback part of an input device
Definition:
struct ff_device { int (*upload)(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old); int (*erase)(struct input_dev *dev, int effect_id); int (*playback)(struct input_dev *dev, int effect_id, int value); void (*set_gain)(struct input_dev *dev, u16 gain); void (*set_autocenter)(struct input_dev *dev, u16 magnitude); void (*destroy)(struct ff_device *); void *private; unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; struct mutex mutex; int max_effects; struct ff_effect *effects; struct file *effect_owners[] ;};Members
uploadCalled to upload an new effect into device
eraseCalled to erase an effect from device
playbackCalled to request device to start playing specified effect
set_gainCalled to set specified gain
set_autocenterCalled to auto-center device
destroycalled by input core when parent input device is beingdestroyed
privatedriver-specific data, will be freed automatically
ffbitbitmap of force feedback capabilities truly supported bydevice (not emulated like ones in input_dev->ffbit)
mutexmutex for serializing access to the device
max_effectsmaximum number of effects supported by device
effectspointer to an array of effects currently loaded into device
effect_ownersarray of effect owners; when file handle owningan effect gets closed the effect is automatically erased
Description
Every force-feedback device must implementupload() andplayback()methods;erase() is optional.set_gain() andset_autocenter() needonly be implemented if driver sets up FF_GAIN and FF_AUTOCENTERbits.
Note thatplayback(),set_gain() andset_autocenter() are called withdev->event_lock spinlock held and interrupts off and thus may notsleep.
- voidinput_event(structinput_dev*dev,unsignedinttype,unsignedintcode,intvalue)¶
report new input event
Parameters
structinput_dev*devdevice that generated the event
unsignedinttypetype of the event
unsignedintcodeevent code
intvaluevalue of the event
Description
This function should be used by drivers implementing various inputdevices to report input events. See alsoinput_inject_event().
NOTE
input_event() may be safely used right after input device wasallocated withinput_allocate_device(), even before it is registeredwithinput_register_device(), but the event will not reach any of theinput handlers. Such early invocation ofinput_event() may be usedto ‘seed’ initial state of a switch or initial position of absoluteaxis, etc.
- voidinput_inject_event(structinput_handle*handle,unsignedinttype,unsignedintcode,intvalue)¶
send input event from input handler
Parameters
structinput_handle*handleinput handle to send event through
unsignedinttypetype of the event
unsignedintcodeevent code
intvaluevalue of the event
Description
Similar toinput_event() but will ignore event if device is“grabbed” and handle injecting event is not the one that ownsthe device.
Parameters
structinput_dev*devthe input device emitting absolute events
Description
If the absinfostructthe caller asked for is already allocated, thisfunctions will not do anything.
- voidinput_copy_abs(structinput_dev*dst,unsignedintdst_axis,conststructinput_dev*src,unsignedintsrc_axis)¶
Copy absinfo from one input_dev to another
Parameters
structinput_dev*dstDestination input device to copy the abs settings to
unsignedintdst_axisABS_* value selecting the destination axis
conststructinput_dev*srcSource input device to copy the abs settings from
unsignedintsrc_axisABS_* value selecting the source axis
Description
Set absinfo for the selected destination axis by copying it fromthe specified source input device’s source axis.This is useful to e.g. setup a pen/stylus input-device for combinedtouchscreen/pen hardware where the pen uses the same coordinates asthe touchscreen.
- intinput_grab_device(structinput_handle*handle)¶
grabs device for exclusive use
Parameters
structinput_handle*handleinput handle that wants to own the device
Description
When a device is grabbed by an input handle all events generated bythe device are delivered only to this handle. Also events injectedby other input handles are ignored while device is grabbed.
- voidinput_release_device(structinput_handle*handle)¶
release previously grabbed device
Parameters
structinput_handle*handleinput handle that owns the device
Description
Releases previously grabbed device so that other input handles canstart receiving input events. Upon release all handlers attachedto the device have theirstart() method called so they have a changeto synchronize device state with the rest of the system.
- intinput_open_device(structinput_handle*handle)¶
open input device
Parameters
structinput_handle*handlehandle through which device is being accessed
Description
This function should be called by input handlers when theywant to start receive events from given input device.
- voidinput_close_device(structinput_handle*handle)¶
close input device
Parameters
structinput_handle*handlehandle through which device is being accessed
Description
This function should be called by input handlers when theywant to stop receive events from given input device.
- intinput_scancode_to_scalar(conststructinput_keymap_entry*ke,unsignedint*scancode)¶
converts scancode in
structinput_keymap_entry
Parameters
conststructinput_keymap_entry*kekeymap entry containing scancode to be converted.
unsignedint*scancodepointer to the location where converted scancode shouldbe stored.
Description
This function is used to convert scancode stored instructkeymap_entryinto scalar form understood by legacy keymap handling methods. Thesemethods expect scancodes to be represented as ‘unsigned int’.
- intinput_get_keycode(structinput_dev*dev,structinput_keymap_entry*ke)¶
retrieve keycode currently mapped to a given scancode
Parameters
structinput_dev*devinput device which keymap is being queried
structinput_keymap_entry*kekeymap entry
Description
This function should be called by anyone interested in retrieving currentkeymap. Presently evdev handlers use it.
- intinput_set_keycode(structinput_dev*dev,conststructinput_keymap_entry*ke)¶
attribute a keycode to a given scancode
Parameters
structinput_dev*devinput device which keymap is being updated
conststructinput_keymap_entry*kenew keymap entry
Description
This function should be called by anyone needing to update currentkeymap. Presently keyboard and evdev handlers use it.
Parameters
structinput_dev*devinput device whose state needs to be reset
Description
This function tries to reset the state of an opened input device andbring internal state and state if the hardware in sync with each other.We mark all keys as released, restore LED state, repeat rate, etc.
Parameters
voidno arguments
Description
Returns preparedstructinput_dev orNULL.
NOTE
Useinput_free_device() to free devices that have not beenregistered;input_unregister_device() should be used for alreadyregistered devices.
Parameters
structdevice*devdevice owning the input device being created
Description
Returns preparedstructinput_dev orNULL.
Managed input devices do not need to be explicitly unregistered orfreed as it will be done automatically when owner device unbinds fromits driver (or binding fails). Once managed input device is allocated,it is ready to be set up and registered in the same fashion as regularinput device. There are no special devm_input_device_[un]register()variants, regular ones work with both managed and unmanaged devices,should you need them. In most cases however, managed input device neednot be explicitly unregistered or freed.
NOTE
the owner device is set up as parent of input device and usersshould not override it.
Parameters
structinput_dev*devinput device to free
Description
This function should only be used ifinput_register_device()was not called yet or if it failed. Once device was registereduseinput_unregister_device() and memory will be freed once lastreference to the device is dropped.
Device should be allocated byinput_allocate_device().
NOTE
If there are references to the input device then memorywill not be freed until last reference is dropped.
Parameters
structinput_dev*devinput device to set timestamp for
ktime_ttimestampthe time at which the event has occurredin CLOCK_MONOTONIC
Description
This function is intended to provide to the input system a moreaccurate time of when an event actually occurred. The driver shouldcall this function as soon as a timestamp is acquired ensuringclock conversions in input_set_timestamp are done correctly.
The system entering suspend state between timestamp acquisition andcalling input_set_timestamp can result in inaccurate conversions.
Parameters
structinput_dev*devinput device to get timestamp from
Description
A valid timestamp is a timestamp of non-zero value.
- voidinput_set_capability(structinput_dev*dev,unsignedinttype,unsignedintcode)¶
mark device as capable of a certain event
Parameters
structinput_dev*devdevice that is capable of emitting or accepting event
unsignedinttypetype of the event (EV_KEY, EV_REL, etc...)
unsignedintcodeevent code
Description
In addition to setting up corresponding bit in appropriate capabilitybitmap the function also adjusts dev->evbit.
Parameters
structinput_dev*devinput device
intdelayrepeat delay
intperiodrepeat period
Description
Enable software autorepeat on the input device.
Parameters
structinput_dev*devdevice to be registered
Description
This function registers device with input core. The device must beallocated withinput_allocate_device() and all it’s capabilitiesset up before registering.If function fails the device must be freed withinput_free_device().Once device has been successfully registered it can be unregisteredwithinput_unregister_device();input_free_device() should not becalled in this case.
Note that this function is also used to register managed input devices(ones allocated withdevm_input_allocate_device()). Such managed inputdevices need not be explicitly unregistered or freed, their tear downis controlled by the devres infrastructure. It is also worth notingthat tear down of managed input devices is internally a 2-step process:registered managed input device is first unregistered, but stays inmemory and can still handleinput_event() calls (although events willnot be delivered anywhere). The freeing of managed input device willhappen later, when devres stack is unwound to the point where deviceallocation was made.
Parameters
structinput_dev*devdevice to be unregistered
Description
This function unregisters an input device. Once device is unregisteredthe caller should not try to access it as it may get freed at any moment.
- intinput_register_handler(structinput_handler*handler)¶
register a new input handler
Parameters
structinput_handler*handlerhandler to be registered
Description
This function registers a new input handler (interface) for inputdevices in the system and attaches it to all input devices thatare compatible with the handler.
- voidinput_unregister_handler(structinput_handler*handler)¶
unregisters an input handler
Parameters
structinput_handler*handlerhandler to be unregistered
Description
This function disconnects a handler from its input devices andremoves it from lists of known handlers.
- intinput_handler_for_each_handle(structinput_handler*handler,void*data,int(*fn)(structinput_handle*,void*))¶
handle iterator
Parameters
structinput_handler*handlerinput handler to iterate
void*datadata for the callback
int(*fn)(structinput_handle*,void*)function to be called for each handle
Description
Iterate overbus’s list of devices, and callfn for each, passingitdata and stop whenfn returns a non-zero value. The function isusing RCU to traverse the list and therefore may be using in atomiccontexts. Thefn callback is invoked from RCU critical section andthus must not sleep.
- intinput_register_handle(structinput_handle*handle)¶
register a new input handle
Parameters
structinput_handle*handlehandle to register
Description
This function puts a new input handle onto device’sand handler’s lists so that events can flow throughit once it is opened usinginput_open_device().
This function is supposed to be called from handler’sconnect() method.
- voidinput_unregister_handle(structinput_handle*handle)¶
unregister an input handle
Parameters
structinput_handle*handlehandle to unregister
Description
This function removes input handle from device’sand handler’s lists.
This function is supposed to be called from handler’sdisconnect() method.
- intinput_get_new_minor(intlegacy_base,unsignedintlegacy_num,boolallow_dynamic)¶
allocates a new input minor number
Parameters
intlegacy_basebeginning or the legacy range to be searched
unsignedintlegacy_numsize of legacy range
boolallow_dynamicwhether we can also take ID from the dynamic range
Description
This function allocates a new device minor for from input major namespace.Caller can request legacy minor by specifyinglegacy_base andlegacy_numparameters and whether ID can be allocated from dynamic range if there areno free IDs in legacy range.
- voidinput_free_minor(unsignedintminor)¶
release previously allocated minor
Parameters
unsignedintminorminor to be released
Description
This function releases previously allocated input minor so that it can bereused later.
- intinput_ff_upload(structinput_dev*dev,structff_effect*effect,structfile*file)¶
upload effect into force-feedback device
Parameters
structinput_dev*devinput device
structff_effect*effecteffect to be uploaded
structfile*fileowner of the effect
- intinput_ff_erase(structinput_dev*dev,inteffect_id,structfile*file)¶
erase a force-feedback effect from device
Parameters
structinput_dev*devinput device to erase effect from
inteffect_idid of the effect to be erased
structfile*filepurported owner of the request
Description
This function erases a force-feedback effect from specified device.The effect will only be erased if it was uploaded through the samefile handle that is requesting erase.
- intinput_ff_event(structinput_dev*dev,unsignedinttype,unsignedintcode,intvalue)¶
generic handler for force-feedback events
Parameters
structinput_dev*devinput device to send the effect to
unsignedinttypeevent type (anything but EV_FF is ignored)
unsignedintcodeevent code
intvalueevent value
Parameters
structinput_dev*devinput device supporting force-feedback
unsignedintmax_effectsmaximum number of effects supported by the device
Description
This function allocates all necessary memory for a force feedbackportion of an input device and installs all default handlers.dev->ffbit should be already set up before calling this function.Once ff device is created you need to setup its upload, erase,playback and other handlers before registering input device
Parameters
structinput_dev*devinput device supporting force feedback
Description
This function is only needed in error path as input core willautomatically free force feedback structures when device isdestroyed.
- intinput_ff_create_memless(structinput_dev*dev,void*data,int(*play_effect)(structinput_dev*,void*,structff_effect*))¶
create memoryless force-feedback device
Parameters
structinput_dev*devinput device supporting force-feedback
void*datadriver-specific data to be passed intoplay_effect
int(*play_effect)(structinput_dev*,void*,structff_effect*)driver-specific method for playing FF effect
Multitouch Library¶
- structinput_mt_slot¶
represents the state of an input MT slot
Definition:
struct input_mt_slot { int abs[ABS_MT_LAST - ABS_MT_FIRST + 1]; unsigned int frame; unsigned int key;};Members
absholds current values of ABS_MT axes for this slot
framelast frame at which
input_mt_report_slot_state()was calledkeyoptional driver designation of this slot
- structinput_mt¶
state of tracked contacts
Definition:
struct input_mt { int trkid; int num_slots; int slot; unsigned int flags; unsigned int frame; int *red; struct input_mt_slot slots[] ;};Members
trkidstores MT tracking ID for the next contact
num_slotsnumber of MT slots the device uses
slotMT slot currently being transmitted
flagsinput_mt operation flags
frameincreases every time
input_mt_sync_frame()is calledredreduced cost matrix for in-kernel tracking
slotsarray of slots holding current values of tracked contacts
- structinput_mt_pos¶
contact position
Definition:
struct input_mt_pos { s16 x, y;};Members
xhorizontal coordinate
yvertical coordinate
- intinput_mt_init_slots(structinput_dev*dev,unsignedintnum_slots,unsignedintflags)¶
initialize MT input slots
Parameters
structinput_dev*devinput device supporting MT events and finger tracking
unsignedintnum_slotsnumber of slots used by the device
unsignedintflagsmt tasks to handle in core
Description
This function allocates all necessary memory for MT slot handlingin the input device, prepares the ABS_MT_SLOT andABS_MT_TRACKING_ID events for use and sets up appropriate buffers.Depending on the flags set, it also performs pointer emulation andframe synchronization.
May be called repeatedly. Returns -EINVAL if attempting toreinitialize with a different number of slots.
Parameters
structinput_dev*devinput device with allocated MT slots
Description
This function is only needed in error path as the input core willautomatically free the MT slots when the device is destroyed.
- boolinput_mt_report_slot_state(structinput_dev*dev,unsignedinttool_type,boolactive)¶
report contact state
Parameters
structinput_dev*devinput device with allocated MT slots
unsignedinttool_typethe tool type to use in this slot
boolactivetrue if contact is active, false otherwise
Description
Reports a contact via ABS_MT_TRACKING_ID, and optionallyABS_MT_TOOL_TYPE. If active is true and the slot is currentlyinactive, or if the tool type is changed, a new tracking id isassigned to the slot. The tool type is only reported if thecorresponding absbit field is set.
Returns true if contact is active.
Parameters
structinput_dev*devinput device with allocated MT slots
intcountthe number of contacts
Description
Reports the contact count via BTN_TOOL_FINGER, BTN_TOOL_DOUBLETAP,BTN_TOOL_TRIPLETAP and BTN_TOOL_QUADTAP.
The input core ensures only the KEY events already setup forthis device will produce output.
Parameters
structinput_dev*devinput device with allocated MT slots
booluse_countreport number of active contacts as finger count
Description
Performs legacy pointer emulation via BTN_TOUCH, ABS_X, ABS_Y andABS_PRESSURE. Touchpad finger count is emulated if use_count is true.
The input core ensures only the KEY and ABS axes already setup forthis device will produce output.
Parameters
structinput_dev*devinput device with allocated MT slots
Description
Lift all slots not seen since the last call to this function.
Parameters
structinput_dev*devinput device with allocated MT slots
Description
Close the frame and prepare the internal state for a new one.Depending on the flags, marks unused slots as inactive and performspointer emulation.
- intinput_mt_assign_slots(structinput_dev*dev,int*slots,conststructinput_mt_pos*pos,intnum_pos,intdmax)¶
perform a best-match assignment
Parameters
structinput_dev*devinput device with allocated MT slots
int*slotsthe slot assignment to be filled
conststructinput_mt_pos*posthe position array to match
intnum_posnumber of positions
intdmaxmaximum ABS_MT_POSITION displacement (zero for infinite)
Description
Performs a best match against the current contacts and returnsthe slot assignment list. New contacts are assigned to unusedslots.
The assignments are balanced so that all coordinate displacements arebelow the euclidian distance dmax. If no such assignment can be found,some contacts are assigned to unused slots.
Returns zero on success, or negative error in case of failure.
Parameters
structinput_dev*devinput device with allocated MT slots
intkeythe key of the sought slot
Description
Returns the slot of the given key, if it exists, otherwiseset the key on the first unused slot and return.
If no available slot can be found, -1 is returned.Note that for this function to work properly,input_mt_sync_frame() hasto be called at each frame.
Matrix keyboards/keypads¶
- structmatrix_keymap_data¶
keymap for matrix keyboards
Definition:
struct matrix_keymap_data { const uint32_t *keymap; unsigned int keymap_size;};Members
keymappointer to array of uint32 values encoded with
KEY()macrorepresenting keymapkeymap_sizenumber of entries (initialized) in this keymap
Description
This structure is supposed to be used by platform code to supplykeymaps to drivers that implement matrix-like keypads/keyboards.
Sparse keymap support¶
- structkey_entry¶
keymap entry for use in sparse keymap
Definition:
struct key_entry { int type; u32 code; union { u16 keycode; struct { u8 code; u8 value; } sw; };};Members
typeType of the key entry (KE_KEY, KE_SW, KE_VSW, KE_END);drivers are allowed to extend the list with their ownprivate definitions.
codeDevice-specific data identifying the button/switch
{unnamed_union}anonymous
keycodeKEY_* code assigned to a key/button
swstructwithcode/value used by KE_SW and KE_VSWsw.codeSW_* code assigned to a switch
sw.valueValue that should be sent in an input even when KE_SWswitch is toggled. KE_VSW switches ignore this field andexpect driver to supply value for the event.
Description
This structure defines an entry in a sparse keymap used by someinput devices for which traditional table-based approach is notsuitable.
- structkey_entry*sparse_keymap_entry_from_scancode(structinput_dev*dev,unsignedintcode)¶
perform sparse keymap lookup
Parameters
structinput_dev*devInput device using sparse keymap
unsignedintcodeScan code
Description
This function is used to performstructkey_entry lookup in aninput device using sparse keymap.
- structkey_entry*sparse_keymap_entry_from_keycode(structinput_dev*dev,unsignedintkeycode)¶
perform sparse keymap lookup
Parameters
structinput_dev*devInput device using sparse keymap
unsignedintkeycodeKey code
Description
This function is used to performstructkey_entry lookup in aninput device using sparse keymap.
- intsparse_keymap_setup(structinput_dev*dev,conststructkey_entry*keymap,int(*setup)(structinput_dev*,structkey_entry*))¶
set up sparse keymap for an input device
Parameters
structinput_dev*devInput device
conststructkey_entry*keymapKeymap in form of array of
key_entrystructures endingwithKE_ENDtype entryint(*setup)(structinput_dev*,structkey_entry*)Function that can be used to adjust keymap entriesdepending on device’s needs, may be
NULL
Description
The function calculates size and allocates copy of the originalkeymap after which sets up input device event bits appropriately.The allocated copy of the keymap is automatically freed when itis no longer needed.
- voidsparse_keymap_report_entry(structinput_dev*dev,conststructkey_entry*ke,unsignedintvalue,boolautorelease)¶
report event corresponding to given key entry
Parameters
structinput_dev*devInput device for which event should be reported
conststructkey_entry*kekey entry describing event
unsignedintvalueValue that should be reported (ignored by
KE_SWentries)boolautoreleaseSignals whether release event should be emitted for
KE_KEYentries right after reporting press event, ignored by all otherentries
Description
This function is used to report input event described by givenstructkey_entry.
- boolsparse_keymap_report_event(structinput_dev*dev,unsignedintcode,unsignedintvalue,boolautorelease)¶
report event corresponding to given scancode
Parameters
structinput_dev*devInput device using sparse keymap
unsignedintcodeScan code
unsignedintvalueValue that should be reported (ignored by
KE_SWentries)boolautoreleaseSignals whether release event should be emitted for
KE_KEYentries right after reporting press event, ignored by all otherentries
Description
This function is used to perform lookup in an input device using sparsekeymap and report corresponding event. Returnstrue if lookup wassuccessful andfalse otherwise.
PS/2 protocol support¶
- enumps2_disposition¶
indicates how received byte should be handled
Constants
PS2_PROCESSpass to the main protocol handler, process normally
PS2_IGNOREskip the byte
PS2_ERRORdo not process the byte, abort command in progress
- structps2dev¶
represents a device using PS/2 protocol
Definition:
struct ps2dev { struct serio *serio; struct mutex cmd_mutex; wait_queue_head_t wait; unsigned long flags; u8 cmdbuf[8]; u8 cmdcnt; u8 nak; ps2_pre_receive_handler_t pre_receive_handler; ps2_receive_handler_t receive_handler;};Members
serioa serio port used by the PS/2 device
cmd_mutexa mutex ensuring that only one command is executing at a time
waita waitqueue used to signal completion from the serio interrupt handler
flagsvarious internal flags indicating stages of PS/2 command execution
cmdbufbuffer holding command response
cmdcntoutstanding number of bytes of the command response
naka byte transmitted by the device when it refuses command
pre_receive_handlerchecks communication errors and returns disposition(
enumps2_disposition) of the received data bytereceive_handlermain handler of particular PS/2 protocol, such as keyboardor mouse protocol
- intps2_sendbyte(structps2dev*ps2dev,u8byte,unsignedinttimeout)¶
sends a byte to the device and wait for acknowledgement
Parameters
structps2dev*ps2deva PS/2 device to send the data to
u8bytedata to be sent to the device
unsignedinttimeouttimeout for sending the data and receiving an acknowledge
Description
The function doesn’t handle retransmission, the caller is expected to handleit when needed.
ps2_sendbyte() can only be called from a process context.
Parameters
structps2dev*ps2deva PS/2 device executing the command
Description
Serializes a complex/compound command. Once command is finishedps2_end_command() should be called.
Parameters
structps2dev*ps2deva PS/2 device executing the command
- voidps2_drain(structps2dev*ps2dev,size_tmaxbytes,unsignedinttimeout)¶
waits for device to transmit requested number of bytes and discards them
Parameters
structps2dev*ps2devthe PS/2 device that should be drained
size_tmaxbytesmaximum number of bytes to be drained
unsignedinttimeouttime to drain the device
- boolps2_is_keyboard_id(u8id_byte)¶
checks received ID byte against the list of known keyboard IDs
Parameters
u8id_bytedata byte that should be checked
Parameters
structps2dev*ps2devthe PS/2 device that should execute the command
u8*parama buffer containing parameters to be sent along with the command,or place where the results of the command execution will be deposited,or both
unsignedintcommandcommand word that encodes the command itself, as well as number ofadditional parameter bytes that should be sent to the device and expectedlength of the command response
Description
Not serialized. Callers should useps2_begin_command() andps2_end_command()to ensure proper serialization for complex commands.
Parameters
structps2dev*ps2devthe PS/2 device that should execute the command
u8*parama buffer containing parameters to be sent along with the command,or place where the results of the command execution will be deposited,or both
unsignedintcommandcommand word that encodes the command itself, as well as number ofadditional parameter bytes that should be sent to the device and expectedlength of the command response
Note
ps2_command() serializes the command execution so that only onecommand can be executed at a time for either individual port or the entire8042 controller.
Parameters
structps2dev*ps2devthe PS/2 device that should execute the command
u8commandcommand byte
Description
The command is sent using “sliced” syntax understood by advanced devices,such as Logitech or Synaptics touchpads. The command is encoded as:0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uuis the command.
- voidps2_init(structps2dev*ps2dev,structserio*serio,ps2_pre_receive_handler_tpre_receive_handler,ps2_receive_handler_treceive_handler)¶
initializes ps2dev structure
Parameters
structps2dev*ps2devstructure to be initialized
structserio*serioserio port associated with the PS/2 device
ps2_pre_receive_handler_tpre_receive_handlervalidation handler to check basic communication state
ps2_receive_handler_treceive_handlermain protocol handler
Description
Prepares ps2dev structure for use in drivers for PS/2 devices.
- irqreturn_tps2_interrupt(structserio*serio,u8data,unsignedintflags)¶
common interrupt handler for PS/2 devices
Parameters
structserio*serioserio port for the device
u8dataa data byte received from the device
unsignedintflagsflags such as
SERIO_PARITYorSERIO_TIMEOUTindicating state ofthe data transfer
Description
ps2_interrupt() invokes pre-receive handler, optionally handles commandacknowledgement and response from the device, and finally passes the datato the main protocol handler for future processing.