Skip to contentSkip to conversation

rust: power_supply class abstraction and SMB347 charger driver

RFC PATCH In review Bruce Robertson 5 participants 11 messages Jul 8 – Jul 26

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover rust: power_supply class abstraction and SMB347 charger driver

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
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/3 rust: i2c: add SMBus byte transfer helpers

The Rust I2cClient abstraction provides device-model plumbing but no way to perform register I/O. Add safe wrappers over the SMBus byte primitives:

- smbus_read_byte_data() / smbus_write_byte_data() wrap the C functions, converting the overloaded s32 return into a Result and confining the unsafe FFI behind the type invariant of I2cClient;
- smbus_update_bits() composes them into a masked read-modify-write, with the bit arithmetic factored into a pure, testable apply_bits().

smbus_update_bits() is not atomic against concurrent callers; this is documented and sufficient for single-threaded probe-time use. A lock will be required before a second accessor is introduced.

---
 rust/kernel/i2c.rs | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
rust/kernel/i2c.rs +42 -0
index 624b971ca8b0..07ce4299ff56 100644
@@ -486,6 +486,48 @@ impl<Ctx: device::DeviceContext> I2cClient<Ctx> {
     fn as_raw(&self) -> *mut bindings::i2c_client {
         self.0.get()
     }
+
+    /// Read a byte from the device register at `command` (SMBus read-byte-data).
+    pub fn smbus_read_byte_data(&self, command: u8) -> Result<u8> {
+        // SAFETY: `self.as_raw()` returns a valid pointer to a `struct i2c_client`
+        // by the type invariant of `I2cClient`.
+        let ret = unsafe { bindings::i2c_smbus_read_byte_data(self.as_raw(), command) };
+        if ret < 0 {
+            Err(Error::from_errno(ret))
+        } else {
+            Ok(ret as u8)
+        }
+    }
+
+    /// Write `value` to the device register at `command` (SMBus write-byte-data).
+    pub fn smbus_write_byte_data(&self, command: u8, value: u8) -> Result {
+        // SAFETY: `self.as_raw()` returns a valid pointer to a `struct i2c_client`
+        // by the type invariant of `I2cClient`.
+        to_result(unsafe { bindings::i2c_smbus_write_byte_data(self.as_raw(), command, value) })
+    }
+
+    /// Read-modify-write: set the bits selected by `mask` in the register at
+    /// `command` to `value`. Bits outside `mask` are preserved. Skips the write
+    /// if nothing changes.
+    ///
+    /// # Atomicity
+    ///
+    /// This read-modify-write is **not** atomic against concurrent callers. Two
+    /// callers updating disjoint fields of the same register can lose an update
+    /// (both read the old value; the second write clobbers the first). Rust's
+    /// safety guarantees cover memory, not device-register atomicity. Until this
+    /// is serialized by a lock (cf. `regmap`, which holds its own lock across the
+    /// RMW), callers must ensure mutual exclusion — currently safe only because
+    /// the single probe path is the sole accessor. FIXME: add a lock before the
+    /// threaded IRQ handler (Phase 4) introduces a second accessor.
+    pub fn smbus_update_bits(&self, command: u8, mask: u8, value: u8) -> Result {
+        let old = self.smbus_read_byte_data(command)?;
+        let new = (old & !mask) | (value & mask);
+        if new != old {
+            self.smbus_write_byte_data(command, new)?;
+        }
+        Ok(())
+    }
 }
 
 // SAFETY: `I2cClient` is a transparent wrapper of `struct i2c_client`.
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [RFC PATCH 1/3] rust: i2c: add SMBus byte transfer helpers

Hi Bruce,

Thanks for the patch. Same feedback I gave Muchamad on a similar patch:
I2cClient should implement the Io trait rather than adding standalone SMBus methods like these -- this was already agreed on previously [1][2].

There's also an in-flight series doing exactly this rework right now:
Muchamad's "[RFC PATCH v4 1/3] i2c: rust: implement SMBus read abstraction via kernel::io::Io for I2cClient". Worth looking at before reworking this yourself, both to avoid landing two competing implementations of the same thing, and because I've just raised a problem with that approach that affects this patch too: overriding try_read8()/try_read16() isn't enough on its own -- the generic try_read/try_write/try_update entry points still silently swallow real SMBus failures (NACK, arbitration loss, timeout) unless every one of them gets the same treatment. Your smbus_update_bits() is exactly the kind of read-modify-write that's affected (my reply on that thread, Message-ID <[email protected]>, has the detailed breakdown).

