I want to control chipselect for my spidevice from user space. i am using imax25 board.

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

I want to control chipselect for my spidevice from user space. i am using imax25 board.

13,602 次查看
priti1z
Contributor II

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.

 

 

 

 

 

标记 (2)
0 项奖励
回复
1 回复

3,880 次查看
YS
Contributor IV

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.

0 项奖励
回复