]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/hid/hid-ite.c
HID: Fix assumption that devices have inputs
[mirror_ubuntu-bionic-kernel.git] / drivers / hid / hid-ite.c
1 /*
2 * HID driver for some ITE "special" devices
3 * Copyright (c) 2017 Hans de Goede <hdegoede@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10 #include <linux/device.h>
11 #include <linux/input.h>
12 #include <linux/hid.h>
13 #include <linux/module.h>
14
15 #include "hid-ids.h"
16
17 static int ite_event(struct hid_device *hdev, struct hid_field *field,
18 struct hid_usage *usage, __s32 value)
19 {
20 struct input_dev *input;
21
22 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
23 return 0;
24
25 input = field->hidinput->input;
26
27 /*
28 * The ITE8595 always reports 0 as value for the rfkill button. Luckily
29 * it is the only button in its report, and it sends a report on
30 * release only, so receiving a report means the button was pressed.
31 */
32 if (usage->hid == HID_GD_RFKILL_BTN) {
33 input_event(input, EV_KEY, KEY_RFKILL, 1);
34 input_sync(input);
35 input_event(input, EV_KEY, KEY_RFKILL, 0);
36 input_sync(input);
37 return 1;
38 }
39
40 return 0;
41 }
42
43 static const struct hid_device_id ite_devices[] = {
44 { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
45 { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) },
46 { }
47 };
48 MODULE_DEVICE_TABLE(hid, ite_devices);
49
50 static struct hid_driver ite_driver = {
51 .name = "itetech",
52 .id_table = ite_devices,
53 .event = ite_event,
54 };
55 module_hid_driver(ite_driver);
56
57 MODULE_LICENSE("GPL");