]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
Merge branches 'for-3.11/battery', 'for-3.11/elo', 'for-3.11/holtek' and 'for-3.11...
authorJiri Kosina <jkosina@suse.cz>
Thu, 4 Jul 2013 13:01:01 +0000 (15:01 +0200)
committerJiri Kosina <jkosina@suse.cz>
Thu, 4 Jul 2013 13:01:01 +0000 (15:01 +0200)
drivers/hid/Kconfig
drivers/hid/Makefile
drivers/hid/hid-core.c
drivers/hid/hid-elo.c [new file with mode: 0644]
drivers/hid/hid-holtek-mouse.c [new file with mode: 0644]
drivers/hid/hid-ids.h
drivers/hid/hid-input.c
net/bluetooth/hidp/core.c
net/bluetooth/hidp/hidp.h

index fb52f3f6de80a377112ea0af5dfb8153772cc14e..b93e299eb272ab6d5e446c9a4124510c770575c7 100644 (file)
@@ -217,6 +217,13 @@ config HID_ELECOM
        ---help---
        Support for the ELECOM BM084 (bluetooth mouse).
 
+config HID_ELO
+       tristate "ELO USB 4000/4500 touchscreen"
+       depends on USB_HID
+       ---help---
+       Support for the ELO USB 4000/4500 touchscreens. Note that this is for
+       different devices than those handled by CONFIG_TOUCHSCREEN_USB_ELO.
+
 config HID_EZKEY
        tristate "Ezkey BTC 8193 keyboard" if EXPERT
        depends on HID
@@ -231,6 +238,9 @@ config HID_HOLTEK
        Support for Holtek based devices:
          - Holtek On Line Grip based game controller
          - Trust GXT 18 Gaming Keyboard
+         - Sharkoon Drakonia / Perixx MX-2000 gaming mice
+         - Tracer Sniper TRM-503 / NOVA Gaming Slider X200 /
+           Zalman ZM-GM1
 
 config HOLTEK_FF
        bool "Holtek On Line Grip force feedback support"
index 2065694f57abe482693371988781421404a2485e..7a0340ace1860747c087444a908a9f1d2243247a 100644 (file)
@@ -48,9 +48,11 @@ obj-$(CONFIG_HID_CYPRESS)    += hid-cypress.o
 obj-$(CONFIG_HID_DRAGONRISE)   += hid-dr.o
 obj-$(CONFIG_HID_EMS_FF)       += hid-emsff.o
 obj-$(CONFIG_HID_ELECOM)       += hid-elecom.o
+obj-$(CONFIG_HID_ELO)          += hid-elo.o
 obj-$(CONFIG_HID_EZKEY)                += hid-ezkey.o
 obj-$(CONFIG_HID_GYRATION)     += hid-gyration.o
 obj-$(CONFIG_HID_HOLTEK)       += hid-holtek-kbd.o
+obj-$(CONFIG_HID_HOLTEK)       += hid-holtek-mouse.o
 obj-$(CONFIG_HID_HOLTEK)       += hid-holtekff.o
 obj-$(CONFIG_HID_HYPERV_MOUSE) += hid-hyperv.o
 obj-$(CONFIG_HID_ICADE)                += hid-icade.o
