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=1796144118; b=f0TmxCmDUqnKoZrsN0Nj6EST8mBsno16hyBTzsN2YEMckoWcydBiL3dRPJNlpOLdyRWW +CWM3+gnJKO01QfMj94zmElgcaRBfcvprQg0TvwUGILwi38GwJjdfehryLLXskDPR/TG7 /r+GRq2m5ub4jDuyY+Vuy1t05f9VCN2pjhboVfAP/NsaLHH57SdlHaC7C2gbpWSlpsl98 hclFyyD8yXRLZiHqOBG/zlE6svkAEmEQF2xLV8+rbYYu7ZVFJaJj2NdbNcuheGB78Swln op5w782D3nnq38ef3jfwpvj6nKLFCJv6zwWG375vYym0H6ncB5cBkfwT9YF0VGyYM6A== 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=ZYD3NsiAkfF1916rVkb4hskVEGiiZk7WRzQUS1ssnjqnrVJxGmz7SVUvQZpaxlMYSdkr HJfdJ2GBTnjZQR/kSKgLH9z70LT6ZEKNX9q+Fh8SVU/qR0THULDpFu4klmeGkWz1J3ky5 jXXlK9EX9oxzsQ1kTX7aEcqI09rufpyQB2FCrJgOLvhOkJ/MK6G7fbMw4lBuzNZbRLMJ4 /sDSweM4PTqZMuy6lcPDkVCdWX7n3vRIVLIlSDIQiiuREUbnlSBY5pyYezg5864Euqsrb xpS2AD7/jX959rG5Q5+hbJymKGj4CNmNF9lThdO8eBOiBufJ6MrqOPkuwZZRw25yGCw== 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=FD4+m5y0; 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 65B2A606A69B for ; Tue, 1 Dec 2026 16:55:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65B2A606A69B 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=FD4+m5y0 Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cd60c5da24cso7038270a12.0 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=lists.linux.dev; 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=FD4+m5y0Q/6tQ5VPiCLvdKQeSQI+0+MAWwd6jaTk3ImsAqBoVQHKZVA0cDOml048A+ YPXpG+v9bHKLEBkXQYPwGSCVpUyG89JzYxcVbYIBMbfs7TTTFTYoBvUWPvRsE0gZmQFc 5H5TkFXlyZDE9M/aOTydEcirF6Mp8ayYjoajvSNl47LBw4sQNCHB+6aywBt3wNRjAusc ptNeZJMgiEsaYSgpj7K4K294I1am2/AOvdEKs8TYKrMD100FpEU25xU0W+2J3/O5C53F HxS3qiF2Prba/cO76UbJbmL1r4Zw2S+YqeX5mNoO76rWvGdyXc8sjZsPxF2PJofBCAG9 IzBg== 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=drGakC63xFqm4ES/FQRbHt8nyRTetLdyAsyK3ldGFRgVOnqfxWoqEm4C1lAqRfcnWA YLqcWuT1JdDF8oBdy8UK6x/CX+vT2QBBrtPu4IbP9PBCWSv/Yww7d4sN0UEGqz8crmD1 8z0t4KuKzjMxtaUBJJWo6wTqEjlLHlIfXOgiP+vdhzfIsML25w3QJvkhVjJ1sBWNKWnW ssLeqm+Iza1Xk3m09w2CEnsSp44t7J/LLvTiUfoi7aftg8s3I3AHtckdGobNikP44TXt GriVYEZDnYTlDhfZzLgRaGPcvKtH0ZovZb+eTynBmOgSeb4yGEeugXsAsO1aqTTpCMmE iYFg== X-Forwarded-Encrypted: i=1; AL+hErHebCY3kqdryxmNjaXu3PxSDJvxTDC2ipTKMdDhgq5GJ0xCmSMrW1ytsSIcpOXjIOLWlBjjXLcStUQGPA==@lists.linux.dev X-Gm-Message-State: APuU4Z9GV4Ohdd7D7St4FEOwBSh+JsfhxoyWK4Ipla9KMwZSXOvxZQdJ W82cAT/MF3unSs8VU5xWSe6Km1Igpwk2lF2FFJhTg4nU5MoKH4BUXH+j X-Gm-Gg: AZFdTZesiWK6+dP8POwmCiYjY9+fc1OQQzwnc65y4xa5o4i7pt5qy9ydjGJxUQwQIsO egP1Xk4+fe1CyhQiaV+a66qWDWwUuVTLY0XtzOle/obUDnM1zLU2jWvMMd7OVzAEYFCRK8HBslA vGuoI5ryUsVbhZMSddONfGkqzwRW78BzBmM0gYKiOIah1dqZXzU1jydfiWrSrF6mETSbz2vHowx g0+zBs4+WeK7OGmwko5A7GpbajmSchwNaiDveoeOhOJZDTpZHfiw8UvwsC66Nd13iLzxe3r/hJA 5gjILjEMSQrkedLwK7f6+2bQ36DCpSDlP7wOXfxi+NYN6tUu5KC32NLZDNbIaQf3/PyMFd2Hn7l JnAbpUwJzpFCX/WGpEi31bjJutjGy4vuOvOriekk0wsB69W/08IsOdJ5ZXTBy8HKnBOmIRwOCYK KyVolQSbL14DsyPSwGH3bOF1gxk0Pnv+HLA3THBAiw+JerEQg5VZlq8Mq1ODImENq7olZflHEuB u2al+gv7TOfNyw33iHE+Z/pI1A+U71ENPgs07UgEfUr66Uk8ja6bAKZvKwe9VPtc/6TJ+41E8Qp 4GnM8ksWw/oSn9XphR5Fohl6mXKj9lF58fTjvHqXxrQrHkKVMnlh7S93nLioqWBqDMPOw/OJpD8 EzRVLP86WEjfE/g== 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: driver-core@lists.linux.dev 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