编写I2C设备驱动程序时出现探针问题 [英] Probe problem when writing a I2C device driver
问题描述
我是编写linux设备驱动程序的新手,请原谅我有什么愚蠢的问题和我的英语不好^^
我正在尝试为触摸屏编写驱动程序,该驱动程序通过I2C与CPU通讯.
我试图将设备驱动程序添加到linux平台中,并且注册成功,我的意思是驱动程序已加载,但探测功能未启动!
I am a newbie in writing linux device driver, forgive me if anything stupid a asked and my poor English^^
I am trying to write a driver for a touch panel, which communicate with CPU via I2C.
I tried to add a device driver into linux platform, and the register was success, I mean the driver was loaded, but the probe function didn't fired up!!
上面是我编写的驱动程序的部分代码.
Above is partial code of the driver i wrote.
static int i2c_ts_probe(struct i2c_client *client, const struct i2c_device_id * id) {
/* ... */
}
static int i2c_ts_remove(struct i2c_client *client) {
/* ... */
}
static const struct i2c_device_id i2c_ts_id[] = {
{"Capacitive TS", 0},
{ }
};
MODULE_DEVICE_TABLE(i2c, i2c_ts_id);
static struct i2c_driver i2c_ts = {
.id_table = i2c_ts_id,
.probe = i2c_ts_probe,
.remove = i1c_ts_remobe,
.driver = {
.name = "i2c_ts",
},
};
static int __init i2c_ts_init(void) {
return i2c_add_driver(&i2c_ts);
}
static int __init i2c_ts_exit(void) {
return i2c_del_driver(&i2c_ts);
}
module_init(i2c_ts_init);
module_exit(i2c_ts_exit);
以上是平台(/kernel/arch/arm/mach-pxa/saarb.c)中用于注册i2c设备的部分代码.
Above is partial code in platform (/kernel/arch/arm/mach-pxa/saarb.c) used for registering the i2c device.
static struct i2c_board_info i2c_board_info_ts[] = {
{
.type = i2c_ts,
.irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)),
},
};
static void __init saarb_init(void) {
...
i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts));
...
}
任何建议和评论都将受到欢迎,谢谢^^
any suggestion and comment will be welcome, thanks^^
推荐答案
为了使linux设备/驱动程序模型可以探测您的驱动程序,必须有一个设备要求它:通过比较驱动程序的名称来实现("i2c_ts)和i2c_board_info结构中的设备类型.在您的情况下,我猜类型不等于"i2c_ts".
So that the linux device/driver model can probe your driver, there must be a device requesting it: this is achieved by comparing the name of the driver ("i2c_ts") and the type of the device in the i2c_board_info struct. In your case I guess the type is not equal to "i2c_ts".
因此,我建议您使用I2C_BOARD_INFO宏实例化您的设备,如Documentation/i2c/instantiating_devices中所述.
So I would suggest that you use the I2C_BOARD_INFO macro to instantiate your device, as documented in Documentation/i2c/instantiating_devices.
static struct i2c_board_info i2c_board_info_ts[] = {
{
I2C_BOARD_INFO("i2c_ts", 0x12),
.irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)),
},
};
static void __init saarb_init(void) {
...
i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts));
...
}
您还没有为设备提供地址,I2C_BOARD_INFO需要它.阅读触摸屏的数据表以了解该地址是什么.
You had also not given an address to your device, and I2C_BOARD_INFO needs it. Read the datasheet of your touchscreen to know what that address is.
最后,如上所述,请确保i2c_ts_id是正确的.我不确定它在内核中的设备/模块关联机制中是否起作用,但是我要说,它们共享相同的名称,这要少得多了.
Finally, as suggested above, be sure that i2c_ts_id is correct. I am not sure it plays a role in the device/module association mechanism in the kernel, but I would say it's far less confusing it they all share the same name.
这篇关于编写I2C设备驱动程序时出现探针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!