mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work
@ 2023-07-25  8:31 carlos.song
  2023-07-25 23:41 ` Andi Shyti
  0 siblings, 1 reply; 4+ messages in thread
From: carlos.song @ 2023-07-25  8:31 UTC (permalink / raw)
  To: u.kleine-koenig, andi.shyti, aisheng.dong, shawnguo, s.hauer,
	kernel, festevam
  Cc: carlos.song, xiaoning.wang, haibo.chen, linux-imx, linux-i2c,
	linux-arm-kernel, linux-kernel

From: Gao Pan <pandy.gao@nxp.com>

When i2c peripheral clk rate is 0 directly return -EINVAL.

Signed-off-by: Gao Pan <pandy.gao@nxp.com>
Signed-off-by: Carlos Song <carlos.song@nxp.com>
---
Changes for V2:
- adjust the subject from "debug message" to "error message"
Changes for V3:
- remove output error log when i2c peripheral clk doesn't work
- adjust commit log and subject
---
 drivers/i2c/busses/i2c-imx-lpi2c.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index c3287c887c6f..150d923ca7f1 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -209,6 +209,9 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
 	lpi2c_imx_set_mode(lpi2c_imx);
 
 	clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
+	if (!clk_rate)
+		return -EINVAL;
+
 	if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
 		filt = 0;
 	else
-- 
2.34.1


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

* Re: [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work
  2023-07-25  8:31 [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work carlos.song
@ 2023-07-25 23:41 ` Andi Shyti
  2023-07-26  7:32   ` [EXT] " Carlos Song
  2023-07-26  7:59   ` Aisheng Dong
  0 siblings, 2 replies; 4+ messages in thread
From: Andi Shyti @ 2023-07-25 23:41 UTC (permalink / raw)
  To: carlos.song
  Cc: u.kleine-koenig, aisheng.dong, shawnguo, s.hauer, kernel,
	festevam, xiaoning.wang, haibo.chen, linux-imx, linux-i2c,
	linux-arm-kernel, linux-kernel

Hi Carlos,

> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -209,6 +209,9 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
>  	lpi2c_imx_set_mode(lpi2c_imx);
>  
>  	clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
> +	if (!clk_rate)
> +		return -EINVAL;
> +

this is a very unlikely to happen and generally not really
appreciated.

If you got so far it's basically impossible that clk_rate is '0'.
Uwe asked you in v2 if you actually had such case.

I don't have a strong opinion, thoug... I would drop this patch
unless Dong is OK with it and I can accept it with his ack.

Andi

>  	if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
>  		filt = 0;
>  	else
> -- 
> 2.34.1
> 

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

