Skip to content

Commit d66435c

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
Pull HID updates from Jiri Kosina: - functionally equivalent cleanups for wacom driver, making the code more readable, from Benjamin Tissoires - a bunch of improvements and fixes for thingm driver from Heiner Kallweit - bugfixes to out-of-bound access for generic parsing functions (which have been there since ever) extract() and implement(), from Dmitry Torokhov - a lot of added / improved device support in sony, wacom, microsoft, multitouch and logitech driver, from various people * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: (44 commits) HID: microsoft: Add ID for MS Wireless Comfort Keyboard hid: thingm: reorder calls in thingm_probe HID: i2c-hid: fix OOB write in i2c_hid_set_or_send_report() HID: multitouch: Release all touch slots on reset_resume HID: usbhid: enable NO_INIT_REPORTS quirk for Semico USB Keykoard2 HID: penmount: report only one button for PenMount 6000 USB touchscreen controller HID: i2c-hid: Fix suspend/resume when already runtime suspended HID: i2c-hid: Add hid-over-i2c name to i2c id table HID: multitouch: force retrieving of Win8 signature blob HID: Support for CMedia CM6533 HID audio jack controls HID: thingm: improve locking HID: thingm: switch to managed version of led_classdev_register HID: thingm: remove workqueue HID: corsair: fix mapping of non-keyboard usages HID: wacom: close the wireless receiver on remove() HID: wacom: cleanup input devices HID: wacom: reuse wacom_parse_and_register() in wireless_work HID: wacom: move down wireless_work() HID: wacom: break out parsing of device and registering of input HID: wacom: break out wacom_intuos_get_tool_type ...
2 parents 1a46712 + e1c9b9f commit d66435c

19 files changed

+1422
-630
lines changed

drivers/hid/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ config HID_PRODIKEYS
196196
multimedia keyboard, but will lack support for the musical keyboard
197197
and some additional multimedia keys.
198198

199+
config HID_CMEDIA
200+
tristate "CMedia CM6533 HID audio jack controls"
201+
depends on HID
202+
---help---
203+
Support for CMedia CM6533 HID audio jack controls.
204+
199205
config HID_CP2112
200206
tristate "Silicon Labs CP2112 HID USB-to-SMBus Bridge support"
201207
depends on USB_HID && I2C && GPIOLIB

drivers/hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ obj-$(CONFIG_HID_BELKIN) += hid-belkin.o
2929
obj-$(CONFIG_HID_BETOP_FF) += hid-betopff.o
3030
obj-$(CONFIG_HID_CHERRY) += hid-cherry.o
3131
obj-$(CONFIG_HID_CHICONY) += hid-chicony.o
32+
obj-$(CONFIG_HID_CMEDIA) += hid-cmedia.o
3233
obj-$(CONFIG_HID_CORSAIR) += hid-corsair.o
3334
obj-$(CONFIG_HID_CP2112) += hid-cp2112.o
3435
obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o

