Skip to content

Commit bcd8e77

Browse files
Robin Gongbroonie
authored andcommitted
spi: imx: fallback to PIO if dma setup failure
Fallback to PIO in case dma setup failed. For example, sdma firmware not updated but ERR009165 workaroud added in kernel. Signed-off-by: Robin Gong <[email protected]> Acked-by: Sascha Hauer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8d72880 commit bcd8e77

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

drivers/spi/spi-imx.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct spi_imx_devtype_data {
7171
void (*reset)(struct spi_imx_data *);
7272
void (*setup_wml)(struct spi_imx_data *);
7373
void (*disable)(struct spi_imx_data *);
74+
void (*disable_dma)(struct spi_imx_data *);
7475
bool has_dmamode;
7576
bool has_slavemode;
7677
unsigned int fifo_size;
@@ -485,6 +486,11 @@ static void mx51_ecspi_trigger(struct spi_imx_data *spi_imx)
485486
writel(reg, spi_imx->base + MX51_ECSPI_CTRL);
486487
}
487488

489+
static void mx51_disable_dma(struct spi_imx_data *spi_imx)
490+
{
491+
writel(0, spi_imx->base + MX51_ECSPI_DMA);
492+
}
493+
488494
static void mx51_ecspi_disable(struct spi_imx_data *spi_imx)
489495
{
490496
u32 ctrl;
@@ -987,6 +993,7 @@ static struct spi_imx_devtype_data imx51_ecspi_devtype_data = {
987993
.rx_available = mx51_ecspi_rx_available,
988994
.reset = mx51_ecspi_reset,
989995
.setup_wml = mx51_setup_wml,
996+
.disable_dma = mx51_disable_dma,
990997
.fifo_size = 64,
991998
.has_dmamode = true,
992999
.dynamic_burst = true,
@@ -1001,6 +1008,7 @@ static struct spi_imx_devtype_data imx53_ecspi_devtype_data = {
10011008
.prepare_transfer = mx51_ecspi_prepare_transfer,
10021009
.trigger = mx51_ecspi_trigger,
10031010
.rx_available = mx51_ecspi_rx_available,
1011+
.disable_dma = mx51_disable_dma,
10041012
.reset = mx51_ecspi_reset,
10051013
.fifo_size = 64,
10061014
.has_dmamode = true,
@@ -1385,6 +1393,7 @@ static int spi_imx_dma_transfer(struct spi_imx_data *spi_imx,
13851393
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
13861394
if (!desc_tx) {
13871395
dmaengine_terminate_all(master->dma_tx);
1396+
dmaengine_terminate_all(master->dma_rx);
13881397
return -EINVAL;
13891398
}
13901399

@@ -1498,6 +1507,7 @@ static int spi_imx_transfer(struct spi_device *spi,
14981507
struct spi_transfer *transfer)
14991508
{
15001509
struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
1510+
int ret;
15011511

15021512
/* flush rxfifo before transfer */
15031513
while (spi_imx->devtype_data->rx_available(spi_imx))
@@ -1506,10 +1516,23 @@ static int spi_imx_transfer(struct spi_device *spi,
15061516
if (spi_imx->slave_mode)
15071517
return spi_imx_pio_transfer_slave(spi, transfer);
15081518

1509-
if (spi_imx->usedma)
1510-
return spi_imx_dma_transfer(spi_imx, transfer);
1511-
else
1512-
return spi_imx_pio_transfer(spi, transfer);
1519+
/*
1520+
* fallback PIO mode if dma setup error happen, for example sdma
1521+
* firmware may not be updated as ERR009165 required.
1522+
*/
1523+
if (spi_imx->usedma) {
1524+
ret = spi_imx_dma_transfer(spi_imx, transfer);
1525+
if (ret != -EINVAL)
1526+
return ret;
1527+
1528+
spi_imx->devtype_data->disable_dma(spi_imx);
1529+
1530+
spi_imx->usedma = false;
1531+
spi_imx->dynamic_burst = spi_imx->devtype_data->dynamic_burst;
1532+
dev_dbg(&spi->dev, "Fallback to PIO mode\n");
1533+
}
1534+
1535+
return spi_imx_pio_transfer(spi, transfer);
15131536
}
15141537

15151538
static int spi_imx_setup(struct spi_device *spi)

0 commit comments

Comments
 (0)