Home | History | Annotate | Line # | Download | only in wmi
wmi_eeepc.c revision 1.2.4.2
      1  1.2.4.2  rmind /*	$NetBSD: wmi_eeepc.c,v 1.2.4.2 2011/03/05 20:53:05 rmind Exp $ */
      2  1.2.4.2  rmind 
      3  1.2.4.2  rmind /*-
      4  1.2.4.2  rmind  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  1.2.4.2  rmind  * All rights reserved.
      6  1.2.4.2  rmind  *
      7  1.2.4.2  rmind  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.4.2  rmind  * by Jukka Ruohonen.
      9  1.2.4.2  rmind  *
     10  1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     11  1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     12  1.2.4.2  rmind  * are met:
     13  1.2.4.2  rmind  *
     14  1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     15  1.2.4.2  rmind  *    notice, this list of conditions and the following disclaimer.
     16  1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.2.4.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     18  1.2.4.2  rmind  *    documentation and/or other materials provided with the distribution.
     19  1.2.4.2  rmind  *
     20  1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     21  1.2.4.2  rmind  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22  1.2.4.2  rmind  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  1.2.4.2  rmind  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     24  1.2.4.2  rmind  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25  1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26  1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27  1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28  1.2.4.2  rmind  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29  1.2.4.2  rmind  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30  1.2.4.2  rmind  * SUCH DAMAGE.
     31  1.2.4.2  rmind  */
     32  1.2.4.2  rmind 
     33  1.2.4.2  rmind #include <sys/cdefs.h>
     34  1.2.4.2  rmind __KERNEL_RCSID(0, "$NetBSD: wmi_eeepc.c,v 1.2.4.2 2011/03/05 20:53:05 rmind Exp $");
     35  1.2.4.2  rmind 
     36  1.2.4.2  rmind #include <sys/param.h>
     37  1.2.4.2  rmind #include <sys/device.h>
     38  1.2.4.2  rmind #include <sys/module.h>
     39  1.2.4.2  rmind 
     40  1.2.4.2  rmind #include <dev/acpi/acpireg.h>
     41  1.2.4.2  rmind #include <dev/acpi/acpivar.h>
     42  1.2.4.2  rmind #include <dev/acpi/wmi/wmi_acpivar.h>
     43  1.2.4.2  rmind 
     44  1.2.4.2  rmind #include <dev/sysmon/sysmonvar.h>
     45  1.2.4.2  rmind 
     46  1.2.4.2  rmind #define _COMPONENT			ACPI_RESOURCE_COMPONENT
     47  1.2.4.2  rmind ACPI_MODULE_NAME			("wmi_eeepc")
     48  1.2.4.2  rmind 
     49  1.2.4.2  rmind #define WMI_EEEPC_HK_VOLUME_UP		0x30
     50  1.2.4.2  rmind #define WMI_EEEPC_HK_VOLUME_DOWN	0x31
     51  1.2.4.2  rmind #define WMI_EEEPC_HK_VOLUME_MUTE	0x32
     52  1.2.4.2  rmind #define WMI_EEEPC_HK_DISPLAY_CYCLE	0xCC
     53  1.2.4.2  rmind #define WMI_EEEPC_HK_DISPLAY_OFF	0xE9
     54  1.2.4.2  rmind /*      WMI_EEEPC_HK_UNKNOWN		0xXX */
     55  1.2.4.2  rmind 
     56  1.2.4.2  rmind #define WMI_EEEPC_PSW_DISPLAY_CYCLE	0
     57  1.2.4.2  rmind #define WMI_EEEPC_PSW_COUNT		1
     58  1.2.4.2  rmind 
     59  1.2.4.2  rmind #define WMI_EEEPC_GUID_EVENT		"ABBC0F72-8EA1-11D1-00A0-C90629100000"
     60  1.2.4.2  rmind 
     61  1.2.4.2  rmind struct wmi_eeepc_softc {
     62  1.2.4.2  rmind 	device_t		sc_dev;
     63  1.2.4.2  rmind 	device_t		sc_parent;
     64  1.2.4.2  rmind 	struct sysmon_pswitch	sc_smpsw[WMI_EEEPC_PSW_COUNT];
     65  1.2.4.2  rmind 	bool			sc_smpsw_valid;
     66  1.2.4.2  rmind };
     67  1.2.4.2  rmind 
     68  1.2.4.2  rmind static int	wmi_eeepc_match(device_t, cfdata_t, void *);
     69  1.2.4.2  rmind static void	wmi_eeepc_attach(device_t, device_t, void *);
     70  1.2.4.2  rmind static int	wmi_eeepc_detach(device_t, int);
     71  1.2.4.2  rmind static void	wmi_eeepc_notify_handler(ACPI_HANDLE, uint32_t, void *);
     72  1.2.4.2  rmind static bool	wmi_eeepc_suspend(device_t, const pmf_qual_t *);
     73  1.2.4.2  rmind static bool	wmi_eeepc_resume(device_t, const pmf_qual_t *);
     74  1.2.4.2  rmind 
     75  1.2.4.2  rmind CFATTACH_DECL_NEW(wmieeepc, sizeof(struct wmi_eeepc_softc),
     76  1.2.4.2  rmind     wmi_eeepc_match, wmi_eeepc_attach, wmi_eeepc_detach, NULL);
     77  1.2.4.2  rmind 
     78  1.2.4.2  rmind static int
     79  1.2.4.2  rmind wmi_eeepc_match(device_t parent, cfdata_t match, void *aux)
     80  1.2.4.2  rmind {
     81  1.2.4.2  rmind 	return acpi_wmi_guid_match(parent, WMI_EEEPC_GUID_EVENT);
     82  1.2.4.2  rmind }
     83  1.2.4.2  rmind 
     84  1.2.4.2  rmind static void
     85  1.2.4.2  rmind wmi_eeepc_attach(device_t parent, device_t self, void *aux)
     86  1.2.4.2  rmind {
     87  1.2.4.2  rmind 	static const int dc = WMI_EEEPC_PSW_DISPLAY_CYCLE;
     88  1.2.4.2  rmind 	struct wmi_eeepc_softc *sc = device_private(self);
     89  1.2.4.2  rmind 	ACPI_STATUS rv;
     90  1.2.4.2  rmind 
     91  1.2.4.2  rmind 	sc->sc_dev = self;
     92  1.2.4.2  rmind 	sc->sc_parent = parent;
     93  1.2.4.2  rmind 	sc->sc_smpsw_valid = false;
     94  1.2.4.2  rmind 
     95  1.2.4.2  rmind 	rv = acpi_wmi_event_register(parent, wmi_eeepc_notify_handler);
     96  1.2.4.2  rmind 
     97  1.2.4.2  rmind 	if (ACPI_FAILURE(rv)) {
     98  1.2.4.2  rmind 		aprint_error(": failed to install WMI notify handler\n");
     99  1.2.4.2  rmind 		return;
    100  1.2.4.2  rmind 	}
    101  1.2.4.2  rmind 
    102  1.2.4.2  rmind 	aprint_naive("\n");
    103  1.2.4.2  rmind 	aprint_normal(": Asus Eee PC WMI mappings\n");
    104  1.2.4.2  rmind 
    105  1.2.4.2  rmind 	sc->sc_smpsw[dc].smpsw_type = PSWITCH_TYPE_HOTKEY;
    106  1.2.4.2  rmind 	sc->sc_smpsw[dc].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE;
    107  1.2.4.2  rmind 
    108  1.2.4.2  rmind 	if (sysmon_pswitch_register(&sc->sc_smpsw[dc]) == 0)
    109  1.2.4.2  rmind 		sc->sc_smpsw_valid = true;
    110  1.2.4.2  rmind 
    111  1.2.4.2  rmind 	(void)pmf_device_register(self, wmi_eeepc_suspend, wmi_eeepc_resume);
    112  1.2.4.2  rmind }
    113  1.2.4.2  rmind 
    114  1.2.4.2  rmind static int
    115  1.2.4.2  rmind wmi_eeepc_detach(device_t self, int flags)
    116  1.2.4.2  rmind {
    117  1.2.4.2  rmind 	struct wmi_eeepc_softc *sc = device_private(self);
    118  1.2.4.2  rmind 	device_t parent = sc->sc_parent;
    119  1.2.4.2  rmind 
    120  1.2.4.2  rmind 	(void)pmf_device_deregister(self);
    121  1.2.4.2  rmind 	(void)acpi_wmi_event_deregister(parent);
    122  1.2.4.2  rmind 
    123  1.2.4.2  rmind 	return 0;
    124  1.2.4.2  rmind }
    125  1.2.4.2  rmind 
    126  1.2.4.2  rmind static bool
    127  1.2.4.2  rmind wmi_eeepc_suspend(device_t self, const pmf_qual_t *qual)
    128  1.2.4.2  rmind {
    129  1.2.4.2  rmind 	struct wmi_eeepc_softc *sc = device_private(self);
    130  1.2.4.2  rmind 	device_t parent = sc->sc_parent;
    131  1.2.4.2  rmind 
    132  1.2.4.2  rmind 	(void)acpi_wmi_event_deregister(parent);
    133  1.2.4.2  rmind 
    134  1.2.4.2  rmind 	return true;
    135  1.2.4.2  rmind }
    136  1.2.4.2  rmind 
    137  1.2.4.2  rmind static bool
    138  1.2.4.2  rmind wmi_eeepc_resume(device_t self, const pmf_qual_t *qual)
    139  1.2.4.2  rmind {
    140  1.2.4.2  rmind 	struct wmi_eeepc_softc *sc = device_private(self);
    141  1.2.4.2  rmind 	device_t parent = sc->sc_parent;
    142  1.2.4.2  rmind 
    143  1.2.4.2  rmind 	(void)acpi_wmi_event_register(parent, wmi_eeepc_notify_handler);
    144  1.2.4.2  rmind 
    145  1.2.4.2  rmind 	return true;
    146  1.2.4.2  rmind }
    147  1.2.4.2  rmind 
    148  1.2.4.2  rmind static void
    149  1.2.4.2  rmind wmi_eeepc_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
    150  1.2.4.2  rmind {
    151  1.2.4.2  rmind 	static const int dc = WMI_EEEPC_PSW_DISPLAY_CYCLE;
    152  1.2.4.2  rmind 	struct wmi_eeepc_softc *sc;
    153  1.2.4.2  rmind 	device_t self = aux;
    154  1.2.4.2  rmind 	ACPI_OBJECT *obj;
    155  1.2.4.2  rmind 	ACPI_BUFFER buf;
    156  1.2.4.2  rmind 	ACPI_STATUS rv;
    157  1.2.4.2  rmind 	uint32_t val;
    158  1.2.4.2  rmind 
    159  1.2.4.2  rmind 	buf.Pointer = NULL;
    160  1.2.4.2  rmind 
    161  1.2.4.2  rmind 	sc = device_private(self);
    162  1.2.4.2  rmind 	rv = acpi_wmi_event_get(sc->sc_parent, evt, &buf);
    163  1.2.4.2  rmind 
    164  1.2.4.2  rmind 	if (ACPI_FAILURE(rv))
    165  1.2.4.2  rmind 		goto out;
    166  1.2.4.2  rmind 
    167  1.2.4.2  rmind 	obj = buf.Pointer;
    168  1.2.4.2  rmind 
    169  1.2.4.2  rmind 	if (obj->Type != ACPI_TYPE_INTEGER) {
    170  1.2.4.2  rmind 		rv = AE_TYPE;
    171  1.2.4.2  rmind 		goto out;
    172  1.2.4.2  rmind 	}
    173  1.2.4.2  rmind 
    174  1.2.4.2  rmind 	if (obj->Integer.Value > UINT32_MAX) {
    175  1.2.4.2  rmind 		rv = AE_LIMIT;
    176  1.2.4.2  rmind 		goto out;
    177  1.2.4.2  rmind 	}
    178  1.2.4.2  rmind 
    179  1.2.4.2  rmind 	val = obj->Integer.Value;
    180  1.2.4.2  rmind 
    181  1.2.4.2  rmind 	switch (val) {
    182  1.2.4.2  rmind 
    183  1.2.4.2  rmind 	case WMI_EEEPC_HK_VOLUME_UP:
    184  1.2.4.2  rmind 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
    185  1.2.4.2  rmind 		break;
    186  1.2.4.2  rmind 
    187  1.2.4.2  rmind 	case WMI_EEEPC_HK_VOLUME_DOWN:
    188  1.2.4.2  rmind 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
    189  1.2.4.2  rmind 		break;
    190  1.2.4.2  rmind 
    191  1.2.4.2  rmind 	case WMI_EEEPC_HK_VOLUME_MUTE:
    192  1.2.4.2  rmind 		pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
    193  1.2.4.2  rmind 		break;
    194  1.2.4.2  rmind 
    195  1.2.4.2  rmind 	case WMI_EEEPC_HK_DISPLAY_CYCLE:
    196  1.2.4.2  rmind 
    197  1.2.4.2  rmind 		if (sc->sc_smpsw_valid != true) {
    198  1.2.4.2  rmind 			rv = AE_ABORT_METHOD;
    199  1.2.4.2  rmind 			break;
    200  1.2.4.2  rmind 		}
    201  1.2.4.2  rmind 
    202  1.2.4.2  rmind 		sysmon_pswitch_event(&sc->sc_smpsw[dc], PSWITCH_EVENT_PRESSED);
    203  1.2.4.2  rmind 		break;
    204  1.2.4.2  rmind 
    205  1.2.4.2  rmind 	case WMI_EEEPC_HK_DISPLAY_OFF:
    206  1.2.4.2  rmind 		break;
    207  1.2.4.2  rmind 
    208  1.2.4.2  rmind 	default:
    209  1.2.4.2  rmind 		aprint_debug_dev(sc->sc_dev,
    210  1.2.4.2  rmind 		    "unknown key 0x%02X for event 0x%02X\n", val, evt);
    211  1.2.4.2  rmind 		break;
    212  1.2.4.2  rmind 	}
    213  1.2.4.2  rmind 
    214  1.2.4.2  rmind out:
    215  1.2.4.2  rmind 	if (buf.Pointer != NULL)
    216  1.2.4.2  rmind 		ACPI_FREE(buf.Pointer);
    217  1.2.4.2  rmind 
    218  1.2.4.2  rmind 	if (ACPI_FAILURE(rv))
    219  1.2.4.2  rmind 		aprint_error_dev(sc->sc_dev, "failed to get data for "
    220  1.2.4.2  rmind 		    "event 0x%02X: %s\n", evt, AcpiFormatException(rv));
    221  1.2.4.2  rmind }
    222  1.2.4.2  rmind 
    223  1.2.4.2  rmind MODULE(MODULE_CLASS_DRIVER, wmieeepc, "acpiwmi");
    224  1.2.4.2  rmind 
    225  1.2.4.2  rmind #ifdef _MODULE
    226  1.2.4.2  rmind #include "ioconf.c"
    227  1.2.4.2  rmind #endif
    228  1.2.4.2  rmind 
    229  1.2.4.2  rmind static int
    230  1.2.4.2  rmind wmieeepc_modcmd(modcmd_t cmd, void *aux)
    231  1.2.4.2  rmind {
    232  1.2.4.2  rmind 	int rv = 0;
    233  1.2.4.2  rmind 
    234  1.2.4.2  rmind 	switch (cmd) {
    235  1.2.4.2  rmind 
    236  1.2.4.2  rmind 	case MODULE_CMD_INIT:
    237  1.2.4.2  rmind 
    238  1.2.4.2  rmind #ifdef _MODULE
    239  1.2.4.2  rmind 		rv = config_init_component(cfdriver_ioconf_wmieeepc,
    240  1.2.4.2  rmind 		    cfattach_ioconf_wmieeepc, cfdata_ioconf_wmieeepc);
    241  1.2.4.2  rmind #endif
    242  1.2.4.2  rmind 		break;
    243  1.2.4.2  rmind 
    244  1.2.4.2  rmind 	case MODULE_CMD_FINI:
    245  1.2.4.2  rmind 
    246  1.2.4.2  rmind #ifdef _MODULE
    247  1.2.4.2  rmind 		rv = config_fini_component(cfdriver_ioconf_wmieeepc,
    248  1.2.4.2  rmind 		    cfattach_ioconf_wmieeepc, cfdata_ioconf_wmieeepc);
    249  1.2.4.2  rmind #endif
    250  1.2.4.2  rmind 		break;
    251  1.2.4.2  rmind 
    252  1.2.4.2  rmind 	default:
    253  1.2.4.2  rmind 		rv = ENOTTY;
    254  1.2.4.2  rmind 	}
    255  1.2.4.2  rmind 
    256  1.2.4.2  rmind 	return rv;
    257  1.2.4.2  rmind }
    258