linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Mark Brown <broonie@kernel.org>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
	Magnus Damm <magnus.damm@gmail.com>,
	linux-spi@vger.kernel.org, linux-sh@vger.kernel.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 03/18] [RFC] spi: rspi: Remove unused 16-bit DMA support
Date: Mon,  2 Jun 2014 15:38:05 +0200	[thread overview]
Message-ID: <1401716301-29612-4-git-send-email-geert+renesas@glider.be> (raw)
In-Reply-To: <1401716301-29612-1-git-send-email-geert+renesas@glider.be>

The 16-bit DMA support doesn't fit well within the SPI core DMA framework,
as it needs to manage its own double-sized temporary buffers, for handling
the interleaved data.
Remove it, as there is no in-tree board code that sets
rspi_plat_data.dma_width_16bit.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/spi/spi-rspi.c   | 84 ++++--------------------------------------------
 include/linux/spi/rspi.h |  2 --
 2 files changed, 6 insertions(+), 80 deletions(-)

diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 57beda209599..3bd06fd9af47 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -201,7 +201,6 @@ struct rspi_data {
 	struct dma_chan *chan_tx;
 	struct dma_chan *chan_rx;
 
-	unsigned dma_width_16bit:1;
 	unsigned dma_callbacked:1;
 	unsigned byte_access:1;
 };
@@ -475,60 +474,17 @@ static void rspi_dma_unmap_sg(struct scatterlist *sg, struct dma_chan *chan,
 	dma_unmap_sg(chan->device->dev, sg, 1, dir);
 }
 
