aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorSourav Poddar <sourav.poddar@ti.com>2013-08-22 11:50:48 -0400
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 09:05:53 -0400
commitee1e3cd6a4a84f018f39f0c75a53b51ddc886d6e (patch)
treef2316df5c1510a01fc8cbe5e210ad5c8553c0736 /drivers/spi
parent8cf27f4979551c626540ec68e6cc219b26440799 (diff)
spi: conditional checking of mode and transfer bits.
There is a bug in the following patch: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14420 spi: DUAL and QUAD support fix the previous patch some mistake below: 1. DT in slave node, use "spi-tx-nbits = <1/2/4>" in place of using "spi-tx-dual, spi-tx-quad" directly, same to rx. So correct the previous way to get the property in @of_register_spi_devices(). 2. Change the value of transfer bit macro(SPI_NBITS_SINGLE, SPI_NBITS_DUAL SPI_NBITS_QUAD) to 0x01, 0x02 and 0x04 to match the actual wires. 3. Add the following check (1)keep the tx_nbits and rx_nbits in spi_transfer is not beyond the single, dual and quad. (2)keep tx_nbits and rx_nbits are contained by @spi_device->mode example: if @spi_device->mode = DUAL, then tx/rx_nbits can not be set to QUAD(SPI_NBITS_QUAD) (3)if "@spi_device->mode & SPI_3WIRE", then tx/rx_nbits should be in single(SPI_NBITS_SINGLE) Checking of the tx/rx transfer bits and mode bits should be done conditionally based on type of buffer filled else EINVAL condition will always get hit either for rx or tx. Signed-off-by: Sourav Poddar <sourav.poddar@ti.com> Signed-off-by: Mark Brown <broonie@linaro.org> Signed-off-by: Huang Shijie <b32955@freescale.com>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 621d11628954..2b99994de8b9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1492,33 +1492,37 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
1492 * 2. keep tx/rx_nbits is contained by mode in spi_device 1492 * 2. keep tx/rx_nbits is contained by mode in spi_device
1493 * 3. if SPI_3WIRE, tx/rx_nbits should be in single 1493 * 3. if SPI_3WIRE, tx/rx_nbits should be in single
1494 */ 1494 */
1495 if (xfer->tx_nbits != SPI_NBITS_SINGLE && 1495 if (xfer->tx_buf) {
1496 xfer->tx_nbits != SPI_NBITS_DUAL && 1496 if (xfer->tx_nbits != SPI_NBITS_SINGLE &&
1497 xfer->tx_nbits != SPI_NBITS_QUAD) 1497 xfer->tx_nbits != SPI_NBITS_DUAL &&
1498 return -EINVAL; 1498 xfer->tx_nbits != SPI_NBITS_QUAD)
1499 if ((xfer->tx_nbits == SPI_NBITS_DUAL) && 1499 return -EINVAL;
1500 !(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD))) 1500 if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
1501 return -EINVAL; 1501 !(spi->mode & (SPI_TX_DUAL | SPI_TX_QUAD)))
1502 if ((xfer->tx_nbits == SPI_NBITS_QUAD) && 1502 return -EINVAL;
1503 !(spi->mode & SPI_TX_QUAD)) 1503 if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
1504 return -EINVAL; 1504 !(spi->mode & SPI_TX_QUAD))
1505 if ((spi->mode & SPI_3WIRE) && 1505 return -EINVAL;
1506 (xfer->tx_nbits != SPI_NBITS_SINGLE)) 1506 if ((spi->mode & SPI_3WIRE) &&
1507 return -EINVAL; 1507 (xfer->tx_nbits != SPI_NBITS_SINGLE))
1508 return -EINVAL;
1509 }
1508 /* check transfer rx_nbits */ 1510 /* check transfer rx_nbits */
1509 if (xfer->rx_nbits != SPI_NBITS_SINGLE && 1511 if (xfer->rx_buf) {
1510 xfer->rx_nbits != SPI_NBITS_DUAL && 1512 if (xfer->rx_nbits != SPI_NBITS_SINGLE &&
1511 xfer->rx_nbits != SPI_NBITS_QUAD) 1513 xfer->rx_nbits != SPI_NBITS_DUAL &&
1512 return -EINVAL; 1514 xfer->rx_nbits != SPI_NBITS_QUAD)
1513 if ((xfer->rx_nbits == SPI_NBITS_DUAL) && 1515 return -EINVAL;
1514 !(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD))) 1516 if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
1515 return -EINVAL; 1517 !(spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD)))
1516 if ((xfer->rx_nbits == SPI_NBITS_QUAD) && 1518 return -EINVAL;
1517 !(spi->mode & SPI_RX_QUAD)) 1519 if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
1518 return -EINVAL; 1520 !(spi->mode & SPI_RX_QUAD))
1519 if ((spi->mode & SPI_3WIRE) && 1521 return -EINVAL;
1520 (xfer->rx_nbits != SPI_NBITS_SINGLE)) 1522 if ((spi->mode & SPI_3WIRE) &&
1521 return -EINVAL; 1523 (xfer->rx_nbits != SPI_NBITS_SINGLE))
1524 return -EINVAL;
1525 }
1522 } 1526 }
1523 1527
1524 message->spi = spi; 1528 message->spi = spi;