drivers/hid/hid-cmedia.c

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* HID driver for CMedia CM6533 audio jack controls
3+
*
4+
* Copyright (C) 2015 Ben Chen <[email protected]>
5+
*
6+
* This software is licensed under the terms of the GNU General Public
7+
* License version 2, as published by the Free Software Foundation, and
8+
* may be copied, distributed, and modified under those terms.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*/
15+
16+
#include <linux/device.h>
17+
#include <linux/hid.h>
18+
#include <linux/module.h>
19+
#include "hid-ids.h"
20+
21+
MODULE_AUTHOR("Ben Chen");
22+
MODULE_DESCRIPTION("CM6533 HID jack controls");
23+
MODULE_LICENSE("GPL");
24+
25+
#define CM6533_JD_TYPE_COUNT 1
26+
#define CM6533_JD_RAWEV_LEN 16
27+
#define CM6533_JD_SFX_OFFSET 8
28+
29+
/*
30+
*
31+
*CM6533 audio jack HID raw events:
32+
*
33+
*Plug in:
34+
*01000600 002083xx 080008c0 10000000
35+
*about 3 seconds later...
36+
*01000a00 002083xx 08000380 10000000
37+
*01000600 002083xx 08000380 10000000
38+
*
39+
*Plug out:
40+
*01000400 002083xx 080008c0 x0000000
41+
*/
42+
43+
static const u8 ji_sfx[] = { 0x08, 0x00, 0x08, 0xc0 };
44+
static const u8 ji_in[] = { 0x01, 0x00, 0x06, 0x00 };
45+
static const u8 ji_out[] = { 0x01, 0x00, 0x04, 0x00 };
46+
47+
static int jack_switch_types[CM6533_JD_TYPE_COUNT] = {
48+
SW_HEADPHONE_INSERT,
49+
};
50+
51+
struct cmhid {
52+
struct input_dev *input_dev;
53+
struct hid_device *hid;
54+
unsigned short switch_map[CM6533_JD_TYPE_COUNT];
55+
};
56+
57+
static void hp_ev(struct hid_device *hid, struct cmhid *cm, int value)
58+
{
59+
input_report_switch(cm->input_dev, SW_HEADPHONE_INSERT, value);
60+
input_sync(cm->input_dev);
61+
}
62+
63+
static int cmhid_raw_event(struct hid_device *hid, struct hid_report *report,
64+
u8 *data, int len)
65+
{
66+
struct cmhid *cm = hid_get_drvdata(hid);
67+
68+
if (len != CM6533_JD_RAWEV_LEN)
69+
goto out;
70+
if (memcmp(data+CM6533_JD_SFX_OFFSET, ji_sfx, sizeof(ji_sfx)))
71+
goto out;
72+
73+
if (!memcmp(data, ji_out, sizeof(ji_out))) {
74+
hp_ev(hid, cm, 0);
75+
goto out;
76+
}
77+
if (!memcmp(data, ji_in, sizeof(ji_in))) {
78+
hp_ev(hid, cm, 1);
79+
goto out;
80+
}
81+
82+
out:
83+
return 0;
84+
}
85+
86+
static int cmhid_input_configured(struct hid_device *hid,
87+
struct hid_input *hidinput)
88+
{
89+
struct input_dev *input_dev = hidinput->input;
90+
struct cmhid *cm = hid_get_drvdata(hid);
91+
int i;
92+
93+
cm->input_dev = input_dev;
94+
memcpy(cm->switch_map, jack_switch_types, sizeof(cm->switch_map));
95+
input_dev->evbit[0] = BIT(EV_SW);
96+
for (i = 0; i < CM6533_JD_TYPE_COUNT; i++)
97+
input_set_capability(cm->input_dev,
98+
EV_SW, jack_switch_types[i]);
99+
return 0;
100+
}
101+
102+
static int cmhid_input_mapping(struct hid_device *hid,
103+
struct hid_input *hi, struct hid_field *field,
104+
struct hid_usage *usage, unsigned long **bit, int *max)
105+
{
106+
return -1;
107+
}
108+
109+
static int cmhid_probe(struct hid_device *hid, const struct hid_device_id *id)
110+
{
111+
int ret;
112+
struct cmhid *cm;
113+
114+
cm = kzalloc(sizeof(struct cmhid), GFP_KERNEL);
115+
if (!cm) {
116+
ret = -ENOMEM;
117+
goto allocfail;
118+
}
119+
120+
cm->hid = hid;
121+
122+
hid->quirks |= HID_QUIRK_HIDINPUT_FORCE;
123+
hid_set_drvdata(hid, cm);
124+
125+
ret = hid_parse(hid);
126+
if (ret) {
127+
hid_err(hid, "parse failed\n");
128+
goto fail;
129+
}
130+
131+
ret = hid_hw_start(hid, HID_CONNECT_DEFAULT | HID_CONNECT_HIDDEV_FORCE);
132+
if (ret) {
133+
hid_err(hid, "hw start failed\n");
134+
goto fail;
135+
}
136+
137+
return 0;
138+
fail:
139+
kfree(cm);
140+
allocfail:
141+
return ret;
142+
}
143+
144+
static void cmhid_remove(struct hid_device *hid)
145+
{
146+
struct cmhid *cm = hid_get_drvdata(hid);
147+
148+
hid_hw_stop(hid);
149+
kfree(cm);
150+
}
151+
152+
static const struct hid_device_id cmhid_devices[] = {
153+
{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
154+
{ }
155+
};
156+
MODULE_DEVICE_TABLE(hid, cmhid_devices);
157+
158+
static struct hid_driver cmhid_driver = {
159+
.name = "cm6533_jd",
160+
.id_table = cmhid_devices,
161+
.raw_event = cmhid_raw_event,
162+
.input_configured = cmhid_input_configured,
163+
.probe = cmhid_probe,
164+
.remove = cmhid_remove,
165+
.input_mapping = cmhid_input_mapping,
166+
};
167+
module_hid_driver(cmhid_driver);
168+

drivers/hid/hid-core.c

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,28 +1075,45 @@ static u32 s32ton(__s32 value, unsigned n)
10751075
* Extract/implement a data field from/to a little endian report (bit array).
10761076
*
10771077
* Code sort-of follows HID spec:
1078-
* http://www.usb.org/developers/devclass_docs/HID1_11.pdf
1078+
* http://www.usb.org/developers/hidpage/HID1_11.pdf
10791079
*
10801080
* While the USB HID spec allows unlimited length bit fields in "report
10811081
* descriptors", most devices never use more than 16 bits.
10821082
* One model of UPS is claimed to report "LINEV" as a 32-bit field.
10831083
* Search linux-kernel and linux-usb-devel archives for "hid-core extract".
10841084
*/
10851085

1086-
__u32 hid_field_extract(const struct hid_device *hid, __u8 *report,
1087-
unsigned offset, unsigned n)
1088-
{
1089-
u64 x;
1086+
static u32 __extract(u8 *report, unsigned offset, int n)
1087+
{
1088+
unsigned int idx = offset / 8;
1089+
unsigned int bit_nr = 0;
1090+
unsigned int bit_shift = offset % 8;
1091+
int bits_to_copy = 8 - bit_shift;
1092+
u32 value = 0;
1093+
u32 mask = n < 32 ? (1U << n) - 1 : ~0U;
1094+
1095+
while (n > 0) {
1096+
value |= ((u32)report[idx] >> bit_shift) << bit_nr;
1097+
n -= bits_to_copy;
1098+
bit_nr += bits_to_copy;
1099+
bits_to_copy = 8;
1100+
bit_shift = 0;
1101+
idx++;
1102+
}
1103+
1104+
return value & mask;
1105+
}
10901106

1091-
if (n > 32)
1107+
u32 hid_field_extract(const struct hid_device *hid, u8 *report,
1108+
unsigned offset, unsigned n)
1109+
{
1110+
if (n > 32) {
10921111
hid_warn(hid, "hid_field_extract() called with n (%d) > 32! (%s)\n",
10931112
n, current->comm);
1113+
n = 32;
1114+
}
10941115

1095-
report += offset >> 3; /* adjust byte index */
1096-
offset &= 7; /* now only need bit offset into one byte */
1097-
x = get_unaligned_le64(report);
1098-
x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
1099-
return (u32) x;
1116+
return __extract(report, offset, n);
11001117
}
11011118
EXPORT_SYMBOL_GPL(hid_field_extract);
11021119

@@ -1106,31 +1123,56 @@ EXPORT_SYMBOL_GPL(hid_field_extract);
11061123
* The data mangled in the bit stream remains in little endian
11071124
* order the whole time. It make more sense to talk about
11081125
* endianness of register values by considering a register
1109-
* a "cached" copy of the little endiad bit stream.
1126+
* a "cached" copy of the little endian bit stream.
11101127
*/
1111-
static void implement(const struct hid_device *hid, __u8 *report,
1112-
unsigned offset, unsigned n, __u32 value)
1128+
1129+
static void __implement(u8 *report, unsigned offset, int n, u32 value)
1130+
{
1131+
unsigned int idx = offset / 8;
1132+
unsigned int size = offset + n;
1133+
unsigned int bit_shift = offset % 8;
1134+
int bits_to_set = 8 - bit_shift;
1135+
u8 bit_mask = 0xff << bit_shift;
1136+
1137+
while (n - bits_to_set >= 0) {
1138+
report[idx] &= ~bit_mask;
1139+
report[idx] |= value << bit_shift;
1140+
value >>= bits_to_set;
1141+
n -= bits_to_set;
1142+
bits_to_set = 8;
1143+
bit_mask = 0xff;
1144+
bit_shift = 0;
1145+
idx++;
1146+
}
1147+
1148+
/* last nibble */
1149+
if (n) {
1150+
if (size % 8)
1151+
bit_mask &= (1U << (size % 8)) - 1;
1152+
report[idx] &= ~bit_mask;
1153+
report[idx] |= (value << bit_shift) & bit_mask;
1154+
}
1155+
}
1156+
1157+
static void implement(const struct hid_device *hid, u8 *report,
1158+
unsigned offset, unsigned n, u32 value)
11131159
{
1114-
u64 x;
1115-
u64 m = (1ULL << n) - 1;
1160+
u64 m;
11161161

1117-
if (n > 32)
1162+
if (n > 32) {
11181163
hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n",
11191164
__func__, n, current->comm);
1165+
n = 32;
1166+
}
11201167

1168+
m = (1ULL << n) - 1;
11211169
if (value > m)
11221170
hid_warn(hid, "%s() called with too large value %d! (%s)\n",
11231171
__func__, value, current->comm);
11241172
WARN_ON(value > m);
11251173
value &= m;
11261174

1127-
report += offset >> 3;
1128-
offset &= 7;
1129-
1130-
x = get_unaligned_le64(report);
1131-
x &= ~(m << offset);
1132-
x |= ((u64)value) << offset;
1133-
put_unaligned_le64(x, report);
1175+
__implement(report, offset, n, value);
11341176
}
11351177

11361178
/*
@@ -1251,6 +1293,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
12511293
/* Ignore report if ErrorRollOver */
12521294
if (!(field->flags & HID_MAIN_ITEM_VARIABLE) &&
12531295
value[n] >= min && value[n] <= max &&
1296+
value[n] - min < field->maxusage &&
12541297
field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
12551298
goto exit;
12561299
}
@@ -1263,11 +1306,13 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,
12631306
}
12641307

