2004-07-21 14:47:54 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 OGAWA Takaya <t-ogawa@triaez.kaisei.org>
|
2005-05-14 10:51:16 +00:00
|
|
|
* Copyright (c) 2004 TAKAHASHI Yoshihiro <nyan@FreeBSD.org>
|
2004-07-21 14:47:54 +00:00
|
|
|
* 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/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
2004-11-07 23:18:23 +00:00
|
|
|
#include <sys/power.h>
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2009-06-05 18:44:36 +00:00
|
|
|
#include <contrib/dev/acpica/include/acpi.h>
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
2004-12-13 23:31:46 +00:00
|
|
|
#define _COMPONENT ACPI_OEM
|
|
|
|
ACPI_MODULE_NAME("Panasonic")
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
/* Debug */
|
|
|
|
#undef ACPI_PANASONIC_DEBUG
|
|
|
|
|
|
|
|
/* Operations */
|
|
|
|
#define HKEY_SET 0
|
|
|
|
#define HKEY_GET 1
|
|
|
|
|
|
|
|
/* Functions */
|
2004-11-07 23:18:23 +00:00
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_MAX_AC 0x02
|
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_MIN_AC 0x03
|
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_AC 0x04
|
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_MAX_DC 0x05
|
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_MIN_DC 0x06
|
|
|
|
#define HKEY_REG_LCD_BRIGHTNESS_DC 0x07
|
2004-07-24 20:40:02 +00:00
|
|
|
#define HKEY_REG_SOUND_MUTE 0x08
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
/* Field definitions */
|
|
|
|
#define HKEY_LCD_BRIGHTNESS_BITS 4
|
|
|
|
#define HKEY_LCD_BRIGHTNESS_DIV ((1 << HKEY_LCD_BRIGHTNESS_BITS) - 1)
|
|
|
|
|
|
|
|
struct acpi_panasonic_softc {
|
|
|
|
device_t dev;
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
|
|
|
|
struct sysctl_ctx_list sysctl_ctx;
|
|
|
|
struct sysctl_oid *sysctl_tree;
|
2004-11-07 23:18:23 +00:00
|
|
|
|
|
|
|
eventhandler_tag power_evh;
|
2004-07-21 14:47:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Prototype for HKEY functions for getting/setting a value. */
|
|
|
|
typedef int hkey_fn_t(ACPI_HANDLE, int, UINT32 *);
|
|
|
|
|
|
|
|
static int acpi_panasonic_probe(device_t dev);
|
|
|
|
static int acpi_panasonic_attach(device_t dev);
|
|
|
|
static int acpi_panasonic_detach(device_t dev);
|
2009-02-05 18:39:33 +00:00
|
|
|
static int acpi_panasonic_shutdown(device_t dev);
|
2004-07-21 14:47:54 +00:00
|
|
|
static int acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS);
|
2010-01-21 21:14:28 +00:00
|
|
|
static UINT64 acpi_panasonic_sinf(ACPI_HANDLE h, UINT64 index);
|
|
|
|
static void acpi_panasonic_sset(ACPI_HANDLE h, UINT64 index,
|
|
|
|
UINT64 val);
|
2004-07-21 14:47:54 +00:00
|
|
|
static int acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc,
|
2004-07-24 20:40:02 +00:00
|
|
|
ACPI_HANDLE h, UINT32 *arg);
|
2004-07-21 14:47:54 +00:00
|
|
|
static void acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc,
|
2004-07-24 20:40:02 +00:00
|
|
|
ACPI_HANDLE h, UINT32 key);
|
2004-07-21 14:47:54 +00:00
|
|
|
static void acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify,
|
2004-07-24 20:40:02 +00:00
|
|
|
void *context);
|
2004-11-07 23:18:23 +00:00
|
|
|
static void acpi_panasonic_power_profile(void *arg);
|
2004-07-24 20:40:02 +00:00
|
|
|
|
|
|
|
static hkey_fn_t hkey_lcd_brightness_max;
|
2004-11-07 23:18:23 +00:00
|
|
|
static hkey_fn_t hkey_lcd_brightness_min;
|
2004-07-24 20:40:02 +00:00
|
|
|
static hkey_fn_t hkey_lcd_brightness;
|
|
|
|
static hkey_fn_t hkey_sound_mute;
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_DECL(panasonic, "ACPI Panasonic extras");
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
/* Table of sysctl names and HKEY functions to call. */
|
|
|
|
static struct {
|
|
|
|
char *name;
|
|
|
|
hkey_fn_t *handler;
|
|
|
|
} sysctl_table[] = {
|
|
|
|
/* name, handler */
|
|
|
|
{"lcd_brightness_max", hkey_lcd_brightness_max},
|
2004-11-07 23:18:23 +00:00
|
|
|
{"lcd_brightness_min", hkey_lcd_brightness_min},
|
2004-07-21 14:47:54 +00:00
|
|
|
{"lcd_brightness", hkey_lcd_brightness},
|
|
|
|
{"sound_mute", hkey_sound_mute},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static device_method_t acpi_panasonic_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, acpi_panasonic_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_panasonic_attach),
|
|
|
|
DEVMETHOD(device_detach, acpi_panasonic_detach),
|
2007-06-02 19:37:27 +00:00
|
|
|
DEVMETHOD(device_shutdown, acpi_panasonic_shutdown),
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2013-01-30 18:01:20 +00:00
|
|
|
DEVMETHOD_END
|
2004-07-21 14:47:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_panasonic_driver = {
|
|
|
|
"acpi_panasonic",
|
|
|
|
acpi_panasonic_methods,
|
|
|
|
sizeof(struct acpi_panasonic_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t acpi_panasonic_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(acpi_panasonic, acpi, acpi_panasonic_driver,
|
2004-07-24 20:40:02 +00:00
|
|
|
acpi_panasonic_devclass, 0, 0);
|
2004-07-21 14:47:54 +00:00
|
|
|
MODULE_DEPEND(acpi_panasonic, acpi, 1, 1, 1);
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_panasonic_probe(device_t dev)
|
|
|
|
{
|
|
|
|
static char *mat_ids[] = { "MAT0019", NULL };
|
2018-10-26 00:05:46 +00:00
|
|
|
int rv;
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
if (acpi_disabled("panasonic") ||
|
|
|
|
device_get_unit(dev) != 0)
|
|
|
|
return (ENXIO);
|
2018-10-26 00:05:46 +00:00
|
|
|
rv = ACPI_ID_PROBE(device_get_parent(dev), dev, mat_ids, NULL);
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2018-10-26 00:05:46 +00:00
|
|
|
if (rv <= 0)
|
|
|
|
device_set_desc(dev, "Panasonic Notebook Hotkeys");
|
|
|
|
return (rv);
|
2004-07-21 14:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_panasonic_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_panasonic_softc *sc;
|
|
|
|
struct acpi_softc *acpi_sc;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
sc->dev = dev;
|
|
|
|
sc->handle = acpi_get_handle(dev);
|
|
|
|
|
|
|
|
acpi_sc = acpi_device_get_parent_softc(dev);
|
|
|
|
|
|
|
|
/* Build sysctl tree */
|
|
|
|
sysctl_ctx_init(&sc->sysctl_ctx);
|
|
|
|
sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
|
|
|
|
SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO,
|
|
|
|
"panasonic", CTLFLAG_RD, 0, "");
|
|
|
|
for (i = 0; sysctl_table[i].name != NULL; i++) {
|
|
|
|
SYSCTL_ADD_PROC(&sc->sysctl_ctx,
|
2004-07-24 20:40:02 +00:00
|
|
|
SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
|
|
|
|
sysctl_table[i].name,
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
|
|
|
|
sc, i, acpi_panasonic_sysctl, "I", "");
|
2004-07-21 14:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Activate hotkeys */
|
|
|
|
status = AcpiEvaluateObject(sc->handle, "", NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev, "enable FN keys failed\n");
|
|
|
|
sysctl_ctx_free(&sc->sysctl_ctx);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-06-02 19:37:27 +00:00
|
|
|
/* Handle notifies */
|
2004-07-21 14:47:54 +00:00
|
|
|
status = AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
|
2004-07-24 20:40:02 +00:00
|
|
|
acpi_panasonic_notify, sc);
|
2004-07-21 14:47:54 +00:00
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev, "couldn't install notify handler - %s\n",
|
2004-07-24 20:40:02 +00:00
|
|
|
AcpiFormatException(status));
|
2004-07-21 14:47:54 +00:00
|
|
|
sysctl_ctx_free(&sc->sysctl_ctx);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2004-11-07 23:18:23 +00:00
|
|
|
/* Install power profile event handler */
|
|
|
|
sc->power_evh = EVENTHANDLER_REGISTER(power_profile_change,
|
|
|
|
acpi_panasonic_power_profile, sc->handle, 0);
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_panasonic_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_panasonic_softc *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
2004-11-07 23:18:23 +00:00
|
|
|
/* Remove power profile event handler */
|
|
|
|
EVENTHANDLER_DEREGISTER(power_profile_change, sc->power_evh);
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
/* Remove notify handler */
|
|
|
|
AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
|
2004-07-24 20:40:02 +00:00
|
|
|
acpi_panasonic_notify);
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
/* Free sysctl tree */
|
|
|
|
sysctl_ctx_free(&sc->sysctl_ctx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-02-05 18:39:33 +00:00
|
|
|
static int
|
2007-06-02 19:37:27 +00:00
|
|
|
acpi_panasonic_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_panasonic_softc *sc;
|
|
|
|
int mute;
|
|
|
|
|
|
|
|
/* Mute the main audio during reboot to prevent static burst to speaker. */
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mute = 1;
|
|
|
|
hkey_sound_mute(sc->handle, HKEY_SET, &mute);
|
2009-02-05 18:39:33 +00:00
|
|
|
return (0);
|
2007-06-02 19:37:27 +00:00
|
|
|
}
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
static int
|
|
|
|
acpi_panasonic_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct acpi_panasonic_softc *sc;
|
|
|
|
UINT32 arg;
|
|
|
|
int function, error;
|
|
|
|
hkey_fn_t *handler;
|
|
|
|
|
|
|
|
sc = (struct acpi_panasonic_softc *)oidp->oid_arg1;
|
|
|
|
function = oidp->oid_arg2;
|
|
|
|
handler = sysctl_table[function].handler;
|
|
|
|
|
2007-06-02 19:37:27 +00:00
|
|
|
/* Get the current value from the appropriate function. */
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_BEGIN(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
error = handler(sc->handle, HKEY_GET, &arg);
|
|
|
|
if (error != 0)
|
2004-08-13 06:22:31 +00:00
|
|
|
goto out;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
/* Send the current value to the user and return if no new value. */
|
|
|
|
error = sysctl_handle_int(oidp, &arg, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
2004-08-13 06:22:31 +00:00
|
|
|
goto out;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
/* Set the new value via the appropriate function. */
|
|
|
|
error = handler(sc->handle, HKEY_SET, &arg);
|
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
out:
|
2004-08-24 17:53:25 +00:00
|
|
|
ACPI_SERIAL_END(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2010-01-21 21:14:28 +00:00
|
|
|
static UINT64
|
|
|
|
acpi_panasonic_sinf(ACPI_HANDLE h, UINT64 index)
|
2004-07-21 14:47:54 +00:00
|
|
|
{
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT *res;
|
2010-01-21 21:14:28 +00:00
|
|
|
UINT64 ret;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
ret = -1;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
AcpiEvaluateObject(h, "SINF", NULL, &buf);
|
|
|
|
res = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (res->Type == ACPI_TYPE_PACKAGE)
|
|
|
|
ret = res->Package.Elements[index].Integer.Value;
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-01-21 21:14:28 +00:00
|
|
|
acpi_panasonic_sset(ACPI_HANDLE h, UINT64 index, UINT64 val)
|
2004-07-21 14:47:54 +00:00
|
|
|
{
|
|
|
|
ACPI_OBJECT_LIST args;
|
|
|
|
ACPI_OBJECT obj[2];
|
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
obj[0].Type = ACPI_TYPE_INTEGER;
|
|
|
|
obj[0].Integer.Value = index;
|
|
|
|
obj[1].Type = ACPI_TYPE_INTEGER;
|
|
|
|
obj[1].Integer.Value = val;
|
|
|
|
args.Count = 2;
|
|
|
|
args.Pointer = obj;
|
|
|
|
AcpiEvaluateObject(h, "SSET", &args, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hkey_lcd_brightness_max(ACPI_HANDLE h, int op, UINT32 *val)
|
|
|
|
{
|
2004-11-07 23:18:23 +00:00
|
|
|
int reg;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-11-07 23:18:23 +00:00
|
|
|
reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ?
|
|
|
|
HKEY_REG_LCD_BRIGHTNESS_MAX_AC : HKEY_REG_LCD_BRIGHTNESS_MAX_DC;
|
|
|
|
|
2004-07-21 14:47:54 +00:00
|
|
|
switch (op) {
|
|
|
|
case HKEY_SET:
|
2004-11-07 23:18:23 +00:00
|
|
|
return (EPERM);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
|
|
|
case HKEY_GET:
|
2004-11-07 23:18:23 +00:00
|
|
|
*val = acpi_panasonic_sinf(h, reg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hkey_lcd_brightness_min(ACPI_HANDLE h, int op, UINT32 *val)
|
|
|
|
{
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
|
|
|
reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ?
|
|
|
|
HKEY_REG_LCD_BRIGHTNESS_MIN_AC : HKEY_REG_LCD_BRIGHTNESS_MIN_DC;
|
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case HKEY_SET:
|
|
|
|
return (EPERM);
|
|
|
|
break;
|
|
|
|
case HKEY_GET:
|
|
|
|
*val = acpi_panasonic_sinf(h, reg);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hkey_lcd_brightness(ACPI_HANDLE h, int op, UINT32 *val)
|
|
|
|
{
|
2004-11-07 23:18:23 +00:00
|
|
|
int reg;
|
|
|
|
UINT32 max, min;
|
|
|
|
|
|
|
|
reg = (power_profile_get_state() == POWER_PROFILE_PERFORMANCE) ?
|
|
|
|
HKEY_REG_LCD_BRIGHTNESS_AC : HKEY_REG_LCD_BRIGHTNESS_DC;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
switch (op) {
|
|
|
|
case HKEY_SET:
|
2004-11-07 23:18:23 +00:00
|
|
|
hkey_lcd_brightness_max(h, HKEY_GET, &max);
|
|
|
|
hkey_lcd_brightness_min(h, HKEY_GET, &min);
|
|
|
|
if (*val < min || *val > max)
|
2004-07-21 14:47:54 +00:00
|
|
|
return (EINVAL);
|
2004-11-07 23:18:23 +00:00
|
|
|
acpi_panasonic_sset(h, reg, *val);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
|
|
|
case HKEY_GET:
|
2004-11-07 23:18:23 +00:00
|
|
|
*val = acpi_panasonic_sinf(h, reg);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hkey_sound_mute(ACPI_HANDLE h, int op, UINT32 *val)
|
|
|
|
{
|
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
switch (op) {
|
|
|
|
case HKEY_SET:
|
|
|
|
if (*val != 0 && *val != 1)
|
|
|
|
return (EINVAL);
|
|
|
|
acpi_panasonic_sset(h, HKEY_REG_SOUND_MUTE, *val);
|
|
|
|
break;
|
|
|
|
case HKEY_GET:
|
|
|
|
*val = acpi_panasonic_sinf(h, HKEY_REG_SOUND_MUTE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_panasonic_hkey_event(struct acpi_panasonic_softc *sc, ACPI_HANDLE h,
|
2004-07-24 20:40:02 +00:00
|
|
|
UINT32 *arg)
|
2004-07-21 14:47:54 +00:00
|
|
|
{
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT *res;
|
2010-01-21 21:14:28 +00:00
|
|
|
UINT64 val;
|
2004-07-21 14:47:54 +00:00
|
|
|
int status;
|
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
status = ENXIO;
|
|
|
|
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
buf.Pointer = NULL;
|
|
|
|
AcpiEvaluateObject(h, "HINF", NULL, &buf);
|
|
|
|
res = (ACPI_OBJECT *)buf.Pointer;
|
|
|
|
if (res->Type != ACPI_TYPE_INTEGER) {
|
|
|
|
device_printf(sc->dev, "HINF returned non-integer\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
val = res->Integer.Value;
|
|
|
|
#ifdef ACPI_PANASONIC_DEBUG
|
|
|
|
device_printf(sc->dev, "%s button Fn+F%d\n",
|
|
|
|
(val & 0x80) ? "Pressed" : "Released",
|
|
|
|
(int)(val & 0x7f));
|
|
|
|
#endif
|
|
|
|
if ((val & 0x7f) > 0 && (val & 0x7f) < 11) {
|
|
|
|
*arg = val;
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
if (buf.Pointer)
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_panasonic_hkey_action(struct acpi_panasonic_softc *sc, ACPI_HANDLE h,
|
2004-07-24 20:40:02 +00:00
|
|
|
UINT32 key)
|
2004-07-21 14:47:54 +00:00
|
|
|
{
|
2006-06-05 11:55:20 +00:00
|
|
|
struct acpi_softc *acpi_sc;
|
2004-11-07 23:18:23 +00:00
|
|
|
int arg, max, min;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
2006-06-05 11:55:20 +00:00
|
|
|
acpi_sc = acpi_device_get_parent_softc(sc->dev);
|
|
|
|
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_ASSERT(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
switch (key) {
|
|
|
|
case 1:
|
|
|
|
/* Decrease LCD brightness. */
|
2004-11-07 23:18:23 +00:00
|
|
|
hkey_lcd_brightness_max(h, HKEY_GET, &max);
|
|
|
|
hkey_lcd_brightness_min(h, HKEY_GET, &min);
|
2004-07-21 14:47:54 +00:00
|
|
|
hkey_lcd_brightness(h, HKEY_GET, &arg);
|
2004-11-07 23:18:23 +00:00
|
|
|
arg -= max / HKEY_LCD_BRIGHTNESS_DIV;
|
|
|
|
if (arg < min)
|
|
|
|
arg = min;
|
|
|
|
else if (arg > max)
|
|
|
|
arg = max;
|
2004-07-21 14:47:54 +00:00
|
|
|
hkey_lcd_brightness(h, HKEY_SET, &arg);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* Increase LCD brightness. */
|
2004-11-07 23:18:23 +00:00
|
|
|
hkey_lcd_brightness_max(h, HKEY_GET, &max);
|
|
|
|
hkey_lcd_brightness_min(h, HKEY_GET, &min);
|
2004-07-21 14:47:54 +00:00
|
|
|
hkey_lcd_brightness(h, HKEY_GET, &arg);
|
2004-11-07 23:18:23 +00:00
|
|
|
arg += max / HKEY_LCD_BRIGHTNESS_DIV;
|
|
|
|
if (arg < min)
|
|
|
|
arg = min;
|
|
|
|
else if (arg > max)
|
|
|
|
arg = max;
|
2004-07-21 14:47:54 +00:00
|
|
|
hkey_lcd_brightness(h, HKEY_SET, &arg);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* Toggle sound mute. */
|
|
|
|
hkey_sound_mute(h, HKEY_GET, &arg);
|
|
|
|
if (arg)
|
|
|
|
arg = 0;
|
|
|
|
else
|
|
|
|
arg = 1;
|
|
|
|
hkey_sound_mute(h, HKEY_SET, &arg);
|
|
|
|
break;
|
2006-06-05 11:55:20 +00:00
|
|
|
case 7:
|
|
|
|
/* Suspend. */
|
2006-06-06 15:20:06 +00:00
|
|
|
acpi_event_sleep_button_sleep(acpi_sc);
|
2006-06-05 11:55:20 +00:00
|
|
|
break;
|
2004-07-21 14:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_panasonic_notify(ACPI_HANDLE h, UINT32 notify, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_panasonic_softc *sc;
|
2007-06-17 04:40:33 +00:00
|
|
|
UINT32 key = 0;
|
2004-07-21 14:47:54 +00:00
|
|
|
|
|
|
|
sc = (struct acpi_panasonic_softc *)context;
|
|
|
|
|
|
|
|
switch (notify) {
|
|
|
|
case 0x80:
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_BEGIN(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
if (acpi_panasonic_hkey_event(sc, h, &key) == 0) {
|
|
|
|
acpi_panasonic_hkey_action(sc, h, key);
|
|
|
|
acpi_UserNotify("Panasonic", h, (uint8_t)key);
|
|
|
|
}
|
2004-08-13 06:22:31 +00:00
|
|
|
ACPI_SERIAL_END(panasonic);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
2017-01-27 14:17:48 +00:00
|
|
|
case 0x81:
|
|
|
|
if (!bootverbose)
|
|
|
|
break;
|
|
|
|
/* FALLTHROUGH */
|
2004-07-21 14:47:54 +00:00
|
|
|
default:
|
2004-07-24 20:40:02 +00:00
|
|
|
device_printf(sc->dev, "unknown notify: %#x\n", notify);
|
2004-07-21 14:47:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-11-07 23:18:23 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_panasonic_power_profile(void *arg)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
UINT32 brightness;
|
|
|
|
|
|
|
|
handle = (ACPI_HANDLE)arg;
|
|
|
|
|
|
|
|
/* Reset current brightness according to new power state. */
|
|
|
|
ACPI_SERIAL_BEGIN(panasonic);
|
|
|
|
hkey_lcd_brightness(handle, HKEY_GET, &brightness);
|
|
|
|
hkey_lcd_brightness(handle, HKEY_SET, &brightness);
|
|
|
|
ACPI_SERIAL_END(panasonic);
|
|
|
|
}
|