From: Sanjay Govind <sanjay.govind9@gmail.com>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Rosalie Wanders <rosalie@mailbox.org>,
Brenton Simpson <appsforartists@google.com>,
Sanjay Govind <sanjay.govind9@gmail.com>
Cc: linux-input@vger.kernel.org
Subject: [PATCH] HID: sony: fix DJ Hero PS3 turntable input mapping
Date: Sat, 21 Nov 2026 14:42:58 +1300 [thread overview]
Message-ID: <20261121014257.1630667-2-sanjay.govind9@gmail.com> (raw)
The DJ Hero PS3 turntable mapping has several problems:
- The cross fader and platter button vendor usages are swapped. The
cross fader is usage 0x2d and the platter buttons are 0x2e, so the
cross fader was reported on ABS_RZ and the buttons on ABS_RX.
- The platter buttons are a bitmask in the low byte of the field at
byte 23, not an axis, so exposing them as ABS_RZ is not usable.
- ps3_turntable_absmap only has entries for Z and Rz, so any other
Generic Desktop usage below its size (such as the unused X/Y left
stick) maps to ABS_X (0) and clobbers the left platter. The hat
switch is above the array size and gets ignored, so the d-pad is
lost.
Map the usages correctly, following the layout documented by the
PlasticBand project. Report the six platter buttons as
BTN_TRIGGER_HAPPY1-6 from a raw_event handler, let the HID core handle
the hat switch, and ignore the unused left stick and the unused fourth
accelerometer field.
Fixes: 7245b0017d12 ("HID: sony: add support for more instruments")
Signed-off-by: Sanjay Govind <sanjay.govind9@gmail.com>
---
Notes:
The fix was ported from an out-of-tree hid-sony build, and the port and changelog were written with the help of an AI coding assistant (Claude Opus 5.5). Build-tested with W=1; checkpatch clean.
Runtime-tested on a 7.2.11 kernel with a PS3 DJ Hero turntable, using an external test harness that sends each of 20 input cases, reads the resulting events back over evdev, and checks them against the expected codes and values. All 20 input cases matched.
drivers/hid/hid-sony.c | 95 +++++++++++++++++++++++++++++++++---------
1 file changed, 75 insertions(+), 20 deletions(-)
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 228e74819037..574d3ff3dfb7 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -94,9 +94,17 @@
#define GHL_GUITAR_POKE_INTERVAL 8 /* In seconds */
#define GUITAR_TILT_USAGE 44
-#define TURNTABLE_EFFECTS_KNOB_USAGE 44
-#define TURNTABLE_PLATTER_BUTTONS_USAGE 45
-#define TURNTABLE_CROSS_FADER_USAGE 46
+/*
+ * DJ Hero turntable vendor usages, for the 10-bit fields at bytes 19-24 that
+ * are accelerometer X/Z/Y on other PS3 devices. See
+ * https://github.com/TheNathannator/PlasticBand/blob/main/Docs/Instruments/Turntable/PS3.md
+ */
+#define TURNTABLE_EFFECTS_KNOB_USAGE 0x2c
+#define TURNTABLE_CROSS_FADER_USAGE 0x2d
+#define TURNTABLE_PLATTER_BUTTONS_USAGE 0x2e
+#define TURNTABLE_UNUSED_GYRO_USAGE 0x2f
+/* Platter buttons are a bitmask in the low byte of the field at byte 23 */
+#define TURNTABLE_PLATTER_BUTTONS_OFFSET 23
/* Magic data taken from GHLtarUtility:
* https://github.com/ghlre/GHLtarUtility/blob/master/PS3Guitar.cs
@@ -438,9 +446,17 @@ static const unsigned int rb4_absmap[] = {
[0x31] = ABS_Y,
};
-static const unsigned int ps3_turntable_absmap[] = {
- [0x32] = ABS_X,
- [0x35] = ABS_Y,
+/* Platter buttons, reported as keys by djh_turntable_raw_event */
+static const struct {
+ u8 mask;
+ unsigned int key;
+} djh_turntable_platter_buttons[] = {
+ { 0x10, BTN_TRIGGER_HAPPY1 }, /* left green */
+ { 0x20, BTN_TRIGGER_HAPPY2 }, /* left red */
+ { 0x40, BTN_TRIGGER_HAPPY3 }, /* left blue */
+ { 0x01, BTN_TRIGGER_HAPPY4 }, /* right green */
+ { 0x02, BTN_TRIGGER_HAPPY5 }, /* right red */
+ { 0x04, BTN_TRIGGER_HAPPY6 }, /* right blue */
};
static const unsigned int instrument_keymap[] = {
@@ -662,32 +678,68 @@ static int djh_turntable_mapping(struct hid_device *hdev, struct hid_input *hi,
unsigned long **bit, int *max)
{
if ((usage->hid & HID_USAGE_PAGE) == HID_UP_MSVENDOR) {
- unsigned int abs = usage->hid & HID_USAGE;
-
- if (abs == TURNTABLE_CROSS_FADER_USAGE) {
+ switch (usage->hid & HID_USAGE) {
+ case TURNTABLE_CROSS_FADER_USAGE:
hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RX);
return 1;
- } else if (abs == TURNTABLE_EFFECTS_KNOB_USAGE) {
+ case TURNTABLE_EFFECTS_KNOB_USAGE:
hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RY);
return 1;
- } else if (abs == TURNTABLE_PLATTER_BUTTONS_USAGE) {
- hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_RZ);
- return 1;
+ case TURNTABLE_PLATTER_BUTTONS_USAGE:
+ /* A bitmask, reported as keys by djh_turntable_raw_event */
+ case TURNTABLE_UNUSED_GYRO_USAGE:
+ return -1;
}
} else if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK) {
- unsigned int abs = usage->hid & HID_USAGE;
-
- if (abs >= ARRAY_SIZE(ps3_turntable_absmap))
+ switch (usage->hid) {
+ case HID_GD_HATSWITCH:
+ /* Let the HID parser deal with the HAT. */
+ return 0;
+ case HID_GD_Z:
+ /* Left platter velocity */
+ hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_X);
+ return 1;
+ case HID_GD_RZ:
+ /* Right platter velocity */
+ hid_map_usage_clear(hi, usage, bit, max, EV_ABS, ABS_Y);
+ return 1;
+ default:
+ /* The left stick is unused */
return -1;
+ }
+ }
+ return 0;
+}
- abs = ps3_turntable_absmap[abs];
+static int djh_turntable_raw_event(struct sony_sc *sc, u8 *rd, int size)
+{
+ u8 buttons;
+ int i;
+
+ if (size <= TURNTABLE_PLATTER_BUTTONS_OFFSET)
+ return 0;
+
+ buttons = rd[TURNTABLE_PLATTER_BUTTONS_OFFSET];
+
+ /*
+ * Synced along with the rest of the report by the HID core, which
+ * still handles the rest of the report as usual.
+ */
+ for (i = 0; i < ARRAY_SIZE(djh_turntable_platter_buttons); i++)
+ input_report_key(sc->input_dev, djh_turntable_platter_buttons[i].key,
+ buttons & djh_turntable_platter_buttons[i].mask);
- hid_map_usage_clear(hi, usage, bit, max, EV_ABS, abs);
- return 1;
- }
return 0;
}
+static void djh_turntable_setup_input(struct input_dev *input_dev)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(djh_turntable_platter_buttons); i++)
+ input_set_capability(input_dev, EV_KEY, djh_turntable_platter_buttons[i].key);
+}
+
static int instrument_mapping(struct hid_device *hdev, struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
@@ -2288,6 +2340,9 @@ static int sony_input_configured(struct hid_device *hdev,
sony_init_raw_event_handler(sc, rb4_ps4_guitar_raw_event);
} else if (sc->quirks & RB4_GUITAR_PS5) {
sony_init_raw_event_handler(sc, rb4_ps5_guitar_raw_event);
+ } else if (sc->quirks & DJH_TURNTABLE) {
+ djh_turntable_setup_input(hidinput->input);
+ sony_init_raw_event_handler(sc, djh_turntable_raw_event);
}
if (sc->quirks & SONY_LED_SUPPORT) {
--
2.56.0
reply other threads:[~2026-11-21 1:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121014257.1630667-2-sanjay.govind9@gmail.com \
--to=sanjay.govind9@gmail.com \
--cc=appsforartists@google.com \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=rosalie@mailbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox