linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] HID: steelseries: Bug fixes
@ 2024-10-23 11:24 Bastien Nocera
  2024-10-23 11:24 ` [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time Bastien Nocera
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bastien Nocera @ 2024-10-23 11:24 UTC (permalink / raw)
  To: linux-input; +Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires, 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(-)

-- 
2.47.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time
  2024-10-23 11:24 [PATCH 0/2] HID: steelseries: Bug fixes Bastien Nocera
@ 2024-10-23 11:24 ` Bastien Nocera
  2024-10-23 11:24 ` [PATCH 2/2] HID: steelseries: Add capacity_level mapping Bastien Nocera
  2024-11-06 14:10 ` [PATCH 0/2] HID: steelseries: Bug fixes Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Bastien Nocera @ 2024-10-23 11:24 UTC (permalink / raw)
  To: linux-input; +Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires, Bastien Nocera

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.

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-steelseries.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
index 7e83fee1ffa0..16138f7dae17 100644
--- a/drivers/hid/hid-steelseries.c
+++ b/drivers/hid/hid-steelseries.c
@@ -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,
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] HID: steelseries: Add capacity_level mapping
  2024-10-23 11:24 [PATCH 0/2] HID: steelseries: Bug fixes Bastien Nocera
  2024-10-23 11:24 ` [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time Bastien Nocera
@ 2024-10-23 11:24 ` Bastien Nocera
  2024-11-06 14:10 ` [PATCH 0/2] HID: steelseries: Bug fixes Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Bastien Nocera @ 2024-10-23 11:24 UTC (permalink / raw)
  To: linux-input; +Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires, 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:

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-steelseries.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
index 16138f7dae17..f9ff5be94309 100644
--- a/drivers/hid/hid-steelseries.c
+++ b/drivers/hid/hid-steelseries.c
@@ -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)
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] HID: steelseries: Bug fixes
  2024-10-23 11:24 [PATCH 0/2] HID: steelseries: Bug fixes Bastien Nocera
  2024-10-23 11:24 ` [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time Bastien Nocera
  2024-10-23 11:24 ` [PATCH 2/2] HID: steelseries: Add capacity_level mapping Bastien Nocera
@ 2024-11-06 14:10 ` Jiri Kosina
  2 siblings, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2024-11-06 14:10 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: linux-input, linux-kernel, Benjamin Tissoires

On Wed, 23 Oct 2024, Bastien Nocera wrote:

> 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.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-06 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-23 11:24 [PATCH 0/2] HID: steelseries: Bug fixes Bastien Nocera
2024-10-23 11:24 ` [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time Bastien Nocera
2024-10-23 11:24 ` [PATCH 2/2] HID: steelseries: Add capacity_level mapping Bastien Nocera
2024-11-06 14:10 ` [PATCH 0/2] HID: steelseries: Bug fixes Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).