From: matthieu Date: Fri, 11 Nov 2022 15:25:13 +0000 (+0000) Subject: Add icc(4) to handle Customer Control keyboards attached to i2c bus. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2022a111166570abb5dcfc446f52f46a762128f3;p=openbsd Add icc(4) to handle Customer Control keyboards attached to i2c bus. ok anton@ patrick@ --- diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 2e3c0f4f499..e6b81569678 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.825 2022/11/10 13:08:57 patrick Exp $ +# $OpenBSD: Makefile,v 1.826 2022/11/11 15:25:13 matthieu Exp $ MAN= aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \ acpi.4 acpiac.4 acpials.4 acpiasus.4 acpibat.4 \ @@ -41,7 +41,8 @@ MAN= aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \ hds.4 hiclock.4 hidwusb.4 hil.4 hilid.4 hilkbd.4 hilms.4 \ hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \ hvn.4 hvs.4 hyperv.4 \ - iatp.4 iavf.4 ichiic.4 ichwdt.4 icmp.4 icmp6.4 icsphy.4 ifmedia.4 \ + iatp.4 iavf.4 icc.4 ichiic.4 ichwdt.4 \ + icmp.4 icmp6.4 icsphy.4 ifmedia.4 \ igc.4 iha.4 ihidev.4 iic.4 iicmux.4 ikbd.4 ims.4 imt.4 imxanatop.4 \ imxdog.4 imxesdhc.4 imxgpc.4 imxgpio.4 imxiic.4 imxpciephy.4 \ imxpwm.4 imxrtc.4 imxspi.4 imxsrc.4 imxtmu.4 imxuart.4 \ diff --git a/share/man/man4/icc.4 b/share/man/man4/icc.4 new file mode 100644 index 00000000000..556216aed79 --- /dev/null +++ b/share/man/man4/icc.4 @@ -0,0 +1,48 @@ +.\" $OpenBSD: icc.4,v 1.1 2022/11/11 15:25:13 matthieu Exp $ +.\" +.\" Copyright (c) 2021 Anton Lindqvist +.\" +.\" 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: November 11 2022 $ +.Dt ICC 4 +.Os +.Sh NAME +.Nm icc +.Nd Consumer Control keyboards +.Sh SYNOPSIS +.Cd "icc* at ihidev?" +.Cd "wsbkd* at icc? mux 1" +.Sh DESCRIPTION +The +.Nm +driver provides support for Consumer Control pseudo keyboards, often used to +expose screen brightness control +.Sh SEE ALSO +.Xr intro 4 , +.Xr ucc 4 , +.Xr umstc 4 , +.Xr ihidev 4 , +.Xr wskbd 4 +.Sh HISTORY +The +.Nm +driver first appeared in +.Ox 7.3 . +.Sh AUTHORS +The +.Nm +driver was written by +.An Anton Lindqvist Aq Mt anton@openbsd.org +and +.An Matthieu Herrb Aq Mt matthieu@openbsd.org . diff --git a/sys/dev/hid/hidcc.c b/sys/dev/hid/hidcc.c index 7ab8c39f30e..d45b9eca936 100644 --- a/sys/dev/hid/hidcc.c +++ b/sys/dev/hid/hidcc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hidcc.c,v 1.2 2022/11/11 13:59:40 anton Exp $ */ +/* $OpenBSD: hidcc.c,v 1.3 2022/11/11 15:25:13 matthieu Exp $ */ /* * Copyright (c) 2022 Anton Lindqvist @@ -30,7 +30,7 @@ #define DEVNAME(sc) ((sc)->sc_dev->dv_xname) -/* #define HIDCC_DEBUG */ +#define HIDCC_DEBUG #ifdef HIDCC_DEBUG #define DPRINTF(x...) do { if (hidcc_debug) printf(x); } while (0) struct hidcc; @@ -163,8 +163,8 @@ static const struct hidcc_keysym hidcc_keysyms[] = { N(0x006C, "Yellow Menu Button", 0, 0) N(0x006D, "Aspect", 0, 0) N(0x006E, "3D Mode Select", 0, 0) - N(0x006F, "Display Brightness Increment", 0, 0) - N(0x0070, "Display Brightness Decrement", 0, 0) + Y(0x006F, "Display Brightness Increment", KS_Cmd_BrightnessUp, 0) + Y(0x0070, "Display Brightness Decrement", KS_Cmd_BrightnessDown, 0) N(0x0071, "Display Brightness", 0, 0) N(0x0072, "Display Backlight Toggle", 0, 0) N(0x0073, "Display Set Brightness to Minimum", 0, 0) diff --git a/sys/dev/i2c/files.i2c b/sys/dev/i2c/files.i2c index b2b3a89bc40..fd7d61da96f 100644 --- a/sys/dev/i2c/files.i2c +++ b/sys/dev/i2c/files.i2c @@ -1,4 +1,4 @@ -# $OpenBSD: files.i2c,v 1.70 2022/10/23 18:43:00 mglocker Exp $ +# $OpenBSD: files.i2c,v 1.71 2022/11/11 15:25:13 matthieu Exp $ # $NetBSD: files.i2c,v 1.3 2003/10/20 16:24:10 briggs Exp $ define i2c {[addr = -1], [size = -1]} @@ -268,3 +268,8 @@ file dev/i2c/tmp451.c titmp device pijuice attach pijuice at i2c file dev/i2c/pijuice.c pijuice + +# Consumer Control Keyboards +device icc: hid, hidcc, wskbddev +attach icc at ihidbus +file dev/i2c/icc.c icc diff --git a/sys/dev/i2c/icc.c b/sys/dev/i2c/icc.c new file mode 100644 index 00000000000..14dfc81cd83 --- /dev/null +++ b/sys/dev/i2c/icc.c @@ -0,0 +1,135 @@ +/* $OpenBSD: icc.c,v 1.1 2022/11/11 15:25:13 matthieu Exp $ */ + +/* + * Copyright (c) 2021 Anton Lindqvist + * Copyright (c) 2022 Matthieu Herrb + * + * 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 +#include +#include + +#include +#include + +#include +#include + +struct icc_softc { + struct ihidev sc_hdev; + struct hidcc *sc_cc; + int sc_keydown; +}; + +int icc_match(struct device *, void *, void *); +void icc_attach(struct device *, struct device *, void *); +int icc_detach(struct device *, int); +void icc_intr(struct ihidev *, void *, u_int); + +int icc_enable(void *, int); + +struct cfdriver icc_cd = { + NULL, "icc", DV_DULL +}; + +const struct cfattach icc_ca = { + sizeof(struct icc_softc), + icc_match, + icc_attach, +}; + +int +icc_match(struct device *parent, void *match, void *aux) +{ + struct ihidev_attach_arg *iha = aux; + void *desc; + int size; + + if (iha->reportid == IHIDEV_CLAIM_MULTIPLEID) + return IMATCH_NONE; + + ihidev_get_report_desc(iha->parent, &desc, &size); + if (hid_report_size(desc, size, hid_input, iha->reportid) == 0) + return IMATCH_NONE; + + if (!hidcc_match(desc, size, iha->reportid)) + return IMATCH_NONE; + return IMATCH_IFACECLASS; +} + +void +icc_attach(struct device *parent, struct device *self, void *aux) +{ + struct icc_softc *sc = (struct icc_softc *)self; + struct ihidev_attach_arg *iha = aux; + void *desc; + int repid, size; + + sc->sc_hdev.sc_intr = icc_intr; + sc->sc_hdev.sc_parent = iha->parent; + sc->sc_hdev.sc_report_id = iha->reportid; + + ihidev_get_report_desc(iha->parent, &desc, &size); + repid = iha->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); + + struct hidcc_attach_arg hca = { + .device = &sc->sc_hdev.sc_idev, + .audio_cookie = iha->iaa->ia_cookie, + .desc = desc, + .descsiz = size, + .repid = repid, + .isize = sc->sc_hdev.sc_isize, + .enable = icc_enable, + .arg = self, + }; + sc->sc_cc = hidcc_attach(&hca); +} + +int +icc_detach(struct device *self, int flags) +{ + struct icc_softc *sc = (struct icc_softc *)self; + int error = 0; + + ihidev_close(&sc->sc_hdev); + if (sc->sc_cc != NULL) + error = hidcc_detach(sc->sc_cc, flags); + return error; +} + +void +icc_intr(struct ihidev *addr, void *data, u_int len) +{ + struct icc_softc *sc = (struct icc_softc *)addr; + + if (sc->sc_cc != NULL) + hidcc_intr(sc->sc_cc, data, len); +} + +int +icc_enable(void *v, int on) +{ + struct icc_softc *sc = v; + int error = 0; + + if (on) + error = ihidev_open(&sc->sc_hdev); + else + ihidev_close(&sc->sc_hdev); + return error; +}