Separate softc and device_t. Convert to aprint API and make the driver
less verbose by default.
This commit is contained in:
parent
ebae510efc
commit
8302c6904b
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: acpi_bat.c,v 1.57 2007/10/10 23:25:40 xtraeme Exp $ */
|
||||
/* $NetBSD: acpi_bat.c,v 1.58 2007/10/17 23:30:58 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
@ -86,7 +86,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.57 2007/10/10 23:25:40 xtraeme Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.58 2007/10/17 23:30:58 joerg Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -116,7 +116,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.57 2007/10/10 23:25:40 xtraeme Exp $"
|
||||
#define ACPIBAT_NSENSORS 13 /* number of sensors */
|
||||
|
||||
struct acpibat_softc {
|
||||
struct device sc_dev; /* base device glue */
|
||||
device_t sc_dev; /* base device glue */
|
||||
struct acpi_devnode *sc_node; /* our ACPI devnode */
|
||||
int sc_flags; /* see below */
|
||||
int sc_available; /* available information level */
|
||||
@ -172,10 +172,10 @@ static const char * const bat_hid[] = {
|
||||
#define ABAT_ALV_INFO 2 /* battery info is available */
|
||||
#define ABAT_ALV_STAT 3 /* battery status is available */
|
||||
|
||||
static int acpibat_match(struct device *, struct cfdata *, void *);
|
||||
static void acpibat_attach(struct device *, struct device *, void *);
|
||||
static int acpibat_match(device_t, struct cfdata *, void *);
|
||||
static void acpibat_attach(device_t, struct device *, void *);
|
||||
|
||||
CFATTACH_DECL(acpibat, sizeof(struct acpibat_softc),
|
||||
CFATTACH_DECL_NEW(acpibat, sizeof(struct acpibat_softc),
|
||||
acpibat_match, acpibat_attach, NULL, NULL);
|
||||
|
||||
static void acpibat_clear_presence(struct acpibat_softc *);
|
||||
@ -198,7 +198,7 @@ static int acpibat_gtredata(struct sysmon_envsys *, envsys_data_t *);
|
||||
* Autoconfiguration `match' routine.
|
||||
*/
|
||||
static int
|
||||
acpibat_match(struct device *parent, struct cfdata *match, void *aux)
|
||||
acpibat_match(device_t parent, struct cfdata *match, void *aux)
|
||||
{
|
||||
struct acpi_attach_args *aa = aux;
|
||||
|
||||
@ -214,15 +214,16 @@ acpibat_match(struct device *parent, struct cfdata *match, void *aux)
|
||||
* Autoconfiguration `attach' routine.
|
||||
*/
|
||||
static void
|
||||
acpibat_attach(struct device *parent, struct device *self, void *aux)
|
||||
acpibat_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
struct acpibat_softc *sc = (void *) self;
|
||||
struct acpibat_softc *sc = device_private(self);
|
||||
struct acpi_attach_args *aa = aux;
|
||||
ACPI_STATUS rv;
|
||||
|
||||
aprint_naive(": ACPI Battery (Control Method)\n");
|
||||
aprint_normal(": ACPI Battery (Control Method)\n");
|
||||
|
||||
sc->sc_dev = self;
|
||||
sc->sc_node = aa->aa_node;
|
||||
mutex_init(&sc->sc_mtx, MUTEX_DRIVER, IPL_NONE);
|
||||
|
||||
@ -230,8 +231,8 @@ acpibat_attach(struct device *parent, struct device *self, void *aux)
|
||||
ACPI_ALL_NOTIFY,
|
||||
acpibat_notify_handler, sc);
|
||||
if (ACPI_FAILURE(rv)) {
|
||||
aprint_error("%s: unable to register DEVICE/SYSTEM NOTIFY "
|
||||
"handler: %s\n", sc->sc_dev.dv_xname,
|
||||
aprint_error_dev(self,
|
||||
"unable to register DEVICE/SYSTEM NOTIFY handler: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
return;
|
||||
}
|
||||
@ -297,8 +298,8 @@ acpibat_battery_present(struct acpibat_softc *sc)
|
||||
|
||||
rv = acpi_eval_integer(sc->sc_node->ad_handle, "_STA", &val);
|
||||
if (ACPI_FAILURE(rv)) {
|
||||
printf("%s: failed to evaluate _STA: %s\n",
|
||||
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
||||
aprint_error_dev(sc->sc_dev, "failed to evaluate _STA: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -334,20 +335,20 @@ acpibat_get_info(struct acpibat_softc *sc)
|
||||
|
||||
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BIF", &buf);
|
||||
if (ACPI_FAILURE(rv)) {
|
||||
printf("%s: failed to evaluate _BIF: %s\n",
|
||||
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
||||
aprint_error_dev(sc->sc_dev, "failed to evaluate _BIF: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
return rv;
|
||||
}
|
||||
p1 = (ACPI_OBJECT *)buf.Pointer;
|
||||
|
||||
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
||||
printf("%s: expected PACKAGE, got %d\n", sc->sc_dev.dv_xname,
|
||||
aprint_error_dev(sc->sc_dev, "expected PACKAGE, got %d\n",
|
||||
p1->Type);
|
||||
goto out;
|
||||
}
|
||||
if (p1->Package.Count < 13) {
|
||||
printf("%s: expected 13 elts, got %d\n",
|
||||
sc->sc_dev.dv_xname, p1->Package.Count);
|
||||
aprint_error_dev(sc->sc_dev, "expected 13 elements, got %d\n",
|
||||
p1->Package.Count);
|
||||
goto out;
|
||||
}
|
||||
p2 = p1->Package.Elements;
|
||||
@ -394,12 +395,12 @@ acpibat_get_info(struct acpibat_softc *sc)
|
||||
|
||||
mutex_exit(&sc->sc_mtx);
|
||||
|
||||
aprint_normal("%s: battery info: %s, %s, %s", sc->sc_dev.dv_xname,
|
||||
aprint_verbose_dev(sc->sc_dev, "battery info: %s, %s, %s",
|
||||
p2[12].String.Pointer, p2[11].String.Pointer, p2[9].String.Pointer);
|
||||
if (p2[10].String.Pointer)
|
||||
aprint_normal(" %s", p2[10].String.Pointer);
|
||||
aprint_verbose(" %s", p2[10].String.Pointer);
|
||||
|
||||
aprint_normal("\n");
|
||||
aprint_verbose("\n");
|
||||
|
||||
rv = AE_OK;
|
||||
|
||||
@ -423,19 +424,21 @@ acpibat_get_status(struct acpibat_softc *sc)
|
||||
|
||||
rv = acpi_eval_struct(sc->sc_node->ad_handle, "_BST", &buf);
|
||||
if (ACPI_FAILURE(rv)) {
|
||||
printf("%s: failed to evaluate _BST: %s\n",
|
||||
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
||||
aprint_error_dev(sc->sc_dev, "failed to evaluate _BST: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
return rv;
|
||||
}
|
||||
p1 = (ACPI_OBJECT *)buf.Pointer;
|
||||
|
||||
if (p1->Type != ACPI_TYPE_PACKAGE) {
|
||||
printf("bat: expected PACKAGE, got %d\n", p1->Type);
|
||||
aprint_error_dev(sc->sc_dev, "expected PACKAGE, got %d\n",
|
||||
p1->Type);
|
||||
rv = AE_ERROR;
|
||||
goto out;
|
||||
}
|
||||
if (p1->Package.Count < 4) {
|
||||
printf("bat: expected 4 elts, got %d\n", p1->Package.Count);
|
||||
aprint_error_dev(sc->sc_dev, "expected 4 elts, got %d\n",
|
||||
p1->Package.Count);
|
||||
rv = AE_ERROR;
|
||||
goto out;
|
||||
}
|
||||
@ -517,13 +520,12 @@ acpibat_print_info(struct acpibat_softc *sc)
|
||||
else
|
||||
tech = "primary";
|
||||
|
||||
aprint_normal("%s: %s battery, Design %d.%03d%s, Last full %d.%03d%s "
|
||||
"Warn %d.%03d%s Low %d.%03d%s\n",
|
||||
sc->sc_dev.dv_xname, tech,
|
||||
SCALE(sc->sc_data[ACPIBAT_DCAPACITY].value_cur), CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_LFCCAPACITY].value_cur),CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_WCAPACITY].value_cur), CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_LCAPACITY].value_cur), CAPUNITS(sc));
|
||||
aprint_debug_dev(sc->sc_dev, "%s battery, Design %d.%03d%s "
|
||||
"Last full %d.%03d%s Warn %d.%03d%s Low %d.%03d%s\n",
|
||||
tech, SCALE(sc->sc_data[ACPIBAT_DCAPACITY].value_cur), CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_LFCCAPACITY].value_cur),CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_WCAPACITY].value_cur), CAPUNITS(sc),
|
||||
SCALE(sc->sc_data[ACPIBAT_LCAPACITY].value_cur), CAPUNITS(sc));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -557,8 +559,8 @@ acpibat_print_stat(struct acpibat_softc *sc)
|
||||
if (denom > 0)
|
||||
percent = (sc->sc_data[ACPIBAT_CAPACITY].value_cur) / denom;
|
||||
|
||||
aprint_normal("%s: %s%s: %d.%03dV cap %d.%03d%s (%d%%) "
|
||||
"rate %d.%03d%s\n", sc->sc_dev.dv_xname, capstat, chargestat,
|
||||
aprint_debug_dev(sc->sc_dev, "%s%s: %d.%03dV cap %d.%03d%s (%d%%) "
|
||||
"rate %d.%03d%s\n", capstat, chargestat,
|
||||
SCALE(sc->sc_data[ACPIBAT_VOLTAGE].value_cur),
|
||||
SCALE(sc->sc_data[ACPIBAT_CAPACITY].value_cur), CAPUNITS(sc),
|
||||
percent, SCALE(value), RATEUNITS(sc));
|
||||
@ -582,16 +584,16 @@ acpibat_update(void *arg)
|
||||
/* presence is invalid */
|
||||
if (acpibat_battery_present(sc) < 0) {
|
||||
/* error */
|
||||
aprint_debug("%s: cannot get battery "
|
||||
"presence.\n", sc->sc_dev.dv_xname);
|
||||
aprint_debug_dev(sc->sc_dev,
|
||||
"cannot get battery presence.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ABAT_ISSET(sc, ABAT_F_PRESENT)) {
|
||||
/* the battery is present. */
|
||||
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
||||
aprint_debug("%s: battery is present.\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
aprint_debug_dev(sc->sc_dev,
|
||||
"battery is present.\n");
|
||||
if (ACPI_FAILURE(acpibat_get_info(sc)))
|
||||
return;
|
||||
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
||||
@ -599,8 +601,8 @@ acpibat_update(void *arg)
|
||||
} else {
|
||||
/* the battery is not present. */
|
||||
if (ABAT_ISSET(sc, ABAT_F_VERBOSE))
|
||||
aprint_debug("%s: battery is not present.\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
aprint_debug_dev(sc->sc_dev,
|
||||
"battery is not present.\n");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -630,8 +632,7 @@ acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
||||
int rv;
|
||||
|
||||
#ifdef ACPI_BAT_DEBUG
|
||||
printf("%s: received notify message: 0x%x\n",
|
||||
sc->sc_dev.dv_xname, notify);
|
||||
aprint_debug_dev(sc->sc_dev, "received notify message: 0x%x\n", notify);
|
||||
#endif
|
||||
|
||||
switch (notify) {
|
||||
@ -646,8 +647,9 @@ acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
||||
rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
|
||||
acpibat_update, sc);
|
||||
if (ACPI_FAILURE(rv))
|
||||
printf("%s: unable to queue status check: %s\n",
|
||||
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to queue status check: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
break;
|
||||
|
||||
case ACPI_NOTIFY_BatteryStatusChanged:
|
||||
@ -657,13 +659,14 @@ acpibat_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
|
||||
rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
|
||||
acpibat_update, sc);
|
||||
if (ACPI_FAILURE(rv))
|
||||
printf("%s: unable to queue status check: %s\n",
|
||||
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to queue status check: %s\n",
|
||||
AcpiFormatException(rv));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("%s: received unknown notify message: 0x%x\n",
|
||||
sc->sc_dev.dv_xname, notify);
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"received unknown notify message: 0x%x\n", notify);
|
||||
}
|
||||
}
|
||||
|
||||
@ -685,7 +688,7 @@ acpibat_init_envsys(struct acpibat_softc *sc)
|
||||
sc->sc_data[index].units = unit; \
|
||||
sc->sc_data[index].state = ENVSYS_SVALID; \
|
||||
snprintf(sc->sc_data[index].desc, sizeof(sc->sc_data->desc), \
|
||||
"%s %s", sc->sc_dev.dv_xname, string); \
|
||||
"%s %s", device_xname(sc->sc_dev), string); \
|
||||
|
||||
INITDATA(ACPIBAT_PRESENT, ENVSYS_INDICATOR, "present");
|
||||
INITDATA(ACPIBAT_DCAPACITY, capunit, "design cap");
|
||||
@ -719,7 +722,7 @@ acpibat_init_envsys(struct acpibat_softc *sc)
|
||||
sc->sc_data[ACPIBAT_LCAPACITY].flags = ENVSYS_FMONNOTSUPP;
|
||||
|
||||
sc->sc_sysmon.sme_sensor_data = sc->sc_data;
|
||||
sc->sc_sysmon.sme_name = sc->sc_dev.dv_xname;
|
||||
sc->sc_sysmon.sme_name = device_xname(sc->sc_dev);
|
||||
sc->sc_sysmon.sme_cookie = sc;
|
||||
sc->sc_sysmon.sme_gtredata = acpibat_gtredata;
|
||||
sc->sc_sysmon.sme_nsensors = ACPIBAT_NSENSORS;
|
||||
@ -729,8 +732,7 @@ acpibat_init_envsys(struct acpibat_softc *sc)
|
||||
sc->sc_updateinterval.tv_usec = 0;
|
||||
|
||||
if (sysmon_envsys_register(&sc->sc_sysmon))
|
||||
aprint_error("%s: unable to register with sysmon\n",
|
||||
sc->sc_dev.dv_xname);
|
||||
aprint_error_dev(sc->sc_dev, "unable to register with sysmon\n");
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
Reference in New Issue
Block a user