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