mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rahul Rameshbabu <sergeantsagara@protonmail.com>
To: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-input@vger.kernel.org, dri-devel@lists.freedesktop.org
Cc: "Jiri Kosina" <jikos@kernel.org>,
	"Benjamin Tissoires" <bentiss@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Rahul Rameshbabu" <sergeantsagara@protonmail.com>,
	"Julius Zint" <julius@zint.sh>
Subject: [PATCH RFC 2/3] rust: hid: USB Monitor Control Class driver
Date: Thu, 13 Mar 2025 16:03:51 +0000	[thread overview]
Message-ID: <20250313160220.6410-5-sergeantsagara@protonmail.com> (raw)
In-Reply-To: <20250313160220.6410-2-sergeantsagara@protonmail.com>

This code will eventually contain the logic needed to drive the backlight
of displays that implement the USB Monitor Control Class specification.
Examples include the Apple Studio Display and Apple Pro Display XDR
monitors. USB Monitor Control Class encompasses more than just backlight
control, so the driver could be further extended as monitors support more
functionality in the specification.

This code is a skeleton currently, where the focus right now is on the core
Rust API. The driver skeleton was written before approaching the Rust API
and C binding work. This was done to provide a guide for what the Rust API
should look like and avoid any rough C binding work from being exposed to
Rust HID device drivers.

To go forward with this driver for the purpose of external monitor
backlight control, a new DRM backlight API that is scoped per connector
will be required. I am currently in the process of developing this new API.
I document the details in my related blog posts. The issue with the current
backlight API is it was designed on the assumption that only internal
panels have controllable backlights. Using this assumption combined with
another that there can only ever be a single internal panel, having more
than one device register with the backlight interface would confuse
userspace applications.

Julius Zint originally tried to implement such a driver a bit more than a
year ago with a C driver but was blocked by the limitations of the
backlight API. I asked him for permission to continue the work in Rust
while accrediting him for the HID report parsing logic for the backlight
support in the USB Monitor Control Class specification.

Cc: Julius Zint <julius@zint.sh>
Link: https://lore.kernel.org/lkml/20230820094118.20521-1-julius@zint.sh/
Link: https://binary-eater.github.io/posts/linux_usb_monitor_control/
Link: https://www.usb.org/sites/default/files/usbmon11.pdf
Signed-off-by: Rahul Rameshbabu <sergeantsagara@protonmail.com>
---
 drivers/hid/Kconfig                |  8 +++++++
 drivers/hid/Makefile               |  1 +
 drivers/hid/hid_monitor_control.rs | 37 ++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
 create mode 100644 drivers/hid/hid_monitor_control.rs

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index e085964c7ffc..92be13acb956 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -722,6 +722,14 @@ config RUST_HID_ABSTRACTIONS
 	Adds support needed for HID drivers written in Rust. It provides a
 	wrapper around the C hid core.
 
+config HID_MONITOR_CONTROL
+	tristate "USB Monitor Control Class support"
+	depends on USB_HID
+	depends on RUST_HID_ABSTRACTIONS
+	help
+	Say Y here if you want to enable control over a monitor that uses USB
+	Monitor Control Class.
+
 config HID_REDRAGON
 	tristate "Redragon keyboards"
 	default !EXPERT
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 482b096eea28..bf8b096bcf23 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -86,6 +86,7 @@ obj-$(CONFIG_HID_MCP2221)	+= hid-mcp2221.o
 obj-$(CONFIG_HID_MAYFLASH)	+= hid-mf.o
 obj-$(CONFIG_HID_MEGAWORLD_FF)	+= hid-megaworld.o
 obj-$(CONFIG_HID_MICROSOFT)	+= hid-microsoft.o
+obj-$(CONFIG_HID_MONITOR_CONTROL)	+= hid_monitor_control.o
 obj-$(CONFIG_HID_MONTEREY)	+= hid-monterey.o
 obj-$(CONFIG_HID_MULTITOUCH)	+= hid-multitouch.o
 obj-$(CONFIG_HID_NINTENDO)	+= hid-nintendo.o
diff --git a/drivers/hid/hid_monitor_control.rs b/drivers/hid/hid_monitor_control.rs
new file mode 100644
index 000000000000..18afd69a56d5
--- /dev/null
+++ b/drivers/hid/hid_monitor_control.rs
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+
+// Copyright (C) 2025 Rahul Rameshbabu <sergeantsagara@protonmail.com>
+
+use kernel::prelude::*;
+use kernel::hid::{
+    self,
+    Driver,
+};
+
+struct HidMonitorControl;
+
+#[vtable]
+impl Driver for HidMonitorControl {
+    fn probe(dev: &mut hid::Device, id: &hid::DeviceId) -> Result<()> {
+        /* TODO implement */
+        Ok(())
+    }
+
+    fn remove(dev: &mut hid::Device) {
+        /* TODO implement */
+    }
+}
+
+kernel::module_hid_driver! {
+    driver: HidMonitorControl,
+    id_table: [
+        kernel::usb_device! {
+            vendor: /* TODO fill in */,
+            product: /* TODO fill in */,
+        },
+    ],
+    name: "monitor_control",
+    author: "Rahul Rameshbabu <sergeantsagara@protonmail.com>",
+    description: "Driver for the USB Monitor Control Class",
+    license: "GPL",
+}
-- 
2.47.2



  parent reply	other threads:[~2025-03-13 16:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 16:02 [PATCH RFC 0/3] Initial work for Rust abstraction for HID device driver development Rahul Rameshbabu
2025-03-13 16:03 ` [PATCH RFC 1/3] rust: core abstractions for HID drivers Rahul Rameshbabu
2025-03-13 16:54   ` Benjamin Tissoires
2025-03-13 19:25   ` Danilo Krummrich
2025-03-16  2:07     ` Rahul Rameshbabu
2025-03-13 16:03 ` Rahul Rameshbabu [this message]
2025-03-13 16:58   ` [PATCH RFC 2/3] rust: hid: USB Monitor Control Class driver Benjamin Tissoires
2025-03-14 14:41     ` Miguel Ojeda
2025-03-16  2:20       ` Rahul Rameshbabu
2025-03-13 16:04 ` [PATCH RFC 3/3] rust: hid: demo the core abstractions for probe and remove Rahul Rameshbabu
2025-03-13 17:05   ` Benjamin Tissoires
2025-03-16  4:20     ` Rahul Rameshbabu
2025-03-16 10:02       ` Daniel Brooks
2025-03-13 16:31 ` [PATCH RFC 0/3] Initial work for Rust abstraction for HID device driver development Benjamin Tissoires
2025-03-15 23:07   ` Rahul Rameshbabu
2025-03-13 18:04 ` Benno Lossin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313160220.6410-5-sergeantsagara@protonmail.com \
    --to=sergeantsagara@protonmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bentiss@kernel.org \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=jikos@kernel.org \
    --cc=julius@zint.sh \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®