Skip to contentSkip to conversation

Create i2c_writesl_vi() to use with VI I2C

PATCH Superseded Sowjanya Komatineni 2 participants 5 messages Jan 12, 2021

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Create i2c_writesl_vi() to use with VI I2C

Patch in this series is to fix silent hang seen when using writesl() for filling VI I2C TX FIFO.

Delta between patch versions:
[v2]: Creates i2c_writesl_vi() for vi i2c based on v1 feedback.

[v1]: Updates i2c_writesl() to use writel() followed by i2c_readl().

Sowjanya Komatineni (1):
i2c: tegra: Create i2c_writesl_vi() to use with VI I2C for filling TX
FIFO

 drivers/i2c/busses/i2c-tegra.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/1 i2c: tegra: Create i2c_writesl_vi() to use with VI I2C for filling TX FIFO

VI I2C don't have DMA support and uses PIO mode all the time.

Current driver uses writesl() to fill TX FIFO based on available empty slots and with this seeing strange silent hang during any I2C register access after filling TX FIFO with 8 words.

Using writel() followed by i2c_readl() in a loop to write all words to TX FIFO instead of using writesl() helps for large transfers in PIO mode.

So, this patch creates i2c_writesl_vi() API to use with VI I2C for filling TX FIFO.

---
 drivers/i2c/busses/i2c-tegra.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-tegra.c +19 -1
index 6f08c0c..e2b7503 100644
@@ -339,6 +339,21 @@ static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
 	writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
 }
 
+static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, u32 *data,
+			   unsigned int reg, unsigned int len)
+{
+	/*
+	 * Using writesl() to fill VI I2C TX FIFO for transfers more than
+	 * 6 words is causing a silent hang on any VI I2C register access
+	 * after TX FIFO writes.
+	 * So using writel() followed by i2c_readl().
+	 */
+	while (len--) {
+		writel(*data++, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+		i2c_readl(i2c_dev, I2C_INT_STATUS);
+	}
+}
+
 static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
 		       unsigned int reg, unsigned int len)
 {
@@ -811,7 +826,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
 		i2c_dev->msg_buf_remaining = buf_remaining;
 		i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
 
-		i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		if (i2c_dev->is_vi)
+			i2c_writesl_vi(i2c_dev, (u32 *)buf, I2C_TX_FIFO, words_to_transfer);
+		else
+			i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
 
 		buf += words_to_transfer * BYTES_PER_FIFO_WORD;
 	}
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v2] i2c: tegra: Create i2c_writesl_vi() to use with VI I2C for filling TX FIFO

12.01.2021 07:06, Sowjanya Komatineni пишет:

Quoted 47 lines

VI I2C don't have DMA support and uses PIO mode all the time.

Current driver uses writesl() to fill TX FIFO based on available empty slots and with this seeing strange silent hang during any I2C register access after filling TX FIFO with 8 words.

Using writel() followed by i2c_readl() in a loop to write all words to TX FIFO instead of using writesl() helps for large transfers in PIO mode.

So, this patch creates i2c_writesl_vi() API to use with VI I2C for filling TX FIFO.

---
 drivers/i2c/busses/i2c-tegra.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-tegra.c +15 -0
index 6f08c0c..e2b7503 100644
@@ -339,6 +339,21 @@ static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
 	writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
 }
 
+static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, u32 *data,
+			   unsigned int reg, unsigned int len)
+{
+	/*
+	 * Using writesl() to fill VI I2C TX FIFO for transfers more than
+	 * 6 words is causing a silent hang on any VI I2C register access
+	 * after TX FIFO writes.
+	 * So using writel() followed by i2c_readl().
+	 */
+	while (len--) {
+		writel(*data++, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+		i2c_readl(i2c_dev, I2C_INT_STATUS);
+	}
+}
+
 static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
 		       unsigned int reg, unsigned int len)
 {
@@ -811,7 +826,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
 		i2c_dev->msg_buf_remaining = buf_remaining;

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) · line 835

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +4 -1
 		i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
 
-		i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		if (i2c_dev->is_vi)
+			i2c_writesl_vi(i2c_dev, (u32 *)buf, I2C_TX_FIFO, words_to_transfer);
+		else
+			i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
 
 		buf += words_to_transfer * BYTES_PER_FIFO_WORD;
 	}

Looks almost good, could we please use a relaxed writel and avoid the casting in the code?

Like this:

drivers/i2c/busses/i2c-tegra.c +21 -1
index 6f08c0c3238d..4f843b423d83 100644
@@ -326,6 +326,8 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned int reg)
 	/* read back register to make sure that register writes completed */
 	if (reg != I2C_TX_FIFO)
 		readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+	else
+		readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, I2C_INT_STATUS));
 }
 
 static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
@@ -339,6 +341,21 @@ static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
 	writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
 }
 
