Style cleanups to match the rest of this directory. For acpi_battery.c,

remove unused includes.
This commit is contained in:
njl 2003-08-11 15:34:43 +00:00
parent 316c9b0831
commit 3a0d835d8c
4 changed files with 783 additions and 861 deletions

View File

@ -43,129 +43,29 @@
#include <dev/acpica/acpivar.h>
#include <dev/acpica/acpiio.h>
/*
* Hooks for the ACPI CA debugging infrastructure
*/
/* Hooks for the ACPI CA debugging infrastructure */
#define _COMPONENT ACPI_AC_ADAPTER
ACPI_MODULE_NAME("AC_ADAPTER")
/* Number of times to retry initialization before giving up. */
#define ACPI_ACAD_RETRY_MAX 6
#define ACPI_DEVICE_CHECK_PNP 0x00
#define ACPI_DEVICE_CHECK_EXISTENCE 0x01
#define ACPI_POWERSOURCE_STAT_CHANGE 0x80
static void acpi_acad_get_status(void * );
static void acpi_acad_notify_handler(ACPI_HANDLE , UINT32 ,void *);
static int acpi_acad_probe(device_t);
static int acpi_acad_attach(device_t);
static int acpi_acad_ioctl(u_long, caddr_t, void *);
static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS);
static void acpi_acad_init_acline(void *arg);
struct acpi_acad_softc {
int status;
int initializing;
struct acpi_acad_softc {
int status;
int initializing;
};
static void
acpi_acad_get_status(void *context)
{
int newstatus;
device_t dev = context;
struct acpi_acad_softc *sc = device_get_softc(dev);
ACPI_HANDLE h = acpi_get_handle(dev);
if (ACPI_FAILURE(acpi_EvaluateInteger(h, "_PSR", &newstatus))) {
sc->status = -1;
return;
}
if (sc->status != newstatus) {
sc->status = newstatus;
/* set system power profile based on AC adapter status */
power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE : POWER_PROFILE_ECONOMY);
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"%s Line\n",(sc->status) ? "On" : "Off");
}
}
static void
acpi_acad_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
device_t dev = context;
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"Notify %d\n", notify);
switch (notify) {
case ACPI_DEVICE_CHECK_PNP:
case ACPI_DEVICE_CHECK_EXISTENCE:
case ACPI_POWERSOURCE_STAT_CHANGE:
/*Temporally. It is better to notify policy manager*/
AcpiOsQueueForExecution(OSD_PRIORITY_LO,
acpi_acad_get_status,context);
break;
default:
break;
}
}
static int
acpi_acad_probe(device_t dev)
{
if ((acpi_get_type(dev) == ACPI_TYPE_DEVICE) &&
acpi_MatchHid(dev, "ACPI0003")) {
/*
* Set device description
*/
device_set_desc(dev, "AC adapter");
return(0);
}
return(ENXIO);
}
static int
acpi_acad_attach(device_t dev)
{
int error;
struct acpi_acad_softc *sc;
struct acpi_softc *acpi_sc;
ACPI_HANDLE handle = acpi_get_handle(dev);
AcpiInstallNotifyHandler(handle,
ACPI_DEVICE_NOTIFY,
acpi_acad_notify_handler, dev);
/*Installing system notify is not so good*/
AcpiInstallNotifyHandler(handle,
ACPI_SYSTEM_NOTIFY,
acpi_acad_notify_handler, dev);
if ((sc = device_get_softc(dev)) == NULL) {
return (ENXIO);
}
if ((error = acpi_register_ioctl(ACPIIO_ACAD_GET_STATUS,
acpi_acad_ioctl, dev)) != 0) {
return (error);
}
if (device_get_unit(dev) == 0) {
acpi_sc = acpi_device_get_parent_softc(dev);
SYSCTL_ADD_PROC(&acpi_sc->acpi_sysctl_ctx,
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD,
&sc->status, 0, acpi_acad_sysctl, "I", "");
}
/* Get initial status after whole system is up. */
sc->status = -1;
sc->initializing = 0;
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_init_acline, dev);
return(0);
}
static void acpi_acad_get_status(void *);
static void acpi_acad_notify_handler(ACPI_HANDLE, UINT32, void *);
static int acpi_acad_probe(device_t);
static int acpi_acad_attach(device_t);
static int acpi_acad_ioctl(u_long, caddr_t, void *);
static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS);
static void acpi_acad_init_acline(void *arg);
static device_method_t acpi_acad_methods[] = {
/* Device interface */
@ -182,101 +82,191 @@ static driver_t acpi_acad_driver = {
};
static devclass_t acpi_acad_devclass;
DRIVER_MODULE(acpi_acad,acpi,acpi_acad_driver,acpi_acad_devclass,0,0);
DRIVER_MODULE(acpi_acad, acpi, acpi_acad_driver, acpi_acad_devclass, 0, 0);
static void
acpi_acad_get_status(void *context)
{
struct acpi_acad_softc *sc;
device_t dev;
ACPI_HANDLE h;
int newstatus;
dev = context;
sc = device_get_softc(dev);
h = acpi_get_handle(dev);
if (ACPI_FAILURE(acpi_EvaluateInteger(h, "_PSR", &newstatus))) {
sc->status = -1;
return;
}
if (sc->status != newstatus) {
sc->status = newstatus;
/* Set system power profile based on AC adapter status */
power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE :
POWER_PROFILE_ECONOMY);
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"%s Line\n", sc->status ? "On" : "Off");
}
}
static void
acpi_acad_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
device_t dev = context;
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"Notify %d\n", notify);
switch (notify) {
case ACPI_DEVICE_CHECK_PNP:
case ACPI_DEVICE_CHECK_EXISTENCE:
case ACPI_POWERSOURCE_STAT_CHANGE:
/* Temporarily. It is better to notify policy manager */
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_get_status, context);
break;
default:
break;
}
}
static int
acpi_acad_probe(device_t dev)
{
if (acpi_get_type(dev) == ACPI_TYPE_DEVICE &&
acpi_MatchHid(dev, "ACPI0003")) {
device_set_desc(dev, "AC adapter");
return (0);
}
return (ENXIO);
}
static int
acpi_acad_attach(device_t dev)
{
struct acpi_acad_softc *sc;
struct acpi_softc *acpi_sc;
ACPI_HANDLE handle;
int error;
handle = acpi_get_handle(dev);
AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
acpi_acad_notify_handler, dev);
/* XXX Installing system notify is not so good */
AcpiInstallNotifyHandler(handle, ACPI_SYSTEM_NOTIFY,
acpi_acad_notify_handler, dev);
if ((sc = device_get_softc(dev)) == NULL)
return (ENXIO);
error = acpi_register_ioctl(ACPIIO_ACAD_GET_STATUS, acpi_acad_ioctl, dev);
if (error != 0)
return (error);
if (device_get_unit(dev) == 0) {
acpi_sc = acpi_device_get_parent_softc(dev);
SYSCTL_ADD_PROC(&acpi_sc->acpi_sysctl_ctx,
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD,
&sc->status, 0, acpi_acad_sysctl, "I", "");
}
/* Get initial status after whole system is up. */
sc->status = -1;
sc->initializing = 0;
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_init_acline, dev);
return (0);
}
static int
acpi_acad_ioctl(u_long cmd, caddr_t addr, void *arg)
{
device_t dev;
struct acpi_acad_softc *sc;
struct acpi_acad_softc *sc;
device_t dev;
dev = (device_t)arg;
if ((sc = device_get_softc(dev)) == NULL) {
return(ENXIO);
}
dev = (device_t)arg;
if ((sc = device_get_softc(dev)) == NULL)
return(ENXIO);
/*
* No security check required: information retrieval only. If
* new functions are added here, a check might be required.
*/
/*
* No security check required: information retrieval only. If
* new functions are added here, a check might be required.
*/
switch (cmd) {
case ACPIIO_ACAD_GET_STATUS:
acpi_acad_get_status(dev);
*(int *)addr = sc->status;
break;
default:
break;
}
switch (cmd) {
case ACPIIO_ACAD_GET_STATUS:
acpi_acad_get_status(dev);
*(int *)addr = sc->status;
break;
}
return(0);
return (0);
}
static int
acpi_acad_sysctl(SYSCTL_HANDLER_ARGS)
{
int val;
int error;
int val, error;
if (acpi_acad_get_acline(&val)) {
return (ENXIO);
}
if (acpi_acad_get_acline(&val) != 0)
return (ENXIO);
val = *(u_int *)oidp->oid_arg1;
error = sysctl_handle_int(oidp, &val, 0, req);
return (error);
val = *(u_int *)oidp->oid_arg1;
error = sysctl_handle_int(oidp, &val, 0, req);
return (error);
}
static void
acpi_acad_init_acline(void *arg)
{
int retry;
int status;
device_t dev = (device_t)arg;
struct acpi_acad_softc *sc = device_get_softc(dev);
#define ACPI_ACAD_RETRY_MAX 6
struct acpi_acad_softc *sc;
device_t dev;
int retry, status;
if (sc->initializing) {
return;
}
dev = (device_t)arg;
sc = device_get_softc(dev);
if (sc->initializing)
return;
sc->initializing = 1;
sc->initializing = 1;
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"acline initialization start\n");
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"acline initialization start\n");
status = 0;
for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
acpi_acad_get_status(dev);
if (status != sc->status)
break;
}
status = 0;
for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) {
acpi_acad_get_status(dev);
if (status != sc->status)
break;
}
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"acline initialization done, tried %d times\n", retry+1);
sc->initializing = 0;
sc->initializing = 0;
ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
"acline initialization done, tried %d times\n", retry+1);
}
/*
* Public interfaces.
*/
int
acpi_acad_get_acline(int *status)
{
device_t dev;
struct acpi_acad_softc *sc;
struct acpi_acad_softc *sc;
device_t dev;
if ((dev = devclass_get_device(acpi_acad_devclass, 0)) == NULL) {
return (ENXIO);
}
dev = devclass_get_device(acpi_acad_devclass, 0);
if (dev == NULL)
return (ENXIO);
sc = device_get_softc(dev);
if (sc == NULL)
return (ENXIO);
if ((sc = device_get_softc(dev)) == NULL) {
return (ENXIO);
}
acpi_acad_get_status(dev);
*status = sc->status;
acpi_acad_get_status(dev);
*status = sc->status;
return (0);
return (0);
}

