diff options
author | Richard Genoud <richard.genoud@gmail.com> | 2013-05-02 07:25:11 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-05-02 09:40:45 -0400 |
commit | f557c98b168a2860bfc7dedf4b4e3bafb59dc267 (patch) | |
tree | d507a886d34d68fc19f6ba3496cc4f90835c54b1 /drivers/spi | |
parent | cd8d984f0def2a8c5733a9468634ec3e0feec03d (diff) |
spi/spi-atmel: BUG: fix doesn' support 16 bits transfers using PIO
Fix using PIO transfer mode only support 8 bits transfer, doesn't support 16 bits.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
[wenyou.yang@atmel.com: submit the patch]
Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-atmel.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 787bd2c22bca..d8cb7da65efe 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c | |||
@@ -526,13 +526,17 @@ static void atmel_spi_next_xfer_pio(struct spi_master *master, | |||
526 | } | 526 | } |
527 | 527 | ||
528 | if (xfer->tx_buf) | 528 | if (xfer->tx_buf) |
529 | spi_writel(as, TDR, *(u8 *)(xfer->tx_buf)); | 529 | if (xfer->bits_per_word > 8) |
530 | spi_writel(as, TDR, *(u16 *)(xfer->tx_buf)); | ||
531 | else | ||
532 | spi_writel(as, TDR, *(u8 *)(xfer->tx_buf)); | ||
530 | else | 533 | else |
531 | spi_writel(as, TDR, 0); | 534 | spi_writel(as, TDR, 0); |
532 | 535 | ||
533 | dev_dbg(master->dev.parent, | 536 | dev_dbg(master->dev.parent, |
534 | " start pio xfer %p: len %u tx %p rx %p\n", | 537 | " start pio xfer %p: len %u tx %p rx %p bitpw %d\n", |
535 | xfer, xfer->len, xfer->tx_buf, xfer->rx_buf); | 538 | xfer, xfer->len, xfer->tx_buf, xfer->rx_buf, |
539 | xfer->bits_per_word); | ||
536 | 540 | ||
537 | /* Enable relevant interrupts */ | 541 | /* Enable relevant interrupts */ |
538 | spi_writel(as, IER, SPI_BIT(RDRF) | SPI_BIT(OVRES)); | 542 | spi_writel(as, IER, SPI_BIT(RDRF) | SPI_BIT(OVRES)); |
@@ -950,21 +954,39 @@ atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer) | |||
950 | { | 954 | { |
951 | u8 *txp; | 955 | u8 *txp; |
952 | u8 *rxp; | 956 | u8 *rxp; |
957 | u16 *txp16; | ||
958 | u16 *rxp16; | ||
953 | unsigned long xfer_pos = xfer->len - as->current_remaining_bytes; | 959 | unsigned long xfer_pos = xfer->len - as->current_remaining_bytes; |
954 | 960 | ||
955 | if (xfer->rx_buf) { | 961 | if (xfer->rx_buf) { |
956 | rxp = ((u8 *)xfer->rx_buf) + xfer_pos; | 962 | if (xfer->bits_per_word > 8) { |
957 | *rxp = spi_readl(as, RDR); | 963 | rxp16 = (u16 *)(((u8 *)xfer->rx_buf) + xfer_pos); |
964 | *rxp16 = spi_readl(as, RDR); | ||
965 | } else { | ||
966 | rxp = ((u8 *)xfer->rx_buf) + xfer_pos; | ||
967 | *rxp = spi_readl(as, RDR); | ||
968 | } | ||
958 | } else { | 969 | } else { |
959 | spi_readl(as, RDR); | 970 | spi_readl(as, RDR); |
960 | } | 971 | } |
961 | 972 | if (xfer->bits_per_word > 8) { | |
962 | as->current_remaining_bytes--; | 973 | as->current_remaining_bytes -= 2; |
974 | if (as->current_remaining_bytes < 0) | ||
975 | as->current_remaining_bytes = 0; | ||
976 | } else { | ||
977 | as->current_remaining_bytes--; | ||
978 | } | ||
963 | 979 | ||
964 | if (as->current_remaining_bytes) { | 980 | if (as->current_remaining_bytes) { |
965 | if (xfer->tx_buf) { | 981 | if (xfer->tx_buf) { |
966 | txp = ((u8 *)xfer->tx_buf) + xfer_pos + 1; | 982 | if (xfer->bits_per_word > 8) { |
967 | spi_writel(as, TDR, *txp); | 983 | txp16 = (u16 *)(((u8 *)xfer->tx_buf) |
984 | + xfer_pos + 2); | ||
985 | spi_writel(as, TDR, *txp16); | ||
986 | } else { | ||
987 | txp = ((u8 *)xfer->tx_buf) + xfer_pos + 1; | ||
988 | spi_writel(as, TDR, *txp); | ||
989 | } | ||
968 | } else { | 990 | } else { |
969 | spi_writel(as, TDR, 0); | 991 | spi_writel(as, TDR, 0); |
970 | } | 992 | } |
@@ -1378,6 +1400,13 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg) | |||
1378 | } | 1400 | } |
1379 | } | 1401 | } |
1380 | 1402 | ||
1403 | if (xfer->bits_per_word > 8) { | ||
1404 | if (xfer->len % 2) { | ||
1405 | dev_dbg(&spi->dev, "buffer len should be 16 bits aligned\n"); | ||
1406 | return -EINVAL; | ||
1407 | } | ||
1408 | } | ||
1409 | |||
1381 | /* FIXME implement these protocol options!! */ | 1410 | /* FIXME implement these protocol options!! */ |
1382 | if (xfer->speed_hz) { | 1411 | if (xfer->speed_hz) { |
1383 | dev_dbg(&spi->dev, "no protocol options yet\n"); | 1412 | dev_dbg(&spi->dev, "no protocol options yet\n"); |