]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: usb: hdpvr: use I2C core to handle only supported messages
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 22 May 2025 08:09:55 +0000 (10:09 +0200)
committerHans Verkuil <hverkuil@xs4all.nl>
Tue, 17 Jun 2025 08:35:15 +0000 (10:35 +0200)
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>
drivers/media/usb/hdpvr/hdpvr-i2c.c

index 54956a8ff15e86b1bbaf83a3574d5c62fe89d1a0..9eacc85e3f11dc944714444f282c5aa658a6422f 100644 (file)
@@ -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 = {