Input Subsystem¶
Input core¶
-
struct input_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
-
struct input_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 __rcu *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 (struct input_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 the device in a packet (between EV_SYN/SYN_REPORT events). Used by event handlers to estimate size of the buffer needed to hold events.
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 implement sparse keymaps. If not supplied default mechanism will be used. The method is being called while holding event_lock and thus must not sleep
getkeycodeoptional legacy method to retrieve current keymap.
ffforce feedback structure associated with the device if device supports force feedback effects
pollerpoller structure associated with the device if device is set up to use polling mode
repeat_keystores key code of the last key pressed; used to implement software autorepeat
timertimer for software autorepeat
repcurrent values for autorepeat parameters (delay, rate)
mtpointer to multitouch state
absinfoarray of
struct input_absinfoelements holding information about 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 device to start generating events (start polling thread, request an IRQ, submit URB, etc.). The meaning of open() is to 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 stop providing events to the input core.flushpurges the device. Most commonly used to get rid of force feedback effects loaded into the device when disconnecting from it
eventevent handler for events sent _to_ the device, like EV_LED or EV_SND. The device is expected to carry out the requested action (turn on a LED, play sound, etc.) The call is protected by event_lock and must not sleep
grabinput handle that currently has the device grabbed (via EVIOCGRAB ioctl). When a handle grabs a device it becomes sole recipient for all input events coming from the device
event_lockthis spinlock is taken when input core receives and 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 device has been registered with input core must take this lock.mutexserializes calls to open(), close() and flush() methods
usersstores number of users (input handlers) that opened this device. It is used by
input_open_device()andinput_close_device()to make sure that dev->open() is only called when the first user opens device and dev->close() is called when the very last user closes the devicegoing_awaymarks devices that are in a middle of unregistering and causes input_open_device*() fail with -ENODEV.
devdriver model’s view of this device
h_listlist of input handles associated with the device. When accessing 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 framework and needs not be explicitly unregistered or freed.
timestampstorage for a timestamp set by input_set_timestamp called by a driver
inhibitedindicates that the input device is inhibited. If that is the 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.
-
struct input_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);
void (*events)(struct input_handle *handle, const 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 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 with interrupts disabled and dev->event_lock spinlock held and so it may not sleep
eventsevent sequence handler. This method is being called by input core with interrupts disabled and dev->event_lock spinlock held and so it may not sleep
filtersimilar to event; separates normal event handlers from “filters”.
matchcalled after comparing device’s id with handler’s id_table to 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 by input core right after connect() method and also when a process that “grabbed” a device releases it
legacy_minorsset to
trueby drivers using legacy minor rangesminorbeginning of range of 32 legacy minors for devices this driver can provide
namename of the handler, to be shown in /proc/bus/input/handlers
id_tablepointer to a table of input_device_ids this driver can handle
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. There are likely several handlers attached to any given input device at the same time. All of them will get their copy of input event generated by the device.
The very same structure is used to implement input filters. Input core
allows filters to run first and will not pass event to regular handlers
if any of the filters indicate that the event should be filtered (by
returning true from their filter() method).
Note that input core serializes calls to connect() and disconnect() methods.
-
struct input_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;
struct list_head d_node;
struct list_head h_node;
};
Members
privatehandler-specific data
opencounter showing whether the handle is ‘open’, i.e. should deliver events 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
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 which it gets events
-
void input_set_events_per_packet(struct input_dev *dev, int n_events)¶
tell handlers about the driver event rate
Parameters
struct input_dev *devthe input device used by the driver
int n_eventsthe average number of events between calls to input_sync()
Description
If the event rate sent from a device is unusually large, use this function to set the expected event rate. This will allow handlers to set up an appropriate buffer size for the event stream, in order to minimize information loss.
-
struct ff_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 being destroyed
privatedriver-specific data, will be freed automatically
ffbitbitmap of force feedback capabilities truly supported by device (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 owning an effect gets closed the effect is automatically erased
Description
Every force-feedback device must implement upload() and playback() methods; erase() is optional. set_gain() and set_autocenter() need only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER bits.
Note that playback(), set_gain() and set_autocenter() are called with dev->event_lock spinlock held and interrupts off and thus may not sleep.
-
void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)¶
report new input event
Parameters
struct input_dev *devdevice that generated the event
unsigned int typetype of the event
unsigned int codeevent code
int valuevalue of the event
Description
This function should be used by drivers implementing various input
devices to report input events. See also input_inject_event().
NOTE
input_event() may be safely used right after input device was
allocated with input_allocate_device(), even before it is registered
with input_register_device(), but the event will not reach any of the
input handlers. Such early invocation of input_event() may be used
to ‘seed’ initial state of a switch or initial position of absolute
axis, etc.
-
void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value)¶
send input event from input handler
Parameters
struct input_handle *handleinput handle to send event through
unsigned int typetype of the event
unsigned int codeevent code
int valuevalue of the event
Description
Similar to input_event() but will ignore event if device is
“grabbed” and handle injecting event is not the one that owns
the device.
Parameters
struct input_dev *devthe input device emitting absolute events
Description
If the absinfo struct the caller asked for is already allocated, this functions will not do anything.
-
void input_copy_abs(struct input_dev *dst, unsigned int dst_axis, const struct input_dev *src, unsigned int src_axis)¶
Copy absinfo from one input_dev to another
Parameters
struct input_dev *dstDestination input device to copy the abs settings to
unsigned int dst_axisABS_* value selecting the destination axis
const struct input_dev *srcSource input device to copy the abs settings from
unsigned int src_axisABS_* value selecting the source axis
Description
Set absinfo for the selected destination axis by copying it from the specified source input device’s source axis. This is useful to e.g. setup a pen/stylus input-device for combined touchscreen/pen hardware where the pen uses the same coordinates as the touchscreen.
-
int input_grab_device(struct input_handle *handle)¶
grabs device for exclusive use
Parameters
struct input_handle *handleinput handle that wants to own the device
Description
When a device is grabbed by an input handle all events generated by the device are delivered only to this handle. Also events injected by other input handles are ignored while device is grabbed.
-
void input_release_device(struct input_handle *handle)¶
release previously grabbed device
Parameters
struct input_handle *handleinput handle that owns the device
Description
Releases previously grabbed device so that other input handles can
start receiving input events. Upon release all handlers attached
to the device have their start() method called so they have a change
to synchronize device state with the rest of the system.
-
int input_open_device(struct input_handle *handle)¶
open input device
Parameters
struct input_handle *handlehandle through which device is being accessed
Description
This function should be called by input handlers when they want to start receive events from given input device.
-
void input_close_device(struct input_handle *handle)¶
close input device
Parameters
struct input_handle *handlehandle through which device is being accessed
Description
This function should be called by input handlers when they want to stop receive events from given input device.
-
int input_scancode_to_scalar(const struct input_keymap_entry *ke, unsigned int *scancode)¶
converts scancode in
struct input_keymap_entry
Parameters
const struct input_keymap_entry *kekeymap entry containing scancode to be converted.
unsigned int *scancodepointer to the location where converted scancode should be stored.
Description
This function is used to convert scancode stored in struct keymap_entry
into scalar form understood by legacy keymap handling methods. These
methods expect scancodes to be represented as ‘unsigned int’.
-
int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke)¶
retrieve keycode currently mapped to a given scancode
Parameters
struct input_dev *devinput device which keymap is being queried
struct input_keymap_entry *kekeymap entry
Description
This function should be called by anyone interested in retrieving current keymap. Presently evdev handlers use it.
-
int input_set_keycode(struct input_dev *dev, const struct input_keymap_entry *ke)¶
attribute a keycode to a given scancode
Parameters
struct input_dev *devinput device which keymap is being updated
const struct input_keymap_entry *kenew keymap entry
Description
This function should be called by anyone needing to update current keymap. Presently keyboard and evdev handlers use it.
Parameters
struct input_dev *devinput device whose state needs to be reset
Description
This function tries to reset the state of an opened input device and bring 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 prepared struct input_dev or NULL.
NOTE
Use input_free_device() to free devices that have not been
registered; input_unregister_device() should be used for already
registered devices.
Parameters
struct device *devdevice owning the input device being created
Description
Returns prepared struct input_dev or NULL.
Managed input devices do not need to be explicitly unregistered or freed as it will be done automatically when owner device unbinds from its driver (or binding fails). Once managed input device is allocated, it is ready to be set up and registered in the same fashion as regular input 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 need not be explicitly unregistered or freed.
NOTE
the owner device is set up as parent of input device and users should not override it.
Parameters
struct input_dev *devinput device to free
Description
This function should only be used if input_register_device()
was not called yet or if it failed. Once device was registered
use input_unregister_device() and memory will be freed once last
reference to the device is dropped.
Device should be allocated by input_allocate_device().
NOTE
If there are references to the input device then memory will not be freed until last reference is dropped.
Parameters
struct input_dev *devinput device to set timestamp for
ktime_t timestampthe time at which the event has occurred in CLOCK_MONOTONIC
Description
This function is intended to provide to the input system a more accurate time of when an event actually occurred. The driver should call this function as soon as a timestamp is acquired ensuring clock conversions in input_set_timestamp are done correctly.
The system entering suspend state between timestamp acquisition and calling input_set_timestamp can result in inaccurate conversions.
Parameters
struct input_dev *devinput device to get timestamp from
Description
A valid timestamp is a timestamp of non-zero value.
-
void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int code)¶
mark device as capable of a certain event
Parameters
struct input_dev *devdevice that is capable of emitting or accepting event
unsigned int typetype of the event (EV_KEY, EV_REL, etc...)
unsigned int codeevent code
Description
In addition to setting up corresponding bit in appropriate capability bitmap the function also adjusts dev->evbit.
-
void input_enable_softrepeat(struct input_dev *dev, int delay, int period)¶
enable software autorepeat
Parameters
struct input_dev *devinput device
int delayrepeat delay
int periodrepeat period
Description
Enable software autorepeat on the input device.
Parameters
struct input_dev *devdevice to be registered
Description
This function registers device with input core. The device must be
allocated with input_allocate_device() and all it’s capabilities
set up before registering.
If function fails the device must be freed with input_free_device().
Once device has been successfully registered it can be unregistered
with input_unregister_device(); input_free_device() should not be
called in this case.
Note that this function is also used to register managed input devices
(ones allocated with devm_input_allocate_device()). Such managed input
devices need not be explicitly unregistered or freed, their tear down
is controlled by the devres infrastructure. It is also worth noting
that tear down of managed input devices is internally a 2-step process:
registered managed input device is first unregistered, but stays in
memory and can still handle input_event() calls (although events will
not be delivered anywhere). The freeing of managed input device will
happen later, when devres stack is unwound to the point where device
allocation was made.
Parameters
struct input_dev *devdevice to be unregistered
Description
This function unregisters an input device. Once device is unregistered the caller should not try to access it as it may get freed at any moment.
-
int input_register_handler(struct input_handler *handler)¶
register a new input handler
Parameters
struct input_handler *handlerhandler to be registered
Description
This function registers a new input handler (interface) for input devices in the system and attaches it to all input devices that are compatible with the handler.
-
void input_unregister_handler(struct input_handler *handler)¶
unregisters an input handler
Parameters
struct input_handler *handlerhandler to be unregistered
Description
This function disconnects a handler from its input devices and removes it from lists of known handlers.
-
int input_handler_for_each_handle(struct input_handler *handler, void *data, int (*fn)(struct input_handle*, void*))¶
handle iterator
Parameters
struct input_handler *handlerinput handler to iterate
void *datadata for the callback
int (*fn)(struct input_handle *, void *)function to be called for each handle
Description
Iterate over bus’s list of devices, and call fn for each, passing it data and stop when fn returns a non-zero value. The function is using RCU to traverse the list and therefore may be using in atomic contexts. The fn callback is invoked from RCU critical section and thus must not sleep.
-
int input_register_handle(struct input_handle *handle)¶
register a new input handle
Parameters
struct input_handle *handlehandle to register
Description
This function puts a new input handle onto device’s
and handler’s lists so that events can flow through
it once it is opened using input_open_device().
This function is supposed to be called from handler’s connect() method.
-
void input_unregister_handle(struct input_handle *handle)¶
unregister an input handle
Parameters
struct input_handle *handlehandle to unregister
Description
This function removes input handle from device’s and handler’s lists.
This function is supposed to be called from handler’s disconnect() method.
-
int input_get_new_minor(int legacy_base, unsigned int legacy_num, bool allow_dynamic)¶
allocates a new input minor number
Parameters
int legacy_basebeginning or the legacy range to be searched
unsigned int legacy_numsize of legacy range
bool allow_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 specifying legacy_base and legacy_num parameters and whether ID can be allocated from dynamic range if there are no free IDs in legacy range.
-
void input_free_minor(unsigned int minor)¶
release previously allocated minor
Parameters
unsigned int minorminor to be released
Description
This function releases previously allocated input minor so that it can be reused later.
-
int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file)¶
upload effect into force-feedback device
Parameters
struct input_dev *devinput device
struct ff_effect *effecteffect to be uploaded
struct file *fileowner of the effect
-
int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file)¶
erase a force-feedback effect from device
Parameters
struct input_dev *devinput device to erase effect from
int effect_idid of the effect to be erased
struct file *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 same file handle that is requesting erase.
-
int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)¶
generic handler for force-feedback events
Parameters
struct input_dev *devinput device to send the effect to
unsigned int typeevent type (anything but EV_FF is ignored)
unsigned int codeevent code
int valueevent value
Parameters
struct input_dev *devinput device supporting force-feedback
unsigned int max_effectsmaximum number of effects supported by the device
Description
This function allocates all necessary memory for a force feedback portion 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
struct input_dev *devinput device supporting force feedback
Description
This function is only needed in error path as input core will automatically free force feedback structures when device is destroyed.
-
int input_ff_create_memless(struct input_dev *dev, void *data, int (*play_effect)(struct input_dev*, void*, struct ff_effect*))¶
create memoryless force-feedback device
Parameters
struct input_dev *devinput device supporting force-feedback
void *datadriver-specific data to be passed into play_effect
int (*play_effect)(struct input_dev *, void *, struct ff_effect *)driver-specific method for playing FF effect
Multitouch Library¶
-
struct input_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
-
struct input_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
-
struct input_mt_pos¶
contact position
Definition:
struct input_mt_pos {
s16 x, y;
};
Members
xhorizontal coordinate
yvertical coordinate
-
int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, unsigned int flags)¶
initialize MT input slots
Parameters
struct input_dev *devinput device supporting MT events and finger tracking
unsigned int num_slotsnumber of slots used by the device
unsigned int flagsmt tasks to handle in core
Description
This function allocates all necessary memory for MT slot handling in the input device, prepares the ABS_MT_SLOT and ABS_MT_TRACKING_ID events for use and sets up appropriate buffers. Depending on the flags set, it also performs pointer emulation and frame synchronization.
May be called repeatedly. Returns -EINVAL if attempting to reinitialize with a different number of slots.
Parameters
struct input_dev *devinput device with allocated MT slots
Description
This function is only needed in error path as the input core will automatically free the MT slots when the device is destroyed.
-
bool input_mt_report_slot_state(struct input_dev *dev, unsigned int tool_type, bool active)¶
report contact state
Parameters
struct input_dev *devinput device with allocated MT slots
unsigned int tool_typethe tool type to use in this slot
bool activetrue if contact is active, false otherwise
Description
Reports a contact via ABS_MT_TRACKING_ID, and optionally ABS_MT_TOOL_TYPE. If active is true and the slot is currently inactive, or if the tool type is changed, a new tracking id is assigned to the slot. The tool type is only reported if the corresponding absbit field is set.
Returns true if contact is active.
Parameters
struct input_dev *devinput device with allocated MT slots
int countthe 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 for this device will produce output.
-
void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count)¶
common pointer emulation
Parameters
struct input_dev *devinput device with allocated MT slots
bool use_countreport number of active contacts as finger count
Description
Performs legacy pointer emulation via BTN_TOUCH, ABS_X, ABS_Y and ABS_PRESSURE. Touchpad finger count is emulated if use_count is true.
The input core ensures only the KEY and ABS axes already setup for this device will produce output.
Parameters
struct input_dev *devinput device with allocated MT slots
Description
Lift all slots not seen since the last call to this function.
Parameters
struct input_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 performs pointer emulation.
-
int input_mt_assign_slots(struct input_dev *dev, int *slots, const struct input_mt_pos *pos, int num_pos, int dmax)¶
perform a best-match assignment
Parameters
struct input_dev *devinput device with allocated MT slots
int *slotsthe slot assignment to be filled
const struct input_mt_pos *posthe position array to match
int num_posnumber of positions
int dmaxmaximum ABS_MT_POSITION displacement (zero for infinite)
Description
Performs a best match against the current contacts and returns the slot assignment list. New contacts are assigned to unused slots.
The assignments are balanced so that all coordinate displacements are below 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
struct input_dev *devinput device with allocated MT slots
int keythe key of the sought slot
Description
Returns the slot of the given key, if it exists, otherwise set 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() has
to be called at each frame.
Matrix keyboards/keypads¶
-
struct matrix_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() macro representing keymap
keymap_sizenumber of entries (initialized) in this keymap
Description
This structure is supposed to be used by platform code to supply keymaps to drivers that implement matrix-like keypads/keyboards.
-
struct matrix_keypad_platform_data¶
platform-dependent keypad data
Definition:
struct matrix_keypad_platform_data {
const struct matrix_keymap_data *keymap_data;
const unsigned int *row_gpios;
const unsigned int *col_gpios;
unsigned int num_row_gpios;
unsigned int num_col_gpios;
unsigned int col_scan_delay_us;
unsigned int debounce_ms;
unsigned int clustered_irq;
unsigned int clustered_irq_flags;
bool active_low;
bool wakeup;
bool no_autorepeat;
bool drive_inactive_cols;
};
Members
keymap_datapointer to
matrix_keymap_datarow_gpiospointer to array of gpio numbers representing rows
col_gpiospointer to array of gpio numbers reporesenting colums
num_row_gpiosactual number of row gpios used by device
num_col_gpiosactual number of col gpios used by device
col_scan_delay_usdelay, measured in microseconds, that is needed before we can keypad after activating column gpio
debounce_msdebounce interval in milliseconds
clustered_irqmay be specified if interrupts of all row/column GPIOs are bundled to one single irq
clustered_irq_flagsflags that are needed for the clustered irq
active_lowgpio polarity
wakeupcontrols whether the device should be set up as wakeup source
no_autorepeatdisable key autorepeat
drive_inactive_colsdrive inactive columns during scan, rather than making them inputs.
Description
This structure represents platform-specific data that use used by matrix_keypad driver to perform proper initialization.
Sparse keymap support¶
-
struct key_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 own private definitions.
codeDevice-specific data identifying the button/switch
{unnamed_union}anonymous
keycodeKEY_* code assigned to a key/button
swstruct with code/value used by KE_SW and KE_VSW
sw.codeSW_* code assigned to a switch
sw.valueValue that should be sent in an input even when KE_SW switch is toggled. KE_VSW switches ignore this field and expect driver to supply value for the event.
Description
This structure defines an entry in a sparse keymap used by some input devices for which traditional table-based approach is not suitable.
-
struct key_entry *sparse_keymap_entry_from_scancode(struct input_dev *dev, unsigned int code)¶
perform sparse keymap lookup
Parameters
struct input_dev *devInput device using sparse keymap
unsigned int codeScan code
Description
This function is used to perform struct key_entry lookup in an
input device using sparse keymap.
-
struct key_entry *sparse_keymap_entry_from_keycode(struct input_dev *dev, unsigned int keycode)¶
perform sparse keymap lookup
Parameters
struct input_dev *devInput device using sparse keymap
unsigned int keycodeKey code
Description
This function is used to perform struct key_entry lookup in an
input device using sparse keymap.
-
int sparse_keymap_setup(struct input_dev *dev, const struct key_entry *keymap, int (*setup)(struct input_dev*, struct key_entry*))¶
set up sparse keymap for an input device
Parameters
struct input_dev *devInput device
const struct key_entry *keymapKeymap in form of array of
key_entrystructures ending withKE_ENDtype entryint (*setup)(struct input_dev *, struct key_entry *)Function that can be used to adjust keymap entries depending on device’s needs, may be
NULL
Description
The function calculates size and allocates copy of the original keymap after which sets up input device event bits appropriately. The allocated copy of the keymap is automatically freed when it is no longer needed.
-
void sparse_keymap_report_entry(struct input_dev *dev, const struct key_entry *ke, unsigned int value, bool autorelease)¶
report event corresponding to given key entry
Parameters
struct input_dev *devInput device for which event should be reported
const struct key_entry *kekey entry describing event
unsigned int valueValue that should be reported (ignored by
KE_SWentries)bool autoreleaseSignals whether release event should be emitted for
KE_KEYentries right after reporting press event, ignored by all other entries
Description
This function is used to report input event described by given
struct key_entry.
-
bool sparse_keymap_report_event(struct input_dev *dev, unsigned int code, unsigned int value, bool autorelease)¶
report event corresponding to given scancode
Parameters
struct input_dev *devInput device using sparse keymap
unsigned int codeScan code
unsigned int valueValue that should be reported (ignored by
KE_SWentries)bool autoreleaseSignals whether release event should be emitted for
KE_KEYentries right after reporting press event, ignored by all other entries
Description
This function is used to perform lookup in an input device using sparse
keymap and report corresponding event. Returns true if lookup was
successful and false otherwise.