summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Stein <jcs@cvs.openbsd.org>2020-05-31 18:15:38 +0000
committerJoshua Stein <jcs@cvs.openbsd.org>2020-05-31 18:15:38 +0000
commitf39862bd815ebbf8e461f7471ca13ef253aa79e9 (patch)
treeb30fef0d897265e799dc5f64bce0b752bf039676
parent313fc8c0aaa22cd3b9830866544b743746394b08 (diff)
add umstc(4) for Microsoft Surface Type Cover keyboards
-rw-r--r--share/man/man4/Makefile6
-rw-r--r--share/man/man4/umstc.444
-rw-r--r--share/man/man4/usb.46
-rw-r--r--sys/arch/amd64/conf/GENERIC3
-rw-r--r--sys/dev/hid/hid.h7
-rw-r--r--sys/dev/usb/files.usb7
-rw-r--r--sys/dev/usb/umstc.c172
7 files changed, 237 insertions, 8 deletions
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 2d9a57d3814..2cce0a9a132 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.772 2020/04/27 21:36:07 patrick Exp $
+# $OpenBSD: Makefile,v 1.773 2020/05/31 18:15:36 jcs Exp $
MAN= aac.4 abcrtc.4 ac97.4 acphy.4 acrtc.4 \
acpi.4 acpiac.4 acpials.4 acpiasus.4 acpibat.4 \
@@ -83,8 +83,8 @@ MAN= aac.4 abcrtc.4 ac97.4 acphy.4 acrtc.4 \
uftdi.4 ugen.4 ugl.4 ugold.4 uguru.4 uhci.4 uhid.4 uhidev.4 uipaq.4 \
uk.4 ukbd.4 \
ukphy.4 ulpt.4 umass.4 umb.4 umbg.4 umcs.4 umct.4 umidi.4 umodem.4 \
- ums.4 umsm.4 umt.4 unix.4 uonerng.4 uow.4 uoaklux.4 uoakrh.4 uoakv.4 \
- upd.4 upgt.4 upl.4 uplcom.4 ural.4 ure.4 url.4 urlphy.4 \
+ ums.4 umsm.4 umstc.4 umt.4 unix.4 uonerng.4 uow.4 uoaklux.4 uoakrh.4 \
+ uoakv.4 upd.4 upgt.4 upl.4 uplcom.4 ural.4 ure.4 url.4 urlphy.4 \
urndis.4 urng.4 urtw.4 urtwn.4 usb.4 uscom.4 uslcom.4 usps.4 \
uthum.4 uticom.4 utpms.4 utwitch.4 utrh.4 uts.4 utvfu.4 uvideo.4 \
uvisor.4 uvscom.4 uwacom.4 uxrcom.4 \
diff --git a/share/man/man4/umstc.4 b/share/man/man4/umstc.4
new file mode 100644
index 00000000000..3c5788a87df
--- /dev/null
+++ b/share/man/man4/umstc.4
@@ -0,0 +1,44 @@
+.\" $OpenBSD: umstc.4,v 1.1 2020/05/31 18:15:36 jcs Exp $
+.\"
+.\" Copyright (c) 2020 joshua stein <jcs@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.
+.\"
+.Dd $Mdocdate: May 31 2020 $
+.Dt UMSTC 4
+.Os
+.Sh NAME
+.Nm umstc
+.Nd Microsoft Surface Type Cover driver
+.Sh SYNOPSIS
+.Cd "umstc* at uhidev?"
+.Sh DESCRIPTION
+The
+.Nm
+driver responds to some special keys on the Microsoft Type Cover
+keyboard, such as volume and screen brightness keys.
+.Sh SEE ALSO
+.Xr uhidev 4 ,
+.Xr usb 4 ,
+.Xr sysctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 6.8 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An joshua stein Aq Mt jcs@jcs.org .
diff --git a/share/man/man4/usb.4 b/share/man/man4/usb.4
index 805106537a0..ffdb17c9595 100644
--- a/share/man/man4/usb.4
+++ b/share/man/man4/usb.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: usb.4,v 1.200 2020/05/12 13:03:52 schwarze Exp $
+.\" $OpenBSD: usb.4,v 1.201 2020/05/31 18:15:36 jcs Exp $
.\" $NetBSD: usb.4,v 1.15 1999/07/29 14:20:32 augustss Exp $
.\"
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 12 2020 $
+.Dd $Mdocdate: May 31 2020 $
.Dt USB 4
.Os
.Sh NAME
@@ -257,6 +257,8 @@ Base driver for all Human Interface Devices
USB keyboards that follow the boot protocol
.It Xr ums 4
USB HID mouse, touchscreen and digitiser devices
+.It Xr umstc 4
+Microsoft Surface Type Cover keyboards
.It Xr umt 4
USB HID multitouch touchpad devices
.It Xr uoaklux 4
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC
index 87893bfafea..9aa0a390690 100644
--- a/sys/arch/amd64/conf/GENERIC
+++ b/sys/arch/amd64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.488 2020/03/06 08:39:34 patrick Exp $
+# $OpenBSD: GENERIC,v 1.489 2020/05/31 18:15:36 jcs Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -283,6 +283,7 @@ ucom* at uslhcom?
uhid* at uhidev? # USB generic HID support
fido* at uhidev? # FIDO/U2F security key support
upd* at uhidev? # USB Power Devices sensors
+umstc* at uhidev? # Microsoft Surface Type Cover
aue* at uhub? # ADMtek AN986 Pegasus Ethernet
atu* at uhub? # Atmel AT76c50x based 802.11b
axe* at uhub? # ASIX Electronics AX88172 USB Ethernet
diff --git a/sys/dev/hid/hid.h b/sys/dev/hid/hid.h
index 17de4065e0c..dd9586d7cc2 100644
--- a/sys/dev/hid/hid.h
+++ b/sys/dev/hid/hid.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hid.h,v 1.6 2019/12/17 13:08:54 reyk Exp $ */
+/* $OpenBSD: hid.h,v 1.7 2020/05/31 18:15:37 jcs Exp $ */
/* $NetBSD: hid.h,v 1.8 2002/07/11 21:14:25 augustss Exp $ */
/* $FreeBSD: src/sys/dev/usb/hid.h,v 1.7 1999/11/17 22:33:40 n_hibma Exp $ */
@@ -396,6 +396,11 @@ int hid_is_collection(const void *, int, uint8_t, int32_t);
#define HUL_KANA 0x0005
/* Usages, Consumer */
+#define HUC_CONTROL 0x0001
+#define HUC_PLAY_PAUSE 0x00cd
+#define HUC_MUTE 0x00e2
+#define HUC_VOL_INC 0x00e9
+#define HUC_VOL_DEC 0x00ea
#define HUC_AC_PAN 0x0238
/* Usages, FIDO */
diff --git a/sys/dev/usb/files.usb b/sys/dev/usb/files.usb
index c3597c54775..1d673cf635d 100644
--- a/sys/dev/usb/files.usb
+++ b/sys/dev/usb/files.usb
@@ -1,4 +1,4 @@
-# $OpenBSD: files.usb,v 1.142 2020/01/24 05:14:51 jsg Exp $
+# $OpenBSD: files.usb,v 1.143 2020/05/31 18:15:37 jcs Exp $
# $NetBSD: files.usb,v 1.16 2000/02/14 20:29:54 augustss Exp $
#
# Config file and device description for machine-independent USB code.
@@ -473,3 +473,8 @@ file dev/usb/uwacom.c uwacom
attach bwfm at uhub with bwfm_usb: firmload
file dev/usb/if_bwfm_usb.c bwfm_usb
+
+# Microsoft Surface Type Cover
+device umstc: hid
+attach umstc at uhidbus
+file dev/usb/umstc.c umstc
diff --git a/sys/dev/usb/umstc.c b/sys/dev/usb/umstc.c
new file mode 100644
index 00000000000..bed4edd45bf
--- /dev/null
+++ b/sys/dev/usb/umstc.c
@@ -0,0 +1,172 @@
+/* $OpenBSD: umstc.c,v 1.1 2020/05/31 18:15:37 jcs Exp $ */
+
+/*
+ * Copyright (c) 2020 joshua stein <jcs@jcs.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.
+ */
+
+/*
+ * Microsoft Surface Type Cover driver to respond to F1-F7 keys, but also to
+ * keep the USB HID pipes open or else the Type Cover will detach and reattach
+ * each time one of these buttons is pressed.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/uhidev.h>
+
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsdisplayvar.h>
+
+#include "audio.h"
+#include "wsdisplay.h"
+
+struct umstc_softc {
+ struct uhidev sc_hdev;
+};
+
+void umstc_intr(struct uhidev *addr, void *ibuf, u_int len);
+int umstc_match(struct device *, void *, void *);
+void umstc_attach(struct device *, struct device *, void *);
+int umstc_detach(struct device *, int flags);
+
+extern int wskbd_set_mixervolume(long, long);
+
+struct cfdriver umstc_cd = {
+ NULL, "umstc", DV_DULL
+};
+
+const struct cfattach umstc_ca = {
+ sizeof(struct umstc_softc),
+ umstc_match,
+ umstc_attach,
+ umstc_detach,
+};
+
+static const struct usb_devno umstc_devs[] = {
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_TYPECOVER },
+ { USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_TYPECOVER2 },
+};
+
+int
+umstc_match(struct device *parent, void *match, void *aux)
+{
+ struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
+ int size;
+ void *desc;
+
+ if (!usb_lookup(umstc_devs, uha->uaa->vendor, uha->uaa->product))
+ return UMATCH_NONE;
+
+ uhidev_get_report_desc(uha->parent, &desc, &size);
+
+ if (hid_is_collection(desc, size, uha->reportid,
+ HID_USAGE2(HUP_CONSUMER, HUC_CONTROL)))
+ return UMATCH_IFACECLASS;
+
+ return UMATCH_NONE;
+}
+
+void
+umstc_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct umstc_softc *sc = (struct umstc_softc *)self;
+ struct uhidev_attach_arg *uha = (struct uhidev_attach_arg *)aux;
+ struct usb_attach_arg *uaa = uha->uaa;
+ int size, repid;
+ void *desc;
+
+ sc->sc_hdev.sc_intr = umstc_intr;
+ sc->sc_hdev.sc_parent = uha->parent;
+ sc->sc_hdev.sc_udev = uaa->device;
+ sc->sc_hdev.sc_report_id = uha->reportid;
+
+ uhidev_get_report_desc(uha->parent, &desc, &size);
+ repid = uha->reportid;
+ sc->sc_hdev.sc_isize = hid_report_size(desc, size, hid_input, repid);
+ sc->sc_hdev.sc_osize = hid_report_size(desc, size, hid_output, repid);
+ sc->sc_hdev.sc_fsize = hid_report_size(desc, size, hid_feature, repid);
+
+ uhidev_open(&sc->sc_hdev);
+
+ printf("\n");
+}
+
+int
+umstc_detach(struct device *self, int flags)
+{
+ struct umstc_softc *sc = (struct umstc_softc *)self;
+
+ uhidev_close(&sc->sc_hdev);
+
+ return 0;
+}
+
+void
+umstc_intr(struct uhidev *addr, void *buf, u_int len)
+{
+ struct umstc_softc *sc = (struct umstc_softc *)addr;
+ int i;
+
+ if (!len)
+ return;
+
+ switch (((unsigned char *)buf)[0]) {
+ case HUC_PLAY_PAUSE:
+ /*
+ * It would be nice to pass this through to userland but we'd
+ * need to attach a wskbd
+ */
+ break;
+ case HUC_MUTE:
+#if NAUDIO > 0
+ wskbd_set_mixervolume(0, 1);
+#endif
+ break;
+ case HUC_VOL_INC:
+#if NAUDIO > 0
+ wskbd_set_mixervolume(1, 1);
+#endif
+ break;
+ case HUC_VOL_DEC:
+#if NAUDIO > 0
+ wskbd_set_mixervolume(-1, 1);
+#endif
+ break;
+ case 0x70: /* brightness down */
+#if NWSDISPLAY > 0
+ wsdisplay_brightness_step(NULL, -1);
+#endif
+ break;
+ case 0x6f: /* brightness up */
+#if NWSDISPLAY > 0
+ wsdisplay_brightness_step(NULL, 1);
+#endif
+ break;
+ case 0:
+ break;
+ default:
+ printf("%s: unhandled key ", sc->sc_hdev.sc_dev.dv_xname);
+ for (i = 0; i < len; i++)
+ printf(" 0x%02x", ((unsigned char *)buf)[i]);
+ printf("\n");
+ }
+}