omap3630 linux i2c总线驱动分析,OMAP3630 Linux I2C总线驱动分析

4 OMAP3630 I2C device驱动在Linux内核中,I2C device驱动位于drivers/i2c/chips目录下,可以看到该目录下有很多相关的device驱动,这里以xxxx项目的mma7455为例介绍device驱动的注册过程,对应的device驱动程序为mma7455.c。

既然有device驱动,那么必定有相应的device,I2C的device是什么呢?其实就是我们在1.3节中提到的i2c_client,所以在device驱动注册之前先来了解下i2c_client的注册过程。4.1 Mma7455 device注册    Mma7455 device即i2c_client的创建以及注册分为两步。4.1.1 将mma7455设备信息加入到设备链表    在板级初始化时将I2C device的名称,地址和相关的信息加入到链表__i2c_board_list中,该链表记录了具体开发板上的I2C设备信息。

在board-xxxx.c中,定义了mma7455的设备信息定义如下:

staticstructi2c_board_info __initdata xxxx_i2c_bus3_info[] = {

……

#ifdef CONFIG_SENSORS_MMA7455

{

I2C_BOARD_INFO("mma7455", 0x1D),

.platform_data = &xxxx_mma7455_platform_data,

},

#endif

};

Mma7455加入到设备链表__i2c_board_list的流程图如下图:

65dc7bf2497f30febfd705fae23b620e.gif

图4.1 mma7455加入到I2C设备链表的过程

i2c_register_board_info()函数的定义如下:

int__init i2c_register_board_info(intbusnum,

structi2c_board_infoconst*info, unsigned len)

{

……

for(status = 0; len; len--, info++) {

structi2c_devinfo  *devinfo;

devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);

……

devinfo->busnum = busnum;

devinfo->board_info = *info;

list_add_tail(&devinfo->list, &__i2c_board_list);

}

……

}

4.1.2 创建并注册i2c_client    i2c_client的创建和注册在I2C adapter驱动注册过程中完成,I2C adapter驱动的注册可以参考3.2.2节,i2c_add_numbered_adapter()函数在注册I2C adapter驱动的同时会扫描4.1.1中提到的I2C设备链表__i2c_board_list,如果该总线上有对应的I2C设备,则创建相应的i2c_client,并将其注册到I2C core中。流程图如下所示:

f22059a915b88fe2651d55ebff834efe.gif

图4.2创建并注册i2c_client

相应的代码位于i2c-core.c如下:

staticvoidi2c_scan_static_board_info(structi2c_adapter *adapter)

{

……

list_for_each_entry(devinfo, &__i2c_board_list, list) {

if(devinfo->busnum == adapter->nr

&& !i2c_new_device(adapter,

&devinfo->board_info))

……

}

……

}

在i2c_scan_static_board_info()函数中遍历I2C设备链表__i2c_board_list,设备的总线号和adapter的总线号相等,则使用函数i2c_new_device()创建该设备。

structi2c_client *

i2c_new_device(structi2c_adapter *adap,structi2c_board_infoconst*info)

{

……

client = kzalloc(sizeof*client, GFP_KERNEL);

if(!client)

returnNULL;

client->adapter = adap;

client->dev.platform_data = info->platform_data;

if(info->archdata)

client->dev.archdata = *info->archdata;

client->flags = info->flags;

client->addr = info->addr;

client->irq = info->irq;

strlcpy(client->name, info->type,sizeof(client->name));

……

status = i2c_attach_client(client);

……

}

在函数i2c_new_device()中创建一个i2c_client,初始化该结构体的adapter,addr,name等变量,这里的client->name被初始化为info->type,在4.1.1中,info->type初始化为“mma7455”, client->name后面会用于I2C device和I2C driver匹配时使用,最后调用i2c_attach_client()将该client注册到I2C core。

inti2c_attach_client(structi2c_client *client)

{

structi2c_adapter *adapter = client->adapter;

……

client->dev.parent = &client->adapter->dev;

client->dev.bus = &i2c_bus_type;

……

res = device_register(&client->dev);

……

}

函数i2c_attach_client()进一步初始化i2c_client结构体,将该设备的总线初始化为i2c_bus_type,说明该设备被放在I2C总线上,用于后面跟I2C driver匹配时使用,最后使用device_register(&client->dev)注册该i2c_client设备。4.2 Mma7455 device驱动注册    在mma7455.c中,定义了mma7455的device驱动,代码如下:

