Re: [PATCH v6 2/3] rust: i2c: Add basic I2C driver abstractions

From: Danilo Krummrich
Date: Sun Nov 02 2025 - 13:02:18 EST


On Sun Nov 2, 2025 at 6:45 PM CET, Igor Korotin wrote:
> Hello Danilo
>
> On 10/27/2025 10:00 PM, Danilo Krummrich wrote:
>> It's called from other drivers (e.g. DRM drivers [1] or network drivers [2])
>> that are bound to some bus device themselves, e.g. a platform device or a PCI
>> device.
>>
>> This is the device that we can give to i2c:Registration::new() and use for the
>> internal call to devres.
>
> After the recent change where i2c::Registration::new() returns impl
> PinInit<Devres<Self>, Error> instead of Result<Self>, I’m unsure how to
> adapt the Rust I2C sample driver. The sample doesn’t have a parent
> device available.

Indeed, and that's a good thing that this doesn't work now. :)

I think the best course of action is to make the sample driver closer to a real
driver.

For this you can do what the debugfs sample (samples/rust/rust_debugfs.rs) does
and use a platform driver with either ACPI

kernel::acpi_device_table!(
ACPI_TABLE,
MODULE_ACPI_TABLE,
<RustDebugFs as platform::Driver>::IdInfo,
[(acpi::DeviceId::new(c_str!("LNUXBEEF")), ())]
);

or OF

kernel::of_device_table!(
OF_TABLE,
MODULE_OF_TABLE,
<SampleDriver as platform::Driver>::IdInfo,
[(of::DeviceId::new(c_str!("test,rust-device")), Info(42))]
);

and then create an i2c::Registration from platform::Driver::probe().

- Danilo