^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * HID driver for ELO usb touchscreen 4000/4500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2013 Jiri Slaby
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Data parsing taken from elousb driver by Vojtech Pavlik.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ELO_PERIODIC_READ_INTERVAL HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ELO_SMARTSET_CMD_TIMEOUT 2000 /* msec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* Elo SmartSet commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ELO_FLUSH_SMARTSET_RESPONSES 0x02 /* Flush all pending smartset responses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ELO_SEND_SMARTSET_COMMAND 0x05 /* Send a smartset command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ELO_GET_SMARTSET_RESPONSE 0x06 /* Get a smartset response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define ELO_DIAG 0x64 /* Diagnostics command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define ELO_SMARTSET_PACKET_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct elo_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct usb_device *usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned char buffer[ELO_SMARTSET_PACKET_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static bool use_fw_quirk = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) module_param(use_fw_quirk, bool, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_PARM_DESC(use_fw_quirk, "Do periodic pokes for broken M firmwares (default = true)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int elo_input_configured(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct hid_input *hidinput)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct input_dev *input = hidinput->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * ELO devices have one Button usage in GenDesk field, which makes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * hid-input map it to BTN_LEFT; that confuses userspace, which then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * considers the device to be a mouse/touchpad instead of touchscreen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) clear_bit(BTN_LEFT, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) set_bit(BTN_TOUCH, input->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) set_bit(ABS_PRESSURE, input->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) input_set_abs_params(input, ABS_PRESSURE, 0, 256, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static void elo_process_data(struct input_dev *input, const u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int press;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) input_report_abs(input, ABS_X, (data[3] << 8) | data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) input_report_abs(input, ABS_Y, (data[5] << 8) | data[4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) press = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (data[1] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) press = (data[7] << 8) | data[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) input_report_abs(input, ABS_PRESSURE, press);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (data[1] & 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) input_report_key(input, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (data[1] & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) input_report_key(input, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static int elo_raw_event(struct hid_device *hdev, struct hid_report *report,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct hid_input *hidinput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!(hdev->claimed & HID_CLAIMED_INPUT) || list_empty(&hdev->inputs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) hidinput = list_first_entry(&hdev->inputs, struct hid_input, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) switch (report->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (data[0] == 'T') { /* Mandatory ELO packet marker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) elo_process_data(hidinput->input, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) default: /* unknown report */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* Unknown report type; pass upstream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) hid_info(hdev, "unknown report type %d\n", report->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int elo_smartset_send_get(struct usb_device *dev, u8 command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) u8 dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (command == ELO_SEND_SMARTSET_COMMAND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) pipe = usb_sndctrlpipe(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) dir = USB_DIR_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) } else if (command == ELO_GET_SMARTSET_RESPONSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) pipe = usb_rcvctrlpipe(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dir = USB_DIR_IN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return usb_control_msg(dev, pipe, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) dir | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 0, 0, data, ELO_SMARTSET_PACKET_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ELO_SMARTSET_CMD_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int elo_flush_smartset_responses(struct usb_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) ELO_FLUSH_SMARTSET_RESPONSES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void elo_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct elo_priv *priv = container_of(work, struct elo_priv, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct usb_device *dev = priv->usbdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned char *buffer = priv->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = elo_flush_smartset_responses(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dev_err(&dev->dev, "initial FLUSH_SMARTSET_RESPONSES failed, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* send Diagnostics command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *buffer = ELO_DIAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = elo_smartset_send_get(dev, ELO_SEND_SMARTSET_COMMAND, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) dev_err(&dev->dev, "send Diagnostics Command failed, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* get the result */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) dev_err(&dev->dev, "get Diagnostics Command response failed, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* read the ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (*buffer != 'A') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ret = elo_smartset_send_get(dev, ELO_GET_SMARTSET_RESPONSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dev_err(&dev->dev, "get acknowledge response failed, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ret = elo_flush_smartset_responses(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) dev_err(&dev->dev, "final FLUSH_SMARTSET_RESPONSES failed, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * Not all Elo devices need the periodic HID descriptor reads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Only firmware version M needs this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static bool elo_broken_firmware(struct usb_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct usb_device *hub = dev->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct usb_device *child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u16 fw_lvl = le16_to_cpu(dev->descriptor.bcdDevice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) u16 child_vid, child_pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!use_fw_quirk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (fw_lvl != 0x10d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* iterate sibling devices of the touch controller */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) usb_hub_for_each_child(hub, i, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) child_vid = le16_to_cpu(child->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) child_pid = le16_to_cpu(child->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * If one of the devices below is present attached as a sibling of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * the touch controller then this is a newer IBM 4820 monitor that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * does not need the IBM-requested workaround if fw level is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * 0x010d - aka 'M'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * No other HW can have this combination.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (child_vid==0x04b3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) switch (child_pid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) case 0x4676: /* 4820 21x Video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) case 0x4677: /* 4820 51x Video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case 0x4678: /* 4820 2Lx Video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) case 0x4679: /* 4820 5Lx Video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int elo_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct elo_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!hid_is_usb(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) priv = kzalloc(sizeof(*priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) INIT_DELAYED_WORK(&priv->work, elo_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) priv->usbdev = interface_to_usbdev(to_usb_interface(hdev->dev.parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) hid_set_drvdata(hdev, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (elo_broken_firmware(priv->usbdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) hid_info(hdev, "broken firmware found, installing workaround\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) queue_delayed_work(wq, &priv->work, ELO_PERIODIC_READ_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void elo_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct elo_priv *priv = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) cancel_delayed_work_sync(&priv->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static const struct hid_device_id elo_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) { HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0030), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_DEVICE_TABLE(hid, elo_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static struct hid_driver elo_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .name = "elo",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .id_table = elo_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .probe = elo_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .remove = elo_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .raw_event = elo_raw_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .input_configured = elo_input_configured,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static int __init elo_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) wq = create_singlethread_workqueue("elousb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ret = hid_register_driver(&elo_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) destroy_workqueue(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) module_init(elo_driver_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static void __exit elo_driver_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) hid_unregister_driver(&elo_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) destroy_workqueue(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) module_exit(elo_driver_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_AUTHOR("Jiri Slaby <jslaby@suse.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) MODULE_LICENSE("GPL");