Rust for Linux List
 help / color / mirror / Atom feed
* [RFC PATCH v8 0/4] iio: position: add Rust driver for ams AS5600
@ 2026-12-01 16:55 Muchamad Coirul Anwar
  2026-12-01 16:55 ` [RFC PATCH v8 1/4] rust: io: add FallibleIoCapable Muchamad Coirul Anwar
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Muchamad Coirul Anwar @ 2026-12-01 16:55 UTC (permalink / raw)
  To: Jonathan Cameron, Miguel Ojeda, Igor Korotin, Danilo Krummrich
  Cc: David Lechner, Nuno Sá, Andy Shevchenko, Andi Shyti,
	Daniel Almeida, Alice Ryhl, Mark Brown, Joshua Crofts,
	Markus Probst, Shuai Liu, linux-iio, linux-i2c, rust-for-linux,
	driver-core, linux-kernel

This series adds a Rust driver for the ams AS5600 12-bit magnetic rotary
position sensor. It also adds fallible I/O, SMBus access, and the IIO
abstractions needed by the driver. The driver exposes raw angle and scale
through IIO sysfs.

The internal I2C register interface remains an interim approach while Rust
regmap abstractions are unavailable. Following the RFC v7 discussion [1],
the long-term plan is to migrate drivers like this to regmap to avoid
duplication, using this internal interface only until Rust regmap support
lands. Feedback from I2C and Rust maintainers on this approach is still
welcome.

Thanks to Igor Korotin for co-developing the device ownership and
bound-client lifetime rework in Patches 3 and 4, and for reporting the
two Clippy warnings in Patch 3/4 of v7. Thanks also to Markus Probst for
suggesting `Sync` on `I2cClient<device::Bound>` for Patch 2/4.

Igor reviewed Patch 2/4 in v7, but since I added `Sync` on
`I2cClient<device::Bound>` and updated some docs afterward, I did not
carry his `Reviewed-by:` tag forward. Another review would be
appreciated.

[1] https://lore.kernel.org/all/20261128235858.39e8e5f6@jic23-hlaptop/

---

Previous versions:

  v7: https://lore.kernel.org/all/20261109155743.83740-1-muchamadcoirulanwar@gmail.com/
  v6: https://lore.kernel.org/all/20261016154819.17936-1-muchamadcoirulanwar@gmail.com/

Changes since RFC v7:

- Rebase on top of Linux v7.4-rc4 (which includes the removal of
  TryFrom<&Device> for &I2cClient).
- Patch 2/4: Implement `Sync` for `I2cClient<device::Bound>`, as
  suggested by Markus Probst, removing the need for
  `unsafe impl Send`/`Sync` on `As5600Priv`. Update SMBus
  documentation and invariant comments.
- Patch 3/4: Gate `pub mod iio;` on `#[cfg(CONFIG_IIO = "y")]`.
- Patch 3/4: Fix the two Clippy warnings in `rust/kernel/iio.rs`
  reported by Igor Korotin.
- Patch 3/4: Thread the `'parent` bound lifetime through `Device` and
  `UnregisteredDevice`, and mark `UnregisteredDevice::register()` as
  `unsafe`.
- Patch 4/4: Remove `unsafe impl Send`/`Sync` from `As5600Priv` and bind
  `Device` to the `'bound` parent lifetime.

Testing:

Clippy (`CLIPPY=1`) and debug builds (`CONFIG_RUST_DEBUG_ASSERTIONS`,
`CONFIG_KFENCE`, `CONFIG_UBSAN`, `CONFIG_PROVE_LOCKING`, and
`CONFIG_DEBUG_KMEMLEAK`) passed on ARMv7 (`I2C=y`, `IIO=y`, `AS5600=m`),
with no warnings on `rust/kernel.o` or `drivers/iio/position/as5600.o`.

Runtime testing was performed on a BeagleBone Black with an AS5600 on
i2c-2 at 0x36:
- Raw angle (including magnet rotation) and scale reads via sysfs, and
  ENODATA when the magnet-detected bit is clear.
- I2C bus disconnect returning -EREMOTEIO and recovering on
  reconnect, plus clean module removal while in bus error state.
- 10 concurrent readers, 50 unbind/rebind cycles (including concurrent
  reads), 50 module load/unload cycles, and module removal during active
  reads and with an open sysfs file descriptor.
- KFENCE, UBSAN, lockdep, and kmemleak reported no issues (KASAN was
  disabled because 32-bit ARM selects `HAVE_RUST` only when `!KASAN`).

Muchamad Coirul Anwar (4):
  rust: io: add FallibleIoCapable
  i2c: rust: implement SMBus access via IoBackend
  rust: add minimal IIO subsystem abstractions
  iio: position: add Rust driver for ams AS5600

 drivers/iio/position/Kconfig    |  11 +
 drivers/iio/position/Makefile   |   1 +
 drivers/iio/position/as5600.rs  | 193 ++++++++++++
 include/linux/iio/iio.h         |   6 +-
 rust/bindings/bindings_helper.h |   2 +
 rust/kernel/bits.rs             |  29 ++
 rust/kernel/i2c.rs              | 243 ++++++++++++++-
 rust/kernel/iio.rs              | 519 ++++++++++++++++++++++++++++++++
 rust/kernel/io.rs               |  62 ++--
 rust/kernel/lib.rs              |   2 +
 10 files changed, 1048 insertions(+), 20 deletions(-)
 create mode 100644 drivers/iio/position/as5600.rs
 create mode 100644 rust/kernel/iio.rs


base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
-- 
2.50.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-01 17:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 16:55 [RFC PATCH v8 0/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-12-01 16:55 ` [RFC PATCH v8 1/4] rust: io: add FallibleIoCapable Muchamad Coirul Anwar
2026-12-01 17:40   ` Markus Probst
2026-12-01 16:55 ` [RFC PATCH v8 2/4] i2c: rust: implement SMBus access via IoBackend Muchamad Coirul Anwar
2026-12-01 17:41   ` Markus Probst
2026-12-01 16:55 ` [RFC PATCH v8 3/4] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-12-01 16:55 ` [RFC PATCH v8 4/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox