Skip to contentSkip to conversation

Input: joystick: xpad: Add X-Box Adaptive Controller support

PATCH In review Nate Yocom 3 participants 11 messages Sep 8, 2022 – Sep 29, 2022

Subsystems (3)
lore
Share & tools
lore

Nate Yocom

author
#0 lore raw

v6 cover Input: joystick: xpad: Add X-Box Adaptive Controller support

Adds support for the X-Box Adaptive Controller, which is protocol compatible with the XTYPE_XBOXONE support in the driver with two deltas:

- The X-Box button sets 0x02 as its activation ID, where others set 0x01
- The controller has an additional Profile button with 4 active states, which this change maps to an Axis control with 4 possible values

Patch series adds device to the supported table, adds support for the Profile button, and adds support for the X-Box button as distinct changes.

Nate Yocom (5):
Input: joystick: xpad: Add X-Box Adaptive support
Input: joystick: xpad: Add X-Box Adaptive XBox button
Input: joystick: xpad: Add ABS_PROFILE to uapi
Input: joystick: xpad: Add ABS_PROFILE to Docs
Input: joystick: xpad: Add X-Box Adaptive Profile button

v2: Fix warning Reported-by: kernel test robot <[email protected]>
v3: Break into multi-part and remove VID/PID check for XBox button
v4: Rename Layer -> Profile as suggested by Bastien Nocera
v5: Add new ABS_PROFILE axis to uapi and use it for the profile button
v6: Add ABS_PROFILE to absolutes array and docs as requested by Dmitry

 Documentation/input/event-codes.rst    |  6 ++++++
 Documentation/input/gamepad.rst        |  6 ++++++
 drivers/hid/hid-debug.c                |  3 ++-
 drivers/input/joystick/xpad.c          | 15 ++++++++++++++-
 include/uapi/linux/input-event-codes.h |  1 +
 5 files changed, 29 insertions(+), 2 deletions(-)

base-commit: 26b1224903b3fb66e8aa564868d0d57648c32b15

Signature · 1 line
2.30.2
author
#1 lore raw

PATCH v6 1/5 Input: joystick: xpad: Add X-Box Adaptive support

Adds correct VID/PID for this XTYPE_XBOXONE compatible controller to xpad_device[] table.

---
 drivers/input/joystick/xpad.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/joystick/xpad.c +1 -0
