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

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input

Pull more input updates from Dmitry Torokhov:
"The second round of updates for the input subsystem, mainly changes to
xpad driver to better hanlde Xbox One controllers"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input:
Input: gpio-keys - allow disabling individual buttons in DT
Input: gpio-keys - allow setting input device name in DT
Input: xpad - correct xbox one pad device name
Input: atmel_mxt_ts - improve touchscreen size/orientation handling
Input: xpad - use LED API when identifying wireless controllers
Input: xpad - workaround dead irq_out after suspend/ resume
Input: xpad - update Xbox One Force Feedback Support
Input: xpad - correctly handle concurrent LED and FF requests
Input: xpad - handle "present" and "gone" correctly
Input: xpad - remove spurious events of wireless xpad 360 controller

+456 -210
+1
Documentation/devicetree/bindings/input/gpio-keys.txt
··· 6 6 Optional properties: 7 7 - autorepeat: Boolean, Enable auto repeat feature of Linux input 8 8 subsystem. 9 + - label: String, name of the input device. 9 10 10 11 Each button (key) is represented as a sub-node of "gpio-keys": 11 12 Subnode properties:
+425 -166
drivers/input/joystick/xpad.c
··· 76 76 */ 77 77 78 78 #include <linux/kernel.h> 79 + #include <linux/input.h> 80 + #include <linux/rcupdate.h> 79 81 #include <linux/slab.h> 80 82 #include <linux/stat.h> 81 83 #include <linux/module.h> 82 84 #include <linux/usb/input.h> 85 + #include <linux/usb/quirks.h> 83 86 84 87 #define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" 85 88 #define DRIVER_DESC "X-Box pad driver" ··· 128 125 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX }, 129 126 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 }, 130 127 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE }, 131 - { 0x045e, 0x02dd, "Microsoft X-Box One pad (Covert Forces)", 0, XTYPE_XBOXONE }, 128 + { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE }, 132 129 { 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 133 130 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 134 131 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX }, ··· 320 317 321 318 MODULE_DEVICE_TABLE(usb, xpad_table); 322 319 320 + struct xpad_output_packet { 321 + u8 data[XPAD_PKT_LEN]; 322 + u8 len; 323 + bool pending; 324 + }; 325 + 326 + #define XPAD_OUT_CMD_IDX 0 327 + #define XPAD_OUT_FF_IDX 1 328 + #define XPAD_OUT_LED_IDX (1 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF)) 329 + #define XPAD_NUM_OUT_PACKETS (1 + \ 330 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF) + \ 331 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_LEDS)) 332 + 323 333 struct usb_xpad { 324 334 struct input_dev *dev; /* input device interface */ 335 + struct input_dev __rcu *x360w_dev; 325 336 struct usb_device *udev; /* usb device */ 326 337 struct usb_interface *intf; /* usb interface */ 327 338 328 - int pad_present; 339 + bool pad_present; 340 + bool input_created; 329 341 330 342 struct urb *irq_in; /* urb for interrupt in report */ 331 343 unsigned char *idata; /* input data */ 332 344 dma_addr_t idata_dma; 333 345 334 346 struct urb *irq_out; /* urb for interrupt out report */ 347 + struct usb_anchor irq_out_anchor; 348 + bool irq_out_active; /* we must not use an active URB */ 349 + u8 odata_serial; /* serial number for xbox one protocol */ 335 350 unsigned char *odata; /* output data */ 336 351 dma_addr_t odata_dma; 337 - struct mutex odata_mutex; 352 + spinlock_t odata_lock; 353 + 354 + struct xpad_output_packet out_packets[XPAD_NUM_OUT_PACKETS]; 355 + int last_out_packet; 338 356 339 357 #if defined(CONFIG_JOYSTICK_XPAD_LEDS) 340 358 struct xpad_led *led; ··· 367 343 int xtype; /* type of xbox device */ 368 344 int pad_nr; /* the order x360 pads were attached */ 369 345 const char *name; /* name of the device */ 346 + struct work_struct work; /* init/remove device from callback */ 370 347 }; 348 + 349 + static int xpad_init_input(struct usb_xpad *xpad); 350 + static void xpad_deinit_input(struct usb_xpad *xpad); 371 351 372 352 /* 373 353 * xpad_process_packet ··· 452 424 * http://www.free60.org/wiki/Gamepad 453 425 */ 454 426 455 - static void xpad360_process_packet(struct usb_xpad *xpad, 427 + static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev, 456 428 u16 cmd, unsigned char *data) 457 429 { 458 - struct input_dev *dev = xpad->dev; 459 - 460 430 /* digital pad */ 461 431 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 462 432 /* dpad as buttons (left, right, up, down) */ ··· 521 495 input_sync(dev); 522 496 } 523 497 524 - static void xpad_identify_controller(struct usb_xpad *xpad); 498 + static void xpad_presence_work(struct work_struct *work) 499 + { 500 + struct usb_xpad *xpad = container_of(work, struct usb_xpad, work); 501 + int error; 502 + 503 + if (xpad->pad_present) { 504 + error = xpad_init_input(xpad); 505 + if (error) { 506 + /* complain only, not much else we can do here */ 507 + dev_err(&xpad->dev->dev, 508 + "unable to init device: %d\n", error); 509 + } else { 510 + rcu_assign_pointer(xpad->x360w_dev, xpad->dev); 511 + } 512 + } else { 513 + RCU_INIT_POINTER(xpad->x360w_dev, NULL); 514 + synchronize_rcu(); 515 + /* 516 + * Now that we are sure xpad360w_process_packet is not 517 + * using input device we can get rid of it. 518 + */ 519 + xpad_deinit_input(xpad); 520 + } 521 + } 525 522 526 523 /* 527 524 * xpad360w_process_packet ··· 562 513 */ 563 514 static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) 564 515 { 516 + struct input_dev *dev; 517 + bool present; 518 + 565 519 /* Presence change */ 566 520 if (data[0] & 0x08) { 567 - if (data[1] & 0x80) { 568 - xpad->pad_present = 1; 569 - /* 570 - * Light up the segment corresponding to 571 - * controller number. 572 - */ 573 - xpad_identify_controller(xpad); 574 - } else 575 - xpad->pad_present = 0; 521 + present = (data[1] & 0x80) != 0; 522 + 523 + if (xpad->pad_present != present) { 524 + xpad->pad_present = present; 525 + schedule_work(&xpad->work); 526 + } 576 527 } 577 528 578 529 /* Valid pad data */ 579 - if (!(data[1] & 0x1)) 530 + if (data[1] != 0x1) 580 531 return; 581 532 582 - xpad360_process_packet(xpad, cmd, &data[4]); 533 + rcu_read_lock(); 534 + dev = rcu_dereference(xpad->x360w_dev); 535 + if (dev) 536 + xpad360_process_packet(xpad, dev, cmd, &data[4]); 537 + rcu_read_unlock(); 583 538 } 584 539 585 540 /* ··· 712 659 713 660 switch (xpad->xtype) { 714 661 case XTYPE_XBOX360: 715 - xpad360_process_packet(xpad, 0, xpad->idata); 662 + xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata); 716 663 break; 717 664 case XTYPE_XBOX360W: 718 665 xpad360w_process_packet(xpad, 0, xpad->idata); ··· 731 678 __func__, retval); 732 679 } 733 680 681 + /* Callers must hold xpad->odata_lock spinlock */ 682 + static bool xpad_prepare_next_out_packet(struct usb_xpad *xpad) 683 + { 684 + struct xpad_output_packet *pkt, *packet = NULL; 685 + int i; 686 + 687 + for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) { 688 + if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) 689 + xpad->last_out_packet = 0; 690 + 691 + pkt = &xpad->out_packets[xpad->last_out_packet]; 692 + if (pkt->pending) { 693 + dev_dbg(&xpad->intf->dev, 694 + "%s - found pending output packet %d\n", 695 + __func__, xpad->last_out_packet); 696 + packet = pkt; 697 + break; 698 + } 699 + } 700 + 701 + if (packet) { 702 + memcpy(xpad->odata, packet->data, packet->len); 703 + xpad->irq_out->transfer_buffer_length = packet->len; 704 + return true; 705 + } 706 + 707 + return false; 708 + } 709 + 710 + /* Callers must hold xpad->odata_lock spinlock */ 711 + static int xpad_try_sending_next_out_packet(struct usb_xpad *xpad) 712 + { 713 + int error; 714 + 715 + if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) { 716 + usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor); 717 + error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC); 718 + if (error) { 719 + dev_err(&xpad->intf->dev, 720 + "%s - usb_submit_urb failed with result %d\n", 721 + __func__, error); 722 + usb_unanchor_urb(xpad->irq_out); 723 + return -EIO; 724 + } 725 + 726 + xpad->irq_out_active = true; 727 + } 728 + 729 + return 0; 730 + } 731 + 734 732 static void xpad_irq_out(struct urb *urb) 735 733 { 736 734 struct usb_xpad *xpad = urb->context; 737 735 struct device *dev = &xpad->intf->dev; 738 - int retval, status; 736 + int status = urb->status; 737 + int error; 738 + unsigned long flags; 739 739 740 - status = urb->status; 740 + spin_lock_irqsave(&xpad->odata_lock, flags); 741 741 742 742 switch (status) { 743 743 case 0: 744 744 /* success */ 745 - return; 745 + xpad->out_packets[xpad->last_out_packet].pending = false; 746 + xpad->irq_out_active = xpad_prepare_next_out_packet(xpad); 747 + break; 746 748 747 749 case -ECONNRESET: 748 750 case -ENOENT: ··· 805 697 /* this urb is terminated, clean up */ 806 698 dev_dbg(dev, "%s - urb shutting down with status: %d\n", 807 699 __func__, status); 808 - return; 700 + xpad->irq_out_active = false; 701 + break; 809 702 810 703 default: 811 704 dev_dbg(dev, "%s - nonzero urb status received: %d\n", 812 705 __func__, status); 813 - goto exit; 706 + break; 814 707 } 815 708 816 - exit: 817 - retval = usb_submit_urb(urb, GFP_ATOMIC); 818 - if (retval) 819 - dev_err(dev, "%s - usb_submit_urb failed with result %d\n", 820 - __func__, retval); 709 + if (xpad->irq_out_active) { 710 + usb_anchor_urb(urb, &xpad->irq_out_anchor); 711 + error = usb_submit_urb(urb, GFP_ATOMIC); 712 + if (error) { 713 + dev_err(dev, 714 + "%s - usb_submit_urb failed with result %d\n", 715 + __func__, error); 716 + usb_unanchor_urb(urb); 717 + xpad->irq_out_active = false; 718 + } 719 + } 720 + 721 + spin_unlock_irqrestore(&xpad->odata_lock, flags); 821 722 } 822 723 823 724 static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) ··· 838 721 if (xpad->xtype == XTYPE_UNKNOWN) 839 722 return 0; 840 723 724 + init_usb_anchor(&xpad->irq_out_anchor); 725 + 841 726 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, 842 727 GFP_KERNEL, &xpad->odata_dma); 843 728 if (!xpad->odata) { ··· 847 728 goto fail1; 848 729 } 849 730 850 - mutex_init(&xpad->odata_mutex); 731 + spin_lock_init(&xpad->odata_lock); 851 732 852 733 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); 853 734 if (!xpad->irq_out) { ··· 874 755 875 756 static void xpad_stop_output(struct usb_xpad *xpad) 876 757 { 877 - if (xpad->xtype != XTYPE_UNKNOWN) 878 - usb_kill_urb(xpad->irq_out); 758 + if (xpad->xtype != XTYPE_UNKNOWN) { 759 + if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, 760 + 5000)) { 761 + dev_warn(&xpad->intf->dev, 762 + "timed out waiting for output URB to complete, killing\n"); 763 + usb_kill_anchored_urbs(&xpad->irq_out_anchor); 764 + } 765 + } 879 766 } 880 767 881 768 static void xpad_deinit_output(struct usb_xpad *xpad) ··· 895 770 896 771 static int xpad_inquiry_pad_presence(struct usb_xpad *xpad) 897 772 { 773 + struct xpad_output_packet *packet = 774 + &xpad->out_packets[XPAD_OUT_CMD_IDX]; 775 + unsigned long flags; 898 776 int retval; 899 777 900 - mutex_lock(&xpad->odata_mutex); 778 + spin_lock_irqsave(&xpad->odata_lock, flags); 901 779 902 - xpad->odata[0] = 0x08; 903 - xpad->odata[1] = 0x00; 904 - xpad->odata[2] = 0x0F; 905 - xpad->odata[3] = 0xC0; 906 - xpad->odata[4] = 0x00; 907 - xpad->odata[5] = 0x00; 908 - xpad->odata[6] = 0x00; 909 - xpad->odata[7] = 0x00; 910 - xpad->odata[8] = 0x00; 911 - xpad->odata[9] = 0x00; 912 - xpad->odata[10] = 0x00; 913 - xpad->odata[11] = 0x00; 914 - xpad->irq_out->transfer_buffer_length = 12; 780 + packet->data[0] = 0x08; 781 + packet->data[1] = 0x00; 782 + packet->data[2] = 0x0F; 783 + packet->data[3] = 0xC0; 784 + packet->data[4] = 0x00; 785 + packet->data[5] = 0x00; 786 + packet->data[6] = 0x00; 787 + packet->data[7] = 0x00; 788 + packet->data[8] = 0x00; 789 + packet->data[9] = 0x00; 790 + packet->data[10] = 0x00; 791 + packet->data[11] = 0x00; 792 + packet->len = 12; 793 + packet->pending = true; 915 794 916 - retval = usb_submit_urb(xpad->irq_out, GFP_KERNEL); 795 + /* Reset the sequence so we send out presence first */ 796 + xpad->last_out_packet = -1; 797 + retval = xpad_try_sending_next_out_packet(xpad); 917 798 918 - mutex_unlock(&xpad->odata_mutex); 799 + spin_unlock_irqrestore(&xpad->odata_lock, flags); 800 + 801 + return retval; 802 + } 803 + 804 + static int xpad_start_xbox_one(struct usb_xpad *xpad) 805 + { 806 + struct xpad_output_packet *packet = 807 + &xpad->out_packets[XPAD_OUT_CMD_IDX]; 808 + unsigned long flags; 809 + int retval; 810 + 811 + spin_lock_irqsave(&xpad->odata_lock, flags); 812 + 813 + /* Xbox one controller needs to be initialized. */ 814 + packet->data[0] = 0x05; 815 + packet->data[1] = 0x20; 816 + packet->data[2] = xpad->odata_serial++; /* packet serial */ 817 + packet->data[3] = 0x01; /* rumble bit enable? */ 818 + packet->data[4] = 0x00; 819 + packet->len = 5; 820 + packet->pending = true; 821 + 822 + /* Reset the sequence so we send out start packet first */ 823 + xpad->last_out_packet = -1; 824 + retval = xpad_try_sending_next_out_packet(xpad); 825 + 826 + spin_unlock_irqrestore(&xpad->odata_lock, flags); 919 827 920 828 return retval; 921 829 } ··· 957 799 static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) 958 800 { 959 801 struct usb_xpad *xpad = input_get_drvdata(dev); 802 + struct xpad_output_packet *packet = &xpad->out_packets[XPAD_OUT_FF_IDX]; 960 803 __u16 strong; 961 804 __u16 weak; 805 + int retval; 806 + unsigned long flags; 962 807 963 808 if (effect->type != FF_RUMBLE) 964 809 return 0; ··· 969 808 strong = effect->u.rumble.strong_magnitude; 970 809 weak = effect->u.rumble.weak_magnitude; 971 810 811 + spin_lock_irqsave(&xpad->odata_lock, flags); 812 + 972 813 switch (xpad->xtype) { 973 814 case XTYPE_XBOX: 974 - xpad->odata[0] = 0x00; 975 - xpad->odata[1] = 0x06; 976 - xpad->odata[2] = 0x00; 977 - xpad->odata[3] = strong / 256; /* left actuator */ 978 - xpad->odata[4] = 0x00; 979 - xpad->odata[5] = weak / 256; /* right actuator */ 980 - xpad->irq_out->transfer_buffer_length = 6; 815 + packet->data[0] = 0x00; 816 + packet->data[1] = 0x06; 817 + packet->data[2] = 0x00; 818 + packet->data[3] = strong / 256; /* left actuator */ 819 + packet->data[4] = 0x00; 820 + packet->data[5] = weak / 256; /* right actuator */ 821 + packet->len = 6; 822 + packet->pending = true; 981 823 break; 982 824 983 825 case XTYPE_XBOX360: 984 - xpad->odata[0] = 0x00; 985 - xpad->odata[1] = 0x08; 986 - xpad->odata[2] = 0x00; 987 - xpad->odata[3] = strong / 256; /* left actuator? */ 988 - xpad->odata[4] = weak / 256; /* right actuator? */ 989 - xpad->odata[5] = 0x00; 990 - xpad->odata[6] = 0x00; 991 - xpad->odata[7] = 0x00; 992 - xpad->irq_out->transfer_buffer_length = 8; 826 + packet->data[0] = 0x00; 827 + packet->data[1] = 0x08; 828 + packet->data[2] = 0x00; 829 + packet->data[3] = strong / 256; /* left actuator? */ 830 + packet->data[4] = weak / 256; /* right actuator? */ 831 + packet->data[5] = 0x00; 832 + packet->data[6] = 0x00; 833 + packet->data[7] = 0x00; 834 + packet->len = 8; 835 + packet->pending = true; 993 836 break; 994 837 995 838 case XTYPE_XBOX360W: 996 - xpad->odata[0] = 0x00; 997 - xpad->odata[1] = 0x01; 998 - xpad->odata[2] = 0x0F; 999 - xpad->odata[3] = 0xC0; 1000 - xpad->odata[4] = 0x00; 1001 - xpad->odata[5] = strong / 256; 1002 - xpad->odata[6] = weak / 256; 1003 - xpad->odata[7] = 0x00; 1004 - xpad->odata[8] = 0x00; 1005 - xpad->odata[9] = 0x00; 1006 - xpad->odata[10] = 0x00; 1007 - xpad->odata[11] = 0x00; 1008 - xpad->irq_out->transfer_buffer_length = 12; 839 + packet->data[0] = 0x00; 840 + packet->data[1] = 0x01; 841 + packet->data[2] = 0x0F; 842 + packet->data[3] = 0xC0; 843 + packet->data[4] = 0x00; 844 + packet->data[5] = strong / 256; 845 + packet->data[6] = weak / 256; 846 + packet->data[7] = 0x00; 847 + packet->data[8] = 0x00; 848 + packet->data[9] = 0x00; 849 + packet->data[10] = 0x00; 850 + packet->data[11] = 0x00; 851 + packet->len = 12; 852 + packet->pending = true; 1009 853 break; 1010 854 1011 855 case XTYPE_XBOXONE: 1012 - xpad->odata[0] = 0x09; /* activate rumble */ 1013 - xpad->odata[1] = 0x08; 1014 - xpad->odata[2] = 0x00; 1015 - xpad->odata[3] = 0x08; /* continuous effect */ 1016 - xpad->odata[4] = 0x00; /* simple rumble mode */ 1017 - xpad->odata[5] = 0x03; /* L and R actuator only */ 1018 - xpad->odata[6] = 0x00; /* TODO: LT actuator */ 1019 - xpad->odata[7] = 0x00; /* TODO: RT actuator */ 1020 - xpad->odata[8] = strong / 256; /* left actuator */ 1021 - xpad->odata[9] = weak / 256; /* right actuator */ 1022 - xpad->odata[10] = 0x80; /* length of pulse */ 1023 - xpad->odata[11] = 0x00; /* stop period of pulse */ 1024 - xpad->irq_out->transfer_buffer_length = 12; 856 + packet->data[0] = 0x09; /* activate rumble */ 857 + packet->data[1] = 0x08; 858 + packet->data[2] = xpad->odata_serial++; 859 + packet->data[3] = 0x08; /* continuous effect */ 860 + packet->data[4] = 0x00; /* simple rumble mode */ 861 + packet->data[5] = 0x03; /* L and R actuator only */ 862 + packet->data[6] = 0x00; /* TODO: LT actuator */ 863 + packet->data[7] = 0x00; /* TODO: RT actuator */ 864 + packet->data[8] = strong / 512; /* left actuator */ 865 + packet->data[9] = weak / 512; /* right actuator */ 866 + packet->data[10] = 0x80; /* length of pulse */ 867 + packet->data[11] = 0x00; /* stop period of pulse */ 868 + packet->data[12] = 0x00; 869 + packet->len = 13; 870 + packet->pending = true; 1025 871 break; 1026 872 1027 873 default: 1028 874 dev_dbg(&xpad->dev->dev, 1029 875 "%s - rumble command sent to unsupported xpad type: %d\n", 1030 876 __func__, xpad->xtype); 1031 - return -EINVAL; 877 + retval = -EINVAL; 878 + goto out; 1032 879 } 1033 880 1034 - return usb_submit_urb(xpad->irq_out, GFP_ATOMIC); 881 + retval = xpad_try_sending_next_out_packet(xpad); 882 + 883 + out: 884 + spin_unlock_irqrestore(&xpad->odata_lock, flags); 885 + return retval; 1035 886 } 1036 887 1037 888 static int xpad_init_ff(struct usb_xpad *xpad) ··· 1094 921 */ 1095 922 static void xpad_send_led_command(struct usb_xpad *xpad, int command) 1096 923 { 924 + struct xpad_output_packet *packet = 925 + &xpad->out_packets[XPAD_OUT_LED_IDX]; 926 + unsigned long flags; 927 + 1097 928 command %= 16; 1098 929 1099 - mutex_lock(&xpad->odata_mutex); 930 + spin_lock_irqsave(&xpad->odata_lock, flags); 1100 931 1101 932 switch (xpad->xtype) { 1102 933 case XTYPE_XBOX360: 1103 - xpad->odata[0] = 0x01; 1104 - xpad->odata[1] = 0x03; 1105 - xpad->odata[2] = command; 1106 - xpad->irq_out->transfer_buffer_length = 3; 934 + packet->data[0] = 0x01; 935 + packet->data[1] = 0x03; 936 + packet->data[2] = command; 937 + packet->len = 3; 938 + packet->pending = true; 1107 939 break; 940 + 1108 941 case XTYPE_XBOX360W: 1109 - xpad->odata[0] = 0x00; 1110 - xpad->odata[1] = 0x00; 1111 - xpad->odata[2] = 0x08; 1112 - xpad->odata[3] = 0x40 + command; 1113 - xpad->odata[4] = 0x00; 1114 - xpad->odata[5] = 0x00; 1115 - xpad->odata[6] = 0x00; 1116 - xpad->odata[7] = 0x00; 1117 - xpad->odata[8] = 0x00; 1118 - xpad->odata[9] = 0x00; 1119 - xpad->odata[10] = 0x00; 1120 - xpad->odata[11] = 0x00; 1121 - xpad->irq_out->transfer_buffer_length = 12; 942 + packet->data[0] = 0x00; 943 + packet->data[1] = 0x00; 944 + packet->data[2] = 0x08; 945 + packet->data[3] = 0x40 + command; 946 + packet->data[4] = 0x00; 947 + packet->data[5] = 0x00; 948 + packet->data[6] = 0x00; 949 + packet->data[7] = 0x00; 950 + packet->data[8] = 0x00; 951 + packet->data[9] = 0x00; 952 + packet->data[10] = 0x00; 953 + packet->data[11] = 0x00; 954 + packet->len = 12; 955 + packet->pending = true; 1122 956 break; 1123 957 } 1124 958 1125 - usb_submit_urb(xpad->irq_out, GFP_KERNEL); 1126 - mutex_unlock(&xpad->odata_mutex); 959 + xpad_try_sending_next_out_packet(xpad); 960 + 961 + spin_unlock_irqrestore(&xpad->odata_lock, flags); 1127 962 } 1128 963 1129 964 /* ··· 1140 959 */ 1141 960 static void xpad_identify_controller(struct usb_xpad *xpad) 1142 961 { 1143 - xpad_send_led_command(xpad, (xpad->pad_nr % 4) + 2); 962 + led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2); 1144 963 } 1145 964 1146 965 static void xpad_led_set(struct led_classdev *led_cdev, ··· 1182 1001 if (error) 1183 1002 goto err_free_id; 1184 1003 1185 - if (xpad->xtype == XTYPE_XBOX360) { 1186 - /* 1187 - * Light up the segment corresponding to controller 1188 - * number on wired devices. On wireless we'll do that 1189 - * when they respond to "presence" packet. 1190 - */ 1191 - xpad_identify_controller(xpad); 1192 - } 1004 + xpad_identify_controller(xpad); 1193 1005 1194 1006 return 0; 1195 1007 ··· 1210 1036 static void xpad_identify_controller(struct usb_xpad *xpad) { } 1211 1037 #endif 1212 1038 1213 - static int xpad_open(struct input_dev *dev) 1039 + static int xpad_start_input(struct usb_xpad *xpad) 1214 1040 { 1215 - struct usb_xpad *xpad = input_get_drvdata(dev); 1041 + int error; 1216 1042 1217 - /* URB was submitted in probe */ 1218 - if (xpad->xtype == XTYPE_XBOX360W) 1219 - return 0; 1220 - 1221 - xpad->irq_in->dev = xpad->udev; 1222 1043 if (usb_submit_urb(xpad->irq_in, GFP_KERNEL)) 1223 1044 return -EIO; 1224 1045 1225 1046 if (xpad->xtype == XTYPE_XBOXONE) { 1226 - /* Xbox one controller needs to be initialized. */ 1227 - xpad->odata[0] = 0x05; 1228 - xpad->odata[1] = 0x20; 1229 - xpad->irq_out->transfer_buffer_length = 2; 1230 - return usb_submit_urb(xpad->irq_out, GFP_KERNEL); 1047 + error = xpad_start_xbox_one(xpad); 1048 + if (error) { 1049 + usb_kill_urb(xpad->irq_in); 1050 + return error; 1051 + } 1231 1052 } 1232 1053 1233 1054 return 0; 1055 + } 1056 + 1057 + static void xpad_stop_input(struct usb_xpad *xpad) 1058 + { 1059 + usb_kill_urb(xpad->irq_in); 1060 + } 1061 + 1062 + static int xpad360w_start_input(struct usb_xpad *xpad) 1063 + { 1064 + int error; 1065 + 1066 + error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); 1067 + if (error) 1068 + return -EIO; 1069 + 1070 + /* 1071 + * Send presence packet. 1072 + * This will force the controller to resend connection packets. 1073 + * This is useful in the case we activate the module after the 1074 + * adapter has been plugged in, as it won't automatically 1075 + * send us info about the controllers. 1076 + */ 1077 + error = xpad_inquiry_pad_presence(xpad); 1078 + if (error) { 1079 + usb_kill_urb(xpad->irq_in); 1080 + return error; 1081 + } 1082 + 1083 + return 0; 1084 + } 1085 + 1086 + static void xpad360w_stop_input(struct usb_xpad *xpad) 1087 + { 1088 + usb_kill_urb(xpad->irq_in); 1089 + 1090 + /* Make sure we are done with presence work if it was scheduled */ 1091 + flush_work(&xpad->work); 1092 + } 1093 + 1094 + static int xpad_open(struct input_dev *dev) 1095 + { 1096 + struct usb_xpad *xpad = input_get_drvdata(dev); 1097 + 1098 + return xpad_start_input(xpad); 1234 1099 } 1235 1100 1236 1101 static void xpad_close(struct input_dev *dev) 1237 1102 { 1238 1103 struct usb_xpad *xpad = input_get_drvdata(dev); 1239 1104 1240 - if (xpad->xtype != XTYPE_XBOX360W) 1241 - usb_kill_urb(xpad->irq_in); 1242 - 1243 - xpad_stop_output(xpad); 1105 + xpad_stop_input(xpad); 1244 1106 } 1245 1107 1246 1108 static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) ··· 1307 1097 1308 1098 static void xpad_deinit_input(struct usb_xpad *xpad) 1309 1099 { 1310 - xpad_led_disconnect(xpad); 1311 - input_unregister_device(xpad->dev); 1100 + if (xpad->input_created) { 1101 + xpad->input_created = false; 1102 + xpad_led_disconnect(xpad); 1103 + input_unregister_device(xpad->dev); 1104 + } 1312 1105 } 1313 1106 1314 1107 static int xpad_init_input(struct usb_xpad *xpad) ··· 1331 1118 1332 1119 input_set_drvdata(input_dev, xpad); 1333 1120 1334 - input_dev->open = xpad_open; 1335 - input_dev->close = xpad_close; 1121 + if (xpad->xtype != XTYPE_XBOX360W) { 1122 + input_dev->open = xpad_open; 1123 + input_dev->close = xpad_close; 1124 + } 1336 1125 1337 1126 __set_bit(EV_KEY, input_dev->evbit); 1338 1127 ··· 1396 1181 if (error) 1397 1182 goto err_disconnect_led; 1398 1183 1184 + xpad->input_created = true; 1399 1185 return 0; 1400 1186 1401 1187 err_disconnect_led: ··· 1457 1241 xpad->mapping = xpad_device[i].mapping; 1458 1242 xpad->xtype = xpad_device[i].xtype; 1459 1243 xpad->name = xpad_device[i].name; 1244 + INIT_WORK(&xpad->work, xpad_presence_work); 1460 1245 1461 1246 if (xpad->xtype == XTYPE_UNKNOWN) { 1462 1247 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { ··· 1494 1277 1495 1278 usb_set_intfdata(intf, xpad); 1496 1279 1497 - error = xpad_init_input(xpad); 1498 - if (error) 1499 - goto err_deinit_output; 1500 - 1501 1280 if (xpad->xtype == XTYPE_XBOX360W) { 1502 1281 /* 1503 1282 * Submit the int URB immediately rather than waiting for open ··· 1502 1289 * exactly the message that a controller has arrived that 1503 1290 * we're waiting for. 1504 1291 */ 1505 - xpad->irq_in->dev = xpad->udev; 1506 - error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); 1292 + error = xpad360w_start_input(xpad); 1507 1293 if (error) 1508 - goto err_deinit_input; 1509 - 1294 + goto err_deinit_output; 1510 1295 /* 1511 - * Send presence packet. 1512 - * This will force the controller to resend connection packets. 1513 - * This is useful in the case we activate the module after the 1514 - * adapter has been plugged in, as it won't automatically 1515 - * send us info about the controllers. 1296 + * Wireless controllers require RESET_RESUME to work properly 1297 + * after suspend. Ideally this quirk should be in usb core 1298 + * quirk list, but we have too many vendors producing these 1299 + * controllers and we'd need to maintain 2 identical lists 1300 + * here in this driver and in usb core. 1516 1301 */ 1517 - error = xpad_inquiry_pad_presence(xpad); 1302 + udev->quirks |= USB_QUIRK_RESET_RESUME; 1303 + } else { 1304 + error = xpad_init_input(xpad); 1518 1305 if (error) 1519 - goto err_kill_in_urb; 1306 + goto err_deinit_output; 1520 1307 } 1521 1308 return 0; 1522 1309 1523 - err_kill_in_urb: 1524 - usb_kill_urb(xpad->irq_in); 1525 - err_deinit_input: 1526 - xpad_deinit_input(xpad); 1527 1310 err_deinit_output: 1528 1311 xpad_deinit_output(xpad); 1529 1312 err_free_in_urb: ··· 1529 1320 err_free_mem: 1530 1321 kfree(xpad); 1531 1322 return error; 1532 - 1533 1323 } 1534 1324 1535 1325 static void xpad_disconnect(struct usb_interface *intf) 1536 1326 { 1537 - struct usb_xpad *xpad = usb_get_intfdata (intf); 1327 + struct usb_xpad *xpad = usb_get_intfdata(intf); 1328 + 1329 + if (xpad->xtype == XTYPE_XBOX360W) 1330 + xpad360w_stop_input(xpad); 1538 1331 1539 1332 xpad_deinit_input(xpad); 1540 - xpad_deinit_output(xpad); 1541 1333 1542 - if (xpad->xtype == XTYPE_XBOX360W) { 1543 - usb_kill_urb(xpad->irq_in); 1544 - } 1334 + /* 1335 + * Now that both input device and LED device are gone we can 1336 + * stop output URB. 1337 + */ 1338 + xpad_stop_output(xpad); 1339 + 1340 + xpad_deinit_output(xpad); 1545 1341 1546 1342 usb_free_urb(xpad->irq_in); 1547 1343 usb_free_coherent(xpad->udev, XPAD_PKT_LEN, ··· 1557 1343 usb_set_intfdata(intf, NULL); 1558 1344 } 1559 1345 1346 + static int xpad_suspend(struct usb_interface *intf, pm_message_t message) 1347 + { 1348 + struct usb_xpad *xpad = usb_get_intfdata(intf); 1349 + struct input_dev *input = xpad->dev; 1350 + 1351 + if (xpad->xtype == XTYPE_XBOX360W) { 1352 + /* 1353 + * Wireless controllers always listen to input so 1354 + * they are notified when controller shows up 1355 + * or goes away. 1356 + */ 1357 + xpad360w_stop_input(xpad); 1358 + } else { 1359 + mutex_lock(&input->mutex); 1360 + if (input->users) 1361 + xpad_stop_input(xpad); 1362 + mutex_unlock(&input->mutex); 1363 + } 1364 + 1365 + xpad_stop_output(xpad); 1366 + 1367 + return 0; 1368 + } 1369 + 1370 + static int xpad_resume(struct usb_interface *intf) 1371 + { 1372 + struct usb_xpad *xpad = usb_get_intfdata(intf); 1373 + struct input_dev *input = xpad->dev; 1374 + int retval = 0; 1375 + 1376 + if (xpad->xtype == XTYPE_XBOX360W) { 1377 + retval = xpad360w_start_input(xpad); 1378 + } else { 1379 + mutex_lock(&input->mutex); 1380 + if (input->users) 1381 + retval = xpad_start_input(xpad); 1382 + mutex_unlock(&input->mutex); 1383 + } 1384 + 1385 + return retval; 1386 + } 1387 + 1560 1388 static struct usb_driver xpad_driver = { 1561 1389 .name = "xpad", 1562 1390 .probe = xpad_probe, 1563 1391 .disconnect = xpad_disconnect, 1392 + .suspend = xpad_suspend, 1393 + .resume = xpad_resume, 1394 + .reset_resume = xpad_resume, 1564 1395 .id_table = xpad_table, 1565 1396 }; 1566 1397
+4 -2
drivers/input/keyboard/gpio_keys.c
··· 630 630 if (!node) 631 631 return ERR_PTR(-ENODEV); 632 632 633 - nbuttons = of_get_child_count(node); 633 + nbuttons = of_get_available_child_count(node); 634 634 if (nbuttons == 0) 635 635 return ERR_PTR(-ENODEV); 636 636 ··· 645 645 646 646 pdata->rep = !!of_get_property(node, "autorepeat", NULL); 647 647 648 + of_property_read_string(node, "label", &pdata->name); 649 + 648 650 i = 0; 649 - for_each_child_of_node(node, pp) { 651 + for_each_available_child_of_node(node, pp) { 650 652 enum of_gpio_flags flags; 651 653 652 654 button = &pdata->buttons[i++];
+26 -42
drivers/input/touchscreen/atmel_mxt_ts.c
··· 113 113 #define MXT_T9_DETECT (1 << 7) 114 114 115 115 struct t9_range { 116 - u16 x; 117 - u16 y; 116 + __le16 x; 117 + __le16 y; 118 118 } __packed; 119 119 120 120 /* MXT_TOUCH_MULTI_T9 orient */ ··· 216 216 unsigned int irq; 217 217 unsigned int max_x; 218 218 unsigned int max_y; 219 + bool xy_switch; 219 220 bool in_bootloader; 220 221 u16 mem_size; 221 222 u8 t100_aux_ampl; ··· 1666 1665 if (error) 1667 1666 return error; 1668 1667 1669 - le16_to_cpus(&range.x); 1670 - le16_to_cpus(&range.y); 1668 + data->max_x = get_unaligned_le16(&range.x); 1669 + data->max_y = get_unaligned_le16(&range.y); 1671 1670 1672 1671 error = __mxt_read_reg(client, 1673 1672 object->start_address + MXT_T9_ORIENT, ··· 1675 1674 if (error) 1676 1675 return error; 1677 1676 1678 - /* Handle default values */ 1679 - if (range.x == 0) 1680 - range.x = 1023; 1681 - 1682 - if (range.y == 0) 1683 - range.y = 1023; 1684 - 1685 - if (orient & MXT_T9_ORIENT_SWITCH) { 1686 - data->max_x = range.y; 1687 - data->max_y = range.x; 1688 - } else { 1689 - data->max_x = range.x; 1690 - data->max_y = range.y; 1691 - } 1692 - 1693 - dev_dbg(&client->dev, 1694 - "Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1677 + data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; 1695 1678 1696 1679 return 0; 1697 1680 } ··· 1693 1708 if (!object) 1694 1709 return -EINVAL; 1695 1710 1711 + /* read touchscreen dimensions */ 1696 1712 error = __mxt_read_reg(client, 1697 1713 object->start_address + MXT_T100_XRANGE, 1698 1714 sizeof(range_x), &range_x); 1699 1715 if (error) 1700 1716 return error; 1701 1717 1702 - le16_to_cpus(&range_x); 1718 + data->max_x = get_unaligned_le16(&range_x); 1703 1719 1704 1720 error = __mxt_read_reg(client, 1705 1721 object->start_address + MXT_T100_YRANGE, ··· 1708 1722 if (error) 1709 1723 return error; 1710 1724 1711 - le16_to_cpus(&range_y); 1725 + data->max_y = get_unaligned_le16(&range_y); 1712 1726 1727 + /* read orientation config */ 1713 1728 error = __mxt_read_reg(client, 1714 1729 object->start_address + MXT_T100_CFG1, 1715 1730 1, &cfg); 1716 1731 if (error) 1717 1732 return error; 1718 1733 1734 + data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; 1735 + 1736 + /* allocate aux bytes */ 1719 1737 error = __mxt_read_reg(client, 1720 1738 object->start_address + MXT_T100_TCHAUX, 1721 1739 1, &tchaux); 1722 1740 if (error) 1723 1741 return error; 1724 1742 1725 - /* Handle default values */ 1726 - if (range_x == 0) 1727 - range_x = 1023; 1728 - 1729 - if (range_y == 0) 1730 - range_y = 1023; 1731 - 1732 - if (cfg & MXT_T100_CFG_SWITCHXY) { 1733 - data->max_x = range_y; 1734 - data->max_y = range_x; 1735 - } else { 1736 - data->max_x = range_x; 1737 - data->max_y = range_y; 1738 - } 1739 - 1740 - /* allocate aux bytes */ 1741 1743 aux = 6; 1742 1744 1743 1745 if (tchaux & MXT_T100_TCHAUX_VECT) ··· 1740 1766 dev_dbg(&client->dev, 1741 1767 "T100 aux mappings vect:%u ampl:%u area:%u\n", 1742 1768 data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area); 1743 - 1744 - dev_info(&client->dev, 1745 - "T100 Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1746 1769 1747 1770 return 0; 1748 1771 } ··· 1799 1828 return -EINVAL; 1800 1829 } 1801 1830 1831 + /* Handle default values and orientation switch */ 1832 + if (data->max_x == 0) 1833 + data->max_x = 1023; 1834 + 1835 + if (data->max_y == 0) 1836 + data->max_y = 1023; 1837 + 1838 + if (data->xy_switch) 1839 + swap(data->max_x, data->max_y); 1840 + 1841 + dev_info(dev, "Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1842 + 1843 + /* Register input device */ 1802 1844 input_dev = input_allocate_device(); 1803 1845 if (!input_dev) { 1804 1846 dev_err(dev, "Failed to allocate memory\n");