diff options
author | David Brownell <david-b@pacbell.net> | 2006-04-03 18:46:22 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-05-16 17:33:57 -0400 |
commit | ccf77cc4af5b048e20cfd9327fcc286cb69c34cc (patch) | |
tree | 0a19a6948fe8bbf2128010a655e170ffebc9d8b8 | |
parent | ff9f4771b5f017ee0f57629488b6cd7a6ef3d19b (diff) |
[PATCH] SPI: devices can require LSB-first encodings
Add spi_device hook for LSB-first word encoding, and update all the
(in-tree) controller drivers to reject such devices. Eventually,
some controller drivers will be updated to support lsb-first encodings
on the wire; no current drivers need this.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/spi/spi_bitbang.c | 11 | ||||
-rw-r--r-- | include/linux/spi/spi.h | 7 |
2 files changed, 15 insertions, 3 deletions
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c index 6c3da64d609a..0f7f5c64391c 100644 --- a/drivers/spi/spi_bitbang.c +++ b/drivers/spi/spi_bitbang.c | |||
@@ -187,13 +187,22 @@ int spi_bitbang_setup(struct spi_device *spi) | |||
187 | if (!spi->max_speed_hz) | 187 | if (!spi->max_speed_hz) |
188 | return -EINVAL; | 188 | return -EINVAL; |
189 | 189 | ||
190 | bitbang = spi_master_get_devdata(spi->master); | ||
191 | |||
192 | /* REVISIT: some systems will want to support devices using lsb-first | ||
193 | * bit encodings on the wire. In pure software that would be trivial, | ||
194 | * just bitbang_txrx_le_cphaX() routines shifting the other way, and | ||
195 | * some hardware controllers also have this support. | ||
196 | */ | ||
197 | if ((spi->mode & SPI_LSB_FIRST) != 0) | ||
198 | return -EINVAL; | ||
199 | |||
190 | if (!cs) { | 200 | if (!cs) { |
191 | cs = kzalloc(sizeof *cs, SLAB_KERNEL); | 201 | cs = kzalloc(sizeof *cs, SLAB_KERNEL); |
192 | if (!cs) | 202 | if (!cs) |
193 | return -ENOMEM; | 203 | return -ENOMEM; |
194 | spi->controller_state = cs; | 204 | spi->controller_state = cs; |
195 | } | 205 | } |
196 | bitbang = spi_master_get_devdata(spi->master); | ||
197 | 206 | ||
198 | if (!spi->bits_per_word) | 207 | if (!spi->bits_per_word) |
199 | spi->bits_per_word = 8; | 208 | spi->bits_per_word = 8; |
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 082006714b85..77add901691d 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h | |||
@@ -35,10 +35,13 @@ extern struct bus_type spi_bus_type; | |||
35 | * @chip-select: Chipselect, distinguishing chips handled by "master". | 35 | * @chip-select: Chipselect, distinguishing chips handled by "master". |
36 | * @mode: The spi mode defines how data is clocked out and in. | 36 | * @mode: The spi mode defines how data is clocked out and in. |
37 | * This may be changed by the device's driver. | 37 | * This may be changed by the device's driver. |
38 | * The "active low" default for chipselect mode can be overridden, | ||
39 | * as can the "MSB first" default for each word in a transfer. | ||
38 | * @bits_per_word: Data transfers involve one or more words; word sizes | 40 | * @bits_per_word: Data transfers involve one or more words; word sizes |
39 | * like eight or 12 bits are common. In-memory wordsizes are | 41 | * like eight or 12 bits are common. In-memory wordsizes are |
40 | * powers of two bytes (e.g. 20 bit samples use 32 bits). | 42 | * powers of two bytes (e.g. 20 bit samples use 32 bits). |
41 | * This may be changed by the device's driver. | 43 | * This may be changed by the device's driver, or left at the |
44 | * default (0) indicating protocol words are eight bit bytes. | ||
42 | * The spi_transfer.bits_per_word can override this for each transfer. | 45 | * The spi_transfer.bits_per_word can override this for each transfer. |
43 | * @irq: Negative, or the number passed to request_irq() to receive | 46 | * @irq: Negative, or the number passed to request_irq() to receive |
44 | * interrupts from this device. | 47 | * interrupts from this device. |
@@ -67,6 +70,7 @@ struct spi_device { | |||
67 | #define SPI_MODE_2 (SPI_CPOL|0) | 70 | #define SPI_MODE_2 (SPI_CPOL|0) |
68 | #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA) | 71 | #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA) |
69 | #define SPI_CS_HIGH 0x04 /* chipselect active high? */ | 72 | #define SPI_CS_HIGH 0x04 /* chipselect active high? */ |
73 | #define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */ | ||
70 | u8 bits_per_word; | 74 | u8 bits_per_word; |
71 | int irq; | 75 | int irq; |
72 | void *controller_state; | 76 | void *controller_state; |
@@ -75,7 +79,6 @@ struct spi_device { | |||
75 | 79 | ||
76 | // likely need more hooks for more protocol options affecting how | 80 | // likely need more hooks for more protocol options affecting how |
77 | // the controller talks to each chip, like: | 81 | // the controller talks to each chip, like: |
78 | // - bit order (default is wordwise msb-first) | ||
79 | // - memory packing (12 bit samples into low bits, others zeroed) | 82 | // - memory packing (12 bit samples into low bits, others zeroed) |
80 | // - priority | 83 | // - priority |
81 | // - drop chipselect after each word | 84 | // - drop chipselect after each word |