1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * HID driver for Lenovo:
4 * - ThinkPad USB Keyboard with TrackPoint (tpkbd)
5 * - ThinkPad Compact Bluetooth Keyboard with TrackPoint (cptkbd)
6 * - ThinkPad Compact USB Keyboard with TrackPoint (cptkbd)
7 * - ThinkPad TrackPoint Keyboard II USB/Bluetooth (cptkbd/tpIIkbd)
9 * Copyright (c) 2012 Bernhard Seibold
10 * Copyright (c) 2014 Jamie Lentin <jm@lentin.co.uk>
12 * Linux IBM/Lenovo Scrollpoint mouse driver:
13 * - IBM Scrollpoint III
14 * - IBM Scrollpoint Pro
15 * - IBM Scrollpoint Optical
16 * - IBM Scrollpoint Optical 800dpi
17 * - IBM Scrollpoint Optical 800dpi Pro
18 * - Lenovo Scrollpoint Optical
20 * Copyright (c) 2012 Peter De Wachter <pdewacht@gmail.com>
21 * Copyright (c) 2018 Peter Ganzhorn <peter.ganzhorn@gmail.com>
27 #include <linux/module.h>
28 #include <linux/sysfs.h>
29 #include <linux/device.h>
30 #include <linux/hid.h>
31 #include <linux/input.h>
32 #include <linux/leds.h>
33 #include <linux/workqueue.h>
37 /* Userspace expects F20 for mic-mute KEY_MICMUTE does not work */
38 #define LENOVO_KEY_MICMUTE KEY_F20
40 struct lenovo_drvdata
{
41 u8 led_report
[3]; /* Must be first for proper alignment */
43 struct mutex led_report_mutex
;
44 struct led_classdev led_mute
;
45 struct led_classdev led_micmute
;
46 struct work_struct fn_lock_sync_work
;
47 struct hid_device
*hdev
;
50 int release_to_select
;
58 u8 middlebutton_state
;
60 bool middleclick_workaround_cptkbd
;
63 #define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
65 #define TP10UBKBD_LED_OUTPUT_REPORT 9
67 #define TP10UBKBD_FN_LOCK_LED 0x54
68 #define TP10UBKBD_MUTE_LED 0x64
69 #define TP10UBKBD_MICMUTE_LED 0x74
71 #define TP10UBKBD_LED_OFF 1
72 #define TP10UBKBD_LED_ON 2
74 static int lenovo_led_set_tp10ubkbd(struct hid_device
*hdev
, u8 led_code
,
75 enum led_brightness value
)
77 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
80 mutex_lock(&data
->led_report_mutex
);
82 data
->led_report
[0] = TP10UBKBD_LED_OUTPUT_REPORT
;
83 data
->led_report
[1] = led_code
;
84 data
->led_report
[2] = value
? TP10UBKBD_LED_ON
: TP10UBKBD_LED_OFF
;
85 ret
= hid_hw_raw_request(hdev
, data
->led_report
[0], data
->led_report
, 3,
86 HID_OUTPUT_REPORT
, HID_REQ_SET_REPORT
);
89 hid_err(hdev
, "Set LED output report error: %d\n", ret
);
91 ret
= ret
< 0 ? ret
: -EIO
;
96 mutex_unlock(&data
->led_report_mutex
);
101 static void lenovo_tp10ubkbd_sync_fn_lock(struct work_struct
*work
)
103 struct lenovo_drvdata
*data
=
104 container_of(work
, struct lenovo_drvdata
, fn_lock_sync_work
);
106 lenovo_led_set_tp10ubkbd(data
->hdev
, TP10UBKBD_FN_LOCK_LED
,
110 static const __u8 lenovo_pro_dock_need_fixup_collection
[] = {
111 0x05, 0x88, /* Usage Page (Vendor Usage Page 0x88) */
112 0x09, 0x01, /* Usage (Vendor Usage 0x01) */
113 0xa1, 0x01, /* Collection (Application) */
114 0x85, 0x04, /* Report ID (4) */
115 0x19, 0x00, /* Usage Minimum (0) */
116 0x2a, 0xff, 0xff, /* Usage Maximum (65535) */
119 /* Broken ThinkPad TrackPoint II collection (Bluetooth mode) */
120 static const __u8 lenovo_tpIIbtkbd_need_fixup_collection
[] = {
121 0x06, 0x00, 0xFF, /* Usage Page (Vendor Defined 0xFF00) */
122 0x09, 0x01, /* Usage (0x01) */
123 0xA1, 0x01, /* Collection (Application) */
124 0x85, 0x05, /* Report ID (5) */
125 0x1A, 0xF1, 0x00, /* Usage Minimum (0xF1) */
126 0x2A, 0xFC, 0x00, /* Usage Maximum (0xFC) */
127 0x15, 0x00, /* Logical Minimum (0) */
128 0x25, 0x01, /* Logical Maximum (1) */
129 0x75, 0x01, /* Report Size (1) */
130 0x95, 0x0D, /* Report Count (13) */
131 0x81, 0x02, /* Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) */
132 0x95, 0x03, /* Report Count (3) */
133 0x81, 0x01, /* Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) */
136 static const __u8
*lenovo_report_fixup(struct hid_device
*hdev
, __u8
*rdesc
,
139 switch (hdev
->product
) {
140 case USB_DEVICE_ID_LENOVO_TPPRODOCK
:
141 /* the fixups that need to be done:
142 * - get a reasonable usage max for the vendor collection
143 * 0x8801 from the report ID 4
146 memcmp(&rdesc
[140], lenovo_pro_dock_need_fixup_collection
,
147 sizeof(lenovo_pro_dock_need_fixup_collection
)) == 0) {
152 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
154 memcmp(&rdesc
[234], lenovo_tpIIbtkbd_need_fixup_collection
,
155 sizeof(lenovo_tpIIbtkbd_need_fixup_collection
)) == 0) {
156 rdesc
[244] = 0x00; /* usage minimum = 0x00 */
157 rdesc
[247] = 0xff; /* usage maximum = 0xff */
158 rdesc
[252] = 0xff; /* logical maximum = 0xff */
159 rdesc
[254] = 0x08; /* report size = 0x08 */
160 rdesc
[256] = 0x01; /* report count = 0x01 */
161 rdesc
[258] = 0x00; /* input = 0x00 */
162 rdesc
[260] = 0x01; /* report count (2) = 0x01 */
169 static int lenovo_input_mapping_tpkbd(struct hid_device
*hdev
,
170 struct hid_input
*hi
, struct hid_field
*field
,
171 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
173 if (usage
->hid
== (HID_UP_BUTTON
| 0x0010)) {
174 /* This sub-device contains trackpoint, mark it */
175 hid_set_drvdata(hdev
, (void *)1);
176 map_key_clear(LENOVO_KEY_MICMUTE
);
182 static int lenovo_input_mapping_cptkbd(struct hid_device
*hdev
,
183 struct hid_input
*hi
, struct hid_field
*field
,
184 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
186 /* HID_UP_LNVENDOR = USB, HID_UP_MSVENDOR = BT */
187 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_MSVENDOR
||
188 (usage
->hid
& HID_USAGE_PAGE
) == HID_UP_LNVENDOR
) {
189 switch (usage
->hid
& HID_USAGE
) {
190 case 0x00f1: /* Fn-F4: Mic mute */
191 map_key_clear(LENOVO_KEY_MICMUTE
);
193 case 0x00f2: /* Fn-F5: Brightness down */
194 map_key_clear(KEY_BRIGHTNESSDOWN
);
196 case 0x00f3: /* Fn-F6: Brightness up */
197 map_key_clear(KEY_BRIGHTNESSUP
);
199 case 0x00f4: /* Fn-F7: External display (projector) */
200 map_key_clear(KEY_SWITCHVIDEOMODE
);
202 case 0x00f5: /* Fn-F8: Wireless */
203 map_key_clear(KEY_WLAN
);
205 case 0x00f6: /* Fn-F9: Control panel */
206 map_key_clear(KEY_CONFIG
);
208 case 0x00f8: /* Fn-F11: View open applications (3 boxes) */
209 map_key_clear(KEY_SCALE
);
211 case 0x00f9: /* Fn-F12: Open My computer (6 boxes) USB-only */
212 /* NB: This mapping is invented in raw_event below */
213 map_key_clear(KEY_FILE
);
215 case 0x00fa: /* Fn-Esc: Fn-lock toggle */
216 map_key_clear(KEY_FN_ESC
);
218 case 0x00fb: /* Middle mouse button (in native mode) */
219 map_key_clear(BTN_MIDDLE
);
224 /* Compatibility middle/wheel mappings should be ignored */
225 if (usage
->hid
== HID_GD_WHEEL
)
227 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_BUTTON
&&
228 (usage
->hid
& HID_USAGE
) == 0x003)
230 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_CONSUMER
&&
231 (usage
->hid
& HID_USAGE
) == 0x238)
234 /* Map wheel emulation reports: 0xffa1 = USB, 0xff10 = BT */
235 if ((usage
->hid
& HID_USAGE_PAGE
) == 0xff100000 ||
236 (usage
->hid
& HID_USAGE_PAGE
) == 0xffa10000) {
237 field
->flags
|= HID_MAIN_ITEM_RELATIVE
| HID_MAIN_ITEM_VARIABLE
;
238 field
->logical_minimum
= -127;
239 field
->logical_maximum
= 127;
241 switch (usage
->hid
& HID_USAGE
) {
243 hid_map_usage(hi
, usage
, bit
, max
, EV_REL
, REL_HWHEEL
);
246 hid_map_usage(hi
, usage
, bit
, max
, EV_REL
, REL_WHEEL
);
256 static int lenovo_input_mapping_tpIIkbd(struct hid_device
*hdev
,
257 struct hid_input
*hi
, struct hid_field
*field
,
258 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
261 * 0xff0a0000 = USB, HID_UP_MSVENDOR = BT.
263 * In BT mode, there are two HID_UP_MSVENDOR pages.
264 * Use only the page that contains report ID == 5.
266 if (((usage
->hid
& HID_USAGE_PAGE
) == 0xff0a0000 ||
267 (usage
->hid
& HID_USAGE_PAGE
) == HID_UP_MSVENDOR
) &&
268 field
->report
->id
== 5) {
269 switch (usage
->hid
& HID_USAGE
) {
270 case 0x00bb: /* Fn-F4: Mic mute */
271 map_key_clear(LENOVO_KEY_MICMUTE
);
273 case 0x00c3: /* Fn-F5: Brightness down */
274 map_key_clear(KEY_BRIGHTNESSDOWN
);
276 case 0x00c4: /* Fn-F6: Brightness up */
277 map_key_clear(KEY_BRIGHTNESSUP
);
279 case 0x00c1: /* Fn-F8: Notification center */
280 map_key_clear(KEY_NOTIFICATION_CENTER
);
282 case 0x00bc: /* Fn-F9: Control panel */
283 map_key_clear(KEY_CONFIG
);
285 case 0x00b6: /* Fn-F10: Bluetooth */
286 map_key_clear(KEY_BLUETOOTH
);
288 case 0x00b7: /* Fn-F11: Keyboard config */
289 map_key_clear(KEY_KEYBOARD
);
291 case 0x00b8: /* Fn-F12: User function */
292 map_key_clear(KEY_PROG1
);
294 case 0x00b9: /* Fn-PrtSc: Snipping tool */
295 map_key_clear(KEY_SELECTIVE_SCREENSHOT
);
297 case 0x00b5: /* Fn-Esc: Fn-lock toggle */
298 map_key_clear(KEY_FN_ESC
);
303 if ((usage
->hid
& HID_USAGE_PAGE
) == 0xffa00000) {
304 switch (usage
->hid
& HID_USAGE
) {
305 case 0x00fb: /* Middle mouse (in native USB mode) */
306 map_key_clear(BTN_MIDDLE
);
311 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_MSVENDOR
&&
312 field
->report
->id
== 21) {
313 switch (usage
->hid
& HID_USAGE
) {
314 case 0x0004: /* Middle mouse (in native Bluetooth mode) */
315 map_key_clear(BTN_MIDDLE
);
320 /* Compatibility middle/wheel mappings should be ignored */
321 if (usage
->hid
== HID_GD_WHEEL
)
323 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_BUTTON
&&
324 (usage
->hid
& HID_USAGE
) == 0x003)
326 if ((usage
->hid
& HID_USAGE_PAGE
) == HID_UP_CONSUMER
&&
327 (usage
->hid
& HID_USAGE
) == 0x238)
330 /* Map wheel emulation reports: 0xff10 */
331 if ((usage
->hid
& HID_USAGE_PAGE
) == 0xff100000) {
332 field
->flags
|= HID_MAIN_ITEM_RELATIVE
| HID_MAIN_ITEM_VARIABLE
;
333 field
->logical_minimum
= -127;
334 field
->logical_maximum
= 127;
336 switch (usage
->hid
& HID_USAGE
) {
338 hid_map_usage(hi
, usage
, bit
, max
, EV_REL
, REL_HWHEEL
);
341 hid_map_usage(hi
, usage
, bit
, max
, EV_REL
, REL_WHEEL
);
351 static int lenovo_input_mapping_scrollpoint(struct hid_device
*hdev
,
352 struct hid_input
*hi
, struct hid_field
*field
,
353 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
355 if (usage
->hid
== HID_GD_Z
) {
356 hid_map_usage(hi
, usage
, bit
, max
, EV_REL
, REL_HWHEEL
);
362 static int lenovo_input_mapping_tp10_ultrabook_kbd(struct hid_device
*hdev
,
363 struct hid_input
*hi
, struct hid_field
*field
,
364 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
367 * The ThinkPad 10 Ultrabook Keyboard uses 0x000c0001 usage for
368 * a bunch of keys which have no standard consumer page code.
370 if (usage
->hid
== 0x000c0001) {
371 switch (usage
->usage_index
) {
372 case 8: /* Fn-Esc: Fn-lock toggle */
373 map_key_clear(KEY_FN_ESC
);
375 case 9: /* Fn-F4: Mic mute */
376 map_key_clear(LENOVO_KEY_MICMUTE
);
378 case 10: /* Fn-F7: Control panel */
379 map_key_clear(KEY_CONFIG
);
381 case 11: /* Fn-F8: Search (magnifier glass) */
382 map_key_clear(KEY_SEARCH
);
384 case 12: /* Fn-F10: Open My computer (6 boxes) */
385 map_key_clear(KEY_FILE
);
391 * The Ultrabook Keyboard sends a spurious F23 key-press when resuming
392 * from suspend and it does not actually have a F23 key, ignore it.
394 if (usage
->hid
== 0x00070072)
400 static int lenovo_input_mapping_x1_tab_kbd(struct hid_device
*hdev
,
401 struct hid_input
*hi
, struct hid_field
*field
,
402 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
405 * The ThinkPad X1 Tablet Thin Keyboard uses 0x000c0001 usage for
406 * a bunch of keys which have no standard consumer page code.
408 if (usage
->hid
== 0x000c0001) {
409 switch (usage
->usage_index
) {
410 case 0: /* Fn-F10: Enable/disable bluetooth */
411 map_key_clear(KEY_BLUETOOTH
);
413 case 1: /* Fn-F11: Keyboard settings */
414 map_key_clear(KEY_KEYBOARD
);
416 case 2: /* Fn-F12: User function / Cortana */
417 map_key_clear(KEY_MACRO1
);
419 case 3: /* Fn-PrtSc: Snipping tool */
420 map_key_clear(KEY_SELECTIVE_SCREENSHOT
);
422 case 8: /* Fn-Esc: Fn-lock toggle */
423 map_key_clear(KEY_FN_ESC
);
425 case 9: /* Fn-F4: Mute/unmute microphone */
426 map_key_clear(KEY_MICMUTE
);
428 case 10: /* Fn-F9: Settings */
429 map_key_clear(KEY_CONFIG
);
431 case 13: /* Fn-F7: Manage external displays */
432 map_key_clear(KEY_SWITCHVIDEOMODE
);
434 case 14: /* Fn-F8: Enable/disable wifi */
435 map_key_clear(KEY_WLAN
);
440 if (usage
->hid
== (HID_UP_KEYBOARD
| 0x009a)) {
441 map_key_clear(KEY_SYSRQ
);
448 static int lenovo_input_mapping(struct hid_device
*hdev
,
449 struct hid_input
*hi
, struct hid_field
*field
,
450 struct hid_usage
*usage
, unsigned long **bit
, int *max
)
452 switch (hdev
->product
) {
453 case USB_DEVICE_ID_LENOVO_TPKBD
:
454 return lenovo_input_mapping_tpkbd(hdev
, hi
, field
,
456 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
457 case USB_DEVICE_ID_LENOVO_CBTKBD
:
458 return lenovo_input_mapping_cptkbd(hdev
, hi
, field
,
460 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
461 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
462 return lenovo_input_mapping_tpIIkbd(hdev
, hi
, field
,
464 case USB_DEVICE_ID_IBM_SCROLLPOINT_III
:
465 case USB_DEVICE_ID_IBM_SCROLLPOINT_PRO
:
466 case USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL
:
467 case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL
:
468 case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO
:
469 case USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL
:
470 return lenovo_input_mapping_scrollpoint(hdev
, hi
, field
,
472 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
473 return lenovo_input_mapping_tp10_ultrabook_kbd(hdev
, hi
, field
,
475 case USB_DEVICE_ID_LENOVO_X1_TAB
:
476 return lenovo_input_mapping_x1_tab_kbd(hdev
, hi
, field
, usage
, bit
, max
);
484 /* Send a config command to the keyboard */
485 static int lenovo_send_cmd_cptkbd(struct hid_device
*hdev
,
486 unsigned char byte2
, unsigned char byte3
)
491 buf
= kzalloc(3, GFP_KERNEL
);
496 * Feature report 0x13 is used for USB,
497 * output report 0x18 is used for Bluetooth.
498 * buf[0] is ignored by hid_hw_raw_request.
504 switch (hdev
->product
) {
505 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
506 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
507 ret
= hid_hw_raw_request(hdev
, 0x13, buf
, 3,
508 HID_FEATURE_REPORT
, HID_REQ_SET_REPORT
);
510 case USB_DEVICE_ID_LENOVO_CBTKBD
:
511 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
512 ret
= hid_hw_output_report(hdev
, buf
, 3);
521 return ret
< 0 ? ret
: 0; /* BT returns 0, USB returns sizeof(buf) */
524 static void lenovo_features_set_cptkbd(struct hid_device
*hdev
)
527 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
530 * Tell the keyboard a driver understands it, and turn F7, F9, F11 into
533 ret
= lenovo_send_cmd_cptkbd(hdev
, 0x01, 0x03);
535 hid_warn(hdev
, "Failed to switch F7/9/11 mode: %d\n", ret
);
537 /* Switch middle button to native mode */
538 ret
= lenovo_send_cmd_cptkbd(hdev
, 0x09, 0x01);
540 hid_warn(hdev
, "Failed to switch middle button: %d\n", ret
);
542 ret
= lenovo_send_cmd_cptkbd(hdev
, 0x05, cptkbd_data
->fn_lock
);
544 hid_err(hdev
, "Fn-lock setting failed: %d\n", ret
);
546 ret
= lenovo_send_cmd_cptkbd(hdev
, 0x02, cptkbd_data
->sensitivity
);
548 hid_err(hdev
, "Sensitivity setting failed: %d\n", ret
);
551 static ssize_t
attr_fn_lock_show(struct device
*dev
,
552 struct device_attribute
*attr
,
555 struct hid_device
*hdev
= to_hid_device(dev
);
556 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
558 return sysfs_emit(buf
, "%u\n", data
->fn_lock
);
561 static ssize_t
attr_fn_lock_store(struct device
*dev
,
562 struct device_attribute
*attr
,
566 struct hid_device
*hdev
= to_hid_device(dev
);
567 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
570 if (kstrtoint(buf
, 10, &value
))
572 if (value
< 0 || value
> 1)
575 data
->fn_lock
= !!value
;
577 switch (hdev
->product
) {
578 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
579 case USB_DEVICE_ID_LENOVO_CBTKBD
:
580 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
581 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
582 lenovo_features_set_cptkbd(hdev
);
584 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
585 case USB_DEVICE_ID_LENOVO_X1_TAB
:
586 ret
= lenovo_led_set_tp10ubkbd(hdev
, TP10UBKBD_FN_LOCK_LED
, value
);
595 static ssize_t
attr_sensitivity_show_cptkbd(struct device
*dev
,
596 struct device_attribute
*attr
,
599 struct hid_device
*hdev
= to_hid_device(dev
);
600 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
602 return sysfs_emit(buf
, "%u\n", cptkbd_data
->sensitivity
);
605 static ssize_t
attr_sensitivity_store_cptkbd(struct device
*dev
,
606 struct device_attribute
*attr
,
610 struct hid_device
*hdev
= to_hid_device(dev
);
611 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
614 if (kstrtoint(buf
, 10, &value
) || value
< 1 || value
> 255)
617 cptkbd_data
->sensitivity
= value
;
618 lenovo_features_set_cptkbd(hdev
);
623 static ssize_t
attr_middleclick_workaround_show_cptkbd(struct device
*dev
,
624 struct device_attribute
*attr
,
627 struct hid_device
*hdev
= to_hid_device(dev
);
628 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
630 return sysfs_emit(buf
, "%u\n",
631 cptkbd_data
->middleclick_workaround_cptkbd
);
634 static ssize_t
attr_middleclick_workaround_store_cptkbd(struct device
*dev
,
635 struct device_attribute
*attr
,
639 struct hid_device
*hdev
= to_hid_device(dev
);
640 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
643 if (kstrtoint(buf
, 10, &value
))
645 if (value
< 0 || value
> 1)
648 cptkbd_data
->middleclick_workaround_cptkbd
= !!value
;
654 static struct device_attribute dev_attr_fn_lock
=
655 __ATTR(fn_lock
, S_IWUSR
| S_IRUGO
,
659 static struct device_attribute dev_attr_sensitivity_cptkbd
=
660 __ATTR(sensitivity
, S_IWUSR
| S_IRUGO
,
661 attr_sensitivity_show_cptkbd
,
662 attr_sensitivity_store_cptkbd
);
664 static struct device_attribute dev_attr_middleclick_workaround_cptkbd
=
665 __ATTR(middleclick_workaround
, S_IWUSR
| S_IRUGO
,
666 attr_middleclick_workaround_show_cptkbd
,
667 attr_middleclick_workaround_store_cptkbd
);
670 static struct attribute
*lenovo_attributes_cptkbd
[] = {
671 &dev_attr_fn_lock
.attr
,
672 &dev_attr_sensitivity_cptkbd
.attr
,
673 &dev_attr_middleclick_workaround_cptkbd
.attr
,
677 static const struct attribute_group lenovo_attr_group_cptkbd
= {
678 .attrs
= lenovo_attributes_cptkbd
,
681 static int lenovo_raw_event(struct hid_device
*hdev
,
682 struct hid_report
*report
, u8
*data
, int size
)
685 * Compact USB keyboard's Fn-F12 report holds down many other keys, and
686 * its own key is outside the usage page range. Remove extra
687 * keypresses and remap to inside usage page.
689 if (unlikely(hdev
->product
== USB_DEVICE_ID_LENOVO_CUSBKBD
693 && data
[2] == 0x01)) {
701 static int lenovo_event_tp10ubkbd(struct hid_device
*hdev
,
702 struct hid_field
*field
, struct hid_usage
*usage
, __s32 value
)
704 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
706 if (usage
->type
== EV_KEY
&& usage
->code
== KEY_FN_ESC
&& value
== 1) {
708 * The user has toggled the Fn-lock state. Toggle our own
709 * cached value of it and sync our value to the keyboard to
710 * ensure things are in sync (the sycning should be a no-op).
712 data
->fn_lock
= !data
->fn_lock
;
713 schedule_work(&data
->fn_lock_sync_work
);
719 static int lenovo_event_cptkbd(struct hid_device
*hdev
,
720 struct hid_field
*field
, struct hid_usage
*usage
, __s32 value
)
722 struct lenovo_drvdata
*cptkbd_data
= hid_get_drvdata(hdev
);
724 if (cptkbd_data
->middleclick_workaround_cptkbd
) {
725 /* "wheel" scroll events */
726 if (usage
->type
== EV_REL
&& (usage
->code
== REL_WHEEL
||
727 usage
->code
== REL_HWHEEL
)) {
728 /* Scroll events disable middle-click event */
729 cptkbd_data
->middlebutton_state
= 2;
733 /* Middle click events */
734 if (usage
->type
== EV_KEY
&& usage
->code
== BTN_MIDDLE
) {
736 cptkbd_data
->middlebutton_state
= 1;
737 } else if (value
== 0) {
738 if (cptkbd_data
->middlebutton_state
== 1) {
739 /* No scrolling inbetween, send middle-click */
740 input_event(field
->hidinput
->input
,
741 EV_KEY
, BTN_MIDDLE
, 1);
742 input_sync(field
->hidinput
->input
);
743 input_event(field
->hidinput
->input
,
744 EV_KEY
, BTN_MIDDLE
, 0);
745 input_sync(field
->hidinput
->input
);
747 cptkbd_data
->middlebutton_state
= 0;
753 if (usage
->type
== EV_KEY
&& usage
->code
== KEY_FN_ESC
&& value
== 1) {
755 * The user has toggled the Fn-lock state. Toggle our own
756 * cached value of it and sync our value to the keyboard to
757 * ensure things are in sync (the syncing should be a no-op).
759 cptkbd_data
->fn_lock
= !cptkbd_data
->fn_lock
;
765 static int lenovo_event(struct hid_device
*hdev
, struct hid_field
*field
,
766 struct hid_usage
*usage
, __s32 value
)
768 if (!hid_get_drvdata(hdev
))
771 switch (hdev
->product
) {
772 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
773 case USB_DEVICE_ID_LENOVO_CBTKBD
:
774 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
775 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
776 return lenovo_event_cptkbd(hdev
, field
, usage
, value
);
777 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
778 case USB_DEVICE_ID_LENOVO_X1_TAB
:
779 return lenovo_event_tp10ubkbd(hdev
, field
, usage
, value
);
785 static int lenovo_features_set_tpkbd(struct hid_device
*hdev
)
787 struct hid_report
*report
;
788 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
790 report
= hdev
->report_enum
[HID_FEATURE_REPORT
].report_id_hash
[4];
792 report
->field
[0]->value
[0] = data_pointer
->press_to_select
? 0x01 : 0x02;
793 report
->field
[0]->value
[0] |= data_pointer
->dragging
? 0x04 : 0x08;
794 report
->field
[0]->value
[0] |= data_pointer
->release_to_select
? 0x10 : 0x20;
795 report
->field
[0]->value
[0] |= data_pointer
->select_right
? 0x80 : 0x40;
796 report
->field
[1]->value
[0] = 0x03; // unknown setting, imitate windows driver
797 report
->field
[2]->value
[0] = data_pointer
->sensitivity
;
798 report
->field
[3]->value
[0] = data_pointer
->press_speed
;
800 hid_hw_request(hdev
, report
, HID_REQ_SET_REPORT
);
804 static ssize_t
attr_press_to_select_show_tpkbd(struct device
*dev
,
805 struct device_attribute
*attr
,
808 struct hid_device
*hdev
= to_hid_device(dev
);
809 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
811 return sysfs_emit(buf
, "%u\n", data_pointer
->press_to_select
);
814 static ssize_t
attr_press_to_select_store_tpkbd(struct device
*dev
,
815 struct device_attribute
*attr
,
819 struct hid_device
*hdev
= to_hid_device(dev
);
820 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
823 if (kstrtoint(buf
, 10, &value
))
825 if (value
< 0 || value
> 1)
828 data_pointer
->press_to_select
= value
;
829 lenovo_features_set_tpkbd(hdev
);
834 static ssize_t
attr_dragging_show_tpkbd(struct device
*dev
,
835 struct device_attribute
*attr
,
838 struct hid_device
*hdev
= to_hid_device(dev
);
839 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
841 return sysfs_emit(buf
, "%u\n", data_pointer
->dragging
);
844 static ssize_t
attr_dragging_store_tpkbd(struct device
*dev
,
845 struct device_attribute
*attr
,
849 struct hid_device
*hdev
= to_hid_device(dev
);
850 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
853 if (kstrtoint(buf
, 10, &value
))
855 if (value
< 0 || value
> 1)
858 data_pointer
->dragging
= value
;
859 lenovo_features_set_tpkbd(hdev
);
864 static ssize_t
attr_release_to_select_show_tpkbd(struct device
*dev
,
865 struct device_attribute
*attr
,
868 struct hid_device
*hdev
= to_hid_device(dev
);
869 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
871 return sysfs_emit(buf
, "%u\n", data_pointer
->release_to_select
);
874 static ssize_t
attr_release_to_select_store_tpkbd(struct device
*dev
,
875 struct device_attribute
*attr
,
879 struct hid_device
*hdev
= to_hid_device(dev
);
880 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
883 if (kstrtoint(buf
, 10, &value
))
885 if (value
< 0 || value
> 1)
888 data_pointer
->release_to_select
= value
;
889 lenovo_features_set_tpkbd(hdev
);
894 static ssize_t
attr_select_right_show_tpkbd(struct device
*dev
,
895 struct device_attribute
*attr
,
898 struct hid_device
*hdev
= to_hid_device(dev
);
899 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
901 return sysfs_emit(buf
, "%u\n", data_pointer
->select_right
);
904 static ssize_t
attr_select_right_store_tpkbd(struct device
*dev
,
905 struct device_attribute
*attr
,
909 struct hid_device
*hdev
= to_hid_device(dev
);
910 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
913 if (kstrtoint(buf
, 10, &value
))
915 if (value
< 0 || value
> 1)
918 data_pointer
->select_right
= value
;
919 lenovo_features_set_tpkbd(hdev
);
924 static ssize_t
attr_sensitivity_show_tpkbd(struct device
*dev
,
925 struct device_attribute
*attr
,
928 struct hid_device
*hdev
= to_hid_device(dev
);
929 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
931 return sysfs_emit(buf
, "%u\n", data_pointer
->sensitivity
);
934 static ssize_t
attr_sensitivity_store_tpkbd(struct device
*dev
,
935 struct device_attribute
*attr
,
939 struct hid_device
*hdev
= to_hid_device(dev
);
940 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
943 if (kstrtoint(buf
, 10, &value
) || value
< 1 || value
> 255)
946 data_pointer
->sensitivity
= value
;
947 lenovo_features_set_tpkbd(hdev
);
952 static ssize_t
attr_press_speed_show_tpkbd(struct device
*dev
,
953 struct device_attribute
*attr
,
956 struct hid_device
*hdev
= to_hid_device(dev
);
957 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
959 return sysfs_emit(buf
, "%u\n", data_pointer
->press_speed
);
962 static ssize_t
attr_press_speed_store_tpkbd(struct device
*dev
,
963 struct device_attribute
*attr
,
967 struct hid_device
*hdev
= to_hid_device(dev
);
968 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
971 if (kstrtoint(buf
, 10, &value
) || value
< 1 || value
> 255)
974 data_pointer
->press_speed
= value
;
975 lenovo_features_set_tpkbd(hdev
);
980 static struct device_attribute dev_attr_press_to_select_tpkbd
=
981 __ATTR(press_to_select
, S_IWUSR
| S_IRUGO
,
982 attr_press_to_select_show_tpkbd
,
983 attr_press_to_select_store_tpkbd
);
985 static struct device_attribute dev_attr_dragging_tpkbd
=
986 __ATTR(dragging
, S_IWUSR
| S_IRUGO
,
987 attr_dragging_show_tpkbd
,
988 attr_dragging_store_tpkbd
);
990 static struct device_attribute dev_attr_release_to_select_tpkbd
=
991 __ATTR(release_to_select
, S_IWUSR
| S_IRUGO
,
992 attr_release_to_select_show_tpkbd
,
993 attr_release_to_select_store_tpkbd
);
995 static struct device_attribute dev_attr_select_right_tpkbd
=
996 __ATTR(select_right
, S_IWUSR
| S_IRUGO
,
997 attr_select_right_show_tpkbd
,
998 attr_select_right_store_tpkbd
);
1000 static struct device_attribute dev_attr_sensitivity_tpkbd
=
1001 __ATTR(sensitivity
, S_IWUSR
| S_IRUGO
,
1002 attr_sensitivity_show_tpkbd
,
1003 attr_sensitivity_store_tpkbd
);
1005 static struct device_attribute dev_attr_press_speed_tpkbd
=
1006 __ATTR(press_speed
, S_IWUSR
| S_IRUGO
,
1007 attr_press_speed_show_tpkbd
,
1008 attr_press_speed_store_tpkbd
);
1010 static struct attribute
*lenovo_attributes_tpkbd
[] = {
1011 &dev_attr_press_to_select_tpkbd
.attr
,
1012 &dev_attr_dragging_tpkbd
.attr
,
1013 &dev_attr_release_to_select_tpkbd
.attr
,
1014 &dev_attr_select_right_tpkbd
.attr
,
1015 &dev_attr_sensitivity_tpkbd
.attr
,
1016 &dev_attr_press_speed_tpkbd
.attr
,
1020 static const struct attribute_group lenovo_attr_group_tpkbd
= {
1021 .attrs
= lenovo_attributes_tpkbd
,
1024 static void lenovo_led_set_tpkbd(struct hid_device
*hdev
)
1026 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
1027 struct hid_report
*report
;
1029 report
= hdev
->report_enum
[HID_OUTPUT_REPORT
].report_id_hash
[3];
1030 report
->field
[0]->value
[0] = (data_pointer
->led_state
>> 0) & 1;
1031 report
->field
[0]->value
[1] = (data_pointer
->led_state
>> 1) & 1;
1032 hid_hw_request(hdev
, report
, HID_REQ_SET_REPORT
);
1035 static int lenovo_led_brightness_set(struct led_classdev
*led_cdev
,
1036 enum led_brightness value
)
1038 struct device
*dev
= led_cdev
->dev
->parent
;
1039 struct hid_device
*hdev
= to_hid_device(dev
);
1040 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
1041 static const u8 tp10ubkbd_led
[] = { TP10UBKBD_MUTE_LED
, TP10UBKBD_MICMUTE_LED
};
1045 if (led_cdev
== &data_pointer
->led_micmute
)
1048 if (value
== LED_OFF
)
1049 data_pointer
->led_state
&= ~(1 << led_nr
);
1051 data_pointer
->led_state
|= 1 << led_nr
;
1053 switch (hdev
->product
) {
1054 case USB_DEVICE_ID_LENOVO_TPKBD
:
1055 lenovo_led_set_tpkbd(hdev
);
1057 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
1058 case USB_DEVICE_ID_LENOVO_X1_TAB
:
1059 ret
= lenovo_led_set_tp10ubkbd(hdev
, tp10ubkbd_led
[led_nr
], value
);
1066 static int lenovo_register_leds(struct hid_device
*hdev
)
1068 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
1069 size_t name_sz
= strlen(dev_name(&hdev
->dev
)) + 16;
1070 char *name_mute
, *name_micm
;
1073 name_mute
= devm_kzalloc(&hdev
->dev
, name_sz
, GFP_KERNEL
);
1074 name_micm
= devm_kzalloc(&hdev
->dev
, name_sz
, GFP_KERNEL
);
1075 if (name_mute
== NULL
|| name_micm
== NULL
) {
1076 hid_err(hdev
, "Could not allocate memory for led data\n");
1079 snprintf(name_mute
, name_sz
, "%s:amber:mute", dev_name(&hdev
->dev
));
1080 snprintf(name_micm
, name_sz
, "%s:amber:micmute", dev_name(&hdev
->dev
));
1082 data
->led_mute
.name
= name_mute
;
1083 data
->led_mute
.default_trigger
= "audio-mute";
1084 data
->led_mute
.brightness_set_blocking
= lenovo_led_brightness_set
;
1085 data
->led_mute
.max_brightness
= 1;
1086 data
->led_mute
.flags
= LED_HW_PLUGGABLE
;
1087 data
->led_mute
.dev
= &hdev
->dev
;
1088 ret
= led_classdev_register(&hdev
->dev
, &data
->led_mute
);
1092 data
->led_micmute
.name
= name_micm
;
1093 data
->led_micmute
.default_trigger
= "audio-micmute";
1094 data
->led_micmute
.brightness_set_blocking
= lenovo_led_brightness_set
;
1095 data
->led_micmute
.max_brightness
= 1;
1096 data
->led_micmute
.flags
= LED_HW_PLUGGABLE
;
1097 data
->led_micmute
.dev
= &hdev
->dev
;
1098 ret
= led_classdev_register(&hdev
->dev
, &data
->led_micmute
);
1100 led_classdev_unregister(&data
->led_mute
);
1107 static int lenovo_probe_tpkbd(struct hid_device
*hdev
)
1109 struct lenovo_drvdata
*data_pointer
;
1113 * Only register extra settings against subdevice where input_mapping
1114 * set drvdata to 1, i.e. the trackpoint.
1116 if (!hid_get_drvdata(hdev
))
1119 hid_set_drvdata(hdev
, NULL
);
1121 /* Validate required reports. */
1122 for (i
= 0; i
< 4; i
++) {
1123 if (!hid_validate_values(hdev
, HID_FEATURE_REPORT
, 4, i
, 1))
1126 if (!hid_validate_values(hdev
, HID_OUTPUT_REPORT
, 3, 0, 2))
1129 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &lenovo_attr_group_tpkbd
);
1131 hid_warn(hdev
, "Could not create sysfs group: %d\n", ret
);
1133 data_pointer
= devm_kzalloc(&hdev
->dev
,
1134 sizeof(struct lenovo_drvdata
),
1136 if (data_pointer
== NULL
) {
1137 hid_err(hdev
, "Could not allocate memory for driver data\n");
1142 // set same default values as windows driver
1143 data_pointer
->sensitivity
= 0xa0;
1144 data_pointer
->press_speed
= 0x38;
1146 hid_set_drvdata(hdev
, data_pointer
);
1148 ret
= lenovo_register_leds(hdev
);
1152 lenovo_features_set_tpkbd(hdev
);
1156 sysfs_remove_group(&hdev
->dev
.kobj
, &lenovo_attr_group_tpkbd
);
1160 static int lenovo_probe_cptkbd(struct hid_device
*hdev
)
1163 struct lenovo_drvdata
*cptkbd_data
;
1165 /* All the custom action happens on the USBMOUSE device for USB */
1166 if (((hdev
->product
== USB_DEVICE_ID_LENOVO_CUSBKBD
) ||
1167 (hdev
->product
== USB_DEVICE_ID_LENOVO_TPIIUSBKBD
)) &&
1168 hdev
->type
!= HID_TYPE_USBMOUSE
) {
1169 hid_dbg(hdev
, "Ignoring keyboard half of device\n");
1173 cptkbd_data
= devm_kzalloc(&hdev
->dev
,
1174 sizeof(*cptkbd_data
),
1176 if (cptkbd_data
== NULL
) {
1177 hid_err(hdev
, "can't alloc keyboard descriptor\n");
1180 hid_set_drvdata(hdev
, cptkbd_data
);
1182 /* Set keyboard settings to known state */
1183 cptkbd_data
->middlebutton_state
= 0;
1184 cptkbd_data
->fn_lock
= true;
1185 cptkbd_data
->sensitivity
= 0x05;
1186 cptkbd_data
->middleclick_workaround_cptkbd
= true;
1187 lenovo_features_set_cptkbd(hdev
);
1189 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &lenovo_attr_group_cptkbd
);
1191 hid_warn(hdev
, "Could not create sysfs group: %d\n", ret
);
1196 static struct attribute
*lenovo_attributes_tp10ubkbd
[] = {
1197 &dev_attr_fn_lock
.attr
,
1201 static const struct attribute_group lenovo_attr_group_tp10ubkbd
= {
1202 .attrs
= lenovo_attributes_tp10ubkbd
,
1205 static int lenovo_probe_tp10ubkbd(struct hid_device
*hdev
)
1207 struct hid_report_enum
*rep_enum
;
1208 struct lenovo_drvdata
*data
;
1209 struct hid_report
*rep
;
1214 * The LEDs and the Fn-lock functionality use output report 9,
1215 * with an application of 0xffa0001, add the LEDs on the interface
1216 * with this output report.
1219 rep_enum
= &hdev
->report_enum
[HID_OUTPUT_REPORT
];
1220 list_for_each_entry(rep
, &rep_enum
->report_list
, list
) {
1221 if (rep
->application
== 0xffa00001)
1227 data
= devm_kzalloc(&hdev
->dev
, sizeof(*data
), GFP_KERNEL
);
1231 mutex_init(&data
->led_report_mutex
);
1232 INIT_WORK(&data
->fn_lock_sync_work
, lenovo_tp10ubkbd_sync_fn_lock
);
1235 hid_set_drvdata(hdev
, data
);
1238 * The Thinkpad 10 ultrabook USB kbd dock's Fn-lock defaults to on.
1239 * We cannot read the state, only set it, so we force it to on here
1240 * (which should be a no-op) to make sure that our state matches the
1241 * keyboard's FN-lock state. This is the same as what Windows does.
1243 data
->fn_lock
= true;
1244 lenovo_led_set_tp10ubkbd(hdev
, TP10UBKBD_FN_LOCK_LED
, data
->fn_lock
);
1246 ret
= sysfs_create_group(&hdev
->dev
.kobj
, &lenovo_attr_group_tp10ubkbd
);
1250 ret
= lenovo_register_leds(hdev
);
1256 sysfs_remove_group(&hdev
->dev
.kobj
, &lenovo_attr_group_tp10ubkbd
);
1260 static int lenovo_probe(struct hid_device
*hdev
,
1261 const struct hid_device_id
*id
)
1265 ret
= hid_parse(hdev
);
1267 hid_err(hdev
, "hid_parse failed\n");
1271 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
);
1273 hid_err(hdev
, "hid_hw_start failed\n");
1277 switch (hdev
->product
) {
1278 case USB_DEVICE_ID_LENOVO_TPKBD
:
1279 ret
= lenovo_probe_tpkbd(hdev
);
1281 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
1282 case USB_DEVICE_ID_LENOVO_CBTKBD
:
1283 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
1284 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
1285 ret
= lenovo_probe_cptkbd(hdev
);
1287 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
1288 case USB_DEVICE_ID_LENOVO_X1_TAB
:
1289 ret
= lenovo_probe_tp10ubkbd(hdev
);
1306 static int lenovo_reset_resume(struct hid_device
*hdev
)
1308 switch (hdev
->product
) {
1309 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
1310 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
1311 if (hdev
->type
== HID_TYPE_USBMOUSE
)
1312 lenovo_features_set_cptkbd(hdev
);
1323 static void lenovo_remove_tpkbd(struct hid_device
*hdev
)
1325 struct lenovo_drvdata
*data_pointer
= hid_get_drvdata(hdev
);
1328 * Only the trackpoint half of the keyboard has drvdata and stuff that
1329 * needs unregistering.
1331 if (data_pointer
== NULL
)
1334 sysfs_remove_group(&hdev
->dev
.kobj
,
1335 &lenovo_attr_group_tpkbd
);
1337 led_classdev_unregister(&data_pointer
->led_micmute
);
1338 led_classdev_unregister(&data_pointer
->led_mute
);
1341 static void lenovo_remove_cptkbd(struct hid_device
*hdev
)
1343 sysfs_remove_group(&hdev
->dev
.kobj
,
1344 &lenovo_attr_group_cptkbd
);
1347 static void lenovo_remove_tp10ubkbd(struct hid_device
*hdev
)
1349 struct lenovo_drvdata
*data
= hid_get_drvdata(hdev
);
1354 led_classdev_unregister(&data
->led_micmute
);
1355 led_classdev_unregister(&data
->led_mute
);
1357 sysfs_remove_group(&hdev
->dev
.kobj
, &lenovo_attr_group_tp10ubkbd
);
1358 cancel_work_sync(&data
->fn_lock_sync_work
);
1361 static void lenovo_remove(struct hid_device
*hdev
)
1363 switch (hdev
->product
) {
1364 case USB_DEVICE_ID_LENOVO_TPKBD
:
1365 lenovo_remove_tpkbd(hdev
);
1367 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
1368 case USB_DEVICE_ID_LENOVO_CBTKBD
:
1369 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
1370 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
1371 lenovo_remove_cptkbd(hdev
);
1373 case USB_DEVICE_ID_LENOVO_TP10UBKBD
:
1374 case USB_DEVICE_ID_LENOVO_X1_TAB
:
1375 lenovo_remove_tp10ubkbd(hdev
);
1382 static int lenovo_input_configured(struct hid_device
*hdev
,
1383 struct hid_input
*hi
)
1385 switch (hdev
->product
) {
1386 case USB_DEVICE_ID_LENOVO_TPKBD
:
1387 case USB_DEVICE_ID_LENOVO_CUSBKBD
:
1388 case USB_DEVICE_ID_LENOVO_CBTKBD
:
1389 case USB_DEVICE_ID_LENOVO_TPIIUSBKBD
:
1390 case USB_DEVICE_ID_LENOVO_TPIIBTKBD
:
1391 if (test_bit(EV_REL
, hi
->input
->evbit
)) {
1392 /* set only for trackpoint device */
1393 __set_bit(INPUT_PROP_POINTER
, hi
->input
->propbit
);
1394 __set_bit(INPUT_PROP_POINTING_STICK
,
1395 hi
->input
->propbit
);
1404 static const struct hid_device_id lenovo_devices
[] = {
1405 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_TPKBD
) },
1406 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_CUSBKBD
) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_TPIIUSBKBD
) },
1408 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_CBTKBD
) },
1409 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_TPIIBTKBD
) },
1410 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_TPPRODOCK
) },
1411 { HID_USB_DEVICE(USB_VENDOR_ID_IBM
, USB_DEVICE_ID_IBM_SCROLLPOINT_III
) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_IBM
, USB_DEVICE_ID_IBM_SCROLLPOINT_PRO
) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_IBM
, USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL
) },
1414 { HID_USB_DEVICE(USB_VENDOR_ID_IBM
, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL
) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_IBM
, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO
) },
1416 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL
) },
1417 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_TP10UBKBD
) },
1419 * Note bind to the HID_GROUP_GENERIC group, so that we only bind to the keyboard
1420 * part, while letting hid-multitouch.c handle the touchpad and trackpoint.
1422 { HID_DEVICE(BUS_USB
, HID_GROUP_GENERIC
,
1423 USB_VENDOR_ID_LENOVO
, USB_DEVICE_ID_LENOVO_X1_TAB
) },
1427 MODULE_DEVICE_TABLE(hid
, lenovo_devices
);
1429 static struct hid_driver lenovo_driver
= {
1431 .id_table
= lenovo_devices
,
1432 .input_configured
= lenovo_input_configured
,
1433 .input_mapping
= lenovo_input_mapping
,
1434 .probe
= lenovo_probe
,
1435 .remove
= lenovo_remove
,
1436 .raw_event
= lenovo_raw_event
,
1437 .event
= lenovo_event
,
1438 .report_fixup
= lenovo_report_fixup
,
1440 .reset_resume
= lenovo_reset_resume
,
1443 module_hid_driver(lenovo_driver
);
1445 MODULE_DESCRIPTION("HID driver for IBM/Lenovo");
1446 MODULE_LICENSE("GPL");