From nobody Tue Nov 26 02:41:38 2024 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: hadess@hadess.net Content-Type: text/plain; charset="utf-8" The capacity level mappings are taken from: https://support.steelseries.com/hc/en-us/articles/360049205612-How-do-I-kno= w-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 h= id_device *hdev) "Battery query failed (err: %d)\n", ret); } =20 +static int battery_capacity_to_level(int capacity) +{ + if (capacity >=3D 50) + return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; + if (capacity >=3D 20) + return POWER_SUPPLY_CAPACITY_LEVEL_LOW; + return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; +} + static void steelseries_headset_battery_timer_tick(struct work_struct *wor= k) { struct steelseries_device *sd =3D container_of(work, @@ -442,6 +451,9 @@ static int steelseries_headset_battery_get_property(str= uct power_supply *psy, case POWER_SUPPLY_PROP_CAPACITY: val->intval =3D sd->battery_capacity; break; + case POWER_SUPPLY_PROP_CAPACITY_LEVEL: + val->intval =3D battery_capacity_to_level(sd->battery_capacity); + break; default: ret =3D -EINVAL; break; @@ -469,6 +481,7 @@ static enum power_supply_property steelseries_headset_b= attery_props[] =3D { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_SCOPE, POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CAPACITY_LEVEL, }; =20 static int steelseries_headset_battery_register(struct steelseries_device = *sd) --=20 2.47.0