Download raw body.
qcpas: generate apm events upon ac state changes
On Fri, Nov 08, 2024 at 07:06:44PM +0100, Landry Breuil wrote:
> hi,
>
> small diff that allows qcpas to send apm events when the ac is plugged
> in/unplugged, thanks jca@ for the pointer.
>
> in userland, that's used by sysutils/upower that gives me the fancy battery/ac
> status via xfce4-power-manager on the x13s, before that it never got events on
> ac state changes, only the battery levels.
>
> i don't know if events should be sent upon battery level changes,
That would be nice for people using apmd -z/-Z. Probably using the
same trick but with info->battery_life. Untested diff below if you
want to give it a try.
> i know upower
> doesn't use them as it reads the 'remaining capacity' value from
> hw.sensors.qcpas0, cf https://gitlab.freedesktop.org/upower/upower/-/blob/master/src/openbsd/up-backend.c?ref_type=heads#L393.
>
> will also test on the omnibook x14 in a few.
>
> Index: qcpas.c
> ===================================================================
> RCS file: /cvs/src/sys/dev/fdt/qcpas.c,v
> diff -u -p -r1.7 qcpas.c
> --- qcpas.c 1 Sep 2024 03:14:48 -0000 1.7
> +++ qcpas.c 8 Nov 2024 17:51:25 -0000
> @@ -1532,9 +1532,13 @@ qcpas_pmic_rtr_bat_status(struct qcpas_s
> info->minutes_left = (60 * delta) / abs(bat->rate);
>
> if (bat->power_state & BATTMGR_PWR_STATE_AC_ON) {
> + if (info->ac_state != APM_AC_ON)
> + apm_record_event(APM_POWER_CHANGE);
> info->ac_state = APM_AC_ON;
> hw_power = 1;
> } else {
> + if (info->ac_state != APM_AC_OFF)
> + apm_record_event(APM_POWER_CHANGE);
> info->ac_state = APM_AC_OFF;
> hw_power = 0;
> }
>
> i'm also attaching a small test program that prints apm events received by
> kqueue on stderr.
>
> comments ?
ok jca@ for the AC status change. If the additional diff below works
for you, feel free to commit it.
Index: dev/fdt/qcpas.c
===================================================================
RCS file: /cvs/src/sys/dev/fdt/qcpas.c,v
diff -u -p -r1.7 qcpas.c
--- dev/fdt/qcpas.c 1 Sep 2024 03:14:48 -0000 1.7
+++ dev/fdt/qcpas.c 8 Nov 2024 18:20:12 -0000
@@ -1461,6 +1461,7 @@ qcpas_pmic_rtr_bat_status(struct qcpas_s
extern int hw_power;
struct apm_power_info *info = &qcpas_pmic_rtr_apm_power_info;
uint32_t delta;
+ u_char battery_life;
#endif
#ifndef SMALL_KERNEL
@@ -1509,8 +1510,10 @@ qcpas_pmic_rtr_bat_status(struct qcpas_s
return;
}
- info->battery_life =
- ((bat->capacity * 100) / sc->sc_last_full_capacity);
+ battery_life = ((bat->capacity * 100) / sc->sc_last_full_capacity);
+ if (battery_life != info->battery_life)
+ apm_record_event(APM_POWER_CHANGE);
+ info->battery_life = battery_life;
if (info->battery_life > 50)
info->battery_state = APM_BATT_HIGH;
else if (info->battery_life > 25)
--
jca
qcpas: generate apm events upon ac state changes