ek_spi_devices 数组就在本文件内。
/*
* SPI devices.
*/
static struct spi_board_info ek_spi_devices[] = {
#if !(defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_AT91))
{/* DataFlash chip */
.modalias= "mtd_dataflash",
.chip_select= 1,
.max_speed_hz= 15 * 1000 * 1000,
.bus_num= 0,
},
#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
{/* DataFlash card */
.modalias= "mtd_dataflash",
.chip_select= 0,
.max_speed_hz= 15 * 1000 * 1000,
.bus_num= 0,
},
#endif
#endif
};
看起来还是很简单,后来网上查了一下,得出了进一步的信息:
struct spi_board_info {
char modalias[SPI_NAME_SIZE];
const void * platform_data;
void * controller_data;
int irq;
u32 max_speed_hz;
u16 bus_num;
u16 chip_select;
u8 mode;
};
Members
modalias[SPI_NAME_SIZE]
Initializes spi_device.modalias; identifies the driver.
platform_data
Initializes spi_device.platform_data; the particular data stored there is driver-specific.
controller_data
Initializes spi_device.controller_data; some controllers need hints about hardware setup, e.g. for DMA.
irq
Initializes spi_device.irq; depends on how the board is wired.
max_speed_hz
Initializes spi_device.max_speed_hz; based on limits from the chip datasheet and board-specific signal quality issues.
bus_num
Identifies which spi_master parents the spi_device; unused by spi_new_device, and otherwise depends on board wiring.
chip_select
Initializes spi_device.chip_select; depends on how the board is wired.
mode
Initializes spi_device.mode; based on the chip datasheet, board wiring (some devices support both 3WIRE and standard modes), and possibly presence of an inverter in the chipselect path.
Description
When adding new SPI devices to the device tree, these structures serve as a partial device template. They hold information which can't always be determined by drivers. Information that probe can establish (such as the default transfer wordsize) is not included here.
These structures are used in two places. Their primary role is to be stored in tables of board-specific device descriptors, which are declared early in board initialization and then used (much later) to populate a controller's device tree after the that controller's driver initializes. A secondary (and atypical) role is as a parameter to spi_new_device call, which happens after those controller drivers are active in some dynamic board configuration models.
于是自己仿照着写了一个:
/*
* SPI devices.
*/
static struct spi_board_info ek_spi_devices[] = {
{
.modalias = "HCMS-29xx",
.chip_select = 0, // choice PB3
.max_speed_hz = 1*1000*1000,
.bus_num = 1, // SPI1
},
};
这样,硬件部分这样基本就完成了。至于 .modalias = "HCMS-29xx"。 后面我会将到,这个参数的值不能随便取。
后面要做的就是驱动了。这个网上有很多资料,大家看看就可以了,我主要说明一下,我们在SPI的驱动里需要自己实现probe函数。 因为在内核将我们的驱动和刚刚我们
申请的SPI 设备匹配成功后就需要调用这个函数。 写驱动时,大家要注意了,我们需要申明一个名为 spi_driver 的结构体。下面是我申请的结构体:
static struct spi_driver hcms29xx_spi_driver = {
.driver = {
.name ="HCMS-29xx",
.owner = THIS_MODULE,
},
.probe =hcms29xx_spi_probe,
.remove =hcms29xx_spi_remove
};
注意里面有一个 .name 的成员。 它是设备和驱动匹配的关键。 想想我们在前面初始化SPI设备后,它是怎么和我们写的驱动挂上勾的呢? 就是它! 这个结构体里面的.name.
就是靠他和前面设备里 那个 modalias 成员。 所以我们在给他们赋值时。他们的取值要相等,这样才能匹配成功。
剩下的就是写驱动和调试驱动了,这些就不必说了吧,会C语言的基本上都会,