12651308
if (field->value[n] >= min && field->value[n] <= max
1309+
&& field->value[n] - min < field->maxusage
12661310
&& field->usage[field->value[n] - min].hid
12671311
&& search(value, field->value[n], count))
12681312
hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
12691313

12701314
if (value[n] >= min && value[n] <= max
1315+
&& value[n] - min < field->maxusage
12711316
&& field->usage[value[n] - min].hid
12721317
&& search(field->value, value[n], count))
12731318
hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
@@ -1891,6 +1936,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
18911936
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
18921937
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
18931938
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1939+
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DUAL_ACTION) },
18941940
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
18951941
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD_CORD) },
18961942
{ HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
@@ -1919,6 +1965,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
19191965
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) },
19201966
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) },
19211967
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_MOUSE_4500) },
1968+
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_COMFORT_KEYBOARD) },
19221969
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
19231970
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
19241971
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K_JP) },
@@ -2003,6 +2050,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
20032050
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS4_CONTROLLER) },
20042051
{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
20052052
{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGP_MOUSE) },
2053+
{ HID_USB_DEVICE(USB_VENDOR_ID_SINO_LITE, USB_DEVICE_ID_SINO_LITE_CONTROLLER) },
20062054
{ HID_USB_DEVICE(USB_VENDOR_ID_STEELSERIES, USB_DEVICE_ID_STEELSERIES_SRWS1) },
20072055
{ HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
20082056
{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM, USB_DEVICE_ID_BLINK1) },
@@ -2051,6 +2099,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
20512099
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE) },
20522100
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_NINTENDO, USB_DEVICE_ID_NINTENDO_WIIMOTE2) },
20532101
{ HID_USB_DEVICE(USB_VENDOR_ID_RAZER, USB_DEVICE_ID_RAZER_BLADE_14) },
2102+
{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM6533) },
20542103
{ }
20552104
};
20562105

@@ -2615,9 +2664,10 @@ int hid_add_device(struct hid_device *hdev)
26152664
/*
26162665
* Scan generic devices for group information
26172666
*/
2618-
if (hid_ignore_special_drivers ||
2619-
(!hdev->group &&
2620-
!hid_match_id(hdev, hid_have_special_driver))) {
2667+
if (hid_ignore_special_drivers) {
2668+
hdev->group = HID_GROUP_GENERIC;
2669+
} else if (!hdev->group &&
2670+
!hid_match_id(hdev, hid_have_special_driver)) {
26212671
ret = hid_scan_report(hdev);
26222672
if (ret)
26232673
hid_warn(hdev, "bad device descriptor (%d)\n", ret);

drivers/hid/hid-corsair.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ static int corsair_input_mapping(struct hid_device *dev,
595595
{
596596
int gkey;
597597

598+
if ((usage->hid & HID_USAGE_PAGE) != HID_UP_KEYBOARD)
599+
return 0;
600+
598601
gkey = corsair_usage_to_gkey(usage->hid & HID_USAGE);
599602
if (gkey != 0) {
600603
hid_map_usage_clear(input, usage, bit, max, EV_KEY,

0 commit comments

Comments
 (0)