Skip to content

Commit 2caae00

Browse files
committed
samples/rust: add platform device driver sample
This is a minimal sample of registering a driver for a platform device. The driver doesn't really do anything, and serves as a template for future new platform drivers. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
1 parent cffb910 commit 2caae00

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

samples/rust/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,14 @@ config SAMPLE_RUST_RANDOM
110110

111111
If unsure, say N.
112112

113+
config SAMPLE_RUST_PLATFORM
114+
tristate "Platform device driver"
115+
help
116+
This option builds the Rust platform device driver sample.
117+
118+
To compile this as a module, choose M here:
119+
the module will be called rust_platform.
120+
121+
If unsure, say N.
122+
113123
endif # SAMPLES_RUST

samples/rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ obj-$(CONFIG_SAMPLE_RUST_STACK_PROBING) += rust_stack_probing.o
1010
obj-$(CONFIG_SAMPLE_RUST_SEMAPHORE) += rust_semaphore.o
1111
obj-$(CONFIG_SAMPLE_RUST_SEMAPHORE_C) += rust_semaphore_c.o
1212
obj-$(CONFIG_SAMPLE_RUST_RANDOM) += rust_random.o
13+
obj-$(CONFIG_SAMPLE_RUST_PLATFORM) += rust_platform.o

samples/rust/rust_platform.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
//! Rust platform device driver sample.
4+
5+
#![no_std]
6+
#![feature(allocator_api, global_asm)]
7+
8+
use kernel::{module_platform_driver, of, platform, prelude::*};
9+
10+
module_platform_driver! {
11+
type: Driver,
12+
name: b"rust_platform",
13+
license: b"GPL v2",
14+
}
15+
16+
struct Driver;
17+
impl platform::Driver for Driver {
18+
kernel::define_of_id_table! {(), [
19+
(of::DeviceId::Compatible(b"rust,sample"), None),
20+
]}
21+
22+
fn probe(_dev: &mut platform::Device, _id_info: Option<&Self::IdInfo>) -> Result {
23+
Ok(())
24+
}
25+
}

0 commit comments

Comments
 (0)