* RE: [EXT] Re: [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work
  2023-07-25 23:41 ` Andi Shyti
@ 2023-07-26  7:32   ` Carlos Song
  2023-07-26  7:59   ` Aisheng Dong
  1 sibling, 0 replies; 4+ messages in thread
From: Carlos Song @ 2023-07-26  7:32 UTC (permalink / raw)
  To: Andi Shyti
  Cc: u.kleine-koenig, Aisheng Dong, shawnguo, s.hauer, kernel,
	festevam, Clark Wang, Bough Chen, dl-linux-imx, linux-i2c,
	linux-arm-kernel, linux-kernel

Hi, Andi

According to Aisheng, I find that if the i2c clock rate is not assigned on MX8,
due to chip architecture, the default speed will be 0, it cause our i2c not work.
The judgment will be triggered easily. This is a special case for imx.

The log like this:
[    2.401402] imx-lpi2c 5a800000.i2c: use pio mode
[    2.419788] i2c i2c-4: clk_per rate is 0
[    2.423724] i2c i2c-4: clk_per rate is 0
[    2.444071] i2c i2c-4: clk_per rate is 0
[    2.448011] fxos8700_i2c 4-001e: Error reading chip id
[    2.453172] fxos8700_i2c: probe of 4-001e failed with error -22
[    2.459271] i2c i2c-4: supply vdd not found, using dummy regulator
[    2.465522] i2c i2c-4: supply vddio not found, using dummy regulator
[    2.471913] i2c i2c-4: clk_per rate is 0
[    2.475867] fxas21002c_i2c: probe of 4-0020 failed with error -22
[    2.482066] i2c i2c-4: clk_per rate is 0
[    2.495716] i2c i2c-4: clk_per rate is 0
[    2.505464] i2c i2c-4: clk_per rate is 0
[    2.514786] i2c i2c-4: LPI2C adapter registered

So the patch can not be dropped.
> -----Original Message-----
> From: Andi Shyti <andi.shyti@kernel.org>
> Sent: Wednesday, July 26, 2023 7:41 AM
> To: Carlos Song <carlos.song@nxp.com>
> Cc: u.kleine-koenig@pengutronix.de; Aisheng Dong <aisheng.dong@nxp.com>;
> shawnguo@kernel.org; s.hauer@pengutronix.de; kernel@pengutronix.de;
> festevam@gmail.com; Clark Wang <xiaoning.wang@nxp.com>; Bough Chen
> <haibo.chen@nxp.com>; dl-linux-imx <linux-imx@nxp.com>;
> linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> linux-kernel@vger.kernel.org
> Subject: [EXT] Re: [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral
> clk doesn't work
> 
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report this
> email' button
> 
> 
> Hi Carlos,
> 
> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > @@ -209,6 +209,9 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct
> *lpi2c_imx)
> >       lpi2c_imx_set_mode(lpi2c_imx);
> >
> >       clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
> > +     if (!clk_rate)
> > +             return -EINVAL;
> > +
> 
> this is a very unlikely to happen and generally not really appreciated.
> 
> If you got so far it's basically impossible that clk_rate is '0'.
> Uwe asked you in v2 if you actually had such case.
> 
> I don't have a strong opinion, thoug... I would drop this patch unless Dong is OK
> with it and I can accept it with his ack.
> 
> Andi
> 
> >       if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
> >               filt = 0;
> >       else
> > --
> > 2.34.1
> >

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

* RE: [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work
  2023-07-25 23:41 ` Andi Shyti
  2023-07-26  7:32   ` [EXT] " Carlos Song
@ 2023-07-26  7:59   ` Aisheng Dong
  1 sibling, 0 replies; 4+ messages in thread
From: Aisheng Dong @ 2023-07-26  7:59 UTC (permalink / raw)
  To: Andi Shyti, Carlos Song
  Cc: u.kleine-koenig, shawnguo, s.hauer, kernel, festevam, Clark Wang,
	Bough Chen, dl-linux-imx, linux-i2c, linux-arm-kernel,
	linux-kernel

> From: Andi Shyti <andi.shyti@kernel.org>
> Sent: 2023年7月26日 7:41
> Hi Carlos,
> 
> > --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> > +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> > @@ -209,6 +209,9 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct
> *lpi2c_imx)
> >  	lpi2c_imx_set_mode(lpi2c_imx);
> >
> >  	clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk);
> > +	if (!clk_rate)
> > +		return -EINVAL;
> > +
> 
> this is a very unlikely to happen and generally not really appreciated.
> 
> If you got so far it's basically impossible that clk_rate is '0'.
> Uwe asked you in v2 if you actually had such case.
> 
> I don't have a strong opinion, thoug... I would drop this patch unless Dong is
> OK with it and I can accept it with his ack.

On MX8X platforms, the default clock rate is 0 if without explicit clock setting in
dts nodes. So I wonder it may be worth adding a check here.
If you're also ok, feel free to add my tag.
Acked-by: Dong Aisheng <Aisheng.dong@nxp.com>

BTW, please see another reply from Carlos with the test log.

Regards
Aisheng

> 
> Andi
> 
> >  	if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
> >  		filt = 0;
> >  	else
> > --
> > 2.34.1
> >

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

end of thread, other threads:[~2023-07-26  8:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-25  8:31 [PATCH v4] i2c: imx-lpi2c: return -EINVAL when i2c peripheral clk doesn't work carlos.song
2023-07-25 23:41 ` Andi Shyti
2023-07-26  7:32   ` [EXT] " Carlos Song
2023-07-26  7:59   ` Aisheng Dong

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

all inboxes | Powered by JetHome®