105
105
#define PKT_XBE2_FW_5_EARLY 3
106
106
#define PKT_XBE2_FW_5_11 4
107
107
108
+ #define FLAG_DELAY_INIT BIT(0)
109
+
108
110
static bool dpad_to_buttons ;
109
111
module_param (dpad_to_buttons , bool , S_IRUGO );
110
112
MODULE_PARM_DESC (dpad_to_buttons , "Map D-PAD to buttons rather than axes for unknown pads" );
@@ -127,6 +129,7 @@ static const struct xpad_device {
127
129
char * name ;
128
130
u8 mapping ;
129
131
u8 xtype ;
132
+ u8 flags ;
130
133
} xpad_device [] = {
131
134
/* Please keep this list sorted by vendor and product ID. */
132
135
{ 0x0079 , 0x18d4 , "GPD Win 2 X-Box Controller" , 0 , XTYPE_XBOX360 },
@@ -596,6 +599,7 @@ struct xboxone_init_packet {
596
599
* - https://github.com/medusalix/xone/blob/master/bus/protocol.c
597
600
*/
598
601
#define GIP_CMD_ACK 0x01
602
+ #define GIP_CMD_ANNOUNCE 0x02
599
603
#define GIP_CMD_IDENTIFY 0x04
600
604
#define GIP_CMD_POWER 0x05
601
605
#define GIP_CMD_AUTHENTICATE 0x06
@@ -785,10 +789,13 @@ struct usb_xpad {
785
789
const char * name ; /* name of the device */
786
790
struct work_struct work ; /* init/remove device from callback */
787
791
time64_t mode_btn_down_ts ;
792
+ bool delay_init ; /* init packets should be delayed */
793
+ bool delayed_init_done ;
788
794
};
789
795
790
796
static int xpad_init_input (struct usb_xpad * xpad );
791
797
static void xpad_deinit_input (struct usb_xpad * xpad );
798
+ static int xpad_start_input (struct usb_xpad * xpad );
792
799
static void xpadone_ack_mode_report (struct usb_xpad * xpad , u8 seq_num );
793
800
static void xpad360w_poweroff_controller (struct usb_xpad * xpad );
794
801
@@ -1073,6 +1080,17 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
1073
1080
1074
1081
do_sync = true;
1075
1082
}
1083
+ } else if (data [0 ] == GIP_CMD_ANNOUNCE ) {
1084
+ int error ;
1085
+
1086
+ if (xpad -> delay_init && !xpad -> delayed_init_done ) {
1087
+ xpad -> delayed_init_done = true;
1088
+ error = xpad_start_input (xpad );
1089
+ if (error )
1090
+ dev_warn (& xpad -> dev -> dev ,
1091
+ "unable to start delayed input: %d\n" ,
1092
+ error );
1093
+ }
1076
1094
} else if (data [0 ] == GIP_CMD_INPUT ) { /* The main valid packet type for inputs */
1077
1095
/* menu/view buttons */
1078
1096
input_report_key (dev , BTN_START , data [4 ] & BIT (2 ));
@@ -1251,6 +1269,14 @@ static bool xpad_prepare_next_init_packet(struct usb_xpad *xpad)
1251
1269
if (xpad -> xtype != XTYPE_XBOXONE )
1252
1270
return false;
1253
1271
1272
+ /*
1273
+ * Some dongles will discard init packets if they're sent before the
1274
+ * controller connects. In these cases, we need to wait until we get
1275
+ * an announce packet from them to send the init packet sequence.
1276
+ */
1277
+ if (xpad -> delay_init && !xpad -> delayed_init_done )
1278
+ return false;
1279
+
1254
1280
/* Perform initialization sequence for Xbox One pads that require it */
1255
1281
while (xpad -> init_seq < ARRAY_SIZE (xboxone_init_packets )) {
1256
1282
init_packet = & xboxone_init_packets [xpad -> init_seq ++ ];
@@ -2066,6 +2092,9 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
2066
2092
xpad -> mapping = xpad_device [i ].mapping ;
2067
2093
xpad -> xtype = xpad_device [i ].xtype ;
2068
2094
xpad -> name = xpad_device [i ].name ;
2095
+ if (xpad_device [i ].flags & FLAG_DELAY_INIT )
2096
+ xpad -> delay_init = true;
2097
+
2069
2098
xpad -> packet_type = PKT_XB ;
2070
2099
INIT_WORK (& xpad -> work , xpad_presence_work );
2071
2100
@@ -2265,6 +2294,7 @@ static int xpad_resume(struct usb_interface *intf)
2265
2294
struct usb_xpad * xpad = usb_get_intfdata (intf );
2266
2295
struct input_dev * input = xpad -> dev ;
2267
2296
2297
+ xpad -> delayed_init_done = false;
2268
2298
if (xpad -> xtype == XTYPE_XBOX360W )
2269
2299
return xpad360w_start_input (xpad );
2270
2300
0 commit comments