LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: Hans-Peter Nilsson <hans-peter.nilsson@axis.com>
Cc: linux-kernel@vger.kernel.org, mikael.starvik@axis.com,
	spi-devel-general@lists.sourceforge.net
Subject: Re: [PATCH 1/2] take 2: (was-kind-of: 3/5 SPI tx_default) 2.6.20-rc6
Date: Fri, 26 Jan 2007 20:21:54 -0800	[thread overview]
Message-ID: <200701262021.55317.david-b@pacbell.net> (raw)
In-Reply-To: <200701261521.15844.david-b@pacbell.net>

On Friday 26 January 2007 3:21 pm, David Brownell wrote:
> > FWIW, I defined it as a single bit in that patch, because that's
> > what my HW can do when the transmitter is disabled - and because
> > MOSI *is* a single-valued signal. ;-) 
> 
> I wouldn't mind a single bit flag either, saying whether to shift
> out all ones or all zeroes.  The controller driver would morph it
> to something appropriate ... 0xff, 0xffffffff, etc.

In fact, how about this one instead?  It uses a bit in spi->mode
since that's pretty easy to test.  And while it doesn't get rid
of the multiple conditionals when the tx buffer is null, it does
let the other values be constants (0, ~0) that compilers like.

(I can update your patch #4, etc, to match.)

- Dave


Index: g26/include/linux/spi/spi.h
===================================================================
--- g26.orig/include/linux/spi/spi.h	2007-01-26 15:16:26.000000000 -0800
+++ g26/include/linux/spi/spi.h	2007-01-26 17:07:30.000000000 -0800
@@ -71,6 +71,7 @@ struct spi_device {
 #define	SPI_MODE_3	(SPI_CPOL|SPI_CPHA)
 #define	SPI_CS_HIGH	0x04			/* chipselect active high? */
 #define	SPI_LSB_FIRST	0x08			/* per-word bits-on-wire */
+#define	SPI_TX_1	0x10			/* shift out ones on rx-only */
 	u8			bits_per_word;
 	int			irq;
 	void			*controller_state;
@@ -296,8 +297,9 @@ extern struct spi_master *spi_busnum_to_
  * the data being transferred; that may reduce overhead, when the
  * underlying driver uses dma.
  *
- * If the transmit buffer is null, zeroes will be shifted out
- * while filling rx_buf.  If the receive buffer is null, the data
+ * If the transmit buffer is null, zeroes will be shifted out while
+ * filling rx_buf, unless SPI_TX_1 is set in spi->mode (in which case
+ * ones will be shifted out).  If the receive buffer is null, the data
  * shifted in will be discarded.  Only "len" bytes shift out (or in).
  * It's an error to try to shift out a partial word.  (For example, by
  * shifting out three bytes with word size of sixteen or twenty bits;
Index: g26/drivers/spi/spi_bitbang.c
===================================================================
--- g26.orig/drivers/spi/spi_bitbang.c	2007-01-26 17:29:55.000000000 -0800
+++ g26/drivers/spi/spi_bitbang.c	2007-01-26 17:36:17.000000000 -0800
@@ -73,10 +73,14 @@ static unsigned bitbang_txrx_8(
 	u8			*rx = t->rx_buf;
 
 	while (likely(count > 0)) {
-		u8		word = 0;
+		u8		word;
 
 		if (tx)
 			word = *tx++;
+		else if (spi->mode & SPI_TX_1)
+			word = ~0;
+		else
+			word = 0;
 		word = txrx_word(spi, ns, word, bits);
 		if (rx)
 			*rx++ = word;
@@ -99,10 +103,14 @@ static unsigned bitbang_txrx_16(
 	u16			*rx = t->rx_buf;
 
 	while (likely(count > 1)) {
-		u16		word = 0;
+		u16		word;
 
 		if (tx)
 			word = *tx++;
+		else if (spi->mode & SPI_TX_1)
+			word = ~0;
+		else
+			word = 0;
 		word = txrx_word(spi, ns, word, bits);
 		if (rx)
 			*rx++ = word;
@@ -125,10 +133,14 @@ static unsigned bitbang_txrx_32(
 	u32			*rx = t->rx_buf;
 
 	while (likely(count > 3)) {
-		u32		word = 0;
+		u32		word;
 
 		if (tx)
 			word = *tx++;
+		else if (spi->mode & SPI_TX_1)
+			word = ~0;
+		else
+			word = 0;
 		word = txrx_word(spi, ns, word, bits);
 		if (rx)
 			*rx++ = word;
@@ -176,6 +188,8 @@ int spi_bitbang_setup_transfer(struct sp
 }
 EXPORT_SYMBOL_GPL(spi_bitbang_setup_transfer);
 
+#define MODEBITS	(SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_TX_1)
+
 /**
  * spi_bitbang_setup - default setup for per-word I/O loops
  */
@@ -192,8 +206,11 @@ int spi_bitbang_setup(struct spi_device 
 	 * just bitbang_txrx_le_cphaX() routines shifting the other way, and
 	 * some hardware controllers also have this support.
 	 */
-	if ((spi->mode & SPI_LSB_FIRST) != 0)
+	if (spi->mode & ~MODEBITS) {
+		dev_dbg(&spi->dev, "unsupported SPI mode bits %04x\n",
+				spi->mode & ~MODEBITS);
 		return -EINVAL;
+	}
 
 	if (!cs) {
 		cs = kzalloc(sizeof *cs, GFP_KERNEL);

  reply	other threads:[~2007-01-27 19:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-25  4:52 [PATCH] 3/5: Updates to SPI and mmc_spi: tx_default, kernel 2.6.19 Hans-Peter Nilsson
2007-01-25 13:02 ` David Brownell
2007-01-26 10:46   ` [PATCH 1/2] take 2: (was-kind-of: 3/5 SPI tx_default) 2.6.20-rc6 Hans-Peter Nilsson
2007-01-26 23:21     ` David Brownell
2007-01-27  4:21       ` David Brownell [this message]
2007-01-27 20:19         ` Hans-Peter Nilsson
2007-01-27 20:26           ` Hans-Peter Nilsson
2007-01-27 20:59           ` [PATCH] take 3: mmc_spi with SPI_TX_1 2.6.20-rc6 Hans-Peter Nilsson
2007-01-28 17:46             ` [PATCH] take 4: " Hans-Peter Nilsson
2007-01-27 10:11       ` [PATCH 1/2] take 2: (was-kind-of: 3/5 SPI tx_default) 2.6.20-rc6 Hans-Peter Nilsson
2007-01-27 19:25         ` David Brownell
2007-01-26 10:48   ` [PATCH 2/2] " Hans-Peter Nilsson

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=200701262021.55317.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=hans-peter.nilsson@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikael.starvik@axis.com \
    --cc=spi-devel-general@lists.sourceforge.net \
    --subject='Re: [PATCH 1/2] take 2: (was-kind-of: 3/5 SPI tx_default) 2.6.20-rc6' \
    /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

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).