Merge branch 'next' into for-linus
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 1 Mar 2010 07:55:20 +0000 (23:55 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 1 Mar 2010 07:55:20 +0000 (23:55 -0800)
1  2 
drivers/input/input.c
drivers/input/touchscreen/usbtouchscreen.c
include/linux/input.h

diff --combined drivers/input/input.c
index 86cb2d2196ff9792f18c39646e44983af46fcf61,dae49eba6ccd724cf5e2ad22c1de33535a46be1c..41168d5f8c17bb0d1847b03695db8c095565ade5
@@@ -46,7 -46,6 +46,7 @@@ static unsigned int input_abs_bypass_in
        ABS_MT_TOOL_TYPE,
        ABS_MT_BLOB_ID,
        ABS_MT_TRACKING_ID,
 +      ABS_MT_PRESSURE,
        0
  };
  static unsigned long input_abs_bypass[BITS_TO_LONGS(ABS_CNT)];
@@@ -87,12 -86,14 +87,14 @@@ static int input_defuzz_abs_event(int v
  }
  
  /*
-  * Pass event through all open handles. This function is called with
+  * 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 void input_pass_event(struct input_dev *dev,
                             unsigned int type, unsigned int code, int value)
  {
+       struct input_handler *handler;
        struct input_handle *handle;
  
        rcu_read_lock();
        handle = rcu_dereference(dev->grab);
        if (handle)
                handle->handler->event(handle, type, code, value);
-       else
-               list_for_each_entry_rcu(handle, &dev->h_list, d_node)
-                       if (handle->open)
-                               handle->handler->event(handle,
-                                                       type, code, value);
+       else {
+               bool filtered = false;
+               list_for_each_entry_rcu(handle, &dev->h_list, d_node) {
+                       if (!handle->open)
+                               continue;
+                       handler = handle->handler;
+                       if (!handler->filter) {
+                               if (filtered)
+                                       break;
+                               handler->event(handle, type, code, value);
+                       } else if (handler->filter(handle, type, code, value))
+                               filtered = true;
+               }
+       }
        rcu_read_unlock();
  }
  
@@@ -615,12 -630,12 +631,12 @@@ static int input_default_setkeycode(str
                }
        }
  
-       clear_bit(old_keycode, dev->keybit);
-       set_bit(keycode, dev->keybit);
+       __clear_bit(old_keycode, dev->keybit);
+       __set_bit(keycode, dev->keybit);
  
        for (i = 0; i < dev->keycodemax; i++) {
                if (input_fetch_keycode(dev, i) == old_keycode) {
-                       set_bit(old_keycode, dev->keybit);
+                       __set_bit(old_keycode, dev->keybit);
                        break; /* Setting the bit twice is useless, so break */
                }
        }
