Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

samples: rust: add Rust platform sample driver

Add a sample Rust platform driver illustrating the usage of the platform
bus abstractions.

This driver probes through either a match of device / driver name or a
match within the OF ID table.

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Tested-by: Fabien Parent <fabien.parent@linaro.org>
Link: https://lore.kernel.org/r/20241219170425.12036-16-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Danilo Krummrich and committed by
Greg Kroah-Hartman
b2e8a832 683a63be

+66
+1
MAINTAINERS
··· 7038 7038 F: rust/kernel/devres.rs 7039 7039 F: rust/kernel/driver.rs 7040 7040 F: rust/kernel/platform.rs 7041 + F: samples/rust/rust_driver_platform.rs 7041 7042 7042 7043 DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS) 7043 7044 M: Nishanth Menon <nm@ti.com>
+5
drivers/of/unittest-data/tests-platform.dtsi
··· 33 33 reg = <0x100>; 34 34 }; 35 35 }; 36 + 37 + test-device@2 { 38 + compatible = "test,rust-device"; 39 + reg = <0x2>; 40 + }; 36 41 }; 37 42 }; 38 43 };
+10
samples/rust/Kconfig
··· 51 51 52 52 If unsure, say N. 53 53 54 + config SAMPLE_RUST_DRIVER_PLATFORM 55 + tristate "Platform Driver" 56 + help 57 + This option builds the Rust Platform driver sample. 58 + 59 + To compile this as a module, choose M here: 60 + the module will be called rust_driver_platform. 61 + 62 + If unsure, say N. 63 + 54 64 config SAMPLE_RUST_HOSTPROGS 55 65 bool "Host programs" 56 66 help
+1
samples/rust/Makefile
··· 5 5 obj-$(CONFIG_SAMPLE_RUST_MISC_DEVICE) += rust_misc_device.o 6 6 obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o 7 7 obj-$(CONFIG_SAMPLE_RUST_DRIVER_PCI) += rust_driver_pci.o 8 + obj-$(CONFIG_SAMPLE_RUST_DRIVER_PLATFORM) += rust_driver_platform.o 8 9 9 10 rust_print-y := rust_print_main.o rust_print_events.o 10 11
+49
samples/rust/rust_driver_platform.rs
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + //! Rust Platform driver sample. 4 + 5 + use kernel::{c_str, of, platform, prelude::*}; 6 + 7 + struct SampleDriver { 8 + pdev: platform::Device, 9 + } 10 + 11 + struct Info(u32); 12 + 13 + kernel::of_device_table!( 14 + OF_TABLE, 15 + MODULE_OF_TABLE, 16 + <SampleDriver as platform::Driver>::IdInfo, 17 + [(of::DeviceId::new(c_str!("test,rust-device")), Info(42))] 18 + ); 19 + 20 + impl platform::Driver for SampleDriver { 21 + type IdInfo = Info; 22 + const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE); 23 + 24 + fn probe(pdev: &mut platform::Device, info: Option<&Self::IdInfo>) -> Result<Pin<KBox<Self>>> { 25 + dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n"); 26 + 27 + if let Some(info) = info { 28 + dev_info!(pdev.as_ref(), "Probed with info: '{}'.\n", info.0); 29 + } 30 + 31 + let drvdata = KBox::new(Self { pdev: pdev.clone() }, GFP_KERNEL)?; 32 + 33 + Ok(drvdata.into()) 34 + } 35 + } 36 + 37 + impl Drop for SampleDriver { 38 + fn drop(&mut self) { 39 + dev_dbg!(self.pdev.as_ref(), "Remove Rust Platform driver sample.\n"); 40 + } 41 + } 42 + 43 + kernel::module_platform_driver! { 44 + type: SampleDriver, 45 + name: "rust_driver_platform", 46 + author: "Danilo Krummrich", 47 + description: "Rust Platform driver", 48 + license: "GPL v2", 49 + }