Skip to content

Commit 27c5438

Browse files
mayer-chJiri Kosina
authored andcommitted
HID: steelseries: export charging state for the SteelSeries Arctis 9 headset
The Arctis 9 headset provides the information if the power cable is plugged in and charging via the battery report. This information can be exported. Signed-off-by: Christian Mayer <git@mayer-bgk.de> Reviewed-by: Bastien Nocera <hadess@hadess.net> Tested-by: Bastien Nocera <hadess@hadess.net> Signed-off-by: Jiri Kosina <jkosina@suse.com>
1 parent 6596be6 commit 27c5438

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

drivers/hid/hid-steelseries.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct steelseries_device {
3333
struct power_supply *battery;
3434
uint8_t battery_capacity;
3535
bool headset_connected;
36+
bool battery_charging;
3637
};
3738

3839
#if IS_BUILTIN(CONFIG_LEDS_CLASS) || \
@@ -450,9 +451,12 @@ static int steelseries_headset_battery_get_property(struct power_supply *psy,
450451
val->intval = 1;
451452
break;
452453
case POWER_SUPPLY_PROP_STATUS:
453-
val->intval = sd->headset_connected ?
454-
POWER_SUPPLY_STATUS_DISCHARGING :
455-
POWER_SUPPLY_STATUS_UNKNOWN;
454+
if (sd->headset_connected) {
455+
val->intval = sd->battery_charging ?
456+
POWER_SUPPLY_STATUS_CHARGING :
457+
POWER_SUPPLY_STATUS_DISCHARGING;
458+
} else
459+
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
456460
break;
457461
case POWER_SUPPLY_PROP_SCOPE:
458462
val->intval = POWER_SUPPLY_SCOPE_DEVICE;
@@ -514,6 +518,7 @@ static int steelseries_headset_battery_register(struct steelseries_device *sd)
514518
/* avoid the warning of 0% battery while waiting for the first info */
515519
steelseries_headset_set_wireless_status(sd->hdev, false);
516520
sd->battery_capacity = 100;
521+
sd->battery_charging = false;
517522

518523
sd->battery = devm_power_supply_register(&sd->hdev->dev,
519524
&sd->battery_desc, &battery_cfg);
@@ -646,6 +651,7 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
646651
struct steelseries_device *sd = hid_get_drvdata(hdev);
647652
int capacity = sd->battery_capacity;
648653
bool connected = sd->headset_connected;
654+
bool charging = sd->battery_charging;
649655
unsigned long flags;
650656

651657
/* Not a headset */
@@ -681,6 +687,7 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
681687

682688
if (read_buf[0] == 0xaa && read_buf[1] == 0x01) {
683689
connected = true;
690+
charging = read_buf[4] == 0x01;
684691

685692
/*
686693
* Found no official documentation about min and max.
@@ -693,6 +700,7 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
693700
* there is no known status of the device read_buf[0] == 0x55
694701
*/
695702
connected = false;
703+
charging = false;
696704
}
697705
}
698706

@@ -713,6 +721,15 @@ static int steelseries_headset_raw_event(struct hid_device *hdev,
713721
power_supply_changed(sd->battery);
714722
}
715723

724+
if (charging != sd->battery_charging) {
725+
hid_dbg(sd->hdev,
726+
"Battery charging status changed from %scharging to %scharging\n",
727+
sd->battery_charging ? "" : "not ",
728+
charging ? "" : "not ");
729+
sd->battery_charging = charging;
730+
power_supply_changed(sd->battery);
731+
}
732+
716733
request_battery:
717734
spin_lock_irqsave(&sd->lock, flags);
718735
if (!sd->removed)

0 commit comments

Comments
 (0)