Commit 32e13575 authored by Mark Brown's avatar Mark Brown

spi: more tx_buf/rx_buf removal

Merge series from David Lechner <dlechner@baylibre.com>:

I found a couple more controller drivers that were checking if the
tx_buf and rx_buf fields in the spi_transfer structure were set by a
peripheral driver that I missed in [1]. These checks can be removed
as well.

[1]: https://lore.kernel.org/linux-spi/20240325-spi-remove-is_dma_mapped-v2-1-d08d62b61f1c@baylibre.com/
parents 09f347cd 64fe73d1
...@@ -314,11 +314,8 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t) ...@@ -314,11 +314,8 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
hw->tx = t->tx_buf; hw->tx = t->tx_buf;
hw->rx = t->rx_buf; hw->rx = t->rx_buf;
dma_tx_addr = t->tx_dma;
dma_rx_addr = t->rx_dma;
/* /*
* check if buffers are already dma mapped, map them otherwise:
* - first map the TX buffer, so cache data gets written to memory * - first map the TX buffer, so cache data gets written to memory
* - then map the RX buffer, so that cache entries (with * - then map the RX buffer, so that cache entries (with
* soon-to-be-stale data) get removed * soon-to-be-stale data) get removed
...@@ -326,23 +323,17 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t) ...@@ -326,23 +323,17 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
* use temp rx buffer (preallocated or realloc to fit) for rx dma * use temp rx buffer (preallocated or realloc to fit) for rx dma
*/ */
if (t->tx_buf) { if (t->tx_buf) {
if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ dma_tx_addr = dma_map_single(hw->dev, (void *)t->tx_buf,
dma_tx_addr = dma_map_single(hw->dev,
(void *)t->tx_buf,
t->len, DMA_TO_DEVICE); t->len, DMA_TO_DEVICE);
if (dma_mapping_error(hw->dev, dma_tx_addr)) if (dma_mapping_error(hw->dev, dma_tx_addr))
dev_err(hw->dev, "tx dma map error\n"); dev_err(hw->dev, "tx dma map error\n");
} }
}
if (t->rx_buf) { if (t->rx_buf) {
if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ dma_rx_addr = dma_map_single(hw->dev, (void *)t->rx_buf,
dma_rx_addr = dma_map_single(hw->dev,
(void *)t->rx_buf,
t->len, DMA_FROM_DEVICE); t->len, DMA_FROM_DEVICE);
if (dma_mapping_error(hw->dev, dma_rx_addr)) if (dma_mapping_error(hw->dev, dma_rx_addr))
dev_err(hw->dev, "rx dma map error\n"); dev_err(hw->dev, "rx dma map error\n");
}
} else { } else {
if (t->len > hw->dma_rx_tmpbuf_size) { if (t->len > hw->dma_rx_tmpbuf_size) {
int ret; int ret;
...@@ -398,10 +389,10 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t) ...@@ -398,10 +389,10 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
} }
/* unmap buffers if mapped above */ /* unmap buffers if mapped above */
if (t->rx_buf && t->rx_dma == 0) if (t->rx_buf)
dma_unmap_single(hw->dev, dma_rx_addr, t->len, dma_unmap_single(hw->dev, dma_rx_addr, t->len,
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
if (t->tx_buf && t->tx_dma == 0) if (t->tx_buf)
dma_unmap_single(hw->dev, dma_tx_addr, t->len, dma_unmap_single(hw->dev, dma_tx_addr, t->len,
DMA_TO_DEVICE); DMA_TO_DEVICE);
......
...@@ -98,19 +98,13 @@ static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi) ...@@ -98,19 +98,13 @@ static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi)
mpc8xxx_spi_write_reg(&reg_base->command, SPCOM_STR); mpc8xxx_spi_write_reg(&reg_base->command, SPCOM_STR);
} }
int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, struct spi_transfer *t)
struct spi_transfer *t, bool is_dma_mapped)
{ {
struct device *dev = mspi->dev; struct device *dev = mspi->dev;
struct fsl_spi_reg __iomem *reg_base = mspi->reg_base; struct fsl_spi_reg __iomem *reg_base = mspi->reg_base;
if (is_dma_mapped) {
mspi->map_tx_dma = 0;
mspi->map_rx_dma = 0;
} else {
mspi->map_tx_dma = 1; mspi->map_tx_dma = 1;
mspi->map_rx_dma = 1; mspi->map_rx_dma = 1;
}
if (!t->tx_buf) { if (!t->tx_buf) {
mspi->tx_dma = mspi->dma_dummy_tx; mspi->tx_dma = mspi->dma_dummy_tx;
...@@ -147,7 +141,7 @@ int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, ...@@ -147,7 +141,7 @@ int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
return -ENOMEM; return -ENOMEM;
} }
} else if (t->tx_buf) { } else if (t->tx_buf) {
mspi->tx_dma = t->tx_dma; mspi->tx_dma = 0;
} }
if (mspi->map_rx_dma) { if (mspi->map_rx_dma) {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#ifdef CONFIG_FSL_SOC #ifdef CONFIG_FSL_SOC
extern void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi); extern void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi);
extern int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, extern int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
struct spi_transfer *t, bool is_dma_mapped); struct spi_transfer *t);
extern void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi); extern void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi);
extern void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events); extern void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events);
extern int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi); extern int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi);
...@@ -28,8 +28,7 @@ extern void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi); ...@@ -28,8 +28,7 @@ extern void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi);
#else #else
static inline void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi) { } static inline void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi) { }
static inline int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, static inline int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
struct spi_transfer *t, struct spi_transfer *t) { return 0; }
bool is_dma_mapped) { return 0; }
static inline void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) { } static inline void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) { }
static inline void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) { } static inline void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) { }
static inline int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) { return 0; } static inline int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) { return 0; }
......
...@@ -249,8 +249,7 @@ static int fsl_spi_cpu_bufs(struct mpc8xxx_spi *mspi, ...@@ -249,8 +249,7 @@ static int fsl_spi_cpu_bufs(struct mpc8xxx_spi *mspi,
return 0; return 0;
} }
static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
bool is_dma_mapped)
{ {
struct mpc8xxx_spi *mpc8xxx_spi = spi_controller_get_devdata(spi->controller); struct mpc8xxx_spi *mpc8xxx_spi = spi_controller_get_devdata(spi->controller);
struct fsl_spi_reg __iomem *reg_base; struct fsl_spi_reg __iomem *reg_base;
...@@ -274,7 +273,7 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, ...@@ -274,7 +273,7 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t,
reinit_completion(&mpc8xxx_spi->done); reinit_completion(&mpc8xxx_spi->done);
if (mpc8xxx_spi->flags & SPI_CPM_MODE) if (mpc8xxx_spi->flags & SPI_CPM_MODE)
ret = fsl_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped); ret = fsl_spi_cpm_bufs(mpc8xxx_spi, t);
else else
ret = fsl_spi_cpu_bufs(mpc8xxx_spi, t, len); ret = fsl_spi_cpu_bufs(mpc8xxx_spi, t, len);
if (ret) if (ret)
...@@ -353,7 +352,7 @@ static int fsl_spi_transfer_one(struct spi_controller *controller, ...@@ -353,7 +352,7 @@ static int fsl_spi_transfer_one(struct spi_controller *controller,
if (status < 0) if (status < 0)
return status; return status;
if (t->len) if (t->len)
status = fsl_spi_bufs(spi, t, !!t->tx_dma || !!t->rx_dma); status = fsl_spi_bufs(spi, t);
if (status > 0) if (status > 0)
return -EMSGSIZE; return -EMSGSIZE;
......
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