linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
@ 2024-12-16 15:16 Stefan Eichenberger
  2024-12-16 16:35 ` Frank Li
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stefan Eichenberger @ 2024-12-16 15:16 UTC (permalink / raw)
  To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
	Frank.Li, stefan.eichenberger, francesco.dolcini
  Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel

From: Stefan Eichenberger <stefan.eichenberger@toradex.com>

A regression was introduced with the implementation of single-master
mode, preventing proper stop conditions from being generated. Devices
that require a valid stop condition, such as EEPROMs, fail to function
correctly as a result.

The issue only affects devices with the single-master property enabled.

This commit resolves the issue by re-enabling I2C bus busy bit (IBB)
polling for single-master mode when generating a stop condition. The fix
further ensures that the i2c_imx->stopped flag is cleared at the start
of each transfer, allowing the stop condition to be correctly generated
in i2c_imx_stop().

According to the reference manual (IMX8MMRM, Rev. 2, 09/2019, page
5270), polling the IBB bit to determine if the bus is free is only
necessary in multi-master mode. Consequently, the IBB bit is not polled
for the start condition in single-master mode.

Fixes: 6692694aca86 ("i2c: imx: do not poll for bus busy in single master mode")
Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
---
 drivers/i2c/busses/i2c-imx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f751d231ded8..cbf66a69e20b 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -534,20 +534,18 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
 {
 	unsigned long orig_jiffies = jiffies;
 	unsigned int temp;
-
-	if (!i2c_imx->multi_master)
-		return 0;
+	bool multi_master = i2c_imx->multi_master;
 
 	while (1) {
 		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
 
 		/* check for arbitration lost */
-		if (temp & I2SR_IAL) {
+		if (multi_master && (temp & I2SR_IAL)) {
 			i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
 			return -EAGAIN;
 		}
 
-		if (for_busy && (temp & I2SR_IBB)) {
+		if (for_busy && (!multi_master || (temp & I2SR_IBB))) {
 			i2c_imx->stopped = 0;
 			break;
 		}
-- 
2.45.2



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

* Re: [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
  2024-12-16 15:16 [PATCH v1] i2c: imx: fix missing stop condition in single-master mode Stefan Eichenberger
@ 2024-12-16 16:35 ` Frank Li
  2024-12-18 18:00   ` Andi Shyti
  2024-12-16 18:42 ` Francesco Dolcini
  2024-12-18 18:16 ` Andi Shyti
  2 siblings, 1 reply; 6+ messages in thread
From: Frank Li @ 2024-12-16 16:35 UTC (permalink / raw)
  To: Stefan Eichenberger
  Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
	stefan.eichenberger, francesco.dolcini, linux-i2c, imx,
	linux-arm-kernel, linux-kernel

On Mon, Dec 16, 2024 at 04:16:40PM +0100, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
>
> A regression was introduced with the implementation of single-master
> mode, preventing proper stop conditions from being generated. Devices
> that require a valid stop condition, such as EEPROMs, fail to function
> correctly as a result.
>
> The issue only affects devices with the single-master property enabled.
>
> This commit resolves the issue by re-enabling I2C bus busy bit (IBB)
> polling for single-master mode when generating a stop condition. The fix
> further ensures that the i2c_imx->stopped flag is cleared at the start
> of each transfer, allowing the stop condition to be correctly generated
> in i2c_imx_stop().
>
> According to the reference manual (IMX8MMRM, Rev. 2, 09/2019, page
> 5270), polling the IBB bit to determine if the bus is free is only
> necessary in multi-master mode. Consequently, the IBB bit is not polled
> for the start condition in single-master mode.
>
> Fixes: 6692694aca86 ("i2c: imx: do not poll for bus busy in single master mode")
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> ---
>  drivers/i2c/busses/i2c-imx.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index f751d231ded8..cbf66a69e20b 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -534,20 +534,18 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
>  {
>  	unsigned long orig_jiffies = jiffies;
>  	unsigned int temp;
> -
> -	if (!i2c_imx->multi_master)
> -		return 0;
> +	bool multi_master = i2c_imx->multi_master;

Move "bool multi_master = i2c_imx->multi_master;" before
"unsigned long orig_jiffies = jiffies;" to keep reverse christmas tree
order.

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>
>  	while (1) {
>  		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
>
>  		/* check for arbitration lost */
> -		if (temp & I2SR_IAL) {
> +		if (multi_master && (temp & I2SR_IAL)) {
>  			i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
>  			return -EAGAIN;
>  		}
>
> -		if (for_busy && (temp & I2SR_IBB)) {
> +		if (for_busy && (!multi_master || (temp & I2SR_IBB))) {
>  			i2c_imx->stopped = 0;
>  			break;
>  		}
> --
> 2.45.2
>


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

* Re: [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
  2024-12-16 15:16 [PATCH v1] i2c: imx: fix missing stop condition in single-master mode Stefan Eichenberger
  2024-12-16 16:35 ` Frank Li
