Skip to contentSkip to conversation

HID: steelseries: Bug fixes

PATCH Applied Bastien Nocera 2 participants 4 messages Oct 23, 2024 – Nov 6, 2024 HID

lore
Share & tools
lore
#0 lore raw

cover HID: steelseries: Bug fixes

A couple of bug fixes for the battery reporting for the Steelseries Arctis 1 after using the feature for a while.

Bastien Nocera (2):
HID: steelseries: Fix battery requests stopping after some time
HID: steelseries: Add capacity_level mapping

 drivers/hid/hid-steelseries.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.0
#1 lore raw

PATCH 1/2 HID: steelseries: Fix battery requests stopping after some time

In some cases, the headset receiver will answer one of our requests with garbage, or not at all. This is a problem when we only request battery information once we've received a battery response, as we might never get to request battery information again.

If the data from the receiver could not be parsed, and there's no pending battery requests, schedule a new request.

---
 drivers/hid/hid-steelseries.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/hid/hid-steelseries.c +5 -1
index 7e83fee1ffa0..16138f7dae17 100644
@@ -603,8 +603,11 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
 		hid_dbg(sd->hdev,
 			"Parsing raw event for Arctis 1 headset (%*ph)\n", size, read_buf);
 		if (size < ARCTIS_1_BATTERY_RESPONSE_LEN ||
-		    memcmp (read_buf, arctis_1_battery_request, sizeof(arctis_1_battery_request)))
+		    memcmp(read_buf, arctis_1_battery_request, sizeof(arctis_1_battery_request))) {
+			if (!delayed_work_pending(&sd->battery_work))
+				goto request_battery;
 			return 0;
+		}
 		if (read_buf[2] == 0x01) {
 			connected = false;
 			capacity = 100;
@@ -631,6 +634,7 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
 		power_supply_changed(sd->battery);
 	}
 
+request_battery:
 	spin_lock_irqsave(&sd->lock, flags);
 	if (!sd->removed)
 		schedule_delayed_work(&sd->battery_work,
Signature · 1 line
2.47.0
#2 lore raw

PATCH 2/2 HID: steelseries: Add capacity_level mapping

In reply to Bastien Nocera

The capacity level mappings are taken from:
https://support.steelseries.com/hc/en-us/articles/360049205612-How-do-I-know-the-Arctis-battery-level-how-do-I-charge-the-Arctis

Even if we have a percentage, exporting a capacity_level that matches with the hardware warning levels means that upower can show warnings at the same time as the hardware. So the headset starts beeping at the same time as the critical warning notification appears :eyeroll:

---
 drivers/hid/hid-steelseries.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/hid/hid-steelseries.c +13 -0
index 16138f7dae17..f9ff5be94309 100644
@@ -411,6 +411,15 @@ static void steelseries_headset_fetch_battery(struct hid_device *hdev)
 			"Battery query failed (err: %d)\n", ret);
 }
 
+static int battery_capacity_to_level(int capacity)
+{
+	if (capacity >= 50)
+		return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
+	if (capacity >= 20)
+		return POWER_SUPPLY_CAPACITY_LEVEL_LOW;
+	return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
+}
+
 static void steelseries_headset_battery_timer_tick(struct work_struct *work)
 {
 	struct steelseries_device *sd = container_of(work,
@@ -442,6 +451,9 @@ static int steelseries_headset_battery_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_CAPACITY:
 		val->intval = sd->battery_capacity;
 		break;
+	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
+		val->intval = battery_capacity_to_level(sd->battery_capacity);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
@@ -469,6 +481,7 @@ static enum power_supply_property steelseries_headset_battery_props[] = {
 	POWER_SUPPLY_PROP_STATUS,
 	POWER_SUPPLY_PROP_SCOPE,
 	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
 };
 
 static int steelseries_headset_battery_register(struct steelseries_device *sd)
Signature · 1 line
2.47.0
maintainer Applied
#3 lore raw
In reply to Bastien Nocera
Quoted 9 lines · Bastien Nocera

A couple of bug fixes for the battery reporting for the Steelseries Arctis 1 after using the feature for a while.

Bastien Nocera (2):
HID: steelseries: Fix battery requests stopping after some time
HID: steelseries: Add capacity_level mapping

 drivers/hid/hid-steelseries.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Applied, thanks Bastien.

Signature · 2 lines
Jiri Kosina
SUSE Labs