2454 lines
60 KiB
C
2454 lines
60 KiB
C
/*
|
|
* The input core
|
|
*
|
|
* Copyright (c) 1999-2002 Vojtech Pavlik
|
|
*/
|
|
|
|
/*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_BASENAME ": " fmt
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/types.h>
|
|
#include <linux/idr.h>
|
|
#include <linux/input/mt.h>
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/random.h>
|
|
#include <linux/major.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/poll.h>
|
|
#include <linux/device.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/rcupdate.h>
|
|
#include "input-compat.h"
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
|
|
MODULE_DESCRIPTION("Input core");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
#define INPUT_MAX_CHAR_DEVICES 1024
|
|
#define INPUT_FIRST_DYNAMIC_DEV 256
|
|
static DEFINE_IDA(input_ida);
|
|
|
|
static LIST_HEAD(input_dev_list);
|
|
static LIST_HEAD(input_handler_list);
|
|
|
|
/*
|
|
* input_mutex protects access to both input_dev_list and input_handler_list.
|
|
* This also causes input_[un]register_device and input_[un]register_handler
|
|
* be mutually exclusive which simplifies locking in drivers implementing
|
|
* input handlers.
|
|
*/
|
|
static DEFINE_MUTEX(input_mutex);
|
|
|
|
static const struct input_value input_value_sync = { EV_SYN, SYN_REPORT, 1 };
|
|
|
|
static inline int is_event_supported(unsigned int code,
|
|
unsigned long *bm, unsigned int max)
|
|
{
|
|
return code <= max && test_bit(code, bm);
|
|
}
|
|
|
|
static int input_defuzz_abs_event(int value, int old_val, int fuzz)
|
|
{
|
|
if (fuzz) {
|
|
if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2)
|
|
return old_val;
|
|
|
|
if (value > old_val - fuzz && value < old_val + fuzz)
|
|
return (old_val * 3 + value) / 4;
|
|
|
|
if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
|
|
return (old_val + value) / 2;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
static void input_start_autorepeat(struct input_dev *dev, int code)
|
|
{
|
|
if (test_bit(EV_REP, dev->evbit) &&
|
|
dev->rep[REP_PERIOD] && dev->rep[REP_DELAY] &&
|
|
dev->timer.data) {
|
|
dev->repeat_key = code;
|
|
mod_timer(&dev->timer,
|
|
jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]));
|
|
}
|
|
}
|
|
|
|
static void input_stop_autorepeat(struct input_dev *dev)
|
|
{
|
|
del_timer(&dev->timer);
|
|
}
|
|
|
|
/*
|
|
* Pass event first through all filters and then, if event has not been
|
|
* filtered out, through all open handles. This function is called with
|
|
* dev->event_lock held and interrupts disabled.
|
|
*/
|
|
static unsigned int input_to_handler(struct input_handle *handle,
|
|
struct input_value *vals, unsigned int count)
|
|
{
|
|
struct input_handler *handler = handle->handler;
|
|
struct input_value *end = vals;
|
|
struct input_value *v;
|
|
|
|
if (handler->filter) {
|
|
for (v = vals; v != vals + count; v++) {
|
|
if (handler->filter(handle, v->type, v->code, v->value))
|
|
continue;
|
|
if (end != v)
|
|
*end = *v;
|
|
end++;
|
|
}
|
|
count = end - vals;
|
|
}
|
|
|
|
if (!count)
|
|
return 0;
|
|
|
|
if (handler->events)
|
|
handler->events(handle, vals, count);
|
|
else if (handler->event)
|
|
for (v = vals; v != vals + count; v++)
|
|
handler->event(handle, v->type, v->code, v->value);
|
|
|
|
return count;
|
|
}
|
|
|
|
/*
|
|
* Pass values first through all filters and then, if event has not been
|
|
* filtered out, through all open handles. This function is called with
|
|
* dev->event_lock held and interrupts disabled.
|
|
*/
|
|
static void input_pass_values(struct input_dev *dev,
|
|
struct input_value *vals, unsigned int count)
|
|
{
|
|
struct input_handle *handle;
|
|
struct input_value *v;
|
|
|
|
if (!count)
|
|
return;
|
|
|
|
rcu_read_lock();
|
|
|
|
handle = rcu_dereference(dev->grab);
|
|
if (handle) {
|
|
count = input_to_handler(handle, vals, count);
|
|
} else {
|
|
list_for_each_entry_rcu(handle, &dev->h_list, d_node)
|
|
if (handle->open) {
|
|
count = input_to_handler(handle, vals, count);
|
|
if (!count)
|
|
break;
|
|
}
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
/* trigger auto repeat for key events */
|
|
if (test_bit(EV_REP, dev->evbit) && test_bit(EV_KEY, dev->evbit)) {
|
|
for (v = vals; v != vals + count; v++) {
|
|
if (v->type == EV_KEY && v->value != 2) {
|
|
if (v->value)
|
|
input_start_autorepeat(dev, v->code);
|
|
else
|
|
input_stop_autorepeat(dev);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void input_pass_event(struct input_dev *dev,
|
|
unsigned int type, unsigned int code, int value)
|
|
{
|
|
struct input_value vals[] = { { type, code, value } };
|
|
|
|
input_pass_values(dev, vals, ARRAY_SIZE(vals));
|
|
}
|
|
|
|
/*
|
|
* Generate software autorepeat event. Note that we take
|
|
* dev->event_lock here to avoid racing with input_event
|
|
* which may cause keys get "stuck".
|
|
*/
|
|
static void input_repeat_key(unsigned long data)
|
|
{
|
|
struct input_dev *dev = (void *) data;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
|
|
if (test_bit(dev->repeat_key, dev->key) &&
|
|
is_event_supported(dev->repeat_key, dev->keybit, KEY_MAX)) {
|
|
struct input_value vals[] = {
|
|
{ EV_KEY, dev->repeat_key, 2 },
|
|
input_value_sync
|
|
};
|
|
|
|
input_pass_values(dev, vals, ARRAY_SIZE(vals));
|
|
|
|
if (dev->rep[REP_PERIOD])
|
|
mod_timer(&dev->timer, jiffies +
|
|
msecs_to_jiffies(dev->rep[REP_PERIOD]));
|
|
}
|
|
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
}
|
|
|
|
#define INPUT_IGNORE_EVENT 0
|
|
#define INPUT_PASS_TO_HANDLERS 1
|
|
#define INPUT_PASS_TO_DEVICE 2
|
|
#define INPUT_SLOT 4
|
|
#define INPUT_FLUSH 8
|
|
#define INPUT_PASS_TO_ALL (INPUT_PASS_TO_HANDLERS | INPUT_PASS_TO_DEVICE)
|
|
|
|
static int input_handle_abs_event(struct input_dev *dev,
|
|
unsigned int code, int *pval)
|
|
{
|
|
struct input_mt *mt = dev->mt;
|
|
bool is_mt_event;
|
|
int *pold;
|
|
|
|
if (code == ABS_MT_SLOT) {
|
|
/*
|
|
* "Stage" the event; we'll flush it later, when we
|
|
* get actual touch data.
|
|
*/
|
|
if (mt && *pval >= 0 && *pval < mt->num_slots)
|
|
mt->slot = *pval;
|
|
|
|
return INPUT_IGNORE_EVENT;
|
|
}
|
|
|
|
is_mt_event = input_is_mt_value(code);
|
|
|
|
if (!is_mt_event) {
|
|
pold = &dev->absinfo[code].value;
|
|
} else if (mt) {
|
|
pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST];
|
|
} else {
|
|
/*
|
|
* Bypass filtering for multi-touch events when
|
|
* not employing slots.
|
|
*/
|
|
pold = NULL;
|
|
}
|
|
|
|
if (pold) {
|
|
*pval = input_defuzz_abs_event(*pval, *pold,
|
|
dev->absinfo[code].fuzz);
|
|
if (*pold == *pval)
|
|
return INPUT_IGNORE_EVENT;
|
|
|
|
*pold = *pval;
|
|
}
|
|
|
|
/* Flush pending "slot" event */
|
|
if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) {
|
|
input_abs_set_val(dev, ABS_MT_SLOT, mt->slot);
|
|
return INPUT_PASS_TO_HANDLERS | INPUT_SLOT;
|
|
}
|
|
|
|
return INPUT_PASS_TO_HANDLERS;
|
|
}
|
|
|
|
static int input_get_disposition(struct input_dev *dev,
|
|
unsigned int type, unsigned int code, int *pval)
|
|
{
|
|
int disposition = INPUT_IGNORE_EVENT;
|
|
int value = *pval;
|
|
|
|
switch (type) {
|
|
|
|
case EV_SYN:
|
|
switch (code) {
|
|
case SYN_CONFIG:
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
break;
|
|
|
|
case SYN_REPORT:
|
|
disposition = INPUT_PASS_TO_HANDLERS | INPUT_FLUSH;
|
|
break;
|
|
case SYN_MT_REPORT:
|
|
disposition = INPUT_PASS_TO_HANDLERS;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case EV_KEY:
|
|
if (is_event_supported(code, dev->keybit, KEY_MAX)) {
|
|
|
|
/* auto-repeat bypasses state updates */
|
|
if (value == 2) {
|
|
disposition = INPUT_PASS_TO_HANDLERS;
|
|
break;
|
|
}
|
|
|
|
if (!!test_bit(code, dev->key) != !!value) {
|
|
|
|
__change_bit(code, dev->key);
|
|
disposition = INPUT_PASS_TO_HANDLERS;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case EV_SW:
|
|
if (is_event_supported(code, dev->swbit, SW_MAX) &&
|
|
!!test_bit(code, dev->sw) != !!value) {
|
|
|
|
__change_bit(code, dev->sw);
|
|
disposition = INPUT_PASS_TO_HANDLERS;
|
|
}
|
|
break;
|
|
|
|
case EV_ABS:
|
|
if (is_event_supported(code, dev->absbit, ABS_MAX))
|
|
disposition = input_handle_abs_event(dev, code, &value);
|
|
|
|
break;
|
|
|
|
case EV_REL:
|
|
if (is_event_supported(code, dev->relbit, REL_MAX) && value)
|
|
disposition = INPUT_PASS_TO_HANDLERS;
|
|
|
|
break;
|
|
|
|
case EV_MSC:
|
|
if (is_event_supported(code, dev->mscbit, MSC_MAX))
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
|
|
break;
|
|
|
|
case EV_LED:
|
|
if (is_event_supported(code, dev->ledbit, LED_MAX) &&
|
|
!!test_bit(code, dev->led) != !!value) {
|
|
|
|
__change_bit(code, dev->led);
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
}
|
|
break;
|
|
|
|
case EV_SND:
|
|
if (is_event_supported(code, dev->sndbit, SND_MAX)) {
|
|
|
|
if (!!test_bit(code, dev->snd) != !!value)
|
|
__change_bit(code, dev->snd);
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
}
|
|
break;
|
|
|
|
case EV_REP:
|
|
if (code <= REP_MAX && value >= 0 && dev->rep[code] != value) {
|
|
dev->rep[code] = value;
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
}
|
|
break;
|
|
|
|
case EV_FF:
|
|
if (value >= 0)
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
break;
|
|
|
|
case EV_PWR:
|
|
disposition = INPUT_PASS_TO_ALL;
|
|
break;
|
|
}
|
|
|
|
*pval = value;
|
|
return disposition;
|
|
}
|
|
|
|
static void input_handle_event(struct input_dev *dev,
|
|
unsigned int type, unsigned int code, int value)
|
|
{
|
|
int disposition = input_get_disposition(dev, type, code, &value);
|
|
|
|
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
|
|
add_input_randomness(type, code, value);
|
|
|
|
if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
|
|
dev->event(dev, type, code, value);
|
|
|
|
if (!dev->vals)
|
|
return;
|
|
|
|
if (disposition & INPUT_PASS_TO_HANDLERS) {
|
|
struct input_value *v;
|
|
|
|
if (disposition & INPUT_SLOT) {
|
|
v = &dev->vals[dev->num_vals++];
|
|
v->type = EV_ABS;
|
|
v->code = ABS_MT_SLOT;
|
|
v->value = dev->mt->slot;
|
|
}
|
|
|
|
v = &dev->vals[dev->num_vals++];
|
|
v->type = type;
|
|
v->code = code;
|
|
v->value = value;
|
|
}
|
|
|
|
if (disposition & INPUT_FLUSH) {
|
|
if (dev->num_vals >= 2)
|
|
input_pass_values(dev, dev->vals, dev->num_vals);
|
|
dev->num_vals = 0;
|
|
} else if (dev->num_vals >= dev->max_vals - 2) {
|
|
dev->vals[dev->num_vals++] = input_value_sync;
|
|
input_pass_values(dev, dev->vals, dev->num_vals);
|
|
dev->num_vals = 0;
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* input_event() - report new input event
|
|
* @dev: device that generated the event
|
|
* @type: type of the event
|
|
* @code: event code
|
|
* @value: value of the event
|
|
*
|
|
* 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_event(struct input_dev *dev,
|
|
unsigned int type, unsigned int code, int value)
|
|
{
|
|
unsigned long flags;
|
|
|
|
if (is_event_supported(type, dev->evbit, EV_MAX)) {
|
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
input_handle_event(dev, type, code, value);
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(input_event);
|
|
|
|
/**
|
|
* input_inject_event() - send input event from input handler
|
|
* @handle: input handle to send event through
|
|
* @type: type of the event
|
|
* @code: event code
|
|
* @value: value of the event
|
|
*
|
|
* Similar to input_event() but will ignore event if device is
|
|
* "grabbed" and handle injecting event is not the one that owns
|
|
* the device.
|
|
*/
|
|
void input_inject_event(struct input_handle *handle,
|
|
unsigned int type, unsigned int code, int value)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
struct input_handle *grab;
|
|
unsigned long flags;
|
|
|
|
if (is_event_supported(type, dev->evbit, EV_MAX)) {
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
|
|
rcu_read_lock();
|
|
grab = rcu_dereference(dev->grab);
|
|
if (!grab || grab == handle)
|
|
input_handle_event(dev, type, code, value);
|
|
rcu_read_unlock();
|
|
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(input_inject_event);
|
|
|
|
/**
|
|
* input_alloc_absinfo - allocates array of input_absinfo structs
|
|
* @dev: the input device emitting absolute events
|
|
*
|
|
* If the absinfo struct the caller asked for is already allocated, this
|
|
* functions will not do anything.
|
|
*/
|
|
void input_alloc_absinfo(struct input_dev *dev)
|
|
{
|
|
if (!dev->absinfo)
|
|
dev->absinfo = kcalloc(ABS_CNT, sizeof(struct input_absinfo),
|
|
GFP_KERNEL);
|
|
|
|
WARN(!dev->absinfo, "%s(): kcalloc() failed?\n", __func__);
|
|
}
|
|
EXPORT_SYMBOL(input_alloc_absinfo);
|
|
|
|
void input_set_abs_params(struct input_dev *dev, unsigned int axis,
|
|
int min, int max, int fuzz, int flat)
|
|
{
|
|
struct input_absinfo *absinfo;
|
|
|
|
input_alloc_absinfo(dev);
|
|
if (!dev->absinfo)
|
|
return;
|
|
|
|
absinfo = &dev->absinfo[axis];
|
|
absinfo->minimum = min;
|
|
absinfo->maximum = max;
|
|
absinfo->fuzz = fuzz;
|
|
absinfo->flat = flat;
|
|
|
|
__set_bit(EV_ABS, dev->evbit);
|
|
__set_bit(axis, dev->absbit);
|
|
}
|
|
EXPORT_SYMBOL(input_set_abs_params);
|
|
|
|
|
|
/**
|
|
* input_grab_device - grabs device for exclusive use
|
|
* @handle: input handle that wants to own the device
|
|
*
|
|
* 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.
|
|
*/
|
|
int input_grab_device(struct input_handle *handle)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
int retval;
|
|
|
|
retval = mutex_lock_interruptible(&dev->mutex);
|
|
if (retval)
|
|
return retval;
|
|
|
|
if (dev->grab) {
|
|
retval = -EBUSY;
|
|
goto out;
|
|
}
|
|
|
|
rcu_assign_pointer(dev->grab, handle);
|
|
|
|
out:
|
|
mutex_unlock(&dev->mutex);
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(input_grab_device);
|
|
|
|
static void __input_release_device(struct input_handle *handle)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
struct input_handle *grabber;
|
|
|
|
grabber = rcu_dereference_protected(dev->grab,
|
|
lockdep_is_held(&dev->mutex));
|
|
if (grabber == handle) {
|
|
rcu_assign_pointer(dev->grab, NULL);
|
|
/* Make sure input_pass_event() notices that grab is gone */
|
|
synchronize_rcu();
|
|
|
|
list_for_each_entry(handle, &dev->h_list, d_node)
|
|
if (handle->open && handle->handler->start)
|
|
handle->handler->start(handle);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* input_release_device - release previously grabbed device
|
|
* @handle: input handle that owns the device
|
|
*
|
|
* 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.
|
|
*/
|
|
void input_release_device(struct input_handle *handle)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
|
|
mutex_lock(&dev->mutex);
|
|
__input_release_device(handle);
|
|
mutex_unlock(&dev->mutex);
|
|
}
|
|
EXPORT_SYMBOL(input_release_device);
|
|
|
|
/**
|
|
* input_open_device - open input device
|
|
* @handle: handle through which device is being accessed
|
|
*
|
|
* This function should be called by input handlers when they
|
|
* want to start receive events from given input device.
|
|
*/
|
|
int input_open_device(struct input_handle *handle)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
int retval;
|
|
|
|
retval = mutex_lock_interruptible(&dev->mutex);
|
|
if (retval)
|
|
return retval;
|
|
|
|
if (dev->going_away) {
|
|
retval = -ENODEV;
|
|
goto out;
|
|
}
|
|
|
|
handle->open++;
|
|
|
|
if (!dev->users++ && dev->open)
|
|
retval = dev->open(dev);
|
|
|
|
if (retval) {
|
|
dev->users--;
|
|
if (!--handle->open) {
|
|
/*
|
|
* Make sure we are not delivering any more events
|
|
* through this handle
|
|
*/
|
|
synchronize_rcu();
|
|
}
|
|
}
|
|
|
|
out:
|
|
mutex_unlock(&dev->mutex);
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(input_open_device);
|
|
|
|
int input_flush_device(struct input_handle *handle, struct file *file)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
int retval;
|
|
|
|
retval = mutex_lock_interruptible(&dev->mutex);
|
|
if (retval)
|
|
return retval;
|
|
|
|
if (dev->flush)
|
|
retval = dev->flush(dev, file);
|
|
|
|
mutex_unlock(&dev->mutex);
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(input_flush_device);
|
|
|
|
/**
|
|
* input_close_device - close input device
|
|
* @handle: handle through which device is being accessed
|
|
*
|
|
* This function should be called by input handlers when they
|
|
* want to stop receive events from given input device.
|
|
*/
|
|
void input_close_device(struct input_handle *handle)
|
|
{
|
|
struct input_dev *dev = handle->dev;
|
|
|
|
mutex_lock(&dev->mutex);
|
|
|
|
__input_release_device(handle);
|
|
|
|
if (!--dev->users && dev->close)
|
|
dev->close(dev);
|
|
|
|
if (!--handle->open) {
|
|
/*
|
|
* synchronize_rcu() makes sure that input_pass_event()
|
|
* completed and that no more input events are delivered
|
|
* through this handle
|
|
*/
|
|
synchronize_rcu();
|
|
}
|
|
|
|
mutex_unlock(&dev->mutex);
|
|
}
|
|
EXPORT_SYMBOL(input_close_device);
|
|
|
|
/*
|
|
* Simulate keyup events for all keys that are marked as pressed.
|
|
* The function must be called with dev->event_lock held.
|
|
*/
|
|
static void input_dev_release_keys(struct input_dev *dev)
|
|
{
|
|
bool need_sync = false;
|
|
int code;
|
|
|
|
if (is_event_supported(EV_KEY, dev->evbit, EV_MAX)) {
|
|
for_each_set_bit(code, dev->key, KEY_CNT) {
|
|
input_pass_event(dev, EV_KEY, code, 0);
|
|
need_sync = true;
|
|
}
|
|
|
|
if (need_sync)
|
|
input_pass_event(dev, EV_SYN, SYN_REPORT, 1);
|
|
|
|
memset(dev->key, 0, sizeof(dev->key));
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Prepare device for unregistering
|
|
*/
|
|
static void input_disconnect_device(struct input_dev *dev)
|
|
{
|
|
struct input_handle *handle;
|
|
|
|
/*
|
|
* Mark device as going away. Note that we take dev->mutex here
|
|
* not to protect access to dev->going_away but rather to ensure
|
|
* that there are no threads in the middle of input_open_device()
|
|
*/
|
|
mutex_lock(&dev->mutex);
|
|
dev->going_away = true;
|
|
mutex_unlock(&dev->mutex);
|
|
|
|
spin_lock_irq(&dev->event_lock);
|
|
|
|
/*
|
|
* Simulate keyup events for all pressed keys so that handlers
|
|
* are not left with "stuck" keys. The driver may continue
|
|
* generate events even after we done here but they will not
|
|
* reach any handlers.
|
|
*/
|
|
input_dev_release_keys(dev);
|
|
|
|
list_for_each_entry(handle, &dev->h_list, d_node)
|
|
handle->open = 0;
|
|
|
|
spin_unlock_irq(&dev->event_lock);
|
|
}
|
|
|
|
/**
|
|
* input_scancode_to_scalar() - converts scancode in &struct input_keymap_entry
|
|
* @ke: keymap entry containing scancode to be converted.
|
|
* @scancode: pointer to the location where converted scancode should
|
|
* be stored.
|
|
*
|
|
* 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_scancode_to_scalar(const struct input_keymap_entry *ke,
|
|
unsigned int *scancode)
|
|
{
|
|
switch (ke->len) {
|
|
case 1:
|
|
*scancode = *((u8 *)ke->scancode);
|
|
break;
|
|
|
|
case 2:
|
|
*scancode = *((u16 *)ke->scancode);
|
|
break;
|
|
|
|
case 4:
|
|
*scancode = *((u32 *)ke->scancode);
|
|
break;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(input_scancode_to_scalar);
|
|
|
|
/*
|
|
* Those routines handle the default case where no [gs]etkeycode() is
|
|
* defined. In this case, an array indexed by the scancode is used.
|
|
*/
|
|
|
|
static unsigned int input_fetch_keycode(struct input_dev *dev,
|
|
unsigned int index)
|
|
{
|
|
switch (dev->keycodesize) {
|
|
case 1:
|
|
return ((u8 *)dev->keycode)[index];
|
|
|
|
case 2:
|
|
return ((u16 *)dev->keycode)[index];
|
|
|
|
default:
|
|
return ((u32 *)dev->keycode)[index];
|
|
}
|
|
}
|
|
|
|
static int input_default_getkeycode(struct input_dev *dev,
|
|
struct input_keymap_entry *ke)
|
|
{
|
|
unsigned int index;
|
|
int error;
|
|
|
|
if (!dev->keycodesize)
|
|
return -EINVAL;
|
|
|
|
if (ke->flags & INPUT_KEYMAP_BY_INDEX)
|
|
index = ke->index;
|
|
else {
|
|
error = input_scancode_to_scalar(ke, &index);
|
|
if (error)
|
|
return error;
|
|
}
|
|
|
|
if (index >= dev->keycodemax)
|
|
return -EINVAL;
|
|
|
|
ke->keycode = input_fetch_keycode(dev, index);
|
|
ke->index = index;
|
|
ke->len = sizeof(index);
|
|
memcpy(ke->scancode, &index, sizeof(index));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int input_default_setkeycode(struct input_dev *dev,
|
|
const struct input_keymap_entry *ke,
|
|
unsigned int *old_keycode)
|
|
{
|
|
unsigned int index;
|
|
int error;
|
|
int i;
|
|
|
|
if (!dev->keycodesize)
|
|
return -EINVAL;
|
|
|
|
if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
|
|
index = ke->index;
|
|
} else {
|
|
error = input_scancode_to_scalar(ke, &index);
|
|
if (error)
|
|
return error;
|
|
}
|
|
|
|
if (index >= dev->keycodemax)
|
|
return -EINVAL;
|
|
|
|
if (dev->keycodesize < sizeof(ke->keycode) &&
|
|
(ke->keycode >> (dev->keycodesize * 8)))
|
|
return -EINVAL;
|
|
|
|
switch (dev->keycodesize) {
|
|
case 1: {
|
|
u8 *k = (u8 *)dev->keycode;
|
|
*old_keycode = k[index];
|
|
k[index] = ke->keycode;
|
|
break;
|
|
}
|
|
case 2: {
|
|
u16 *k = (u16 *)dev->keycode;
|
|
*old_keycode = k[index];
|
|
k[index] = ke->keycode;
|
|
break;
|
|
}
|
|
default: {
|
|
u32 *k = (u32 *)dev->keycode;
|
|
*old_keycode = k[index];
|
|
k[index] = ke->keycode;
|
|
break;
|
|
}
|
|
}
|
|
|
|
__clear_bit(*old_keycode, dev->keybit);
|
|
__set_bit(ke->keycode, dev->keybit);
|
|
|
|
for (i = 0; i < dev->keycodemax; i++) {
|
|
if (input_fetch_keycode(dev, i) == *old_keycode) {
|
|
__set_bit(*old_keycode, dev->keybit);
|
|
break; /* Setting the bit twice is useless, so break */
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* input_get_keycode - retrieve keycode currently mapped to a given scancode
|
|
* @dev: input device which keymap is being queried
|
|
* @ke: keymap entry
|
|
*
|
|
* This function should be called by anyone interested in retrieving current
|
|
* keymap. Presently evdev handlers use it.
|
|
*/
|
|
int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke)
|
|
{
|
|
unsigned long flags;
|
|
int retval;
|
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
retval = dev->getkeycode(dev, ke);
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(input_get_keycode);
|
|
|
|
/**
|
|
* input_set_keycode - attribute a keycode to a given scancode
|
|
* @dev: input device which keymap is being updated
|
|
* @ke: new keymap entry
|
|
*
|
|
* This function should be called by anyone needing to update current
|
|
* keymap. Presently keyboard and evdev handlers use it.
|
|
*/
|
|
int input_set_keycode(struct input_dev *dev,
|
|
const struct input_keymap_entry *ke)
|
|
{
|
|
unsigned long flags;
|
|
unsigned int old_keycode;
|
|
int retval;
|
|
|
|
if (ke->keycode > KEY_MAX)
|
|
return -EINVAL;
|
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
|
|
|
retval = dev->setkeycode(dev, ke, &old_keycode);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/* Make sure KEY_RESERVED did not get enabled. */
|
|
__clear_bit(KEY_RESERVED, dev->keybit);
|
|
|
|
/*
|
|
* Simulate keyup event if keycode is not present
|
|
* in the keymap anymore
|
|
*/
|
|
if (test_bit(EV_KEY, dev->evbit) &&
|
|
!is_event_supported(old_keycode, dev->keybit, KEY_MAX) &&
|
|
__test_and_clear_bit(old_keycode, dev->key)) {
|
|
struct input_value vals[] = {
|
|
{ EV_KEY, old_keycode, 0 },
|
|
input_value_sync
|
|
};
|
|
|
|
input_pass_values(dev, vals, ARRAY_SIZE(vals));
|
|
}
|
|
|
|
out:
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
|
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(input_set_keycode);
|
|
|
|
static const struct input_device_id *input_match_device(struct input_handler *handler,
|
|
struct input_dev *dev)
|
|
{
|
|
const struct input_device_id *id;
|
|
|
|
for (id = handler->id_table; id->flags || id->driver_info; id++) {
|
|
|
|
if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
|
|
if (id->bustype != dev->id.bustype)
|
|
continue;
|
|
|
|
if (id->flags & INPUT_DEVICE_ID_MATCH_VENDOR)
|
|
if (id->vendor != dev->id.vendor)
|
|
continue;
|
|
|
|
if (id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT)
|
|
if (id->product != dev->id.product)
|
|
continue;
|
|
|
|
if (id->flags & INPUT_DEVICE_ID_MATCH_VERSION)
|
|
if (id->version != dev->id.version)
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->evbit, dev->evbit, EV_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->keybit, dev->keybit, KEY_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->relbit, dev->relbit, REL_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->absbit, dev->absbit, ABS_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->mscbit, dev->mscbit, MSC_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->ledbit, dev->ledbit, LED_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->sndbit, dev->sndbit, SND_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->ffbit, dev->ffbit, FF_MAX))
|
|
continue;
|
|
|
|
if (!bitmap_subset(id->swbit, dev->swbit, SW_MAX))
|
|
continue;
|
|
|
|
if (!handler->match || handler->match(handler, dev))
|
|
return id;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static int input_attach_handler(struct input_dev *dev, struct input_handler *handler)
|
|
{
|
|
const struct input_device_id *id;
|
|
int error;
|
|
|
|
id = input_match_device(handler, dev);
|
|
if (!id)
|
|
return -ENODEV;
|
|
|
|
error = handler->connect(handler, dev, id);
|
|
if (error && error != -ENODEV)
|
|
pr_err("failed to attach handler %s to device %s, error: %d\n",
|
|
handler->name, kobject_name(&dev->dev.kobj), error);
|
|
|
|
return error;
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static int input_bits_to_string(char *buf, int buf_size,
|
|
unsigned long bits, bool skip_empty)
|
|
{
|
|
int len = 0;
|
|
|
|
if (in_compat_syscall()) {
|
|
u32 dword = bits >> 32;
|
|
if (dword || !skip_empty)
|
|
len += snprintf(buf, buf_size, "%x ", dword);
|
|
|
|
dword = bits & 0xffffffffUL;
|
|
if (dword || !skip_empty || len)
|
|
len += snprintf(buf + len, max(buf_size - len, 0),
|
|
"%x", dword);
|
|
} else {
|
|
if (bits || !skip_empty)
|
|
len += snprintf(buf, buf_size, "%lx", bits);
|
|
}
|
|
|
|
return len;
|
|
}
|
|
|
|
#else /* !CONFIG_COMPAT */
|
|
|
|
static int input_bits_to_string(char *buf, int buf_size,
|
|
unsigned long bits, bool skip_empty)
|
|
{
|
|
return bits || !skip_empty ?
|
|
snprintf(buf, buf_size, "%lx", bits) : 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
static struct proc_dir_entry *proc_bus_input_dir;
|
|
static DECLARE_WAIT_QUEUE_HEAD(input_devices_poll_wait);
|
|
static int input_devices_state;
|
|
|
|
static inline void input_wakeup_procfs_readers(void)
|
|
{
|
|
input_devices_state++;
|
|
wake_up(&input_devices_poll_wait);
|
|
}
|
|
|
|
static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
|
|
{
|
|
poll_wait(file, &input_devices_poll_wait, wait);
|
|
if (file->f_version != input_devices_state) {
|
|
file->f_version = input_devices_state;
|
|
return POLLIN | POLLRDNORM;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
union input_seq_state {
|
|
struct {
|
|
unsigned short pos;
|
|
bool mutex_acquired;
|
|
};
|
|
void *p;
|
|
};
|
|
|
|
static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
|
|
{
|
|
union input_seq_state *state = (union input_seq_state *)&seq->private;
|
|
int error;
|
|
|
|
/* We need to fit into seq->private pointer */
|
|
BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
|
|
|
|
error = mutex_lock_interruptible(&input_mutex);
|
|
if (error) {
|
|
state->mutex_acquired = false;
|
|
return ERR_PTR(error);
|
|
}
|
|
|
|
state->mutex_acquired = true;
|
|
|
|
return seq_list_start(&input_dev_list, *pos);
|
|
}
|
|
|
|
static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
{
|
|
return seq_list_next(v, &input_dev_list, pos);
|
|
}
|
|
|
|
static void input_seq_stop(struct seq_file *seq, void *v)
|
|
{
|
|
union input_seq_state *state = (union input_seq_state *)&seq->private;
|
|
|
|
if (state->mutex_acquired)
|
|
mutex_unlock(&input_mutex);
|
|
}
|
|
|
|
static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
|
|
unsigned long *bitmap, int max)
|
|
{
|
|
int i;
|
|
bool skip_empty = true;
|
|
char buf[18];
|
|
|
|
seq_printf(seq, "B: %s=", name);
|
|
|
|
for (i = BITS_TO_LONGS(max) - 1; i >= 0; i--) {
|
|
if (input_bits_to_string(buf, sizeof(buf),
|
|
bitmap[i], skip_empty)) {
|
|
skip_empty = false;
|
|
seq_printf(seq, "%s%s", buf, i > 0 ? " " : "");
|
|
}
|
|
}
|
|
|
|
/*
|
|
* If no output was produced print a single 0.
|
|
*/
|
|
if (skip_empty)
|
|
seq_puts(seq, "0");
|
|
|
|
seq_putc(seq, '\n');
|
|
}
|
|
|
|
static int input_devices_seq_show(struct seq_file *seq, void *v)
|
|
{
|
|
struct input_dev *dev = container_of(v, struct input_dev, node);
|
|
const char *path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
|
|
struct input_handle *handle;
|
|
|
|
seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
|
|
dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
|
|
|
|
seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
|
|
seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
|
|
seq_printf(seq, "S: Sysfs=%s\n", path ? path : "");
|
|
seq_printf(seq, "U: Uniq=%s\n", dev->uniq ? dev->uniq : "");
|
|
seq_printf(seq, "H: Handlers=");
|
|
|
|
list_for_each_entry(handle, &dev->h_list, d_node)
|
|
seq_printf(seq, "%s ", handle->name);
|
|
seq_putc(seq, '\n');
|
|
|
|
input_seq_print_bitmap(seq, "PROP", dev->propbit, INPUT_PROP_MAX);
|
|
|
|
input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
|
|
if (test_bit(EV_KEY, dev->evbit))
|
|
input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
|
|
if (test_bit(EV_REL, dev->evbit))
|
|
input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
|
|
if (test_bit(EV_ABS, dev->evbit))
|
|
input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
|
|
if (test_bit(EV_MSC, dev->evbit))
|
|
input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
|
|
if (test_bit(EV_LED, dev->evbit))
|
|
input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
|
|
if (test_bit(EV_SND, dev->evbit))
|
|
input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
|
|
if (test_bit(EV_FF, dev->evbit))
|
|
input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
|
|
if (test_bit(EV_SW, dev->evbit))
|
|
input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
|
|
|
|
seq_putc(seq, '\n');
|
|
|
|
kfree(path);
|
|
return 0;
|
|
}
|
|
|
|
static const struct seq_operations input_devices_seq_ops = {
|
|
.start = input_devices_seq_start,
|
|
.next = input_devices_seq_next,
|
|
.stop = input_seq_stop,
|
|
.show = input_devices_seq_show,
|
|
};
|
|
|
|
static int input_proc_devices_open(struct inode *inode, struct file *file)
|
|
{
|
|
return seq_open(file, &input_devices_seq_ops);
|
|
}
|
|
|
|
static const struct file_operations input_devices_fileops = {
|
|
.owner = THIS_MODULE,
|
|
.open = input_proc_devices_open,
|
|
.poll = input_proc_devices_poll,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
|
|
{
|
|
union input_seq_state *state = (union input_seq_state *)&seq->private;
|
|
int error;
|
|
|
|
/* We need to fit into seq->private pointer */
|
|
BUILD_BUG_ON(sizeof(union input_seq_state) != sizeof(seq->private));
|
|
|
|
error = mutex_lock_interruptible(&input_mutex);
|
|
if (error) {
|
|
state->mutex_acquired = false;
|
|
return ERR_PTR(error);
|
|
}
|
|
|
|
state->mutex_acquired = true;
|
|
state->pos = *pos;
|
|
|
|
return seq_list_start(&input_handler_list, *pos);
|
|
}
|
|
|
|
static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
{
|
|
union input_seq_state *state = (union input_seq_state *)&seq->private;
|
|
|
|
state->pos = *pos + 1;
|
|
return seq_list_next(v, &input_handler_list, pos);
|
|
}
|
|
|
|
static int input_handlers_seq_show(struct seq_file *seq, void *v)
|
|
{
|
|
struct input_handler *handler = container_of(v, struct input_handler, node);
|
|
union input_seq_state *state = (union input_seq_state *)&seq->private;
|
|
|
|
seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
|
|
if (handler->filter)
|
|
seq_puts(seq, " (filter)");
|
|
if (handler->legacy_minors)
|
|
seq_printf(seq, " Minor=%d", handler->minor);
|
|
seq_putc(seq, '\n');
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct seq_operations input_handlers_seq_ops = {
|
|
.start = input_handlers_seq_start,
|
|
.next = input_handlers_seq_next,
|
|
.stop = input_seq_stop,
|
|
.show = input_handlers_seq_show,
|
|
};
|
|
|
|
static int input_proc_handlers_open(struct inode *inode, struct file *file)
|
|
{
|
|
return seq_open(file, &input_handlers_seq_ops);
|
|
}
|
|
|
|
static const struct file_operations input_handlers_fileops = {
|
|
.owner = THIS_MODULE,
|
|
.open = input_proc_handlers_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release,
|
|
};
|
|
|
|
static int __init input_proc_init(void)
|
|
{
|
|
struct proc_dir_entry *entry;
|
|
|
|
proc_bus_input_dir = proc_mkdir("bus/input", NULL);
|
|
if (!proc_bus_input_dir)
|
|
return -ENOMEM;
|
|
|
|
entry = proc_create("devices", 0, proc_bus_input_dir,
|
|
&input_devices_fileops);
|
|
if (!entry)
|
|
goto fail1;
|
|
|
|
entry = proc_create("handlers", 0, proc_bus_input_dir,
|
|
&input_handlers_fileops);
|
|
if (!entry)
|
|
goto fail2;
|
|
|
|
return 0;
|
|
|
|
fail2: remove_proc_entry("devices", proc_bus_input_dir);
|
|
fail1: remove_proc_entry("bus/input", NULL);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static void input_proc_exit(void)
|
|
{
|
|
remove_proc_entry("devices", proc_bus_input_dir);
|
|
remove_proc_entry("handlers", proc_bus_input_dir);
|
|
remove_proc_entry("bus/input", NULL);
|
|
}
|
|
|
|
#else /* !CONFIG_PROC_FS */
|
|
static inline void input_wakeup_procfs_readers(void) { }
|
|
static inline int input_proc_init(void) { return 0; }
|
|
static inline void input_proc_exit(void) { }
|
|
#endif
|
|
|
|
#define INPUT_DEV_STRING_ATTR_SHOW(name) \
|
|
static ssize_t input_dev_show_##name(struct device *dev, \
|
|
struct device_attribute *attr, \
|
|
char *buf) \
|
|
{ \
|
|
struct input_dev *input_dev = to_input_dev(dev); \
|
|
\
|
|
return scnprintf(buf, PAGE_SIZE, "%s\n", \
|
|
input_dev->name ? input_dev->name : ""); \
|
|
} \
|
|
static DEVICE_ATTR(name, S_IRUGO, input_dev_show_##name, NULL)
|
|
|
|
INPUT_DEV_STRING_ATTR_SHOW(name);
|
|
INPUT_DEV_STRING_ATTR_SHOW(phys);
|
|
INPUT_DEV_STRING_ATTR_SHOW(uniq);
|
|
|
|
static int input_print_modalias_bits(char *buf, int size,
|
|
char name, unsigned long *bm,
|
|
unsigned int min_bit, unsigned int max_bit)
|
|
{
|
|
int len = 0, i;
|
|
|
|
len += snprintf(buf, max(size, 0), "%c", name);
|
|
for (i = min_bit; i < max_bit; i++)
|
|
if (bm[BIT_WORD(i)] & BIT_MASK(i))
|
|
len += snprintf(buf + len, max(size - len, 0), "%X,", i);
|
|
return len;
|
|
}
|
|
|
|
static int input_print_modalias(char *buf, int size, struct input_dev *id,
|
|
int add_cr)
|
|
{
|
|
int len;
|
|
|
|
len = snprintf(buf, max(size, 0),
|
|
"input:b%04Xv%04Xp%04Xe%04X-",
|
|
id->id.bustype, id->id.vendor,
|
|
id->id.product, id->id.version);
|
|
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'e', id->evbit, 0, EV_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'r', id->relbit, 0, REL_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'a', id->absbit, 0, ABS_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'm', id->mscbit, 0, MSC_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'l', id->ledbit, 0, LED_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
's', id->sndbit, 0, SND_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'f', id->ffbit, 0, FF_MAX);
|
|
len += input_print_modalias_bits(buf + len, size - len,
|
|
'w', id->swbit, 0, SW_MAX);
|
|
|
|
if (add_cr)
|
|
len += snprintf(buf + len, max(size - len, 0), "\n");
|
|
|
|
return len;
|
|
}
|
|
|
|
static ssize_t input_dev_show_modalias(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct input_dev *id = to_input_dev(dev);
|
|
ssize_t len;
|
|
|
|
len = input_print_modalias(buf, PAGE_SIZE, id, 1);
|
|
|
|
return min_t(int, len, PAGE_SIZE);
|
|
}
|
|
static DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
|
|
|
|
static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
|
|
int max, int add_cr);
|
|
|
|
static ssize_t input_dev_show_properties(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct input_dev *input_dev = to_input_dev(dev);
|
|
int len = input_print_bitmap(buf, PAGE_SIZE, input_dev->propbit,
|
|
INPUT_PROP_MAX |