Skip to content

Commit 207efc7

Browse files
JoseExpositogregkh
authored andcommitted
HID: input: report battery status changes immediately
[ Upstream commit e94536e ] Previously, the battery status (charging/discharging) was not reported immediately to user-space.  For most input devices, this wasn't problematic because changing their battery status requires connecting them to a different bus. For example, a gamepad would report a discharging status while connected via Bluetooth and a charging status while connected via USB. However, certain devices are not connected or disconnected when their battery status changes. For example, a phone battery changes its status without connecting or disconnecting it. In these cases, the battery status was not reported immediately to user space. Report battery status changes immediately to user space to support these kinds of devices. Fixes: a608dc1 ("HID: input: map battery system charging") Reported-by: 卢国宏 <luguohong@xiaomi.com> Closes: https://lore.kernel.org/linux-input/aI49Im0sGb6fpgc8@fedora/T/ Tested-by: 卢国宏 <luguohong@xiaomi.com> Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7450f1b commit 207efc7

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

drivers/hid/hid-input.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,19 @@ static bool hidinput_update_battery_charge_status(struct hid_device *dev,
609609
return false;
610610
}
611611

612-
static void hidinput_update_battery(struct hid_device *dev, int value)
612+
static void hidinput_update_battery(struct hid_device *dev, unsigned int usage,
613+
int value)
613614
{
614615
int capacity;
615616

616617
if (!dev->battery)
617618
return;
618619

620+
if (hidinput_update_battery_charge_status(dev, usage, value)) {
621+
power_supply_changed(dev->battery);
622+
return;
623+
}
624+
619625
if (value == 0 || value < dev->battery_min || value > dev->battery_max)
620626
return;
621627

@@ -642,13 +648,8 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
642648
{
643649
}
644650

645-
static bool hidinput_update_battery_charge_status(struct hid_device *dev,
646-
unsigned int usage, int value)
647-
{
648-
return false;
649-
}
650-
651-
static void hidinput_update_battery(struct hid_device *dev, int value)
651+
static void hidinput_update_battery(struct hid_device *dev, unsigned int usage,
652+
int value)
652653
{
653654
}
654655
#endif /* CONFIG_HID_BATTERY_STRENGTH */
@@ -1515,11 +1516,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
15151516
return;
15161517

15171518
if (usage->type == EV_PWR) {
1518-
bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
1519-
1520-
if (!handled)
1521-
hidinput_update_battery(hid, value);
1522-
1519+
hidinput_update_battery(hid, usage->hid, value);
15231520
return;
15241521
}
15251522

0 commit comments

Comments
 (0)