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

From: Muchamad Coirul Anwar

Date: Wed Apr 29 2026 - 09:27:40 EST


This is v2 of the Rust driver for the ams AS5600 12-bit magnetic rotary
position sensor. v1 was a probe-only stub; this version adds minimal
Rust IIO abstractions and exposes in_angl_raw and in_angl_scale via
sysfs.

Link: https://lore.kernel.org/linux-iio/20260419151327.26306-1-muchamadcoirulanwar@xxxxxxxxx/

Changes since RFC v1:
- Moved magnet validation from probe() to read_raw() per Jonathan's
feedback. probe() now only verifies I2C communication.
- Added minimal Rust IIO abstractions (rust/kernel/iio.rs) wrapping
iio_device_alloc, iio_device_register, and the read_raw callback.
- Added OF device table for devicetree matching (ams,as5600).
- Replaced hex bit masks with kernel::bits::bit_u8() per Miguel's
pointer.
- Replaced magic numbers with bindings constants
(iio_chan_info_enum_*, INDIO_DIRECT_MODE).
- Downgraded log messages to dev_dbg!(), removed unbind noise.
- Added devicetree binding documentation.
- iio_info vtable is now a compile-time const.
- Uses iio_device_alloc with PinnedDrop instead of devm_* to avoid
lifetime conflicts with Rust's ownership model.

The IIO abstraction design was informed by earlier unpublished work
from Brandon Saint-John.

The IIO abstraction is intentionally minimal: it supports read_raw
with IIO_VAL_INT, IIO_VAL_INT_PLUS_NANO, IIO_VAL_INT_PLUS_MICRO,
and IIO_VAL_FRACTIONAL. write_raw and buffer support are left for
future work.

Muchamad Coirul Anwar (4):
i2c: rust: add smbus_read_byte_data and smbus_read_word_data
rust: add minimal IIO subsystem abstractions
dt-bindings: iio: position: add ams,as5600
iio: position: add Rust driver for ams AS5600

Signed-off-by: Muchamad Coirul Anwar <muchamadcoirulanwar@xxxxxxxxx>
---
Tested on BeagleBone Black (AM335x), kernel v7.0.0-rc3,
AS5600 on i2c-2 (0x36) at 3.3V, diametric neodymium magnet.

$ cat /sys/bus/iio/devices/iio:device0/in_angl_raw
3296
$ cat /sys/bus/iio/devices/iio:device0/in_angl_raw
1675
$ cat /sys/bus/iio/devices/iio:device0/in_angl_raw
468

$ cat /sys/bus/iio/devices/iio:device0/in_angl_scale
0.001533981

Magnet removed:

$ cat /sys/bus/iio/devices/iio:device0/in_angl_raw
cat: '/sys/bus/iio/devices/iio:device0/in_angl_raw': No data available

Muchamad Coirul Anwar (4):
i2c: rust: add smbus_read_byte_data and smbus_read_word_data
rust: add minimal IIO subsystem abstractions
dt-bindings: iio: position: add ams,as5600
iio: position: add Rust driver for ams AS5600

.../bindings/iio/position/ams,as5600.yaml | 40 ++++
drivers/iio/position/Kconfig | 14 ++
drivers/iio/position/Makefile | 1 +
drivers/iio/position/as5600.rs | 129 +++++
rust/bindings/bindings_helper.h | 2 +
rust/kernel/i2c.rs | 24 +
rust/kernel/iio.rs | 224 ++++++++++
rust/kernel/lib.rs | 2 +
8 files changed, 436 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/position/ams,as5600.yaml
create mode 100644 drivers/iio/position/as5600.rs
create mode 100644 rust/kernel/iio.rs

--
2.50.0