diff mbox series

[v2,1/4] i2c: imx: only poll for bus busy in multi master mode

Message ID 20240819072052.8722-2-eichest@gmail.com
State Superseded
Headers show
Series i2c: imx: prevent rescheduling in non-dma mode | expand

Commit Message

Stefan Eichenberger Aug. 19, 2024, 7:19 a.m. UTC
From: Stefan Eichenberger <stefan.eichenberger@toradex.com>

According to the i.MX8M Mini reference manual chapter "16.1.4.2
Generation of Start" it is only necessary to poll for bus busy and
arbitration lost in multi master mode. This helps to avoid rescheduling
while the i2c bus is busy and avoids SMBus devices to timeout.

Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
---
 drivers/i2c/busses/i2c-imx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Fabio Estevam Aug. 21, 2024, 11:01 a.m. UTC | #1
Hi Stefan,

On Mon, Aug 19, 2024 at 4:20 AM Stefan Eichenberger <eichest@gmail.com> wrote:
>
> From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
>
> According to the i.MX8M Mini reference manual chapter "16.1.4.2
> Generation of Start" it is only necessary to poll for bus busy and
> arbitration lost in multi master mode. This helps to avoid rescheduling
> while the i2c bus is busy and avoids SMBus devices to timeout.
>
> Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>

This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:

