Skip to contentSkip to conversation

i2c: i2c-cdns: Driver fixes

PATCH Applied Michal Simek 2 participants 5 messages Mar 1, 2022 – Mar 9, 2022 I2C

lore
Share & tools
lore
#0 lore raw

cover i2c: i2c-cdns: Driver fixes

Hi,

these 3 patches came from checking functionality on QEMU in connection to SOM program.

Thanks,
Michal

Sai Pavan Boddu (3):
i2c: i2c-cdns: Start read transaction after write to transfer_size reg
i2c: i2c-cdns: Fix write transaction state
i2c: i2c-cdns: Prevent early termination of write

 drivers/i2c/i2c-cdns.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/3 i2c: i2c-cdns: Fix write transaction state

From: Sai Pavan Boddu <[email protected]>

Start write transfer after loading data to FIFO.

---

 drivers/i2c/i2c-cdns.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/i2c/i2c-cdns.c +6 -0
index 5736afb45191..07d53be11f12 100644
@@ -251,6 +251,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 	u8 *cur_data = data;
 	struct cdns_i2c_regs *regs = i2c_bus->regs;
 	u32 ret;
+	bool start = 1;
 
 	/* Set the controller in Master transmit mode and clear FIFO */
 	setbits_le32(&regs->control, CDNS_I2C_CONTROL_CLR_FIFO);
@@ -269,6 +270,11 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 
 	while (len-- && !is_arbitration_lost(regs)) {
 		writel(*(cur_data++), &regs->data);
+		/* Trigger write only after loading data */
+		if (start) {
+			writel(addr, &regs->address);
+			start = 0;
+		}
 		if (len && readl(&regs->transfer_size) == CDNS_I2C_FIFO_DEPTH) {
 			ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP |
 					    CDNS_I2C_INTERRUPT_ARBLOST);
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/3 i2c: i2c-cdns: Start read transaction after write to transfer_size reg

In reply to Michal Simek

From: Sai Pavan Boddu <[email protected]>

Avoid a race condition where read transaction is started keeping expected bytes as 0. Which sometimes would result in sending STOP signal as no data is expected. Observed on QEMU platform.

---

 drivers/i2c/i2c-cdns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/i2c-cdns.c +1 -1
index a650dd69b89f..5736afb45191 100644
@@ -375,7 +375,6 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 				curr_recv_count = recv_count;
 			}
 		} else if (recv_count && !hold_quirk && !curr_recv_count) {
-			writel(addr, &regs->address);
 			if (recv_count > CDNS_I2C_TRANSFER_SIZE) {
 				writel(CDNS_I2C_TRANSFER_SIZE,
 				       &regs->transfer_size);
@@ -384,6 +383,7 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 				writel(recv_count, &regs->transfer_size);
 				curr_recv_count = recv_count;
 			}
+			writel(addr, &regs->address);
 		}
 	}
 
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/3 i2c: i2c-cdns: Prevent early termination of write

In reply to Michal Simek

From: Sai Pavan Boddu <[email protected]>

During sequential loading of data, hold the bus to prevent controller from sending stop signal in case no data is available in fifo.

---

 drivers/i2c/i2c-cdns.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/i2c/i2c-cdns.c +6 -4
index 07d53be11f12..0da9f6f35a9f 100644
@@ -257,16 +257,18 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data,
 	setbits_le32(&regs->control, CDNS_I2C_CONTROL_CLR_FIFO);
 	clrbits_le32(&regs->control, CDNS_I2C_CONTROL_RW);
 
-	/* Check message size against FIFO depth, and set hold bus bit
-	 * if it is greater than FIFO depth
+	/*
+	 * For sequential data load hold the bus.
 	 */
-	if (len > CDNS_I2C_FIFO_DEPTH)
+	if (len > 1)
 		setbits_le32(&regs->control, CDNS_I2C_CONTROL_HOLD);
 
 	/* Clear the interrupts in status register */
 	writel(CDNS_I2C_INTERRUPTS_MASK, &regs->interrupt_status);
 
-	writel(addr, &regs->address);
+	/* In case of Probe (i.e no data), start the transfer */
+	if (!len)
+		writel(addr, &regs->address);
 
 	while (len-- && !is_arbitration_lost(regs)) {
 		writel(*(cur_data++), &regs->data);
Signature · 1 line
2.35.1
Applied
#4 lore raw
In reply to Michal Simek

út 1. 3. 2022 v 9:16 odesílatel Michal Simek <[email protected]> napsal:

Quoted 15 lines

Hi,

these 3 patches came from checking functionality on QEMU in connection to SOM program.

Thanks,
Michal

Sai Pavan Boddu (3):
i2c: i2c-cdns: Start read transaction after write to transfer_size reg
i2c: i2c-cdns: Fix write transaction state
i2c: i2c-cdns: Prevent early termination of write

Quoted 6 lines
 drivers/i2c/i2c-cdns.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

--
2.35.1

applied.
M

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs