Input Subsystem

Input core

structinput_value

input value representation

Definition:

struct input_value {    __u16 type;    __u16 code;    __s32 value;};

Members

type

type of value (EV_KEY, EV_ABS, etc)

code

the value code

value

the 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

name

name of the device

phys

physical path to the device in the system hierarchy

uniq

unique identification code for the device (if device has it)

id

id of the device (structinput_id)

propbit

bitmap of device properties and quirks

evbit

bitmap of types of events supported by the device (EV_KEY,EV_REL, etc.)

keybit

bitmap of keys/buttons this device has

relbit

bitmap of relative axes for the device

absbit

bitmap of absolute axes for the device

mscbit

bitmap of miscellaneous events supported by the device

ledbit

bitmap of leds present on the device

sndbit

bitmap of sound effects supported by the device

ffbit

bitmap of force feedback effects supported by the device

swbit

bitmap of switches present on the device

hint_events_per_packet

average 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.

keycodemax

size of keycode table

keycodesize

size of elements in keycode table

keycode

map of scancodes to keycodes for this device

setkeycode

optional 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

getkeycode

optional legacy method to retrieve current keymap.

ff

force feedback structure associated with the device if devicesupports force feedback effects

poller

poller structure associated with the device if device isset up to use polling mode

repeat_key

stores key code of the last key pressed; used to implementsoftware autorepeat

timer

timer for software autorepeat

rep

current values for autorepeat parameters (delay, rate)

mt

pointer to multitouch state

absinfo

array ofstructinput_absinfo elements holding informationabout absolute axes (current value, min, max, flat, fuzz,resolution)

key

reflects current state of device’s keys/buttons

led

reflects current state of device’s LEDs

snd

reflects current state of sound effects

sw

reflects current state of device’s switches

open

this method is called when the very first user callsinput_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.

close

this method is called when the very last user callsinput_close_device(). The meaning of close() is to stopproviding events to the input core.

flush

purges the device. Most commonly used to get rid of forcefeedback effects loaded into the device when disconnectingfrom it

event

event 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

grab

input 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_lock

