On Thu May 22 10:09:55 2025 +0200, Wolfram Sang wrote: > 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+rene...@sang-engineering.com> > Signed-off-by: Hans Verkuil <hverk...@xs4all.nl>
Patch committed. Thanks, Hans Verkuil drivers/media/usb/hdpvr/hdpvr-i2c.c | 28 ++++------------------------ 1 file 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 = {