--- /dev/null
+.\" $OpenBSD: icc.4,v 1.1 2022/11/11 15:25:13 matthieu Exp $
+.\"
+.\" Copyright (c) 2021 Anton Lindqvist <anton@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: 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 .
-/* $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 <anton@openbsd.org>
#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;
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)
--- /dev/null
+/* $OpenBSD: icc.c,v 1.1 2022/11/11 15:25:13 matthieu Exp $ */
+
+/*
+ * Copyright (c) 2021 Anton Lindqvist <anton@openbsd.org>
+ * Copyright (c) 2022 Matthieu Herrb <matthieu@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 <sys/device.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/ihidev.h>
+
+#include <dev/hid/hid.h>
+#include <dev/hid/hidccvar.h>
+
+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;
+}