From: Jian Zhang <zhangjian.3032@bytedance.com>
To: linux-aspeed@lists.ozlabs.org
Subject: [PATCH] i2c: aspeed: Fix i2c bus hang in slave read
Date: Thu, 10 Aug 2023 15:21:55 +0800 [thread overview]
Message-ID: <20230810072155.3726352-1-zhangjian.3032@bytedance.com> (raw)
When the `CONFIG_I2C_SLAVE` option is enabled and the device operates
as a slave, a situation arises where the master sends a START signal
without the accompanying STOP signal. This action results in a
persistent I2C bus timeout. The core issue stems from the fact that
the i2c controller remains in a slave read state without a timeout
mechanism. As a consequence, the bus perpetually experiences timeouts.
This proposed patch addresses this problem by introducing a status
check during i2c transmit timeouts. In the event that the controller
is in a slave read state, the i2c controller will be reset to restore
proper functionality and allow the I2C bus to resume normal operation.
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
---
drivers/i2c/busses/i2c-aspeed.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index e76befe3f60f..1a95205fc946 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -113,6 +113,7 @@
ASPEED_I2CD_M_RX_CMD | \
ASPEED_I2CD_M_TX_CMD | \
ASPEED_I2CD_M_START_CMD)
+#define ASPEED_I2CD_SLAVE_CMDS_MASK GENMASK(31, 29)
/* 0x18 : I2CD Slave Device Address Register */
#define ASPEED_I2CD_DEV_ADDR_MASK GENMASK(6, 0)
@@ -706,6 +707,22 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap,
ASPEED_I2CD_BUS_BUSY_STS))
aspeed_i2c_recover_bus(bus);
+#if IS_ENABLED(CONFIG_I2C_SLAVE)
+ /*
+ * If master timed out and bus is in slave mode.
+ * reset the slave mode.
+ */
+ if (readl(bus->base + ASPEED_I2C_CMD_REG) & ASPEED_I2CD_SLAVE_CMDS_MASK) {
+ spin_lock_irqsave(&bus->lock, flags);
+ u32 func_ctrl_reg_val = readl(bus->base + ASPEED_I2C_FUN_CTRL_REG);
+
+ writel(0, bus->base + ASPEED_I2C_FUN_CTRL_REG);
+ writel(func_ctrl_reg_val, bus->base + ASPEED_I2C_FUN_CTRL_REG);
+ bus->slave_state = ASPEED_I2C_SLAVE_INACTIVE;
+ spin_unlock_irqrestore(&bus->lock, flags);
+ }
+#endif
+
/*
* If timed out and the state is still pending, drop the pending
* master command.
--
2.30.2
next reply other threads:[~2023-08-10 7:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 7:21 Jian Zhang [this message]
2023-09-22 6:47 ` [PATCH] i2c: aspeed: Fix i2c bus hang in slave read Joel Stanley
2023-09-22 14:39 ` [External] " Jian Zhang
2023-09-27 2:42 ` Joel Stanley
2023-09-27 3:24 ` Tommy Huang
2023-09-27 6:18 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230810072155.3726352-1-zhangjian.3032@bytedance.com \
--to=zhangjian.3032@bytedance.com \
--cc=linux-aspeed@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox