static int cy8ctst242_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct cy8ctst242_ts_data *cy8ctst242_ts;
struct input_dev *input_dev;
struct device_node *np = client->dev.of_node;
const char *fw_name;
int len,temp_val,err = 0;
#ifdef CY8C242_PROXIMITY
struct input_dev *input_proximity;
#endif
//struct common_ts_platform_data *pdata = client->dev.platform_data;
struct common_ts_platform_data *pdata = &common_ts_info;
TPDBG("Cy8c242_ts cy8ctst242_ts_probe\n");
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
err = -ENODEV;
goto exit_check_functionality_failed;
}
cy8ctst242_ts = kzalloc(sizeof(*cy8ctst242_ts), GFP_KERNEL);
if (!cy8ctst242_ts) {
err = -ENOMEM;
goto exit_alloc_data_failed;
}
g_cy8ctst242_ts = cy8ctst242_ts;
cy8ctst242_ts->platform_data = pdata;
this_client = client;
cy8ctst242_ts->client = client;
i2c_set_clientdata(client, cy8ctst242_ts);
fw_name = "Junda_8076d_vd807.iic";
err = of_property_read_string(np, "cy8c242,fw-name", &fw_name);
if (err && (err != -EINVAL)) {
dev_err(&client->dev, "Unable to read fw name\n");
goto prase_dt_err; }
if (fw_name) {
len = strlen(fw_name);
if (len > CY_FW_NAME_MAX_LEN - 1) {
dev_err(&client->dev, "Invalid firmware name\n");
goto prase_dt_err;
}
strlcpy(cy8ctst242_ts->fw_name, fw_name, len + 1);
}
err = of_property_read_u32(np, "cy8c242,fw-upgrade-id", &temp_val);
if (err && (err!= -EINVAL)) {
dev_err(&client->dev, "Unable to read fw upgrade id1\n");
goto prase_dt_err;
} else if (err!= -EINVAL)
cy8ctst242_ts->update_fw_version= temp_val;
if(cy8ctst242_ts_hw_init()<0)
goto exit_create_singlethread;
mutex_init(&cy8ctst242_ts->lock);
wake_lock_init(&cy8ctst242_ts->wake_lock, WAKE_LOCK_SUSPEND, CY8C242_NAME);
INIT_WORK(&cy8ctst242_ts->pen_event_work, cy8ctst242_ts_pen_irq_work);
INIT_WORK(&cy8ctst242_ts->fw_update_work,fw_update_work);
#ifdef CY8C242_PROXIMITY
INIT_DELAYED_WORK(&cy8ctst242_ts->delayed_work, cy8ctst242_ts_proximity_work);
#endif
cy8ctst242_ts->ts_workqueue = create_singlethread_workqueue(dev_name(&client->dev));
if (!cy8ctst242_ts->ts_workqueue) {
err = -ESRCH;
goto exit_create_singlethread;
}
#ifdef CFG_DETECT_UP_EVENT
dev_dbg(&client->dev,"%s: add up event timer \n",__func__);
init_timer(&_st_up_evnet_timer);
_st_up_evnet_timer.function = cy8ctst242_force_read_up_event;
_st_up_evnet_timer.data = 1;
_sui_last_point_cnt = 0;
msleep(10);
#endif
dev_dbg(&client->dev,"%s IRQ number is %d", client->name, client->irq);
input_dev = input_allocate_device();
if (!input_dev) {
err = -ENOMEM;
dev_err(&client->dev, "failed to allocate input device\n");
goto exit_input_dev_alloc_failed;
}
cy8ctst242_ts->input_dev = input_dev;
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 start*/
if(get_hipad_board_id()==HIPAD_BOARD_ID_CP5217){
screen_max_y=SCREEN_MAX_Y_CP5217;
}else if(get_hipad_board_id()==HIPAD_BOARD_ID_CP5310){
screen_max_y=SCREEN_MAX_Y_CP5310;
}
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 end*/
#ifdef CONFIG_CY8CTST242_MULTITOUCH
set_bit(EV_KEY, input_dev->evbit);
set_bit(EV_ABS, input_dev->evbit);
//set_bit(EV_SYN, input_dev->evbit);
set_bit(BTN_TOUCH, input_dev->keybit);
set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
//set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit);
//set_bit(ABS_MT_POSITION_X, input_dev->absbit);
//set_bit(ABS_MT_POSITION_Y, input_dev->absbit);
//set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit);
//__set_bit(KEY_MENU, input_dev->keybit);
//__set_bit(KEY_BACK, input_dev->keybit);
//__set_bit(KEY_HOME, input_dev->keybit);
//__set_bit(KEY_SEARCH, input_dev->keybit);
input_set_abs_params(input_dev,
ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 start*/
//input_set_abs_params(input_dev,
// ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
input_set_abs_params(input_dev,
ABS_MT_POSITION_Y, 0, screen_max_y, 0, 0);
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 end*/
input_set_abs_params(input_dev,
ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
input_set_abs_params(input_dev,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
#else
set_bit(ABS_X, input_dev->absbit);
set_bit(ABS_Y, input_dev->absbit);
set_bit(ABS_PRESSURE, input_dev->absbit);
set_bit(BTN_TOUCH, input_dev->keybit);
set_bit(EV_ABS, input_dev->evbit);
set_bit(EV_KEY, input_dev->evbit);
input_set_abs_params(input_dev, ABS_X, 0, SCREEN_MAX_X, 0, 0);
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 start*/
//input_set_abs_params(input_dev, ABS_Y, 0, SCREEN_MAX_Y, 0, 0);
input_set_abs_params(input_dev, ABS_Y, 0, screen_max_y, 0, 0);
/*guliangzeng add for cp5217 cp5310 virtual_key self-adaption 20140126 end*/
input_set_abs_params(input_dev,
ABS_PRESSURE, 0, PRESS_MAX, 0 , 0);
#endif
#ifdef TOUCH_VIRTUAL_KEYS
cy8ctst242_ts_virtual_keys_init();
#endif
cy8ctst242_dev_info();
input_dev->name = CY8C242_TS_DEVICE; //dev_name(&client->dev)
err = input_register_device(input_dev);
if (err) {
dev_err(&client->dev,
"cy8ctst242_ts_probe: failed to register input device: %s\n",
dev_name(&client->dev));
goto exit_input_register_device_failed;
}
#ifdef CY8C242_PROXIMITY
input_proximity = input_allocate_device();
if (!input_proximity) {
err = -ENOMEM;
dev_err(&client->dev, "failed to allocate input proximity\n");
goto exit_input_dev_alloc_failed;
}
cy8ctst242_ts->input_proximity = input_proximity;
input_set_abs_params(input_proximity, ABS_DISTANCE, 0, 1, 0, 0);
set_bit(EV_ABS, input_proximity->evbit);
input_proximity->name = "cy8c242_proximity";
err = input_register_device(input_proximity);
if (err) {
dev_err(&client->dev,
"failed to register input proximity: %s\n",
dev_name(&client->dev));
goto exit_input_register_device_failed;
}
/*make sure CTP already finish startup process */
msleep(10);
#endif
dev_dbg(&client->dev,"==register_early_suspend =");
#if defined (CONFIG_HAS_EARLYSUSPEND)
cy8ctst242_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
cy8ctst242_ts->early_suspend.suspend = cy8ctst242_ts_suspend;
cy8ctst242_ts->early_suspend.resume = cy8ctst242_ts_resume;
register_early_suspend(&cy8ctst242_ts.early_suspend);
#endif
msleep(10);
err = misc_register(&cy8c242_misc_device);
if (err < 0) {
pr_err("Register cy8c242 misc device failed\n");
goto err_misc_register;
}
#ifdef CY8C242_PROXIMITY
err = misc_register(&cy8c242_proximity_misc_device);
if (err < 0) {
pr_err("Register cy8c242 proximity misc device failed\n");
goto err_misc_register;
}
#endif
#ifdef SYSFS
//cy8ctst242_create_sysfs(client);
#endif
err = request_irq(client->irq, cy8ctst242_ts_interrupt, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->name, cy8ctst242_ts);
if (err < 0) {
dev_err(&client->dev, "cy8ctst242_probe: request irq failed\n");
goto exit_irq_request_failed;
}
/* fangxiaofei modify for add cy8c242_ts 2013-11-26*/
cy8ctst242_ts_reset();
/* fangxiaofei modify for add cy8c242_ts 2013-11-26*/
cy8c242_ts_del_time_sync();
msleep(10);
cy8c242_ts_add_time();
err = device_create_file(&client->dev, &dev_attr_update_fw);
if (err) {
dev_err(&client->dev, "sys file creation failed\n");
goto free_fw_update_sys;
}
dev_dbg(&client->dev,"%s: ==probe OK =\n",__func__);
return 0;
free_fw_update_sys:
exit_irq_request_failed:
free_irq(client->irq, cy8ctst242_ts);
err_misc_register:
exit_input_dev_alloc_failed:
exit_input_register_device_failed:
input_free_device(input_dev);
cancel_work_sync(&cy8ctst242_ts->pen_event_work);
destroy_workqueue(cy8ctst242_ts->ts_workqueue);
exit_create_singlethread:
prase_dt_err:
i2c_set_clientdata(client, NULL);
kfree(cy8ctst242_ts);
g_cy8ctst242_ts=NULL;
exit_alloc_data_failed:
exit_check_functionality_failed:
dev_err(&client->dev,"%s failed\n", __func__);
return err;
}