Skip to contentSkip to conversation

i2c: rtl9300: two cleanups

PATCH Applied Rosen Penev 3 participants 7 messages Dec 17, 2025 – Jan 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover i2c: rtl9300: two cleanups

const fix and fwnode removal.

Rosen Penev (2):
i2c: rtl9300: remove const cast
i2c: rtl9300: use of instead of fwnode

 drivers/i2c/busses/i2c-rtl9300.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

--
2.52.0

#1 lore raw

PATCH 1/2 i2c: rtl9300: remove const cast

These casts are used to remove const for no good reason. Fix the types instead.

---
 drivers/i2c/busses/i2c-rtl9300.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-rtl9300.c +4 -4
index 4723e48cfe18..f2aa341a7cdd 100644
@@ -129,7 +129,7 @@ static int rtl9310_i2c_select_scl(struct rtl9300_i2c *i2c, u8 scl)
 
 static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan)
 {
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
 	int ret;
 
 	if (i2c->sda_num == chan->sda_num)
@@ -139,7 +139,7 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
 	if (ret)
 		return ret;
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
 	ret = drv_data->select_scl(i2c, i2c->scl_num);
 	if (ret)
 		return ret;
@@ -372,7 +372,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rtl9300_i2c *i2c;
 	struct fwnode_handle *child;
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
 	struct reg_field fields[F_NUM_FIELDS];
 	u32 clock_freq, scl_num, sda_num;
 	int ret, i = 0;
@@ -399,7 +399,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, i2c);
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
 	if (device_get_child_node_count(dev) > drv_data->max_nchan)
 		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
 
Signature · 1 line
2.52.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] i2c: rtl9300: remove const cast

Hi Rosen,

Quoted 4 lines · Rosen Penev

These casts are used to remove const for no good reason. Fix the types instead.

Quoted 44 lines
---
  drivers/i2c/busses/i2c-rtl9300.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-rtl9300.c +4 -4
