编写I2C设备驱动时的探针问题

发布于 2024-09-05 06:46:39 字数 1327 浏览 13 评论 0原文

我是编写 Linux 设备驱动程序的新手,如果有任何愚蠢的问题和我糟糕的英语,请原谅我^^
我正在尝试为触摸屏编写一个驱动程序,它通过 I2C 与 CPU 通信。
我尝试在linux平台上添加设备驱动程序,注册成功,我的意思是驱动程序已加载,但探测功能没有启动!

以上是我编写的驱动程序的部分代码。

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 设备的部分代码。

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));  
    ...  
}

欢迎任何建议和意见,谢谢^^

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);

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^^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野生奥特曼 2024-09-12 06:46:39

为了使 Linux 设备/驱动程序模型能够探测您的驱动程序,必须有一个设备请求它:这是通过比较驱动程序名称(“i2c_ts”)和 i2c_board_info 结构中的设备类型来实现的。在你的情况下,我猜类型不等于“i2c_ts”。

因此,我建议您使用 I2C_BOARD_INFO 宏来实例化您的设备,如 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 需要它。阅读触摸屏的数据表以了解该地址是什么。

最后,如上所述,确保 i2c_ts_id 正确。我不确定它在内核中的设备/模块关联机制中发挥作用,但我想说,如果它们都共享相同的名称,那么就不那么令人困惑了。

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".

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));  
    ... 
}

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.

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.

我的痛♀有谁懂 2024-09-12 06:46:39

仅当设备与驱动程序名称匹配时才会调用探测方法。正如您提到的驱动程序名称为“i2c_ts”,请检查设备树中的设备名称。两者应该相同。

Probe method will only be called when the device matches the driver name.As you have mentioned your driver name as 'i2c_ts' please check your device tree for the device name.Both should be same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文