linux驱动原载-- touch pannel驱动

i2c设备:一. Touch驱动的注册:1. i2c_add_driver(struct i2c_driver  xx_i2c_driver):  这个函数仅是调用 i2c_register_driver(struct module *owner, struct i2c_driver *driver);2. i2c_register_driver(struct mo
摘要由CSDN通过智能技术生成

i2c设备:

一. Touch驱动的注册:

1. i2c_add_driver(struct i2c_driver  xx_i2c_driver): 

这个函数仅是调用 i2c_register_driver(struct module *owner, struct i2c_driver *driver);


2. i2c_register_driver(struct module *owner, s`truct i2c_driver *driver):

主要有两个功能:

a. 初始化 xx_i2c_driver 中的 'struct device_driver’ 结构体(xx_i2c_device),最主要的是初始化 ‘struct device_driver’ 结构体中的 ‘bus’参数,赋值为‘i2c_bus_type(一个在i2c中已初始化的结构体)’。i2c_bus_type 结构体中包含的函数值得研究。

b. 调用 driver_register(struct device_driver *drv) 函数;

c. 创建 struct i2c_client:

 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver) ---> __process_new_driver() ---> i2c_do_add_adapter() ---> i2c_detect() ---> i2c_detect_address() ---> i2c_new_device()


3. driver_register(struct device_driver *drv)函数:

先通过 xx_i2c_device的成员变量name在 i2c_device_list上检测是否该驱动已经被注册,如果没有注册则调用 bus_add_driver(struct device_driver *drv)函数 进行注册。


4. bus_add_driver(struct device_driver *drv)函数:

这个函数主要是将 xx_i2c_driver 和 xx_i2c_device 挂在到 i2c 总线队列上。

到了底层,基本上都是大量的链表,结构体和指针~


PS:整个注册过程中,xx_i2c_device的成员变量 name 起了非常大的作用。



二. Touch的平台数据(platform-data&

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Linux Touch Panel驱动的demo: ```c #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/input.h> #include <linux/i2c.h> #include <linux/delay.h> #define DEVICE_NAME "touchpanel" static struct i2c_device_id touchpanel_id_table[] = { {DEVICE_NAME, 0}, {} }; MODULE_DEVICE_TABLE(i2c, touchpanel_id_table); static int touchpanel_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct input_dev *input; int error = 0; input = input_allocate_device(); if (!input) { dev_err(&client->dev, "input_allocate_device failed\n"); error = -ENOMEM; goto err_free_mem; } input->name = "Touch Panel"; input->id.bustype = BUS_I2C; input->dev.parent = &client->dev; input_set_capability(input, EV_KEY, BTN_TOUCH); error = input_register_device(input); if (error) { dev_err(&client->dev, "input_register_device failed\n"); goto err_free_mem; } return 0; err_free_mem: input_free_device(input); return error; } static int touchpanel_remove(struct i2c_client *client) { struct input_dev *input = i2c_get_clientdata(client); input_unregister_device(input); input_free_device(input); return 0; } static const struct of_device_id touchpanel_of_match[] = { { .compatible = "linux,touchpanel", }, {} }; MODULE_DEVICE_TABLE(of, touchpanel_of_match); static struct i2c_driver touchpanel_driver = { .probe = touchpanel_probe, .remove = touchpanel_remove, .id_table = touchpanel_id_table, .driver = { .name = DEVICE_NAME, .of_match_table = touchpanel_of_match, }, }; module_i2c_driver(touchpanel_driver); MODULE_AUTHOR("Your Name"); MODULE_DESCRIPTION("Touch Panel Driver"); MODULE_LICENSE("GPL"); ``` 这个驱动程序使用I2C总线与触摸屏进行通信,并向输入子系统注册输入设备。在`probe`函数中,它分配了一个新的输入设备并配置其名称、总线类型和父设备。它还设置了该设备支持BTN_TOUCH事件。在`remove`函数中,它注销了输入设备并释放了分配的内存。这个驱动程序还包含了一些必要的Linux模块元数据,如作者、描述和许可证信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值