diff --git a/sys/dev/acpi/asus_acpi.c b/sys/dev/acpi/asus_acpi.c new file mode 100644 index 000000000000..e2e3cd7d84e5 --- /dev/null +++ b/sys/dev/acpi/asus_acpi.c @@ -0,0 +1,225 @@ +/* $NetBSD: asus_acpi.c,v 1.1 2008/03/31 15:17:21 jmcneill Exp $ */ + +/*- + * Copyright (c) 2007, 2008 Jared D. McNeill + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jared D. McNeill. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 +__KERNEL_RCSID(0, "$NetBSD: asus_acpi.c,v 1.1 2008/03/31 15:17:21 jmcneill Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef struct asus_softc { + device_t sc_dev; + struct acpi_devnode *sc_node; + +#define ASUS_PSW_DISPLAY_CYCLE 0 +#define ASUS_PSW_LAST 1 + struct sysmon_pswitch sc_smpsw[ASUS_PSW_LAST]; + bool sc_smpsw_valid; +} asus_softc_t; + +#define ASUS_NOTIFY_WirelessSwitch 0x10 +#define ASUS_NOTIFY_BrightnessLow 0x20 +#define ASUS_NOTIFY_BrightnessHigh 0x2f +#define ASUS_NOTIFY_DisplayCycle 0x30 +#define ASUS_NOTIFY_WindowSwitch 0x12 /* XXXJDM ?? */ +#define ASUS_NOTIFY_VolumeMute 0x13 +#define ASUS_NOTIFY_VolumeDown 0x14 +#define ASUS_NOTIFY_VolumeUp 0x15 + +#define ASUS_METHOD_SDSP "SDSP" +#define ASUS_SDSP_LCD 0x01 +#define ASUS_SDSP_CRT 0x02 +#define ASUS_SDSP_TV 0x04 +#define ASUS_SDSP_DVI 0x08 +#define ASUS_SDSP_ALL \ + (ASUS_SDSP_LCD | ASUS_SDSP_CRT | ASUS_SDSP_TV | ASUS_SDSP_DVI) + +static int asus_match(device_t, struct cfdata *, void *); +static void asus_attach(device_t, device_t, void *); + +static void asus_notify_handler(ACPI_HANDLE, UINT32, void *); + +static void asus_init(device_t); +static bool asus_resume(device_t PMF_FN_PROTO); + +CFATTACH_DECL_NEW(asus, sizeof(asus_softc_t), + asus_match, asus_attach, NULL, NULL); + +static const char * const asus_ids[] = { + "ASUS010", + NULL +}; + +static int +asus_match(device_t parent, cfdata_t match, void *opaque) +{ + struct acpi_attach_args *aa = opaque; + + if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) + return 0; + + return acpi_match_hid(aa->aa_node->ad_devinfo, asus_ids); +} + +static void +asus_attach(device_t parent, device_t self, void *opaque) +{ + asus_softc_t *sc = device_private(self); + struct acpi_attach_args *aa = opaque; + ACPI_STATUS rv; + + sc->sc_node = aa->aa_node; + sc->sc_dev = self; + + aprint_naive("\n"); + aprint_normal("\n"); + + asus_init(self); + + sc->sc_smpsw_valid = true; + sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_name = + PSWITCH_HK_DISPLAY_CYCLE; + sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE].smpsw_type = + PSWITCH_TYPE_HOTKEY; + if (sysmon_pswitch_register(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE])) { + aprint_error_dev(self, "couldn't register with sysmon\n"); + sc->sc_smpsw_valid = false; + } + + rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_ALL_NOTIFY, + asus_notify_handler, sc); + if (ACPI_FAILURE(rv)) + aprint_error_dev(self, "couldn't install notify handler: %s\n", + AcpiFormatException(rv)); + + if (!pmf_device_register(self, NULL, asus_resume)) + aprint_error_dev(self, "couldn't establish power handler\n"); + + return; +} + +static void +asus_notify_handler(ACPI_HANDLE hdl, UINT32 notify, void *opaque) +{ + asus_softc_t *sc = opaque; + + if (notify >= ASUS_NOTIFY_BrightnessLow && + notify <= ASUS_NOTIFY_BrightnessHigh) { + aprint_debug_dev(sc->sc_dev, "brightness %d percent\n", + (notify & 0xf) * 100 / 0xf); + return; + } + + switch (notify) { + case ASUS_NOTIFY_WirelessSwitch: /* handled by AML */ + case ASUS_NOTIFY_WindowSwitch: /* XXXJDM what is this? */ + break; + case ASUS_NOTIFY_DisplayCycle: + if (sc->sc_smpsw_valid == false) + break; + sysmon_pswitch_event(&sc->sc_smpsw[ASUS_PSW_DISPLAY_CYCLE], + PSWITCH_EVENT_PRESSED); + break; + case ASUS_NOTIFY_VolumeMute: + pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE); + break; + case ASUS_NOTIFY_VolumeDown: + pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN); + break; + case ASUS_NOTIFY_VolumeUp: + pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP); + break; + default: + aprint_debug_dev(sc->sc_dev, "unknown event 0x%02x\n", notify); + break; + } +} + +static void +asus_init(device_t self) +{ + asus_softc_t *sc = device_private(self); + ACPI_STATUS rv; + ACPI_OBJECT param; + ACPI_OBJECT_LIST params; + ACPI_BUFFER ret; + + ret.Pointer = NULL; + ret.Length = ACPI_ALLOCATE_BUFFER; + param.Type = ACPI_TYPE_INTEGER; + param.Integer.Value = 0x40; /* disable ASL display switching */ + params.Pointer = ¶m; + params.Count = 1; + + rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "INIT", + ¶ms, &ret); + if (ACPI_FAILURE(rv)) + aprint_error_dev(self, "couldn't evaluate INIT: %s\n", + AcpiFormatException(rv)); +} + +static bool +asus_resume(device_t self PMF_FN_ARGS) +{ + asus_softc_t *sc = device_private(self); + ACPI_STATUS rv; + ACPI_OBJECT param; + ACPI_OBJECT_LIST params; + ACPI_BUFFER ret; + + asus_init(self); + + ret.Pointer = NULL; + ret.Length = ACPI_ALLOCATE_BUFFER; + param.Type = ACPI_TYPE_INTEGER; + param.Integer.Value = ASUS_SDSP_LCD; + params.Pointer = ¶m; + params.Count = 1; + + rv = AcpiEvaluateObject(sc->sc_node->ad_handle, ASUS_METHOD_SDSP, + ¶ms, &ret); + if (ACPI_FAILURE(rv)) + aprint_error_dev(self, "couldn't evaluate SDSP: %s\n", + AcpiFormatException(rv)); + + return true; +} diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index 399ee3fd3194..49e9c92f232f 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $NetBSD: files.acpi,v 1.49 2007/12/23 17:29:26 jmcneill Exp $ +# $NetBSD: files.acpi,v 1.50 2008/03/31 15:17:21 jmcneill Exp $ include "dev/acpi/acpica/files.acpica" @@ -113,6 +113,11 @@ device aiboost: sysmon_envsys attach aiboost at acpinodebus file dev/acpi/aiboost.c aiboost +# ASUS hotkey device +device asus: sysmon_power +attach asus at acpinodebus +file dev/acpi/asus_acpi.c asus + # Abit uGuru 2005 attach ug at acpinodebus with ug_acpi file dev/acpi/ug_acpi.c ug_acpi