public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt
@ 2021-12-14  2:55 tamal.saha
  2021-12-14 12:00 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: tamal.saha @ 2021-12-14  2:55 UTC (permalink / raw)
  To: wsa, andriy.shevchenko, jarkko.nikula, linux-i2c; +Cc: tamal.saha, bala.senthil

From: Tamal Saha <tamal.saha@intel.com>

Intel Keem Bay platform supports multimaster operations over same i2c
bus using Synopsys i2c DesignWare IP. When multi masters initiate i2c
operation simultaneously in a loop, SCL line is stucked low forever
after few i2c operations. Following interrupt sequences are observed
in:
  working case: TX_EMPTY, RX_FULL and STOP_DET
  non working case: TX_EMPTY, STOP_DET, RX_FULL.

DW_apb_i2c stretches the SCL line when the TX FIFO is empty or when
RX FIFO is full. The DW_apb_i2c master will continue to hold the SCL
line LOW until RX FIFO is read.

Linux kernel i2c DesignWare driver does not handle above non working
sequence. TX_EMPTY, RX_FULL and STOP_DET routine execution are required
in sequence although RX_FULL interrupt is raised after STOP_DET by
hardware. Clear STOP_DET for the following conditions:
  (STOP_DET ,RX_FULL, rx_outstanding)
    Write Operation: (1, 0, 0)
    Read Operation:
      RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0)
      STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0)
      RX_FULL and STOP_DET together: (1, 1, 1)

Signed-off-by: Tamal Saha <tamal.saha@intel.com>
---
 drivers/i2c/busses/i2c-designware-master.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
index 9b08bb5df38d..9177463c2cbb 100644
--- a/drivers/i2c/busses/i2c-designware-master.c
+++ b/drivers/i2c/busses/i2c-designware-master.c
@@ -701,7 +701,8 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
 		regmap_read(dev->map, DW_IC_CLR_RX_DONE, &dummy);
 	if (stat & DW_IC_INTR_ACTIVITY)
 		regmap_read(dev->map, DW_IC_CLR_ACTIVITY, &dummy);
-	if (stat & DW_IC_INTR_STOP_DET)
+	if ((stat & DW_IC_INTR_STOP_DET) &&
+	    ((dev->rx_outstanding == 0) || (stat & DW_IC_INTR_RX_FULL)))
 		regmap_read(dev->map, DW_IC_CLR_STOP_DET, &dummy);
 	if (stat & DW_IC_INTR_START_DET)
 		regmap_read(dev->map, DW_IC_CLR_START_DET, &dummy);
