linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: exynos5: Preserve high speed master code
@ 2021-02-15 19:03 Mårten Lindahl
  2021-02-16  7:51 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Mårten Lindahl @ 2021-02-15 19:03 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: kernel, Mårten Lindahl, linux-i2c, linux-arm-kernel,
	linux-samsung-soc, linux-kernel

From: Mårten Lindahl <martenli@axis.com>

When the controller starts to send a message with the MASTER_ID field
set (high speed), the whole I2C_ADDR register is overwritten including
MASTER_ID as the SLV_ADDR_MAS field is set.

This patch preserves already written fields in I2C_ADDR when writing
SLV_ADDR_MAS.

Signed-off-by: Mårten Lindahl <martenli@axis.com>
---
 drivers/i2c/busses/i2c-exynos5.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 20a9881a0d6c..f2d04c241299 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -606,6 +606,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
 	u32 i2c_ctl;
 	u32 int_en = 0;
 	u32 i2c_auto_conf = 0;
+	u32 i2c_addr = 0;
 	u32 fifo_ctl;
 	unsigned long flags;
 	unsigned short trig_lvl;
@@ -640,7 +641,12 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
 		int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN;
 	}
 
-	writel(HSI2C_SLV_ADDR_MAS(i2c->msg->addr), i2c->regs + HSI2C_ADDR);
+	i2c_addr = HSI2C_SLV_ADDR_MAS(i2c->msg->addr);
+
+	if (i2c->op_clock >= I2C_MAX_FAST_MODE_PLUS_FREQ)
+		i2c_addr |= readl(i2c->regs + HSI2C_ADDR);
+
+	writel(i2c_addr, i2c->regs + HSI2C_ADDR);
 
 	writel(fifo_ctl, i2c->regs + HSI2C_FIFO_CTL);
 	writel(i2c_ctl, i2c->regs + HSI2C_CTL);
-- 
2.11.0


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

* Re: [PATCH] i2c: exynos5: Preserve high speed master code
  2021-02-15 19:03 [PATCH] i2c: exynos5: Preserve high speed master code Mårten Lindahl
@ 2021-02-16  7:51 ` Krzysztof Kozlowski
  2021-02-16 22:09   ` Marten Lindahl
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-02-16  7:51 UTC (permalink / raw)
  To: Mårten Lindahl
  Cc: kernel, Mårten Lindahl, linux-i2c, linux-arm-kernel,
	linux-samsung-soc, linux-kernel

On Mon, Feb 15, 2021 at 08:03:21PM +0100, Mårten Lindahl wrote:
> From: Mårten Lindahl <martenli@axis.com>
> 
> When the controller starts to send a message with the MASTER_ID field
> set (high speed), the whole I2C_ADDR register is overwritten including
> MASTER_ID as the SLV_ADDR_MAS field is set.

Are you here describing bug in driver or hardware (the controller?)?
Looking at the code, I think the driver, but description got me
confused.

> 
> This patch preserves already written fields in I2C_ADDR when writing
> SLV_ADDR_MAS.
> 
> Signed-off-by: Mårten Lindahl <martenli@axis.com>
> ---
>  drivers/i2c/busses/i2c-exynos5.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
> index 20a9881a0d6c..f2d04c241299 100644
> --- a/drivers/i2c/busses/i2c-exynos5.c
> +++ b/drivers/i2c/busses/i2c-exynos5.c
> @@ -606,6 +606,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
>  	u32 i2c_ctl;
>  	u32 int_en = 0;
>  	u32 i2c_auto_conf = 0;
> +	u32 i2c_addr = 0;
>  	u32 fifo_ctl;
>  	unsigned long flags;
>  	unsigned short trig_lvl;
> @@ -640,7 +641,12 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
>  		int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN;
>  	}
>  
> -	writel(HSI2C_SLV_ADDR_MAS(i2c->msg->addr), i2c->regs + HSI2C_ADDR);
> +	i2c_addr = HSI2C_SLV_ADDR_MAS(i2c->msg->addr);
> +
> +	if (i2c->op_clock >= I2C_MAX_FAST_MODE_PLUS_FREQ)
> +		i2c_addr |= readl(i2c->regs + HSI2C_ADDR);

