summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2021-04-01 10:34:21 +0000
committerkn <kn@openbsd.org>2021-04-01 10:34:21 +0000
commit8706e35857510b21082a2e044b430d55f3cca478 (patch)
tree5796d291ca85d312b0cdabd5e9db562851ba8366
parentmerge NSD 4.3.6rc1 (diff)
downloadwireguard-openbsd-8706e35857510b21082a2e044b430d55f3cca478.tar.xz
wireguard-openbsd-8706e35857510b21082a2e044b430d55f3cca478.zip
Hardcode meaningful alert level, track apm's battery state better
The current code looks for the nonexistent "cellwise,alert-level" property and falls back to zero as threshold (like the original NetBSD code). It also updates the CONFIG register with that very threshold to let the hardware set a bit and thus alert us when it has been reached. Since our sensor framework is designed to poll every N seconds and this driver does not actually look at whether the hardware alerted, neither using a default threshold of zero nor updating the hardware with it makes sense. Remove the alert level code and simply map >50%, >25% and <=25% of remaining battery life to apm(4)'s "high", "low" and "critical" battery state respectively; this matches exactly what acpibat(4) does and provides more meaningful sensor readings without relying on nonexistent device tree bindings. Feedback OK patrick
Diffstat (limited to '')
-rw-r--r--sys/dev/fdt/cwfg.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/sys/dev/fdt/cwfg.c b/sys/dev/fdt/cwfg.c
index 7940273e1a9..ad174fbf1ce 100644
--- a/sys/dev/fdt/cwfg.c
+++ b/sys/dev/fdt/cwfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cwfg.c,v 1.4 2021/03/26 22:54:41 kn Exp $ */
+/* $OpenBSD: cwfg.c,v 1.5 2021/04/01 10:34:21 kn Exp $ */
/* $NetBSD: cwfg.c,v 1.1 2020/01/03 18:00:05 jmcneill Exp $ */
/*-
* Copyright (c) 2020 Jared McNeill <jmcneill@invisible.ca>
@@ -58,8 +58,6 @@
#define RTT_LO_MASK 0xff
#define RTT_LO_SHIFT 0
#define CONFIG_REG 0x08
-#define CONFIG_ATHD_MASK 0x1f
-#define CONFIG_ATHD_SHIFT 3
#define CONFIG_UFG (1 << 1)
#define MODE_REG 0x0a
#define MODE_SLEEP_MASK (0x3 << 6)
@@ -91,7 +89,6 @@ struct cwfg_softc {
uint8_t sc_batinfo[BATINFO_SIZE];
- uint32_t sc_alert_level;
uint32_t sc_monitor_interval;
uint32_t sc_design_capacity;
@@ -101,7 +98,6 @@ struct cwfg_softc {
#define CWFG_MONITOR_INTERVAL_DEFAULT 5000
#define CWFG_DESIGN_CAPACITY_DEFAULT 2000
-#define CWFG_ALERT_LEVEL_DEFAULT 0
int cwfg_match(struct device *, void *, void *);
void cwfg_attach(struct device *, struct device *, void *);
@@ -189,8 +185,6 @@ cwfg_attach(struct device *parent, struct device *self, void *aux)
"cellwise,monitor-interval-ms", CWFG_MONITOR_INTERVAL_DEFAULT);
sc->sc_design_capacity = OF_getpropint(sc->sc_node,
"cellwise,design-capacity", CWFG_DESIGN_CAPACITY_DEFAULT);
- sc->sc_alert_level = OF_getpropint(sc->sc_node,
- "cellwise,alert-level", CWFG_ALERT_LEVEL_DEFAULT);
if (cwfg_init(sc) != 0) {
printf(": failed to initialize device\n");
@@ -271,7 +265,6 @@ done:
int
cwfg_set_config(struct cwfg_softc *sc)
{
- uint32_t alert_level;
uint8_t config, mode, val;
int need_update;
int error, n;
@@ -280,19 +273,6 @@ cwfg_set_config(struct cwfg_softc *sc)
if ((error = cwfg_read(sc, CONFIG_REG, &config)) != 0)
return error;
- /* Update alert level, if necessary */
- alert_level = (config >> CONFIG_ATHD_SHIFT) & CONFIG_ATHD_MASK;
- if (alert_level != sc->sc_alert_level) {
- config &= ~(CONFIG_ATHD_MASK << CONFIG_ATHD_SHIFT);
- config |= (sc->sc_alert_level << CONFIG_ATHD_SHIFT);
- if ((error = cwfg_write(sc, CONFIG_REG, config)) != 0)
- return error;
- }
-
- /* Re-read current config */
- if ((error = cwfg_read(sc, CONFIG_REG, &config)) != 0)
- return error;
-
/*
* We need to upload a battery profile if either the UFG flag
* is unset, or the current battery profile differs from the
@@ -387,9 +367,13 @@ cwfg_update_sensors(void *arg)
sc->sc_sensor[CWFG_SENSOR_SOC].value = val * 1000;
sc->sc_sensor[CWFG_SENSOR_SOC].flags &= ~SENSOR_FINVALID;
#if NAPM > 0
- cwfg_power.battery_state = val > sc->sc_alert_level ?
- APM_BATT_HIGH : APM_BATT_LOW;
cwfg_power.battery_life = val;
+ if (val > 50)
+ cwfg_power.battery_state = APM_BATT_HIGH;
+ else if (val > 25)
+ cwfg_power.battery_state = APM_BATT_LOW;
+ else
+ cwfg_power.battery_state = APM_BATT_CRITICAL;
#endif
}