+static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, void *data,
+			   unsigned int reg, unsigned int len)
+{
+	u32 *data32 = data;
+
+	/*
+	 * Using writesl() to fill VI I2C TX FIFO for transfers more than
+	 * 6 words is causing a silent hang on any VI I2C register access
+	 * after TX FIFO writes. Each write to FIFO should follow by a read
+	 * of any I2C register in order to work around the problem.
+	 */
+	while (len--)
+		i2c_writel(i2c_dev, *data32++, reg);
+}
+
 static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
 		       unsigned int reg, unsigned int len)
 {
@@ -811,7 +828,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
 		i2c_dev->msg_buf_remaining = buf_remaining;
 		i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
 
-		i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		if (i2c_dev->is_vi)
+			i2c_writesl_vi(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		else
+			i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
 
 		buf += words_to_transfer * BYTES_PER_FIFO_WORD;
 	}
#3 lore raw

Re: [PATCH v2] i2c: tegra: Create i2c_writesl_vi() to use with VI I2C for filling TX FIFO

Quoted 99 lines · Dmitry Osipenko

12.01.2021 07:06, Sowjanya Komatineni пишет:

Quoted 47 lines

VI I2C don't have DMA support and uses PIO mode all the time.

Current driver uses writesl() to fill TX FIFO based on available empty slots and with this seeing strange silent hang during any I2C register access after filling TX FIFO with 8 words.

Using writel() followed by i2c_readl() in a loop to write all words to TX FIFO instead of using writesl() helps for large transfers in PIO mode.

So, this patch creates i2c_writesl_vi() API to use with VI I2C for filling TX FIFO.

---
  drivers/i2c/busses/i2c-tegra.c | 20 +++++++++++++++++++-
  1 file changed, 19 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-tegra.c +15 -0
index 6f08c0c..e2b7503 100644
@@ -339,6 +339,21 @@ static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
  	writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
  }
 
+static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, u32 *data,
+			   unsigned int reg, unsigned int len)
+{
+	/*
+	 * Using writesl() to fill VI I2C TX FIFO for transfers more than
+	 * 6 words is causing a silent hang on any VI I2C register access
+	 * after TX FIFO writes.
+	 * So using writel() followed by i2c_readl().
+	 */
+	while (len--) {
+		writel(*data++, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+		i2c_readl(i2c_dev, I2C_INT_STATUS);
+	}
+}
+
  static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
  		       unsigned int reg, unsigned int len)
  {
@@ -811,7 +826,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
  		i2c_dev->msg_buf_remaining = buf_remaining;

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) · line 835

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +4 -1
  		i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
 
-		i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		if (i2c_dev->is_vi)
+			i2c_writesl_vi(i2c_dev, (u32 *)buf, I2C_TX_FIFO, words_to_transfer);
+		else
+			i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
 
  		buf += words_to_transfer * BYTES_PER_FIFO_WORD;
  	}

Looks almost good, could we please use a relaxed writel and avoid the casting in the code?

Like this:

drivers/i2c/busses/i2c-tegra.c +17 -0
index 6f08c0c3238d..4f843b423d83 100644
@@ -326,6 +326,8 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val, unsigned int reg)
  	/* read back register to make sure that register writes completed */
  	if (reg != I2C_TX_FIFO)
  		readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+	else
+		readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, I2C_INT_STATUS));
  }
 
  static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned int reg)
@@ -339,6 +341,21 @@ static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
  	writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data, len);
  }
 
+static void i2c_writesl_vi(struct tegra_i2c_dev *i2c_dev, void *data,
+			   unsigned int reg, unsigned int len)
+{
+	u32 *data32 = data;
+
+	/*
+	 * Using writesl() to fill VI I2C TX FIFO for transfers more than
+	 * 6 words is causing a silent hang on any VI I2C register access
+	 * after TX FIFO writes. Each write to FIFO should follow by a read
+	 * of any I2C register in order to work around the problem.
+	 */
+	while (len--)
+		i2c_writel(i2c_dev, *data32++, reg);
+}
+
  static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
  		       unsigned int reg, unsigned int len)
  {
@@ -811,7 +828,10 @@ static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev)
  		i2c_dev->msg_buf_remaining = buf_remaining;

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_fill_tx_fifo(struct tegra_i2c_dev *i2c_dev) · line 837

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +4 -1
  		i2c_dev->msg_buf = buf + words_to_transfer * BYTES_PER_FIFO_WORD;
 
-		i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		if (i2c_dev->is_vi)
+			i2c_writesl_vi(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
+		else
+			i2c_writesl(i2c_dev, buf, I2C_TX_FIFO, words_to_transfer);
 
  		buf += words_to_transfer * BYTES_PER_FIFO_WORD;
  	}

Will have v3.

#4 lore raw

Re: [PATCH v2] i2c: tegra: Create i2c_writesl_vi() to use with VI I2C for filling TX FIFO

12.01.2021 19:57, Sowjanya Komatineni пишет:
...

Quoted 11 lines
Quoted 10 lines
(quoted diff) +0 -0
@@ -326,6 +326,8 @@ static void i2c_writel(struct tegra_i2c_dev
 *i2c_dev, u32 val, unsigned int reg)
       /* read back register to make sure that register writes

completed */
      if (reg != I2C_TX_FIFO) readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
+    else
+        readl_relaxed(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, I2C_INT_STATUS));

Perhaps will be a bit better to replace this "else" with "else if (i2c_dev->is_vi)".