static s32 tool_i2c_write_no_extra(u8 *buf, u16 len) { s32 ret = -1; ret = gtp_i2c_write(gt_client, buf, len); return ret; }
/******************************************************* Function: Send config. Input: client: i2c device. Output: result of i2c write operation. 1: succeed, otherwise: failed *********************************************************/ s32 gtp_send_cfg(struct i2c_client *client) { s32 ret = 2; #if GTP_DRIVER_SEND_CFG s32 retry = 0; struct goodix_ts_data *ts = i2c_get_clientdata(client); if (ts->fixed_cfg) { GTP_INFO("Ic fixed config, no config sent!"); return 2; } GTP_INFO("driver send config"); for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); if (ret > 0) { break; } } #endif return ret; }
/******************************************************* Function: write i2c end cmd. Input: client: i2c device. Output: numbers of i2c_msgs to transfer. *********************************************************/ s32 gtp_i2c_end_cmd(struct i2c_client *client) { s32 ret = -1; u8 end_cmd_data[2]={0x80, 0x00}; GTP_DEBUG_FUNC(); ret = gtp_i2c_write(client, end_cmd_data, 2); return ret; }
s32 gtp_send_charge_cfg(struct i2c_client *client) { s32 ret = -1; s32 retry = 0; for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(client, charge_config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); if (ret > 0) { break; } } return ret; }
s32 gtp_send_cfg(struct i2c_client *client) { struct goodix_ts_data *ts = i2c_get_clientdata(client); s32 ret = 0; #if GTP_DRIVER_SEND_CFG u8 retry = 0; for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH); if (ret > 0) break; } #endif return ret; }
/******************************************************* Function: Send config Function. Input: client: i2c client. Output: Executive outcomes.0--success,non-0--fail. *******************************************************/ s32 gtp_send_cfg(struct i2c_client *client) { s32 ret = 0; #if GTP_DRIVER_SEND_CFG s32 retry = 0; for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); if (ret > 0) { break; } } #endif return ret; }
/******************************************************* Function: Send config Function. Input: client: i2c client. Output: Executive outcomes.0¡ª¡ªsuccess,non-0¡ª¡ªfail. *******************************************************/ s32 gtp_send_cfg(struct i2c_client *client) { #if GTP_DRIVER_SEND_CFG s32 retry = 0; s32 ret = -1; for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(client, config , GTP_CONFIG_LENGTH + GTP_ADDR_LENGTH); if (ret > 0) { return 0; } } return retry; #else return 0; #endif }
static s32 tool_i2c_write_no_extra(u8* buf, u16 len) { s32 ret = -1; /* s32 i = 0; struct i2c_msg msg; msg.flags = !I2C_M_RD; msg.addr = gt_client->addr; msg.len = len; msg.buf = buf; for (i = 0; i < cmd_head.retry; i++) { ret=i2c_transfer(gt_client->adapter, &msg, 1); if (ret > 0) { break; } } */ ret = gtp_i2c_write(gt_client,buf,len); return ret; }
static int gtp_send_cfg(struct goodix_ts_data *ts) { int ret; #if GTP_DRIVER_SEND_CFG int retry = 0; if (ts->fixed_cfg) { dev_dbg(&ts->client->dev, "Ic fixed config, no config sent!"); ret = 2; } else { for (retry = 0; retry < 5; retry++) { ret = gtp_i2c_write(ts->client, ts->config_data, GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); if (ret > 0) break; } } #endif return ret; }
static void goodix_ts_work_func(struct work_struct *work) { struct goodix_ts_data *ts = NULL; static u16 pre_touch; static u8 pre_key; u8 end_cmd[3] = { GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0 }; u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = { GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF }; u8 touch_num = 0; u8 finger = 0; u8 key_value = 0; u8 *coor_data = NULL; s32 input_x = 0; s32 input_y = 0; s32 input_w = 0; s32 id = 0; s32 i, ret; GTP_DEBUG_FUNC(); ts = container_of(work, struct goodix_ts_data, work); if (ts->enter_update) return; ret = gtp_i2c_read(ts->client, point_data, 12); if (ret < 0) { GTP_ERROR("I2C transfer error. errno:%d\n ", ret); goto exit_work_func; } finger = point_data[GTP_ADDR_LENGTH]; if ((finger & 0x80) == 0) goto exit_work_func; touch_num = finger & 0x0f; if (touch_num > GTP_MAX_TOUCH) goto exit_work_func; if (touch_num > 1) { u8 buf[8 * GTP_MAX_TOUCH] = { (GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff }; ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1)); memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); } #if GTP_HAVE_TOUCH_KEY key_value = point_data[3 + 8 * touch_num]; if (key_value || pre_key) { for (i = 0; i < GTP_MAX_KEY_NUM; i++) input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01 << i)); touch_num = 0; pre_touch = 0; } #endif pre_key = key_value; GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); #if GTP_ICS_SLOT_REPORT if (pre_touch || touch_num) { s32 pos = 0; u16 touch_index = 0; coor_data = &point_data[3]; if (touch_num) { id = coor_data[pos] & 0x0F; touch_index |= (0x01 << id); } GTP_DEBUG("id=%d, touch_index=0x%x, pre_touch=0x%x\n",\ id, touch_index, pre_touch); for (i = 0; i < GTP_MAX_TOUCH; i++) { if (touch_index & (0x01<<i)) { input_x = coor_data[pos + 1] | coor_data[pos + 2] << 8; input_y = coor_data[pos + 3] | coor_data[pos + 4] << 8; input_w = coor_data[pos + 5] | coor_data[pos + 6] << 8; gtp_touch_down(ts, id, input_x, input_y, input_w); pre_touch |= 0x01 << i; pos += 8; id = coor_data[pos] & 0x0F; touch_index |= (0x01<<id); } else { gtp_touch_up(ts, i); pre_touch &= ~(0x01 << i); } } } #else if (touch_num) { for (i = 0; i < touch_num; i++) { coor_data = &point_data[i * 8 + 3]; id = coor_data[0] & 0x0F; input_x = coor_data[1] | coor_data[2] << 8; input_y = coor_data[3] | coor_data[4] << 8; input_w = coor_data[5] | coor_data[6] << 8; gtp_touch_down(ts, id, input_x, input_y, input_w); } } else if (pre_touch) { GTP_DEBUG("Touch Release!"); gtp_touch_up(ts, 0); } pre_touch = touch_num; input_report_key(ts->input_dev, BTN_TOUCH, (touch_num || key_value)); #endif input_sync(ts->input_dev); exit_work_func: if (!ts->gtp_rawdiff_mode) { ret = gtp_i2c_write(ts->client, end_cmd, 3); if (ret < 0) GTP_ERROR("I2C write end_cmd error!"); } if (ts->use_irq) gtp_irq_enable(ts); } static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer) { struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer); GTP_DEBUG_FUNC(); queue_work(goodix_wq, &ts->work); hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME + 6) * 1000000), HRTIMER_MODE_REL); return HRTIMER_NORESTART; } static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id) { struct goodix_ts_data *ts = dev_id; GTP_DEBUG_FUNC(); gtp_irq_disable(ts); queue_work(goodix_wq, &ts->work); return IRQ_HANDLED; } static void gtp_int_sync(struct i2c_client *client, s32 ms) { struct gtp_platform_data *gtp_data = client->dev.platform_data; GTP_GPIO_OUTPUT(gtp_data->irq, 0); GTP_MSLEEP(ms); GTP_GPIO_AS_INT(gtp_data->irq); } void gtp_reset_guitar(struct i2c_client *client, s32 ms) { struct gtp_platform_data *gtp_data = client->dev.platform_data; GTP_DEBUG_FUNC(); /* begin select I2C slave addr */ GTP_GPIO_OUTPUT(gtp_data->reset, 0); GTP_MSLEEP(ms); GTP_GPIO_OUTPUT(gtp_data->irq, client->addr == 0x14); GTP_MSLEEP(2); GTP_GPIO_OUTPUT(gtp_data->reset, 1); /* must > 3ms */ GTP_MSLEEP(6); GTP_GPIO_AS_INPUT(gtp_data->reset); /* end select I2C slave addr */ gtp_int_sync(client, 50); } static s32 gtp_init_panel(struct goodix_ts_data *ts) { s32 ret; #if GTP_DRIVER_SEND_CFG s32 i; u8 check_sum = 0; u8 rd_cfg_buf[16]; u8 cfg_info_group1[] = CTP_CFG_GROUP1; u8 cfg_info_group2[] = CTP_CFG_GROUP2; u8 cfg_info_group3[] = CTP_CFG_GROUP3; u8 *send_cfg_buf[3] = { cfg_info_group1, cfg_info_group2, cfg_info_group3 }; u8 cfg_info_len[3] = { sizeof(cfg_info_group1) / sizeof(cfg_info_group1[0]), sizeof(cfg_info_group2) / sizeof(cfg_info_group2[0]), sizeof(cfg_info_group3) / sizeof(cfg_info_group3[0]) }; for (i = 0; i < 3; i++) { if (cfg_info_len[i] > ts->gtp_cfg_len) ts->gtp_cfg_len = cfg_info_len[i]; } GTP_DEBUG("len1=%d, len2=%d, len3=%d, send_len:%d", cfg_info_len[0], \ cfg_info_len[1], cfg_info_len[2], ts->gtp_cfg_len); if ((!cfg_info_len[1]) && (!cfg_info_len[2])) rd_cfg_buf[GTP_ADDR_LENGTH] = 0; else { rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8; rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff; ret = gtp_i2c_read(ts->client, rd_cfg_buf, 3); if (ret < 0) { GTP_ERROR("Read SENSOR ID failed, " \ "default use group1 config!"); rd_cfg_buf[GTP_ADDR_LENGTH] = 0; } rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x07; } GTP_DEBUG("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]); memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], ts->gtp_cfg_len); #if GTP_CUSTOM_CFG config[RESOLUTION_LOC] = (u8)ts->data->gtp_max_width; config[RESOLUTION_LOC + 1] = (u8)(ts->data->gtp_max_width>>8); config[RESOLUTION_LOC + 2] = (u8)ts->data->gtp_max_height; config[RESOLUTION_LOC + 3] = (u8)(ts->data->gtp_max_height>>8); if (GTP_INT_TRIGGER == 0) /* RISING */ config[TRIGGER_LOC] &= 0xfe; else if (GTP_INT_TRIGGER == 1) /* FALLING */ config[TRIGGER_LOC] |= 0x01; #endif check_sum = 0; for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) check_sum += config[i]; config[ts->gtp_cfg_len] = (~check_sum) + 1; #else if (ts->gtp_cfg_len == 0) ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH; ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH); if (ret < 0) { GTP_ERROR("GTP read resolution & max_touch_num failed, " \ "use default value!"); ts->abs_x_max = ts->data->gtp_max_width; ts->abs_y_max = ts->data->gtp_max_height; ts->int_trigger_type = GTP_INT_TRIGGER; return ret; } #endif GTP_DEBUG_FUNC(); ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03; if ((!ts->abs_x_max) || (!ts->abs_y_max)) { GTP_ERROR("GTP resolution & max_touch_num invalid, " \ "use default value!"); ts->abs_x_max = ts->data->gtp_max_width; ts->abs_y_max = ts->data->gtp_max_height; } /* MUST delay >20ms before send cfg */ GTP_MSLEEP(20); ret = gtp_send_cfg(ts->client); if (ret < 0) { GTP_ERROR("Send config error."); return ret; } GTP_DEBUG("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x", ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type); GTP_MSLEEP(10); return 0; }