Skip to content

Commit c158c2a

Browse files
jwrdegoedeakobel
authored andcommitted
HID: lenovo: Add support for Thinkpad X1 Tablet Thin keyboard
The Thinkpad X1 Tablet Thin keyboard's HID interface for the media-keys and other special functions, is quite similar to the Thinkpad 10 ultrabook keyboard's mouse/media-keys HID interface. The only difference is that it needs a bit different key mappings. Add support for the mute-LED and the non-standard media-keys on this keyboard by re-using the tp10_ultrabook_kbd code combined with a new lenovo_input_mapping_x1_tab_kbd() function. Co-authored-by: Alexander Kobel <[email protected]> Tested-by: Alexander Kobel <[email protected]> Signed-off-by: Alexander Kobel <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 2d0f1c0 commit c158c2a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

drivers/hid/hid-lenovo.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,54 @@ static int lenovo_input_mapping_tp10_ultrabook_kbd(struct hid_device *hdev,
266266
return 0;
267267
}
268268

269+
static int lenovo_input_mapping_x1_tab_kbd(struct hid_device *hdev,
270+
struct hid_input *hi, struct hid_field *field,
271+
struct hid_usage *usage, unsigned long **bit, int *max)
272+
{
273+
/*
274+
* The ThinkPad X1 Tablet Thin Keyboard uses 0x000c0001 usage for
275+
* a bunch of keys which have no standard consumer page code.
276+
*/
277+
if (usage->hid == 0x000c0001) {
278+
switch (usage->usage_index) {
279+
case 0: /* Fn-F10: Enable/disable bluetooth */
280+
map_key_clear(KEY_BLUETOOTH);
281+
return 1;
282+
case 1: /* Fn-F11: Keyboard settings */
283+
map_key_clear(KEY_KEYBOARD);
284+
return 1;
285+
case 2: /* Fn-F12: User function / Cortana */
286+
map_key_clear(KEY_MACRO1);
287+
return 1;
288+
case 3: /* Fn-PrtSc: Snipping tool */
289+
map_key_clear(KEY_SELECTIVE_SCREENSHOT);
290+
return 1;
291+
case 8: /* Fn-Esc: Fn-lock toggle */
292+
map_key_clear(KEY_FN_ESC);
293+
return 1;
294+
case 9: /* Fn-F4: Mute/unmute microphone */
295+
map_key_clear(KEY_MICMUTE);
296+
return 1;
297+
case 10: /* Fn-F9: Settings */
298+
map_key_clear(KEY_CONFIG);
299+
return 1;
300+
case 13: /* Fn-F7: Manage external displays */
301+
map_key_clear(KEY_SWITCHVIDEOMODE);
302+
return 1;
303+
case 14: /* Fn-F8: Enable/disable wifi */
304+
map_key_clear(KEY_WLAN);
305+
return 1;
306+
}
307+
}
308+
309+
if (usage->hid == (HID_UP_KEYBOARD | 0x009a)) {
310+
map_key_clear(KEY_SYSRQ);
311+
return 1;
312+
}
313+
314+
return 0;
315+
}
316+
269317
static int lenovo_input_mapping(struct hid_device *hdev,
270318
struct hid_input *hi, struct hid_field *field,
271319
struct hid_usage *usage, unsigned long **bit, int *max)
@@ -289,6 +337,8 @@ static int lenovo_input_mapping(struct hid_device *hdev,
289337
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
290338
return lenovo_input_mapping_tp10_ultrabook_kbd(hdev, hi, field,
291339
usage, bit, max);
340+
case USB_DEVICE_ID_LENOVO_X1_TAB:
341+
return lenovo_input_mapping_x1_tab_kbd(hdev, hi, field, usage, bit, max);
292342
default:
293343
return 0;
294344
}
@@ -375,6 +425,7 @@ static ssize_t attr_fn_lock_store(struct device *dev,
375425
lenovo_features_set_cptkbd(hdev);
376426
break;
377427
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
428+
case USB_DEVICE_ID_LENOVO_X1_TAB:
378429
ret = lenovo_led_set_tp10ubkbd(hdev, TP10UBKBD_FN_LOCK_LED, value);
379430
if (ret)
380431
return ret;
@@ -519,6 +570,7 @@ static int lenovo_event(struct hid_device *hdev, struct hid_field *field,
519570
case USB_DEVICE_ID_LENOVO_CBTKBD:
520571
return lenovo_event_cptkbd(hdev, field, usage, value);
521572
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
573+
case USB_DEVICE_ID_LENOVO_X1_TAB:
522574
return lenovo_event_tp10ubkbd(hdev, field, usage, value);
523575
default:
524576
return 0;
@@ -800,6 +852,7 @@ static int lenovo_led_brightness_set(struct led_classdev *led_cdev,
800852
lenovo_led_set_tpkbd(hdev);
801853
break;
802854
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
855+
case USB_DEVICE_ID_LENOVO_X1_TAB:
803856
ret = lenovo_led_set_tp10ubkbd(hdev, tp10ubkbd_led[led_nr], value);
804857
break;
805858
}
@@ -1038,6 +1091,7 @@ static int lenovo_probe(struct hid_device *hdev,
10381091
ret = lenovo_probe_cptkbd(hdev);
10391092
break;
10401093
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
1094+
case USB_DEVICE_ID_LENOVO_X1_TAB:
10411095
ret = lenovo_probe_tp10ubkbd(hdev);
10421096
break;
10431097
default:
@@ -1103,6 +1157,7 @@ static void lenovo_remove(struct hid_device *hdev)
11031157
lenovo_remove_cptkbd(hdev);
11041158
break;
11051159
case USB_DEVICE_ID_LENOVO_TP10UBKBD:
1160+
case USB_DEVICE_ID_LENOVO_X1_TAB:
11061161
lenovo_remove_tp10ubkbd(hdev);
11071162
break;
11081163
}
@@ -1142,6 +1197,12 @@ static const struct hid_device_id lenovo_devices[] = {
11421197
{ HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO) },
11431198
{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL) },
11441199
{ HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TP10UBKBD) },
1200+
/*
1201+
* Note bind to the HID_GROUP_GENERIC group, so that we only bind to the keyboard
1202+
* part, while letting hid-multitouch.c handle the touchpad and trackpoint.
1203+
*/
1204+
{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
1205+
USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_TAB) },
11451206
{ }
11461207
};
11471208

0 commit comments

Comments
 (0)