@ 2024-12-16 18:42 ` Francesco Dolcini
  2024-12-18 18:16 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Francesco Dolcini @ 2024-12-16 18:42 UTC (permalink / raw)
  To: Stefan Eichenberger
  Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
	Frank.Li, stefan.eichenberger, francesco.dolcini, linux-i2c, imx,
	linux-arm-kernel, linux-kernel

On Mon, Dec 16, 2024 at 04:16:40PM +0100, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> 
> A regression was introduced with the implementation of single-master
> mode, preventing proper stop conditions from being generated. Devices
> that require a valid stop condition, such as EEPROMs, fail to function
> correctly as a result.
> 
> The issue only affects devices with the single-master property enabled.
> 
> This commit resolves the issue by re-enabling I2C bus busy bit (IBB)
> polling for single-master mode when generating a stop condition. The fix
> further ensures that the i2c_imx->stopped flag is cleared at the start
> of each transfer, allowing the stop condition to be correctly generated
> in i2c_imx_stop().
> 
> According to the reference manual (IMX8MMRM, Rev. 2, 09/2019, page
> 5270), polling the IBB bit to determine if the bus is free is only
> necessary in multi-master mode. Consequently, the IBB bit is not polled
> for the start condition in single-master mode.
> 
> Fixes: 6692694aca86 ("i2c: imx: do not poll for bus busy in single master mode")
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>

Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>



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

* Re: [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
  2024-12-16 16:35 ` Frank Li
@ 2024-12-18 18:00   ` Andi Shyti
  0 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-12-18 18:00 UTC (permalink / raw)
  To: Frank Li
  Cc: Stefan Eichenberger, o.rempel, kernel, shawnguo, s.hauer,
	festevam, stefan.eichenberger, francesco.dolcini, linux-i2c, imx,
	linux-arm-kernel, linux-kernel

Hi,

...

> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index f751d231ded8..cbf66a69e20b 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -534,20 +534,18 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
> >  {
> >  	unsigned long orig_jiffies = jiffies;
> >  	unsigned int temp;
> > -
> > -	if (!i2c_imx->multi_master)
> > -		return 0;
> > +	bool multi_master = i2c_imx->multi_master;
> 
> Move "bool multi_master = i2c_imx->multi_master;" before
> "unsigned long orig_jiffies = jiffies;" to keep reverse christmas tree
> order.

I will take care of it.

Thanks, Stefan.

Andi


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

* Re: [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
  2024-12-16 15:16 [PATCH v1] i2c: imx: fix missing stop condition in single-master mode Stefan Eichenberger
  2024-12-16 16:35 ` Frank Li
  2024-12-16 18:42 ` Francesco Dolcini
@ 2024-12-18 18:16 ` Andi Shyti
  2024-12-19  9:19   ` Stefan Eichenberger
  2 siblings, 1 reply; 6+ messages in thread
From: Andi Shyti @ 2024-12-18 18:16 UTC (permalink / raw)
  To: Stefan Eichenberger
  Cc: o.rempel, kernel, shawnguo, s.hauer, festevam, Frank.Li,
	stefan.eichenberger, francesco.dolcini, linux-i2c, imx,
	linux-arm-kernel, linux-kernel

Hi Stefan,

On Mon, Dec 16, 2024 at 04:16:40PM +0100, Stefan Eichenberger wrote:
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> 
> A regression was introduced with the implementation of single-master
> mode, preventing proper stop conditions from being generated. Devices
> that require a valid stop condition, such as EEPROMs, fail to function
> correctly as a result.
> 
> The issue only affects devices with the single-master property enabled.
> 
> This commit resolves the issue by re-enabling I2C bus busy bit (IBB)
> polling for single-master mode when generating a stop condition. The fix
> further ensures that the i2c_imx->stopped flag is cleared at the start
> of each transfer, allowing the stop condition to be correctly generated
> in i2c_imx_stop().
> 
> According to the reference manual (IMX8MMRM, Rev. 2, 09/2019, page
> 5270), polling the IBB bit to determine if the bus is free is only
> necessary in multi-master mode. Consequently, the IBB bit is not polled
> for the start condition in single-master mode.
> 
> Fixes: 6692694aca86 ("i2c: imx: do not poll for bus busy in single master mode")
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> ---
>  drivers/i2c/busses/i2c-imx.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index f751d231ded8..cbf66a69e20b 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -534,20 +534,18 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
>  {
>  	unsigned long orig_jiffies = jiffies;
>  	unsigned int temp;
> -
> -	if (!i2c_imx->multi_master)
> -		return 0;
> +	bool multi_master = i2c_imx->multi_master;

with this small adjustment, I have applied your patch to 
i2c/i2c-host-fixes.

The idea behind the change is that variables are sorted by 
length, forming a kind of reversed Christmas tree shape. It's 
not a strict rule—some communities enforce it, others don't, and 
some follow entirely different conventions.

Since it feels somewhat arbitrary to me, I don't enforce it 
strictly. However, I personally try to adhere to the reversed 
Christmas tree rule whenever possible.

Andi

>  
>  	while (1) {
>  		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
>  
>  		/* check for arbitration lost */
> -		if (temp & I2SR_IAL) {
> +		if (multi_master && (temp & I2SR_IAL)) {
>  			i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
>  			return -EAGAIN;
>  		}
>  
> -		if (for_busy && (temp & I2SR_IBB)) {
> +		if (for_busy && (!multi_master || (temp & I2SR_IBB))) {
>  			i2c_imx->stopped = 0;
>  			break;
>  		}
> -- 
> 2.45.2
> 


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

* Re: [PATCH v1] i2c: imx: fix missing stop condition in single-master mode
  2024-12-18 18:16 ` Andi Shyti
