From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795910346; b=ggSIe0dO9TTx1hMfJkd6bGj7ZtOwTUm7iqUzR/RxV9OHf6aFAW2bEi01n4v+8vKS27bJ 3fo5xMYJOl9dgQxbUeOPDA2q1UrPrYoilndGKZiEpOFM2PLd8YlSoWtS1QNpRaG3UWRo4 5/22sWTMamb325Bo1pPippmgKlLSJn7/gtBrbbyPbFzCaoJMVq8N/LxeqytsKhd8Uvbeq Dwa2LzRbWlEHig3AQNSnzo2I5hfE3ACcTRq7clvMQDyelojUKwV0xqMhQRBdV74xGJzR/ iCdxIIM/9lkyIWkH1vckxXbi7TmpC/ib7yA02DTxm2KfSY0EJsLeze1LPWCQPcIDqJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910346; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: In-Reply-To:References:X-Mailer:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=FuHdFH4rF4sBrXt6gxWMai+9/9X1x3N6EMNeTXgXstM=; b=U1fxAfHVUL5m8dj1H3M3mfzRqR35eLkR+zwryxQKVaaFP3XGEBsK5Pr+cgG63muxvh5O NK2PvNATnxu/5eU/+v6Bv8wnzn/V3Si6gNCKujWMqiCDOidT9CElZCewwI6QYhiUxuKgD tmgfM9XpSUWqIbV9r2iqtt16EZkBy4M+CWqSQpzeqchZivXg1D5BRIMTFGuRe5XFV4pC7 UflTLz4ZlwOpTQ1JG6MvDwrEGtprJ/wIMhn9NNY+Y8+z/sZ3nY5NFU0KV1GOD7yEJAabx uc5WCLqhmX9ukdPEJIaq6euneMtVb1lb2gKT1qmfyOy3Z6LyKXc8sd29xDRm3FuMTjw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mUug8PXG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6223606A68F; Sat, 28 Nov 2026 23:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mUug8PXG Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF2111F00929; Sat, 28 Nov 2026 23:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910345; bh=FuHdFH4rF4sBrXt6gxWMai+9/9X1x3N6EMNeTXgXstM=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=mUug8PXG235Hd0kLapMbHxf7WNBAkz++IJKvSb1RcziRuGwU0xVSZ9rbrvhznngIk BIDxWIy5o+9Lqpz6r0Go+chWIZDgV8blMpSNcyqwN7s1jFBwnu7FXd0NUpvCHfJ9xP fGiD/+xzk8ZJAVYbHZTJooVSqmp4/ABP1dYE33No0X/WvV0x4wTjZetcGngbRmst6A eUWoDV1Ufkh9b92nsnW1rAwAcwMgpl1+PAHtICEoJWybT3CfInHp3fmLYOthAifSGN 5J9GlKCRdm7BVq4Mlc8RBiGt27OVZ976z2IOJjojLqw6/bcxth41Q2lVclgjVHby28 ydVmIV2he3KEQ== Date: Sat, 28 Nov 2026 23:58:58 +0000 From: Jonathan Cameron To: Muchamad Coirul Anwar Cc: Miguel Ojeda , Igor Korotin , Danilo Krummrich , David Lechner , Alice Ryhl , Daniel Almeida , Mark Brown , Andi Shyti , Shuai Liu <847807867@qq.com>, linux-iio@vger.kernel.org, linux-i2c@vger.kernel.org, rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v7 0/4] iio: position: add Rust driver for ams AS5600 Message-ID: <20261128235858.39e8e5f6@jic23-hlaptop> In-Reply-To: <20261109155743.83740-1-muchamadcoirulanwar@gmail.com> References: <20261109155743.83740-1-muchamadcoirulanwar@gmail.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 9 Nov 2026 22:57:39 +0700 Muchamad Coirul Anwar wrote: > 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. Do we have any like timescale on regmap support? Long term I think things should go that way simply to avoid duplication. Given the rust bindings we have here are very strongly assuming a register interface regmap should in most cases probably replaces these. The irony is that I'd be much happier seeing an i2c only binding if it was for the many i2c devices that don't present a simple register interface. Note though that this stuff is effectively internal to the kernel so I wouldn't mind going forward with I2C register interface now and then flipping over to regmap and deprecating the I2C register interface later. Jonathan > > 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/179286358623.55649.5397316745104390556@linux.dev/ > > 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/tencent_173B7731E90B9624F9F82613DC3031B70907@qq.com/ > > --- > > Previous versions: > > v6: https://lore.kernel.org/linux-iio/20261004130303.65432-1-muchamadcoirulanwar@gmail.com/ > > Changes since RFC v6: > > - Rebase on top of Linux 7.3.0. > - Make register() return Device, 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 >