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

Merge branch 'upstream-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jikos/hid

* 'upstream-fixes' of master.kernel.org:/pub/scm/linux/kernel/git/jikos/hid:
USB HID: hiddev - fix race between hiddev_send_event() and hiddev_release()
HID: add hooks for getkeycode() and setkeycode() methods
HID: switch to using input_dev->dev.parent
USB HID: Logitech wheel 0x046d/0xc294 needs HID_QUIRK_NOGET quirk
USB HID: usb_buffer_free() cleanup
USB HID: report descriptor of Cypress USB barcode readers needs fixup
Bluetooth HID: HIDP - don't initialize force feedback
USB HID: update CONFIG_USB_HIDINPUT_POWERBOOK description
HID: add input mappings for non-working keys on Logitech S510 remote

+171 -39
+96 -5
drivers/hid/hid-input.c
··· 240 240 } 241 241 #endif 242 242 243 + static inline int match_scancode(int code, int scancode) 244 + { 245 + if (scancode == 0) 246 + return 1; 247 + return ((code & (HID_USAGE_PAGE | HID_USAGE)) == scancode); 248 + } 249 + 250 + static inline int match_keycode(int code, int keycode) 251 + { 252 + if (keycode == 0) 253 + return 1; 254 + return (code == keycode); 255 + } 256 + 257 + static struct hid_usage *hidinput_find_key(struct hid_device *hid, 258 + int scancode, int keycode) 259 + { 260 + int i, j, k; 261 + struct hid_report *report; 262 + struct hid_usage *usage; 263 + 264 + for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { 265 + list_for_each_entry(report, &hid->report_enum[k].report_list, list) { 266 + for (i = 0; i < report->maxfield; i++) { 267 + for ( j = 0; j < report->field[i]->maxusage; j++) { 268 + usage = report->field[i]->usage + j; 269 + if (usage->type == EV_KEY && 270 + match_scancode(usage->hid, scancode) && 271 + match_keycode(usage->code, keycode)) 272 + return usage; 273 + } 274 + } 275 + } 276 + } 277 + return NULL; 278 + } 279 + 280 + static int hidinput_getkeycode(struct input_dev *dev, int scancode, 281 + int *keycode) 282 + { 283 + struct hid_device *hid = dev->private; 284 + struct hid_usage *usage; 285 + 286 + usage = hidinput_find_key(hid, scancode, 0); 287 + if (usage) { 288 + *keycode = usage->code; 289 + return 0; 290 + } 291 + return -EINVAL; 292 + } 293 + 294 + static int hidinput_setkeycode(struct input_dev *dev, int scancode, 295 + int keycode) 296 + { 297 + struct hid_device *hid = dev->private; 298 + struct hid_usage *usage; 299 + int old_keycode; 300 + 301 + if (keycode < 0 || keycode > KEY_MAX) 302 + return -EINVAL; 303 + 304 + usage = hidinput_find_key(hid, scancode, 0); 305 + if (usage) { 306 + old_keycode = usage->code; 307 + usage->code = keycode; 308 + 309 + clear_bit(old_keycode, dev->keybit); 310 + set_bit(usage->code, dev->keybit); 311 + #ifdef CONFIG_HID_DEBUG 312 + printk (KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", keycode, scancode); 313 + #endif 314 + /* Set the keybit for the old keycode if the old keycode is used 315 + * by another key */ 316 + if (hidinput_find_key (hid, 0, old_keycode)) 317 + set_bit(old_keycode, dev->keybit); 318 + 319 + return 0; 320 + } 321 + 322 + return -EINVAL; 323 + } 324 + 325 + 243 326 static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, 244 327 struct hid_usage *usage) 245 328 { 246 329 struct input_dev *input = hidinput->input; 247 - struct hid_device *device = input->private; 330 + struct hid_device *device = input_get_drvdata(input); 248 331 int max = 0, code; 249 332 unsigned long *bit = NULL; 250 333 ··· 636 553 case 0x1015: map_key_clear(KEY_RECORD); break; 637 554 case 0x1016: map_key_clear(KEY_PLAYER); break; 638 555 case 0x1017: map_key_clear(KEY_EJECTCD); break; 556 + case 0x1018: map_key_clear(KEY_MEDIA); break; 639 557 case 0x1019: map_key_clear(KEY_PROG1); break; 640 558 case 0x101a: map_key_clear(KEY_PROG2); break; 641 559 case 0x101b: map_key_clear(KEY_PROG3); break; ··· 644 560 case 0x1020: map_key_clear(KEY_ZOOMOUT); break; 645 561 case 0x1021: map_key_clear(KEY_ZOOMRESET); break; 646 562 case 0x1023: map_key_clear(KEY_CLOSE); break; 563 + case 0x1027: map_key_clear(KEY_MENU); break; 647 564 /* this one is marked as 'Rotate' */ 648 565 case 0x1028: map_key_clear(KEY_ANGLE); break; 649 566 case 0x1029: map_key_clear(KEY_SHUFFLE); break; 567 + case 0x102a: map_key_clear(KEY_BACK); break; 568 + case 0x102b: map_key_clear(KEY_CYCLEWINDOWS); break; 650 569 case 0x1041: map_key_clear(KEY_BATTERY); break; 651 570 case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break; 652 571 case 0x1043: map_key_clear(KEY_SPREADSHEET); break; ··· 942 855 943 856 static int hidinput_open(struct input_dev *dev) 944 857 { 945 - struct hid_device *hid = dev->private; 858 + struct hid_device *hid = input_get_drvdata(dev); 859 + 946 860 return hid->hid_open(hid); 947 861 } 948 862 949 863 static void hidinput_close(struct input_dev *dev) 950 864 { 951 - struct hid_device *hid = dev->private; 865 + struct hid_device *hid = input_get_drvdata(dev); 866 + 952 867 hid->hid_close(hid); 953 868 } 954 869 ··· 998 909 return -1; 999 910 } 1000 911 1001 - input_dev->private = hid; 912 + input_set_drvdata(input_dev, hid); 1002 913 input_dev->event = hid->hidinput_input_event; 1003 914 input_dev->open = hidinput_open; 1004 915 input_dev->close = hidinput_close; 916 + input_dev->setkeycode = hidinput_setkeycode; 917 + input_dev->getkeycode = hidinput_getkeycode; 1005 918 1006 919 input_dev->name = hid->name; 1007 920 input_dev->phys = hid->phys; ··· 1012 921 input_dev->id.vendor = hid->vendor; 1013 922 input_dev->id.product = hid->product; 1014 923 input_dev->id.version = hid->version; 1015 - input_dev->cdev.dev = hid->dev; 924 + input_dev->dev.parent = hid->dev; 1016 925 hidinput->input = input_dev; 1017 926 list_add_tail(&hidinput->list, &hid->inputs); 1018 927 }
+2 -2
drivers/hid/usbhid/Kconfig
··· 25 25 depends on USB_HID && INPUT=n 26 26 27 27 config USB_HIDINPUT_POWERBOOK 28 - bool "Enable support for iBook/PowerBook special keys" 28 + bool "Enable support for iBook/PowerBook/MacBook/MacBookPro special keys" 29 29 default n 30 30 depends on USB_HID 31 31 help 32 32 Say Y here if you want support for the special keys (Fn, Numlock) on 33 - Apple iBooks and PowerBooks. 33 + Apple iBooks, PowerBooks, MacBooks and MacBook Pros. 34 34 35 35 If unsure, say N. 36 36
+32 -9
drivers/hid/usbhid/hid-core.c
··· 446 446 447 447 static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 448 448 { 449 - struct hid_device *hid = dev->private; 449 + struct hid_device *hid = input_get_drvdata(dev); 450 450 struct hid_field *field; 451 451 int offset; 452 452 ··· 626 626 { 627 627 struct usbhid_device *usbhid = hid->driver_data; 628 628 629 - if (usbhid->inbuf) 630 - usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); 631 - if (usbhid->outbuf) 632 - usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); 633 - if (usbhid->cr) 634 - usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); 635 - if (usbhid->ctrlbuf) 636 - usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); 629 + usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); 630 + usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); 631 + usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); 632 + usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); 637 633 } 638 634 639 635 /* ··· 686 690 rdesc[84] = rdesc[89] = 0x4d; 687 691 rdesc[85] = rdesc[90] = 0x10; 688 692 } 693 + } 694 + 695 + /* 696 + * Some USB barcode readers from cypress have usage min and usage max in 697 + * the wrong order 698 + */ 699 + static void hid_fixup_cypress_descriptor(unsigned char *rdesc, int rsize) 700 + { 701 + short fixed = 0; 702 + int i; 703 + 704 + for (i = 0; i < rsize - 4; i++) { 705 + if (rdesc[i] == 0x29 && rdesc [i+2] == 0x19) { 706 + unsigned char tmp; 707 + 708 + rdesc[i] = 0x19; rdesc[i+2] = 0x29; 709 + tmp = rdesc[i+3]; 710 + rdesc[i+3] = rdesc[i+1]; 711 + rdesc[i+1] = tmp; 712 + } 713 + } 714 + 715 + if (fixed) 716 + info("Fixing up Cypress report descriptor"); 689 717 } 690 718 691 719 static struct hid_device *usb_hid_configure(struct usb_interface *intf) ··· 777 757 778 758 if (quirks & HID_QUIRK_LOGITECH_DESCRIPTOR) 779 759 hid_fixup_logitech_descriptor(rdesc, rsize); 760 + 761 + if (quirks & HID_QUIRK_SWAPPED_MIN_MAX) 762 + hid_fixup_cypress_descriptor(rdesc, rsize); 780 763 781 764 #ifdef CONFIG_HID_DEBUG 782 765 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
+1 -1
drivers/hid/usbhid/hid-lgff.c
··· 60 60 61 61 static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 62 62 { 63 - struct hid_device *hid = dev->private; 63 + struct hid_device *hid = input_get_drvdata(dev); 64 64 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 65 65 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 66 66 int x, y;
+1 -1
drivers/hid/usbhid/hid-plff.c
··· 37 37 static int hid_plff_play(struct input_dev *dev, void *data, 38 38 struct ff_effect *effect) 39 39 { 40 - struct hid_device *hid = dev->private; 40 + struct hid_device *hid = input_get_drvdata(dev); 41 41 struct plff_device *plff = data; 42 42 int left, right; 43 43
+7
drivers/hid/usbhid/hid-quirks.c
··· 92 92 #define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 93 93 #define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 94 94 #define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 95 + #define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61 96 + #define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64 95 97 96 98 #define USB_VENDOR_ID_DELL 0x413c 97 99 #define USB_DEVICE_ID_DELL_W7658 0x2005 ··· 195 193 196 194 #define USB_VENDOR_ID_LOGITECH 0x046d 197 195 #define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 196 + #define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294 198 197 #define USB_DEVICE_ID_S510_RECEIVER 0xc50c 199 198 #define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 200 199 #define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 ··· 425 422 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 426 423 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 427 424 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 425 + { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET }, 428 426 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 429 427 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 430 428 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, ··· 448 444 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE }, 449 445 450 446 { USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS }, 447 + 448 + { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_SWAPPED_MIN_MAX }, 449 + { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_SWAPPED_MIN_MAX }, 451 450 452 451 { 0, 0 } 453 452 };
+1 -1
drivers/hid/usbhid/hid-tmff.c
··· 59 59 60 60 static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 61 61 { 62 - struct hid_device *hid = dev->private; 62 + struct hid_device *hid = input_get_drvdata(dev); 63 63 struct tmff_device *tmff = data; 64 64 int left, right; /* Rumbling */ 65 65
+1 -1
drivers/hid/usbhid/hid-zpff.c
··· 37 37 static int hid_zpff_play(struct input_dev *dev, void *data, 38 38 struct ff_effect *effect) 39 39 { 40 - struct hid_device *hid = dev->private; 40 + struct hid_device *hid = input_get_drvdata(dev); 41 41 struct zpff_device *zpff = data; 42 42 int left, right; 43 43
+14
drivers/hid/usbhid/hiddev.c
··· 51 51 wait_queue_head_t wait; 52 52 struct hid_device *hid; 53 53 struct list_head list; 54 + spinlock_t list_lock; 54 55 }; 55 56 56 57 struct hiddev_list { ··· 162 161 { 163 162 struct hiddev *hiddev = hid->hiddev; 164 163 struct hiddev_list *list; 164 + unsigned long flags; 165 165 166 + spin_lock_irqsave(&hiddev->list_lock, flags); 166 167 list_for_each_entry(list, &hiddev->list, node) { 167 168 if (uref->field_index != HID_FIELD_INDEX_NONE || 168 169 (list->flags & HIDDEV_FLAG_REPORT) != 0) { ··· 174 171 kill_fasync(&list->fasync, SIGIO, POLL_IN); 175 172 } 176 173 } 174 + spin_unlock_irqrestore(&hiddev->list_lock, flags); 177 175 178 176 wake_up_interruptible(&hiddev->wait); 179 177 } ··· 239 235 static int hiddev_release(struct inode * inode, struct file * file) 240 236 { 241 237 struct hiddev_list *list = file->private_data; 238 + unsigned long flags; 242 239 243 240 hiddev_fasync(-1, file, 0); 241 + 242 + spin_lock_irqsave(&list->hiddev->list_lock, flags); 244 243 list_del(&list->node); 244 + spin_unlock_irqrestore(&list->hiddev->list_lock, flags); 245 245 246 246 if (!--list->hiddev->open) { 247 247 if (list->hiddev->exist) ··· 265 257 static int hiddev_open(struct inode *inode, struct file *file) 266 258 { 267 259 struct hiddev_list *list; 260 + unsigned long flags; 268 261 269 262 int i = iminor(inode) - HIDDEV_MINOR_BASE; 270 263 ··· 276 267 return -ENOMEM; 277 268 278 269 list->hiddev = hiddev_table[i]; 270 + 271 + spin_lock_irqsave(&list->hiddev->list_lock, flags); 279 272 list_add_tail(&list->node, &hiddev_table[i]->list); 273 + spin_unlock_irqrestore(&list->hiddev->list_lock, flags); 274 + 280 275 file->private_data = list; 281 276 282 277 if (!list->hiddev->open++) ··· 786 773 787 774 init_waitqueue_head(&hiddev->wait); 788 775 INIT_LIST_HEAD(&hiddev->list); 776 + spin_lock_init(&hiddev->list_lock); 789 777 hiddev->hid = hid; 790 778 hiddev->exist = 1; 791 779
+9 -12
drivers/hid/usbhid/usbkbd.c
··· 133 133 static int usb_kbd_event(struct input_dev *dev, unsigned int type, 134 134 unsigned int code, int value) 135 135 { 136 - struct usb_kbd *kbd = dev->private; 136 + struct usb_kbd *kbd = input_get_drvdata(dev); 137 137 138 138 if (type != EV_LED) 139 139 return -1; 140 - 141 140 142 141 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) | 143 142 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) | ··· 174 175 175 176 static int usb_kbd_open(struct input_dev *dev) 176 177 { 177 - struct usb_kbd *kbd = dev->private; 178 + struct usb_kbd *kbd = input_get_drvdata(dev); 178 179 179 180 kbd->irq->dev = kbd->usbdev; 180 181 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) ··· 185 186 186 187 static void usb_kbd_close(struct input_dev *dev) 187 188 { 188 - struct usb_kbd *kbd = dev->private; 189 + struct usb_kbd *kbd = input_get_drvdata(dev); 189 190 190 191 usb_kill_urb(kbd->irq); 191 192 } ··· 210 211 { 211 212 usb_free_urb(kbd->irq); 212 213 usb_free_urb(kbd->led); 213 - if (kbd->new) 214 - usb_buffer_free(dev, 8, kbd->new, kbd->new_dma); 215 - if (kbd->cr) 216 - usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma); 217 - if (kbd->leds) 218 - usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); 214 + usb_buffer_free(dev, 8, kbd->new, kbd->new_dma); 215 + usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma); 216 + usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); 219 217 } 220 218 221 219 static int usb_kbd_probe(struct usb_interface *iface, ··· 270 274 input_dev->name = kbd->name; 271 275 input_dev->phys = kbd->phys; 272 276 usb_to_input_id(dev, &input_dev->id); 273 - input_dev->cdev.dev = &iface->dev; 274 - input_dev->private = kbd; 277 + input_dev->dev.parent = &iface->dev; 278 + 279 + input_set_drvdata(input_dev, kbd); 275 280 276 281 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 277 282 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA);
+5 -4
drivers/hid/usbhid/usbmouse.c
··· 96 96 97 97 static int usb_mouse_open(struct input_dev *dev) 98 98 { 99 - struct usb_mouse *mouse = dev->private; 99 + struct usb_mouse *mouse = input_get_drvdata(dev); 100 100 101 101 mouse->irq->dev = mouse->usbdev; 102 102 if (usb_submit_urb(mouse->irq, GFP_KERNEL)) ··· 107 107 108 108 static void usb_mouse_close(struct input_dev *dev) 109 109 { 110 - struct usb_mouse *mouse = dev->private; 110 + struct usb_mouse *mouse = input_get_drvdata(dev); 111 111 112 112 usb_kill_urb(mouse->irq); 113 113 } ··· 171 171 input_dev->name = mouse->name; 172 172 input_dev->phys = mouse->phys; 173 173 usb_to_input_id(dev, &input_dev->id); 174 - input_dev->cdev.dev = &intf->dev; 174 + input_dev->dev.parent = &intf->dev; 175 175 176 176 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 177 177 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); ··· 179 179 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); 180 180 input_dev->relbit[0] |= BIT(REL_WHEEL); 181 181 182 - input_dev->private = mouse; 182 + input_set_drvdata(input_dev, mouse); 183 + 183 184 input_dev->open = usb_mouse_open; 184 185 input_dev->close = usb_mouse_close; 185 186
+1
include/linux/hid.h
··· 275 275 #define HID_QUIRK_LOGITECH_DESCRIPTOR 0x00100000 276 276 #define HID_QUIRK_DUPLICATE_USAGES 0x00200000 277 277 #define HID_QUIRK_RESET_LEDS 0x00400000 278 + #define HID_QUIRK_SWAPPED_MIN_MAX 0x00800000 278 279 279 280 /* 280 281 * This is the global environment of the parser. This information is
+1 -3
net/bluetooth/hidp/core.c
··· 737 737 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) 738 738 hidp_send_report(session, report); 739 739 740 - if (hidinput_connect(hid) == 0) { 740 + if (hidinput_connect(hid) == 0) 741 741 hid->claimed |= HID_CLAIMED_INPUT; 742 - hid_ff_init(hid); 743 - } 744 742 } 745 743 746 744 int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock)