Input: factor out and export input_device_id matching code
Subsystems (3)
Dmitry Torokhov
maintainerPATCH 1/3 Input: factor out and export input_device_id matching code
Factor out and export input_match_device_id() so that modules may use it. It will be needed by joydev to blacklist accelerometers in composite devices.
Signed-off-by Dmitry Torokhov <[email protected]>
--- drivers/input/input.c | 83 +++++++++++++++++++++++---------------------------- include/linux/input.h | 3 ++ 2 files changed, 41 insertions(+), 45 deletions(-)
drivers/input/input.c +38 -45
@@ -938,58 +938,51 @@ int input_set_keycode(struct input_dev *dev, }EXPORT_SYMBOL (input_set_keycode); +bool input_match_device_id (const struct input_dev *dev, +const struct input_device_id *id) +{ +if (id->flags &INPUT_DEVICE_ID_MATCH_BUS ) +if (id->bustype != dev->id.bustype) +return false; + +if (id->flags &INPUT_DEVICE_ID_MATCH_VENDOR ) +if (id->vendor != dev->id.vendor) +return false; + +if (id->flags &INPUT_DEVICE_ID_MATCH_PRODUCT ) +if (id->product != dev->id.product) +return false; + +if (id->flags &INPUT_DEVICE_ID_MATCH_VERSION ) +if (id->version != dev->id.version) +return false; + +if (!bitmap_subset (id->evbit, dev->evbit,EV_MAX ) || + !bitmap_subset (id->keybit, dev->keybit,KEY_MAX ) || + !bitmap_subset (id->relbit, dev->relbit,REL_MAX ) || + !bitmap_subset (id->absbit, dev->absbit,ABS_MAX ) || + !bitmap_subset (id->mscbit, dev->mscbit,MSC_MAX ) || + !bitmap_subset (id->ledbit, dev->ledbit,LED_MAX ) || + !bitmap_subset (id->sndbit, dev->sndbit,SND_MAX ) || + !bitmap_subset (id->ffbit, dev->ffbit,FF_MAX ) || + !bitmap_subset (id->swbit, dev->swbit,SW_MAX )) { +return false; + } + +return true; +} +EXPORT_SYMBOL (input_match_device_id); +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)) +if (input_match_device_id (dev, id) && + (!handler->match || handler->match (handler, dev))) {return id; + } }return NULL ;
include/linux/input.h +3 -0
@@ -477,6 +477,9 @@ int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke);int input_set_keycode (struct input_dev *dev,const struct input_keymap_entry *ke); +bool input_match_device_id (const struct input_dev *dev, +const struct input_device_id *id); +void input_enable_softrepeat (struct input_dev *dev,int delay,int period);extern struct class input_class;
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
Dmitry Torokhov
maintainerPATCH 2/3 Input: allow matching device IDs on property bits
Let's allow matching input devices on their property bits, both in-kernel and when generating module aliases.
Signed-off-by Dmitry Torokhov <[email protected]>
--- drivers/input/input.c | 3 ++- include/linux/input.h | 4 ++++ include/linux/mod_devicetable.h | 3 +++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 6 +++++- 5 files changed, 15 insertions(+), 2 deletions(-)
drivers/input/input.c +2 -1
@@ -965,7 +965,8 @@ bool input_match_device_id(const struct input_dev *dev, !bitmap_subset (id->ledbit, dev->ledbit,LED_MAX ) || !bitmap_subset (id->sndbit, dev->sndbit,SND_MAX ) || !bitmap_subset (id->ffbit, dev->ffbit,FF_MAX ) || - !bitmap_subset(id->swbit, dev->swbit, SW_MAX)) { + !bitmap_subset (id->swbit, dev->swbit,SW_MAX ) || + !bitmap_subset(id->propbit, dev->propbit, INPUT_PROP_MAX)) { return false; }
include/linux/input.h +4 -0
@@ -238,6 +238,10 @@ struct input_dev {#error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"#endif +#if INPUT_PROP_MAX !=INPUT_DEVICE_ID_PROP_MAX +#error "INPUT_PROP_MAX and INPUT_DEVICE_ID_PROP_MAX do not match" +#endif +#define INPUT_DEVICE_ID_MATCH_DEVICE \ (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)#define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
include/linux/mod_devicetable.h +3 -0
@@ -293,6 +293,7 @@ struct pcmcia_device_id {#define INPUT_DEVICE_ID_SND_MAX 0x07#define INPUT_DEVICE_ID_FF_MAX 0x7f#define INPUT_DEVICE_ID_SW_MAX 0x0f +#define INPUT_DEVICE_ID_PROP_MAX 0x1f#define INPUT_DEVICE_ID_MATCH_BUS 1#define INPUT_DEVICE_ID_MATCH_VENDOR 2
@@ -308,6 +309,7 @@ struct pcmcia_device_id {#define INPUT_DEVICE_ID_MATCH_SNDBIT 0x0400#define INPUT_DEVICE_ID_MATCH_FFBIT 0x0800#define INPUT_DEVICE_ID_MATCH_SWBIT 0x1000 +#define INPUT_DEVICE_ID_MATCH_PROPBIT 0x2000struct input_device_id {
@@ -327,6 +329,7 @@ struct input_device_id {kernel_ulong_t sndbit[INPUT_DEVICE_ID_SND_MAX /BITS_PER_LONG +1 ];kernel_ulong_t ffbit[INPUT_DEVICE_ID_FF_MAX /BITS_PER_LONG +1 ];kernel_ulong_t swbit[INPUT_DEVICE_ID_SW_MAX /BITS_PER_LONG +1 ]; +kernel_ulong_t propbit[INPUT_DEVICE_ID_PROP_MAX /BITS_PER_LONG +1 ];kernel_ulong_t driver_info; };
scripts/mod/devicetable-offsets.c +1 -0
@@ -105,6 +105,7 @@ int main(void)DEVID_FIELD (input_device_id, sndbit);DEVID_FIELD (input_device_id, ffbit);DEVID_FIELD (input_device_id, swbit); +DEVID_FIELD (input_device_id, propbit);DEVID (eisa_device_id);DEVID_FIELD (eisa_device_id, sig);
scripts/mod/file2alias.c +5 -1
@@ -761,7 +761,7 @@ static void do_input(char *alias,sprintf (alias +strlen (alias),"%X,*" , i); } -/* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */ +/* input:b0v0p0e0-eXkXrXaXmXlXsXfXwXprX where X is comma-separated %02X. */ static int do_input_entry (const char *filename,void *symval,char *alias) {
@@ -779,6 +779,7 @@ static int do_input_entry(const char *filename, void *symval,DEF_FIELD_ADDR (symval, input_device_id, sndbit);DEF_FIELD_ADDR (symval, input_device_id, ffbit);DEF_FIELD_ADDR (symval, input_device_id, swbit); +DEF_FIELD_ADDR (symval, input_device_id, propbit);sprintf (alias,"input:" );
@@ -816,6 +817,9 @@ static int do_input_entry(const char *filename, void *symval,sprintf (alias +strlen (alias),"w*" );if (flags &INPUT_DEVICE_ID_MATCH_SWBIT )do_input (alias, *swbit,0 ,INPUT_DEVICE_ID_SW_MAX ); +sprintf (alias +strlen (alias),"pr*" ); +if (flags &INPUT_DEVICE_ID_MATCH_PROPBIT ) +do_input (alias, *propbit,0 ,INPUT_DEVICE_ID_PROP_MAX );return 1 ; }ADD_TO_DEVTABLE ("input" , input_device_id, do_input_entry);
Signature · 1 line
2.14.2.920.gcf0c67979c-goog
Dmitry Torokhov
maintainerPATCH 3/3 Input: joydev - blacklist ds3/ds4/udraw motion sensors
In reply to Dmitry TorokhovFrom: Roderick Colenbrander <[email protected]>
Introduce a device table used for blacklisting devices. We currently blacklist the motion sensor subdevice of THQ Udraw and Sony ds3/ds4.
Signed-off-by Roderick Colenbrander <[email protected]>
Signed-off-by Dmitry Torokhov <[email protected]>
--- drivers/input/joydev.c | 70 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 6 deletions(-)
drivers/input/joydev.c +64 -6
@@ -747,6 +747,68 @@ static void joydev_cleanup(struct joydev *joydev)input_close_device (handle); } +/* +* These codes are copied from from hid-ids.h, unfortunately there is no common +* usb_ids/bt_ids.h header. +*/ +#define USB_VENDOR_ID_SONY 0x054c +#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268 +#define USB_DEVICE_ID_SONY_PS4_CONTROLLER 0x05c4 +#define USB_DEVICE_ID_SONY_PS4_CONTROLLER_2 0x09cc +#define USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE 0x0ba0 + +#define USB_VENDOR_ID_THQ 0x20d6 +#define USB_DEVICE_ID_THQ_PS3_UDRAW 0xcb17 + +#define ACCEL_DEV (vnd, prd) \ + { \ + .flags = INPUT_DEVICE_ID_MATCH_VENDOR | \ + INPUT_DEVICE_ID_MATCH_PRODUCT | \ + INPUT_DEVICE_ID_MATCH_PROPBIT, \ + .vendor = (vnd), \ + .product = (prd), \ + .propbit = { BIT_MASK(INPUT_PROP_ACCELEROMETER) }, \ + } + +static const struct input_device_id joydev_blacklist[] = { +/* Avoid touchpads and touchscreens */ + { + .flags =INPUT_DEVICE_ID_MATCH_EVBIT | +INPUT_DEVICE_ID_MATCH_KEYBIT , + .evbit = {BIT_MASK (EV_KEY ) }, + .keybit = { [BIT_WORD (BTN_TOUCH )] =BIT_MASK (BTN_TOUCH ) }, + }, +/* Avoid tablets, digitisers and similar devices */ + { + .flags =INPUT_DEVICE_ID_MATCH_EVBIT | +INPUT_DEVICE_ID_MATCH_KEYBIT , + .evbit = {BIT_MASK (EV_KEY ) }, + .keybit = { [BIT_WORD (BTN_DIGI )] =BIT_MASK (BTN_DIGI ) }, + }, +/* Disable accelerometers on composite devices */ +ACCEL_DEV (USB_VENDOR_ID_SONY ,USB_DEVICE_ID_SONY_PS3_CONTROLLER ), +ACCEL_DEV (USB_VENDOR_ID_SONY ,USB_DEVICE_ID_SONY_PS4_CONTROLLER ), +ACCEL_DEV (USB_VENDOR_ID_SONY ,USB_DEVICE_ID_SONY_PS4_CONTROLLER_2 ), +ACCEL_DEV (USB_VENDOR_ID_SONY ,USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE ), +ACCEL_DEV (USB_VENDOR_ID_THQ ,USB_DEVICE_ID_THQ_PS3_UDRAW ), + {/* sentinel */ } +}; + +static bool joydev_dev_is_blacklisted (struct input_dev *dev) +{ +const struct input_device_id *id; + +for (id = joydev_blacklist; id->flags; id++) { +if (input_match_device_id (dev, id)) { +dev_dbg (&dev->dev, +"joydev: blacklisting '%s'\n" , dev->name); +return true; + } + } + +return false; +} +static bool joydev_dev_is_absolute_mouse (struct input_dev *dev) {DECLARE_BITMAP (jd_scratch,KEY_CNT );
@@ -807,12 +869,8 @@ static bool joydev_dev_is_absolute_mouse(struct input_dev *dev)static bool joydev_match (struct input_handler *handler,struct input_dev *dev) { -/* Avoid touchpads and touchscreens */ -if (test_bit (EV_KEY , dev->evbit) &&test_bit (BTN_TOUCH , dev->keybit)) -return false; - -/* Avoid tablets, digitisers and similar devices */ -if (test_bit (EV_KEY , dev->evbit) &&test_bit (BTN_DIGI , dev->keybit)) +/* Disable blacklisted devices */ +if (joydev_dev_is_blacklisted (dev))return false;/* Avoid absolute mice */
Signature · 1 line
2.14.2.920.gcf0c67979c-goog