drivers/i2c/i2c-dev.c处驱动为用户空间驱动i2c方法。
查看名字 # cat /sys/class/i2c-dev/i2c-0/name
hisi_i2c 可以通过这个名字来查找到设备源码
drivers/i2c/busses/i2c-hisilicon.c:#define HI_I2C "hisi_i2c"
///////////////////////////////////////////////////////////////////////////////
drivers/i2c/busses/i2c-hisilicon.c
#define HI_I2C "hisi_i2c"
///////////////////////////
drivers/i2c/busses/i2c-hisilicon.c
module_init(hi_i2c_module_init);
static int __init hi_i2c_module_init(void)
{
int ret;
//device和driver放在了同一个文件里面来了,三星可不是这么搞得,海思为何这么搞???
ret = platform_add_devices(hi_i2c_devices, ARRAY_SIZE(hi_i2c_devices));
if (ret) {
hi_err("i2c device register failed!\n");
return ret;
}
ret = platform_driver_register(&hi_i2c_driver);
return ret;
}
///////////////////////////////////////////////////////////////
//这里就是板级别设备信息
drivers/i2c/busses/i2c-hisilicon.c
static struct platform_device *hi_i2c_devices[] __initdata = {
#ifdef CONFIG_HI_I2C0
&hi_i2c0_device,
#endif
#ifdef CONFIG_HI_I2C1
&hi_i2c1_device,
#endif
};
//////////////////////////////////////////////////////////////////////////////////
//这里就是板级别设备信息device
drivers/i2c/busses/i2c-hisilicon.c
#ifdef CONFIG_HI_I2C0
static struct resource hi_i2c0_resources[] = {
[0] = {
.start = CONFIG_HI_I2C0_IO_BASE,
.end = CONFIG_HI_I2C0_IO_BASE
+ CONFIG_HI_I2C0_IO_SIZE - 1,
.flags = IORESOURCE_MEM,
},
};
struct hi_platform_i2c hi_i2c0_platform_data = {
.clk_limit = CONFIG_HI_I2C0_CLK_LIMIT,
.i2c_class = I2C_CLASS_DDC,
};
struct platform_device hi_i2c0_device = {
.name = HI_I2C,
.id = 0,
.resource = hi_i2c0_resources,
.num_resources = ARRAY_SIZE(hi_i2c0_resources),
.dev = {
.platform_data = &hi_i2c0_platform_data,
}
};
#endif
/////////////////////////////////////////////////////////////////////////////
这里是驱动driver
drivers/i2c/busses/i2c-hisilicon.c
static struct platform_driver hi_i2c_driver = {
.probe = hi_i2c_probe,
.remove = hi_i2c_remove,
.suspend = hi_i2c_suspend,
.resume = hi_i2c_resume,
.driver = {
.owner = THIS_MODULE,
.name = HI_I2C,
},
};