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.

rust: Add SoC Driver Sample

Shows registration of a SoC device upon receipt of a probe.

Signed-off-by: Matthew Maurer <mmaurer@google.com>
Link: https://patch.msgid.link/20251226-soc-bindings-v4-3-2c2fac08f820@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Matthew Maurer and committed by
Danilo Krummrich
d43a12e4 057d44b0

+94
+1
MAINTAINERS
··· 7705 7705 F: samples/rust/rust_debugfs_scoped.rs 7706 7706 F: samples/rust/rust_driver_platform.rs 7707 7707 F: samples/rust/rust_driver_faux.rs 7708 + F: samples/rust/rust_soc.rs 7708 7709 7709 7710 DRIVERS FOR OMAP ADAPTIVE VOLTAGE SCALING (AVS) 7710 7711 M: Nishanth Menon <nm@ti.com>
+11
samples/rust/Kconfig
··· 161 161 162 162 If unsure, say N. 163 163 164 + config SAMPLE_RUST_SOC 165 + tristate "SoC Driver" 166 + select SOC_BUS 167 + help 168 + This option builds the Rust SoC driver sample. 169 + 170 + To compile this as a module, choose M here: 171 + the module will be called rust_soc. 172 + 173 + If unsure, say N. 174 + 164 175 config SAMPLE_RUST_HOSTPROGS 165 176 bool "Host programs" 166 177 help
+1
samples/rust/Makefile
··· 15 15 obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) += rust_driver_faux.o 16 16 obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) += rust_driver_auxiliary.o 17 17 obj-$(CONFIG_SAMPLE_RUST_CONFIGFS) += rust_configfs.o 18 + obj-$(CONFIG_SAMPLE_RUST_SOC) += rust_soc.o 18 19 19 20 rust_print-y := rust_print_main.o rust_print_events.o 20 21
+81
samples/rust/rust_soc.rs
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + //! Rust SoC Platform driver sample. 4 + 5 + use kernel::{ 6 + acpi, 7 + device::Core, 8 + of, 9 + platform, 10 + prelude::*, 11 + soc, 12 + str::CString, 13 + sync::aref::ARef, // 14 + }; 15 + use pin_init::pin_init_scope; 16 + 17 + #[pin_data] 18 + struct SampleSocDriver { 19 + pdev: ARef<platform::Device>, 20 + #[pin] 21 + _dev_reg: soc::Registration, 22 + } 23 + 24 + kernel::of_device_table!( 25 + OF_TABLE, 26 + MODULE_OF_TABLE, 27 + <SampleSocDriver as platform::Driver>::IdInfo, 28 + [(of::DeviceId::new(c"test,rust-device"), ())] 29 + ); 30 + 31 + kernel::acpi_device_table!( 32 + ACPI_TABLE, 33 + MODULE_ACPI_TABLE, 34 + <SampleSocDriver as platform::Driver>::IdInfo, 35 + [(acpi::DeviceId::new(c"LNUXBEEF"), ())] 36 + ); 37 + 38 + impl platform::Driver for SampleSocDriver { 39 + type IdInfo = (); 40 + const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE); 41 + const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE); 42 + 43 + fn probe( 44 + pdev: &platform::Device<Core>, 45 + _info: Option<&Self::IdInfo>, 46 + ) -> impl PinInit<Self, Error> { 47 + let dev = pdev.as_ref(); 48 + 49 + dev_dbg!(dev, "Probe Rust SoC driver sample.\n"); 50 + 51 + let pdev = pdev.into(); 52 + pin_init_scope(move || { 53 + let machine = CString::try_from(c"My cool ACME15 dev board")?; 54 + let family = CString::try_from(c"ACME")?; 55 + let revision = CString::try_from(c"1.2")?; 56 + let serial_number = CString::try_from(c"12345")?; 57 + let soc_id = CString::try_from(c"ACME15")?; 58 + 59 + let attr = soc::Attributes { 60 + machine: Some(machine), 61 + family: Some(family), 62 + revision: Some(revision), 63 + serial_number: Some(serial_number), 64 + soc_id: Some(soc_id), 65 + }; 66 + 67 + Ok(try_pin_init!(SampleSocDriver { 68 + pdev: pdev, 69 + _dev_reg <- soc::Registration::new(attr), 70 + }? Error)) 71 + }) 72 + } 73 + } 74 + 75 + kernel::module_platform_driver! { 76 + type: SampleSocDriver, 77 + name: "rust_soc", 78 + authors: ["Matthew Maurer"], 79 + description: "Rust SoC Driver", 80 + license: "GPL", 81 + }