index 264f550999406f7b924be6634917e3826e80a161..b29c956c395c93c8ed35e5de4b64b3ed03de425a 100644 (file)
@@ -1573,6 +1573,8 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006) },
        { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011) },
        { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030) },
        { HID_USB_DEVICE(USB_VENDOR_ID_EMS, USB_DEVICE_ID_EMS_TRIO_LINKER_PLUS_II) },
        { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
        { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
@@ -1584,6 +1586,8 @@ static const struct hid_device_id hid_have_special_driver[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE_3) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
        { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT, USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
        { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD) },
        { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
        { HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
diff --git a/drivers/hid/hid-elo.c b/drivers/hid/hid-elo.c
new file mode 100644 (file)
index 0000000..f042a6c
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * HID driver for ELO usb touchscreen 4000/4500
+ *
+ * Copyright (c) 2013 Jiri Slaby
+ *
+ * Data parsing taken from elousb driver by Vojtech Pavlik.
+ *
+ * This driver is licensed under the terms of GPLv2.
+ */
+
+#include <linux/hid.h>
+#include <linux/input.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/workqueue.h>
+
+#include "hid-ids.h"
+
+#define ELO_PERIODIC_READ_INTERVAL     HZ
+#define ELO_SMARTSET_CMD_TIMEOUT       2000 /* msec */
+
+/* Elo SmartSet commands */
+#define ELO_FLUSH_SMARTSET_RESPONSES   0x02 /* Flush all pending smartset responses */
+#define ELO_SEND_SMARTSET_COMMAND      0x05 /* Send a smartset command */
+#define ELO_GET_SMARTSET_RESPONSE      0x06 /* Get a smartset response */
+#define ELO_DIAG                       0x64 /* Diagnostics command */
+#define ELO_SMARTSET_PACKET_SIZE       8
+
+struct elo_priv {
+       struct usb_device *usbdev;
+       struct delayed_work work;
+       unsigned char buffer[ELO_SMARTSET_PACKET_SIZE];
+};
+
+static struct workqueue_struct *wq;
+static bool use_fw_quirk = true;
+module_param(use_fw_quirk, bool, S_IRUGO);
+MODULE_PARM_DESC(use_fw_quirk, "Do periodic pokes for broken M firmwares (default = true)");
+
+static void elo_input_configured(struct hid_device *hdev,
+               struct hid_input *hidinput)
+{
+       struct input_dev *input = hidinput->input;
+
+       set_bit(BTN_TOUCH, input->keybit);
+       set_bit(ABS_PRESSURE, input->absbit);
+       input_set_abs_params(input, ABS_PRESSURE, 0, 256, 0, 0);
+}
+
+static void elo_process_data(struct input_dev *input, const u8 *data, int size)
+{
+       int press;
+
+       input_report_abs(input, ABS_X, (data[3] << 8) | data[2]);
+       input_report_abs(input, ABS_Y, (data[5] << 8) | data[4]);
+
+       press = 0;
+       if (data[1] & 0x80)
+               press = (data[7] << 8) | data[6];
+       input_report_abs(input, ABS_PRESSURE, press);
+
+       if (data[1] & 0x03) {
+               input_report_key(input, BTN_TOUCH, 1);
+               input_sync(input);
+       }
+
+       if (data[1] & 0x04)
+               input_report_key(input, BTN_TOUCH, 0);
+
+       input_sync(input);
+}
+
+static int elo_raw_event(struct hid_device *hdev, struct hid_report *report,
+        u8 *data, int size)
+{
+       struct hid_input *hidinput;
+
+       if (!(hdev->claimed & HID_CLAIMED_INPUT) || list_empty(&hdev->inputs))
+               return 0;
+
+       hidinput = list_first_entry(&hdev->inputs, struct hid_input, list);
+
+       switch (report->id) {
+       case 0:
+               if (data[0] == 'T') {   /* Mandatory ELO packet marker */
+                       elo_process_data(hidinput->input, data, size);
+                       return 1;
+               }
+               break;
+       default:        /* unknown report */
+               /* Unknown report type; pass upstream */
+               hid_info(hdev, "unknown report type %d\n", report->id);
+               break;
+       }
+
+       return 0;
+}
+
+static int elo_smartset_send_get(struct usb_device *dev, u8 command,
+               void *data)
+{
+       unsigned int pipe;
+       u8 dir;
+
+       if (command == ELO_SEND_SMARTSET_COMMAND) {
+               pipe = usb_sndctrlpipe(dev, 0);
+               dir = USB_DIR_OUT;
+       } else if (command == ELO_GET_SMARTSET_RESPONSE) {
+               pipe = usb_rcvctrlpipe(dev, 0);
+               dir = USB_DIR_IN;
+       } else
+               return -EINVAL;
+
+       return usb_control_msg(dev, pipe, command,
+                       dir | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       0, 0, data, ELO_SMARTSET_PACKET_SIZE,
+                       ELO_SMARTSET_CMD_TIMEOUT);
+}
+
+static int elo_flush_smartset_responses(struct usb_device *dev)
+{
+       return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
+                       ELO_FLUSH_SMARTSET_RESPONSES,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
+}
+
+static void elo_work(struct work_struct *work)
+{
+       struct elo_priv *priv = container_of(work, struct elo_priv, work.work);
+       struct usb_device *dev = priv->usbdev;
+       unsigned char *buffer = priv->buffer;
+       int ret;
+
+       ret = elo_flush_smartset_responses(dev);
+       if (ret < 0) {
+               dev_err(&dev->dev, "initial FLUSH_SMARTSET_RESPONSES failed, error %d\n",
+                               ret);
+               goto fail;
+       }
+
+       /* send Diagnostics command */
+       *buffer = ELO_DIAG;
+       ret = elo_smartset_send_get(dev, ELO_SEND_SMARTSET_COMMAND, buffer);
+       if (ret < 0) {
+               dev_err(&dev->dev, "send Diagnostics Command failed, error %d\n",
+                               ret);
+               goto fail;
+       }
+
+       /* get the result */
+       ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE, buffer);
+       if (ret < 0) {
+               dev_err(&dev->dev, "get Diagnostics Command response failed, error %d\n",
+                               ret);
+               goto fail;
+       }
+
+       /* read the ack */
+       if (*buffer != 'A') {
+               ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE,
+                               buffer);
+               if (ret < 0) {
+                       dev_err(&dev->dev, "get acknowledge response failed, error %d\n",
+                                       ret);
+                       goto fail;
+               }
+       }
+
+fail:
+       ret = elo_flush_smartset_responses(dev);
+       if (ret < 0)
+               dev_err(&dev->dev, "final FLUSH_SMARTSET_RESPONSES failed, error %d\n",
+                               ret);
+       queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL);
+}
+
+/*
+ * Not all Elo devices need the periodic HID descriptor reads.
+ * Only firmware version M needs this.
+ */
+static bool elo_broken_firmware(struct usb_device *dev)
+{
+       return use_fw_quirk && le16_to_cpu(dev->descriptor.bcdDevice) == 0x10d;
+}
+
+static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
+{
+       struct elo_priv *priv;
+       int ret;
+
+       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       INIT_DELAYED_WORK(&priv->work, elo_work);
+       priv->usbdev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
+
+       hid_set_drvdata(hdev, priv);
+
+       ret = hid_parse(hdev);
+       if (ret) {
+               hid_err(hdev, "parse failed\n");
+               goto err_free;
+       }
+
+       ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+       if (ret) {
+               hid_err(hdev, "hw start failed\n");
+               goto err_free;
+       }
+
+       if (elo_broken_firmware(priv->usbdev)) {
+               hid_info(hdev, "broken firmware found, installing workaround\n");
+               queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL);
+       }
+
+       return 0;
+err_free:
+       kfree(priv);
+       return ret;
+}
+
+static void elo_remove(struct hid_device *hdev)
+{
+       struct elo_priv *priv = hid_get_drvdata(hdev);
+
+       hid_hw_stop(hdev);
+       flush_workqueue(wq);
+       kfree(priv);
+}
+
+static const struct hid_device_id elo_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009), },
+       { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030), },
+       { }
+};
+MODULE_DEVICE_TABLE(hid, elo_devices);
+
+static struct hid_driver elo_driver = {
+       .name = "elo",
+       .id_table = elo_devices,
+       .probe = elo_probe,
+       .remove = elo_remove,
+       .raw_event = elo_raw_event,
+       .input_configured = elo_input_configured,
+};
+
+static int __init elo_driver_init(void)
+{
+       int ret;
+
+       wq = create_singlethread_workqueue("elousb");
+       if (!wq)
+               return -ENOMEM;
+
+       ret = hid_register_driver(&elo_driver);
+       if (ret)
+               destroy_workqueue(wq);
+
+       return ret;
+}
+module_init(elo_driver_init);
+
+static void __exit elo_driver_exit(void)
+{
+       hid_unregister_driver(&elo_driver);
+       destroy_workqueue(wq);
+}
+module_exit(elo_driver_exit);
+
+MODULE_AUTHOR("Jiri Slaby <jslaby@suse.cz>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-holtek-mouse.c b/drivers/hid/hid-holtek-mouse.c
new file mode 100644 (file)
index 0000000..7e6db3c
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * HID driver for Holtek gaming mice
+ * Copyright (c) 2013 Christian Ohm
+ * Heavily inspired by various other HID drivers that adjust the report
+ * descriptor.
+*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ */
+
+#include <linux/hid.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+#include "hid-ids.h"
+
+/*
+ * The report descriptor of some Holtek based gaming mice specifies an
+ * excessively large number of consumer usages (2^15), which is more than
+ * HID_MAX_USAGES. This prevents proper parsing of the report descriptor.
+ *
+ * This driver fixes the report descriptor for:
+ * - USB ID 04d9:a067, sold as Sharkoon Drakonia and Perixx MX-2000
+ * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
+ *   and Zalman ZM-GM1
+ */
+
+static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
+               unsigned int *rsize)
+{
+       struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
+
+       if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
+               /* Change usage maximum and logical maximum from 0x7fff to
+                * 0x2fff, so they don't exceed HID_MAX_USAGES */
+               switch (hdev->product) {
+               case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
+                       if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
+                                       && rdesc[120] == 0xff && rdesc[121] == 0x7f) {
+                               hid_info(hdev, "Fixing up report descriptor\n");
+                               rdesc[116] = rdesc[121] = 0x2f;
+                       }
+                       break;
+               case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A:
+                       if (*rsize >= 113 && rdesc[106] == 0xff && rdesc[107] == 0x7f
+                                       && rdesc[111] == 0xff && rdesc[112] == 0x7f) {
+                               hid_info(hdev, "Fixing up report descriptor\n");
+                               rdesc[107] = rdesc[112] = 0x2f;
+                       }
+                       break;
+               }
+
+       }
+       return rdesc;
+}
+
+static const struct hid_device_id holtek_mouse_devices[] = {
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
+                       USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
+       { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
+                       USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
+       { }
+};
+MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);
+
+static struct hid_driver holtek_mouse_driver = {
+       .name = "holtek_mouse",
+       .id_table = holtek_mouse_devices,
+       .report_fixup = holtek_mouse_report_fixup,
+};
+
+module_hid_driver(holtek_mouse_driver);
+MODULE_LICENSE("GPL");
index 38535c9243d532b36d8cd321638fd4f2aeabb9c4..a9fcb9ea6c16f95cdfb5fd79d94122f3d6aedddf 100644 (file)
 
 #define USB_VENDOR_ID_HOLTEK_ALT               0x04d9
 #define USB_DEVICE_ID_HOLTEK_ALT_KEYBOARD      0xa055
