Skip to content

Commit 991cd89

Browse files
Rustam AdilovAndi Shyti
authored andcommitted
i2c: rtl9300: introduce new function properties to driver data
Due to the very nature of differences between RTL9607C i2c controller and RTL9300 / RTL9310 that are incompatible with each other in some areas of this driver, for example in clock configuration, channel configuration and initialization at the end of the probe, introduce new function properties to the driver data struct to handle those differences. With these new properties, create configuration functions for RTL9300 and RTL9310 and assign them to their respective driver data structs. Signed-off-by: Rustam Adilov <adilov@disroot.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20260401180648.337834-8-adilov@disroot.org
1 parent f60d279 commit 991cd89

1 file changed

Lines changed: 44 additions & 22 deletions

File tree

drivers/i2c/busses/i2c-rtl9300.c

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ enum rtl9300_i2c_reg_fields {
6565
struct rtl9300_i2c_drv_data {
6666
struct rtl9300_i2c_reg_field field_desc[F_NUM_FIELDS];
6767
int (*select_scl)(struct rtl9300_i2c *i2c, u8 scl);
68+
int (*config_chan)(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan);
69+
void (*config_clock)(u32 clock_freq, struct rtl9300_i2c_chan *chan);
70+
int (*misc_init)(struct rtl9300_i2c *i2c);
6871
u32 rd_reg;
6972
u32 wd_reg;
7073
u8 max_nchan;
@@ -175,6 +178,30 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
175178
return 0;
176179
}
177180

181+
static void rtl9300_i2c_config_clock(u32 clock_freq, struct rtl9300_i2c_chan *chan)
182+
{
183+
struct rtl9300_i2c *i2c = chan->i2c;
184+
185+
switch (clock_freq) {
186+
case I2C_MAX_STANDARD_MODE_FREQ:
187+
chan->bus_freq = RTL9300_I2C_STD_FREQ;
188+
break;
189+
case I2C_MAX_FAST_MODE_FREQ:
190+
chan->bus_freq = RTL9300_I2C_FAST_FREQ;
191+
break;
192+
case RTL9300_I2C_MAX_SUPER_FAST_FREQ:
193+
chan->bus_freq = RTL9300_I2C_SUPER_FAST_FREQ;
194+
break;
195+
case RTL9300_I2C_MAX_SLOW_FREQ:
196+
chan->bus_freq = RTL9300_I2C_SLOW_FREQ;
197+
break;
198+
default:
199+
dev_warn(i2c->dev, "SDA%d clock-frequency %d not supported using default\n",
200+
chan->sda_num, clock_freq);
201+
break;
202+
}
203+
}
204+
178205
static int rtl9300_i2c_read(struct rtl9300_i2c *i2c, u8 *buf, u8 len)
179206
{
180207
u32 vals[4] = {};
@@ -322,7 +349,7 @@ static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned s
322349
guard(rtl9300_i2c)(i2c);
323350

324351
drv_data = device_get_match_data(i2c->dev);
325-
ret = rtl9300_i2c_config_chan(i2c, chan);
352+
ret = drv_data->config_chan(i2c, chan);
326353
if (ret)
327354
return ret;
328355

@@ -389,6 +416,12 @@ static struct i2c_adapter_quirks rtl9300_i2c_quirks = {
389416
.max_write_len = 16,
390417
};
391418

419+
static int rtl9300_i2c_init(struct rtl9300_i2c *i2c)
420+
{
421+
/* only use standard read format */
422+
return regmap_field_write(i2c->fields[F_RD_MODE], 0);
423+
}
424+
392425
static int rtl9300_i2c_probe(struct platform_device *pdev)
393426
{
394427
struct device *dev = &pdev->dev;
@@ -453,27 +486,11 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
453486
if (ret)
454487
clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
455488

456-
switch (clock_freq) {
457-
case I2C_MAX_STANDARD_MODE_FREQ:
458-
chan->bus_freq = RTL9300_I2C_STD_FREQ;
459-
break;
460-
case I2C_MAX_FAST_MODE_FREQ:
461-
chan->bus_freq = RTL9300_I2C_FAST_FREQ;
462-
break;
463-
case RTL9300_I2C_MAX_SUPER_FAST_FREQ:
464-
chan->bus_freq = RTL9300_I2C_SUPER_FAST_FREQ;
465-
break;
466-
case RTL9300_I2C_MAX_SLOW_FREQ:
467-
chan->bus_freq = RTL9300_I2C_SLOW_FREQ;
468-
break;
469-
default:
470-
dev_warn(i2c->dev, "SDA%d clock-frequency %d not supported using default\n",
471-
sda_num, clock_freq);
472-
break;
473-
}
474-
475489
chan->sda_num = sda_num;
476490
chan->i2c = i2c;
491+
492+
drv_data->config_clock(clock_freq, chan);
493+
477494
adap = &i2c->chans[i].adap;
478495
adap->owner = THIS_MODULE;
479496
adap->algo = &rtl9300_i2c_algo;
@@ -491,8 +508,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
491508
}
492509
i2c->sda_num = 0xff;
493510

494-
/* only use standard read format */
495-
ret = regmap_field_write(i2c->fields[F_RD_MODE], 0);
511+
ret = drv_data->misc_init(i2c);
496512
if (ret)
497513
return ret;
498514

@@ -521,6 +537,9 @@ static const struct rtl9300_i2c_drv_data rtl9300_i2c_drv_data = {
521537
[F_BUSY] = MST_REG_FIELD(RTL9300_I2C_MST_CTRL1, 0, 0),
522538
},
523539
.select_scl = rtl9300_i2c_select_scl,
540+
.config_chan = rtl9300_i2c_config_chan,
541+
.config_clock = rtl9300_i2c_config_clock,
542+
.misc_init = rtl9300_i2c_init,
524543
.rd_reg = RTL9300_I2C_MST_DATA_WORD0,
525544
.wd_reg = RTL9300_I2C_MST_DATA_WORD0,
526545
.max_nchan = RTL9300_I2C_MUX_NCHAN,
@@ -545,6 +564,9 @@ static const struct rtl9300_i2c_drv_data rtl9310_i2c_drv_data = {
545564
[F_BUSY] = MST_REG_FIELD(RTL9310_I2C_MST_CTRL, 0, 0),
546565
},
547566
.select_scl = rtl9310_i2c_select_scl,
567+
.config_chan = rtl9300_i2c_config_chan,
568+
.config_clock = rtl9300_i2c_config_clock,
569+
.misc_init = rtl9300_i2c_init,
548570
.rd_reg = RTL9310_I2C_MST_DATA_CTRL,
549571
.wd_reg = RTL9310_I2C_MST_DATA_CTRL,
550572
.max_nchan = RTL9310_I2C_MUX_NCHAN,

0 commit comments

Comments
 (0)