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.

Input: xpad - add support for XBOX One Elite paddles

An effort has been made to support every official model and firmware
version I could track down info on. The following controllers _should_
have working paddles with this PR:
- Xbox Elite (**untested**)
- Xbox Elite Series 2 on early firmwares (**untested**)
- Xbox Elite Series 2 on v4 firmwares (Tested v4.8.1908.0)
- Xbox Elite Series 2 on v5 pre-BLE firmwares (**untested**)
- Xbox Elite Series 2 on v5 post-BLE firmwares (Tested v5.13.3143.0)

This patch also introduces correct handling for the Elite 1 controller
and properly suppresses paddle inputs when using a custom profile slot.

Starting with firmware v5.11, certain inputs for the Elite 2 were moved
to an extra packet that is not enabled by default.

We must first manually enable this extra packet in order to correctly
process paddle input data with these later firmwares.

Signed-off-by: Christopher Crockett <chaorace@gmail.com>
Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
Tested-by: Bastien Nocera <hadess@hadess.net>
Link: https://lore.kernel.org/r/20220818154411.510308-5-rojtberg@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Christopher Crockett and committed by
Dmitry Torokhov
e23c69e3 da7e2128

+201 -69
+201 -69
drivers/input/joystick/xpad.c
··· 80 80 #define MAP_TRIGGERS_TO_BUTTONS (1 << 1) 81 81 #define MAP_STICKS_TO_NULL (1 << 2) 82 82 #define MAP_SELECT_BUTTON (1 << 3) 83 + #define MAP_PADDLES (1 << 4) 83 84 #define DANCEPAD_MAP_CONFIG (MAP_DPAD_TO_BUTTONS | \ 84 85 MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL) 85 86 ··· 94 93 * seconds 95 94 */ 96 95 #define XPAD360W_POWEROFF_TIMEOUT 5 96 + 97 + #define PKT_XB 0 98 + #define PKT_XBE1 1 99 + #define PKT_XBE2_FW_OLD 2 100 + #define PKT_XBE2_FW_5_EARLY 3 101 + #define PKT_XBE2_FW_5_11 4 97 102 98 103 static bool dpad_to_buttons; 99 104 module_param(dpad_to_buttons, bool, S_IRUGO); ··· 123 116 char *name; 124 117 u8 mapping; 125 118 u8 xtype; 119 + u8 packet_type; 126 120 } xpad_device[] = { 127 121 { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 }, 128 122 { 0x03eb, 0xff01, "Wooting One (Legacy)", 0, XTYPE_XBOX360 }, ··· 143 135 { 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 144 136 { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE }, 145 137 { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE }, 146 - { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE }, 138 + { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", MAP_PADDLES, XTYPE_XBOXONE }, 139 + { 0x045e, 0x0b00, "Microsoft X-Box One Elite 2 pad", MAP_PADDLES, XTYPE_XBOXONE }, 147 140 { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE }, 148 141 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 149 142 { 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE }, ··· 417 408 -1 418 409 }; 419 410 411 + /* used when the controller has extra paddle buttons */ 412 + static const signed short xpad_btn_paddles[] = { 413 + BTN_TRIGGER_HAPPY5, BTN_TRIGGER_HAPPY6, /* paddle upper right, lower right */ 414 + BTN_TRIGGER_HAPPY7, BTN_TRIGGER_HAPPY8, /* paddle upper left, lower left */ 415 + -1 /* terminating entry */ 416 + }; 417 + 420 418 /* 421 419 * Xbox 360 has a vendor-specific class, so we cannot match it with only 422 420 * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we ··· 533 517 }; 534 518 535 519 /* 520 + * This packet is required to get additional input data 521 + * from Xbox One Elite Series 2 (0x045e:0x0b00) pads. 522 + * We mostly do this right now to get paddle data 523 + */ 524 + static const u8 extra_input_packet_init[] = { 525 + 0x4d, 0x10, 0x01, 0x02, 0x07, 0x00 526 + }; 527 + 528 + /* 536 529 * This packet is required for the Titanfall 2 Xbox One pads 537 530 * (0x0e6f:0x0165) to finish initialization and for Hori pads 538 531 * (0x0f0d:0x0067) to make the analog sticks work. ··· 601 576 XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_fw2015_init), 602 577 XBOXONE_INIT_PKT(0x045e, 0x02ea, xboxone_s_init), 603 578 XBOXONE_INIT_PKT(0x045e, 0x0b00, xboxone_s_init), 579 + XBOXONE_INIT_PKT(0x045e, 0x0b00, extra_input_packet_init), 604 580 XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init1), 605 581 XBOXONE_INIT_PKT(0x0e6f, 0x0000, xboxone_pdp_init2), 606 582 XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init), ··· 658 632 659 633 int mapping; /* map d-pad to buttons or to axes */ 660 634 int xtype; /* type of xbox device */ 635 + int packet_type; /* type of the extended packet */ 661 636 int pad_nr; /* the order x360 pads were attached */ 662 637 const char *name; /* name of the device */ 663 638 struct work_struct work; /* init/remove device from callback */ ··· 916 889 static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) 917 890 { 918 891 struct input_dev *dev = xpad->dev; 892 + bool do_sync = false; 919 893 920 894 /* the xbox button has its own special report */ 921 895 if (data[0] == 0X07) { ··· 929 901 xpadone_ack_mode_report(xpad, data[2]); 930 902 931 903 input_report_key(dev, BTN_MODE, data[4] & 0x01); 904 + 905 + do_sync = true; 906 + } else if (data[0] == 0X0C) { 907 + /* Some packet formats force us to use this separate to poll paddle inputs */ 908 + if (xpad->packet_type == PKT_XBE2_FW_5_11) { 909 + /* Mute paddles if controller is in a custom profile slot 910 + * Checked by looking at the active profile slot to 911 + * verify it's the default slot 912 + */ 913 + if (data[19] != 0) 914 + data[18] = 0; 915 + 916 + /* Elite Series 2 split packet paddle bits */ 917 + input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & 0x01); 918 + input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & 0x02); 919 + input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & 0x04); 920 + input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & 0x08); 921 + 922 + do_sync = true; 923 + } 924 + } else if (data[0] == 0X20) { /* The main valid packet type for inputs */ 925 + /* menu/view buttons */ 926 + input_report_key(dev, BTN_START, data[4] & 0x04); 927 + input_report_key(dev, BTN_SELECT, data[4] & 0x08); 928 + if (xpad->mapping & MAP_SELECT_BUTTON) 929 + input_report_key(dev, KEY_RECORD, data[22] & 0x01); 930 + 931 + /* buttons A,B,X,Y */ 932 + input_report_key(dev, BTN_A, data[4] & 0x10); 933 + input_report_key(dev, BTN_B, data[4] & 0x20); 934 + input_report_key(dev, BTN_X, data[4] & 0x40); 935 + input_report_key(dev, BTN_Y, data[4] & 0x80); 936 + 937 + /* digital pad */ 938 + if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 939 + /* dpad as buttons (left, right, up, down) */ 940 + input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & 0x04); 941 + input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & 0x08); 942 + input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & 0x01); 943 + input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & 0x02); 944 + } else { 945 + input_report_abs(dev, ABS_HAT0X, 946 + !!(data[5] & 0x08) - !!(data[5] & 0x04)); 947 + input_report_abs(dev, ABS_HAT0Y, 948 + !!(data[5] & 0x02) - !!(data[5] & 0x01)); 949 + } 950 + 951 + /* TL/TR */ 952 + input_report_key(dev, BTN_TL, data[5] & 0x10); 953 + input_report_key(dev, BTN_TR, data[5] & 0x20); 954 + 955 + /* stick press left/right */ 956 + input_report_key(dev, BTN_THUMBL, data[5] & 0x40); 957 + input_report_key(dev, BTN_THUMBR, data[5] & 0x80); 958 + 959 + if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 960 + /* left stick */ 961 + input_report_abs(dev, ABS_X, 962 + (__s16) le16_to_cpup((__le16 *)(data + 10))); 963 + input_report_abs(dev, ABS_Y, 964 + ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 965 + 966 + /* right stick */ 967 + input_report_abs(dev, ABS_RX, 968 + (__s16) le16_to_cpup((__le16 *)(data + 14))); 969 + input_report_abs(dev, ABS_RY, 970 + ~(__s16) le16_to_cpup((__le16 *)(data + 16))); 971 + } 972 + 973 + /* triggers left/right */ 974 + if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 975 + input_report_key(dev, BTN_TL2, 976 + (__u16) le16_to_cpup((__le16 *)(data + 6))); 977 + input_report_key(dev, BTN_TR2, 978 + (__u16) le16_to_cpup((__le16 *)(data + 8))); 979 + } else { 980 + input_report_abs(dev, ABS_Z, 981 + (__u16) le16_to_cpup((__le16 *)(data + 6))); 982 + input_report_abs(dev, ABS_RZ, 983 + (__u16) le16_to_cpup((__le16 *)(data + 8))); 984 + } 985 + 986 + /* paddle handling */ 987 + /* based on SDL's SDL_hidapi_xboxone.c */ 988 + if (xpad->mapping & MAP_PADDLES) { 989 + if (xpad->packet_type == PKT_XBE1) { 990 + /* Mute paddles if controller has a custom mapping applied. 991 + * Checked by comparing the current mapping 992 + * config against the factory mapping config 993 + */ 994 + if (memcmp(&data[4], &data[18], 2) != 0) 995 + data[32] = 0; 996 + 997 + /* OG Elite Series Controller paddle bits */ 998 + input_report_key(dev, BTN_TRIGGER_HAPPY5, data[32] & 0x02); 999 + input_report_key(dev, BTN_TRIGGER_HAPPY6, data[32] & 0x08); 1000 + input_report_key(dev, BTN_TRIGGER_HAPPY7, data[32] & 0x01); 1001 + input_report_key(dev, BTN_TRIGGER_HAPPY8, data[32] & 0x04); 1002 + } else if (xpad->packet_type == PKT_XBE2_FW_OLD) { 1003 + /* Mute paddles if controller has a custom mapping applied. 1004 + * Checked by comparing the current mapping 1005 + * config against the factory mapping config 1006 + */ 1007 + if (data[19] != 0) 1008 + data[18] = 0; 1009 + 1010 + /* Elite Series 2 4.x firmware paddle bits */ 1011 + input_report_key(dev, BTN_TRIGGER_HAPPY5, data[18] & 0x01); 1012 + input_report_key(dev, BTN_TRIGGER_HAPPY6, data[18] & 0x02); 1013 + input_report_key(dev, BTN_TRIGGER_HAPPY7, data[18] & 0x04); 1014 + input_report_key(dev, BTN_TRIGGER_HAPPY8, data[18] & 0x08); 1015 + } else if (xpad->packet_type == PKT_XBE2_FW_5_EARLY) { 1016 + /* Mute paddles if controller has a custom mapping applied. 1017 + * Checked by comparing the current mapping 1018 + * config against the factory mapping config 1019 + */ 1020 + if (data[23] != 0) 1021 + data[22] = 0; 1022 + 1023 + /* Elite Series 2 5.x firmware paddle bits 1024 + * (before the packet was split) 1025 + */ 1026 + input_report_key(dev, BTN_TRIGGER_HAPPY5, data[22] & 0x01); 1027 + input_report_key(dev, BTN_TRIGGER_HAPPY6, data[22] & 0x02); 1028 + input_report_key(dev, BTN_TRIGGER_HAPPY7, data[22] & 0x04); 1029 + input_report_key(dev, BTN_TRIGGER_HAPPY8, data[22] & 0x08); 1030 + } 1031 + } 1032 + 1033 + do_sync = true; 1034 + } 1035 + 1036 + if (do_sync) 932 1037 input_sync(dev); 933 - return; 934 - } 935 - /* check invalid packet */ 936 - else if (data[0] != 0X20) 937 - return; 938 - 939 - /* menu/view buttons */ 940 - input_report_key(dev, BTN_START, data[4] & 0x04); 941 - input_report_key(dev, BTN_SELECT, data[4] & 0x08); 942 - if (xpad->mapping & MAP_SELECT_BUTTON) 943 - input_report_key(dev, KEY_RECORD, data[22] & 0x01); 944 - 945 - /* buttons A,B,X,Y */ 946 - input_report_key(dev, BTN_A, data[4] & 0x10); 947 - input_report_key(dev, BTN_B, data[4] & 0x20); 948 - input_report_key(dev, BTN_X, data[4] & 0x40); 949 - input_report_key(dev, BTN_Y, data[4] & 0x80); 950 - 951 - /* digital pad */ 952 - if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { 953 - /* dpad as buttons (left, right, up, down) */ 954 - input_report_key(dev, BTN_TRIGGER_HAPPY1, data[5] & 0x04); 955 - input_report_key(dev, BTN_TRIGGER_HAPPY2, data[5] & 0x08); 956 - input_report_key(dev, BTN_TRIGGER_HAPPY3, data[5] & 0x01); 957 - input_report_key(dev, BTN_TRIGGER_HAPPY4, data[5] & 0x02); 958 - } else { 959 - input_report_abs(dev, ABS_HAT0X, 960 - !!(data[5] & 0x08) - !!(data[5] & 0x04)); 961 - input_report_abs(dev, ABS_HAT0Y, 962 - !!(data[5] & 0x02) - !!(data[5] & 0x01)); 963 - } 964 - 965 - /* TL/TR */ 966 - input_report_key(dev, BTN_TL, data[5] & 0x10); 967 - input_report_key(dev, BTN_TR, data[5] & 0x20); 968 - 969 - /* stick press left/right */ 970 - input_report_key(dev, BTN_THUMBL, data[5] & 0x40); 971 - input_report_key(dev, BTN_THUMBR, data[5] & 0x80); 972 - 973 - if (!(xpad->mapping & MAP_STICKS_TO_NULL)) { 974 - /* left stick */ 975 - input_report_abs(dev, ABS_X, 976 - (__s16) le16_to_cpup((__le16 *)(data + 10))); 977 - input_report_abs(dev, ABS_Y, 978 - ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 979 - 980 - /* right stick */ 981 - input_report_abs(dev, ABS_RX, 982 - (__s16) le16_to_cpup((__le16 *)(data + 14))); 983 - input_report_abs(dev, ABS_RY, 984 - ~(__s16) le16_to_cpup((__le16 *)(data + 16))); 985 - } 986 - 987 - /* triggers left/right */ 988 - if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { 989 - input_report_key(dev, BTN_TL2, 990 - (__u16) le16_to_cpup((__le16 *)(data + 6))); 991 - input_report_key(dev, BTN_TR2, 992 - (__u16) le16_to_cpup((__le16 *)(data + 8))); 993 - } else { 994 - input_report_abs(dev, ABS_Z, 995 - (__u16) le16_to_cpup((__le16 *)(data + 6))); 996 - input_report_abs(dev, ABS_RZ, 997 - (__u16) le16_to_cpup((__le16 *)(data + 8))); 998 - } 999 - 1000 - input_sync(dev); 1001 1038 } 1002 1039 1003 1040 static void xpad_irq_in(struct urb *urb) ··· 1829 1736 xpad_btn_pad[i]); 1830 1737 } 1831 1738 1739 + /* set up paddles if the controller has them */ 1740 + if (xpad->mapping & MAP_PADDLES) { 1741 + for (i = 0; xpad_btn_paddles[i] >= 0; i++) 1742 + input_set_capability(input_dev, EV_KEY, xpad_btn_paddles[i]); 1743 + } 1744 + 1832 1745 /* 1833 1746 * This should be a simple else block. However historically 1834 1747 * xbox360w has mapped DPAD to buttons while xbox360 did not. This ··· 1921 1822 xpad->mapping = xpad_device[i].mapping; 1922 1823 xpad->xtype = xpad_device[i].xtype; 1923 1824 xpad->name = xpad_device[i].name; 1825 + xpad->packet_type = PKT_XB; 1924 1826 INIT_WORK(&xpad->work, xpad_presence_work); 1925 1827 1926 1828 if (xpad->xtype == XTYPE_UNKNOWN) { ··· 1986 1886 xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1987 1887 1988 1888 usb_set_intfdata(intf, xpad); 1889 + 1890 + /* Packet type detection */ 1891 + if (le16_to_cpu(udev->descriptor.idVendor) == 0x045e) { /* Microsoft controllers */ 1892 + if (le16_to_cpu(udev->descriptor.idProduct) == 0x02e3) { 1893 + /* The original elite controller always uses the oldest 1894 + * type of extended packet 1895 + */ 1896 + xpad->packet_type = PKT_XBE1; 1897 + } else if (le16_to_cpu(udev->descriptor.idProduct) == 0x0b00) { 1898 + /* The elite 2 controller has seen multiple packet 1899 + * revisions. These are tied to specific firmware 1900 + * versions 1901 + */ 1902 + if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x0500) { 1903 + /* This is the format that the Elite 2 used 1904 + * prior to the BLE update 1905 + */ 1906 + xpad->packet_type = PKT_XBE2_FW_OLD; 1907 + } else if (le16_to_cpu(udev->descriptor.bcdDevice) < 1908 + 0x050b) { 1909 + /* This is the format that the Elite 2 used 1910 + * prior to the update that split the packet 1911 + */ 1912 + xpad->packet_type = PKT_XBE2_FW_5_EARLY; 1913 + } else { 1914 + /* The split packet format that was introduced 1915 + * in firmware v5.11 1916 + */ 1917 + xpad->packet_type = PKT_XBE2_FW_5_11; 1918 + } 1919 + } 1920 + } 1989 1921 1990 1922 if (xpad->xtype == XTYPE_XBOX360W) { 1991 1923 /*