]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i2c: rtl9300: introduce max length property to driver data
authorRustam Adilov <adilov@disroot.org>
Wed, 1 Apr 2026 18:06:42 +0000 (23:06 +0500)
committerAndi Shyti <andi.shyti@kernel.org>
Wed, 1 Apr 2026 22:09:06 +0000 (00:09 +0200)
In RTL9607C i2c controller, theoretical maximum the data length
can be is 4 bytes as opposed to 16 bytes on rtl9300 and rtl9310.

Introduce a new property to the driver data struct for that.
Adjust if statement in prepare_xfer function to follow that new
property instead of the hardcoded value.

Signed-off-by: Rustam Adilov <adilov@disroot.org>
Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20260401180648.337834-3-adilov@disroot.org
drivers/i2c/busses/i2c-rtl9300.c

index 9bf4c6b08e05a3fb4c4ee9132f369a17a22f0b41..2cada6038b44f06cb1d9446bd6c5851f8e3ea494 100644 (file)
@@ -64,11 +64,14 @@ struct rtl9300_i2c_drv_data {
        u32 rd_reg;
        u32 wd_reg;
        u8 max_nchan;
+       u8 max_data_len;
 };
 
 #define RTL9300_I2C_MUX_NCHAN  8
 #define RTL9310_I2C_MUX_NCHAN  12
 
+#define RTL9300_I2C_MAX_DATA_LEN       16
+
 struct rtl9300_i2c {
        struct regmap *regmap;
        struct device *dev;
@@ -210,9 +213,11 @@ static int rtl9300_i2c_writel(struct rtl9300_i2c *i2c, u32 data)
 
 static int rtl9300_i2c_prepare_xfer(struct rtl9300_i2c *i2c, struct rtl9300_i2c_xfer *xfer)
 {
+       const struct rtl9300_i2c_drv_data *drv_data;
        int ret;
 
-       if (xfer->data_len < 1 || xfer->data_len > 16)
+       drv_data = device_get_match_data(i2c->dev);
+       if (xfer->data_len < 1 || xfer->data_len > drv_data->max_data_len)
                return -EINVAL;
 
        ret = regmap_field_write(i2c->fields[F_DEV_ADDR], xfer->dev_addr);
@@ -505,6 +510,7 @@ static const struct rtl9300_i2c_drv_data rtl9300_i2c_drv_data = {
        .rd_reg = RTL9300_I2C_MST_DATA_WORD0,
        .wd_reg = RTL9300_I2C_MST_DATA_WORD0,
        .max_nchan = RTL9300_I2C_MUX_NCHAN,
+       .max_data_len = RTL9300_I2C_MAX_DATA_LEN,
 };
 
 static const struct rtl9300_i2c_drv_data rtl9310_i2c_drv_data = {
@@ -526,6 +532,7 @@ static const struct rtl9300_i2c_drv_data rtl9310_i2c_drv_data = {
        .rd_reg = RTL9310_I2C_MST_DATA_CTRL,
        .wd_reg = RTL9310_I2C_MST_DATA_CTRL,
        .max_nchan = RTL9310_I2C_MUX_NCHAN,
+       .max_data_len = RTL9300_I2C_MAX_DATA_LEN,
 };
 
 static const struct of_device_id i2c_rtl9300_dt_ids[] = {