1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-19 10:53:58 +00:00

Provide an analogous sysctl to hw.acpi.acline (dev.pmu.0.acline) to

determine whether the computer is plugged in to mains power.
This commit is contained in:
Nathan Whitehorn 2009-05-31 10:02:20 +00:00
parent 89614fc2ff
commit 1165ddc233
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=193159

View File

@ -72,6 +72,7 @@ static void pmu_poll(device_t dev);
static void pmu_set_sleepled(void *xsc, int onoff);
static int pmu_server_mode(SYSCTL_HANDLER_ARGS);
static int pmu_acline_state(SYSCTL_HANDLER_ARGS);
static int pmu_query_battery(struct pmu_softc *sc, int batt,
struct pmu_battstate *info);
static int pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS);
@ -393,6 +394,10 @@ pmu_attach(device_t dev)
struct sysctl_oid *oid, *battroot;
char battnum[2];
SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
"acline", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
pmu_acline_state, "I", "AC Line Status");
battroot = SYSCTL_ADD_NODE(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
"batteries", CTLFLAG_RD, 0, "Battery Information");
@ -842,6 +847,27 @@ pmu_query_battery(struct pmu_softc *sc, int batt, struct pmu_battstate *info)
return (0);
}
static int
pmu_acline_state(SYSCTL_HANDLER_ARGS)
{
struct pmu_softc *sc;
struct pmu_battstate batt;
int error, result;
sc = arg1;
/* The PMU treats the AC line status as a property of the battery */
error = pmu_query_battery(sc, 0, &batt);
if (error != 0)
return (error);
result = (batt.state & PMU_PWR_AC_PRESENT) ? 1 : 0;
error = sysctl_handle_int(oidp, &result, 0, req);
return (error);
}
static int
pmu_battquery_sysctl(SYSCTL_HANDLER_ARGS)
{