CHROMEOS: HID: Support for Logitech T651 Touchpad
[cascardo/linux.git] / drivers / hid / hid-core.c
index 4da66b4..4ad213f 100644 (file)
@@ -1097,7 +1097,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
        if (!hid)
                return -ENODEV;
 
-       if (down_trylock(&hid->driver_lock))
+       if (down_trylock(&hid->driver_input_lock))
                return -EBUSY;
 
        if (!hid->driver) {
@@ -1150,7 +1150,7 @@ nomem:
        hid_report_raw_event(hid, type, data, size, interrupt);
 
 unlock:
-       up(&hid->driver_lock);
+       up(&hid->driver_input_lock);
        return ret;
 }
 EXPORT_SYMBOL_GPL(hid_input_report);
@@ -1480,6 +1480,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) },
+       { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_WIRELESS_TOUCHPAD_T651) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH) },
        { HID_USB_DEVICE(USB_VENDOR_ID_LUMIO, USB_DEVICE_ID_CRYSTALTOUCH_DUAL) },
        { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
@@ -1703,6 +1704,11 @@ static int hid_device_probe(struct device *dev)
 
        if (down_interruptible(&hdev->driver_lock))
                return -EINTR;
+       if (down_interruptible(&hdev->driver_input_lock)) {
+               ret = -EINTR;
+               goto unlock_driver_lock;
+       }
+       hdev->io_started = false;
 
        if (!hdev->driver) {
                id = hid_match_device(hdev, hdrv);
@@ -1726,6 +1732,9 @@ static int hid_device_probe(struct device *dev)
                        hdev->driver = NULL;
        }
 unlock:
+       if (!hdev->io_started)
+               up(&hdev->driver_input_lock);
+unlock_driver_lock:
        up(&hdev->driver_lock);
        return ret;
 }
@@ -1734,9 +1743,15 @@ static int hid_device_remove(struct device *dev)
 {
        struct hid_device *hdev = container_of(dev, struct hid_device, dev);
        struct hid_driver *hdrv;
+       int ret = 0;
 
        if (down_interruptible(&hdev->driver_lock))
                return -EINTR;
+       if (down_interruptible(&hdev->driver_input_lock)) {
+               ret = -EINTR;
+               goto unlock_driver_lock;
+       }
+       hdev->io_started = false;
 
        hdrv = hdev->driver;
        if (hdrv) {
@@ -1747,8 +1762,11 @@ static int hid_device_remove(struct device *dev)
                hdev->driver = NULL;
        }
 
+       if (!hdev->io_started)
+               up(&hdev->driver_input_lock);
+unlock_driver_lock:
        up(&hdev->driver_lock);
-       return 0;
+       return ret;
 }
 
 static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
@@ -2013,8 +2031,13 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
        { }
 };
 
-static bool hid_ignore(struct hid_device *hdev)
+bool hid_ignore(struct hid_device *hdev)
 {
+       if (hdev->quirks & HID_QUIRK_NO_IGNORE)
+               return false;
+       if (hdev->quirks & HID_QUIRK_IGNORE)
+               return true;
+
        switch (hdev->vendor) {
        case USB_VENDOR_ID_CODEMERCS:
                /* ignore all Code Mercenaries IOWarrior devices */
@@ -2060,6 +2083,7 @@ static bool hid_ignore(struct hid_device *hdev)
 
        return !!hid_match_id(hdev, hid_ignore_list);
 }
+EXPORT_SYMBOL_GPL(hid_ignore);
 
 int hid_add_device(struct hid_device *hdev)
 {
@@ -2071,8 +2095,7 @@ int hid_add_device(struct hid_device *hdev)
 
        /* we need to kill them here, otherwise they will stay allocated to
         * wait for coming driver */
-       if (!(hdev->quirks & HID_QUIRK_NO_IGNORE)
-            && (hid_ignore(hdev) || (hdev->quirks & HID_QUIRK_IGNORE)))
+       if (hid_ignore(hdev))
                return -ENODEV;
 
        /* XXX hack, any other cleaner solution after the driver core
@@ -2126,6 +2149,7 @@ struct hid_device *hid_allocate_device(void)
        init_waitqueue_head(&hdev->debug_wait);
        INIT_LIST_HEAD(&hdev->debug_list);
        sema_init(&hdev->driver_lock, 1);
+       sema_init(&hdev->driver_input_lock, 1);
 
        return hdev;
 err: