[RFC PATCH v8 0/4] iio: position: add Rust driver for ams AS5600

From: Muchamad Coirul Anwar

Date: Tue Dec 01 2026 - 11:56:42 EST


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@xxxxxxxxx/
v6: https://lore.kernel.org/all/20261016154819.17936-1-muchamadcoirulanwar@xxxxxxxxx/

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