From: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
To: jic23@kernel.org, linux-iio@vger.kernel.org,
rust-for-linux@vger.kernel.org, devicetree@vger.kernel.org
Cc: branstj@gmail.com, lars@metafoo.de, ojeda@kernel.org,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
igor.korotin.linux@gmail.com, linux-kernel@vger.kernel.org,
Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
Subject: [RFC PATCH v2 1/4] i2c: rust: add smbus_read_byte_data and smbus_read_word_data
Date: Wed, 29 Apr 2026 20:22:27 +0700 [thread overview]
Message-ID: <20260429132234.30514-2-muchamadcoirulanwar@gmail.com> (raw)
In-Reply-To: <20260429132234.30514-1-muchamadcoirulanwar@gmail.com>
Signed-off-by: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
---
rust/kernel/i2c.rs | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/rust/kernel/i2c.rs b/rust/kernel/i2c.rs
index 7b908f0c5a58..6eaea1158fda 100644
--- a/rust/kernel/i2c.rs
+++ b/rust/kernel/i2c.rs
@@ -477,6 +477,30 @@ impl<Ctx: device::DeviceContext> I2cClient<Ctx> {
fn as_raw(&self) -> *mut bindings::i2c_client {
self.0.get()
}
+
+ /// Reads a single byte from a register via SMBus.
+ pub fn smbus_read_byte_data(&self, reg: u8) -> Result<u8> {
+ // SAFETY: `self.as_raw()` is a valid pointer to a `struct i2c_client`
+ // by the type invariant of `I2cClient`.
+ let ret = unsafe { bindings::i2c_smbus_read_byte_data(self.as_raw(), reg) };
+ if ret < 0 {
+ Err(Error::from_errno(ret))
+ } else {
+ Ok(ret as u8)
+ }
+ }
+
+ /// Reads a 16-bit word from a register via SMBus.
+ pub fn smbus_read_word_data(&self, reg: u8) -> Result<u16> {
+ // SAFETY: `self.as_raw()` is a valid pointer to a `struct i2c_client`
+ // by the type invariant of `I2cClient`.
+ let ret = unsafe { bindings::i2c_smbus_read_word_data(self.as_raw(), reg) };
+ if ret < 0 {
+ Err(Error::from_errno(ret))
+ } else {
+ Ok(ret as u16)
+ }
+ }
}
// SAFETY: `I2cClient` is a transparent wrapper of `struct i2c_client`.
--
2.50.0
next prev parent reply other threads:[~2026-04-29 13:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 13:22 [RFC PATCH v2 0/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-04-29 13:22 ` Muchamad Coirul Anwar [this message]
2026-05-04 10:29 ` [RFC PATCH v2 1/4] i2c: rust: add smbus_read_byte_data and smbus_read_word_data Igor Korotin
2026-04-29 13:22 ` [RFC PATCH v2 2/4] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-04-29 13:22 ` [RFC PATCH v2 3/4] dt-bindings: iio: position: add ams,as5600 Muchamad Coirul Anwar
2026-04-29 13:46 ` Krzysztof Kozlowski
2026-04-29 13:22 ` [RFC PATCH v2 4/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
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=20260429132234.30514-2-muchamadcoirulanwar@gmail.com \
--to=muchamadcoirulanwar@gmail.com \
--cc=branstj@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=igor.korotin.linux@gmail.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=robh@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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