index 4723e48cfe18..f2aa341a7cdd 100644
@@ -129,7 +129,7 @@ static int rtl9310_i2c_select_scl(struct rtl9300_i2c *i2c, u8 scl)
 
  static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_chan *chan)
  {
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
  	int ret;
 
  	if (i2c->sda_num == chan->sda_num)
@@ -139,7 +139,7 @@ static int rtl9300_i2c_config_chan(struct rtl9300_i2c *i2c, struct rtl9300_i2c_c
  	if (ret)
  		return ret;
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
  	ret = drv_data->select_scl(i2c, i2c->scl_num);
  	if (ret)
  		return ret;
@@ -372,7 +372,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
  	struct device *dev = &pdev->dev;
  	struct rtl9300_i2c *i2c;
  	struct fwnode_handle *child;
-	struct rtl9300_i2c_drv_data *drv_data;
+	const struct rtl9300_i2c_drv_data *drv_data;
  	struct reg_field fields[F_NUM_FIELDS];
  	u32 clock_freq, scl_num, sda_num;
  	int ret, i = 0;
@@ -399,7 +399,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 
  	platform_set_drvdata(pdev, i2c);
 
-	drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
+	drv_data = device_get_match_data(i2c->dev);
  	if (device_get_child_node_count(dev) > drv_data->max_nchan)
  		return dev_err_probe(dev, -EINVAL, "Too many channels\n");
 
#3 lore raw

PATCH 2/2 i2c: rtl9300: use of instead of fwnode

In reply to Rosen Penev

Avoids having to use to_of_node and just assign directly. This is an OF only driver anyway.

Use _scoped for the for each loop to avoid refcount leaks.

---
 drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-rtl9300.c +4 -5
index f2aa341a7cdd..672cb978066d 100644
@@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct rtl9300_i2c *i2c;
-	struct fwnode_handle *child;
 	const struct rtl9300_i2c_drv_data *drv_data;
 	struct reg_field fields[F_NUM_FIELDS];
 	u32 clock_freq, scl_num, sda_num;
@@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 		return ret;
 
 	i = 0;
-	device_for_each_child_node(dev, child) {
+	for_each_child_of_node_scoped(dev->of_node, child) {
 		struct rtl9300_i2c_chan *chan = &i2c->chans[i];
 		struct i2c_adapter *adap = &chan->adap;
 
-		ret = fwnode_property_read_u32(child, "reg", &sda_num);
+		ret = of_property_read_u32(child, "reg", &sda_num);
 		if (ret)
 			return ret;
 
-		ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
+		ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
 		if (ret)
 			clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
 
@@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
 		adap->retries = 3;
 		adap->dev.parent = dev;
 		i2c_set_adapdata(adap, chan);
-		adap->dev.of_node = to_of_node(child);
+		adap->dev.of_node = child;
 		snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
 		i++;
 
Signature · 1 line
2.52.0
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] i2c: rtl9300: use of instead of fwnode

Hi Rosen,

Quoted 6 lines · Rosen Penev

Avoids having to use to_of_node and just assign directly. This is an OF only driver anyway.

Use _scoped for the for each loop to avoid refcount leaks.

I thought the trend was to move to the more generic device properties rather than using of_ specific APIs which is why I wrote the driver using them. I agree that this driver is unlikely to be used on any platform that doesn't use a device tree so if Andi is happy with this I'm fine with the change.

Quoted 44 lines
---
  drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-rtl9300.c +4 -5
index f2aa341a7cdd..672cb978066d 100644
@@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
  {
  	struct device *dev = &pdev->dev;
  	struct rtl9300_i2c *i2c;
-	struct fwnode_handle *child;
  	const struct rtl9300_i2c_drv_data *drv_data;
  	struct reg_field fields[F_NUM_FIELDS];
  	u32 clock_freq, scl_num, sda_num;
@@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
  		return ret;
 
  	i = 0;
-	device_for_each_child_node(dev, child) {
+	for_each_child_of_node_scoped(dev->of_node, child) {
  		struct rtl9300_i2c_chan *chan = &i2c->chans[i];
  		struct i2c_adapter *adap = &chan->adap;
 
-		ret = fwnode_property_read_u32(child, "reg", &sda_num);
+		ret = of_property_read_u32(child, "reg", &sda_num);
  		if (ret)
  			return ret;
 
-		ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
+		ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
  		if (ret)
  			clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
 
@@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
  		adap->retries = 3;
  		adap->dev.parent = dev;
  		i2c_set_adapdata(adap, chan);
-		adap->dev.of_node = to_of_node(child);
+		adap->dev.of_node = child;
  		snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
  		i++;
 
#5 lore raw

Re: [PATCH 2/2] i2c: rtl9300: use of instead of fwnode

Quoted 9 lines · Chris Packham

Hi Rosen,

Quoted 5 lines · Rosen Penev

Avoids having to use to_of_node and just assign directly. This is an OF only driver anyway.

Use _scoped for the for each loop to avoid refcount leaks.

Quoted 7 lines
Quoted 1 line

I thought the trend was to move to the more generic device properties rather than using of_ specific APIs which is why I wrote the driver using them. I agree that this driver is unlikely to be used on any platform that doesn't use a device tree so if Andi is happy with this I'm fine with the change.

I've gotten the opposite advice on netdev before.

Quoted 47 lines
Quoted 44 lines
---
  drivers/i2c/busses/i2c-rtl9300.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-rtl9300.c +4 -5
index f2aa341a7cdd..672cb978066d 100644
@@ -371,7 +371,6 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
  {
      struct device *dev = &pdev->dev;
      struct rtl9300_i2c *i2c;
-     struct fwnode_handle *child;
      const struct rtl9300_i2c_drv_data *drv_data;
      struct reg_field fields[F_NUM_FIELDS];
      u32 clock_freq, scl_num, sda_num;
@@ -415,15 +414,15 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
              return ret;
 
      i = 0;
-     device_for_each_child_node(dev, child) {
+     for_each_child_of_node_scoped(dev->of_node, child) {
              struct rtl9300_i2c_chan *chan = &i2c->chans[i];
              struct i2c_adapter *adap = &chan->adap;
 
-             ret = fwnode_property_read_u32(child, "reg", &sda_num);
+             ret = of_property_read_u32(child, "reg", &sda_num);
              if (ret)
                      return ret;
 
-             ret = fwnode_property_read_u32(child, "clock-frequency", &clock_freq);
+             ret = of_property_read_u32(child, "clock-frequency", &clock_freq);
              if (ret)
                      clock_freq = I2C_MAX_STANDARD_MODE_FREQ;
 
@@ -449,7 +448,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
              adap->retries = 3;
              adap->dev.parent = dev;
              i2c_set_adapdata(adap, chan);
-             adap->dev.of_node = to_of_node(child);
+             adap->dev.of_node = child;
              snprintf(adap->name, sizeof(adap->name), "%s SDA%d\n", dev_name(dev), sda_num);
              i++;
 
maintainer Applied
#6 lore raw
In reply to Rosen Penev

Hi Rosen,

Quoted 3 lines · Rosen Penev

Rosen Penev (2):
i2c: rtl9300: remove const cast
i2c: rtl9300: use of instead of fwnode

merged to i2c/i2c-host.

Thanks,
Andi