Re: [RFC PATCH v8 4/4] iio: position: add Rust driver for ams AS5600
From: Andy Shevchenko
Date: Thu Dec 03 2026 - 06:02:54 EST
On Tue, Dec 01, 2026 at 11:55:08PM +0700, Muchamad Coirul Anwar wrote:
> Add a Rust driver for the ams AS5600 12-bit magnetic rotary position
> sensor.
>
> Expose the raw angle and scale through the IIO sysfs interface in direct
> mode. Read the status register before each angle sample and return
> ENODATA when the magnet-detected bit is clear. Serialize the status and
> angle transaction sequence with a mutex and propagate I2C transport
> errors directly to userspace.
>
> Capture a bound I2C client reference during probe and store it in the
> IIO private data. The registered IIO device carries the same bound
> lifetime, keeping the client valid throughout read_raw callbacks.
>
> The AS5600 stores the raw angle with the high byte at register 0x0c.
> Use the byte-swapped SMBus word helper and mask the result to 12 bits.
>
> Add usize bit and mask helpers for constructing the IIO channel
> information mask.
> Suggested-by: Shuai Liu <847807867@xxxxxx>
> Link: https://lore.kernel.org/all/tencent_173B7731E90B9624F9F82613DC3031B70907@xxxxxx/
> Link: https://lore.kernel.org/all/179286358623.55649.5397316745104390556@xxxxxxxxx/
Again, do not put unreferred Link tags.
...
> + tristate "ams AS5600 magnetic rotary position sensor"
Make this line to be the same or very similar to the top comment in the file.
(or other way around)
> +//! Driver for ams AS5600 12-bit magnetic rotary position sensor.
> + description: "I2C Driver for ams OSRAM AS5600 Magnetic Rotary Position Sensor",
Same for these.
...
> + depends on IIO=y && I2C=y && RUST
Huh?!
...
> + help
> + Support for the ams OSRAM AS5600 12-bit magnetic rotary
> + position sensor. Provides in_angl_raw (0-4095) and
> + in_angl_scale (radians per LSB) via sysfs.
Unneeded details, what we need is something like top level parameters (12-bit,
for example, that's already mentioned). Sysfs and related Linux kernel pieces
are usually not being interested to the users here.
> + To compile this driver as a module, choose M here: the
> + module will be called as5600.
...
> + // Scale factor: radians per LSB = 2*pi / 4096 ~= 0.001533981
> + IioChanInfo::Scale => Ok(IioVal::IntPlusNano(0, 1533981)),
Please try to provide calculations based on the proper constants,
use PI constant (for now open coded) with desired precision and
shift it right by log2(2048). I believe you want 9-sign (yes,
9 in the fraction part) PI == 3141592654 (or ...53 if mentioned
in the datasheet).
--
With Best Regards,
Andy Shevchenko