Input Subsystem
Input core #
struct input_value #
input value representation
Definition
;
Members
type: type of value (EV_KEY, EV_ABS, etc)code: the value codevalue: the value
struct input_dev #
represents an input device
Definition
;
Members
name: name of the devicephys: physical path to the device in the system hierarchyuniq: unique identification code for the device (if device has it)id: id of the device (struct input_id)propbit: bitmap of device properties and quirksevbit: bitmap of types of events supported by the device (EV_KEY, EV_REL, etc.)keybit: bitmap of keys/buttons this device hasrelbit: bitmap of relative axes for the deviceabsbit: bitmap of absolute axes for the devicemscbit: bitmap of miscellaneous events supported by the deviceledbit: bitmap of leds present on the devicesndbit: bitmap of sound effects supported by the deviceffbit: bitmap of force feedback effects supported by the deviceswbit: bitmap of switches present on the devicehint_events_per_packet: average 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.keycodemax: size of keycode tablekeycodesize: size of elements in keycode tablekeycode: map of scancodes to keycodes for this devicesetkeycode: optional 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 sleepgetkeycode: optional legacy method to retrieve current keymap.ff: force feedback structure associated with the device if device supports force feedback effectspoller: poller structure associated with the device if device is set up to use polling moderepeat_key: stores key code of the last key pressed; used to implement software autorepeattimer: timer for software autorepeatrep: current values for autorepeat parameters (delay, rate)mt: pointer to multitouch stateabsinfo: array ofstruct input_absinfoelements holding information about absolute axes (current value, min, max, flat, fuzz, resolution)key: reflects current state of device's keys/buttonsled: reflects current state of device's LEDssnd: reflects current state of sound effectssw: reflects current state of device's switchesopen: this method is called when the very first user callsinput_open_device(). The driver must prepare the device to start generating events (start polling thread, request an IRQ, submit URB, etc.). The meaning ofopen()is to start providing events to the input core.close: this method is called when the very last user callsinput_close_device(). The meaning ofclose()is to stop providing events to the input core.flush: purges the device. Most commonly used to get rid of force feedback effects loaded into the device when disconnecting from itevent: event 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 sleepgrab: input 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 deviceevent_lock: this spinlock is taken when input core receives and 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 device has been registered with input core must take this lock.mutex: serializes calls toopen(),close()andflush()methodsusers: stores number of users (input handlers) that opened this device. It is used byinput_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_away: marks devices that are in a middle of unregistering and causes input_open_device*() fail with -ENODEV.dev: driver model's view of this deviceh_list: list of input handles associated with the device. When accessing the list dev->mutex must be heldnode: used to place the device onto input_dev_listnum_vals: number of values queued in the current framemax_vals: maximum number of values queued in a framevals: array of values queued in the current framedevres_managed: indicates that devices is managed with devres framework and needs not be explicitly unregistered or freed.timestamp: storage for a timestamp set by input_set_timestamp called by a driverinhibited: indicates that the input device is inhibited. If that is the case then input core ignores any events generated by the device. Device'sclose()is called when it is being inhibited and itsopen()is called when it is being uninhibited.
struct input_handler #
implements one of interfaces for input devices
Definition
;
Members
private: driver-specific dataevent: event handler. This method is being called by input core with interrupts disabled and dev->event_lock spinlock held and so it may not sleepevents: event 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. The method must return number of events passed to it.filter: similar to event; separates normal event handlers from "filters".match: called after comparing device's id with handler's id_table to perform fine-grained matching between device and handlerconnect: called when attaching a handler to an input devicedisconnect: disconnects a handler from input devicestart: starts handler for given handle. This function is called by input core right afterconnect()method and also when a process that "grabbed" a device releases itpassive_observer: set totrueby drivers only interested in observing data stream from devices if there are other users present. Such drivers will not result in starting underlying hardware device wheninput_open_device()is called for their handleslegacy_minors: set totrueby drivers using legacy minor rangesminor: beginning of range of 32 legacy minors for devices this driver can providename: name of the handler, to be shown in /proc/bus/input/handlersid_table: pointer to a table of input_device_ids this driver can handleh_list: list of input handles associated with the handlernode: for 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
;
Members
private: handler-specific dataopen: counter showing whether the handle is 'open', i.e. should deliver events from its devicename: name given to the handle by handler that created itdev: input device the handle is attached tohandler: handler that works with the device through this handlehandle_events: event sequence handler. It is set up by the input core according to event handling method specified in the handler. Seeinput_handle_setup_event_handler(). This method is being called by the input core with interrupts disabled and dev->event_lock spinlock held and so it may not sleep.d_node: used to put the handle on device's list of attached handlesh_node: used to put the handle on handler's list of handles from which it gets events
input_set_events_per_packet() #
void tell handlers about the driver event rate
Parameters
struct input_dev *dev: the input device used by the driverint n_events: the average number of events between calls toinput_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
;
Members
upload: Called to upload an new effect into deviceerase: Called to erase an effect from deviceplayback: Called to request device to start playing specified effectset_gain: Called to set specified gainset_autocenter: Called to auto-center devicedestroy: called by input core when parent input device is being destroyedprivate: driver-specific data, will be freed automaticallyffbit: bitmap of force feedback capabilities truly supported by device (not emulated like ones in input_dev->ffbit)mutex: mutex for serializing access to the devicemax_effects: maximum number of effects supported by deviceeffects: pointer to an array of effects currently loaded into deviceeffect_owners: array 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.
input_event() #
void report new input event
Parameters
struct input_dev *dev: device that generated the eventunsigned int type: type of the eventunsigned int code: event codeint value: value 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.
input_inject_event() #
void send input event from input handler
Parameters
struct input_handle *handle: input handle to send event throughunsigned int type: type of the eventunsigned int code: event codeint value: value 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.
input_alloc_absinfo() #
void allocates array of input_absinfo structs
Parameters
struct input_dev *dev: the input device emitting absolute events
Description
If the absinfo struct the caller asked for is already allocated, this functions will not do anything.
input_copy_abs() #
void Copy absinfo from one input_dev to another
Parameters
struct input_dev *dst: Destination input device to copy the abs settings tounsigned int dst_axis: ABS_* value selecting the destination axisconst struct input_dev *src: Source input device to copy the abs settings fromunsigned int src_axis: ABS_* 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.
input_grab_device() #
int grabs device for exclusive use
Parameters
struct input_handle *handle: input 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.
input_release_device() #
void release previously grabbed device
Parameters
struct input_handle *handle: input 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.
input_open_device() #
int open input device
Parameters
struct input_handle *handle: handle 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.
input_close_device() #
void close input device
Parameters
struct input_handle *handle: handle 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.
input_scancode_to_scalar() #
int converts scancode in struct input_keymap_entry
Parameters
const struct input_keymap_entry *ke: keymap entry containing scancode to be converted.unsigned int *scancode: pointer 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'.
input_get_keycode() #
int retrieve keycode currently mapped to a given scancode
Parameters
struct input_dev *dev: input device which keymap is being queriedstruct input_keymap_entry *ke: keymap entry
Description
This function should be called by anyone interested in retrieving current keymap. Presently evdev handlers use it.
input_set_keycode() #
int attribute a keycode to a given scancode
Parameters
struct input_dev *dev: input device which keymap is being updatedconst struct input_keymap_entry *ke: new keymap entry
Description
This function should be called by anyone needing to update current keymap. Presently keyboard and evdev handlers use it.
input_reset_device() #
void reset/restore the state of input device
Parameters
struct input_dev *dev: input 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.
input_allocate_device() #
struct input_dev * allocate memory for new input device
Parameters
void: no 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.
devm_input_allocate_device() #
struct input_dev * allocate managed input device
Parameters
struct device *dev: device 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.
input_free_device() #
void free memory occupied by input_dev structure
Parameters
struct input_dev *dev: input 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.
input_set_timestamp() #
void set timestamp for input events
Parameters
struct input_dev *dev: input device to set timestamp forktime_t timestamp: the 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.
input_get_timestamp() #
ktime_t * get timestamp for input events
Parameters
struct input_dev *dev: input device to get timestamp from
Description
A valid timestamp is a timestamp of non-zero value.
input_set_capability() #
void mark device as capable of a certain event
Parameters
struct input_dev *dev: device that is capable of emitting or accepting eventunsigned int type: type of the event (EV_KEY, EV_REL, etc...)unsigned int code: event code
Description
In addition to setting up corresponding bit in appropriate capability bitmap the function also adjusts dev->evbit.
input_enable_softrepeat() #
void enable software autorepeat
Parameters
struct input_dev *dev: input deviceint delay: repeat delayint period: repeat period
Description
Enable software autorepeat on the input device.
input_register_device() #
int register device with input core
Parameters
struct input_dev *dev: device 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.
input_unregister_device() #
void unregister previously registered device
Parameters
struct input_dev *dev: device 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.
input_register_handler() #
int register a new input handler
Parameters
struct input_handler *handler: handler 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.
input_unregister_handler() #
void unregisters an input handler
Parameters
struct input_handler *handler: handler to be unregistered
Description
This function disconnects a handler from its input devices and removes it from lists of known handlers.
input_handler_for_each_handle() #
int handle iterator
Parameters
struct input_handler *handler: input handler to iteratevoid *data: data for the callbackint (*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.
input_register_handle() #
int register a new input handle
Parameters
struct input_handle *handle: handle 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.
input_unregister_handle() #
void unregister an input handle
Parameters
struct input_handle *handle: handle 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.
input_get_new_minor() #
int allocates a new input minor number
Parameters
int legacy_base: beginning or the legacy range to be searchedunsigned int legacy_num: size of legacy rangebool allow_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 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.
input_free_minor() #
void release previously allocated minor
Parameters
unsigned int minor: minor to be released
Description
This function releases previously allocated input minor so that it can be reused later.
input_ff_upload() #
int upload effect into force-feedback device
Parameters
struct input_dev *dev: input devicestruct ff_effect *effect: effect to be uploadedstruct file *file: owner of the effect
input_ff_erase() #
int erase a force-feedback effect from device
Parameters
struct input_dev *dev: input device to erase effect fromint effect_id: id of the effect to be erasedstruct file *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 same file handle that is requesting erase.
input_ff_event() #
int generic handler for force-feedback events
Parameters
struct input_dev *dev: input device to send the effect tounsigned int type: event type (anything but EV_FF is ignored)unsigned int code: event codeint value: event value
input_ff_create() #
int create force-feedback device
Parameters
struct input_dev *dev: input device supporting force-feedbackunsigned int max_effects: maximum 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
input_ff_destroy() #
void frees force feedback portion of input device
Parameters
struct input_dev *dev: input 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.
input_ff_create_memless() #
int create memoryless force-feedback device
Parameters
struct input_dev *dev: input device supporting force-feedbackvoid *data: driver-specific data to be passed into play_effectint (*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
;
Members
abs: holds current values of ABS_MT axes for this slotframe: last frame at whichinput_mt_report_slot_state()was calledkey: optional driver designation of this slot
struct input_mt #
state of tracked contacts
Definition
;
Members
trkid: stores MT tracking ID for the next contactnum_slots: number of MT slots the device usesslot: MT slot currently being transmittedflags: input_mt operation flagsframe: increases every timeinput_mt_sync_frame()is calledred: reduced cost matrix for in-kernel trackingslots: array of slots holding current values of tracked contacts
struct input_mt_pos #
contact position
Definition
;
Members
x: horizontal coordinatey: vertical coordinate
input_mt_init_slots() #
int initialize MT input slots
Parameters
struct input_dev *dev: input device supporting MT events and finger trackingunsigned int num_slots: number of slots used by the deviceunsigned int flags: mt 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.
input_mt_destroy_slots() #
void frees the MT slots of the input device
Parameters
struct input_dev *dev: input 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.
input_mt_report_slot_state() #
bool report contact state
Parameters
struct input_dev *dev: input device with allocated MT slotsunsigned int tool_type: the tool type to use in this slotbool active: true 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.
input_mt_report_finger_count() #
void report contact count
Parameters
struct input_dev *dev: input device with allocated MT slotsint count: 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 for this device will produce output.
input_mt_report_pointer_emulation() #
void common pointer emulation
Parameters
struct input_dev *dev: input device with allocated MT slotsbool use_count: report 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.
input_mt_drop_unused() #
void Inactivate slots not seen in this frame
Parameters
struct input_dev *dev: input device with allocated MT slots
Description
Lift all slots not seen since the last call to this function.
input_mt_sync_frame() #
void synchronize mt frame
Parameters
struct input_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 performs pointer emulation.
input_mt_assign_slots() #
int perform a best-match assignment
Parameters
struct input_dev *dev: input device with allocated MT slotsint *slots: the slot assignment to be filledconst struct input_mt_pos *pos: the position array to matchint num_pos: number of positionsint dmax: maximum 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.
input_mt_get_slot_by_key() #
int return slot matching key
Parameters
struct input_dev *dev: input device with allocated MT slotsint key: the 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
;
Members
keymap: pointer to array of uint32 values encoded withKEY()macro representing keymapkeymap_size: number 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.
Sparse keymap support #
struct key_entry #
keymap entry for use in sparse keymap
Definition
;
Members
type: Type of the key entry (KE_KEY, KE_SW, KE_VSW, KE_END); drivers are allowed to extend the list with their own private definitions.code: Device-specific data identifying the button/switch{unnamed_union}: anonymouskeycode: KEY_* code assigned to a key/buttonsw: struct with code/value used by KE_SW and KE_VSWsw.code: SW_* code assigned to a switchsw.value: Value 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.
sparse_keymap_entry_from_scancode() #
struct key_entry * perform sparse keymap lookup
Parameters
struct input_dev *dev: Input device using sparse keymapunsigned int code: Scan code
Description
This function is used to perform struct key_entry lookup in an
input device using sparse keymap.
sparse_keymap_entry_from_keycode() #
struct key_entry * perform sparse keymap lookup
Parameters
struct input_dev *dev: Input device using sparse keymapunsigned int keycode: Key code
Description
This function is used to perform struct key_entry lookup in an
input device using sparse keymap.
sparse_keymap_setup() #
int set up sparse keymap for an input device
Parameters
struct input_dev *dev: Input deviceconst struct key_entry *keymap: Keymap in form of array ofkey_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 beNULL
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.
sparse_keymap_report_entry() #
void report event corresponding to given key entry
Parameters
struct input_dev *dev: Input device for which event should be reportedconst struct key_entry *ke: key entry describing eventunsigned int value: Value that should be reported (ignored byKE_SWentries)bool autorelease: Signals whether release event should be emitted forKE_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.
sparse_keymap_report_event() #
bool report event corresponding to given scancode
Parameters
struct input_dev *dev: Input device using sparse keymapunsigned int code: Scan codeunsigned int value: Value that should be reported (ignored byKE_SWentries)bool autorelease: Signals whether release event should be emitted forKE_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.
PS/2 protocol support #
enum ps2_disposition #
indicates how received byte should be handled
Constants
PS2_PROCESS: pass to the main protocol handler, process normallyPS2_IGNORE: skip the bytePS2_ERROR: do not process the byte, abort command in progress
struct ps2dev #
represents a device using PS/2 protocol
Definition
;
Members
serio: a serio port used by the PS/2 devicecmd_mutex: a mutex ensuring that only one command is executing at a timewait: a waitqueue used to signal completion from the serio interrupt handlerflags: various internal flags indicating stages of PS/2 command executioncmdbuf: buffer holding command responsecmdcnt: outstanding number of bytes of the command responsenak: a byte transmitted by the device when it refuses commandpre_receive_handler: checks communication errors and returns disposition (enum ps2_disposition) of the received data bytereceive_handler: main handler of particular PS/2 protocol, such as keyboard or mouse protocol
ps2_sendbyte() #
int sends a byte to the device and wait for acknowledgement
Parameters
struct ps2dev *ps2dev: a PS/2 device to send the data tou8 byte: data to be sent to the deviceunsigned int timeout: timeout for sending the data and receiving an acknowledge
Description
The function doesn't handle retransmission, the caller is expected to handle it when needed.
ps2_sendbyte() can only be called from a process context.
ps2_begin_command() #
void mark beginning of execution of a complex command
Parameters
struct ps2dev *ps2dev: a PS/2 device executing the command
Description
Serializes a complex/compound command. Once command is finished
ps2_end_command() should be called.
ps2_end_command() #
void mark end of execution of a complex command
Parameters
struct ps2dev *ps2dev: a PS/2 device executing the command
ps2_drain() #
void waits for device to transmit requested number of bytes and discards them
Parameters
struct ps2dev *ps2dev: the PS/2 device that should be drainedsize_t maxbytes: maximum number of bytes to be drainedunsigned int timeout: time to drain the device
ps2_is_keyboard_id() #
bool checks received ID byte against the list of known keyboard IDs
Parameters
u8 id_byte: data byte that should be checked
__ps2_command() #
int send a command to PS/2 device
Parameters
struct ps2dev *ps2dev: the PS/2 device that should execute the commandu8 *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 bothunsigned int command: command word that encodes the command itself, as well as number of additional parameter bytes that should be sent to the device and expected length of the command response
Description
Not serialized. Callers should use ps2_begin_command() and ps2_end_command()
to ensure proper serialization for complex commands.
ps2_command() #
int send a command to PS/2 device
Parameters
struct ps2dev *ps2dev: the PS/2 device that should execute the commandu8 *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 bothunsigned int command: command word that encodes the command itself, as well as number of additional parameter bytes that should be sent to the device and expected length of the command response
Note
ps2_command() serializes the command execution so that only one
command can be executed at a time for either individual port or the entire
8042 controller.
ps2_sliced_command() #
int sends an extended PS/2 command to a mouse
Parameters
struct ps2dev *ps2dev: the PS/2 device that should execute the commandu8 command: 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 (rr64)+(ss16)+(tt*4)+uu is the command.
ps2_init() #
void initializes ps2dev structure
Parameters
struct ps2dev *ps2dev: structure to be initializedstruct serio *serio: serio port associated with the PS/2 deviceps2_pre_receive_handler_t pre_receive_handler: validation handler to check basic communication stateps2_receive_handler_t receive_handler: main protocol handler
Description
Prepares ps2dev structure for use in drivers for PS/2 devices.
ps2_interrupt() #
irqreturn_t common interrupt handler for PS/2 devices
Parameters
struct serio *serio: serio port for the deviceu8 data: a data byte received from the deviceunsigned int flags: flags such asSERIO_PARITYorSERIO_TIMEOUTindicating state of the data transfer
Description
ps2_interrupt() invokes pre-receive handler, optionally handles command
acknowledgement and response from the device, and finally passes the data
to the main protocol handler for future processing.