+#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067    0xa067
+#define USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A    0xa04a
 
 #define USB_VENDOR_ID_IMATION          0x0718
 #define USB_DEVICE_ID_DISC_STAKKA      0xd000
index 945b8158ec4c7f556d6c9db8753762ac958276c1..c526a3ccbe5b1389f4bb824b7bf2f4db8ae230ee 100644 (file)
@@ -354,10 +354,10 @@ static int hidinput_get_battery_property(struct power_supply *psy,
                                              dev->battery_report_type);
 
                if (ret != 2) {
-                       if (ret >= 0)
-                               ret = -EINVAL;
+                       ret = -ENODATA;
                        break;
                }
+               ret = 0;
 
                if (dev->battery_min < dev->battery_max &&
                    buf[1] >= dev->battery_min &&
index 940f5acb6694c3901c0607df32ecc8fef1e5f224..46c6a148f0b361ac4f7a87a63b039fb5949d510a 100644 (file)
@@ -850,6 +850,29 @@ static void hidp_session_dev_del(struct hidp_session *session)
                input_unregister_device(session->input);
 }
 
+/*
+ * Asynchronous device registration
+ * HID device drivers might want to perform I/O during initialization to
+ * detect device types. Therefore, call device registration in a separate
+ * worker so the HIDP thread can schedule I/O operations.
+ * Note that this must be called after the worker thread was initialized
+ * successfully. This will then add the devices and increase session state
+ * on success, otherwise it will terminate the session thread.
+ */
+static void hidp_session_dev_work(struct work_struct *work)
+{
+       struct hidp_session *session = container_of(work,
+                                                   struct hidp_session,
+                                                   dev_init);
+       int ret;
+
+       ret = hidp_session_dev_add(session);
+       if (!ret)
+               atomic_inc(&session->state);
+       else
+               hidp_session_terminate(session);
+}
+
 /*
  * Create new session object
  * Allocate session object, initialize static fields, copy input data into the
@@ -897,6 +920,7 @@ static int hidp_session_new(struct hidp_session **out, const bdaddr_t *bdaddr,
        session->idle_to = req->idle_to;
 
        /* device management */
