ATMEL-based SPI Model
Let's take a look at this article.ArticleAnalysis:
Http://blog.chinaunix.net/u3/96265/showart_1925533.html
[Post indicated source] http://blog.csdn.net/lanmanck
However, some details are not mentioned. I would like to add it. If not, please point it out:
1. the driver has the concept of bus and equipment.
SPI controller is the bus (SPI bus), corresponding to atmel_spi.c
An external chip on the SPI controller, such as serial flash, can transceiver, and clock chip, is a device. This involves the issue of device drivers.
2. These SPI devices can correspond to spidev. C or specific files.
For example, if I connect to a flash chip, you can specify it when defining the spi_board_info array:
Static struct spi_board_info at_spi_board_info_all_devices [] =
{
{/* Dataflash chip mc13783 */
. Modalias = "mtd_dataflash ",
. Chip_select = 0, // indicates the number of parts of the bus_num SPI device.
. Max_speed_hz = 20000000,
. Bus_num = 0, // indicates the number of SPI
. IRQ = int_num_mix1,
},
}
Note that this modalias is defined as mtd_dataflash because the probe function in mtd_dataflash.c is named "mtd_dataflash"
For example, the ads7846 touch screen chip I connected can be defined as follows:
{
. Modalias = "ads7846 ",
. Chip_select = 2,
. Max_speed_hz = 125000*26,/* (max sample rate @ 3 V) * (CMD + Data + overhead )*/
. Bus_num = 0,
. Platform_data = & ads_info,
. IRQ = at91sam9261_id_irq0,
},
Here, the. modalias = "ads7846", also because of the ads7846.c file, otherwise the device driver cannot be successful, so the/Dev will not see the device.
3. What should I do if I don't want to write a specific chip driver? For example, I have a can transceiver. This requires spidev. C.
Open spidev. C and you will find the standard IOCTL/read/write function. This is the Read Write function corresponding to the user layer. Therefore, the modalias of spi_board_info needs to be defined as follows:
. Modalias = "spidev ",
// If you do not want to write the driver from the device, you must specify it as "spidev", because spidev. c is the probe function of the device, which contains the read/write/ioctl function.
After the device is started, you can see the spidev0.0 text in/dev. 0.0 is bus_num.chip_select.
You may understand this.