Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'hid-for-linus-2025060301' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid

Pull HID updates from Jiri Kosina:

- support for Apple Magic Mouse 2 USB-C (Aditya Garg)

- power management improvement for multitouch devices (Werner Sembach)

- fix for ACPI initialization in intel-thc driver (Wentao Guan)

- adaptation of HID drivers to use new gpio_chip's line setter
callbacks (Bartosz Golaszewski)

- fix potential OOB in usbhid_parse() (Terry Junge)

- make it possible to set hid_mouse_ignore_list dynamically (the same
way we handle other quirks) (Aditya Garg)

- other small assorted fixes and device ID additions

* tag 'hid-for-linus-2025060301' of git://git.kernel.org/pub/scm/linux/kernel/git/hid/hid:
HID: multitouch: Disable touchpad on firmware level while not in use
HID: core: Add functions for HID drivers to react on first open and last close call
HID: HID_APPLETB_BL should depend on X86
HID: HID_APPLETB_KBD should depend on X86
HID: appletb-kbd: Use secs_to_jiffies() instead of msecs_to_jiffies()
HID: intel-thc-hid: intel-thc: make read-only arrays static const
HID: magicmouse: Apple Magic Mouse 2 USB-C support
HID: mcp2221: use new line value setter callbacks
HID: mcp2200: use new line value setter callbacks
HID: cp2112: use new line value setter callbacks
HID: cp2112: use lock guards
HID: cp2112: hold the lock for the entire direction_output() call
HID: cp2112: destroy mutex on driver detach
HID: intel-thc-hid: intel-quicki2c: pass correct arguments to acpi_evaluate_object
HID: corsair-void: Use to_delayed_work()
HID: hid-logitech: use sysfs_emit_at() instead of scnprintf()
HID: quirks: Add HID_QUIRK_IGNORE_MOUSE quirk
HID: usbhid: Eliminate recurrent out-of-bounds bug in usbhid_parse()
HID: Kysona: Add periodic online check

