点击打开链接

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函数传递参数的寻找(下)的更多相关文章

  1. linux中 probe函数的何时调用的?

    点击打开链接 linux中 probe函数何时调用的 所以的驱动教程上都说:只有设备和驱动的名字匹配,BUS就会调用驱动的probe函数,但是有时我们要看看probe函数里面到底做了什么,还有传递给p ...

  2. linux中probe函数中传递的参数来源(上)

    点击打开链接 上一篇中,我们追踪了probe函数在何时调用,知道了满足什么条件会调用probe函数,但probe函数中传递的参数我们并不知道在何时定义,到底是谁定义的,反正不是我们在驱动中定义的(当然 ...

  3. 深入理解python中函数传递参数是值传递还是引用传递

    深入理解python中函数传递参数是值传递还是引用传递 目前网络上大部分博客的结论都是这样的: Python不允许程序员选择采用传值还是传 引用.Python参数传递采用的肯定是"传对象引用 ...

  4. Python中函数传递参数有四种形式

    Python中函数传递参数有四种形式 fun1(a,b,c) fun2(a=1,b=2,c=3) fun3(*args) fun4(**kargs) 四种中最常见是前两种,基本上一般点的教程都会涉及, ...

  5. python 函数传递参数的多种方法

    python中函数根据是否有返回值可以分为四种:无参数无返回值,无参数有返回值,有参数无返回值,有参数有返回值. Python中函数传递参数的形式主要有以下五种,分别为位置传递,关键字传递,默认值传递 ...

  6. C++向main函数传递参数的方法(实例已上传至github)

    通常情况下,我们定义的main函数都只有空形参列表: int main(){...} 然而,有时我们确实需要给mian传递实参,一种常见的情况是用户设置一组选项来确定函数所要执行的操作.例如,假定ma ...

  7. jsp中四种传递参数的方法

    jsp中四种传递参数的方法如下: 1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="i ...

  8. scrapy回调函数传递参数

    scrapy.Request 的callback传参的两种方式 1.使用 lambda方式传递参数 def parse(self, response): for sel in response.xpa ...

  9. open()函数 linux中open函数使用

    来源:http://www.cnblogs.com/songfeixiang/p/3733855.html   linux中open函数使用 open函数用来打开一个设备,他返回的是一个整型变量,如果 ...

随机推荐

  1. [LeetCode] Image Smoother 图片平滑器

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

  2. html checkbox样式美化

    思路:使用label结合checkbox,背景图片进行美化. 原理: 1. for 属性规定 label 与哪个表单元素绑定,显式绑定和隐式绑定,均可实现checkbox的选用与取消效果,具体见:&l ...

  3. Java 中的时间日期 API

    自从 14 年发布 Java 8 以后,我们古老 java.util.Date 终于不再是我们 Java 里操作日期时间的唯一的选择. 其实 Java 里的日期时间的相关 API 一直为世猿诟病,不仅 ...

  4. 重载运算符“ <<” 和“>>” 运算符

    :" <<  "   "  >>  " 的重载作为友元函数重载,有两种方法:1,把变量作为public,就可以不用友元声明:2,先友元声 ...

  5. [ZJOI2010]基站选址

    题目描述 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离第1个村庄的距离为Di.需要在这些村庄中建立不超过K个通讯基站,在第i个村庄建立基站的费用为Ci.如果在距离第i个村庄不超过Si的范 ...

  6. hdu 5340 (manacher)

    Sample Input 2 abc abaadada   Sample Output Yes No 判断是否能成为3个非空回文子串 manacher算法求出个点回文长度,在找出第一个和最后一个保存下 ...

  7. bzoj4034[HAOI2015]树上操作 树链剖分+线段树

    4034: [HAOI2015]树上操作 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 6163  Solved: 2025[Submit][Stat ...

  8. BZOJ1187 [HNOI2007]神奇游乐园(插头dp)

    麻麻我会写插头dp了! 推荐陈丹琦论文:https://wenku.baidu.com/view/3e90d32b453610661ed9f4bd.html 破题调一年 #include <cs ...

  9. django rest-framework 2.请求和响应

    一.请求对象 REST 框架引入Request来扩展常规的HttpRequest,并提供了更灵活的请求解析.Request对象的核心功能是request.data属性. 导入方式: from rest ...

  10. Python Django的分页,Form验证,中间件

    本节内容 Django的分页 Form 中间件 1 Django 分页 1.1 Django自带的分页 1.首先来看下我的测试数据环境 ############ models.py ######### ...