i2c: imx: Fix and enable DMA support for LS1021A
Subsystems (4)
v4 cover i2c: imx: Fix and enable DMA support for LS1021A
From: Esben Haabendal <[email protected]>
This patch series fixes two race conditions and minor issues with tracking the stopped state when something goes wrong.
With that in place, DMA support works with NXP LS1021A, so it is enabled in the last patch.
Changes in v4:
* Added condition checking by use of common use_dma variable in patch 1/3
* Added Acked-by for patches 1/3 and 2/3
* Rebased to v4.18
Changes in v3:
* Rebased to v4.18-rc8, dropping patch 1/4 which have been merged
* Avoid unnecessary register write in patch 2/3
* Removed unneeded braces in patch 3/3
Changes in v2:
* Fixed speling mistake in commit message
* Rebased to v4.18-rc4
Esben Haabendal (3):
i2c: imx: Fix race condition in dma read
i2c: imx: Simplify stopped state tracking
arm: dts: ls1021a: Enable I2C DMA support
arch/arm/boot/dts/ls1021a.dtsi | 6 ++++++ drivers/i2c/busses/i2c-imx.c | 23 +++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-)
Signature · 1 line
2.18.0
PATCH v4 1/3 i2c: imx: Fix race condition in dma read
From: Esben Haabendal <[email protected]>
This fixes a race condition, where the DMAEN bit ends up being set after I2C slave has transmitted a byte following the dummy read. When that happens, an interrupt is generated instead, and no DMA request is generated to kickstart the DMA read, and a timeout happens after DMA_TIMEOUT (1 sec).
Fixed by setting the DMAEN bit before the dummy read.
--- drivers/i2c/busses/i2c-imx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx.c +4 -4
@@ -668,9 +668,6 @@ 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; - temp =imx_i2c_read_reg (i2c_imx,IMX_I2C_I2CR ); - temp |=I2CR_DMAEN ; -imx_i2c_write_reg (temp, i2c_imx,IMX_I2C_I2CR ); dma->chan_using = dma->chan_rx; dma->dma_transfer_dir =DMA_DEV_TO_MEM ;
@@ -783,6 +780,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, boint i, result;unsigned int temp;int block_data = msgs->flags &I2C_M_RECV_LEN ; +int use_dma = i2c_imx->dma && msgs->len >=DMA_THRESHOLD && !block_data; dev_dbg(&i2c_imx->adapter.dev, "<%s> write slave address: addr=0x%x\n",
@@ -809,12 +807,14 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo*/ 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 (i2c_imx->dma && msgs->len >=DMA_THRESHOLD && !block_data) +if (use_dma)return i2c_imx_dma_read (i2c_imx, msgs, is_lastmsg);/* read data */
Signature · 1 line
2.18.0
PATCH v4 2/3 i2c: imx: Simplify stopped state tracking
In reply to Esben HaabendalFrom: Esben Haabendal <[email protected]>
Always update the stopped state when busy status have been checked. This is identical to what was done before, with the exception of error handling.
Without this change, some errors cause the stopped state to be left in incorrect state in i2c_imx_stop(), i2c_imx_dma_read(), i2c_imx_read() and i2c_imx_xfer().
--- drivers/i2c/busses/i2c-imx.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/i2c/busses/i2c-imx.c +7 -8
@@ -421,10 +421,14 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)return -EAGAIN ; } -if (for_busy && (temp &I2SR_IBB )) +if (for_busy && (temp &I2SR_IBB )) { + i2c_imx->stopped =0 ;break ; -if (!for_busy && !(temp &I2SR_IBB )) + } +if (!for_busy && !(temp &I2SR_IBB )) { + i2c_imx->stopped =1 ;break ; + }if (time_after (jiffies, orig_jiffies +msecs_to_jiffies (500 ))) {dev_dbg (&i2c_imx->adapter.dev,"<%s> I2C bus is busy\n" , __func__);
@@ -538,7 +542,6 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) result =i2c_imx_bus_busy (i2c_imx,1 );if (result)return result; - i2c_imx->stopped =0 ; temp |=I2CR_IIEN |I2CR_MTX |I2CR_TXAK ; temp &= ~I2CR_DMAEN ;
@@ -567,10 +570,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)udelay (i2c_imx->disable_delay); } -if (!i2c_imx->stopped) { +if (!i2c_imx->stopped)i2c_imx_bus_busy (i2c_imx,0 ); - i2c_imx->stopped =1 ; - }/* Disable I2C controller */ temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
@@ -724,7 +725,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx, temp &= ~(I2CR_MSTA |I2CR_MTX );imx_i2c_write_reg (temp, i2c_imx,IMX_I2C_I2CR );i2c_imx_bus_busy (i2c_imx,0 ); - i2c_imx->stopped =1 ; }else {/* * For i2c master receiver repeat restart operation like:
@@ -850,7 +850,6 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo temp &= ~(I2CR_MSTA |I2CR_MTX );imx_i2c_write_reg (temp, i2c_imx,IMX_I2C_I2CR );i2c_imx_bus_busy (i2c_imx,0 ); - i2c_imx->stopped =1 ; }else {/* * For i2c master receiver repeat restart operation like:
Signature · 1 line
2.18.0
PATCH v4 3/3 arm: dts: ls1021a: Enable I2C DMA support
In reply to Esben HaabendalFrom: Esben Haabendal <[email protected]>
Gives substantial performance improvement for transfers larger than 16 bytes (DMA_THRESHOLD). Smaller transfers are unaffected.
--- arch/arm/boot/dts/ls1021a.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/boot/dts/ls1021a.dtsi +6 -0
@@ -363,6 +363,8 @@ interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_HIGH>; clock-names = "i2c"; clocks = <&clockgen 4 1>; + dma-names = "tx", "rx"; + dmas = <&edma0 1 39>, <&edma0 1 38>; status = "disabled"; };
@@ -374,6 +376,8 @@ interrupts = <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>; clock-names = "i2c"; clocks = <&clockgen 4 1>; + dma-names = "tx", "rx"; + dmas = <&edma0 1 37>, <&edma0 1 36>; status = "disabled"; };
@@ -385,6 +389,8 @@ interrupts = <GIC_SPI 90 IRQ_TYPE_LEVEL_HIGH>; clock-names = "i2c"; clocks = <&clockgen 4 1>; + dma-names = "tx", "rx"; + dmas = <&edma0 1 35>, <&edma0 1 34>; status = "disabled"; };
Signature · 1 line
2.18.0
Re: [PATCH v4 3/3] arm: dts: ls1021a: Enable I2C DMA support
Quoted 6 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
Gives substantial performance improvement for transfers larger than 16 bytes (
DMA_THRESHOLD). Smaller transfers are unaffected.Signed-off-by Esben Haabendal <[email protected]>
Looks reasonable to me.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Wolfram Sang
AppliedRe: [PATCH v4 1/3] i2c: imx: Fix race condition in dma read
In reply to Esben HaabendalQuoted 11 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
This fixes a race condition, where the DMAEN bit ends up being set after I2C slave has transmitted a byte following the dummy read. When that happens, an interrupt is generated instead, and no DMA request is generated to kickstart the DMA read, and a timeout happens after
DMA_TIMEOUT(1 sec).Fixed by setting the DMAEN bit before the dummy read.
Signed-off-by Esben Haabendal <[email protected]>Acked-by Uwe Kleine-König <[email protected]>
Applied to for-next and added stable, thanks!
Wolfram Sang
AppliedRe: [PATCH v4 2/3] i2c: imx: Simplify stopped state tracking
In reply to Esben HaabendalQuoted 11 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
Always update the stopped state when busy status have been checked. This is identical to what was done before, with the exception of error handling.
Without this change, some errors cause the stopped state to be left in incorrect state ini2c_imx_stop(),i2c_imx_dma_read(),i2c_imx_read()andi2c_imx_xfer().Signed-off-by Esben Haabendal <[email protected]>Acked-by Uwe Kleine-König <[email protected]>
Applied to for-next, thanks! I did not add stable because the cover latter said minor issue? Not really sure here, though...
Re: [PATCH v4 3/3] arm: dts: ls1021a: Enable I2C DMA support
In reply to Esben HaabendalQuoted 6 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
Gives substantial performance improvement for transfers larger than 16 bytes (
DMA_THRESHOLD). Smaller transfers are unaffected.Signed-off-by Esben Haabendal <[email protected]>
This needs to go via arm-soc. The two other patches will be in v4.19 with my pull request later this week.
Re: [PATCH v4 2/3] i2c: imx: Simplify stopped state tracking
In reply to Wolfram SangQuoted 10 lines · Wolfram Sang
Quoted 9 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
Always update the stopped state when busy status have been checked. This is identical to what was done before, with the exception of error handling.
Without this change, some errors cause the stopped state to be left in incorrect state ini2c_imx_stop(),i2c_imx_dma_read(),i2c_imx_read()andi2c_imx_xfer().
Quoted 5 lines
Quoted 2 lines
Signed-off-by Esben Haabendal <[email protected]>Acked-by Uwe Kleine-König <[email protected]>Applied to for-next, thanks! I did not add stable because the cover latter said minor issue? Not really sure here, though...
I agree, it does not need to go into stable.
/Esben
Re: [PATCH v4 3/3] arm: dts: ls1021a: Enable I2C DMA support
In reply to Wolfram SangQuoted 10 lines · Wolfram Sang
Quoted 6 lines · Esben Haabendal
From: Esben Haabendal <[email protected]>
Gives substantial performance improvement for transfers larger than 16 bytes (
DMA_THRESHOLD). Smaller transfers are unaffected.Signed-off-by Esben Haabendal <[email protected]>This needs to go via arm-soc. The two other patches will be in v4.19 with my pull request later this week.
Ok, do I need to send to additional list(s)?
[email protected]?
/Esben
Re: [PATCH v4 3/3] arm: dts: ls1021a: Enable I2C DMA support
Quoted 3 lines
Ok, do I need to send to additional list(s)?
[email protected]?
I'd say resend this patch after rc1 is out and the other 2 patches are upstream.