+       INIT_WORK(&session->dev_init, hidp_session_dev_work);
        setup_timer(&session->timer, hidp_idle_timeout,
                    (unsigned long)session);
 
@@ -1035,8 +1059,8 @@ static void hidp_session_terminate(struct hidp_session *session)
  * Probe HIDP session
  * This is called from the l2cap_conn core when our l2cap_user object is bound
  * to the hci-connection. We get the session via the \user object and can now
- * start the session thread, register the HID/input devices and link it into
- * the global session list.
+ * start the session thread, link it into the global session list and
+ * schedule HID/input device registration.
  * The global session-list owns its own reference to the session object so you
  * can drop your own reference after registering the l2cap_user object.
  */
@@ -1058,21 +1082,30 @@ static int hidp_session_probe(struct l2cap_conn *conn,
                goto out_unlock;
        }
 
+       if (session->input) {
+               ret = hidp_session_dev_add(session);
+               if (ret)
+                       goto out_unlock;
+       }
+
        ret = hidp_session_start_sync(session);
        if (ret)
-               goto out_unlock;
+               goto out_del;
 
-       ret = hidp_session_dev_add(session);
-       if (ret)
-               goto out_stop;
+       /* HID device registration is async to allow I/O during probe */
+       if (session->input)
+               atomic_inc(&session->state);
+       else
+               schedule_work(&session->dev_init);
 
        hidp_session_get(session);
        list_add(&session->list, &hidp_session_list);
        ret = 0;
        goto out_unlock;
 
