2007-12-09 23:27:42 +03:00
|
|
|
/* $NetBSD: acpi_bat.c,v 1.64 2007/12/09 20:27:52 jmcneill Exp $ */
|
2003-11-01 06:45:58 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum of By Noon Software, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2001 Bill Sommerfeld.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
#if 0
|
2002-03-24 06:46:10 +03:00
|
|
|
#define ACPI_BAT_DEBUG
|
2002-12-30 16:06:43 +03:00
|
|
|
#endif
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI Battery Driver.
|
|
|
|
*
|
|
|
|
* ACPI defines two different battery device interfaces: "Control
|
|
|
|
* Method" batteries, in which AML methods are defined in order to get
|
|
|
|
* battery status and set battery alarm thresholds, and a "Smart
|
|
|
|
* Battery" device, which is an SMbus device accessed through the ACPI
|
|
|
|
* Embedded Controller device.
|
|
|
|
*
|
|
|
|
* This driver is for the "Control Method"-style battery only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2007-12-09 23:27:42 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.64 2007/12/09 20:27:52 jmcneill Exp $");
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h> /* for hz */
|
|
|
|
#include <sys/device.h>
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
#include <sys/mutex.h>
|
2002-12-31 08:26:56 +03:00
|
|
|
#include <dev/sysmon/sysmonvar.h>
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
#include <dev/acpi/acpica.h>
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
|
2002-12-31 08:26:56 +03:00
|
|
|
/* sensor indexes */
|
2003-02-16 19:50:09 +03:00
|
|
|
#define ACPIBAT_PRESENT 0
|
|
|
|
#define ACPIBAT_DCAPACITY 1
|
|
|
|
#define ACPIBAT_LFCCAPACITY 2
|
|
|
|
#define ACPIBAT_TECHNOLOGY 3
|
|
|
|
#define ACPIBAT_DVOLTAGE 4
|
|
|
|
#define ACPIBAT_WCAPACITY 5
|
|
|
|
#define ACPIBAT_LCAPACITY 6
|
|
|
|
#define ACPIBAT_VOLTAGE 7
|
2003-11-01 13:24:17 +03:00
|
|
|
#define ACPIBAT_CHARGERATE 8
|
|
|
|
#define ACPIBAT_DISCHARGERATE 9
|
|
|
|
#define ACPIBAT_CAPACITY 10
|
|
|
|
#define ACPIBAT_CHARGING 11
|
2007-09-02 23:38:32 +04:00
|
|
|
#define ACPIBAT_CHARGE_STATE 12
|
|
|
|
#define ACPIBAT_NSENSORS 13 /* number of sensors */
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
struct acpibat_softc {
|
|
|
|
struct acpi_devnode *sc_node; /* our ACPI devnode */
|
|
|
|
int sc_flags; /* see below */
|
2003-02-16 19:50:09 +03:00
|
|
|
int sc_available; /* available information level */
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
struct sysmon_envsys *sc_sme;
|
|
|
|
envsys_data_t sc_sensor[ACPIBAT_NSENSORS];
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
kmutex_t sc_mtx;
|
2003-10-31 01:12:02 +03:00
|
|
|
|
|
|
|
struct timeval sc_lastupdate, sc_updateinterval;
|
2002-03-24 06:46:10 +03:00
|
|
|
};
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
static const char * const bat_hid[] = {
|
|
|
|
"PNP0C0A",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
/*
|
|
|
|
* These flags are used to examine the battery device data returned from
|
|
|
|
* the ACPI interface, specifically the "battery status"
|
|
|
|
*/
|
|
|
|
#define ACPIBAT_PWRUNIT_MA 0x00000001 /* mA not mW */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These flags are used to examine the battery charge/discharge/critical
|
|
|
|
* state returned from a get-status command.
|
|
|
|
*/
|
2002-12-31 08:26:56 +03:00
|
|
|
#define ACPIBAT_ST_DISCHARGING 0x00000001 /* battery is discharging */
|
|
|
|
#define ACPIBAT_ST_CHARGING 0x00000002 /* battery is charging */
|
|
|
|
#define ACPIBAT_ST_CRITICAL 0x00000004 /* battery is critical */
|
2002-12-30 12:37:50 +03:00
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
/*
|
|
|
|
* Flags for battery status from _STA return
|
|
|
|
*/
|
2003-02-16 19:50:09 +03:00
|
|
|
#define ACPIBAT_STA_PRESENT 0x00000010 /* battery present */
|
2002-12-30 16:06:43 +03:00
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
/*
|
|
|
|
* These flags are used to set internal state in our softc.
|
|
|
|
*/
|
2002-03-24 06:46:10 +03:00
|
|
|
#define ABAT_F_VERBOSE 0x01 /* verbose events */
|
|
|
|
#define ABAT_F_PWRUNIT_MA 0x02 /* mA instead of mW */
|
2003-02-16 19:50:09 +03:00
|
|
|
#define ABAT_F_PRESENT 0x04 /* is the battery present? */
|
|
|
|
|
|
|
|
#define ABAT_SET(sc, f) (void)((sc)->sc_flags |= (f))
|
|
|
|
#define ABAT_CLEAR(sc, f) (void)((sc)->sc_flags &= ~(f))
|
|
|
|
#define ABAT_ISSET(sc, f) ((sc)->sc_flags & (f))
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
/*
|
|
|
|
* Available info level
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ABAT_ALV_NONE 0 /* none is available */
|
|
|
|
#define ABAT_ALV_PRESENCE 1 /* presence info is available */
|
|
|
|
#define ABAT_ALV_INFO 2 /* battery info is available */
|
|
|
|
#define ABAT_ALV_STAT 3 /* battery status is available */
|
|
|
|
|
2007-10-18 03:30:58 +04:00
|
|
|
static int acpibat_match(device_t, struct cfdata *, void *);
|
|
|
|
static void acpibat_attach(device_t, struct device *, void *);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2007-10-18 03:30:58 +04:00
|
|
|
CFATTACH_DECL_NEW(acpibat, sizeof(struct acpibat_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
acpibat_match, acpibat_attach, NULL, NULL);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
static void acpibat_clear_presence(struct acpibat_softc *);
|
|
|
|
static void acpibat_clear_info(struct acpibat_softc *);
|
|
|
|
static void acpibat_clear_stat(struct acpibat_softc *);
|
2007-10-19 03:54:54 +04:00
|
|
|
static int acpibat_battery_present(device_t);
|
|
|
|
static ACPI_STATUS acpibat_get_status(device_t);
|
|
|
|
static ACPI_STATUS acpibat_get_info(device_t);
|
|
|
|
static void acpibat_print_info(device_t);
|
|
|
|
static void acpibat_print_stat(device_t);
|
2003-02-16 19:50:09 +03:00
|
|
|
static void acpibat_update(void *);
|
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
static void acpibat_init_envsys(device_t);
|
2006-02-16 09:19:26 +03:00
|
|
|
static void acpibat_notify_handler(ACPI_HANDLE, UINT32, void *);
|
2007-11-16 11:00:11 +03:00
|
|
|
static void acpibat_refresh(struct sysmon_envsys *, envsys_data_t *);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_match:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `match' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2007-10-18 03:30:58 +04:00
|
|
|
acpibat_match(device_t parent, struct cfdata *match, void *aux)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
|
|
|
|
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
|
2004-04-11 10:48:25 +04:00
|
|
|
return 0;
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return acpi_match_hid(aa->aa_node->ad_devinfo, bat_hid);
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_attach:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `attach' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2007-10-18 03:30:58 +04:00
|
|
|
acpibat_attach(device_t parent, device_t self, void *aux)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
2007-10-18 03:30:58 +04:00
|
|
|
struct acpibat_softc *sc = device_private(self);
|
2002-03-24 06:46:10 +03:00
|
|
|
struct acpi_attach_args *aa = aux;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_naive(": ACPI Battery (Control Method)\n");
|
|
|
|
aprint_normal(": ACPI Battery (Control Method)\n");
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
sc->sc_node = aa->aa_node;
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
|
2007-07-03 11:44:05 +04:00
|
|
|
ACPI_ALL_NOTIFY,
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_notify_handler, self);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2007-10-18 03:30:58 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to register DEVICE/SYSTEM NOTIFY handler: %s\n",
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
AcpiFormatException(rv));
|
2002-03-24 06:46:10 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-12-30 16:06:43 +03:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
#ifdef ACPI_BAT_DEBUG
|
|
|
|
ABAT_SET(sc, ABAT_F_VERBOSE);
|
|
|
|
#endif
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_init_envsys(self);
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
/*
|
|
|
|
* clear informations
|
|
|
|
*/
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_presence(struct acpibat_softc *sc)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_info(sc);
|
|
|
|
sc->sc_available = ABAT_ALV_NONE;
|
|
|
|
ABAT_CLEAR(sc, ABAT_F_PRESENT);
|
|
|
|
}
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_info(struct acpibat_softc *sc)
|
|
|
|
{
|
|
|
|
acpibat_clear_stat(sc);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
if (sc->sc_available > ABAT_ALV_PRESENCE)
|
2003-02-17 17:37:57 +03:00
|
|
|
sc->sc_available = ABAT_ALV_PRESENCE;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_DCAPACITY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_LFCCAPACITY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_TECHNOLOGY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_DVOLTAGE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].state = ENVSYS_SINVALID;
|
2003-02-16 19:50:09 +03:00
|
|
|
}
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_stat(struct acpibat_softc *sc)
|
|
|
|
{
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
if (sc->sc_available > ABAT_ALV_INFO)
|
2003-02-17 17:37:57 +03:00
|
|
|
sc->sc_available = ABAT_ALV_INFO;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_VOLTAGE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SINVALID;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
|
2002-12-30 16:06:43 +03:00
|
|
|
/*
|
|
|
|
* returns 0 for no battery, 1 for present, and -1 on error
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_battery_present(device_t dv)
|
2002-12-30 16:06:43 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
uint32_t sta;
|
2004-03-24 14:26:46 +03:00
|
|
|
ACPI_INTEGER val;
|
2002-12-30 16:06:43 +03:00
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2003-05-22 19:35:51 +04:00
|
|
|
rv = acpi_eval_integer(sc->sc_node->ad_handle, "_STA", &val);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "failed to evaluate _STA: %s\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
AcpiFormatException(rv));
|
2004-04-11 10:48:25 +04:00
|
|
|
return -1;
|
2002-12-30 16:06:43 +03:00
|
|
|
}
|
|
|
|
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
sta = (uint32_t)val;
|
2002-12-30 16:06:43 +03:00
|
|
|
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2003-02-16 19:50:09 +03:00
|
|
|
sc->sc_available = ABAT_ALV_PRESENCE;
|
|
|
|
if (sta & ACPIBAT_STA_PRESENT) {
|
|
|
|
ABAT_SET(sc, ABAT_F_PRESENT);
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_PRESENT].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_PRESENT].value_cur = 1;
|
2003-02-16 19:50:09 +03:00
|
|
|
} else
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_PRESENT].value_cur = 0;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mtx);
|
2002-12-30 16:06:43 +03:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return (sta & ACPIBAT_STA_PRESENT) ? 1 : 0;
|
2002-12-30 16:06:43 +03:00
|
|
|
}
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_get_info
|
|
|
|
*
|
|
|
|
* Get, and possibly display, the battery info.
|
|
|
|
*/
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static ACPI_STATUS
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_get_info(device_t dv)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2002-03-24 06:46:10 +03:00
|
|
|
ACPI_OBJECT *p1, *p2;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
int capunit, rateunit;
|
2002-12-30 16:06:43 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BIF", &buf);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "failed to evaluate _BIF: %s\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
AcpiFormatException(rv));
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
p1 = (ACPI_OBJECT *)buf.Pointer;
|
2003-11-02 01:55:53 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "expected PACKAGE, got %d\n", p1->Type);
|
2002-03-24 06:46:10 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2002-12-30 07:47:22 +03:00
|
|
|
if (p1->Package.Count < 13) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "expected 13 elements, got %d\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
p1->Package.Count);
|
2002-12-30 07:47:22 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2003-11-02 01:55:53 +03:00
|
|
|
p2 = p1->Package.Elements;
|
2003-02-16 19:50:09 +03:00
|
|
|
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2003-02-16 19:50:09 +03:00
|
|
|
if ((p2[0].Integer.Value & ACPIBAT_PWRUNIT_MA) != 0) {
|
|
|
|
ABAT_SET(sc, ABAT_F_PWRUNIT_MA);
|
|
|
|
capunit = ENVSYS_SAMPHOUR;
|
|
|
|
rateunit = ENVSYS_SAMPS;
|
|
|
|
} else {
|
|
|
|
ABAT_CLEAR(sc, ABAT_F_PWRUNIT_MA);
|
|
|
|
capunit = ENVSYS_SWATTHOUR;
|
|
|
|
rateunit = ENVSYS_SWATTS;
|
|
|
|
}
|
2003-11-02 01:55:53 +03:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_DCAPACITY].units = capunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_LFCCAPACITY].units = capunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].units = capunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].units = capunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].units = rateunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].units = rateunit;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].units = capunit;
|
|
|
|
|
|
|
|
sc->sc_sensor[ACPIBAT_DCAPACITY].value_cur = p2[1].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_DCAPACITY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_LFCCAPACITY].value_cur = p2[2].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_LFCCAPACITY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].value_max = p2[2].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_TECHNOLOGY].value_cur = p2[3].Integer.Value;
|
|
|
|
sc->sc_sensor[ACPIBAT_TECHNOLOGY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_DVOLTAGE].value_cur = p2[4].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_DVOLTAGE].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].value_cur = p2[5].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].value_max = p2[2].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].flags |=
|
2007-08-27 00:47:42 +04:00
|
|
|
(ENVSYS_FPERCENT|ENVSYS_FVALID_MAX);
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].value_cur = p2[6].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].value_max = p2[2].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].flags |=
|
2007-08-27 00:47:42 +04:00
|
|
|
(ENVSYS_FPERCENT|ENVSYS_FVALID_MAX);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
sc->sc_available = ABAT_ALV_INFO;
|
2003-11-02 01:55:53 +03:00
|
|
|
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2003-11-02 01:55:53 +03:00
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_verbose_dev(dv, "battery info: %s, %s, %s",
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
p2[12].String.Pointer, p2[11].String.Pointer, p2[9].String.Pointer);
|
|
|
|
if (p2[10].String.Pointer)
|
2007-10-18 03:30:58 +04:00
|
|
|
aprint_verbose(" %s", p2[10].String.Pointer);
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2007-10-18 03:30:58 +04:00
|
|
|
aprint_verbose("\n");
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
rv = AE_OK;
|
2002-03-24 06:46:10 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_get_status:
|
|
|
|
*
|
|
|
|
* Get, and possibly display, the current battery line status.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static ACPI_STATUS
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_get_status(device_t dv)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
int status, battrate;
|
2002-03-24 06:46:10 +03:00
|
|
|
ACPI_OBJECT *p1, *p2;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
2003-05-22 19:35:51 +04:00
|
|
|
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BST", &buf);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "failed to evaluate _BST: %s\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
AcpiFormatException(rv));
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
p1 = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
|
|
|
|
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "expected PACKAGE, got %d\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
p1->Type);
|
2003-05-22 19:35:51 +04:00
|
|
|
rv = AE_ERROR;
|
|
|
|
goto out;
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
2002-12-30 09:20:02 +03:00
|
|
|
if (p1->Package.Count < 4) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "expected 4 elts, got %d\n",
|
2007-10-18 03:30:58 +04:00
|
|
|
p1->Package.Count);
|
2003-05-22 19:35:51 +04:00
|
|
|
rv = AE_ERROR;
|
|
|
|
goto out;
|
2002-12-30 09:20:02 +03:00
|
|
|
}
|
2002-03-24 06:46:10 +03:00
|
|
|
p2 = p1->Package.Elements;
|
|
|
|
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
status = p2[0].Integer.Value;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
battrate = p2[1].Integer.Value;
|
|
|
|
|
|
|
|
if (status & ACPIBAT_ST_CHARGING) {
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].value_cur = battrate * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 1;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
} else if (status & ACPIBAT_ST_DISCHARGING) {
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].value_cur = battrate * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 0;
|
2007-08-08 12:36:41 +04:00
|
|
|
} else if (!(status & (ACPIBAT_ST_CHARGING|ACPIBAT_ST_DISCHARGING))) {
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 0;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
|
2003-11-01 13:24:17 +03:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].value_cur =
|
2007-11-04 02:05:21 +03:00
|
|
|
ENVSYS_BATTERY_CAPACITY_NORMAL;
|
2007-09-04 20:56:30 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].value_cur = p2[2].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SVALID;
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].flags |=
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
(ENVSYS_FPERCENT|ENVSYS_FVALID_MAX);
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_VOLTAGE].value_cur = p2[3].Integer.Value * 1000;
|
|
|
|
sc->sc_sensor[ACPIBAT_VOLTAGE].state = ENVSYS_SVALID;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sc->sc_sensor[ACPIBAT_CAPACITY].value_cur <
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].value_cur) {
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SWARNUNDER;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].value_cur =
|
2007-11-04 02:05:21 +03:00
|
|
|
ENVSYS_BATTERY_CAPACITY_WARNING;
|
2007-09-02 23:38:32 +04:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sc->sc_sensor[ACPIBAT_CAPACITY].value_cur <
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].value_cur) {
|
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SCRITUNDER;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].value_cur =
|
2007-11-04 02:05:21 +03:00
|
|
|
ENVSYS_BATTERY_CAPACITY_LOW;
|
2007-09-02 23:38:32 +04:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-09-02 23:38:32 +04:00
|
|
|
if (status & ACPIBAT_ST_CRITICAL) {
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CAPACITY].state = ENVSYS_SCRITICAL;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].value_cur =
|
2007-11-04 02:05:21 +03:00
|
|
|
ENVSYS_BATTERY_CAPACITY_CRITICAL;
|
2007-09-02 23:38:32 +04:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mtx);
|
2003-02-16 19:50:09 +03:00
|
|
|
|
2003-05-22 19:35:51 +04:00
|
|
|
rv = AE_OK;
|
2003-11-02 01:55:53 +03:00
|
|
|
|
|
|
|
out:
|
2003-05-22 19:35:51 +04:00
|
|
|
AcpiOsFree(buf.Pointer);
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2003-02-16 19:50:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SCALE(x) ((x)/1000000), (((x)%1000000)/1000)
|
2003-08-31 05:36:12 +04:00
|
|
|
#define CAPUNITS(sc) (ABAT_ISSET((sc), ABAT_F_PWRUNIT_MA)?"Ah":"Wh")
|
|
|
|
#define RATEUNITS(sc) (ABAT_ISSET((sc), ABAT_F_PWRUNIT_MA)?"A":"W")
|
2003-02-16 19:50:09 +03:00
|
|
|
static void
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_print_info(device_t dv)
|
2003-02-16 19:50:09 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2003-02-16 19:50:09 +03:00
|
|
|
const char *tech;
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sc->sc_sensor[ACPIBAT_TECHNOLOGY].value_cur)
|
2003-02-16 19:50:09 +03:00
|
|
|
tech = "secondary";
|
|
|
|
else
|
|
|
|
tech = "primary";
|
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv, "%s battery, Design %d.%03d%s "
|
2007-10-18 03:30:58 +04:00
|
|
|
"Last full %d.%03d%s Warn %d.%03d%s Low %d.%03d%s\n",
|
2007-11-16 11:00:11 +03:00
|
|
|
tech, SCALE(sc->sc_sensor[ACPIBAT_DCAPACITY].value_cur), CAPUNITS(sc),
|
|
|
|
SCALE(sc->sc_sensor[ACPIBAT_LFCCAPACITY].value_cur),CAPUNITS(sc),
|
|
|
|
SCALE(sc->sc_sensor[ACPIBAT_WCAPACITY].value_cur), CAPUNITS(sc),
|
|
|
|
SCALE(sc->sc_sensor[ACPIBAT_LCAPACITY].value_cur), CAPUNITS(sc));
|
2003-02-16 19:50:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_print_stat(device_t dv)
|
2003-02-16 19:50:09 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2003-02-16 19:50:09 +03:00
|
|
|
const char *capstat, *chargestat;
|
2003-05-29 06:47:49 +04:00
|
|
|
int percent, denom;
|
2007-08-08 12:36:41 +04:00
|
|
|
int32_t value;
|
2003-02-16 19:50:09 +03:00
|
|
|
|
2003-05-22 19:35:51 +04:00
|
|
|
percent = 0;
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sc->sc_sensor[ACPIBAT_CAPACITY].state == ENVSYS_SCRITUNDER)
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
capstat = "CRITICAL UNDER ";
|
2007-11-16 11:00:11 +03:00
|
|
|
else if (sc->sc_sensor[ACPIBAT_CAPACITY].state == ENVSYS_SCRITOVER)
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
capstat = "CRITICAL OVER ";
|
2003-02-16 19:50:09 +03:00
|
|
|
else
|
|
|
|
capstat = "";
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sc->sc_sensor[ACPIBAT_CHARGING].state != ENVSYS_SVALID) {
|
2003-02-16 19:50:09 +03:00
|
|
|
chargestat = "idling";
|
2007-08-08 12:36:41 +04:00
|
|
|
value = 0;
|
2007-11-16 11:00:11 +03:00
|
|
|
} else if (sc->sc_sensor[ACPIBAT_CHARGING].value_cur == 0) {
|
2007-08-08 12:36:41 +04:00
|
|
|
chargestat = "discharging";
|
2007-11-16 11:00:11 +03:00
|
|
|
value = sc->sc_sensor[ACPIBAT_DISCHARGERATE].value_cur;
|
2007-08-08 12:36:41 +04:00
|
|
|
} else {
|
|
|
|
chargestat = "charging";
|
2007-11-16 11:00:11 +03:00
|
|
|
value = sc->sc_sensor[ACPIBAT_CHARGERATE].value_cur;
|
2007-08-08 12:36:41 +04:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
denom = sc->sc_sensor[ACPIBAT_LFCCAPACITY].value_cur / 100;
|
2003-05-29 06:47:49 +04:00
|
|
|
if (denom > 0)
|
2007-11-16 11:00:11 +03:00
|
|
|
percent = (sc->sc_sensor[ACPIBAT_CAPACITY].value_cur) / denom;
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv, "%s%s: %d.%03dV cap %d.%03d%s (%d%%) "
|
2007-10-18 03:30:58 +04:00
|
|
|
"rate %d.%03d%s\n", capstat, chargestat,
|
2007-11-16 11:00:11 +03:00
|
|
|
SCALE(sc->sc_sensor[ACPIBAT_VOLTAGE].value_cur),
|
|
|
|
SCALE(sc->sc_sensor[ACPIBAT_CAPACITY].value_cur), CAPUNITS(sc),
|
2007-08-08 12:36:41 +04:00
|
|
|
percent, SCALE(value), RATEUNITS(sc));
|
2003-02-16 19:50:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpibat_update(void *arg)
|
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
device_t dv = arg;
|
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2003-02-16 19:50:09 +03:00
|
|
|
|
|
|
|
if (sc->sc_available < ABAT_ALV_INFO) {
|
|
|
|
/* current information is invalid */
|
2003-02-17 17:37:57 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* XXX: The driver sometimes unaware that the battery exist.
|
|
|
|
* (i.e. just after the boot or resuming)
|
|
|
|
* Thus, the driver should always check it here.
|
|
|
|
*/
|
2003-02-16 19:50:09 +03:00
|
|
|
if (sc->sc_available < ABAT_ALV_PRESENCE)
|
2003-02-17 17:37:57 +03:00
|
|
|
#endif
|
2003-02-16 19:50:09 +03:00
|
|
|
/* presence is invalid */
|
2007-10-19 03:54:54 +04:00
|
|
|
if (acpibat_battery_present(dv) < 0) {
|
2003-02-16 19:50:09 +03:00
|
|
|
/* error */
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"cannot get battery presence.\n");
|
2003-02-16 19:50:09 +03:00
|
|
|
return;
|
2003-02-17 17:37:57 +03:00
|
|
|
}
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
if (ABAT_ISSET(sc, ABAT_F_PRESENT)) {
|
|
|
|
/* the battery is present. */
|
|
|
|
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"battery is present.\n");
|
2007-10-19 03:54:54 +04:00
|
|
|
if (ACPI_FAILURE(acpibat_get_info(dv)))
|
2003-02-16 19:50:09 +03:00
|
|
|
return;
|
|
|
|
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_print_info(dv);
|
2003-02-16 19:50:09 +03:00
|
|
|
} else {
|
|
|
|
/* the battery is not present. */
|
|
|
|
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"battery is not present.\n");
|
2003-02-16 19:50:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* current information is valid */
|
2003-02-17 17:37:57 +03:00
|
|
|
if (!ABAT_ISSET(sc, ABAT_F_PRESENT)) {
|
2003-02-16 19:50:09 +03:00
|
|
|
/* the battery is not present. */
|
|
|
|
return;
|
2003-02-17 17:37:57 +03:00
|
|
|
}
|
2003-02-16 19:50:09 +03:00
|
|
|
}
|
|
|
|
|
2007-10-19 03:54:54 +04:00
|
|
|
if (ACPI_FAILURE(acpibat_get_status(dv)))
|
2003-02-16 19:50:09 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_print_stat(dv);
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpibat_notify_handler:
|
|
|
|
*
|
|
|
|
* Callback from ACPI interrupt handler to notify us of an event.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
2002-03-24 06:46:10 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
device_t dv = context;
|
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
int rv;
|
2002-03-24 06:46:10 +03:00
|
|
|
|
2002-12-30 12:37:50 +03:00
|
|
|
#ifdef ACPI_BAT_DEBUG
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_debug_dev(dv, "received notify message: 0x%x\n", notify);
|
2002-12-30 12:37:50 +03:00
|
|
|
#endif
|
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
switch (notify) {
|
|
|
|
case ACPI_NOTIFY_BusCheck:
|
2002-12-30 12:37:50 +03:00
|
|
|
break;
|
|
|
|
|
2004-06-25 17:47:04 +04:00
|
|
|
case ACPI_NOTIFY_DeviceCheck:
|
2002-03-24 06:46:10 +03:00
|
|
|
case ACPI_NOTIFY_BatteryInformationChanged:
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_presence(sc);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2007-12-09 23:27:42 +03:00
|
|
|
rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, acpibat_update, dv);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"unable to queue status check: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2002-12-30 16:06:43 +03:00
|
|
|
break;
|
2002-12-30 12:37:50 +03:00
|
|
|
|
|
|
|
case ACPI_NOTIFY_BatteryStatusChanged:
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_enter(&sc->sc_mtx);
|
2003-02-16 19:50:09 +03:00
|
|
|
acpibat_clear_stat(sc);
|
Imported envsys 2, a brief description of the new features:
(Part 2: drivers)
* Support for detachable sensors.
* Cleaned up the API for simplicity and efficiency.
* Ability to send capacity/critical/warning events to powerd(8).
* Adapted all the code to the new locking order.
* Compatibility with the old envsys API: the ENVSYS_GTREINFO
and ENVSYS_GTREDATA ioctl(2)s are supported.
* Added support for a 'dictionary based communication channel' between
sysmon_power(9) and powerd(8), that means there is no 32 bytes event
size restriction anymore.
* Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40.
* All drivers with the n^2 gtredata bug were fixed, PR kern/36226.
Tested by:
blymn: smsc(4).
bouyer: ipmi(4), mfi(4).
kefren: ug(4).
njoly: viaenv(4), adt7463.c.
riz: owtemp(4).
xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
2007-07-01 11:37:12 +04:00
|
|
|
mutex_exit(&sc->sc_mtx);
|
2007-12-09 23:27:42 +03:00
|
|
|
rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, acpibat_update, dv);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"unable to queue status check: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2002-03-24 06:46:10 +03:00
|
|
|
break;
|
2002-12-30 12:37:50 +03:00
|
|
|
|
2002-03-24 06:46:10 +03:00
|
|
|
default:
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv,
|
2007-10-18 03:30:58 +04:00
|
|
|
"received unknown notify message: 0x%x\n", notify);
|
2002-03-24 06:46:10 +03:00
|
|
|
}
|
|
|
|
}
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_init_envsys(device_t dv)
|
2002-12-31 08:26:56 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2007-11-16 11:00:11 +03:00
|
|
|
int i, capunit, rateunit;
|
2002-12-31 08:26:56 +03:00
|
|
|
|
|
|
|
if (sc->sc_flags & ABAT_F_PWRUNIT_MA) {
|
|
|
|
capunit = ENVSYS_SAMPHOUR;
|
|
|
|
rateunit = ENVSYS_SAMPS;
|
|
|
|
} else {
|
|
|
|
capunit = ENVSYS_SWATTHOUR;
|
|
|
|
rateunit = ENVSYS_SWATTS;
|
|
|
|
}
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
#define INITDATA(index, unit, string) \
|
|
|
|
sc->sc_sensor[index].state = ENVSYS_SVALID; \
|
|
|
|
sc->sc_sensor[index].units = unit; \
|
|
|
|
strlcpy(sc->sc_sensor[index].desc, string, \
|
|
|
|
sizeof(sc->sc_sensor[index].desc));
|
2003-11-02 01:55:53 +03:00
|
|
|
|
2003-02-16 19:50:09 +03:00
|
|
|
INITDATA(ACPIBAT_PRESENT, ENVSYS_INDICATOR, "present");
|
2002-12-31 08:26:56 +03:00
|
|
|
INITDATA(ACPIBAT_DCAPACITY, capunit, "design cap");
|
2003-11-01 12:49:45 +03:00
|
|
|
INITDATA(ACPIBAT_LFCCAPACITY, capunit, "last full cap");
|
2002-12-31 08:26:56 +03:00
|
|
|
INITDATA(ACPIBAT_TECHNOLOGY, ENVSYS_INTEGER, "technology");
|
|
|
|
INITDATA(ACPIBAT_DVOLTAGE, ENVSYS_SVOLTS_DC, "design voltage");
|
|
|
|
INITDATA(ACPIBAT_WCAPACITY, capunit, "warn cap");
|
|
|
|
INITDATA(ACPIBAT_LCAPACITY, capunit, "low cap");
|
|
|
|
INITDATA(ACPIBAT_VOLTAGE, ENVSYS_SVOLTS_DC, "voltage");
|
2003-11-01 13:24:17 +03:00
|
|
|
INITDATA(ACPIBAT_CHARGERATE, rateunit, "charge rate");
|
|
|
|
INITDATA(ACPIBAT_DISCHARGERATE, rateunit, "discharge rate");
|
|
|
|
INITDATA(ACPIBAT_CAPACITY, capunit, "charge");
|
2007-11-04 02:05:21 +03:00
|
|
|
INITDATA(ACPIBAT_CHARGING, ENVSYS_BATTERY_CHARGE, "charging");
|
|
|
|
INITDATA(ACPIBAT_CHARGE_STATE, ENVSYS_BATTERY_CAPACITY, "charge state");
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2003-11-02 01:55:53 +03:00
|
|
|
#undef INITDATA
|
|
|
|
|
2007-09-04 20:56:30 +04:00
|
|
|
/* Enable monitoring for the charge state sensor */
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].monitor = true;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGE_STATE].flags |= ENVSYS_FMONSTCHANGED;
|
2007-08-27 00:47:42 +04:00
|
|
|
|
|
|
|
/* Disable userland monitoring on these sensors */
|
2007-11-16 11:00:11 +03:00
|
|
|
sc->sc_sensor[ACPIBAT_VOLTAGE].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_CHARGERATE].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_DISCHARGERATE].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_DCAPACITY].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_LFCCAPACITY].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_TECHNOLOGY].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_DVOLTAGE].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_WCAPACITY].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
sc->sc_sensor[ACPIBAT_LCAPACITY].flags = ENVSYS_FMONNOTSUPP;
|
|
|
|
|
|
|
|
sc->sc_sme = sysmon_envsys_create();
|
|
|
|
for (i = 0; i < ACPIBAT_NSENSORS; i++) {
|
|
|
|
if (sysmon_envsys_sensor_attach(sc->sc_sme,
|
|
|
|
&sc->sc_sensor[i])) {
|
|
|
|
aprint_error_dev(dv, "unable to add sensor%d\n", i);
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_sme->sme_name = device_xname(dv);
|
|
|
|
sc->sc_sme->sme_cookie = dv;
|
|
|
|
sc->sc_sme->sme_refresh = acpibat_refresh;
|
|
|
|
sc->sc_sme->sme_class = SME_CLASS_BATTERY;
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2003-10-31 01:12:02 +03:00
|
|
|
sc->sc_updateinterval.tv_sec = 1;
|
|
|
|
sc->sc_updateinterval.tv_usec = 0;
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
if (sysmon_envsys_register(sc->sc_sme)) {
|
2007-10-19 03:54:54 +04:00
|
|
|
aprint_error_dev(dv, "unable to register with sysmon\n");
|
2007-11-16 11:00:11 +03:00
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
|
|
|
}
|
2002-12-31 08:26:56 +03:00
|
|
|
}
|
|
|
|
|
2007-11-16 11:00:11 +03:00
|
|
|
static void
|
|
|
|
acpibat_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
|
2002-12-31 08:26:56 +03:00
|
|
|
{
|
2007-10-19 03:54:54 +04:00
|
|
|
device_t dv = sme->sme_cookie;
|
|
|
|
struct acpibat_softc *sc = device_private(dv);
|
2002-12-31 08:26:56 +03:00
|
|
|
|
2003-10-31 01:12:02 +03:00
|
|
|
if (ratecheck(&sc->sc_lastupdate, &sc->sc_updateinterval))
|
2007-10-19 03:54:54 +04:00
|
|
|
acpibat_update(dv);
|
2002-12-31 08:26:56 +03:00
|
|
|
}
|