I'd suggest holding this patch until that discussion settles -- Cc'ing Danilo here too, since it's ultimately a question of whether Io/IoCapable is the right abstraction for I2C at all -- rather than reworking it in parallel.

Cheers
Igor

[1] https://lore.kernel.org/rust-for-linux/[email protected]/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git/commit/?h=driver-core-testing&id=121d87b28e1d9061d3aaa156c43a627d3cb5e620

#3 lore raw

Re: [RFC PATCH 1/3] rust: i2c: add SMBus byte transfer helpers

Quoted 4 lines · Igor Korotin

I'd suggest holding this patch until that discussion settles -- Cc'ing Danilo here too, since it's ultimately a question of whether Io/IoCapable is the right abstraction for I2C at all -- rather than reworking it in parallel.

Please see the reply in [1].

[1] https://lore.kernel.org/all/[email protected]/

#4 lore raw

Re: [RFC PATCH 1/3] rust: i2c: add SMBus byte transfer helpers

In reply to Igor Korotin
Quoted 6 lines · Igor Korotin

I2cClient should implement the Io trait rather than adding standalone SMBus methods like these -- this was already agreed on previously [1][2].

There's also an in-flight series doing exactly this rework right now:
Muchamad's "[RFC PATCH v4 1/3] i2c: rust: implement SMBus read abstraction via kernel::io::Io for I2cClient".

