You need to set the tx_nbits and rx_nbits fields of the spi_ioc_transfer 
struct
to something valid. Zero will do.

If you are using a stack variable (which your code snippet implied), the 
tx_nbits
and rx_nbits fields are likely random garbage.

You might just be getting lucky now.

--- from include/uapi/linux/spi/spidev.h

struct spi_ioc_transfer {
        __u64           tx_buf;
        __u64           rx_buf;
        __u32           len;
        __u32           speed_hz;
        __u16           delay_usecs;
        __u8            bits_per_word;
        __u8            cs_change;
        __u8            tx_nbits;
        __u8            rx_nbits;
        __u16           pad;
};

--- from include/linux/spi/spi.h
...
/**
 * struct spi_transfer - a read/write buffer pair
 * @tx_buf: data to be written (dma-safe memory), or NULL
 * @rx_buf: data to be read (dma-safe memory), or NULL
 * @tx_dma: DMA address of tx_buf, if @spi_message.is_dma_mapped
 * @rx_dma: DMA address of rx_buf, if @spi_message.is_dma_mapped
 * @tx_nbits: number of bits used for writing. If 0 the default
 *      (SPI_NBITS_SINGLE) is used.
 * @rx_nbits: number of bits used for reading. If 0 the default
 *      (SPI_NBITS_SINGLE) is used.
 ...

--- from drivers/spi/spi.c

2013 static int __spi_validate(struct spi_device *spi, struct spi_message 
*message)
2014 {
...
2087                 /* check transfer tx/rx_nbits:
2088                  * 1. check the value matches one of single, dual and 
quad
2089                  * 2. check tx/rx_nbits match the mode in spi_device
2090                  */
2091                 if (xfer->tx_buf) {
2092                         if (xfer->tx_nbits != SPI_NBITS_SINGLE &&
2093                                 xfer->tx_nbits != SPI_NBITS_DUAL &&
2094                                 xfer->tx_nbits != SPI_NBITS_QUAD)
2095                                 return -EINVAL;
2096                         if ((xfer->tx_nbits == SPI_NBITS_DUAL) &&
2097                                 !(spi->mode & (SPI_TX_DUAL | 
SPI_TX_QUAD)))
2098                                 return -EINVAL;
2099                         if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
2100                                 !(spi->mode & SPI_TX_QUAD))
2101                                 return -EINVAL;
2102                 }
2103                 /* check transfer rx_nbits */
2104                 if (xfer->rx_buf) {
2105                         if (xfer->rx_nbits != SPI_NBITS_SINGLE &&
2106                                 xfer->rx_nbits != SPI_NBITS_DUAL &&
2107                                 xfer->rx_nbits != SPI_NBITS_QUAD)
2108                                 return -EINVAL;
2109                         if ((xfer->rx_nbits == SPI_NBITS_DUAL) &&
2110                                 !(spi->mode & (SPI_RX_DUAL | 
SPI_RX_QUAD)))
2111                                 return -EINVAL;
2112                         if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
2113                                 !(spi->mode & SPI_RX_QUAD))
2114                                 return -EINVAL;
2115                 }
...

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to