RFC iio: position: add Rust driver for ams AS5600
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v7 RFC Latest4 patches 3 repliesIn review
- v6 RFC4 patches 8 repliesSuperseded
- v5 RFC3 patches 9 repliesSuperseded
Earlier versions · 4
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v4 RFC | 3 patches | 21 replies | Superseded | |
| v3 RFC | 4 patches | 16 replies | Superseded | |
| v2 RFC | 4 patches | 4 replies | Superseded | |
| v1 RFC | 1 patch | 4 replies | Superseded |
Changes in v7 from the cover letter
- Rebase on top of Linux 7.3.0.
- Make register() return Device<T, Registered>, stored in the driver data, so the IIO device is unregistered before its private data is freed.
- Remove the bound parent parameter from IioDriver::read_raw(); the driver now stores its bound I2C client reference directly.
- Drop the parent lifetime parameter from UnregisteredDevice.
- Use pin_init::raw_try_init() in Device::build_device().
- Document sign conventions for IioVal::IntPlusMicro and IioVal::IntPlusNano.
- Add IIO=y and I2C=y dependencies to CONFIG_AS5600.
- Use typed pointer casts and lossless integer conversion to fix Clippy diagnostics reported by Shuai Liu.
- Replace the ignored AS5600 doctest with a generic no_run example.
- Move raw SMBus FFI calls and errno conversion into safe bound-client methods, as suggested by Shuai Liu.
Patches in v7 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/4 | rust: io: add FallibleIoCapablerust/ | +45 | 0 replies | |
| 2/4 | i2c: rust: implement SMBus access via IoBackendrust/ | +235 | 2 replies | |
| 3/4 | rust: add minimal IIO subsystem abstractionsinclude/ rust/ rust/ +1 more | +471 | 1 reply | |
| 4/4 | iio: position: add Rust driver for ams AS5600drivers/ drivers/ drivers/ +1 more | +227 | 0 replies |
Reviews trailers per patch
1 of 4 patches has a Reviewed-by or Acked-by.
| Patch | Igor Korotin |
|---|---|
| 1/4 | |
| 2/4 | R-b |
| 3/4 | |
| 4/4 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [RFC PATCH v7 0/4] iio: position: add Rust driver for ams AS5600
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.
Feedback on the I2C and IIO lifetimes, locking, and device teardown would be appreciated.
The Region-based view models byte-addressed registers and is not a general model for command-indexed 16-bit registers. The standalone word-read helpers accept any SMBus command byte.
The current interface is intentionally limited while a Rust regmap abstraction is unavailable. Feedback on whether this is an appropriate interim approach, or whether the work should wait for regmap, would be appreciated.
Based on Linux v7.3.
Thanks to Igor Korotin for the device ownership and bound-client lifetime rework used in patches 3 and 4:
https://lore.kernel.org/all/[email protected]/
Thanks to Shuai Liu for reviewing v6. This version addresses the Clippy warnings, replaces the ignored SMBus doctest, and moves repeated unsafe SMBus calls into safe helpers:
https://lore.kernel.org/all/[email protected]/
---
Previous versions:
v6: https://lore.kernel.org/linux-iio/[email protected]/
Changes since RFC v6:
- Rebase on top of Linux 7.3.0.
- Make register() return Device<T, Registered>, stored in the driver data, so the IIO device is unregistered before its private data is freed.
- Remove the bound parent parameter from IioDriver::read_raw(); the driver now stores its bound I2C client reference directly.
- Drop the parent lifetime parameter from UnregisteredDevice.
- Use pin_init::raw_try_init() in Device::build_device().
- Document sign conventions for IioVal::IntPlusMicro and IioVal::IntPlusNano.
- Add IIO=y and I2C=y dependencies to CONFIG_AS5600.
- Use typed pointer casts and lossless integer conversion to fix Clippy diagnostics reported by Shuai Liu.
- Replace the ignored AS5600 doctest with a generic no_run example.
- Move raw SMBus FFI calls and errno conversion into safe bound-client methods, as suggested by Shuai Liu.
Testing:
Clippy and debug builds completed for ARM with Rust enabled, I2C built in, and AS5600 built as a module.
Runtime testing was performed on a BeagleBone Black with an AS5600 on i2c-2 at 0x36. Raw angle and scale reads worked with the magnet detected, and reads returned ENODATA when the magnet-detected bit was clear.
I2C errors were propagated when the bus was disconnected, and reads recovered after reconnection. Concurrent reads were tested with 10 readers, including during 20 unbind/rebind cycles.
Lifecycle testing covered 50 unbind/rebind cycles, 50 module load/unload cycles, module removal during active reads, module removal with an open sysfs file descriptor, and module removal while the I2C bus was in an error state.
KFENCE, UBSAN, lockdep, and kmemleak reported no issues. KASAN was not enabled because 32-bit ARM selects HAVE_RUST only when KASAN is disabled.
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 | 186 +++++++++++++ include/linux/iio/iio.h | 6 +- rust/bindings/bindings_helper.h | 2 + rust/kernel/bits.rs | 29 ++ rust/kernel/i2c.rs | 235 ++++++++++++++++ rust/kernel/iio.rs | 463 ++++++++++++++++++++++++++++++++ rust/kernel/io.rs | 62 +++-- rust/kernel/lib.rs | 2 + 10 files changed, 978 insertions(+), 19 deletions(-) create mode 100644 drivers/iio/position/as5600.rs create mode 100644 rust/kernel/iio.rs