Thanks -- I hadn't seen the prior agreement or Muchamad's series (it ran on linux-iio, which I don't follow). The Io direction makes sense to me, especially given Danilo's point that it's what gets I2C the register!() framework.

I'll drop this patch. No point in two competing implementations, and Muchamad's series is further along the agreed path. When the FallibleIoCapable discussion settles I'll rebase the SMB347 driver (patch 3/3) onto the Io-based accessors it provides.

Quoted 2 lines

Your smbus_update_bits() is exactly the kind of read-modify-write that's affected

Right -- and it may be useful as a test case. Unlike the AS5600, the SMB347 driver is write-capable: it does a config-unlock write and read-modify-write updates of charge-control fields, so it exercises exactly the try_write/try_update paths you identified as unsound if left routed through the infallible backend. I've offered it as an early consumer on that thread.

The power_supply abstraction and the driver (patches 2/3 and 3/3) don't depend on the shape of the I2C accessors, so I'll continue revising those in the meantime.

Bruce

[1] https://lore.kernel.org/all/[email protected]/

#5 lore raw

RFC PATCH 2/3 rust: power_supply: add power supply class abstraction

In reply to Bruce Robertson

There is no Rust abstraction for the power supply class in mainline or rust-next. Add a minimal one:

- a Driver trait carrying the supply's name, type and property list,

    plus a get_property() method;

- a generic extern "C" trampoline the power supply core calls back into, recovering the driver's private data via the parent device and dispatching to get_property();
- a Registration that owns the power_supply_desc and unregisters the supply on drop, freeing the descriptor in the correct order.

Property, type and status constants are re-exported so drivers need not reach into the generated bindings directly.

---
 MAINTAINERS                     |   1 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/lib.rs              |   1 +
 rust/kernel/power_supply.rs     | 133 ++++++++++++++++++++++++++++++++
 4 files changed, 136 insertions(+)
 create mode 100644 rust/kernel/power_supply.rs
MAINTAINERS +1 -0
index 15011f5752a9..8e41f7917825 100644
@@ -21546,6 +21546,7 @@ F:	Documentation/devicetree/bindings/power/supply/
 F:	drivers/power/supply/
 F:	include/linux/power/
 F:	include/linux/power_supply.h
+F:	rust/kernel/power_supply.rs
 F:	tools/testing/selftests/power_supply/
 
 POWERNV OPERATOR PANEL LCD DISPLAY DRIVER
rust/bindings/bindings_helper.h +1 -0
index 1124785e210b..0bdaf7316140 100644
@@ -78,6 +78,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_opp.h>
 #include <linux/poll.h>
+#include <linux/power_supply.h>
 #include <linux/property.h>
 #include <linux/pwm.h>
 #include <linux/random.h>
rust/kernel/lib.rs +1 -0
index 9512af7156df..5013bdd30361 100644
@@ -106,6 +106,7 @@
 pub mod pci;
 pub mod pid_namespace;
 pub mod platform;
+pub mod power_supply;
 pub mod prelude;
 pub mod print;
 pub mod processor;
rust/kernel/power_supply.rs new file +133 -0

133 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer
#6 lore raw

Re: [RFC PATCH 2/3] rust: power_supply: add power supply class abstraction

Quoted 17 lines · Bruce Robertson

There is no Rust abstraction for the power supply class in mainline or rust-next. Add a minimal one:

- a Driver trait carrying the supply's name, type and property list,

    plus a get_property() method;

- a generic extern "C" trampoline the power supply core calls back into, recovering the driver's private data via the parent device and dispatching to get_property();
- a Registration that owns the power_supply_desc and unregisters the supply on drop, freeing the descriptor in the correct order.

Property, type and status constants are re-exported so drivers need not reach into the generated bindings directly.

rust/kernel/power_supply.rs new file +1 -0
+impl Drop for Registration {

rust/kernel/power_supply.rs line 110

Quoted 10 lines
rust/kernel/power_supply.rs new file +10 -0
+    fn drop(&mut self) {
+        // SAFETY: `psy` came from a successful `power_supply_register` and has not been
+        // unregistered. `power_supply_unregister` blocks until no callback is running;
+        // `_desc` (dropped immediately after) is then no longer referenced by the core.
+        unsafe { bindings::power_supply_unregister(self.psy) };
+    }
+}
+
+/// Register a power supply backed by driver `T` against `dev`.
+pub fn register<T: Driver + 'static>(dev: &Device) -> Result<Registration> {

Should this be &Device<Bound>?

Quoted 13 lines
rust/kernel/power_supply.rs new file +13 -0
+    let mut desc = KBox::new(bindings::power_supply_desc::default(), GFP_KERNEL)?;
+    desc.name = T::NAME.as_char_ptr();
+    desc.type_ = T::TYPE;
+    desc.properties = T::PROPERTIES.as_ptr();
+    desc.num_properties = T::PROPERTIES.len();
+    desc.get_property = Some(get_property_trampoline::<T>);
+
+    // Stable heap address; moving the KBox into `Registration` keeps this valid
+    // (moving a KBox moves the pointer, not the heap allocation).
+    let desc_ptr: *const bindings::power_supply_desc = &*desc;
+
+    let cfg = bindings::power_supply_config {
+        drv_data: dev.as_raw().cast::<kernel::ffi::c_void>(),

rust/kernel/power_supply.rs line 133

Quoted 10 lines
rust/kernel/power_supply.rs new file +10 -0
+        ..Default::default()
+    };
+
+    // SAFETY: `dev` valid; `desc_ptr` points into `desc`, kept alive in the returned
+    // `Registration` and freed only after `power_supply_unregister`; `cfg` valid for the call.
+    let psy = unsafe { bindings::power_supply_register(dev.as_raw(), desc_ptr, &cfg) };
+    let psy = from_err_ptr(psy)?;
+
+    Ok(Registration { psy, _desc: desc })
+}

This looks like it should be a ::new() method on Registration instead?

I would compare with existing Registration abstractions and mirror how they do it.

Alice

#7 lore raw

Re: [RFC PATCH 2/3] rust: power_supply: add power supply class abstraction

Quoted 4 lines · Alice Ryhl

rust/kernel/power_supply.rs line 110

Quoted 2 lines
rust/kernel/power_supply.rs new file +2 -0
+/// Register a power supply backed by driver `T` against `dev`.
+pub fn register<T: Driver + 'static>(dev: &Device) -> Result<Registration> {

Should this be &Device<Bound>?

Yes, it should. That also lines up with Danilo's comment on the i2c side of this series that I/O-capable operations need at least the Bound device context. Will fix in v2.

Taking &Device<Bound> also helps with a lifetime problem the cover letter flagged: the trampoline currently recovers the driver's private data via device drvdata, which the i2c core only sets after probe() returns, while power_supply_register() exposes sysfs before that. For v2 I plan to pass the driver data through power_supply_config::drv_data at registration time instead, so the callback never depends on drvdata ordering, and to add a Sync bound on Driver since get_property() can be called concurrently.

Quoted 4 lines

This looks like it should be a ::new() method on Registration instead?

I would compare with existing Registration abstractions and mirror how they do it.

Agreed. I'll rework it as Registration::new(dev: &Device<Bound>, ...) in v2, following the existing Registration patterns in the tree, and look at tying the descriptor lifetime to devres while I'm there rather than relying on Drop ordering alone.

