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 驱动。相关推荐

  1. linux读取文件修改时间函数,Linux服务器编程之utime()函数修改文件存取时间

    Linux服务器编程之utime()函数修改文件存取时间 C语言utime()函数:修改文件的存取时间和更改时间 头文件: #include #include 定义函数: int utime(cons ...

  2. linux下通过字符串调用函数,linux中字符串转换函数 simple_strtoul

    转自 http://blog.csdn.net/tommy_wxie/article/details/7480087 Linux内核中提供的一些字符串转换函数: lib/vsprintf.c 1. u ...

  3. linux获取机器cpuid地址函数,Linux下获取CPUID、硬盘序列号与MAC地址

    在很多系统软件的开发中,需要使用一些系统的唯一性信息.所以,得到主机的CPUID.硬盘序列号及网卡的MAC地址,就成个一件很重要的应用. 本人经过一番google即自己的钻研,基本上实现了这几个功能. ...

  4. Linux获取本机hostname函数,Linux下获得主机与域名-gethostbyname和gethostbyaddr

    1.数据结构hostent和servent: struct hostent{ char *h_name;/* official domain name of host */ char **h_alia ...

  5. linux内核udp校验和计算函数,Linux 内核IP和UDP检验和计算

    ·IP checksum a.接收报文 struct iphdr *iph = ip_hdr(skb); if (unlikely(ip_fast_csum((u8 *)iph, iph->ih ...

  6. linux c中字符替换函数,Linux C 支持正则表达式的字符串替换函数

    [root@localhost src]# cat a.c /** * Linux C 支持正则表达式的字符串替换函数 * * Author: cnscn@163.com * Homepage: ww ...

  7. linux c数字转字符串函数,Linux常用C函数—字符串转换篇

    Linux 常用C 函数-字符串转换篇 atof (将字符串转换成浮点型数) 相关函数 atoi ,atol ,strtod ,strtol ,strtoul 定义函数 double atof(con ...

  8. linux 清理内存的c函数,Linux C函数之内存配置函数

    1. 配置和释放内存 alloca: 配置内存空间 头文件: stdlib.h 函数定义: void *alloc(size_t size); 说明: alloca()用来配置size个字节的内存空间 ...

  9. linux实现自己的write函数,Linux 内核源码阅读 - write 系统调用的实现

    最近在看write系统调用的实现,虽然还有一下细节不是很清楚,但是大致的实现机理还是有一定的理解了.总结如下: 这里假设最普通的情况,不考虑Direct IO 的情况.从全家的高度看,要往一个文件中写 ...

最新文章

  1. 关于 eclipse startexplorer插件 快速打开文件夹
  2. clistctrl控件最后插入在后面_用图表控件做一个简单的员工信息查询系统
  3. win7 设置自动关机
  4. OutOfMemoryError/OOM/内存溢出异常实例分析--堆内存溢出
  5. 使用 Swagger 文档化和定义 RESTful API
  6. java多线程--多线程基础小结
  7. kubernetes安装_kubernetes安装教程之三:安装kubeadm
  8. android linearlayout 间隔
  9. 结合计算机专业谈创新,计算机专业学生创新能力培养论文
  10. python 循环控制语句结束_Python控制语句.while循环语句
  11. javascript中的原型
  12. 优秀的测试网站(转载)
  13. UMeditor上传图片无反应
  14. Java 接口和抽象类的异同点
  15. Linux设备驱动——驱动模型之基本结构
  16. ios UISearchController
  17. HTML动态视频背景全代码
  18. 国家开放大学专科计算机应用实训项目,国家开放大学电大专科《微机系统与维护》网络课实训1实训3作业及答案.docx...
  19. Win7系统如何卸载残留无用驱动设备
  20. oracle获取当前时间

热门文章

  1. 第七十四期:从bug看11种编程语言演化史,果然如今Python比较流行
  2. 第十二期:面试官问你什么是消息队列?把这篇甩给他!
  3. 玩转oracle 11g(27):ora-12154和客户端版本低
  4. centos7搭建apache服务器(亲测可用)
  5. centos源码安装PHP
  6. 计算机面试的时候写过的代码,程序员悲催瞬间:来之不易的美团面试,我尽然挂了(还原真实场景)...
  7. oracle数据库归档闪回,[Oracle]Oracle的闪回归档
  8. JS之返回数组指定元素的slice
  9. poj 4468Spy(kmp算法)
  10. linux分区从1开始,Linux 学习笔记 1 使用最小的系统,从分区安装系统开始