Re: [PATCH v5 1/3] rust: i2c: add basic I2C device and driver abstractions

From: Danilo Krummrich

Date: Thu Sep 11 2025 - 16:23:52 EST


On Thu Sep 11, 2025 at 5:49 PM CEST, Igor Korotin wrote:
> +pub trait Driver: Send {
> + /// The type holding information about each device id supported by the driver.
> + // TODO: Use `associated_type_defaults` once stabilized:
> + //
> + // ```
> + // type IdInfo: 'static = ();
> + // ```
> + type IdInfo: 'static;
> +
> + /// The table of device ids supported by the driver.
> + const I2C_ID_TABLE: Option<IdTable<Self::IdInfo>> = None;
> +
> + /// The table of OF device ids supported by the driver.
> + const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> +
> + /// The table of ACPI device ids supported by the driver.
> + const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None;
> +
> + /// I2C driver probe.
> + ///
> + /// Called when a new i2c client is added or discovered.
> + /// Implementers should attempt to initialize the client here.
> + fn probe(
> + dev: &I2cClient<device::Core>,
> + id_info: Option<&Self::IdInfo>,
> + ) -> Result<Pin<KBox<Self>>>;
> +
> + /// I2C driver shutdown
> + ///
> + /// Called when

Seems like you did forget to actually finish the comment.

> + fn shutdown(dev: &I2cClient<device::Core>) {

You should also provide a Pin<&Self> argument.

> + let _ = dev;
> + }

Can you please also add an unbind() method analogous to PCI, platform, etc.? It
avoids that people have to use try_access() for accessing device resources on
remove().