mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sanjay Govind <sanjay.govind9@gmail.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Sanjay Govind <sanjay.govind9@gmail.com>
Subject: [PATCH 4/4] HID: sony: report the battery of Rock Band 4 PS5 drums
Date: Tue,  1 Dec 2026 15:09:23 +1300	[thread overview]
Message-ID: <20261201020922.3552247-6-sanjay.govind9@gmail.com> (raw)
In-Reply-To: <20261201020922.3552247-2-sanjay.govind9@gmail.com>

Rock Band 4 PS5 drum kits report their battery state in byte 30 of
their input report, encoded the same way as on Rock Band 4 PS5
guitars. The Stage Tour drum kit reports its battery level there, for
example 0x19 (charging, level 9) when connected over USB.

Move the decoding of this byte out of the PS5 guitar handler into a
helper, and use it for PS5 drum kits as well. Like the guitars, these
kits have no MAC address, so give them a device ID to keep the name of
their battery unique.

Signed-off-by: Sanjay Govind <sanjay.govind9@gmail.com>
---

Notes:
    Depends on the series fixing the RB4 PS5 guitar battery reporting
    ("HID: sony: handle RB4 PS5 guitars that do not report a battery
    level" and "HID: sony: fix battery name clash between RB4 PS5
    guitars").
    
    Tested on a Stage Tour drum kit in PS5 mode (3958:d600):
    - Over USB, it reports 0x19 in byte 30 and its battery is reported as
      charging at 95%.
    - Through its wireless dongle, which uses the same USB ID, it reports
      0x08 and its battery is reported as discharging at 85%.
    
    Built hid-sony.ko with W=1 against the 7.3.6 headers, no warnings;
    checkpatch clean.
    
    The patch and changelog were written with the help of an AI coding
    assistant (Claude Opus 5.5).

 drivers/hid/hid-sony.c | 67 ++++++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 29 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 4e68eb11c418..55662d163f57 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -82,7 +82,7 @@
 #define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER | BUZZ_CONTROLLER |\
 				MOTION_CONTROLLER | NAVIGATION_CONTROLLER)
 #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER |\
-				RB4_GUITAR_PS5)
+				RB4_GUITAR_PS5 | RB4_DRUMS_PS5)
 #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | MOTION_CONTROLLER)
 #define SONY_BT_DEVICE (SIXAXIS_CONTROLLER_BT | MOTION_CONTROLLER_BT | NAVIGATION_CONTROLLER_BT)
 #define NSG_MRXU_REMOTE (NSG_MR5U_REMOTE_BT | NSG_MR7U_REMOTE_BT)
@@ -1165,38 +1165,24 @@ static int rb4_ps4_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
 	return 0;
 }
 