@@@ -678,6 -693,9 +694,9 @@@ int input_set_keycode(struct input_dev 
        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
@@@ -705,12 -723,13 +724,13 @@@ EXPORT_SYMBOL(input_set_keycode)
                if (i != BITS_TO_LONGS(max)) \
                        continue;
  
- static const struct input_device_id *input_match_device(const struct input_device_id *id,
+ static const struct input_device_id *input_match_device(struct input_handler *handler,
                                                        struct input_dev *dev)
  {
+       const struct input_device_id *id;
        int i;
  
-       for (; id->flags || id->driver_info; 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)
                MATCH_BIT(ffbit,  FF_MAX);
                MATCH_BIT(swbit,  SW_MAX);
  
-               return id;
+               if (!handler->match || handler->match(handler, dev))
+                       return id;
        }
  
        return NULL;
@@@ -749,10 -769,7 +770,7 @@@ static int input_attach_handler(struct 
        const struct input_device_id *id;
        int error;
  
-       if (handler->blacklist && input_match_device(handler->blacklist, dev))
-               return -ENODEV;
-       id = input_match_device(handler->id_table, dev);
+       id = input_match_device(handler, dev);
        if (!id)
                return -ENODEV;
  
@@@ -988,6 -1005,8 +1006,8 @@@ static int input_handlers_seq_show(stru
        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->fops)
                seq_printf(seq, " Minor=%d", handler->minor);
        seq_putc(seq, '\n');
@@@ -1551,6 -1570,25 +1571,25 @@@ void input_set_capability(struct input_
  }
  EXPORT_SYMBOL(input_set_capability);
  
+ #define INPUT_CLEANSE_BITMASK(dev, type, bits)                                \
+       do {                                                            \
+               if (!test_bit(EV_##type, dev->evbit))                   \
+                       memset(dev->bits##bit, 0,                       \
+                               sizeof(dev->bits##bit));                \
+       } while (0)
+ static void input_cleanse_bitmasks(struct input_dev *dev)
+ {
+       INPUT_CLEANSE_BITMASK(dev, KEY, key);
+       INPUT_CLEANSE_BITMASK(dev, REL, rel);
+       INPUT_CLEANSE_BITMASK(dev, ABS, abs);
+       INPUT_CLEANSE_BITMASK(dev, MSC, msc);
+       INPUT_CLEANSE_BITMASK(dev, LED, led);
+       INPUT_CLEANSE_BITMASK(dev, SND, snd);
+       INPUT_CLEANSE_BITMASK(dev, FF, ff);
+       INPUT_CLEANSE_BITMASK(dev, SW, sw);
+ }
  /**
   * input_register_device - register device with input core
   * @dev: device to be registered
@@@ -1570,13 -1608,19 +1609,19 @@@ int input_register_device(struct input_
        const char *path;
        int error;
  
+       /* Every input device generates EV_SYN/SYN_REPORT events. */
        __set_bit(EV_SYN, dev->evbit);
  
+       /* KEY_RESERVED is not supposed to be transmitted to userspace. */
+       __clear_bit(KEY_RESERVED, dev->keybit);
+       /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
+       input_cleanse_bitmasks(dev);
        /*
         * If delay and period are pre-set by the driver, then autorepeating
         * is handled by the driver itself and we don't do it in input.c.
         */
        init_timer(&dev->timer);
        if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
                dev->timer.data = (long) dev;
@@@ -1776,7 -1820,16 +1821,16 @@@ int input_register_handle(struct input_
        error = mutex_lock_interruptible(&dev->mutex);
        if (error)
                return error;
-       list_add_tail_rcu(&handle->d_node, &dev->h_list);
+       /*
+        * Filters go to the head of the list, normal handlers
+        * to the tail.
+        */
+       if (handler->filter)
+               list_add_rcu(&handle->d_node, &dev->h_list);
+       else
+               list_add_tail_rcu(&handle->d_node, &dev->h_list);
        mutex_unlock(&dev->mutex);
  
        /*
index 5256123a52285c35ed352d980ec7ad4641f941ee,7a2d39abc58645260a4112bfd0816b9cb1eb4b57..99330bbdbac761c7f4d940f6b475861eec0bcf91
@@@ -15,6 -15,7 +15,7 @@@
   *  - GoTop Super_Q2/GogoPen/PenPower tablets
   *  - JASTEC USB touch controller/DigiTech DTR-02U
   *  - Zytronic capacitive touchscreen
+  *  - NEXIO/iNexio
   *
   * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
   * Copyright (C) by Todd E. Johnson (mtouchusb.c)
@@@ -95,6 -96,7 +96,7 @@@ struct usbtouch_device_info 
  
        int  (*read_data)   (struct usbtouch_usb *usbtouch, unsigned char *pkt);
        int  (*init)        (struct usbtouch_usb *usbtouch);
+       void (*exit)        (struct usbtouch_usb *usbtouch);
  };
  
  /* a usbtouch device */
@@@ -104,11 -106,12 +106,12 @@@ struct usbtouch_usb 
        unsigned char *buffer;
        int buf_len;
        struct urb *irq;
-       struct usb_device *udev;
+       struct usb_interface *interface;
        struct input_dev *input;
        struct usbtouch_device_info *type;
        char name[128];
        char phys[64];
+       void *priv;
  
        int x, y;
        int touch, press;
@@@ -133,6 -136,7 +136,7 @@@ enum 
        DEVTYPE_E2I,
        DEVTYPE_ZYTRONIC,
        DEVTYPE_TC5UH,
+       DEVTYPE_NEXIO,
  };
  
  #define USB_DEVICE_HID_CLASS(vend, prod) \
        .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
        .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
  
- static struct usb_device_id usbtouch_devices[] = {
+ static const struct usb_device_id usbtouch_devices[] = {
  #ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
        /* ignore the HID capable devices, handled by usbhid */
        {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
        {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
  #endif
  
+ #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
+       /* data interface only */
+       {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
+               .driver_info = DEVTYPE_NEXIO},
+       {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
+               .driver_info = DEVTYPE_NEXIO},
+ #endif
        {}
  };
  
  static int e2i_init(struct usbtouch_usb *usbtouch)
  {
        int ret;
+       struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
  
-       ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
+       ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                              0x01, 0x02, 0x0000, 0x0081,
                              NULL, 0, USB_CTRL_SET_TIMEOUT);
  
@@@ -344,8 -357,9 +357,9 @@@ static int mtouch_read_data(struct usbt
  static int mtouch_init(struct usbtouch_usb *usbtouch)
  {
        int ret, i;
+       struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
  
-       ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
+       ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                              MTOUCHUSB_RESET,
                              USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
        msleep(150);
  
        for (i = 0; i < 3; i++) {
-               ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
+               ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                      MTOUCHUSB_ASYNC_REPORT,
                                      USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                                      1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
@@@ -489,7 -503,7 +503,7 @@@ static int gunze_read_data(struct usbto
  
  static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
  {
-       struct usb_device *dev = usbtouch->udev;
+       struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
        int ret = -ENOMEM;
        unsigned char *buf;
  
@@@ -618,8 -632,8 +632,8 @@@ static int idealtek_read_data(struct us
  #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
  static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
  {
 -      dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ;
 -      dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ;
 +      dev->x = (pkt[2] << 8) | pkt[1];
 +      dev->y = (pkt[4] << 8) | pkt[3];
        dev->press = pkt[5] & 0xff;
        dev->touch = pkt[0] & 0x01;
  
@@@ -689,6 -703,229 +703,229 @@@ static int zytronic_read_data(struct us
  }
  #endif
  
+ /*****************************************************************************
+  * NEXIO Part
+  */
+ #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
+ #define NEXIO_TIMEOUT 5000
+ #define NEXIO_BUFSIZE 1024
+ #define NEXIO_THRESHOLD       50
+ struct nexio_priv {
+       struct urb *ack;
+       unsigned char *ack_buf;
+ };
+ struct nexio_touch_packet {
+       u8      flags;          /* 0xe1 = touch, 0xe1 = release */
+       __be16  data_len;       /* total bytes of touch data */
+       __be16  x_len;          /* bytes for X axis */
+       __be16  y_len;          /* bytes for Y axis */
+       u8      data[];
+ } __attribute__ ((packed));
+ static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
+ static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
+ static void nexio_ack_complete(struct urb *urb)
+ {
+ }
+ static int nexio_init(struct usbtouch_usb *usbtouch)
+ {
+       struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
+       struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
+       struct nexio_priv *priv;
+       int ret = -ENOMEM;
+       int actual_len, i;
+       unsigned char *buf;
+       char *firmware_ver = NULL, *device_name = NULL;
+       int input_ep = 0, output_ep = 0;
+       /* find first input and output endpoint */
+       for (i = 0; i < interface->desc.bNumEndpoints; i++) {
+               if (!input_ep &&
+                   usb_endpoint_dir_in(&interface->endpoint[i].desc))
+                       input_ep = interface->endpoint[i].desc.bEndpointAddress;
+               if (!output_ep &&
+                   usb_endpoint_dir_out(&interface->endpoint[i].desc))
+                       output_ep = interface->endpoint[i].desc.bEndpointAddress;
+       }
+       if (!input_ep || !output_ep)
+               return -ENXIO;
+       buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL);
+       if (!buf)
+               goto out_buf;
+       /* two empty reads */
+       for (i = 0; i < 2; i++) {
+               ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
+                                  buf, NEXIO_BUFSIZE, &actual_len,
+                                  NEXIO_TIMEOUT);
+               if (ret < 0)
+                       goto out_buf;
+       }
+       /* send init command */
+       memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
+       ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
+                          buf, sizeof(nexio_init_pkt), &actual_len,
+                          NEXIO_TIMEOUT);
+       if (ret < 0)
+               goto out_buf;
+       /* read replies */
+       for (i = 0; i < 3; i++) {
+               memset(buf, 0, NEXIO_BUFSIZE);
+               ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
+                                  buf, NEXIO_BUFSIZE, &actual_len,
+                                  NEXIO_TIMEOUT);
+               if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
+                       continue;
+               switch (buf[0]) {
+               case 0x83:      /* firmware version */
+                       if (!firmware_ver)
+                               firmware_ver = kstrdup(&buf[2], GFP_KERNEL);
+                       break;
+               case 0x84:      /* device name */
+                       if (!device_name)
+                               device_name = kstrdup(&buf[2], GFP_KERNEL);
+                       break;
+               }
+       }
+       printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
+              device_name, firmware_ver);
+       kfree(firmware_ver);
+       kfree(device_name);
+       /* prepare ACK URB */
+       ret = -ENOMEM;
+       usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
+       if (!usbtouch->priv)
+               goto out_buf;
+       priv = usbtouch->priv;
+       priv->ack_buf = kmalloc(sizeof(nexio_ack_pkt), GFP_KERNEL);
+       if (!priv->ack_buf)
+               goto err_priv;
+       memcpy(priv->ack_buf, nexio_ack_pkt, sizeof(nexio_ack_pkt));
+       priv->ack = usb_alloc_urb(0, GFP_KERNEL);
+       if (!priv->ack) {
+               dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
+               goto err_ack_buf;
+       }
+       usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
+                         priv->ack_buf, sizeof(nexio_ack_pkt),
+                         nexio_ack_complete, usbtouch);
+       ret = 0;
+       goto out_buf;
+ err_ack_buf:
+       kfree(priv->ack_buf);
+ err_priv:
+       kfree(priv);
+ out_buf:
+       kfree(buf);
+       return ret;
+ }
+ static void nexio_exit(struct usbtouch_usb *usbtouch)
+ {
+       struct nexio_priv *priv = usbtouch->priv;
+       usb_kill_urb(priv->ack);
+       usb_free_urb(priv->ack);
+       kfree(priv->ack_buf);
+       kfree(priv);
+ }
+ static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
+ {
+       int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
+       struct nexio_touch_packet *packet = (void *) pkt;
+       struct nexio_priv *priv = usbtouch->priv;
+       /* got touch data? */
+       if ((pkt[0] & 0xe0) != 0xe0)
+               return 0;
+       /* send ACK */
+       ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
+       if (!usbtouch->type->max_xc) {
+               usbtouch->type->max_xc = 2 * be16_to_cpu(packet->x_len);
+               input_set_abs_params(usbtouch->input, ABS_X, 0,
+                                    2 * be16_to_cpu(packet->x_len), 0, 0);
+               usbtouch->type->max_yc = 2 * be16_to_cpu(packet->y_len);
+               input_set_abs_params(usbtouch->input, ABS_Y, 0,
+                                    2 * be16_to_cpu(packet->y_len), 0, 0);
+       }
+       /*
+        * The device reports state of IR sensors on X and Y axes.
+        * Each byte represents "darkness" percentage (0-100) of one element.
+        * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
+        * This also means that there's a limited multi-touch capability but
+        * it's disabled (and untested) here as there's no X driver for that.
+        */
+       begin_x = end_x = begin_y = end_y = -1;
+       for (x = 0; x < be16_to_cpu(packet->x_len); x++) {
+               if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
+                       begin_x = x;
+                       continue;
+               }
+               if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
+                       end_x = x - 1;
+                       for (y = be16_to_cpu(packet->x_len);
+                            y < be16_to_cpu(packet->data_len); y++) {
+                               if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
+                                       begin_y = y - be16_to_cpu(packet->x_len);
+                                       continue;
+                               }
+                               if (end_y == -1 &&
+                                   begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
+                                       end_y = y - 1 - be16_to_cpu(packet->x_len);
+                                       w = end_x - begin_x;
+                                       h = end_y - begin_y;
+ #if 0
+                                       /* multi-touch */
+                                       input_report_abs(usbtouch->input,
+                                                   ABS_MT_TOUCH_MAJOR, max(w,h));
+                                       input_report_abs(usbtouch->input,
+                                                   ABS_MT_TOUCH_MINOR, min(x,h));
+                                       input_report_abs(usbtouch->input,
+                                                   ABS_MT_POSITION_X, 2*begin_x+w);
+                                       input_report_abs(usbtouch->input,
+                                                   ABS_MT_POSITION_Y, 2*begin_y+h);
+                                       input_report_abs(usbtouch->input,
+                                                   ABS_MT_ORIENTATION, w > h);
+                                       input_mt_sync(usbtouch->input);
+ #endif
+                                       /* single touch */
+                                       usbtouch->x = 2 * begin_x + w;
+                                       usbtouch->y = 2 * begin_y + h;
+                                       usbtouch->touch = packet->flags & 0x01;
+                                       begin_y = end_y = -1;
+                                       return 1;
+                               }
+                       }
+                       begin_x = end_x = -1;
+               }
+       }
+       return 0;
+ }
+ #endif
  /*****************************************************************************
   * the different device descriptors
   */
@@@ -809,9 -1046,9 +1046,9 @@@ static struct usbtouch_device_info usbt
  #ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
        [DEVTYPE_GENERAL_TOUCH] = {
                .min_xc         = 0x0,
 -              .max_xc         = 0x0500,
 +              .max_xc         = 0x7fff,
                .min_yc         = 0x0,
 -              .max_yc         = 0x0500,
 +              .max_yc         = 0x7fff,
                .rept_size      = 7,
                .read_data      = general_touch_read_data,
        },
                .read_data      = tc5uh_read_data,
        },
  #endif
+ #ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
+       [DEVTYPE_NEXIO] = {
+               .rept_size      = 128,
+               .irq_always     = true,
+               .read_data      = nexio_read_data,
+               .init           = nexio_init,
+               .exit           = nexio_exit,
+       },
+ #endif
  };
  
  
@@@ -998,6 -1245,7 +1245,7 @@@ static void usbtouch_irq(struct urb *ur
        case -ECONNRESET:
        case -ENOENT:
        case -ESHUTDOWN:
+       case -EPIPE:
                /* this urb is terminated, clean up */
                dbg("%s - urb shutting down with status: %d",
                    __func__, urb->status);
@@@ -1021,7 -1269,7 +1269,7 @@@ static int usbtouch_open(struct input_d
  {
        struct usbtouch_usb *usbtouch = input_get_drvdata(input);
  
-       usbtouch->irq->dev = usbtouch->udev;
+       usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
  
        if (!usbtouch->type->irq_always) {
                if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
@@@ -1048,13 -1296,23 +1296,23 @@@ static void usbtouch_free_buffers(struc
        kfree(usbtouch->buffer);
  }
  
+ static struct usb_endpoint_descriptor *
+ usbtouch_get_input_endpoint(struct usb_host_interface *interface)
+ {
+       int i;
+       for (i = 0; i < interface->desc.bNumEndpoints; i++)
+               if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
+                       return &interface->endpoint[i].desc;
+       return NULL;
+ }
  
  static int usbtouch_probe(struct usb_interface *intf,
                          const struct usb_device_id *id)
  {
        struct usbtouch_usb *usbtouch;
        struct input_dev *input_dev;
-       struct usb_host_interface *interface;
        struct usb_endpoint_descriptor *endpoint;
        struct usb_device *udev = interface_to_usbdev(intf);
        struct usbtouch_device_info *type;
        if (id->driver_info == DEVTYPE_IGNORE)
                return -ENODEV;
  
-       interface = intf->cur_altsetting;
-       endpoint = &interface->endpoint[0].desc;
+       endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
+       if (!endpoint)
+               return -ENXIO;
  
        usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
        input_dev = input_allocate_device();
                goto out_free_buffers;
        }
  
-       usbtouch->udev = udev;
+       usbtouch->interface = intf;
        usbtouch->input = input_dev;
  
        if (udev->manufacturer)
                input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
                                     type->max_press, 0, 0);
  
-       usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
-                        usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress),
+       if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
+               usb_fill_int_urb(usbtouch->irq, udev,
+                        usb_rcvintpipe(udev, endpoint->bEndpointAddress),
                         usbtouch->data, type->rept_size,
                         usbtouch_irq, usbtouch, endpoint->bInterval);
+       else
+               usb_fill_bulk_urb(usbtouch->irq, udev,
+                        usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
+                        usbtouch->data, type->rept_size,
+                        usbtouch_irq, usbtouch);
  
-       usbtouch->irq->dev = usbtouch->udev;
+       usbtouch->irq->dev = udev;
        usbtouch->irq->transfer_dma = usbtouch->data_dma;
        usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  
                err = type->init(usbtouch);
                if (err) {
                        dbg("%s - type->init() failed, err: %d", __func__, err);
-                       goto out_free_buffers;
+                       goto out_free_urb;
                }
        }
  
        err = input_register_device(usbtouch->input);
        if (err) {
                dbg("%s - input_register_device failed, err: %d", __func__, err);
-               goto out_free_buffers;
+               goto out_do_exit;
        }
  
        usb_set_intfdata(intf, usbtouch);
  
-       if (usbtouch->type->irq_always)
-               usb_submit_urb(usbtouch->irq, GFP_KERNEL);
+       if (usbtouch->type->irq_always) {
+               err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
+               if (err) {
+                       err("%s - usb_submit_urb failed with result: %d",
+                           __func__, err);
+                       goto out_unregister_input;
+               }
+       }
  
        return 0;
  
+ out_unregister_input:
+       input_unregister_device(input_dev);
+       input_dev = NULL;
+ out_do_exit:
+       if (type->exit)
+               type->exit(usbtouch);
+ out_free_urb:
+       usb_free_urb(usbtouch->irq);
  out_free_buffers:
        usbtouch_free_buffers(udev, usbtouch);
  out_free:
@@@ -1186,6 -1465,8 +1465,8 @@@ static void usbtouch_disconnect(struct 
        /* this will stop IO via close */
        input_unregister_device(usbtouch->input);
        usb_free_urb(usbtouch->irq);
+       if (usbtouch->type->exit)
+               usbtouch->type->exit(usbtouch);
        usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
        kfree(usbtouch);
  }
diff --combined include/linux/input.h
index 663208afb64ce37ed16334debe6f40a4a858418f,b1a74fb2e436f2aad3be697eac8115b7ab54ff61..889a4801f7be5606ff282321110538b3df1a077d
@@@ -376,9 -376,8 +376,9 @@@ struct input_absinfo 
  #define KEY_DISPLAY_OFF               245     /* display device to off state */
  
  #define KEY_WIMAX             246
 +#define KEY_RFKILL            247     /* Key that controls all radios */
  
- /* Range 248 - 255 is reserved for special needs of AT keyboard driver */
+ /* Code 255 is reserved for special needs of AT keyboard driver */
  
  #define BTN_MISC              0x100
  #define BTN_0                 0x100
  #define KEY_NUMERIC_POUND     0x20b
  
  #define KEY_CAMERA_FOCUS      0x210
+ #define KEY_WPS_BUTTON                0x211   /* WiFi Protected Setup key */
  
  /* We avoid low common keys in module aliases so they don't get huge. */
  #define KEY_MIN_INTERESTING   KEY_MUTE
  #define ABS_MT_TOOL_TYPE      0x37    /* Type of touching device */
  #define ABS_MT_BLOB_ID                0x38    /* Group a set of packets as a blob */
  #define ABS_MT_TRACKING_ID    0x39    /* Unique ID of initiated contact */
 +#define ABS_MT_PRESSURE               0x3a    /* Pressure on contact area */
  
  #define ABS_MAX                       0x3f
  #define ABS_CNT                       (ABS_MAX+1)
@@@ -1200,6 -1199,10 +1201,10 @@@ struct input_handle
   * @event: event handler. This method is being called by input core with
   *    interrupts disabled and dev->event_lock spinlock held and so
   *    it may not sleep
+  * @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 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 by
   * @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 can
   *    handle
-  * @blacklist: pointer to a table of input_device_ids this driver should
-  *    ignore even if they match @id_table
   * @h_list: list of input handles associated with the handler
   * @node: for placing the driver onto input_handler_list
   *
   * 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.
   */
@@@ -1229,6 -1235,8 +1237,8 @@@ struct input_handler 
        void *private;
  
        void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
+       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);
        const char *name;
  
        const struct input_device_id *id_table;
-       const struct input_device_id *blacklist;
  
        struct list_head        h_list;
        struct list_head        node;