File Index
Files and directories
Sign in
FILE

rust_driver_usb.rs

File preview with syntax highlighting.

linux-6.19.14/samples/rust/rust_driver_usb.rs RUST
 1// SPDX-License-Identifier: GPL-2.0
 2// SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd.
 3
 4//! Rust USB driver sample.
 5
 6use kernel::{device, device::Core, prelude::*, sync::aref::ARef, usb};
 7
 8struct SampleDriver {
 9    _intf: ARef<usb::Interface>,
10}
11
12kernel::usb_device_table!(
13    USB_TABLE,
14    MODULE_USB_TABLE,
15    <SampleDriver as usb::Driver>::IdInfo,
16    [(usb::DeviceId::from_id(0x1234, 0x5678), ()),]
17);
18
19impl usb::Driver for SampleDriver {
20    type IdInfo = ();
21    const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;
22
23    fn probe(
24        intf: &usb::Interface<Core>,
25        _id: &usb::DeviceId,
26        _info: &Self::IdInfo,
27    ) -> impl PinInit<Self, Error> {
28        let dev: &device::Device<Core> = intf.as_ref();
29        dev_info!(dev, "Rust USB driver sample probed\n");
30
31        Ok(Self { _intf: intf.into() })
32    }
33
34    fn disconnect(intf: &usb::Interface<Core>, _data: Pin<&Self>) {
35        let dev: &device::Device<Core> = intf.as_ref();
36        dev_info!(dev, "Rust USB driver sample disconnected\n");
37    }
38}
39
40kernel::module_usb_driver! {
41    type: SampleDriver,
42    name: "rust_driver_usb",
43    authors: ["Daniel Almeida"],
44    description: "Rust USB driver sample",
45    license: "GPL v2",
46}
~/ Read-only file preview.