rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rob Herring (Arm)" <robh@kernel.org>
To: "Saravana Kannan" <saravanak@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Dirk Behme" <dirk.behme@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	 rust-for-linux@vger.kernel.org
Subject: [PATCH RFC 3/3] samples: rust: platform: Add property read examples
Date: Fri, 25 Oct 2024 16:05:48 -0500	[thread overview]
Message-ID: <20241025-rust-platform-dev-v1-3-0df8dcf7c20b@kernel.org> (raw)
In-Reply-To: <20241025-rust-platform-dev-v1-0-0df8dcf7c20b@kernel.org>

Add some example usage of the device property read methods for
DT/ACPI/swnode properties.

Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
---
 drivers/of/unittest-data/tests-platform.dtsi |  3 +++
 samples/rust/rust_driver_platform.rs         | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/drivers/of/unittest-data/tests-platform.dtsi b/drivers/of/unittest-data/tests-platform.dtsi
index 2caaf1c10ee6..a5369b9343b8 100644
--- a/drivers/of/unittest-data/tests-platform.dtsi
+++ b/drivers/of/unittest-data/tests-platform.dtsi
@@ -37,6 +37,9 @@ dev@100 {
 			test-device@2 {
 				compatible = "test,rust-device";
 				reg = <0x2>;
+
+				test,u32-prop = <0xdeadbeef>;
+				test,i16-array = /bits/ 16 <1 2 (-3) (-4)>;
 			};
 		};
 	};
diff --git a/samples/rust/rust_driver_platform.rs b/samples/rust/rust_driver_platform.rs
index 5cf4a8f86c13..95c290806862 100644
--- a/samples/rust/rust_driver_platform.rs
+++ b/samples/rust/rust_driver_platform.rs
@@ -41,6 +41,28 @@ fn probe(pdev: &mut platform::Device, info: Option<&Self::IdInfo>) -> Result<Pin
             }
         };
 
+        let dev = pdev.as_ref();
+        if let Ok(idx) = dev.property_match_string(c_str!("compatible"), c_str!("test,rust-device"))
+        {
+            dev_info!(pdev.as_ref(), "matched compatible string idx = {}\n", idx);
+        }
+
+        let prop = dev.property_read_bool(c_str!("test,bool-prop"));
+        dev_info!(dev, "bool prop is {}\n", prop);
+
+        let _prop = dev.property_read::<u32>(c_str!("test,u32-prop"))?;
+        let prop: u32 = dev.property_read(c_str!("test,u32-prop"))?;
+        dev_info!(dev, "'test,u32-prop' is {:#x}\n", prop);
+
+        let prop: [i16; 4] = dev.property_read_array(c_str!("test,i16-array"))?;
+        dev_info!(dev, "'test,i16-array' is {:?}\n", prop);
+        dev_info!(
+            dev,
+            "'test,i16-array' length is {}\n",
+            dev.property_count_elem::<u16>(c_str!("test,i16-array"))
+                .unwrap()
+        );
+
         let drvdata = KBox::new(Self { pdev: pdev.clone() }, GFP_KERNEL)?;
 
         Ok(drvdata.into())

-- 
2.45.2


  parent reply	other threads:[~2024-10-25 21:06 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 21:05 [PATCH RFC 0/3] Initial rust bindings for device property reads Rob Herring (Arm)
2024-10-25 21:05 ` [PATCH RFC 1/3] of: unittest: Add a platform device node for rust platform driver sample Rob Herring (Arm)
2024-10-28  7:11   ` Dirk Behme
2024-10-25 21:05 ` [PATCH RFC 2/3] rust: Add bindings for device properties Rob Herring (Arm)
2024-10-25 21:12   ` Alex Gaynor
2024-10-27 22:07     ` Rob Herring
2024-10-28 22:24     ` Rob Herring
2024-10-29  2:08       ` Alex Gaynor
2024-10-28  7:12   ` Dirk Behme
2024-10-29 14:16   ` Alice Ryhl
2024-10-29 17:57     ` Rob Herring
2024-10-29 18:29       ` Miguel Ojeda
2024-10-29 18:30         ` Miguel Ojeda
2024-10-29 18:48       ` Alice Ryhl
2024-10-29 18:57         ` Miguel Ojeda
2024-10-29 19:35           ` Rob Herring
2024-10-29 22:05             ` Rob Herring
2024-10-30  8:09               ` Alice Ryhl
2024-10-30  8:15             ` Alice Ryhl
2024-10-30 14:05               ` Rob Herring
2024-10-30 15:43                 ` Alice Ryhl
2024-10-30 16:03                 ` Dirk Behme
2024-10-30 16:47                   ` Rob Herring
2024-10-31  7:19                     ` Dirk Behme
2024-11-15  6:39                     ` Dirk Behme
2024-10-25 21:05 ` Rob Herring (Arm) [this message]
2024-10-28  7:13   ` [PATCH RFC 3/3] samples: rust: platform: Add property read examples Dirk Behme
2024-10-28  7:11 ` [PATCH RFC 0/3] Initial rust bindings for device property reads Dirk Behme

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241025-rust-platform-dev-v1-3-0df8dcf7c20b@kernel.org \
    --to=robh@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dirk.behme@gmail.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=saravanak@google.com \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).