public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND TO CC MAILLIST] i2c: designware: fix master holding SCL low when I2C_DYNAMIC_TAR_UPDATE not set
@ 2024-11-01  8:12 Liu Peibao
  2024-11-01  8:44 ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Liu Peibao @ 2024-11-01  8:12 UTC (permalink / raw)
  To: Jarkko Nikula, Andy Shevchenko, Mika Westerberg, Jan Dabros,
	Andi Shyti
  Cc: xiaowu . ding, Angus Chen, Liu Peibao, linux-i2c, linux-kernel

When Tx FIFO empty and last command with no STOP bit set, the master
holds SCL low. If I2C_DYNAMIC_TAR_UPDATE is not set, BIT(13) MST_ON_HOLD
of IC_RAW_INTR_STAT is not Enabled, causing the __i2c_dw_disable()
timeout. This is quiet similar as commit 2409205acd3c ("i2c: designware:
fix __i2c_dw_disable() in case master is holding SCL low") mentioned.
Check BIT(7) MST_HOLD_TX_FIFO_EMPTY in IC_STATUS also which is available
when IC_STAT_FOR_CLK_STRETCH is set.

Signed-off-by: Liu Peibao <loven.liu@jaguarmicro.com>
Signed-off-by: xiaowu.ding <xiaowu.ding@jaguarmicro.com>
Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
---
 drivers/i2c/busses/i2c-designware-common.c | 6 ++++--
 drivers/i2c/busses/i2c-designware-core.h   | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index f31d352d98b5..9d88b4fa03e4 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -524,7 +524,7 @@ int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev)
 void __i2c_dw_disable(struct dw_i2c_dev *dev)
 {
 	struct i2c_timings *t = &dev->timings;
-	unsigned int raw_intr_stats;
+	unsigned int raw_intr_stats, ic_stats;
 	unsigned int enable;
 	int timeout = 100;
 	bool abort_needed;
@@ -532,9 +532,11 @@ void __i2c_dw_disable(struct dw_i2c_dev *dev)
 	int ret;
 
 	regmap_read(dev->map, DW_IC_RAW_INTR_STAT, &raw_intr_stats);
+	regmap_read(dev->map, DW_IC_STATUS, &ic_stats);
 	regmap_read(dev->map, DW_IC_ENABLE, &enable);
 
-	abort_needed = raw_intr_stats & DW_IC_INTR_MST_ON_HOLD;
+	abort_needed = (raw_intr_stats & DW_IC_INTR_MST_ON_HOLD) ||
+			(ic_stats & DW_IC_STATUS_MASTER_HOLD_TX_FIFO_EMPTY);
 	if (abort_needed) {
 		if (!(enable & DW_IC_ENABLE_ENABLE)) {
 			regmap_write(dev->map, DW_IC_ENABLE, DW_IC_ENABLE_ENABLE);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 8e8854ec9882..2d32896d0673 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -116,6 +116,7 @@
 #define DW_IC_STATUS_RFNE			BIT(3)
 #define DW_IC_STATUS_MASTER_ACTIVITY		BIT(5)
 #define DW_IC_STATUS_SLAVE_ACTIVITY		BIT(6)
+#define DW_IC_STATUS_MASTER_HOLD_TX_FIFO_EMPTY	BIT(7)
 
 #define DW_IC_SDA_HOLD_RX_SHIFT			16
 #define DW_IC_SDA_HOLD_RX_MASK			GENMASK(23, 16)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-11-06 23:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-01  8:12 [PATCH RESEND TO CC MAILLIST] i2c: designware: fix master holding SCL low when I2C_DYNAMIC_TAR_UPDATE not set Liu Peibao
2024-11-01  8:44 ` Andy Shevchenko
2024-11-01 10:18   ` Liu Peibao
2024-11-05 20:30     ` Andi Shyti
2024-11-06  7:27       ` Liu Peibao
2024-11-06  9:46         ` Andi Shyti
2024-11-06 10:09           ` Liu Peibao
2024-11-06 11:53             ` Jarkko Nikula
2024-11-06 23:07               ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox