Linux-RISC-V Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/1] fix i2c polling mode workaround for FU540-C000 SoC
@ 2020-10-09 15:39 Sagar Shrikant Kadam
  2020-10-09 15:39 ` [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
  0 siblings, 1 reply; 4+ messages in thread
From: Sagar Shrikant Kadam @ 2020-10-09 15:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andrew, peter, aou, palmer, linux-i2c, paul.walmsley,
	linux-riscv, Sagar Shrikant Kadam

The polling mode workaround for the FU540-C000 on HiFive Unleashed A00
board was added earlier. The logic for this seems to work only in case
the interrupt property was missing/not added into the i2c0 device node.

Here we address this issue by identifying the SOC based on compatibility
string and set the master xfer's to polling mode if it's the FU540-C000
SoC.

The fix has been tested on Linux 5.9.0-rc8 with a PMOD based RTCC sensor
connected to I2C pins J1 header of the board. Log for reference

# uname -a
Linux buildroot 5.9.0-rc8-00001-g9da7791 #1 SMP Fri Oct 9 07:56:13 PDT 2020 riscv64 GNU/Linux
# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f
70: -- -- -- -- -- -- -- --
# i2cget 0 0x57 0 b -y
0xa5
# i2cset 0 0x57 0 0x9f b -y
# i2cget 0 0x57 0 b -y
0x9f
# i2cget 0 0x57 1 b -y
0xff
# i2cset 0 0x57 1 0xa9 b -y
# i2cget 0 0x57 1 b -y
0xa9
# i2cget 0 0x6f 0x20 b -y
0x98
# i2cset 0 0x6f 0x20 0xa5 b -y
# i2cget 0 0x6f 0x20 b -y
0xa5
# i2cget 0 0x6f 0x5f b -y
0x55
# i2cset 0 0x6f 0x5f 0x5a b -y
# i2cget 0 0x6f 0x5f b -y
0x5a
#

Without the fix here, it's observed that "i2cdetect -y 0"
turns the system unresponsive, with CPU stall messages.

Patch History:
===============================
V2: 
-Incorporated changes as suggested by Peter Kosgaard
 https://lkml.org/lkml/2020/10/8/663

V1: Base version

Sagar Shrikant Kadam (1):
  i2c: ocores: fix polling mode workaround on FU540-C000 SoC

 drivers/i2c/busses/i2c-ocores.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

-- 
2.7.4


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-09 15:39 [PATCH v2 0/1] fix i2c polling mode workaround for FU540-C000 SoC Sagar Shrikant Kadam
@ 2020-10-09 15:39 ` Sagar Shrikant Kadam
  2020-10-09 18:24   ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Sagar Shrikant Kadam @ 2020-10-09 15:39 UTC (permalink / raw)
  To: linux-kernel
  Cc: andrew, peter, aou, palmer, linux-i2c, paul.walmsley,
	linux-riscv, Sagar Shrikant Kadam

The FU540-C000 has a broken IRQ and support was added earlier
so that it will operate in polling mode, but seems to work only
in case interrupts property is missing from the i2c0 dt-node.
This should not be the case and the driver should handle polling
mode with the interrupt property present in i2c0 node of the
device tree.
So check if it's the FU540-C000 soc and enable polling mode master
xfers, as the IRQ for this chip is broken.