Any reason why not "|= MASTER_ID(i2c->adap.nr)" here instead of more
expensive IO read? It's quite important because your current code will
bitwise-or old I2C slave address with a new one... This should break
during tests with multiple I2C slave devices, shouldn't it?

On which HW did you test it?

Best regards,
Krzysztof


> +
> +	writel(i2c_addr, i2c->regs + HSI2C_ADDR);

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

* Re: [PATCH] i2c: exynos5: Preserve high speed master code
  2021-02-16  7:51 ` Krzysztof Kozlowski
@ 2021-02-16 22:09   ` Marten Lindahl
  2021-02-17  8:07     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Marten Lindahl @ 2021-02-16 22:09 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: linux-i2c, linux-arm-kernel, linux-samsung-soc, linux-kernel, kernel

Hi Krzysztof!

Thank you for your comments! Please see my reply below.
I will send v2 in a moment.

On Tue, Feb 16, 2021 at 08:51:41AM +0100, Krzysztof Kozlowski wrote:
> On Mon, Feb 15, 2021 at 08:03:21PM +0100, Mårten Lindahl wrote:
> > From: Mårten Lindahl <martenli@axis.com>
> > 
> > When the controller starts to send a message with the MASTER_ID field
> > set (high speed), the whole I2C_ADDR register is overwritten including
> > MASTER_ID as the SLV_ADDR_MAS field is set.
> 
> Are you here describing bug in driver or hardware (the controller?)?
> Looking at the code, I think the driver, but description got me
> confused.
> 

Yes, it is the driver. I will change.

> > 
> > This patch preserves already written fields in I2C_ADDR when writing
> > SLV_ADDR_MAS.
> > 
> > Signed-off-by: Mårten Lindahl <martenli@axis.com>
> > ---
> >  drivers/i2c/busses/i2c-exynos5.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
> > index 20a9881a0d6c..f2d04c241299 100644
> > --- a/drivers/i2c/busses/i2c-exynos5.c
> > +++ b/drivers/i2c/busses/i2c-exynos5.c
> > @@ -606,6 +606,7 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
> >  	u32 i2c_ctl;
> >  	u32 int_en = 0;
> >  	u32 i2c_auto_conf = 0;
> > +	u32 i2c_addr = 0;
> >  	u32 fifo_ctl;
> >  	unsigned long flags;
> >  	unsigned short trig_lvl;
> > @@ -640,7 +641,12 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)
> >  		int_en |= HSI2C_INT_TX_ALMOSTEMPTY_EN;
> >  	}
> >  
> > -	writel(HSI2C_SLV_ADDR_MAS(i2c->msg->addr), i2c->regs + HSI2C_ADDR);
> > +	i2c_addr = HSI2C_SLV_ADDR_MAS(i2c->msg->addr);
> > +
> > +	if (i2c->op_clock >= I2C_MAX_FAST_MODE_PLUS_FREQ)
> > +		i2c_addr |= readl(i2c->regs + HSI2C_ADDR);
> 
> Any reason why not "|= MASTER_ID(i2c->adap.nr)" here instead of more
> expensive IO read? It's quite important because your current code will
> bitwise-or old I2C slave address with a new one... This should break
> during tests with multiple I2C slave devices, shouldn't it?
> 

You are correct. It is better to use the macro instead, and yes,
safer too. I only have one device that supports high speed i2c, but
I get your point. It could potentially break.

> On which HW did you test it?

I used an Artpec development board as master and INA230EVM board
as slave.

> 
> Best regards,
> Krzysztof
> 

Best regards
Mårten
> 
> > +
> > +	writel(i2c_addr, i2c->regs + HSI2C_ADDR);

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

