From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144118; b=PeSNRWXGUeQU1JqRBVbvt7SzZeelW0p/n1YaMGfwibUtOBc/ckuPxbjP14bbs9X7klQF iJo90KVqvEvw2qJAUTJwEKD87UPLvcuzioM46EpGZJg1fbhx6pwQ4VpEEbqsK9C7L5mXk W+iqQ5TbL+vW1QRtQMxI4SOaJ40B2tfioxSt0G/8ovKJSt36mC8twO/t6mRSV9q9n5eOR x4AS6gvyZLPcV9iBof9eBoSDryFvza9AoO0Fw/HjiUIt6VIEKiudqc9k4DhhzOiJoradU 4ORhQTFklo6KXLwp9JhweT1EVpNJci9Ui30MQ13i2GgZZ6Vd0w0hVhUKs0hNOsgPYJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144118; 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=AjC2udAgifd5a/qVbFIuAbBf3F7vM/y1Pm6pooQxa4Alh8tvq+k1ybjch538nHsmGPSv tqL0JPzQ9q7kP3G5OthWhS/TcIyCwQ9dgiGuvdJep5+BY0EQmnKwM0DHiHlxkHrY5H6M4 nxWylMPyKSNVt7fzPOdSgUrk37bTGljvEBGxBueFQRCqMdLJpdlvTl9W9SYlWhfFMwIWW sxapGPqkZKL3/hYH1V6USeHNEY6W+Jdyf5yqx3y1xJBEtwCjw+0H7fWFhMTMMF7rwHrwU 6rGc7olLrkOBFh2YW4dHra3IwnKsERzxtU1KXlYsi9IEtwrHHeVwKSE3Iadkk22/OLw== 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.170 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 5EC47606A68F for ; Tue, 1 Dec 2026 16:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5EC47606A68F 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-f170.google.com with SMTP id 41be03b00d2f7-cd62c570b5dso8020603a12.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=dsBKO4sSHGZJYgCPr4KXvtubCjIQ60ZPzuHGzept7pSdqWjMvyTl/uHwt05H1i7zab BvoScxetdbLP8YBXY/o7dzoBRT8SDkFw7r3jYLpHrZZdkrpz2+lF0HAk/ZHVriyQqBqj xdCPm4dod6xCVbgB3Dm7t/ohNM7uTI3tpno3xyxv96rtc8Nv/M+K5czYTmEPDzQvcX0c TKQ2JG7nyK+Ts5u0CXYXtsKaotSGyxT2PsfY3X8hjDYZvEXDrshFUb+nX47zhyOL968u cViWnvtQHnWoY5G78VG6J2flORXdnYSVLEKEnZweObnCUtf/Y4JrKyVU2O0ji5LY481B 0b6g== X-Forwarded-Encrypted: i=1; AL+hErGkzCxMU8EylzjrAg+n+Bm8oEcFzQSam60ZVsbDqblhA08S86GC9Z3BV29gwFUxwcrc4s4icWfXKL8Ma00=@vger.kernel.org X-Gm-Message-State: APuU4Z94+AaBqR8cXbnVP+RaftQumR4sdDhh3m702mDqKPL73wGdDSHf QYzm2+50H94+fwtFEMJC0l4bEsOu+8k0jcomDTwAYTp40zyosBNykb2V X-Gm-Gg: AZFdTZd0UuONneljZkvfztzXsWNYphIsnXQgNpRKZxJyTFO8a/S9FD6PUxmd1OHdOjh EyNajLlLhyXnZcUQIc35BrBss/EQh+i8dK4kAUGHIUJtKuKbjwp0Q68MudQ4rq8RzgFjRjGGl8y UKM2Xgjwr4SXlFNm3+OwN5YGQ8ERhI/KGc8iKfp2l6lEGducdVhpstu7UMVYQouUdaw0dMRRrgD boRo0+bz0esTUoCJKIaNnSDzO9eIfq6Pe85zP3pN8pkEdHaOVzQ5M6qSNq5BpnRBvYahrc5MFWp u7zRnohzhOL76F24huAJzb4tTmc2DgPMb4MN5feNIw7DkSZRkP/vTy3AVF9tNFkME/7ZY+kmCvu fMkL+FXZzmVzdMYWNbMKNJb+kPPU8xUeiwl24EQD8oaNfYLrD8NLcG21kWAzJ2fiE6Ald70itnb phEluBvAV1AI+9ex/TIpVg3QSPlZ2zYdml0zC3G1k8FlQdk9TuTCKrl8CE+nI1Lne2uwMig7cGj re0kZ9aZox2BXDxGA/HfaJ5V0rYzNAsKK+f0M92mk9xrGak9k00s3IeI7o3/lMNbf5Vv+CVlLxn LNtWsCMrA/PeoO53ZZuj0fpTeFp6GXv81sLuy0HyPIRcDGSq4BxcVksh/fUH/F8mr/HkPyo2rB/ LxcJ6Xh6ZnlYC/Q== 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-kernel@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