I have a requirement for control chipselect for my spidevice.
The requirement is between two writes or reads my device should remain selected from contoller.
For example the sequence is like :
Write opreation
1)chip select
2)send some data ( i am using ioctl(SPI_IOC_MESSAGE(1) )
3)send some more data ( means sending one more time ioctl command).
4)chip deselect
Now after Write operation i need to read the data.
Read Operation
1)chip select
2)Read data ( i am using ioctl(SPI_IOC_MESSAGE(1) )
3)Read more data ( means sending one more time ioctl command).
4)chip deselect
but as per my understanding whenever we call ioctl(SPI_IOC_MESSAGE(1)) the control finally goes to mxc_spi.c (which is controller driver) and for each write/read it selects the chip -> enables the clock -> write/read data then deselects the chip.
Note : i saw it wrtites to the control register which actually has the value for chip select and all.
Is there any way i can meet the above requirement?
i am really stuck.
SPI_IOC_MESSAGE can execute multiple read/write operations in single ioctl() request.
struct spi_ioc_transfer have member cs_change, which specifies if you want to deactivate CS between request or keep activated.
unsigned char cmd_buf[4];
unsigned char data_buf[8];
struct spi_ioc_transfer xfer[2];
/* You must set command sequence on cmd_buf */
xfer[0].tx_buf = (__u64) cmd_buf;
xfer[0].len = 4; /* Length of command to write*/
xfer[0].cs_change = 0; /* Keep CS activated */
xfer[1].rx_buf = (__u64) data_buf;
xfer[1].len = 8; /* Length of Data to read */
xfer[1].cs_change = 0;
ioctl(fd, SPI_IOC_MESSAGE(2), xfer);
It worked on iMX28 at least.