-out_stop:
-       hidp_session_terminate(session);
+out_del:
+       if (session->input)
+               hidp_session_dev_del(session);
 out_unlock:
        up_write(&hidp_session_sem);
        return ret;
@@ -1102,7 +1135,12 @@ static void hidp_session_remove(struct l2cap_conn *conn,
        down_write(&hidp_session_sem);
 
        hidp_session_terminate(session);
-       hidp_session_dev_del(session);
+
+       cancel_work_sync(&session->dev_init);
+       if (session->input ||
+           atomic_read(&session->state) > HIDP_SESSION_PREPARING)
+               hidp_session_dev_del(session);
+
        list_del(&session->list);
 
        up_write(&hidp_session_sem);
index 6162ce8606acc8206dbc3ce437425518aee8a8c2..9e6cc355310504ae965035e033bdac7d5008527b 100644 (file)
@@ -128,6 +128,7 @@ int hidp_get_conninfo(struct hidp_conninfo *ci);
 
 enum hidp_session_state {
        HIDP_SESSION_IDLING,
+       HIDP_SESSION_PREPARING,
        HIDP_SESSION_RUNNING,
 };
 
@@ -156,6 +157,7 @@ struct hidp_session {
        unsigned long idle_to;
 
        /* device management */
+       struct work_struct dev_init;
        struct input_dev *input;
        struct hid_device *hid;
        struct timer_list timer;