-static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
+/*
+ * Rock Band 4 PS5 instruments report the battery status and level at byte 30
+ * of their input report.
+ */
+static void rb4_ps5_parse_battery(struct sony_sc *sc, u8 data)
 {
 	u8 charging_status;
 	u8 battery_data;
 	u8 battery_capacity;
 	u8 battery_status;
 
-	if (unlikely(size != 64 || rd[0] != 0x01))
-		return 0;
-
-	/*
-	 * Rock Band 4 PS5 guitars have whammy and
-	 * tilt functionality, they're located at
-	 * byte 41 and 42 respectively.
-	 *
-	 * We will map these values to the triggers
-	 * because the guitars don't have anything
-	 * mapped there.
-	 */
-	input_report_abs(sc->input_dev, ABS_Z, rd[41]);
-	input_report_abs(sc->input_dev, ABS_RZ, rd[42]);
-
-	/*
-	 * Rock Band 4 PS5 guitars also report the
-	 * battery status and level at byte 30.
-	 */
-	charging_status = (rd[30] >> 4) & 0x0F;
-	battery_data = rd[30] & 0x0F;
+	charging_status = (data >> 4) & 0x0F;
+	battery_data = data & 0x0F;
 
 	/*
-	 * A level of 0x0c means that the guitar does not report its battery
-	 * level. Keep the capacity at 100% to avoid low battery warnings.
+	 * A level of 0x0c means that the instrument does not report its
+	 * battery level. Keep the capacity at 100% to avoid low battery
+	 * warnings.
 	 */
 	if (battery_data == 0x0c) {
 		battery_capacity = 100;
@@ -1228,6 +1214,26 @@ static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
 		sc->battery_capacity = battery_capacity;
 		sc->battery_status = battery_status;
 	}
+}
+
+static int rb4_ps5_guitar_raw_event(struct sony_sc *sc, u8 *rd, int size)
+{
+	if (unlikely(size != 64 || rd[0] != 0x01))
+		return 0;
+
+	/*
+	 * Rock Band 4 PS5 guitars have whammy and
+	 * tilt functionality, they're located at
+	 * byte 41 and 42 respectively.
+	 *
+	 * We will map these values to the triggers
+	 * because the guitars don't have anything
+	 * mapped there.
+	 */
+	input_report_abs(sc->input_dev, ABS_Z, rd[41]);
+	input_report_abs(sc->input_dev, ABS_RZ, rd[42]);
+
+	rb4_ps5_parse_battery(sc, rd[30]);
 
 	input_sync(sc->input_dev);
 	return 0;
@@ -1267,6 +1273,9 @@ static int rb4_drums_raw_event(struct sony_sc *sc, u8 *rd, int size)
 		input_report_abs(input, rb4_drums_velocity_absmap[i],
 				 rd[velocity_offset + i]);
 
+	if (sc->quirks & RB4_DRUMS_PS5)
+		rb4_ps5_parse_battery(sc, rd[30]);
+
 	/*
 	 * hid-input syncs these events together with the buttons of the same
 	 * report, so that each hit arrives as a single frame.
@@ -2005,7 +2014,7 @@ static int sony_battery_probe(struct sony_sc *sc, int append_dev_id)
 	int ret;
 
 	/*
-	 * Devices without a MAC address, such as Rock Band 4 PS5 guitars,
+	 * Devices without a MAC address, such as Rock Band 4 PS5 instruments,
 	 * would all get the same name, so use the device ID to tell them
 	 * apart.
 	 */
@@ -2186,10 +2195,10 @@ static int sony_set_device_id(struct sony_sc *sc)
 	int ret;
 
 	/*
-	 * Only Sixaxis controllers, and Rock Band 4 PS5 guitars which need it
-	 * to name their battery, get an id. All others are set to -1.
+	 * Only Sixaxis controllers, and Rock Band 4 PS5 instruments which need
+	 * it to name their battery, get an id. All others are set to -1.
 	 */
-	if (sc->quirks & (SIXAXIS_CONTROLLER | RB4_GUITAR_PS5)) {
+	if (sc->quirks & (SIXAXIS_CONTROLLER | RB4_GUITAR_PS5 | RB4_DRUMS_PS5)) {
 		ret = ida_alloc(&sony_device_id_allocator, GFP_KERNEL);
 		if (ret < 0) {
 			sc->device_id = -1;
-- 
2.56.1


      parent reply	other threads:[~2026-12-01  2:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  2:09 [PATCH 0/4] HID: sony: add support for new CRKD and RedOctane Games instruments Sanjay Govind
2026-12-01  2:09 ` [PATCH 1/4] HID: sony: add IDs for the 2026 CRKD Gibson SG and Gibson Kramer guitars Sanjay Govind
2026-12-01  2:09 ` [PATCH 2/4] HID: sony: add support for the Stage Tour drum kit Sanjay Govind
2026-12-01  2:09 ` [PATCH 3/4] HID: sony: add support for the PDP and MadCatz Rock Band 4 PS4 drums Sanjay Govind
2026-12-01  2:09 ` Sanjay Govind [this message]

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=20261201020922.3552247-6-sanjay.govind9@gmail.com \
    --to=sanjay.govind9@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®