@@ -723,6 +724,7 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
 	if (stat & DW_IC_INTR_TX_ABRT) {
 		dev->cmd_err |= DW_IC_ERR_TX_ABRT;
 		dev->status = STATUS_IDLE;
+		dev->rx_outstanding = 0;
 
 		/*
 		 * Anytime TX_ABRT is set, the contents of the tx/rx
@@ -745,7 +747,8 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
 	 */
 
 tx_aborted:
-	if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err)
+	if (((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err) &&
+	     (dev->rx_outstanding == 0))
 		complete(&dev->cmd_complete);
 	else if (unlikely(dev->flags & ACCESS_INTR_MASK)) {
 		/* Workaround to trigger pending interrupt */
-- 
2.17.1


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

* Re: [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt
  2021-12-14  2:55 [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt tamal.saha
@ 2021-12-14 12:00 ` Andy Shevchenko
  2021-12-14 12:03   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-12-14 12:00 UTC (permalink / raw)
  To: tamal.saha; +Cc: wsa, jarkko.nikula, linux-i2c, bala.senthil

On Tue, Dec 14, 2021 at 08:25:18AM +0530, tamal.saha@intel.com wrote:
> From: Tamal Saha <tamal.saha@intel.com>
> 
> Intel Keem Bay platform supports multimaster operations over same i2c
> bus using Synopsys i2c DesignWare IP. When multi masters initiate i2c
> operation simultaneously in a loop, SCL line is stucked low forever
> after few i2c operations. Following interrupt sequences are observed
> in:
>   working case: TX_EMPTY, RX_FULL and STOP_DET
>   non working case: TX_EMPTY, STOP_DET, RX_FULL.
> 
> DW_apb_i2c stretches the SCL line when the TX FIFO is empty or when
> RX FIFO is full. The DW_apb_i2c master will continue to hold the SCL
> line LOW until RX FIFO is read.
> 
> Linux kernel i2c DesignWare driver does not handle above non working
> sequence. TX_EMPTY, RX_FULL and STOP_DET routine execution are required
> in sequence although RX_FULL interrupt is raised after STOP_DET by
> hardware. Clear STOP_DET for the following conditions:
>   (STOP_DET ,RX_FULL, rx_outstanding)
>     Write Operation: (1, 0, 0)
>     Read Operation:
>       RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0)
>       STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0)
>       RX_FULL and STOP_DET together: (1, 1, 1)
> 
> Signed-off-by: Tamal Saha <tamal.saha@intel.com>
> ---

So, where is the changelog?

>  drivers/i2c/busses/i2c-designware-master.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c
> index 9b08bb5df38d..9177463c2cbb 100644
> --- a/drivers/i2c/busses/i2c-designware-master.c
> +++ b/drivers/i2c/busses/i2c-designware-master.c
> @@ -701,7 +701,8 @@ static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
>  		regmap_read(dev->map, DW_IC_CLR_RX_DONE, &dummy);
>  	if (stat & DW_IC_INTR_ACTIVITY)
>  		regmap_read(dev->map, DW_IC_CLR_ACTIVITY, &dummy);
> -	if (stat & DW_IC_INTR_STOP_DET)
> +	if ((stat & DW_IC_INTR_STOP_DET) &&
> +	    ((dev->rx_outstanding == 0) || (stat & DW_IC_INTR_RX_FULL)))
>  		regmap_read(dev->map, DW_IC_CLR_STOP_DET, &dummy);
>  	if (stat & DW_IC_INTR_START_DET)
>  		regmap_read(dev->map, DW_IC_CLR_START_DET, &dummy);
> @@ -723,6 +724,7 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
>  	if (stat & DW_IC_INTR_TX_ABRT) {
>  		dev->cmd_err |= DW_IC_ERR_TX_ABRT;
>  		dev->status = STATUS_IDLE;
> +		dev->rx_outstanding = 0;
>  
>  		/*
>  		 * Anytime TX_ABRT is set, the contents of the tx/rx
> @@ -745,7 +747,8 @@ static int i2c_dw_irq_handler_master(struct dw_i2c_dev *dev)
>  	 */
>  
>  tx_aborted:
> -	if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err)
> +	if (((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err) &&
> +	     (dev->rx_outstanding == 0))
>  		complete(&dev->cmd_complete);
>  	else if (unlikely(dev->flags & ACCESS_INTR_MASK)) {
>  		/* Workaround to trigger pending interrupt */
> -- 
> 2.17.1
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt
  2021-12-14 12:00 ` Andy Shevchenko
@ 2021-12-14 12:03   ` Andy Shevchenko
  2021-12-14 13:06     ` Saha, Tamal
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-12-14 12:03 UTC (permalink / raw)
  To: tamal.saha; +Cc: wsa, jarkko.nikula, linux-i2c, bala.senthil

On Tue, Dec 14, 2021 at 02:00:59PM +0200, Andy Shevchenko wrote:
> On Tue, Dec 14, 2021 at 08:25:18AM +0530, tamal.saha@intel.com wrote:
> > From: Tamal Saha <tamal.saha@intel.com>
> > 
> > Intel Keem Bay platform supports multimaster operations over same i2c

Here you put multimaster...

> > bus using Synopsys i2c DesignWare IP. When multi masters initiate i2c

...and here multi masters.

Be consistent.

I believe the best way is to use dash variant, i.e. multi-master(s),

> > operation simultaneously in a loop, SCL line is stucked low forever
> > after few i2c operations. Following interrupt sequences are observed
> > in:
> >   working case: TX_EMPTY, RX_FULL and STOP_DET
> >   non working case: TX_EMPTY, STOP_DET, RX_FULL.
> > 
> > DW_apb_i2c stretches the SCL line when the TX FIFO is empty or when
> > RX FIFO is full. The DW_apb_i2c master will continue to hold the SCL
> > line LOW until RX FIFO is read.
> > 
> > Linux kernel i2c DesignWare driver does not handle above non working
> > sequence. TX_EMPTY, RX_FULL and STOP_DET routine execution are required
> > in sequence although RX_FULL interrupt is raised after STOP_DET by
> > hardware. Clear STOP_DET for the following conditions:
> >   (STOP_DET ,RX_FULL, rx_outstanding)
> >     Write Operation: (1, 0, 0)
> >     Read Operation:
> >       RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0)
> >       STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0)
> >       RX_FULL and STOP_DET together: (1, 1, 1)
> > 
> > Signed-off-by: Tamal Saha <tamal.saha@intel.com>
> > ---
> 
> So, where is the changelog?

-- 
With Best Regards,
Andy Shevchenko



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

* RE: [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt
  2021-12-14 12:03   ` Andy Shevchenko
@ 2021-12-14 13:06     ` Saha, Tamal
  0 siblings, 0 replies; 4+ messages in thread
From: Saha, Tamal @ 2021-12-14 13:06 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: wsa@kernel.org, jarkko.nikula@linux.intel.com,
	linux-i2c@vger.kernel.org, Senthil, Bala

Thanks Andy. I'll incorporate patch version changelog and review findings for this patch in next version.
Please let me know, if you have more findings for this patch.

> -----Original Message-----
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Sent: Tuesday, 14 December, 2021 5:33 PM
> To: Saha, Tamal <tamal.saha@intel.com>
> Cc: wsa@kernel.org; jarkko.nikula@linux.intel.com; linux-
> i2c@vger.kernel.org; Senthil, Bala <bala.senthil@intel.com>
> Subject: Re: [PATCH v2] i2c: designware: Do not complete i2c read without
> RX_FULL interrupt
> 
> On Tue, Dec 14, 2021 at 02:00:59PM +0200, Andy Shevchenko wrote:
> > On Tue, Dec 14, 2021 at 08:25:18AM +0530, tamal.saha@intel.com wrote:
> > > From: Tamal Saha <tamal.saha@intel.com>
> > >
> > > Intel Keem Bay platform supports multimaster operations over same
> > > i2c
> 
> Here you put multimaster...
> 
> > > bus using Synopsys i2c DesignWare IP. When multi masters initiate
> > > i2c
> 
> ...and here multi masters.
> 
> Be consistent.
> 
> I believe the best way is to use dash variant, i.e. multi-master(s),
> 
> > > operation simultaneously in a loop, SCL line is stucked low forever
> > > after few i2c operations. Following interrupt sequences are observed
> > > in:
> > >   working case: TX_EMPTY, RX_FULL and STOP_DET
> > >   non working case: TX_EMPTY, STOP_DET, RX_FULL.
> > >
> > > DW_apb_i2c stretches the SCL line when the TX FIFO is empty or when
> > > RX FIFO is full. The DW_apb_i2c master will continue to hold the SCL
> > > line LOW until RX FIFO is read.
> > >
> > > Linux kernel i2c DesignWare driver does not handle above non working
> > > sequence. TX_EMPTY, RX_FULL and STOP_DET routine execution are
> > > required in sequence although RX_FULL interrupt is raised after
> > > STOP_DET by hardware. Clear STOP_DET for the following conditions:
> > >   (STOP_DET ,RX_FULL, rx_outstanding)
> > >     Write Operation: (1, 0, 0)
> > >     Read Operation:
> > >       RX_FULL followed by STOP_DET: (0, 1, 1) -> (1, 0, 0)
> > >       STOP_DET followed by RX_FULL: (1, 0, 1) -> (1, 1, 0)
> > >       RX_FULL and STOP_DET together: (1, 1, 1)
> > >
> > > Signed-off-by: Tamal Saha <tamal.saha@intel.com>
> > > ---
> >
> > So, where is the changelog?
> 
> --
> With Best Regards,
> Andy Shevchenko
> 


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

end of thread, other threads:[~2021-12-14 13:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-14  2:55 [PATCH v2] i2c: designware: Do not complete i2c read without RX_FULL interrupt tamal.saha
2021-12-14 12:00 ` Andy Shevchenko
2021-12-14 12:03   ` Andy Shevchenko
2021-12-14 13:06     ` Saha, Tamal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox