Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 1 | /* |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 2 | * HID driver for Asus notebook built-in keyboard. |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 3 | * Fixes small logical maximum to match usage maximum. |
| 4 | * |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 5 | * Currently supported devices are: |
| 6 | * EeeBook X205TA |
| 7 | * VivoBook E200HA |
| 8 | * |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 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 |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 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> |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 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 | |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 29 | #include <linux/dmi.h> |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 30 | #include <linux/hid.h> |
| 31 | #include <linux/module.h> |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 32 | #include <linux/input/mt.h> |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 33 | #include <linux/usb.h> /* For to_usb_interface for T100 touchpad intf check */ |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 34 | |
| 35 | #include "hid-ids.h" |
| 36 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 37 | MODULE_AUTHOR("Yusuke Fujimaki <usk.fujimaki@gmail.com>"); |
| 38 | MODULE_AUTHOR("Brendan McGrath <redmcg@redmandi.dyndns.org>"); |
| 39 | MODULE_AUTHOR("Victor Vlasenko <victor.vlasenko@sysgears.com>"); |
| 40 | MODULE_AUTHOR("Frederik Wenigwieser <frederik.wenigwieser@gmail.com>"); |
| 41 | MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); |
| 42 | |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 43 | #define T100_TPAD_INTF 2 |
| 44 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 45 | #define T100CHI_MOUSE_REPORT_ID 0x06 |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 46 | #define FEATURE_REPORT_ID 0x0d |
| 47 | #define INPUT_REPORT_ID 0x5d |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 48 | #define FEATURE_KBD_REPORT_ID 0x5a |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 49 | #define FEATURE_KBD_REPORT_SIZE 16 |
| 50 | |
| 51 | #define SUPPORT_KBD_BACKLIGHT BIT(0) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 52 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 53 | #define MAX_TOUCH_MAJOR 8 |
| 54 | #define MAX_PRESSURE 128 |
| 55 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 56 | #define BTN_LEFT_MASK 0x01 |
| 57 | #define CONTACT_TOOL_TYPE_MASK 0x80 |
| 58 | #define CONTACT_X_MSB_MASK 0xf0 |
| 59 | #define CONTACT_Y_MSB_MASK 0x0f |
| 60 | #define CONTACT_TOUCH_MAJOR_MASK 0x07 |
| 61 | #define CONTACT_PRESSURE_MASK 0x7f |
| 62 | |
| 63 | #define QUIRK_FIX_NOTEBOOK_REPORT BIT(0) |
| 64 | #define QUIRK_NO_INIT_REPORTS BIT(1) |
| 65 | #define QUIRK_SKIP_INPUT_MAPPING BIT(2) |
| 66 | #define QUIRK_IS_MULTITOUCH BIT(3) |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 67 | #define QUIRK_NO_CONSUMER_USAGES BIT(4) |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 68 | #define QUIRK_USE_KBD_BACKLIGHT BIT(5) |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 69 | #define QUIRK_T100_KEYBOARD BIT(6) |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 70 | #define QUIRK_T100CHI BIT(7) |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 71 | #define QUIRK_G752_KEYBOARD BIT(8) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 72 | |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 73 | #define I2C_KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 74 | QUIRK_NO_INIT_REPORTS | \ |
| 75 | QUIRK_NO_CONSUMER_USAGES) |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 76 | #define I2C_TOUCHPAD_QUIRKS (QUIRK_NO_INIT_REPORTS | \ |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 77 | QUIRK_SKIP_INPUT_MAPPING | \ |
| 78 | QUIRK_IS_MULTITOUCH) |
| 79 | |
| 80 | #define TRKID_SGN ((TRKID_MAX + 1) >> 1) |
| 81 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 82 | struct asus_kbd_leds { |
| 83 | struct led_classdev cdev; |
| 84 | struct hid_device *hdev; |
| 85 | struct work_struct work; |
| 86 | unsigned int brightness; |
| 87 | bool removed; |
| 88 | }; |
| 89 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 90 | struct asus_touchpad_info { |
| 91 | int max_x; |
| 92 | int max_y; |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 93 | int res_x; |
| 94 | int res_y; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 95 | int contact_size; |
| 96 | int max_contacts; |
| 97 | }; |
| 98 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 99 | struct asus_drvdata { |
| 100 | unsigned long quirks; |
| 101 | struct input_dev *input; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 102 | struct asus_kbd_leds *kbd_backlight; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 103 | const struct asus_touchpad_info *tp; |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 104 | bool enable_backlight; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 105 | }; |
| 106 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 107 | static const struct asus_touchpad_info asus_i2c_tp = { |
| 108 | .max_x = 2794, |
| 109 | .max_y = 1758, |
| 110 | .contact_size = 5, |
| 111 | .max_contacts = 5, |
| 112 | }; |
| 113 | |
| 114 | static const struct asus_touchpad_info asus_t100ta_tp = { |
| 115 | .max_x = 2240, |
Hans de Goede | 25cc261 | 2017-07-02 16:34:13 +0200 | [diff] [blame] | 116 | .max_y = 1120, |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 117 | .res_x = 30, /* units/mm */ |
| 118 | .res_y = 27, /* units/mm */ |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 119 | .contact_size = 5, |
| 120 | .max_contacts = 5, |
| 121 | }; |
| 122 | |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 123 | static const struct asus_touchpad_info asus_t100ha_tp = { |
| 124 | .max_x = 2640, |
| 125 | .max_y = 1320, |
| 126 | .res_x = 30, /* units/mm */ |
| 127 | .res_y = 29, /* units/mm */ |
| 128 | .contact_size = 5, |
| 129 | .max_contacts = 5, |
| 130 | }; |
| 131 | |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 132 | static const struct asus_touchpad_info asus_t200ta_tp = { |
| 133 | .max_x = 3120, |
| 134 | .max_y = 1716, |
| 135 | .res_x = 30, /* units/mm */ |
| 136 | .res_y = 28, /* units/mm */ |
| 137 | .contact_size = 5, |
| 138 | .max_contacts = 5, |
| 139 | }; |
| 140 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 141 | static const struct asus_touchpad_info asus_t100chi_tp = { |
| 142 | .max_x = 2640, |
| 143 | .max_y = 1320, |
| 144 | .res_x = 31, /* units/mm */ |
| 145 | .res_y = 29, /* units/mm */ |
| 146 | .contact_size = 3, |
| 147 | .max_contacts = 4, |
| 148 | }; |
| 149 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 150 | static void asus_report_contact_down(struct asus_drvdata *drvdat, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 151 | int toolType, u8 *data) |
| 152 | { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 153 | struct input_dev *input = drvdat->input; |
| 154 | int touch_major, pressure, x, y; |
| 155 | |
| 156 | x = (data[0] & CONTACT_X_MSB_MASK) << 4 | data[1]; |
| 157 | y = drvdat->tp->max_y - ((data[0] & CONTACT_Y_MSB_MASK) << 8 | data[2]); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 158 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 159 | input_report_abs(input, ABS_MT_POSITION_X, x); |
| 160 | input_report_abs(input, ABS_MT_POSITION_Y, y); |
| 161 | |
| 162 | if (drvdat->tp->contact_size < 5) |
| 163 | return; |
| 164 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 165 | if (toolType == MT_TOOL_PALM) { |
| 166 | touch_major = MAX_TOUCH_MAJOR; |
| 167 | pressure = MAX_PRESSURE; |
| 168 | } else { |
| 169 | touch_major = (data[3] >> 4) & CONTACT_TOUCH_MAJOR_MASK; |
| 170 | pressure = data[4] & CONTACT_PRESSURE_MASK; |
| 171 | } |
| 172 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 173 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, touch_major); |
| 174 | input_report_abs(input, ABS_MT_PRESSURE, pressure); |
| 175 | } |
| 176 | |
| 177 | /* Required for Synaptics Palm Detection */ |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 178 | static void asus_report_tool_width(struct asus_drvdata *drvdat) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 179 | { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 180 | struct input_mt *mt = drvdat->input->mt; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 181 | struct input_mt_slot *oldest; |
| 182 | int oldid, count, i; |
| 183 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 184 | if (drvdat->tp->contact_size < 5) |
| 185 | return; |
| 186 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 187 | oldest = NULL; |
| 188 | oldid = mt->trkid; |
| 189 | count = 0; |
| 190 | |
| 191 | for (i = 0; i < mt->num_slots; ++i) { |
| 192 | struct input_mt_slot *ps = &mt->slots[i]; |
| 193 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); |
| 194 | |
| 195 | if (id < 0) |
| 196 | continue; |
| 197 | if ((id - oldid) & TRKID_SGN) { |
| 198 | oldest = ps; |
| 199 | oldid = id; |
| 200 | } |
| 201 | count++; |
| 202 | } |
| 203 | |
| 204 | if (oldest) { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 205 | input_report_abs(drvdat->input, ABS_TOOL_WIDTH, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 206 | input_mt_get_value(oldest, ABS_MT_TOUCH_MAJOR)); |
| 207 | } |
| 208 | } |
| 209 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 210 | static int asus_report_input(struct asus_drvdata *drvdat, u8 *data, int size) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 211 | { |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 212 | int i, toolType = MT_TOOL_FINGER; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 213 | u8 *contactData = data + 2; |
| 214 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 215 | if (size != 3 + drvdat->tp->contact_size * drvdat->tp->max_contacts) |
| 216 | return 0; |
| 217 | |
| 218 | for (i = 0; i < drvdat->tp->max_contacts; i++) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 219 | bool down = !!(data[1] & BIT(i+3)); |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 220 | |
| 221 | if (drvdat->tp->contact_size >= 5) |
| 222 | toolType = contactData[3] & CONTACT_TOOL_TYPE_MASK ? |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 223 | MT_TOOL_PALM : MT_TOOL_FINGER; |
| 224 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 225 | input_mt_slot(drvdat->input, i); |
| 226 | input_mt_report_slot_state(drvdat->input, toolType, down); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 227 | |
| 228 | if (down) { |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 229 | asus_report_contact_down(drvdat, toolType, contactData); |
| 230 | contactData += drvdat->tp->contact_size; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 234 | input_report_key(drvdat->input, BTN_LEFT, data[1] & BTN_LEFT_MASK); |
| 235 | asus_report_tool_width(drvdat); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 236 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 237 | input_mt_sync_frame(drvdat->input); |
| 238 | input_sync(drvdat->input); |
| 239 | |
| 240 | return 1; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static int asus_raw_event(struct hid_device *hdev, |
| 244 | struct hid_report *report, u8 *data, int size) |
| 245 | { |
| 246 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 247 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 248 | if (drvdata->tp && data[0] == INPUT_REPORT_ID) |
| 249 | return asus_report_input(drvdata, data, size); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 254 | static int asus_kbd_set_report(struct hid_device *hdev, u8 *buf, size_t buf_size) |
| 255 | { |
| 256 | unsigned char *dmabuf; |
| 257 | int ret; |
| 258 | |
| 259 | dmabuf = kmemdup(buf, buf_size, GFP_KERNEL); |
| 260 | if (!dmabuf) |
| 261 | return -ENOMEM; |
| 262 | |
| 263 | ret = hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, dmabuf, |
| 264 | buf_size, HID_FEATURE_REPORT, |
| 265 | HID_REQ_SET_REPORT); |
| 266 | kfree(dmabuf); |
| 267 | |
| 268 | return ret; |
| 269 | } |
| 270 | |
| 271 | static int asus_kbd_init(struct hid_device *hdev) |
| 272 | { |
| 273 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x41, 0x53, 0x55, 0x53, 0x20, 0x54, |
| 274 | 0x65, 0x63, 0x68, 0x2e, 0x49, 0x6e, 0x63, 0x2e, 0x00 }; |
| 275 | int ret; |
| 276 | |
| 277 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); |
| 278 | if (ret < 0) |
| 279 | hid_err(hdev, "Asus failed to send init command: %d\n", ret); |
| 280 | |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | static int asus_kbd_get_functions(struct hid_device *hdev, |
| 285 | unsigned char *kbd_func) |
| 286 | { |
| 287 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0x05, 0x20, 0x31, 0x00, 0x08 }; |
| 288 | u8 *readbuf; |
| 289 | int ret; |
| 290 | |
| 291 | ret = asus_kbd_set_report(hdev, buf, sizeof(buf)); |
| 292 | if (ret < 0) { |
| 293 | hid_err(hdev, "Asus failed to send configuration command: %d\n", ret); |
| 294 | return ret; |
| 295 | } |
| 296 | |
| 297 | readbuf = kzalloc(FEATURE_KBD_REPORT_SIZE, GFP_KERNEL); |
| 298 | if (!readbuf) |
| 299 | return -ENOMEM; |
| 300 | |
| 301 | ret = hid_hw_raw_request(hdev, FEATURE_KBD_REPORT_ID, readbuf, |
| 302 | FEATURE_KBD_REPORT_SIZE, HID_FEATURE_REPORT, |
| 303 | HID_REQ_GET_REPORT); |
| 304 | if (ret < 0) { |
| 305 | hid_err(hdev, "Asus failed to request functions: %d\n", ret); |
| 306 | kfree(readbuf); |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | *kbd_func = readbuf[6]; |
| 311 | |
| 312 | kfree(readbuf); |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | static void asus_kbd_backlight_set(struct led_classdev *led_cdev, |
| 317 | enum led_brightness brightness) |
| 318 | { |
| 319 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, |
| 320 | cdev); |
| 321 | if (led->brightness == brightness) |
| 322 | return; |
| 323 | |
| 324 | led->brightness = brightness; |
| 325 | schedule_work(&led->work); |
| 326 | } |
| 327 | |
| 328 | static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev) |
| 329 | { |
| 330 | struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds, |
| 331 | cdev); |
| 332 | |
| 333 | return led->brightness; |
| 334 | } |
| 335 | |
| 336 | static void asus_kbd_backlight_work(struct work_struct *work) |
| 337 | { |
| 338 | struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work); |
| 339 | u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, 0x00 }; |
| 340 | int ret; |
| 341 | |
| 342 | if (led->removed) |
| 343 | return; |
| 344 | |
| 345 | buf[4] = led->brightness; |
| 346 | |
| 347 | ret = asus_kbd_set_report(led->hdev, buf, sizeof(buf)); |
| 348 | if (ret < 0) |
| 349 | hid_err(led->hdev, "Asus failed to set keyboard backlight: %d\n", ret); |
| 350 | } |
| 351 | |
| 352 | static int asus_kbd_register_leds(struct hid_device *hdev) |
| 353 | { |
| 354 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 355 | unsigned char kbd_func; |
| 356 | int ret; |
| 357 | |
| 358 | /* Initialize keyboard */ |
| 359 | ret = asus_kbd_init(hdev); |
| 360 | if (ret < 0) |
| 361 | return ret; |
| 362 | |
| 363 | /* Get keyboard functions */ |
| 364 | ret = asus_kbd_get_functions(hdev, &kbd_func); |
| 365 | if (ret < 0) |
| 366 | return ret; |
| 367 | |
| 368 | /* Check for backlight support */ |
| 369 | if (!(kbd_func & SUPPORT_KBD_BACKLIGHT)) |
| 370 | return -ENODEV; |
| 371 | |
| 372 | drvdata->kbd_backlight = devm_kzalloc(&hdev->dev, |
| 373 | sizeof(struct asus_kbd_leds), |
| 374 | GFP_KERNEL); |
| 375 | if (!drvdata->kbd_backlight) |
| 376 | return -ENOMEM; |
| 377 | |
| 378 | drvdata->kbd_backlight->removed = false; |
| 379 | drvdata->kbd_backlight->brightness = 0; |
| 380 | drvdata->kbd_backlight->hdev = hdev; |
| 381 | drvdata->kbd_backlight->cdev.name = "asus::kbd_backlight"; |
| 382 | drvdata->kbd_backlight->cdev.max_brightness = 3; |
| 383 | drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set; |
| 384 | drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get; |
| 385 | INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work); |
| 386 | |
| 387 | ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev); |
| 388 | if (ret < 0) { |
| 389 | /* No need to have this still around */ |
| 390 | devm_kfree(&hdev->dev, drvdata->kbd_backlight); |
| 391 | } |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 396 | static int asus_input_configured(struct hid_device *hdev, struct hid_input *hi) |
| 397 | { |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 398 | struct input_dev *input = hi->input; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 399 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 400 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 401 | /* T100CHI uses MULTI_INPUT, bind the touchpad to the mouse hid_input */ |
| 402 | if (drvdata->quirks & QUIRK_T100CHI && |
| 403 | hi->report->id != T100CHI_MOUSE_REPORT_ID) |
| 404 | return 0; |
| 405 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 406 | if (drvdata->tp) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 407 | int ret; |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 408 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 409 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, |
| 410 | drvdata->tp->max_x, 0, 0); |
| 411 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, |
| 412 | drvdata->tp->max_y, 0, 0); |
Hans de Goede | b61d43e6 | 2017-07-02 16:34:14 +0200 | [diff] [blame] | 413 | input_abs_set_res(input, ABS_MT_POSITION_X, drvdata->tp->res_x); |
| 414 | input_abs_set_res(input, ABS_MT_POSITION_Y, drvdata->tp->res_y); |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 415 | |
| 416 | if (drvdata->tp->contact_size >= 5) { |
| 417 | input_set_abs_params(input, ABS_TOOL_WIDTH, 0, |
| 418 | MAX_TOUCH_MAJOR, 0, 0); |
| 419 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, |
| 420 | MAX_TOUCH_MAJOR, 0, 0); |
| 421 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, |
| 422 | MAX_PRESSURE, 0, 0); |
| 423 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 424 | |
| 425 | __set_bit(BTN_LEFT, input->keybit); |
| 426 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
| 427 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 428 | ret = input_mt_init_slots(input, drvdata->tp->max_contacts, |
| 429 | INPUT_MT_POINTER); |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 430 | |
| 431 | if (ret) { |
| 432 | hid_err(hdev, "Asus input mt init slots failed: %d\n", ret); |
| 433 | return ret; |
| 434 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 435 | } |
| 436 | |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 437 | drvdata->input = input; |
| 438 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 439 | if (drvdata->enable_backlight && asus_kbd_register_leds(hdev)) |
| 440 | hid_warn(hdev, "Failed to initialize backlight.\n"); |
| 441 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 445 | #define asus_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 446 | max, EV_KEY, (c)) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 447 | static int asus_input_mapping(struct hid_device *hdev, |
| 448 | struct hid_input *hi, struct hid_field *field, |
| 449 | struct hid_usage *usage, unsigned long **bit, |
| 450 | int *max) |
| 451 | { |
| 452 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 453 | |
| 454 | if (drvdata->quirks & QUIRK_SKIP_INPUT_MAPPING) { |
| 455 | /* Don't map anything from the HID report. |
| 456 | * We do it all manually in asus_input_configured |
| 457 | */ |
| 458 | return -1; |
| 459 | } |
| 460 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 461 | /* |
| 462 | * Ignore a bunch of bogus collections in the T100CHI descriptor. |
| 463 | * This avoids a bunch of non-functional hid_input devices getting |
| 464 | * created because of the T100CHI using HID_QUIRK_MULTI_INPUT. |
| 465 | */ |
| 466 | if (drvdata->quirks & QUIRK_T100CHI) { |
| 467 | if (field->application == (HID_UP_GENDESK | 0x0080) || |
| 468 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0024) || |
| 469 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0025) || |
| 470 | usage->hid == (HID_UP_GENDEVCTRLS | 0x0026)) |
| 471 | return -1; |
| 472 | /* |
| 473 | * We use the hid_input for the mouse report for the touchpad, |
| 474 | * keep the left button, to avoid the core removing it. |
| 475 | */ |
| 476 | if (field->application == HID_GD_MOUSE && |
| 477 | usage->hid != (HID_UP_BUTTON | 1)) |
| 478 | return -1; |
| 479 | } |
| 480 | |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 481 | /* ASUS-specific keyboard hotkeys */ |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 482 | if ((usage->hid & HID_USAGE_PAGE) == 0xff310000) { |
| 483 | set_bit(EV_REP, hi->input->evbit); |
| 484 | switch (usage->hid & HID_USAGE) { |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 485 | case 0x10: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 486 | case 0x20: asus_map_key_clear(KEY_BRIGHTNESSUP); break; |
| 487 | case 0x35: asus_map_key_clear(KEY_DISPLAY_OFF); break; |
| 488 | case 0x6c: asus_map_key_clear(KEY_SLEEP); break; |
| 489 | case 0x82: asus_map_key_clear(KEY_CAMERA); break; |
Matjaz Hegedic | 802b24b | 2017-03-09 00:31:15 +0100 | [diff] [blame] | 490 | case 0x88: asus_map_key_clear(KEY_RFKILL); break; |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 491 | case 0xb5: asus_map_key_clear(KEY_CALC); break; |
| 492 | case 0xc4: asus_map_key_clear(KEY_KBDILLUMUP); break; |
| 493 | case 0xc5: asus_map_key_clear(KEY_KBDILLUMDOWN); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 494 | |
| 495 | /* ASUS touchpad toggle */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 496 | case 0x6b: asus_map_key_clear(KEY_F21); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 497 | |
| 498 | /* ROG key */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 499 | case 0x38: asus_map_key_clear(KEY_PROG1); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 500 | |
| 501 | /* Fn+C ASUS Splendid */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 502 | case 0xba: asus_map_key_clear(KEY_PROG2); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 503 | |
| 504 | /* Fn+Space Power4Gear Hybrid */ |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 505 | case 0x5c: asus_map_key_clear(KEY_PROG3); break; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 506 | |
| 507 | default: |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 508 | /* ASUS lazily declares 256 usages, ignore the rest, |
| 509 | * as some make the keyboard appear as a pointer device. */ |
| 510 | return -1; |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 511 | } |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * Check and enable backlight only on devices with UsagePage == |
| 515 | * 0xff31 to avoid initializing the keyboard firmware multiple |
| 516 | * times on devices with multiple HID descriptors but same |
| 517 | * PID/VID. |
| 518 | */ |
| 519 | if (drvdata->quirks & QUIRK_USE_KBD_BACKLIGHT) |
| 520 | drvdata->enable_backlight = true; |
| 521 | |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 522 | return 1; |
| 523 | } |
| 524 | |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 525 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) { |
| 526 | set_bit(EV_REP, hi->input->evbit); |
| 527 | switch (usage->hid & HID_USAGE) { |
| 528 | case 0xff01: asus_map_key_clear(BTN_1); break; |
| 529 | case 0xff02: asus_map_key_clear(BTN_2); break; |
| 530 | case 0xff03: asus_map_key_clear(BTN_3); break; |
| 531 | case 0xff04: asus_map_key_clear(BTN_4); break; |
| 532 | case 0xff05: asus_map_key_clear(BTN_5); break; |
| 533 | case 0xff06: asus_map_key_clear(BTN_6); break; |
| 534 | case 0xff07: asus_map_key_clear(BTN_7); break; |
| 535 | case 0xff08: asus_map_key_clear(BTN_8); break; |
| 536 | case 0xff09: asus_map_key_clear(BTN_9); break; |
| 537 | case 0xff0a: asus_map_key_clear(BTN_A); break; |
| 538 | case 0xff0b: asus_map_key_clear(BTN_B); break; |
| 539 | case 0x00f1: asus_map_key_clear(KEY_WLAN); break; |
| 540 | case 0x00f2: asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; |
| 541 | case 0x00f3: asus_map_key_clear(KEY_BRIGHTNESSUP); break; |
| 542 | case 0x00f4: asus_map_key_clear(KEY_DISPLAY_OFF); break; |
| 543 | case 0x00f7: asus_map_key_clear(KEY_CAMERA); break; |
| 544 | case 0x00f8: asus_map_key_clear(KEY_PROG1); break; |
| 545 | default: |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | return 1; |
| 550 | } |
| 551 | |
Matjaz Hegedic | 0485b1e | 2017-03-09 00:31:14 +0100 | [diff] [blame] | 552 | if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES && |
| 553 | (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { |
| 554 | switch (usage->hid & HID_USAGE) { |
| 555 | case 0xe2: /* Mute */ |
| 556 | case 0xe9: /* Volume up */ |
| 557 | case 0xea: /* Volume down */ |
| 558 | return 0; |
| 559 | default: |
| 560 | /* Ignore dummy Consumer usages which make the |
| 561 | * keyboard incorrectly appear as a pointer device. |
| 562 | */ |
| 563 | return -1; |
| 564 | } |
| 565 | } |
| 566 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static int asus_start_multitouch(struct hid_device *hdev) |
| 571 | { |
| 572 | int ret; |
| 573 | const unsigned char buf[] = { FEATURE_REPORT_ID, 0x00, 0x03, 0x01, 0x00 }; |
| 574 | unsigned char *dmabuf = kmemdup(buf, sizeof(buf), GFP_KERNEL); |
| 575 | |
| 576 | if (!dmabuf) { |
| 577 | ret = -ENOMEM; |
| 578 | hid_err(hdev, "Asus failed to alloc dma buf: %d\n", ret); |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | ret = hid_hw_raw_request(hdev, dmabuf[0], dmabuf, sizeof(buf), |
| 583 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 584 | |
| 585 | kfree(dmabuf); |
| 586 | |
| 587 | if (ret != sizeof(buf)) { |
| 588 | hid_err(hdev, "Asus failed to start multitouch: %d\n", ret); |
| 589 | return ret; |
| 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int __maybe_unused asus_reset_resume(struct hid_device *hdev) |
| 596 | { |
| 597 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 598 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 599 | if (drvdata->tp) |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 600 | return asus_start_multitouch(hdev); |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 606 | { |
| 607 | int ret; |
| 608 | struct asus_drvdata *drvdata; |
| 609 | |
| 610 | drvdata = devm_kzalloc(&hdev->dev, sizeof(*drvdata), GFP_KERNEL); |
| 611 | if (drvdata == NULL) { |
| 612 | hid_err(hdev, "Can't alloc Asus descriptor\n"); |
| 613 | return -ENOMEM; |
| 614 | } |
| 615 | |
| 616 | hid_set_drvdata(hdev, drvdata); |
| 617 | |
| 618 | drvdata->quirks = id->driver_data; |
| 619 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 620 | if (drvdata->quirks & QUIRK_IS_MULTITOUCH) |
| 621 | drvdata->tp = &asus_i2c_tp; |
| 622 | |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 623 | if (drvdata->quirks & QUIRK_T100_KEYBOARD) { |
| 624 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 625 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 626 | if (intf->altsetting->desc.bInterfaceNumber == T100_TPAD_INTF) { |
| 627 | drvdata->quirks = QUIRK_SKIP_INPUT_MAPPING; |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 628 | /* |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 629 | * The T100HA uses the same USB-ids as the T100TAF and |
| 630 | * the T200TA uses the same USB-ids as the T100TA, while |
| 631 | * both have different max x/y values as the T100TA[F]. |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 632 | */ |
| 633 | if (dmi_match(DMI_PRODUCT_NAME, "T100HAN")) |
| 634 | drvdata->tp = &asus_t100ha_tp; |
Hans de Goede | dbd3ef2 | 2018-01-05 12:09:18 +0100 | [diff] [blame] | 635 | else if (dmi_match(DMI_PRODUCT_NAME, "T200TA")) |
| 636 | drvdata->tp = &asus_t200ta_tp; |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 637 | else |
| 638 | drvdata->tp = &asus_t100ta_tp; |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 639 | } |
Hans de Goede | 57573c5 | 2017-05-25 16:49:21 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 642 | if (drvdata->quirks & QUIRK_T100CHI) { |
| 643 | /* |
| 644 | * All functionality is on a single HID interface and for |
| 645 | * userspace the touchpad must be a separate input_dev. |
| 646 | */ |
Benjamin Tissoires | 39335d1 | 2018-03-20 12:04:49 +0100 | [diff] [blame^] | 647 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
Hans de Goede | 73c75d3 | 2017-08-04 15:31:04 +0200 | [diff] [blame] | 648 | drvdata->tp = &asus_t100chi_tp; |
| 649 | } |
| 650 | |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 651 | if (drvdata->quirks & QUIRK_NO_INIT_REPORTS) |
| 652 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 653 | |
| 654 | ret = hid_parse(hdev); |
| 655 | if (ret) { |
| 656 | hid_err(hdev, "Asus hid parse failed: %d\n", ret); |
| 657 | return ret; |
| 658 | } |
| 659 | |
| 660 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 661 | if (ret) { |
| 662 | hid_err(hdev, "Asus hw start failed: %d\n", ret); |
| 663 | return ret; |
| 664 | } |
| 665 | |
| 666 | if (!drvdata->input) { |
| 667 | hid_err(hdev, "Asus input not registered\n"); |
| 668 | ret = -ENOMEM; |
| 669 | goto err_stop_hw; |
| 670 | } |
| 671 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 672 | if (drvdata->tp) { |
Brendan McGrath | c8b1b3d | 2016-12-10 21:20:42 +1100 | [diff] [blame] | 673 | drvdata->input->name = "Asus TouchPad"; |
| 674 | } else { |
| 675 | drvdata->input->name = "Asus Keyboard"; |
| 676 | } |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 677 | |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 678 | if (drvdata->tp) { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 679 | ret = asus_start_multitouch(hdev); |
| 680 | if (ret) |
| 681 | goto err_stop_hw; |
| 682 | } |
| 683 | |
| 684 | return 0; |
| 685 | err_stop_hw: |
| 686 | hid_hw_stop(hdev); |
| 687 | return ret; |
| 688 | } |
| 689 | |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 690 | static void asus_remove(struct hid_device *hdev) |
| 691 | { |
| 692 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 693 | |
| 694 | if (drvdata->kbd_backlight) { |
| 695 | drvdata->kbd_backlight->removed = true; |
| 696 | cancel_work_sync(&drvdata->kbd_backlight->work); |
| 697 | } |
Carlo Caione | 715e944 | 2017-05-30 22:39:46 +0200 | [diff] [blame] | 698 | |
| 699 | hid_hw_stop(hdev); |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 700 | } |
| 701 | |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 702 | static const __u8 asus_g752_fixed_rdesc[] = { |
| 703 | 0x19, 0x00, /* Usage Minimum (0x00) */ |
| 704 | 0x2A, 0xFF, 0x00, /* Usage Maximum (0xFF) */ |
| 705 | }; |
| 706 | |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 707 | static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 708 | unsigned int *rsize) |
| 709 | { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 710 | struct asus_drvdata *drvdata = hid_get_drvdata(hdev); |
| 711 | |
| 712 | if (drvdata->quirks & QUIRK_FIX_NOTEBOOK_REPORT && |
| 713 | *rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x65) { |
Yusuke Fujimaki | b94f7d5 | 2016-04-03 23:15:16 +0900 | [diff] [blame] | 714 | hid_info(hdev, "Fixing up Asus notebook report descriptor\n"); |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 715 | rdesc[55] = 0xdd; |
| 716 | } |
Hans de Goede | 33edee4 | 2018-01-05 12:09:19 +0100 | [diff] [blame] | 717 | /* For the T100TA/T200TA keyboard dock */ |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 718 | if (drvdata->quirks & QUIRK_T100_KEYBOARD && |
Hans de Goede | 33edee4 | 2018-01-05 12:09:19 +0100 | [diff] [blame] | 719 | (*rsize == 76 || *rsize == 101) && |
| 720 | rdesc[73] == 0x81 && rdesc[74] == 0x01) { |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 721 | hid_info(hdev, "Fixing up Asus T100 keyb report descriptor\n"); |
| 722 | rdesc[74] &= ~HID_MAIN_ITEM_CONSTANT; |
| 723 | } |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 724 | /* For the T100CHI keyboard dock */ |
| 725 | if (drvdata->quirks & QUIRK_T100CHI && |
| 726 | *rsize == 403 && rdesc[388] == 0x09 && rdesc[389] == 0x76) { |
| 727 | /* |
| 728 | * Change Usage (76h) to Usage Minimum (00h), Usage Maximum |
| 729 | * (FFh) and clear the flags in the Input() byte. |
| 730 | * Note the descriptor has a bogus 0 byte at the end so we |
| 731 | * only need 1 extra byte. |
| 732 | */ |
| 733 | *rsize = 404; |
| 734 | rdesc = kmemdup(rdesc, *rsize, GFP_KERNEL); |
| 735 | if (!rdesc) |
| 736 | return NULL; |
| 737 | |
| 738 | hid_info(hdev, "Fixing up T100CHI keyb report descriptor\n"); |
| 739 | memmove(rdesc + 392, rdesc + 390, 12); |
| 740 | rdesc[388] = 0x19; |
| 741 | rdesc[389] = 0x00; |
| 742 | rdesc[390] = 0x29; |
| 743 | rdesc[391] = 0xff; |
| 744 | rdesc[402] = 0x00; |
| 745 | } |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 746 | if (drvdata->quirks & QUIRK_G752_KEYBOARD && |
| 747 | *rsize == 75 && rdesc[61] == 0x15 && rdesc[62] == 0x00) { |
| 748 | /* report is missing usage mninum and maximum */ |
| 749 | __u8 *new_rdesc; |
| 750 | size_t new_size = *rsize + sizeof(asus_g752_fixed_rdesc); |
| 751 | |
| 752 | new_rdesc = devm_kzalloc(&hdev->dev, new_size, GFP_KERNEL); |
| 753 | if (new_rdesc == NULL) |
| 754 | return rdesc; |
| 755 | |
| 756 | hid_info(hdev, "Fixing up Asus G752 keyb report descriptor\n"); |
| 757 | /* copy the valid part */ |
| 758 | memcpy(new_rdesc, rdesc, 61); |
| 759 | /* insert missing part */ |
| 760 | memcpy(new_rdesc + 61, asus_g752_fixed_rdesc, sizeof(asus_g752_fixed_rdesc)); |
| 761 | /* copy remaining data */ |
| 762 | memcpy(new_rdesc + 61 + sizeof(asus_g752_fixed_rdesc), rdesc + 61, *rsize - 61); |
| 763 | |
| 764 | *rsize = new_size; |
| 765 | rdesc = new_rdesc; |
| 766 | } |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 767 | |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 768 | return rdesc; |
| 769 | } |
| 770 | |
| 771 | static const struct hid_device_id asus_devices[] = { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 772 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Matjaz Hegedic | a93913e | 2017-03-09 00:31:13 +0100 | [diff] [blame] | 773 | USB_DEVICE_ID_ASUSTEK_I2C_KEYBOARD), I2C_KEYBOARD_QUIRKS}, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 774 | { HID_I2C_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Hans de Goede | c81760b | 2017-07-02 16:34:12 +0200 | [diff] [blame] | 775 | USB_DEVICE_ID_ASUSTEK_I2C_TOUCHPAD), I2C_TOUCHPAD_QUIRKS }, |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 776 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Mustafa Kuscu | 339ee3f | 2017-10-28 10:31:40 +0300 | [diff] [blame] | 777 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD1), QUIRK_USE_KBD_BACKLIGHT }, |
Chris Chiu | 1caccc2 | 2017-03-01 15:48:51 -0600 | [diff] [blame] | 778 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 779 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD2), QUIRK_USE_KBD_BACKLIGHT }, |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 780 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Maxime Bellengé | 832e1ee | 2017-09-07 21:17:28 +0200 | [diff] [blame] | 781 | USB_DEVICE_ID_ASUSTEK_ROG_KEYBOARD3), QUIRK_G752_KEYBOARD }, |
| 782 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
Hans de Goede | 762f948 | 2017-11-26 16:40:10 +0100 | [diff] [blame] | 783 | USB_DEVICE_ID_ASUSTEK_T100TA_KEYBOARD), |
| 784 | QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES }, |
| 785 | { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, |
| 786 | USB_DEVICE_ID_ASUSTEK_T100TAF_KEYBOARD), |
Hans de Goede | 76dd1fb | 2017-05-15 09:31:41 +0200 | [diff] [blame] | 787 | QUIRK_T100_KEYBOARD | QUIRK_NO_CONSUMER_USAGES }, |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 788 | { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_ASUS_AK1D) }, |
Daniel Drake | 38b2d78 | 2017-06-05 14:58:57 -0600 | [diff] [blame] | 789 | { HID_USB_DEVICE(USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_ASUS_MD_5110) }, |
Daniel Drake | 5be9180 | 2017-06-05 14:58:56 -0600 | [diff] [blame] | 790 | { HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_ASUS_MD_5112) }, |
Hans de Goede | 5703e52 | 2017-07-02 16:34:15 +0200 | [diff] [blame] | 791 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ASUSTEK, |
| 792 | USB_DEVICE_ID_ASUSTEK_T100CHI_KEYBOARD), QUIRK_T100CHI }, |
| 793 | |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 794 | { } |
| 795 | }; |
| 796 | MODULE_DEVICE_TABLE(hid, asus_devices); |
| 797 | |
| 798 | static struct hid_driver asus_driver = { |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 799 | .name = "asus", |
| 800 | .id_table = asus_devices, |
| 801 | .report_fixup = asus_report_fixup, |
| 802 | .probe = asus_probe, |
Carlo Caione | af22a61 | 2017-04-06 12:18:17 +0200 | [diff] [blame] | 803 | .remove = asus_remove, |
Brendan McGrath | 9ce12d8 | 2016-11-29 18:59:25 +1100 | [diff] [blame] | 804 | .input_mapping = asus_input_mapping, |
| 805 | .input_configured = asus_input_configured, |
| 806 | #ifdef CONFIG_PM |
| 807 | .reset_resume = asus_reset_resume, |
| 808 | #endif |
| 809 | .raw_event = asus_raw_event |
Yusuke Fujimaki | eeb01a5 | 2016-03-21 16:18:42 +0900 | [diff] [blame] | 810 | }; |
| 811 | module_hid_driver(asus_driver); |
| 812 | |
| 813 | MODULE_LICENSE("GPL"); |