diff options
author | Landry Breuil <landry@cvs.openbsd.org> | 2024-11-08 21:13:35 +0000 |
---|---|---|
committer | Landry Breuil <landry@cvs.openbsd.org> | 2024-11-08 21:13:35 +0000 |
commit | 9b6cf787da7fc6506b6f0ef1603b47fe8d525054 (patch) | |
tree | 42c4b7593a81f2b209053b4aac62d72fc28f2041 /sys/dev | |
parent | 1248588e735f7b60f23d59cb076795a831a4a3fe (diff) |
qcpas: send APM_POWER_CHANGE events upon ac / battery life changes
allows upowerd to react on power changes, and now i have nifty
notifications in xfce4 on the x13s when plugging/unplugging the ac.
Also works on the omnibook x14.
ok phessler@ kettenis@ jca@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/fdt/qcpas.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/sys/dev/fdt/qcpas.c b/sys/dev/fdt/qcpas.c index 5d05897788a..614ec8591a0 100644 --- a/sys/dev/fdt/qcpas.c +++ b/sys/dev/fdt/qcpas.c @@ -1,4 +1,4 @@ -/* $OpenBSD: qcpas.c,v 1.7 2024/09/01 03:14:48 jsg Exp $ */ +/* $OpenBSD: qcpas.c,v 1.8 2024/11/08 21:13:34 landry Exp $ */ /* * Copyright (c) 2023 Patrick Wildt <patrick@blueri.se> * @@ -1461,6 +1461,7 @@ qcpas_pmic_rtr_bat_status(struct qcpas_softc *sc, extern int hw_power; struct apm_power_info *info = &qcpas_pmic_rtr_apm_power_info; uint32_t delta; + u_char nblife; #endif #ifndef SMALL_KERNEL @@ -1509,8 +1510,10 @@ qcpas_pmic_rtr_bat_status(struct qcpas_softc *sc, return; } - info->battery_life = - ((bat->capacity * 100) / sc->sc_last_full_capacity); + nblife = ((bat->capacity * 100) / sc->sc_last_full_capacity); + if (info->battery_life != nblife) + apm_record_event(APM_POWER_CHANGE); + info->battery_life = nblife; if (info->battery_life > 50) info->battery_state = APM_BATT_HIGH; else if (info->battery_life > 25) @@ -1532,9 +1535,13 @@ qcpas_pmic_rtr_bat_status(struct qcpas_softc *sc, 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; } |