diff options
author | 2018-06-30 18:15:12 +0000 | |
---|---|---|
committer | 2018-06-30 18:15:12 +0000 | |
commit | 144c780a7ba301eae677589b7677496f09dbfa85 (patch) | |
tree | 2e15585bc1d77ae5c73e02964392a20e692da149 | |
parent | Fix a few more of the same. (diff) | |
download | wireguard-openbsd-144c780a7ba301eae677589b7677496f09dbfa85.tar.xz wireguard-openbsd-144c780a7ba301eae677589b7677496f09dbfa85.zip |
acpisurface(4): driver for Surface Pro 4 and Surface Book hardware
buttons.
ok phessler, deraadt, kettenis
-rw-r--r-- | sys/arch/amd64/conf/GENERIC | 3 | ||||
-rw-r--r-- | sys/dev/acpi/acpisurface.c | 153 | ||||
-rw-r--r-- | sys/dev/acpi/files.acpi | 7 |
3 files changed, 161 insertions, 2 deletions
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index 9f0f94a589e..ae6b68a73ff 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.455 2018/05/23 22:17:34 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.456 2018/06/30 18:15:12 mlarkin Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -67,6 +67,7 @@ acpicbkbd* at acpi? acpials* at acpi? tpm* at acpi? acpihve* at acpi? +acpisurface* at acpi? ipmi0 at acpi? disable ccpmic* at iic? tipmic* at iic? diff --git a/sys/dev/acpi/acpisurface.c b/sys/dev/acpi/acpisurface.c new file mode 100644 index 00000000000..361c7871ea0 --- /dev/null +++ b/sys/dev/acpi/acpisurface.c @@ -0,0 +1,153 @@ +/* $OpenBSD: acpisurface.c,v 1.1 2018/06/30 18:15:12 mlarkin Exp $ */ +/* + * Copyright (c) 2018 Mike Larkin <mlarkin@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> + +#include <dev/acpi/acpireg.h> +#include <dev/acpi/acpivar.h> +#include <dev/acpi/acpidev.h> +#include <dev/acpi/amltypes.h> +#include <dev/acpi/dsdt.h> + +#include "audio.h" +#include "wskbd.h" + +/* #define ACPISURFACE_DEBUG */ + +#ifdef ACPISURFACE_DEBUG +#define DPRINTF(x...) do { printf(x); } while(0) +#else +#define DPRINTF(x...) +#endif /* ACPISURFACE_DEBUG */ + +#define SURFACE_ACCESSORY_REMOVED 0xC8 +#define SURFACE_WINDOWS_KEY_PRESSED 0xC4 +#define SURFACE_WINDOWS_KEY_RELEASED 0xC5 +#define SURFACE_VOLUME_UP_PRESSED 0xC0 +#define SURFACE_VOLUME_UP_RELEASED 0xC1 +#define SURFACE_VOLUME_DOWN_PRESSED 0xC2 +#define SURFACE_VOLUME_DOWN_RELEASED 0xC3 +#define SURFACE_POWER_BUTTON_PRESSED 0xC6 +#define SURFACE_POWER_BUTTON_RELEASED 0xC7 + +struct acpisurface_softc { + struct device sc_dev; + + struct acpiec_softc *sc_ec; + struct acpi_softc *sc_acpi; + struct aml_node *sc_devnode; +}; + +int surface_match(struct device *, void *, void *); +void surface_attach(struct device *, struct device *, void *); +int surface_hotkey(struct aml_node *, int, void *); + +#if NAUDIO > 0 && NWSKBD > 0 +extern int wskbd_set_mixervolume(long, long); +#endif + +struct cfattach acpisurface_ca = { + sizeof(struct acpisurface_softc), surface_match, surface_attach, + NULL, NULL +}; + +struct cfdriver acpisurface_cd = { + NULL, "acpisurface", DV_DULL +}; + +const char *acpisurface_hids[] = { + "MSHW0040", + NULL +}; + +int +surface_match(struct device *parent, void *match, void *aux) +{ + struct acpi_attach_args *aa = aux; + struct cfdata *cf = match; + + if (!acpi_matchhids(aa, acpisurface_hids, cf->cf_driver->cd_name)) + return (0); + + return (1); +} + +void +surface_attach(struct device *parent, struct device *self, void *aux) +{ + struct acpisurface_softc *sc = (struct acpisurface_softc *)self; + struct acpi_attach_args *aa = aux; + + sc->sc_acpi = (struct acpi_softc *)parent; + sc->sc_devnode = aa->aaa_node; + + printf("\n"); + + /* Run surface_hotkey on button presses */ + aml_register_notify(sc->sc_devnode, aa->aaa_dev, + surface_hotkey, sc, ACPIDEV_NOPOLL); +} + +int +surface_hotkey(struct aml_node *node, int notify_type, void *arg) +{ + struct acpisurface_softc *sc = arg; + + switch (notify_type) { + case SURFACE_ACCESSORY_REMOVED: + DPRINTF("%s: accessory removed\n", __func__); + break; + case SURFACE_VOLUME_UP_PRESSED: + DPRINTF("%s: volume up pressed\n", __func__); +#if NAUDIO > 0 && NWSKBD > 0 + wskbd_set_mixervolume(1, 10); +#endif + break; + case SURFACE_VOLUME_UP_RELEASED: + DPRINTF("%s: volume up released\n", __func__); + break; + case SURFACE_VOLUME_DOWN_PRESSED: + DPRINTF("%s: volume down pressed\n", __func__); +#if NAUDIO > 0 && NWSKBD > 0 + wskbd_set_mixervolume(-1, 10); +#endif + break; + case SURFACE_VOLUME_DOWN_RELEASED: + DPRINTF("%s: volume down released\n", __func__); + break; + case SURFACE_POWER_BUTTON_PRESSED: + DPRINTF("%s: power button pressed\n", __func__); + break; + case SURFACE_POWER_BUTTON_RELEASED: + DPRINTF("%s: power button released\n", __func__); + acpi_addtask(sc->sc_acpi, acpi_powerdown_task, + sc->sc_acpi, 0); + break; + case SURFACE_WINDOWS_KEY_PRESSED: + DPRINTF("%s: windows key pressed\n", __func__); + break; + case SURFACE_WINDOWS_KEY_RELEASED: + DPRINTF("%s: windows key released\n", __func__); + break; + default: + DPRINTF("%s: unknown notification 0x%x\n", __func__, + notify_type); + } + + return (0); +} diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index e0163a382d7..efc8b7f1ac5 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $OpenBSD: files.acpi,v 1.42 2018/05/21 13:37:31 kettenis Exp $ +# $OpenBSD: files.acpi,v 1.43 2018/06/30 18:15:12 mlarkin Exp $ # # Config file and device description for machine-independent ACPI code. # Included by ports that need it. @@ -170,6 +170,11 @@ device acpisbs attach acpisbs at acpi file dev/acpi/acpisbs.c acpisbs +# MSHW0040 Sufrace/Surface Book media buttons +device acpisurface +attach acpisurface at acpi +file dev/acpi/acpisurface.c acpisurface + # IPMI attach ipmi at acpi with ipmi_acpi file dev/acpi/ipmi_acpi.c ipmi_acpi |