Is there any way to read/write more than 32 bytes on Linux based SMBus interface?

1.3k Views Asked by At

I am trying to access an I2C based device through SMBus ioctls on Linux. I need write more than 32 bytes. I2C_SMBUS ioctl limits the size to 32 bytes. The underlying driver does not support I2C_RDWR ioctl and direct read()/write() calls. I have also tried byte by byte R/W but it does not work for me.

1

There are 1 best solutions below

0
On

You'll need to use I2C_RDWR. The smbus functions have a hard-coded size. Not only in the userspace i2c-dev driver, but also the kernel function i2c_smbus_xfer(), which is passed data as a union i2c_smbus_data.

The SMBUS spec is limited to 32 bytes. So it's possible your master does not support writing more than 32 bytes at once, if it is only design to support SMBUS.

What you'll need to do is look at the specs for the master hardware and see if it can support > 32 bytes. If so, you could extend the driver to support generic I2C messages and then you could use I2C_RDRW.

A generic I2C xfer method (algo->master_xfer() for I2C vs algo->smbus_xfer()) is used only if the driver doesn't have an smbus specific method for an operation, so you can add a generic I2C xfer function as a fallback for operations that aren't already implemented. The generic I2C xfer method doesn't have to support every possible I2C transaction. Just support the one you need.