Skip to content

Commit

Permalink
SPI100k: Fix 8-bit and RX-only transfers
Browse files Browse the repository at this point in the history
This change fixes 8-bit transfers and RX-only transfers.  The
SPI100k framework requires minimum 16-bit words to be written, so 8-bit
transfers must be shited by 8 bits and sent out as a 16-bit word.

Additionally, receive-only transfers were failing due to the
perceived need to fill the TX buffer with something.  This is in
fact not needed.

Signed-off-by: Cory Maccarrone <darkstar6262@gmail.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
Cory Maccarrone authored and Grant Likely committed Jul 4, 2010
1 parent 4751c1c commit 5c2818c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions drivers/spi/omap_spi_100k.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ static void spi100k_write_data(struct spi_master *master, int len, int data)
{
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);

/* write 16-bit word */
/* write 16-bit word, shifting 8-bit data if necessary */
if (len <= 8) {
data <<= 8;
len = 16;
}

spi100k_enable_clock(master);
writew( data , spi100k->base + SPI_TX_MSB);

Expand All @@ -162,6 +167,10 @@ static int spi100k_read_data(struct spi_master *master, int len)
int dataH,dataL;
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);

/* Always do at least 16 bits */
if (len <= 8)
len = 16;

spi100k_enable_clock(master);
writew(SPI_CTRL_SEN(0) |
SPI_CTRL_WORD_SIZE(len) |
Expand Down Expand Up @@ -214,10 +223,6 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
c = count;
word_len = cs->word_len;

/* RX_ONLY mode needs dummy data in TX reg */
if (xfer->tx_buf == NULL)
spi100k_write_data(spi->master,word_len, 0);

if (word_len <= 8) {
u8 *rx;
const u8 *tx;
Expand All @@ -227,9 +232,9 @@ omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
do {
c-=1;
if (xfer->tx_buf != NULL)
spi100k_write_data(spi->master,word_len, *tx);
spi100k_write_data(spi->master, word_len, *tx++);
if (xfer->rx_buf != NULL)
*rx = spi100k_read_data(spi->master,word_len);
*rx++ = spi100k_read_data(spi->master, word_len);
} while(c);
} else if (word_len <= 16) {
u16 *rx;
Expand Down Expand Up @@ -380,10 +385,6 @@ static void omap1_spi100k_work(struct work_struct *work)
if (t->len) {
unsigned count;

/* RX_ONLY mode needs dummy data in TX reg */
if (t->tx_buf == NULL)
spi100k_write_data(spi->master, 8, 0);

count = omap1_spi100k_txrx_pio(spi, t);
m->actual_length += count;

Expand Down

0 comments on commit 5c2818c

Please sign in to comment.