Commit 8b983e90 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Mark Brown

spi: rspi: Extract rspi_common_transfer()

Extract the common parts of rspi_transfer_one(), rspi_rz_transfer_one(),
and qspi_transfer_out_in() into the new function rspi_common_transfer().
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent e7fb921d
...@@ -586,25 +586,16 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, ...@@ -586,25 +586,16 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi,
return __rspi_can_dma(rspi, xfer); return __rspi_can_dma(rspi, xfer);
} }
static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, static int rspi_common_transfer(struct rspi_data *rspi,
struct spi_transfer *xfer) struct spi_transfer *xfer)
{ {
struct rspi_data *rspi = spi_master_get_devdata(master);
u8 spcr;
int ret; int ret;
spcr = rspi_read8(rspi, RSPI_SPCR); if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) {
if (xfer->rx_buf) { /* rx_buf can be NULL on RSPI on SH in TX-only Mode */
rspi_receive_init(rspi);
spcr &= ~SPCR_TXMD;
} else {
spcr |= SPCR_TXMD;
}
rspi_write8(rspi, spcr, RSPI_SPCR);
if (master->can_dma && __rspi_can_dma(rspi, xfer))
return rspi_dma_transfer(rspi, &xfer->tx_sg, return rspi_dma_transfer(rspi, &xfer->tx_sg,
xfer->rx_buf ? &xfer->rx_sg : NULL); xfer->rx_buf ? &xfer->rx_sg : NULL);
}
ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len);
if (ret < 0) if (ret < 0)
...@@ -616,6 +607,24 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, ...@@ -616,6 +607,24 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi,
return 0; return 0;
} }
static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi,
struct spi_transfer *xfer)
{
struct rspi_data *rspi = spi_master_get_devdata(master);
u8 spcr;
spcr = rspi_read8(rspi, RSPI_SPCR);
if (xfer->rx_buf) {
rspi_receive_init(rspi);
spcr &= ~SPCR_TXMD;
} else {
spcr |= SPCR_TXMD;
}
rspi_write8(rspi, spcr, RSPI_SPCR);
return rspi_common_transfer(rspi, xfer);
}
static int rspi_rz_transfer_one(struct spi_master *master, static int rspi_rz_transfer_one(struct spi_master *master,
struct spi_device *spi, struct spi_device *spi,
struct spi_transfer *xfer) struct spi_transfer *xfer)
...@@ -625,37 +634,15 @@ static int rspi_rz_transfer_one(struct spi_master *master, ...@@ -625,37 +634,15 @@ static int rspi_rz_transfer_one(struct spi_master *master,
rspi_rz_receive_init(rspi); rspi_rz_receive_init(rspi);
if (master->can_dma && __rspi_can_dma(rspi, xfer)) return rspi_common_transfer(rspi, xfer);
return rspi_dma_transfer(rspi, &xfer->tx_sg, &xfer->rx_sg);
ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len);
if (ret < 0)
return ret;
/* Wait for the last transmission */
rspi_wait_for_tx_empty(rspi);
return 0;
} }
static int qspi_transfer_out_in(struct rspi_data *rspi, static int qspi_transfer_out_in(struct rspi_data *rspi,
struct spi_transfer *xfer) struct spi_transfer *xfer)
{ {
int ret;
qspi_receive_init(rspi); qspi_receive_init(rspi);
if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) return rspi_common_transfer(rspi, xfer);
return rspi_dma_transfer(rspi, &xfer->tx_sg, &xfer->rx_sg);
ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len);
if (ret < 0)
return ret;
/* Wait for the last transmission */
rspi_wait_for_tx_empty(rspi);
return 0;
} }
static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment