Skip to contentSkip to conversation

i2c: rockchip: De-initialize the bus after start bit failure

PATCH In review Ondřej Jirman 3 participants 4 messages May 25, 2023 – Jun 5, 2023 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: rockchip: De-initialize the bus after start bit failure

From: Ondrej Jirman <[email protected]>

Failure can happen when i2c is used without initializing pinctrl properly, which U-Boot happily allows in SPL. Without this fix, further I2C access would fail, even after proper pinctrl initialization.

---
 drivers/i2c/rk_i2c.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/i2c/rk_i2c.c +4 -3
index f8fac45b6ca0..9927af94a80b 100644
@@ -342,7 +342,7 @@ static int rockchip_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
 			     int nmsgs)
 {
 	struct rk_i2c *i2c = dev_get_priv(bus);
-	int ret;
+	int ret = 0;
 
 	debug("i2c_xfer: %d messages\n", nmsgs);
 	for (; nmsgs > 0; nmsgs--, msg++) {
@@ -356,14 +356,15 @@ static int rockchip_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
 		}
 		if (ret) {
 			debug("i2c_write: error sending\n");
-			return -EREMOTEIO;
+			ret = -EREMOTEIO;
+			break;
 		}
 	}
 
 	rk_i2c_send_stop_bit(i2c);
 	rk_i2c_disable(i2c);
 
-	return 0;
+	return ret;
 }
 
 int rockchip_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ondřej Jirman

From: Ondrej Jirman <[email protected]>

Failure can happen when i2c is used without initializing pinctrl properly, which U-Boot happily allows in SPL. Without this fix, further I2C access would fail, even after proper pinctrl initialization.

Thanks,
- Kever

Quoted 35 lines
---
  drivers/i2c/rk_i2c.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/i2c/rk_i2c.c +4 -3
index f8fac45b6ca0..9927af94a80b 100644
@@ -342,7 +342,7 @@ static int rockchip_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
  			     int nmsgs)
  {
  	struct rk_i2c *i2c = dev_get_priv(bus);
-	int ret;
+	int ret = 0;
 
  	debug("i2c_xfer: %d messages\n", nmsgs);
  	for (; nmsgs > 0; nmsgs--, msg++) {
@@ -356,14 +356,15 @@ static int rockchip_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,
  		}
  		if (ret) {
  			debug("i2c_write: error sending\n");
-			return -EREMOTEIO;
+			ret = -EREMOTEIO;
+			break;
  		}
  	}
 
  	rk_i2c_send_stop_bit(i2c);
  	rk_i2c_disable(i2c);
 
-	return 0;
+	return ret;
  }
 
  int rockchip_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ondřej Jirman

Hello Jirman,

Quoted 11 lines · Ondřej Jirman

From: Ondrej Jirman <[email protected]>

Failure can happen when i2c is used without initializing pinctrl properly, which U-Boot happily allows in SPL. Without this fix, further I2C access would fail, even after proper pinctrl initialization.

---
 drivers/i2c/rk_i2c.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

@kever: Patch is delegated to you on patchwork, for me it is fine, if you
pick it up. If you do not plan to pick it up, please delegate it to me.

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#3 lore raw
In reply to Ondřej Jirman

Hello Ondrej,

Quoted 11 lines · Ondřej Jirman

From: Ondrej Jirman <[email protected]>

Failure can happen when i2c is used without initializing pinctrl properly, which U-Boot happily allows in SPL. Without this fix, further I2C access would fail, even after proper pinctrl initialization.

---
 drivers/i2c/rk_i2c.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Applied to u-boot-i2c.git master

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]