linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND 0/3] i2c: at91: Fixes and updates
@ 2022-06-14 10:13 Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Codrin Ciubotariu @ 2022-06-14 10:13 UTC (permalink / raw)
  To: linux-i2c, linux-arm-kernel, linux-kernel
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches, andrew,
	mhoffman, khali, wsa, peda, Codrin Ciubotariu

Resend due to the fact that the i2c list no longer accepts replys on the
old patch-set. Comments not addressed yet.

The first patch is mostly a prerequisite for the second one. It only
moves the i2c_recover_bus() out of the actual transfer function. This
helps the second patch disable the controller before using GPIO
recovery. The second patch will keep the controller enabled when a
transfer occurs. Before using GPIO recovery, the controller must be
disabled, to ignore potential glitches. However, the controller must be
enabled for HW recovery (bus CLEAR command). The third and last patch
adds advanced digital filtering support for SAMA5D4. The TWI IP found in
SAMA5D4 supports advanced digital filtering, even if, at the moment of
this patch, the SAMA5D4 datasheet does not mention it.

Codrin Ciubotariu (3):
  i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer()
  i2c: at91: keep the controller disabled when it is not used
  i2c: at91: add advanced digital filtering support for SAMA5D4

 drivers/i2c/busses/i2c-at91-core.c   |  1 +
 drivers/i2c/busses/i2c-at91-master.c | 53 ++++++++++++++++++++++------
 2 files changed, 44 insertions(+), 10 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer()
  2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
@ 2022-06-14 10:13 ` Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 2/3] i2c: at91: keep the controller disabled when it is not used Codrin Ciubotariu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Codrin Ciubotariu @ 2022-06-14 10:13 UTC (permalink / raw)
  To: linux-i2c, linux-arm-kernel, linux-kernel
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches, andrew,
	mhoffman, khali, wsa, peda, Codrin Ciubotariu

This patch doesn't add a functional change, it just separates the recovery
from the transfer itself.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---

Removed 'Fixes' tag

 drivers/i2c/busses/i2c-at91-master.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index c0c35785a0dc..34df1614bc37 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -639,13 +639,6 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
 			       AT91_TWI_THRCLR | AT91_TWI_LOCKCLR);
 	}
 
-	/*
-	 * some faulty I2C slave devices might hold SDA down;
-	 * we can send a bus clear command, hoping that the pins will be
-	 * released
-	 */
-	i2c_recover_bus(&dev->adapter);
-
 	return ret;
 }
 
@@ -716,7 +709,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
 	ret = at91_do_twi_transfer(dev);
 	i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret);
 
-	ret = (ret < 0) ? ret : num;
+	if (ret < 0) {
+		/*
+		 * some faulty I2C slave devices might hold SDA down;
+		 * we can send a bus clear command, hoping that the pins will be
+		 * released
+		 */
+		i2c_recover_bus(&dev->adapter);
+	} else {
+		ret = num;
+	}
+
 out:
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RESEND 2/3] i2c: at91: keep the controller disabled when it is not used
  2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
@ 2022-06-14 10:13 ` Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4 Codrin Ciubotariu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Codrin Ciubotariu @ 2022-06-14 10:13 UTC (permalink / raw)
  To: linux-i2c, linux-arm-kernel, linux-kernel
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches, andrew,
	mhoffman, khali, wsa, peda, Codrin Ciubotariu

The controller (master mode) should be disabled when it is not used, to
avoid potential glitches on the bus. The controller must be disabled
only when the controller is not running.
This fixes an issue on Microchip's SAMA5D4 platform when pinctrl changes
the I2C's pin states between GPIO and I2C, done when GPIO recovery is used.

Fixes: 813e30e9ab91 ("i2c: New Atmel AT91 bus driver")
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 drivers/i2c/busses/i2c-at91-master.c | 34 ++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index 34df1614bc37..14c2a4856978 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -38,7 +38,7 @@ void at91_init_twi_bus_master(struct at91_twi_dev *dev)
 	/* FIFO should be enabled immediately after the software reset */
 	if (dev->fifo_size)
 		at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_FIFOEN);
-	at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSEN);
+	at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSDIS);
 	at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_SVDIS);
 	at91_twi_write(dev, AT91_TWI_CWGR, dev->twi_cwgr_reg);
 
@@ -593,7 +593,6 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
 	if (time_left == 0) {
 		dev->transfer_status |= at91_twi_read(dev, AT91_TWI_SR);
 		dev_err(dev->dev, "controller timed out\n");
-		at91_init_twi_bus(dev);
 		ret = -ETIMEDOUT;
 		goto error;
 	}
@@ -642,6 +641,26 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
 	return ret;
 }
 