View File

@ -26,36 +26,23 @@
* $FreeBSD$
*/
#include "opt_acpi.h" /* XXX trim includes */
#include "opt_acpi.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/ioccom.h>
#include <sys/reboot.h>
#include <sys/sysctl.h>
#include <sys/ctype.h>
#include <machine/clock.h>
#include <machine/resource.h>
#include "acpi.h"
#include <dev/acpica/acpivar.h>
#include <dev/acpica/acpiio.h>
MALLOC_DEFINE(M_ACPIBATT, "acpibatt", "ACPI generic battery data");
/*
* ACPI Battery Abstruction Layer.
*/
struct acpi_batteries {
TAILQ_ENTRY(acpi_batteries) link;
struct acpi_battdesc battdesc;
TAILQ_ENTRY(acpi_batteries) link;
struct acpi_battdesc battdesc;
};
static TAILQ_HEAD(,acpi_batteries) acpi_batteries;
@ -67,200 +54,190 @@ static struct acpi_battinfo acpi_battery_battinfo;
int
acpi_battery_get_units(void)
{
return (acpi_batteries_units);
return (acpi_batteries_units);
}
int
acpi_battery_get_battdesc(int logical_unit, struct acpi_battdesc *battdesc)
{
int i;
struct acpi_batteries *bp;
if (logical_unit < 0 || logical_unit >= acpi_batteries_units) {
return (ENXIO);
}
i = 0;
TAILQ_FOREACH(bp, &acpi_batteries, link) {
if (logical_unit == i) {
battdesc->type = bp->battdesc.type;
battdesc->phys_unit = bp->battdesc.phys_unit;
return (0);
}
i++;
}
struct acpi_batteries *bp;
int i;
if (logical_unit < 0 || logical_unit >= acpi_batteries_units)
return (ENXIO);
i = 0;
TAILQ_FOREACH(bp, &acpi_batteries, link) {
if (logical_unit == i) {
battdesc->type = bp->battdesc.type;
battdesc->phys_unit = bp->battdesc.phys_unit;
return (0);
}
i++;
}
return (ENXIO);
}
int
acpi_battery_get_battinfo(int unit, struct acpi_battinfo *battinfo)
{
int error;
struct acpi_battdesc battdesc;
struct acpi_battdesc battdesc;
int error;
error = 0;
if (unit == -1) {
error = acpi_cmbat_get_battinfo(-1, battinfo);
goto out;
} else {
if ((error = acpi_battery_get_battdesc(unit, &battdesc)) != 0) {
goto out;
}
switch (battdesc.type) {
case ACPI_BATT_TYPE_CMBAT:
error = acpi_cmbat_get_battinfo(battdesc.phys_unit,
battinfo);
break;
default:
error = ENXIO;
break;
}
error = 0;
if (unit == -1) {
error = acpi_cmbat_get_battinfo(-1, battinfo);
goto out;
} else {
error = acpi_battery_get_battdesc(unit, &battdesc);
if (error != 0)
goto out;
switch (battdesc.type) {
case ACPI_BATT_TYPE_CMBAT:
error = acpi_cmbat_get_battinfo(battdesc.phys_unit, battinfo);
break;
default:
error = ENXIO;
break;
}
}
out:
return (error);
return (error);
}
int
acpi_battery_get_info_expire(void)
{
return (acpi_battery_info_expire);
return (acpi_battery_info_expire);
}
static int
acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg)
{
int error;
int logical_unit;
union acpi_battery_ioctl_arg *ioctl_arg;
union acpi_battery_ioctl_arg *ioctl_arg;
int error, logical_unit;
ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
error = 0;
ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
error = 0;
/*
* No security check required: information retrieval only. If
* new functions are added here, a check might be required.
*/
/*
* No security check required: information retrieval only. If
* new functions are added here, a check might be required.
*/
switch (cmd) {
case ACPIIO_BATT_GET_UNITS:
*(int *)addr = acpi_battery_get_units();
break;
case ACPIIO_BATT_GET_BATTDESC:
logical_unit = ioctl_arg->unit;
error = acpi_battery_get_battdesc(logical_unit, &ioctl_arg->battdesc);
break;
case ACPIIO_BATT_GET_BATTINFO:
logical_unit = ioctl_arg->unit;
error = acpi_battery_get_battinfo(logical_unit, &ioctl_arg->battinfo);
break;
default:
error = EINVAL;
break;
}
switch (cmd) {
case ACPIIO_BATT_GET_UNITS:
*(int *)addr = acpi_battery_get_units();
break;
case ACPIIO_BATT_GET_BATTDESC:
logical_unit = ioctl_arg->unit;
error = acpi_battery_get_battdesc(logical_unit, &ioctl_arg->battdesc);
break;
case ACPIIO_BATT_GET_BATTINFO:
logical_unit = ioctl_arg->unit;
error = acpi_battery_get_battinfo(logical_unit,
&ioctl_arg->battinfo);
break;
default:
error = EINVAL;
break;
}
return (error);
return (error);
}
static int
acpi_battery_sysctl(SYSCTL_HANDLER_ARGS)
{
int val;
int error;
int val, error;
acpi_battery_get_battinfo(-1, &acpi_battery_battinfo);
val = *(u_int *)oidp->oid_arg1;
error = sysctl_handle_int(oidp, &val, 0, req);
return (error);
acpi_battery_get_battinfo(-1, &acpi_battery_battinfo);
val = *(u_int *)oidp->oid_arg1;
error = sysctl_handle_int(oidp, &val, 0, req);
return (error);
}
static int
acpi_battery_init(void)
{
device_t dev;
struct acpi_softc *sc;
int error;
struct acpi_softc *sc;
device_t dev;
int error;
if ((dev = devclass_get_device(devclass_find("acpi"), 0)) == NULL) {
return (ENXIO);
}
if ((sc = device_get_softc(dev)) == NULL) {
return (ENXIO);
}
dev = devclass_get_device(devclass_find("acpi"), 0);
if (dev == NULL)
return (ENXIO);
sc = device_get_softc(dev);
if (sc == NULL)
return (ENXIO);
error = 0;
TAILQ_INIT(&acpi_batteries);
acpi_batteries_initted = 1;
if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS,
acpi_battery_ioctl, NULL)) != 0) {
return (error);
}
if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTDESC,
acpi_battery_ioctl, NULL)) != 0) {
return (error);
}
if ((error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO,
acpi_battery_ioctl, NULL)) != 0) {
return (error);
}
sysctl_ctx_init(&sc->acpi_battery_sysctl_ctx);
sc->acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
OID_AUTO, "battery", CTLFLAG_RD, 0, "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "units", CTLFLAG_RD, &acpi_batteries_units, 0, "");
SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
&acpi_battery_info_expire, 0, "");
error = 0;
TAILQ_INIT(&acpi_batteries);
acpi_batteries_initted = 1;
error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS, acpi_battery_ioctl,
NULL);
if (error != 0)
return (error);
error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTDESC, acpi_battery_ioctl,
NULL);
if (error != 0)
return (error);
error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO, acpi_battery_ioctl,
NULL);
if (error != 0)
return (error);
sysctl_ctx_init(&sc->acpi_battery_sysctl_ctx);
sc->acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
OID_AUTO, "battery", CTLFLAG_RD, 0, "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
&acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "units", CTLFLAG_RD, &acpi_batteries_units, 0, "");
SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
&acpi_battery_info_expire, 0, "");
return (error);
}
int
acpi_battery_register(int type, int phys_unit)
{
int error;
struct acpi_batteries *bp;
struct acpi_batteries *bp;
int error;
error = 0;
if ((bp = malloc(sizeof(*bp), M_ACPIBATT, M_NOWAIT)) == NULL) {
return(ENOMEM);
error = 0;
bp = malloc(sizeof(*bp), M_ACPIBATT, M_NOWAIT);
if (bp == NULL)
return (ENOMEM);
bp->battdesc.type = type;
bp->battdesc.phys_unit = phys_unit;
if (acpi_batteries_initted == 0) {
if ((error = acpi_battery_init()) != 0) {
free(bp, M_ACPIBATT);
return (error);
}
}
bp->battdesc.type = type;
bp->battdesc.phys_unit = phys_unit;
if (acpi_batteries_initted == 0) {
if ((error = acpi_battery_init()) != 0) {
free(bp, M_ACPIBATT);
return(error);
}
}
TAILQ_INSERT_TAIL(&acpi_batteries, bp, link);
acpi_batteries_units++;
TAILQ_INSERT_TAIL(&acpi_batteries, bp, link);
acpi_batteries_units++;
return(0);
return (0);
}

View File

@ -34,28 +34,29 @@
#include <sys/bus.h>
#include "acpi.h"
#include <dev/acpica/acpivar.h>
/*
* Hooks for the ACPI CA debugging infrastructure
*/
/* Hooks for the ACPI CA debugging infrastructure */
#define _COMPONENT ACPI_BUTTON
ACPI_MODULE_NAME("BUTTON")
struct acpi_button_softc {
device_t button_dev;
ACPI_HANDLE button_handle;
#define ACPI_POWER_BUTTON 0
#define ACPI_SLEEP_BUTTON 1
boolean_t button_type; /* Power or Sleep Button */
#define ACPI_POWER_BUTTON 0
#define ACPI_SLEEP_BUTTON 1
};
#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP 0x80
#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP 0x02
static int acpi_button_probe(device_t dev);
static int acpi_button_attach(device_t dev);
static int acpi_button_suspend(device_t dev);
static int acpi_button_resume(device_t dev);
static void acpi_button_notify_handler(ACPI_HANDLE h,UINT32 notify, void *context);
static void acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify,
void *context);
static void acpi_button_notify_pressed_for_sleep(void *arg);
static void acpi_button_notify_pressed_for_wakeup(void *arg);
@ -77,7 +78,8 @@ static driver_t acpi_button_driver = {
};
static devclass_t acpi_button_devclass;
DRIVER_MODULE(acpi_button, acpi, acpi_button_driver, acpi_button_devclass, 0, 0);
DRIVER_MODULE(acpi_button, acpi, acpi_button_driver, acpi_button_devclass,
0, 0);
static int
acpi_button_probe(device_t dev)
@ -90,16 +92,16 @@ acpi_button_probe(device_t dev)
if (acpi_MatchHid(dev, "PNP0C0C")) {
device_set_desc(dev, "Power Button");
sc->button_type = ACPI_POWER_BUTTON;
return(0);
return (0);
}
if (acpi_MatchHid(dev, "PNP0C0E")) {
device_set_desc(dev, "Sleep Button");
sc->button_type = ACPI_SLEEP_BUTTON;
return(0);
return (0);
}
}
}
return(ENXIO);
return (ENXIO);
}
static int
@ -114,13 +116,15 @@ acpi_button_attach(device_t dev)
sc->button_dev = dev;
sc->button_handle = acpi_get_handle(dev);
if (ACPI_FAILURE(status = AcpiInstallNotifyHandler(sc->button_handle, ACPI_DEVICE_NOTIFY,
acpi_button_notify_handler, sc))) {
device_printf(sc->button_dev, "couldn't install Notify handler - %s\n", AcpiFormatException(status));
return_VALUE(ENXIO);
status = AcpiInstallNotifyHandler(sc->button_handle, ACPI_DEVICE_NOTIFY,
acpi_button_notify_handler, sc);
if (ACPI_FAILURE(status)) {
device_printf(sc->button_dev, "couldn't install Notify handler - %s\n",
AcpiFormatException(status));
return_VALUE (ENXIO);
}
acpi_device_enable_wake_capability(sc->button_handle, 1);
return_VALUE(0);
return_VALUE (0);
}
static int
@ -136,7 +140,6 @@ acpi_button_suspend(device_t dev)
static int
acpi_button_resume(device_t dev)
{
return (0);
}
@ -150,9 +153,8 @@ acpi_button_notify_pressed_for_sleep(void *arg)
sc = (struct acpi_button_softc *)arg;
acpi_sc = acpi_device_get_parent_softc(sc->button_dev);
if (acpi_sc == NULL) {
if (acpi_sc == NULL)
return_VOID;
}
switch (sc->button_type) {
case ACPI_POWER_BUTTON:
@ -166,7 +168,6 @@ acpi_button_notify_pressed_for_sleep(void *arg)
default:
break; /* unknown button type */
}
return_VOID;
}
static void
@ -179,9 +180,8 @@ acpi_button_notify_pressed_for_wakeup(void *arg)
sc = (struct acpi_button_softc *)arg;
acpi_sc = acpi_device_get_parent_softc(sc->button_dev);
if (acpi_sc == NULL) {
if (acpi_sc == NULL)
return_VOID;
}
switch (sc->button_type) {
case ACPI_POWER_BUTTON:
@ -195,13 +195,8 @@ acpi_button_notify_pressed_for_wakeup(void *arg)
default:
break; /* unknown button type */
}
return_VOID;
}
/* XXX maybe not here */
#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP 0x80
#define ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP 0x02
static void
acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
{
@ -211,15 +206,14 @@ acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context)
switch (notify) {
case ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP:
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_pressed_for_sleep, sc);
AcpiOsQueueForExecution(OSD_PRIORITY_LO,
acpi_button_notify_pressed_for_sleep, sc);
break;
case ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP:
AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_pressed_for_wakeup, sc);
AcpiOsQueueForExecution(OSD_PRIORITY_LO,
acpi_button_notify_pressed_for_wakeup, sc);
break;
default:
break; /* unknown notification value */
}
return_VOID;
}

File diff suppressed because it is too large Load Diff