#include "opt_acpi.h"
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include "acpi.h"
#include "acpi_if.h"
#include <sys/module.h>
#include <dev/acpica/acpivar.h>
#include <sys/sysctl.h>
#define _COMPONENT ACPI_OEM
ACPI_MODULE_NAME("Sony")
#define ACPI_SONY_GET_PID "GPID"
struct acpi_sony_softc {
int pid;
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
};
static struct acpi_sony_name_list
{
char *nodename;
char *getmethod;
char *setmethod;
char *comment;
} acpi_sony_oids[] = {
{ "brightness", "GBRT", "SBRT", "Display Brightness"},
{ "brightness_default", "GPBR", "SPBR", "Default Display Brightness"},
{ "contrast", "GCTR", "SCTR", "Display Contrast"},
{ "bass_gain", "GMGB", "SMGB", "Multimedia Bass Gain"},
{ "pcr", "GPCR", "SPCR", "???"},
#if 0
{ "cmi", "GCMI", "SCMI", "???"},
#endif
{ "wdp", "GWDP", NULL, "???"},
{ "cdp", "GCDP", "CDPW", "CD Power"},
{ "azp", "GAZP", "AZPW", "Audio Power"},
{ "lnp", "GLNP", "LNPW", "LAN Power"},
{ NULL, NULL, NULL }
};
static int acpi_sony_probe(device_t dev);
static int acpi_sony_attach(device_t dev);
static int acpi_sony_detach(device_t dev);
static int sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS);
static device_method_t acpi_sony_methods[] = {
DEVMETHOD(device_probe, acpi_sony_probe),
DEVMETHOD(device_attach, acpi_sony_attach),
DEVMETHOD(device_detach, acpi_sony_detach),
DEVMETHOD_END
};
static driver_t acpi_sony_driver = {
"acpi_sony",
acpi_sony_methods,
sizeof(struct acpi_sony_softc),
};
static devclass_t acpi_sony_devclass;
DRIVER_MODULE(acpi_sony, acpi, acpi_sony_driver, acpi_sony_devclass,
NULL, NULL);
MODULE_DEPEND(acpi_sony, acpi, 1, 1, 1);
static char *sny_id[] = {"SNY5001", NULL};
static int
acpi_sony_probe(device_t dev)
{
int ret = ENXIO;
if (ACPI_ID_PROBE(device_get_parent(dev), dev, sny_id)) {
device_set_desc(dev, "Sony notebook controller");
ret = 0;
}
return (ret);
}
static int
acpi_sony_attach(device_t dev)
{
struct acpi_sony_softc *sc;
struct acpi_softc *acpi_sc;
int i;
sc = device_get_softc(dev);
acpi_sc = acpi_device_get_parent_softc(dev);
acpi_GetInteger(acpi_get_handle(dev), ACPI_SONY_GET_PID, &sc->pid);
device_printf(dev, "PID %x\n", sc->pid);
sysctl_ctx_init(&sc->sysctl_ctx);
sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
"sony", CTLFLAG_RD, 0, "");
for (i = 0 ; acpi_sony_oids[i].nodename != NULL; i++){
SYSCTL_ADD_PROC(&sc->sysctl_ctx,
SYSCTL_CHILDREN(sc->sysctl_tree),
i, acpi_sony_oids[i].nodename , CTLTYPE_INT |
((acpi_sony_oids[i].setmethod)? CTLFLAG_RW: CTLFLAG_RD),
dev, i, sysctl_acpi_sony_gen_handler, "I",
acpi_sony_oids[i].comment);
}
return (0);
}
static int
acpi_sony_detach(device_t dev)
{
struct acpi_sony_softc *sc;
sc = device_get_softc(dev);
sysctl_ctx_free(&sc->sysctl_ctx);
return (0);
}
#if 0
static int
acpi_sony_suspend(device_t dev)
{
struct acpi_sony_softc *sc = device_get_softc(dev);
return (0);
}
static int
acpi_sony_resume(device_t dev)
{
return (0);
}
#endif
static int
sysctl_acpi_sony_gen_handler(SYSCTL_HANDLER_ARGS)
{
device_t dev = arg1;
int function = oidp->oid_arg2;
int error = 0, val;
acpi_GetInteger(acpi_get_handle(dev),
acpi_sony_oids[function].getmethod, &val);
error = sysctl_handle_int(oidp, &val, 0, req);
if (error || !req->newptr || !acpi_sony_oids[function].setmethod)
return (error);
acpi_SetInteger(acpi_get_handle(dev),
acpi_sony_oids[function].setmethod, val);
return (0);
}