blob: d40221d781883fff8c98a6400ecff1540125a875 [file] [log] [blame]
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +01001/*
Jamie Lentin6a5b4142014-07-23 23:30:46 +01002 * HID driver for Lenovo:
3 * - ThinkPad USB Keyboard with TrackPoint (tpkbd)
Jamie Lentinf3d4ff02014-07-23 23:30:48 +01004 * - ThinkPad Compact Bluetooth Keyboard with TrackPoint (cptkbd)
5 * - ThinkPad Compact USB Keyboard with TrackPoint (cptkbd)
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +01006 *
7 * Copyright (c) 2012 Bernhard Seibold
Jamie Lentinf3d4ff02014-07-23 23:30:48 +01008 * Copyright (c) 2014 Jamie Lentin <jm@lentin.co.uk>
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +01009 */
10
11/*
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#include <linux/module.h>
19#include <linux/sysfs.h>
20#include <linux/device.h>
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010021#include <linux/hid.h>
22#include <linux/input.h>
23#include <linux/leds.h>
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010024
25#include "hid-ids.h"
26
Jamie Lentin94723bf2014-07-23 23:30:45 +010027struct lenovo_drvdata_tpkbd {
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010028 int led_state;
29 struct led_classdev led_mute;
30 struct led_classdev led_micmute;
31 int press_to_select;
32 int dragging;
33 int release_to_select;
34 int select_right;
35 int sensitivity;
36 int press_speed;
37};
38
Jamie Lentinf3d4ff02014-07-23 23:30:48 +010039struct lenovo_drvdata_cptkbd {
40 bool fn_lock;
Jamie Lentine3cb0ac2014-12-16 21:26:45 +000041 int sensitivity;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +010042};
43
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010044#define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c))
45
Benjamin Tissoires181a8b92015-05-01 16:22:45 -040046static const __u8 lenovo_pro_dock_need_fixup_collection[] = {
47 0x05, 0x88, /* Usage Page (Vendor Usage Page 0x88) */
48 0x09, 0x01, /* Usage (Vendor Usage 0x01) */
49 0xa1, 0x01, /* Collection (Application) */
50 0x85, 0x04, /* Report ID (4) */
51 0x19, 0x00, /* Usage Minimum (0) */
52 0x2a, 0xff, 0xff, /* Usage Maximum (65535) */
53};
54
55static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc,
56 unsigned int *rsize)
57{
58 switch (hdev->product) {
59 case USB_DEVICE_ID_LENOVO_TPPRODOCK:
60 /* the fixups that need to be done:
61 * - get a reasonable usage max for the vendor collection
62 * 0x8801 from the report ID 4
63 */
64 if (*rsize >= 153 &&
65 memcmp(&rdesc[140], lenovo_pro_dock_need_fixup_collection,
66 sizeof(lenovo_pro_dock_need_fixup_collection)) == 0) {
67 rdesc[151] = 0x01;
68 rdesc[152] = 0x00;
69 }
70 break;
71 }
72 return rdesc;
73}
74
Jamie Lentin94723bf2014-07-23 23:30:45 +010075static int lenovo_input_mapping_tpkbd(struct hid_device *hdev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010076 struct hid_input *hi, struct hid_field *field,
77 struct hid_usage *usage, unsigned long **bit, int *max)
78{
Benjamin Tissoires0c521832013-09-11 22:12:24 +020079 if (usage->hid == (HID_UP_BUTTON | 0x0010)) {
Jamie Lentin6a5b4142014-07-23 23:30:46 +010080 /* This sub-device contains trackpoint, mark it */
Benjamin Tissoires0c521832013-09-11 22:12:24 +020081 hid_set_drvdata(hdev, (void *)1);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +010082 map_key_clear(KEY_MICMUTE);
83 return 1;
84 }
85 return 0;
86}
87
Jamie Lentinf3d4ff02014-07-23 23:30:48 +010088static int lenovo_input_mapping_cptkbd(struct hid_device *hdev,
89 struct hid_input *hi, struct hid_field *field,
90 struct hid_usage *usage, unsigned long **bit, int *max)
91{
92 /* HID_UP_LNVENDOR = USB, HID_UP_MSVENDOR = BT */
93 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR ||
94 (usage->hid & HID_USAGE_PAGE) == HID_UP_LNVENDOR) {
Jamie Lentinf3d4ff02014-07-23 23:30:48 +010095 switch (usage->hid & HID_USAGE) {
96 case 0x00f1: /* Fn-F4: Mic mute */
97 map_key_clear(KEY_MICMUTE);
98 return 1;
99 case 0x00f2: /* Fn-F5: Brightness down */
100 map_key_clear(KEY_BRIGHTNESSDOWN);
101 return 1;
102 case 0x00f3: /* Fn-F6: Brightness up */
103 map_key_clear(KEY_BRIGHTNESSUP);
104 return 1;
105 case 0x00f4: /* Fn-F7: External display (projector) */
106 map_key_clear(KEY_SWITCHVIDEOMODE);
107 return 1;
108 case 0x00f5: /* Fn-F8: Wireless */
109 map_key_clear(KEY_WLAN);
110 return 1;
111 case 0x00f6: /* Fn-F9: Control panel */
112 map_key_clear(KEY_CONFIG);
113 return 1;
114 case 0x00f8: /* Fn-F11: View open applications (3 boxes) */
115 map_key_clear(KEY_SCALE);
116 return 1;
Jamie Lentin5556eb12014-11-09 07:54:29 +0000117 case 0x00f9: /* Fn-F12: Open My computer (6 boxes) USB-only */
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100118 /* NB: This mapping is invented in raw_event below */
119 map_key_clear(KEY_FILE);
120 return 1;
Jamie Lentin5556eb12014-11-09 07:54:29 +0000121 case 0x00fa: /* Fn-Esc: Fn-lock toggle */
122 map_key_clear(KEY_FN_ESC);
123 return 1;
Jamie Lentin94eefa22014-12-16 21:26:46 +0000124 case 0x00fb: /* Middle mouse button (in native mode) */
125 map_key_clear(BTN_MIDDLE);
126 return 1;
127 }
128 }
129
130 /* Compatibility middle/wheel mappings should be ignored */
131 if (usage->hid == HID_GD_WHEEL)
132 return -1;
133 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON &&
134 (usage->hid & HID_USAGE) == 0x003)
135 return -1;
136 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER &&
137 (usage->hid & HID_USAGE) == 0x238)
138 return -1;
139
140 /* Map wheel emulation reports: 0xffa1 = USB, 0xff10 = BT */
141 if ((usage->hid & HID_USAGE_PAGE) == 0xff100000 ||
142 (usage->hid & HID_USAGE_PAGE) == 0xffa10000) {
143 field->flags |= HID_MAIN_ITEM_RELATIVE | HID_MAIN_ITEM_VARIABLE;
144 field->logical_minimum = -127;
145 field->logical_maximum = 127;
146
147 switch (usage->hid & HID_USAGE) {
148 case 0x0000:
Jamie Lentin7f650682015-08-11 22:40:50 +0100149 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
Jamie Lentin94eefa22014-12-16 21:26:46 +0000150 return 1;
151 case 0x0001:
Jamie Lentin7f650682015-08-11 22:40:50 +0100152 hid_map_usage(hi, usage, bit, max, EV_REL, REL_WHEEL);
Jamie Lentin94eefa22014-12-16 21:26:46 +0000153 return 1;
154 default:
155 return -1;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100156 }
157 }
158
159 return 0;
160}
161
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100162static int lenovo_input_mapping(struct hid_device *hdev,
163 struct hid_input *hi, struct hid_field *field,
164 struct hid_usage *usage, unsigned long **bit, int *max)
165{
166 switch (hdev->product) {
167 case USB_DEVICE_ID_LENOVO_TPKBD:
168 return lenovo_input_mapping_tpkbd(hdev, hi, field,
169 usage, bit, max);
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100170 case USB_DEVICE_ID_LENOVO_CUSBKBD:
171 case USB_DEVICE_ID_LENOVO_CBTKBD:
172 return lenovo_input_mapping_cptkbd(hdev, hi, field,
173 usage, bit, max);
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100174 default:
175 return 0;
176 }
177}
178
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100179#undef map_key_clear
180
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100181/* Send a config command to the keyboard */
182static int lenovo_send_cmd_cptkbd(struct hid_device *hdev,
183 unsigned char byte2, unsigned char byte3)
184{
185 int ret;
186 unsigned char buf[] = {0x18, byte2, byte3};
187
188 switch (hdev->product) {
189 case USB_DEVICE_ID_LENOVO_CUSBKBD:
190 ret = hid_hw_raw_request(hdev, 0x13, buf, sizeof(buf),
191 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
192 break;
193 case USB_DEVICE_ID_LENOVO_CBTKBD:
194 ret = hid_hw_output_report(hdev, buf, sizeof(buf));
195 break;
196 default:
197 ret = -EINVAL;
198 break;
199 }
200
201 return ret < 0 ? ret : 0; /* BT returns 0, USB returns sizeof(buf) */
202}
203
204static void lenovo_features_set_cptkbd(struct hid_device *hdev)
205{
206 int ret;
207 struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
208
209 ret = lenovo_send_cmd_cptkbd(hdev, 0x05, cptkbd_data->fn_lock);
210 if (ret)
211 hid_err(hdev, "Fn-lock setting failed: %d\n", ret);
Jamie Lentindbfebb42015-08-11 22:40:51 +0100212
213 ret = lenovo_send_cmd_cptkbd(hdev, 0x02, cptkbd_data->sensitivity);
214 if (ret)
215 hid_err(hdev, "Sensitivity setting failed: %d\n", ret);
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100216}
217
218static ssize_t attr_fn_lock_show_cptkbd(struct device *dev,
219 struct device_attribute *attr,
220 char *buf)
221{
222 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
223 struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
224
225 return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock);
226}
227
228static ssize_t attr_fn_lock_store_cptkbd(struct device *dev,
229 struct device_attribute *attr,
230 const char *buf,
231 size_t count)
232{
233 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
234 struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
235 int value;
236
237 if (kstrtoint(buf, 10, &value))
238 return -EINVAL;
239 if (value < 0 || value > 1)
240 return -EINVAL;
241
242 cptkbd_data->fn_lock = !!value;
243 lenovo_features_set_cptkbd(hdev);
244
245 return count;
246}
247
Jamie Lentine3cb0ac2014-12-16 21:26:45 +0000248static ssize_t attr_sensitivity_show_cptkbd(struct device *dev,
249 struct device_attribute *attr,
250 char *buf)
251{
252 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
253 struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
254
255 return snprintf(buf, PAGE_SIZE, "%u\n",
256 cptkbd_data->sensitivity);
257}
258
259static ssize_t attr_sensitivity_store_cptkbd(struct device *dev,
260 struct device_attribute *attr,
261 const char *buf,
262 size_t count)
263{
264 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
265 struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
266 int value;
267
268 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
269 return -EINVAL;
270
271 cptkbd_data->sensitivity = value;
272 lenovo_features_set_cptkbd(hdev);
273
274 return count;
275}
276
277
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100278static struct device_attribute dev_attr_fn_lock_cptkbd =
279 __ATTR(fn_lock, S_IWUSR | S_IRUGO,
280 attr_fn_lock_show_cptkbd,
281 attr_fn_lock_store_cptkbd);
282
Jamie Lentine3cb0ac2014-12-16 21:26:45 +0000283static struct device_attribute dev_attr_sensitivity_cptkbd =
284 __ATTR(sensitivity, S_IWUSR | S_IRUGO,
285 attr_sensitivity_show_cptkbd,
286 attr_sensitivity_store_cptkbd);
287
288
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100289static struct attribute *lenovo_attributes_cptkbd[] = {
290 &dev_attr_fn_lock_cptkbd.attr,
Jamie Lentine3cb0ac2014-12-16 21:26:45 +0000291 &dev_attr_sensitivity_cptkbd.attr,
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100292 NULL
293};
294
295static const struct attribute_group lenovo_attr_group_cptkbd = {
296 .attrs = lenovo_attributes_cptkbd,
297};
298
299static int lenovo_raw_event(struct hid_device *hdev,
300 struct hid_report *report, u8 *data, int size)
301{
302 /*
303 * Compact USB keyboard's Fn-F12 report holds down many other keys, and
304 * its own key is outside the usage page range. Remove extra
305 * keypresses and remap to inside usage page.
306 */
307 if (unlikely(hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD
308 && size == 3
309 && data[0] == 0x15
310 && data[1] == 0x94
311 && data[2] == 0x01)) {
Jamie Lentin5556eb12014-11-09 07:54:29 +0000312 data[1] = 0x00;
313 data[2] = 0x01;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100314 }
315
316 return 0;
317}
318
Jamie Lentin94723bf2014-07-23 23:30:45 +0100319static int lenovo_features_set_tpkbd(struct hid_device *hdev)
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100320{
321 struct hid_report *report;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100322 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100323
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100324 report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4];
325
326 report->field[0]->value[0] = data_pointer->press_to_select ? 0x01 : 0x02;
327 report->field[0]->value[0] |= data_pointer->dragging ? 0x04 : 0x08;
328 report->field[0]->value[0] |= data_pointer->release_to_select ? 0x10 : 0x20;
329 report->field[0]->value[0] |= data_pointer->select_right ? 0x80 : 0x40;
330 report->field[1]->value[0] = 0x03; // unknown setting, imitate windows driver
331 report->field[2]->value[0] = data_pointer->sensitivity;
332 report->field[3]->value[0] = data_pointer->press_speed;
333
Benjamin Tissoiresd88142722013-02-25 11:31:46 +0100334 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100335 return 0;
336}
337
Jamie Lentin94723bf2014-07-23 23:30:45 +0100338static ssize_t attr_press_to_select_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100339 struct device_attribute *attr,
340 char *buf)
341{
Axel Lin832fbea2012-09-13 14:12:08 +0800342 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100343 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100344
345 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select);
346}
347
Jamie Lentin94723bf2014-07-23 23:30:45 +0100348static ssize_t attr_press_to_select_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100349 struct device_attribute *attr,
350 const char *buf,
351 size_t count)
352{
Axel Lin832fbea2012-09-13 14:12:08 +0800353 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100354 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100355 int value;
356
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100357 if (kstrtoint(buf, 10, &value))
358 return -EINVAL;
359 if (value < 0 || value > 1)
360 return -EINVAL;
361
362 data_pointer->press_to_select = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100363 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100364
365 return count;
366}
367
Jamie Lentin94723bf2014-07-23 23:30:45 +0100368static ssize_t attr_dragging_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100369 struct device_attribute *attr,
370 char *buf)
371{
Axel Lin832fbea2012-09-13 14:12:08 +0800372 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100373 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100374
375 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging);
376}
377
Jamie Lentin94723bf2014-07-23 23:30:45 +0100378static ssize_t attr_dragging_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100379 struct device_attribute *attr,
380 const char *buf,
381 size_t count)
382{
Axel Lin832fbea2012-09-13 14:12:08 +0800383 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100384 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100385 int value;
386
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100387 if (kstrtoint(buf, 10, &value))
388 return -EINVAL;
389 if (value < 0 || value > 1)
390 return -EINVAL;
391
392 data_pointer->dragging = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100393 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100394
395 return count;
396}
397
Jamie Lentin94723bf2014-07-23 23:30:45 +0100398static ssize_t attr_release_to_select_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100399 struct device_attribute *attr,
400 char *buf)
401{
Axel Lin832fbea2012-09-13 14:12:08 +0800402 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100403 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100404
405 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select);
406}
407
Jamie Lentin94723bf2014-07-23 23:30:45 +0100408static ssize_t attr_release_to_select_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100409 struct device_attribute *attr,
410 const char *buf,
411 size_t count)
412{
Axel Lin832fbea2012-09-13 14:12:08 +0800413 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100414 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100415 int value;
416
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100417 if (kstrtoint(buf, 10, &value))
418 return -EINVAL;
419 if (value < 0 || value > 1)
420 return -EINVAL;
421
422 data_pointer->release_to_select = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100423 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100424
425 return count;
426}
427
Jamie Lentin94723bf2014-07-23 23:30:45 +0100428static ssize_t attr_select_right_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100429 struct device_attribute *attr,
430 char *buf)
431{
Axel Lin832fbea2012-09-13 14:12:08 +0800432 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100433 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100434
435 return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
436}
437
Jamie Lentin94723bf2014-07-23 23:30:45 +0100438static ssize_t attr_select_right_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100439 struct device_attribute *attr,
440 const char *buf,
441 size_t count)
442{
Axel Lin832fbea2012-09-13 14:12:08 +0800443 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100444 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100445 int value;
446
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100447 if (kstrtoint(buf, 10, &value))
448 return -EINVAL;
449 if (value < 0 || value > 1)
450 return -EINVAL;
451
452 data_pointer->select_right = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100453 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100454
455 return count;
456}
457
Jamie Lentin94723bf2014-07-23 23:30:45 +0100458static ssize_t attr_sensitivity_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100459 struct device_attribute *attr,
460 char *buf)
461{
Axel Lin832fbea2012-09-13 14:12:08 +0800462 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100463 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100464
465 return snprintf(buf, PAGE_SIZE, "%u\n",
466 data_pointer->sensitivity);
467}
468
Jamie Lentin94723bf2014-07-23 23:30:45 +0100469static ssize_t attr_sensitivity_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100470 struct device_attribute *attr,
471 const char *buf,
472 size_t count)
473{
Axel Lin832fbea2012-09-13 14:12:08 +0800474 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100475 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100476 int value;
477
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100478 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
479 return -EINVAL;
480
481 data_pointer->sensitivity = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100482 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100483
484 return count;
485}
486
Jamie Lentin94723bf2014-07-23 23:30:45 +0100487static ssize_t attr_press_speed_show_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100488 struct device_attribute *attr,
489 char *buf)
490{
Axel Lin832fbea2012-09-13 14:12:08 +0800491 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100492 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100493
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100494 return snprintf(buf, PAGE_SIZE, "%u\n",
495 data_pointer->press_speed);
496}
497
Jamie Lentin94723bf2014-07-23 23:30:45 +0100498static ssize_t attr_press_speed_store_tpkbd(struct device *dev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100499 struct device_attribute *attr,
500 const char *buf,
501 size_t count)
502{
Axel Lin832fbea2012-09-13 14:12:08 +0800503 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100504 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100505 int value;
506
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100507 if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
508 return -EINVAL;
509
510 data_pointer->press_speed = value;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100511 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100512
513 return count;
514}
515
Jamie Lentin94723bf2014-07-23 23:30:45 +0100516static struct device_attribute dev_attr_press_to_select_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100517 __ATTR(press_to_select, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100518 attr_press_to_select_show_tpkbd,
519 attr_press_to_select_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100520
Jamie Lentin94723bf2014-07-23 23:30:45 +0100521static struct device_attribute dev_attr_dragging_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100522 __ATTR(dragging, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100523 attr_dragging_show_tpkbd,
524 attr_dragging_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100525
Jamie Lentin94723bf2014-07-23 23:30:45 +0100526static struct device_attribute dev_attr_release_to_select_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100527 __ATTR(release_to_select, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100528 attr_release_to_select_show_tpkbd,
529 attr_release_to_select_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100530
Jamie Lentin94723bf2014-07-23 23:30:45 +0100531static struct device_attribute dev_attr_select_right_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100532 __ATTR(select_right, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100533 attr_select_right_show_tpkbd,
534 attr_select_right_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100535
Jamie Lentin94723bf2014-07-23 23:30:45 +0100536static struct device_attribute dev_attr_sensitivity_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100537 __ATTR(sensitivity, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100538 attr_sensitivity_show_tpkbd,
539 attr_sensitivity_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100540
Jamie Lentin94723bf2014-07-23 23:30:45 +0100541static struct device_attribute dev_attr_press_speed_tpkbd =
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100542 __ATTR(press_speed, S_IWUSR | S_IRUGO,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100543 attr_press_speed_show_tpkbd,
544 attr_press_speed_store_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100545
Jamie Lentin94723bf2014-07-23 23:30:45 +0100546static struct attribute *lenovo_attributes_tpkbd[] = {
547 &dev_attr_press_to_select_tpkbd.attr,
548 &dev_attr_dragging_tpkbd.attr,
549 &dev_attr_release_to_select_tpkbd.attr,
550 &dev_attr_select_right_tpkbd.attr,
551 &dev_attr_sensitivity_tpkbd.attr,
552 &dev_attr_press_speed_tpkbd.attr,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100553 NULL
554};
555
Jamie Lentin94723bf2014-07-23 23:30:45 +0100556static const struct attribute_group lenovo_attr_group_tpkbd = {
557 .attrs = lenovo_attributes_tpkbd,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100558};
559
Jamie Lentin94723bf2014-07-23 23:30:45 +0100560static enum led_brightness lenovo_led_brightness_get_tpkbd(
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100561 struct led_classdev *led_cdev)
562{
Axel Lin832fbea2012-09-13 14:12:08 +0800563 struct device *dev = led_cdev->dev->parent;
564 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100565 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100566 int led_nr = 0;
567
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100568 if (led_cdev == &data_pointer->led_micmute)
569 led_nr = 1;
570
571 return data_pointer->led_state & (1 << led_nr)
572 ? LED_FULL
573 : LED_OFF;
574}
575
Jamie Lentin94723bf2014-07-23 23:30:45 +0100576static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100577 enum led_brightness value)
578{
Axel Lin832fbea2012-09-13 14:12:08 +0800579 struct device *dev = led_cdev->dev->parent;
580 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Jamie Lentin94723bf2014-07-23 23:30:45 +0100581 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100582 struct hid_report *report;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100583 int led_nr = 0;
584
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100585 if (led_cdev == &data_pointer->led_micmute)
586 led_nr = 1;
587
588 if (value == LED_OFF)
589 data_pointer->led_state &= ~(1 << led_nr);
590 else
591 data_pointer->led_state |= 1 << led_nr;
592
593 report = hdev->report_enum[HID_OUTPUT_REPORT].report_id_hash[3];
594 report->field[0]->value[0] = (data_pointer->led_state >> 0) & 1;
595 report->field[0]->value[1] = (data_pointer->led_state >> 1) & 1;
Benjamin Tissoiresd88142722013-02-25 11:31:46 +0100596 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100597}
598
Jamie Lentin94723bf2014-07-23 23:30:45 +0100599static int lenovo_probe_tpkbd(struct hid_device *hdev)
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100600{
601 struct device *dev = &hdev->dev;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100602 struct lenovo_drvdata_tpkbd *data_pointer;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100603 size_t name_sz = strlen(dev_name(dev)) + 16;
604 char *name_mute, *name_micmute;
Benjamin Tissoires01ab35f2013-09-11 22:12:23 +0200605 int i;
Jamie Lentine0a6aad2014-07-26 15:42:27 +0100606 int ret;
Kees Cook0a9cd0a2013-09-11 21:56:55 +0200607
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100608 /*
609 * Only register extra settings against subdevice where input_mapping
610 * set drvdata to 1, i.e. the trackpoint.
611 */
612 if (!hid_get_drvdata(hdev))
613 return 0;
614
615 hid_set_drvdata(hdev, NULL);
616
Kees Cook0a9cd0a2013-09-11 21:56:55 +0200617 /* Validate required reports. */
618 for (i = 0; i < 4; i++) {
619 if (!hid_validate_values(hdev, HID_FEATURE_REPORT, 4, i, 1))
620 return -ENODEV;
621 }
622 if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 3, 0, 2))
623 return -ENODEV;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100624
Jamie Lentine0a6aad2014-07-26 15:42:27 +0100625 ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd);
626 if (ret)
627 hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100628
Benjamin Tissoires01ab35f2013-09-11 22:12:23 +0200629 data_pointer = devm_kzalloc(&hdev->dev,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100630 sizeof(struct lenovo_drvdata_tpkbd),
Benjamin Tissoires01ab35f2013-09-11 22:12:23 +0200631 GFP_KERNEL);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100632 if (data_pointer == NULL) {
633 hid_err(hdev, "Could not allocate memory for driver data\n");
Alexey Khoroshilovb7212602015-05-29 03:39:31 +0300634 ret = -ENOMEM;
635 goto err;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100636 }
637
638 // set same default values as windows driver
639 data_pointer->sensitivity = 0xa0;
640 data_pointer->press_speed = 0x38;
641
Benjamin Tissoires01ab35f2013-09-11 22:12:23 +0200642 name_mute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
643 name_micmute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL);
644 if (name_mute == NULL || name_micmute == NULL) {
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100645 hid_err(hdev, "Could not allocate memory for led data\n");
Alexey Khoroshilovb7212602015-05-29 03:39:31 +0300646 ret = -ENOMEM;
647 goto err;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100648 }
649 snprintf(name_mute, name_sz, "%s:amber:mute", dev_name(dev));
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100650 snprintf(name_micmute, name_sz, "%s:amber:micmute", dev_name(dev));
651
652 hid_set_drvdata(hdev, data_pointer);
653
654 data_pointer->led_mute.name = name_mute;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100655 data_pointer->led_mute.brightness_get = lenovo_led_brightness_get_tpkbd;
656 data_pointer->led_mute.brightness_set = lenovo_led_brightness_set_tpkbd;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100657 data_pointer->led_mute.dev = dev;
658 led_classdev_register(dev, &data_pointer->led_mute);
659
660 data_pointer->led_micmute.name = name_micmute;
Jamie Lentin94723bf2014-07-23 23:30:45 +0100661 data_pointer->led_micmute.brightness_get =
662 lenovo_led_brightness_get_tpkbd;
663 data_pointer->led_micmute.brightness_set =
664 lenovo_led_brightness_set_tpkbd;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100665 data_pointer->led_micmute.dev = dev;
666 led_classdev_register(dev, &data_pointer->led_micmute);
667
Jamie Lentin94723bf2014-07-23 23:30:45 +0100668 lenovo_features_set_tpkbd(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100669
670 return 0;
Alexey Khoroshilovb7212602015-05-29 03:39:31 +0300671err:
672 sysfs_remove_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd);
673 return ret;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100674}
675
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100676static int lenovo_probe_cptkbd(struct hid_device *hdev)
677{
678 int ret;
679 struct lenovo_drvdata_cptkbd *cptkbd_data;
680
681 /* All the custom action happens on the USBMOUSE device for USB */
682 if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD
683 && hdev->type != HID_TYPE_USBMOUSE) {
684 hid_dbg(hdev, "Ignoring keyboard half of device\n");
685 return 0;
686 }
687
688 cptkbd_data = devm_kzalloc(&hdev->dev,
689 sizeof(*cptkbd_data),
690 GFP_KERNEL);
691 if (cptkbd_data == NULL) {
692 hid_err(hdev, "can't alloc keyboard descriptor\n");
693 return -ENOMEM;
694 }
695 hid_set_drvdata(hdev, cptkbd_data);
696
697 /*
698 * Tell the keyboard a driver understands it, and turn F7, F9, F11 into
699 * regular keys
700 */
701 ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03);
702 if (ret)
703 hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret);
704
Jamie Lentin94eefa22014-12-16 21:26:46 +0000705 /* Switch middle button to native mode */
706 ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01);
707 if (ret)
708 hid_warn(hdev, "Failed to switch middle button: %d\n", ret);
709
Jamie Lentine3cb0ac2014-12-16 21:26:45 +0000710 /* Set keyboard settings to known state */
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100711 cptkbd_data->fn_lock = true;
Jamie Lentine3cb0ac2014-12-16 21:26:45 +0000712 cptkbd_data->sensitivity = 0x05;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100713 lenovo_features_set_cptkbd(hdev);
714
715 ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_cptkbd);
716 if (ret)
717 hid_warn(hdev, "Could not create sysfs group: %d\n", ret);
718
719 return 0;
720}
721
Jamie Lentin94723bf2014-07-23 23:30:45 +0100722static int lenovo_probe(struct hid_device *hdev,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100723 const struct hid_device_id *id)
724{
725 int ret;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100726
727 ret = hid_parse(hdev);
728 if (ret) {
729 hid_err(hdev, "hid_parse failed\n");
Benjamin Tissoires0ccdd9e2013-09-11 21:56:59 +0200730 goto err;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100731 }
732
733 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
734 if (ret) {
735 hid_err(hdev, "hid_hw_start failed\n");
Benjamin Tissoires0ccdd9e2013-09-11 21:56:59 +0200736 goto err;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100737 }
738
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100739 switch (hdev->product) {
740 case USB_DEVICE_ID_LENOVO_TPKBD:
Jamie Lentin94723bf2014-07-23 23:30:45 +0100741 ret = lenovo_probe_tpkbd(hdev);
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100742 break;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100743 case USB_DEVICE_ID_LENOVO_CUSBKBD:
744 case USB_DEVICE_ID_LENOVO_CBTKBD:
745 ret = lenovo_probe_cptkbd(hdev);
746 break;
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100747 default:
748 ret = 0;
749 break;
Benjamin Tissoires0ccdd9e2013-09-11 21:56:59 +0200750 }
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100751 if (ret)
752 goto err_hid;
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100753
754 return 0;
Benjamin Tissoires0ccdd9e2013-09-11 21:56:59 +0200755err_hid:
756 hid_hw_stop(hdev);
757err:
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100758 return ret;
759}
760
Jamie Lentin94723bf2014-07-23 23:30:45 +0100761static void lenovo_remove_tpkbd(struct hid_device *hdev)
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100762{
Jamie Lentin94723bf2014-07-23 23:30:45 +0100763 struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100764
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100765 /*
766 * Only the trackpoint half of the keyboard has drvdata and stuff that
767 * needs unregistering.
768 */
769 if (data_pointer == NULL)
770 return;
771
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100772 sysfs_remove_group(&hdev->dev.kobj,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100773 &lenovo_attr_group_tpkbd);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100774
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100775 led_classdev_unregister(&data_pointer->led_micmute);
776 led_classdev_unregister(&data_pointer->led_mute);
777
778 hid_set_drvdata(hdev, NULL);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100779}
780
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100781static void lenovo_remove_cptkbd(struct hid_device *hdev)
782{
783 sysfs_remove_group(&hdev->dev.kobj,
784 &lenovo_attr_group_cptkbd);
785}
786
Jamie Lentin94723bf2014-07-23 23:30:45 +0100787static void lenovo_remove(struct hid_device *hdev)
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100788{
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100789 switch (hdev->product) {
790 case USB_DEVICE_ID_LENOVO_TPKBD:
Jamie Lentin94723bf2014-07-23 23:30:45 +0100791 lenovo_remove_tpkbd(hdev);
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100792 break;
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100793 case USB_DEVICE_ID_LENOVO_CUSBKBD:
794 case USB_DEVICE_ID_LENOVO_CBTKBD:
795 lenovo_remove_cptkbd(hdev);
796 break;
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100797 }
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100798
799 hid_hw_stop(hdev);
800}
801
Andreas Fleigd92189e2015-04-23 10:25:58 +0200802static void lenovo_input_configured(struct hid_device *hdev,
803 struct hid_input *hi)
804{
805 switch (hdev->product) {
806 case USB_DEVICE_ID_LENOVO_TPKBD:
807 case USB_DEVICE_ID_LENOVO_CUSBKBD:
808 case USB_DEVICE_ID_LENOVO_CBTKBD:
809 if (test_bit(EV_REL, hi->input->evbit)) {
810 /* set only for trackpoint device */
811 __set_bit(INPUT_PROP_POINTER, hi->input->propbit);
812 __set_bit(INPUT_PROP_POINTING_STICK,
813 hi->input->propbit);
814 }
815 break;
816 }
817}
818
819
Jamie Lentin94723bf2014-07-23 23:30:45 +0100820static const struct hid_device_id lenovo_devices[] = {
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100821 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) },
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100822 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) },
823 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) },
Benjamin Tissoires181a8b92015-05-01 16:22:45 -0400824 { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) },
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100825 { }
826};
827
Jamie Lentin94723bf2014-07-23 23:30:45 +0100828MODULE_DEVICE_TABLE(hid, lenovo_devices);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100829
Jamie Lentin94723bf2014-07-23 23:30:45 +0100830static struct hid_driver lenovo_driver = {
831 .name = "lenovo",
832 .id_table = lenovo_devices,
Andreas Fleigd92189e2015-04-23 10:25:58 +0200833 .input_configured = lenovo_input_configured,
Jamie Lentin6a5b4142014-07-23 23:30:46 +0100834 .input_mapping = lenovo_input_mapping,
Jamie Lentin94723bf2014-07-23 23:30:45 +0100835 .probe = lenovo_probe,
836 .remove = lenovo_remove,
Jamie Lentinf3d4ff02014-07-23 23:30:48 +0100837 .raw_event = lenovo_raw_event,
Benjamin Tissoires181a8b92015-05-01 16:22:45 -0400838 .report_fixup = lenovo_report_fixup,
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100839};
Jamie Lentin94723bf2014-07-23 23:30:45 +0100840module_hid_driver(lenovo_driver);
Bernhard Seiboldc1dcad2d2012-02-15 13:40:43 +0100841
842MODULE_LICENSE("GPL");