From patchwork Wed Oct 23 11:24:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 13846931 X-Patchwork-Delegate: jikos@jikos.cz Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E9A01AA785; Wed, 23 Oct 2024 11:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729682913; cv=none; b=n+jo+8A1fQLgyLFs5cLOZ4O5dOjJ2EZfNZ9Yr4DnAUYV3rtcdGvvUnvU+ZhYBKRi/PwovxDeqROzBnp3GADwKHJpuQOnkcKXZpQKGbFdeexP9qu7y+CAaKkWBWU3IDjZEY2/Q+UUbCYXMqJaj/eAPTlLXY85rYygVPSM2I/Gx5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729682913; c=relaxed/simple; bh=YuALfZjDu5Eg0RrCHLqSkglk4U+sAtMqa52Q9dE/aII=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rzz3TKiBcZWsoOAAc1aphLV4a6earmRqjfPKUj5fV776Fb1Ekl1yrtNdoYKc9AGoIsHoKCdYwPbMOqnPb+Olf42MN2YEIKTxCp/kFBfDEkfFwFAWIrG3dGVkDTBa1CT8USlzfjjBQMTtWfw6j3OrLkhsmOpw0Nn2pfXVnuf8iIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id 76277C0008; Wed, 23 Oct 2024 11:28:29 +0000 (UTC) From: Bastien Nocera To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Bastien Nocera Subject: [PATCH 1/2] HID: steelseries: Fix battery requests stopping after some time Date: Wed, 23 Oct 2024 13:24:37 +0200 Message-ID: <20241023112828.320157-2-hadess@hadess.net> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023112828.320157-1-hadess@hadess.net> References: <20241023112828.320157-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: hadess@hadess.net 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 --- 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, From patchwork Wed Oct 23 11:24:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastien Nocera X-Patchwork-Id: 13846932 X-Patchwork-Delegate: jikos@jikos.cz Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E89B154439; Wed, 23 Oct 2024 11:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729682914; cv=none; b=T4S74AbX8GNNoLTNxwimT/M1jaksnw8qkFNNezAyfC+Qq+GNyhaA56R6j4IfKNutrXWdmgQ+aNXOwdXO4FGaZga8GycuRN2UsQBDL1Biq6n4QoPaN1I7u8FgkZtx/KYjXKrs1J4RQ48V+HJVQ07csAZ6OXWc/wCF5AZzVBSt+uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729682914; c=relaxed/simple; bh=GqTYAOl7cc4VcNc1E1dwaKhqZe3YTizqExvYMx6H4Bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iuWaLdlibXovpLpfeh3inUlYZuuWoV5uBb4ghXfRBXB0Lb07Jiorrm0qRA7+xMp8yjIrtocjO62cFRH7wagRp1N6CM5N88xA7pnH94fW7d6n2wKlgtMRmZoypXssXee9ELbXf320ZpT0/+5I9t/2bTTztuf/BcPF2KRVbR433mw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id 11198C0007; Wed, 23 Oct 2024 11:28:29 +0000 (UTC) From: Bastien Nocera To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Bastien Nocera Subject: [PATCH 2/2] HID: steelseries: Add capacity_level mapping Date: Wed, 23 Oct 2024 13:24:38 +0200 Message-ID: <20241023112828.320157-3-hadess@hadess.net> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023112828.320157-1-hadess@hadess.net> References: <20241023112828.320157-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: hadess@hadess.net 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 --- 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)