+static void at91_twi_disable(struct at91_twi_dev *dev)
+{
+	/* return if previous operation is completed */
+	if (!(at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_TXCOMP)) {
+		/* wait for previous command to complete before disabling the controller */
+		dev_dbg(dev->dev, "wait for command to complete...\n");
+		reinit_completion(&dev->cmd_complete);
+		dev->transfer_status = 0;
+		at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP);
+		wait_for_completion_timeout(&dev->cmd_complete, dev->adapter.timeout);
+		if (!(dev->transfer_status & AT91_TWI_TXCOMP)) {
+			dev_dbg(dev->dev, "IP still busy, resetting the controller...\n");
+			at91_init_twi_bus(dev);
+			return;
+		}
+	}
+
+	at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSDIS);
+}
+
 static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
 {
 	struct at91_twi_dev *dev = i2c_get_adapdata(adap);
@@ -657,6 +676,8 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
 	if (ret < 0)
 		goto out;
 
+	at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSEN);
+
 	if (num == 2) {
 		int internal_address = 0;
 		int i;
@@ -710,13 +731,22 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
 	i2c_put_dma_safe_msg_buf(dma_buf, m_start, !ret);
 
 	if (ret < 0) {
+		/* disable controller before using GPIO recovery */
+		if (!dev->pdata->has_clear_cmd)
+			at91_twi_disable(dev);
+
 		/*
 		 * some faulty I2C slave devices might hold SDA down;
 		 * we can send a bus clear command, hoping that the pins will be
 		 * released
 		 */
 		i2c_recover_bus(&dev->adapter);
+
+		/* disable controller if not disabled before */
+		if (dev->pdata->has_clear_cmd)
+			at91_twi_disable(dev);
 	} else {
+		at91_twi_disable(dev);
 		ret = num;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RESEND 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4
  2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
  2022-06-14 10:13 ` [RESEND 2/3] i2c: at91: keep the controller disabled when it is not used Codrin Ciubotariu
@ 2022-06-14 10:13 ` Codrin Ciubotariu
  2022-06-29 19:46 ` [RESEND 0/3] i2c: at91: Fixes and updates Wolfram Sang
  2025-03-20 22:18 ` Andi Shyti
  4 siblings, 0 replies; 8+ messages in thread
From: Codrin Ciubotariu @ 2022-06-14 10:13 UTC (permalink / raw)
  To: linux-i2c, linux-arm-kernel, linux-kernel
  Cc: nicolas.ferre, alexandre.belloni, ludovic.desroches, andrew,
	mhoffman, khali, wsa, peda, Codrin Ciubotariu

I2C/TWI IP variant found in SAMA5D4 supports advanced digital filtering,
even though, at the time of this patch, it is not present in Datasheet.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 drivers/i2c/busses/i2c-at91-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/i2c/busses/i2c-at91-core.c b/drivers/i2c/busses/i2c-at91-core.c
index 2df9df585131..7549a75a98ef 100644
--- a/drivers/i2c/busses/i2c-at91-core.c
+++ b/drivers/i2c/busses/i2c-at91-core.c
@@ -120,6 +120,7 @@ static struct at91_twi_pdata sama5d4_config = {
 	.clk_offset = 4,
 	.has_hold_field = true,
 	.has_dig_filtr = true,
+	.has_adv_dig_filtr = true,
 };
 
 static struct at91_twi_pdata sama5d2_config = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RESEND 0/3] i2c: at91: Fixes and updates
  2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
                   ` (2 preceding siblings ...)
  2022-06-14 10:13 ` [RESEND 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4 Codrin Ciubotariu
@ 2022-06-29 19:46 ` Wolfram Sang
  2022-06-30  7:41   ` Nicolas Ferre
  2025-03-20 22:18 ` Andi Shyti
  4 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2022-06-29 19:46 UTC (permalink / raw)
  To: Codrin Ciubotariu
  Cc: linux-i2c, linux-arm-kernel, linux-kernel, nicolas.ferre,
	alexandre.belloni, ludovic.desroches, andrew, mhoffman, khali,
	peda

[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

On Tue, Jun 14, 2022 at 01:13:44PM +0300, Codrin Ciubotariu wrote:
> Resend due to the fact that the i2c list no longer accepts replys on the
> old patch-set. Comments not addressed yet.
> 
> The first patch is mostly a prerequisite for the second one. It only
> moves the i2c_recover_bus() out of the actual transfer function. This
> helps the second patch disable the controller before using GPIO
> recovery. The second patch will keep the controller enabled when a
> transfer occurs. Before using GPIO recovery, the controller must be
> disabled, to ignore potential glitches. However, the controller must be
> enabled for HW recovery (bus CLEAR command). The third and last patch
> adds advanced digital filtering support for SAMA5D4. The TWI IP found in
> SAMA5D4 supports advanced digital filtering, even if, at the moment of
> this patch, the SAMA5D4 datasheet does not mention it.

So, can you guys read this mail? It should be possible somehow that I
can read your remarks to my remarks, no?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND 0/3] i2c: at91: Fixes and updates
  2022-06-29 19:46 ` [RESEND 0/3] i2c: at91: Fixes and updates Wolfram Sang
@ 2022-06-30  7:41   ` Nicolas Ferre
  2022-06-30  8:09     ` Wolfram Sang
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Ferre @ 2022-06-30  7:41 UTC (permalink / raw)
  To: Wolfram Sang, Codrin Ciubotariu, linux-i2c, linux-arm-kernel,
	linux-kernel, alexandre.belloni, ludovic.desroches, andrew,
	mhoffman, khali, peda, Claudiu Beznea
  Cc: Cristian Birsan

Hi Wolfram,

On 29/06/2022 at 21:46, Wolfram Sang wrote:
> On Tue, Jun 14, 2022 at 01:13:44PM +0300, Codrin Ciubotariu wrote:
>> Resend due to the fact that the i2c list no longer accepts replys on the
>> old patch-set. Comments not addressed yet.
>>
>> The first patch is mostly a prerequisite for the second one. It only
>> moves the i2c_recover_bus() out of the actual transfer function. This
>> helps the second patch disable the controller before using GPIO
>> recovery. The second patch will keep the controller enabled when a
>> transfer occurs. Before using GPIO recovery, the controller must be
>> disabled, to ignore potential glitches. However, the controller must be
>> enabled for HW recovery (bus CLEAR command). The third and last patch
>> adds advanced digital filtering support for SAMA5D4. The TWI IP found in
>> SAMA5D4 supports advanced digital filtering, even if, at the moment of
>> this patch, the SAMA5D4 datasheet does not mention it.
 >
> So, can you guys read this mail? It should be possible somehow that I
> can read your remarks to my remarks, no?

Codrin is not with Microchip anymore and we have to re-distribute the 
maintenance of this driver internally. His email address will probably 
"bounce" soon.

So, forgive us if there's a lack of response for some time ;-)

Best regards,
   Nicolas

-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND 0/3] i2c: at91: Fixes and updates
  2022-06-30  7:41   ` Nicolas Ferre
@ 2022-06-30  8:09     ` Wolfram Sang
  0 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2022-06-30  8:09 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Codrin Ciubotariu, linux-i2c, linux-arm-kernel, linux-kernel,
	alexandre.belloni, ludovic.desroches, andrew, mhoffman, khali,
	peda, Claudiu Beznea, Cristian Birsan

[-- Attachment #1: Type: text/plain, Size: 308 bytes --]

Hi Nicolas,

> Codrin is not with Microchip anymore and we have to re-distribute the
> maintenance of this driver internally. His email address will probably
> "bounce" soon.

Ah, very unfortunate that we couldn't move this series forward
because of the mysterious mail problems.

All the best,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RESEND 0/3] i2c: at91: Fixes and updates
  2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
                   ` (3 preceding siblings ...)
  2022-06-29 19:46 ` [RESEND 0/3] i2c: at91: Fixes and updates Wolfram Sang
@ 2025-03-20 22:18 ` Andi Shyti
  4 siblings, 0 replies; 8+ messages in thread
From: Andi Shyti @ 2025-03-20 22:18 UTC (permalink / raw)
  To: Codrin Ciubotariu
  Cc: linux-i2c, linux-arm-kernel, linux-kernel, nicolas.ferre,
	alexandre.belloni, ludovic.desroches, andrew, mhoffman, khali,
	wsa, peda

Hi Codrin,

> Codrin Ciubotariu (3):
>   i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer()
>   i2c: at91: keep the controller disabled when it is not used
>   i2c: at91: add advanced digital filtering support for SAMA5D4

if you still have interest in applying this patch, may I please
ask you to resend it?

Thanks,
Andi

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-03-20 22:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14 10:13 [RESEND 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
2022-06-14 10:13 ` [RESEND 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
2022-06-14 10:13 ` [RESEND 2/3] i2c: at91: keep the controller disabled when it is not used Codrin Ciubotariu
2022-06-14 10:13 ` [RESEND 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4 Codrin Ciubotariu
2022-06-29 19:46 ` [RESEND 0/3] i2c: at91: Fixes and updates Wolfram Sang
2022-06-30  7:41   ` Nicolas Ferre
2022-06-30  8:09     ` Wolfram Sang
2025-03-20 22:18 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).