4403d99d9f32b27bab9d7282fa3d395e7722d9d9
[openwrt/openwrt.git] /
1 From 6b0549abc8582a81425f89a436def8e28d8d7dce Mon Sep 17 00:00:00 2001
2 From: Jonas Jelonek <jelonek.jonas@gmail.com>
3 Date: Sat, 27 Sep 2025 10:19:26 +0000
4 Subject: [PATCH] i2c: rtl9300: move setting SCL frequency to config_io
5
6 Move the register operation to set the SCL frequency to the
7 rtl9300_i2c_config_io function instead of the rtl9300_i2c_config_xfer
8 function. This rather belongs there next to selecting the current SDA
9 output line.
10
11 Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
12 Tested-by: Sven Eckelmann <sven@narfation.org>
13 Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
14 Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz> # On RTL9302C based board
15 Tested-by: Markus Stockhausen <markus.stockhausen@gmx.de>
16 Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
17 Link: https://lore.kernel.org/r/20250927101931.71575-5-jelonek.jonas@gmail.com
18
19 diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
20 index f9b5ac7670c2..4177cfb77094 100644
21 --- a/drivers/i2c/busses/i2c-rtl9300.c
22 +++ b/drivers/i2c/busses/i2c-rtl9300.c
23 @@ -95,18 +95,23 @@ static int rtl9300_i2c_select_scl(struct rtl9300_i2c *i2c, u8 scl)
24 return regmap_field_write(i2c->fields[F_SCL_SEL], 1);
25 }
26
27 -static int rtl9300_i2c_config_io(struct rtl9300_i2c *i2c, u8 sda_pin)
28 +static int rtl9300_i2c_config_io(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan)
29 {
30 struct rtl9300_i2c_drv_data *drv_data;
31 int ret;
32
33 drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
34
35 - ret = regmap_field_update_bits(i2c->fields[F_SDA_SEL], BIT(sda_num), BIT(sda_num));
36 + ret = regmap_field_update_bits(i2c->fields[F_SDA_SEL], BIT(chan->sda_num),
37 + BIT(chan->sda_num));
38 if (ret)
39 return ret;
40
41 - ret = regmap_field_write(i2c->fields[F_SDA_OUT_SEL], sda_num);
42 + ret = regmap_field_write(i2c->fields[F_SDA_OUT_SEL], chan->sda_num);
43 + if (ret)
44 + return ret;
45 +
46 + ret = regmap_field_write(i2c->fields[F_SCL_FREQ], chan->bus_freq);
47 if (ret)
48 return ret;
49
50 @@ -121,10 +126,6 @@ static int rtl9300_i2c_config_xfer(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
51 if (len < 1 || len > 16)
52 return -EINVAL;
53
54 - ret = regmap_field_write(i2c->fields[F_SCL_FREQ], chan->bus_freq);
55 - if (ret)
56 - return ret;
57 -
58 ret = regmap_field_write(i2c->fields[F_DEV_ADDR], addr);
59 if (ret)
60 return ret;
61 @@ -244,7 +245,7 @@ static int rtl9300_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, unsigned s
62
63 mutex_lock(&i2c->lock);
64 if (chan->sda_num != i2c->sda_num) {
65 - ret = rtl9300_i2c_config_io(i2c, chan->sda_pin);
66 + ret = rtl9300_i2c_config_io(i2c, chan);
67 if (ret)
68 goto out_unlock;
69 i2c->sda_num = chan->sda_num;
70 --
71 2.48.1
72