* [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode
@ 2024-08-19 7:19 Stefan Eichenberger
2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger
` (3 more replies)
0 siblings, 4 replies; 26+ messages in thread
From: Stefan Eichenberger @ 2024-08-19 7:19 UTC (permalink / raw)
To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam,
Frank.Li, francesco.dolcini
Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel
While running tests on an i.MX8M Mini connected to a TI ADS1015 ADC, we
found that the ADC would stop responding to i2c requests because it
would timeout after the bus was idle for 25ms. This timeout could be
traced back to the rescheduling events in the i2c-imx driver. The
problem is that if the system is under heavy load, the schedule call and
the wait_event_timeout may be rescheduled too late to reach the 25ms
timeout. The same problem may occur with other SMBus devices. Therefore,
this patchset removes the scheduling calls for non-DMA mode by handling
the interrupt events directly in the ISR instead of scheduling a task to
handle the events.
This patch will introduce some bigger changes because the logic for
handling events in the ISR had to be rewritten. Therefore we have tested
the following combinations:
- i.MX8M Mini with dma
- i.MX8M Mini without dma
- i.MX8M Plus with dma
- i.MX8M Plus without dma
- i.MX7D with dma
- i.MX7D without dma
- i.MX7D atomic mode
Because we do not have any devices that use the SMBus block transfer
mode, we were not able to test it.
The ideas are based on the RFC:
https://lore.kernel.org/all/20240531142437.74831-1-eichest@gmail.com/
However, the handling of events in the ISR is new, because further
testing showed that it was not enough to simply remove the schedule
call.
Changes since v1:
- Add Reviewed-by tags from Frank
- Add new patch to use readb_relaxed and writeb_relaxed (Frank)
- Update commit message for patch 1 with some clarifications (Frank)
Stefan Eichenberger (4):
i2c: imx: only poll for bus busy in multi master mode
i2c: imx: separate atomic, dma and non-dma use case
i2c: imx: use readb_relaxed and writeb_relaxed
i2c: imx: prevent rescheduling in non dma mode
drivers/i2c/busses/i2c-imx.c | 357 ++++++++++++++++++++++++++++++-----
1 file changed, 305 insertions(+), 52 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 26+ messages in thread* [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-19 7:19 [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger @ 2024-08-19 7:19 ` Stefan Eichenberger 2024-08-21 11:01 ` Fabio Estevam 2024-08-21 22:21 ` Andi Shyti 2024-08-19 7:19 ` [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case Stefan Eichenberger ` (2 subsequent siblings) 3 siblings, 2 replies; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-19 7:19 UTC (permalink / raw) To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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(-) 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, -- 2.43.0 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger @ 2024-08-21 11:01 ` Fabio Estevam 2024-08-21 14:39 ` Oleksij Rempel ` (2 more replies) 2024-08-21 22:21 ` Andi Shyti 1 sibling, 3 replies; 26+ messages in thread From: Fabio Estevam @ 2024-08-21 11:01 UTC (permalink / raw) To: Stefan Eichenberger Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 11:01 ` Fabio Estevam @ 2024-08-21 14:39 ` Oleksij Rempel 2024-08-21 15:23 ` Stefan Eichenberger 2024-08-22 6:51 ` Oleksij Rempel 2024-08-22 11:07 ` Fabio Estevam 2 siblings, 1 reply; 26+ messages in thread From: Oleksij Rempel @ 2024-08-21 14:39 UTC (permalink / raw) To: Fabio Estevam Cc: Stefan Eichenberger, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 14:39 ` Oleksij Rempel @ 2024-08-21 15:23 ` Stefan Eichenberger 2024-08-21 16:43 ` Fabio Estevam 2024-08-21 22:31 ` Andi Shyti 0 siblings, 2 replies; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-21 15:23 UTC (permalink / raw) To: Oleksij Rempel Cc: Fabio Estevam, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 15:23 ` Stefan Eichenberger @ 2024-08-21 16:43 ` Fabio Estevam 2024-08-21 22:31 ` Andi Shyti 1 sibling, 0 replies; 26+ messages in thread From: Fabio Estevam @ 2024-08-21 16:43 UTC (permalink / raw) To: Stefan Eichenberger Cc: Oleksij Rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 15:23 ` Stefan Eichenberger 2024-08-21 16:43 ` Fabio Estevam @ 2024-08-21 22:31 ` Andi Shyti 1 sibling, 0 replies; 26+ messages in thread From: Andi Shyti @ 2024-08-21 22:31 UTC (permalink / raw) To: Stefan Eichenberger Cc: Oleksij Rempel, Fabio Estevam, kernel, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 11:01 ` Fabio Estevam 2024-08-21 14:39 ` Oleksij Rempel @ 2024-08-22 6:51 ` Oleksij Rempel 2024-08-22 11:07 ` Fabio Estevam 2 siblings, 0 replies; 26+ messages in thread From: Oleksij Rempel @ 2024-08-22 6:51 UTC (permalink / raw) To: Fabio Estevam Cc: Stefan Eichenberger, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 11:01 ` Fabio Estevam 2024-08-21 14:39 ` Oleksij Rempel 2024-08-22 6:51 ` Oleksij Rempel @ 2024-08-22 11:07 ` Fabio Estevam 2024-08-22 11:50 ` Stefan Eichenberger 2024-08-23 13:43 ` Stefan Eichenberger 2 siblings, 2 replies; 26+ messages in thread From: Fabio Estevam @ 2024-08-22 11:07 UTC (permalink / raw) To: Stefan Eichenberger Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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? ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 11:07 ` Fabio Estevam @ 2024-08-22 11:50 ` Stefan Eichenberger 2024-08-22 12:59 ` Fabio Estevam 2024-08-23 13:43 ` Stefan Eichenberger 1 sibling, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-22 11:50 UTC (permalink / raw) To: Fabio Estevam Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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? ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 11:50 ` Stefan Eichenberger @ 2024-08-22 12:59 ` Fabio Estevam 0 siblings, 0 replies; 26+ messages in thread From: Fabio Estevam @ 2024-08-22 12:59 UTC (permalink / raw) To: Stefan Eichenberger Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 11:07 ` Fabio Estevam 2024-08-22 11:50 ` Stefan Eichenberger @ 2024-08-23 13:43 ` Stefan Eichenberger 1 sibling, 0 replies; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-23 13:43 UTC (permalink / raw) To: Fabio Estevam Cc: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger 2024-08-21 11:01 ` Fabio Estevam @ 2024-08-21 22:21 ` Andi Shyti 2024-08-22 7:03 ` Stefan Eichenberger 1 sibling, 1 reply; 26+ messages in thread From: Andi Shyti @ 2024-08-21 22:21 UTC (permalink / raw) To: Stefan Eichenberger Cc: o.rempel, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-21 22:21 ` Andi Shyti @ 2024-08-22 7:03 ` Stefan Eichenberger 2024-08-22 10:04 ` Oleksij Rempel 0 siblings, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-22 7:03 UTC (permalink / raw) To: Andi Shyti Cc: o.rempel, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 7:03 ` Stefan Eichenberger @ 2024-08-22 10:04 ` Oleksij Rempel 2024-08-22 12:03 ` Stefan Eichenberger 2024-08-23 0:35 ` Andi Shyti 0 siblings, 2 replies; 26+ messages in thread From: Oleksij Rempel @ 2024-08-22 10:04 UTC (permalink / raw) To: Stefan Eichenberger Cc: Andi Shyti, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 10:04 ` Oleksij Rempel @ 2024-08-22 12:03 ` Stefan Eichenberger 2024-08-23 0:35 ` Andi Shyti 1 sibling, 0 replies; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-22 12:03 UTC (permalink / raw) To: Oleksij Rempel Cc: Andi Shyti, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-22 10:04 ` Oleksij Rempel 2024-08-22 12:03 ` Stefan Eichenberger @ 2024-08-23 0:35 ` Andi Shyti 2024-08-23 13:48 ` Stefan Eichenberger 1 sibling, 1 reply; 26+ messages in thread From: Andi Shyti @ 2024-08-23 0:35 UTC (permalink / raw) To: Oleksij Rempel Cc: Stefan Eichenberger, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger, Krzysztof Kozlowski 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-23 0:35 ` Andi Shyti @ 2024-08-23 13:48 ` Stefan Eichenberger 2024-08-23 14:04 ` Oleksij Rempel 0 siblings, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-23 13:48 UTC (permalink / raw) To: Andi Shyti Cc: Oleksij Rempel, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger, Krzysztof Kozlowski 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-23 13:48 ` Stefan Eichenberger @ 2024-08-23 14:04 ` Oleksij Rempel 2024-08-23 14:42 ` Stefan Eichenberger 0 siblings, 1 reply; 26+ messages in thread From: Oleksij Rempel @ 2024-08-23 14:04 UTC (permalink / raw) To: Stefan Eichenberger Cc: Andi Shyti, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger, Krzysztof Kozlowski 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 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode 2024-08-23 14:04 ` Oleksij Rempel @ 2024-08-23 14:42 ` Stefan Eichenberger 0 siblings, 0 replies; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-23 14:42 UTC (permalink / raw) To: Oleksij Rempel Cc: Andi Shyti, kernel, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger, Krzysztof Kozlowski 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 ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case 2024-08-19 7:19 [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger @ 2024-08-19 7:19 ` Stefan Eichenberger 2024-08-30 7:31 ` Oleksij Rempel 2024-08-19 7:19 ` [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode Stefan Eichenberger 3 siblings, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-19 7:19 UTC (permalink / raw) To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger From: Stefan Eichenberger <stefan.eichenberger@toradex.com> Separate the atomic, dma and non-dma use case as a preparation step for moving the non-dma use case to the isr to avoid rescheduling while a transfer is in progress. Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> --- drivers/i2c/busses/i2c-imx.c | 107 +++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 1add946e3bc20..e242166cb6638 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1011,6 +1011,43 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx, return i2c_imx_acked(i2c_imx); } +static int i2c_imx_start_read(struct imx_i2c_struct *i2c_imx, + struct i2c_msg *msgs, bool atomic, + bool use_dma) +{ + int result; + unsigned int temp = 0; + + /* write slave address */ + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); + result = i2c_imx_trx_complete(i2c_imx, atomic); + if (result) + return result; + result = i2c_imx_acked(i2c_imx); + if (result) + return result; + + dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); + + /* setup bus to read data */ + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp &= ~I2CR_MTX; + + /* + * Reset the I2CR_TXAK flag initially for SMBus block read since the + * length is unknown + */ + if (msgs->len - 1) + temp &= ~I2CR_TXAK; + if (use_dma) + temp |= I2CR_DMAEN; + + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ + + return 0; +} + static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bool is_lastmsg) { @@ -1021,6 +1058,11 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, struct imx_i2c_dma *dma = i2c_imx->dma; struct device *dev = &i2c_imx->adapter.dev; + result = i2c_imx_start_read(i2c_imx, msgs, false, true); + if (result) + return result; + + dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); dma->chan_using = dma->chan_rx; dma->dma_transfer_dir = DMA_DEV_TO_MEM; @@ -1131,50 +1173,24 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, return 0; } +static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) +{ + return i2c_imx_write(i2c_imx, msgs, true); +} + static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bool is_lastmsg, bool atomic) { int i, result; unsigned int temp; int block_data = msgs->flags & I2C_M_RECV_LEN; - int use_dma = i2c_imx->dma && msgs->flags & I2C_M_DMA_SAFE && - msgs->len >= DMA_THRESHOLD && !block_data; - dev_dbg(&i2c_imx->adapter.dev, - "<%s> write slave address: addr=0x%x\n", - __func__, i2c_8bit_addr_from_msg(msgs)); - - /* write slave address */ - imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); - result = i2c_imx_trx_complete(i2c_imx, atomic); + result = i2c_imx_start_read(i2c_imx, msgs, atomic, false); if (result) return result; - result = i2c_imx_acked(i2c_imx); - if (result) - return result; - - dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); - - /* setup bus to read data */ - temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); - temp &= ~I2CR_MTX; - - /* - * Reset the I2CR_TXAK flag initially for SMBus block read since the - * length is unknown - */ - if ((msgs->len - 1) || block_data) - temp &= ~I2CR_TXAK; - if (use_dma) - temp |= I2CR_DMAEN; - imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); - imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); - if (use_dma) - return i2c_imx_dma_read(i2c_imx, msgs, is_lastmsg); - /* read data */ for (i = 0; i < msgs->len; i++) { u8 len = 0; @@ -1241,6 +1257,12 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, return 0; } +static int i2c_imx_atomic_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, + bool is_lastmsg) +{ + return i2c_imx_read(i2c_imx, msgs, is_lastmsg, true); +} + static int i2c_imx_xfer_common(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num, bool atomic) { @@ -1248,6 +1270,7 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, int result; bool is_lastmsg = false; struct imx_i2c_struct *i2c_imx = i2c_get_adapdata(adapter); + int use_dma = 0; /* Start I2C transfer */ result = i2c_imx_start(i2c_imx, atomic); @@ -1300,15 +1323,25 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, (temp & I2SR_SRW ? 1 : 0), (temp & I2SR_IIF ? 1 : 0), (temp & I2SR_RXAK ? 1 : 0)); #endif + + use_dma = i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && + msgs[i].flags & I2C_M_DMA_SAFE; if (msgs[i].flags & I2C_M_RD) { - result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, atomic); + int block_data = msgs->flags & I2C_M_RECV_LEN; + + if (atomic) + result = i2c_imx_atomic_read(i2c_imx, &msgs[i], is_lastmsg); + else if (use_dma && !block_data) + result = i2c_imx_dma_read(i2c_imx, &msgs[i], is_lastmsg); + else + result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, false); } else { - if (!atomic && - i2c_imx->dma && msgs[i].len >= DMA_THRESHOLD && - msgs[i].flags & I2C_M_DMA_SAFE) + if (atomic) + result = i2c_imx_atomic_write(i2c_imx, &msgs[i]); + else if (use_dma) result = i2c_imx_dma_write(i2c_imx, &msgs[i]); else - result = i2c_imx_write(i2c_imx, &msgs[i], atomic); + result = i2c_imx_write(i2c_imx, &msgs[i], false); } if (result) goto fail0; -- 2.43.0 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case 2024-08-19 7:19 ` [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case Stefan Eichenberger @ 2024-08-30 7:31 ` Oleksij Rempel 0 siblings, 0 replies; 26+ messages in thread From: Oleksij Rempel @ 2024-08-30 7:31 UTC (permalink / raw) To: Stefan Eichenberger Cc: kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger On Mon, Aug 19, 2024 at 09:19:08AM +0200, Stefan Eichenberger wrote: > From: Stefan Eichenberger <stefan.eichenberger@toradex.com> > > Separate the atomic, dma and non-dma use case as a preparation step for > moving the non-dma use case to the isr to avoid rescheduling while a > transfer is in progress. > > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> > Reviewed-by: Frank Li <Frank.Li@nxp.com> I would prefer to rename i2c_imx_start_read() to i2c_imx_prepare_read() With this change: Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> Thank you! Regards, Oleksij -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed 2024-08-19 7:19 [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case Stefan Eichenberger @ 2024-08-19 7:19 ` Stefan Eichenberger 2024-08-30 7:37 ` Oleksij Rempel 2024-08-19 7:19 ` [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode Stefan Eichenberger 3 siblings, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-19 7:19 UTC (permalink / raw) To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger From: Stefan Eichenberger <stefan.eichenberger@toradex.com> Use the relaxed version of readb and writeb to reduce overhead. It is safe to use the relaxed version because we either do not rely on dma completion, or we use a dma callback to ensure that the dma transfer is complete before we continue. Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> --- drivers/i2c/busses/i2c-imx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index e242166cb6638..ccb466c50f598 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -313,13 +313,13 @@ static inline int is_vf610_i2c(struct imx_i2c_struct *i2c_imx) static inline void imx_i2c_write_reg(unsigned int val, struct imx_i2c_struct *i2c_imx, unsigned int reg) { - writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); + writeb_relaxed(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); } static inline unsigned char imx_i2c_read_reg(struct imx_i2c_struct *i2c_imx, unsigned int reg) { - return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); + return readb_relaxed(i2c_imx->base + (reg << i2c_imx->hwdata->regshift)); } static void i2c_imx_clear_irq(struct imx_i2c_struct *i2c_imx, unsigned int bits) -- 2.43.0 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed 2024-08-19 7:19 ` [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed Stefan Eichenberger @ 2024-08-30 7:37 ` Oleksij Rempel 0 siblings, 0 replies; 26+ messages in thread From: Oleksij Rempel @ 2024-08-30 7:37 UTC (permalink / raw) To: Stefan Eichenberger Cc: kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger On Mon, Aug 19, 2024 at 09:19:09AM +0200, Stefan Eichenberger wrote: > From: Stefan Eichenberger <stefan.eichenberger@toradex.com> > > Use the relaxed version of readb and writeb to reduce overhead. It is > safe to use the relaxed version because we either do not rely on dma > completion, or we use a dma callback to ensure that the dma transfer is > complete before we continue. > > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode 2024-08-19 7:19 [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger ` (2 preceding siblings ...) 2024-08-19 7:19 ` [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed Stefan Eichenberger @ 2024-08-19 7:19 ` Stefan Eichenberger 2024-08-30 8:13 ` Oleksij Rempel 3 siblings, 1 reply; 26+ messages in thread From: Stefan Eichenberger @ 2024-08-19 7:19 UTC (permalink / raw) To: o.rempel, kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini Cc: linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger From: Stefan Eichenberger <stefan.eichenberger@toradex.com> We are experiencing a problem with the i.MX I2C controller when communicating with SMBus devices. We are seeing devices time-out because the time between sending/receiving two bytes is too long, and the SMBus device returns to the idle state. This happens because the i.MX I2C controller sends and receives byte by byte. When a byte is sent or received, we get an interrupt and can send or receive the next byte. The current implementation sends a byte and then waits for an event generated by the interrupt subroutine. After the event is received, the next byte is sent and we wait again. This waiting allows the scheduler to reschedule other tasks, with the disadvantage that we may not send the next byte for a long time because the send task is not immediately scheduled. For example, if the rescheduling takes more than 25ms, this can cause SMBus devices to timeout and communication to fail. This patch changes the behavior so that we do not reschedule the send/receive task, but instead send or receive the next byte in the interrupt subroutine. This prevents rescheduling and drastically reduces the time between sending/receiving bytes. The cost in the interrupt subroutine is relatively small, we check what state we are in and then send/receive the next byte. Before we had to call wake_up, which is even less expensive. However, we also had to do some scheduling, which increased the overall cost compared to the new solution. The wake_up function to wake up the send/receive task is now only called when an error occurs or when the transfer is complete. Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> --- drivers/i2c/busses/i2c-imx.c | 257 ++++++++++++++++++++++++++++++++--- 1 file changed, 235 insertions(+), 22 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index ccb466c50f598..aa0c99ac7cf7f 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -197,6 +197,17 @@ struct imx_i2c_dma { enum dma_data_direction dma_data_dir; }; +enum imx_i2c_state { + IMX_I2C_STATE_DONE, + IMX_I2C_STATE_FAILED, + IMX_I2C_STATE_WRITE, + IMX_I2C_STATE_DMA, + IMX_I2C_STATE_READ, + IMX_I2C_STATE_READ_CONTINUE, + IMX_I2C_STATE_READ_BLOCK_DATA, + IMX_I2C_STATE_READ_BLOCK_DATA_LEN, +}; + struct imx_i2c_struct { struct i2c_adapter adapter; struct clk *clk; @@ -216,6 +227,12 @@ struct imx_i2c_struct { struct i2c_client *slave; enum i2c_slave_event last_slave_event; + struct i2c_msg *msg; + unsigned int msg_buf_idx; + int isr_result; + bool is_lastmsg; + enum imx_i2c_state state; + bool multi_master; /* For checking slave events. */ @@ -908,11 +925,150 @@ static int i2c_imx_unreg_slave(struct i2c_client *client) return ret; } +static inline int i2c_imx_isr_acked(struct imx_i2c_struct *i2c_imx) +{ + i2c_imx->isr_result = 0; + + if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) { + i2c_imx->state = IMX_I2C_STATE_FAILED; + i2c_imx->isr_result = -ENXIO; + wake_up(&i2c_imx->queue); + } + + return i2c_imx->isr_result; +} + +static inline int i2c_imx_isr_write(struct imx_i2c_struct *i2c_imx) +{ + int result; + + result = i2c_imx_isr_acked(i2c_imx); + if (result) + return result; + + if (i2c_imx->msg->len == i2c_imx->msg_buf_idx) + return 0; + + imx_i2c_write_reg(i2c_imx->msg->buf[i2c_imx->msg_buf_idx++], i2c_imx, IMX_I2C_I2DR); + + return 1; +} + +static inline int i2c_imx_isr_read(struct imx_i2c_struct *i2c_imx) +{ + int result; + unsigned int temp; + + result = i2c_imx_isr_acked(i2c_imx); + if (result) + return result; + + /* setup bus to read data */ + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp &= ~I2CR_MTX; + if (i2c_imx->msg->len - 1) + temp &= ~I2CR_TXAK; + + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */ + + return 0; +} + +static inline void i2c_imx_isr_read_continue(struct imx_i2c_struct *i2c_imx) +{ + unsigned int temp; + + if ((i2c_imx->msg->len - 1) == i2c_imx->msg_buf_idx) { + if (i2c_imx->is_lastmsg) { + /* + * It must generate STOP before read I2DR to prevent + * controller from generating another clock cycle + */ + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + if (!(temp & I2CR_MSTA)) + i2c_imx->stopped = 1; + temp &= ~(I2CR_MSTA | I2CR_MTX); + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + } else { + /* + * For i2c master receiver repeat restart operation like: + * read -> repeat MSTA -> read/write + * The controller must set MTX before read the last byte in + * the first read operation, otherwise the first read cost + * one extra clock cycle. + */ + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp |= I2CR_MTX; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + } + } else if (i2c_imx->msg_buf_idx == (i2c_imx->msg->len - 2)) { + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp |= I2CR_TXAK; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + } + + i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); +} + +static inline void i2c_imx_isr_read_block_data_len(struct imx_i2c_struct *i2c_imx) +{ + u8 len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); + + if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) { + i2c_imx->isr_result = -EPROTO; + i2c_imx->state = IMX_I2C_STATE_FAILED; + wake_up(&i2c_imx->queue); + } + i2c_imx->msg->len += len; +} + static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned int status) { - /* save status register */ - i2c_imx->i2csr = status; - wake_up(&i2c_imx->queue); + switch (i2c_imx->state) { + case IMX_I2C_STATE_DMA: + i2c_imx->i2csr = status; + wake_up(&i2c_imx->queue); + break; + + case IMX_I2C_STATE_READ: + if (i2c_imx_isr_read(i2c_imx)) + break; + i2c_imx->state = IMX_I2C_STATE_READ_CONTINUE; + break; + + case IMX_I2C_STATE_READ_CONTINUE: + i2c_imx_isr_read_continue(i2c_imx); + if (i2c_imx->msg_buf_idx == i2c_imx->msg->len) { + i2c_imx->state = IMX_I2C_STATE_DONE; + wake_up(&i2c_imx->queue); + } + break; + + case IMX_I2C_STATE_READ_BLOCK_DATA: + if (i2c_imx_isr_read(i2c_imx)) + break; + i2c_imx->state = IMX_I2C_STATE_READ_BLOCK_DATA_LEN; + break; + + case IMX_I2C_STATE_READ_BLOCK_DATA_LEN: + i2c_imx_isr_read_block_data_len(i2c_imx); + i2c_imx->state = IMX_I2C_STATE_READ_CONTINUE; + break; + + case IMX_I2C_STATE_WRITE: + if (i2c_imx_isr_write(i2c_imx)) + break; + i2c_imx->state = IMX_I2C_STATE_DONE; + wake_up(&i2c_imx->queue); + break; + + default: + i2c_imx->i2csr = status; + i2c_imx->state = IMX_I2C_STATE_FAILED; + i2c_imx->isr_result = -EINVAL; + wake_up(&i2c_imx->queue); + } return IRQ_HANDLED; } @@ -959,6 +1115,8 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx, struct imx_i2c_dma *dma = i2c_imx->dma; struct device *dev = &i2c_imx->adapter.dev; + i2c_imx->state = IMX_I2C_STATE_DMA; + dma->chan_using = dma->chan_tx; dma->dma_transfer_dir = DMA_MEM_TO_DEV; dma->dma_data_dir = DMA_TO_DEVICE; @@ -1012,15 +1170,14 @@ static int i2c_imx_dma_write(struct imx_i2c_struct *i2c_imx, } static int i2c_imx_start_read(struct imx_i2c_struct *i2c_imx, - struct i2c_msg *msgs, bool atomic, - bool use_dma) + struct i2c_msg *msgs, bool use_dma) { int result; unsigned int temp = 0; /* write slave address */ imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); - result = i2c_imx_trx_complete(i2c_imx, atomic); + result = i2c_imx_trx_complete(i2c_imx, !use_dma); if (result) return result; result = i2c_imx_acked(i2c_imx); @@ -1058,7 +1215,9 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, struct imx_i2c_dma *dma = i2c_imx->dma; struct device *dev = &i2c_imx->adapter.dev; - result = i2c_imx_start_read(i2c_imx, msgs, false, true); + i2c_imx->state = IMX_I2C_STATE_DMA; + + result = i2c_imx_start_read(i2c_imx, msgs, true); if (result) return result; @@ -1139,8 +1298,8 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, return 0; } -static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, - bool atomic) +static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx, + struct i2c_msg *msgs) { int i, result; @@ -1149,7 +1308,7 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, /* write slave address */ imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); - result = i2c_imx_trx_complete(i2c_imx, atomic); + result = i2c_imx_trx_complete(i2c_imx, true); if (result) return result; result = i2c_imx_acked(i2c_imx); @@ -1163,7 +1322,7 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, "<%s> write byte: B%d=0x%X\n", __func__, i, msgs->buf[i]); imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR); - result = i2c_imx_trx_complete(i2c_imx, atomic); + result = i2c_imx_trx_complete(i2c_imx, true); if (result) return result; result = i2c_imx_acked(i2c_imx); @@ -1173,19 +1332,40 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, return 0; } -static int i2c_imx_atomic_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) +static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs) { - return i2c_imx_write(i2c_imx, msgs, true); + dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n", + __func__, i2c_8bit_addr_from_msg(msgs)); + + i2c_imx->state = IMX_I2C_STATE_WRITE; + i2c_imx->msg = msgs; + i2c_imx->msg_buf_idx = 0; + /* write slave address and start transmission */ + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); + wait_event_timeout(i2c_imx->queue, + i2c_imx->state == IMX_I2C_STATE_DONE || + i2c_imx->state == IMX_I2C_STATE_FAILED, + (msgs->len + 1)*HZ / 10); + if (i2c_imx->state == IMX_I2C_STATE_FAILED) { + dev_err(&i2c_imx->adapter.dev, "<%s> write failed with %d\n", + __func__, i2c_imx->isr_result); + return i2c_imx->isr_result; + } + if (i2c_imx->state != IMX_I2C_STATE_DONE) { + dev_err(&i2c_imx->adapter.dev, "<%s> write timedout\n", __func__); + return -ETIMEDOUT; + } + return 0; } -static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, - bool is_lastmsg, bool atomic) +static int i2c_imx_atomic_read(struct imx_i2c_struct *i2c_imx, + struct i2c_msg *msgs, bool is_lastmsg) { int i, result; unsigned int temp; int block_data = msgs->flags & I2C_M_RECV_LEN; - result = i2c_imx_start_read(i2c_imx, msgs, atomic, false); + result = i2c_imx_start_read(i2c_imx, msgs, false); if (result) return result; @@ -1195,7 +1375,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, for (i = 0; i < msgs->len; i++) { u8 len = 0; - result = i2c_imx_trx_complete(i2c_imx, atomic); + result = i2c_imx_trx_complete(i2c_imx, true); if (result) return result; /* @@ -1226,7 +1406,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, temp &= ~(I2CR_MSTA | I2CR_MTX); imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); if (!i2c_imx->stopped) - i2c_imx_bus_busy(i2c_imx, 0, atomic); + i2c_imx_bus_busy(i2c_imx, 0, true); } else { /* * For i2c master receiver repeat restart operation like: @@ -1257,10 +1437,43 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, return 0; } -static int i2c_imx_atomic_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, +static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bool is_lastmsg) { - return i2c_imx_read(i2c_imx, msgs, is_lastmsg, true); + int block_data = msgs->flags & I2C_M_RECV_LEN; + + dev_dbg(&i2c_imx->adapter.dev, + "<%s> write slave address: addr=0x%x\n", + __func__, i2c_8bit_addr_from_msg(msgs)); + + i2c_imx->is_lastmsg = is_lastmsg; + + if (block_data) + i2c_imx->state = IMX_I2C_STATE_READ_BLOCK_DATA; + else + i2c_imx->state = IMX_I2C_STATE_READ; + i2c_imx->msg = msgs; + i2c_imx->msg_buf_idx = 0; + + /* write slave address */ + imx_i2c_write_reg(i2c_8bit_addr_from_msg(msgs), i2c_imx, IMX_I2C_I2DR); + wait_event_timeout(i2c_imx->queue, + i2c_imx->state == IMX_I2C_STATE_DONE || + i2c_imx->state == IMX_I2C_STATE_FAILED, + (msgs->len + 1)*HZ / 10); + if (i2c_imx->state == IMX_I2C_STATE_FAILED) { + dev_err(&i2c_imx->adapter.dev, "<%s> write failed with %d\n", + __func__, i2c_imx->isr_result); + return i2c_imx->isr_result; + } + if (i2c_imx->state != IMX_I2C_STATE_DONE) { + dev_err(&i2c_imx->adapter.dev, "<%s> write timedout\n", __func__); + return -ETIMEDOUT; + } + if (!i2c_imx->stopped) + return i2c_imx_bus_busy(i2c_imx, 0, false); + + return 0; } static int i2c_imx_xfer_common(struct i2c_adapter *adapter, @@ -1334,14 +1547,14 @@ static int i2c_imx_xfer_common(struct i2c_adapter *adapter, else if (use_dma && !block_data) result = i2c_imx_dma_read(i2c_imx, &msgs[i], is_lastmsg); else - result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg, false); + result = i2c_imx_read(i2c_imx, &msgs[i], is_lastmsg); } else { if (atomic) result = i2c_imx_atomic_write(i2c_imx, &msgs[i]); else if (use_dma) result = i2c_imx_dma_write(i2c_imx, &msgs[i]); else - result = i2c_imx_write(i2c_imx, &msgs[i], false); + result = i2c_imx_write(i2c_imx, &msgs[i]); } if (result) goto fail0; -- 2.43.0 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode 2024-08-19 7:19 ` [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode Stefan Eichenberger @ 2024-08-30 8:13 ` Oleksij Rempel 0 siblings, 0 replies; 26+ messages in thread From: Oleksij Rempel @ 2024-08-30 8:13 UTC (permalink / raw) To: Stefan Eichenberger Cc: kernel, andi.shyti, shawnguo, s.hauer, festevam, Frank.Li, francesco.dolcini, linux-i2c, imx, linux-arm-kernel, linux-kernel, Stefan Eichenberger On Mon, Aug 19, 2024 at 09:19:10AM +0200, Stefan Eichenberger wrote: > From: Stefan Eichenberger <stefan.eichenberger@toradex.com> > > We are experiencing a problem with the i.MX I2C controller when > communicating with SMBus devices. We are seeing devices time-out because > the time between sending/receiving two bytes is too long, and the SMBus > device returns to the idle state. This happens because the i.MX I2C > controller sends and receives byte by byte. When a byte is sent or > received, we get an interrupt and can send or receive the next byte. > > The current implementation sends a byte and then waits for an event > generated by the interrupt subroutine. After the event is received, the > next byte is sent and we wait again. This waiting allows the scheduler > to reschedule other tasks, with the disadvantage that we may not send > the next byte for a long time because the send task is not immediately > scheduled. For example, if the rescheduling takes more than 25ms, this > can cause SMBus devices to timeout and communication to fail. > > This patch changes the behavior so that we do not reschedule the > send/receive task, but instead send or receive the next byte in the > interrupt subroutine. This prevents rescheduling and drastically reduces > the time between sending/receiving bytes. The cost in the interrupt > subroutine is relatively small, we check what state we are in and then > send/receive the next byte. Before we had to call wake_up, which is even > less expensive. However, we also had to do some scheduling, which > increased the overall cost compared to the new solution. The wake_up > function to wake up the send/receive task is now only called when an > error occurs or when the transfer is complete. > > Signed-off-by: Stefan Eichenberger <stefan.eichenberger@toradex.com> Acked-by: Oleksij Rempel <o.rempel@pengutronix.de> -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | ^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2024-08-30 8:14 UTC | newest] Thread overview: 26+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-19 7:19 [PATCH v2 0/4] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 1/4] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger 2024-08-21 11:01 ` Fabio Estevam 2024-08-21 14:39 ` Oleksij Rempel 2024-08-21 15:23 ` Stefan Eichenberger 2024-08-21 16:43 ` Fabio Estevam 2024-08-21 22:31 ` Andi Shyti 2024-08-22 6:51 ` Oleksij Rempel 2024-08-22 11:07 ` Fabio Estevam 2024-08-22 11:50 ` Stefan Eichenberger 2024-08-22 12:59 ` Fabio Estevam 2024-08-23 13:43 ` Stefan Eichenberger 2024-08-21 22:21 ` Andi Shyti 2024-08-22 7:03 ` Stefan Eichenberger 2024-08-22 10:04 ` Oleksij Rempel 2024-08-22 12:03 ` Stefan Eichenberger 2024-08-23 0:35 ` Andi Shyti 2024-08-23 13:48 ` Stefan Eichenberger 2024-08-23 14:04 ` Oleksij Rempel 2024-08-23 14:42 ` Stefan Eichenberger 2024-08-19 7:19 ` [PATCH v2 2/4] i2c: imx: separate atomic, dma and non-dma use case Stefan Eichenberger 2024-08-30 7:31 ` Oleksij Rempel 2024-08-19 7:19 ` [PATCH v2 3/4] i2c: imx: use readb_relaxed and writeb_relaxed Stefan Eichenberger 2024-08-30 7:37 ` Oleksij Rempel 2024-08-19 7:19 ` [PATCH v2 4/4] i2c: imx: prevent rescheduling in non dma mode Stefan Eichenberger 2024-08-30 8:13 ` Oleksij Rempel
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).