mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/8] atmel_spi: split transfert to atmel_spi_do_xfer
Date: Tue,  6 Nov 2012 20:33:30 +0100	[thread overview]
Message-ID: <1352230416-9396-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1352230416-9396-1-git-send-email-plagnioj@jcrosoft.com>

This make the code mre readable

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/spi/atmel_spi.c |   89 ++++++++++++++++++++++++++---------------------
 1 file changed, 49 insertions(+), 40 deletions(-)

diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 3375f81..afbca9f 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -178,13 +178,54 @@ static int atmel_spi_xchg(struct atmel_spi *as, u32 tx_val)
 	return spi_readl(as, RDR) & 0xffff;
 }
 
+static int atmel_spi_do_xfer(struct spi_device *spi, struct atmel_spi *as,
+			     struct spi_transfer *t)
+{
+	unsigned int bits = spi->bits_per_word;
+	u32 tx_val;
+	int i = 0, rx_val;
+
+	if (bits <= 8) {
+		const u8 *txbuf = t->tx_buf;
+		u8 *rxbuf = t->rx_buf;
+
+		while (i < t->len) {
+			tx_val = txbuf ? txbuf[i] : 0;
+
+			rx_val = atmel_spi_xchg(as, tx_val);
+			if (rx_val < 0)
+				return rx_val;
+
+			if (rxbuf)
+				rxbuf[i] = rx_val;
+			i++;
+		}
+	} else if (bits <= 16) {
+		const u16 *txbuf = t->tx_buf;
+		u16 *rxbuf = t->rx_buf;
+
+		while (i < t->len >> 1) {
+			tx_val = txbuf ? txbuf[i] : 0;
+
+			rx_val = atmel_spi_xchg(as, tx_val);
+			if (rx_val < 0)
+				return rx_val;
+
+			if (rxbuf)
+				rxbuf[i] = rx_val;
+			i++;
+		}
+	}
+
+	return t->len;
+}
+
 static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 {
 	int ret;
 	struct spi_master *master	= spi->master;
 	struct atmel_spi *as		= to_atmel_spi(master);
 	struct spi_transfer *t		= NULL;
-	unsigned int bits		= spi->bits_per_word;
 
 	mesg->actual_length = 0;
 	ret = master->setup(spi);
@@ -203,47 +244,15 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 	}
 #endif
 	atmel_spi_chipselect(spi, as, 1);
+
 	list_for_each_entry(t, &mesg->transfers, transfer_list) {
-		u32 tx_val;
-		int i = 0, rx_val;
-
-		mesg->actual_length += t->len;
-		if (bits <= 8) {
-			const u8 *txbuf = t->tx_buf;
-			u8 *rxbuf = t->rx_buf;
-
-			while (i < t->len) {
-				tx_val = txbuf ? txbuf[i] : 0;
-
-				rx_val = atmel_spi_xchg(as, tx_val);
-				if (rx_val < 0) {
-					ret = rx_val;
-					goto out;
-				}
-
-				if (rxbuf)
-					rxbuf[i] = rx_val;
-				i++;
-			}
-		} else if (bits <= 16) {
-			const u16 *txbuf = t->tx_buf;
-			u16 *rxbuf = t->rx_buf;
-
-			while (i < t->len >> 1) {
-				tx_val = txbuf ? txbuf[i] : 0;
-
-				rx_val = atmel_spi_xchg(as, tx_val);
-				if (rx_val < 0) {
-					ret = rx_val;
-					goto out;
-				}
-
-				if (rxbuf)
-					rxbuf[i] = rx_val;
-				i++;
-			}
-		}
+
+		ret = atmel_spi_do_xfer(spi, as, t);
+		if (ret < 0)
+			goto out;
+		mesg->actual_length += ret;
 	}
+
 out:
 	atmel_spi_chipselect(spi, as, 0);
 	return ret;
-- 
1.7.10.4


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

  reply	other threads:[~2012-11-06 19:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-06 19:30 [PATCH 0/8] atmtel: fix spi driver + rm9200 Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33 ` [PATCH 1/8] atmel_spi: use device id as bus num Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-11-13 14:45     ` [PATCH 2/8] atmel_spi: split transfert to atmel_spi_do_xfer Thomas Petazzoni
2012-11-06 19:33   ` [PATCH 3/8] atmel_spi: after setup the cs need to be disable Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` [PATCH 4/8] atmel_spi: add sanity check in setup Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` [PATCH 5/8] atmel_spi: fix cs support Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` [PATCH 6/8] atmel_spi: drop setup during transfer Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` [PATCH 7/8] atmel_spi: add cs change support Jean-Christophe PLAGNIOL-VILLARD
2012-11-06 19:33   ` [PATCH 8/8] at91rm9200: fix spi cs support Jean-Christophe PLAGNIOL-VILLARD
2012-11-12  7:36 ` [PATCH 0/8] atmtel: fix spi driver + rm9200 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=1352230416-9396-2-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --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