linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
	Lee Jones <lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Eric Anholt <eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Cc: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
Subject: [PATCH v3 8/8] spi: bcm2835: move to spi-core methods translate_message and can_dma
Date: Mon, 14 Dec 2015 15:20:25 +0000	[thread overview]
Message-ID: <1450106426-2277-9-git-send-email-kernel@martin.sperl.org> (raw)
In-Reply-To: <1450106426-2277-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>

From: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>

Remove all limitations in can_dma that inhibit the use of DMA

To meet the limitiations of the HW we are now using the standardized
version of spi_translate_message, that:
* splits long transfers (> 60k)
* aligns transfers (on 4 byte boundary)
* merges transfers (for optimizations)

Signed-off-by: Martin Sperl <kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
---
 drivers/spi/spi-bcm2835.c |   58 +++++++++++++++------------------------------
 1 file changed, 19 insertions(+), 39 deletions(-)

Changelog:
  V1 -> V3: move to use spi-core methods where possible

diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c
index cf04960..75e4425 100644
--- a/drivers/spi/spi-bcm2835.c
+++ b/drivers/spi/spi-bcm2835.c
@@ -361,44 +361,8 @@ static bool bcm2835_spi_can_dma(struct spi_master *master,
 	if (!gpio_is_valid(spi->cs_gpio))
 		return false;

-	/* we start DMA efforts only on bigger transfers */
-	if (tfr->len < BCM2835_SPI_DMA_MIN_LENGTH)
-		return false;
-
-	/* BCM2835_SPI_DLEN has defined a max transfer size as
-	 * 16 bit, so max is 65535
-	 * we can revisit this by using an alternative transfer
-	 * method - ideally this would get done without any more
-	 * interaction...
-	 */
-	if (tfr->len > 65535) {
-		dev_warn_once(&spi->dev,
-			      "transfer size of %d too big for dma-transfer\n",
-			      tfr->len);
-		return false;
-	}
-
-	/* if we run rx/tx_buf with word aligned addresses then we are OK */
-	if ((((size_t)tfr->rx_buf & 3) == 0) &&
-	    (((size_t)tfr->tx_buf & 3) == 0))
-		return true;
-
-	/* otherwise we only allow transfers within the same page
-	 * to avoid wasting time on dma_mapping when it is not practical
-	 */
-	if (((size_t)tfr->tx_buf & (PAGE_SIZE - 1)) + tfr->len > PAGE_SIZE) {
-		dev_warn_once(&spi->dev,
-			      "Unaligned spi tx-transfer bridging page\n");
-		return false;
-	}
-	if (((size_t)tfr->rx_buf & (PAGE_SIZE - 1)) + tfr->len > PAGE_SIZE) {
-		dev_warn_once(&spi->dev,
-			      "Unaligned spi rx-transfer bridging page\n");
-		return false;
-	}
-
-	/* return OK */
-	return true;
+	/* use the default implementation */
+	return spi_can_dma_min_dma_len(master, spi, tfr);
 }

 static void bcm2835_dma_release(struct spi_master *master)
@@ -461,7 +425,23 @@ static void bcm2835_dma_init(struct spi_master *master, struct device *dev)

 	/* all went well, so set can_dma */
 	master->can_dma = bcm2835_spi_can_dma;
-	master->max_dma_len = 65535; /* limitation by BCM2835_SPI_DLEN */
+
+	/* set up transform message using the default implementation
+	 * for size, alignment and merging transfers
+	 */
+	master->translate_message = spi_translate_message_size_align_merge;
+
+	/* the minimum length when we run DMA */
+	master->min_dma_len = BCM2835_SPI_DMA_MIN_LENGTH;
+
+	/* the max_dma_len limited by BCM2835_SPI_DLEN is actually 65535,
+	 * but for al practical purposes we use 15 pages (60k)
+	 */
+	master->max_dma_len = 15 * PAGE_SIZE;
+
+	/* dma alignment is 4 bytes */
+	master->dma_alignment = 4;
+
 	/* need to do TX AND RX DMA, so we need dummy buffers */
 	master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;

--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2015-12-14 15:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 15:20 [PATCH v3 0/8] spi: spi-message transformation framework kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found] ` <1450106426-2277-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-12-14 15:20   ` [PATCH v3 1/8] spi: core: added spi_resource management kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-14 15:20   ` [PATCH v3 2/8] spi: core: add spi_replace_transfers method kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-14 15:20   ` [PATCH v3 3/8] spi: core: add spi_split_transfers_maxsize kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found]     ` <1450106426-2277-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-02-16  8:52       ` Geert Uytterhoeven
2015-12-14 15:20   ` [PATCH v3 4/8] spi: core: added spi_split_transfers_unaligned kernel-TqfNSX0MhmxHKSADF0wUEw
     [not found]     ` <1450106426-2277-5-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-12-16 16:11       ` Martin Sperl
2015-12-14 15:20   ` [PATCH v3 5/8] spi: core: add spi_merge_transfers method kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-14 15:20   ` [PATCH v3 6/8] spi: core: add spi_master.translate_message kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-14 15:20   ` [PATCH v3 7/8] spi: core: add spi_master.min_dma_len and supporting methods kernel-TqfNSX0MhmxHKSADF0wUEw
2015-12-14 15:20   ` kernel-TqfNSX0MhmxHKSADF0wUEw [this message]

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=1450106426-2277-9-git-send-email-kernel@martin.sperl.org \
    --to=kernel-tqfnsx0mhmxhksadf0wuew@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org \
    --cc=lee-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-rpi-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
    /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).