Skip to contentSkip to conversation

Input: xbox_gip - Add new driver for Xbox GIP

PATCH Superseded Vicki Pfau 3 participants 10 messages Aug 8, 2025 – Aug 11, 2025

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Vicki Pfau

author
#0 lore raw

cover Input: xbox_gip - Add new driver for Xbox GIP

This introduces a new driver for the Xbox One/Series controller protocol, officially known as the Gaming Input Protocol, or GIP for short.

Microsoft released documentation on (some of) GIP in late 2024, upon which this driver is based. Though the documentation was incomplete, it still provided enough information to warrant a clean start over the previous, incomplete implementation.

This driver is already at feature parity with the GIP support in xpad, along with several more enhancements:

- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters, including the presence and location in the message of the share button, as well as detection of specific device types
- Controllable LED support
- HID passthrough for the Chatpad
- Preliminary support for racing wheels and flight sticks

The framework set out in this driver also allows future expansion for specialized device types and additional features more cleanly than xpad.

Future plans include:

- Improved support for racing wheels and flight sticks, including force feedback and LED support.
- Support for the security handshake, which is required for devices that use wireless dongles.
- Exposing a raw character device to enable sending vendor-specific commands from userspace.
- Event logging to either sysfs or dmesg.
- Support for the headphone jack.

Also included in this series is the addition of three new ABS input types, with the two relevant ones to HID added to the mappings

Vicki Pfau (6):
Input: xbox_gip - Add new driver for Xbox GIP
Input: xpad - Remove Xbox One support
Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
HID: Map more automobile simulation inputs
Input: xbox_gip - Add wheel support
Input: xbox_gip - Add flight stick support

 Documentation/input/devices/xpad.rst   |   17 +-
 MAINTAINERS                            |    6 +
 drivers/hid/hid-debug.c                |   16 +-
 drivers/hid/hid-input.c                |    2 +
 drivers/input/joystick/Kconfig         |   26 +
 drivers/input/joystick/Makefile        |    1 +
 drivers/input/joystick/xbox_gip.c      | 3434 ++++++++++++++++++++++++
 drivers/input/joystick/xpad.c          |  634 +----
 include/uapi/linux/input-event-codes.h |    3 +
 9 files changed, 3492 insertions(+), 647 deletions(-)
 create mode 100644 drivers/input/joystick/xbox_gip.c
Signature · 1 line
2.50.1
author
#1 lore raw

PATCH 1/6 Input: xbox_gip - Add new driver for Xbox GIP

This introduces a new driver for the Xbox One/Series controller protocol, officially known as the Gaming Input Protocol, or GIP for short.

Microsoft released documentation on (some of) GIP in late 2024, upon which this driver is based. Though the documentation was incomplete, it still provided enough information to warrant a clean start over the previous, incomplete implementation.

This driver is already at feature parity with the GIP support in xpad, along with several more enhancements:

- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters, including the presence and location in the message of the share button, as well as detection of specific device types
- Controllable LED support
- HID passthrough for the Chatpad

The framework set out in this driver also allows future expansion for specialized device types and additional features more cleanly than xpad.

Future plans include:

- Adding support for more device types, such as racing wheels and flight sticks.
- Support for the security handshake, which is required for devices that use wireless dongles.
- Exposing a raw character device to enable sending vendor-specific commands from userspace.
- Event logging to either sysfs or dmesg.
- Support for the headphone jack.

---
 MAINTAINERS                       |    6 +
 drivers/input/joystick/Kconfig    |   26 +
 drivers/input/joystick/Makefile   |    1 +
 drivers/input/joystick/xbox_gip.c | 3121 +++++++++++++++++++++++++++++
 4 files changed, 3154 insertions(+)
 create mode 100644 drivers/input/joystick/xbox_gip.c
MAINTAINERS +6 -0
index c0b444e5fd5ad..0088831b7f717 100644
@@ -26993,6 +26993,12 @@ S:	Maintained
 F:	drivers/media/rc/keymaps/rc-xbox-dvd.c
 F:	drivers/media/rc/xbox_remote.c
 
+XBOX GIP
+M:	Vicki Pfau <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/input/joystick/xbox_gip.c
+
 XC2028/3028 TUNER DRIVER
 M:	Mauro Carvalho Chehab <[email protected]>
 L:	[email protected]
drivers/input/joystick/Kconfig +26 -0
index 7755e5b454d2c..609edc8d78c5d 100644
@@ -291,6 +291,32 @@ config JOYSTICK_JOYDUMP
 	  To compile this driver as a module, choose M here: the
 	  module will be called joydump.
 
+config JOYSTICK_XBOX_GIP
+	tristate "Xbox One/Series controller support"
+	depends on USB_ARCH_HAS_HCD
+	select USB
+	help
+	  Say Y here if you want to use Xbox One and Series controllers with your
+	  computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
+	  and/or "Event interface support" (CONFIG_INPUT_EVDEV) as well.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called xbox_gip.
+
+config JOYSTICK_XBOX_GIP_FF
+	bool "Xbox One/Series controller rumble support"
+	depends on JOYSTICK_XBOX_GIP && INPUT
+	select INPUT_FF_MEMLESS
+	help
+	  Say Y here if you want to take advantage of Xbox One/Series rumble.
+
+config JOYSTICK_XBOX_GIP_LEDS
+	bool "LED Support for the Xbox One/Series controller Guide button"
+	depends on JOYSTICK_XBOX_GIP && LEDS_CLASS_MULTICOLOR
+	help
+	  This option enables support for the LED which surrounds the Big X on
+	  Xbox One/Series controllers.
+
 config JOYSTICK_XPAD
 	tristate "Xbox gamepad support"
 	depends on USB_ARCH_HAS_HCD
