Re: [RFC PATCH v4 3/3] iio: position: add Rust driver for ams AS5600

Nuno Sá <[email protected]> Tue, 4 Aug 2026 15:57:17 +0100
Newsgroups org.kernel.vger.linux-i2c,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <anH7kbxvS6z5GlPI@nsa>
Hi Coirul,

Same as Jonathan on my rust capabilities (maybe now I'll have proper
motivation to learn it :)).

Just one question below...

On Tue, Jul 07, 2026 at 10:15:42PM +0700, Muchamad Coirul Anwar wrote:
> Add a Rust driver for the ams AS5600 12-bit magnetic rotary position
> sensor. The driver exposes in_angl_raw and in_angl_scale via the IIO
> sysfs interface.
> 
> Features:
> - ARef<I2cClient> for safe refcounted I2C client access
> - Mutex-serialized status + angle read sequence
> - Static channel spec (module-level const)
> - No magnet validation at probe (deferred to read_raw per IIO convention)
> - Error propagation via ? operator (no recovery state machine)
> 
> The byte order for the AS5600's big-endian registers is handled via
> swap_bytes() in-driver. This is equivalent to C's
> i2c_smbus_read_word_swapped(). The long-term solution is regmap-rs
> where endianness is configured once at the transport level.
> 
> Tested on BeagleBone Black (AM335x) with AS5600 on i2c-2 (0x36).
> 
> Signed-off-by: Muchamad Coirul Anwar <[email protected]>
> ---

...

> +impl IioDriver for As5600Priv {
> +    fn read_raw(&self, _chan: *const iio_chan_spec, mask: isize) -> Result<IioVal> {
> +        const INFO_RAW: isize = iio_chan_info_enum_IIO_CHAN_INFO_RAW as isize;
> +        const INFO_SCALE: isize = iio_chan_info_enum_IIO_CHAN_INFO_SCALE as isize;

Likely stupid question but do we always need the above? Some drivers might have
several INFO_* bits sets and we often need to nest the match if multiple channels have the
same bits. For those cases having to define all of them like this and
then doing the match seems not great to me. I guess we can directly have 
` iio_chan_info_enum_IIO_CHAN_INFO_RAW as isize` in match but not sure
if it's also that neat...

So bottom line, it would be nice if we could have something nicely
readable that we could directly pass to match.

On another topic, I believe mask is present in several drivers for
historic reasons but note that this parameter is not really a mask. So
other name like 'info' is more appropriate.

- Nuno Sá