* [PATCH v2 1/1] i2c: i2c-xiic: fix clearing of bnb irq
2026-10-15 8:11 [PATCH v2 0/1] i2c: i2c-xiic: fix clearing of bnb irq Thilo Zirnstein
@ 2026-10-15 8:11 ` Thilo Zirnstein
0 siblings, 0 replies; 2+ messages in thread
From: Thilo Zirnstein @ 2026-10-15 8:11 UTC (permalink / raw)
To: michal.simek, andi.shyti
Cc: linux-arm-kernel, linux-i2c, linux-kernel, Thilo Zirnstein
Add a function for clearing the bnb bit,
It waits for all preconditions before clearing the bnb bit or times out.
Tested on Zynqmp dev board with some custom logic.
Tested-by: Thilo Zirnstein <thi.zirnstein@gmail.com>
Signed-off-by: Thilo Zirnstein <thi.zirnstein@gmail.com>
---
drivers/i2c/busses/i2c-xiic.c | 42 +++++++++++++++++++++++++++--------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 5e397a7e63f6..da9cedb86f94 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -230,7 +230,9 @@ static const struct timing_regs timing_reg_values[] = {
#define XIIC_RESET_MASK 0xAUL
-#define XIIC_PM_TIMEOUT 1000 /* ms */
+#define XIIC_PM_TIMEOUT 1000 /* ms */
+/* timeout waiting for bus busy */
+#define XIIC_BB_TIMEOUT (msecs_to_jiffies(1))
/* timeout waiting for the controller to respond */
#define XIIC_I2C_TIMEOUT (msecs_to_jiffies(1000))
/* timeout waiting for the controller finish transfers */
@@ -392,6 +394,30 @@ static int xiic_wait_tx_empty(struct xiic_i2c *i2c)
return 0;
}
+static int xiic_clear_en_bnb(struct xiic_i2c *i2c)
+{
+ u8 sr = 0, isr = 0;
+ unsigned long timeout;
+
+ timeout = jiffies + XIIC_BB_TIMEOUT;
+ for (isr = xiic_getreg8(i2c, XIIC_IISR_OFFSET);
+ (isr & XIIC_INTR_BNB_MASK);
+ isr = xiic_getreg8(i2c, XIIC_IISR_OFFSET)) {
+
+ sr = xiic_getreg8(i2c, XIIC_SR_REG_OFFSET);
+ if (sr & XIIC_SR_BUS_BUSY_MASK)
+ xiic_setreg8(i2c, XIIC_IISR_OFFSET, XIIC_INTR_BNB_MASK);
+
+ if (time_after(jiffies, timeout)) {
+ dev_err(i2c->dev, "Failed to clear bnb\n");
+ return -ETIMEDOUT;
+ }
+ }
+
+ xiic_irq_en(i2c, XIIC_INTR_BNB_MASK);
+ return 0;
+}
+
/**
* xiic_setclk - Sets the configured clock rate
* @i2c: Pointer to the xiic device structure
@@ -881,9 +907,6 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
}
if (pend & XIIC_INTR_BNB_MASK) {
- /* IIC bus has transitioned to not busy */
- clr |= XIIC_INTR_BNB_MASK;
-
/* The bus is not busy, disable BusNotBusy interrupt */
xiic_irq_dis(i2c, XIIC_INTR_BNB_MASK);
@@ -1028,7 +1051,7 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, val);
- xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK);
+ xiic_clear_en_bnb(i2c);
} else {
/*
* If previous message is Tx, make sure that Tx FIFO is empty
@@ -1095,7 +1118,7 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
if (i2c->nmsgs == 1)
/* very last, enable bus not busy as well */
- xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK);
+ xiic_clear_en_bnb(i2c);
/* the message is tx:ed */
i2c->tx_pos = msg->len;
@@ -1179,11 +1202,11 @@ static void xiic_start_send(struct xiic_i2c *i2c)
/* Clear any pending Tx empty, Tx Error and then enable them */
xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK |
XIIC_INTR_TX_ERROR_MASK |
- XIIC_INTR_BNB_MASK |
((i2c->nmsgs > 1 || xiic_tx_space(i2c)) ?
XIIC_INTR_TX_HALF_MASK : 0));
xiic_fill_tx_fifo(i2c);
+ xiic_clear_en_bnb(i2c);
} else {
/*
* If previous message is Tx, make sure that Tx FIFO is empty
@@ -1225,8 +1248,9 @@ static void xiic_start_send(struct xiic_i2c *i2c)
/* Clear any pending Tx empty, Tx Error and then enable them */
xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK |
- XIIC_INTR_TX_ERROR_MASK |
- XIIC_INTR_BNB_MASK);
+ XIIC_INTR_TX_ERROR_MASK);
+
+ xiic_clear_en_bnb(i2c);
}
i2c->prev_msg_tx = true;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread