Commit | Line | Data |
---|---|---|
eeb01a57 | 1 | /* |
b94f7d5d | 2 | * HID driver for Asus notebook built-in keyboard. |
eeb01a57 YF |
3 | * Fixes small logical maximum to match usage maximum. |
4 | * | |
b94f7d5d YF |
5 | * Currently supported devices are: |
6 | * EeeBook X205TA | |
7 | * VivoBook E200HA | |
8 | * | |
eeb01a57 YF |
9 | * Copyright (c) 2016 Yusuke Fujimaki <usk.fujimaki@gmail.com> |
10 | * | |
11 | * This module based on hid-ortek by | |
12 | * Copyright (c) 2010 Johnathon Harris <jmharris@gmail.com> | |
13 | * Copyright (c) 2011 Jiri Kosina | |
9ce12d8b BM |
14 | * |
15 | * This module has been updated to add support for Asus i2c touchpad. | |
16 | * | |
17 | * Copyright (c) 2016 Brendan McGrath <redmcg@redmandi.dyndns.org> | |
18 | * Copyright (c) 2016 Victor Vlasenko <victor.vlasenko@sysgears.com> | |
19 | * Copyright (c) 2016 Frederik Wenigwieser <frederik.wenigwieser@gmail.com> | |
eeb01a57 YF |
20 | */ |
21 | ||
22 | /* | |
23 | * This program is free software; you can redistribute it and/or modify it | |
24 | * under the terms of the GNU General Public License as published by the Free | |
25 | * Software Foundation; either version 2 of the License, or (at your option) | |
26 | * any later version. | |
27 | */ | |
28 | ||
eeb01a57 YF |
29 | #include <linux/hid.h> |
30 | #include <linux/module.h> | |
9ce12d8b | 31 | #include <linux/input/mt.h> |
57573c54 | 32 | #include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */ |
eeb01a57 YF |
33 | |
34 | #include "hid-ids.h" | |
35 | ||
9ce12d8b BM |
36 | MODULE_AUTHOR("Yusuke Fujimaki <usk.fujimaki@gmail.com>"); |
37 | MODULE_AUTHOR("Brendan McGrath <redmcg@redmandi.dyndns.org>"); | |
38 | MODULE_AUTHOR("Victor Vlasenko <victor.vlasenko@sysgears.com>"); | |
39 | MODULE_AUTHOR("Frederik Wenigwieser <frederik.wenigwieser@gmail.com>"); | |
40 | MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); | |
41 | ||
57573c54 HG |
42 | #define T100_TPAD_INTF 2 |
43 | ||
9ce12d8b BM |
44 | #define FEATURE_REPORT_ID 0x0d |
45 | #define INPUT_REPORT_ID 0x5d | |
af22a610 | 46 | #define FEATURE_KBD_REPORT_ID 0x5a |
af22a610 CC |
47 | #define FEATURE_KBD_REPORT_SIZE 16 |
48 | ||
49 | #define SUPPORT_KBD_BACKLIGHT BIT(0) | |
9ce12d8b | 50 | |
9ce12d8b BM |
51 | #define MAX_TOUCH_MAJOR 8 |
52 | #define MAX_PRESSURE 128 | |
53 | ||
9ce12d8b BM |
54 | #define BTN_LEFT_MASK 0x01 |
55 | #define CONTACT_TOOL_TYPE_MASK 0x80 | |
56 | #define CONTACT_X_MSB_MASK 0xf0 | |
57 | #define CONTACT_Y_MSB_MASK 0x0f | |
58 | #define CONTACT_TOUCH_MAJOR_MASK 0x07 | |
59 | #define CONTACT_PRESSURE_MASK 0x7f | |
60 | ||
61 | #define QUIRK_FIX_NOTEBOOK_REPORT BIT(0) | |
62 | #define QUIRK_NO_INIT_REPORTS BIT(1) | |
63 | #define QUIRK_SKIP_INPUT_MAPPING BIT(2) | |
64 | #define QUIRK_IS_MULTITOUCH BIT(3) | |
0485b1ec | 65 | #define QUIRK_NO_CONSUMER_USAGES BIT(4) |
af22a610 | 66 | #define QUIRK_USE_KBD_BACKLIGHT BIT(5) |
76dd1fbe | 67 | #define QUIRK_T100_KEYBOARD BIT(6) |
9ce12d8b | 68 | |
a93913e1 | 69 | #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ |
0485b1ec MH |
70 | QUIRK_NO_INIT_REPORTS | \ |
71 | QUIRK_NO_CONSUMER_USAGES) | |
c81760b9 | 72 | #define I2C_TOUCHPAD_QUIRKS (QUIRK_NO_INIT_REPORTS | \ |
9ce12d8b BM |
73 | QUIRK_SKIP_INPUT_MAPPING | \ |
74 | QUIRK_IS_MULTITOUCH) | |
75 | ||
76 | #define TRKID_SGN ((TRKID_MAX + 1) >> 1) | |
77 | ||
af22a610 CC |
78 | struct asus_kbd_leds { |
79 | struct led_classdev cdev; | |
80 | struct hid_device *hdev; | |
81 | struct work_struct work; | |
82 | unsigned int brightness; | |
83 | bool removed; | |
84 | }; | |
85 | ||
c81760b9 HG |
86 | struct asus_touchpad_info { |
87 | int max_x; | |
88 | int max_y; | |
89 | int contact_size; | |
90 | int max_contacts; | |
91 | }; | |
92 | ||
9ce12d8b BM |
93 | struct asus_drvdata { |
94 | unsigned long quirks; | |
95 | struct input_dev *input; | |
af22a610 | 96 | struct asus_kbd_leds *kbd_backlight; |
c81760b9 | 97 | const struct asus_touchpad_info *tp; |
af22a610 | 98 | bool enable_backlight; |
9ce12d8b BM |
99 | }; |
100 | ||
c81760b9 HG |
101 | static const struct asus_touchpad_info asus_i2c_tp = { |
102 | .max_x = 2794, | |
103 | .max_y = 1758, | |
104 | .contact_size = 5, | |
105 | .max_contacts = 5, | |
106 | }; | |
107 | ||
108 | static const struct asus_touchpad_info asus_t100ta_tp = { | |
109 | .max_x = 2240, | |
110 | .max_y = 1758, | |
111 | .contact_size = 5, | |
112 | .max_contacts = 5, | |
113 | }; | |
114 | ||
115 | static void asus_report_contact_down(struct asus_drvdata *drvdat, | |
9ce12d8b BM |
116 | int toolType, u8 *data) |
117 | { | |
c81760b9 HG |
118 | struct input_dev *input = drvdat->input; |
119 | int touch_major, pressure, x, y; | |
120 | ||
121 | x = (data[0] & CONTACT_X_MSB_MASK) << 4 | data[1]; | |
122 | y = drvdat->tp->max_y - ((data[0] & CONTACT_Y_MSB_MASK) << 8 | data[2]); | |
9ce12d8b BM |
123 | |
124 | if (toolType == MT_TOOL_PALM) { | |
125 | touch_major = MAX_TOUCH_MAJOR; | |
126 | pressure = MAX_PRESSURE; | |
127 | } else { | |
128 | touch_major = (data[3] >> 4) & CONTACT_TOUCH_MAJOR_MASK; | |
129 | pressure = data[4] & CONTACT_PRESSURE_MASK; | |
130 | } | |
131 | ||
132 | input_report_abs(input, ABS_MT_POSITION_X, x); | |
133 | input_report_abs(input, ABS_MT_POSITION_Y, y); | |
134 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major); | |
135 | input_report_abs(input, ABS_MT_PRESSURE, pressure); | |
136 | } | |
137 | ||
138 | /* Required for Synaptics Palm Detection */ | |
c81760b9 | 139 | static void asus_report_tool_width(struct asus_drvdata *drvdat) |
9ce12d8b | 140 | { |
c81760b9 | 141 | struct input_mt *mt = drvdat->input->mt; |
9ce12d8b BM |
142 | struct input_mt_slot *oldest; |
143 | int oldid, count, i; | |
144 | ||
145 | oldest = NULL; | |
146 | oldid = mt->trkid; | |
147 | count = 0; | |
148 | ||
149 | for (i = 0; i < mt->num_slots; ++i) { | |
150 | struct input_mt_slot *ps = &mt->slots[i]; | |
151 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); | |
152 | ||
153 | if (id < 0) | |
154 | continue; | |
155 | if ((id - oldid) & TRKID_SGN) { | |
156 | oldest = ps; | |
157 | oldid = id; | |
158 | } | |
159 | count++; | |
160 | } | |
161 | ||
162 | if (oldest) { | |
c81760b9 | 163 | input_report_abs(drvdat->input, ABS_TOOL_WIDTH, |
9ce12d8b BM |
164 | input_mt_get_value(oldest, ABS_MT_TOUCH_MAJOR)); |
165 | } | |
166 | } | |
167 | ||
c81760b9 | 168 | static int asus_report_input(struct asus_drvdata *drvdat, u8 *data, int size) |
9ce12d8b BM |
169 | { |
170 | int i; | |
171 | u8 *contactData = data + 2; | |
172 | ||
c81760b9 HG |
173 | if (size != 3 + drvdat->tp->contact_size * drvdat->tp->max_contacts) |
174 | return 0; | |
175 | ||
176 | for (i = 0; i < drvdat->tp->max_contacts; i++) { | |
9ce12d8b BM |
177 | bool down = !!(data[1] & BIT(i+3)); |
178 | int toolType = contactData[3] & CONTACT_TOOL_TYPE_MASK ? | |
179 | MT_TOOL_PALM : MT_TOOL_FINGER; | |
180 | ||
c81760b9 HG |
181 | input_mt_slot(drvdat->input, i); |
182 | input_mt_report_slot_state(drvdat->input, toolType, down); | |
9ce12d8b BM |
183 | |
184 | if (down) { | |
c81760b9 HG |
185 | asus_report_contact_down(drvdat, toolType, contactData); |
186 | contactData += drvdat->tp->contact_size; | |
9ce12d8b BM |
187 | } |
188 | } | |
189 | ||
c81760b9 HG |
190 | input_report_key(drvdat->input, BTN_LEFT, data[1] & BTN_LEFT_MASK); |
191 | asus_report_tool_width(drvdat); | |
192 | ||
193 | input_mt_sync_frame(drvdat->input); | |
194 | input_sync(drvdat->input); | |
9ce12d8b | 195 | |
c81760b9 | 196 | return 1; |
9ce12d8b BM |
197 | } |
198 | ||
199 | static int asus_raw_event(struct hid_device *hdev, | |
200 | struct hid_report *report, u8 *data, int size) | |
201 | { | |
202 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); | |
203 | ||
c81760b9 HG |
204 | if (drvdata->tp && data[0] == INPUT_REPORT_ID) |
205 | return asus_report_input(drvdata, data, size); | |
9ce12d8b BM |
206 | |
207 | return 0; | |
208 | } | |
209 | ||
af22a610 CC |
210 | static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size) |
211 | { | |
212 | unsigned char *dmabuf; | |
213 | int ret; | |
214 | ||
215 | dmabuf = kmemdup(buf, buf_size, GFP_KERNEL); | |
216 | if (!dmabuf) | |
217 | return -ENOMEM; | |
218 | ||
219 | ret = hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, dmabuf, | |
220 | buf_size, HID_FEATURE_REPORT, | |
221 | HID_REQ_SET_REPORT); | |
222 | kfree(dmabuf); | |
223 | ||
224 | return ret; | |
225 | } | |
226 | ||
227 | static int asus_kbd_init(struct hid_device *hdev) | |
228 | { | |
229 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54, | |
230 | 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 }; | |
231 | int ret; | |
232 | ||
233 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); | |
234 | if (ret < 0) | |
235 | hid_err(hdev, "Asus failed to send init command: %d\n", ret); | |
236 | ||
237 | return ret; | |
238 | } | |
239 | ||
240 | static int asus_kbd_get_functions(struct hid_device *hdev, | |
241 | unsigned char *kbd_func) | |
242 | { | |
243 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 }; | |
244 | u8 *readbuf; | |
245 | int ret; | |
246 | ||
247 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); | |
248 | if (ret < 0) { | |
249 | hid_err(hdev, "Asus failed to send configuration command: %d\n", ret); | |
250 | return ret; | |
251 | } | |
252 | ||
253 | readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); | |
254 | if (!readbuf) | |
255 | return -ENOMEM; | |
256 | ||
257 | ret = hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, readbuf, | |
258 | FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT, | |
259 | HID_REQ_GET_REPORT); | |
260 | if (ret < 0) { | |
261 | hid_err(hdev, "Asus failed to request functions: %d\n", ret); | |
262 | kfree(readbuf); | |
263 | return ret; | |
264 | } | |
265 | ||
266 | *kbd_func = readbuf[6]; | |
267 | ||
268 | kfree(readbuf); | |
269 | return ret; | |
270 | } | |
271 | ||
272 | static void asus_kbd_backlight_set(struct led_classdev *led_cdev, | |
273 | enum led_brightness brightness) | |
274 | { | |
275 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, | |
276 | cdev); | |
277 | if (led->brightness == brightness) | |
278 | return; | |
279 | ||
280 | led->brightness = brightness; | |
281 | schedule_work(&led->work); | |
282 | } | |
283 | ||
284 | static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev) | |
285 | { | |
286 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, | |
287 | cdev); | |
288 | ||
289 | return led->brightness; | |
290 | } | |
291 | ||
292 | static void asus_kbd_backlight_work(struct work_struct *work) | |
293 | { | |
294 | struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work); | |
295 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, 0x00 }; | |
296 | int ret; | |
297 | ||
298 | if (led->removed) | |
299 | return; | |
300 | ||
301 | buf[4] = led->brightness; | |
302 | ||
303 | ret = asus_kbd_set_report(led->hdev, buf, sizeof(buf)); | |
304 | if (ret < 0) | |
305 | hid_err(led->hdev, "Asus failed to set keyboard backlight: %d\n", ret); | |
306 | } | |
307 | ||
308 | static int asus_kbd_register_leds(struct hid_device *hdev) | |
309 | { | |
310 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); | |
311 | unsigned char kbd_func; | |
312 | int ret; | |
313 | ||
314 | /* Initialize keyboard */ | |
315 | ret = asus_kbd_init(hdev); | |
316 | if (ret < 0) | |
317 | return ret; | |
318 | ||
319 | /* Get keyboard functions */ | |
320 | ret = asus_kbd_get_functions(hdev, &kbd_func); | |
321 | if (ret < 0) | |
322 | return ret; | |
323 | ||
324 | /* Check for backlight support */ | |
325 | if (!(kbd_func & SUPPORT_KBD_BACKLIGHT)) | |
326 | return -ENODEV; | |
327 | ||
328 | drvdata->kbd_backlight = devm_kzalloc(&hdev->dev, | |
329 | sizeof(struct asus_kbd_leds), | |
330 | GFP_KERNEL); | |
331 | if (!drvdata->kbd_backlight) | |
332 | return -ENOMEM; | |
333 | ||
334 | drvdata->kbd_backlight->removed = false; | |
335 | drvdata->kbd_backlight->brightness = 0; | |
336 | drvdata->kbd_backlight->hdev = hdev; | |
337 | drvdata->kbd_backlight->cdev.name = "asus::kbd_backlight"; | |
338 | drvdata->kbd_backlight->cdev.max_brightness = 3; | |
339 | drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; | |
340 | drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; | |
341 | INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work); | |
342 | ||
343 | ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev); | |
344 | if (ret < 0) { | |
345 | /* No need to have this still around */ | |
346 | devm_kfree(&hdev->dev, drvdata->kbd_backlight); | |
347 | } | |
348 | ||
349 | return ret; | |
350 | } | |
351 | ||
9ce12d8b BM |
352 | static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) |
353 | { | |
c8b1b3dd | 354 | struct input_dev *input = hi->input; |
9ce12d8b BM |
355 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
356 | ||
c81760b9 | 357 | if (drvdata->tp) { |
9ce12d8b | 358 | int ret; |
9ce12d8b | 359 | |
c81760b9 HG |
360 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, |
361 | drvdata->tp->max_x, 0, 0); | |
362 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, | |
363 | drvdata->tp->max_y, 0, 0); | |
9ce12d8b BM |
364 | input_set_abs_params(input, ABS_TOOL_WIDTH, 0, MAX_TOUCH_MAJOR, 0, 0); |
365 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, MAX_TOUCH_MAJOR, 0, 0); | |
366 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, MAX_PRESSURE, 0, 0); | |
367 | ||
368 | __set_bit(BTN_LEFT, input->keybit); | |
369 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | |
370 | ||
c81760b9 HG |
371 | ret = input_mt_init_slots(input, drvdata->tp->max_contacts, |
372 | INPUT_MT_POINTER); | |
9ce12d8b BM |
373 | |
374 | if (ret) { | |
375 | hid_err(hdev, "Asus input mt init slots failed: %d\n", ret); | |
376 | return ret; | |
377 | } | |
9ce12d8b BM |
378 | } |
379 | ||
c8b1b3dd BM |
380 | drvdata->input = input; |
381 | ||
af22a610 CC |
382 | if (drvdata->enable_backlight && asus_kbd_register_leds(hdev)) |
383 | hid_warn(hdev, "Failed to initialize backlight.\n"); | |
384 | ||
9ce12d8b BM |
385 | return 0; |
386 | } | |
387 | ||
a93913e1 | 388 | #define asus_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ |
1caccc25 | 389 | max, EV_KEY, (c)) |
9ce12d8b BM |
390 | static int asus_input_mapping(struct hid_device *hdev, |
391 | struct hid_input *hi, struct hid_field *field, | |
392 | struct hid_usage *usage, unsigned long **bit, | |
393 | int *max) | |
394 | { | |
395 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); | |
396 | ||
397 | if (drvdata->quirks & QUIRK_SKIP_INPUT_MAPPING) { | |
398 | /* Don't map anything from the HID report. | |
399 | * We do it all manually in asus_input_configured | |
400 | */ | |
401 | return -1; | |
402 | } | |
403 | ||
a93913e1 | 404 | /* ASUS-specific keyboard hotkeys */ |
1caccc25 CC |
405 | if ((usage->hid & HID_USAGE_PAGE) == 0xff310000) { |
406 | set_bit(EV_REP, hi->input->evbit); | |
407 | switch (usage->hid & HID_USAGE) { | |
a93913e1 MH |
408 | case 0x10: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
409 | case 0x20: asus_map_key_clear(KEY_BRIGHTNESSUP); break; | |
410 | case 0x35: asus_map_key_clear(KEY_DISPLAY_OFF); break; | |
411 | case 0x6c: asus_map_key_clear(KEY_SLEEP); break; | |
412 | case 0x82: asus_map_key_clear(KEY_CAMERA); break; | |
802b24b4 | 413 | case 0x88: asus_map_key_clear(KEY_RFKILL); break; |
a93913e1 MH |
414 | case 0xb5: asus_map_key_clear(KEY_CALC); break; |
415 | case 0xc4: asus_map_key_clear(KEY_KBDILLUMUP); break; | |
416 | case 0xc5: asus_map_key_clear(KEY_KBDILLUMDOWN); break; | |
1caccc25 CC |
417 | |
418 | /* ASUS touchpad toggle */ | |
a93913e1 | 419 | case 0x6b: asus_map_key_clear(KEY_F21); break; |
1caccc25 CC |
420 | |
421 | /* ROG key */ | |
a93913e1 | 422 | case 0x38: asus_map_key_clear(KEY_PROG1); break; |
1caccc25 CC |
423 | |
424 | /* Fn+C ASUS Splendid */ | |
a93913e1 | 425 | case 0xba: asus_map_key_clear(KEY_PROG2); break; |
1caccc25 CC |
426 | |
427 | /* Fn+Space Power4Gear Hybrid */ | |
a93913e1 | 428 | case 0x5c: asus_map_key_clear(KEY_PROG3); break; |
1caccc25 CC |
429 | |
430 | default: | |
0485b1ec MH |
431 | /* ASUS lazily declares 256 usages, ignore the rest, |
432 | * as some make the keyboard appear as a pointer device. */ | |
433 | return -1; | |
1caccc25 | 434 | } |
af22a610 CC |
435 | |
436 | /* | |
437 | * Check and enable backlight only on devices with UsagePage == | |
438 | * 0xff31 to avoid initializing the keyboard firmware multiple | |
439 | * times on devices with multiple HID descriptors but same | |
440 | * PID/VID. | |
441 | */ | |
442 | if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) | |
443 | drvdata->enable_backlight = true; | |
444 | ||
1caccc25 CC |
445 | return 1; |
446 | } | |
447 | ||
5be91803 DD |
448 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { |
449 | set_bit(EV_REP, hi->input->evbit); | |
450 | switch (usage->hid & HID_USAGE) { | |
451 | case 0xff01: asus_map_key_clear(BTN_1); break; | |
452 | case 0xff02: asus_map_key_clear(BTN_2); break; | |
453 | case 0xff03: asus_map_key_clear(BTN_3); break; | |
454 | case 0xff04: asus_map_key_clear(BTN_4); break; | |
455 | case 0xff05: asus_map_key_clear(BTN_5); break; | |
456 | case 0xff06: asus_map_key_clear(BTN_6); break; | |
457 | case 0xff07: asus_map_key_clear(BTN_7); break; | |
458 | case 0xff08: asus_map_key_clear(BTN_8); break; | |
459 | case 0xff09: asus_map_key_clear(BTN_9); break; | |
460 | case 0xff0a: asus_map_key_clear(BTN_A); break; | |
461 | case 0xff0b: asus_map_key_clear(BTN_B); break; | |
462 | case 0x00f1: asus_map_key_clear(KEY_WLAN); break; | |
463 | case 0x00f2: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; | |
464 | case 0x00f3: asus_map_key_clear(KEY_BRIGHTNESSUP); break; | |
465 | case 0x00f4: asus_map_key_clear(KEY_DISPLAY_OFF); break; | |
466 | case 0x00f7: asus_map_key_clear(KEY_CAMERA); break; | |
467 | case 0x00f8: asus_map_key_clear(KEY_PROG1); break; | |
468 | default: | |
469 | return 0; | |
470 | } | |
471 | ||
472 | return 1; | |
473 | } | |
474 | ||
0485b1ec MH |
475 | if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES && |
476 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { | |
477 | switch (usage->hid & HID_USAGE) { | |
478 | case 0xe2: /* Mute */ | |
479 | case 0xe9: /* Volume up */ | |
480 | case 0xea: /* Volume down */ | |
481 | return 0; | |
482 | default: | |
483 | /* Ignore dummy Consumer usages which make the | |
484 | * keyboard incorrectly appear as a pointer device. | |
485 | */ | |
486 | return -1; | |
487 | } | |
488 | } | |
489 | ||
9ce12d8b BM |
490 | return 0; |
491 | } | |
492 | ||
493 | static int asus_start_multitouch(struct hid_device *hdev) | |
494 | { | |
495 | int ret; | |
496 | const unsigned char buf[] = { FEATURE_REPORT_ID, 0x00, 0x03, 0x01, 0x00 }; | |
497 | unsigned char *dmabuf = kmemdup(buf, sizeof(buf), GFP_KERNEL); | |
498 | ||
499 | if (!dmabuf) { | |
500 | ret = -ENOMEM; | |
501 | hid_err(hdev, "Asus failed to alloc dma buf: %d\n", ret); | |
502 | return ret; | |
503 | } | |
504 | ||
505 | ret = hid_hw_raw_request(hdev, dmabuf[0], dmabuf, sizeof(buf), | |
506 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); | |
507 | ||
508 | kfree(dmabuf); | |
509 | ||
510 | if (ret != sizeof(buf)) { | |
511 | hid_err(hdev, "Asus failed to start multitouch: %d\n", ret); | |
512 | return ret; | |
513 | } | |
514 | ||
515 | return 0; | |
516 | } | |
517 | ||
518 | static int __maybe_unused asus_reset_resume(struct hid_device *hdev) | |
519 | { | |
520 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); | |
521 | ||
c81760b9 | 522 | if (drvdata->tp) |
9ce12d8b BM |
523 | return asus_start_multitouch(hdev); |
524 | ||
525 | return 0; | |
526 | } | |
527 | ||
528 | static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) | |
529 | { | |
530 | int ret; | |
531 | struct asus_drvdata *drvdata; | |
532 | ||
533 | drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); | |
534 | if (drvdata == NULL) { | |
535 | hid_err(hdev, "Can't alloc Asus descriptor\n"); | |
536 | return -ENOMEM; | |
537 | } | |
538 | ||
539 | hid_set_drvdata(hdev, drvdata); | |
540 | ||
541 | drvdata->quirks = id->driver_data; | |
542 | ||
c81760b9 HG |
543 | if (drvdata->quirks & QUIRK_IS_MULTITOUCH) |
544 | drvdata->tp = &asus_i2c_tp; | |
545 | ||
57573c54 HG |
546 | if (drvdata->quirks & QUIRK_T100_KEYBOARD) { |
547 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); | |
548 | ||
c81760b9 HG |
549 | if (intf->altsetting->desc.bInterfaceNumber == T100_TPAD_INTF) { |
550 | drvdata->quirks = QUIRK_SKIP_INPUT_MAPPING; | |
551 | drvdata->tp = &asus_t100ta_tp; | |
552 | } | |
57573c54 HG |
553 | } |
554 | ||
9ce12d8b BM |
555 | if (drvdata->quirks & QUIRK_NO_INIT_REPORTS) |
556 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; | |
557 | ||
558 | ret = hid_parse(hdev); | |
559 | if (ret) { | |
560 | hid_err(hdev, "Asus hid parse failed: %d\n", ret); | |
561 | return ret; | |
562 | } | |
563 | ||
564 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | |
565 | if (ret) { | |
566 | hid_err(hdev, "Asus hw start failed: %d\n", ret); | |
567 | return ret; | |
568 | } | |
569 | ||
570 | if (!drvdata->input) { | |
571 | hid_err(hdev, "Asus input not registered\n"); | |
572 | ret = -ENOMEM; | |
573 | goto err_stop_hw; | |
574 | } | |
575 | ||
c81760b9 | 576 | if (drvdata->tp) { |
c8b1b3dd BM |
577 | drvdata->input->name = "Asus TouchPad"; |
578 | } else { | |
579 | drvdata->input->name = "Asus Keyboard"; | |
580 | } | |
9ce12d8b | 581 | |
c81760b9 | 582 | if (drvdata->tp) { |
9ce12d8b BM |
583 | ret = asus_start_multitouch(hdev); |
584 | if (ret) | |
585 | goto err_stop_hw; | |
586 | } | |
587 | ||
588 | return 0; | |
589 | err_stop_hw: | |
590 | hid_hw_stop(hdev); | |
591 | return ret; | |
592 | } | |
593 | ||
af22a610 CC |
594 | static void asus_remove(struct hid_device *hdev) |
595 | { | |
596 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); | |
597 | ||
598 | if (drvdata->kbd_backlight) { | |
599 | drvdata->kbd_backlight->removed = true; | |
600 | cancel_work_sync(&drvdata->kbd_backlight->work); | |
601 | } | |
715e944f CC |
602 | |
603 | hid_hw_stop(hdev); | |
af22a610 CC |
604 | } |
605 | ||
eeb01a57 YF |
606 | static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
607 | unsigned int *rsize) | |
608 | { | |
9ce12d8b BM |
609 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
610 | ||
611 | if (drvdata->quirks & QUIRK_FIX_NOTEBOOK_REPORT && | |
612 | *rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x65) { | |
b94f7d5d | 613 | hid_info(hdev, "Fixing up Asus notebook report descriptor\n"); |
eeb01a57 YF |
614 | rdesc[55] = 0xdd; |
615 | } | |
76dd1fbe HG |
616 | if (drvdata->quirks & QUIRK_T100_KEYBOARD && |
617 | *rsize == 76 && rdesc[73] == 0x81 && rdesc[74] == 0x01) { | |
618 | hid_info(hdev, "Fixing up Asus T100 keyb report descriptor\n"); | |
619 | rdesc[74] &= ~HID_MAIN_ITEM_CONSTANT; | |
620 | } | |
621 | ||
eeb01a57 YF |
622 | return rdesc; |
623 | } | |
624 | ||
625 | static const struct hid_device_id asus_devices[] = { | |
9ce12d8b | 626 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
a93913e1 | 627 | USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD), I2C_KEYBOARD_QUIRKS}, |
9ce12d8b | 628 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
c81760b9 | 629 | USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD), I2C_TOUCHPAD_QUIRKS }, |
1caccc25 CC |
630 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
631 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1) }, | |
632 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, | |
af22a610 | 633 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2), QUIRK_USE_KBD_BACKLIGHT }, |
76dd1fbe HG |
634 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
635 | USB_DEVICE_ID_ASUSTEK_T100_KEYBOARD), | |
636 | QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES }, | |
5be91803 | 637 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_ASUS_AK1D) }, |
38b2d78c | 638 | { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_ASUS_MD_5110) }, |
5be91803 | 639 | { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_ASUS_MD_5112) }, |
eeb01a57 YF |
640 | { } |
641 | }; | |
642 | MODULE_DEVICE_TABLE(hid, asus_devices); | |
643 | ||
644 | static struct hid_driver asus_driver = { | |
9ce12d8b BM |
645 | .name = "asus", |
646 | .id_table = asus_devices, | |
647 | .report_fixup = asus_report_fixup, | |
648 | .probe = asus_probe, | |
af22a610 | 649 | .remove = asus_remove, |
9ce12d8b BM |
650 | .input_mapping = asus_input_mapping, |
651 | .input_configured = asus_input_configured, | |
652 | #ifdef CONFIG_PM | |
653 | .reset_resume = asus_reset_resume, | |
654 | #endif | |
655 | .raw_event = asus_raw_event | |
eeb01a57 YF |
656 | }; |
657 | module_hid_driver(asus_driver); | |
658 | ||
659 | MODULE_LICENSE("GPL"); |