Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Rustam Adilov and committed by
Andi Shyti
991cd899 f60d2792

+44 -22
+44 -22
drivers/i2c/busses/i2c-rtl9300.c
··· 65 65 struct rtl9300_i2c_drv_data { 66 66 struct rtl9300_i2c_reg_field field_desc[F_NUM_FIELDS]; 67 67 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); 68 71 u32 rd_reg; 69 72 u32 wd_reg; 70 73 u8 max_nchan; ··· 176 173 177 174 i2c->sda_num = chan->sda_num; 178 175 return 0; 176 + } 177 + 178 + static void rtl9300_i2c_config_clock(u32 clock_freq, struct rtl9300_i2c_chan *chan) 179 + { 180 + struct rtl9300_i2c *i2c = chan->i2c; 181 + 182 + switch (clock_freq) { 183 + case I2C_MAX_STANDARD_MODE_FREQ: 184 + chan->bus_freq = RTL9300_I2C_STD_FREQ; 185 + break; 186 + case I2C_MAX_FAST_MODE_FREQ: 187 + chan->bus_freq = RTL9300_I2C_FAST_FREQ; 188 + break; 189 + case RTL9300_I2C_MAX_SUPER_FAST_FREQ: 190 + chan->bus_freq = RTL9300_I2C_SUPER_FAST_FREQ; 191 + break; 192 + case RTL9300_I2C_MAX_SLOW_FREQ: 193 + chan->bus_freq = RTL9300_I2C_SLOW_FREQ; 194 + break; 195 + default: 196 + dev_warn(i2c->dev, "SDA%d clock-frequency %d not supported using default\n", 197 + chan->sda_num, clock_freq); 198 + break; 199 + } 179 200 } 180 201 181 202 static int rtl9300_i2c_read(struct rtl9300_i2c *i2c, u8 *buf, u8 len) ··· 349 322 guard(rtl9300_i2c)(i2c); 350 323 351 324 drv_data = device_get_match_data(i2c->dev); 352 - ret = rtl9300_i2c_config_chan(i2c, chan); 325 + ret = drv_data->config_chan(i2c, chan); 353 326 if (ret) 354 327 return ret; 355 328 ··· 416 389 .max_write_len = 16, 417 390 }; 418 391 392 + static int rtl9300_i2c_init(struct rtl9300_i2c *i2c) 393 + { 394 + /* only use standard read format */ 395 + return regmap_field_write(i2c->fields[F_RD_MODE], 0); 396 + } 397 + 419 398 static int rtl9300_i2c_probe(struct platform_device *pdev) 420 399 { 421 400 struct device *dev = &pdev->dev; ··· 486 453 if (ret) 487 454 clock_freq = I2C_MAX_STANDARD_MODE_FREQ; 488 455 489 - switch (clock_freq) { 490 - case I2C_MAX_STANDARD_MODE_FREQ: 491 - chan->bus_freq = RTL9300_I2C_STD_FREQ; 492 - break; 493 - case I2C_MAX_FAST_MODE_FREQ: 494 - chan->bus_freq = RTL9300_I2C_FAST_FREQ; 495 - break; 496 - case RTL9300_I2C_MAX_SUPER_FAST_FREQ: 497 - chan->bus_freq = RTL9300_I2C_SUPER_FAST_FREQ; 498 - break; 499 - case RTL9300_I2C_MAX_SLOW_FREQ: 500 - chan->bus_freq = RTL9300_I2C_SLOW_FREQ; 501 - break; 502 - default: 503 - dev_warn(i2c->dev, "SDA%d clock-frequency %d not supported using default\n", 504 - sda_num, clock_freq); 505 - break; 506 - } 507 - 508 456 chan->sda_num = sda_num; 509 457 chan->i2c = i2c; 458 + 459 + drv_data->config_clock(clock_freq, chan); 460 + 510 461 adap = &i2c->chans[i].adap; 511 462 adap->owner = THIS_MODULE; 512 463 adap->algo = &rtl9300_i2c_algo; ··· 508 491 } 509 492 i2c->sda_num = 0xff; 510 493 511 - /* only use standard read format */ 512 - ret = regmap_field_write(i2c->fields[F_RD_MODE], 0); 494 + ret = drv_data->misc_init(i2c); 513 495 if (ret) 514 496 return ret; 515 497 ··· 537 521 [F_BUSY] = MST_REG_FIELD(RTL9300_I2C_MST_CTRL1, 0, 0), 538 522 }, 539 523 .select_scl = rtl9300_i2c_select_scl, 524 + .config_chan = rtl9300_i2c_config_chan, 525 + .config_clock = rtl9300_i2c_config_clock, 526 + .misc_init = rtl9300_i2c_init, 540 527 .rd_reg = RTL9300_I2C_MST_DATA_WORD0, 541 528 .wd_reg = RTL9300_I2C_MST_DATA_WORD0, 542 529 .max_nchan = RTL9300_I2C_MUX_NCHAN, ··· 564 545 [F_BUSY] = MST_REG_FIELD(RTL9310_I2C_MST_CTRL, 0, 0), 565 546 }, 566 547 .select_scl = rtl9310_i2c_select_scl, 548 + .config_chan = rtl9300_i2c_config_chan, 549 + .config_clock = rtl9300_i2c_config_clock, 550 + .misc_init = rtl9300_i2c_init, 567 551 .rd_reg = RTL9310_I2C_MST_DATA_CTRL, 568 552 .wd_reg = RTL9310_I2C_MST_DATA_CTRL, 569 553 .max_nchan = RTL9310_I2C_MUX_NCHAN,