From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144119; b=RRZh48KpRSEifh1gJbzCLkBju8KiKv3n6XjH9YjJHu2vbbAa3giPEhwkzz0gMn2/XK3E HBDIuQEVQKvcb5Ewo+XbCJlpXwlP1+LjOtUtMz3RCyqO3SSDOAVPZ1FdqBINAOIJxOwww 9F2yOhlbqWuViwT4T4ExObR7RiTiZhk3b5B7Asrn1bDKPmx7MDZhAgBeq0mu5A3RQrom8 WFHlxI/EPEiIHtUPD4wvZGxDcDxQD96TrmobFU+oOAScNZdDjD7IzfcScelKJ2/L4lQNs ty3EkHf+pRSe4C96Gx18mwwUn+hovkY0gPZfVBFVWdoGo350n8rcawCyGcEL4uqYodw== 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=liZ4UrPHh5oGNbjDg5eRw1Rvjhzd+WhrjA8oUXm0cXFp0WXyovg/Ntnl6hQ0yXOBixpx 6znZQ0hb+jfEWjor4iIEM8WLCMamtbiC0ZhCDcmqC8f9ZBsvfAjiejJvzUW4GBl5FRTMN TC2J0VEv7Vw0aohNCFJErUTkUwLuawJVkiCTNjDBxWswNmOKdKJL0hLp6Fqx4aVRruDVk 6Ynq3jMH4n266a1rmXHs/HjbnoASmY/z2K/BQU6xqH6EodJ0qB5/FHljehFOWU51Pc6vK XIduRkLEHF3L5VGfDAcfNqqEFAkWRfbtysLNfbDD3GM59Mh9NOkYNm+nNPBQ+qR0gRg== 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.176 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 645FA606A68B for ; Tue, 1 Dec 2026 16:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 645FA606A68B 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-f176.google.com with SMTP id 41be03b00d2f7-cd69954c755so8671898a12.3 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=1cu0Sj5oZ70vIpgkcFiji67LRdA87LAx7Nq8zqpW4kVLXEx1OFN7MffEAZT4RxkkRi ZK/4wYzMhx2+fKcS1bBWyVgVxbU+lKyBMIUzr2s3ek0R5TmO2XPL0w7GioFktKrcaC8K livBMoAGKjSbd5F6iJcFITs8PYP74R0HccRnElKmCjiu35GHj3NY4fg7c+8Lt0QYoAD2 SvLUMUC4Zg87gQinFFg/sivV4apqvVriT8TAc2RRAlt624kuraepihIDd7D57Rk+UVv9 C9EG93PSu5tymvNVXPHgT05vKRsSdrXvlGWOaFCQpR/4UvP+BVrRd+ZUKWSxF3yPBRlN LpNQ== X-Forwarded-Encrypted: i=1; AL+hErG0LJ66MwRdDXYqkA4NHXdX/NxCWg92b2vhFBbPCBGWyEAm3ZMrZGEq9Q06+cCGx3NVJ6Aj2/LalGl4IRPODA==@vger.kernel.org X-Gm-Message-State: APuU4Z/75itmKGwxo8PGQmvsRfZKkmd3KedFDzFp7LTfrPHX9wbq9hMq k6eJQcQ4wtWjNcm+vKA7avtXIACYi1J2/XzWwlTzBfrAI/9jsViM6tuT X-Gm-Gg: AZFdTZfn1X8jY/nx4a9ISZ4vczGQTPkAtoIaDnE07i+QI8fKEZJQJ2df2xQpTCb7HHf py6luOJqqvoYeXZrncOL1gnoxo82ygcynPAZT9bxCBDsNSiJxhAnFsDXNf4fWZ6cEeLuI5j4Gi5 CpkdqcAdfx7zV4agD0ZNp/oeATHEcp5o+rmSjx9pJt1JU5v3iMhFnOjME1p6qJD9o3Ygx/S5Kj/ IUX+GWKrxMhyAappjP72feo6wH6sjOzL2wCmvuyutiMJVcH4pxazXbRKFa5ESBpGdxCWo0Z33LN p/IaKiHoGIHWKu+MYhN0Eg0v+NSkqQvinFNfMK2PCM6drX9WSFXkDwfd21DFJ9GYDk09WnC7Mii jQnz6aBzx2Zq6LDTvFUEQvhQcOLWgRTs6EEkufOWL3r7Zg+WHwPjjolo7oOhCWWGEgSq0nMKyPM D0cV20b4FYjMP9CgaF+co/qpUw+hjdTWt/q7CxYmh+edgXrDbHMWd8kyhIYwvUa1ZJ0zTF6cazv ck6upP3z13DFf8U1GPaxJCd27vPg711R82HpIA+Xau6dLSyWmJ8dMdWg3Oy5PUd+FO9evyt1qvL grf1d+WRrLW5HL6fNF1FALUkQ+YugSEHf/2NLHALX8J+t0dGa1h0r+/tRcCFRf4gzzwPvdm3qrw h3HiV5JYQC4184A== 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: rust-for-linux@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