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> |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 32 | |
| 33 | #include "hid-ids.h" |
| 34 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 35 | struct lenovo_drvdata_tpkbd { |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 36 | int led_state; |
| 37 | struct led_classdev led_mute; |
| 38 | struct led_classdev led_micmute; |
| 39 | int press_to_select; |
| 40 | int dragging; |
| 41 | int release_to_select; |
| 42 | int select_right; |
| 43 | int sensitivity; |
| 44 | int press_speed; |
| 45 | }; |
| 46 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 47 | struct lenovo_drvdata_cptkbd { |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 48 | u8 middlebutton_state; /* 0:Up, 1:Down (undecided), 2:Scrolling */ |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 49 | bool fn_lock; |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 50 | int sensitivity; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 53 | #define map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, EV_KEY, (c)) |
| 54 | |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 55 | static const __u8 lenovo_pro_dock_need_fixup_collection[] = { |
| 56 | 0x05, 0x88, /* Usage Page (Vendor Usage Page 0x88) */ |
| 57 | 0x09, 0x01, /* Usage (Vendor Usage 0x01) */ |
| 58 | 0xa1, 0x01, /* Collection (Application) */ |
| 59 | 0x85, 0x04, /* Report ID (4) */ |
| 60 | 0x19, 0x00, /* Usage Minimum (0) */ |
| 61 | 0x2a, 0xff, 0xff, /* Usage Maximum (65535) */ |
| 62 | }; |
| 63 | |
| 64 | static __u8 *lenovo_report_fixup(struct hid_device *hdev, __u8 *rdesc, |
| 65 | unsigned int *rsize) |
| 66 | { |
| 67 | switch (hdev->product) { |
| 68 | case USB_DEVICE_ID_LENOVO_TPPRODOCK: |
| 69 | /* the fixups that need to be done: |
| 70 | * - get a reasonable usage max for the vendor collection |
| 71 | * 0x8801 from the report ID 4 |
| 72 | */ |
| 73 | if (*rsize >= 153 && |
| 74 | memcmp(&rdesc[140], lenovo_pro_dock_need_fixup_collection, |
| 75 | sizeof(lenovo_pro_dock_need_fixup_collection)) == 0) { |
| 76 | rdesc[151] = 0x01; |
| 77 | rdesc[152] = 0x00; |
| 78 | } |
| 79 | break; |
| 80 | } |
| 81 | return rdesc; |
| 82 | } |
| 83 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 84 | static int lenovo_input_mapping_tpkbd(struct hid_device *hdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 85 | struct hid_input *hi, struct hid_field *field, |
| 86 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 87 | { |
Benjamin Tissoires | 0c52183 | 2013-09-11 22:12:24 +0200 | [diff] [blame] | 88 | if (usage->hid == (HID_UP_BUTTON | 0x0010)) { |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 89 | /* This sub-device contains trackpoint, mark it */ |
Benjamin Tissoires | 0c52183 | 2013-09-11 22:12:24 +0200 | [diff] [blame] | 90 | hid_set_drvdata(hdev, (void *)1); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 91 | map_key_clear(KEY_MICMUTE); |
| 92 | return 1; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 97 | static int lenovo_input_mapping_cptkbd(struct hid_device *hdev, |
| 98 | struct hid_input *hi, struct hid_field *field, |
| 99 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 100 | { |
| 101 | /* HID_UP_LNVENDOR = USB, HID_UP_MSVENDOR = BT */ |
| 102 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR || |
| 103 | (usage->hid & HID_USAGE_PAGE) == HID_UP_LNVENDOR) { |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 104 | switch (usage->hid & HID_USAGE) { |
| 105 | case 0x00f1: /* Fn-F4: Mic mute */ |
| 106 | map_key_clear(KEY_MICMUTE); |
| 107 | return 1; |
| 108 | case 0x00f2: /* Fn-F5: Brightness down */ |
| 109 | map_key_clear(KEY_BRIGHTNESSDOWN); |
| 110 | return 1; |
| 111 | case 0x00f3: /* Fn-F6: Brightness up */ |
| 112 | map_key_clear(KEY_BRIGHTNESSUP); |
| 113 | return 1; |
| 114 | case 0x00f4: /* Fn-F7: External display (projector) */ |
| 115 | map_key_clear(KEY_SWITCHVIDEOMODE); |
| 116 | return 1; |
| 117 | case 0x00f5: /* Fn-F8: Wireless */ |
| 118 | map_key_clear(KEY_WLAN); |
| 119 | return 1; |
| 120 | case 0x00f6: /* Fn-F9: Control panel */ |
| 121 | map_key_clear(KEY_CONFIG); |
| 122 | return 1; |
| 123 | case 0x00f8: /* Fn-F11: View open applications (3 boxes) */ |
| 124 | map_key_clear(KEY_SCALE); |
| 125 | return 1; |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 126 | case 0x00f9: /* Fn-F12: Open My computer (6 boxes) USB-only */ |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 127 | /* NB: This mapping is invented in raw_event below */ |
| 128 | map_key_clear(KEY_FILE); |
| 129 | return 1; |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 130 | case 0x00fa: /* Fn-Esc: Fn-lock toggle */ |
| 131 | map_key_clear(KEY_FN_ESC); |
| 132 | return 1; |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 133 | case 0x00fb: /* Middle mouse button (in native mode) */ |
| 134 | map_key_clear(BTN_MIDDLE); |
| 135 | return 1; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /* Compatibility middle/wheel mappings should be ignored */ |
| 140 | if (usage->hid == HID_GD_WHEEL) |
| 141 | return -1; |
| 142 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_BUTTON && |
| 143 | (usage->hid & HID_USAGE) == 0x003) |
| 144 | return -1; |
| 145 | if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER && |
| 146 | (usage->hid & HID_USAGE) == 0x238) |
| 147 | return -1; |
| 148 | |
| 149 | /* Map wheel emulation reports: 0xffa1 = USB, 0xff10 = BT */ |
| 150 | if ((usage->hid & HID_USAGE_PAGE) == 0xff100000 || |
| 151 | (usage->hid & HID_USAGE_PAGE) == 0xffa10000) { |
| 152 | field->flags |= HID_MAIN_ITEM_RELATIVE | HID_MAIN_ITEM_VARIABLE; |
| 153 | field->logical_minimum = -127; |
| 154 | field->logical_maximum = 127; |
| 155 | |
| 156 | switch (usage->hid & HID_USAGE) { |
| 157 | case 0x0000: |
Jamie Lentin | 7f65068 | 2015-08-11 22:40:50 +0100 | [diff] [blame] | 158 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 159 | return 1; |
| 160 | case 0x0001: |
Jamie Lentin | 7f65068 | 2015-08-11 22:40:50 +0100 | [diff] [blame] | 161 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_WHEEL); |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 162 | return 1; |
| 163 | default: |
| 164 | return -1; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 171 | static int lenovo_input_mapping_scrollpoint(struct hid_device *hdev, |
| 172 | struct hid_input *hi, struct hid_field *field, |
| 173 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 174 | { |
| 175 | if (usage->hid == HID_GD_Z) { |
| 176 | hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL); |
| 177 | return 1; |
| 178 | } |
| 179 | return 0; |
| 180 | } |
| 181 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 182 | static int lenovo_input_mapping(struct hid_device *hdev, |
| 183 | struct hid_input *hi, struct hid_field *field, |
| 184 | struct hid_usage *usage, unsigned long **bit, int *max) |
| 185 | { |
| 186 | switch (hdev->product) { |
| 187 | case USB_DEVICE_ID_LENOVO_TPKBD: |
| 188 | return lenovo_input_mapping_tpkbd(hdev, hi, field, |
| 189 | usage, bit, max); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 190 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 191 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 192 | return lenovo_input_mapping_cptkbd(hdev, hi, field, |
| 193 | usage, bit, max); |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 194 | case USB_DEVICE_ID_IBM_SCROLLPOINT_III: |
| 195 | case USB_DEVICE_ID_IBM_SCROLLPOINT_PRO: |
| 196 | case USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL: |
| 197 | case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL: |
| 198 | case USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO: |
| 199 | case USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL: |
| 200 | return lenovo_input_mapping_scrollpoint(hdev, hi, field, |
| 201 | usage, bit, max); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 202 | default: |
| 203 | return 0; |
| 204 | } |
| 205 | } |
| 206 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 207 | #undef map_key_clear |
| 208 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 209 | /* Send a config command to the keyboard */ |
| 210 | static int lenovo_send_cmd_cptkbd(struct hid_device *hdev, |
| 211 | unsigned char byte2, unsigned char byte3) |
| 212 | { |
| 213 | int ret; |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 214 | unsigned char *buf; |
| 215 | |
| 216 | buf = kzalloc(3, GFP_KERNEL); |
| 217 | if (!buf) |
| 218 | return -ENOMEM; |
| 219 | |
| 220 | buf[0] = 0x18; |
| 221 | buf[1] = byte2; |
| 222 | buf[2] = byte3; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 223 | |
| 224 | switch (hdev->product) { |
| 225 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 226 | ret = hid_hw_raw_request(hdev, 0x13, buf, 3, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 227 | HID_FEATURE_REPORT, HID_REQ_SET_REPORT); |
| 228 | break; |
| 229 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 230 | ret = hid_hw_output_report(hdev, buf, 3); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 231 | break; |
| 232 | default: |
| 233 | ret = -EINVAL; |
| 234 | break; |
| 235 | } |
| 236 | |
Josh Boyer | ea36ae0 | 2016-03-28 09:22:14 -0400 | [diff] [blame] | 237 | kfree(buf); |
| 238 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 239 | return ret < 0 ? ret : 0; /* BT returns 0, USB returns sizeof(buf) */ |
| 240 | } |
| 241 | |
| 242 | static void lenovo_features_set_cptkbd(struct hid_device *hdev) |
| 243 | { |
| 244 | int ret; |
| 245 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 246 | |
| 247 | ret = lenovo_send_cmd_cptkbd(hdev, 0x05, cptkbd_data->fn_lock); |
| 248 | if (ret) |
| 249 | hid_err(hdev, "Fn-lock setting failed: %d\n", ret); |
Jamie Lentin | dbfebb4 | 2015-08-11 22:40:51 +0100 | [diff] [blame] | 250 | |
| 251 | ret = lenovo_send_cmd_cptkbd(hdev, 0x02, cptkbd_data->sensitivity); |
| 252 | if (ret) |
| 253 | hid_err(hdev, "Sensitivity setting failed: %d\n", ret); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static ssize_t attr_fn_lock_show_cptkbd(struct device *dev, |
| 257 | struct device_attribute *attr, |
| 258 | char *buf) |
| 259 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 260 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 261 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 262 | |
| 263 | return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock); |
| 264 | } |
| 265 | |
| 266 | static ssize_t attr_fn_lock_store_cptkbd(struct device *dev, |
| 267 | struct device_attribute *attr, |
| 268 | const char *buf, |
| 269 | size_t count) |
| 270 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 271 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 272 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 273 | int value; |
| 274 | |
| 275 | if (kstrtoint(buf, 10, &value)) |
| 276 | return -EINVAL; |
| 277 | if (value < 0 || value > 1) |
| 278 | return -EINVAL; |
| 279 | |
| 280 | cptkbd_data->fn_lock = !!value; |
| 281 | lenovo_features_set_cptkbd(hdev); |
| 282 | |
| 283 | return count; |
| 284 | } |
| 285 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 286 | static ssize_t attr_sensitivity_show_cptkbd(struct device *dev, |
| 287 | struct device_attribute *attr, |
| 288 | char *buf) |
| 289 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 290 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 291 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 292 | |
| 293 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 294 | cptkbd_data->sensitivity); |
| 295 | } |
| 296 | |
| 297 | static ssize_t attr_sensitivity_store_cptkbd(struct device *dev, |
| 298 | struct device_attribute *attr, |
| 299 | const char *buf, |
| 300 | size_t count) |
| 301 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 302 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 303 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 304 | int value; |
| 305 | |
| 306 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 307 | return -EINVAL; |
| 308 | |
| 309 | cptkbd_data->sensitivity = value; |
| 310 | lenovo_features_set_cptkbd(hdev); |
| 311 | |
| 312 | return count; |
| 313 | } |
| 314 | |
| 315 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 316 | static struct device_attribute dev_attr_fn_lock_cptkbd = |
| 317 | __ATTR(fn_lock, S_IWUSR | S_IRUGO, |
| 318 | attr_fn_lock_show_cptkbd, |
| 319 | attr_fn_lock_store_cptkbd); |
| 320 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 321 | static struct device_attribute dev_attr_sensitivity_cptkbd = |
| 322 | __ATTR(sensitivity, S_IWUSR | S_IRUGO, |
| 323 | attr_sensitivity_show_cptkbd, |
| 324 | attr_sensitivity_store_cptkbd); |
| 325 | |
| 326 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 327 | static struct attribute *lenovo_attributes_cptkbd[] = { |
| 328 | &dev_attr_fn_lock_cptkbd.attr, |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 329 | &dev_attr_sensitivity_cptkbd.attr, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 330 | NULL |
| 331 | }; |
| 332 | |
| 333 | static const struct attribute_group lenovo_attr_group_cptkbd = { |
| 334 | .attrs = lenovo_attributes_cptkbd, |
| 335 | }; |
| 336 | |
| 337 | static int lenovo_raw_event(struct hid_device *hdev, |
| 338 | struct hid_report *report, u8 *data, int size) |
| 339 | { |
| 340 | /* |
| 341 | * Compact USB keyboard's Fn-F12 report holds down many other keys, and |
| 342 | * its own key is outside the usage page range. Remove extra |
| 343 | * keypresses and remap to inside usage page. |
| 344 | */ |
| 345 | if (unlikely(hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD |
| 346 | && size == 3 |
| 347 | && data[0] == 0x15 |
| 348 | && data[1] == 0x94 |
| 349 | && data[2] == 0x01)) { |
Jamie Lentin | 5556eb1 | 2014-11-09 07:54:29 +0000 | [diff] [blame] | 350 | data[1] = 0x00; |
| 351 | data[2] = 0x01; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 357 | static int lenovo_event_cptkbd(struct hid_device *hdev, |
| 358 | struct hid_field *field, struct hid_usage *usage, __s32 value) |
| 359 | { |
| 360 | struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); |
| 361 | |
| 362 | /* "wheel" scroll events */ |
| 363 | if (usage->type == EV_REL && (usage->code == REL_WHEEL || |
| 364 | usage->code == REL_HWHEEL)) { |
| 365 | /* Scroll events disable middle-click event */ |
| 366 | cptkbd_data->middlebutton_state = 2; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* Middle click events */ |
| 371 | if (usage->type == EV_KEY && usage->code == BTN_MIDDLE) { |
| 372 | if (value == 1) { |
| 373 | cptkbd_data->middlebutton_state = 1; |
| 374 | } else if (value == 0) { |
| 375 | if (cptkbd_data->middlebutton_state == 1) { |
| 376 | /* No scrolling inbetween, send middle-click */ |
| 377 | input_event(field->hidinput->input, |
| 378 | EV_KEY, BTN_MIDDLE, 1); |
| 379 | input_sync(field->hidinput->input); |
| 380 | input_event(field->hidinput->input, |
| 381 | EV_KEY, BTN_MIDDLE, 0); |
| 382 | input_sync(field->hidinput->input); |
| 383 | } |
| 384 | cptkbd_data->middlebutton_state = 0; |
| 385 | } |
| 386 | return 1; |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int lenovo_event(struct hid_device *hdev, struct hid_field *field, |
| 393 | struct hid_usage *usage, __s32 value) |
| 394 | { |
| 395 | switch (hdev->product) { |
| 396 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 397 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 398 | return lenovo_event_cptkbd(hdev, field, usage, value); |
| 399 | default: |
| 400 | return 0; |
| 401 | } |
| 402 | } |
| 403 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 404 | static int lenovo_features_set_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 405 | { |
| 406 | struct hid_report *report; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 407 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 408 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 409 | report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[4]; |
| 410 | |
| 411 | report->field[0]->value[0] = data_pointer->press_to_select ? 0x01 : 0x02; |
| 412 | report->field[0]->value[0] |= data_pointer->dragging ? 0x04 : 0x08; |
| 413 | report->field[0]->value[0] |= data_pointer->release_to_select ? 0x10 : 0x20; |
| 414 | report->field[0]->value[0] |= data_pointer->select_right ? 0x80 : 0x40; |
| 415 | report->field[1]->value[0] = 0x03; // unknown setting, imitate windows driver |
| 416 | report->field[2]->value[0] = data_pointer->sensitivity; |
| 417 | report->field[3]->value[0] = data_pointer->press_speed; |
| 418 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 419 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 423 | static ssize_t attr_press_to_select_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 424 | struct device_attribute *attr, |
| 425 | char *buf) |
| 426 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 427 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 428 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 429 | |
| 430 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select); |
| 431 | } |
| 432 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 433 | static ssize_t attr_press_to_select_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 434 | struct device_attribute *attr, |
| 435 | const char *buf, |
| 436 | size_t count) |
| 437 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 438 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 439 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 440 | int value; |
| 441 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 442 | if (kstrtoint(buf, 10, &value)) |
| 443 | return -EINVAL; |
| 444 | if (value < 0 || value > 1) |
| 445 | return -EINVAL; |
| 446 | |
| 447 | data_pointer->press_to_select = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 448 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 449 | |
| 450 | return count; |
| 451 | } |
| 452 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 453 | static ssize_t attr_dragging_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 454 | struct device_attribute *attr, |
| 455 | char *buf) |
| 456 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 457 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 458 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 459 | |
| 460 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging); |
| 461 | } |
| 462 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 463 | static ssize_t attr_dragging_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 464 | struct device_attribute *attr, |
| 465 | const char *buf, |
| 466 | size_t count) |
| 467 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 468 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 469 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 470 | int value; |
| 471 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 472 | if (kstrtoint(buf, 10, &value)) |
| 473 | return -EINVAL; |
| 474 | if (value < 0 || value > 1) |
| 475 | return -EINVAL; |
| 476 | |
| 477 | data_pointer->dragging = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 478 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 479 | |
| 480 | return count; |
| 481 | } |
| 482 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 483 | static ssize_t attr_release_to_select_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 484 | struct device_attribute *attr, |
| 485 | char *buf) |
| 486 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 487 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 488 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 489 | |
| 490 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select); |
| 491 | } |
| 492 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 493 | static ssize_t attr_release_to_select_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 494 | struct device_attribute *attr, |
| 495 | const char *buf, |
| 496 | size_t count) |
| 497 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 498 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 499 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 500 | int value; |
| 501 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 502 | if (kstrtoint(buf, 10, &value)) |
| 503 | return -EINVAL; |
| 504 | if (value < 0 || value > 1) |
| 505 | return -EINVAL; |
| 506 | |
| 507 | data_pointer->release_to_select = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 508 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 509 | |
| 510 | return count; |
| 511 | } |
| 512 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 513 | static ssize_t attr_select_right_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 514 | struct device_attribute *attr, |
| 515 | char *buf) |
| 516 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 517 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 518 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 519 | |
| 520 | return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right); |
| 521 | } |
| 522 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 523 | static ssize_t attr_select_right_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 524 | struct device_attribute *attr, |
| 525 | const char *buf, |
| 526 | size_t count) |
| 527 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 528 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 529 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 530 | int value; |
| 531 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 532 | if (kstrtoint(buf, 10, &value)) |
| 533 | return -EINVAL; |
| 534 | if (value < 0 || value > 1) |
| 535 | return -EINVAL; |
| 536 | |
| 537 | data_pointer->select_right = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 538 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 539 | |
| 540 | return count; |
| 541 | } |
| 542 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 543 | static ssize_t attr_sensitivity_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 544 | struct device_attribute *attr, |
| 545 | char *buf) |
| 546 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 547 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 548 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 549 | |
| 550 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 551 | data_pointer->sensitivity); |
| 552 | } |
| 553 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 554 | static ssize_t attr_sensitivity_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 555 | struct device_attribute *attr, |
| 556 | const char *buf, |
| 557 | size_t count) |
| 558 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 559 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 560 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 561 | int value; |
| 562 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 563 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 564 | return -EINVAL; |
| 565 | |
| 566 | data_pointer->sensitivity = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 567 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 568 | |
| 569 | return count; |
| 570 | } |
| 571 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 572 | static ssize_t attr_press_speed_show_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 573 | struct device_attribute *attr, |
| 574 | char *buf) |
| 575 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 576 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 577 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 578 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 579 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 580 | data_pointer->press_speed); |
| 581 | } |
| 582 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 583 | static ssize_t attr_press_speed_store_tpkbd(struct device *dev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 584 | struct device_attribute *attr, |
| 585 | const char *buf, |
| 586 | size_t count) |
| 587 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 588 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 589 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 590 | int value; |
| 591 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 592 | if (kstrtoint(buf, 10, &value) || value < 1 || value > 255) |
| 593 | return -EINVAL; |
| 594 | |
| 595 | data_pointer->press_speed = value; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 596 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 597 | |
| 598 | return count; |
| 599 | } |
| 600 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 601 | static struct device_attribute dev_attr_press_to_select_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 602 | __ATTR(press_to_select, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 603 | attr_press_to_select_show_tpkbd, |
| 604 | attr_press_to_select_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 605 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 606 | static struct device_attribute dev_attr_dragging_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 607 | __ATTR(dragging, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 608 | attr_dragging_show_tpkbd, |
| 609 | attr_dragging_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 610 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 611 | static struct device_attribute dev_attr_release_to_select_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 612 | __ATTR(release_to_select, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 613 | attr_release_to_select_show_tpkbd, |
| 614 | attr_release_to_select_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 615 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 616 | static struct device_attribute dev_attr_select_right_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 617 | __ATTR(select_right, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 618 | attr_select_right_show_tpkbd, |
| 619 | attr_select_right_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 620 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 621 | static struct device_attribute dev_attr_sensitivity_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 622 | __ATTR(sensitivity, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 623 | attr_sensitivity_show_tpkbd, |
| 624 | attr_sensitivity_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 625 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 626 | static struct device_attribute dev_attr_press_speed_tpkbd = |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 627 | __ATTR(press_speed, S_IWUSR | S_IRUGO, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 628 | attr_press_speed_show_tpkbd, |
| 629 | attr_press_speed_store_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 630 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 631 | static struct attribute *lenovo_attributes_tpkbd[] = { |
| 632 | &dev_attr_press_to_select_tpkbd.attr, |
| 633 | &dev_attr_dragging_tpkbd.attr, |
| 634 | &dev_attr_release_to_select_tpkbd.attr, |
| 635 | &dev_attr_select_right_tpkbd.attr, |
| 636 | &dev_attr_sensitivity_tpkbd.attr, |
| 637 | &dev_attr_press_speed_tpkbd.attr, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 638 | NULL |
| 639 | }; |
| 640 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 641 | static const struct attribute_group lenovo_attr_group_tpkbd = { |
| 642 | .attrs = lenovo_attributes_tpkbd, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 643 | }; |
| 644 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 645 | static enum led_brightness lenovo_led_brightness_get_tpkbd( |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 646 | struct led_classdev *led_cdev) |
| 647 | { |
Axel Lin | 832fbea | 2012-09-13 14:12:08 +0800 | [diff] [blame] | 648 | struct device *dev = led_cdev->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 649 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 650 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 651 | int led_nr = 0; |
| 652 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 653 | if (led_cdev == &data_pointer->led_micmute) |
| 654 | led_nr = 1; |
| 655 | |
| 656 | return data_pointer->led_state & (1 << led_nr) |
| 657 | ? LED_FULL |
| 658 | : LED_OFF; |
| 659 | } |
| 660 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 661 | static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 662 | enum led_brightness value) |
| 663 | { |
Axel Lin | 832fbea | 2012-09-13 14:12:08 +0800 | [diff] [blame] | 664 | struct device *dev = led_cdev->dev->parent; |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 665 | struct hid_device *hdev = to_hid_device(dev); |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 666 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 667 | struct hid_report *report; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 668 | int led_nr = 0; |
| 669 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 670 | if (led_cdev == &data_pointer->led_micmute) |
| 671 | led_nr = 1; |
| 672 | |
| 673 | if (value == LED_OFF) |
| 674 | data_pointer->led_state &= ~(1 << led_nr); |
| 675 | else |
| 676 | data_pointer->led_state |= 1 << led_nr; |
| 677 | |
| 678 | report = hdev->report_enum[HID_OUTPUT_REPORT].report_id_hash[3]; |
| 679 | report->field[0]->value[0] = (data_pointer->led_state >> 0) & 1; |
| 680 | report->field[0]->value[1] = (data_pointer->led_state >> 1) & 1; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 681 | hid_hw_request(hdev, report, HID_REQ_SET_REPORT); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 684 | static int lenovo_probe_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 685 | { |
| 686 | struct device *dev = &hdev->dev; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 687 | struct lenovo_drvdata_tpkbd *data_pointer; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 688 | size_t name_sz = strlen(dev_name(dev)) + 16; |
| 689 | char *name_mute, *name_micmute; |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 690 | int i; |
Jamie Lentin | e0a6aad | 2014-07-26 15:42:27 +0100 | [diff] [blame] | 691 | int ret; |
Kees Cook | 0a9cd0a | 2013-09-11 21:56:55 +0200 | [diff] [blame] | 692 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 693 | /* |
| 694 | * Only register extra settings against subdevice where input_mapping |
| 695 | * set drvdata to 1, i.e. the trackpoint. |
| 696 | */ |
| 697 | if (!hid_get_drvdata(hdev)) |
| 698 | return 0; |
| 699 | |
| 700 | hid_set_drvdata(hdev, NULL); |
| 701 | |
Kees Cook | 0a9cd0a | 2013-09-11 21:56:55 +0200 | [diff] [blame] | 702 | /* Validate required reports. */ |
| 703 | for (i = 0; i < 4; i++) { |
| 704 | if (!hid_validate_values(hdev, HID_FEATURE_REPORT, 4, i, 1)) |
| 705 | return -ENODEV; |
| 706 | } |
| 707 | if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, 3, 0, 2)) |
| 708 | return -ENODEV; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 709 | |
Jamie Lentin | e0a6aad | 2014-07-26 15:42:27 +0100 | [diff] [blame] | 710 | ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd); |
| 711 | if (ret) |
| 712 | hid_warn(hdev, "Could not create sysfs group: %d\n", ret); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 713 | |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 714 | data_pointer = devm_kzalloc(&hdev->dev, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 715 | sizeof(struct lenovo_drvdata_tpkbd), |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 716 | GFP_KERNEL); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 717 | if (data_pointer == NULL) { |
| 718 | hid_err(hdev, "Could not allocate memory for driver data\n"); |
Alexey Khoroshilov | b721260 | 2015-05-29 03:39:31 +0300 | [diff] [blame] | 719 | ret = -ENOMEM; |
| 720 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | // set same default values as windows driver |
| 724 | data_pointer->sensitivity = 0xa0; |
| 725 | data_pointer->press_speed = 0x38; |
| 726 | |
Benjamin Tissoires | 01ab35f | 2013-09-11 22:12:23 +0200 | [diff] [blame] | 727 | name_mute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL); |
| 728 | name_micmute = devm_kzalloc(&hdev->dev, name_sz, GFP_KERNEL); |
| 729 | if (name_mute == NULL || name_micmute == NULL) { |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 730 | hid_err(hdev, "Could not allocate memory for led data\n"); |
Alexey Khoroshilov | b721260 | 2015-05-29 03:39:31 +0300 | [diff] [blame] | 731 | ret = -ENOMEM; |
| 732 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 733 | } |
| 734 | snprintf(name_mute, name_sz, "%s:amber:mute", dev_name(dev)); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 735 | snprintf(name_micmute, name_sz, "%s:amber:micmute", dev_name(dev)); |
| 736 | |
| 737 | hid_set_drvdata(hdev, data_pointer); |
| 738 | |
| 739 | data_pointer->led_mute.name = name_mute; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 740 | data_pointer->led_mute.brightness_get = lenovo_led_brightness_get_tpkbd; |
| 741 | data_pointer->led_mute.brightness_set = lenovo_led_brightness_set_tpkbd; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 742 | data_pointer->led_mute.dev = dev; |
Aditya Pakki | 6ae16df | 2018-12-24 15:39:14 -0600 | [diff] [blame] | 743 | ret = led_classdev_register(dev, &data_pointer->led_mute); |
| 744 | if (ret < 0) |
| 745 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 746 | |
| 747 | data_pointer->led_micmute.name = name_micmute; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 748 | data_pointer->led_micmute.brightness_get = |
| 749 | lenovo_led_brightness_get_tpkbd; |
| 750 | data_pointer->led_micmute.brightness_set = |
| 751 | lenovo_led_brightness_set_tpkbd; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 752 | data_pointer->led_micmute.dev = dev; |
Aditya Pakki | 6ae16df | 2018-12-24 15:39:14 -0600 | [diff] [blame] | 753 | ret = led_classdev_register(dev, &data_pointer->led_micmute); |
| 754 | if (ret < 0) { |
| 755 | led_classdev_unregister(&data_pointer->led_mute); |
| 756 | goto err; |
| 757 | } |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 758 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 759 | lenovo_features_set_tpkbd(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 760 | |
| 761 | return 0; |
Alexey Khoroshilov | b721260 | 2015-05-29 03:39:31 +0300 | [diff] [blame] | 762 | err: |
| 763 | sysfs_remove_group(&hdev->dev.kobj, &lenovo_attr_group_tpkbd); |
| 764 | return ret; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 767 | static int lenovo_probe_cptkbd(struct hid_device *hdev) |
| 768 | { |
| 769 | int ret; |
| 770 | struct lenovo_drvdata_cptkbd *cptkbd_data; |
| 771 | |
| 772 | /* All the custom action happens on the USBMOUSE device for USB */ |
| 773 | if (hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD |
| 774 | && hdev->type != HID_TYPE_USBMOUSE) { |
| 775 | hid_dbg(hdev, "Ignoring keyboard half of device\n"); |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | cptkbd_data = devm_kzalloc(&hdev->dev, |
| 780 | sizeof(*cptkbd_data), |
| 781 | GFP_KERNEL); |
| 782 | if (cptkbd_data == NULL) { |
| 783 | hid_err(hdev, "can't alloc keyboard descriptor\n"); |
| 784 | return -ENOMEM; |
| 785 | } |
| 786 | hid_set_drvdata(hdev, cptkbd_data); |
| 787 | |
| 788 | /* |
| 789 | * Tell the keyboard a driver understands it, and turn F7, F9, F11 into |
| 790 | * regular keys |
| 791 | */ |
| 792 | ret = lenovo_send_cmd_cptkbd(hdev, 0x01, 0x03); |
| 793 | if (ret) |
| 794 | hid_warn(hdev, "Failed to switch F7/9/11 mode: %d\n", ret); |
| 795 | |
Jamie Lentin | 94eefa2 | 2014-12-16 21:26:46 +0000 | [diff] [blame] | 796 | /* Switch middle button to native mode */ |
| 797 | ret = lenovo_send_cmd_cptkbd(hdev, 0x09, 0x01); |
| 798 | if (ret) |
| 799 | hid_warn(hdev, "Failed to switch middle button: %d\n", ret); |
| 800 | |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 801 | /* Set keyboard settings to known state */ |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 802 | cptkbd_data->middlebutton_state = 0; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 803 | cptkbd_data->fn_lock = true; |
Jamie Lentin | e3cb0ac | 2014-12-16 21:26:45 +0000 | [diff] [blame] | 804 | cptkbd_data->sensitivity = 0x05; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 805 | lenovo_features_set_cptkbd(hdev); |
| 806 | |
| 807 | ret = sysfs_create_group(&hdev->dev.kobj, &lenovo_attr_group_cptkbd); |
| 808 | if (ret) |
| 809 | hid_warn(hdev, "Could not create sysfs group: %d\n", ret); |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 814 | static int lenovo_probe(struct hid_device *hdev, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 815 | const struct hid_device_id *id) |
| 816 | { |
| 817 | int ret; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 818 | |
| 819 | ret = hid_parse(hdev); |
| 820 | if (ret) { |
| 821 | hid_err(hdev, "hid_parse failed\n"); |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 822 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 826 | if (ret) { |
| 827 | hid_err(hdev, "hid_hw_start failed\n"); |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 828 | goto err; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 831 | switch (hdev->product) { |
| 832 | case USB_DEVICE_ID_LENOVO_TPKBD: |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 833 | ret = lenovo_probe_tpkbd(hdev); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 834 | break; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 835 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 836 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 837 | ret = lenovo_probe_cptkbd(hdev); |
| 838 | break; |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 839 | default: |
| 840 | ret = 0; |
| 841 | break; |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 842 | } |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 843 | if (ret) |
| 844 | goto err_hid; |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 845 | |
| 846 | return 0; |
Benjamin Tissoires | 0ccdd9e | 2013-09-11 21:56:59 +0200 | [diff] [blame] | 847 | err_hid: |
| 848 | hid_hw_stop(hdev); |
| 849 | err: |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 850 | return ret; |
| 851 | } |
| 852 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 853 | static void lenovo_remove_tpkbd(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 854 | { |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 855 | struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 856 | |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 857 | /* |
| 858 | * Only the trackpoint half of the keyboard has drvdata and stuff that |
| 859 | * needs unregistering. |
| 860 | */ |
| 861 | if (data_pointer == NULL) |
| 862 | return; |
| 863 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 864 | sysfs_remove_group(&hdev->dev.kobj, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 865 | &lenovo_attr_group_tpkbd); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 866 | |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 867 | led_classdev_unregister(&data_pointer->led_micmute); |
| 868 | led_classdev_unregister(&data_pointer->led_mute); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 871 | static void lenovo_remove_cptkbd(struct hid_device *hdev) |
| 872 | { |
| 873 | sysfs_remove_group(&hdev->dev.kobj, |
| 874 | &lenovo_attr_group_cptkbd); |
| 875 | } |
| 876 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 877 | static void lenovo_remove(struct hid_device *hdev) |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 878 | { |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 879 | switch (hdev->product) { |
| 880 | case USB_DEVICE_ID_LENOVO_TPKBD: |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 881 | lenovo_remove_tpkbd(hdev); |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 882 | break; |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 883 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 884 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 885 | lenovo_remove_cptkbd(hdev); |
| 886 | break; |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 887 | } |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 888 | |
| 889 | hid_hw_stop(hdev); |
| 890 | } |
| 891 | |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 892 | static int lenovo_input_configured(struct hid_device *hdev, |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 893 | struct hid_input *hi) |
| 894 | { |
| 895 | switch (hdev->product) { |
| 896 | case USB_DEVICE_ID_LENOVO_TPKBD: |
| 897 | case USB_DEVICE_ID_LENOVO_CUSBKBD: |
| 898 | case USB_DEVICE_ID_LENOVO_CBTKBD: |
| 899 | if (test_bit(EV_REL, hi->input->evbit)) { |
| 900 | /* set only for trackpoint device */ |
| 901 | __set_bit(INPUT_PROP_POINTER, hi->input->propbit); |
| 902 | __set_bit(INPUT_PROP_POINTING_STICK, |
| 903 | hi->input->propbit); |
| 904 | } |
| 905 | break; |
| 906 | } |
Dmitry Torokhov | 9154301 | 2015-09-29 15:52:59 -0700 | [diff] [blame] | 907 | |
| 908 | return 0; |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 912 | static const struct hid_device_id lenovo_devices[] = { |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 913 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPKBD) }, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 914 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CUSBKBD) }, |
| 915 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_CBTKBD) }, |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 916 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_TPPRODOCK) }, |
pgzh | a230cd5 | 2018-04-12 19:36:47 +0200 | [diff] [blame] | 917 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_III) }, |
| 918 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_PRO) }, |
| 919 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_OPTICAL) }, |
| 920 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL) }, |
| 921 | { HID_USB_DEVICE(USB_VENDOR_ID_IBM, USB_DEVICE_ID_IBM_SCROLLPOINT_800DPI_OPTICAL_PRO) }, |
| 922 | { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_SCROLLPOINT_OPTICAL) }, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 923 | { } |
| 924 | }; |
| 925 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 926 | MODULE_DEVICE_TABLE(hid, lenovo_devices); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 927 | |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 928 | static struct hid_driver lenovo_driver = { |
| 929 | .name = "lenovo", |
| 930 | .id_table = lenovo_devices, |
Andreas Fleig | d92189e | 2015-04-23 10:25:58 +0200 | [diff] [blame] | 931 | .input_configured = lenovo_input_configured, |
Jamie Lentin | 6a5b414 | 2014-07-23 23:30:46 +0100 | [diff] [blame] | 932 | .input_mapping = lenovo_input_mapping, |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 933 | .probe = lenovo_probe, |
| 934 | .remove = lenovo_remove, |
Jamie Lentin | f3d4ff0 | 2014-07-23 23:30:48 +0100 | [diff] [blame] | 935 | .raw_event = lenovo_raw_event, |
Jamie Lentin | 3cb5ff0 | 2015-08-11 22:40:52 +0100 | [diff] [blame] | 936 | .event = lenovo_event, |
Benjamin Tissoires | 181a8b9 | 2015-05-01 16:22:45 -0400 | [diff] [blame] | 937 | .report_fixup = lenovo_report_fixup, |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 938 | }; |
Jamie Lentin | 94723bf | 2014-07-23 23:30:45 +0100 | [diff] [blame] | 939 | module_hid_driver(lenovo_driver); |
Bernhard Seibold | c1dcad2d | 2012-02-15 13:40:43 +0100 | [diff] [blame] | 940 | |
| 941 | MODULE_LICENSE("GPL"); |