Thanks for the review.

Apologies for slow response. Was wilderness camping.

Bruce

#8 lore raw

RFC PATCH 3/3 power: supply: add Rust SMB347 charger driver

In reply to Bruce Robertson

Add a Rust port of the Summit SMB347 battery charger driver, built on the Rust i2c and power_supply abstractions. The driver binds over I2C, reads the charger's status registers, and registers a power supply that reports STATUS, ONLINE and CHARGE_TYPE to sysfs.

It is the first in-tree consumer of the new power_supply abstraction.

---
 drivers/power/supply/Kconfig                |  14 ++
 drivers/power/supply/Makefile               |   1 +
 drivers/power/supply/smb347-charger_rust.rs | 180 ++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 drivers/power/supply/smb347-charger_rust.rs
drivers/power/supply/Kconfig +14 -0
index f0ede1cecb6a..b6521c86b47c 100644
@@ -875,6 +875,20 @@ config CHARGER_SMB347
 	  Say Y to include support for Summit Microelectronics SMB345,
 	  SMB347 or SMB358 Battery Charger.
 
+config CHARGER_SMB347_RUST
+	tristate "Summit Microelectronics SMB3XX Battery Charger RUST"
+	depends on I2C
+	depends on RUST
+	help
+    Say Y to include support for the Summit Microelectronics SMB347
+    battery charger, implemented in Rust. The driver binds over I2C
+    and reports charging status, online state and charge type through
+    the power supply class. It is a Rust port demonstrating the
+    in-tree i2c and power_supply Rust abstractions.
+
+    To compile as a module, choose M here; the module will be called
+    smb347-charger_rust.
+
 config CHARGER_TPS65090
 	tristate "TPS65090 battery charger driver"
 	depends on MFD_TPS65090
drivers/power/supply/Makefile +1 -0
index 31fe4a145929..96616fb381a9 100644
@@ -109,6 +109,7 @@ obj-$(CONFIG_CHARGER_BQ256XX)	+= bq256xx_charger.o
 obj-$(CONFIG_CHARGER_RK817)	+= rk817_charger.o
 obj-$(CONFIG_CHARGER_S2M)	+= s2m-charger.o
 obj-$(CONFIG_CHARGER_SMB347)	+= smb347-charger.o
+obj-$(CONFIG_CHARGER_SMB347_RUST) += smb347-charger_rust.o
 obj-$(CONFIG_CHARGER_TPS65090)	+= tps65090-charger.o
 obj-$(CONFIG_CHARGER_TPS65217)	+= tps65217_charger.o
 obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o
drivers/power/supply/smb347-charger_rust.rs new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
2.43.0
#9 lore raw
In reply to Bruce Robertson

Hi,

Quoted 3 lines · Bruce Robertson

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,

Having Rust bindings for new drivers sounds good to me.

Quoted 2 lines

and a Rust port of the Summit SMB347 battery charger as the first consumer.

Any reason for Summit SMB347 specifically? I would prefer not to have two drivers for the same hardware. Looks like this is used by just three relatively old devices:

rg -l '"summit,smb347"' arch arch/arm/boot/dts/ti/omap/omap4-samsung-espresso10.dts arch/arm/boot/dts/nvidia/tegra30-asus-nexus7-grouper-common.dtsi arch/arm/boot/dts/samsung/exynos4412-p4note.dtsi

All are ARM32 based, so Rust is at least available by all users. So I suppose replacing this C driver would be an option, OTOH I don't want to motivate people to rewrite things either :)

Quoted 9 lines

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.

Quoted 7 lines

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.

A new driver supporting CHARGE_TYPE should also support CHARGE_TYPES.

Quoted 6 lines

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.

If the idea is to just have a user for the Rust binding and something to test/play around: Maybe convert test_power instead? It would also decouple the power-supply Rust bindings from I2C/SMBus. The disadvantage is, that this driver is a special-case, since it has no parent device :)

Greetings,

-- Sebastian

Quoted 44 lines

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
Signature · 1 line
2.43.0
#10 lore raw