@ 2024-12-19  9:19   ` Stefan Eichenberger
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Eichenberger @ 2024-12-19  9:19 UTC (permalink / raw)
  To: Andi Shyti
  Cc: o.rempel, kernel, shawnguo, s.hauer, festevam, Frank.Li,
	stefan.eichenberger, francesco.dolcini, linux-i2c, imx,
	linux-arm-kernel, linux-kernel

Hi Andi,

On Wed, Dec 18, 2024 at 07:16:23PM +0100, Andi Shyti wrote:
> Hi Stefan,
> 
> On Mon, Dec 16, 2024 at 04:16:40PM +0100, Stefan Eichenberger wrote:
> > From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > 
> > A regression was introduced with the implementation of single-master
> > mode, preventing proper stop conditions from being generated. Devices
> > that require a valid stop condition, such as EEPROMs, fail to function
> > correctly as a result.
> > 
> > The issue only affects devices with the single-master property enabled.
> > 
> > This commit resolves the issue by re-enabling I2C bus busy bit (IBB)
> > polling for single-master mode when generating a stop condition. The fix
> > further ensures that the i2c_imx->stopped flag is cleared at the start
> > of each transfer, allowing the stop condition to be correctly generated
> > in i2c_imx_stop().
> > 
> > According to the reference manual (IMX8MMRM, Rev. 2, 09/2019, page
> > 5270), polling the IBB bit to determine if the bus is free is only
> > necessary in multi-master mode. Consequently, the IBB bit is not polled
> > for the start condition in single-master mode.
> > 
> > Fixes: 6692694aca86 ("i2c: imx: do not poll for bus busy in single master mode")
> > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > ---
> >  drivers/i2c/busses/i2c-imx.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index f751d231ded8..cbf66a69e20b 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -534,20 +534,18 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a
> >  {
> >  	unsigned long orig_jiffies = jiffies;
> >  	unsigned int temp;
> > -
> > -	if (!i2c_imx->multi_master)
> > -		return 0;
> > +	bool multi_master = i2c_imx->multi_master;
> 
> with this small adjustment, I have applied your patch to 
> i2c/i2c-host-fixes.
> 
> The idea behind the change is that variables are sorted by 
> length, forming a kind of reversed Christmas tree shape. It's 
> not a strict rule—some communities enforce it, others don't, and 
> some follow entirely different conventions.
> 
> Since it feels somewhat arbitrary to me, I don't enforce it 
> strictly. However, I personally try to adhere to the reversed 
> Christmas tree rule whenever possible.

Thanks a lot for doing the change and for the explanation. I will keep
it in mind for future patches.

Best regards,
Stefan


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

end of thread, other threads:[~2024-12-19  9:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16 15:16 [PATCH v1] i2c: imx: fix missing stop condition in single-master mode Stefan Eichenberger
2024-12-16 16:35 ` Frank Li
2024-12-18 18:00   ` Andi Shyti
2024-12-16 18:42 ` Francesco Dolcini
2024-12-18 18:16 ` Andi Shyti
2024-12-19  9:19   ` Stefan Eichenberger

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