Skip to content

Commit

Permalink
Merge pull request raspberrypi#202 from notro/LoSSI
Browse files Browse the repository at this point in the history
spi-bcm2708: add 9-bit support using LoSSI mode
  • Loading branch information
popcornmix committed Mar 24, 2013
2 parents e959a8e + bf5eb33 commit 6bf302e
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions drivers/spi/spi-bcm2708.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,31 @@ static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
{
u8 byte;
u16 val;

if (len > bs->len)
len = bs->len;

if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
/* LoSSI mode */
if (unlikely(len % 2)) {
printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
bs->len = 0;
return;
}
while (len) {
if (bs->tx_buf) {
val = *(const u16 *)bs->tx_buf;
bs->tx_buf += 2;
} else
val = 0;
bcm2708_wr(bs, SPI_FIFO, val);
bs->len -= 2;
len -= 2;
}
return;
}

while (len--) {
byte = bs->tx_buf ? *bs->tx_buf++ : 0;
bcm2708_wr(bs, SPI_FIFO, byte);
Expand Down Expand Up @@ -234,8 +255,12 @@ static int bcm2708_setup_state(struct spi_master *master,
switch (bpw) {
case 8:
break;
case 9:
/* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
cs |= SPI_CS_LEN;
break;
default:
dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8)\n",
dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
bpw);
return -EINVAL;
}
Expand Down Expand Up @@ -283,7 +308,8 @@ static int bcm2708_process_transfer(struct bcm2708_spi *bs,
ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
spi->chip_select, spi->mode,
spi->bits_per_word);
xfer->bits_per_word ? xfer->bits_per_word :
spi->bits_per_word);
if (ret)
return ret;

Expand Down

0 comments on commit 6bf302e

Please sign in to comment.