Fixes commit c45d4ba86731 ("i2c: ocores: add polling mode workaround
for Sifive FU540-C000 SoC")

Signed-off-by: Sagar Shrikant Kadam <sagar.kadam@sifive.com>
---
 drivers/i2c/busses/i2c-ocores.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index f5fc75b..9b3d1ab 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -686,17 +686,21 @@ static int ocores_i2c_probe(struct platform_device *pdev)
 
 	init_waitqueue_head(&i2c->wait);
 
+	/*
+	 * Set OCORES_FLAG_BROKEN_IRQ to enable workaround for
+	 * FU540-C000 SoC in polling mode.
+	 * Since the SoC does have interrupt it's dt has the interrupt
+	 * defined but it should be bypassed in driver as this SoC has
+	 * a broken IRQ, hence update the master_xfer to use polling
+	 * transfers.
+	 */
+	if (of_device_is_compatible(pdev->dev.of_node,
+				    "sifive,fu540-c000-i2c"))
+		i2c->flags |= OCORES_FLAG_BROKEN_IRQ;
+
 	irq = platform_get_irq(pdev, 0);
-	if (irq == -ENXIO) {
+	if (i2c->flags & OCORES_FLAG_BROKEN_IRQ || irq == -ENXIO) {
 		ocores_algorithm.master_xfer = ocores_xfer_polling;
-
-		/*
-		 * Set in OCORES_FLAG_BROKEN_IRQ to enable workaround for
-		 * FU540-C000 SoC in polling mode.
-		 */
-		match = of_match_node(ocores_i2c_match, pdev->dev.of_node);
-		if (match && (long)match->data == TYPE_SIFIVE_REV0)
-			i2c->flags |= OCORES_FLAG_BROKEN_IRQ;
 	} else {
 		if (irq < 0)
 			return irq;
-- 
2.7.4


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-09 15:39 ` [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
@ 2020-10-09 18:24   ` Andreas Schwab
  2020-10-12 15:49     ` Sagar Kadam
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2020-10-09 18:24 UTC (permalink / raw)
  To: Sagar Shrikant Kadam
  Cc: andrew, peter, aou, linux-kernel, palmer, linux-i2c,
	paul.walmsley, linux-riscv

On Okt 09 2020, Sagar Shrikant Kadam wrote:

> diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
> index f5fc75b..9b3d1ab 100644
> --- a/drivers/i2c/busses/i2c-ocores.c
> +++ b/drivers/i2c/busses/i2c-ocores.c
> @@ -686,17 +686,21 @@ static int ocores_i2c_probe(struct platform_device *pdev)
>  
>  	init_waitqueue_head(&i2c->wait);
>  
> +	/*
> +	 * Set OCORES_FLAG_BROKEN_IRQ to enable workaround for
> +	 * FU540-C000 SoC in polling mode.
> +	 * Since the SoC does have interrupt it's dt has the interrupt

Typo: its

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* RE: [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-09 18:24   ` Andreas Schwab
@ 2020-10-12 15:49     ` Sagar Kadam
  0 siblings, 0 replies; 4+ messages in thread
From: Sagar Kadam @ 2020-10-12 15:49 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: andrew, peter, aou, linux-kernel, palmer, linux-i2c,
	Paul Walmsley ( Sifive),
	linux-riscv


> -----Original Message-----
> From: Andreas Schwab <schwab@linux-m68k.org>
> Sent: Friday, October 9, 2020 11:55 PM
> To: Sagar Kadam <sagar.kadam@openfive.com>
> Cc: linux-kernel@vger.kernel.org; linux-riscv@lists.infradead.org; linux-
> i2c@vger.kernel.org; peter@korsgaard.com; andrew@lunn.ch; Paul
> Walmsley ( Sifive) <paul.walmsley@sifive.com>; palmer@dabbelt.com;
> aou@eecs.berkeley.edu
> Subject: Re: [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on
> FU540-C000 SoC
> 
> [External Email] Do not click links or attachments unless you recognize the
> sender and know the content is safe
> 
> On Okt 09 2020, Sagar Shrikant Kadam wrote:
> 
> > diff --git a/drivers/i2c/busses/i2c-ocores.c
> > b/drivers/i2c/busses/i2c-ocores.c index f5fc75b..9b3d1ab 100644
> > --- a/drivers/i2c/busses/i2c-ocores.c
> > +++ b/drivers/i2c/busses/i2c-ocores.c
> > @@ -686,17 +686,21 @@ static int ocores_i2c_probe(struct
> > platform_device *pdev)
> >
> >       init_waitqueue_head(&i2c->wait);
> >
> > +     /*
> > +      * Set OCORES_FLAG_BROKEN_IRQ to enable workaround for
> > +      * FU540-C000 SoC in polling mode.
> > +      * Since the SoC does have interrupt it's dt has the interrupt
> 
> Typo: its
> 

Thanks Andreas,
I will submit v3 with the change.

BR,
Sagar
> Andreas.
> 
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA
> AEC1 "And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-09 15:39 [PATCH v2 0/1] fix i2c polling mode workaround for FU540-C000 SoC Sagar Shrikant Kadam
2020-10-09 15:39 ` [PATCH v2 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
2020-10-09 18:24   ` Andreas Schwab
2020-10-12 15:49     ` Sagar Kadam

Linux-RISC-V Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-riscv/0 linux-riscv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-riscv linux-riscv/ https://lore.kernel.org/linux-riscv \
		linux-riscv@lists.infradead.org
	public-inbox-index linux-riscv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-riscv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git