linux中probe函数传递参数的寻找(下)
linux中probe函数传递参数的寻找(下)
通过追寻driver的脚步,我们有了努力的方向:只有找到spi_bus_type的填充device即可,下面该从device去打通,当两个连通之日,也是任督二脉打通之时。先从设备定义去查看,在mach-smdk6410.c中定义了硬件设备信息,从这作为突破口。
/* for mx25lx*/
static void cs_set_level(unsigned line_id, int lvl) {
gpio_direction_output(line_id, lvl);
};
static struct s3c64xx_spi_csinfos3c64xx_spi1_csinfo = {
.fb_delay=0x3,
.line=S3C64XX_GPC(7),
.set_level=cs_set_level,
};
static int mx25lx_ioSetup(struct spi_device*spi)
{
printk(KERN_INFO"mx25lx: setup gpio pins CS and External Int\n");
s3c_gpio_setpull(S3C64XX_GPL(8),S3C_GPIO_PULL_UP); //External interrupt from CAN controller
s3c_gpio_cfgpin(S3C64XX_GPL(8),S3C_GPIO_SFN(3)); //External interrupt from CAN controller (hopefully external interrupt)
//s3c_gpio_cfgpin(S3C64XX_GPL(8),S3C_GPIO_INPUT); //External interrupt from CAN controller
s3c_gpio_setpull(S3C64XX_GPC(7),S3C_GPIO_PULL_NONE); // Manual chipselect pin as used in 6410_set_cs
s3c_gpio_cfgpin(S3C64XX_GPC(7),S3C_GPIO_OUTPUT); // Manualchip select pin as used in 6410_set_cs
return0;
}
static struct mx25lx_platform_datamx25lx_info =
{
.oscillator_frequency= 8000000,
.board_specific_setup= mx25lx_ioSetup,
.transceiver_enable= NULL,
.power_enable= NULL,
};
static struct spi_board_info __initdataforlinx6410_mc251x_info[] =
{
{
.modalias= "mcp2515",
.platform_data = &mx25lx_info,
.irq= IRQ_EINT(16),
.max_speed_hz= 10*1000*1000,
.bus_num= 1,
.chip_select= 0,
.mode= SPI_MODE_0,
.controller_data=&s3c64xx_spi1_csinfo,
},
};
struct platform_device s3c64xx_device_spi0= {
.name = "s3c64xx-spi",
.id = 0,
.num_resources =ARRAY_SIZE(s3c64xx_spi0_resource),
.resource =s3c64xx_spi0_resource,
.dev= {
.dma_mask = &spi_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
.platform_data= &s3c64xx_spi0_pdata,
},
};
static struct platform_device*smdk6410_devices[] __initdata =
{
……
/*addby fatfish*/
&s3c64xx_device_spi0,
&s3c64xx_device_spi1,
};
其中platform_device定义为:
struct platform_device {
constchar * name;
int id;
structdevice dev;
u32 num_resources;
structresource * resource;
conststruct platform_device_id *id_entry;
/*MFD cell pointer */
structmfd_cell *mfd_cell;
/*arch specific additions */
structpdev_archdata archdata;
};
初始化函数如下:
static void __initsmdk6410_machine_init(void)
{
……
s3c64xx_spi_set_info(0,0,1);
s3c64xx_spi_set_info(1,0,1);
spi_register_board_info(forlinx6410_mc251x_info,ARRAY_SIZE(forlinx6410_mc251x_info));
……
}
其中的注册板信息的函数如下,后项参数为1,其中board_list为spi.c中定义的全局变量,即:static LIST_HEAD(board_list);。
int __init
spi_register_board_info(structspi_board_info const *info, unsigned n)
{
structboardinfo *bi;
inti;
bi= kzalloc(n * sizeof(*bi), GFP_KERNEL);
if(!bi)
return-ENOMEM;
for(i = 0; i < n; i++, bi++, info++) {
structspi_master *master;
memcpy(&bi->board_info,info, sizeof(*info));
mutex_lock(&board_lock);
list_add_tail(&bi->list,&board_list);
list_for_each_entry(master,&spi_master_list, list)
spi_match_master_to_boardinfo(master,&bi->board_info);
mutex_unlock(&board_lock);
}
return0;
}
其中结果成员如下:
先加锁,然后将board_list加入链接中,在遍历设备,最关键的函数是:
static voidspi_match_master_to_boardinfo(struct spi_master *master,
structspi_board_info *bi)
{
structspi_device *dev;
if(master->bus_num != bi->bus_num)
return;
dev= spi_new_device(master, bi);
if(!dev)
dev_err(master->dev.parent,"can't create new device for %s\n",
bi->modalias);
}
spi_new_device作用是实例化一个新设备,定义如下:
struct spi_device *spi_new_device(structspi_master *master,
struct spi_board_info *chip)
{
structspi_device *proxy;
int status;
proxy= spi_alloc_device(master);
if(!proxy)
returnNULL;
……
strlcpy(proxy->modalias,chip->modalias, sizeof(proxy->modalias));
proxy->dev.platform_data = (void *)chip->platform_data;
proxy->controller_data= chip->controller_data;
proxy->controller_state= NULL;
status= spi_add_device(proxy);
if(status < 0) {
spi_dev_put(proxy);
returnNULL;
}
returnproxy;
}
拷贝了platform_data,即mx25lx_info。其中的spi_alloc_device函数定义如下:
struct spi_device *spi_alloc_device(structspi_master *master)
{
structspi_device *spi;
structdevice *dev =master->dev.parent;
if(!spi_master_get(master))
returnNULL;
spi= kzalloc(sizeof *spi, GFP_KERNEL);
if(!spi) {
dev_err(dev,"cannot alloc spi_device\n");
spi_master_put(master);
returnNULL;
}
spi->master= master;
spi->dev.parent= dev;
spi->dev.bus= &spi_bus_type;
spi->dev.release= spidev_release;
device_initialize(&spi->dev);
returnspi;
}
在这个定义中将spi_bus_type和dev联系起来,不过此时还没有我们定义的设备信息,设备信息在接下来的赋值中完成。
最后是spi_add_device,将设备信息提交。
int spi_add_device(struct spi_device *spi)
{
staticDEFINE_MUTEX(spi_add_lock);
structdevice *dev = spi->master->dev.parent;
structdevice *d;
intstatus;
……
mutex_lock(&spi_add_lock);
d= bus_find_device_by_name(&spi_bus_type, NULL, dev_name(&spi->dev));
……
status= spi_setup(spi);
if(status < 0) {
dev_err(dev,"can't setup %s, status %d\n",
dev_name(&spi->dev),status);
gotodone;
}
……
done:
mutex_unlock(&spi_add_lock);
returnstatus;
}
最终完成将spi_bus_type与定义的device信息联系起来。由于本人才疏学浅,不正确的地方,恳求大牛指正,在此表示感谢
linux中probe函数传递参数的寻找(下)的更多相关文章
- linux中 probe函数的何时调用的?
点击打开链接 linux中 probe函数何时调用的 所以的驱动教程上都说:只有设备和驱动的名字匹配,BUS就会调用驱动的probe函数,但是有时我们要看看probe函数里面到底做了什么,还有传递给p ...
- linux中probe函数中传递的参数来源(上)
点击打开链接 上一篇中,我们追踪了probe函数在何时调用,知道了满足什么条件会调用probe函数,但probe函数中传递的参数我们并不知道在何时定义,到底是谁定义的,反正不是我们在驱动中定义的(当然 ...
- 深入理解python中函数传递参数是值传递还是引用传递
深入理解python中函数传递参数是值传递还是引用传递 目前网络上大部分博客的结论都是这样的: Python不允许程序员选择采用传值还是传 引用.Python参数传递采用的肯定是"传对象引用 ...
- Python中函数传递参数有四种形式
Python中函数传递参数有四种形式 fun1(a,b,c) fun2(a=1,b=2,c=3) fun3(*args) fun4(**kargs) 四种中最常见是前两种,基本上一般点的教程都会涉及, ...
- python 函数传递参数的多种方法
python中函数根据是否有返回值可以分为四种:无参数无返回值,无参数有返回值,有参数无返回值,有参数有返回值. Python中函数传递参数的形式主要有以下五种,分别为位置传递,关键字传递,默认值传递 ...
- C++向main函数传递参数的方法(实例已上传至github)
通常情况下,我们定义的main函数都只有空形参列表: int main(){...} 然而,有时我们确实需要给mian传递实参,一种常见的情况是用户设置一组选项来确定函数所要执行的操作.例如,假定ma ...
- jsp中四种传递参数的方法
jsp中四种传递参数的方法如下: 1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="i ...
- scrapy回调函数传递参数
scrapy.Request 的callback传参的两种方式 1.使用 lambda方式传递参数 def parse(self, response): for sel in response.xpa ...
- open()函数 linux中open函数使用
来源:http://www.cnblogs.com/songfeixiang/p/3733855.html linux中open函数使用 open函数用来打开一个设备,他返回的是一个整型变量,如果 ...
随机推荐
- [LeetCode] Find Pivot Index 寻找中枢点
Given an array of integers nums, write a method that returns the "pivot" index of this arr ...
- [LeetCode] Longest Word in Dictionary 字典中的最长单词
Given a list of strings words representing an English Dictionary, find the longest word in words tha ...
- [LeetCode] Boundary of Binary Tree 二叉树的边界
Given a binary tree, return the values of its boundary in anti-clockwise direction starting from roo ...
- [LeetCode] Target Sum 目标和
You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symb ...
- MySQL 并行复制从库发生自动重启分析
并行复制从库发生自动重启分析 背景 半同步复制从库在晚上凌晨2点半发生自动重启,另一个异步复制从库在第二天凌晨3点也发生了自动重启. 分析 版本mysql 5.7.16 mysql> show ...
- webpack构建react项目(一)
前言 下面是我们使用到技术栈: webpack + react + redux + react-router + react-thunk + ES6 + .... 注意事项: 建议使用npm5.X 或 ...
- [HAOI2006]数字序列
题目描述 现在我们有一个长度为n的整数序列A.但是它太不好看了,于是我们希望把它变成一个单调严格上升的序列.但是不希望改变过多的数,也不希望改变的幅度太大. 输入输出格式 输入格式: 第一行包含一个数 ...
- hihocoder 1391 树状数组
#1391 : Countries 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There are two antagonistic countries, countr ...
- hdu 3397 线段树双标记
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- bzoj1858[Scoi2010]序列操作 线段树
1858: [Scoi2010]序列操作 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 3079 Solved: 1475[Submit][Statu ...