mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-02-28 19:06:51 +01:00
Convert all imports to use "kernel vertical" style. With this, subsequent patches neither introduce unrelated changes nor leave an inconsistent import pattern. While at it, drop unnecessary imports covered by prelude::*. Link: https://docs.kernel.org/rust/coding-guidelines.html#imports Signed-off-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://patch.msgid.link/20260105142123.95030-4-dakr@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
55 lines
1.2 KiB
Rust
55 lines
1.2 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
// SPDX-FileCopyrightText: Copyright (C) 2025 Collabora Ltd.
|
|
|
|
//! Rust USB driver sample.
|
|
|
|
use kernel::{
|
|
device::{
|
|
self,
|
|
Core, //
|
|
},
|
|
prelude::*,
|
|
sync::aref::ARef,
|
|
usb, //
|
|
};
|
|
|
|
struct SampleDriver {
|
|
_intf: ARef<usb::Interface>,
|
|
}
|
|
|
|
kernel::usb_device_table!(
|
|
USB_TABLE,
|
|
MODULE_USB_TABLE,
|
|
<SampleDriver as usb::Driver>::IdInfo,
|
|
[(usb::DeviceId::from_id(0x1234, 0x5678), ()),]
|
|
);
|
|
|
|
impl usb::Driver for SampleDriver {
|
|
type IdInfo = ();
|
|
const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;
|
|
|
|
fn probe(
|
|
intf: &usb::Interface<Core>,
|
|
_id: &usb::DeviceId,
|
|
_info: &Self::IdInfo,
|
|
) -> impl PinInit<Self, Error> {
|
|
let dev: &device::Device<Core> = intf.as_ref();
|
|
dev_info!(dev, "Rust USB driver sample probed\n");
|
|
|
|
Ok(Self { _intf: intf.into() })
|
|
}
|
|
|
|
fn disconnect(intf: &usb::Interface<Core>, _data: Pin<&Self>) {
|
|
let dev: &device::Device<Core> = intf.as_ref();
|
|
dev_info!(dev, "Rust USB driver sample disconnected\n");
|
|
}
|
|
}
|
|
|
|
kernel::module_usb_driver! {
|
|
type: SampleDriver,
|
|
name: "rust_driver_usb",
|
|
authors: ["Daniel Almeida"],
|
|
description: "Rust USB driver sample",
|
|
license: "GPL v2",
|
|
}
|