[    1.893260] pca953x 2-0020: failed writing register
[    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11

Could you please add a Fixes tag and Cc stable so that this can reach
the stable kernels?

Tested-by: Fabio Estevam <festevam@denx.de>

Thanks a lot,

Fabio Estevam
Oleksij Rempel Aug. 21, 2024, 2:39 p.m. UTC | #2
Hi Fabio, Stefan,

On Wed, Aug 21, 2024 at 08:01:20AM -0300, Fabio Estevam wrote:
> Hi Stefan,
> 
> On Mon, Aug 19, 2024 at 4:20 AM Stefan Eichenberger <eichest@gmail.com> wrote:
> >
> > From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> >
> > According to the i.MX8M Mini reference manual chapter "16.1.4.2
> > Generation of Start" it is only necessary to poll for bus busy and
> > arbitration lost in multi master mode. This helps to avoid rescheduling
> > while the i2c bus is busy and avoids SMBus devices to timeout.
> >
> > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> 
> This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> 
> [    1.893260] pca953x 2-0020: failed writing register
> [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> 
> Could you please add a Fixes tag and Cc stable so that this can reach
> the stable kernels?
> 
> Tested-by: Fabio Estevam <festevam@denx.de>
> 
> Thanks a lot,

It looks like with this patch, the I2SR_IAL interrupt is not cleared.
I would expect some kind of interrupt storm. Can you confirm it?

Regards,
Oleksij
Stefan Eichenberger Aug. 21, 2024, 3:23 p.m. UTC | #3
Hi Fabio, Oleksij,

On Wed, Aug 21, 2024 at 04:39:39PM +0200, Oleksij Rempel wrote:
> Hi Fabio, Stefan,
> 
> On Wed, Aug 21, 2024 at 08:01:20AM -0300, Fabio Estevam wrote:
> > Hi Stefan,
> > 
> > On Mon, Aug 19, 2024 at 4:20 AM Stefan Eichenberger <eichest@gmail.com> wrote:
> > >
> > > From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > >
> > > According to the i.MX8M Mini reference manual chapter "16.1.4.2
> > > Generation of Start" it is only necessary to poll for bus busy and
> > > arbitration lost in multi master mode. This helps to avoid rescheduling
> > > while the i2c bus is busy and avoids SMBus devices to timeout.
> > >
> > > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> > 
> > This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> > 
> > [    1.893260] pca953x 2-0020: failed writing register
> > [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> > 
> > Could you please add a Fixes tag and Cc stable so that this can reach
> > the stable kernels?
> > 
> > Tested-by: Fabio Estevam <festevam@denx.de>

Thanks a lot for testing. Are the other patches required as well or did
only introducing the master mode flag solve the issue?

> > 
> > Thanks a lot,
> 
> It looks like with this patch, the I2SR_IAL interrupt is not cleared.
> I would expect some kind of interrupt storm. Can you confirm it?

This is a good question. i2c_imx_trx_complete was never called in the
interrupt handler. So that would mean the storm would already be there
before just for a shorter time. We only clear the IFF flag in the isr.

> This causes a processor interrupt request (if the interrupt enable is
> asserted [IIEN = 1]). The interrupt is set when one of the following
> occurs:
> - One byte transfer is completed (the interrupt is set at the falling
>   edge of the ninth clock).
> - An address is received that matches its own specific address in
>   Slave Receive mode.
> - Arbitration is lost.

Unfortunately, I don't have a device that uses multi master mode and we
would only see it on such a device. However, also from the reference
manual:

> IAL must be cleared by software by writing a "0" to it at the start of
> the interrupt service routine

So most likely it was wrong the whole the time we just didn't see it
before, could that be? I think a fix would be relatively easy we have to
clear it at the beginning of the isr but after we read the status. I
could add this to the series if you agree.

Regards,
Stefan
Fabio Estevam Aug. 21, 2024, 4:43 p.m. UTC | #4
Hi Stefan and Oleksij,

On Wed, Aug 21, 2024 at 12:23 PM Stefan Eichenberger <eichest@gmail.com> wrote:

> Thanks a lot for testing. Are the other patches required as well or did
> only introducing the master mode flag solve the issue?

Only applying this one fixed the problem.

> > It looks like with this patch, the I2SR_IAL interrupt is not cleared.
> > I would expect some kind of interrupt storm. Can you confirm it?

I have just inspected 'cat /proc/interrupts' and no interrupt storm is seen.

Thanks
Andi Shyti Aug. 21, 2024, 10:21 p.m. UTC | #5
Hi Stefan,

> @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
>  		goto rpm_disable;
>  	}
>  
> +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> +

you might also want to add the multi-master boolean property in
the binding.

Andi
Andi Shyti Aug. 21, 2024, 10:31 p.m. UTC | #6
Hi Stefan,

On Wed, Aug 21, 2024 at 05:23:24PM GMT, Stefan Eichenberger wrote:
> On Wed, Aug 21, 2024 at 04:39:39PM +0200, Oleksij Rempel wrote:
> > On Wed, Aug 21, 2024 at 08:01:20AM -0300, Fabio Estevam wrote:
> > > On Mon, Aug 19, 2024 at 4:20 AM Stefan Eichenberger <eichest@gmail.com> wrote:
> > > > According to the i.MX8M Mini reference manual chapter "16.1.4.2
> > > > Generation of Start" it is only necessary to poll for bus busy and
> > > > arbitration lost in multi master mode. This helps to avoid rescheduling
> > > > while the i2c bus is busy and avoids SMBus devices to timeout.
> > > >
> > > > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > > > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> > > 
> > > This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> > > 
> > > [    1.893260] pca953x 2-0020: failed writing register
> > > [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> > > 
> > > Could you please add a Fixes tag and Cc stable so that this can reach
> > > the stable kernels?
> > > 
> > > Tested-by: Fabio Estevam <festevam@denx.de>
> 
> Thanks a lot for testing. Are the other patches required as well or did
> only introducing the master mode flag solve the issue?

The other patches don't need the Fix tag.

One question, does the issue happen with atomic transfers or any
transfers?

> > It looks like with this patch, the I2SR_IAL interrupt is not cleared.
> > I would expect some kind of interrupt storm. Can you confirm it?
> 
> This is a good question. i2c_imx_trx_complete was never called in the
> interrupt handler. So that would mean the storm would already be there
> before just for a shorter time. We only clear the IFF flag in the isr.
> 
> > This causes a processor interrupt request (if the interrupt enable is
> > asserted [IIEN = 1]). The interrupt is set when one of the following
> > occurs:
> > - One byte transfer is completed (the interrupt is set at the falling
> >   edge of the ninth clock).
> > - An address is received that matches its own specific address in
> >   Slave Receive mode.
> > - Arbitration is lost.
> 
> Unfortunately, I don't have a device that uses multi master mode and we
> would only see it on such a device. However, also from the reference
> manual:
> 
> > IAL must be cleared by software by writing a "0" to it at the start of
> > the interrupt service routine
> 
> So most likely it was wrong the whole the time we just didn't see it
> before, could that be? I think a fix would be relatively easy we have to
> clear it at the beginning of the isr but after we read the status. I
> could add this to the series if you agree.

Please, if you can't test the patch don't send it.

Oleksij, I need your ack to apply this patch. What do you think
here?

Thanks,
Andi
Oleksij Rempel Aug. 22, 2024, 6:51 a.m. UTC | #7
On Wed, Aug 21, 2024 at 08:01:20AM -0300, Fabio Estevam wrote:
> Hi Stefan,
> 
> On Mon, Aug 19, 2024 at 4:20 AM Stefan Eichenberger <eichest@gmail.com> wrote:
> >
> > From: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> >
> > According to the i.MX8M Mini reference manual chapter "16.1.4.2
> > Generation of Start" it is only necessary to poll for bus busy and
> > arbitration lost in multi master mode. This helps to avoid rescheduling
> > while the i2c bus is busy and avoids SMBus devices to timeout.
> >
> > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com>
> > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> 
> This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> 
> [    1.893260] pca953x 2-0020: failed writing register
> [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> 
> Could you please add a Fixes tag and Cc stable so that this can reach
> the stable kernels?
> 
> Tested-by: Fabio Estevam <festevam@denx.de>
> 
> Thanks a lot,

With this updates and extended devicetree binding, you can add my:
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Please send DMA related patches as separate set.

Regards,
Oleksij
Stefan Eichenberger Aug. 22, 2024, 7:03 a.m. UTC | #8
Hi Andi,

On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> Hi Stefan,
> 
> > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> >  		goto rpm_disable;
> >  	}
> >  
> > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > +
> 
> you might also want to add the multi-master boolean property in
> the binding.

We discussed this internally and weren't sure when it was required
because e.g. i2c-rcar and i2c-tegra don't have it documented in their
bindings. Is it still required if it is part of the dt-schema?
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml

If so, I will add it in the next version.

Thanks,
Stefan
Oleksij Rempel Aug. 22, 2024, 10:04 a.m. UTC | #9
On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> Hi Andi,
> 
> On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > Hi Stefan,
> > 
> > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > >  		goto rpm_disable;
> > >  	}
> > >  
> > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > +
> > 
> > you might also want to add the multi-master boolean property in
> > the binding.
> 
> We discussed this internally and weren't sure when it was required
> because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> bindings. Is it still required if it is part of the dt-schema?
> https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml

The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
every thing not in this yaml

> If so, I will add it in the next version.

Yes, please.

Regards,
Oleksij
Fabio Estevam Aug. 22, 2024, 11:07 a.m. UTC | #10
Hi Stefan and Oleksij,

On Wed, Aug 21, 2024 at 8:01 AM Fabio Estevam <festevam@gmail.com> wrote:

> This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
>
> [    1.893260] pca953x 2-0020: failed writing register
> [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
>
> Could you please add a Fixes tag and Cc stable so that this can reach
> the stable kernels?
>
> Tested-by: Fabio Estevam <festevam@denx.de>

I am sorry, but I have to withdraw my Tested-by tag.

For debugging purposes, I kept 'fw_devlink=off' in the kernel command
line and that's what made it work.

Removing 'fw_devlink=off' I still get the probe failure, even with all
the series from Stefan applied:

[    1.849097] pca953x 2-0020: supply vcc not found, using dummy regulator
[    1.855857] pca953x 2-0020: using no AI
[    1.859965] i2c i2c-2: <i2c_imx_write> write failed with -6
[    1.865578] pca953x 2-0020: failed writing register: -6

In my case, I can get the pca953x driver to probe successfully in one
of the following cases:

1. Select pca953x as a module instead of built-in

or

2. Pass 'fw_devlink=off' in the kernel command line

or

3.  Register the i2c-imx driver as module_platform_driver():

--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -1586,17 +1586,7 @@ static struct platform_driver i2c_imx_driver = {
        .id_table = imx_i2c_devtype,
 };

-static int __init i2c_adap_imx_init(void)
-{
-       return platform_driver_register(&i2c_imx_driver);
-}
-subsys_initcall(i2c_adap_imx_init);
-
-static void __exit i2c_adap_imx_exit(void)
-{
-       platform_driver_unregister(&i2c_imx_driver);
-}
-module_exit(i2c_adap_imx_exit);
+module_platform_driver(i2c_imx_driver);

or

4. Use the NXP vendor kernel imx_6.1.22_2.0.0 kernel

Stefan, do you get the arbitration errors if you try methods 2 or 3 above?
Stefan Eichenberger Aug. 22, 2024, 11:50 a.m. UTC | #11
Hi Fabio,

On Thu, Aug 22, 2024 at 08:07:44AM -0300, Fabio Estevam wrote:
> Hi Stefan and Oleksij,
> 
> On Wed, Aug 21, 2024 at 8:01 AM Fabio Estevam <festevam@gmail.com> wrote:
> 
> > This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> >
> > [    1.893260] pca953x 2-0020: failed writing register
> > [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> >
> > Could you please add a Fixes tag and Cc stable so that this can reach
> > the stable kernels?
> >
> > Tested-by: Fabio Estevam <festevam@denx.de>
> 
> I am sorry, but I have to withdraw my Tested-by tag.
> 
> For debugging purposes, I kept 'fw_devlink=off' in the kernel command
> line and that's what made it work.
> 
> Removing 'fw_devlink=off' I still get the probe failure, even with all
> the series from Stefan applied:
> 
> [    1.849097] pca953x 2-0020: supply vcc not found, using dummy regulator
> [    1.855857] pca953x 2-0020: using no AI
> [    1.859965] i2c i2c-2: <i2c_imx_write> write failed with -6
> [    1.865578] pca953x 2-0020: failed writing register: -6
> 
> In my case, I can get the pca953x driver to probe successfully in one
> of the following cases:
> 
> 1. Select pca953x as a module instead of built-in
> 
> or
> 
> 2. Pass 'fw_devlink=off' in the kernel command line
> 
> or
> 
> 3.  Register the i2c-imx driver as module_platform_driver():
> 
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1586,17 +1586,7 @@ static struct platform_driver i2c_imx_driver = {
>         .id_table = imx_i2c_devtype,
>  };
> 
> -static int __init i2c_adap_imx_init(void)
> -{
> -       return platform_driver_register(&i2c_imx_driver);
> -}
> -subsys_initcall(i2c_adap_imx_init);
> -
> -static void __exit i2c_adap_imx_exit(void)
> -{
> -       platform_driver_unregister(&i2c_imx_driver);
> -}
> -module_exit(i2c_adap_imx_exit);
> +module_platform_driver(i2c_imx_driver);
> 
> or
> 
> 4. Use the NXP vendor kernel imx_6.1.22_2.0.0 kernel
> 
> Stefan, do you get the arbitration errors if you try methods 2 or 3 above?

I will try to test this on my end tomorrow. In our test case however one
problem was that when the schedule was called the ADC (TI ADS1015) may
timeout if it is not processed within 25ms which sometimes happened.
However, it also requires the other change because even if we have not
set multi-master, the wakeup of the sender/receiver thread can take too
much time, so we still end up in this 25ms timeout. This only happens
when the system is under heavy load.

In your setup, do you know what mode (atomic, interrupt, dma) the driver
uses when it works and when it fails?
Stefan Eichenberger Aug. 22, 2024, 12:03 p.m. UTC | #12
On Thu, Aug 22, 2024 at 12:04:43PM +0200, Oleksij Rempel wrote:
> On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> > Hi Andi,
> > 
> > On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > > Hi Stefan,
> > > 
> > > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > > >  		goto rpm_disable;
> > > >  	}
> > > >  
> > > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > > +
> > > 
> > > you might also want to add the multi-master boolean property in
> > > the binding.
> > 
> > We discussed this internally and weren't sure when it was required
> > because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> > bindings. Is it still required if it is part of the dt-schema?
> > https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml
> 
> The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
> every thing not in this yaml
> 
> > If so, I will add it in the next version.
> 
> Yes, please.

Perfect, thanks for the explanation.

Regards,
Stefan
Fabio Estevam Aug. 22, 2024, 12:59 p.m. UTC | #13
Hi Stefan,

On Thu, Aug 22, 2024 at 8:50 AM Stefan Eichenberger <eichest@gmail.com> wrote:

> In your setup, do you know what mode (atomic, interrupt, dma) the driver
> uses when it works and when it fails?

On the imx8mp board I am testing, the very first I2C register write
done by the pca935x driver fails.

Thanks
Andi Shyti Aug. 23, 2024, 12:35 a.m. UTC | #14
Hi,

On Thu, Aug 22, 2024 at 12:04:43PM GMT, Oleksij Rempel wrote:
> On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> > Hi Andi,
> > 
> > On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > > Hi Stefan,
> > > 
> > > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > > >  		goto rpm_disable;
> > > >  	}
> > > >  
> > > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > > +
> > > 
> > > you might also want to add the multi-master boolean property in
> > > the binding.
> > 
> > We discussed this internally and weren't sure when it was required
> > because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> > bindings. Is it still required if it is part of the dt-schema?
> > https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml
> 
> The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
> every thing not in this yaml
> 
> > If so, I will add it in the next version.
> 
> Yes, please.

sorry for the confusion, please don't add it. I had a chat with
Krzysztof and I will quote him: "this is a core property, coming
with dtschema, so they dont need to update bindings".

He also sent a cleanup to remove the only binding using it.

Thanks,
Andi
Stefan Eichenberger Aug. 23, 2024, 1:43 p.m. UTC | #15
Hi Fabio,

On Thu, Aug 22, 2024 at 08:07:44AM -0300, Fabio Estevam wrote:
> Hi Stefan and Oleksij,
> 
> On Wed, Aug 21, 2024 at 8:01 AM Fabio Estevam <festevam@gmail.com> wrote:
> 
> > This fixes a pca953x probe error on an imx8mp board running linux-stable 6.6:
> >
> > [    1.893260] pca953x 2-0020: failed writing register
> > [    1.898258] pca953x 2-0020: probe with driver pca953x failed with error -11
> >
> > Could you please add a Fixes tag and Cc stable so that this can reach
> > the stable kernels?
> >
> > Tested-by: Fabio Estevam <festevam@denx.de>
> 
> I am sorry, but I have to withdraw my Tested-by tag.
> 
> For debugging purposes, I kept 'fw_devlink=off' in the kernel command
> line and that's what made it work.
> 
> Removing 'fw_devlink=off' I still get the probe failure, even with all
> the series from Stefan applied:
> 
> [    1.849097] pca953x 2-0020: supply vcc not found, using dummy regulator
> [    1.855857] pca953x 2-0020: using no AI
> [    1.859965] i2c i2c-2: <i2c_imx_write> write failed with -6
> [    1.865578] pca953x 2-0020: failed writing register: -6
> 
> In my case, I can get the pca953x driver to probe successfully in one
> of the following cases:
> 
> 1. Select pca953x as a module instead of built-in
> 
> or
> 
> 2. Pass 'fw_devlink=off' in the kernel command line
> 
> or
> 
> 3.  Register the i2c-imx driver as module_platform_driver():
> 
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1586,17 +1586,7 @@ static struct platform_driver i2c_imx_driver = {
>         .id_table = imx_i2c_devtype,
>  };
> 
> -static int __init i2c_adap_imx_init(void)
> -{
> -       return platform_driver_register(&i2c_imx_driver);
> -}
> -subsys_initcall(i2c_adap_imx_init);
> -
> -static void __exit i2c_adap_imx_exit(void)
> -{
> -       platform_driver_unregister(&i2c_imx_driver);
> -}
> -module_exit(i2c_adap_imx_exit);
> +module_platform_driver(i2c_imx_driver);
> 
> or
> 
> 4. Use the NXP vendor kernel imx_6.1.22_2.0.0 kernel
> 
> Stefan, do you get the arbitration errors if you try methods 2 or 3 above?

I have tried method 3 an it did not work for me. I still have the same
issue as before that sometimes the timeout occurs and the ads1015 will
not ack anymore. So the patch series is still the only way I found so
far to get rid of the problem. I also checked the datasheet of a pca953x
device (PCAL6416A) and it doesn't seem to have a timeout mechanism.
Therefore, I don't think we are affected by the same issue.

Regards,
Stefan
Stefan Eichenberger Aug. 23, 2024, 1:48 p.m. UTC | #16
Hi Andi,

On Fri, Aug 23, 2024 at 02:35:54AM +0200, Andi Shyti wrote:
> Hi,
> 
> On Thu, Aug 22, 2024 at 12:04:43PM GMT, Oleksij Rempel wrote:
> > On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> > > Hi Andi,
> > > 
> > > On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > > > Hi Stefan,
> > > > 
> > > > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > > > >  		goto rpm_disable;
> > > > >  	}
> > > > >  
> > > > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > > > +
> > > > 
> > > > you might also want to add the multi-master boolean property in
> > > > the binding.
> > > 
> > > We discussed this internally and weren't sure when it was required
> > > because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> > > bindings. Is it still required if it is part of the dt-schema?
> > > https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml
> > 
> > The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
> > every thing not in this yaml
> > 
> > > If so, I will add it in the next version.
> > 
> > Yes, please.
> 
> sorry for the confusion, please don't add it. I had a chat with
> Krzysztof and I will quote him: "this is a core property, coming
> with dtschema, so they dont need to update bindings".
> 
> He also sent a cleanup to remove the only binding using it.

No problem, thanks for the clarification. 

Should I still separate the multi-master patch from the rest of the
series, even though it doesn't seem to fix the problem Fabio sees? I did
some more testing today and the workarounds he found do not solve the
problem I see, so they are definitely not the same.

Regards,
Stefan
Oleksij Rempel Aug. 23, 2024, 2:04 p.m. UTC | #17
On Fri, Aug 23, 2024 at 03:48:32PM +0200, Stefan Eichenberger wrote:
> Hi Andi,
> 
> On Fri, Aug 23, 2024 at 02:35:54AM +0200, Andi Shyti wrote:
> > Hi,
> > 
> > On Thu, Aug 22, 2024 at 12:04:43PM GMT, Oleksij Rempel wrote:
> > > On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> > > > Hi Andi,
> > > > 
> > > > On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > > > > Hi Stefan,
> > > > > 
> > > > > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > > > > >  		goto rpm_disable;
> > > > > >  	}
> > > > > >  
> > > > > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > > > > +
> > > > > 
> > > > > you might also want to add the multi-master boolean property in
> > > > > the binding.
> > > > 
> > > > We discussed this internally and weren't sure when it was required
> > > > because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> > > > bindings. Is it still required if it is part of the dt-schema?
> > > > https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml
> > > 
> > > The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
> > > every thing not in this yaml
> > > 
> > > > If so, I will add it in the next version.
> > > 
> > > Yes, please.
> > 
> > sorry for the confusion, please don't add it. I had a chat with
> > Krzysztof and I will quote him: "this is a core property, coming
> > with dtschema, so they dont need to update bindings".
> > 
> > He also sent a cleanup to remove the only binding using it.
> 
> No problem, thanks for the clarification. 
> 
> Should I still separate the multi-master patch from the rest of the
> series, even though it doesn't seem to fix the problem Fabio sees? I did
> some more testing today and the workarounds he found do not solve the
> problem I see, so they are definitely not the same.