* Re: [PATCH] i2c: exynos5: Preserve high speed master code
  2021-02-16 22:09   ` Marten Lindahl
@ 2021-02-17  8:07     ` Krzysztof Kozlowski
  2021-02-17  8:32       ` Jesper Nilsson
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-02-17  8:07 UTC (permalink / raw)
  To: Marten Lindahl
  Cc: linux-i2c, linux-arm-kernel, linux-samsung-soc, linux-kernel, kernel

On Tue, Feb 16, 2021 at 11:09:33PM +0100, Marten Lindahl wrote:
> > Any reason why not "|= MASTER_ID(i2c->adap.nr)" here instead of more
> > expensive IO read? It's quite important because your current code will
> > bitwise-or old I2C slave address with a new one... This should break
> > during tests with multiple I2C slave devices, shouldn't it?
> > 
> 
> You are correct. It is better to use the macro instead, and yes,
> safer too. I only have one device that supports high speed i2c, but
> I get your point. It could potentially break.
> 
> > On which HW did you test it?
> 
> I used an Artpec development board as master and INA230EVM board
> as slave.

Artpec development board with? What SoC?

Best regards,
Krzysztof


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

* Re: [PATCH] i2c: exynos5: Preserve high speed master code
  2021-02-17  8:07     ` Krzysztof Kozlowski
@ 2021-02-17  8:32       ` Jesper Nilsson
  2021-02-17  8:43         ` Krzysztof Kozlowski
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Nilsson @ 2021-02-17  8:32 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Mårten Lindahl, linux-samsung-soc, kernel, linux-i2c,
	linux-arm-kernel, linux-kernel

On Wed, Feb 17, 2021 at 09:07:47AM +0100, Krzysztof Kozlowski wrote:
> On Tue, Feb 16, 2021 at 11:09:33PM +0100, Marten Lindahl wrote:
> > > Any reason why not "|= MASTER_ID(i2c->adap.nr)" here instead of more
> > > expensive IO read? It's quite important because your current code will
> > > bitwise-or old I2C slave address with a new one... This should break
> > > during tests with multiple I2C slave devices, shouldn't it?
> > > 
> > 
> > You are correct. It is better to use the macro instead, and yes,
> > safer too. I only have one device that supports high speed i2c, but
> > I get your point. It could potentially break.
> > 
> > > On which HW did you test it?
> > 
> > I used an Artpec development board as master and INA230EVM board
> > as slave.
> 
> Artpec development board with? What SoC?

The ARTPEC-line of SoC:s are Axis Communications own ASICs, in the latest iteration
it's a Cortex-53 and includes instances of the exynos5 HSI2C ip.

> Best regards,
> Krzysztof

/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@axis.com

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

* Re: [PATCH] i2c: exynos5: Preserve high speed master code
  2021-02-17  8:32       ` Jesper Nilsson
@ 2021-02-17  8:43         ` Krzysztof Kozlowski
  0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2021-02-17  8:43 UTC (permalink / raw)
  To: Jesper Nilsson
  Cc: Mårten Lindahl, linux-samsung-soc, kernel, linux-i2c,
	linux-arm-kernel, linux-kernel

On Wed, Feb 17, 2021 at 09:32:11AM +0100, Jesper Nilsson wrote:
> On Wed, Feb 17, 2021 at 09:07:47AM +0100, Krzysztof Kozlowski wrote:
> > On Tue, Feb 16, 2021 at 11:09:33PM +0100, Marten Lindahl wrote:
> > > > Any reason why not "|= MASTER_ID(i2c->adap.nr)" here instead of more
> > > > expensive IO read? It's quite important because your current code will
> > > > bitwise-or old I2C slave address with a new one... This should break
> > > > during tests with multiple I2C slave devices, shouldn't it?
> > > > 
> > > 
> > > You are correct. It is better to use the macro instead, and yes,
> > > safer too. I only have one device that supports high speed i2c, but
> > > I get your point. It could potentially break.
> > > 
> > > > On which HW did you test it?
> > > 
> > > I used an Artpec development board as master and INA230EVM board
> > > as slave.
> > 
> > Artpec development board with? What SoC?
> 
> The ARTPEC-line of SoC:s are Axis Communications own ASICs, in the latest iteration
> it's a Cortex-53 and includes instances of the exynos5 HSI2C ip.

Cool! Good to see that this code is re-used. :)

Best regards,
Krzysztof


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

end of thread, other threads:[~2021-02-17  8:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 19:03 [PATCH] i2c: exynos5: Preserve high speed master code Mårten Lindahl
2021-02-16  7:51 ` Krzysztof Kozlowski
2021-02-16 22:09   ` Marten Lindahl
2021-02-17  8:07     ` Krzysztof Kozlowski
2021-02-17  8:32       ` Jesper Nilsson
2021-02-17  8:43         ` Krzysztof Kozlowski

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