mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/3] spi: i.MX: create SoC specific transfer functions
Date: Mon, 31 Aug 2015 17:12:45 +0200	[thread overview]
Message-ID: <1441033966-14045-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1441033966-14045-1-git-send-email-s.hauer@pengutronix.de>

There are SoC specific ways to optimize transfers. Make the way free
to implement these by creating SoC specific transfer functions.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/imx_spi.c | 45 +++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 81fa3b0..9a3f05c 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -39,11 +39,18 @@ struct imx_spi {
 	struct clk		*clk;
 
 	unsigned int		(*xchg_single)(struct imx_spi *imx, u32 data);
+	void			(*do_transfer)(struct spi_device *spi);
 	void			(*chipselect)(struct spi_device *spi, int active);
+
+	const void *tx_buf;
+	void *rx_buf;
+	int xfer_len;
+	int bits_per_word;
 };
 
 struct spi_imx_devtype_data {
 	unsigned int		(*xchg_single)(struct imx_spi *imx, u32 data);
+	void			(*do_transfer)(struct spi_device *spi);
 	void			(*chipselect)(struct spi_device *spi, int active);
 	void			(*init)(struct imx_spi *imx);
 };
@@ -332,38 +339,39 @@ static u32 imx_xchg_single(struct spi_device *spi, u32 tx_val)
 	return imx_spi_maybe_reverse_bits(spi, rx_val);
 }
 
-static void imx_spi_do_transfer(struct spi_device *spi, struct spi_transfer *t)
+static void imx_spi_do_transfer(struct spi_device *spi)
 {
+	struct imx_spi *imx = container_of(spi->master, struct imx_spi, master);
 	unsigned i;
 
-	if (spi->bits_per_word <= 8) {
-		const u8	*tx_buf = t->tx_buf;
-		u8		*rx_buf = t->rx_buf;
+	if (imx->bits_per_word <= 8) {
+		const u8	*tx_buf = imx->tx_buf;
+		u8		*rx_buf = imx->rx_buf;
 		u8		rx_val;
 
-		for (i = 0; i < t->len; i++) {
+		for (i = 0; i < imx->xfer_len; i++) {
 			rx_val = imx_xchg_single(spi, tx_buf ? tx_buf[i] : 0);
 
 			if (rx_buf)
 				rx_buf[i] = rx_val;
 		}
-	} else if (spi->bits_per_word <= 16) {
-		const u16	*tx_buf = t->tx_buf;
-		u16		*rx_buf = t->rx_buf;
+	} else if (imx->bits_per_word <= 16) {
+		const u16	*tx_buf = imx->tx_buf;
+		u16		*rx_buf = imx->rx_buf;
 		u16		rx_val;
 
-		for (i = 0; i < t->len >> 1; i++) {
+		for (i = 0; i < imx->xfer_len >> 1; i++) {
 			rx_val = imx_xchg_single(spi, tx_buf ? tx_buf[i] : 0);
 
 			if (rx_buf)
 				rx_buf[i] = rx_val;
 		}
-	} else if (spi->bits_per_word <= 32) {
-		const u32	*tx_buf = t->tx_buf;
-		u32		*rx_buf = t->rx_buf;
+	} else if (imx->bits_per_word <= 32) {
+		const u32	*tx_buf = imx->tx_buf;
+		u32		*rx_buf = imx->rx_buf;
 		u32		rx_val;
 
-		for (i = 0; i < t->len >> 2; i++) {
+		for (i = 0; i < imx->xfer_len >> 2; i++) {
 			rx_val = imx_xchg_single(spi, tx_buf ? tx_buf[i] : 0);
 
 			if (rx_buf)
@@ -395,7 +403,12 @@ static int imx_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 
 		cs_change = t->cs_change;
 
-		imx_spi_do_transfer(spi, t);
+		imx->tx_buf = t->tx_buf;
+		imx->rx_buf = t->rx_buf;
+		imx->xfer_len = t->len;
+		imx->bits_per_word = spi->bits_per_word;
+		imx->do_transfer(spi);
+
 		mesg->actual_length += t->len;
 
 		if (cs_change)
@@ -411,17 +424,20 @@ static int imx_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 static __maybe_unused struct spi_imx_devtype_data spi_imx_devtype_data_0_0 = {
 	.chipselect = cspi_0_0_chipselect,
 	.xchg_single = cspi_0_0_xchg_single,
+	.do_transfer = imx_spi_do_transfer,
 	.init = cspi_0_0_init,
 };
 
 static __maybe_unused struct spi_imx_devtype_data spi_imx_devtype_data_0_7 = {
 	.chipselect = cspi_0_7_chipselect,
 	.xchg_single = cspi_0_7_xchg_single,
+	.do_transfer = imx_spi_do_transfer,
 	.init = cspi_0_7_init,
 };
 
 static __maybe_unused struct spi_imx_devtype_data spi_imx_devtype_data_2_3 = {
 	.chipselect = cspi_2_3_chipselect,
+	.do_transfer = imx_spi_do_transfer,
 	.xchg_single = cspi_2_3_xchg_single,
 };
 
@@ -486,6 +502,7 @@ static int imx_spi_probe(struct device_d *dev)
 
 	imx->chipselect = devdata->chipselect;
 	imx->xchg_single = devdata->xchg_single;
+	imx->do_transfer = devdata->do_transfer;
 	imx->regs = dev_request_mem_region(dev, 0);
 
 	if (devdata->init)
-- 
2.5.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2015-08-31 15:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-31 15:12 [PATCH 1/3] spi: i.MX: use start mode control bit Sascha Hauer
2015-08-31 15:12 ` Sascha Hauer [this message]
2015-08-31 15:12 ` [PATCH 3/3] spi: i.MX: optimize transfers for ECSPI v2.3 Sascha Hauer
2015-10-05  7:52   ` Sascha Hauer

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=1441033966-14045-2-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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