I'll try to review your DMA patches next week.

Regards,
Oleksij
Stefan Eichenberger Aug. 23, 2024, 2:42 p.m. UTC | #18
Hi Oleksij,

On Fri, Aug 23, 2024 at 04:04:58PM +0200, Oleksij Rempel wrote:
> On Fri, Aug 23, 2024 at 03:48:32PM +0200, Stefan Eichenberger wrote:
> > Hi Andi,
> > 
> > On Fri, Aug 23, 2024 at 02:35:54AM +0200, Andi Shyti wrote:
> > > Hi,
> > > 
> > > On Thu, Aug 22, 2024 at 12:04:43PM GMT, Oleksij Rempel wrote:
> > > > On Thu, Aug 22, 2024 at 09:03:55AM +0200, Stefan Eichenberger wrote:
> > > > > Hi Andi,
> > > > > 
> > > > > On Thu, Aug 22, 2024 at 12:21:30AM +0200, Andi Shyti wrote:
> > > > > > Hi Stefan,
> > > > > > 
> > > > > > > @@ -1468,6 +1473,8 @@ static int i2c_imx_probe(struct platform_device *pdev)
> > > > > > >  		goto rpm_disable;
> > > > > > >  	}
> > > > > > >  
> > > > > > > +	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
> > > > > > > +
> > > > > > 
> > > > > > you might also want to add the multi-master boolean property in
> > > > > > the binding.
> > > > > 
> > > > > We discussed this internally and weren't sure when it was required
> > > > > because e.g. i2c-rcar and i2c-tegra don't have it documented in their
> > > > > bindings. Is it still required if it is part of the dt-schema?
> > > > > https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/i2c/i2c-controller.yaml
> > > > 
> > > > The i2c-imx.yaml has "unevaluatedProperties: false", which fill discard
> > > > every thing not in this yaml
> > > > 
> > > > > If so, I will add it in the next version.
> > > > 
> > > > Yes, please.
> > > 
> > > sorry for the confusion, please don't add it. I had a chat with
> > > Krzysztof and I will quote him: "this is a core property, coming
> > > with dtschema, so they dont need to update bindings".
> > > 
> > > He also sent a cleanup to remove the only binding using it.
> > 
> > No problem, thanks for the clarification. 
> > 
> > Should I still separate the multi-master patch from the rest of the
> > series, even though it doesn't seem to fix the problem Fabio sees? I did
> > some more testing today and the workarounds he found do not solve the
> > problem I see, so they are definitely not the same.
> 
> I'll try to review your DMA patches next week.

Perfect, thank you, no need to hurry.

Regards,
Stefan
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 3842e527116b7..1add946e3bc20 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -216,6 +216,8 @@  struct imx_i2c_struct {
 	struct i2c_client	*slave;
 	enum i2c_slave_event last_slave_event;
 
+	bool			multi_master;
+
 	/* For checking slave events. */
 	spinlock_t     slave_lock;
 	struct hrtimer slave_timer;
@@ -481,6 +483,9 @@  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;
+
 	while (1) {
 		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
 
@@ -540,8 +545,8 @@  static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic)
 		return -ETIMEDOUT;
 	}
 
-	/* check for arbitration lost */
-	if (i2c_imx->i2csr & I2SR_IAL) {
+	/* In multi-master mode check for arbitration lost */
+	if (i2c_imx->multi_master && (i2c_imx->i2csr & I2SR_IAL)) {
 		dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__);
 		i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
 
@@ -1468,6 +1473,8 @@  static int i2c_imx_probe(struct platform_device *pdev)
 		goto rpm_disable;
 	}
 
+	i2c_imx->multi_master = of_property_read_bool(pdev->dev.of_node, "multi-master");
+
 	/* Set up clock divider */
 	i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ;
 	ret = of_property_read_u32(pdev->dev.of_node,