staticstructi2c_driver mma7455_driver = {

.driver     = {

.name ="mma7455",

},

.class= I2C_CLASS_HWMON,

.probe      = mma7455_probe,

.remove     = mma7455_remove,

.id_table   = mma7455_id,

……

};

注册的简要示意图如下:

b8244f54218354a47e23cdf5c38dcaa2.gif

图4.3 device驱动的注册

相应的代码位于mma7455.c和i2c-core.c。

staticint__init init_mma7455(void)

{

……

res = i2c_add_driver(&mma7455_driver);

……

return(res);

}

在模块加载的时候首先调用init_mma7455(),然后init_mma7455()调用函数i2c_add_driver()注册mma7455_driver结构体。

inti2c_register_driver(structmodule *owner,structi2c_driver *driver)

{

…….

/* add the driver to the list of i2c drivers in the driver core */

driver->driver.owner = owner;

driver->driver.bus = &i2c_bus_type;

……

res = driver_register(&driver->driver);

if(res)

returnres;

……

}

函数i2c_register_driver()初始化该驱动的总线为i2c_bus_type,然后使用函数driver_register(&driver->driver)注册该驱动,因此内核会在I2C总线上遍历所有I2C设备,由于该mma7455 device驱动的匹配因子name变量为“mma7455”,因此正好和在4.1.2里创建的name也为“mma7455”的i2c client匹配。因此总线的probe函数将会被调用,I2C总线的probe函数为i2c_device_probe(),具体代码如下:

staticinti2c_device_probe(structdevice *dev)

{

structi2c_client   *client = to_i2c_client(dev);

structi2c_driver   *driver = to_i2c_driver(dev->driver);

intstatus;

if(!driver->probe || !driver->id_table)

return-ENODEV;

client->driver = driver;

…….

status = driver->probe(client, i2c_match_id(driver->id_table, client));

……

returnstatus;

}

在i2c_device_probe()函数中,语句client->driver = driver将I2C device和I2C driver绑定,然后直接调用具体设备的probe函数,这里即mma7455的probe函数mma7455_probe()。

    在mma7455_probe()函数会完成一些具体I2C设备相关的初始化等操作,这边就不再详述。0b1331709591d260c1c78e86d0c51c18.png

The OMAP36xx high-performance, multimedia application device is based on the enhanced OMAP™ 3 architecture and is integrated on TI advanced 45-nm process technology. The architecture is designed to provide best-in-class video, image, and graphics processing sufficient to support the following: • Streaming video • 2-dimension/3-dimension (2D/3D) mobile gaming • Video conferencing • High-resolution still image • Video capture in 2.5G wireless terminals, 3G wireless terminals, rich multimedia-featured handsets, and high-performance personal digital assistants (PDAs) The device supports high-level operating systems (OSs) such as: • Android™ OS • Linux® • Symbian OS™ • Windows® CE This OMAP device includes state-of-the-art power-management techniques required for high-performance mobile products. The following subsystems are part of the device: • Microprocessor unit (MPU) subsystem based on the ARM Cortex™-A8 microprocessor • Imaging video and audio (IVA2.2) subsystem with a TMS320C64x™ digital signal processor (DSP) core • POWERVR® SGX530 subsystem for 2D and 3D graphics acceleration to support display and gaming effects • Camera image signal processor (ISP2P) that supports multiple formats and interfacing options to a wide variety of image sensors • Display subsystem with a wide variety of features for multiple concurrent image manipulation, and a programmable interface supporting a wide variety of displays. The display subsystem also supports NTSC/PAL video out. • Level 3 (L3) and level 4 (L4) interconnects that provide high-bandwidth data transfers for multiple initiators to the internal and external memory controllers and to on-chip peripherals The device also offers: • A comprehensive power and clock-management scheme that enables high-performance, low-power operation, and ultralow-power standby features. The device also supports SmartReflex™ adaptative voltage control. This power-management technique for automatic control of the operating voltage of a module reduces the active power consumption. • Connectivity to various cellular modem chipset • Memory stacking feature using the package-on-package (POP) implementation (see Section 1.4, Package-on-Package Concept)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值