drivers/acpi/battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
When entering the acpi_mattery_notify function, no matter what the event
is, acpi_mattery_update will definitely be called.
Use the acpi_listen command to listen, sometimes the log looks like this:
battery xxx:00 00000081 00000001
battery xxx:00 00000000 00000001
battery xxx:00 00000080 00000001
Firmware manufacturers will customize some events like 0x0, so
non-matching events will be ignored.
Signed-off-by: zhangzihuan <zhangzihuan@kylinos.cn>
---
drivers/acpi/battery.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 6760330a8af5..9446c57b77e7 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1083,7 +1083,8 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
msleep(battery_notification_delay_ms);
if (event == ACPI_BATTERY_NOTIFY_INFO)
acpi_battery_refresh(battery);
- acpi_battery_update(battery, false);
+ if (event == ACPI_BATTERY_NOTIFY_STATUS)
+ acpi_battery_update(battery, false);
acpi_bus_generate_netlink_event(device->pnp.device_class,
dev_name(&device->dev), event,
acpi_battery_present(battery));
--
2.25.1
On Tue, Apr 22, 2025 at 11:11 AM zhangzihuan <zhangzihuan@kylinos.cn> wrote: > > When entering the acpi_mattery_notify function, no matter what the event > is, acpi_mattery_update will definitely be called. I think you mean acpi_battery_update(). > Use the acpi_listen command to listen, sometimes the log looks like this: > > battery xxx:00 00000081 00000001 > battery xxx:00 00000000 00000001 > battery xxx:00 00000080 00000001 > > Firmware manufacturers will customize some events like 0x0, so > non-matching events will be ignored. I don't quite get what you are trying to achieve here. > Signed-off-by: zhangzihuan <zhangzihuan@kylinos.cn> > --- > drivers/acpi/battery.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c > index 6760330a8af5..9446c57b77e7 100644 > --- a/drivers/acpi/battery.c > +++ b/drivers/acpi/battery.c > @@ -1083,7 +1083,8 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) > msleep(battery_notification_delay_ms); > if (event == ACPI_BATTERY_NOTIFY_INFO) > acpi_battery_refresh(battery); > - acpi_battery_update(battery, false); > + if (event == ACPI_BATTERY_NOTIFY_STATUS) > + acpi_battery_update(battery, false); So only call acpi_battery_update() for ACPI_BATTERY_NOTIFY_STATUS. Why do you think this is the only case in which acpi_battery_update() needs to be called? > acpi_bus_generate_netlink_event(device->pnp.device_class, > dev_name(&device->dev), event, > acpi_battery_present(battery)); > --
Hi Rafael, Thank you for the review! 在 2025/5/10 02:23, Rafael J. Wysocki 写道: > On Tue, Apr 22, 2025 at 11:11 AM zhangzihuan <zhangzihuan@kylinos.cn> wrote: >> When entering the acpi_mattery_notify function, no matter what the event >> is, acpi_mattery_update will definitely be called. > I think you mean acpi_battery_update(). Right. >> Use the acpi_listen command to listen, sometimes the log looks like this: >> >> battery xxx:00 00000081 00000001 >> battery xxx:00 00000000 00000001 >> battery xxx:00 00000080 00000001 >> >> Firmware manufacturers will customize some events like 0x0, so >> non-matching events will be ignored. > I don't quite get what you are trying to achieve here. > While the laptop is charging, acpi_battery_notify() receives a steady stream of 0x81 events, and only receives 0x80 events when the battery is almost fully charged or the adapter is plugged in. If acpi_battery_update() is just to update the battery status, it didn't need to be called frequently. >> Signed-off-by: zhangzihuan <zhangzihuan@kylinos.cn> >> --- >> drivers/acpi/battery.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c >> index 6760330a8af5..9446c57b77e7 100644 >> --- a/drivers/acpi/battery.c >> +++ b/drivers/acpi/battery.c >> @@ -1083,7 +1083,8 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) >> msleep(battery_notification_delay_ms); >> if (event == ACPI_BATTERY_NOTIFY_INFO) >> acpi_battery_refresh(battery); >> - acpi_battery_update(battery, false); >> + if (event == ACPI_BATTERY_NOTIFY_STATUS) >> + acpi_battery_update(battery, false); > So only call acpi_battery_update() for ACPI_BATTERY_NOTIFY_STATUS. > > Why do you think this is the only case in which acpi_battery_update() > needs to be called? acpi_battery_update() calls acpi_battery_get_status() to get the battery update status. It will only be updated if it receives an event that the battery status has changed. >> acpi_bus_generate_netlink_event(device->pnp.device_class, >> dev_name(&device->dev), event, >> acpi_battery_present(battery)); >> --
© 2016 - 2026 Red Hat, Inc.