this spinlock is taken when input core receivesand processes a new event for the device (ininput_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.

mutex

serializes calls to open(), close() andflush() methods

users

stores number of users (input handlers) that opened thisdevice. It is used byinput_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 device

going_away

marks devices that are in a middle of unregistering andcauses input_open_device*() fail with -ENODEV.

dev

driver model’s view of this device

h_list

list of input handles associated with the device. Whenaccessing the list dev->mutex must be held

node

used to place the device onto input_dev_list

num_vals

number of values queued in the current frame

max_vals

maximum number of values queued in a frame

vals

array of values queued in the current frame

devres_managed

indicates that devices is managed with devres frameworkand needs not be explicitly unregistered or freed.

timestamp

storage for a timestamp set by input_set_timestamp calledby a driver

inhibited

indicates 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

private

driver-specific data

event

event handler. This method is being called by input core withinterrupts disabled and dev->event_lock spinlock held and soit may not sleep

events

event 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.

filter

similar toevent; separates normal event handlers from“filters”.

match

called after comparing device’s id with handler’s id_tableto perform fine-grained matching between device and handler

connect

called when attaching a handler to an input device

disconnect

disconnects a handler from input device

start

starts handler for given handle. This function is called byinput core right afterconnect() method and also when a processthat “grabbed” a device releases it

passive_observer

set totrue by 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 handles

legacy_minors

set totrue by drivers using legacy minor ranges

minor

beginning of range of 32 legacy minors for devices this drivercan provide

name

name of the handler, to be shown in /proc/bus/input/handlers

id_table

pointer to a table of input_device_ids this driver canhandle

h_list

list of input handles associated with the handler

node

for 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

private

handler-specific data

open

counter showing whether the handle is ‘open’, i.e. should deliverevents from its device

name

name given to the handle by handler that created it

dev

input device the handle is attached to

handler

handler that works with the device through this handle

handle_events

event sequence handler. It is set up by the input coreaccording to event handling method specified in thehandler. Seeinput_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_node

used to put the handle on device’s list of attached handles

h_node

used 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*dev

the input device used by the driver

intn_events

the average number of events between calls toinput_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

upload

Called to upload an new effect into device

erase

Called to erase an effect from device

playback

Called to request device to start playing specified effect

set_gain

Called to set specified gain

set_autocenter

Called to auto-center device

destroy

called by input core when parent input device is beingdestroyed

private

driver-specific data, will be freed automatically

ffbit

bitmap of force feedback capabilities truly supported bydevice (not emulated like ones in input_dev->ffbit)

mutex

mutex for serializing access to the device

max_effects

maximum number of effects supported by device

effects

pointer to an array of effects currently loaded into device

effect_owners

array 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*dev

device that generated the event

unsignedinttype

type of the event

unsignedintcode

event code

intvalue

value 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*handle

input handle to send event through

unsignedinttype

type of the event

unsignedintcode

event code

intvalue

value 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.

voidinput_alloc_absinfo(structinput_dev*dev)

allocates array of input_absinfo structs

Parameters

structinput_dev*dev

the 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*dst

Destination input device to copy the abs settings to

unsignedintdst_axis

ABS_* value selecting the destination axis

conststructinput_dev*src

Source input device to copy the abs settings from

unsignedintsrc_axis

ABS_* 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*handle

input 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*handle

input 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*handle

handle 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*handle

handle 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 instructinput_keymap_entry

Parameters

conststructinput_keymap_entry*ke

keymap entry containing scancode to be converted.

unsignedint*scancode

pointer 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*dev

input device which keymap is being queried

structinput_keymap_entry*ke

keymap 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*dev

input device which keymap is being updated

conststructinput_keymap_entry*ke

new keymap entry

Description

This function should be called by anyone needing to update currentkeymap. Presently keyboard and evdev handlers use it.

voidinput_reset_device(structinput_dev*dev)

reset/restore the state of input device

Parameters

structinput_dev*dev

input 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.

structinput_dev*input_allocate_device(void)

allocate memory for new input device

Parameters

void

no 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.

structinput_dev*devm_input_allocate_device(structdevice*dev)

allocate managed input device

Parameters

structdevice*dev

device 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.

voidinput_free_device(structinput_dev*dev)

free memory occupied by input_dev structure

Parameters

structinput_dev*dev

input 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.

voidinput_set_timestamp(structinput_dev*dev,ktime_ttimestamp)

set timestamp for input events

Parameters

structinput_dev*dev

input device to set timestamp for

ktime_ttimestamp

the 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.

ktime_t*input_get_timestamp(structinput_dev*dev)

get timestamp for input events

Parameters

structinput_dev*dev

input 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*dev

device that is capable of emitting or accepting event

unsignedinttype

type of the event (EV_KEY, EV_REL, etc...)

unsignedintcode

event code

Description

In addition to setting up corresponding bit in appropriate capabilitybitmap the function also adjusts dev->evbit.

voidinput_enable_softrepeat(structinput_dev*dev,intdelay,intperiod)

enable software autorepeat

Parameters

structinput_dev*dev

input device

intdelay

repeat delay

intperiod

repeat period

Description

Enable software autorepeat on the input device.

intinput_register_device(structinput_dev*dev)

register device with input core

Parameters

structinput_dev*dev

device 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.

voidinput_unregister_device(structinput_dev*dev)

unregister previously registered device

Parameters

structinput_dev*dev

device 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*handler

handler 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*handler

handler 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*handler

input handler to iterate

void*data

data 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*handle

handle 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*handle

handle 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_base

beginning or the legacy range to be searched

unsignedintlegacy_num

size of legacy range

boolallow_dynamic

whether 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

unsignedintminor

minor 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*dev

input device

structff_effect*effect

effect to be uploaded

structfile*file

owner of the effect

intinput_ff_erase(structinput_dev*dev,inteffect_id,structfile*file)

erase a force-feedback effect from device

Parameters

structinput_dev*dev

input device to erase effect from

inteffect_id

id of the effect to be erased

structfile*file

purported 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*dev

input device to send the effect to

unsignedinttype

event type (anything but EV_FF is ignored)

unsignedintcode

event code

intvalue

event value

intinput_ff_create(structinput_dev*dev,unsignedintmax_effects)

create force-feedback device

Parameters

structinput_dev*dev

input device supporting force-feedback

unsignedintmax_effects

maximum 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

voidinput_ff_destroy(structinput_dev*dev)

frees force feedback portion of input device

Parameters

structinput_dev*dev

input 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*dev

input device supporting force-feedback

void*data

driver-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

abs

holds current values of ABS_MT axes for this slot

frame

last frame at whichinput_mt_report_slot_state() was called

key

optional 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

trkid

stores MT tracking ID for the next contact

num_slots

number of MT slots the device uses

slot

MT slot currently being transmitted

flags

input_mt operation flags

frame

increases every timeinput_mt_sync_frame() is called

red

reduced cost matrix for in-kernel tracking

slots

array of slots holding current values of tracked contacts

structinput_mt_pos

contact position

Definition:

struct input_mt_pos {    s16 x, y;};

Members

x

horizontal coordinate

y

vertical coordinate

intinput_mt_init_slots(structinput_dev*dev,unsignedintnum_slots,unsignedintflags)

initialize MT input slots

Parameters

structinput_dev*dev

input device supporting MT events and finger tracking

unsignedintnum_slots

number of slots used by the device

unsignedintflags

mt 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.

voidinput_mt_destroy_slots(structinput_dev*dev)

frees the MT slots of the input device

Parameters

structinput_dev*dev

input 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*dev

input device with allocated MT slots

unsignedinttool_type

the tool type to use in this slot

boolactive

true 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.

voidinput_mt_report_finger_count(structinput_dev*dev,intcount)

report contact count

Parameters

structinput_dev*dev

input device with allocated MT slots

intcount

the 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.

voidinput_mt_report_pointer_emulation(structinput_dev*dev,booluse_count)

common pointer emulation

Parameters

structinput_dev*dev

input device with allocated MT slots

booluse_count

report 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.

voidinput_mt_drop_unused(structinput_dev*dev)

Inactivate slots not seen in this frame

Parameters

structinput_dev*dev

input device with allocated MT slots

Description

Lift all slots not seen since the last call to this function.

voidinput_mt_sync_frame(structinput_dev*dev)

synchronize mt frame

Parameters

structinput_dev*dev

input 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*dev

input device with allocated MT slots

int*slots

the slot assignment to be filled

conststructinput_mt_pos*pos

the position array to match

intnum_pos

number of positions

intdmax

maximum 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.

intinput_mt_get_slot_by_key(structinput_dev*dev,intkey)

return slot matching key

Parameters

structinput_dev*dev

input device with allocated MT slots

intkey

the 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

keymap

pointer to array of uint32 values encoded withKEY() macrorepresenting keymap

keymap_size

number 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

type

Type of the key entry (KE_KEY, KE_SW, KE_VSW, KE_END);drivers are allowed to extend the list with their ownprivate definitions.

code

Device-specific data identifying the button/switch

{unnamed_union}

anonymous

keycode

KEY_* code assigned to a key/button

sw

structwith code/value used by KE_SW and KE_VSW

sw.code

SW_* code assigned to a switch

sw.value

Value 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*dev

Input device using sparse keymap

unsignedintcode

Scan 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*dev

Input device using sparse keymap

unsignedintkeycode

Key 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*dev

Input device

conststructkey_entry*keymap

Keymap in form of array ofkey_entry structures endingwithKE_END type entry

int(*setup)(structinput_dev*,structkey_entry*)

Function that can be used to adjust keymap entriesdepending on device’s needs, may beNULL

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*dev

Input device for which event should be reported

conststructkey_entry*ke

key entry describing event

unsignedintvalue

Value that should be reported (ignored byKE_SW entries)

boolautorelease

Signals whether release event should be emitted forKE_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*dev

Input device using sparse keymap

unsignedintcode

Scan code

unsignedintvalue

Value that should be reported (ignored byKE_SW entries)

boolautorelease

Signals whether release event should be emitted forKE_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_PROCESS

pass to the main protocol handler, process normally

PS2_IGNORE

skip the byte

PS2_ERROR

do 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

serio

a serio port used by the PS/2 device

cmd_mutex

a mutex ensuring that only one command is executing at a time

wait

a waitqueue used to signal completion from the serio interrupt handler

flags

various internal flags indicating stages of PS/2 command execution

cmdbuf

buffer holding command response

cmdcnt

outstanding number of bytes of the command response

nak

a byte transmitted by the device when it refuses command

pre_receive_handler

checks communication errors and returns disposition(enumps2_disposition) of the received data byte

receive_handler

main 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*ps2dev

a PS/2 device to send the data to

u8byte

data to be sent to the device

unsignedinttimeout

timeout 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.

voidps2_begin_command(structps2dev*ps2dev)

mark beginning of execution of a complex command

Parameters

structps2dev*ps2dev

a PS/2 device executing the command

Description

Serializes a complex/compound command. Once command is finishedps2_end_command() should be called.

voidps2_end_command(structps2dev*ps2dev)

mark end of execution of a complex command

Parameters

structps2dev*ps2dev

a 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*ps2dev

the PS/2 device that should be drained

size_tmaxbytes

maximum number of bytes to be drained

unsignedinttimeout

time to drain the device

boolps2_is_keyboard_id(u8id_byte)

checks received ID byte against the list of known keyboard IDs

Parameters

u8id_byte

data byte that should be checked

int__ps2_command(structps2dev*ps2dev,u8*param,unsignedintcommand)

send a command to PS/2 device

Parameters

structps2dev*ps2dev

the PS/2 device that should execute the command

u8*param

a buffer containing parameters to be sent along with the command,or place where the results of the command execution will be deposited,or both

unsignedintcommand

command 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.

intps2_command(structps2dev*ps2dev,u8*param,unsignedintcommand)

send a command to PS/2 device

Parameters

structps2dev*ps2dev

the PS/2 device that should execute the command

u8*param

a buffer containing parameters to be sent along with the command,or place where the results of the command execution will be deposited,or both

unsignedintcommand

command 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.

intps2_sliced_command(structps2dev*ps2dev,u8command)

sends an extended PS/2 command to a mouse

Parameters

structps2dev*ps2dev

the PS/2 device that should execute the command

u8command

command 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*ps2dev

structure to be initialized

structserio*serio

serio port associated with the PS/2 device

ps2_pre_receive_handler_tpre_receive_handler

validation handler to check basic communication state

ps2_receive_handler_treceive_handler

main 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*serio

serio port for the device

u8data

a data byte received from the device

unsignedintflags

flags such asSERIO_PARITY orSERIO_TIMEOUT indicating 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.