linux i2c ctp核心流程学习

来源:互联网 发布:js post html代码 编辑:程序博客网 时间:2024/06/05 22:33

以i2c通信的ctp驱动,本质上是一个i2c驱动,i2c驱动是一个platform型的设备驱动。
platform型驱动主要包含platform device和platform driver,当两者都注册并匹配成功后会触发driver的probe函数。
一般来说i2c device在内核里已经注册,用户的主要工作,是编写i2c的driver,即i2c_driver,进行注册,即可完成工作。


i2c_driver例子:
static struct i2c_driver goodix_ts_driver = {
        .class          = I2C_CLASS_HWMON,
        .probe          = goodix_ts_probe,  //最重要函数
        .remove         = goodix_ts_remove,
#ifndef CONFIG_HAS_EARLYSUSPEND
#ifdef CONFIG_PM
        .suspend        = goodix_ts_suspend,
        .resume         = goodix_ts_resume,
#endif
#endif
        .id_table       = goodix_ts_id,//匹配i2c_board_info里的名字
        .driver = {
                .name   = CTP_NAME,
                .owner  = THIS_MODULE,
        },
        .address_list = normal_i2c,
};

定义:
struct i2c_driver {
unsigned int class;


/* Notifies the driver that a new bus has appeared or is about to be
* removed. You should avoid using this, it will be removed in a
* near future.
*/
int (*attach_adapter)(struct i2c_adapter *) __deprecated;
int (*detach_adapter)(struct i2c_adapter *) __deprecated;


/* Standard driver model interfaces */
int (*probe)(struct i2c_client *, const struct i2c_device_id *);  //probe函数
int (*remove)(struct i2c_client *);


/* driver model interfaces that don't relate to enumeration  */
void (*shutdown)(struct i2c_client *);
int (*suspend)(struct i2c_client *, pm_message_t mesg);
int (*resume)(struct i2c_client *);


/* Alert callback, for example for the SMBus alert protocol.
* The format and meaning of the data value depends on the protocol.
* For the SMBus alert protocol, there is a single bit of data passed
* as the alert response's low bit ("event flag").
*/
void (*alert)(struct i2c_client *, unsigned int data);


/* a ioctl like command that can be used to perform specific functions
* with the device.
*/
int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);


struct device_driver driver;
const struct i2c_device_id *id_table;//匹配i2c_board_info里的名字,新架构里没用到?


/* Device detection callback for automatic device creation */
int (*detect)(struct i2c_client *, struct i2c_board_info *);//检测函数
const unsigned short *address_list;//里面要放iic地址
struct list_head clients;//
};


i2c_board_info,某些平台是
/*ctp info*/
static struct sw_device_info ctps[] = {
        { "ft5x_ts", {      0x38},   0xa3, {0x55,0x08,0x02,0x06,0xa3}, 0},
        {   "gt82x", {      0x5d},  0xf7d, {0x13,0x27,0x28          }, 0},
        { "gslX680", {      0x40},   0x00, {0x00                    }, 0},
        {"gt9xx_ts", {0x14, 0x5d}, 0x8140, {0x39                    }, 0},
        {   "gt811", {      0x5d},  0x715, {0x11                    }, 0},
        { "zet622x", {      0x76},   0x00, {0x00                    }, 0},
};
static struct base_info ctps[] = {
        { "ft5x_ts", {      0x38},   0xa3, {0x55,0x08,0x02,0x06,0xa3}},
        {   "gt82x", {      0x5d},  0xf7d, {0x13,0x27,0x28          }},
        { "gslX680", {      0x40},   0x00, {0x00                    }},
        {"gt9xx_ts", {0x14, 0x5d}, 0x8140, {0x39                    }},
        {   "gt811", {      0x5d},  0x715, {0x11                    }},
};
,这里的name要和i2c_device_id匹配,新架构里没用到?




初始化工作:
1.构建i2c_driver,包括添加detect
2.添加i2c_driver


probe函数进行的重要工作:
1,INIT_WORK(&ts->work, goodix_ts_work_func);//添加工作进队列
2,ret = gtp_request_input_dev(ts);//申请input
3,ret = gtp_request_irq(ts); //申请中断,中断响应函数会调度工作队列goodix_ts_work_func
0 0