0

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.

tsk
  • 1
  • 2
  • 2
    Maybe this helps: https://stackoverflow.com/a/25984891/12548337 – jerch Dec 27 '19 at 01:02
  • 1
    Good find @jerch. Possible duplicate of [Why I2C\_SMBUS\_BLOCK\_MAX is limited to 32 bytes?](https://stackoverflow.com/questions/25982525/why-i2c-smbus-block-max-is-limited-to-32-bytes) – jww Dec 27 '19 at 01:29
  • read/write system calls are not working on this device due to the driver limitation. They are returning EOPNOTSUPP error. – tsk Dec 27 '19 at 01:56
  • Please show the relevant code and state the exact problem or error. A description alone is not enough. Also see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww Dec 27 '19 at 01:58
  • If you have to rely on kernel buffering you cannot bypass the 32 bytes limit as it is specified as such and hardcoded in https://github.com/torvalds/linux/blob/6f0d349d922ba44e4348a17a78ea51b7135965b1/include/uapi/linux/i2c.h#L134 – jerch Dec 27 '19 at 02:10

1 Answers1

0

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.

TrentP
  • 4,240
  • 24
  • 35