* [PATCH v2] i2c: spacemit: fix detect issue
@ 2025-11-13 13:21 Troy Mitchell
2025-11-13 15:37 ` Michael Opdenacker
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Troy Mitchell @ 2025-11-13 13:21 UTC (permalink / raw)
To: Andi Shyti, Yixun Lan, Alex Elder, Michael Opdenacker,
Aurelien Jarno
Cc: Troy Mitchell, linux-i2c, linux-kernel, linux-riscv, spacemit,
Troy Mitchell
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")
Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
---
Changelog in v2:
- handle ALD and BED errors separately in spacemit_i2c_handle_err()
- move clear_int_status() above spacemit_i2c_init()
- move clear_int_status() from xfer() into spacemit_i2c_init()
- Link to v1: https://lore.kernel.org/all/20251103-fix-k1-detect-failure-v1-1-bb07a8d7de7c@linux.spacemit.com/
---
drivers/i2c/busses/i2c-k1.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c
index 6b918770e612e098b8ad17418f420d87c94df166..d42c03ef5db5984ea8e06b3d7eb485b4f899e616 100644
--- a/drivers/i2c/busses/i2c-k1.c
+++ b/drivers/i2c/busses/i2c-k1.c
@@ -158,11 +158,16 @@ static int spacemit_i2c_handle_err(struct spacemit_i2c_dev *i2c)
{
dev_dbg(i2c->dev, "i2c error status: 0x%08x\n", i2c->status);
- if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
+ /* Arbitration Loss Detected */
+ if (i2c->status & SPACEMIT_SR_ALD) {
spacemit_i2c_reset(i2c);
return -EAGAIN;
}
+ /* Bus Error No ACK/NAK */
+ if (i2c->status & SPACEMIT_SR_BED)
+ spacemit_i2c_reset(i2c);
+
return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
}
@@ -224,6 +229,12 @@ static void spacemit_i2c_check_bus_release(struct spacemit_i2c_dev *i2c)
}
}
+static inline void
+spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
+{
+ writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
+}
+
static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
{
u32 val;
@@ -267,12 +278,8 @@ static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
val = readl(i2c->base + SPACEMIT_IRCR);
val |= SPACEMIT_RCR_SDA_GLITCH_NOFIX;
writel(val, i2c->base + SPACEMIT_IRCR);
-}
-static inline void
-spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
-{
- writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
+ spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
}
static void spacemit_i2c_start(struct spacemit_i2c_dev *i2c)
---
base-commit: 6fa9041b7177f6771817b95e83f6df17b147c8c6
change-id: 20251113-fix-k1-detect-failure-63483e45168b
Best regards,
--
Troy Mitchell <troy.mitchell@linux.spacemit.com>
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2] i2c: spacemit: fix detect issue
2025-11-13 13:21 [PATCH v2] i2c: spacemit: fix detect issue Troy Mitchell
@ 2025-11-13 15:37 ` Michael Opdenacker
2025-11-14 13:32 ` Troy Mitchell
2025-11-13 21:41 ` Aurelien Jarno
2025-12-03 20:46 ` Andi Shyti
2 siblings, 1 reply; 6+ messages in thread
From: Michael Opdenacker @ 2025-11-13 15:37 UTC (permalink / raw)
To: Troy Mitchell, Andi Shyti, Yixun Lan, Alex Elder, Aurelien Jarno
Cc: michael.opdenacker, Troy Mitchell, linux-i2c, linux-kernel,
linux-riscv, spacemit
Hi Troy
Thanks for the fix!
On 11/13/25 14:21, Troy Mitchell wrote:
> 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")
> Tested-by: Aurelien Jarno <aurelien@aurel32.net>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
> Changelog in v2:
> - handle ALD and BED errors separately in spacemit_i2c_handle_err()
> - move clear_int_status() above spacemit_i2c_init()
> - move clear_int_status() from xfer() into spacemit_i2c_init()
> - Link to v1: https://lore.kernel.org/all/20251103-fix-k1-detect-failure-v1-1-bb07a8d7de7c@linux.spacemit.com/
> ---
> drivers/i2c/busses/i2c-k1.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-k1.c b/drivers/i2c/busses/i2c-k1.c
> index 6b918770e612e098b8ad17418f420d87c94df166..d42c03ef5db5984ea8e06b3d7eb485b4f899e616 100644
> --- a/drivers/i2c/busses/i2c-k1.c
> +++ b/drivers/i2c/busses/i2c-k1.c
> @@ -158,11 +158,16 @@ static int spacemit_i2c_handle_err(struct spacemit_i2c_dev *i2c)
> {
> dev_dbg(i2c->dev, "i2c error status: 0x%08x\n", i2c->status);
>
> - if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
> + /* Arbitration Loss Detected */
> + if (i2c->status & SPACEMIT_SR_ALD) {
> spacemit_i2c_reset(i2c);
> return -EAGAIN;
> }
>
> + /* Bus Error No ACK/NAK */
> + if (i2c->status & SPACEMIT_SR_BED)
> + spacemit_i2c_reset(i2c);
> +
> return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
> }
>
> @@ -224,6 +229,12 @@ static void spacemit_i2c_check_bus_release(struct spacemit_i2c_dev *i2c)
> }
> }
>
> +static inline void
> +spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
> +{
> + writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
> +}
> +
> static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
> {
> u32 val;
> @@ -267,12 +278,8 @@ static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
> val = readl(i2c->base + SPACEMIT_IRCR);
> val |= SPACEMIT_RCR_SDA_GLITCH_NOFIX;
> writel(val, i2c->base + SPACEMIT_IRCR);
> -}
>
> -static inline void
> -spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
> -{
> - writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
> + spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
> }
>
> static void spacemit_i2c_start(struct spacemit_i2c_dev *i2c)
>
> ---
> base-commit: 6fa9041b7177f6771817b95e83f6df17b147c8c6
> change-id: 20251113-fix-k1-detect-failure-63483e45168b
Tested successfully on OrangePi RV2.
Tested-by: Michael Opdenacker <michael.opdenacker@rootcommit.com>
Thanks again
Michael.
--
Michael Opdenacker
Root Commit
Yocto Project and OpenEmbedded Training course - Learn by doing:
https://rootcommit.com/training/yocto/
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] i2c: spacemit: fix detect issue
2025-11-13 15:37 ` Michael Opdenacker
@ 2025-11-14 13:32 ` Troy Mitchell
0 siblings, 0 replies; 6+ messages in thread
From: Troy Mitchell @ 2025-11-14 13:32 UTC (permalink / raw)
To: Michael Opdenacker, Troy Mitchell, Andi Shyti, Yixun Lan,
Alex Elder, Aurelien Jarno
Cc: Troy Mitchell, linux-i2c, linux-kernel, linux-riscv, spacemit
Hi Michael,
On Thu, Nov 13, 2025 at 03:37:32PM +0000, Michael Opdenacker wrote:
> Tested successfully on OrangePi RV2.
Thanks for your test on RV2!
- Troy
>
> Tested-by: Michael Opdenacker <michael.opdenacker@rootcommit.com>
> Thanks again
> Michael.
>
> --
> Michael Opdenacker
> Root Commit
> Yocto Project and OpenEmbedded Training course - Learn by doing:
> https://rootcommit.com/training/yocto/
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] i2c: spacemit: fix detect issue
2025-11-13 13:21 [PATCH v2] i2c: spacemit: fix detect issue Troy Mitchell
2025-11-13 15:37 ` Michael Opdenacker
@ 2025-11-13 21:41 ` Aurelien Jarno
2025-11-14 13:31 ` Troy Mitchell
2025-12-03 20:46 ` Andi Shyti
2 siblings, 1 reply; 6+ messages in thread
From: Aurelien Jarno @ 2025-11-13 21:41 UTC (permalink / raw)
To: Troy Mitchell
Cc: Andi Shyti, Yixun Lan, Alex Elder, Michael Opdenacker,
Troy Mitchell, linux-i2c, linux-kernel, linux-riscv, spacemit
On 2025-11-13 21:21, Troy Mitchell wrote:
> 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")
> Tested-by: Aurelien Jarno <aurelien@aurel32.net>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> ---
> Changelog in v2:
> - handle ALD and BED errors separately in spacemit_i2c_handle_err()
> - move clear_int_status() above spacemit_i2c_init()
> - move clear_int_status() from xfer() into spacemit_i2c_init()
> - Link to v1: https://lore.kernel.org/all/20251103-fix-k1-detect-failure-v1-1-bb07a8d7de7c@linux.spacemit.com/
> ---
> drivers/i2c/busses/i2c-k1.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
Tested-by: Aurelien Jarno <aurelien@aurel32.net>
Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v2] i2c: spacemit: fix detect issue
2025-11-13 21:41 ` Aurelien Jarno
@ 2025-11-14 13:31 ` Troy Mitchell
0 siblings, 0 replies; 6+ messages in thread
From: Troy Mitchell @ 2025-11-14 13:31 UTC (permalink / raw)
To: Troy Mitchell, Andi Shyti, Yixun Lan, Alex Elder,
Michael Opdenacker, Troy Mitchell, linux-i2c, linux-kernel,
linux-riscv, spacemit
Hi Aurelien,
On Thu, Nov 13, 2025 at 10:41:18PM +0100, Aurelien Jarno wrote:
> On 2025-11-13 21:21, Troy Mitchell wrote:
>
> Tested-by: Aurelien Jarno <aurelien@aurel32.net>
> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Thanks for your test and review!
- Troy
>
> --
> Aurelien Jarno GPG: 4096R/1DDD8C9B
> aurelien@aurel32.net http://aurel32.net
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] i2c: spacemit: fix detect issue
2025-11-13 13:21 [PATCH v2] i2c: spacemit: fix detect issue Troy Mitchell
2025-11-13 15:37 ` Michael Opdenacker
2025-11-13 21:41 ` Aurelien Jarno
@ 2025-12-03 20:46 ` Andi Shyti
2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2025-12-03 20:46 UTC (permalink / raw)
To: Troy Mitchell
Cc: Yixun Lan, Alex Elder, Michael Opdenacker, Aurelien Jarno,
Troy Mitchell, linux-i2c, linux-kernel, linux-riscv, spacemit
Hi Troy,
On Thu, Nov 13, 2025 at 09:21:50PM +0800, Troy Mitchell wrote:
> 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")
> Tested-by: Aurelien Jarno <aurelien@aurel32.net>
> Signed-off-by: Troy Mitchell <troy.mitchell@linux.spacemit.com>
merged to i2c/i2c-host.
Thanks,
Andi
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-12-03 20:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-13 13:21 [PATCH v2] i2c: spacemit: fix detect issue Troy Mitchell
2025-11-13 15:37 ` Michael Opdenacker
2025-11-14 13:32 ` Troy Mitchell
2025-11-13 21:41 ` Aurelien Jarno
2025-11-14 13:31 ` Troy Mitchell
2025-12-03 20:46 ` Andi Shyti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox