git: afd590d9e566 - main - hid: Import hidmap and bunch of drivers based on it
Vladimir Kondratyev
wulf at FreeBSD.org
Thu Jan 7 23:20:50 UTC 2021
The branch main has been updated by wulf:
URL: https://cgit.FreeBSD.org/src/commit/?id=afd590d9e56686e179cbbf626ec567aeaaa49199
commit afd590d9e56686e179cbbf626ec567aeaaa49199
Author: Vladimir Kondratyev <wulf at FreeBSD.org>
AuthorDate: 2020-10-14 22:02:15 +0000
Commit: Vladimir Kondratyev <wulf at FreeBSD.org>
CommitDate: 2021-01-07 23:18:44 +0000
hid: Import hidmap and bunch of drivers based on it
hidmap is a kernel module that maps HID input usages to evdev events.
Following dependent drivers is included in the commit:
hms - HID mouse driver.
hcons - Consumer page AKA Multimedia keys driver.
hsctrl - System Controls page (Power/Sleep keys) driver.
ps4dshock - Sony DualShock 4 gamepad driver.
Reviewed by: hselasky
Differential revision: https://reviews.freebsd.org/D27993
---
share/man/man4/Makefile | 4 +
share/man/man4/hcons.4 | 98 +++
share/man/man4/hms.4 | 115 +++
share/man/man4/hsctrl.4 | 98 +++
share/man/man4/ps4dshock.4 | 109 +++
sys/conf/files | 5 +
sys/dev/hid/hcons.c | 295 ++++++++
sys/dev/hid/hidmap.c | 832 +++++++++++++++++++++
sys/dev/hid/hidmap.h | 262 +++++++
sys/dev/hid/hms.c | 267 +++++++
sys/dev/hid/hsctrl.c | 110 +++
sys/dev/hid/ps4dshock.c | 1406 ++++++++++++++++++++++++++++++++++++
sys/modules/hid/Makefile | 7 +-
sys/modules/hid/hcons/Makefile | 9 +
sys/modules/hid/hidmap/Makefile | 9 +
sys/modules/hid/hms/Makefile | 9 +
sys/modules/hid/hsctrl/Makefile | 9 +
sys/modules/hid/ps4dshock/Makefile | 9 +
18 files changed, 3652 insertions(+), 1 deletion(-)
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 02d1bca75a3f..60c1b5f19a9b 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -180,11 +180,13 @@ MAN= aac.4 \
gre.4 \
h_ertt.4 \
hconf.4 \
+ hcons.4 \
hidbus.4 \
hidquirk.4 \
hidraw.4 \
hifn.4 \
hkbd.4 \
+ hms.4 \
hmt.4 \
hpet.4 \
${_hpt27xx.4} \
@@ -192,6 +194,7 @@ MAN= aac.4 \
${_hptmv.4} \
${_hptnr.4} \
${_hptrr.4} \
+ hsctrl.4 \
${_hv_kvp.4} \
${_hv_netvsc.4} \
${_hv_storvsc.4} \
@@ -432,6 +435,7 @@ MAN= aac.4 \
ppi.4 \
procdesc.4 \
proto.4 \
+ ps4dshock.4 \
psm.4 \
pst.4 \
pt.4 \
diff --git a/share/man/man4/hcons.4 b/share/man/man4/hcons.4
new file mode 100644
index 000000000000..a8fe22983453
--- /dev/null
+++ b/share/man/man4/hcons.4
@@ -0,0 +1,98 @@
+.\" Copyright (c) 2020 Vladimir Kondratyev <wulf at FreeBSD.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 14, 2020
+.Dt HCONS 4
+.Os
+.Sh NAME
+.Nm hcons
+.Nd HID consumer page controls driver
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device hcons"
+.Cd "device hid"
+.Cd "device hidbus"
+.Cd "device hidmap"
+.Cd "device evdev"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+hgame_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for HID consumer page controls most often used as
+"Multimedia keys" found on many keyboards.
+.Pp
+The
+.Pa /dev/input/event*
+device presents the consumer page controls as a
+.Ar evdev
+type device.
+.Sh SYSCTL VARIABLES
+The following variable is available as both
+.Xr sysctl 8
+variable and
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va dev.hcons.X.debug
+Debug output level, where 0 is debugging disabled and larger values increase
+debug message verbosity.
+Default is 0.
+.El
+.Pp
+It default value is set with
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va hw.hid.hcons.debug
+.El
+.Sh FILES
+.Bl -tag -width /dev/input/event* -compact
+.It Pa /dev/input/event*
+input event device node.
+.El
+.Sh SEE ALSO
+.Xr iichid 4 ,
+.Xr usbhid 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 13.0.
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Vladimir Kondratyev Aq Mt wulf at FreeBSD.org .
diff --git a/share/man/man4/hms.4 b/share/man/man4/hms.4
new file mode 100644
index 000000000000..eb413e943976
--- /dev/null
+++ b/share/man/man4/hms.4
@@ -0,0 +1,115 @@
+.\" Copyright (c)
+.\" 1999 Nick Hibma <n_hibma at FreeBSD.org>. All rights reserved.
+.\" 2020 Vladimir Kondratyev <wulf at FreeBSD.org>.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 12, 2020
+.Dt HMS 4
+.Os
+.Sh NAME
+.Nm hms
+.Nd HID mouse driver
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device hms"
+.Cd "device hidbus"
+.Cd "device hid"
+.Cd "device evdev"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+hms_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for HID mice that attach to the HID transport
+backend.
+See
+.Xr iichid 4
+or
+.Xr usbhid 4 .
+Supported are
+mice with any number of buttons, mice with a wheel and absolute mice.
+.Pp
+The
+.Pa /dev/input/eventX
+device presents the mouse as a
+.Ar evdev
+type device.
+.Sh SYSCTL VARIABLES
+The following variable is available as both
+.Xr sysctl 8
+variable and
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va dev.hms.X.debug
+Debug output level, where 0 is debugging disabled and larger values increase
+debug message verbosity.
+Default is 0.
+.El
+.Pp
+It default value is derived from
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va hw.hid.hms.debug
+.El
+.Sh FILES
+.Bl -tag -width /dev/input/eventX -compact
+.It Pa /dev/input/eventX
+input event device node.
+.El
+.Sh SEE ALSO
+.Xr iichid 4 ,
+.Xr usbhid 4 ,
+.Xr xorg.conf 5 Pq Pa ports/x11/xorg
+.\.Xr moused 8
+.Sh BUGS
+.Nm
+cannot act like
+.Xr sysmouse 4
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Vladimir Kondratyev Aq Mt wulf at FreeBSD.org .
+.Pp
+This manual page was originally written by
+.An Nick Hibma Aq Mt n_hibma at FreeBSD.org
+for
+.Xr umt 4
+driver and was adopted for
+.Nm
+by
+.An Vladimir Kondratyev Aq Mt wulf at FreeBSD.org .
diff --git a/share/man/man4/hsctrl.4 b/share/man/man4/hsctrl.4
new file mode 100644
index 000000000000..ba7976c3c03d
--- /dev/null
+++ b/share/man/man4/hsctrl.4
@@ -0,0 +1,98 @@
+.\" Copyright (c) 2020 Vladimir Kondratyev <wulf at FreeBSD.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 14, 2020
+.Dt HSCTRL 4
+.Os
+.Sh NAME
+.Nm hsctrl
+.Nd HID system controls driver
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device hsctrl"
+.Cd "device hid"
+.Cd "device hidbus"
+.Cd "device hidmap"
+.Cd "device evdev"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+hgame_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for HID system controls most often used as
+"Power off/Sleep keys" found on many keyboards.
+.Pp
+The
+.Pa /dev/input/event*
+device presents the consumer page controls as a
+.Ar evdev
+type device.
+.Sh SYSCTL VARIABLES
+The following variable is available as both
+.Xr sysctl 8
+variable and
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va dev.hsctrl.X.debug
+Debug output level, where 0 is debugging disabled and larger values increase
+debug message verbosity.
+Default is 0.
+.El
+.Pp
+It default value is set with
+.Xr loader 8
+tunable:
+.Bl -tag -width indent
+.It Va hw.hid.hsctrl.debug
+.El
+.Sh FILES
+.Bl -tag -width /dev/input/event* -compact
+.It Pa /dev/input/event*
+input event device node.
+.El
+.Sh SEE ALSO
+.Xr iichid 4 ,
+.Xr usbhid 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 13.0.
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Vladimir Kondratyev Aq Mt wulf at FreeBSD.org .
diff --git a/share/man/man4/ps4dshock.4 b/share/man/man4/ps4dshock.4
new file mode 100644
index 000000000000..e2295533989f
--- /dev/null
+++ b/share/man/man4/ps4dshock.4
@@ -0,0 +1,109 @@
+.\" Copyright (c) 2020 Vladimir Kondratyev <wulf at FreeBSD.org>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 19, 2020
+.Dt PS4DSHOCK 4
+.Os
+.Sh NAME
+.Nm ps4dshock
+.Nd Sony PlayStation 4 Dualshock 4 gamepad driver
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device ps4dshock"
+.Cd "device hid"
+.Cd "device hidbus"
+.Cd "device hidmap"
+.Cd "device evdev"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+ps4dshock_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for Sony PlayStation 4 Dualshock 4 gamepad driver.
+.Pp
+The
+.Pa /dev/input/event*
+device presents the game controller as a
+.Ar evdev
+type device.
+.Sh SYSCTL VARIABLES
+Next parameters are available as
+.Xr sysctl 8
+variables.
+Debug parameter is available as
+.Xr loader 8
+tunable as well.
+.Bl -tag -width indent
+.It Va dev.p4dshock.*.led_state
+LED state: 0 - off, 1 - on, 2 - blinking.
+.It Va dev.p4dshock.*.led_color_r
+LED color.
+Red component.
+.It Va dev.p4dshock.*.led_color_g
+LED color.
+Green component.
+.It Va dev.p4dshock.*.led_color_b
+LED color.
+Blue component.
+.It Va dev.p4dshock.*.led_delay_on
+LED blink.
+On delay, msecs.
+.It Va dev.p4dshock.*.led_delay_off
+LED blink.
+Off delay, msecs.
+.It Va hw.hid.ps4dshock.debug
+Debug output level, where 0 is debugging disabled and larger values increase
+debug message verbosity.
+Default is 0.
+.El
+.Sh FILES
+.Bl -tag -width /dev/input/event* -compact
+.It Pa /dev/input/event*
+input event device node.
+.El
+.Sh BUGS
+The
+.Nm
+does not support force-feedback events.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 13.0.
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Vladimir Kondratyev Aq Mt wulf at FreeBSD.org .
diff --git a/sys/conf/files b/sys/conf/files
index cea809deb039..31a06150a329 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1816,13 +1816,18 @@ dev/gpio/gpiobus_if.m optional gpio
dev/gpio/gpiopps.c optional gpiopps fdt
dev/gpio/ofw_gpiobus.c optional fdt gpio
dev/hid/hconf.c optional hconf
+dev/hid/hcons.c optional hcons
dev/hid/hid.c optional hid
dev/hid/hid_if.m optional hid
dev/hid/hidbus.c optional hidbus
+dev/hid/hidmap.c optional hidmap
dev/hid/hidquirk.c optional hid
dev/hid/hidraw.c optional hidraw
dev/hid/hkbd.c optional hkbd
+dev/hid/hms.c optional hms
dev/hid/hmt.c optional hmt hconf
+dev/hid/hsctrl.c optional hsctrl
+dev/hid/ps4dshock.c optional ps4dshock
dev/hifn/hifn7751.c optional hifn
dev/hptiop/hptiop.c optional hptiop scbus
dev/hwpmc/hwpmc_logging.c optional hwpmc
diff --git a/sys/dev/hid/hcons.c b/sys/dev/hid/hcons.c
new file mode 100644
index 000000000000..559e84d468f3
--- /dev/null
+++ b/sys/dev/hid/hcons.c
@@ -0,0 +1,295 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Vladimir Kondratyev <wulf at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Consumer Controls usage page driver
+ * https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
+ */
+
+#include <sys/param.h>
+#include <sys/bitstring.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+
+#include <dev/evdev/input.h>
+#include <dev/evdev/evdev.h>
+
+#include <dev/hid/hid.h>
+#include <dev/hid/hidbus.h>
+#include <dev/hid/hidmap.h>
+
+static hidmap_cb_t hcons_rel_volume_cb;
+
+#define HCONS_MAP_KEY(usage, code) \
+ { HIDMAP_KEY(HUP_CONSUMER, usage, code) }
+#define HCONS_MAP_ABS(usage, code) \
+ { HIDMAP_ABS(HUP_CONSUMER, usage, code) }
+#define HCONS_MAP_REL(usage, code) \
+ { HIDMAP_REL(HUP_CONSUMER, usage, code) }
+#define HCONS_MAP_REL_CB(usage, callback) \
+ { HIDMAP_REL_CB(HUP_CONSUMER, usage, &callback) }
+
+static const struct hidmap_item hcons_map[] = {
+ HCONS_MAP_KEY(0x030, KEY_POWER),
+ HCONS_MAP_KEY(0x031, KEY_RESTART),
+ HCONS_MAP_KEY(0x032, KEY_SLEEP),
+ HCONS_MAP_KEY(0x034, KEY_SLEEP),
+ HCONS_MAP_KEY(0x035, KEY_KBDILLUMTOGGLE),
+ HCONS_MAP_KEY(0x036, BTN_MISC),
+ HCONS_MAP_KEY(0x040, KEY_MENU), /* Menu */
+ HCONS_MAP_KEY(0x041, KEY_SELECT), /* Menu Pick */
+ HCONS_MAP_KEY(0x042, KEY_UP), /* Menu Up */
+ HCONS_MAP_KEY(0x043, KEY_DOWN), /* Menu Down */
+ HCONS_MAP_KEY(0x044, KEY_LEFT), /* Menu Left */
+ HCONS_MAP_KEY(0x045, KEY_RIGHT), /* Menu Right */
+ HCONS_MAP_KEY(0x046, KEY_ESC), /* Menu Escape */
+ HCONS_MAP_KEY(0x047, KEY_KPPLUS), /* Menu Value Increase */
+ HCONS_MAP_KEY(0x048, KEY_KPMINUS), /* Menu Value Decrease */
+ HCONS_MAP_KEY(0x060, KEY_INFO), /* Data On Screen */
+ HCONS_MAP_KEY(0x061, KEY_SUBTITLE), /* Closed Caption */
+ HCONS_MAP_KEY(0x063, KEY_VCR), /* VCR/TV */
+ HCONS_MAP_KEY(0x065, KEY_CAMERA), /* Snapshot */
+ HCONS_MAP_KEY(0x069, KEY_RED),
+ HCONS_MAP_KEY(0x06a, KEY_GREEN),
+ HCONS_MAP_KEY(0x06b, KEY_BLUE),
+ HCONS_MAP_KEY(0x06c, KEY_YELLOW),
+ HCONS_MAP_KEY(0x06d, KEY_ASPECT_RATIO),
+ HCONS_MAP_KEY(0x06f, KEY_BRIGHTNESSUP),
+ HCONS_MAP_KEY(0x070, KEY_BRIGHTNESSDOWN),
+ HCONS_MAP_KEY(0x072, KEY_BRIGHTNESS_TOGGLE),
+ HCONS_MAP_KEY(0x073, KEY_BRIGHTNESS_MIN),
+ HCONS_MAP_KEY(0x074, KEY_BRIGHTNESS_MAX),
+ HCONS_MAP_KEY(0x075, KEY_BRIGHTNESS_AUTO),
+ HCONS_MAP_KEY(0x079, KEY_KBDILLUMUP),
+ HCONS_MAP_KEY(0x07a, KEY_KBDILLUMDOWN),
+ HCONS_MAP_KEY(0x07c, KEY_KBDILLUMTOGGLE),
+ HCONS_MAP_KEY(0x082, KEY_VIDEO_NEXT),
+ HCONS_MAP_KEY(0x083, KEY_LAST),
+ HCONS_MAP_KEY(0x084, KEY_ENTER),
+ HCONS_MAP_KEY(0x088, KEY_PC),
+ HCONS_MAP_KEY(0x089, KEY_TV),
+ HCONS_MAP_KEY(0x08a, KEY_WWW),
+ HCONS_MAP_KEY(0x08b, KEY_DVD),
+ HCONS_MAP_KEY(0x08c, KEY_PHONE),
+ HCONS_MAP_KEY(0x08d, KEY_PROGRAM),
+ HCONS_MAP_KEY(0x08e, KEY_VIDEOPHONE),
+ HCONS_MAP_KEY(0x08f, KEY_GAMES),
+ HCONS_MAP_KEY(0x090, KEY_MEMO),
+ HCONS_MAP_KEY(0x091, KEY_CD),
+ HCONS_MAP_KEY(0x092, KEY_VCR),
+ HCONS_MAP_KEY(0x093, KEY_TUNER),
+ HCONS_MAP_KEY(0x094, KEY_EXIT),
+ HCONS_MAP_KEY(0x095, KEY_HELP),
+ HCONS_MAP_KEY(0x096, KEY_TAPE),
+ HCONS_MAP_KEY(0x097, KEY_TV2),
+ HCONS_MAP_KEY(0x098, KEY_SAT),
+ HCONS_MAP_KEY(0x09a, KEY_PVR),
+ HCONS_MAP_KEY(0x09c, KEY_CHANNELUP),
+ HCONS_MAP_KEY(0x09d, KEY_CHANNELDOWN),
+ HCONS_MAP_KEY(0x0a0, KEY_VCR2),
+ HCONS_MAP_KEY(0x0b0, KEY_PLAY),
+ HCONS_MAP_KEY(0x0b1, KEY_PAUSE),
+ HCONS_MAP_KEY(0x0b2, KEY_RECORD),
+ HCONS_MAP_KEY(0x0b3, KEY_FASTFORWARD),
+ HCONS_MAP_KEY(0x0b4, KEY_REWIND),
+ HCONS_MAP_KEY(0x0b5, KEY_NEXTSONG),
+ HCONS_MAP_KEY(0x0b6, KEY_PREVIOUSSONG),
+ HCONS_MAP_KEY(0x0b7, KEY_STOPCD),
+ HCONS_MAP_KEY(0x0b8, KEY_EJECTCD),
+ HCONS_MAP_KEY(0x0bc, KEY_MEDIA_REPEAT),
+ HCONS_MAP_KEY(0x0b9, KEY_SHUFFLE),
+ HCONS_MAP_KEY(0x0bf, KEY_SLOW),
+ HCONS_MAP_KEY(0x0cd, KEY_PLAYPAUSE),
+ HCONS_MAP_KEY(0x0cf, KEY_VOICECOMMAND),
+ HCONS_MAP_ABS(0x0e0, ABS_VOLUME),
+ HCONS_MAP_REL_CB(0x0e0, hcons_rel_volume_cb),
+ HCONS_MAP_KEY(0x0e2, KEY_MUTE),
+ HCONS_MAP_KEY(0x0e5, KEY_BASSBOOST),
+ HCONS_MAP_KEY(0x0e9, KEY_VOLUMEUP),
+ HCONS_MAP_KEY(0x0ea, KEY_VOLUMEDOWN),
+ HCONS_MAP_KEY(0x0f5, KEY_SLOW),
+ HCONS_MAP_KEY(0x181, KEY_BUTTONCONFIG),
+ HCONS_MAP_KEY(0x182, KEY_BOOKMARKS),
+ HCONS_MAP_KEY(0x183, KEY_CONFIG),
+ HCONS_MAP_KEY(0x184, KEY_WORDPROCESSOR),
+ HCONS_MAP_KEY(0x185, KEY_EDITOR),
+ HCONS_MAP_KEY(0x186, KEY_SPREADSHEET),
+ HCONS_MAP_KEY(0x187, KEY_GRAPHICSEDITOR),
+ HCONS_MAP_KEY(0x188, KEY_PRESENTATION),
+ HCONS_MAP_KEY(0x189, KEY_DATABASE),
+ HCONS_MAP_KEY(0x18a, KEY_MAIL),
+ HCONS_MAP_KEY(0x18b, KEY_NEWS),
+ HCONS_MAP_KEY(0x18c, KEY_VOICEMAIL),
+ HCONS_MAP_KEY(0x18d, KEY_ADDRESSBOOK),
+ HCONS_MAP_KEY(0x18e, KEY_CALENDAR),
+ HCONS_MAP_KEY(0x18f, KEY_TASKMANAGER),
+ HCONS_MAP_KEY(0x190, KEY_JOURNAL),
+ HCONS_MAP_KEY(0x191, KEY_FINANCE),
+ HCONS_MAP_KEY(0x192, KEY_CALC),
+ HCONS_MAP_KEY(0x193, KEY_PLAYER),
+ HCONS_MAP_KEY(0x194, KEY_FILE),
+ HCONS_MAP_KEY(0x196, KEY_WWW),
+ HCONS_MAP_KEY(0x199, KEY_CHAT),
+ HCONS_MAP_KEY(0x19c, KEY_LOGOFF),
+ HCONS_MAP_KEY(0x19e, KEY_COFFEE),
+ HCONS_MAP_KEY(0x19f, KEY_CONTROLPANEL),
+ HCONS_MAP_KEY(0x1a2, KEY_APPSELECT),
+ HCONS_MAP_KEY(0x1a3, KEY_NEXT),
+ HCONS_MAP_KEY(0x1a4, KEY_PREVIOUS),
+ HCONS_MAP_KEY(0x1a6, KEY_HELP),
+ HCONS_MAP_KEY(0x1a7, KEY_DOCUMENTS),
+ HCONS_MAP_KEY(0x1ab, KEY_SPELLCHECK),
+ HCONS_MAP_KEY(0x1ae, KEY_KEYBOARD),
+ HCONS_MAP_KEY(0x1b1, KEY_SCREENSAVER),
+ HCONS_MAP_KEY(0x1b4, KEY_FILE),
+ HCONS_MAP_KEY(0x1b6, KEY_IMAGES),
+ HCONS_MAP_KEY(0x1b7, KEY_AUDIO),
+ HCONS_MAP_KEY(0x1b8, KEY_VIDEO),
+ HCONS_MAP_KEY(0x1bc, KEY_MESSENGER),
+ HCONS_MAP_KEY(0x1bd, KEY_INFO),
+ HCONS_MAP_KEY(0x1cb, KEY_ASSISTANT),
+ HCONS_MAP_KEY(0x201, KEY_NEW),
+ HCONS_MAP_KEY(0x202, KEY_OPEN),
+ HCONS_MAP_KEY(0x203, KEY_CLOSE),
+ HCONS_MAP_KEY(0x204, KEY_EXIT),
+ HCONS_MAP_KEY(0x207, KEY_SAVE),
+ HCONS_MAP_KEY(0x208, KEY_PRINT),
+ HCONS_MAP_KEY(0x209, KEY_PROPS),
+ HCONS_MAP_KEY(0x21a, KEY_UNDO),
+ HCONS_MAP_KEY(0x21b, KEY_COPY),
+ HCONS_MAP_KEY(0x21c, KEY_CUT),
+ HCONS_MAP_KEY(0x21d, KEY_PASTE),
+ HCONS_MAP_KEY(0x21f, KEY_FIND),
+ HCONS_MAP_KEY(0x221, KEY_SEARCH),
+ HCONS_MAP_KEY(0x222, KEY_GOTO),
+ HCONS_MAP_KEY(0x223, KEY_HOMEPAGE),
+ HCONS_MAP_KEY(0x224, KEY_BACK),
+ HCONS_MAP_KEY(0x225, KEY_FORWARD),
+ HCONS_MAP_KEY(0x226, KEY_STOP),
+ HCONS_MAP_KEY(0x227, KEY_REFRESH),
+ HCONS_MAP_KEY(0x22a, KEY_BOOKMARKS),
+ HCONS_MAP_KEY(0x22d, KEY_ZOOMIN),
+ HCONS_MAP_KEY(0x22e, KEY_ZOOMOUT),
+ HCONS_MAP_KEY(0x22f, KEY_ZOOMRESET),
+ HCONS_MAP_KEY(0x232, KEY_FULL_SCREEN),
+ HCONS_MAP_KEY(0x233, KEY_SCROLLUP),
+ HCONS_MAP_KEY(0x234, KEY_SCROLLDOWN),
+ HCONS_MAP_REL(0x238, REL_HWHEEL), /* AC Pan */
+ HCONS_MAP_KEY(0x23d, KEY_EDIT),
+ HCONS_MAP_KEY(0x25f, KEY_CANCEL),
+ HCONS_MAP_KEY(0x269, KEY_INSERT),
+ HCONS_MAP_KEY(0x26a, KEY_DELETE),
+ HCONS_MAP_KEY(0x279, KEY_REDO),
+ HCONS_MAP_KEY(0x289, KEY_REPLY),
+ HCONS_MAP_KEY(0x28b, KEY_FORWARDMAIL),
+ HCONS_MAP_KEY(0x28c, KEY_SEND),
+ HCONS_MAP_KEY(0x29d, KEY_KBD_LAYOUT_NEXT),
+ HCONS_MAP_KEY(0x2c7, KEY_KBDINPUTASSIST_PREV),
+ HCONS_MAP_KEY(0x2c8, KEY_KBDINPUTASSIST_NEXT),
+ HCONS_MAP_KEY(0x2c9, KEY_KBDINPUTASSIST_PREVGROUP),
+ HCONS_MAP_KEY(0x2ca, KEY_KBDINPUTASSIST_NEXTGROUP),
+ HCONS_MAP_KEY(0x2cb, KEY_KBDINPUTASSIST_ACCEPT),
+ HCONS_MAP_KEY(0x2cc, KEY_KBDINPUTASSIST_CANCEL),
+ HCONS_MAP_KEY(0x29f, KEY_SCALE),
+};
+
+static const struct hid_device_id hcons_devs[] = {
+ { HID_TLC(HUP_CONSUMER, HUC_CONTROL) },
+};
+
+/*
+ * Emulate relative Consumer volume usage with pressing
+ * VOLUMEUP and VOLUMEDOWN keys appropriate number of times
+ */
+static int
+hcons_rel_volume_cb(HIDMAP_CB_ARGS)
+{
+ struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV();
+ int32_t code;
+ int nrepeats;
+
+ switch (HIDMAP_CB_GET_STATE()) {
+ case HIDMAP_CB_IS_ATTACHING:
+ evdev_support_event(evdev, EV_KEY);
+ evdev_support_key(evdev, KEY_VOLUMEUP);
+ evdev_support_key(evdev, KEY_VOLUMEDOWN);
+ break;
+ case HIDMAP_CB_IS_RUNNING:
+ /* Nothing to report. */
+ if (ctx.data == 0)
+ return (ENOMSG);
+ code = ctx.data > 0 ? KEY_VOLUMEUP : KEY_VOLUMEDOWN;
+ for (nrepeats = abs(ctx.data); nrepeats > 0; nrepeats--) {
+ evdev_push_key(evdev, code, 1);
+ evdev_push_key(evdev, code, 0);
+ }
+ }
+
+ return (0);
+}
+
+static int
+hcons_probe(device_t dev)
+{
+ return (HIDMAP_PROBE(device_get_softc(dev), dev,
+ hcons_devs, hcons_map, "Consumer Control"));
+}
+
+static int
+hcons_attach(device_t dev)
+{
+ return (hidmap_attach(device_get_softc(dev)));
+}
+
+static int
+hcons_detach(device_t dev)
+{
+ return (hidmap_detach(device_get_softc(dev)));
+}
+
+static devclass_t hcons_devclass;
+static device_method_t hcons_methods[] = {
+ DEVMETHOD(device_probe, hcons_probe),
+ DEVMETHOD(device_attach, hcons_attach),
+ DEVMETHOD(device_detach, hcons_detach),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(hcons, hcons_driver, hcons_methods, sizeof(struct hidmap));
+DRIVER_MODULE(hcons, hidbus, hcons_driver, hcons_devclass, NULL, 0);
+MODULE_DEPEND(hcons, hid, 1, 1, 1);
+MODULE_DEPEND(hcons, hidbus, 1, 1, 1);
+MODULE_DEPEND(hcons, hidmap, 1, 1, 1);
+MODULE_DEPEND(hcons, evdev, 1, 1, 1);
+MODULE_VERSION(hcons, 1);
+HID_PNP_INFO(hcons_devs);
diff --git a/sys/dev/hid/hidmap.c b/sys/dev/hid/hidmap.c
new file mode 100644
index 000000000000..163d63c20232
--- /dev/null
+++ b/sys/dev/hid/hidmap.c
@@ -0,0 +1,832 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2020 Vladimir Kondratyev <wulf at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Abstract 1 to 1 HID input usage to evdev event mapper driver.
+ */
+
+#include "opt_hid.h"
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+
+#include <dev/evdev/input.h>
+#include <dev/evdev/evdev.h>
+
+#include <dev/hid/hid.h>
+#include <dev/hid/hidbus.h>
+#include <dev/hid/hidmap.h>
+
+#ifdef HID_DEBUG
+#define DPRINTFN(hm, n, fmt, ...) do { \
+ if ((hm)->debug_var != NULL && *(hm)->debug_var >= (n)) { \
+ device_printf((hm)->dev, "%s: " fmt, \
+ __FUNCTION__ ,##__VA_ARGS__); \
+ } \
+} while (0)
+#define DPRINTF(hm, ...) DPRINTFN(hm, 1, __VA_ARGS__)
+#else
+#define DPRINTF(...) do { } while (0)
+#define DPRINTFN(...) do { } while (0)
+#endif
+
+static evdev_open_t hidmap_ev_open;
+static evdev_close_t hidmap_ev_close;
+
+#define HIDMAP_WANT_MERGE_KEYS(hm) ((hm)->key_rel != NULL)
+
+#define HIDMAP_FOREACH_ITEM(hm, mi, uoff) \
+ for (u_int _map = 0, _item = 0, _uoff_priv = -1; \
+ ((mi) = hidmap_get_next_map_item( \
+ (hm), &_map, &_item, &_uoff_priv, &(uoff))) != NULL;)
+
+static inline bool
+hidmap_get_next_map_index(const struct hidmap_item *map, int nmap_items,
+ uint32_t *index, uint16_t *usage_offset)
+{
+
+ ++*usage_offset;
+ if ((*index != 0 || *usage_offset != 0) &&
+ *usage_offset >= map[*index].nusages) {
+ ++*index;
+ *usage_offset = 0;
+ }
+
+ return (*index < nmap_items);
+}
+
+static inline const struct hidmap_item *
+hidmap_get_next_map_item(struct hidmap *hm, u_int *map, u_int *item,
+ u_int *uoff_priv, uint16_t *uoff)
+{
+
+ *uoff = *uoff_priv;
+ while (!hidmap_get_next_map_index(
+ hm->map[*map], hm->nmap_items[*map], item, uoff)) {
+ ++*map;
+ *item = 0;
+ *uoff = -1;
+ if (*map >= hm->nmaps)
+ return (NULL);
+ }
+ *uoff_priv = *uoff;
+
+ return (hm->map[*map] + *item);
+}
+
+void
+_hidmap_set_debug_var(struct hidmap *hm, int *debug_var)
+{
+#ifdef HID_DEBUG
+ hm->debug_var = debug_var;
+#endif
+}
+
+static int
+hidmap_ev_close(struct evdev_dev *evdev)
+{
+ return (hidbus_intr_stop(evdev_get_softc(evdev)));
+}
+
+static int
+hidmap_ev_open(struct evdev_dev *evdev)
+{
+ return (hidbus_intr_start(evdev_get_softc(evdev)));
+}
+
+void
+hidmap_support_key(struct hidmap *hm, uint16_t key)
+{
+ if (hm->key_press == NULL) {
+ hm->key_press = malloc(howmany(KEY_CNT, 8), M_DEVBUF,
+ M_ZERO | M_WAITOK);
*** 2864 LINES SKIPPED ***
More information about the dev-commits-src-all
mailing list