Skip to content

Commit 25faa53

Browse files
TroyMitchell911Andi Shyti
authored andcommitted
i2c: spacemit: fix detect issue
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: 5ea5584 ("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> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net> Tested-by: Michael Opdenacker <michael.opdenacker@rootcommit.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20251113-fix-k1-detect-failure-v2-1-b02a9a74f65a@linux.spacemit.com
1 parent a6ee6aa commit 25faa53

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

drivers/i2c/busses/i2c-k1.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,16 @@ static int spacemit_i2c_handle_err(struct spacemit_i2c_dev *i2c)
158158
{
159159
dev_dbg(i2c->dev, "i2c error status: 0x%08x\n", i2c->status);
160160

161-
if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
161+
/* Arbitration Loss Detected */
162+
if (i2c->status & SPACEMIT_SR_ALD) {
162163
spacemit_i2c_reset(i2c);
163164
return -EAGAIN;
164165
}
165166

167+
/* Bus Error No ACK/NAK */
168+
if (i2c->status & SPACEMIT_SR_BED)
169+
spacemit_i2c_reset(i2c);
170+
166171
return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
167172
}
168173

@@ -224,6 +229,12 @@ static void spacemit_i2c_check_bus_release(struct spacemit_i2c_dev *i2c)
224229
}
225230
}
226231

232+
static inline void
233+
spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
234+
{
235+
writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
236+
}
237+
227238
static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
228239
{
229240
u32 val;
@@ -267,12 +278,8 @@ static void spacemit_i2c_init(struct spacemit_i2c_dev *i2c)
267278
val = readl(i2c->base + SPACEMIT_IRCR);
268279
val |= SPACEMIT_RCR_SDA_GLITCH_NOFIX;
269280
writel(val, i2c->base + SPACEMIT_IRCR);
270-
}
271281

272-
static inline void
273-
spacemit_i2c_clear_int_status(struct spacemit_i2c_dev *i2c, u32 mask)
274-
{
275-
writel(mask & SPACEMIT_I2C_INT_STATUS_MASK, i2c->base + SPACEMIT_ISR);
282+
spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
276283
}
277284

278285
static void spacemit_i2c_start(struct spacemit_i2c_dev *i2c)

0 commit comments

Comments
 (0)