-static void rspi_memory_to_8bit(void *buf, const void *data, unsigned len)
-{
-	u16 *dst = buf;
-	const u8 *src = data;
-
-	while (len) {
-		*dst++ = (u16)(*src++);
-		len--;
-	}
-}
-
-static void rspi_memory_from_8bit(void *buf, const void *data, unsigned len)
-{
-	u8 *dst = buf;
-	const u16 *src = data;
-
-	while (len) {
-		*dst++ = (u8)*src++;
-		len--;
-	}
-}
-
 static int rspi_send_dma(struct rspi_data *rspi, struct spi_transfer *t)
 {
 	struct scatterlist sg;
-	const void *buf = NULL;
+	const void *buf = t->tx_buf;
 	struct dma_async_tx_descriptor *desc;
-	unsigned int len;
+	unsigned int len = t->len;
 	int ret = 0;
 
-	if (rspi->dma_width_16bit) {
-		void *tmp;
-		/*
-		 * If DMAC bus width is 16-bit, the driver allocates a dummy
-		 * buffer. And, the driver converts original data into the
-		 * DMAC data as the following format:
-		 *  original data: 1st byte, 2nd byte ...
-		 *  DMAC data:     1st byte, dummy, 2nd byte, dummy ...
-		 */
-		len = t->len * 2;
-		tmp = kmalloc(len, GFP_KERNEL);
-		if (!tmp)
-			return -ENOMEM;
-		rspi_memory_to_8bit(tmp, t->tx_buf, t->len);
-		buf = tmp;
-	} else {
-		len = t->len;
-		buf = t->tx_buf;
-	}
+	if (!rspi_dma_map_sg(&sg, buf, len, rspi->chan_tx, DMA_TO_DEVICE))
+		return -EFAULT;
 
-	if (!rspi_dma_map_sg(&sg, buf, len, rspi->chan_tx, DMA_TO_DEVICE)) {
-		ret = -EFAULT;
-		goto end_nomap;
-	}
 	desc = dmaengine_prep_slave_sg(rspi->chan_tx, &sg, 1, DMA_TO_DEVICE,
 				       DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
 	if (!desc) {
@@ -563,10 +519,6 @@ static int rspi_send_dma(struct rspi_data *rspi, struct spi_transfer *t)
 
 end:
 	rspi_dma_unmap_sg(&sg, rspi->chan_tx, DMA_TO_DEVICE);
-end_nomap:
-	if (rspi->dma_width_16bit)
-		kfree(buf);
-
 	return ret;
 }
 
@@ -603,28 +555,11 @@ static void qspi_receive_init(const struct rspi_data *rspi)
 static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t)
 {
 	struct scatterlist sg, sg_dummy;
-	void *dummy = NULL, *rx_buf = NULL;
+	void *dummy = NULL, *rx_buf = t->rx_buf;
 	struct dma_async_tx_descriptor *desc, *desc_dummy;
-	unsigned int len;
+	unsigned int len = t->len;
 	int ret = 0;
 
-	if (rspi->dma_width_16bit) {
-		/*
-		 * If DMAC bus width is 16-bit, the driver allocates a dummy
-		 * buffer. And, finally the driver converts the DMAC data into
-		 * actual data as the following format:
-		 *  DMAC data:   1st byte, dummy, 2nd byte, dummy ...
-		 *  actual data: 1st byte, 2nd byte ...
-		 */
-		len = t->len * 2;
-		rx_buf = kmalloc(len, GFP_KERNEL);
-		if (!rx_buf)
-			return -ENOMEM;
-	 } else {
-		len = t->len;
-		rx_buf = t->rx_buf;
-	}
-
 	/* prepare dummy transfer to generate SPI clocks */
 	dummy = kzalloc(len, GFP_KERNEL);
 	if (!dummy) {
@@ -697,11 +632,6 @@ end:
 end_dummy_mapped:
 	rspi_dma_unmap_sg(&sg_dummy, rspi->chan_tx, DMA_TO_DEVICE);
 end_nomap:
-	if (rspi->dma_width_16bit) {
-		if (!ret)
-			rspi_memory_from_8bit(t->rx_buf, rx_buf, t->len);
-		kfree(rx_buf);
-	}
 	kfree(dummy);
 
 	return ret;
@@ -1073,8 +1003,6 @@ static int rspi_request_dma(struct rspi_data *rspi,
 	if (!res || !rspi_pd)
 		return 0;	/* The driver assumes no error. */
 
-	rspi->dma_width_16bit = rspi_pd->dma_width_16bit;
-
 	/* If the module receives data by DMAC, it also needs TX DMAC */
 	if (rspi_pd->dma_rx_id && rspi_pd->dma_tx_id) {
 		dma_cap_zero(mask);
diff --git a/include/linux/spi/rspi.h b/include/linux/spi/rspi.h
index a25bd6f65e7f..e546b2ceb623 100644
--- a/include/linux/spi/rspi.h
+++ b/include/linux/spi/rspi.h
@@ -25,8 +25,6 @@ struct rspi_plat_data {
 	unsigned int dma_tx_id;
 	unsigned int dma_rx_id;
 
-	unsigned dma_width_16bit:1;	/* DMAC read/write width = 16-bit */
-
 	u16 num_chipselect;
 };
 
-- 
1.9.1


  parent reply	other threads:[~2014-06-02 13:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-02 13:38 [PATCH 00/18] spi: rspi: Add DMA support for QSPI on R-Car Gen2 Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 01/18] spi: rspi: Extract rspi_wait_for_{tx_empty,rx_full}() Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 02/18] spi: rspi: Do not call rspi_receive_init() for TX-only Geert Uytterhoeven
2014-06-02 13:38 ` Geert Uytterhoeven [this message]
2014-06-02 13:38 ` [PATCH 05/18] spi: rspi: Extract rspi_pio_transfer() Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 06/18] spi: rspi: Don't consider DMA configuration failures fatal Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 09/18] spi: rspi: SPI DMA core needs both RX and TX DMA to function Geert Uytterhoeven
     [not found]   ` <1401716301-29612-10-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2014-06-02 14:42     ` Mark Brown
2014-06-02 14:55       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdXra=NjAy6WuQBf1Rm3iHv8J2qYubTpq3scxGq8+wK_tg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-06-02 16:28           ` Mark Brown
2014-06-02 13:38 ` [PATCH 12/18] spi: rspi: Pass sg_tables instead of spi_tranfer to rspi_*_dma() Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 13/18] spi: rspi: Merge rspi_*_dma() into rspi_dma_transfer() Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 14/18] spi: rspi: Absorb rspi_rz_transfer_out_in() into rspi_rz_transfer_one() Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 15/18] spi: rspi: Add DMA support for QSPI on R-Car Gen2 Geert Uytterhoeven
     [not found] ` <1401716301-29612-1-git-send-email-geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
2014-06-02 13:38   ` [PATCH 04/18] spi: rspi: Use core SPI_MASTER_MUST_[RT]X handling Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 07/18] spi: rspi: Extract rspi_request_dma_chan() Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 08/18] spi: rspi: Remove unneeded resource test in DMA setup Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 10/18] spi: rspi: Use SPI core DMA mapping framework Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 11/18] spi: rspi: Move RSPI-specific setup out of DMA routines Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 16/18] spi: rspi: Add DMA support for RSPI on RZ/A1H Geert Uytterhoeven
2014-06-02 13:38   ` [PATCH 18/18] [RFC] spi: rspi: Add DT support to DMA setup Geert Uytterhoeven
2014-06-02 14:54     ` Mark Brown
     [not found]       ` <20140602145447.GJ31751-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-06-02 14:57         ` Geert Uytterhoeven
2014-06-02 13:38 ` [PATCH 17/18] spi: rspi: Extract rspi_common_transfer() Geert Uytterhoeven
2014-06-05  5:58 ` [PATCH 00/18] spi: rspi: Add DMA support for QSPI on R-Car Gen2 Yoshihiro Shimoda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401716301-29612-4-git-send-email-geert+renesas@glider.be \
    --to=geert+renesas@glider.be \
    --cc=broonie@kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).