[PATCH RFC 3/3] rust: hid: demo the core abstractions for probe and remove

From: Rahul Rameshbabu
Date: Thu Mar 13 2025 - 12:16:16 EST


This is a very basic "hello, world!" implementation to illustrate that the
probe and remove callbacks are working as expected. I chose an arbitrary
device I had on hand for populating in the HID device id table.

[ +0.012968] monitor_control: Probing HID device vendor: 2389 product: 29204 using Rust!
[ +0.000108] monitor_control: Removing HID device vendor: 2389 product: 29204 using Rust!

Signed-off-by: Rahul Rameshbabu <sergeantsagara@xxxxxxxxxxxxxx>
---
drivers/hid/hid_monitor_control.rs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid_monitor_control.rs b/drivers/hid/hid_monitor_control.rs
index 18afd69a56d5..aeb6e4058a6b 100644
--- a/drivers/hid/hid_monitor_control.rs
+++ b/drivers/hid/hid_monitor_control.rs
@@ -8,17 +8,22 @@
Driver,
};

+const USB_VENDOR_ID_NVIDIA: u32 = 0x0955;
+const USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER: u32 = 0x7214;
+
struct HidMonitorControl;

#[vtable]
impl Driver for HidMonitorControl {
fn probe(dev: &mut hid::Device, id: &hid::DeviceId) -> Result<()> {
/* TODO implement */
+ pr_info!("Probing HID device vendor: {} product: {} using Rust!\n", id.vendor(), id.product());
Ok(())
}

fn remove(dev: &mut hid::Device) {
/* TODO implement */
+ pr_info!("Removing HID device vendor: {} product: {} using Rust!\n", dev.vendor(), dev.product());
}
}

@@ -26,8 +31,8 @@ fn remove(dev: &mut hid::Device) {
driver: HidMonitorControl,
id_table: [
kernel::usb_device! {
- vendor: /* TODO fill in */,
- product: /* TODO fill in */,
+ vendor: USB_VENDOR_ID_NVIDIA,
+ product: USB_DEVICE_ID_NVIDIA_THUNDERSTRIKE_CONTROLLER,
},
],
name: "monitor_control",
--
2.47.2