drivers/input/joystick/Makefile +1 -0
index 9976f596a9208..ad92f1b64b96a 100644
@@ -39,5 +39,6 @@ obj-$(CONFIG_JOYSTICK_TURBOGRAFX)	+= turbografx.o
 obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
 obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
 obj-$(CONFIG_JOYSTICK_WALKERA0701)	+= walkera0701.o
+obj-$(CONFIG_JOYSTICK_XBOX_GIP)		+= xbox_gip.o
 obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
 obj-$(CONFIG_JOYSTICK_ZHENHUA)		+= zhenhua.o
drivers/input/joystick/xbox_gip.c new file +3121 -0

2,950 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.50.1

Part of the diff is not shown here. View the raw message.

author
#2 lore raw

PATCH 2/6 Input: xpad - Remove Xbox One support

In reply to Vicki Pfau

It has been superseded by xbox_gip. As the new driver is already at feature parity, removing the fairly rough Xbox One support from xpad is safe and will prevent any potential conflicts.

---
 Documentation/input/devices/xpad.rst |  17 +-
 drivers/input/joystick/xpad.c        | 634 +--------------------------
 2 files changed, 11 insertions(+), 640 deletions(-)
Documentation/input/devices/xpad.rst +7 -10
index a480bc781565e..fd2afdd7b4059 100644
@@ -2,19 +2,19 @@
 xpad - Linux USB driver for Xbox compatible controllers
 =======================================================
 
-This driver exposes all first-party and third-party Xbox compatible
-controllers. It has a long history and has enjoyed considerable usage
-as Windows' xinput library caused most PC games to focus on Xbox
-controller compatibility.
+This driver exposes all first-party and third-party Xbox and Xbox 360
+compatible controllers. It has a long history and has enjoyed considerable
+usage as Windows' xinput library caused most PC games to focus on Xbox
+controller compatibility. Xbox One/Series controller support has been
+superseded by the xbox_gip driver, which specializes in the Gaming Input
+Protocl that is introduced on the Xbox One.
 
 Due to backwards compatibility all buttons are reported as digital.
 This only affects Original Xbox controllers. All later controller models
 have only digital face buttons.
 
 Rumble is supported on some models of Xbox 360 controllers but not of
-Original Xbox controllers nor on Xbox One controllers. As of writing
-the Xbox One's rumble protocol has not been reverse-engineered but in
-the future could be supported.
+Original Xbox controllers.
 
 
 Notes
@@ -98,9 +98,6 @@ All generations of Xbox controllers speak USB over the wire.
 - Wireless Xbox 360 controllers require a 'Xbox 360 Wireless Gaming Receiver
   for Windows'
 - Wired Xbox 360 controllers use standard USB connectors.
-- Xbox One controllers can be wireless but speak Wi-Fi Direct and are not
-  yet supported.
-- Xbox One controllers can be wired and use standard Micro-USB connectors.
 
 
 
drivers/input/joystick/xpad.c +4 -630

928 lines not on this page · raw message

Signature · 1 line
2.50.1
author
#3 lore raw

PATCH 3/6 Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER

In reply to Vicki Pfau

Add new absolute axes for racing game controllers

