diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2025-05-22 10:09:55 +0200 |
---|---|---|
committer | Hans Verkuil <hverkuil@xs4all.nl> | 2025-06-17 10:35:15 +0200 |
commit | 1cb109d8863da75c22458b90c43b4e61b994e332 (patch) | |
tree | 17d100c63e738eae96f0efed2259e003228facc7 | |
parent | b5ae5a79825ba8037b0be3ef677a24de8c063abf (diff) |
media: usb: hdpvr: use I2C core to handle only supported messages
The HW can only do write-then-read transactions. This is a common
limitation, so we can add an adapter quirk flag to let the I2C core
enforce the checks instead of open coding them.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
-rw-r--r-- | drivers/media/usb/hdpvr/hdpvr-i2c.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/drivers/media/usb/hdpvr/hdpvr-i2c.c b/drivers/media/usb/hdpvr/hdpvr-i2c.c index 54956a8ff15e..9eacc85e3f11 100644 --- a/drivers/media/usb/hdpvr/hdpvr-i2c.c +++ b/drivers/media/usb/hdpvr/hdpvr-i2c.c @@ -124,32 +124,12 @@ static int hdpvr_transfer(struct i2c_adapter *i2c_adapter, struct i2c_msg *msgs, else retval = hdpvr_i2c_write(dev, 1, addr, msgs[0].buf, msgs[0].len); - } else if (num == 2) { - if (msgs[0].addr != msgs[1].addr) { - v4l2_warn(&dev->v4l2_dev, "refusing 2-phase i2c xfer with conflicting target addresses\n"); - retval = -EINVAL; - goto out; - } - - if ((msgs[0].flags & I2C_M_RD) || !(msgs[1].flags & I2C_M_RD)) { - v4l2_warn(&dev->v4l2_dev, "refusing complex xfer with r0=%d, r1=%d\n", - msgs[0].flags & I2C_M_RD, - msgs[1].flags & I2C_M_RD); - retval = -EINVAL; - goto out; - } - - /* - * Write followed by atomic read is the only complex xfer that - * we actually support here. - */ + } else { + /* do write-then-read */ retval = hdpvr_i2c_read(dev, 1, addr, msgs[0].buf, msgs[0].len, msgs[1].buf, msgs[1].len); - } else { - v4l2_warn(&dev->v4l2_dev, "refusing %d-phase i2c xfer\n", num); } -out: mutex_unlock(&dev->i2c_mutex); return retval ? retval : num; @@ -165,9 +145,9 @@ static const struct i2c_algorithm hdpvr_algo = { .functionality = hdpvr_functionality, }; -/* prevent invalid 0-length usb_control_msg */ +/* prevent invalid 0-length usb_control_msg and support only write-then-read */ static const struct i2c_adapter_quirks hdpvr_quirks = { - .flags = I2C_AQ_NO_ZERO_LEN_READ, + .flags = I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_COMB_WRITE_THEN_READ, }; static const struct i2c_adapter hdpvr_i2c_adapter_template = { |