Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 2 | /* |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 3 | * HID driver for Lenovo: |
| 4 | * - ThinkPad USB Keyboard with TrackPoint (tpkbd) |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 5 | * - ThinkPad Compact Bluetooth Keyboard with TrackPoint (cptkbd) |
| 6 | * - ThinkPad Compact USB Keyboard with TrackPoint (cptkbd) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 7 | * |
| 8 | * Copyright (c) 2012 Bernhard Seibold |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 9 | * Copyright (c) 2014 Jamie Lentin <jm@lentin.co.uk> |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 10 | * |
| 11 | * Linux IBM/Lenovo Scrollpoint mouse driver: |
| 12 | * - IBM Scrollpoint III |
| 13 | * - IBM Scrollpoint Pro |
| 14 | * - IBM Scrollpoint Optical |
| 15 | * - IBM Scrollpoint Optical 800dpi |
| 16 | * - IBM Scrollpoint Optical 800dpi Pro |
| 17 | * - Lenovo Scrollpoint Optical |
| 18 | * |
| 19 | * Copyright (c) 2012 Peter De Wachter <pdewacht@gmail.com> |
| 20 | * Copyright (c) 2018 Peter Ganzhorn <peter.ganzhorn@gmail.com> |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/sysfs.h> |
| 28 | #include <linux/device.h> |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 29 | #include <linux/hid.h> |
| 30 | #include <linux/input.h> |
| 31 | #include <linux/leds.h> |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 32 | #include <linux/workqueue.h> |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 33 | |
| 34 | #include "hid-ids.h" |
| 35 | |
Hans de Goede | 6171032 | 2021-04-04 10:04:29 +0200 | [diff] [blame] | 36 | /* Userspace expects F20 for mic-mute KEY_MICMUTE does not work */ |
| 37 | #define LENOVO_KEY_MICMUTE KEY_F20 |
| 38 | |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 39 | struct lenovo_drvdata { |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 40 | u8 led_report[3]; /* Must be first for proper alignment */ |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 41 | int led_state; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 42 | struct mutex led_report_mutex; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 43 | struct led_classdev led_mute; |
| 44 | struct led_classdev led_micmute; |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 45 | struct work_struct fn_lock_sync_work; |
| 46 | struct hid_device *hdev; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 47 | int press_to_select; |
| 48 | int dragging; |
| 49 | int release_to_select; |
| 50 | int select_right; |
| 51 | int sensitivity; |
| 52 | int press_speed; |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 53 | u8 middlebutton_state; /* 0:Up, 1:Down (undecided), 2:Scrolling */ |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 54 | bool fn_lock; |
| 55 | }; |
| 56 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 57 | #define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c)) |
| 58 | |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 59 | #define TP10UBKBD_LED_OUTPUT_REPORT 9 |
| 60 | |
| 61 | #define TP10UBKBD_FN_LOCK_LED 0x54 |
| 62 | #define TP10UBKBD_MUTE_LED 0x64 |
| 63 | #define TP10UBKBD_MICMUTE_LED 0x74 |
| 64 | |
| 65 | #define TP10UBKBD_LED_OFF 1 |
| 66 | #define TP10UBKBD_LED_ON 2 |
| 67 | |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 68 | static int lenovo_led_set_tp10ubkbd(struct hid_device *hdev, u8 led_code, |
| 69 | enum led_brightness value) |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 70 | { |
| 71 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
| 72 | int ret; |
| 73 | |
| 74 | mutex_lock(&data->led_report_mutex); |
| 75 | |
| 76 | data->led_report[0] = TP10UBKBD_LED_OUTPUT_REPORT; |
| 77 | data->led_report[1] = led_code; |
| 78 | data->led_report[2] = value ? TP10UBKBD_LED_ON : TP10UBKBD_LED_OFF; |
| 79 | ret = hid_hw_raw_request(hdev, data->led_report[0], data->led_report, 3, |
| 80 | HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 81 | if (ret != 3) { |
| 82 | if (ret != -ENODEV) |
| 83 | hid_err(hdev, "Set LED output report error: %d\n", ret); |
| 84 | |
| 85 | ret = ret < 0 ? ret : -EIO; |
| 86 | } else { |
| 87 | ret = 0; |
| 88 | } |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 89 | |
| 90 | mutex_unlock(&data->led_report_mutex); |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 91 | |
| 92 | return ret; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 95 | static void lenovo_tp10ubkbd_sync_fn_lock(struct work_struct *work) |
| 96 | { |
| 97 | struct lenovo_drvdata *data = |
| 98 | container_of(work, struct lenovo_drvdata, fn_lock_sync_work); |
| 99 | |
| 100 | lenovo_led_set_tp10ubkbd(data->hdev, TP10UBKBD_FN_LOCK_LED, |
| 101 | data->fn_lock); |
| 102 | } |
| 103 | |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 104 | static const __u8 lenovo_pro_dock_need_fixup_collection[] = { |
| 105 | 0x05, 0x88, /* Usage Page (Vendor Usage Page 0x88) */ |
| 106 | 0x09, 0x01, /* Usage (Vendor Usage 0x01) */ |
| 107 | 0xa1, 0x01, /* Collection (Application) */ |
| 108 | 0x85, 0x04, /* Report ID (4) */ |
| 109 | 0x19, 0x00, /* Usage Minimum (0) */ |
| 110 | 0x2a, 0xff, 0xff, /* Usage Maximum (65535) */ |
| 111 | }; |
| 112 | |
| 113 | static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 114 | unsigned int *rsize) |
| 115 | { |
| 116 | switch (hdev->product) { |
| 117 | case USB_DEVICE_ID_LENOVO_TPPRODOCK: |
| 118 | /* the fixups that need to be done: |
| 119 | * - get a reasonable usage max for the vendor collection |
| 120 | * 0x8801 from the report ID 4 |
| 121 | */ |
| 122 | if (*rsize >= 153 && |
| 123 | memcmp(&rdesc[140], lenovo_pro_dock_need_fixup_collection, |
| 124 | sizeof(lenovo_pro_dock_need_fixup_collection)) == 0) { |
| 125 | rdesc[151] = 0x01; |
| 126 | rdesc[152] = 0x00; |
| 127 | } |
| 128 | break; |
| 129 | } |
| 130 | return rdesc; |
| 131 | } |
| 132 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 133 | static int lenovo_input_mapping_tpkbd(struct hid_device *hdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 134 | struct hid_input *hi, struct hid_field *field, |
| 135 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 136 | { |
Benjamin Tissoires | 0c52183 | 2013-09-11 22:12:24 +0200 | [diff] [blame] | 137 | if (usage->hid == (HID_UP_BUTTON | 0x0010)) { |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 138 | /* This sub-device contains trackpoint, mark it */ |
Benjamin Tissoires | 0c52183 | 2013-09-11 22:12:24 +0200 | [diff] [blame] | 139 | hid_set_drvdata(hdev, (void *)1); |
Hans de Goede | 6171032 | 2021-04-04 10:04:29 +0200 | [diff] [blame] | 140 | map_key_clear(LENOVO_KEY_MICMUTE); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 141 | return 1; |
| 142 | } |
| 143 | return 0; |
| 144 | } |
| 145 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 146 | static int lenovo_input_mapping_cptkbd(struct hid_device *hdev, |
| 147 | struct hid_input *hi, struct hid_field *field, |
| 148 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 149 | { |
| 150 | /* HID_UP_LNVENDOR = USB, HID_UP_MSVENDOR = BT */ |
| 151 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR || |
| 152 | (usage->hid & HID_USAGE_PAGE) == HID_UP_LNVENDOR) { |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 153 | switch (usage->hid & HID_USAGE) { |
| 154 | case 0x00f1: /* Fn-F4: Mic mute */ |
Hans de Goede | 6171032 | 2021-04-04 10:04:29 +0200 | [diff] [blame] | 155 | map_key_clear(LENOVO_KEY_MICMUTE); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 156 | return 1; |
| 157 | case 0x00f2: /* Fn-F5: Brightness down */ |
| 158 | map_key_clear(KEY_BRIGHTNESSDOWN); |
| 159 | return 1; |
| 160 | case 0x00f3: /* Fn-F6: Brightness up */ |
| 161 | map_key_clear(KEY_BRIGHTNESSUP); |
| 162 | return 1; |
| 163 | case 0x00f4: /* Fn-F7: External display (projector) */ |
| 164 | map_key_clear(KEY_SWITCHVIDEOMODE); |
| 165 | return 1; |
| 166 | case 0x00f5: /* Fn-F8: Wireless */ |
| 167 | map_key_clear(KEY_WLAN); |
| 168 | return 1; |
| 169 | case 0x00f6: /* Fn-F9: Control panel */ |
| 170 | map_key_clear(KEY_CONFIG); |
| 171 | return 1; |
| 172 | case 0x00f8: /* Fn-F11: View open applications (3 boxes) */ |
| 173 | map_key_clear(KEY_SCALE); |
| 174 | return 1; |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 175 | case 0x00f9: /* Fn-F12: Open My computer (6 boxes) USB-only */ |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 176 | /* NB: This mapping is invented in raw_event below */ |
| 177 | map_key_clear(KEY_FILE); |
| 178 | return 1; |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 179 | case 0x00fa: /* Fn-Esc: Fn-lock toggle */ |
| 180 | map_key_clear(KEY_FN_ESC); |
| 181 | return 1; |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 182 | case 0x00fb: /* Middle mouse button (in native mode) */ |
| 183 | map_key_clear(BTN_MIDDLE); |
| 184 | return 1; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /* Compatibility middle/wheel mappings should be ignored */ |
| 189 | if (usage->hid == HID_GD_WHEEL) |
| 190 | return -1; |
| 191 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON && |
| 192 | (usage->hid & HID_USAGE) == 0x003) |
| 193 | return -1; |
| 194 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER && |
| 195 | (usage->hid & HID_USAGE) == 0x238) |
| 196 | return -1; |
| 197 | |
| 198 | /* Map wheel emulation reports: 0xffa1 = USB, 0xff10 = BT */ |
| 199 | if ((usage->hid & HID_USAGE_PAGE) == 0xff100000 || |
| 200 | (usage->hid & HID_USAGE_PAGE) == 0xffa10000) { |
| 201 | field->flags |= HID_MAIN_ITEM_RELATIVE | HID_MAIN_ITEM_VARIABLE; |
| 202 | field->logical_minimum = -127; |
| 203 | field->logical_maximum = 127; |
| 204 | |
| 205 | switch (usage->hid & HID_USAGE) { |
| 206 | case 0x0000: |
Jamie Lentin | 7f65068 | 2015-08-11 22:40:50 +0100 | [diff] [blame] | 207 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 208 | return 1; |
| 209 | case 0x0001: |
Jamie Lentin | 7f65068 | 2015-08-11 22:40:50 +0100 | [diff] [blame] | 210 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_WHEEL); |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 211 | return 1; |
| 212 | default: |
| 213 | return -1; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 220 | static int lenovo_input_mapping_scrollpoint(struct hid_device *hdev, |
| 221 | struct hid_input *hi, struct hid_field *field, |
| 222 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 223 | { |
| 224 | if (usage->hid == HID_GD_Z) { |
| 225 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
| 226 | return 1; |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 231 | static int lenovo_input_mapping_tp10_ultrabook_kbd(struct hid_device *hdev, |
| 232 | struct hid_input *hi, struct hid_field *field, |
| 233 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 234 | { |
| 235 | /* |
| 236 | * The ThinkPad 10 Ultrabook Keyboard uses 0x000c0001 usage for |
| 237 | * a bunch of keys which have no standard consumer page code. |
| 238 | */ |
| 239 | if (usage->hid == 0x000c0001) { |
| 240 | switch (usage->usage_index) { |
| 241 | case 8: /* Fn-Esc: Fn-lock toggle */ |
| 242 | map_key_clear(KEY_FN_ESC); |
| 243 | return 1; |
| 244 | case 9: /* Fn-F4: Mic mute */ |
Hans de Goede | 6171032 | 2021-04-04 10:04:29 +0200 | [diff] [blame] | 245 | map_key_clear(LENOVO_KEY_MICMUTE); |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 246 | return 1; |
| 247 | case 10: /* Fn-F7: Control panel */ |
| 248 | map_key_clear(KEY_CONFIG); |
| 249 | return 1; |
| 250 | case 11: /* Fn-F8: Search (magnifier glass) */ |
| 251 | map_key_clear(KEY_SEARCH); |
| 252 | return 1; |
| 253 | case 12: /* Fn-F10: Open My computer (6 boxes) */ |
| 254 | map_key_clear(KEY_FILE); |
| 255 | return 1; |
| 256 | } |
| 257 | } |
| 258 | |
Hans de Goede | 4942942 | 2020-07-04 22:10:59 +0200 | [diff] [blame] | 259 | /* |
| 260 | * The Ultrabook Keyboard sends a spurious F23 key-press when resuming |
| 261 | * from suspend and it does not actually have a F23 key, ignore it. |
| 262 | */ |
| 263 | if (usage->hid == 0x00070072) |
| 264 | return -1; |
| 265 | |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 269 | static int lenovo_input_mapping_x1_tab_kbd(struct hid_device *hdev, |
| 270 | struct hid_input *hi, struct hid_field *field, |
| 271 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 272 | { |
| 273 | /* |
| 274 | * The ThinkPad X1 Tablet Thin Keyboard uses 0x000c0001 usage for |
| 275 | * a bunch of keys which have no standard consumer page code. |
| 276 | */ |
| 277 | if (usage->hid == 0x000c0001) { |
| 278 | switch (usage->usage_index) { |
| 279 | case 0: /* Fn-F10: Enable/disable bluetooth */ |
| 280 | map_key_clear(KEY_BLUETOOTH); |
| 281 | return 1; |
| 282 | case 1: /* Fn-F11: Keyboard settings */ |
| 283 | map_key_clear(KEY_KEYBOARD); |
| 284 | return 1; |
| 285 | case 2: /* Fn-F12: User function / Cortana */ |
| 286 | map_key_clear(KEY_MACRO1); |
| 287 | return 1; |
| 288 | case 3: /* Fn-PrtSc: Snipping tool */ |
| 289 | map_key_clear(KEY_SELECTIVE_SCREENSHOT); |
| 290 | return 1; |
| 291 | case 8: /* Fn-Esc: Fn-lock toggle */ |
| 292 | map_key_clear(KEY_FN_ESC); |
| 293 | return 1; |
| 294 | case 9: /* Fn-F4: Mute/unmute microphone */ |
| 295 | map_key_clear(KEY_MICMUTE); |
| 296 | return 1; |
| 297 | case 10: /* Fn-F9: Settings */ |
| 298 | map_key_clear(KEY_CONFIG); |
| 299 | return 1; |
| 300 | case 13: /* Fn-F7: Manage external displays */ |
| 301 | map_key_clear(KEY_SWITCHVIDEOMODE); |
| 302 | return 1; |
| 303 | case 14: /* Fn-F8: Enable/disable wifi */ |
| 304 | map_key_clear(KEY_WLAN); |
| 305 | return 1; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (usage->hid == (HID_UP_KEYBOARD | 0x009a)) { |
| 310 | map_key_clear(KEY_SYSRQ); |
| 311 | return 1; |
| 312 | } |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 317 | static int lenovo_input_mapping(struct hid_device *hdev, |
| 318 | struct hid_input *hi, struct hid_field *field, |
| 319 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 320 | { |
| 321 | switch (hdev->product) { |
| 322 | case USB_DEVICE_ID_LENOVO_TPKBD: |
| 323 | return lenovo_input_mapping_tpkbd(hdev, hi, field, |
| 324 | usage, bit, max); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 325 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 326 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 327 | return lenovo_input_mapping_cptkbd(hdev, hi, field, |
| 328 | usage, bit, max); |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 329 | case USB_DEVICE_ID_IBM_SCROLLPOINT_III: |
| 330 | case USB_DEVICE_ID_IBM_SCROLLPOINT_PRO: |
| 331 | case USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL: |
| 332 | case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL: |
| 333 | case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO: |
| 334 | case USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL: |
| 335 | return lenovo_input_mapping_scrollpoint(hdev, hi, field, |
| 336 | usage, bit, max); |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 337 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
| 338 | return lenovo_input_mapping_tp10_ultrabook_kbd(hdev, hi, field, |
| 339 | usage, bit, max); |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 340 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
| 341 | return lenovo_input_mapping_x1_tab_kbd(hdev, hi, field, usage, bit, max); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 342 | default: |
| 343 | return 0; |
| 344 | } |
| 345 | } |
| 346 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 347 | #undef map_key_clear |
| 348 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 349 | /* Send a config command to the keyboard */ |
| 350 | static int lenovo_send_cmd_cptkbd(struct hid_device *hdev, |
| 351 | unsigned char byte2, unsigned char byte3) |
| 352 | { |
| 353 | int ret; |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 354 | unsigned char *buf; |
| 355 | |
| 356 | buf = kzalloc(3, GFP_KERNEL); |
| 357 | if (!buf) |
| 358 | return -ENOMEM; |
| 359 | |
| 360 | buf[0] = 0x18; |
| 361 | buf[1] = byte2; |
| 362 | buf[2] = byte3; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 363 | |
| 364 | switch (hdev->product) { |
| 365 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 366 | ret = hid_hw_raw_request(hdev, 0x13, buf, 3, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 367 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 368 | break; |
| 369 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 370 | ret = hid_hw_output_report(hdev, buf, 3); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 371 | break; |
| 372 | default: |
| 373 | ret = -EINVAL; |
| 374 | break; |
| 375 | } |
| 376 | |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 377 | kfree(buf); |
| 378 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 379 | return ret < 0 ? ret : 0; /* BT returns 0, USB returns sizeof(buf) */ |
| 380 | } |
| 381 | |
| 382 | static void lenovo_features_set_cptkbd(struct hid_device *hdev) |
| 383 | { |
| 384 | int ret; |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 385 | struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 386 | |
| 387 | ret = lenovo_send_cmd_cptkbd(hdev, 0x05, cptkbd_data->fn_lock); |
| 388 | if (ret) |
| 389 | hid_err(hdev, "Fn-lock setting failed: %d\n", ret); |
Jamie Lentin | dbfebb4 | 2015-08-11 22:40:51 +0100 | [diff] [blame] | 390 | |
| 391 | ret = lenovo_send_cmd_cptkbd(hdev, 0x02, cptkbd_data->sensitivity); |
| 392 | if (ret) |
| 393 | hid_err(hdev, "Sensitivity setting failed: %d\n", ret); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 396 | static ssize_t attr_fn_lock_show(struct device *dev, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 397 | struct device_attribute *attr, |
| 398 | char *buf) |
| 399 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 400 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 401 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 402 | |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 403 | return snprintf(buf, PAGE_SIZE, "%u\n", data->fn_lock); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 406 | static ssize_t attr_fn_lock_store(struct device *dev, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 407 | struct device_attribute *attr, |
| 408 | const char *buf, |
| 409 | size_t count) |
| 410 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 411 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 412 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 413 | int value, ret; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 414 | |
| 415 | if (kstrtoint(buf, 10, &value)) |
| 416 | return -EINVAL; |
| 417 | if (value < 0 || value > 1) |
| 418 | return -EINVAL; |
| 419 | |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 420 | data->fn_lock = !!value; |
| 421 | |
| 422 | switch (hdev->product) { |
| 423 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 424 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 425 | lenovo_features_set_cptkbd(hdev); |
| 426 | break; |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 427 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 428 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 429 | ret = lenovo_led_set_tp10ubkbd(hdev, TP10UBKBD_FN_LOCK_LED, value); |
| 430 | if (ret) |
| 431 | return ret; |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 432 | break; |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 433 | } |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 434 | |
| 435 | return count; |
| 436 | } |
| 437 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 438 | static ssize_t attr_sensitivity_show_cptkbd(struct device *dev, |
| 439 | struct device_attribute *attr, |
| 440 | char *buf) |
| 441 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 442 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 443 | struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 444 | |
| 445 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 446 | cptkbd_data->sensitivity); |
| 447 | } |
| 448 | |
| 449 | static ssize_t attr_sensitivity_store_cptkbd(struct device *dev, |
| 450 | struct device_attribute *attr, |
| 451 | const char *buf, |
| 452 | size_t count) |
| 453 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 454 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 455 | struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 456 | int value; |
| 457 | |
| 458 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 459 | return -EINVAL; |
| 460 | |
| 461 | cptkbd_data->sensitivity = value; |
| 462 | lenovo_features_set_cptkbd(hdev); |
| 463 | |
| 464 | return count; |
| 465 | } |
| 466 | |
| 467 | |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 468 | static struct device_attribute dev_attr_fn_lock = |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 469 | __ATTR(fn_lock, S_IWUSR | S_IRUGO, |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 470 | attr_fn_lock_show, |
| 471 | attr_fn_lock_store); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 472 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 473 | static struct device_attribute dev_attr_sensitivity_cptkbd = |
| 474 | __ATTR(sensitivity, S_IWUSR | S_IRUGO, |
| 475 | attr_sensitivity_show_cptkbd, |
| 476 | attr_sensitivity_store_cptkbd); |
| 477 | |
| 478 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 479 | static struct attribute *lenovo_attributes_cptkbd[] = { |
Hans de Goede | ef550c5 | 2020-07-04 15:27:40 +0200 | [diff] [blame] | 480 | &dev_attr_fn_lock.attr, |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 481 | &dev_attr_sensitivity_cptkbd.attr, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 482 | NULL |
| 483 | }; |
| 484 | |
| 485 | static const struct attribute_group lenovo_attr_group_cptkbd = { |
| 486 | .attrs = lenovo_attributes_cptkbd, |
| 487 | }; |
| 488 | |
| 489 | static int lenovo_raw_event(struct hid_device *hdev, |
| 490 | struct hid_report *report, u8 *data, int size) |
| 491 | { |
| 492 | /* |
| 493 | * Compact USB keyboard's Fn-F12 report holds down many other keys, and |
| 494 | * its own key is outside the usage page range. Remove extra |
| 495 | * keypresses and remap to inside usage page. |
| 496 | */ |
| 497 | if (unlikely(hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD |
| 498 | && size == 3 |
| 499 | && data[0] == 0x15 |
| 500 | && data[1] == 0x94 |
| 501 | && data[2] == 0x01)) { |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 502 | data[1] = 0x00; |
| 503 | data[2] = 0x01; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 509 | static int lenovo_event_tp10ubkbd(struct hid_device *hdev, |
| 510 | struct hid_field *field, struct hid_usage *usage, __s32 value) |
| 511 | { |
| 512 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
| 513 | |
| 514 | if (usage->type == EV_KEY && usage->code == KEY_FN_ESC && value == 1) { |
| 515 | /* |
| 516 | * The user has toggled the Fn-lock state. Toggle our own |
| 517 | * cached value of it and sync our value to the keyboard to |
| 518 | * ensure things are in sync (the sycning should be a no-op). |
| 519 | */ |
| 520 | data->fn_lock = !data->fn_lock; |
| 521 | schedule_work(&data->fn_lock_sync_work); |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 527 | static int lenovo_event_cptkbd(struct hid_device *hdev, |
| 528 | struct hid_field *field, struct hid_usage *usage, __s32 value) |
| 529 | { |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 530 | struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 531 | |
| 532 | /* "wheel" scroll events */ |
| 533 | if (usage->type == EV_REL && (usage->code == REL_WHEEL || |
| 534 | usage->code == REL_HWHEEL)) { |
| 535 | /* Scroll events disable middle-click event */ |
| 536 | cptkbd_data->middlebutton_state = 2; |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | /* Middle click events */ |
| 541 | if (usage->type == EV_KEY && usage->code == BTN_MIDDLE) { |
| 542 | if (value == 1) { |
| 543 | cptkbd_data->middlebutton_state = 1; |
| 544 | } else if (value == 0) { |
| 545 | if (cptkbd_data->middlebutton_state == 1) { |
| 546 | /* No scrolling inbetween, send middle-click */ |
| 547 | input_event(field->hidinput->input, |
| 548 | EV_KEY, BTN_MIDDLE, 1); |
| 549 | input_sync(field->hidinput->input); |
| 550 | input_event(field->hidinput->input, |
| 551 | EV_KEY, BTN_MIDDLE, 0); |
| 552 | input_sync(field->hidinput->input); |
| 553 | } |
| 554 | cptkbd_data->middlebutton_state = 0; |
| 555 | } |
| 556 | return 1; |
| 557 | } |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static int lenovo_event(struct hid_device *hdev, struct hid_field *field, |
| 563 | struct hid_usage *usage, __s32 value) |
| 564 | { |
Hans de Goede | 34348a8 | 2021-04-04 10:04:26 +0200 | [diff] [blame] | 565 | if (!hid_get_drvdata(hdev)) |
| 566 | return 0; |
| 567 | |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 568 | switch (hdev->product) { |
| 569 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 570 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 571 | return lenovo_event_cptkbd(hdev, field, usage, value); |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 572 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 573 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 574 | return lenovo_event_tp10ubkbd(hdev, field, usage, value); |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 575 | default: |
| 576 | return 0; |
| 577 | } |
| 578 | } |
| 579 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 580 | static int lenovo_features_set_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 581 | { |
| 582 | struct hid_report *report; |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 583 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 584 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 585 | report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4]; |
| 586 | |
| 587 | report->field[0]->value[0] = data_pointer->press_to_select ? 0x01 : 0x02; |
| 588 | report->field[0]->value[0] |= data_pointer->dragging ? 0x04 : 0x08; |
| 589 | report->field[0]->value[0] |= data_pointer->release_to_select ? 0x10 : 0x20; |
| 590 | report->field[0]->value[0] |= data_pointer->select_right ? 0x80 : 0x40; |
| 591 | report->field[1]->value[0] = 0x03; // unknown setting, imitate windows driver |
| 592 | report->field[2]->value[0] = data_pointer->sensitivity; |
| 593 | report->field[3]->value[0] = data_pointer->press_speed; |
| 594 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 595 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 596 | return 0; |
| 597 | } |
| 598 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 599 | static ssize_t attr_press_to_select_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 600 | struct device_attribute *attr, |
| 601 | char *buf) |
| 602 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 603 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 604 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 605 | |
| 606 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select); |
| 607 | } |
| 608 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 609 | static ssize_t attr_press_to_select_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 610 | struct device_attribute *attr, |
| 611 | const char *buf, |
| 612 | size_t count) |
| 613 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 614 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 615 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 616 | int value; |
| 617 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 618 | if (kstrtoint(buf, 10, &value)) |
| 619 | return -EINVAL; |
| 620 | if (value < 0 || value > 1) |
| 621 | return -EINVAL; |
| 622 | |
| 623 | data_pointer->press_to_select = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 624 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 625 | |
| 626 | return count; |
| 627 | } |
| 628 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 629 | static ssize_t attr_dragging_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 630 | struct device_attribute *attr, |
| 631 | char *buf) |
| 632 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 633 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 634 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 635 | |
| 636 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging); |
| 637 | } |
| 638 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 639 | static ssize_t attr_dragging_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 640 | struct device_attribute *attr, |
| 641 | const char *buf, |
| 642 | size_t count) |
| 643 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 644 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 645 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 646 | int value; |
| 647 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 648 | if (kstrtoint(buf, 10, &value)) |
| 649 | return -EINVAL; |
| 650 | if (value < 0 || value > 1) |
| 651 | return -EINVAL; |
| 652 | |
| 653 | data_pointer->dragging = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 654 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 655 | |
| 656 | return count; |
| 657 | } |
| 658 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 659 | static ssize_t attr_release_to_select_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 660 | struct device_attribute *attr, |
| 661 | char *buf) |
| 662 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 663 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 664 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 665 | |
| 666 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select); |
| 667 | } |
| 668 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 669 | static ssize_t attr_release_to_select_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 670 | struct device_attribute *attr, |
| 671 | const char *buf, |
| 672 | size_t count) |
| 673 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 674 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 675 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 676 | int value; |
| 677 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 678 | if (kstrtoint(buf, 10, &value)) |
| 679 | return -EINVAL; |
| 680 | if (value < 0 || value > 1) |
| 681 | return -EINVAL; |
| 682 | |
| 683 | data_pointer->release_to_select = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 684 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 685 | |
| 686 | return count; |
| 687 | } |
| 688 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 689 | static ssize_t attr_select_right_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 690 | struct device_attribute *attr, |
| 691 | char *buf) |
| 692 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 693 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 694 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 695 | |
| 696 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right); |
| 697 | } |
| 698 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 699 | static ssize_t attr_select_right_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 700 | struct device_attribute *attr, |
| 701 | const char *buf, |
| 702 | size_t count) |
| 703 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 704 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 705 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 706 | int value; |
| 707 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 708 | if (kstrtoint(buf, 10, &value)) |
| 709 | return -EINVAL; |
| 710 | if (value < 0 || value > 1) |
| 711 | return -EINVAL; |
| 712 | |
| 713 | data_pointer->select_right = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 714 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 715 | |
| 716 | return count; |
| 717 | } |
| 718 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 719 | static ssize_t attr_sensitivity_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 720 | struct device_attribute *attr, |
| 721 | char *buf) |
| 722 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 723 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 724 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 725 | |
| 726 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 727 | data_pointer->sensitivity); |
| 728 | } |
| 729 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 730 | static ssize_t attr_sensitivity_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 731 | struct device_attribute *attr, |
| 732 | const char *buf, |
| 733 | size_t count) |
| 734 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 735 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 736 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 737 | int value; |
| 738 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 739 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 740 | return -EINVAL; |
| 741 | |
| 742 | data_pointer->sensitivity = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 743 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 744 | |
| 745 | return count; |
| 746 | } |
| 747 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 748 | static ssize_t attr_press_speed_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 749 | struct device_attribute *attr, |
| 750 | char *buf) |
| 751 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 752 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 753 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 754 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 755 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 756 | data_pointer->press_speed); |
| 757 | } |
| 758 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 759 | static ssize_t attr_press_speed_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 760 | struct device_attribute *attr, |
| 761 | const char *buf, |
| 762 | size_t count) |
| 763 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 764 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 765 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 766 | int value; |
| 767 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 768 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 769 | return -EINVAL; |
| 770 | |
| 771 | data_pointer->press_speed = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 772 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 773 | |
| 774 | return count; |
| 775 | } |
| 776 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 777 | static struct device_attribute dev_attr_press_to_select_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 778 | __ATTR(press_to_select, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 779 | attr_press_to_select_show_tpkbd, |
| 780 | attr_press_to_select_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 781 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 782 | static struct device_attribute dev_attr_dragging_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 783 | __ATTR(dragging, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 784 | attr_dragging_show_tpkbd, |
| 785 | attr_dragging_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 786 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 787 | static struct device_attribute dev_attr_release_to_select_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 788 | __ATTR(release_to_select, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 789 | attr_release_to_select_show_tpkbd, |
| 790 | attr_release_to_select_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 791 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 792 | static struct device_attribute dev_attr_select_right_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 793 | __ATTR(select_right, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 794 | attr_select_right_show_tpkbd, |
| 795 | attr_select_right_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 796 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 797 | static struct device_attribute dev_attr_sensitivity_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 798 | __ATTR(sensitivity, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 799 | attr_sensitivity_show_tpkbd, |
| 800 | attr_sensitivity_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 801 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 802 | static struct device_attribute dev_attr_press_speed_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 803 | __ATTR(press_speed, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 804 | attr_press_speed_show_tpkbd, |
| 805 | attr_press_speed_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 806 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 807 | static struct attribute *lenovo_attributes_tpkbd[] = { |
| 808 | &dev_attr_press_to_select_tpkbd.attr, |
| 809 | &dev_attr_dragging_tpkbd.attr, |
| 810 | &dev_attr_release_to_select_tpkbd.attr, |
| 811 | &dev_attr_select_right_tpkbd.attr, |
| 812 | &dev_attr_sensitivity_tpkbd.attr, |
| 813 | &dev_attr_press_speed_tpkbd.attr, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 814 | NULL |
| 815 | }; |
| 816 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 817 | static const struct attribute_group lenovo_attr_group_tpkbd = { |
| 818 | .attrs = lenovo_attributes_tpkbd, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 819 | }; |
| 820 | |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 821 | static void lenovo_led_set_tpkbd(struct hid_device *hdev) |
| 822 | { |
| 823 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
| 824 | struct hid_report *report; |
| 825 | |
| 826 | report = hdev->report_enum[HID_OUTPUT_REPORT].report_id_hash[3]; |
| 827 | report->field[0]->value[0] = (data_pointer->led_state >> 0) & 1; |
| 828 | report->field[0]->value[1] = (data_pointer->led_state >> 1) & 1; |
| 829 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
| 830 | } |
| 831 | |
Hans de Goede | bbf6264 | 2021-04-04 10:04:24 +0200 | [diff] [blame] | 832 | static int lenovo_led_brightness_set(struct led_classdev *led_cdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 833 | enum led_brightness value) |
| 834 | { |
Axel Lin | 832fbea | 2012-09-13 14:12:08 +0800 | [diff] [blame] | 835 | struct device *dev = led_cdev->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 836 | struct hid_device *hdev = to_hid_device(dev); |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 837 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 838 | u8 tp10ubkbd_led[] = { TP10UBKBD_MUTE_LED, TP10UBKBD_MICMUTE_LED }; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 839 | int led_nr = 0; |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 840 | int ret = 0; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 841 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 842 | if (led_cdev == &data_pointer->led_micmute) |
| 843 | led_nr = 1; |
| 844 | |
| 845 | if (value == LED_OFF) |
| 846 | data_pointer->led_state &= ~(1 << led_nr); |
| 847 | else |
| 848 | data_pointer->led_state |= 1 << led_nr; |
| 849 | |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 850 | switch (hdev->product) { |
| 851 | case USB_DEVICE_ID_LENOVO_TPKBD: |
| 852 | lenovo_led_set_tpkbd(hdev); |
| 853 | break; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 854 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 855 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 856 | ret = lenovo_led_set_tp10ubkbd(hdev, tp10ubkbd_led[led_nr], value); |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 857 | break; |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 858 | } |
Hans de Goede | bbf6264 | 2021-04-04 10:04:24 +0200 | [diff] [blame] | 859 | |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 860 | return ret; |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | static int lenovo_register_leds(struct hid_device *hdev) |
| 864 | { |
| 865 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
| 866 | size_t name_sz = strlen(dev_name(&hdev->dev)) + 16; |
| 867 | char *name_mute, *name_micm; |
| 868 | int ret; |
| 869 | |
| 870 | name_mute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL); |
| 871 | name_micm = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL); |
| 872 | if (name_mute == NULL || name_micm == NULL) { |
| 873 | hid_err(hdev, "Could not allocate memory for led data\n"); |
| 874 | return -ENOMEM; |
| 875 | } |
| 876 | snprintf(name_mute, name_sz, "%s:amber:mute", dev_name(&hdev->dev)); |
| 877 | snprintf(name_micm, name_sz, "%s:amber:micmute", dev_name(&hdev->dev)); |
| 878 | |
| 879 | data->led_mute.name = name_mute; |
Hans de Goede | e2da5ff | 2021-04-04 10:04:30 +0200 | [diff] [blame] | 880 | data->led_mute.default_trigger = "audio-mute"; |
Hans de Goede | bbf6264 | 2021-04-04 10:04:24 +0200 | [diff] [blame] | 881 | data->led_mute.brightness_set_blocking = lenovo_led_brightness_set; |
Hans de Goede | 8744eee | 2021-04-04 10:04:28 +0200 | [diff] [blame] | 882 | data->led_mute.max_brightness = 1; |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 883 | data->led_mute.flags = LED_HW_PLUGGABLE; |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 884 | data->led_mute.dev = &hdev->dev; |
| 885 | ret = led_classdev_register(&hdev->dev, &data->led_mute); |
| 886 | if (ret < 0) |
| 887 | return ret; |
| 888 | |
| 889 | data->led_micmute.name = name_micm; |
Hans de Goede | e2da5ff | 2021-04-04 10:04:30 +0200 | [diff] [blame] | 890 | data->led_micmute.default_trigger = "audio-micmute"; |
Hans de Goede | bbf6264 | 2021-04-04 10:04:24 +0200 | [diff] [blame] | 891 | data->led_micmute.brightness_set_blocking = lenovo_led_brightness_set; |
Hans de Goede | 8744eee | 2021-04-04 10:04:28 +0200 | [diff] [blame] | 892 | data->led_micmute.max_brightness = 1; |
Hans de Goede | 658d04e | 2021-04-04 10:04:25 +0200 | [diff] [blame] | 893 | data->led_micmute.flags = LED_HW_PLUGGABLE; |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 894 | data->led_micmute.dev = &hdev->dev; |
| 895 | ret = led_classdev_register(&hdev->dev, &data->led_micmute); |
| 896 | if (ret < 0) { |
| 897 | led_classdev_unregister(&data->led_mute); |
| 898 | return ret; |
| 899 | } |
| 900 | |
| 901 | return 0; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 902 | } |
| 903 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 904 | static int lenovo_probe_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 905 | { |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 906 | struct lenovo_drvdata *data_pointer; |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 907 | int i, ret; |
Kees Cook | 0a9cd0a | 2013-09-11 21:56:55 +0200 | [diff] [blame] | 908 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 909 | /* |
| 910 | * Only register extra settings against subdevice where input_mapping |
| 911 | * set drvdata to 1, i.e. the trackpoint. |
| 912 | */ |
| 913 | if (!hid_get_drvdata(hdev)) |
| 914 | return 0; |
| 915 | |
| 916 | hid_set_drvdata(hdev, NULL); |
| 917 | |
Kees Cook | 0a9cd0a | 2013-09-11 21:56:55 +0200 | [diff] [blame] | 918 | /* Validate required reports. */ |
| 919 | for (i = 0; i < 4; i++) { |
| 920 | if (!hid_validate_values(hdev, HID_FEATURE_REPORT, 4, i, 1)) |
| 921 | return -ENODEV; |
| 922 | } |
| 923 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 3, 0, 2)) |
| 924 | return -ENODEV; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 925 | |
Jamie Lentin | e0a6aad | 2014-07-26 15:42:27 +0100 | [diff] [blame] | 926 | ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd); |
| 927 | if (ret) |
| 928 | hid_warn(hdev, "Could not create sysfs group: %d\n", ret); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 929 | |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 930 | data_pointer = devm_kzalloc(&hdev->dev, |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 931 | sizeof(struct lenovo_drvdata), |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 932 | GFP_KERNEL); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 933 | if (data_pointer == NULL) { |
| 934 | hid_err(hdev, "Could not allocate memory for driver data\n"); |
Alexey Khoroshilov | b721260 | 2015-05-29 03:39:31 +0300 | [diff] [blame] | 935 | ret = -ENOMEM; |
| 936 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | // set same default values as windows driver |
| 940 | data_pointer->sensitivity = 0xa0; |
| 941 | data_pointer->press_speed = 0x38; |
| 942 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 943 | hid_set_drvdata(hdev, data_pointer); |
| 944 | |
Hans de Goede | 484921f | 2020-07-04 15:27:39 +0200 | [diff] [blame] | 945 | ret = lenovo_register_leds(hdev); |
| 946 | if (ret) |
Aditya Pakki | 6ae16df | 2018-12-24 15:39:14 -0600 | [diff] [blame] | 947 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 948 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 949 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 950 | |
| 951 | return 0; |
Alexey Khoroshilov | b721260 | 2015-05-29 03:39:31 +0300 | [diff] [blame] | 952 | err: |
| 953 | sysfs_remove_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd); |
| 954 | return ret; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 957 | static int lenovo_probe_cptkbd(struct hid_device *hdev) |
| 958 | { |
| 959 | int ret; |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 960 | struct lenovo_drvdata *cptkbd_data; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 961 | |
| 962 | /* All the custom action happens on the USBMOUSE device for USB */ |
| 963 | if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD |
| 964 | && hdev->type != HID_TYPE_USBMOUSE) { |
| 965 | hid_dbg(hdev, "Ignoring keyboard half of device\n"); |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | cptkbd_data = devm_kzalloc(&hdev->dev, |
| 970 | sizeof(*cptkbd_data), |
| 971 | GFP_KERNEL); |
| 972 | if (cptkbd_data == NULL) { |
| 973 | hid_err(hdev, "can't alloc keyboard descriptor\n"); |
| 974 | return -ENOMEM; |
| 975 | } |
| 976 | hid_set_drvdata(hdev, cptkbd_data); |
| 977 | |
| 978 | /* |
| 979 | * Tell the keyboard a driver understands it, and turn F7, F9, F11 into |
| 980 | * regular keys |
| 981 | */ |
| 982 | ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); |
| 983 | if (ret) |
| 984 | hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); |
| 985 | |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 986 | /* Switch middle button to native mode */ |
| 987 | ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); |
| 988 | if (ret) |
| 989 | hid_warn(hdev, "Failed to switch middle button: %d\n", ret); |
| 990 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 991 | /* Set keyboard settings to known state */ |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 992 | cptkbd_data->middlebutton_state = 0; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 993 | cptkbd_data->fn_lock = true; |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 994 | cptkbd_data->sensitivity = 0x05; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 995 | lenovo_features_set_cptkbd(hdev); |
| 996 | |
| 997 | ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_cptkbd); |
| 998 | if (ret) |
| 999 | hid_warn(hdev, "Could not create sysfs group: %d\n", ret); |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 1004 | static struct attribute *lenovo_attributes_tp10ubkbd[] = { |
| 1005 | &dev_attr_fn_lock.attr, |
| 1006 | NULL |
| 1007 | }; |
| 1008 | |
| 1009 | static const struct attribute_group lenovo_attr_group_tp10ubkbd = { |
| 1010 | .attrs = lenovo_attributes_tp10ubkbd, |
| 1011 | }; |
| 1012 | |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1013 | static int lenovo_probe_tp10ubkbd(struct hid_device *hdev) |
| 1014 | { |
Hans de Goede | 2d0f1c0 | 2021-04-04 10:04:31 +0200 | [diff] [blame] | 1015 | struct hid_report_enum *rep_enum; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1016 | struct lenovo_drvdata *data; |
Hans de Goede | 2d0f1c0 | 2021-04-04 10:04:31 +0200 | [diff] [blame] | 1017 | struct hid_report *rep; |
| 1018 | bool found; |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 1019 | int ret; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1020 | |
Hans de Goede | 2d0f1c0 | 2021-04-04 10:04:31 +0200 | [diff] [blame] | 1021 | /* |
| 1022 | * The LEDs and the Fn-lock functionality use output report 9, |
| 1023 | * with an application of 0xffa0001, add the LEDs on the interface |
| 1024 | * with this output report. |
| 1025 | */ |
| 1026 | found = false; |
| 1027 | rep_enum = &hdev->report_enum[HID_OUTPUT_REPORT]; |
| 1028 | list_for_each_entry(rep, &rep_enum->report_list, list) { |
| 1029 | if (rep->application == 0xffa00001) |
| 1030 | found = true; |
| 1031 | } |
| 1032 | if (!found) |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1033 | return 0; |
| 1034 | |
| 1035 | data = devm_kzalloc(&hdev->dev, sizeof(*data), GFP_KERNEL); |
| 1036 | if (!data) |
| 1037 | return -ENOMEM; |
| 1038 | |
| 1039 | mutex_init(&data->led_report_mutex); |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 1040 | INIT_WORK(&data->fn_lock_sync_work, lenovo_tp10ubkbd_sync_fn_lock); |
| 1041 | data->hdev = hdev; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1042 | |
| 1043 | hid_set_drvdata(hdev, data); |
| 1044 | |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 1045 | /* |
| 1046 | * The Thinkpad 10 ultrabook USB kbd dock's Fn-lock defaults to on. |
| 1047 | * We cannot read the state, only set it, so we force it to on here |
| 1048 | * (which should be a no-op) to make sure that our state matches the |
| 1049 | * keyboard's FN-lock state. This is the same as what Windows does. |
| 1050 | */ |
| 1051 | data->fn_lock = true; |
| 1052 | lenovo_led_set_tp10ubkbd(hdev, TP10UBKBD_FN_LOCK_LED, data->fn_lock); |
| 1053 | |
| 1054 | ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tp10ubkbd); |
| 1055 | if (ret) |
| 1056 | return ret; |
| 1057 | |
| 1058 | ret = lenovo_register_leds(hdev); |
| 1059 | if (ret) |
| 1060 | goto err; |
| 1061 | |
| 1062 | return 0; |
| 1063 | err: |
| 1064 | sysfs_remove_group(&hdev->dev.kobj, &lenovo_attr_group_tp10ubkbd); |
| 1065 | return ret; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1066 | } |
| 1067 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1068 | static int lenovo_probe(struct hid_device *hdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1069 | const struct hid_device_id *id) |
| 1070 | { |
| 1071 | int ret; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1072 | |
| 1073 | ret = hid_parse(hdev); |
| 1074 | if (ret) { |
| 1075 | hid_err(hdev, "hid_parse failed\n"); |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 1076 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 1080 | if (ret) { |
| 1081 | hid_err(hdev, "hid_hw_start failed\n"); |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 1082 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1083 | } |
| 1084 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1085 | switch (hdev->product) { |
| 1086 | case USB_DEVICE_ID_LENOVO_TPKBD: |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1087 | ret = lenovo_probe_tpkbd(hdev); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1088 | break; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 1089 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 1090 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 1091 | ret = lenovo_probe_cptkbd(hdev); |
| 1092 | break; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1093 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 1094 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1095 | ret = lenovo_probe_tp10ubkbd(hdev); |
| 1096 | break; |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1097 | default: |
| 1098 | ret = 0; |
| 1099 | break; |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 1100 | } |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1101 | if (ret) |
| 1102 | goto err_hid; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1103 | |
| 1104 | return 0; |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 1105 | err_hid: |
| 1106 | hid_hw_stop(hdev); |
| 1107 | err: |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1108 | return ret; |
| 1109 | } |
| 1110 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1111 | static void lenovo_remove_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1112 | { |
Hans de Goede | b72cdfa | 2020-07-04 15:27:38 +0200 | [diff] [blame] | 1113 | struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1114 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1115 | /* |
| 1116 | * Only the trackpoint half of the keyboard has drvdata and stuff that |
| 1117 | * needs unregistering. |
| 1118 | */ |
| 1119 | if (data_pointer == NULL) |
| 1120 | return; |
| 1121 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1122 | sysfs_remove_group(&hdev->dev.kobj, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1123 | &lenovo_attr_group_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1124 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1125 | led_classdev_unregister(&data_pointer->led_micmute); |
| 1126 | led_classdev_unregister(&data_pointer->led_mute); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 1129 | static void lenovo_remove_cptkbd(struct hid_device *hdev) |
| 1130 | { |
| 1131 | sysfs_remove_group(&hdev->dev.kobj, |
| 1132 | &lenovo_attr_group_cptkbd); |
| 1133 | } |
| 1134 | |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1135 | static void lenovo_remove_tp10ubkbd(struct hid_device *hdev) |
| 1136 | { |
| 1137 | struct lenovo_drvdata *data = hid_get_drvdata(hdev); |
| 1138 | |
| 1139 | if (data == NULL) |
| 1140 | return; |
| 1141 | |
| 1142 | led_classdev_unregister(&data->led_micmute); |
| 1143 | led_classdev_unregister(&data->led_mute); |
Hans de Goede | c87de33 | 2020-07-04 15:27:42 +0200 | [diff] [blame] | 1144 | |
| 1145 | sysfs_remove_group(&hdev->dev.kobj, &lenovo_attr_group_tp10ubkbd); |
| 1146 | cancel_work_sync(&data->fn_lock_sync_work); |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1149 | static void lenovo_remove(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1150 | { |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1151 | switch (hdev->product) { |
| 1152 | case USB_DEVICE_ID_LENOVO_TPKBD: |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1153 | lenovo_remove_tpkbd(hdev); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1154 | break; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 1155 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 1156 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 1157 | lenovo_remove_cptkbd(hdev); |
| 1158 | break; |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1159 | case USB_DEVICE_ID_LENOVO_TP10UBKBD: |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 1160 | case USB_DEVICE_ID_LENOVO_X1_TAB: |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1161 | lenovo_remove_tp10ubkbd(hdev); |
| 1162 | break; |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1163 | } |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1164 | |
| 1165 | hid_hw_stop(hdev); |
| 1166 | } |
| 1167 | |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1168 | static int lenovo_input_configured(struct hid_device *hdev, |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 1169 | struct hid_input *hi) |
| 1170 | { |
| 1171 | switch (hdev->product) { |
| 1172 | case USB_DEVICE_ID_LENOVO_TPKBD: |
| 1173 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 1174 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 1175 | if (test_bit(EV_REL, hi->input->evbit)) { |
| 1176 | /* set only for trackpoint device */ |
| 1177 | __set_bit(INPUT_PROP_POINTER, hi->input->propbit); |
| 1178 | __set_bit(INPUT_PROP_POINTING_STICK, |
| 1179 | hi->input->propbit); |
| 1180 | } |
| 1181 | break; |
| 1182 | } |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 1183 | |
| 1184 | return 0; |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1188 | static const struct hid_device_id lenovo_devices[] = { |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1189 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) }, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 1190 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) }, |
| 1191 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) }, |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 1192 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) }, |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 1193 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_III) }, |
| 1194 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_PRO) }, |
| 1195 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL) }, |
| 1196 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL) }, |
| 1197 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO) }, |
| 1198 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL) }, |
Hans de Goede | bc04b37 | 2020-07-04 15:27:41 +0200 | [diff] [blame] | 1199 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TP10UBKBD) }, |
Hans de Goede | c158c2a | 2021-04-04 10:04:32 +0200 | [diff] [blame] | 1200 | /* |
| 1201 | * Note bind to the HID_GROUP_GENERIC group, so that we only bind to the keyboard |
| 1202 | * part, while letting hid-multitouch.c handle the touchpad and trackpoint. |
| 1203 | */ |
| 1204 | { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, |
| 1205 | USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_X1_TAB) }, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1206 | { } |
| 1207 | }; |
| 1208 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1209 | MODULE_DEVICE_TABLE(hid, lenovo_devices); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1210 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1211 | static struct hid_driver lenovo_driver = { |
| 1212 | .name = "lenovo", |
| 1213 | .id_table = lenovo_devices, |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 1214 | .input_configured = lenovo_input_configured, |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 1215 | .input_mapping = lenovo_input_mapping, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1216 | .probe = lenovo_probe, |
| 1217 | .remove = lenovo_remove, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 1218 | .raw_event = lenovo_raw_event, |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 1219 | .event = lenovo_event, |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 1220 | .report_fixup = lenovo_report_fixup, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1221 | }; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 1222 | module_hid_driver(lenovo_driver); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 1223 | |
| 1224 | MODULE_LICENSE("GPL"); |