From: Rustam Adilov Date: Wed, 1 Apr 2026 18:06:42 +0000 (+0500) Subject: i2c: rtl9300: introduce max length property to driver data X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98773df61f8416594ac993e8464df596755ee1b8;p=thirdparty%2Flinux.git i2c: rtl9300: introduce max length property to driver data 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 Reviewed-by: Chris Packham Signed-off-by: Andi Shyti Link: https://lore.kernel.org/r/20260401180648.337834-3-adilov@disroot.org --- diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c index 9bf4c6b08e05a..2cada6038b44f 100644 --- a/drivers/i2c/busses/i2c-rtl9300.c +++ b/drivers/i2c/busses/i2c-rtl9300.c @@ -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[] = {