---
 drivers/hid/hid-debug.c                | 16 +++++++++-------
 include/uapi/linux/input-event-codes.h |  3 +++
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/hid/hid-debug.c +9 -7
index 264eefaed08fb..534df8e4082da 100644
@@ -3505,13 +3505,15 @@ static const char *absolutes[ABS_CNT] = {
 	[ABS_RY] = "Ry",		[ABS_RZ] = "Rz",
 	[ABS_THROTTLE] = "Throttle",	[ABS_RUDDER] = "Rudder",
 	[ABS_WHEEL] = "Wheel",		[ABS_GAS] = "Gas",
-	[ABS_BRAKE] = "Brake",		[ABS_HAT0X] = "Hat0X",
-	[ABS_HAT0Y] = "Hat0Y",		[ABS_HAT1X] = "Hat1X",
-	[ABS_HAT1Y] = "Hat1Y",		[ABS_HAT2X] = "Hat2X",
-	[ABS_HAT2Y] = "Hat2Y",		[ABS_HAT3X] = "Hat3X",
-	[ABS_HAT3Y] = "Hat 3Y",		[ABS_PRESSURE] = "Pressure",
-	[ABS_DISTANCE] = "Distance",	[ABS_TILT_X] = "XTilt",
-	[ABS_TILT_Y] = "YTilt",		[ABS_TOOL_WIDTH] = "ToolWidth",
+	[ABS_BRAKE] = "Brake",		[ABS_CLUTCH] = "Clutch",
+	[ABS_HANDBRAKE] = "Handbrake",	[ABS_SHIFTER] = "Shifter",
+	[ABS_HAT0X] = "Hat0X",		[ABS_HAT0Y] = "Hat0Y",
+	[ABS_HAT1X] = "Hat1X",		[ABS_HAT1Y] = "Hat1Y",
+	[ABS_HAT2X] = "Hat2X",		[ABS_HAT2Y] = "Hat2Y",
+	[ABS_HAT3X] = "Hat3X",		[ABS_HAT3Y] = "Hat3Y",
+	[ABS_PRESSURE] = "Pressure",	[ABS_DISTANCE] = "Distance",
+	[ABS_TILT_X] = "XTilt",		[ABS_TILT_Y] = "YTilt",
+	[ABS_TOOL_WIDTH] = "ToolWidth",
 	[ABS_VOLUME] = "Volume",	[ABS_PROFILE] = "Profile",
 	[ABS_MISC] = "Misc",
 	[ABS_MT_SLOT] = "MTSlot",
include/uapi/linux/input-event-codes.h +3 -0
index 08cb157ab5936..195139e895ffb 100644
@@ -859,6 +859,9 @@
 #define ABS_WHEEL		0x08
 #define ABS_GAS			0x09
 #define ABS_BRAKE		0x0a
+#define ABS_CLUTCH		0x0b
+#define ABS_HANDBRAKE		0x0c
+#define ABS_SHIFTER		0x0d
 #define ABS_HAT0X		0x10
 #define ABS_HAT0Y		0x11
 #define ABS_HAT1X		0x12
Signature · 1 line
2.50.1
maintainer
#4 lore raw

Re: [PATCH 3/6] Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER

Quoted 40 lines · Vicki Pfau

Add new absolute axes for racing game controllers

---
 drivers/hid/hid-debug.c                | 16 +++++++++-------
 include/uapi/linux/input-event-codes.h |  3 +++
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/hid/hid-debug.c +9 -7
index 264eefaed08fb..534df8e4082da 100644
@@ -3505,13 +3505,15 @@ static const char *absolutes[ABS_CNT] = {
 	[ABS_RY] = "Ry",		[ABS_RZ] = "Rz",
 	[ABS_THROTTLE] = "Throttle",	[ABS_RUDDER] = "Rudder",
 	[ABS_WHEEL] = "Wheel",		[ABS_GAS] = "Gas",
-	[ABS_BRAKE] = "Brake",		[ABS_HAT0X] = "Hat0X",
-	[ABS_HAT0Y] = "Hat0Y",		[ABS_HAT1X] = "Hat1X",
-	[ABS_HAT1Y] = "Hat1Y",		[ABS_HAT2X] = "Hat2X",
-	[ABS_HAT2Y] = "Hat2Y",		[ABS_HAT3X] = "Hat3X",
-	[ABS_HAT3Y] = "Hat 3Y",		[ABS_PRESSURE] = "Pressure",
-	[ABS_DISTANCE] = "Distance",	[ABS_TILT_X] = "XTilt",
-	[ABS_TILT_Y] = "YTilt",		[ABS_TOOL_WIDTH] = "ToolWidth",
+	[ABS_BRAKE] = "Brake",		[ABS_CLUTCH] = "Clutch",
+	[ABS_HANDBRAKE] = "Handbrake",	[ABS_SHIFTER] = "Shifter",
+	[ABS_HAT0X] = "Hat0X",		[ABS_HAT0Y] = "Hat0Y",
+	[ABS_HAT1X] = "Hat1X",		[ABS_HAT1Y] = "Hat1Y",
+	[ABS_HAT2X] = "Hat2X",		[ABS_HAT2Y] = "Hat2Y",
+	[ABS_HAT3X] = "Hat3X",		[ABS_HAT3Y] = "Hat3Y",
+	[ABS_PRESSURE] = "Pressure",	[ABS_DISTANCE] = "Distance",
+	[ABS_TILT_X] = "XTilt",		[ABS_TILT_Y] = "YTilt",
+	[ABS_TOOL_WIDTH] = "ToolWidth",
 	[ABS_VOLUME] = "Volume",	[ABS_PROFILE] = "Profile",
 	[ABS_MISC] = "Misc",
 	[ABS_MT_SLOT] = "MTSlot",
include/uapi/linux/input-event-codes.h +0 -0
index 08cb157ab5936..195139e895ffb 100644

include/uapi/linux/input-event-codes.h line 864

Quoted 6 lines
include/uapi/linux/input-event-codes.h +3 -0
@@ -859,6 +859,9 @@
 #define ABS_WHEEL		0x08
 #define ABS_GAS			0x09
 #define ABS_BRAKE		0x0a
+#define ABS_CLUTCH		0x0b
+#define ABS_HANDBRAKE		0x0c
+#define ABS_SHIFTER		0x0d

We have BTN_GEAR_UP and BTN_GEAR_DOWN, can they be used?

Thanks.

Signature · 1 line
Dmitry
author
#5 lore raw

Re: [PATCH 3/6] Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER

Quoted 41 lines · Dmitry Torokhov
Quoted 40 lines · Vicki Pfau

Add new absolute axes for racing game controllers

---
 drivers/hid/hid-debug.c                | 16 +++++++++-------
 include/uapi/linux/input-event-codes.h |  3 +++
 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/hid/hid-debug.c +9 -7
index 264eefaed08fb..534df8e4082da 100644
@@ -3505,13 +3505,15 @@ static const char *absolutes[ABS_CNT] = {
 	[ABS_RY] = "Ry",		[ABS_RZ] = "Rz",
 	[ABS_THROTTLE] = "Throttle",	[ABS_RUDDER] = "Rudder",
 	[ABS_WHEEL] = "Wheel",		[ABS_GAS] = "Gas",
-	[ABS_BRAKE] = "Brake",		[ABS_HAT0X] = "Hat0X",
-	[ABS_HAT0Y] = "Hat0Y",		[ABS_HAT1X] = "Hat1X",
-	[ABS_HAT1Y] = "Hat1Y",		[ABS_HAT2X] = "Hat2X",
-	[ABS_HAT2Y] = "Hat2Y",		[ABS_HAT3X] = "Hat3X",
-	[ABS_HAT3Y] = "Hat 3Y",		[ABS_PRESSURE] = "Pressure",
-	[ABS_DISTANCE] = "Distance",	[ABS_TILT_X] = "XTilt",
-	[ABS_TILT_Y] = "YTilt",		[ABS_TOOL_WIDTH] = "ToolWidth",
+	[ABS_BRAKE] = "Brake",		[ABS_CLUTCH] = "Clutch",
+	[ABS_HANDBRAKE] = "Handbrake",	[ABS_SHIFTER] = "Shifter",
+	[ABS_HAT0X] = "Hat0X",		[ABS_HAT0Y] = "Hat0Y",
+	[ABS_HAT1X] = "Hat1X",		[ABS_HAT1Y] = "Hat1Y",
+	[ABS_HAT2X] = "Hat2X",		[ABS_HAT2Y] = "Hat2Y",
+	[ABS_HAT3X] = "Hat3X",		[ABS_HAT3Y] = "Hat3Y",
+	[ABS_PRESSURE] = "Pressure",	[ABS_DISTANCE] = "Distance",
+	[ABS_TILT_X] = "XTilt",		[ABS_TILT_Y] = "YTilt",
+	[ABS_TOOL_WIDTH] = "ToolWidth",
 	[ABS_VOLUME] = "Volume",	[ABS_PROFILE] = "Profile",
 	[ABS_MISC] = "Misc",
 	[ABS_MT_SLOT] = "MTSlot",
include/uapi/linux/input-event-codes.h +0 -0
index 08cb157ab5936..195139e895ffb 100644
@@ -859,6 +859,9 @@
Quoted 8 lines

include/uapi/linux/input-event-codes.h line 864

Quoted 6 lines
include/uapi/linux/input-event-codes.h +3 -0
 #define ABS_WHEEL		0x08
 #define ABS_GAS			0x09
 #define ABS_BRAKE		0x0a
+#define ABS_CLUTCH		0x0b
+#define ABS_HANDBRAKE		0x0c
+#define ABS_SHIFTER		0x0d

We have BTN_GEAR_UP and BTN_GEAR_DOWN, can they be used?

The controller reports absolute values, not relative. If it were relative, BTN_GEAR_UP and BTN_GEAR_DOWN might make sense.

That said, I've been rethinking how to do mapping on both the wheel and flight stick, so I'm probably going go back to the drawing board on those. Feedback would still be nice, but I think the only one of these that might be mergeable as is is patch 1 (patch 2 was made against 6.16 by accident and does not apply to master). The shifter on Windows presents as individual buttons, one per gear, which is weird...but it's what games expect. Likewise, the dial presents as two buttons for the two relative values. I thought these methods were nonsensical (and I still do), but for compatibility reasons it might be better.

Quoted 3 lines

Thanks.

author
#6 lore raw

PATCH 4/6 HID: Map more automobile simulation inputs

In reply to Vicki Pfau

The HID usage tables section 5.3 specify clutch and shifter values that had previously been ignored. As the ABS_CLUTCH and ABS_SHIFTER bits now exist, we should use them appropriately.

---
 drivers/hid/hid-input.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hid/hid-input.c +2 -0
index ff1784b5c2a47..adcffbcb30834 100644
@@ -782,6 +782,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
 		case 0xbb: map_abs(ABS_THROTTLE); break;
 		case 0xc4: map_abs(ABS_GAS);      break;
 		case 0xc5: map_abs(ABS_BRAKE);    break;
+		case 0xc6: map_abs(ABS_CLUTCH);   break;
+		case 0xc7: map_abs(ABS_SHIFTER);  break;
 		case 0xc8: map_abs(ABS_WHEEL);    break;
 		default:   goto ignore;
 		}
Signature · 1 line
2.50.1
maintainer Acked-by on v1 4/6
#7 lore raw

Re: [PATCH 4/6] HID: Map more automobile simulation inputs

Quoted 5 lines · Vicki Pfau

The HID usage tables section 5.3 specify clutch and shifter values that had previously been ignored. As the ABS_CLUTCH and ABS_SHIFTER bits now exist, we should use them appropriately.

FWIW

so that it could be merged together with the rest of the series.

Signature · 2 lines
Jiri Kosina
SUSE Labs
author
#8 lore raw

PATCH 5/6 Input: xbox_gip - Add wheel support

In reply to Vicki Pfau

This adds preliminary support for racing wheel support in xbox_gip, exposing them mapped to the newly added axes.

---
 drivers/input/joystick/xbox_gip.c | 209 ++++++++++++++++++++++++++++--
 1 file changed, 201 insertions(+), 8 deletions(-)
drivers/input/joystick/xbox_gip.c +201 -8
index afb70311c064e..874705a9b6bfb 100644
@@ -10,7 +10,7 @@
  * - Event logging
  * - Sending fragmented messages
  * - Raw character device
- * - Wheel support
+ * - Wheel force feedback
  * - Flight stick support
  * - More arcade stick testing
  * - Arcade stick extra buttons
@@ -219,6 +219,22 @@
 #define GIP_EXTENDED_STATUS_ACCESS_DENIED	3
 #define GIP_EXTENDED_STATUS_FAILED		4
 
+/* Wheel-specific flags */
+#define GIP_WHEEL_HAS_POWER		BIT(3)
+#define GIP_WHEEL_HANDBRAKE_CONN	BIT(4)
+#define GIP_WHEEL_CLUTCH_CONN		BIT(5)
+#define GIP_WHEEL_BRAKE_CONN		BIT(6)
+#define GIP_WHEEL_THROTTLE_CONN		BIT(7)
+
+#define GIP_HSHIFTER_NONE	0
+#define GIP_HSHIFTER_2POS	1 /* 2 position, no neutral */
+#define GIP_HSHIFTER_2POS_N	2 /* 2 position, neutral */
+#define GIP_HSHIFTER_RTL_1TL	3 /* Reverse top left, first top left */
+#define GIP_HSHIFTER_RTL_1BL	4 /* Reverse top left, first bottom left */
+#define GIP_HSHIFTER_RBL	5 /* Reverse bottom left */
+#define GIP_HSHIFTER_RTR	6 /* Reverse top right */
+#define GIP_HSHIFTER_RBR	7 /* Reverse bottom right */
+
 /* Internal constants, not part of protocol */
 #define GIP_DEFAULT_IN_SYSTEM_MESSAGES 0x5e
 #define GIP_DEFAULT_OUT_SYSTEM_MESSAGES 0x472
@@ -234,6 +250,8 @@
 
 #define GIP_QUIRK_NO_HELLO		BIT(0)
 #define GIP_QUIRK_NO_IMPULSE_VIBRATION	BIT(1)
+#define GIP_QUIRK_FORCE_GAMEPAD_SB	BIT(2)
+#define GIP_QUIRK_WHEEL_FORCE_HANDBRAKE	BIT(31)
 
 #define GIP_LED_GUIDE_MAX_BRIGHTNESS	100 /* Spec says 47, but larger values work */
 #define GIP_LED_GUIDE_INIT_BRIGHTNESS	20
@@ -276,6 +294,11 @@ enum gip_elite_button_format {
 	GIP_BTN_FMT_XBE2_5,
 };
 
+enum gip_vendor_type {
+	GIP_VENDOR_NONE = 0,
+	GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL = 1,
+};
+
 static const guid_t guid_arcade_stick =
 	GUID_INIT(0x332054cc, 0xa34b, 0x41d5, 0xa3, 0x4a, 0xa6, 0xa6, 0x71, 0x1e, 0xc4, 0xb3);
 static const guid_t guid_console_function_map =
@@ -354,6 +377,18 @@ static const struct gip_audio_format gip_audio_format_table[MAX_GIP_AUDIO_FORMAT
 	[GIP_AUDIO_FORMAT_48000HZ_8CH] = { .rate = 48000, .channels = 8 },
 };
 
+struct gip_wheel_info {
+	uint8_t connections;
+	uint8_t shifter_type: 3;
+	uint8_t max_gear: 5;
+	uint16_t angle_setting;
+	uint16_t max_angle;
+	uint16_t max_throttle;
+	uint16_t max_brake;
+	uint16_t max_clutch;
+	uint8_t max_handbrake;
+};
+
 struct gip_quirks {
 	uint16_t vendor_id;
 	uint16_t product_id;
@@ -370,6 +405,11 @@ struct gip_quirks {
 };
 
 static const struct gip_quirks quirks[] = {
+	/* Thrustmaster T128X GIP Racing Wheel */
+	{ 0x044f, 0xb69c, 0,
+		.quirks = GIP_QUIRK_FORCE_GAMEPAD_SB | GIP_QUIRK_WHEEL_FORCE_HANDBRAKE,
+		.device_type = GIP_TYPE_WHEEL },
+
 	/* Xbox One Controller (model 1573) */
 	{ 0x045e, 0x02d1, 0, .override_name = "Xbox One Controller" },
 
@@ -497,11 +537,14 @@ struct gip_attachment {
 	enum gip_elite_button_format xbe_format;
 	uint32_t features;
 	uint32_t quirks;
+	enum gip_vendor_type vendor_type;
 
 	int extra_buttons;
 	int extra_axes;
 
 	bool dpad_as_buttons;
+	struct gip_wheel_info wheel;
+	int8_t logi_dial_state;
 	struct hid_device *hdev;
 };
 
@@ -1573,10 +1616,44 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
 		input_set_capability(input, EV_KEY, BTN_THUMBR);
 		input_set_capability(input, EV_KEY, BTN_THUMBL);
 		break;
-	case GIP_TYPE_FLIGHT_STICK:
 	case GIP_TYPE_WHEEL:
+		input_set_abs_params(input, ABS_WHEEL,
+			-attachment->wheel.max_angle - 1,
+			attachment->wheel.max_angle, 0, 0);
+		input_abs_set_res(input, ABS_WHEEL, attachment->wheel.angle_setting);
+		if (attachment->wheel.max_throttle)
+			input_set_abs_params(input, ABS_GAS, 0,
+				attachment->wheel.max_throttle, 0, 0);
+
+		if (attachment->wheel.max_brake)
+			input_set_abs_params(input, ABS_BRAKE, 0,
+				attachment->wheel.max_brake, 0, 0);
+
+		if (attachment->wheel.max_clutch)
+			input_set_abs_params(input, ABS_CLUTCH, 0,
+				attachment->wheel.max_clutch, 0, 0);
+
+		if (attachment->wheel.max_handbrake)
+			input_set_abs_params(input, ABS_HANDBRAKE, 0,
+				attachment->wheel.max_handbrake, 0, 0);
+
+		if (attachment->wheel.shifter_type)
+			input_set_abs_params(input, ABS_SHIFTER, -1,
+				attachment->wheel.max_gear, 0, 0);
+
+
+		if (attachment->vendor_type == GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL) {
+			input_set_capability(input, EV_KEY, BTN_THUMBL);
+			input_set_capability(input, EV_KEY, BTN_THUMBR);
+			input_set_capability(input, EV_KEY, KEY_KPPLUS);
+			input_set_capability(input, EV_KEY, KEY_KPMINUS);
+			input_set_capability(input, EV_KEY, KEY_KPENTER);
+			input_set_capability(input, EV_REL, REL_DIAL);
+		}
+		break;
 	case GIP_TYPE_UNKNOWN:
 	case GIP_TYPE_NAVIGATION_CONTROLLER:
+	case GIP_TYPE_FLIGHT_STICK:
 		break;
 	case GIP_TYPE_CHATPAD:
 	case GIP_TYPE_HEADSET:
@@ -1601,6 +1678,11 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
 	if (attachment->vendor_id == 0x045e && attachment->product_id == 0x0b0a)
 		input_set_abs_params(input, ABS_PROFILE, 0, 3, 0, 0);
 
+	if (attachment->quirks & GIP_QUIRK_WHEEL_FORCE_HANDBRAKE) {
+		input_set_capability(input, EV_KEY, BTN_THUMBR);
+		input_set_capability(input, EV_KEY, BTN_THUMBL);
+	}
+
 #ifdef CONFIG_JOYSTICK_XBOX_GIP_FF
 	if (attachment->features & GIP_FEATURE_MOTOR_CONTROL) {
 		input_set_capability(input, EV_FF, FF_RUMBLE);
@@ -1680,6 +1762,14 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
 			return rc;
 	}
 
+	if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+		struct gip_initial_reports_request request = { 0 };
+
+		gip_send_vendor_message(attachment,
+			GIP_CMD_INITIAL_REPORTS_REQUEST, 0, &request,
+			sizeof(request));
+	}
+
 	usb_make_path(attachment->device->udev, attachment->phys,
 		sizeof(attachment->phys));
 	len = strlen(attachment->phys);
@@ -1688,7 +1778,8 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
 			sizeof(attachment->phys) - len, "/input%d",
 			attachment->attachment_index);
 
-	if (gip_attachment_is_controller(attachment) && !attachment->input) {
+	if (gip_attachment_is_controller(attachment) && !attachment->input
+		&& attachment->attachment_type != GIP_TYPE_WHEEL) {
 		rc = gip_setup_input_device(attachment);
 		if (rc == -ENODEV)
 			return 0;
@@ -2005,6 +2096,13 @@ static int gip_handle_command_metadata_respose(struct gip_attachment *attachment
 			expected_guid = &guid_headset;
 			break;
 		}
+
+		if (strcmp(type, "Logi.Xbox.Input.TrueForceWheel") == 0) {
+			attachment->attachment_type = GIP_TYPE_WHEEL;
+			attachment->vendor_type = GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL;
+			expected_guid = &guid_logi_true_force_wheel;
+			break;
+		}
 	}
 
 	found_expected_guid = !expected_guid;
@@ -2307,13 +2405,87 @@ static void gip_handle_arcade_stick_report(struct gip_attachment *attachment,
 	}
 }
 
+static void gip_handle_wheel_report(struct gip_attachment *attachment,
+	struct input_dev *dev, const uint8_t *bytes, int num_bytes)
+{
+	int32_t axis;
+
+	if (num_bytes < 16)
+		return;
+
+	axis = bytes[2];
+	axis |= bytes[3] << 8;
+	input_report_abs(dev, ABS_WHEEL, axis - 0x8000);
+
+	if (attachment->wheel.connections & GIP_WHEEL_THROTTLE_CONN) {
+		axis = bytes[4];
+		axis |= bytes[5] << 8;
+		input_report_abs(dev, ABS_GAS, axis);
+	}
+
+	if (attachment->wheel.connections & GIP_WHEEL_BRAKE_CONN) {
+		axis = bytes[6];
+		axis |= bytes[7] << 8;
+		input_report_abs(dev, ABS_BRAKE, axis);
+	}
+
+	if (attachment->wheel.connections & GIP_WHEEL_CLUTCH_CONN) {
+		axis = bytes[8];
+		axis |= bytes[9] << 8;
+		input_report_abs(dev, ABS_CLUTCH, axis);
+	}
+
+	if (attachment->wheel.connections & GIP_WHEEL_HANDBRAKE_CONN)
+		input_report_abs(dev, ABS_HANDBRAKE, bytes[10]);
+
+	if (attachment->wheel.shifter_type)
+		input_report_abs(dev, ABS_SHIFTER, (int8_t)bytes[12]);
+
+	if (attachment->vendor_type == GIP_VENDOR_LOGI_TRUE_FORCE_WHEEL && num_bytes >= 18) {
+		int dial = bytes[17] >> 5;
+
+		input_report_key(dev, BTN_THUMBL, bytes[17] & BIT(0));
+		input_report_key(dev, BTN_THUMBR, bytes[17] & BIT(1));
+		input_report_key(dev, KEY_KPPLUS, bytes[17] & BIT(2));
+		input_report_key(dev, KEY_KPMINUS, bytes[17] & BIT(3));
+		input_report_key(dev, KEY_KPENTER, bytes[17] & BIT(4));
+		if (dial == 0 && attachment->logi_dial_state == 7)
+			input_report_rel(dev, REL_DIAL, -1);
+		else if (dial == 7 && attachment->logi_dial_state == 0)
+			input_report_rel(dev, REL_DIAL, 1);
+		else
+			input_report_rel(dev, REL_DIAL,
+				attachment->logi_dial_state - dial);
+		attachment->logi_dial_state = dial;
+	}
+}
+
 static int gip_handle_ll_input_report(struct gip_attachment *attachment,
 	const struct gip_header *header, const uint8_t *bytes, int num_bytes)
 {
 	struct input_dev *dev = attachment->input;
 
-	if (!dev)
-		return -ENODEV;
+	if (!dev) {
+		if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+			if (num_bytes < 17)
+				return -EINVAL;
+			attachment->wheel.max_gear = bytes[11] & 0x1F;
+			attachment->wheel.shifter_type = bytes[11] >> 5;
+			attachment->wheel.angle_setting = bytes[13];
+			attachment->wheel.angle_setting |= bytes[14] << 8;
+			attachment->wheel.connections = bytes[16];
+
+			if (attachment->quirks & GIP_QUIRK_WHEEL_FORCE_HANDBRAKE)
+				attachment->wheel.connections |= GIP_WHEEL_HANDBRAKE_CONN;
+
+			if (attachment->wheel.angle_setting && attachment->wheel.max_angle)
+				return gip_setup_input_device(attachment);
+			else
+				return 0;
+		} else {
+			return -ENODEV;
+		}
+	}
 
 	if (attachment->device_state != GIP_STATE_START) {
 		dev_dbg(GIP_DEV(attachment), "Discarding early input report\n");
@@ -2336,6 +2508,14 @@ static int gip_handle_ll_input_report(struct gip_attachment *attachment,
 	case GIP_TYPE_ARCADE_STICK:
 		gip_handle_arcade_stick_report(attachment, dev, bytes, num_bytes);
 		break;
+	case GIP_TYPE_WHEEL:
+		gip_handle_wheel_report(attachment, dev, bytes, num_bytes);
+		break;
+	}
+
+	if (attachment->quirks & GIP_QUIRK_FORCE_GAMEPAD_SB) {
+		input_report_key(dev, BTN_THUMBL, bytes[1] & BIT(6));
+		input_report_key(dev, BTN_THUMBR, bytes[1] & BIT(7));
 	}
 
 	if (attachment->features & GIP_FEATURE_ELITE_BUTTONS) {
@@ -2413,9 +2593,22 @@ static int gip_handle_ll_input_report(struct gip_attachment *attachment,
 static int gip_handle_ll_static_configuration(struct gip_attachment *attachment,
 	const struct gip_header *header, const uint8_t *bytes, int num_bytes)
 {
-	/* TODO */
-	dev_dbg(GIP_DEV(attachment), "Unimplemented Static Configuration message\n");
-	return -ENOTSUPP;
+	if (attachment->attachment_type == GIP_TYPE_WHEEL) {
+		if (num_bytes < 11)
+			return -EINVAL;
+		attachment->wheel.max_angle = BIT(bytes[0]) - 1;
+		attachment->wheel.max_throttle = BIT(bytes[1]) - 1;
+		attachment->wheel.max_brake = BIT(bytes[2]) - 1;
+		attachment->wheel.max_clutch = BIT(bytes[3]) - 1;
+		attachment->wheel.max_handbrake = BIT(bytes[4]) - 1;
+		if (attachment->wheel.angle_setting && attachment->wheel.max_angle)
+			return gip_setup_input_device(attachment);
+	} else {
+		/* TODO */
+		dev_dbg(GIP_DEV(attachment), "Unimplemented Static Configuration message\n");
+		return -ENOTSUPP;
+	}
+	return 0;
 }
 
 static int gip_handle_ll_button_info_report(struct gip_attachment *attachment,
Signature · 1 line
2.50.1
author
#9 lore raw

PATCH 6/6 Input: xbox_gip - Add flight stick support

In reply to Vicki Pfau

This adds preliminary flight stick support, with a few caveats:

- Flight sticks support up to 64 extra buttons. This only exposes the first 50, as there isn't any good place to map the remainder.
- Flight sticks support up to 12 extra axes. This picks a fairly abritrary mapping for them, as there's again no good place to map them.

Flight sticks also have addressible LEDs, but I don't have a device that supports them so I can't test them yet.

---
 drivers/input/joystick/xbox_gip.c | 126 +++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 3 deletions(-)
drivers/input/joystick/xbox_gip.c +123 -3
index 874705a9b6bfb..36611ba8d038e 100644
@@ -11,9 +11,10 @@
  * - Sending fragmented messages
  * - Raw character device
  * - Wheel force feedback
- * - Flight stick support
  * - More arcade stick testing
  * - Arcade stick extra buttons
+ * - More flight stick testing
+ * - Flight stick LEDs
  *
  * This driver is based on the Microsoft GIP spec at:
  * https://aka.ms/gipdocs
@@ -37,6 +38,9 @@
 #define MAX_MESSAGE_LENGTH 0x4000
 #define MAX_ATTACHMENTS 8
 
+#define MAX_GIP_FLIGHT_STICK_BUTTONS 64
+#define MAX_GIP_FLIGHT_STICK_AXES 12
+
 #define MAX_IN_MESSAGES 8
 #define MAX_OUT_MESSAGES 8
 
@@ -377,6 +381,21 @@ static const struct gip_audio_format gip_audio_format_table[MAX_GIP_AUDIO_FORMAT
 	[GIP_AUDIO_FORMAT_48000HZ_8CH] = { .rate = 48000, .channels = 8 },
 };
 
+static const unsigned int gip_flight_stick_extra_axes[MAX_GIP_FLIGHT_STICK_AXES] = {
+	ABS_RUDDER,
+	ABS_WHEEL,
+	ABS_GAS,
+	ABS_BRAKE,
+	ABS_CLUTCH,
+	ABS_HANDBRAKE,
+	ABS_HAT1X,
+	ABS_HAT1Y,
+	ABS_HAT2X,
+	ABS_HAT2Y,
+	ABS_HAT3X,
+	ABS_HAT3Y,
+};
+
 struct gip_wheel_info {
 	uint8_t connections;
 	uint8_t shifter_type: 3;
@@ -1564,6 +1583,7 @@ static bool gip_send_set_device_state(struct gip_attachment *attachment, uint8_t
 static int gip_setup_input_device(struct gip_attachment *attachment)
 {
 	struct input_dev *input;
+	int i;
 	int rc;
 
 	input = input_allocate_device();
@@ -1616,6 +1636,24 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
 		input_set_capability(input, EV_KEY, BTN_THUMBR);
 		input_set_capability(input, EV_KEY, BTN_THUMBL);
 		break;
+	case GIP_TYPE_FLIGHT_STICK:
+		input_set_capability(input, EV_KEY, BTN_TOP);
+		input_set_capability(input, EV_KEY, BTN_TOP2);
+		for (i = 0; i < attachment->extra_buttons && i < 10; i++)
+			input_set_capability(input, EV_KEY, BTN_0 + i);
+		for (i = 10; i < attachment->extra_buttons && i - 10 < 40; i++)
+			input_set_capability(input, EV_KEY, BTN_TRIGGER_HAPPY + i - 10);
+		if (attachment->extra_buttons > 50)
+			dev_info(GIP_DEV(attachment),
+				"Device has too many extra buttons, 51 through %i ignored\n",
+				attachment->extra_buttons);
+		input_set_abs_params(input, ABS_X, -32768, 32767, 0, 0);
+		input_set_abs_params(input, ABS_Y, -32768, 32767, 0, 0);
+		input_set_abs_params(input, ABS_Z, -32768, 32767, 0, 0);
+		input_set_abs_params(input, ABS_THROTTLE, 0, 65535, 0, 0);
+		for (i = 0; i < attachment->extra_axes && i < MAX_GIP_FLIGHT_STICK_AXES; i++)
+			input_set_abs_params(input, gip_flight_stick_extra_axes[i], 0, 65535, 0, 0);
+		break;
 	case GIP_TYPE_WHEEL:
 		input_set_abs_params(input, ABS_WHEEL,
 			-attachment->wheel.max_angle - 1,
@@ -1653,7 +1691,6 @@ static int gip_setup_input_device(struct gip_attachment *attachment)
 		break;
 	case GIP_TYPE_UNKNOWN:
 	case GIP_TYPE_NAVIGATION_CONTROLLER:
-	case GIP_TYPE_FLIGHT_STICK:
 		break;
 	case GIP_TYPE_CHATPAD:
 	case GIP_TYPE_HEADSET:
@@ -1770,6 +1807,12 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
 			sizeof(request));
 	}
 
+	if (attachment->attachment_type == GIP_TYPE_FLIGHT_STICK
+		&& gip_supports_vendor_message(attachment,
+		GIP_CMD_DEVICE_CAPABILITIES, false))
+		gip_send_vendor_message(attachment,
+			GIP_CMD_DEVICE_CAPABILITIES, 0, NULL, 0);
+
 	usb_make_path(attachment->device->udev, attachment->phys,
 		sizeof(attachment->phys));
 	len = strlen(attachment->phys);
@@ -1779,7 +1822,8 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)
 			attachment->attachment_index);
 
 	if (gip_attachment_is_controller(attachment) && !attachment->input
-		&& attachment->attachment_type != GIP_TYPE_WHEEL) {
+		&& attachment->attachment_type != GIP_TYPE_WHEEL
+		&& attachment->attachment_type != GIP_TYPE_FLIGHT_STICK) {
 		rc = gip_setup_input_device(attachment);
 		if (rc == -ENODEV)
 			return 0;
@@ -2242,6 +2286,22 @@ static int gip_handle_command_firmware(struct gip_attachment *attachment,
 	return -ENOTSUPP;
 }
 
+static int gip_handle_device_capabilities(struct gip_attachment *attachment,
+	const struct gip_header *header, const void *bytes, int num_bytes)
+{
+	const struct gip_device_capabilities_response *response = bytes;
+
+	if (attachment->input)
+		return 0;
+
+	if (num_bytes < 4)
+		return -EINVAL;
+
+	attachment->extra_axes = response->extra_axis_count;
+	attachment->extra_buttons = response->extra_button_count;
+	return gip_setup_input_device(attachment);
+}
+
 static int gip_handle_command_raw_report(struct gip_attachment *attachment,
 	const struct gip_header *header, const uint8_t *bytes, int num_bytes)
 {
@@ -2405,6 +2465,58 @@ static void gip_handle_arcade_stick_report(struct gip_attachment *attachment,
 	}
 }
 
+static void gip_handle_flight_stick_report(struct gip_attachment *attachment,
+	struct input_dev *dev, const uint8_t *bytes, int num_bytes)
+{
+	int32_t axis;
+	int i;
+
+	if (num_bytes < 19)
+		return;
+
+	/* Fire 1 and 2 */
+	input_report_key(dev, BTN_TOP, bytes[2] & BIT(0));
+	input_report_key(dev, BTN_TOP2, bytes[2] & BIT(1));
+
+	for (i = 0; i < attachment->extra_buttons && i < 10; i++) {
+		input_report_key(dev, BTN_0 + i,
+			bytes[i / 8 + 3] & BIT(i));
+	}
+	for (i = 10; i < attachment->extra_buttons && i - 10 < 40; i++) {
+		input_report_key(dev, BTN_TRIGGER_HAPPY + i - 10,
+			bytes[i / 8 + 3] & BIT(i));
+	}
+
+	/*
+	 * Roll, pitch and yaw are signed. Throttle and any
+	 * extra axes are unsigned. All values are full-range.
+	 */
+	axis = bytes[11];
+	axis |= bytes[12] << 8;
+	input_report_abs(dev, ABS_X, (int16_t) axis);
+
+	axis = bytes[13];
+	axis |= bytes[14] << 8;
+	input_report_abs(dev, ABS_Y, (int16_t) axis);
+
+	axis = bytes[15];
+	axis |= bytes[16] << 8;
+	input_report_abs(dev, ABS_Z, (int16_t) axis);
+
+	axis = bytes[17];
+	axis |= bytes[18] << 8;
+	input_report_abs(dev, ABS_THROTTLE, axis);
+
+	for (i = 0; i < attachment->extra_axes && i < MAX_GIP_FLIGHT_STICK_AXES; i++) {
+		if (20 + i * 2 >= num_bytes)
+			return;
+
+		axis = bytes[19 + i * 2];
+		axis |= bytes[20 + i * 2] << 8;
+		input_report_abs(dev, gip_flight_stick_extra_axes[i], axis);
+	}
+}
+
 static void gip_handle_wheel_report(struct gip_attachment *attachment,
 	struct input_dev *dev, const uint8_t *bytes, int num_bytes)
 {
@@ -2508,6 +2620,9 @@ static int gip_handle_ll_input_report(struct gip_attachment *attachment,
 	case GIP_TYPE_ARCADE_STICK:
 		gip_handle_arcade_stick_report(attachment, dev, bytes, num_bytes);
 		break;
+	case GIP_TYPE_FLIGHT_STICK:
+		gip_handle_flight_stick_report(attachment, dev, bytes, num_bytes);
+		break;
 	case GIP_TYPE_WHEEL:
 		gip_handle_wheel_report(attachment, dev, bytes, num_bytes);
 		break;
@@ -2723,6 +2838,11 @@ static int gip_handle_message(struct gip_attachment *attachment,
 			num_bytes);
 
 	switch (header->message_type) {
+	case GIP_CMD_DEVICE_CAPABILITIES:
+		if (attachment->attachment_type == GIP_TYPE_FLIGHT_STICK)
+			return gip_handle_device_capabilities(attachment,
+				header, bytes, num_bytes);
+		break;
 	case GIP_CMD_RAW_REPORT:
 		if (attachment->features & GIP_FEATURE_ELITE_BUTTONS)
 			return gip_handle_command_raw_report(attachment,
Signature · 1 line
2.50.1