From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DCF83F7A86 for ; Wed, 8 Jul 2026 21:48:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783547308; cv=none; b=bJXVJ0FKCCD/Sslgk154YcN4C9w4K8W9QgxtdFyJtKQbOstGabp4S7K3esaSL1XgVlXkmmUMvqsDn15WRkclFNmPD99WTYVmbZHHQws+S/zweRaRbR3ZHhn/1U2EuqjXWh6oFRbtrHCc0PcnUbpQhuPcoEJSBrk7LgTIcRK6K4U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783547308; c=relaxed/simple; bh=7KJXJzo+UE0xE9qAQMsWzVrOorS//UfnfERkBCDL37I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZkiysacffbNT+sZrdDjVILGCaGSM0F1whTuGr8CcbKNISL9Le39u6qi/pqJYcZyHiJYo96AOUIUVFMQ61yY6ssAqenl1kSXb47NSQM6WG3EwR+M+3JiGy85dFz47FoayCxFimYsabXe+B8V5gMMdxa8Bbtqlgy6QL2jV41NPghk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dbUi5dYO; arc=none smtp.client-ip=209.85.214.181 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.b="dbUi5dYO" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2c9b1edf2bdso17646235ad.1 for ; Wed, 08 Jul 2026 14:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783547306; x=1784152106; 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=ws9RhF/v+RDUhCzwrIsuIgwDdl54OneaRZCtnhDgCNo=; b=dbUi5dYOv74sX1ph2QjqwrH2P1X6X+GyipaScdiG0ElDNBVvZxmbO1qtkb07nDvSVe SRxWkQaUqOcF3+wBYpIeVoSIz7nNpQXsHPfBo82MP6zmqeFc4CWHM+TwSJkozKhQ40qP /KKxm57d7pJiZgJiZjY7kmmDUhFMP+vJTQLyVeOW8AnPgCIZ8INQWyVUOlp8DFSt7BeT YwU7p90uTGLNybComwoe7OcG+652A7bRxLJy2G3Q8QiT4fEuE4BkDdDZ6bKDOr1SHqkc r2Zr/O/T31zZltLZVxnDH2Z+iN9UAbmUmywYAjpJtr812j3ES0bwCoTIynwmj+cJQSu4 ErPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783547306; x=1784152106; 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=ws9RhF/v+RDUhCzwrIsuIgwDdl54OneaRZCtnhDgCNo=; b=Q1ZmSzJu+7LIIYF/MrZGfYu5d/B5FvwcCD7PANOxRMke+/PsiZ4xj6JZGBHvZhEkfm uxncP/7J+79I+Em4jpuGOFmTQob2ytQ10bJPV0lsiMU1oT2Cmv1BLGVXXF/qc+TOKUJs wuNiZa19knDIqnfX4B2B/f0KXaRxQFwGAkuGydBiXlIpk7MumYg3lLvChRwQKfT140cV CoQNvQSjR/zruUFkf7tvZjcFt+l7ZCSENotdbh/+cdH4QLwiTiypAW/9SuHw8WBw1sNR NBwFRJoMqkVz6go45JI0XG9uJi1toplu6nmicMzsInFWqPWC2fxqdYHqyrxwcLofxy7h GL5Q== X-Forwarded-Encrypted: i=1; AHgh+Rqo7qbihSWC3b1ubzoDda1HHf5toom4Ox2VNjTSDlgsBGLAioOL8uQCvQ7EmarajX+qQFqqPhSs2G9z3Ak=@vger.kernel.org X-Gm-Message-State: AOJu0YxIF3KoJ7UJt5EwDjGEd3dgpvPVeQleUrxoAEUF2Diqq0qnXG57 +L4LgBq11yzk2I2BFC5EJ2as2b0dpRlHIFrKmm/ADdBFAVQ0jsyzs921 X-Gm-Gg: AfdE7ckMrvtvJeM10KwoST6vCO295fXkmhLt8y4fykLfXU+xODuW+kkuGoesSCA7ilq 7TETfumW0QIYEwGRQqSz4slvtA8JHW4or69jakCvh8B4dLs4AnOeO37VtoqgC3dgRUPzL4zW8hd Gqin95eNgEtQg14LEmf1GnLNhIKTiuZAsZbUMWIuud3QAcqgk+vysqkRwoGt94j+MH9ZbS+DhDF eqHEga45QfSg5D8S9n1TnL9AXEAsvyurWuLf+rsfOpEbYeFfcyRPJuqllO/uT5lilmF92lLXnHY +rav9jJpPu2x9CQJQmNrzsw6zTVNb8hadNOX80TUfN9kQ0KyKZKHE69d69wYvlok/2buAWH8VZO y/iCyTMafm0DzOKL4CNdVCnToaROweX2g89AESgYYOwmVSYKFQ2n0+cLXBbB/COFw9ROvEmwzNl MstcNQD6dfwmLVW+NQmWWJS+2XyE6nYLr9mlxoFGhEe25G9XMrhwb9/Bb2INsWSrbfIlFHNVgZj 4veb7WCnS/GnhgiprNaAeJ+iKoAK+ZjPQYMmJrn2xauEHxp7xWvFZm0faK3CiSTBb8NwgXxHq1H nYp8dfJFugJj3FXFuWzh9PF9MBrZOtLPAh/p1e+0nNea4eYY4Xkwwru4ce9t5iRcCiSXB57Y X-Received: by 2002:a17:903:987:b0:2c7:f2c6:89e0 with SMTP id d9443c01a7336-2ccea35ad78mr48716195ad.4.1783547306454; Wed, 08 Jul 2026 14:48:26 -0700 (PDT) Received: from ip-172-31-21-198.us-west-2.compute.internal (ec2-35-85-29-74.us-west-2.compute.amazonaws.com. [35.85.29.74]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9d3d946sm33733855ad.66.2026.07.08.14.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 14:48:25 -0700 (PDT) From: Bruce Robertson To: rust-for-linux@vger.kernel.org, linux-pm@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sebastian Reichel , Miguel Ojeda , Igor Korotin , Gary Guo , Tamir Duberstein , Alice Ryhl , Boqun Feng , Bruce Robertson Subject: [RFC PATCH 0/3] rust: power_supply class abstraction and SMB347 charger driver Date: Wed, 8 Jul 2026 21:47:35 +0000 Message-ID: <20260708214738.25008-1-brucer42@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series adds a Rust abstraction for the power supply class -- which does not currently exist in mainline or rust-next -- together with the SMBus helpers needed to drive an I2C charger from Rust, and a Rust port of the Summit SMB347 battery charger as the first consumer. Motivation ---------- Rust drivers for power supply hardware are currently blocked: there is no safe Rust interface to the power supply class, and the I2cClient abstraction exposes no register I/O. This series provides a minimal, self-contained path from binding an I2C charger to reporting charging state through sysfs, entirely in safe Rust, with the unsafe FFI confined to the two abstraction layers. The series is structured abstraction-first: 1/3 Safe SMBus read/write/update_bits over i2c::I2cClient. 2/3 A power_supply Driver trait, a generic get_property trampoline, and an RAII Registration that owns the descriptor lifetime. 3/3 A Rust SMB347 charger driver consuming both: it binds over I2C and reports STATUS, ONLINE and CHARGE_TYPE. Testing ------- Built and exercised against an emulated SMB347 using i2c-stub: seeding the chip's status registers and reading back the corresponding sysfs attributes (status, online, charge_type) confirms the full C->Rust->C path. No physical hardware or interrupt path has been tested. Open questions / known limitations (hence RFC) ---------------------------------------------- - get_property recovers the driver's private data via the parent device's drvdata. The current code relies on the observed ordering (callbacks only fire after probe() has set drvdata); the contract should be made explicit. - smbus_update_bits() is not atomic against concurrent callers; a lock will be required before a charger IRQ handler is added (not yet implemented). - Only get_property and a handful of properties are wired up; set_property, property_is_writeable and the IRQ-driven power_supply_changed() notification are future work. Feedback on the abstraction's shape -- especially the descriptor lifetime and the drvdata recovery -- would be very welcome. checkpatch emits one MAINTAINERS warning on patch 3/3 (new driver file); it is a false positive -- the driver is covered by the existing POWER SUPPLY CLASS "F: drivers/power/supply/" glob and needs no new entry. Patch 2/3 adds the one file outside any existing glob (rust/kernel/power_supply.rs) and updates MAINTAINERS accordingly. Based on rust-next (v7.2-rc1). Bruce Robertson (3): rust: i2c: add SMBus byte transfer helpers rust: power_supply: add power supply class abstraction power: supply: add Rust SMB347 charger driver MAINTAINERS | 1 + drivers/power/supply/Kconfig | 14 ++ drivers/power/supply/Makefile | 1 + drivers/power/supply/smb347-charger_rust.rs | 180 ++++++++++++++++++++ rust/bindings/bindings_helper.h | 1 + rust/kernel/i2c.rs | 42 +++++ rust/kernel/lib.rs | 1 + rust/kernel/power_supply.rs | 133 +++++++++++++++ 8 files changed, 373 insertions(+) create mode 100644 drivers/power/supply/smb347-charger_rust.rs create mode 100644 rust/kernel/power_supply.rs -- 2.43.0