diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-05-17 22:12:52 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-05-17 22:12:52 +0000 |
commit | 7881351b4f494a8ce03efa0ae1671b61fc15ea34 (patch) | |
tree | 3bcfb5aad2cf5e7423d23aa8e4ecc5f668091e04 /sbin/sysctl | |
parent | fa07bd825a90d6a2043a814a621a898caddac440 (diff) |
Implement battery management sysctl. This will provide a set of sysctls
to control the charging of laptop batteries:
* hw.battery.chargemode (int)
-1: force discharge
0: inhibit charge
1: auto
In auto mode charging may be controlled by:
* hw.battery.chargestop (int)
Percentage (0-100) of last full capacity at which the battery should
stop charging.
* hw.battery.chargestart (int)
Percentage (0-100) of last full capacity at which the battery should
start charging.
The idea is that with
hw.battery.chargemode=1
hw.battery.chargestop=80
hw.battery.chargestart=75
the battery would be kept charged within the range between 75% and 80%.
Allowable settings and some details of the behavior may differ between
hardware implementations.
Committing this early to easy testing of further diffs that implement this
functionality in acpithinkpad(4) and aplsmc(4).
ok kn@
Diffstat (limited to 'sbin/sysctl')
-rw-r--r-- | sbin/sysctl/sysctl.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index e7ce921994a..c22bd4b94ec 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.258 2021/07/12 15:09:19 beck Exp $ */ +/* $OpenBSD: sysctl.c,v 1.259 2023/05/17 22:12:51 kettenis Exp $ */ /* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */ /* @@ -132,6 +132,7 @@ struct ctlname ddbname[] = CTL_DDB_NAMES; struct ctlname audioname[] = CTL_KERN_AUDIO_NAMES; struct ctlname videoname[] = CTL_KERN_VIDEO_NAMES; struct ctlname witnessname[] = CTL_KERN_WITNESS_NAMES; +struct ctlname batteryname[] = CTL_HW_BATTERY_NAMES; char names[BUFSIZ]; int lastused; @@ -223,6 +224,7 @@ int sysctl_chipset(char *, char **, int *, int, int *); int sysctl_audio(char *, char **, int *, int, int *); int sysctl_video(char *, char **, int *, int, int *); int sysctl_witness(char *, char **, int *, int, int *); +int sysctl_battery(char *, char **, int *, int, int *); void vfsinit(void); char *equ = "="; @@ -558,6 +560,11 @@ parse(char *string, int flags) if (len < 0) return; break; + case HW_BATTERY: + len = sysctl_battery(string, &bufp, mib, flags, &type); + if (len < 0) + return; + break; case HW_PHYSMEM: case HW_USERMEM: /* @@ -1782,6 +1789,7 @@ struct list tclist = { tcname, KERN_TIMECOUNTER_MAXID }; struct list audiolist = { audioname, KERN_AUDIO_MAXID }; struct list videolist = { videoname, KERN_VIDEO_MAXID }; struct list witnesslist = { witnessname, KERN_WITNESS_MAXID }; +struct list batterylist = { batteryname, HW_BATTERY_MAXID }; /* * handle vfs namei cache statistics @@ -2912,6 +2920,26 @@ sysctl_witness(char *string, char **bufpp, int mib[], int flags, int *typep) } /* + * Handle battery support + */ +int +sysctl_battery(char *string, char **bufpp, int mib[], int flags, + int *typep) +{ + int indx; + + if (*bufpp == NULL) { + listall(string, &batterylist); + return (-1); + } + if ((indx = findname(string, "third", bufpp, &batterylist)) == -1) + return (-1); + mib[2] = indx; + *typep = batterylist.list[indx].ctl_type; + return (3); +} + +/* * Scan a list of names searching for a particular name. */ int |