RE: Issues with i.MX SPI DMA transfers

Robin Gong
2019-03-28T09:23:48Z

[-- Attachment #1: Type: text/plain, Size: 2024 bytes --]

Hi Igor,
Please have a try with the attached patch, assume you have already used the sdma firmware
From https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/imx/sdma/sdma-imx6q.bin
> -----Original Message-----
> From: Igor Plyatov <plyatov@gmail.com>
> Sent: 2019年3月28日 15:04
> To: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Cc: linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> linux-spi@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>; Fabio Estevam
> <festevam@gmail.com>; Pengutronix Kernel Team <kernel@pengutronix.de>;
> Sascha Hauer <s.hauer@pengutronix.de>; Shawn Guo
> <shawnguo@kernel.org>; Mark Brown <broonie@kernel.org>;
> dmaengine@vger.kernel.org; Vinod Koul <vkoul@kernel.org>; Dan Williams
> <dan.j.williams@intel.com>; Andy Duan <fugang.duan@nxp.com>; Han Xu
> <han.xu@nxp.com>; Robin Gong <yibin.gong@nxp.com>; Clark Wang
> <xiaoning.wang@nxp.com>
> Subject: Re: Issues with i.MX SPI DMA transfers
>
> Dear Uwe,
>
>
> > Hello Igor,
> >
> > On Wed, Mar 27, 2019 at 08:40:00PM +0300, Igor Plyatov wrote:
> >> please, help to resolve two issues with SPI DMA transfers at i.MX6Q
> >> platform.
> >>
> >> First issue is
> >>  [ 4465.008003] spi_master spi0: I/O Error in DMA RX
> >>
> >> Second issue is duplication for one of received bytes.
> >>
> >> Probably, these issues related to each one.
> > This is probably the same problem I hit some time ago. Check ERR009165
> > in the errata. You either need to disable DMA or need a fixed
> > sdma-Script.
>
> disabling of DMA is not an option, because high throughput required for SPI bus
> to communicate with DSPs.
>
> I'm aware of ERR009165, but as I write some minutes earlier to list,
> spi0 (alias for ecspi1) and spi1 (alias for ecspi2) work flawless, while
> spi4 (alias for ecspi5) fails very fast.
>
> Does same SDMA script used for all SPI interfaces or scripts are different?
>
> Best wishes.
>
> --
>
> Igor Plyatov

[-- Attachment #2: 0001-dma-engine-imx-sdma-add-mcu_2_ecspi-script.patch --]
[-- Type: application/octet-stream, Size: 1369 bytes --]

From cedd7aece6a3566f61e39cbee9ceeaea3f34cfd1 Mon Sep 17 00:00:00 2001
From: Robin Gong <yibin.gong@nxp.com>
Date: Thu, 28 Mar 2019 16:36:12 +0800
Subject: [PATCH 1/2] dma: engine: imx-sdma: add mcu_2_ecspi script

Add mcu_2_ecspi script to fix ecspi errata ERR009165.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
drivers/dma/imx-sdma.c | 3 +++
include/linux/platform_data/dma-imx-sdma.h | 1 +
2 files changed, 4 insertions(+)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 7fae4bf..1f1ce7c 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -908,6 +908,9 @@ static void sdma_get_pc(struct sdma_channel *sdmac,
emi_2_per = sdma->script_addrs->mcu_2_ata_addr;
break;
case IMX_DMATYPE_CSPI:
+ per_2_emi = sdma->script_addrs->app_2_mcu_addr;
+ emi_2_per = sdma->script_addrs->mcu_2_ecspi_addr;
+ break;
case IMX_DMATYPE_EXT:
case IMX_DMATYPE_SSI:
case IMX_DMATYPE_SAI:
diff --git a/include/linux/platform_data/dma-imx-sdma.h b/include/linux/platform_data/dma-imx-sdma.h
index 6eaa53c..f794fee 100644
--- a/include/linux/platform_data/dma-imx-sdma.h
+++ b/include/linux/platform_data/dma-imx-sdma.h
@@ -51,6 +51,7 @@ struct sdma_script_start_addrs {
/* End of v2 array */
s32 zcanfd_2_mcu_addr;
s32 zqspi_2_mcu_addr;
+ s32 mcu_2_ecspi_addr;
/* End of v3 array */
};

--
2.7.4

[-- Attachment #3: 0002-spi-spi-imx-fix-ERR009165.patch --]
[-- Type: application/octet-stream, Size: 1280 bytes --]

From d3fa24b37adcfb385a6e60b414d7485a52951aca Mon Sep 17 00:00:00 2001
From: Robin Gong <yibin.gong@nxp.com>
Date: Thu, 28 Mar 2019 16:38:13 +0800
Subject: [PATCH 2/2] spi: spi-imx: fix ERR009165

Change to XCH mode even in dma mode, please refer to below
errata:
https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
drivers/spi/spi-imx.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 09c9a1e..2757815 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -585,8 +585,9 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
ctrl |= mx51_ecspi_clkdiv(spi_imx, t->speed_hz, &clk);
spi_imx->spi_bus_clk = clk;

+ /* ERR009165: work in XHC mode as PIO */
if (spi_imx->usedma)
- ctrl |= MX51_ECSPI_CTRL_SMC;
+ ctrl &= ~MX51_ECSPI_CTRL_SMC;

writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);

@@ -1265,10 +1266,6 @@ static int spi_imx_sdma_init(struct device *dev, struct spi_imx_data *spi_imx,
{
int ret;

- /* use pio mode for i.mx6dl chip TKT238285 */
- if (of_machine_is_compatible("fsl,imx6dl"))
- return 0;
-
spi_imx->wml = spi_imx->devtype_data->fifo_size / 2;

/* Prepare for TX DMA: */
--
2.7.4