Re: [PATCH 4/5] rust: i2c: add I2C wrappers

From: Igor Korotin

Date: Sun Feb 08 2026 - 07:45:10 EST


Hello Danilo

On 2/4/2026 4:59 PM, Danilo Krummrich wrote:
On Wed Feb 4, 2026 at 5:49 PM CET, Igor Korotin wrote:
I'm not sure it is appropriate to use IO and register! here. I2C devices
are different. Not all of them use register like access. For example
EEPROM I2C devices allow random read/write operations inside their
address space. After all I2C doesn't implement the same way of accessing
its memory space as for example PCI devices.

Conceptually, it is not different, it is some device memory connected through
some bus.

Memory mapped I/O allows "random read/write operations" as well, see
memcpy_fromio() and memcpy_toio().

The same thing is true for DMA memory. While it's not owned by the device, it's
still shared with a device.

Gary just started working on a generic IoView<'io, T> type which will serve as a
general abstraction to interact with any kind of memory that is shared between a
device and the CPU [1].

So, for I2C this would mean that if you have register like accesses you can use
the register!() abstractions. If you want random read/write operations, you can
use IoView to copy from / to system memory or even to a user buffer directly.

Of course you can also still use Io::read32() and friends.

[1] https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Generic.20I.2FO.20backends/with/571786051

thanks, that makes sense.

I don’t have a strong prior opinion on how this should look yet, so I’m fine aligning the I2C abstractions with the generic direction you describe. Using register!() for register-like accesses and IoView for more general read/write patterns seems reasonable.

At this point I’ll treat this as the intended model and adjust the I2C side accordingly once IoView is in place and its API settles.

Regards,
Igor