Skip to content

Commit ccf77cc

Browse files
David Brownellgregkh
authored andcommitted
[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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ff9f477 commit ccf77cc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

drivers/spi/spi_bitbang.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,22 @@ int spi_bitbang_setup(struct spi_device *spi)
187187
if (!spi->max_speed_hz)
188188
return -EINVAL;
189189

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+
190200
if (!cs) {
191201
cs = kzalloc(sizeof *cs, SLAB_KERNEL);
192202
if (!cs)
193203
return -ENOMEM;
194204
spi->controller_state = cs;
195205
}
196-
bitbang = spi_master_get_devdata(spi->master);
197206

198207
if (!spi->bits_per_word)
199208
spi->bits_per_word = 8;

include/linux/spi/spi.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ extern struct bus_type spi_bus_type;
3535
* @chip-select: Chipselect, distinguishing chips handled by "master".
3636
* @mode: The spi mode defines how data is clocked out and in.
3737
* 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.
3840
* @bits_per_word: Data transfers involve one or more words; word sizes
3941
* like eight or 12 bits are common. In-memory wordsizes are
4042
* 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.
4245
* The spi_transfer.bits_per_word can override this for each transfer.
4346
* @irq: Negative, or the number passed to request_irq() to receive
4447
* interrupts from this device.
@@ -67,6 +70,7 @@ struct spi_device {
6770
#define SPI_MODE_2 (SPI_CPOL|0)
6871
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
6972
#define SPI_CS_HIGH 0x04 /* chipselect active high? */
73+
#define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
7074
u8 bits_per_word;
7175
int irq;
7276
void *controller_state;
@@ -75,7 +79,6 @@ struct spi_device {
7579

7680
// likely need more hooks for more protocol options affecting how
7781
// the controller talks to each chip, like:
78-
// - bit order (default is wordwise msb-first)
7982
// - memory packing (12 bit samples into low bits, others zeroed)
8083
// - priority
8184
// - drop chipselect after each word

0 commit comments

Comments
 (0)