aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2010-02-03 00:08:26 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-02-04 03:25:19 -0500
commit0b7024ac4df5821347141c18e680b7166bc1cb20 (patch)
tree7a61e55e66bdd39351b3ec39ecef367588b47170 /drivers/input
parent1e87a43080a259a0e9739377708ece163b08de8d (diff)
Input: add match() method to input hanlders
Get rid of blacklist in input handler structure and instead allow handlers to define their own match() method to perform fine-grained filtering of supported devices. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/input.c13
-rw-r--r--drivers/input/joydev.c32
2 files changed, 21 insertions, 24 deletions
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7080a9d4b840..dae49eba6ccd 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -723,12 +723,13 @@ EXPORT_SYMBOL(input_set_keycode);
723 if (i != BITS_TO_LONGS(max)) \ 723 if (i != BITS_TO_LONGS(max)) \
724 continue; 724 continue;
725 725
726static const struct input_device_id *input_match_device(const struct input_device_id *id, 726static const struct input_device_id *input_match_device(struct input_handler *handler,
727 struct input_dev *dev) 727 struct input_dev *dev)
728{ 728{
729 const struct input_device_id *id;
729 int i; 730 int i;
730 731
731 for (; id->flags || id->driver_info; id++) { 732 for (id = handler->id_table; id->flags || id->driver_info; id++) {
732 733
733 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) 734 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
734 if (id->bustype != dev->id.bustype) 735 if (id->bustype != dev->id.bustype)
@@ -756,7 +757,8 @@ static const struct input_device_id *input_match_device(const struct input_devic
756 MATCH_BIT(ffbit, FF_MAX); 757 MATCH_BIT(ffbit, FF_MAX);
757 MATCH_BIT(swbit, SW_MAX); 758 MATCH_BIT(swbit, SW_MAX);
758 759
759 return id; 760 if (!handler->match || handler->match(handler, dev))
761 return id;
760 } 762 }
761 763
762 return NULL; 764 return NULL;
@@ -767,10 +769,7 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
767 const struct input_device_id *id; 769 const struct input_device_id *id;
768 int error; 770 int error;
769 771
770 if (handler->blacklist && input_match_device(handler->blacklist, dev)) 772 id = input_match_device(handler, dev);
771 return -ENODEV;
772
773 id = input_match_device(handler->id_table, dev);
774 if (!id) 773 if (!id)
775 return -ENODEV; 774 return -ENODEV;
776 775
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index b1bd6dd32286..63e71f2a7acc 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -775,6 +775,20 @@ static void joydev_cleanup(struct joydev *joydev)
775 input_close_device(handle); 775 input_close_device(handle);
776} 776}
777 777
778
779static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
780{
781 /* Avoid touchpads and touchscreens */
782 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_TOUCH, dev->keybit))
783 return false;
784
785 /* Avoid tablets, digitisers and similar devices */
786 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit))
787 return false;
788
789 return true;
790}
791
778static int joydev_connect(struct input_handler *handler, struct input_dev *dev, 792static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
779 const struct input_device_id *id) 793 const struct input_device_id *id)
780{ 794{
@@ -894,22 +908,6 @@ static void joydev_disconnect(struct input_handle *handle)
894 put_device(&joydev->dev); 908 put_device(&joydev->dev);
895} 909}
896 910
897static const struct input_device_id joydev_blacklist[] = {
898 {
899 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
900 INPUT_DEVICE_ID_MATCH_KEYBIT,
901 .evbit = { BIT_MASK(EV_KEY) },
902 .keybit = { [BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
903 }, /* Avoid itouchpads and touchscreens */
904 {
905 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
906 INPUT_DEVICE_ID_MATCH_KEYBIT,
907 .evbit = { BIT_MASK(EV_KEY) },
908 .keybit = { [BIT_WORD(BTN_DIGI)] = BIT_MASK(BTN_DIGI) },
909 }, /* Avoid tablets, digitisers and similar devices */
910 { } /* Terminating entry */
911};
912
913static const struct input_device_id joydev_ids[] = { 911static const struct input_device_id joydev_ids[] = {
914 { 912 {
915 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 913 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
@@ -936,13 +934,13 @@ MODULE_DEVICE_TABLE(input, joydev_ids);
936 934
937static struct input_handler joydev_handler = { 935static struct input_handler joydev_handler = {
938 .event = joydev_event, 936 .event = joydev_event,
937 .match = joydev_match,
939 .connect = joydev_connect, 938 .connect = joydev_connect,
940 .disconnect = joydev_disconnect, 939 .disconnect = joydev_disconnect,
941 .fops = &joydev_fops, 940 .fops = &joydev_fops,
942 .minor = JOYDEV_MINOR_BASE, 941 .minor = JOYDEV_MINOR_BASE,
943 .name = "joydev", 942 .name = "joydev",
944 .id_table = joydev_ids, 943 .id_table = joydev_ids,
945 .blacklist = joydev_blacklist,
946}; 944};
947 945
948static int __init joydev_init(void) 946static int __init joydev_init(void)