Unverified Commit 412a05d6 authored by Mark Brown's avatar Mark Brown
Browse files

spi: Rework DMA mapped flag

Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

The first part of the series (patches 1 to 7) is an introduction
of a new helper followed by the user conversion.

This consolidates the same code and also makes patch 8 (last one)
be localised to the SPI core part.

The last patch is the main rework to get rid of a recently introduced
hack with a dummy SG list and move to the transfer-based DMA mapped
flag.

That said, the patches 1 to 7 may be applied right away since they
have no functional change intended, while the last one needs more
testing and reviewing.
parents 8a71710b e289df82
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -40,4 +40,12 @@ static inline void spi_unmap_buf(struct spi_controller *ctlr,
}
#endif /* CONFIG_HAS_DMA */

static inline bool spi_xfer_is_dma_mapped(struct spi_controller *ctlr,
					  struct spi_device *spi,
					  struct spi_transfer *xfer)
{
	return ctlr->can_dma && ctlr->can_dma(ctlr, spi, xfer) &&
	       (xfer->tx_sg_mapped || xfer->rx_sg_mapped);
}

#endif /* __LINUX_SPI_INTERNALS_H */
+2 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/string.h>
#include <linux/of.h>

#include "internals.h"
#include "spi-dw.h"

#ifdef CONFIG_DEBUG_FS
@@ -438,8 +439,7 @@ static int dw_spi_transfer_one(struct spi_controller *host,
	transfer->effective_speed_hz = dws->current_freq;

	/* Check if current transfer is a DMA transaction */
	if (host->can_dma && host->can_dma(host, spi, transfer))
		dws->dma_mapped = host->cur_msg_mapped;
	dws->dma_mapped = spi_xfer_is_dma_mapped(host, spi, transfer);

	/* For poll mode just disable all interrupts */
	dw_spi_mask_intr(dws, 0xff);
+2 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/spi/spi.h>
#include "internals.h"

#define REG_SSIDR	0x0
#define REG_SSICR0	0x4
@@ -242,11 +243,10 @@ static int spi_ingenic_transfer_one(struct spi_controller *ctlr,
{
	struct ingenic_spi *priv = spi_controller_get_devdata(ctlr);
	unsigned int bits = xfer->bits_per_word ?: spi->bits_per_word;
	bool can_dma = ctlr->can_dma && ctlr->can_dma(ctlr, spi, xfer);

	spi_ingenic_prepare_transfer(priv, spi, xfer);

	if (ctlr->cur_msg_mapped && can_dma)
	if (spi_xfer_is_dma_mapped(ctlr, spi, xfer))
		return spi_ingenic_dma_tx(ctlr, xfer, bits);

	if (bits > 16)
+4 −4
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@

#include <linux/spi/spi.h>

#include "internals.h"

#include <linux/platform_data/spi-omap2-mcspi.h>

#define OMAP2_MCSPI_MAX_FREQ		48000000
@@ -1208,8 +1210,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr,
		unsigned	count;

		if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
		    ctlr->cur_msg_mapped &&
		    ctlr->can_dma(ctlr, spi, t))
		    spi_xfer_is_dma_mapped(ctlr, spi, t))
			omap2_mcspi_set_fifo(spi, t, 1);

		omap2_mcspi_set_enable(spi, 1);
@@ -1220,8 +1221,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr,
					+ OMAP2_MCSPI_TX0);

		if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&
		    ctlr->cur_msg_mapped &&
		    ctlr->can_dma(ctlr, spi, t))
		    spi_xfer_is_dma_mapped(ctlr, spi, t))
			count = omap2_mcspi_txrx_dma(spi, t);
		else
			count = omap2_mcspi_txrx_pio(spi, t);
+3 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@


#include <linux/bitfield.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
@@ -15,7 +16,7 @@
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/spi/spi.h>
#include <linux/delay.h>
#include "internals.h"

#define DRV_NAME "spi-pci1xxxx"

@@ -567,7 +568,7 @@ static int pci1xxxx_spi_transfer_with_dma(struct spi_controller *spi_ctlr,
static int pci1xxxx_spi_transfer_one(struct spi_controller *spi_ctlr,
				     struct spi_device *spi, struct spi_transfer *xfer)
{
	if (spi_ctlr->can_dma(spi_ctlr, spi, xfer) && spi_ctlr->cur_msg_mapped)
	if (spi_xfer_is_dma_mapped(spi_ctlr, spi, xfer))
		return pci1xxxx_spi_transfer_with_dma(spi_ctlr, spi, xfer);
	else
		return pci1xxxx_spi_transfer_with_io(spi_ctlr, spi, xfer);
Loading