/*-
* Copyright (c) 2007 Michael Lorenz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* battery status */
int sc_flags;
int sc_oflags;
int sc_voltage;
int sc_charge;
int sc_current;
int sc_time;
int sc_cpu_temp;
int sc_bat_temp;
int sc_vmax_charged;
int sc_vmax_charging;
uint32_t sc_timestamp;
};
memset(&sc->sc_sm_acpower, 0, sizeof(struct sysmon_pswitch));
sc->sc_sm_acpower.smpsw_name = "AC Power";
sc->sc_sm_acpower.smpsw_type = PSWITCH_TYPE_ACADAPTER;
if (sysmon_pswitch_register(&sc->sc_sm_acpower) != 0)
aprint_error_dev(self,
"unable to register AC power status with sysmon\n");
}
static int
battery_update(struct battery_softc *sc, int out)
{
int len, vmax, pcharge, vb;
uint8_t buf[16];
if (sc->sc_timestamp == time_second)
return 0;
sc->sc_timestamp = time_second;
len = sc->sc_pmu_ops->do_command(sc->sc_pmu_ops->cookie,
PMU_BATTERY_STATE, 0, NULL, 16, buf);
if (len != 9)
return -1;
sc->sc_flags = buf[1];
if (out) {
if (buf[1] & PMU_PWR_AC_PRESENT)
printf(" AC");
if (buf[1] & PMU_PWR_BATT_CHARGING)
printf(" charging");
if (buf[1] & PMU_PWR_BATT_PRESENT)
printf(" present");
if (buf[1] & PMU_PWR_BATT_FULL)
printf(" full");
printf("\n");
}