Skip to content

Commit bfddd34

Browse files
james-c-linarobroonie
authored andcommitted
spi: fsl-dspi: Avoid using -EINPROGRESS error code
Refactor dspi_rxtx() and dspi_poll() to not return -EINPROGRESS because this isn't actually a status that is ever returned to the core layer but some internal state. Use true/false return value on dspi_rxtx() for this instead. This will help separate internal vs external status for the later change to store the external status directly in cur_msg->status. No functional changes intended. Co-developed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: James Clark <james.clark@linaro.org> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Message-ID: <20250902-james-nxp-spi-dma-v6-1-f7aa2c5e56e2@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 431f6c8 commit bfddd34

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

drivers/spi/spi-fsl-dspi.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -986,36 +986,45 @@ static void dspi_fifo_write(struct fsl_dspi *dspi)
986986
dspi->progress, !dspi->irq);
987987
}
988988

989-
static int dspi_rxtx(struct fsl_dspi *dspi)
989+
/*
990+
* Read the previous transfer from the FIFO and transmit the next one.
991+
*
992+
* Returns false if the buffer to be transmitted is empty, and true if there is
993+
* still data to transmit.
994+
*/
995+
static bool dspi_rxtx(struct fsl_dspi *dspi)
990996
{
991997
dspi_fifo_read(dspi);
992998

993999
if (!dspi->len)
9941000
/* Success! */
995-
return 0;
1001+
return false;
9961002

9971003
dspi_fifo_write(dspi);
9981004

999-
return -EINPROGRESS;
1005+
return true;
10001006
}
10011007

10021008
static int dspi_poll(struct fsl_dspi *dspi)
10031009
{
1004-
int tries = 1000;
1010+
int tries;
1011+
int err = 0;
10051012
u32 spi_sr;
10061013

10071014
do {
1008-
regmap_read(dspi->regmap, SPI_SR, &spi_sr);
1009-
regmap_write(dspi->regmap, SPI_SR, spi_sr);
1010-
1011-
if (spi_sr & SPI_SR_CMDTCF)
1015+
for (tries = 1000; tries > 0; --tries) {
1016+
regmap_read(dspi->regmap, SPI_SR, &spi_sr);
1017+
regmap_write(dspi->regmap, SPI_SR, spi_sr);
1018+
if (spi_sr & SPI_SR_CMDTCF)
1019+
break;
1020+
}
1021+
if (!tries) {
1022+
err = -ETIMEDOUT;
10121023
break;
1013-
} while (--tries);
1014-
1015-
if (!tries)
1016-
return -ETIMEDOUT;
1024+
}
1025+
} while (dspi_rxtx(dspi));
10171026

1018-
return dspi_rxtx(dspi);
1027+
return err;
10191028
}
10201029

10211030
static irqreturn_t dspi_interrupt(int irq, void *dev_id)
@@ -1029,7 +1038,7 @@ static irqreturn_t dspi_interrupt(int irq, void *dev_id)
10291038
if (!(spi_sr & SPI_SR_CMDTCF))
10301039
return IRQ_NONE;
10311040

1032-
if (dspi_rxtx(dspi) == 0)
1041+
if (dspi_rxtx(dspi) == false)
10331042
complete(&dspi->xfer_done);
10341043

10351044
return IRQ_HANDLED;
@@ -1137,9 +1146,7 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr,
11371146
if (dspi->irq) {
11381147
wait_for_completion(&dspi->xfer_done);
11391148
} else {
1140-
do {
1141-
status = dspi_poll(dspi);
1142-
} while (status == -EINPROGRESS);
1149+
status = dspi_poll(dspi);
11431150
}
11441151
}
11451152
if (status)

0 commit comments

Comments
 (0)