diff options
| author | Jiri Slaby <jslaby@suse.cz> | 2013-05-07 05:40:59 -0400 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2013-05-28 19:11:43 -0400 |
| commit | d8e5aec8d9e8754e4b4e12d9b61dc89fe229349b (patch) | |
| tree | 66176f53fae097251e3613718bd074018462d9e3 | |
| parent | d23efc19478ac7fb517038922b920a6979cbd958 (diff) | |
HID: elo: add quirks for broken firmware
One firmare version in the devices the driver takes care of is
completely broken and needs periodic pokes from our side. We
implemented this as a periodic delayed queue. The idea of the pokes
was taken from the suse enterprise kernel, in particular from Libor's
"Elo touchscreen firmware M workaround".
I am quoting him here:
This patch adds periodic polling of the Elo USB touchscreens. Needed
as a workaround for devices with M-level firmware, otherwise these
devices are known to misbehave (as reported by Elo developers).
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Tested-by: Petr Ostadal <postadal@suse.cz>
Cc: Oliver Neukum <oliver@neukum.org>
Cc: Vojtech Pavlik <vojtech@suse.cz>
Cc: Egbert Eich <eich@suse.com>
Cc: Libor Pechacek <lpechacek@suse.cz>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
| -rw-r--r-- | drivers/hid/hid-elo.c | 144 |
1 files changed, 143 insertions, 1 deletions
diff --git a/drivers/hid/hid-elo.c b/drivers/hid/hid-elo.c index 56143e011f22..f042a6cf8b18 100644 --- a/drivers/hid/hid-elo.c +++ b/drivers/hid/hid-elo.c | |||
| @@ -11,9 +11,32 @@ | |||
| 11 | #include <linux/hid.h> | 11 | #include <linux/hid.h> |
| 12 | #include <linux/input.h> | 12 | #include <linux/input.h> |
| 13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
| 14 | #include <linux/usb.h> | ||
| 15 | #include <linux/workqueue.h> | ||
| 14 | 16 | ||
| 15 | #include "hid-ids.h" | 17 | #include "hid-ids.h" |
| 16 | 18 | ||
| 19 | #define ELO_PERIODIC_READ_INTERVAL HZ | ||
| 20 | #define ELO_SMARTSET_CMD_TIMEOUT 2000 /* msec */ | ||
| 21 | |||
| 22 | /* Elo SmartSet commands */ | ||
| 23 | #define ELO_FLUSH_SMARTSET_RESPONSES 0x02 /* Flush all pending smartset responses */ | ||
| 24 | #define ELO_SEND_SMARTSET_COMMAND 0x05 /* Send a smartset command */ | ||
| 25 | #define ELO_GET_SMARTSET_RESPONSE 0x06 /* Get a smartset response */ | ||
| 26 | #define ELO_DIAG 0x64 /* Diagnostics command */ | ||
| 27 | #define ELO_SMARTSET_PACKET_SIZE 8 | ||
| 28 | |||
| 29 | struct elo_priv { | ||
| 30 | struct usb_device *usbdev; | ||
| 31 | struct delayed_work work; | ||
| 32 | unsigned char buffer[ELO_SMARTSET_PACKET_SIZE]; | ||
| 33 | }; | ||
| 34 | |||
| 35 | static struct workqueue_struct *wq; | ||
| 36 | static bool use_fw_quirk = true; | ||
| 37 | module_param(use_fw_quirk, bool, S_IRUGO); | ||
| 38 | MODULE_PARM_DESC(use_fw_quirk, "Do periodic pokes for broken M firmwares (default = true)"); | ||
| 39 | |||
| 17 | static void elo_input_configured(struct hid_device *hdev, | 40 | static void elo_input_configured(struct hid_device *hdev, |
| 18 | struct hid_input *hidinput) | 41 | struct hid_input *hidinput) |
| 19 | { | 42 | { |
| @@ -73,10 +96,108 @@ static int elo_raw_event(struct hid_device *hdev, struct hid_report *report, | |||
| 73 | return 0; | 96 | return 0; |
| 74 | } | 97 | } |
| 75 | 98 | ||
| 99 | static int elo_smartset_send_get(struct usb_device *dev, u8 command, | ||
| 100 | void *data) | ||
| 101 | { | ||
| 102 | unsigned int pipe; | ||
| 103 | u8 dir; | ||
| 104 | |||
| 105 | if (command == ELO_SEND_SMARTSET_COMMAND) { | ||
| 106 | pipe = usb_sndctrlpipe(dev, 0); | ||
| 107 | dir = USB_DIR_OUT; | ||
| 108 | } else if (command == ELO_GET_SMARTSET_RESPONSE) { | ||
| 109 | pipe = usb_rcvctrlpipe(dev, 0); | ||
| 110 | dir = USB_DIR_IN; | ||
| 111 | } else | ||
| 112 | return -EINVAL; | ||
| 113 | |||
| 114 | return usb_control_msg(dev, pipe, command, | ||
| 115 | dir | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
| 116 | 0, 0, data, ELO_SMARTSET_PACKET_SIZE, | ||
| 117 | ELO_SMARTSET_CMD_TIMEOUT); | ||
| 118 | } | ||
| 119 | |||
| 120 | static int elo_flush_smartset_responses(struct usb_device *dev) | ||
| 121 | { | ||
| 122 | return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), | ||
| 123 | ELO_FLUSH_SMARTSET_RESPONSES, | ||
| 124 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
| 125 | 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); | ||
| 126 | } | ||
| 127 | |||
| 128 | static void elo_work(struct work_struct *work) | ||
| 129 | { | ||
| 130 | struct elo_priv *priv = container_of(work, struct elo_priv, work.work); | ||
| 131 | struct usb_device *dev = priv->usbdev; | ||
| 132 | unsigned char *buffer = priv->buffer; | ||
| 133 | int ret; | ||
| 134 | |||
| 135 | ret = elo_flush_smartset_responses(dev); | ||
| 136 | if (ret < 0) { | ||
| 137 | dev_err(&dev->dev, "initial FLUSH_SMARTSET_RESPONSES failed, error %d\n", | ||
| 138 | ret); | ||
| 139 | goto fail; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* send Diagnostics command */ | ||
| 143 | *buffer = ELO_DIAG; | ||
| 144 | ret = elo_smartset_send_get(dev, ELO_SEND_SMARTSET_COMMAND, buffer); | ||
| 145 | if (ret < 0) { | ||
| 146 | dev_err(&dev->dev, "send Diagnostics Command failed, error %d\n", | ||
| 147 | ret); | ||
| 148 | goto fail; | ||
| 149 | } | ||
| 150 | |||
| 151 | /* get the result */ | ||
| 152 | ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE, buffer); | ||
| 153 | if (ret < 0) { | ||
| 154 | dev_err(&dev->dev, "get Diagnostics Command response failed, error %d\n", | ||
| 155 | ret); | ||
| 156 | goto fail; | ||
| 157 | } | ||
| 158 | |||
| 159 | /* read the ack */ | ||
| 160 | if (*buffer != 'A') { | ||
| 161 | ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE, | ||
| 162 | buffer); | ||
| 163 | if (ret < 0) { | ||
| 164 | dev_err(&dev->dev, "get acknowledge response failed, error %d\n", | ||
| 165 | ret); | ||
| 166 | goto fail; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | fail: | ||
| 171 | ret = elo_flush_smartset_responses(dev); | ||
| 172 | if (ret < 0) | ||
| 173 | dev_err(&dev->dev, "final FLUSH_SMARTSET_RESPONSES failed, error %d\n", | ||
| 174 | ret); | ||
| 175 | queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL); | ||
| 176 | } | ||
| 177 | |||
| 178 | /* | ||
| 179 | * Not all Elo devices need the periodic HID descriptor reads. | ||
| 180 | * Only firmware version M needs this. | ||
| 181 | */ | ||
| 182 | static bool elo_broken_firmware(struct usb_device *dev) | ||
| 183 | { | ||
| 184 | return use_fw_quirk && le16_to_cpu(dev->descriptor.bcdDevice) == 0x10d; | ||
| 185 | } | ||
| 186 | |||
| 76 | static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id) | 187 | static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 77 | { | 188 | { |
| 189 | struct elo_priv *priv; | ||
| 78 | int ret; | 190 | int ret; |
| 79 | 191 | ||
| 192 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
| 193 | if (!priv) | ||
| 194 | return -ENOMEM; | ||
| 195 | |||
| 196 | INIT_DELAYED_WORK(&priv->work, elo_work); | ||
| 197 | priv->usbdev = interface_to_usbdev(to_usb_interface(hdev->dev.parent)); | ||
| 198 | |||
| 199 | hid_set_drvdata(hdev, priv); | ||
| 200 | |||
| 80 | ret = hid_parse(hdev); | 201 | ret = hid_parse(hdev); |
| 81 | if (ret) { | 202 | if (ret) { |
| 82 | hid_err(hdev, "parse failed\n"); | 203 | hid_err(hdev, "parse failed\n"); |
| @@ -89,14 +210,24 @@ static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id) | |||
| 89 | goto err_free; | 210 | goto err_free; |
| 90 | } | 211 | } |
| 91 | 212 | ||
| 213 | if (elo_broken_firmware(priv->usbdev)) { | ||
| 214 | hid_info(hdev, "broken firmware found, installing workaround\n"); | ||
| 215 | queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL); | ||
| 216 | } | ||
| 217 | |||
| 92 | return 0; | 218 | return 0; |
| 93 | err_free: | 219 | err_free: |
| 220 | kfree(priv); | ||
| 94 | return ret; | 221 | return ret; |
| 95 | } | 222 | } |
| 96 | 223 | ||
| 97 | static void elo_remove(struct hid_device *hdev) | 224 | static void elo_remove(struct hid_device *hdev) |
| 98 | { | 225 | { |
| 226 | struct elo_priv *priv = hid_get_drvdata(hdev); | ||
| 227 | |||
| 99 | hid_hw_stop(hdev); | 228 | hid_hw_stop(hdev); |
| 229 | flush_workqueue(wq); | ||
| 230 | kfree(priv); | ||
| 100 | } | 231 | } |
| 101 | 232 | ||
| 102 | static const struct hid_device_id elo_devices[] = { | 233 | static const struct hid_device_id elo_devices[] = { |
| @@ -117,13 +248,24 @@ static struct hid_driver elo_driver = { | |||
| 117 | 248 | ||
| 118 | static int __init elo_driver_init(void) | 249 | static int __init elo_driver_init(void) |
| 119 | { | 250 | { |
| 120 | return hid_register_driver(&elo_driver); | 251 | int ret; |
| 252 | |||
| 253 | wq = create_singlethread_workqueue("elousb"); | ||
| 254 | if (!wq) | ||
| 255 | return -ENOMEM; | ||
| 256 | |||
| 257 | ret = hid_register_driver(&elo_driver); | ||
| 258 | if (ret) | ||
| 259 | destroy_workqueue(wq); | ||
| 260 | |||
| 261 | return ret; | ||
| 121 | } | 262 | } |
| 122 | module_init(elo_driver_init); | 263 | module_init(elo_driver_init); |
| 123 | 264 | ||
| 124 | static void __exit elo_driver_exit(void) | 265 | static void __exit elo_driver_exit(void) |
| 125 | { | 266 | { |
| 126 | hid_unregister_driver(&elo_driver); | 267 | hid_unregister_driver(&elo_driver); |
| 268 | destroy_workqueue(wq); | ||
| 127 | } | 269 | } |
| 128 | module_exit(elo_driver_exit); | 270 | module_exit(elo_driver_exit); |
| 129 | 271 | ||
