Page MenuHomeFreeBSD

D57838.id180587.diff
No OneTemporary

D57838.id180587.diff

diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -219,6 +219,7 @@
${_hptmv.4} \
${_hptnr.4} \
${_hptrr.4} \
+ hradio.4 \
hsctrl.4 \
htu21.4 \
${_hv_kvp.4} \
diff --git a/share/man/man4/hradio.4 b/share/man/man4/hradio.4
new file mode 100644
--- /dev/null
+++ b/share/man/man4/hradio.4
@@ -0,0 +1,78 @@
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Copyright (c) 2026 The FreeBSD Foundation
+.\"
+.\" Portions of this software were developed by Aymeric Wibo
+.\" <obiwac@freebsd.org> under sponsorship from the FreeBSD Foundation.
+.\"
+.Dd June 24, 2026
+.Dt HRADIO 4
+.Os
+.Sh NAME
+.Nm hradio
+.Nd HID radio control 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 hradio"
+.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
+hradio_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for HID wireless radio control buttons,
+most often found as an
+.Qq airplane mode
+or RFKILL toggle on laptop keyboards.
+.Pp
+Currently,
+.Nm
+only handles radio button reporting.
+The HID Generic Desktop radio control page also defines radio switches and
+status LEDs; support for these should be added in a future revision of the
+driver.
+.Sh FILES
+.Bl -tag -width /dev/input/event* -compact
+.It Pa /dev/input/event*
+input event device node.
+.El
+.Sh SEE ALSO
+.Xr hsctrl 4 .
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 16.0 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Aymeric Wibo Aq Mt obiwac@freebsd.org
+under sponsorship from the FreeBSD Foundation and by
+.An Daniel Shaefer Aq Mt git@danielschaefer.me
+under sponsorship from Framework Computer Inc.
+.Sh CAVEATS
+.Fx
+does not yet have a generic RFKILL framework analogous to the one found in
+Linux.
+As a result,
+.Nm
+can only report radio button events to userspace via
+.Ar evdev ;
+the kernel itself has no mechanism to act on these events to block or unblock
+wireless devices.
+A future RFKILL framework would allow the driver to integrate directly with
+network interfaces and block transmitters in response to hardware events.
diff --git a/sys/conf/NOTES b/sys/conf/NOTES
--- a/sys/conf/NOTES
+++ b/sys/conf/NOTES
@@ -2435,6 +2435,7 @@
device hms # HID mouse
device hmt # HID multitouch (MS-compatible)
device hpen # Generic pen driver
+device hradio # RFKILL driver
device hsctrl # System controls
device ps4dshock # Sony PS4 DualShock 4 gamepad driver
device u2f # FIDO/U2F authenticator
diff --git a/sys/conf/files b/sys/conf/files
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1797,6 +1797,7 @@
dev/hid/hms.c optional hms
dev/hid/hmt.c optional hmt hconf
dev/hid/hpen.c optional hpen
+dev/hid/hradio.c optional hradio
dev/hid/hsctrl.c optional hsctrl
dev/hid/ietp.c optional ietp
dev/hid/ps4dshock.c optional ps4dshock
diff --git a/sys/dev/hid/hradio.c b/sys/dev/hid/hradio.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/hid/hradio.c
@@ -0,0 +1,111 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 The FreeBSD Foundation
+ * Copyright (c) 2026 Framework Computer Inc
+ *
+ * This software was developed by Aymeric Wibo <obiwac@freebsd.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Portions of this software were developed by Daniel Schaefer
+ * <git@danielschaefer.me> under sponsorship from Framework Computer Inc.
+ */
+
+#include "opt_hid.h"
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <dev/evdev/evdev.h>
+#include <dev/evdev/input.h>
+
+#include <dev/hid/hid.h>
+#include <dev/hid/hidbus.h>
+#include <dev/hid/hidmap.h>
+
+/*
+ * Reference document:
+ * https://www.usb.org/sites/default/files/hutrr40radiohidusagesfinal_0.pdf
+ */
+
+static hidmap_cb_t hradio_cb;
+
+static const struct hidmap_item hradio_map[] = {
+ { HIDMAP_REL_CB(HUP_GENERIC_DESKTOP, HUG_RADIO_BUTTON, &hradio_cb) },
+};
+
+static const struct hid_device_id hradio_devs[] = {
+ { HID_TLC(HUP_GENERIC_DESKTOP, HUG_RADIO_CONTROL) },
+};
+
+/*
+ * Synthesize key-down + key-up for the wireless radio button,
+ * which only reports a relative pulse (value=1) on press.
+ * The firmware latches value=1 and never resets it, so we
+ * track the last value via HIDMAP_CB_UDATA64 and only fire
+ * on the 0 -> non-zero transition.
+ */
+static int
+hradio_cb(HIDMAP_CB_ARGS)
+{
+ struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV();
+ int32_t last;
+
+ switch (HIDMAP_CB_GET_STATE()) {
+ case HIDMAP_CB_IS_ATTACHING:
+ evdev_support_event(evdev, EV_KEY);
+ evdev_support_key(evdev, KEY_RFKILL);
+ HIDMAP_CB_UDATA64 = 0;
+ break;
+ case HIDMAP_CB_IS_RUNNING:
+ last = (int32_t)HIDMAP_CB_UDATA64;
+ HIDMAP_CB_UDATA64 = (uint64_t)ctx.data;
+ if (ctx.data == 0 || ctx.data == last)
+ return (ENOMSG);
+ evdev_push_key(evdev, KEY_RFKILL, 1);
+ evdev_push_key(evdev, KEY_RFKILL, 0);
+ break;
+ default:
+ break;
+ }
+
+ return (0);
+}
+
+static int
+hradio_probe(device_t dev)
+{
+ return (HIDMAP_PROBE(device_get_softc(dev), dev,
+ hradio_devs, hradio_map, "RFKILL Switch"));
+}
+
+static int
+hradio_attach(device_t dev)
+{
+ return (hidmap_attach(device_get_softc(dev)));
+}
+
+static int
+hradio_detach(device_t dev)
+{
+ return (hidmap_detach(device_get_softc(dev)));
+}
+
+static device_method_t hradio_methods[] = {
+ DEVMETHOD(device_probe, hradio_probe),
+ DEVMETHOD(device_attach, hradio_attach),
+ DEVMETHOD(device_detach, hradio_detach),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(hradio, hradio_driver, hradio_methods, sizeof(struct hidmap));
+DRIVER_MODULE(hradio, hidbus, hradio_driver, NULL, NULL);
+MODULE_DEPEND(hradio, hid, 1, 1, 1);
+MODULE_DEPEND(hradio, hidbus, 1, 1, 1);
+MODULE_DEPEND(hradio, hidmap, 1, 1, 1);
+MODULE_DEPEND(hradio, evdev, 1, 1, 1);
+MODULE_VERSION(hradio, 1);
+HID_PNP_INFO(hradio_devs);
diff --git a/sys/modules/hid/Makefile b/sys/modules/hid/Makefile
--- a/sys/modules/hid/Makefile
+++ b/sys/modules/hid/Makefile
@@ -15,6 +15,7 @@
hms \
hmt \
hpen \
+ hradio \
hsctrl \
ietp \
ps4dshock \
diff --git a/sys/modules/hid/hradio/Makefile b/sys/modules/hid/hradio/Makefile
new file mode 100644
--- /dev/null
+++ b/sys/modules/hid/hradio/Makefile
@@ -0,0 +1,8 @@
+.PATH: ${SRCTOP}/sys/dev/hid
+
+KMOD= hradio
+SRCS= hradio.c
+SRCS+= opt_kbd.h
+SRCS+= bus_if.h device_if.h
+
+.include <bsd.kmod.mk>

File Metadata

Mime Type
text/plain
Expires
Sat, Sep 12, 1:21 AM (9 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38749733
Default Alt Text
D57838.id180587.diff (6 KB)

Event Timeline