linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/1] fix i2c polling mode workaround for FU540-C000 SoC
@ 2020-10-21 14:50 Sagar Shrikant Kadam
  2020-10-21 14:50 ` [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
  0 siblings, 1 reply; 5+ messages in thread
From: Sagar Shrikant Kadam @ 2020-10-21 14:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-riscv, linux-i2c, peter, andrew, paul.walmsley, palmer,
	aou, 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 mainline Linux 5.9 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-00001-ge092bd7 #1 SMP Wed Oct 21 06:19:31 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
0xf9
# i2cset 0 0x57 0 0xa5 b -y
# i2cget 0 0x57 0 b -y
0xa5
# i2cget 0 0x57 1 b -y
0xa9
# i2cset 0 0x57 1 0x9a b -y
# i2cget 0 0x57 1 b -y
0x9a
# i2cget 0 0x6f 0x20 b -y
0x98
# i2cset 0 0x6f 0x20 0x5a b -y
# i2cget 0 0x6f 0x20 b -y
0x5a
# i2cget 0 0x6f 0x5f b -y
0x55
# i2cset 0 0x6f 0x5f 0xa5 b -y
# i2cget 0 0x6f 0x5f b -y
0xa5
#

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

Patch History:
===============================
V4:
-Used alternate implementation as suggested here:
 https://lkml.org/lkml/2020/10/15/513
-Removed TYPE_SIFIVE_REV0 field as it is no longer needed to set the polling mode
 and OCORES_FLAG_BROKEN_IRQ flag.

V3:
-Rectified typo as suggested here:
 https://lkml.org/lkml/2020/10/9/902

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 | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

-- 
2.7.4


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

* [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-21 14:50 [PATCH v4 0/1] fix i2c polling mode workaround for FU540-C000 SoC Sagar Shrikant Kadam
@ 2020-10-21 14:50 ` Sagar Shrikant Kadam
  2020-10-21 15:46   ` Peter Korsgaard
  2020-11-03 21:11   ` Wolfram Sang
  0 siblings, 2 replies; 5+ messages in thread
From: Sagar Shrikant Kadam @ 2020-10-21 14:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-riscv, linux-i2c, peter, andrew, paul.walmsley, palmer,
	aou, 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 | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index f5fc75b..a97cbaa 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -83,7 +83,6 @@ struct ocores_i2c {
 
 #define TYPE_OCORES		0
 #define TYPE_GRLIB		1
-#define TYPE_SIFIVE_REV0	2
 
 #define OCORES_FLAG_BROKEN_IRQ BIT(1) /* Broken IRQ for FU540-C000 SoC */
 
@@ -476,11 +475,9 @@ static const struct of_device_id ocores_i2c_match[] = {
 	},
 	{
 		.compatible = "sifive,fu540-c000-i2c",
-		.data = (void *)TYPE_SIFIVE_REV0,
 	},
 	{
 		.compatible = "sifive,i2c0",
-		.data = (void *)TYPE_SIFIVE_REV0,
 	},
 	{},
 };
@@ -606,7 +603,6 @@ static int ocores_i2c_probe(struct platform_device *pdev)
 {
 	struct ocores_i2c *i2c;
 	struct ocores_i2c_platform_data *pdata;
-	const struct of_device_id *match;
 	struct resource *res;
 	int irq;
 	int ret;
@@ -687,16 +683,19 @@ static int ocores_i2c_probe(struct platform_device *pdev)
 	init_waitqueue_head(&i2c->wait);
 
 	irq = platform_get_irq(pdev, 0);
+	/*
+	 * Since the SoC does have an interrupt, its DT has an interrupt
+	 * property - But this should be bypassed as the IRQ logic in this
+	 * SoC is broken.
+	 */
+	if (of_device_is_compatible(pdev->dev.of_node,
+				    "sifive,fu540-c000-i2c")) {
+		i2c->flags |= OCORES_FLAG_BROKEN_IRQ;
+		irq = -ENXIO;
+	}
+
 	if (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


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

* Re: [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-21 14:50 ` [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
@ 2020-10-21 15:46   ` Peter Korsgaard
  2020-10-23 11:55     ` Sagar Kadam
  2020-11-03 21:11   ` Wolfram Sang
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Korsgaard @ 2020-10-21 15:46 UTC (permalink / raw)
  To: Sagar Shrikant Kadam
  Cc: linux-kernel, linux-riscv, linux-i2c, andrew, paul.walmsley, palmer, aou

>>>>> "Sagar" == Sagar Shrikant Kadam <sagar.kadam@sifive.com> writes:

 > 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>

LGTM, thanks.

Acked-by: Peter Korsgaard <peter@korsgaard.com>

-- 
Bye, Peter Korsgaard

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

* RE: [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-21 15:46   ` Peter Korsgaard
@ 2020-10-23 11:55     ` Sagar Kadam
  0 siblings, 0 replies; 5+ messages in thread
From: Sagar Kadam @ 2020-10-23 11:55 UTC (permalink / raw)
  To: Peter Korsgaard
  Cc: linux-kernel, linux-riscv, linux-i2c, andrew,
	Paul Walmsley ( Sifive),
	palmer, aou

Hello Peter,

> -----Original Message-----
> From: Peter Korsgaard <jacmet@gmail.com> On Behalf Of Peter Korsgaard
> Sent: Wednesday, October 21, 2020 9:16 PM
> To: Sagar Kadam <sagar.kadam@openfive.com>
> Cc: linux-kernel@vger.kernel.org; linux-riscv@lists.infradead.org; linux-
> i2c@vger.kernel.org; andrew@lunn.ch; Paul Walmsley ( Sifive)
> <paul.walmsley@sifive.com>; palmer@dabbelt.com;
> aou@eecs.berkeley.edu
> Subject: Re: [PATCH v4 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
> 
> >>>>> "Sagar" == Sagar Shrikant Kadam <sagar.kadam@sifive.com> writes:
> 
>  > 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>
> 
> LGTM, thanks.
> 
> Acked-by: Peter Korsgaard <peter@korsgaard.com>
> 

Thank you for the review and "Acked-by"

BR,
Sagar
> --
> Bye, Peter Korsgaard

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

* Re: [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on FU540-C000 SoC
  2020-10-21 14:50 ` [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
  2020-10-21 15:46   ` Peter Korsgaard
@ 2020-11-03 21:11   ` Wolfram Sang
  1 sibling, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2020-11-03 21:11 UTC (permalink / raw)
  To: Sagar Shrikant Kadam
  Cc: linux-kernel, linux-riscv, linux-i2c, peter, andrew,
	paul.walmsley, palmer, aou

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

On Wed, Oct 21, 2020 at 07:50:14AM -0700, Sagar Shrikant Kadam wrote:
> 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>

Applied to for-next, thanks!


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

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

end of thread, other threads:[~2020-11-03 21:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21 14:50 [PATCH v4 0/1] fix i2c polling mode workaround for FU540-C000 SoC Sagar Shrikant Kadam
2020-10-21 14:50 ` [PATCH v4 1/1] i2c: ocores: fix polling mode workaround on " Sagar Shrikant Kadam
2020-10-21 15:46   ` Peter Korsgaard
2020-10-23 11:55     ` Sagar Kadam
2020-11-03 21:11   ` Wolfram Sang

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).