2006-10-30 05:38:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 Takanori Watanabe
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/bus.h>
|
2009-06-05 18:44:36 +00:00
|
|
|
|
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
|
2006-10-30 05:38:48 +00:00
|
|
|
#include "acpi_if.h"
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
#define _COMPONENT ACPI_OEM
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_MODULE_NAME("AIBOOST")
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
#define DESCSTRLEN 32
|
|
|
|
|
|
|
|
struct acpi_aiboost_element {
|
2006-10-30 05:38:48 +00:00
|
|
|
uint32_t id;
|
2009-10-29 18:03:16 +00:00
|
|
|
char desc[DESCSTRLEN];
|
2006-10-30 05:38:48 +00:00
|
|
|
};
|
2009-10-29 18:03:16 +00:00
|
|
|
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_DECL(aiboost, "ACPI AIBOOST");
|
2009-10-29 18:03:16 +00:00
|
|
|
|
|
|
|
struct acpi_aiboost_component {
|
|
|
|
u_int num;
|
|
|
|
struct acpi_aiboost_element elem[0];
|
2006-10-30 05:38:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct acpi_aiboost_softc {
|
2009-10-29 18:03:16 +00:00
|
|
|
int pid;
|
2006-10-30 05:38:48 +00:00
|
|
|
struct acpi_aiboost_component *temp;
|
|
|
|
struct acpi_aiboost_component *volt;
|
|
|
|
struct acpi_aiboost_component *fan;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int acpi_aiboost_probe(device_t dev);
|
|
|
|
static int acpi_aiboost_attach(device_t dev);
|
2009-10-29 18:03:16 +00:00
|
|
|
static int acpi_aiboost_detach(device_t dev);
|
2006-10-30 05:38:48 +00:00
|
|
|
|
|
|
|
static device_method_t acpi_aiboost_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, acpi_aiboost_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_aiboost_attach),
|
|
|
|
DEVMETHOD(device_detach, acpi_aiboost_detach),
|
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_aiboost_driver = {
|
|
|
|
"acpi_aiboost",
|
|
|
|
acpi_aiboost_methods,
|
|
|
|
sizeof(struct acpi_aiboost_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t acpi_aiboost_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(acpi_aiboost, acpi, acpi_aiboost_driver, acpi_aiboost_devclass,
|
2009-10-29 18:03:16 +00:00
|
|
|
0, 0);
|
2006-10-30 05:38:48 +00:00
|
|
|
MODULE_DEPEND(acpi_aiboost, acpi, 1, 1, 1);
|
2009-10-29 18:03:16 +00:00
|
|
|
|
2006-10-30 05:38:48 +00:00
|
|
|
static char *abs_id[] = {"ATK0110", NULL};
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
/* VSIF, RVLT, SVLT, TSIF, RTMP, STMP, FSIF, RFAN, SFAN */
|
2006-10-30 05:38:48 +00:00
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_aiboost_getcomponent(device_t dev, char *name,
|
|
|
|
struct acpi_aiboost_component **comp)
|
2006-10-30 05:38:48 +00:00
|
|
|
{
|
2009-10-29 18:03:16 +00:00
|
|
|
ACPI_BUFFER buf, buf2;
|
|
|
|
ACPI_OBJECT *elem, *o, *subobj;
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_STATUS status;
|
2009-10-29 18:03:16 +00:00
|
|
|
struct acpi_aiboost_component *c;
|
2006-10-30 05:38:48 +00:00
|
|
|
int i;
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
c = NULL;
|
2006-10-30 05:38:48 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
2006-11-06 12:14:27 +00:00
|
|
|
buf2.Pointer = NULL;
|
2006-10-30 05:38:48 +00:00
|
|
|
status = AcpiEvaluateObject(acpi_get_handle(dev), name, NULL, &buf);
|
2009-10-29 18:03:16 +00:00
|
|
|
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return (status);
|
|
|
|
|
2006-10-30 05:38:48 +00:00
|
|
|
o = buf.Pointer;
|
2009-10-29 18:03:16 +00:00
|
|
|
if (o->Type != ACPI_TYPE_PACKAGE) {
|
|
|
|
device_printf(dev, "%s is not a package\n", name);
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
2009-10-29 18:03:16 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 05:38:48 +00:00
|
|
|
elem = o->Package.Elements;
|
2009-10-29 18:03:16 +00:00
|
|
|
if (elem->Type != ACPI_TYPE_INTEGER) {
|
|
|
|
device_printf(dev, "First item in %s is not a count\n", name);
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
2009-10-29 18:03:16 +00:00
|
|
|
}
|
2006-10-30 05:38:48 +00:00
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
if (elem->Integer.Value != o->Package.Count - 1) {
|
|
|
|
device_printf(dev, "Device count mismatch in %s\n", name);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = malloc(sizeof(struct acpi_aiboost_component) +
|
|
|
|
sizeof(struct acpi_aiboost_element) * elem->Integer.Value, M_DEVBUF,
|
|
|
|
M_WAITOK | M_ZERO);
|
2006-10-30 05:38:48 +00:00
|
|
|
*comp = c;
|
|
|
|
c->num = elem->Integer.Value;
|
2009-10-29 18:03:16 +00:00
|
|
|
|
|
|
|
for (i = 1; i < o->Package.Count; i++) {
|
2006-10-30 05:38:48 +00:00
|
|
|
elem = &o->Package.Elements[i];
|
2009-09-22 18:34:23 +00:00
|
|
|
if (elem->Type == ACPI_TYPE_ANY) {
|
|
|
|
buf2.Pointer = NULL;
|
|
|
|
buf2.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
|
|
|
|
status = AcpiEvaluateObject(elem->Reference.Handle,
|
|
|
|
NULL, NULL, &buf2);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev,
|
|
|
|
"Failed to fetch object for %s\n", name);
|
2009-09-22 18:34:23 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
subobj = buf2.Pointer;
|
|
|
|
} else if (elem->Type == ACPI_TYPE_PACKAGE)
|
|
|
|
subobj = elem;
|
|
|
|
else {
|
2009-10-29 18:03:16 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"Subitem %d was not a package for %s\n", i, name);
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2009-10-29 18:03:16 +00:00
|
|
|
status = acpi_PkgInt32(subobj, 0, &c->elem[i - 1].id);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev,
|
|
|
|
"Failed to fetch ID for subobject %d in %s\n", i,
|
|
|
|
name);
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2009-10-29 18:03:16 +00:00
|
|
|
status = acpi_PkgStr(subobj, 1, c->elem[i - 1].desc,
|
|
|
|
sizeof(c->elem[i - 1].desc));
|
|
|
|
if (ACPI_FAILURE(status)){
|
|
|
|
if (status == E2BIG) {
|
2009-09-22 18:34:23 +00:00
|
|
|
c->elem[i - 1].desc[DESCSTRLEN-1] = 0;
|
2009-10-29 18:03:16 +00:00
|
|
|
} else {
|
|
|
|
device_printf(dev,
|
|
|
|
"Failed to fetch description for subobject %d in %s\n",
|
|
|
|
i, name);
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
2009-10-29 18:03:16 +00:00
|
|
|
|
2009-09-22 18:34:23 +00:00
|
|
|
if (buf2.Pointer) {
|
|
|
|
AcpiOsFree(buf2.Pointer);
|
|
|
|
buf2.Pointer = NULL;
|
|
|
|
}
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
if (buf.Pointer)
|
2006-10-30 05:38:48 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
return (0);
|
2006-10-30 05:38:48 +00:00
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
error:
|
|
|
|
if (buf.Pointer)
|
2006-10-30 05:38:48 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (buf2.Pointer)
|
2006-10-30 05:38:48 +00:00
|
|
|
AcpiOsFree(buf2.Pointer);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (c)
|
2006-10-30 05:38:48 +00:00
|
|
|
free(c, M_DEVBUF);
|
2009-10-29 18:03:16 +00:00
|
|
|
return (AE_BAD_DATA);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static int
|
2006-10-30 05:38:48 +00:00
|
|
|
acpi_aiboost_get_value(ACPI_HANDLE handle, char *path, UINT32 number)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT arg1, *ret;
|
|
|
|
ACPI_OBJECT_LIST args;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
arg1.Type = ACPI_TYPE_INTEGER;
|
|
|
|
arg1.Integer.Value = number;
|
|
|
|
args.Count = 1;
|
|
|
|
args.Pointer = &arg1;
|
2009-10-29 18:03:16 +00:00
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
if (ACPI_FAILURE(AcpiEvaluateObject(handle, path, &args, &buf)))
|
|
|
|
return (-1);
|
2006-10-30 05:38:48 +00:00
|
|
|
|
|
|
|
ret = buf.Pointer;
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ret->Type == ACPI_TYPE_INTEGER)
|
|
|
|
val = ret->Integer.Value;
|
|
|
|
else
|
|
|
|
val = -1;
|
2006-10-30 05:38:48 +00:00
|
|
|
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2009-10-29 18:03:16 +00:00
|
|
|
return (val);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static int
|
|
|
|
acpi_aiboost_temp_sysctl(SYSCTL_HANDLER_ARGS)
|
2006-10-30 05:38:48 +00:00
|
|
|
{
|
2009-10-29 18:03:16 +00:00
|
|
|
device_t dev;
|
|
|
|
int error, val;
|
|
|
|
|
|
|
|
dev = arg1;
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_BEGIN(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
val = acpi_aiboost_get_value(acpi_get_handle(dev), "RTMP", arg2);
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_END(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
return (error);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static int
|
|
|
|
acpi_aiboost_volt_sysctl(SYSCTL_HANDLER_ARGS)
|
2006-10-30 05:38:48 +00:00
|
|
|
{
|
2009-10-29 18:03:16 +00:00
|
|
|
device_t dev;
|
|
|
|
int error, val;
|
|
|
|
|
|
|
|
dev = arg1;
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_BEGIN(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
val = acpi_aiboost_get_value(acpi_get_handle(dev), "RVLT", arg2);
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_END(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
return (error);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static int
|
|
|
|
acpi_aiboost_fan_sysctl(SYSCTL_HANDLER_ARGS)
|
2006-10-30 05:38:48 +00:00
|
|
|
{
|
2009-10-29 18:03:16 +00:00
|
|
|
device_t dev;
|
|
|
|
int error, val;
|
|
|
|
|
|
|
|
dev = arg1;
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_BEGIN(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
val = acpi_aiboost_get_value(acpi_get_handle(dev), "RFAN", arg2);
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
2006-10-30 05:38:48 +00:00
|
|
|
ACPI_SERIAL_END(aiboost);
|
2009-10-29 18:03:16 +00:00
|
|
|
return (error);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_aiboost_probe(device_t dev)
|
|
|
|
{
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ACPI_ID_PROBE(device_get_parent(dev), dev, abs_id) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
device_set_desc(dev, "ASUStek AIBOOSTER");
|
|
|
|
return (0);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_aiboost_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_aiboost_softc *sc;
|
2009-10-29 18:03:16 +00:00
|
|
|
char nambuf[16];
|
2006-10-30 05:38:48 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ACPI_FAILURE(acpi_aiboost_getcomponent(dev, "TSIF", &sc->temp)))
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
2009-10-29 18:03:16 +00:00
|
|
|
for (i = 0; i < sc->temp->num; i++) {
|
|
|
|
snprintf(nambuf, sizeof(nambuf), "temp%d", i);
|
2006-10-30 05:38:48 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
|
2009-10-29 18:03:16 +00:00
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
|
|
|
|
nambuf, CTLTYPE_INT | CTLFLAG_RD, dev, sc->temp->elem[i].id,
|
|
|
|
acpi_aiboost_temp_sysctl, "I", sc->temp->elem[i].desc);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ACPI_FAILURE(acpi_aiboost_getcomponent(dev, "VSIF", &sc->volt)))
|
|
|
|
goto error;
|
|
|
|
for (i = 0; i < sc->volt->num; i++) {
|
|
|
|
snprintf(nambuf, sizeof(nambuf), "volt%d", i);
|
2006-10-30 05:38:48 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
|
2009-10-29 18:03:16 +00:00
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
|
|
|
|
nambuf, CTLTYPE_INT | CTLFLAG_RD, dev, sc->volt->elem[i].id,
|
|
|
|
acpi_aiboost_volt_sysctl, "I", sc->volt->elem[i].desc);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
if (ACPI_FAILURE(acpi_aiboost_getcomponent(dev, "FSIF", &sc->fan)))
|
2006-10-30 05:38:48 +00:00
|
|
|
goto error;
|
2009-10-29 18:03:16 +00:00
|
|
|
for (i = 0; i < sc->fan->num; i++) {
|
|
|
|
snprintf(nambuf, sizeof(nambuf), "fan%d", i);
|
2006-10-30 05:38:48 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
|
2009-10-29 18:03:16 +00:00
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
|
|
|
|
nambuf, CTLTYPE_INT | CTLFLAG_RD, dev, sc->fan->elem[i].id,
|
|
|
|
acpi_aiboost_fan_sysctl, "I", sc->fan->elem[i].desc);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
error:
|
2009-10-29 18:03:16 +00:00
|
|
|
return (EINVAL);
|
2006-10-30 05:38:48 +00:00
|
|
|
}
|
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
static int
|
2006-10-30 05:38:48 +00:00
|
|
|
acpi_aiboost_detach(device_t dev)
|
|
|
|
{
|
2009-10-29 18:03:16 +00:00
|
|
|
struct acpi_aiboost_softc *sc;
|
2006-10-30 05:38:48 +00:00
|
|
|
|
2009-10-29 18:03:16 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
if (sc->temp)
|
2006-10-30 05:38:48 +00:00
|
|
|
free(sc->temp, M_DEVBUF);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (sc->volt)
|
2006-10-30 05:38:48 +00:00
|
|
|
free(sc->volt, M_DEVBUF);
|
2009-10-29 18:03:16 +00:00
|
|
|
if (sc->fan)
|
2006-10-30 05:38:48 +00:00
|
|
|
free(sc->fan, M_DEVBUF);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
acpi_aiboost_suspend(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_aiboost_softc *sc = device_get_softc(dev);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_aiboost_resume(device_t dev)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|