[Resent as plain text -- my first attempt was rejected by the vger lists for containing HTML, so it reached only the people Cc'd directly. Apologies to those of you getting this twice; please reply to this copy, as the first one never made it to the archives.]

Quoted 1 line · Sebastian Reichel

Having Rust bindings for new drivers sounds good to me.

Thanks -- good to hear. That was the part I most wanted confirmed before putting more time into it.

One status note first: patch 1/3 (the SMBus helpers) is dropped. Igor Korotin pointed out that I2cClient is meant to implement kernel::io::Io rather than grow standalone SMBus methods, and there is an in-flight series from Muchamad Coirul Anwar doing exactly that [1]. The SMB347 driver will consume those accessors once they land. Patches 2/3 and 3/3 are unaffected -- more on that at the end.

Quoted 2 lines

Any reason for Summit SMB347 specifically? I would prefer not to have two drivers for the same hardware.

I wrote the C one. drivers/power/supply/smb347-charger.c came in via commit ed1a230f96eb ("Add I2C driver for Summit Microelectronics SMB347 Battery Charger.") in v3.4, back in 2012, and the file header still carries my name. So this is me porting my own driver rather than a drive-by rewrite of someone else's -- which I think also speaks to:

Quoted 3 lines

All are ARM32 based, so Rust is at least available by all users. So I suppose replacing this C driver would be an option, OTOH I don't want to motivate people to rewrite things either :)

Agreed on both counts, and I don't want two drivers either. Replacement is the goal. But I should be straight that the RFC is nowhere near it yet: the C driver is ~1640 lines, the Rust one is 180, with three properties, no IRQ, no set_property, no OTG/regulator support and no DT charge-parameter configuration.

Two things I can do in the meantime:

- Make the two mutually exclusive in Kconfig so that no configuration ever builds both. For v2 I was planning the ax88796b arrangement -- the Rust option as a bool modifier on CHARGER_SMB347 with the Makefile selecting the object -- rather than a second tristate.

- Build-test ARM32. So far I have only built and run this on x86_64 against i2c-stub; I don't have any of the three boards.

What would you want to see before the C driver could actually go away -- parity against a specific feature list, a hardware test from one of the espresso10 / nexus7 / p4note users, a deprecation cycle? I can aim at whatever the bar is, but I can't self-certify a swap on hardware I don't have.

Quoted 1 line

A new driver supporting CHARGE_TYPE should also support CHARGE_TYPES.

Happy to add it. One question on how it should map here.

Reading the ABI and the in-tree users, charge_types is read-write: the supported set comes from the desc->charge_types bitmask, the active one from get_property, and writing selects an algorithm. On the SMB347 the charge type isn't selectable -- the progression from trickle/ pre-charge through fast to taper is autonomous hardware state that the driver only reports out of STAT_C. That is why the C driver has never had a set_property or property_is_writeable at all.

So: would you want CHARGE_TYPES exposed read-only here, with a Trickle|Fast|N/A bitmask and the active value from STAT_C? Or do you consider a read-only CHARGE_TYPE to be exactly the mis-modelling that CHARGE_TYPES is meant to replace? I'll follow whichever you prefer.

Either way it lands on the abstraction rather than just the driver:
desc->charge_types is a descriptor field, not a property callback, so the Rust Driver trait needs a way to express it, and the writable case needs set_property and property_is_writeable plumbed through. Those were on the cover letter's future-work list; this moves them up.

Quoted 3 lines

If the idea is to just have a user for the Rust binding and something to test/play around: Maybe convert test_power instead? It would also decouple the power-supply Rust bindings from I2C/SMBus.

The decoupling is already there, as it happens. Patch 2/3 touches only MAINTAINERS, rust/kernel/lib.rs, rust/bindings/bindings_helper.h and the new rust/kernel/power_supply.rs -- no I2C dependency at all. It is only the driver in 3/3 that consumes both. And with 1/3 dropped, the SMBus layer leaves this series entirely.

Quoted 2 lines

The disadvantage is, that this driver is a special-case, since it has no parent device :)

That is the part that gives me pause about it as the *first* consumer. The open question I flagged in the cover letter -- how the get_property trampoline recovers the driver's private data -- is specifically about the parent-device path, and it is what reviewers have pushed on most. A consumer with no parent device wouldn't exercise it at all, so I'd risk shaping the abstraction around the special case.

For v2 I'm moving the private data into power_supply_config::drv_data at registration time instead of recovering it from parent drvdata, which removes the ordering dependency Alice and I discussed [2] -- and that is also what a parentless supply would need. test_power becomes straightforward once that's in. I'd be glad to do it as a second consumer on top; I'd just rather it not be the only one.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Bruce