From: Troy Mitchell <troy.mitchell@linux.spacemit.com>
To: Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
Alex Elder <elder@riscstar.com>,
Michael Opdenacker <michael.opdenacker@rootcommit.com>
Cc: Troy Mitchell <troymitchell988@gmail.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
Troy Mitchell <troy.mitchell@linux.spacemit.com>
Subject: [PATCH] i2c: spacemit: fix detect issue
Date: Mon, 03 Nov 2025 15:06:24 +0800 [thread overview]
Message-ID: <20251103-fix-k1-detect-failure-v1-1-bb07a8d7de7c@linux.spacemit.com> (raw)
This commit addresses two issues causing i2c detect to fail.
The identified issues are:
1. Incorrect error handling for BED (Bus Error No ACK/NAK):
Before this commit, Both ALD (Arbitration Loss Detected) and
BED returned -EAGAIN.
2. Missing interrupt status clear after initialization in xfer():
On the K1 SoC, simply fixing the first issue changed the error
from -EAGAIN to -ETIMEOUT. Through tracing, it was determined that
this is likely due to MSD (Master Stop Detected) latency issues.
That means the MSD bit in the ISR may still be set on the next transfer.
As a result, the controller won't work — we can see from the scope that
it doesn't issue any signal.
(This only occurs during rapid consecutive I2C transfers.
That explains why the issue only shows up with i2cdetect.)
With these two fixes, i2c device detection now functions correctly on the K1 SoC.
Fixes: 5ea558473fa31 ("i2c: spacemit: add support for SpacemiT K1 SoC")
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
I checked the vendor version driver and tried commenting out
spacemit_i2c_clear_int_status() that runs before xfer starts.
Surprisingly, i2cdetect stopped working as well.
---
drivers/i2c/busses/i2c-k1.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c
index 6b918770e612e098b8ad17418f420d87c94df166..37828323317770ae2f0522d213dca67342ae166f 100644
--- a/drivers/i2c/busses/i2c-k1.c
+++ b/drivers/i2c/busses/i2c-k1.c
@@ -160,7 +160,8 @@ static int spacemit_i2c_handle_err(struct spacemit_i2c_dev *i2c)
if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
spacemit_i2c_reset(i2c);
- return -EAGAIN;
+ if (i2c->status & SPACEMIT_SR_ALD)
+ return -EAGAIN;
}
return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
@@ -491,6 +492,8 @@ static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in
spacemit_i2c_init(i2c);
+ spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
+
spacemit_i2c_enable(i2c);
ret = spacemit_i2c_wait_bus_idle(i2c);
---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251103-fix-k1-detect-failure-0b3082c73784
Best regards,
--
Troy Mitchell <troy.mitchell@linux.spacemit.com>
next reply other threads:[~2025-11-03 7:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 7:06 Troy Mitchell [this message]
2025-11-05 22:44 ` Aurelien Jarno
2025-11-06 1:05 ` Troy Mitchell
2025-11-06 5:34 ` Aurelien Jarno
2025-11-06 5:38 ` Troy Mitchell
2025-11-06 18:17 ` Aurelien Jarno
2025-11-07 1:22 ` Troy Mitchell
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=20251103-fix-k1-detect-failure-v1-1-bb07a8d7de7c@linux.spacemit.com \
--to=troy.mitchell@linux.spacemit.com \
--cc=andi.shyti@kernel.org \
--cc=dlan@gentoo.org \
--cc=elder@riscstar.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=michael.opdenacker@rootcommit.com \
--cc=spacemit@lists.linux.dev \
--cc=troymitchell988@gmail.com \
/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
all inboxes | Powered by JetHome®