+217 -111
+2
drivers/hid/Kconfig
··· 151 151 config HID_APPLETB_BL 152 152 tristate "Apple Touch Bar Backlight" 153 153 depends on BACKLIGHT_CLASS_DEVICE 154 + depends on X86 || COMPILE_TEST 154 155 help 155 156 Say Y here if you want support for the backlight of Touch Bars on x86 156 157 MacBook Pros. ··· 164 163 depends on USB_HID 165 164 depends on BACKLIGHT_CLASS_DEVICE 166 165 depends on INPUT 166 + depends on X86 || COMPILE_TEST 167 167 select INPUT_SPARSEKMAP 168 168 select HID_APPLETB_BL 169 169 help
+6 -3
drivers/hid/hid-appletb-kbd.c
··· 172 172 if (!kbd->has_dimmed) { 173 173 backlight_device_set_brightness(kbd->backlight_dev, 1); 174 174 kbd->has_dimmed = true; 175 - mod_timer(&kbd->inactivity_timer, jiffies + msecs_to_jiffies(appletb_tb_idle_timeout * 1000)); 175 + mod_timer(&kbd->inactivity_timer, 176 + jiffies + secs_to_jiffies(appletb_tb_idle_timeout)); 176 177 } else if (!kbd->has_turned_off) { 177 178 backlight_device_set_brightness(kbd->backlight_dev, 0); 178 179 kbd->has_turned_off = true; ··· 189 188 kbd->has_dimmed = false; 190 189 kbd->has_turned_off = false; 191 190 } 192 - mod_timer(&kbd->inactivity_timer, jiffies + msecs_to_jiffies(appletb_tb_dim_timeout * 1000)); 191 + mod_timer(&kbd->inactivity_timer, 192 + jiffies + secs_to_jiffies(appletb_tb_dim_timeout)); 193 193 } 194 194 } 195 195 ··· 409 407 } else { 410 408 backlight_device_set_brightness(kbd->backlight_dev, 2); 411 409 timer_setup(&kbd->inactivity_timer, appletb_inactivity_timer, 0); 412 - mod_timer(&kbd->inactivity_timer, jiffies + msecs_to_jiffies(appletb_tb_dim_timeout * 1000)); 410 + mod_timer(&kbd->inactivity_timer, 411 + jiffies + secs_to_jiffies(appletb_tb_dim_timeout)); 413 412 } 414 413 415 414 kbd->inp_handler.event = appletb_kbd_inp_event;
+8 -1
drivers/hid/hid-core.c
··· 2396 2396 ret = hdev->ll_driver->open(hdev); 2397 2397 if (ret) 2398 2398 hdev->ll_open_count--; 2399 + 2400 + if (hdev->driver->on_hid_hw_open) 2401 + hdev->driver->on_hid_hw_open(hdev); 2399 2402 } 2400 2403 2401 2404 mutex_unlock(&hdev->ll_open_lock); ··· 2418 2415 void hid_hw_close(struct hid_device *hdev) 2419 2416 { 2420 2417 mutex_lock(&hdev->ll_open_lock); 2421 - if (!--hdev->ll_open_count) 2418 + if (!--hdev->ll_open_count) { 2422 2419 hdev->ll_driver->close(hdev); 2420 + 2421 + if (hdev->driver->on_hid_hw_close) 2422 + hdev->driver->on_hid_hw_close(hdev); 2423 + } 2423 2424 mutex_unlock(&hdev->ll_open_lock); 2424 2425 } 2425 2426 EXPORT_SYMBOL_GPL(hid_hw_close);
+2 -2
drivers/hid/hid-corsair-void.c
··· 507 507 struct delayed_work *delayed_work; 508 508 int battery_ret; 509 509 510 - delayed_work = container_of(work, struct delayed_work, work); 510 + delayed_work = to_delayed_work(work); 511 511 drvdata = container_of(delayed_work, struct corsair_void_drvdata, 512 512 delayed_status_work); 513 513 ··· 525 525 struct delayed_work *delayed_work; 526 526 int firmware_ret; 527 527 528 - delayed_work = container_of(work, struct delayed_work, work); 528 + delayed_work = to_delayed_work(work); 529 529 drvdata = container_of(delayed_work, struct corsair_void_drvdata, 530 530 delayed_firmware_work); 531 531
+32 -34
drivers/hid/hid-cp2112.c
··· 17 17 */ 18 18 19 19 #include <linux/bitops.h> 20 + #include <linux/cleanup.h> 20 21 #include <linux/gpio/driver.h> 21 22 #include <linux/hid.h> 22 23 #include <linux/hidraw.h> 23 24 #include <linux/i2c.h> 24 25 #include <linux/module.h> 26 + #include <linux/mutex.h> 25 27 #include <linux/nls.h> 26 28 #include <linux/string_choices.h> 27 29 #include <linux/usb/ch9.h> ··· 187 185 u8 *buf = dev->in_out_buffer; 188 186 int ret; 189 187 190 - mutex_lock(&dev->lock); 188 + guard(mutex)(&dev->lock); 191 189 192 190 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 193 191 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT, ··· 196 194 hid_err(hdev, "error requesting GPIO config: %d\n", ret); 197 195 if (ret >= 0) 198 196 ret = -EIO; 199 - goto exit; 197 + return ret; 200 198 } 201 199 202 200 buf[1] &= ~BIT(offset); ··· 209 207 hid_err(hdev, "error setting GPIO config: %d\n", ret); 210 208 if (ret >= 0) 211 209 ret = -EIO; 212 - goto exit; 210 + return ret; 213 211 } 214 212 215 - ret = 0; 216 - 217 - exit: 218 - mutex_unlock(&dev->lock); 219 - return ret; 213 + return 0; 220 214 } 221 215 222 - static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 216 + static int cp2112_gpio_set_unlocked(struct cp2112_device *dev, 217 + unsigned int offset, int value) 223 218 { 224 - struct cp2112_device *dev = gpiochip_get_data(chip); 225 219 struct hid_device *hdev = dev->hdev; 226 220 u8 *buf = dev->in_out_buffer; 227 221 int ret; 228 - 229 - mutex_lock(&dev->lock); 230 222 231 223 buf[0] = CP2112_GPIO_SET; 232 224 buf[1] = value ? CP2112_GPIO_ALL_GPIO_MASK : 0; ··· 232 236 if (ret < 0) 233 237 hid_err(hdev, "error setting GPIO values: %d\n", ret); 234 238 235 - mutex_unlock(&dev->lock); 239 + return ret; 240 + } 241 + 242 + static int cp2112_gpio_set(struct gpio_chip *chip, unsigned int offset, 243 + int value) 244 + { 245 + struct cp2112_device *dev = gpiochip_get_data(chip); 246 + 247 + guard(mutex)(&dev->lock); 248 + 249 + return cp2112_gpio_set_unlocked(dev, offset, value); 236 250 } 237 251 238 252 static int cp2112_gpio_get_all(struct gpio_chip *chip) ··· 252 246 u8 *buf = dev->in_out_buffer; 253 247 int ret; 254 248 255 - mutex_lock(&dev->lock); 249 + guard(mutex)(&dev->lock); 256 250 257 251 ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, 258 252 CP2112_GPIO_GET_LENGTH, HID_FEATURE_REPORT, 259 253 HID_REQ_GET_REPORT); 260 254 if (ret != CP2112_GPIO_GET_LENGTH) { 261 255 hid_err(hdev, "error requesting GPIO values: %d\n", ret); 262 - ret = ret < 0 ? ret : -EIO; 263 - goto exit; 256 + return ret < 0 ? ret : -EIO; 264 257 } 265 258 266 - ret = buf[1]; 267 - 268 - exit: 269 - mutex_unlock(&dev->lock); 270 - 271 - return ret; 259 + return buf[1]; 272 260 } 273 261 274 262 static int cp2112_gpio_get(struct gpio_chip *chip, unsigned int offset) ··· 284 284 u8 *buf = dev->in_out_buffer; 285 285 int ret; 286 286 287 - mutex_lock(&dev->lock); 287 + guard(mutex)(&dev->lock); 288 288 289 289 ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, 290 290 CP2112_GPIO_CONFIG_LENGTH, HID_FEATURE_REPORT, 291 291 HID_REQ_GET_REPORT); 292 292 if (ret != CP2112_GPIO_CONFIG_LENGTH) { 293 293 hid_err(hdev, "error requesting GPIO config: %d\n", ret); 294 - goto fail; 294 + return ret < 0 ? ret : -EIO; 295 295 } 296 296 297 297 buf[1] |= 1 << offset; ··· 302 302 HID_REQ_SET_REPORT); 303 303 if (ret < 0) { 304 304 hid_err(hdev, "error setting GPIO config: %d\n", ret); 305 - goto fail; 305 + return ret; 306 306 } 307 - 308 - mutex_unlock(&dev->lock); 309 307 310 308 /* 311 309 * Set gpio value when output direction is already set, 312 310 * as specified in AN495, Rev. 0.2, cpt. 4.4 313 311 */ 314 - cp2112_gpio_set(chip, offset, value); 312 + cp2112_gpio_set_unlocked(dev, offset, value); 315 313 316 314 return 0; 317 - 318 - fail: 319 - mutex_unlock(&dev->lock); 320 - return ret < 0 ? ret : -EIO; 321 315 } 322 316 323 317 static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number, ··· 1199 1205 if (!dev->in_out_buffer) 1200 1206 return -ENOMEM; 1201 1207 1202 - mutex_init(&dev->lock); 1208 + ret = devm_mutex_init(&hdev->dev, &dev->lock); 1209 + if (ret) { 1210 + hid_err(hdev, "mutex init failed\n"); 1211 + return ret; 1212 + } 1203 1213 1204 1214 ret = hid_parse(hdev); 1205 1215 if (ret) { ··· 1288 1290 dev->gc.label = "cp2112_gpio"; 1289 1291 dev->gc.direction_input = cp2112_gpio_direction_input; 1290 1292 dev->gc.direction_output = cp2112_gpio_direction_output; 1291 - dev->gc.set = cp2112_gpio_set; 1293 + dev->gc.set_rv = cp2112_gpio_set; 1292 1294 dev->gc.get = cp2112_gpio_get; 1293 1295 dev->gc.base = -1; 1294 1296 dev->gc.ngpio = CP2112_GPIO_MAX_GPIO;
+2 -2
drivers/hid/hid-hyperv.c
··· 192 192 goto cleanup; 193 193 194 194 input_device->report_desc_size = le16_to_cpu( 195 - desc->desc[0].wDescriptorLength); 195 + desc->rpt_desc.wDescriptorLength); 196 196 if (input_device->report_desc_size == 0) { 197 197 input_device->dev_info_status = -EINVAL; 198 198 goto cleanup; ··· 210 210 211 211 memcpy(input_device->report_desc, 212 212 ((unsigned char *)desc) + desc->bLength, 213 - le16_to_cpu(desc->desc[0].wDescriptorLength)); 213 + le16_to_cpu(desc->rpt_desc.wDescriptorLength)); 214 214 215 215 /* Send the ack */ 216 216 memset(&ack, 0, sizeof(struct mousevsc_prt_msg));
+1
drivers/hid/hid-ids.h
··· 96 96 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 97 97 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d 98 98 #define USB_DEVICE_ID_APPLE_MAGICMOUSE2 0x0269 99 + #define USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC 0x0323 99 100 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD 0x030e 100 101 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265 101 102 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC 0x0324
+44 -2
drivers/hid/hid-kysona.c
··· 14 14 15 15 #define BATTERY_TIMEOUT_MS 5000 16 16 17 + #define ONLINE_REPORT_ID 3 17 18 #define BATTERY_REPORT_ID 4 18 19 19 20 struct kysona_drvdata { ··· 81 80 return ret; 82 81 } 83 82 83 + static const char kysona_online_request[] = { 84 + 0x08, ONLINE_REPORT_ID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a 86 + }; 87 + 84 88 static const char kysona_battery_request[] = { 85 89 0x08, BATTERY_REPORT_ID, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49 87 91 }; 92 + 93 + static int kysona_m600_fetch_online(struct hid_device *hdev) 94 + { 95 + u8 *write_buf; 96 + int ret; 97 + 98 + /* Request online information */ 99 + write_buf = kmemdup(kysona_online_request, sizeof(kysona_online_request), GFP_KERNEL); 100 + if (!write_buf) 101 + return -ENOMEM; 102 + 103 + ret = hid_hw_raw_request(hdev, kysona_online_request[0], 104 + write_buf, sizeof(kysona_online_request), 105 + HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); 106 + if (ret < (int)sizeof(kysona_online_request)) { 107 + hid_err(hdev, "hid_hw_raw_request() failed with %d\n", ret); 108 + ret = -ENODATA; 109 + } 110 + kfree(write_buf); 111 + return ret; 112 + } 113 + 114 + static void kysona_fetch_online(struct hid_device *hdev) 115 + { 116 + int ret = kysona_m600_fetch_online(hdev); 117 + 118 + if (ret < 0) 119 + hid_dbg(hdev, 120 + "Online query failed (err: %d)\n", ret); 121 + } 88 122 89 123 static int kysona_m600_fetch_battery(struct hid_device *hdev) 90 124 { ··· 157 121 struct kysona_drvdata, battery_work.work); 158 122 struct hid_device *hdev = drv_data->hdev; 159 123 124 + kysona_fetch_online(hdev); 160 125 kysona_fetch_battery(hdev); 161 126 schedule_delayed_work(&drv_data->battery_work, 162 127 msecs_to_jiffies(BATTERY_TIMEOUT_MS)); ··· 197 160 power_supply_powers(drv_data->battery, &hdev->dev); 198 161 199 162 INIT_DELAYED_WORK(&drv_data->battery_work, kysona_battery_timer_tick); 163 + kysona_fetch_online(hdev); 200 164 kysona_fetch_battery(hdev); 201 165 schedule_delayed_work(&drv_data->battery_work, 202 166 msecs_to_jiffies(BATTERY_TIMEOUT_MS)); ··· 244 206 { 245 207 struct kysona_drvdata *drv_data = hid_get_drvdata(hdev); 246 208 247 - if (drv_data->battery && size == sizeof(kysona_battery_request) && 209 + if (size == sizeof(kysona_online_request) && 210 + data[0] == 8 && data[1] == ONLINE_REPORT_ID) { 211 + drv_data->online = data[6]; 212 + } 213 + 214 + if (size == sizeof(kysona_battery_request) && 248 215 data[0] == 8 && data[1] == BATTERY_REPORT_ID) { 249 216 drv_data->battery_capacity = data[6]; 250 217 drv_data->battery_charging = data[7]; 251 218 drv_data->battery_voltage = (data[8] << 8) | data[9]; 252 - drv_data->online = true; 253 219 } 254 220 255 221 return 0;
+3 -3
drivers/hid/hid-lg4ff.c
··· 823 823 for (i = 0; i < LG4FF_MODE_MAX_IDX; i++) { 824 824 if (entry->wdata.alternate_modes & BIT(i)) { 825 825 /* Print tag and full name */ 826 - count += scnprintf(buf + count, PAGE_SIZE - count, "%s: %s", 826 + count += sysfs_emit_at(buf, count, "%s: %s", 827 827 lg4ff_alternate_modes[i].tag, 828 828 !lg4ff_alternate_modes[i].product_id ? entry->wdata.real_name : lg4ff_alternate_modes[i].name); 829 829 if (count >= PAGE_SIZE - 1) ··· 832 832 /* Mark the currently active mode with an asterisk */ 833 833 if (lg4ff_alternate_modes[i].product_id == entry->wdata.product_id || 834 834 (lg4ff_alternate_modes[i].product_id == 0 && entry->wdata.product_id == entry->wdata.real_product_id)) 835 - count += scnprintf(buf + count, PAGE_SIZE - count, " *\n"); 835 + count += sysfs_emit_at(buf, count, " *\n"); 836 836 else 837 - count += scnprintf(buf + count, PAGE_SIZE - count, "\n"); 837 + count += sysfs_emit_at(buf, count, "\n"); 838 838 839 839 if (count >= PAGE_SIZE - 1) 840 840 return count;
+50 -24
drivers/hid/hid-magicmouse.c
··· 218 218 int pressure = 0; 219 219 220 220 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || 221 - input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 221 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 222 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) { 222 223 id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf; 223 224 x = (tdata[1] << 28 | tdata[0] << 20) >> 20; 224 225 y = -((tdata[2] << 24 | tdata[1] << 16) >> 20); ··· 371 370 372 371 if (report_undeciphered) { 373 372 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || 374 - input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) 373 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 374 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) 375 375 input_event(input, EV_MSC, MSC_RAW, tdata[7]); 376 376 else if (input->id.product != 377 377 USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && ··· 499 497 } 500 498 501 499 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || 502 - input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 500 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 501 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) { 503 502 magicmouse_emit_buttons(msc, clicks & 3); 504 503 input_report_rel(input, REL_X, x); 505 504 input_report_rel(input, REL_Y, y); ··· 522 519 struct hid_usage *usage, __s32 value) 523 520 { 524 521 struct magicmouse_sc *msc = hid_get_drvdata(hdev); 525 - if (msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 && 522 + if ((msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 523 + msc->input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) && 526 524 field->report->id == MOUSE2_REPORT_ID) { 527 525 /* 528 526 * magic_mouse_raw_event has done all the work. Skip hidinput. ··· 544 540 __set_bit(EV_KEY, input->evbit); 545 541 546 542 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || 547 - input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 543 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 544 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) { 548 545 __set_bit(BTN_LEFT, input->keybit); 549 546 __set_bit(BTN_RIGHT, input->keybit); 550 547 if (emulate_3button) ··· 630 625 * inverse of the reported Y. 631 626 */ 632 627 if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE || 633 - input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 628 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 629 + input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC) { 634 630 input_set_abs_params(input, ABS_MT_ORIENTATION, -31, 32, 1, 0); 635 631 input_set_abs_params(input, ABS_MT_POSITION_X, 636 632 MOUSE_MIN_X, MOUSE_MAX_X, 4, 0); ··· 747 741 int ret; 748 742 int feature_size; 749 743 750 - if (hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || 751 - hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { 752 - if (hdev->vendor == BT_VENDOR_ID_APPLE) { 744 + switch (hdev->product) { 745 + case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2: 746 + case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC: 747 + switch (hdev->vendor) { 748 + case BT_VENDOR_ID_APPLE: 753 749 feature_size = sizeof(feature_mt_trackpad2_bt); 754 750 feature = feature_mt_trackpad2_bt; 755 - } else { /* USB_VENDOR_ID_APPLE */ 751 + break; 752 + default: /* USB_VENDOR_ID_APPLE */ 756 753 feature_size = sizeof(feature_mt_trackpad2_usb); 757 754 feature = feature_mt_trackpad2_usb; 758 755 } 759 - } else if (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 756 + break; 757 + case USB_DEVICE_ID_APPLE_MAGICMOUSE2: 758 + case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC: 760 759 feature_size = sizeof(feature_mt_mouse2); 761 760 feature = feature_mt_mouse2; 762 - } else { 761 + break; 762 + default: 763 763 feature_size = sizeof(feature_mt); 764 764 feature = feature_mt; 765 765 } ··· 799 787 800 788 if (!hdev->battery || hdev->vendor != USB_VENDOR_ID_APPLE || 801 789 (hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2 && 790 + hdev->product != USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC && 802 791 hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && 803 792 hdev->product != USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC)) 804 793 return -1; ··· 870 857 871 858 if (id->vendor == USB_VENDOR_ID_APPLE && 872 859 (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 860 + id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC || 873 861 ((id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || 874 862 id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) && 875 863 hdev->type != HID_TYPE_USBMOUSE))) ··· 882 868 goto err_stop_hw; 883 869 } 884 870 885 - if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE) 886 - report = hid_register_report(hdev, HID_INPUT_REPORT, 887 - MOUSE_REPORT_ID, 0); 888 - else if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) 889 - report = hid_register_report(hdev, HID_INPUT_REPORT, 890 - MOUSE2_REPORT_ID, 0); 891 - else if (id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || 892 - id->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) { 893 - if (id->vendor == BT_VENDOR_ID_APPLE) 871 + switch (id->product) { 872 + case USB_DEVICE_ID_APPLE_MAGICMOUSE: 873 + report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE_REPORT_ID, 0); 874 + break; 875 + case USB_DEVICE_ID_APPLE_MAGICMOUSE2: 876 + case USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC: 877 + report = hid_register_report(hdev, HID_INPUT_REPORT, MOUSE2_REPORT_ID, 0); 878 + break; 879 + case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2: 880 + case USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC: 881 + switch (id->vendor) { 882 + case BT_VENDOR_ID_APPLE: 894 883 report = hid_register_report(hdev, HID_INPUT_REPORT, 895 884 TRACKPAD2_BT_REPORT_ID, 0); 896 - else /* USB_VENDOR_ID_APPLE */ 885 + break; 886 + default: 897 887 report = hid_register_report(hdev, HID_INPUT_REPORT, 898 888 TRACKPAD2_USB_REPORT_ID, 0); 899 - } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ 889 + } 890 + break; 891 + default: /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */ 900 892 report = hid_register_report(hdev, HID_INPUT_REPORT, 901 893 TRACKPAD_REPORT_ID, 0); 902 894 report = hid_register_report(hdev, HID_INPUT_REPORT, ··· 929 909 hid_err(hdev, "unable to request touch data (%d)\n", ret); 930 910 goto err_stop_hw; 931 911 } 932 - if (ret == -EIO && id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2) { 912 + if (ret == -EIO && (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 913 + id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC)) { 933 914 schedule_delayed_work(&msc->work, msecs_to_jiffies(500)); 934 915 } 935 916 ··· 966 945 */ 967 946 if (hdev->vendor == USB_VENDOR_ID_APPLE && 968 947 (hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2 || 948 + hdev->product == USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC || 969 949 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || 970 950 hdev->product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC) && 971 951 *rsize == 83 && rdesc[46] == 0x84 && rdesc[58] == 0x85) { ··· 993 971 USB_DEVICE_ID_APPLE_MAGICMOUSE2), .driver_data = 0 }, 994 972 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 995 973 USB_DEVICE_ID_APPLE_MAGICMOUSE2), .driver_data = 0 }, 974 + { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 975 + USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC), .driver_data = 0 }, 976 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 977 + USB_DEVICE_ID_APPLE_MAGICMOUSE2_USBC), .driver_data = 0 }, 996 978 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 997 979 USB_DEVICE_ID_APPLE_MAGICTRACKPAD), .driver_data = 0 }, 998 980 { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE,
+14 -9
drivers/hid/hid-mcp2200.c
··· 127 127 return mcp->status; 128 128 } 129 129 130 - static void mcp_set_multiple(struct gpio_chip *gc, unsigned long *mask, 131 - unsigned long *bits) 130 + static int mcp_set_multiple(struct gpio_chip *gc, unsigned long *mask, 131 + unsigned long *bits) 132 132 { 133 133 struct mcp2200 *mcp = gpiochip_get_data(gc); 134 134 u8 value; ··· 150 150 151 151 if (status == sizeof(struct mcp_set_clear_outputs)) 152 152 mcp->gpio_val = value; 153 + else 154 + status = -EIO; 153 155 154 156 mutex_unlock(&mcp->lock); 157 + 158 + return status; 155 159 } 156 160 157 - static void mcp_set(struct gpio_chip *gc, unsigned int gpio_nr, int value) 161 + static int mcp_set(struct gpio_chip *gc, unsigned int gpio_nr, int value) 158 162 { 159 163 unsigned long mask = 1 << gpio_nr; 160 164 unsigned long bmap_value = value << gpio_nr; 161 165 162 - mcp_set_multiple(gc, &mask, &bmap_value); 166 + return mcp_set_multiple(gc, &mask, &bmap_value); 163 167 } 164 168 165 169 static int mcp_get_multiple(struct gpio_chip *gc, unsigned long *mask, ··· 267 263 bmap_value = value << gpio_nr; 268 264 269 265 ret = mcp_set_direction(gc, gpio_nr, MCP2200_DIR_OUT); 270 - if (!ret) 271 - mcp_set_multiple(gc, &mask, &bmap_value); 272 - return ret; 266 + if (ret) 267 + return ret; 268 + 269 + return mcp_set_multiple(gc, &mask, &bmap_value); 273 270 } 274 271 275 272 static const struct gpio_chip template_chip = { ··· 279 274 .get_direction = mcp_get_direction, 280 275 .direction_input = mcp_direction_input, 281 276 .direction_output = mcp_direction_output, 282 - .set = mcp_set, 283 - .set_multiple = mcp_set_multiple, 277 + .set_rv = mcp_set, 278 + .set_multiple_rv = mcp_set_multiple, 284 279 .get = mcp_get, 285 280 .get_multiple = mcp_get_multiple, 286 281 .base = -1,
+6 -4
drivers/hid/hid-mcp2221.c
··· 624 624 return ret; 625 625 } 626 626 627 - static void mcp_gpio_set(struct gpio_chip *gc, 628 - unsigned int offset, int value) 627 + static int mcp_gpio_set(struct gpio_chip *gc, unsigned int offset, int value) 629 628 { 630 629 struct mcp2221 *mcp = gpiochip_get_data(gc); 630 + int ret; 631 631 632 632 memset(mcp->txbuf, 0, 18); 633 633 mcp->txbuf[0] = MCP2221_GPIO_SET; ··· 638 638 mcp->txbuf[mcp->gp_idx] = !!value; 639 639 640 640 mutex_lock(&mcp->lock); 641 - mcp_send_data_req_status(mcp, mcp->txbuf, 18); 641 + ret = mcp_send_data_req_status(mcp, mcp->txbuf, 18); 642 642 mutex_unlock(&mcp->lock); 643 + 644 + return ret; 643 645 } 644 646 645 647 static int mcp_gpio_dir_set(struct mcp2221 *mcp, ··· 1208 1206 mcp->gc->direction_input = mcp_gpio_direction_input; 1209 1207 mcp->gc->direction_output = mcp_gpio_direction_output; 1210 1208 mcp->gc->get_direction = mcp_gpio_get_direction; 1211 - mcp->gc->set = mcp_gpio_set; 1209 + mcp->gc->set_rv = mcp_gpio_set; 1212 1210 mcp->gc->get = mcp_gpio_get; 1213 1211 mcp->gc->ngpio = MCP_NGPIO; 1214 1212 mcp->gc->base = -1;
+12
drivers/hid/hid-multitouch.c
··· 1887 1887 hid_hw_stop(hdev); 1888 1888 } 1889 1889 1890 + static void mt_on_hid_hw_open(struct hid_device *hdev) 1891 + { 1892 + mt_set_modes(hdev, HID_LATENCY_NORMAL, TOUCHPAD_REPORT_ALL); 1893 + } 1894 + 1895 + static void mt_on_hid_hw_close(struct hid_device *hdev) 1896 + { 1897 + mt_set_modes(hdev, HID_LATENCY_HIGH, TOUCHPAD_REPORT_NONE); 1898 + } 1899 + 1890 1900 /* 1891 1901 * This list contains only: 1892 1902 * - VID/PID of products not working with the default multitouch handling ··· 2364 2354 .suspend = pm_ptr(mt_suspend), 2365 2355 .reset_resume = pm_ptr(mt_reset_resume), 2366 2356 .resume = pm_ptr(mt_resume), 2357 + .on_hid_hw_open = mt_on_hid_hw_open, 2358 + .on_hid_hw_close = mt_on_hid_hw_close, 2367 2359 }; 2368 2360 module_hid_driver(mt_driver);
+4 -1
drivers/hid/hid-quirks.c
··· 1063 1063 } 1064 1064 1065 1065 if (hdev->type == HID_TYPE_USBMOUSE && 1066 - hid_match_id(hdev, hid_mouse_ignore_list)) 1066 + hdev->quirks & HID_QUIRK_IGNORE_MOUSE) 1067 1067 return true; 1068 1068 1069 1069 return !!hid_match_id(hdev, hid_ignore_list); ··· 1266 1266 1267 1267 if (hid_match_id(hdev, hid_ignore_list)) 1268 1268 quirks |= HID_QUIRK_IGNORE; 1269 + 1270 + if (hid_match_id(hdev, hid_mouse_ignore_list)) 1271 + quirks |= HID_QUIRK_IGNORE_MOUSE; 1269 1272 1270 1273 if (hid_match_id(hdev, hid_have_special_driver)) 1271 1274 quirks |= HID_QUIRK_HAVE_SPECIAL_DRIVER;
+1 -6
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
··· 82 82 { 83 83 acpi_handle handle = acpi_device_handle(adev); 84 84 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 85 - union acpi_object obj = { .type = type }; 86 - struct acpi_object_list arg_list = { 87 - .count = 1, 88 - .pointer = &obj, 89 - }; 90 85 union acpi_object *ret_obj; 91 86 acpi_status status; 92 87 93 - status = acpi_evaluate_object(handle, dsd_method_name, &arg_list, &buffer); 88 + status = acpi_evaluate_object(handle, dsd_method_name, NULL, &buffer); 94 89 if (ACPI_FAILURE(status)) { 95 90 acpi_handle_err(handle, 96 91 "Can't evaluate %s method: %d\n", dsd_method_name, status);
+2 -2
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
··· 1121 1121 1122 1122 static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val) 1123 1123 { 1124 - int frequency[] = { 1124 + static const int frequency[] = { 1125 1125 THC_SPI_FREQUENCY_7M, 1126 1126 THC_SPI_FREQUENCY_15M, 1127 1127 THC_SPI_FREQUENCY_17M, ··· 1130 1130 THC_SPI_FREQUENCY_31M, 1131 1131 THC_SPI_FREQUENCY_41M, 1132 1132 }; 1133 - u8 frequency_div[] = { 1133 + static const u8 frequency_div[] = { 1134 1134 THC_SPI_FRQ_DIV_2, 1135 1135 THC_SPI_FRQ_DIV_1, 1136 1136 THC_SPI_FRQ_DIV_7,
+14 -11
drivers/hid/usbhid/hid-core.c
··· 984 984 struct usb_host_interface *interface = intf->cur_altsetting; 985 985 struct usb_device *dev = interface_to_usbdev (intf); 986 986 struct hid_descriptor *hdesc; 987 + struct hid_class_descriptor *hcdesc; 987 988 u32 quirks = 0; 988 989 unsigned int rsize = 0; 989 990 char *rdesc; 990 - int ret, n; 991 - int num_descriptors; 992 - size_t offset = offsetof(struct hid_descriptor, desc); 991 + int ret; 993 992 994 993 quirks = hid_lookup_quirk(hid); 995 994 ··· 1010 1011 return -ENODEV; 1011 1012 } 1012 1013 1013 - if (hdesc->bLength < sizeof(struct hid_descriptor)) { 1014 - dbg_hid("hid descriptor is too short\n"); 1014 + if (!hdesc->bNumDescriptors || 1015 + hdesc->bLength != sizeof(*hdesc) + 1016 + (hdesc->bNumDescriptors - 1) * sizeof(*hcdesc)) { 1017 + dbg_hid("hid descriptor invalid, bLen=%hhu bNum=%hhu\n", 1018 + hdesc->bLength, hdesc->bNumDescriptors); 1015 1019 return -EINVAL; 1016 1020 } 1017 1021 1018 1022 hid->version = le16_to_cpu(hdesc->bcdHID); 1019 1023 hid->country = hdesc->bCountryCode; 1020 1024 1021 - num_descriptors = min_t(int, hdesc->bNumDescriptors, 1022 - (hdesc->bLength - offset) / sizeof(struct hid_class_descriptor)); 1023 - 1024 - for (n = 0; n < num_descriptors; n++) 1025 - if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) 1026 - rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); 1025 + if (hdesc->rpt_desc.bDescriptorType == HID_DT_REPORT) 1026 + rsize = le16_to_cpu(hdesc->rpt_desc.wDescriptorLength); 1027 1027 1028 1028 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { 1029 1029 dbg_hid("weird size of report descriptor (%u)\n", rsize); ··· 1049 1051 dbg_hid("parsing report descriptor failed\n"); 1050 1052 goto err; 1051 1053 } 1054 + 1055 + if (hdesc->bNumDescriptors > 1) 1056 + hid_warn(intf, 1057 + "%u unsupported optional hid class descriptors\n", 1058 + (int)(hdesc->bNumDescriptors - 1)); 1052 1059 1053 1060 hid->quirks |= quirks; 1054 1061
+6 -6
drivers/usb/gadget/function/f_hid.c
··· 144 144 .bcdHID = cpu_to_le16(0x0101), 145 145 .bCountryCode = 0x00, 146 146 .bNumDescriptors = 0x1, 147 - /*.desc[0].bDescriptorType = DYNAMIC */ 148 - /*.desc[0].wDescriptorLenght = DYNAMIC */ 147 + /*.rpt_desc.bDescriptorType = DYNAMIC */ 148 + /*.rpt_desc.wDescriptorLength = DYNAMIC */ 149 149 }; 150 150 151 151 /* Super-Speed Support */ ··· 939 939 struct hid_descriptor hidg_desc_copy = hidg_desc; 940 940 941 941 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n"); 942 - hidg_desc_copy.desc[0].bDescriptorType = HID_DT_REPORT; 943 - hidg_desc_copy.desc[0].wDescriptorLength = 942 + hidg_desc_copy.rpt_desc.bDescriptorType = HID_DT_REPORT; 943 + hidg_desc_copy.rpt_desc.wDescriptorLength = 944 944 cpu_to_le16(hidg->report_desc_length); 945 945 946 946 length = min_t(unsigned short, length, ··· 1210 1210 * We can use hidg_desc struct here but we should not relay 1211 1211 * that its content won't change after returning from this function. 1212 1212 */ 1213 - hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT; 1214 - hidg_desc.desc[0].wDescriptorLength = 1213 + hidg_desc.rpt_desc.bDescriptorType = HID_DT_REPORT; 1214 + hidg_desc.rpt_desc.wDescriptorLength = 1215 1215 cpu_to_le16(hidg->report_desc_length); 1216 1216 1217 1217 hidg_hs_in_ep_desc.bEndpointAddress =
+8 -1
include/linux/hid.h
··· 357 357 * | @HID_QUIRK_INPUT_PER_APP: 358 358 * | @HID_QUIRK_X_INVERT: 359 359 * | @HID_QUIRK_Y_INVERT: 360 + * | @HID_QUIRK_IGNORE_MOUSE: 360 361 * | @HID_QUIRK_SKIP_OUTPUT_REPORTS: 361 362 * | @HID_QUIRK_SKIP_OUTPUT_REPORT_ID: 362 363 * | @HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP: ··· 383 382 #define HID_QUIRK_INPUT_PER_APP BIT(11) 384 383 #define HID_QUIRK_X_INVERT BIT(12) 385 384 #define HID_QUIRK_Y_INVERT BIT(13) 385 + #define HID_QUIRK_IGNORE_MOUSE BIT(14) 386 386 #define HID_QUIRK_SKIP_OUTPUT_REPORTS BIT(16) 387 387 #define HID_QUIRK_SKIP_OUTPUT_REPORT_ID BIT(17) 388 388 #define HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP BIT(18) ··· 742 740 __le16 bcdHID; 743 741 __u8 bCountryCode; 744 742 __u8 bNumDescriptors; 743 + struct hid_class_descriptor rpt_desc; 745 744 746 - struct hid_class_descriptor desc[1]; 745 + struct hid_class_descriptor opt_descs[]; 747 746 } __attribute__ ((packed)); 748 747 749 748 #define HID_DEVICE(b, g, ven, prod) \ ··· 795 792 * @suspend: invoked on suspend (NULL means nop) 796 793 * @resume: invoked on resume if device was not reset (NULL means nop) 797 794 * @reset_resume: invoked on resume if device was reset (NULL means nop) 795 + * @on_hid_hw_open: invoked when hid core opens first instance (NULL means nop) 796 + * @on_hid_hw_close: invoked when hid core closes last instance (NULL means nop) 798 797 * 799 798 * probe should return -errno on error, or 0 on success. During probe, 800 799 * input will not be passed to raw_event unless hid_device_io_start is ··· 852 847 int (*suspend)(struct hid_device *hdev, pm_message_t message); 853 848 int (*resume)(struct hid_device *hdev); 854 849 int (*reset_resume)(struct hid_device *hdev); 850 + void (*on_hid_hw_open)(struct hid_device *hdev); 851 + void (*on_hid_hw_close)(struct hid_device *hdev); 855 852 856 853 /* private: */ 857 854 struct device_driver driver;