linux下spi有哪些函数,linux下怎么快速的使用 SPI 驱动。
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語言的基本上都會,
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的linux下spi有哪些函数,linux下怎么快速的使用 SPI 驱动。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql函数移植到oracle,ora
- 下一篇: 压缩命令_Linux gzip命令:压缩