Merge branch 'x86/cpu' into perf/core, to pick up dependent patches
[linux-block.git] / drivers / hid / hid-a4tech.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
14a21cd4
JS
2/*
3 * HID driver for some a4tech "special" devices
4 *
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
7 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
8 * Copyright (c) 2006-2007 Jiri Kosina
14a21cd4
JS
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
14a21cd4
JS
13 */
14
15#include <linux/device.h>
16#include <linux/input.h>
17#include <linux/hid.h>
18#include <linux/module.h>
5a0e3ad6 19#include <linux/slab.h>
14a21cd4
JS
20
21#include "hid-ids.h"
22
23#define A4_2WHEEL_MOUSE_HACK_7 0x01
24#define A4_2WHEEL_MOUSE_HACK_B8 0x02
25
26struct a4tech_sc {
27 unsigned long quirks;
28 unsigned int hw_wheel;
29 __s32 delayed_value;
30};
31
32static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
33 struct hid_field *field, struct hid_usage *usage,
34 unsigned long **bit, int *max)
35{
36 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
37
abf82e8f 38 if (usage->type == EV_REL && usage->code == REL_WHEEL_HI_RES) {
14a21cd4 39 set_bit(REL_HWHEEL, *bit);
abf82e8f
BS
40 set_bit(REL_HWHEEL_HI_RES, *bit);
41 }
14a21cd4
JS
42
43 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007)
44 return -1;
45
46 return 0;
47}
48
49static int a4_event(struct hid_device *hdev, struct hid_field *field,
50 struct hid_usage *usage, __s32 value)
51{
52 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
53 struct input_dev *input;
54
55 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
56 !usage->type)
57 return 0;
58
59 input = field->hidinput->input;
60
61 if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) {
abf82e8f 62 if (usage->type == EV_REL && usage->code == REL_WHEEL_HI_RES) {
14a21cd4
JS
63 a4->delayed_value = value;
64 return 1;
65 }
66
67 if (usage->hid == 0x000100b8) {
68 input_event(input, EV_REL, value ? REL_HWHEEL :
69 REL_WHEEL, a4->delayed_value);
abf82e8f
BS
70 input_event(input, EV_REL, value ? REL_HWHEEL_HI_RES :
71 REL_WHEEL_HI_RES, a4->delayed_value * 120);
14a21cd4
JS
72 return 1;
73 }
74 }
75
76 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) {
77 a4->hw_wheel = !!value;
78 return 1;
79 }
80
abf82e8f 81 if (usage->code == REL_WHEEL_HI_RES && a4->hw_wheel) {
14a21cd4 82 input_event(input, usage->type, REL_HWHEEL, value);
abf82e8f 83 input_event(input, usage->type, REL_HWHEEL_HI_RES, value * 120);
14a21cd4
JS
84 return 1;
85 }
86
87 return 0;
88}
89
90static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
91{
92 struct a4tech_sc *a4;
93 int ret;
94
abf832bf 95 a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
14a21cd4 96 if (a4 == NULL) {
4291ee30 97 hid_err(hdev, "can't alloc device descriptor\n");
abf832bf 98 return -ENOMEM;
14a21cd4
JS
99 }
100
101 a4->quirks = id->driver_data;
102
103 hid_set_drvdata(hdev, a4);
104
105 ret = hid_parse(hdev);
106 if (ret) {
4291ee30 107 hid_err(hdev, "parse failed\n");
abf832bf 108 return ret;
14a21cd4
JS
109 }
110
93c10132 111 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
14a21cd4 112 if (ret) {
4291ee30 113 hid_err(hdev, "hw start failed\n");
abf832bf 114 return ret;
14a21cd4
JS
115 }
116
117 return 0;
14a21cd4
JS
118}
119
120static const struct hid_device_id a4_devices[] = {
121 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
122 .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
123 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
124 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
b7e1b203
LP
125 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_RP_649),
126 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
14a21cd4
JS
127 { }
128};
129MODULE_DEVICE_TABLE(hid, a4_devices);
130
131static struct hid_driver a4_driver = {
132 .name = "a4tech",
133 .id_table = a4_devices,
134 .input_mapped = a4_input_mapped,
135 .event = a4_event,
136 .probe = a4_probe,
14a21cd4 137};
f425458e 138module_hid_driver(a4_driver);
14a21cd4 139
14a21cd4 140MODULE_LICENSE("GPL");