Makemenuconfig
Location: │
│ -> Device Drivers │
│ -> Input devicesupport │
│ -> Genericinput layer (needed for keyboard, mouse, ...) (INPUT │
│ ->Touchscreens (INPUT_TOUCHSCREEN [=y])
->gslX680
drivers/input/sw-device.c---------Linux kernel modules for Detection i2c device.
static voidsw_devices_events(struct work_struct *work){
device_number =(sizeof(ctps)) / (sizeof(ctps[0]));
ret =sw_register_device_detect(ctps, &c_name, device_number);
static structsw_device_info ctps[] = {
{ "gslX680",0, { 0x40}, 0x00, {0x00 }, 1},
{"gslX680new",0, { 0x40}, 0x00, {0x00 }, 1},
};
static structsw_device_info gsensors[] = {
{ "bma250",0, {0x18, 0x19, 0x08, 0x38}, 0x00, {0x02,0x03,0xf9,0xf8}, 0},
};
drivers/input/touchscreen/gslX680.c
//初始化触摸屏
static int __initgsl_ts_init(void){
if(input_fetch_sysconfig_para(&(config_info.input_type))) {
printk("%s:ctp_fetch_sysconfig_para err.\n", __func__);
return 0;
} else {
input_init_platform_resource(&(config_info.input_type));//获取触摸屏配置对象
}
ctp_get_system_config(){ //获取触摸屏参数
twi_id =config_info.twi_id;
screen_max_x =config_info.screen_max_x;
screen_max_y =config_info.screen_max_y;
revert_x_flag =config_info.revert_x_flag;
revert_y_flag =config_info.revert_y_flag;
exchange_x_y_flag= config_info.exchange_x_y_flag;
}
i2c_add_driver(&gsl_ts_driver);
|
i2c_register_driver(THIS_MODULE,driver)
static structi2c_driver gsl_ts_driver = {
.class =I2C_CLASS_HWMON,
.driver = {
.name =GSLX680_I2C_NAME, ---gslX680
.owner =THIS_MODULE,
},
.probe =gsl_ts_probe,
.remove =gsl_ts_remove,
.id_table =gsl_ts_id,
.suspend = gsl_ts_suspend,
.resume = gsl_ts_resume,
.detect =ctp_detect,
.address_list =normal_i2c,
};
}
//i2c-driver匹配做的事
static intgsl_ts_probe(struct i2c_client *client,
const structi2c_device_id *id){
if(!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {//检查是否支持I2C
dev_err(&client->dev,"I2C functionality not supported\n");
return -ENODEV;
}
gslX680_wq =create_singlethread_workqueue("gslX680_init");//创建单线程中断等待队列
gslX680_resume_wq =create_singlethread_workqueue("gslX680_resume");//创建单线程唤醒等待队列
glsX680_i2c =client; //获得I2C_client
//input_dev的初始化
rc =gsl_ts_init_ts(client, ts){
input_device =input_allocate_device();
//设置可上报按键
__set_bit(EV_ABS,input_device->evbit);
__set_bit(EV_KEY,input_device->evbit);
__set_bit(EV_REP,input_device->evbit);
__set_bit(INPUT_PROP_DIRECT,input_device->propbit);
set_bit(ABS_MT_POSITION_X,input_device->absbit);
set_bit(ABS_MT_POSITION_Y,input_device->absbit);
set_bit(ABS_MT_TOUCH_MAJOR,input_device->absbit);
set_bit(ABS_MT_WIDTH_MAJOR,input_device->absbit);
input_set_abs_params(input_device,ABS_MT_POSITION_X,0, SCREEN_MAX_X, 0, 0);
input_set_abs_params(input_device,ABS_MT_POSITION_Y,0, SCREEN_MAX_Y, 0, 0);
input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR,0, PRESS_MAX, 0, 0);
input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR,0, 200, 0, 0);
staticDECLARE_WORK(glsX680_init_work, glsX680_init_events);
INIT_WORK(&ts->work,gsl_ts_xy_worker); //中断函数
|
static voidgsl_ts_xy_worker(structwork_struct *work){
rc =gsl_ts_read(ts->client, 0x80, ts->touch_data,ts->dd->data_size);
rc =gsl_ts_read( ts->client, 0xbc, read_buf, sizeof(read_buf));
process_gslX680_data(ts);//处理数据
}
rc =input_register_device(input_device);
}
queue_work(gslX680_wq,&glsX680_init_work);
staticDECLARE_WORK(glsX680_init_work,glsX680_init_events);
|
static voidglsX680_init_events (structwork_struct *work) {
ret =input_request_int(&(config_info.input_type),gsl_ts_irq,//申请中断
CTP_IRQ_MODE,ts_init);
|
irqreturn_tgsl_ts_irq(int irq, void*dev_id){
queue_work(ts->wq,&ts->work);
}
}
}