On Fri, Mar 26, 2021 at 7:01 AM Viresh Kumar viresh.kumar@linaro.org wrote:
On 25-03-21, 17:16, Arnd Bergmann wrote:
On Wed, Mar 24, 2021 at 8:33 AM Viresh Kumar viresh.kumar@linaro.org wrote:
+static uint8_t vi2c_xfer(VuDev *dev, struct i2c_msg *msg) +{
- VuI2c *i2c = container_of(dev, VuI2c, dev.parent);
- struct i2c_rdwr_ioctl_data data;
- VI2cAdapter *adapter;
- adapter = vi2c_find_adapter(i2c, msg->addr);
- if (!adapter) {
g_printerr("Failed to find adapter for address: %x\n", msg->addr);
return VIRTIO_I2C_MSG_ERR;
- }
- data.nmsgs = 1;
- data.msgs = msg;
- if (ioctl(adapter->fd, I2C_RDWR, &data) < 0) {
g_printerr("Failed to transfer data to address %x : %d\n", msg->addr, errno);
return VIRTIO_I2C_MSG_ERR;
- }
As you found during testing, this doesn't work for host kernels that only implement the SMBUS protocol. Since most i2c clients only need simple register read/write operations, I think you should at least handle the common ones (and one two byte read/write) here to make it more useful.
I am thinking if that is what we really want to support, then shouldn't the i2c virtio spec be updated first to support SMBUS type transfers as well?
As far as I can tell, all the simple devices should just work, with I2C_FUNC_SMBUS_READ_BLOCK_DATA being the main exception, but it seems that has practically no users.
Arnd