index 18190b529bca..c8b38bb73d34 100644
@@ -131,6 +131,7 @@ static const struct xpad_device {
 	{ 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
+	{ 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
 	{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
 	{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
Signature · 1 line
2.30.2
Reviewed-by on v6 1/5
#2 lore raw

Re: [PATCH v6 1/5] Input: joystick: xpad: Add X-Box Adaptive support

Quoted 5 lines · Nate Yocom

Adds correct VID/PID for this XTYPE_XBOXONE compatible controller to xpad_device[] table.

Quoted 18 lines
---
 drivers/input/joystick/xpad.c | 1 +
 1 file changed, 1 insertion(+)
drivers/input/joystick/xpad.c +1 -0
index 18190b529bca..c8b38bb73d34 100644
@@ -131,6 +131,7 @@ static const struct xpad_device {
 	{ 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
+	{ 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
 	{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
 	{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
Signature · 1 line
2.30.2
author
#3 lore raw

PATCH v6 2/5 Input: joystick: xpad: Add X-Box Adaptive XBox button

In reply to Nate Yocom

Adaptive controller sets 0x02 bit for this button, all others set 0x01 so presence of either is used for BTN_MODE.

---
 drivers/input/joystick/xpad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/joystick/xpad.c +1 -1
index c8b38bb73d34..dff0d099d416 100644
@@ -858,7 +858,7 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
 		if (data[1] == 0x30)
 			xpadone_ack_mode_report(xpad, data[2]);
 
-		input_report_key(dev, BTN_MODE, data[4] & 0x01);
+		input_report_key(dev, BTN_MODE, data[4] & 0x03);
 		input_sync(dev);
 		return;
 	}
Signature · 1 line
2.30.2
Reviewed-by on v6 2/5
#4 lore raw

Re: [PATCH v6 2/5] Input: joystick: xpad: Add X-Box Adaptive XBox button

Hi Nate,

Quoted 5 lines · Nate Yocom

Adaptive controller sets 0x02 bit for this button, all others set 0x01 so presence of either is used for BTN_MODE.

This does not applies properly anymore on dtor/next [1] because of 90c9978959da ("Input: xpad - refactor using BIT() macro") and e23c69e33248 ("Input: xpad - add support for XBOX One Elite paddles")

With that, please add:

Quoted 19 lines
---
 drivers/input/joystick/xpad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/joystick/xpad.c +1 -1
index c8b38bb73d34..dff0d099d416 100644
@@ -858,7 +858,7 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
 		if (data[1] == 0x30)
 			xpadone_ack_mode_report(xpad, data[2]);
 
-		input_report_key(dev, BTN_MODE, data[4] & 0x01);
+		input_report_key(dev, BTN_MODE, data[4] & 0x03);
 		input_sync(dev);
 		return;
 	}
Signature · 1 line
2.30.2
author
#5 lore raw

PATCH v6 3/5 Input: joystick: xpad: Add ABS_PROFILE to uapi

In reply to Nate Yocom

Add an ABS_PROFILE axis for input devices which need it, e.g. X-Box Adaptive Controller and X-Box Elite 2.

---
 drivers/hid/hid-debug.c                | 3 ++-
 include/uapi/linux/input-event-codes.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/hid/hid-debug.c +2 -1
index 81e7e404a5fc..2ca6ab600bc9 100644
@@ -1014,7 +1014,8 @@ static const char *absolutes[ABS_CNT] = {
 	[ABS_HAT3Y] = "Hat 3Y",		[ABS_PRESSURE] = "Pressure",
 	[ABS_DISTANCE] = "Distance",	[ABS_TILT_X] = "XTilt",
 	[ABS_TILT_Y] = "YTilt",		[ABS_TOOL_WIDTH] = "ToolWidth",
-	[ABS_VOLUME] = "Volume",	[ABS_MISC] = "Misc",
+	[ABS_VOLUME] = "Volume",	[ABS_PROFILE] = "Profile",
+	[ABS_MISC] = "Misc",
 	[ABS_MT_TOUCH_MAJOR] = "MTMajor",
 	[ABS_MT_TOUCH_MINOR] = "MTMinor",
 	[ABS_MT_WIDTH_MAJOR] = "MTMajorW",
include/uapi/linux/input-event-codes.h +1 -0
index dff8e7f17074..7ad931a32970 100644
@@ -862,6 +862,7 @@
 #define ABS_TOOL_WIDTH		0x1c
 
 #define ABS_VOLUME		0x20
+#define ABS_PROFILE		0x21
 
 #define ABS_MISC		0x28
 
Signature · 1 line
2.30.2
author
#6 lore raw

PATCH v6 4/5 Input: joystick: xpad: Add ABS_PROFILE to Docs

In reply to Nate Yocom

Add ABS_PROFILE description to Documentation/input/

---
 Documentation/input/event-codes.rst | 6 ++++++
 Documentation/input/gamepad.rst     | 6 ++++++
 2 files changed, 12 insertions(+)
Documentation/input/event-codes.rst +6 -0
index 8741d390b184..b4557462edd7 100644
@@ -235,6 +235,12 @@ A few EV_ABS codes have special meanings:
     BTN_TOOL_<name> signals the type of tool that is currently detected by the
     hardware and is otherwise independent of ABS_DISTANCE and/or BTN_TOUCH.
 
+* ABS_PROFILE:
+
+  - Used to describe the state of a multi-value profile switch.  An event is
+    emitted only when the selected profile changes, indicating the newly
+    selected profile value.
+
 * ABS_MT_<name>:
 
   - Used to describe multitouch input events. Please see
Documentation/input/gamepad.rst +6 -0
index 4d5e7fb80a84..71019de46036 100644
@@ -189,3 +189,9 @@ Gamepads report the following events:
 - Rumble:
 
   Rumble is advertised as FF_RUMBLE.
+
+- Profile:
+
+  Some pads provide a multi-value profile selection switch.  An example is the
+  XBox Adaptive and the XBox Elite 2 controllers.  When the active profile is
+  switched, its newly selected value is emitted as an ABS_PROFILE event.
Signature · 1 line
2.30.2
author
#7 lore raw

PATCH v6 5/5 Input: joystick: xpad: Add X-Box Adaptive Profile button

In reply to Nate Yocom

Adds a new quirk for controllers that have a Profile button which has 4 states, reflected as an ABS_PROFILE axis with 4 values.

---
 drivers/input/joystick/xpad.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/input/joystick/xpad.c +13 -1
index dff0d099d416..ece38f00dfff 100644
@@ -80,6 +80,7 @@
 #define MAP_TRIGGERS_TO_BUTTONS		(1 << 1)
 #define MAP_STICKS_TO_NULL		(1 << 2)
 #define MAP_SELECT_BUTTON		(1 << 3)
+#define MAP_PROFILE_BUTTON		(1 << 4)
 #define DANCEPAD_MAP_CONFIG	(MAP_DPAD_TO_BUTTONS |			\
 				MAP_TRIGGERS_TO_BUTTONS | MAP_STICKS_TO_NULL)
 
@@ -131,7 +132,7 @@ static const struct xpad_device {
 	{ 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
 	{ 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
-	{ 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", 0, XTYPE_XBOXONE },
+	{ 0x045e, 0x0b0a, "Microsoft X-Box Adaptive Controller", MAP_PROFILE_BUTTON, XTYPE_XBOXONE },
 	{ 0x045e, 0x0b12, "Microsoft Xbox Series S|X Controller", MAP_SELECT_BUTTON, XTYPE_XBOXONE },
 	{ 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
 	{ 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
@@ -927,6 +928,10 @@ static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char
 				 (__u16) le16_to_cpup((__le16 *)(data + 8)));
 	}
 
+	/* Profile button has a value of 0-3, so it is reported as an axis */
+	if (xpad->mapping & MAP_PROFILE_BUTTON)
+		input_report_abs(dev, ABS_PROFILE, data[34]);
+
 	input_sync(dev);
 }
 
@@ -1623,6 +1628,9 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
 	case ABS_HAT0Y:	/* the d-pad (only if dpad is mapped to axes */
 		input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
 		break;
+	case ABS_PROFILE: /* 4 value profile button (such as on XAC) */
+		input_set_abs_params(input_dev, abs, 0, 4, 0, 0);
+		break;
 	default:
 		input_set_abs_params(input_dev, abs, 0, 0, 0, 0);
 		break;
@@ -1715,6 +1723,10 @@ static int xpad_init_input(struct usb_xpad *xpad)
 			xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
 	}
 
+	/* setup profile button as an axis with 4 possible values */
+	if (xpad->mapping & MAP_PROFILE_BUTTON)
+		xpad_set_up_abs(input_dev, ABS_PROFILE);
+
 	error = xpad_init_ff(xpad);
 	if (error)
 		goto err_free_input;
Signature · 1 line
2.30.2
author
#8 lore raw
In reply to Nate Yocom
Quoted 35 lines · Nate Yocom

Adds support for the X-Box Adaptive Controller, which is protocol compatible with the XTYPE_XBOXONE support in the driver with two deltas:

- The X-Box button sets 0x02 as its activation ID, where others set 0x01
- The controller has an additional Profile button with 4 active states, which this change maps to an Axis control with 4 possible values

Patch series adds device to the supported table, adds support for the Profile button, and adds support for the X-Box button as distinct changes.

Nate Yocom (5):
Input: joystick: xpad: Add X-Box Adaptive support
Input: joystick: xpad: Add X-Box Adaptive XBox button
Input: joystick: xpad: Add ABS_PROFILE to uapi
Input: joystick: xpad: Add ABS_PROFILE to Docs
Input: joystick: xpad: Add X-Box Adaptive Profile button

v2: Fix warning Reported-by: kernel test robot <[email protected]>
v3: Break into multi-part and remove VID/PID check for XBox button
v4: Rename Layer -> Profile as suggested by Bastien Nocera
v5: Add new ABS_PROFILE axis to uapi and use it for the profile button
v6: Add ABS_PROFILE to absolutes array and docs as requested by Dmitry

 Documentation/input/event-codes.rst    |  6 ++++++
 Documentation/input/gamepad.rst        |  6 ++++++
 drivers/hid/hid-debug.c                |  3 ++-
 drivers/input/joystick/xpad.c          | 15 ++++++++++++++-
 include/uapi/linux/input-event-codes.h |  1 +
 5 files changed, 29 insertions(+), 2 deletions(-)
Quoted 4 lines

base-commit: 26b1224903b3fb66e8aa564868d0d57648c32b15 --
2.30.2

Dmitry et al, anything else I can do to see this through? Thanks!

- Nate

author
#9 lore raw
Quoted 39 lines · Nate Yocom
Quoted 35 lines · Nate Yocom

Adds support for the X-Box Adaptive Controller, which is protocol compatible with the XTYPE_XBOXONE support in the driver with two deltas:

- The X-Box button sets 0x02 as its activation ID, where others set 0x01
- The controller has an additional Profile button with 4 active states, which this change maps to an Axis control with 4 possible values

Patch series adds device to the supported table, adds support for the Profile button, and adds support for the X-Box button as distinct changes.

Nate Yocom (5):
Input: joystick: xpad: Add X-Box Adaptive support
Input: joystick: xpad: Add X-Box Adaptive XBox button
Input: joystick: xpad: Add ABS_PROFILE to uapi
Input: joystick: xpad: Add ABS_PROFILE to Docs
Input: joystick: xpad: Add X-Box Adaptive Profile button

v2: Fix warning Reported-by: kernel test robot <[email protected]>
v3: Break into multi-part and remove VID/PID check for XBox button
v4: Rename Layer -> Profile as suggested by Bastien Nocera
v5: Add new ABS_PROFILE axis to uapi and use it for the profile button
v6: Add ABS_PROFILE to absolutes array and docs as requested by Dmitry

Documentation/input/event-codes.rst    |  6 ++++++
Documentation/input/gamepad.rst        |  6 ++++++
drivers/hid/hid-debug.c                |  3 ++-
drivers/input/joystick/xpad.c          | 15 ++++++++++++++-
include/uapi/linux/input-event-codes.h |  1 +
5 files changed, 29 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 4 lines

base-commit: 26b1224903b3fb66e8aa564868d0d57648c32b15 --
2.30.2

Dmitry et al, anything else I can do to see this through? Thanks!

Anything missing here? Any chance of getting this in?

maintainer
#10 lore raw
In reply to Nate Yocom
Quoted 12 lines · Nate Yocom

Adds support for the X-Box Adaptive Controller, which is protocol compatible with the XTYPE_XBOXONE support in the driver with two deltas:

- The X-Box button sets 0x02 as its activation ID, where others set 0x01
- The controller has an additional Profile button with 4 active states, which this change maps to an Axis control with 4 possible values

Patch series adds device to the supported table, adds support for the Profile button, and adds support for the X-Box button as distinct changes.

Quoted 8 lines

Nate Yocom (5):
Input: joystick: xpad: Add X-Box Adaptive support
Input: joystick: xpad: Add X-Box Adaptive XBox button
Input: joystick: xpad: Add ABS_PROFILE to uapi
Input: joystick: xpad: Add ABS_PROFILE to Docs
Input: joystick: xpad: Add X-Box Adaptive Profile button

Combined patches 3 and 4 and applied the lot, thank you.

Signature · 1 line
Dmitry