2000-12-22 14:41:55 +00:00
|
|
|
/*-
|
2005-07-23 19:36:00 +00:00
|
|
|
* Copyright (c) 2005 Nate Lawson
|
2001-06-23 10:38:25 +00:00
|
|
|
* Copyright (c) 2000 Munehiro Matsuda
|
2000-12-22 14:41:55 +00:00
|
|
|
* Copyright (c) 2000 Takanori Watanabe
|
|
|
|
* Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
|
|
|
|
* 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 AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-12-22 14:41:55 +00:00
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2000-12-22 14:41:55 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
|
2000-12-22 14:41:55 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/acpica/acpiio.h>
|
|
|
|
|
2001-10-30 14:24:26 +00:00
|
|
|
MALLOC_DEFINE(M_ACPICMBAT, "acpicmbat", "ACPI control method battery data");
|
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
/* Number of times to retry initialization before giving up. */
|
|
|
|
#define ACPI_CMBAT_RETRY_MAX 6
|
|
|
|
|
|
|
|
/* Check the battery once a minute. */
|
2004-08-13 06:21:44 +00:00
|
|
|
#define CMBAT_POLLRATE (60 * hz)
|
2001-10-22 18:01:37 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2001-10-30 15:51:52 +00:00
|
|
|
#define _COMPONENT ACPI_BATTERY
|
2002-02-23 05:24:14 +00:00
|
|
|
ACPI_MODULE_NAME("BATTERY")
|
2001-05-29 20:13:42 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
#define ACPI_BATTERY_BST_CHANGE 0x80
|
|
|
|
#define ACPI_BATTERY_BIF_CHANGE 0x81
|
2000-12-24 19:12:10 +00:00
|
|
|
|
2001-10-30 15:51:52 +00:00
|
|
|
struct acpi_cmbat_softc {
|
2003-08-11 15:34:43 +00:00
|
|
|
device_t dev;
|
2005-07-23 19:36:00 +00:00
|
|
|
int flags;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
|
|
|
struct acpi_bif bif;
|
|
|
|
struct acpi_bst bst;
|
|
|
|
struct timespec bst_lastupdated;
|
2001-10-30 15:51:52 +00:00
|
|
|
};
|
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_DECL(cmbat, "ACPI cmbat");
|
2003-08-11 15:34:43 +00:00
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
static int acpi_cmbat_probe(device_t dev);
|
|
|
|
static int acpi_cmbat_attach(device_t dev);
|
|
|
|
static int acpi_cmbat_detach(device_t dev);
|
|
|
|
static int acpi_cmbat_resume(device_t dev);
|
|
|
|
static void acpi_cmbat_notify_handler(ACPI_HANDLE h, UINT32 notify,
|
|
|
|
void *context);
|
|
|
|
static int acpi_cmbat_info_expired(struct timespec *lastupdated);
|
|
|
|
static void acpi_cmbat_info_updated(struct timespec *lastupdated);
|
2005-11-23 00:57:51 +00:00
|
|
|
static void acpi_cmbat_get_bst(void *arg);
|
2005-11-26 07:36:53 +00:00
|
|
|
static void acpi_cmbat_get_bif_task(void *arg);
|
2005-11-23 00:57:51 +00:00
|
|
|
static void acpi_cmbat_get_bif(void *arg);
|
2005-07-23 19:36:00 +00:00
|
|
|
static int acpi_cmbat_bst(device_t dev, struct acpi_bst *bstp);
|
|
|
|
static int acpi_cmbat_bif(device_t dev, struct acpi_bif *bifp);
|
|
|
|
static void acpi_cmbat_init_battery(void *arg);
|
2001-10-30 15:51:52 +00:00
|
|
|
|
2003-08-15 02:18:15 +00:00
|
|
|
static device_method_t acpi_cmbat_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, acpi_cmbat_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_cmbat_attach),
|
2004-07-12 20:53:04 +00:00
|
|
|
DEVMETHOD(device_detach, acpi_cmbat_detach),
|
2003-08-15 02:18:15 +00:00
|
|
|
DEVMETHOD(device_resume, acpi_cmbat_resume),
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
/* ACPI battery interface */
|
|
|
|
DEVMETHOD(acpi_batt_get_info, acpi_cmbat_bif),
|
|
|
|
DEVMETHOD(acpi_batt_get_status, acpi_cmbat_bst),
|
|
|
|
|
2003-08-15 02:18:15 +00:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_cmbat_driver = {
|
2005-07-23 19:36:00 +00:00
|
|
|
"battery",
|
2003-08-15 02:18:15 +00:00
|
|
|
acpi_cmbat_methods,
|
|
|
|
sizeof(struct acpi_cmbat_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t acpi_cmbat_devclass;
|
|
|
|
DRIVER_MODULE(acpi_cmbat, acpi, acpi_cmbat_driver, acpi_cmbat_devclass, 0, 0);
|
2004-04-09 18:14:32 +00:00
|
|
|
MODULE_DEPEND(acpi_cmbat, acpi, 1, 1, 1);
|
2003-08-15 02:18:15 +00:00
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
static int
|
|
|
|
acpi_cmbat_probe(device_t dev)
|
|
|
|
{
|
|
|
|
static char *cmbat_ids[] = { "PNP0C0A", NULL };
|
|
|
|
|
|
|
|
if (acpi_disabled("cmbat") ||
|
|
|
|
ACPI_ID_PROBE(device_get_parent(dev), dev, cmbat_ids) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
device_set_desc(dev, "ACPI Control Method Battery");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cmbat_attach(device_t dev)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
struct acpi_cmbat_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
handle = acpi_get_handle(dev);
|
|
|
|
sc->dev = dev;
|
|
|
|
|
|
|
|
timespecclear(&sc->bst_lastupdated);
|
|
|
|
|
|
|
|
error = acpi_battery_register(dev);
|
|
|
|
if (error != 0) {
|
|
|
|
device_printf(dev, "registering battery failed\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install a system notify handler in addition to the device notify.
|
|
|
|
* Toshiba notebook uses this alternate notify for its battery.
|
|
|
|
*/
|
|
|
|
AcpiInstallNotifyHandler(handle, ACPI_ALL_NOTIFY,
|
|
|
|
acpi_cmbat_notify_handler, dev);
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_cmbat_init_battery, dev);
|
2005-07-23 19:36:00 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cmbat_detach(device_t dev)
|
|
|
|
{
|
2006-04-15 16:10:53 +00:00
|
|
|
ACPI_HANDLE handle;
|
2005-07-23 19:36:00 +00:00
|
|
|
|
2006-04-15 16:10:53 +00:00
|
|
|
handle = acpi_get_handle(dev);
|
2006-04-15 12:31:34 +00:00
|
|
|
AcpiRemoveNotifyHandler(handle, ACPI_ALL_NOTIFY, acpi_cmbat_notify_handler);
|
2006-04-15 16:10:53 +00:00
|
|
|
acpi_battery_remove(dev);
|
2005-07-23 19:36:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_cmbat_resume(device_t dev)
|
|
|
|
{
|
|
|
|
|
2007-03-22 18:16:43 +00:00
|
|
|
AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_cmbat_init_battery, dev);
|
2005-07-23 19:36:00 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_cmbat_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_cmbat_softc *sc;
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
dev = (device_t)context;
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
switch (notify) {
|
|
|
|
case ACPI_NOTIFY_DEVICE_CHECK:
|
|
|
|
case ACPI_BATTERY_BST_CHANGE:
|
2005-11-23 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Clear the last updated time. The next call to retrieve the
|
|
|
|
* battery status will get the new value for us.
|
|
|
|
*/
|
2005-07-23 19:36:00 +00:00
|
|
|
timespecclear(&sc->bst_lastupdated);
|
|
|
|
break;
|
|
|
|
case ACPI_NOTIFY_BUS_CHECK:
|
|
|
|
case ACPI_BATTERY_BIF_CHANGE:
|
2005-11-23 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Queue a callback to get the current battery info from thread
|
|
|
|
* context. It's not safe to block in a notify handler.
|
|
|
|
*/
|
2007-03-22 18:16:43 +00:00
|
|
|
AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_cmbat_get_bif_task, dev);
|
2005-07-23 19:36:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
acpi_UserNotify("CMBAT", h, notify);
|
|
|
|
}
|
|
|
|
|
2003-08-15 02:18:15 +00:00
|
|
|
static int
|
2001-06-23 10:38:25 +00:00
|
|
|
acpi_cmbat_info_expired(struct timespec *lastupdated)
|
|
|
|
{
|
2003-08-11 15:34:43 +00:00
|
|
|
struct timespec curtime;
|
2001-06-23 10:38:25 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_ASSERT(cmbat);
|
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
if (lastupdated == NULL)
|
2004-08-13 06:21:44 +00:00
|
|
|
return (TRUE);
|
2003-08-11 15:34:43 +00:00
|
|
|
if (!timespecisset(lastupdated))
|
2004-08-13 06:21:44 +00:00
|
|
|
return (TRUE);
|
2001-06-24 02:39:08 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
getnanotime(&curtime);
|
|
|
|
timespecsub(&curtime, lastupdated);
|
|
|
|
return (curtime.tv_sec < 0 ||
|
|
|
|
curtime.tv_sec > acpi_battery_get_info_expire());
|
2001-06-23 10:38:25 +00:00
|
|
|
}
|
|
|
|
|
2003-08-15 02:18:15 +00:00
|
|
|
static void
|
2001-06-23 10:38:25 +00:00
|
|
|
acpi_cmbat_info_updated(struct timespec *lastupdated)
|
|
|
|
{
|
2004-08-13 06:21:44 +00:00
|
|
|
|
|
|
|
ACPI_SERIAL_ASSERT(cmbat);
|
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
if (lastupdated != NULL)
|
|
|
|
getnanotime(lastupdated);
|
2001-06-23 10:38:25 +00:00
|
|
|
}
|
|
|
|
|
2000-12-22 14:41:55 +00:00
|
|
|
static void
|
2005-11-23 00:57:51 +00:00
|
|
|
acpi_cmbat_get_bst(void *arg)
|
2000-12-22 14:41:55 +00:00
|
|
|
{
|
2003-08-11 15:34:43 +00:00
|
|
|
struct acpi_cmbat_softc *sc;
|
|
|
|
ACPI_STATUS as;
|
2003-12-23 18:27:35 +00:00
|
|
|
ACPI_OBJECT *res;
|
2003-08-11 15:34:43 +00:00
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_BUFFER bst_buffer;
|
2005-11-23 00:57:51 +00:00
|
|
|
device_t dev;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_ASSERT(cmbat);
|
|
|
|
|
2005-11-23 00:57:51 +00:00
|
|
|
dev = arg;
|
2003-08-11 15:34:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
h = acpi_get_handle(dev);
|
2004-08-13 06:21:44 +00:00
|
|
|
bst_buffer.Pointer = NULL;
|
|
|
|
bst_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
|
|
|
if (!acpi_cmbat_info_expired(&sc->bst_lastupdated))
|
2004-08-13 06:21:44 +00:00
|
|
|
goto end;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
|
|
|
as = AcpiEvaluateObject(h, "_BST", NULL, &bst_buffer);
|
|
|
|
if (ACPI_FAILURE(as)) {
|
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
2001-12-22 16:05:41 +00:00
|
|
|
"error fetching current battery status -- %s\n",
|
|
|
|
AcpiFormatException(as));
|
2003-08-11 15:34:43 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
res = (ACPI_OBJECT *)bst_buffer.Pointer;
|
2003-12-23 18:27:35 +00:00
|
|
|
if (!ACPI_PKG_VALID(res, 4)) {
|
2003-08-11 15:34:43 +00:00
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
2001-11-18 18:12:07 +00:00
|
|
|
"battery status corrupted\n");
|
2003-08-11 15:34:43 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2003-12-23 18:27:35 +00:00
|
|
|
if (acpi_PkgInt32(res, 0, &sc->bst.state) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgInt32(res, 1, &sc->bst.rate) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgInt32(res, 2, &sc->bst.cap) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgInt32(res, 3, &sc->bst.volt) != 0)
|
|
|
|
goto end;
|
2003-08-11 15:34:43 +00:00
|
|
|
acpi_cmbat_info_updated(&sc->bst_lastupdated);
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2010-12-17 16:21:30 +00:00
|
|
|
/* Clear out undefined/extended bits that might be set by hardware. */
|
|
|
|
sc->bst.state &= ACPI_BATT_STAT_BST_MASK;
|
|
|
|
if ((sc->bst.state & ACPI_BATT_STAT_INVALID) == ACPI_BATT_STAT_INVALID)
|
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
|
|
|
"battery reports simultaneous charging and discharging\n");
|
|
|
|
|
2004-12-20 05:03:41 +00:00
|
|
|
/* XXX If all batteries are critical, perhaps we should suspend. */
|
|
|
|
if (sc->bst.state & ACPI_BATT_STAT_CRITICAL) {
|
|
|
|
if ((sc->flags & ACPI_BATT_STAT_CRITICAL) == 0) {
|
|
|
|
sc->flags |= ACPI_BATT_STAT_CRITICAL;
|
|
|
|
device_printf(dev, "critically low charge!\n");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sc->flags &= ~ACPI_BATT_STAT_CRITICAL;
|
2004-10-11 06:18:07 +00:00
|
|
|
|
2000-12-22 14:41:55 +00:00
|
|
|
end:
|
2003-08-11 15:34:43 +00:00
|
|
|
if (bst_buffer.Pointer != NULL)
|
|
|
|
AcpiOsFree(bst_buffer.Pointer);
|
2000-12-22 14:41:55 +00:00
|
|
|
}
|
|
|
|
|
2005-11-26 07:36:53 +00:00
|
|
|
/* XXX There should be a cleaner way to do this locking. */
|
|
|
|
static void
|
|
|
|
acpi_cmbat_get_bif_task(void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
ACPI_SERIAL_BEGIN(cmbat);
|
|
|
|
acpi_cmbat_get_bif(arg);
|
|
|
|
ACPI_SERIAL_END(cmbat);
|
|
|
|
}
|
|
|
|
|
2000-12-22 14:41:55 +00:00
|
|
|
static void
|
2005-11-23 00:57:51 +00:00
|
|
|
acpi_cmbat_get_bif(void *arg)
|
2000-12-22 14:41:55 +00:00
|
|
|
{
|
2003-08-11 15:34:43 +00:00
|
|
|
struct acpi_cmbat_softc *sc;
|
|
|
|
ACPI_STATUS as;
|
2003-12-23 18:27:35 +00:00
|
|
|
ACPI_OBJECT *res;
|
2003-08-11 15:34:43 +00:00
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_BUFFER bif_buffer;
|
2005-11-23 00:57:51 +00:00
|
|
|
device_t dev;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_ASSERT(cmbat);
|
|
|
|
|
2005-11-23 00:57:51 +00:00
|
|
|
dev = arg;
|
2003-08-11 15:34:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
h = acpi_get_handle(dev);
|
2004-08-13 06:21:44 +00:00
|
|
|
bif_buffer.Pointer = NULL;
|
|
|
|
bif_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
2003-08-11 15:34:43 +00:00
|
|
|
|
|
|
|
as = AcpiEvaluateObject(h, "_BIF", NULL, &bif_buffer);
|
|
|
|
if (ACPI_FAILURE(as)) {
|
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
2001-12-22 16:05:41 +00:00
|
|
|
"error fetching current battery info -- %s\n",
|
|
|
|
AcpiFormatException(as));
|
2003-08-11 15:34:43 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2000-12-22 14:41:55 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
res = (ACPI_OBJECT *)bif_buffer.Pointer;
|
2003-12-23 18:27:35 +00:00
|
|
|
if (!ACPI_PKG_VALID(res, 13)) {
|
2003-08-11 15:34:43 +00:00
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
2001-11-18 18:12:07 +00:00
|
|
|
"battery info corrupted\n");
|
2003-08-11 15:34:43 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 0, &sc->bif.units) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 1, &sc->bif.dcap) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 2, &sc->bif.lfcap) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 3, &sc->bif.btech) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 4, &sc->bif.dvol) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 5, &sc->bif.wcap) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 6, &sc->bif.lcap) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 7, &sc->bif.gra1) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
2004-08-13 06:21:44 +00:00
|
|
|
if (acpi_PkgInt32(res, 8, &sc->bif.gra2) != 0)
|
2003-12-23 18:27:35 +00:00
|
|
|
goto end;
|
|
|
|
if (acpi_PkgStr(res, 9, sc->bif.model, ACPI_CMBAT_MAXSTRLEN) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgStr(res, 10, sc->bif.serial, ACPI_CMBAT_MAXSTRLEN) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgStr(res, 11, sc->bif.type, ACPI_CMBAT_MAXSTRLEN) != 0)
|
|
|
|
goto end;
|
|
|
|
if (acpi_PkgStr(res, 12, sc->bif.oeminfo, ACPI_CMBAT_MAXSTRLEN) != 0)
|
|
|
|
goto end;
|
2000-12-22 14:41:55 +00:00
|
|
|
|
|
|
|
end:
|
2003-08-11 15:34:43 +00:00
|
|
|
if (bif_buffer.Pointer != NULL)
|
|
|
|
AcpiOsFree(bif_buffer.Pointer);
|
2000-12-22 14:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-07-23 19:36:00 +00:00
|
|
|
acpi_cmbat_bif(device_t dev, struct acpi_bif *bifp)
|
2000-12-22 14:41:55 +00:00
|
|
|
{
|
2003-08-11 15:34:43 +00:00
|
|
|
struct acpi_cmbat_softc *sc;
|
2001-10-30 15:51:52 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
sc = device_get_softc(dev);
|
2001-06-23 10:38:25 +00:00
|
|
|
|
2005-11-23 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Just copy the data. The only value that should change is the
|
|
|
|
* last-full capacity, so we only update when we get a notify that says
|
|
|
|
* the info has changed. Many systems apparently take a long time to
|
|
|
|
* process a _BIF call so we avoid it if possible.
|
|
|
|
*/
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cmbat);
|
2005-07-23 19:36:00 +00:00
|
|
|
bifp->units = sc->bif.units;
|
|
|
|
bifp->dcap = sc->bif.dcap;
|
|
|
|
bifp->lfcap = sc->bif.lfcap;
|
|
|
|
bifp->btech = sc->bif.btech;
|
|
|
|
bifp->dvol = sc->bif.dvol;
|
|
|
|
bifp->wcap = sc->bif.wcap;
|
|
|
|
bifp->lcap = sc->bif.lcap;
|
|
|
|
bifp->gra1 = sc->bif.gra1;
|
|
|
|
bifp->gra2 = sc->bif.gra2;
|
|
|
|
strncpy(bifp->model, sc->bif.model, sizeof(sc->bif.model));
|
|
|
|
strncpy(bifp->serial, sc->bif.serial, sizeof(sc->bif.serial));
|
|
|
|
strncpy(bifp->type, sc->bif.type, sizeof(sc->bif.type));
|
|
|
|
strncpy(bifp->oeminfo, sc->bif.oeminfo, sizeof(sc->bif.oeminfo));
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_END(cmbat);
|
2004-07-12 20:53:04 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
return (0);
|
2001-10-22 18:01:37 +00:00
|
|
|
}
|
2001-10-30 15:51:52 +00:00
|
|
|
|
2000-12-24 19:12:10 +00:00
|
|
|
static int
|
2005-07-23 19:36:00 +00:00
|
|
|
acpi_cmbat_bst(device_t dev, struct acpi_bst *bstp)
|
2000-12-24 19:12:10 +00:00
|
|
|
{
|
2003-08-11 15:34:43 +00:00
|
|
|
struct acpi_cmbat_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2000-12-24 19:12:10 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cmbat);
|
2005-07-23 19:36:00 +00:00
|
|
|
if (acpi_BatteryIsPresent(dev)) {
|
|
|
|
acpi_cmbat_get_bst(dev);
|
|
|
|
bstp->state = sc->bst.state;
|
|
|
|
bstp->rate = sc->bst.rate;
|
|
|
|
bstp->cap = sc->bst.cap;
|
|
|
|
bstp->volt = sc->bst.volt;
|
|
|
|
} else
|
|
|
|
bstp->state = ACPI_BATT_STAT_NOT_PRESENT;
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_END(cmbat);
|
2000-12-24 19:12:10 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
return (0);
|
2000-12-24 19:12:10 +00:00
|
|
|
}
|
2001-06-23 10:38:25 +00:00
|
|
|
|
2002-11-03 10:49:24 +00:00
|
|
|
static void
|
|
|
|
acpi_cmbat_init_battery(void *arg)
|
|
|
|
{
|
2004-08-13 06:21:44 +00:00
|
|
|
struct acpi_cmbat_softc *sc;
|
2005-07-23 19:36:00 +00:00
|
|
|
int retry, valid;
|
2004-08-13 06:21:44 +00:00
|
|
|
device_t dev;
|
2002-11-03 10:49:24 +00:00
|
|
|
|
2004-08-13 06:21:44 +00:00
|
|
|
dev = (device_t)arg;
|
|
|
|
sc = device_get_softc(dev);
|
2003-08-11 15:34:43 +00:00
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
|
|
|
"battery initialization start\n");
|
2002-11-03 10:49:24 +00:00
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
/*
|
|
|
|
* Try repeatedly to get valid data from the battery. Since the
|
|
|
|
* embedded controller isn't always ready just after boot, we may have
|
|
|
|
* to wait a while.
|
|
|
|
*/
|
2004-12-02 00:25:35 +00:00
|
|
|
for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10000)) {
|
2006-04-15 12:31:34 +00:00
|
|
|
/* batteries on DOCK can be ejected w/ DOCK during retrying */
|
|
|
|
if (!device_is_attached(dev))
|
|
|
|
return;
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
if (!acpi_BatteryIsPresent(dev))
|
2003-08-11 15:34:43 +00:00
|
|
|
continue;
|
2002-11-03 10:49:24 +00:00
|
|
|
|
2005-11-23 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Only query the battery if this is the first try or the specific
|
|
|
|
* type of info is still invalid.
|
|
|
|
*/
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_BEGIN(cmbat);
|
2005-11-23 00:57:51 +00:00
|
|
|
if (retry == 0 || !acpi_battery_bst_valid(&sc->bst)) {
|
|
|
|
timespecclear(&sc->bst_lastupdated);
|
|
|
|
acpi_cmbat_get_bst(dev);
|
|
|
|
}
|
|
|
|
if (retry == 0 || !acpi_battery_bif_valid(&sc->bif))
|
|
|
|
acpi_cmbat_get_bif(dev);
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
valid = acpi_battery_bst_valid(&sc->bst) &&
|
|
|
|
acpi_battery_bif_valid(&sc->bif);
|
2004-08-13 06:21:44 +00:00
|
|
|
ACPI_SERIAL_END(cmbat);
|
|
|
|
|
2005-07-23 19:36:00 +00:00
|
|
|
if (valid)
|
2004-08-13 06:21:44 +00:00
|
|
|
break;
|
2003-08-11 15:34:43 +00:00
|
|
|
}
|
2002-11-03 10:49:24 +00:00
|
|
|
|
2003-08-11 15:34:43 +00:00
|
|
|
if (retry == ACPI_CMBAT_RETRY_MAX) {
|
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
|
|
|
"battery initialization failed, giving up\n");
|
|
|
|
} else {
|
|
|
|
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
|
|
|
|
"battery initialization done, tried %d times\n", retry + 1);
|
|
|
|
}
|
2002-11-03 10:49:24 +00:00
|
|
|
}
|