From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144119; b=FU34R01zsTLlwaBxUtwjplb363iYKhwW3M+RFpaVfiCUPE8yxctergpp4m65DOscSJ+0 rGAfX5DB7ZWMFyr24+Aklq7BVCiRgYtGyPMUn2KY9x0PtG/4Iiu6D75hIVKWhdRLH0W91 bo2y6s79xEOsV434uAH8ghhSIKPk6YJPLtcrv2eC9M2hTq8tStU95airc4JmF7Meu5I0U rXMnO/nP42oDEQAgd8KkdzKK8uRCn6EIPpgVve0mTAS86IEAu+mGqxL9KdgX2fihTTuJh FxJshExoQtIgTKJnC5sJUHhqsrUcysPcxq+weBitYqkxvjrdIZ9CVuxaTIMPhL2p0Vg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144119; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=MUPOxLjjtMyHjWSybRXZ7T8ZsoyVNK4TPRqWFtQ/WXE=; b=SsMFXj1jFsFdOrhTrtEws3A7ql7ukWa17jPXsVzZoNTCKXXTWktXtrnwtk5cE5oY8anP FMy0qBiZON1IYsJFTDyn69KwdA4gWoc2+V4MHRIyIdMCs22mPt0eJnqnZGBgz3lE0uBPP Q5rQK0J81TPwVUo8tpwGk24/X+QygOzQOoDDdsfI7y54gikMcz0ooG6biOrOUxnNzEwoK P42MVYZwyuhxm4/uzMASTTOW1hHj1q6wmmox8sxd+Y73ZG/D9pjnRFdr1SeM9Txw3OnKW R4gklGuejTcnqoBh6Z+Cu5TkGpK19xsrS1yl9/67DNgE5TyiPJfqdBkbV6DyqrtKkpQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="G/ng3Uri"; arc=none smtp.remote-ip=209.85.215.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65A73606A690 for ; Tue, 1 Dec 2026 16:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65A73606A690 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=G/ng3Uri Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cd62c570b5dso8020605a12.2 for ; Tue, 01 Dec 2026 08:55:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796144117; x=1796748917; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=MUPOxLjjtMyHjWSybRXZ7T8ZsoyVNK4TPRqWFtQ/WXE=; b=G/ng3Uriep54AZN4mEMsSxcO1UN5DdaeWGgc7D7N/CYG7VSEnUsKvywWDZNw5sAxoT NVCaR/X4q1Yiw213bpAY0diVh2ZoE7KEhxISk9Pxo4IsfdoKOamrVycZhBb6f6eBbwL9 V6iL2RNj/RQ2SbZ8E5pvIQ373FUv4715YzNcPcpUWmvkAFV+CAymCoxQ7W2co9SmuP11 DQwRr8Xe9xA+tw9gvsA6bSAHRlR6xEdEEfIBhpGs07YWzyVbbEcrY13WTjJzjO41BaJv hM6gMXPXp1/dHvrTshwrsjzOysvZZ34jTfLBqnzXTS6UZCB+oKZojil1PRK42xZtrBxh Qq6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796144117; x=1796748917; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MUPOxLjjtMyHjWSybRXZ7T8ZsoyVNK4TPRqWFtQ/WXE=; b=kcOyoCFO9atJEFd5j2IfJqWDxm13QHipGWnS+FSx57j+91oj4aJPvoQ7NbXfhlQUWD zoHDRXJg733GHIKrD6HdnGdctfEZV7EqXdOZy3l4Jc9qN7UuIbV1joH2HxSUlWzDmGxS kRyYnL1sAesTRxq/9x0m29CHCFLmJnnjTJQMXQE0DKiV2c6mymJ9ygSxq5GJaZnnArtH u9lbfX/03clCcoJpkgJdMxrpMlLkTKTTfmmgV4VYWlKkotpyLvpH+/DU3VWJP+axuxfy bHBbM6wA558/ZXLwdVUosbFoGFmlyyz0J4kNckotqwbHRmSXX8OmCXGPSz7XCkSQ3f0j cWnA== X-Forwarded-Encrypted: i=1; AL+hErEWUAacsUx8T1RR2GOxoCuM41qnSpUfknWhwJtD8fbooGKSAzUmcPgi5vAn5QhzkhJFliwRre2X8mk=@vger.kernel.org X-Gm-Message-State: APuU4Z8EuwdrIssfktpvqMeruaFsoCwQQtpLbunuVs8tOjjiLNlFrRIN bKpwujvZ3qFTAoe5e5ZPV+CpQ785jPR4fpjwWHbdN3sfRCppaLkuIQ4o X-Gm-Gg: AZFdTZcBkeeBGFurCMi82xEI8WjHMjHHhla7bQDT38f4Kke/3TpqT1wopa2N52wDQry gYKBMLjaWJSxKMI7kdj01jz+z4VbKAPjy580UpPacu3WMKNdkeovzaodx6ASJIpl+QyuEWihiQi er2KPtuzbTGuN9HIjv3JbmtlX2YM0ZH3kXVN/iCuGinvZQ/DpinIBvnpumUn1y1sd+MeEfMwboo B2M6qZNBOSkSnWdvYvm6aK4pinyV/LbAkTFY5JU8cphVdOh9EwM+K0LOud7qqbz2OnxX/0iEDbY hs91rSUef9/AF1U8tJtIOzRlsv3/4GwfGlL3N33+Nb2fzhTYKOB3E2qZvZuhPFtUmpRUKbjVqpI vD8jaetsNzHnMT87XC+3OeBYrFvXHzNKjL/lUlpNJM5zJuN21WfwChc6GkI/qOMyEm+WF4kE63A clW/tTzpr7BQahWT2y7oufFOB6zTh7lo404sBGiZxebVWCrDEZjI1wLl007cAElp8MX03iO7U0T /VNS2ORvIyT7vGjaySBcObNSxee52wRrblfNoEaSjBBTvKZYwR7Hrytw0YLQY+rGxAtrIz/mz6q ppjDjckKXFUNBwQ3jEE9aX2bwWw+h7YUScdv/hvngOpZc/Rv8D/JVhyDyJ9Ltb28jPunSQEig1b PWzFuYho9pEkjig== X-Received: by 2002:a17:90a:e70c:b0:3ac:aa8d:19ee with SMTP id 98e67ed59e1d1-3b41cafd533mr37699132a91.38.1796144117459; Tue, 01 Dec 2026 08:55:17 -0800 (PST) Received: from localhost.localdomain ([36.68.98.203]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b73b2b3sm29159174a91.2.2026.12.01.08.55.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 08:55:16 -0800 (PST) From: Muchamad Coirul Anwar To: Jonathan Cameron , Miguel Ojeda , Igor Korotin , Danilo Krummrich Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Andi Shyti , Daniel Almeida , Alice Ryhl , Mark Brown , Joshua Crofts , Markus Probst , 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: [RFC PATCH v8 0/4] iio: position: add Rust driver for ams AS5600 Date: Tue, 1 Dec 2026 23:55:04 +0700 Message-ID: <20261201165508.39336-1-muchamadcoirulanwar@gmail.com> X-Mailer: git-send-email 2.50.0 X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. The internal I2C register interface remains an interim approach while Rust regmap abstractions are unavailable. Following the RFC v7 discussion [1], the long-term plan is to migrate drivers like this to regmap to avoid duplication, using this internal interface only until Rust regmap support lands. Feedback from I2C and Rust maintainers on this approach is still welcome. Thanks to Igor Korotin for co-developing the device ownership and bound-client lifetime rework in Patches 3 and 4, and for reporting the two Clippy warnings in Patch 3/4 of v7. Thanks also to Markus Probst for suggesting `Sync` on `I2cClient` for Patch 2/4. Igor reviewed Patch 2/4 in v7, but since I added `Sync` on `I2cClient` and updated some docs afterward, I did not carry his `Reviewed-by:` tag forward. Another review would be appreciated. [1] https://lore.kernel.org/all/20261128235858.39e8e5f6@jic23-hlaptop/ --- Previous versions: v7: https://lore.kernel.org/all/20261109155743.83740-1-muchamadcoirulanwar@gmail.com/ v6: https://lore.kernel.org/all/20261016154819.17936-1-muchamadcoirulanwar@gmail.com/ Changes since RFC v7: - Rebase on top of Linux v7.4-rc4 (which includes the removal of TryFrom<&Device> for &I2cClient). - Patch 2/4: Implement `Sync` for `I2cClient`, as suggested by Markus Probst, removing the need for `unsafe impl Send`/`Sync` on `As5600Priv`. Update SMBus documentation and invariant comments. - Patch 3/4: Gate `pub mod iio;` on `#[cfg(CONFIG_IIO = "y")]`. - Patch 3/4: Fix the two Clippy warnings in `rust/kernel/iio.rs` reported by Igor Korotin. - Patch 3/4: Thread the `'parent` bound lifetime through `Device` and `UnregisteredDevice`, and mark `UnregisteredDevice::register()` as `unsafe`. - Patch 4/4: Remove `unsafe impl Send`/`Sync` from `As5600Priv` and bind `Device` to the `'bound` parent lifetime. Testing: Clippy (`CLIPPY=1`) and debug builds (`CONFIG_RUST_DEBUG_ASSERTIONS`, `CONFIG_KFENCE`, `CONFIG_UBSAN`, `CONFIG_PROVE_LOCKING`, and `CONFIG_DEBUG_KMEMLEAK`) passed on ARMv7 (`I2C=y`, `IIO=y`, `AS5600=m`), with no warnings on `rust/kernel.o` or `drivers/iio/position/as5600.o`. Runtime testing was performed on a BeagleBone Black with an AS5600 on i2c-2 at 0x36: - Raw angle (including magnet rotation) and scale reads via sysfs, and ENODATA when the magnet-detected bit is clear. - I2C bus disconnect returning -EREMOTEIO and recovering on reconnect, plus clean module removal while in bus error state. - 10 concurrent readers, 50 unbind/rebind cycles (including concurrent reads), 50 module load/unload cycles, and module removal during active reads and with an open sysfs file descriptor. - KFENCE, UBSAN, lockdep, and kmemleak reported no issues (KASAN was disabled because 32-bit ARM selects `HAVE_RUST` only when `!KASAN`). 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 | 193 ++++++++++++ include/linux/iio/iio.h | 6 +- rust/bindings/bindings_helper.h | 2 + rust/kernel/bits.rs | 29 ++ rust/kernel/i2c.rs | 243 ++++++++++++++- rust/kernel/iio.rs | 519 ++++++++++++++++++++++++++++++++ rust/kernel/io.rs | 62 ++-- rust/kernel/lib.rs | 2 + 10 files changed, 1048 insertions(+), 20 deletions(-) create mode 100644 drivers/iio/position/as5600.rs create mode 100644 rust/kernel/iio.rs base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f -- 2.50.0