码迷,mamicode.com
首页 > 其他好文 > 详细

i2c_drivers个人分析

时间:2015-08-11 20:49:50      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

\arch\arm\mach-mx6\board-mx6q_sabresd.c

 1 static struct i2c_board_info i2c_board_info_rtc[] __initdata = {
 2     //isl1208 does not work on the 1st board that‘s sent to Korea, but we should enbaled it later.
 3 #if 1
 4     {
 5         I2C_BOARD_INFO("isl1208", 0x6F),
 6         //.irq = gpio_to_irq(CYNO_GPIO_R10),
 7     },
 8 #else
 9     //pcf8563 is no longer usned.
10     {
11         I2C_BOARD_INFO("pcf8563", 0x51),
12         //.irq = gpio_to_irq(CYNO_GPIO_R10),
13     },
14 #endif
15 };

 这个busnum号决定了adapter->nr之间的关系,如果相等这把这个总线设备和适配器连接起来

i2c_register_board_info(2, i2c_board_info_rtc, ARRAY_SIZE(i2c_board_info_rtc));

下面我们再来分析下i2c_register_board_info这个文件的定义

在drivers/i2c/i2c-boardinfo.c文件中我们找到这个函数的定义:

 1 int __init
 2 i2c_register_board_info(int busnum, //这个busnum号决定了adapter->nr之间的关系,如果相等这把这个总线设备和适配器连接起来
 3     struct i2c_board_info const *info, unsigned len)
 4 {
 5     int status;
 6 
 7     down_write(&__i2c_board_lock);
 8 
 9     /* dynamic bus numbers will be assigned after the last static one */
10     if (busnum >= __i2c_first_dynamic_bus_num)
11         __i2c_first_dynamic_bus_num = busnum + 1;
12 
13     for (status = 0; len; len--, info++) {
14         struct i2c_devinfo    *devinfo;
15 
16         devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
17         if (!devinfo) {
18             pr_debug("i2c-core: can‘t register boardinfo!\n");
19             status = -ENOMEM;
20             break;
21         }
22 
23         devinfo->busnum = busnum;
24         devinfo->board_info = *info;
25         list_add_tail(&devinfo->list, &__i2c_board_list);
26     }
27 
28     up_write(&__i2c_board_lock);
29 
30     return status;
31 }

在这个函数里面定义了bus_num以及RTC相关信息

下面我们针对这个设备具体分析

我们在/drivers/rtc/rtc-isl1208.c这个文件

static const struct i2c_device_id isl1208_id[] = {
{ "isl1208", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, isl1208_id);

static struct i2c_driver isl1208_driver = {
.driver = {
.name = "rtc-isl1208",
},
.probe = isl1208_probe,
.remove = isl1208_remove,
.id_table = isl1208_id,
};

可以看到isl1208_driver真是这个设备所支持的驱动

一旦一个drivers注册了 定会调用其probe函数去查找其相应的adapter,找到adapter后就注册adapter,使得总线和设备驱动通信

i2c_drivers个人分析

标签:

原文地址:http://www.cnblogs.com/haoxing990/p/4718834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!