summaryrefslogtreecommitdiff
path: root/samples/rust
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2025-12-26 20:17:09 +0000
committerDanilo Krummrich <dakr@kernel.org>2025-12-28 12:44:31 +0100
commitd43a12e474351161bb6d7e2a17ab56f591b9302d (patch)
tree753f57927ac85858cf3df52134a4b3cdb6ec5356 /samples/rust
parent057d44b057755f31a38a3cb040960e8727b93610 (diff)
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>
Diffstat (limited to 'samples/rust')
-rw-r--r--samples/rust/Kconfig11
-rw-r--r--samples/rust/Makefile1
-rw-r--r--samples/rust/rust_soc.rs81
3 files changed, 93 insertions, 0 deletions
diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig
index 3efa51bfc8ef..c49ab9106345 100644
--- a/samples/rust/Kconfig
+++ b/samples/rust/Kconfig
@@ -161,6 +161,17 @@ config SAMPLE_RUST_DRIVER_AUXILIARY
If unsure, say N.
+config SAMPLE_RUST_SOC
+ tristate "SoC Driver"
+ select SOC_BUS
+ help
+ This option builds the Rust SoC driver sample.
+
+ To compile this as a module, choose M here:
+ the module will be called rust_soc.
+
+ If unsure, say N.
+
config SAMPLE_RUST_HOSTPROGS
bool "Host programs"
help
diff --git a/samples/rust/Makefile b/samples/rust/Makefile
index f65885d1d62b..6c0aaa58cccc 100644
--- a/samples/rust/Makefile
+++ b/samples/rust/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SAMPLE_RUST_DRIVER_USB) += rust_driver_usb.o
obj-$(CONFIG_SAMPLE_RUST_DRIVER_FAUX) += rust_driver_faux.o
obj-$(CONFIG_SAMPLE_RUST_DRIVER_AUXILIARY) += rust_driver_auxiliary.o
obj-$(CONFIG_SAMPLE_RUST_CONFIGFS) += rust_configfs.o
+obj-$(CONFIG_SAMPLE_RUST_SOC) += rust_soc.o
rust_print-y := rust_print_main.o rust_print_events.o
diff --git a/samples/rust/rust_soc.rs b/samples/rust/rust_soc.rs
new file mode 100644
index 000000000000..403c1137af77
--- /dev/null
+++ b/samples/rust/rust_soc.rs
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Rust SoC Platform driver sample.
+
+use kernel::{
+ acpi,
+ device::Core,
+ of,
+ platform,
+ prelude::*,
+ soc,
+ str::CString,
+ sync::aref::ARef, //
+};
+use pin_init::pin_init_scope;
+
+#[pin_data]
+struct SampleSocDriver {
+ pdev: ARef<platform::Device>,
+ #[pin]
+ _dev_reg: soc::Registration,
+}
+
+kernel::of_device_table!(
+ OF_TABLE,
+ MODULE_OF_TABLE,
+ <SampleSocDriver as platform::Driver>::IdInfo,
+ [(of::DeviceId::new(c"test,rust-device"), ())]
+);
+
+kernel::acpi_device_table!(
+ ACPI_TABLE,
+ MODULE_ACPI_TABLE,
+ <SampleSocDriver as platform::Driver>::IdInfo,
+ [(acpi::DeviceId::new(c"LNUXBEEF"), ())]
+);
+
+impl platform::Driver for SampleSocDriver {
+ type IdInfo = ();
+ const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+ const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
+
+ fn probe(
+ pdev: &platform::Device<Core>,
+ _info: Option<&Self::IdInfo>,
+ ) -> impl PinInit<Self, Error> {
+ let dev = pdev.as_ref();
+
+ dev_dbg!(dev, "Probe Rust SoC driver sample.\n");
+
+ let pdev = pdev.into();
+ pin_init_scope(move || {
+ let machine = CString::try_from(c"My cool ACME15 dev board")?;
+ let family = CString::try_from(c"ACME")?;
+ let revision = CString::try_from(c"1.2")?;
+ let serial_number = CString::try_from(c"12345")?;
+ let soc_id = CString::try_from(c"ACME15")?;
+
+ let attr = soc::Attributes {
+ machine: Some(machine),
+ family: Some(family),
+ revision: Some(revision),
+ serial_number: Some(serial_number),
+ soc_id: Some(soc_id),
+ };
+
+ Ok(try_pin_init!(SampleSocDriver {
+ pdev: pdev,
+ _dev_reg <- soc::Registration::new(attr),
+ }? Error))
+ })
+ }
+}
+
+kernel::module_platform_driver! {
+ type: SampleSocDriver,
+ name: "rust_soc",
+ authors: ["Matthew Maurer"],
+ description: "Rust SoC Driver",
+ license: "GPL",
+}