diff --git a/arch/arm/configs/sun8iw12p1smp_defconfig b/arch/arm/configs/sun8iw12p1smp_defconfig index 84301797..f5516aed 100755 --- a/arch/arm/configs/sun8iw12p1smp_defconfig +++ b/arch/arm/configs/sun8iw12p1smp_defconfig @@ -1519,6 +1519,7 @@ CONFIG_TOUCHSCREEN_GT5688=m CONFIG_TOUCHSCREEN_MSG2XXX=m # CONFIG_WAKEUP_BY_MSG2XXX is not set CONFIG_TOUCHSCREEN_FT6X_TS=m +CONFIG_TOUCHSCREEN_GT9XX_TS=m # CONFIG_INPUT_MISC is not set CONFIG_INPUT_SENSOR=y CONFIG_SENSORS_GPADC=y diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 60b63977..83fdcbe7 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1117,4 +1117,5 @@ source "drivers/input/touchscreen/gslx680/Kconfig" source "drivers/input/touchscreen/gt5688/Kconfig" source "drivers/input/touchscreen/s23501t0-g/Kconfig" source "drivers/input/touchscreen/ft6x/Kconfig" +source "drivers/input/touchscreen/gt9xx/Kconfig" endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 8c1b9f31..4258b8e0 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -96,3 +96,4 @@ obj-$(CONFIG_INPUT_TOUCHSCREEN) += gslx680/ obj-y += gt5688/ obj-y += s23501t0-g/ obj-y += ft6x/ +obj-y += gt9xx/ diff --git a/drivers/input/touchscreen/gt9xx/Kconfig b/drivers/input/touchscreen/gt9xx/Kconfig new file mode 100755 index 00000000..ab1ef452 --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/Kconfig @@ -0,0 +1,10 @@ +# +# Touchscreen driver configuration +# +config TOUCHSCREEN_GT9XX_TS + tristate "gt9xx touchscreen driver" + depends on INPUT && I2C + default m + help + gt9xx touchscreen driver + diff --git a/drivers/input/touchscreen/gt9xx/Makefile b/drivers/input/touchscreen/gt9xx/Makefile new file mode 100755 index 00000000..9dfcd402 --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/Makefile @@ -0,0 +1,9 @@ +# +# Makefile for the touchscreen drivers. +# + +# Each configuration option enables a list of files. + +obj-$(CONFIG_TOUCHSCREEN_GT9XX_TS) += gt9xx_ts.o +gt9xx_ts-objs := goodix_tool.o gt9xx_update.o gt9xx.o + diff --git a/drivers/input/touchscreen/gt9xx/goodix_tool.c b/drivers/input/touchscreen/gt9xx/goodix_tool.c new file mode 100755 index 00000000..86ee93bd --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/goodix_tool.c @@ -0,0 +1,498 @@ +/* drivers/input/touchscreen/goodix_tool.c + * + * 2010 - 2012 Goodix Technology. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be a reference + * to you, when you are integrating the GOODiX's CTP IC into your system, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * Version:1.2 + * V1.0:2012/05/01,create file. + * V1.2:2012/06/08,modify some warning. + * V1.4:2012/08/28,modified to support GT9XX + * + */ + +#include "gt9xx_ts.h" +#define DATA_LENGTH_UINT 512 +#define CMD_HEAD_LENGTH (sizeof(st_cmd_head) - sizeof(u8*)) +#define GOODIX_ENTRY_NAME "goodix_tool" + +#define UPDATE_FUNCTIONS + +#ifdef UPDATE_FUNCTIONS +extern s32 gup_enter_update_mode(struct i2c_client *client); +extern void gup_leave_update_mode(void); +extern s32 gup_update_proc(void *dir); +#endif + +extern void gtp_irq_disable(struct goodix_ts_data *); +extern void gtp_irq_enable(struct goodix_ts_data *); + +#pragma pack(1) +typedef struct{ + u8 wr; //write read flagŁ¬0:R 1:W 2:PID 3: + u8 flag; //0:no need flag/int 1: need flag 2:need int + u8 flag_addr[2]; //flag address + u8 flag_val; //flag val + u8 flag_relation; //flag_val:flag 0:not equal 1:equal 2:> 3:< + u16 circle; //polling cycle + u8 times; //plling times + u8 retry; //I2C retry times + u16 delay; //delay befor read or after write + u16 data_len; //data length + u8 addr_len; //address length + u8 addr[2]; //address + u8 res[3]; //reserved + u8* data; //data pointer +}st_cmd_head; +#pragma pack() +st_cmd_head cmd_head; + +static struct i2c_client *gt_client = NULL; + +static struct proc_dir_entry *goodix_proc_entry; + +static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data); +static s32 goodix_tool_read( char *page, char **start, off_t off, int count, int *eof, void *data ); +static s32 (*tool_i2c_read)(u8 *, u16); +static s32 (*tool_i2c_write)(u8 *, u16); + +s32 DATA_LENGTH = 0; +s8 IC_TYPE[16] = {0}; + +static s32 tool_i2c_read_no_extra(u8* buf, u16 len) +{ + s32 ret = -1; + s32 i = 0; + struct i2c_msg msgs[2]; + + msgs[0].flags = !I2C_M_RD; + msgs[0].addr = gt_client->addr; + msgs[0].len = cmd_head.addr_len; + msgs[0].buf = &buf[0]; + + msgs[1].flags = I2C_M_RD; + msgs[1].addr = gt_client->addr; + msgs[1].len = len; + msgs[1].buf = &buf[GTP_ADDR_LENGTH]; + + for (i = 0; i < cmd_head.retry; i++) { + ret=i2c_transfer(gt_client->adapter, msgs, 2); + if (ret > 0) { + break; + } + } + return ret; +} + +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; + } + } + return ret; +} + +static s32 tool_i2c_read_with_extra(u8* buf, u16 len) +{ + s32 ret = -1; + u8 pre[2] = {0x0f, 0xff}; + u8 end[2] = {0x80, 0x00}; + + tool_i2c_write_no_extra(pre, 2); + ret = tool_i2c_read_no_extra(buf, len); + tool_i2c_write_no_extra(end, 2); + + return ret; +} + +static s32 tool_i2c_write_with_extra(u8* buf, u16 len) +{ + s32 ret = -1; + u8 pre[2] = {0x0f, 0xff}; + u8 end[2] = {0x80, 0x00}; + + tool_i2c_write_no_extra(pre, 2); + ret = tool_i2c_write_no_extra(buf, len); + tool_i2c_write_no_extra(end, 2); + + return ret; +} + +static void register_i2c_func(void) +{ +// if (!strncmp(IC_TYPE, "GT818", 5) || !strncmp(IC_TYPE, "GT816", 5) +// || !strncmp(IC_TYPE, "GT811", 5) || !strncmp(IC_TYPE, "GT818F", 6) +// || !strncmp(IC_TYPE, "GT827", 5) || !strncmp(IC_TYPE,"GT828", 5) +// || !strncmp(IC_TYPE, "GT813", 5)) + if (strncmp(IC_TYPE, "GT8110", 6) && strncmp(IC_TYPE, "GT8105", 6) + && strncmp(IC_TYPE, "GT801", 5) && strncmp(IC_TYPE, "GT800", 5) + && strncmp(IC_TYPE, "GT801PLUS", 9) && strncmp(IC_TYPE, "GT811", 5) + && strncmp(IC_TYPE, "GTxxx", 5)) { + tool_i2c_read = tool_i2c_read_with_extra; + tool_i2c_write = tool_i2c_write_with_extra; + GTP_DEBUG("I2C function: with pre and end cmd!"); + }else { + tool_i2c_read = tool_i2c_read_no_extra; + tool_i2c_write = tool_i2c_write_no_extra; + GTP_INFO("I2C function: without pre and end cmd!"); + } +} + +static void unregister_i2c_func(void) +{ + tool_i2c_read = NULL; + tool_i2c_write = NULL; + GTP_INFO("I2C function: unregister i2c transfer function!"); +} + +static const struct file_operations proc_fops = { + .read = goodix_tool_read, + .write = goodix_tool_write, + .owner = THIS_MODULE, +}; + +s32 init_wr_node(struct i2c_client *client) +{ + s32 i; + + gt_client = client; + memset(&cmd_head, 0, sizeof(cmd_head)); + cmd_head.data = NULL; + + i = 5; + while ((!cmd_head.data) && i) + { + cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL); + if (NULL != cmd_head.data){ + break; + } + i--; + } + + if (i) { + DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH; + GTP_INFO("Applied memory size:%d.", DATA_LENGTH); + }else { + GTP_ERROR("Apply for memory failed."); + return FAIL; + } + + cmd_head.addr_len = 2; + cmd_head.retry = 5; + + register_i2c_func(); + + goodix_proc_entry = proc_create(GOODIX_ENTRY_NAME, 0666, NULL, &proc_fops); + if (goodix_proc_entry == NULL) { + GTP_ERROR("Couldn't create proc entry!"); + return FAIL; + } + return SUCCESS; +} + +void uninit_wr_node(void) +{ + kfree(cmd_head.data); + cmd_head.data = NULL; + unregister_i2c_func(); + remove_proc_entry(GOODIX_ENTRY_NAME, NULL); +} + +static u8 relation(u8 src, u8 dst, u8 rlt) +{ + u8 ret = 0; + + switch (rlt) + { + case 0: + ret = (src != dst) ? true : false; + break; + + case 1: + ret = (src == dst) ? true : false; + GTP_DEBUG("equal:src:0x%02x dst:0x%02x ret:%d.", src, dst, (s32)ret); + break; + + case 2: + ret = (src > dst) ? true : false; + break; + + case 3: + ret = (src < dst) ? true : false; + break; + + case 4: + ret = (src & dst) ? true : false; + break; + + case 5: + ret = (!(src | dst)) ? true : false; + break; + + default: + ret = false; + break; + } + + return ret; +} + +/******************************************************* +Function: + Comfirm function. +Input: + None. +Output: + Return write length. +********************************************************/ +static u8 comfirm(void) +{ + s32 i = 0; + u8 buf[32]; + +// memcpy(&buf[GTP_ADDR_LENGTH - cmd_head.addr_len], &cmd_head.flag_addr, cmd_head.addr_len); +// memcpy(buf, &cmd_head.flag_addr, cmd_head.addr_len);//Modified by Scott, 2012-02-17 + memcpy(buf, cmd_head.flag_addr, cmd_head.addr_len); + + for (i = 0; i < cmd_head.times; i++) { + if (tool_i2c_read(buf, 1) <= 0) { + GTP_ERROR("Read flag data failed!"); + return FAIL; + } + + if (true == relation(buf[GTP_ADDR_LENGTH], cmd_head.flag_val, cmd_head.flag_relation)) { + GTP_DEBUG("value at flag addr:0x%02x.", buf[GTP_ADDR_LENGTH]); + GTP_DEBUG("flag value:0x%02x.", cmd_head.flag_val); + break; + } + + msleep(cmd_head.circle); + } + + if (i >= cmd_head.times) { + GTP_ERROR("Didn't get the flag to continue!"); + return FAIL; + } + + return SUCCESS; +} + +/******************************************************* +Function: + Goodix tool write function. +Input: + standard proc write function param. +Output: + Return write length. +********************************************************/ +static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data) +{ + s32 ret = 0; + GTP_DEBUG_FUNC(); + GTP_DEBUG_ARRAY((u8*)buff, len); + + ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH); + if(ret){ + GTP_ERROR("copy_from_user failed."); + } + + GTP_DEBUG("wr :0x%02x.", cmd_head.wr); + GTP_DEBUG("flag:0x%02x.", cmd_head.flag); + GTP_DEBUG("flag addr:0x%02x%02x.", cmd_head.flag_addr[0], cmd_head.flag_addr[1]); + GTP_DEBUG("flag val:0x%02x.", cmd_head.flag_val); + GTP_DEBUG("flag rel:0x%02x.", cmd_head.flag_relation); + GTP_DEBUG("circle :%d.", (s32)cmd_head.circle); + GTP_DEBUG("times :%d.", (s32)cmd_head.times); + GTP_DEBUG("retry :%d.", (s32)cmd_head.retry); + GTP_DEBUG("delay :%d.", (s32)cmd_head.delay); + GTP_DEBUG("data len:%d.", (s32)cmd_head.data_len); + GTP_DEBUG("addr len:%d.", (s32)cmd_head.addr_len); + GTP_DEBUG("addr:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]); + GTP_DEBUG("len:%d.", (s32)len); + GTP_DEBUG("buf[20]:0x%02x.", buff[CMD_HEAD_LENGTH]); + + if (1 == cmd_head.wr) { + // copy_from_user(&cmd_head.data[cmd_head.addr_len], &buff[CMD_HEAD_LENGTH], cmd_head.data_len); + ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len); + if(ret){ + GTP_ERROR("copy_from_user failed."); + } + memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len); + + GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len); + GTP_DEBUG_ARRAY((u8*)&buff[CMD_HEAD_LENGTH], cmd_head.data_len); + + if (1 == cmd_head.flag) { + if (FAIL == comfirm()) { + GTP_ERROR("[WRITE]Comfirm fail!"); + return FAIL; + } + }else if (2 == cmd_head.flag) { + //Need interrupt! + } + + if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], + cmd_head.data_len + cmd_head.addr_len) <= 0) { + GTP_ERROR("[WRITE]Write data failed!"); + return FAIL; + } + + GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],cmd_head.data_len + cmd_head.addr_len); + if (cmd_head.delay) { + msleep(cmd_head.delay); + } + + return cmd_head.data_len + CMD_HEAD_LENGTH; + }else if (3 == cmd_head.wr) { //Write ic type + ret = copy_from_user(&cmd_head.data[0], &buff[CMD_HEAD_LENGTH], cmd_head.data_len); + if(ret) { + GTP_ERROR("copy_from_user failed."); + } + memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len); + register_i2c_func(); + return cmd_head.data_len + CMD_HEAD_LENGTH; + }else if (5 == cmd_head.wr) { + //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len); + return cmd_head.data_len + CMD_HEAD_LENGTH; + }else if (7 == cmd_head.wr) {//disable irq! + gtp_irq_disable(i2c_get_clientdata(gt_client)); + return CMD_HEAD_LENGTH; + } else if (9 == cmd_head.wr) { //enable irq! + gtp_irq_enable(i2c_get_clientdata(gt_client)); + return CMD_HEAD_LENGTH; + }else if(17 == cmd_head.wr) { + struct goodix_ts_data *ts = i2c_get_clientdata(gt_client); + ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len); + if(ret) { + GTP_DEBUG("copy_from_user failed."); + } + if(cmd_head.data[GTP_ADDR_LENGTH]) { + GTP_DEBUG("gtp enter rawdiff."); + ts->gtp_rawdiff_mode = true; + }else { + ts->gtp_rawdiff_mode = false; + GTP_DEBUG("gtp leave rawdiff."); + } + return CMD_HEAD_LENGTH; + } +#ifdef UPDATE_FUNCTIONS + else if (11 == cmd_head.wr) {//Enter update mode! + if (FAIL == gup_enter_update_mode(gt_client)) { + return FAIL; + } + }else if (13 == cmd_head.wr) {//Leave update mode! + gup_leave_update_mode(); + }else if (15 == cmd_head.wr) { //Update firmware! + show_len = 0; + total_len = 0; + memset(cmd_head.data, 0, cmd_head.data_len + 1); + memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len); + + if (FAIL == gup_update_proc((void*)cmd_head.data)) { + return FAIL; + } + } +#endif + + return CMD_HEAD_LENGTH; +} + +/******************************************************* +Function: + Goodix tool read function. +Input: + standard proc read function param. +Output: + Return read length. +********************************************************/ +static s32 goodix_tool_read( char *page, char **start, off_t off, int count, int *eof, void *data ) +{ + GTP_DEBUG_FUNC(); + + if (cmd_head.wr % 2) { + return FAIL; + }else if (!cmd_head.wr) { + u16 len = 0; + s16 data_len = 0; + u16 loc = 0; + + if (1 == cmd_head.flag) { + if (FAIL == comfirm()) { + GTP_ERROR("[READ]Comfirm fail!"); + return FAIL; + } + }else if (2 == cmd_head.flag) { + //Need interrupt! + } + + memcpy(cmd_head.data, cmd_head.addr, cmd_head.addr_len); + GTP_DEBUG("[CMD HEAD DATA] ADDR:0x%02x%02x.", cmd_head.data[0], cmd_head.data[1]); + GTP_DEBUG("[CMD HEAD ADDR] ADDR:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]); + if (cmd_head.delay) { + msleep(cmd_head.delay); + } + data_len = cmd_head.data_len; + while(data_len > 0) { + if (data_len > DATA_LENGTH) { + len = DATA_LENGTH; + }else { + len = data_len; + } + data_len -= DATA_LENGTH; + if (tool_i2c_read(cmd_head.data, len) <= 0) { + GTP_ERROR("[READ]Read data failed!"); + return FAIL; + } + memcpy(&page[loc], &cmd_head.data[GTP_ADDR_LENGTH], len); + loc += len; + + GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH], len); + GTP_DEBUG_ARRAY(page, len); + } + }else if (2 == cmd_head.wr) { + // memcpy(page, "gt8", cmd_head.data_len); + // memcpy(page, "GT818", 5); + // page[5] = 0; + + GTP_DEBUG("Return ic type:%s len:%d.", page, (s32)cmd_head.data_len); + return cmd_head.data_len; + //return sizeof(IC_TYPE_NAME); + }else if (4 == cmd_head.wr) { + page[0] = show_len >> 8; + page[1] = show_len & 0xff; + page[2] = total_len >> 8; + page[3] = total_len & 0xff; + return cmd_head.data_len; + }else if (6 == cmd_head.wr) { + //Read error code! + }else if (8 == cmd_head.wr) { //Read driver version + // memcpy(page, GTP_DRIVER_VERSION, strlen(GTP_DRIVER_VERSION)); + s32 tmp_len; + tmp_len = strlen(GTP_DRIVER_VERSION); + memcpy(page, GTP_DRIVER_VERSION, tmp_len); + page[tmp_len] = 0; + } + + return cmd_head.data_len; +} diff --git a/drivers/input/touchscreen/gt9xx/gt9xx.c b/drivers/input/touchscreen/gt9xx/gt9xx.c new file mode 100755 index 00000000..9aab9586 --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/gt9xx.c @@ -0,0 +1,1515 @@ +/* drivers/input/touchscreen/gt9xx.c + * + * 2010 - 2012 Goodix Technology. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be a reference + * to you, when you are integrating the GOODiX's CTP IC into your system, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * Version:1.4 + * Author:andrew@goodix.com + * Release Date:2012/12/12 + * Revision record: + * V1.0:2012/08/31,first Release + * V1.2:2012/10/15,modify gtp_reset_guitar,slot report,tracking_id & 0x0F + * V1.4:2012/12/12,modify gt9xx_update.c + * + */ + +#include +#include "gt9xx_ts.h" +#include + +#if GTP_ICS_SLOT_REPORT + #include +#endif + +static const char *goodix_ts_name = "gt9xx"; +static struct workqueue_struct *goodix_wq; +struct i2c_client * i2c_connect_client = NULL; +static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] + = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; + +#if GTP_HAVE_TOUCH_KEY + static const u16 touch_key_array[] = GTP_KEY_TAB; + #define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0])) +#endif + +static s8 gtp_i2c_test(struct i2c_client *client); +void gtp_reset_guitar(struct i2c_client *client, s32 ms); +void gtp_int_sync(s32 ms); + +#ifdef CONFIG_HAS_EARLYSUSPEND +static void goodix_ts_early_suspend(struct early_suspend *h); +static void goodix_ts_late_resume(struct early_suspend *h); +#endif + +#if GTP_CREATE_WR_NODE +extern s32 init_wr_node(struct i2c_client*); +extern void uninit_wr_node(void); +#endif + +#if GTP_AUTO_UPDATE +extern u8 gup_init_update_proc(struct goodix_ts_data *); +#endif + +#if GTP_ESD_PROTECT +static struct delayed_work gtp_esd_check_work; +static struct workqueue_struct * gtp_esd_check_workqueue = NULL; +static void gtp_esd_check_func(struct work_struct *); +s32 gtp_init_ext_watchdog(struct i2c_client *client); +#endif + +/////////////////////////////////////////////// +//specific tp related macro: need be configured for specific tp + +#define CTP_IRQ_NUMBER (config_info.int_number) +#define CTP_IRQ_MODE (IRQF_TRIGGER_FALLING) +#define CTP_NAME ("gt9xx_ts") +#define SCREEN_MAX_X (screen_max_x) +#define SCREEN_MAX_Y (screen_max_y) +#define PRESS_MAX (255) + + +static int screen_max_x = 0; +static int screen_max_y = 0; +static int revert_x_flag = 0; +static int revert_y_flag = 0; +static int exchange_x_y_flag = 0; +static __u32 twi_id = 0; +static char irq_pin_name[8]; + +static u32 debug_mask = 255; + +enum{ + DEBUG_INIT = 1U << 0, + DEBUG_SUSPEND = 1U << 1, + DEBUG_INT_INFO = 1U << 2, + DEBUG_X_Y_INFO = 1U << 3, + DEBUG_KEY_INFO = 1U << 4, + DEBUG_WAKEUP_INFO = 1U << 5, + DEBUG_OTHERS_INFO = 1U << 6, +}; + +#define dprintk(level_mask,fmt,arg...) if(unlikely(debug_mask & level_mask)) \ + printk("***CTP***"fmt, ## arg) +module_param_named(debug_mask,debug_mask,int,S_IRUGO | S_IWUSR | S_IWGRP); + +static const unsigned short normal_i2c[2] = {0x5d,I2C_CLIENT_END}; +//static const int chip_id_value[3] = {57}; +//static uint8_t read_chip_value[3] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff,0}; +struct ctp_config_info config_info = { + .input_type = CTP_TYPE, + .name = NULL, + .int_number = 0, +}; + +//static void goodix_init_events(struct work_struct *work); +static void goodix_resume_events(struct work_struct *work); +static struct workqueue_struct *goodix_wq; +//static struct workqueue_struct *goodix_init_wq; +static struct workqueue_struct *goodix_resume_wq; +//static DECLARE_WORK(goodix_init_work, goodix_init_events); +static DECLARE_WORK(goodix_resume_work, goodix_resume_events); + +/** + * ctp_detect - Device detection callback for automatic device creation + * return value: + * = 0; success; + * < 0; err + */ +static int ctp_detect(struct i2c_client *client, struct i2c_board_info *info) +{ + struct i2c_adapter *adapter = client->adapter; + int ret = -1; + + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)){ + printk("======return=====\n"); + return -ENODEV; + } + + if(twi_id == adapter->nr){ + dprintk(DEBUG_INIT,"%s: addr = %x\n", __func__, client->addr); + ret = gtp_i2c_test(client); + printk("detect ret %d\n",ret); + if(ret != 2){ + printk("%s:I2C connection might be something wrong \n", __func__); + return -ENODEV; + }else{ + strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE); + printk("======detect ok !=====\n"); + return 0; + } + }else{ + return -ENODEV; + } +} + +/** + * ctp_print_info - sysconfig print function + * return value: + * + */ +void ctp_print_info(struct ctp_config_info info,int debug_level) +{ + if(debug_level == DEBUG_INIT) + { + dprintk(DEBUG_INIT,"info.ctp_used:%d\n",info.ctp_used); + dprintk(DEBUG_INIT,"info.twi_id:%d\n",info.twi_id); + dprintk(DEBUG_INIT,"info.screen_max_x:%d\n",info.screen_max_x); + dprintk(DEBUG_INIT,"info.screen_max_y:%d\n",info.screen_max_y); + dprintk(DEBUG_INIT,"info.revert_x_flag:%d\n",info.revert_x_flag); + dprintk(DEBUG_INIT,"info.revert_y_flag:%d\n",info.revert_y_flag); + dprintk(DEBUG_INIT,"info.exchange_x_y_flag:%d\n",info.exchange_x_y_flag); + dprintk(DEBUG_INIT,"info.irq_gpio_number:%d\n",info.irq_gpio.gpio); + dprintk(DEBUG_INIT,"info.wakeup_gpio_number:%d\n",info.wakeup_gpio.gpio); + } +} + +/** + * ctp_wakeup - function + * + */ +int ctp_wakeup(int status,int ms) +{ + dprintk(DEBUG_INIT,"***CTP*** %s:status:%d,ms = %d\n",__func__,status,ms); + + if (status == 0) { + if(ms == 0) { + __gpio_set_value(config_info.wakeup_gpio.gpio, 0); + }else { + __gpio_set_value(config_info.wakeup_gpio.gpio, 0); + msleep(ms); + __gpio_set_value(config_info.wakeup_gpio.gpio, 1); + } + } + if (status == 1) { + if(ms == 0) { + __gpio_set_value(config_info.wakeup_gpio.gpio, 1); + }else { + __gpio_set_value(config_info.wakeup_gpio.gpio, 1); + msleep(ms); + __gpio_set_value(config_info.wakeup_gpio.gpio, 0); + } + } + msleep(5); + + return 0; +} + +void gtp_set_int_value(int status) +{ + long unsigned int config; + + config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF); + pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config); + + if (1 != SUNXI_PINCFG_UNPACK_VALUE(config)){ + config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,1); + pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);; + } + + __gpio_set_value(CTP_IRQ_NUMBER, status); +} + +void gtp_set_io_int(void) +{ + long unsigned int config; + config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF); + pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config); + + if (4 != SUNXI_PINCFG_UNPACK_VALUE(config)){ + config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,4); + pin_config_set(SUNXI_PINCTRL,irq_pin_name,config); + } +} + +void gtp_io_init(int ms) +{ + ctp_wakeup(0, 0); + msleep(ms); + + gtp_set_int_value(0); + msleep(2); + + ctp_wakeup(1, 0); + msleep(6); + +#if GTP_ESD_PROTECT + // gtp_init_ext_watchdog(client); +#endif +} + +/******************************************************* +Function: + Read data from the i2c slave device. + +Input: + client: i2c device. + buf[0]:operate address. + buf[1]~buf[len]:read data buffer. + len:operate length. + +Output: + numbers of i2c_msgs to transfer +*********************************************************/ +s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len) +{ + struct i2c_msg msgs[2]; + s32 ret = -1; + s32 retries = 0; + + msgs[0].flags = !I2C_M_RD; + msgs[0].addr = client->addr; + msgs[0].len = GTP_ADDR_LENGTH; + msgs[0].buf = &buf[0]; + + msgs[1].flags = I2C_M_RD; + msgs[1].addr = client->addr; + msgs[1].len = len - GTP_ADDR_LENGTH; + msgs[1].buf = &buf[GTP_ADDR_LENGTH]; + + while(retries < 2) { + ret = i2c_transfer(client->adapter, msgs, 2); + if(ret == 2) + break; + retries++; + } + + if(retries >= 2) { + printk("%s:I2C retry timeout, reset chip.", __func__); + } + return ret; +} + +/******************************************************* +Function: + write data to the i2c slave device. + +Input: + client: i2c device. + buf[0]:operate address. + buf[1]~buf[len]:write data buffer. + len:operate length. + +Output: + numbers of i2c_msgs to transfer. +*********************************************************/ +s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len) +{ + struct i2c_msg msg; + s32 ret = -1; + s32 retries = 0; + + msg.flags = !I2C_M_RD; + msg.addr = client->addr; + msg.len = len; + msg.buf = buf; + + while(retries < 2) { + ret = i2c_transfer(client->adapter, &msg, 1); + if (ret == 1) + break; + retries++; + } + + if(retries >= 2) { + printk("%s:I2C retry timeout, reset chip.", __func__); + } + 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: + Disable IRQ Function. + +Input: + ts: i2c client private struct. + +Output: + None. +*******************************************************/ +void gtp_irq_disable(struct goodix_ts_data *ts) +{ + unsigned long irqflags; + int ret; + + dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__); + spin_lock_irqsave(&ts->irq_lock, irqflags); + if (!ts->irq_is_disable) { + ts->irq_is_disable = 1; + ret = input_set_int_enable(&(config_info.input_type), 0); + if (ret < 0) + dprintk(DEBUG_OTHERS_INFO,"%s irq disable failed\n", goodix_ts_name); + } + spin_unlock_irqrestore(&ts->irq_lock, irqflags); +} + +/******************************************************* +Function: + Disable IRQ Function. + +Input: + ts: i2c client private struct. + +Output: + None. +*******************************************************/ +void gtp_irq_enable(struct goodix_ts_data *ts) +{ + unsigned long irqflags = 0; + int ret; + + dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__); + + spin_lock_irqsave(&ts->irq_lock, irqflags); + if (ts->irq_is_disable) { + ts->irq_is_disable = 0; + ret = input_set_int_enable(&(config_info.input_type), 1); + if (ret < 0) + dprintk(DEBUG_OTHERS_INFO,"%s irq enable failed\n", goodix_ts_name); + } + spin_unlock_irqrestore(&ts->irq_lock, irqflags); +} + +/******************************************************* +Function: + Touch down report function. + +Input: + ts:private data. + id:tracking id. + x:input x. + y:input y. + w:input weight. + +Output: + None. +*******************************************************/ +static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w) +{ + dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w); + //GTP_ERROR("source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w); + //printk("=================gtp_touch_down-- joey_parking = %d\n", joey_parking); + + //if(1 == exchange_x_y_flag){ + // swap(x, y); + //} + + if(1 == revert_x_flag){ + x = SCREEN_MAX_X - x; + } + + if(1 == revert_y_flag){ + y = SCREEN_MAX_Y - y; + } + + if(1 == exchange_x_y_flag){ + swap(x, y); + } + + dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w); + +#if GTP_ICS_SLOT_REPORT + input_mt_slot(ts->input_dev, id); + input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id); + input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); + input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); + input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); +#else + input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); + input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); + input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); + input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id); + input_mt_sync(ts->input_dev); +#endif + +} + +/******************************************************* +Function: + Touch up report function. + +Input: + ts:private data. + +Output: + None. +*******************************************************/ +static void gtp_touch_up(struct goodix_ts_data* ts, s32 id) +{ +#if GTP_ICS_SLOT_REPORT + input_mt_slot(ts->input_dev, id); + input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1); + dprintk(DEBUG_X_Y_INFO, "Touch id[%2d] release!", id); +#else + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0); + input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0); + input_mt_sync(ts->input_dev); +#endif +} + +/******************************************************* +Function: + Goodix touchscreen work function. + +Input: + work: work_struct of goodix_wq. + +Output: + None. +*******************************************************/ +static void goodix_ts_work_func(struct work_struct *work) +{ + 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; + static u16 pre_touch = 0; + static u8 pre_key = 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 = 0; + s32 ret = -1; + struct goodix_ts_data *ts = NULL; + + + dprintk(DEBUG_X_Y_INFO,"===enter %s===\n",__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){ + printk("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)); + } + + //printk("pre_touch = %d touch_num = %d,\n",pre_touch, touch_num); + + +#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<input_dev, KEY_POWER, 1); + input_sync(ts->input_dev); + input_report_key(ts->input_dev, KEY_POWER, 0); + input_sync(ts->input_dev); + enter_earlysuspend_flag = 0; + } + */ +#endif + pre_key = key_value; + + dprintk(DEBUG_X_Y_INFO, "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<input_dev); + +exit_work_func: + if(!ts->gtp_rawdiff_mode) { + ret = gtp_i2c_write(ts->client, end_cmd, 3); + if (ret < 0) { + printk("I2C write end_cmd error!"); + } + } + return ; +} + +/******************************************************* +Function: + External interrupt service routine. + +Input: + irq: interrupt number. + dev_id: private data pointer. + +Output: + irq execute status. +*******************************************************/ + +irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id) +{ + struct goodix_ts_data *ts = (struct goodix_ts_data *)dev_id; + dprintk(DEBUG_INT_INFO, "==========------TS Interrupt-----============\n"); + + queue_work(goodix_wq, &ts->work); + return 0; +} + + + + +/******************************************************* +Function: + Eter sleep function. + +Input: + ts:private data. + +Output: + Executive outcomes.0--success,non-0--fail. +*******************************************************/ +static s8 gtp_enter_sleep(struct goodix_ts_data * ts) +{ + s8 ret = -1; + s8 retry = 0; + u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5}; + + dprintk(DEBUG_SUSPEND, "%s start!\n", __func__); + + gtp_set_int_value(0); + + while(retry++ < 2) { + ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); + if (ret > 0) { + dprintk(DEBUG_SUSPEND, "GTP enter sleep!"); + return ret; + } + msleep(10); + } + dprintk(DEBUG_SUSPEND, "GTP send sleep cmd failed."); + + return ret; +} + +/******************************************************* +Function: + Wakeup from sleep mode Function. + +Input: + ts: private data. + +Output: + Executive outcomes.0--success,non-0--fail. +*******************************************************/ +static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts) +{ + u8 retry = 0; + s8 ret = -1; + + gtp_io_init(20); + gtp_set_io_int(); + +#if GTP_POWER_CTRL_SLEEP + while(retry++ < 5) + { + ret = gtp_send_cfg(ts->client); + if (ret > 0) + { + dprintk(DEBUG_SUSPEND, "Wakeup sleep send config success."); + return ret; + } + } + + printk("GTP wakeup sleep failed."); + return ret; +#endif + +} + + +/******************************************************* +Function: + GTP initialize function. + +Input: + ts: i2c client private struct. + +Output: + Executive outcomes.0---succeed. +*******************************************************/ +static s32 gtp_init_panel(struct goodix_ts_data *ts) +{ + s32 ret = -1; + +#if GTP_DRIVER_SEND_CFG + s32 i; + u8 check_sum = 0; + u8 rd_cfg_buf[16]; + int index =0; + + static u8 cfg_info_group1[] = CTP_CFG_GROUP1; + static u8 cfg_info_group2[] = CTP_CFG_GROUP2; + static u8 cfg_info_group3[] = CTP_CFG_GROUP3; + static u8 cfg_info_group4[] = CTP_CFG_GROUP4; + static u8 cfg_info_group5[] = CTP_CFG_GROUP5; + static u8 cfg_info_group6[] = CTP_CFG_GROUP6; + static u8 cfg_info_group7[] = CTP_CFG_GROUP7; + u8 *send_cfg_buf[] = {cfg_info_group1,cfg_info_group2,cfg_info_group3,cfg_info_group4,cfg_info_group5,cfg_info_group6,cfg_info_group7}; + u8 cfg_info_len[] = {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]),\ + sizeof(cfg_info_group4)/sizeof(cfg_info_group4[0]),\ + sizeof(cfg_info_group5)/sizeof(cfg_info_group5[0]),\ + sizeof(cfg_info_group6)/sizeof(cfg_info_group6[0]),\ + sizeof(cfg_info_group7)/sizeof(cfg_info_group7[0])}; +#if 0 //gandy + for(i=0; i<3; i++) + { + if(cfg_info_len[i] > ts->gtp_cfg_len) + { + ts->gtp_cfg_len = cfg_info_len[i]; + } + } +#endif + + 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 0 + if ((!cfg_info_len[1]) && (!cfg_info_len[2])) + { + rd_cfg_buf[GTP_ADDR_LENGTH] = 0; + } + else +#endif + { + 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; + } + +#if 0 + if(screen_max_x == 800 && screen_max_y == 480) + { + if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3) + index = 0; + else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 4) + index = 1; + else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 5) + index = 3; + else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0) + index = 6; + } + else if(screen_max_x == 1024 && screen_max_y == 600) + { + if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0) + index = 5; + else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3) + index = 2; + } +#endif + GTP_DEBUG("CTP name : %s\n",config_info.name); + + if (!strcmp(config_info.name,"gt911_805d5")){ + index = 0; + GTP_DEBUG("gt9xx:index = %d\n",index); + + } else if (!strcmp(config_info.name,"gt911_g912")){ + index = 2; + GTP_DEBUG("gt9xx:index = %d\n",index); + + } else if (!strcmp(config_info.name,"gt911_xw785")){ + index = 3; + GTP_DEBUG("gt9xx:index = %d\n",index); + + }else if (!strcmp(config_info.name,"gt911_mb783q6")){ + index = 4; + GTP_DEBUG("gt9xx:index = %d\n",index); + } + else if (!strcmp(config_info.name,"gt911_1060")){ + index = 5; + GTP_DEBUG("gt9xx:index = %d\n",index); + } else { + index = 1; //default p4 / 6.86 + GTP_DEBUG("gt9xx:index = %d\n",index); + } + + //index = rd_cfg_buf[GTP_ADDR_LENGTH]; + ts->gtp_cfg_len = cfg_info_len[index]; + GTP_DEBUG("gandy---SENSOR ID:%d\n", rd_cfg_buf[GTP_ADDR_LENGTH]); + memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); + memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[index], ts->gtp_cfg_len); + +#if GTP_CUSTOM_CFG + config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; + config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8); + config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; + config[RESOLUTION_LOC + 3] = (u8)(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 //endif GTP_CUSTOM_CFG + + 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 //else DRIVER NEED NOT SEND CONFIG + + 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 = GTP_MAX_WIDTH; + ts->abs_y_max = GTP_MAX_HEIGHT; + ts->int_trigger_type = GTP_INT_TRIGGER; + } +#endif //endif GTP_DRIVER_SEND_CFG + + 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 = GTP_MAX_WIDTH; + ts->abs_y_max = GTP_MAX_HEIGHT; + } + + msleep(100); + ret = gtp_send_cfg(ts->client); + if (ret < 0) + { + printk("\ngandy-----send config error.ret=%d\n",ret); + GTP_ERROR("Send config error."); + } + printk("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x", + ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type); + + msleep(10); + + return 0; +} + +/******************************************************* +Function: + Read goodix touchscreen version function. + +Input: + client: i2c client struct. + version:address to store version info + +Output: + Executive outcomes.0---succeed. +*******************************************************/ +s32 gtp_read_version(struct i2c_client *client, u16* version) +{ + s32 ret = -1; + u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; + + dprintk(DEBUG_INIT, "%s ---start!.---\n", __func__); + + ret = gtp_i2c_read(client, buf, sizeof(buf)); + if (ret < 0) { + printk("GTP read version failed"); + return ret; + } + + if (version) { + *version = (buf[7] << 8) | buf[6]; + } + + if (buf[5] == 0x00) { + printk("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]); + } + else { + printk("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]); + } + return ret; +} + +/******************************************************* +Function: + I2c test Function. + +Input: + client:i2c client. + +Output: + Executive outcomes.0--success,non-0--fail. +*******************************************************/ +static s8 gtp_i2c_test(struct i2c_client *client) +{ + u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; + u8 retry = 0; + s8 ret = -1; + + while(retry++ < 10) { + ret = gtp_i2c_read(client, test, 3); + if (ret > 0) { + return ret; + } + printk("GTP i2c test failed time %d.",retry); + msleep(10); + } + return ret; +} + + +/******************************************************* +Function: + Request input device Function. + +Input: + ts:private data. + +Output: + Executive outcomes.0--success,non-0--fail. +*******************************************************/ +static s8 gtp_request_input_dev(struct goodix_ts_data *ts) +{ + s8 ret = -1; +#if GTP_HAVE_TOUCH_KEY + u8 index = 0; +#endif + + ts->input_dev = input_allocate_device(); + if (ts->input_dev == NULL) { + GTP_ERROR("Failed to allocate input device."); + return -ENOMEM; + } + + ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ; +#if GTP_ICS_SLOT_REPORT + __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); + input_mt_init_slots(ts->input_dev, 255); +#else + ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); +#endif + __set_bit(KEY_POWER, ts->input_dev->keybit); + +#if GTP_HAVE_TOUCH_KEY + for (index = 0; index < GTP_MAX_KEY_NUM; index++) { + input_set_capability(ts->input_dev,EV_KEY,touch_key_array[index]); + } +#endif + +//#if GTP_CHANGE_X2Y +// GTP_SWAP(ts->abs_x_max, ts->abs_y_max); +//#endif + + input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0); + set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); + + ts->input_dev->name = CTP_NAME; + ts->input_dev->phys = "input/goodix-ts"; + ts->input_dev->id.bustype = BUS_I2C; + ts->input_dev->id.vendor = 0xDEAD; + ts->input_dev->id.product = 0xBEEF; + ts->input_dev->id.version = 10427; + ret = input_register_device(ts->input_dev); + if (ret) { + printk("Register %s input device failed", ts->input_dev->name); + return -ENODEV; + } +#ifdef CONFIG_HAS_EARLYSUSPEND + ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; + ts->early_suspend.suspend = goodix_ts_early_suspend; + ts->early_suspend.resume = goodix_ts_late_resume; + register_early_suspend(&ts->early_suspend); +#endif + return 0; +} + + +/******************************************************* +Function: + Goodix touchscreen probe function. + +Input: + client: i2c device struct. + id:device id. + +Output: + Executive outcomes. 0---succeed. +*******************************************************/ +static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + s32 ret = -1; + struct goodix_ts_data *ts; + u16 version_info; + + dprintk(DEBUG_INIT, "GTP Driver Version:%s\n",GTP_DRIVER_VERSION); + //dprintk(DEBUG_INIT, "GTP Driver build@%s,%s\n", __TIME__,__DATE__); + printk("GTP I2C Address:0x%02x\n", client->addr); + + i2c_connect_client = client; + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + printk("I2C check functionality failed.\n"); + return -ENODEV; + } + + ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (ts == NULL) { + printk("Alloc GFP_KERNEL memory failed.\n"); + return -ENOMEM; + } + + memset(ts, 0, sizeof(*ts)); + INIT_WORK(&ts->work, goodix_ts_work_func); + ts->client = client; + i2c_set_clientdata(client, ts); + //ts->irq_lock = SPIN_LOCK_UNLOCKED; + ts->gtp_rawdiff_mode = 0; + + + ret = gtp_i2c_test(client); + if (ret < 0){ + printk("I2C communication ERROR!\n"); + goto exit_device_detect; + } + + goodix_resume_wq = create_singlethread_workqueue("goodix_resume"); + if (goodix_resume_wq == NULL) { + printk("create goodix_resume_wq fail!\n"); + return -ENOMEM; + } + + goodix_wq = create_singlethread_workqueue("goodix_wq"); + if (!goodix_wq) { + printk(KERN_ALERT "Creat goodix_wq workqueue failed.\n"); + return -ENOMEM; + } + +#if GTP_AUTO_UPDATE + ret = gup_init_update_proc(ts); + if (ret < 0) { + printk("Create update thread error."); + } +#else + + ret = gtp_init_panel(ts); + if (ret < 0) { + printk("GTP init panel failed.\n"); + } +#endif + ret = gtp_request_input_dev(ts); + if (ret < 0) { + printk("GTP request input dev failed\n"); + goto exit_device_detect; + } + + ret = gtp_read_version(client, &version_info); + if (ret < 0) { + printk("Read version failed."); + } + + config_info.dev = &(ts->input_dev->dev); + ret = input_request_int(&(config_info.input_type), goodix_ts_irq_handler,CTP_IRQ_MODE, ts); + if (ret) { + printk("Request irq fail!.\n"); + } + spin_lock_init(&ts->irq_lock); + +#if GTP_CREATE_WR_NODE + init_wr_node(client); +#endif + +#if GTP_ESD_PROTECT + INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); + gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); + queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); +#endif + dprintk(DEBUG_INIT, "gt9xx probe success!\n"); + return 0; + exit_device_detect: + i2c_set_clientdata(client, NULL); + kfree(ts); + return ret; +} + + +/******************************************************* +Function: + Goodix touchscreen driver release function. + +Input: + client: i2c device struct. + +Output: + Executive outcomes. 0---succeed. +*******************************************************/ +static int goodix_ts_remove(struct i2c_client *client) +{ + struct goodix_ts_data *ts = i2c_get_clientdata(client); + + dprintk(DEBUG_INIT,"%s start!\n", __func__); +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&ts->early_suspend); +#endif + +#if GTP_CREATE_WR_NODE + uninit_wr_node(); +#endif + +#if GTP_ESD_PROTECT + flush_workqueue(gtp_esd_check_workqueue); + if(gtp_esd_check_workqueue) + destroy_workqueue(gtp_esd_check_workqueue); +#endif + input_free_int(&(config_info.input_type), ts); + flush_workqueue(goodix_wq); + //cancel_work_sync(&goodix_init_work); + cancel_work_sync(&goodix_resume_work); + if(goodix_wq) + destroy_workqueue(goodix_wq); + //destroy_workqueue(goodix_init_wq); + if(goodix_resume_wq) + destroy_workqueue(goodix_resume_wq); + i2c_set_clientdata(ts->client, NULL); + input_unregister_device(ts->input_dev); + kfree(ts); + + return 0; +} + +static void goodix_resume_events (struct work_struct *work) +{ + int ret; + struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client); + + ret = gtp_wakeup_sleep(ts); + if (ret < 0) + printk("resume power on failed\n"); + gtp_irq_enable(ts); +} + +/******************************************************* +Function: + Early suspend function. + +Input: + h:early_suspend struct. + +Output: + None. +*******************************************************/ +#ifdef CONFIG_HAS_EARLYSUSPEND +static void goodix_ts_early_suspend(struct early_suspend *h) +{ + struct goodix_ts_data *ts; + s8 ret = -1; + ts = container_of(h, struct goodix_ts_data, early_suspend); + +#if GTP_ESD_PROTECT + ts->gtp_is_suspend = 1; + cancel_delayed_work_sync(>p_esd_check_work); +#endif + + gtp_irq_disable(ts); + + + cancel_work_sync(&goodix_resume_work); + flush_workqueue(goodix_resume_wq); + ret = cancel_work_sync(&ts->work); + flush_workqueue(goodix_wq); + + ret = gtp_enter_sleep(ts); + if (ret < 0) { + printk("GTP early suspend failed."); + } +} + +/******************************************************* +Function: + Late resume function. + +Input: + h:early_suspend struct. + +Output: + None. +*******************************************************/ +static void goodix_ts_late_resume(struct early_suspend *h) +{ + struct goodix_ts_data *ts; + ts = container_of(h, struct goodix_ts_data, early_suspend); + + queue_work(goodix_resume_wq, &goodix_resume_work);//gandy + +#if GTP_ESD_PROTECT + ts->gtp_is_suspend = 0; + queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); +#endif +} +#else +#ifdef CONFIG_PM +static int goodix_ts_suspend(struct device *dev) +{ + struct goodix_ts_data *ts; + s8 ret = -1; + + ts = dev_get_drvdata(dev); + printk("%s goodix_ts_suspend\n", goodix_ts_name); +#if GTP_ESD_PROTECT + ts->gtp_is_suspend = 1; + cancel_delayed_work_sync(>p_esd_check_work); +#endif + + ret = input_set_int_enable(&(config_info.input_type), 0); + if (ret < 0) + dprintk(DEBUG_SUSPEND,"%s irq disable failed\n", goodix_ts_name); + cancel_work_sync(&goodix_resume_work); + flush_workqueue(goodix_resume_wq); + ret = cancel_work_sync(&ts->work); + flush_workqueue(goodix_wq); + + ret = gtp_enter_sleep(ts); + if (ret < 0) { + printk("GTP suspend failed."); + } + return 0; +} + +static int goodix_ts_resume(struct device *dev) +{ + struct goodix_ts_data *ts; + + ts = dev_get_drvdata(dev); + printk("%s goodix_ts_resume\n", goodix_ts_name); + queue_work(goodix_resume_wq, &goodix_resume_work);//gandy + +#if GTP_ESD_PROTECT + ts->gtp_is_suspend = 0; + queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); +#endif + return 0; +} + +static const struct dev_pm_ops goodix_ts_pm_ops = { + .suspend = goodix_ts_suspend, + .resume = goodix_ts_resume, +}; + +#endif +#endif + +#if GTP_ESD_PROTECT +/******************************************************* +Function: + Initialize external watchdog for esd protect +Input: + client: i2c device. +Output: + result of i2c write operation. + 1: succeed, otherwise: failed +*********************************************************/ +s32 gtp_init_ext_watchdog(struct i2c_client *client) +{ + u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA}; + dprintk(DEBUG_INIT, "Init external watchdog..."); + return gtp_i2c_write(client, opr_buffer, 4); +} +/******************************************************* +Function: + Esd protect function. + Added external watchdog by meta, 2013/03/07 +Input: + work: delayed work +Output: + None. +*******************************************************/ +static void gtp_esd_check_func(struct work_struct *work) +{ + s32 i; + s32 ret = -1; + struct goodix_ts_data *ts = NULL; + u8 test[4] = {0x80, 0x40}; + + dprintk(DEBUG_INIT, "enter %s work!\n", __func__); + + ts = i2c_get_clientdata(i2c_connect_client); + + if (ts->gtp_is_suspend || ts->enter_update) { + return; + } + + for (i = 0; i < 3; i++) { + ret = gtp_i2c_read(ts->client, test, 4); + + dprintk(DEBUG_INIT, "0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]); + if ((ret < 0)) { + // IC works abnormally.. + continue; + }else { + if ((test[2] == 0xAA) || (test[3] != 0xAA)) { + // IC works abnormally.. + i = 3; + break; + }else { + // IC works normally, Write 0x8040 0xAA + test[2] = 0xAA; + gtp_i2c_write(ts->client, test, 3); + break; + } + } + } + + if (i >= 3) { + GTP_DEBUG("IC Working ABNORMALLY, Resetting Guitar..."); + // gtp_reset_guitar(ts->client, 50); + } + + if(!ts->gtp_is_suspend) { + queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); + } + + return; +} +#endif + +static const struct i2c_device_id goodix_ts_id[] = { + { CTP_NAME, 0 }, + { } +}; + +static struct i2c_driver goodix_ts_driver = { + .class = I2C_CLASS_HWMON, + .probe = goodix_ts_probe, + .remove = goodix_ts_remove, + .id_table = goodix_ts_id, + .driver = { + .name = CTP_NAME, + .owner = THIS_MODULE, +#ifndef CONFIG_HAS_EARLYSUSPEND +#ifdef CONFIG_PM + .pm = &goodix_ts_pm_ops, +#endif +#endif + }, + .address_list = normal_i2c, +}; + +static int ctp_get_system_config(void) +{ + ctp_print_info(config_info,DEBUG_INIT); + 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; + //screen_max_x = 1280; + //screen_max_y = 720; + //revert_x_flag = 1; + //revert_y_flag = 1; + //exchange_x_y_flag = 0; + + //printk("===========screen_max_x = %d\n",screen_max_x); + //printk("===========screen_max_y = %d\n",screen_max_y); + + if((screen_max_x == 0) || (screen_max_y == 0)){ + printk("%s:read config error!\n",__func__); + return 0; + } + return 1; +} + +/******************************************************* +Function: + Driver Install function. +Input: + None. +Output: + Executive Outcomes. 0---succeed. +********************************************************/ +static int __init goodix_ts_init(void) +{ + int ret = -1; + + printk("*******************************************\n"); + if (input_sensor_startup(&(config_info.input_type))) { + printk("%s: ctp_startup err.\n", __func__); + return 0; + } else { + ret = input_sensor_init(&(config_info.input_type)); + if (ret != 0) + printk("%s:ctp_ops.init err.\n", __func__); + + } + if (config_info.ctp_used == 0) { + printk("*** ctp_used set to 0 !\n"); + printk("if use ctp,please put the sys_config.fex ctp_used set to 1.\n"); + return 0; + } + if (!ctp_get_system_config()) { + printk("%s:read config fail!\n", __func__); + return ret; + } + input_set_power_enable(&(config_info.input_type), 1); + msleep(20); + sunxi_gpio_to_name(CTP_IRQ_NUMBER,irq_pin_name); + gtp_io_init(20); + + goodix_ts_driver.detect = ctp_detect; + ret = i2c_add_driver(&goodix_ts_driver); + + printk("===== goodix_ts_init =====i2c_add_driver is %d\n",ret); + + dprintk(DEBUG_INIT,"****************************************************************\n"); + return ret; +} + +/******************************************************* +Function: + Driver uninstall function. +Input: + None. +Output: + Executive Outcomes. 0---succeed. +********************************************************/ +static void __exit goodix_ts_exit(void) +{ + printk("GTP driver exited.\n"); + input_set_power_enable(&(config_info.input_type), 0); + i2c_del_driver(&goodix_ts_driver); + input_sensor_free(&(config_info.input_type)); +} + +module_init(goodix_ts_init); +module_exit(goodix_ts_exit); + +MODULE_DESCRIPTION("GTP Series Driver"); +MODULE_LICENSE("GPL"); + diff --git a/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h b/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h new file mode 100755 index 00000000..447212cb --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h @@ -0,0 +1,40 @@ +const unsigned char header_fw_array[] = { + 0x5F,0x00,0x05,0xD0,0x02,0x01,0x3D,0x00,0x01,0x08,0x28, + 0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x18,0x1A,0x1E,0x14,0x86,0x26,0x08,0x3D,0x3B,0x31, + 0x0D,0x00,0x00,0x00,0x21,0x03,0x1D,0x00,0x01,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x5A,0x94,0xC5, + 0x02,0x07,0x00,0x00,0x04,0xB9,0x21,0x00,0x9E,0x29,0x00, + 0x88,0x34,0x00,0x7A,0x41,0x00,0x71,0x51,0x00,0x72,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x10,0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1D, + 0x1E,0x1F,0x20,0x21,0x22,0x0A,0x08,0x06,0x04,0x02,0x00, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0x01 +}; +#if 0 +const unsigned char header_fw_array[] = { + 0x5B,0xE0,0x01,0x56,0x03,0x05,0x35,0x00,0x01,0x0F,0x28, + 0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00, + 0x05,0x17,0x1A,0x1D,0x14,0x86,0x26,0x08,0x2A,0x2C,0xD3, + 0x08,0x00,0x00,0x00,0x99,0x03,0x1D,0x00,0x01,0x00,0x00, + 0x00,0x03,0x64,0x32,0x00,0x00,0x00,0x19,0x3C,0x94,0xC5, + 0x02,0x07,0x00,0x00,0x04,0xC2,0x1B,0x00,0xA5,0x20,0x00, + 0x8C,0x26,0x00,0x75,0x2E,0x00,0x63,0x37,0x00,0x63,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0xFF, + 0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x02,0x04,0x06,0x08,0x0A,0x22,0x21,0x20,0x1F,0x1E,0x1D, + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, + 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x01 +}; +#endif \ No newline at end of file diff --git a/drivers/input/touchscreen/gt9xx/gt9xx_ts.h b/drivers/input/touchscreen/gt9xx/gt9xx_ts.h new file mode 100755 index 00000000..3f597f28 --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/gt9xx_ts.h @@ -0,0 +1,355 @@ +/* drivers/input/touchscreen/gt813_827_828.h + * + * 2010 - 2012 Goodix Technology. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be a reference + * to you, when you are integrating the GOODiX's CTP IC into your system, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * Version:1.0 + * V1.0:2012/08/31,first release. + */ + +#ifndef _LINUX_GOODIX_TOUCH_H +#define _LINUX_GOODIX_TOUCH_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_HAS_EARLYSUSPEND +#include +#endif + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../init-input.h" + +struct goodix_ts_data { + spinlock_t irq_lock; + struct i2c_client *client; + struct input_dev *input_dev; + struct hrtimer timer; + struct work_struct work; + +#ifdef CONFIG_HAS_EARLYSUSPEND + struct early_suspend early_suspend; +#endif + + s32 irq_is_free; + s32 irq_is_disable; + s32 use_irq; + u16 abs_x_max; + u16 abs_y_max; + u8 max_touch_num; + u8 int_trigger_type; + u8 green_wake_mode; + u8 chip_type; + u8 enter_update; + u8 gtp_is_suspend; + u8 gtp_rawdiff_mode; + u8 gtp_cfg_len; +}; + +extern u16 show_len; +extern u16 total_len; +extern struct ctp_config_info config_info; + +//***************************PART1:ON/OFF define******************************* +#define GTP_CUSTOM_CFG 0 +#define GTP_DRIVER_SEND_CFG 1 +#define GTP_HAVE_TOUCH_KEY 1 +#define GTP_POWER_CTRL_SLEEP 1 +#define GTP_AUTO_UPDATE 0 +#define GTP_CHANGE_X2Y 0 +#define GTP_ESD_PROTECT 0 +#define GTP_CREATE_WR_NODE 0 +#define GTP_ICS_SLOT_REPORT 0 + +#define GTP_HEADER_FW_UPDATE 1 +#define GTP_SLIDING_WAKEUP 0 + +#define GTP_DEBUG_ON 0 +#define GTP_DEBUG_ARRAY_ON 0 +#define GTP_DEBUG_FUNC_ON 0 + +//***************************PART2:TODO define********************************** +//STEP_1(REQUIRED):Change config table. +/*TODO: puts the config info corresponded to your TP here, the following is just +a sample config, send this config should cause the chip cannot work normally*/ +//default or float +// sochip,ma805d5 ,768*1024,gt911,COB + +#define CTP_CFG_GROUP1 {\ + 0x42,0x00,0x03,0x00,0x04,0x05,0x35,0x00,0x02,0x08,\ + 0x1E,0x0A,0x55,0x3C,0x03,0x05,0x00,0x00,0x00,0x00,\ + 0x02,0x00,0x07,0x17,0x19,0x1D,0x14,0x8C,0x2E,0x0E,\ + 0x31,0x25,0x46,0x10,0x00,0x00,0x00,0x1B,0x02,0x1D,\ + 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x41,0x96,0x94,0x05,0x02,0x08,0x00,0x00,0x31,\ + 0x0E,0x27,0x5D,0x0F,0x2A,0x89,0x10,0x2E,0xB5,0x11,\ + 0x33,0x65,0x16,0x30,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x00,\ + 0x00,0x01,0x1B,0x0F,0x0A,0x14,0x00,0x00,0x02,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x1C,0x1A,0x18,0x16,0x14,0x12,0x10,0x0E,\ + 0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,\ + 0x10,0x12,0x13,0x14,0x16,0x18,0x1C,0x1D,0x1E,0x1F,\ + 0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x34,0x01} + // s906 yiju +//#define CTP_CFG_GROUP1 { +//0x00,0xE0,0x01,0x20,0x03,0x05,0x01,0x00,0x03,0x9F,0x19,0x0F,0x50,0x3C,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0x19,0x1C,0x14,0x8C,0x2E,0x0E,0x14,0x12,0x96,0x12,0x00,0x00,0x01,0x19,0x03,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x96,0x94,0x85,0x02,0x08,0x00,0x00,0x87,0x13,0x12,0xF8,0x16,0x15,0xE3,0x1B,0x15,0x88,0x20,0x17,0x07,0x27,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,0x10,0x12,0x13,0x14,0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x76,0x01} + +//TODO puts your group2 config info here,if need. +//VDDIO +// 6.86,480*1280,gt911,COB +#define CTP_CFG_GROUP2 {\ +0x41,0x56,0x03,0xE0,0x01,0x05,0x3D,0x00,0x01,0x08,\ +0x28,0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x08,0x18,0x1A,0x1E,0x14,0x86,0x26,0x08,\ +0x2E,0x30,0x0F,0x0A,0x00,0x00,0x00,0x01,0x03,0x1D,\ +0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ +0x00,0x24,0x56,0x94,0xC5,0x02,0x07,0x00,0x00,0x04,\ +0x94,0x27,0x00,0x80,0x2E,0x00,0x6D,0x37,0x00,0x5E,\ +0x42,0x00,0x51,0x4F,0x00,0x51,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,\ +0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ +0x00,0x00,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x0A,0x08,\ +0x06,0x04,0x02,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\ +0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\ +,0x00,0x00,0x00,0x00,0x33,0x01} + + + +//TODO puts your group3 config info here,if need. +//GND +//dingzhi ,g912,800*480,gt911,COB +#define CTP_CFG_GROUP3 {\ + 0x43,0x20,0x03,0xE0,0x01,0x0A,0x0D,0x00,0x01,0x2F,\ + 0x14,0x0F,0x37,0x28,0x03,0x05,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x18,0x1A,0x1E,0x14,0x8C,0x2E,0x0E,\ + 0x3F,0x3D,0x48,0x09,0x00,0x00,0x00,0xBA,0x02,0x1D,\ + 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x1E,0x5A,0x94,0xC5,0x02,0x08,0x00,0x00,0x04,\ + 0xEE,0x21,0x00,0xC6,0x29,0x00,0xA1,0x34,0x00,0x7C,\ + 0x41,0x00,0x6E,0x51,0x00,0x64,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,\ + 0x12,0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,\ + 0x10,0x12,0x13,0x14,0x16,0x18,0x1C,0x1D,0x1E,0x1F,\ + 0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x63,0x01} + +//xinwu,xw785,768*1024,gt911,COB +#define CTP_CFG_GROUP4 {\ + 0x00,0x00,0x05,0xD0,0x02,0x0A,0x0D,0x00,0x01,0x08,0x28,0x05,0x50,0x32,0x03, \ + 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x87,0x28,0x0A, \ + 0x32,0x34,0xB5,0x06,0x00,0x00,0x02,0xBA,0x04,0x25,0x00,0x00,0x00,0x00,0x00, \ + 0x03,0x64,0x32,0x00,0x00,0x00,0x14,0x50,0x94,0xC5,0x02,0x07,0x00,0x00,0x04, \ + 0x92,0x1B,0x00,0x66,0x28,0x00,0x47,0x3C,0x00,0x32,0x5A,0x00,0x27,0x86,0x00, \ + 0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10, \ + 0x12,0x14,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x1F,0x20,0x21,0x22,0x24,0x26,0x1D, \ + 0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \ + 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ + 0x00,0x00,0x00,0x00,0x82,0x01 \ +} +#if 0 +#define CTP_CFG_GROUP4 {\ + 0x00,0x00,0x03,0x00,0x04,0x0A,0x31,0x00,0x01,0x0A,\ + 0x1E,0x0A,0x55,0x3C,0x03,0x05,0x01,0x01,0x00,0x00,\ + 0x12,0x11,0x03,0x17,0x18,0x1A,0x14,0x8C,0x2E,0x0E,\ + 0x19,0x1B,0xC1,0x11,0x00,0x00,0x00,0x9B,0x03,0x1D,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x28,0x7D,0x94,0x85,0x02,0x08,0x00,0x00,0x05,\ + 0x0F,0x17,0xBF,0x11,0x19,0x85,0x13,0x1C,0xAF,0x15,\ + 0x20,0xF5,0x16,0x26,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,\ + 0x12,0x14,0x16,0x18,0x1A,0x1C,0xFF,0xFF,0xFF,0xFF,\ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\ + 0xFF,0xFF,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,\ + 0x10,0x12,0x13,0x14,0x16,0x2A,0x29,0x28,0x26,0x24,\ + 0x22,0x21,0x20,0x1F,0x1E,0x1D,0x1C,0x18,0xFF,0xFF,\ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\ + 0xFF,0xFF,0xFF,0xFF,0xFE,0x01} +#endif +//s906 hangtaijinghuaGT911_COB +#define CTP_CFG_GROUP5 {0x41,0x00,0x03,0x00,0x04,0x05,0x35,0x00,0x01,0x08,0x28,0x09,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x11,0x11,0x04,0x16,0x18,0x1D,0x14,0x8C,0x2E,0x0E,0x5A,0x5C,0x7C,0x06,0x00,0x00,0x00,0x9A,0x02,0x1D,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x87,0x94,0xC5,0x02,0x08,0x00,0x00,0x04,0x97,0x41,0x00,0x8A,0x4C,0x00,0x80,0x5A,0x00,0x78,0x6A,0x00,0x72,0x7C,0x00,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0F,0x10,0x12,0x13,0x14,0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x24,0x26,0x28,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x67,0x01} +//v5_dvb_gt911_1060_1280x720 +#define CTP_CFG_GROUP6 {\ + 0x5F,0x00,0x05,0xD0,0x02,0x01,0x3D,0x00,0x01,0x08,0x28,\ + 0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x18,0x1A,0x1E,0x14,0x86,0x26,0x08,0x3D,0x3B,0x31,\ + 0x0D,0x00,0x00,0x00,0x21,0x03,0x1D,0x00,0x01,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x5A,0x94,0xC5,\ + 0x02,0x07,0x00,0x00,0x04,0xB9,0x21,0x00,0x9E,0x29,0x00,\ + 0x88,0x34,0x00,0x7A,0x41,0x00,0x71,0x51,0x00,0x72,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x10,0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0xFF,\ + 0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1D,\ + 0x1E,0x1F,0x20,0x21,0x22,0x0A,0x08,0x06,0x04,0x02,0x00,\ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\ + 0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0x01} +//s906_opd_gt911_800x480 +#define CTP_CFG_GROUP7 {\ +} +//#define GTP_RST_PORT S5PV210_GPJ3(6) +//#define GTP_INT_PORT S5PV210_GPH1(3) +//#define GTP_INT_IRQ SW_INT_IRQNO_PIO +//#define GTP_INT_CFG S3C_GPIO_SFN(0xF) +//#ifdef CONFIG_ARCH_SUN4I +//#define CTP_IRQ_NO (IRQ_EINT21) +//#elif defined CONFIG_ARCH_SUN5I +//#define CTP_IRQ_NO (IRQ_EINT9) +//#endif +//#define CTP_IRQ_MODE (TRIG_EDGE_NEGATIVE) + +#define GTP_GPIO_AS_INPUT(pin) do{\ + gpio_direction_input(pin);\ + s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);\ + }while(0) +#define GTP_GPIO_AS_INT(pin) do{\ + GTP_GPIO_AS_INPUT(pin);\ + s3c_gpio_cfgpin(pin, GTP_INT_CFG);\ + }while(0) +#define GTP_GPIO_GET_VALUE(pin) gpio_get_value(pin) +#define GTP_GPIO_OUTPUT(pin,level) gpio_direction_output(pin,level) +#define GTP_GPIO_REQUEST(pin, label) gpio_request(pin, label) +#define GTP_GPIO_FREE(pin) gpio_free(pin) +#define GTP_IRQ_TAB {IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_LEVEL_HIGH} + +//STEP_3(optional):Custom set some config by themself,if need. +#if GTP_CUSTOM_CFG + // by allen + #define GTP_MAX_HEIGHT 480//1024 + #define GTP_MAX_WIDTH 854//768 + #define GTP_INT_TRIGGER 1 //0:Rising 1:Falling +#else + #define GTP_MAX_HEIGHT 4096 + #define GTP_MAX_WIDTH 4096 + #define GTP_INT_TRIGGER 1 +#endif +#define GTP_MAX_TOUCH 5 +#define GTP_ESD_CHECK_CIRCLE 2000 + +//STEP_4(optional):If this project have touch key,Set touch key config. +#if GTP_HAVE_TOUCH_KEY + #define GTP_KEY_TAB {KEY_MENU, KEY_HOME, KEY_BACK, KEY_SEND} +#endif + +//***************************PART3:OTHER define********************************* +#define GTP_DRIVER_VERSION "V1.4<2012/12/12>" +#define GTP_I2C_NAME "gt9xx_ts" +#define GTP_POLL_TIME 10 +#define GTP_ADDR_LENGTH 2 +#define GTP_CONFIG_MAX_LENGTH 240 +#define FAIL 0 +#define SUCCESS 1 + +//Register define +#define GTP_READ_COOR_ADDR 0x814E +#define GTP_REG_SLEEP 0x8040 +#define GTP_REG_SENSOR_ID 0x814A +#define GTP_REG_CONFIG_DATA 0x8047 +#define GTP_REG_VERSION 0x8140 + +#define RESOLUTION_LOC 3 +#define TRIGGER_LOC 8 + +//Log define +#define GTP_INFO(fmt,arg...) printk("<<-GTP-INFO->> "fmt"\n",##arg) +#define GTP_ERROR(fmt,arg...) printk("<<-GTP-ERROR->> "fmt"\n",##arg) +#define GTP_DEBUG(fmt,arg...) do{\ + if(GTP_DEBUG_ON)\ + printk("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\ + }while(0) +#define GTP_DEBUG_ARRAY(array, num) do{\ + s32 i;\ + u8* a = array;\ + if(GTP_DEBUG_ARRAY_ON)\ + {\ + printk("<<-GTP-DEBUG-ARRAY->>\n");\ + for (i = 0; i < (num); i++)\ + {\ + printk("%02x ", (a)[i]);\ + if ((i + 1 ) %10 == 0)\ + {\ + printk("\n");\ + }\ + }\ + printk("\n");\ + }\ + }while(0) +#define GTP_DEBUG_FUNC() do{\ + if(GTP_DEBUG_FUNC_ON)\ + printk("<<-GTP-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\ + }while(0) +#define GTP_SWAP(x, y) do{\ + typeof(x) z = x;\ + x = y;\ + y = z;\ + }while (0) + +//****************************PART4:UPDATE define******************************* +//Error no +#define ERROR_NO_FILE 2 //ENOENT +#define ERROR_FILE_READ 23 //ENFILE +#define ERROR_FILE_TYPE 21 //EISDIR +#define ERROR_GPIO_REQUEST 4 //EINTR +#define ERROR_I2C_TRANSFER 5 //EIO +#define ERROR_NO_RESPONSE 16 //EBUSY +#define ERROR_TIMEOUT 110 //ETIMEDOUT + +//*****************************End of Part III******************************** + +#endif /* _LINUX_GOODIX_TOUCH_H */ diff --git a/drivers/input/touchscreen/gt9xx/gt9xx_update.c b/drivers/input/touchscreen/gt9xx/gt9xx_update.c new file mode 100755 index 00000000..81f41a11 --- /dev/null +++ b/drivers/input/touchscreen/gt9xx/gt9xx_update.c @@ -0,0 +1,1529 @@ +/* drivers/input/touchscreen/gt813_827_828_update.c + * + * 2010 - 2012 Goodix Technology. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be a reference + * to you, when you are integrating the GOODiX's CTP IC into your system, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * Latest Version:1.6 + * Author: andrew@goodix.com + * Revision Record: + * V1.0: + * first release. By Andrew, 2012/08/31 + * V1.2: + * add force update,GT9110P pid map. By Andrew, 2012/10/15 + * V1.4: + * 1. add config auto update function; + * 2. modify enter_update_mode; + * 3. add update file cal checksum. + * By Andrew, 2012/12/12 + * V1.6: + * 1. replace guitar_client with i2c_connect_client; + * 2. support firmware header array update. + * By Meta, 2013/03/11 + */ +#include +#include "gt9xx_ts.h" +#if GTP_HEADER_FW_UPDATE +#include +#include "gt9xx_firmware.h" +#endif + +#define GUP_REG_HW_INFO 0x4220 +#define GUP_REG_FW_MSG 0x41E4 +#define GUP_REG_PID_VID 0x8140 + +#define GUP_SEARCH_FILE_TIMES 50 +#define UPDATE_FILE_PATH_2 "/data/_goodix_update_.bin" +#define UPDATE_FILE_PATH_1 "/sdcard/_goodix_update_.bin" + +#define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg" +#define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg" + +#define FW_HEAD_LENGTH 14 +#define FW_SECTION_LENGTH 0x2000 +#define FW_DSP_ISP_LENGTH 0x1000 +#define FW_DSP_LENGTH 0x1000 +#define FW_BOOT_LENGTH 0x800 + +#define PACK_SIZE 256 +#define MAX_FRAME_CHECK_TIME 5 + +#define _bRW_MISCTL__SRAM_BANK 0x4048 +#define _bRW_MISCTL__MEM_CD_EN 0x4049 +#define _bRW_MISCTL__CACHE_EN 0x404B +#define _bRW_MISCTL__TMR0_EN 0x40B0 +#define _rRW_MISCTL__SWRST_B0_ 0x4180 +#define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184 +#define _rRW_MISCTL__BOOTCTL_B0_ 0x4190 +#define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218 +#define _rRW_MISCTL__BOOT_CTL_ 0x5094 + +#define FAIL 0 +#define SUCCESS 1 + +#pragma pack(1) +typedef struct +{ + u8 hw_info[4]; //hardware info// + u8 pid[8]; //product id // + u16 vid; //version id // +}st_fw_head; +#pragma pack() + +typedef struct +{ + u8 force_update; + u8 fw_flag; + struct file *file; + struct file *cfg_file; + st_fw_head ic_fw_msg; + mm_segment_t old_fs; +}st_update_msg; + +st_update_msg update_msg; +u16 show_len; +u16 total_len; +u8 got_file_flag = 0; + +extern void gtp_reset_guitar(struct i2c_client *client, s32 ms); +extern s32 gtp_send_cfg(struct i2c_client *client); +extern struct i2c_client * i2c_connect_client; +extern void gtp_irq_enable(struct goodix_ts_data *ts); +extern void gtp_irq_disable(struct goodix_ts_data *ts); +extern void gtp_set_io_int(void); +extern void gtp_io_init(int ms); +extern void gtp_set_int_value(int status); +extern int ctp_wakeup(int status,int ms); + +/******************************************************* +Function: + Read data from the i2c slave device. +Input: + client: i2c device. + buf[0~1]: read start address. + buf[2~len-1]: read data buffer. + len: GTP_ADDR_LENGTH + read bytes count +Output: + numbers of i2c_msgs to transfer: + 2: succeed, otherwise: failed +*********************************************************/ +s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len) +{ + struct i2c_msg msgs[2]; + s32 ret=-1; + s32 retries = 0; + + GTP_DEBUG_FUNC(); + + msgs[0].flags = !I2C_M_RD; + msgs[0].addr = client->addr; + msgs[0].len = GTP_ADDR_LENGTH; + msgs[0].buf = &buf[0]; + + msgs[1].flags = I2C_M_RD; + msgs[1].addr = client->addr; + msgs[1].len = len - GTP_ADDR_LENGTH; + msgs[1].buf = &buf[GTP_ADDR_LENGTH]; + + while(retries < 5) { + ret = i2c_transfer(client->adapter, msgs, 2); + if(ret == 2)break; + retries++; + } + + return ret; +} + +/******************************************************* +Function: + Write data to the i2c slave device. +Input: + client: i2c device. + buf[0~1]: write start address. + buf[2~len-1]: data buffer + len: GTP_ADDR_LENGTH + write bytes count +Output: + numbers of i2c_msgs to transfer: + 1: succeed, otherwise: failed +*********************************************************/ +s32 gup_i2c_write(struct i2c_client *client,u8 *buf,s32 len) +{ + struct i2c_msg msg; + s32 ret=-1; + s32 retries = 0; + + GTP_DEBUG_FUNC(); + + msg.flags = !I2C_M_RD; + msg.addr = client->addr; + msg.len = len; + msg.buf = buf; + + while(retries < 5){ + ret = i2c_transfer(client->adapter, &msg, 1); + if (ret == 1)break; + retries++; + } + + return ret; +} + +static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8* msg, s32 len) +{ + s32 i = 0; + + msg[0] = (addr >> 8) & 0xff; + msg[1] = addr & 0xff; + + for (i = 0; i < 5; i++) { + if (gup_i2c_read(client, msg, GTP_ADDR_LENGTH + len) > 0) { + break; + } + } + + if (i >= 5) { + GTP_ERROR("Read data from 0x%02x%02x failed!", msg[0], msg[1]); + return FAIL; + } + + return SUCCESS; +} + +static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val) +{ + s32 i = 0; + u8 msg[3]; + + msg[0] = (addr >> 8) & 0xff; + msg[1] = addr & 0xff; + msg[2] = val; + + for (i = 0; i < 5; i++) { + if (gup_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0) { + break; + } + } + + if (i >= 5) { + GTP_ERROR("Set data to 0x%02x%02x failed!", msg[0], msg[1]); + return FAIL; + } + + return SUCCESS; +} + +static u8 gup_get_ic_fw_msg(struct i2c_client *client) +{ + s32 ret = -1; + u8 retry = 0; + u8 buf[16]; + u8 i; + + //step1:get hardware info + ret = gup_get_ic_msg(client, GUP_REG_HW_INFO, buf, 4); + if(FAIL == ret) { + GTP_ERROR("Read hardware info fail."); + return ret; + } + + memcpy(update_msg.ic_fw_msg.hw_info, &buf[GTP_ADDR_LENGTH], 4); + for(i=0; i<4; i++) { + update_msg.ic_fw_msg.hw_info[i] = buf[GTP_ADDR_LENGTH + 3 - i]; + } + GTP_DEBUG("IC Hardware info:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0], update_msg.ic_fw_msg.hw_info[1], + update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); + //step2:get firmware message + for(retry=0; retry<2; retry++) { + ret = gup_get_ic_msg(client, GUP_REG_FW_MSG, buf, 1); + if(FAIL == ret) { + GTP_ERROR("Read firmware message fail."); + return ret; + } + + update_msg.force_update = buf[GTP_ADDR_LENGTH]; + if((0xBE != update_msg.force_update)&&(!retry)) { + GTP_INFO("The check sum in ic is error."); + GTP_INFO("The IC will be updated by force."); + continue; + } + break; + } + GTP_DEBUG("IC force update flag:0x%x", update_msg.force_update); + + //step3:get pid & vid + ret = gup_get_ic_msg(client, GUP_REG_PID_VID, buf, 6); + if(FAIL == ret) { + GTP_ERROR("Read product id & version id fail."); + return ret; + } + memset(update_msg.ic_fw_msg.pid, 0, sizeof(update_msg.ic_fw_msg.pid)); + memcpy(update_msg.ic_fw_msg.pid, &buf[GTP_ADDR_LENGTH], 4); + GTP_DEBUG("IC Product id:%s", update_msg.ic_fw_msg.pid); + + //GT9XX PID MAPPING + /*|-----FLASH-----RAM-----| + |------918------918-----| + |------968------968-----| + |------913------913-----| + |------913P-----913P----| + |------927------927-----| + |------927P-----927P----| + |------9110-----9110----| + |------9110P----9111----|*/ + if(update_msg.ic_fw_msg.pid[0] != 0) { + if(!memcmp(update_msg.ic_fw_msg.pid, "9111", 4)) { + GTP_DEBUG("IC Mapping Product id:%s", update_msg.ic_fw_msg.pid); + memcpy(update_msg.ic_fw_msg.pid, "9110P", 5); + } + } + + update_msg.ic_fw_msg.vid = buf[GTP_ADDR_LENGTH+4] + (buf[GTP_ADDR_LENGTH+5]<<8); + GTP_DEBUG("IC version id:%04x", update_msg.ic_fw_msg.vid); + + return SUCCESS; +} + +s32 gup_enter_update_mode(struct i2c_client *client) +{ + s32 ret = -1; + s32 retry = 0; + u8 rd_buf[3]; + + //step1:RST output low last at least 2ms + ctp_wakeup(0, 0); + msleep(5); + + //step2:select I2C slave addr,INT:0--0xBA;1--0x28. + gtp_set_int_value(client->addr == 0x14); + msleep(2); + + //step3:RST output high reset guitar + ctp_wakeup(1, 0); + + gtp_set_io_int(); + //20121211 modify start + msleep(6); + while(retry++ < 200) { + //step4:Hold ss51 & dsp + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); + if(ret <= 0) { + GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); + continue; + } + + //step5:Confirm hold + ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1); + if(ret <= 0) { + GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); + continue; + } + if(0x0C == rd_buf[GTP_ADDR_LENGTH]) { + GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS"); + break; + } + GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf[GTP_ADDR_LENGTH]); + } + + if(retry >= 200) { + GTP_ERROR("Enter update Hold ss51 failed."); + return FAIL; + } + + //step6:DSP_CK and DSP_ALU_CK PowerOn + ret = gup_set_ic_msg(client, 0x4010, 0x00); + + //20121211 modify end + return ret; +} + +void gup_leave_update_mode(void) +{ + + GTP_DEBUG("[leave_update_mode]reset chip."); + gtp_io_init(20); + gtp_set_io_int(); +} + +static u8 gup_enter_update_judge(st_fw_head *fw_head) +{ + //Get the correct nvram data + //The correct conditions: + //1. the hardware info is the same + //2. the product id is the same + //3. the firmware version in update file is greater than the firmware version in ic + //or the check sum in ic is wrong + u16 u16_tmp; + + u16_tmp = fw_head->vid; + fw_head->vid = (u16)(u16_tmp>>8) + (u16)(u16_tmp<<8); + + GTP_DEBUG("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head->hw_info[0], fw_head->hw_info[1], fw_head->hw_info[2], fw_head->hw_info[3]); + GTP_DEBUG("FILE PID:%s", fw_head->pid); + GTP_DEBUG("FILE VID:%04x", fw_head->vid); + + GTP_DEBUG("IC HARDWARE INFO:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0], update_msg.ic_fw_msg.hw_info[1], + update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); + GTP_DEBUG("IC PID:%s", update_msg.ic_fw_msg.pid); + GTP_DEBUG("IC VID:%04x", update_msg.ic_fw_msg.vid); + + //First two conditions + if ( !memcmp(fw_head->hw_info, update_msg.ic_fw_msg.hw_info, + sizeof(update_msg.ic_fw_msg.hw_info))) { + + GTP_DEBUG("Get the same hardware info."); + if( update_msg.force_update != 0xBE ){ + GTP_INFO("FW chksum error,need enter update."); + return SUCCESS; + } + + if (fw_head->vid > update_msg.ic_fw_msg.vid) { + + GTP_INFO("Need enter update."); + return SUCCESS; + } + if (( !memcmp(fw_head->pid, update_msg.ic_fw_msg.pid, + (strlen(fw_head->pid)<3?3:strlen(fw_head->pid))))|| + (!memcmp(update_msg.ic_fw_msg.pid, "91XX", 4))|| + (!memcmp(fw_head->pid, "91XX", 4))) { + + if(!memcmp(fw_head->pid, "91XX", 4)) { + GTP_DEBUG("Force none same pid update mode."); + }else { + GTP_DEBUG("Get the same pid."); + } + +#if 0 + //The third condition + if (fw_head->vid > update_msg.ic_fw_msg.vid) { + + GTP_INFO("Need enter update."); + return SUCCESS; + } +#endif + GTP_ERROR("Don't meet the third condition."); + } + } + return FAIL; +} + +static u8 ascii2hex(u8 a) +{ + s8 value = 0; + + if(a >= '0' && a <= '9') { + value = a - '0'; + }else if(a >= 'A' && a <= 'F') { + value = a - 'A' + 0x0A; + }else if(a >= 'a' && a <= 'f') { + value = a - 'a' + 0x0A; + }else { + value = 0xff; + } + + return value; +} + +static s8 gup_update_config(struct i2c_client *client) +{ + s32 file_len = 0; + s32 ret = 0; + s32 i = 0; + s32 file_cfg_len = 0; + s32 chip_cfg_len = 0; + s32 count = 0; + u8 *buf; + u8 *pre_buf; + u8 *file_config; + u8 checksum = 0; + u8 pid[8]; + + if(NULL == update_msg.cfg_file) { + GTP_ERROR("[update_cfg]No need to upgrade config!"); + return FAIL; + } + file_len = update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_END); + + ret = gup_get_ic_msg(client, GUP_REG_PID_VID, pid, 6); + if(FAIL == ret){ + GTP_ERROR("[update_cfg]Read product id & version id fail."); + return FAIL; + } + pid[5] = '\0'; + GTP_DEBUG("update cfg get pid:%s", &pid[GTP_ADDR_LENGTH]); + + chip_cfg_len = 186; + if(!memcmp(&pid[GTP_ADDR_LENGTH], "968", 3)) { + chip_cfg_len = 228; + } + GTP_DEBUG("[update_cfg]config file len:%d", file_len); + GTP_DEBUG("[update_cfg]need config len:%d",chip_cfg_len); + if((file_len+5) < chip_cfg_len*5) { + GTP_ERROR("Config length error"); + return -1; + } + + buf = (u8*)kzalloc(file_len, GFP_KERNEL); + pre_buf = (u8*)kzalloc(file_len, GFP_KERNEL); + file_config = (u8*)kzalloc(chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL); + update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_SET); + + GTP_DEBUG("[update_cfg]Read config from file."); + ret = update_msg.cfg_file->f_op->read(update_msg.cfg_file, (char*)pre_buf, file_len, &update_msg.cfg_file->f_pos); + if(ret<0){ + GTP_ERROR("[update_cfg]Read config file failed."); + goto update_cfg_file_failed; + } + + GTP_DEBUG("[update_cfg]Delete illgal charactor."); + for(i=0,count=0; i> 8; + file_config[1] = GTP_REG_CONFIG_DATA & 0xff; + for(i=0,file_cfg_len=GTP_ADDR_LENGTH; i 0) { + GTP_INFO("[update_cfg]Send config SUCCESS."); + break; + } + GTP_ERROR("[update_cfg]Send config i2c error."); + } + +update_cfg_file_failed: + kfree(pre_buf); + kfree(buf); + kfree(file_config); + return ret; +} + +#if GTP_HEADER_FW_UPDATE +static u8 gup_check_fs_mounted(char *path_name) +{ + struct path root_path; + struct path path; + int err; + err = kern_path("/", LOOKUP_FOLLOW, &root_path); + + if (err) { + GTP_DEBUG("\"/\" NOT Mounted: %d", err); + return FAIL; + } + err = kern_path(path_name, LOOKUP_FOLLOW, &path); + + if (err){ + GTP_DEBUG("/data/ NOT Mounted: %d", err); + return FAIL; + } + + return SUCCESS; + +} +#endif +static u8 gup_check_update_file(struct i2c_client *client, st_fw_head* fw_head, u8* path) +{ + s32 ret = 0; + s32 i = 0; + s32 fw_checksum = 0; + u8 buf[FW_HEAD_LENGTH]; + + if (path) { + GTP_DEBUG("Update File path:%s, %d", path, strlen(path)); + update_msg.file = filp_open(path, O_RDONLY, 0644); + + if (IS_ERR(update_msg.file)) { + GTP_ERROR("Open update file(%s) error!", path); + return FAIL; + } + }else { +#if GTP_HEADER_FW_UPDATE + for (i = 0; i < (GUP_SEARCH_FILE_TIMES); i++) { + GTP_DEBUG("Waiting for /data/ mounted [%d]", i); + + if (gup_check_fs_mounted("/data") == SUCCESS) { + GTP_DEBUG("/data/ Mounted!"); + break; + } + msleep(3000); + } + + if (i >= (GUP_SEARCH_FILE_TIMES)) { + GTP_ERROR("Wait for /data/ mounting timeout!"); + return FAIL; + } + update_msg.file = filp_open(UPDATE_FILE_PATH_2, O_CREAT | O_RDWR, 0666); + + if ((IS_ERR(update_msg.file))) { + GTP_ERROR("Failed to Create fw file for fw_header!"); + return FAIL; + } + update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET); + update_msg.file->f_op->write(update_msg.file, (char *)header_fw_array, sizeof(header_fw_array), &update_msg.file->f_pos); + filp_close(update_msg.file, NULL); + update_msg.file = filp_open(UPDATE_FILE_PATH_2, O_RDWR , 0444); +#else + u8 fp_len = max(sizeof(UPDATE_FILE_PATH_1), sizeof(UPDATE_FILE_PATH_2)); + u8 cfp_len = max(sizeof(CONFIG_FILE_PATH_1), sizeof(CONFIG_FILE_PATH_2)); + u8 *search_update_path = (u8*)kzalloc(fp_len, GFP_KERNEL); + u8 *search_cfg_path = (u8*)kzalloc(cfp_len, GFP_KERNEL); + //Begin to search update file,the config file & firmware file must be in the same path,single or double. + for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) { + if(i%2) { + memcpy(search_update_path, UPDATE_FILE_PATH_1, sizeof(UPDATE_FILE_PATH_1)); + memcpy(search_cfg_path, CONFIG_FILE_PATH_1, sizeof(CONFIG_FILE_PATH_1)); + }else { + memcpy(search_update_path, UPDATE_FILE_PATH_2, sizeof(UPDATE_FILE_PATH_2)); + memcpy(search_cfg_path, CONFIG_FILE_PATH_2, sizeof(CONFIG_FILE_PATH_2)); + } + + if(!(got_file_flag&0x0F)) { + update_msg.file = filp_open(search_update_path, O_RDWR, 0444); + if(!IS_ERR(update_msg.file)) { + GTP_DEBUG("Find the bin file"); + got_file_flag |= 0x0F; + } + } + if(!(got_file_flag&0xF0)) { + update_msg.cfg_file = filp_open(search_cfg_path, O_RDWR, 0444); + if(!IS_ERR(update_msg.cfg_file)) { + GTP_DEBUG("Find the cfg file"); + got_file_flag |= 0xF0; + } + } + + if(got_file_flag) { + if(got_file_flag == 0xFF) { + break; + }else { + i += 4; + } + } + GTP_DEBUG("%3d:Searching %s %s file...", i, (got_file_flag&0x0F)?"":"bin", (got_file_flag&0xF0)?"":"cfg"); + msleep(3000); + } + kfree(search_update_path); + kfree(search_cfg_path); + + if(!got_file_flag) { + GTP_ERROR("Can't find update file."); + goto load_failed; + } + + if(got_file_flag&0xF0) { + GTP_DEBUG("Got the update config file."); + ret = gup_update_config(client); + if(ret <= 0) { + GTP_ERROR("Update config failed."); + } + filp_close(update_msg.cfg_file, NULL); + msleep(500); //waiting config to be stored in FLASH. + } + if(got_file_flag&0x0F) { + GTP_DEBUG("Got the update firmware file."); + }else { + GTP_ERROR("No need to upgrade firmware."); + goto load_failed; + } +#endif + } + + update_msg.old_fs = get_fs(); + set_fs(KERNEL_DS); + + update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET); + //update_msg.file->f_pos = 0; + + ret = update_msg.file->f_op->read(update_msg.file, (char*)buf, FW_HEAD_LENGTH, &update_msg.file->f_pos); + if (ret < 0){ + GTP_ERROR("Read firmware head in update file error."); + goto load_failed; + } + memcpy(fw_head, buf, FW_HEAD_LENGTH); + + //check firmware legality + fw_checksum = 0; + for(i=0; if_op->read(update_msg.file, (char*)buf, 2, &update_msg.file->f_pos); + if (ret < 0) { + GTP_ERROR("Read firmware file error."); + goto load_failed; + } + //GTP_DEBUG("BUF[0]:%x", buf[0]); + temp = (buf[0]<<8) + buf[1]; + fw_checksum += temp; + } + + GTP_DEBUG("firmware checksum:%x", fw_checksum&0xFFFF); + if(fw_checksum&0xFFFF) { + GTP_ERROR("Illegal firmware file."); + goto load_failed; + } + + return SUCCESS; + +load_failed: + set_fs(update_msg.old_fs); + return FAIL; +} + +#if 0 +static u8 gup_check_update_header(struct i2c_client *client, st_fw_head* fw_head) +{ + const u8* pos; + int i = 0; + u8 mask_num = 0; + s32 ret = 0; + + pos = HEADER_UPDATE_DATA; + + memcpy(fw_head, pos, FW_HEAD_LENGTH); + pos += FW_HEAD_LENGTH; + + ret = gup_enter_update_judge(fw_head); + if(SUCCESS == ret) { + return SUCCESS; + } + return FAIL; +} +#endif + +static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr, u16 total_length) +{ + s32 ret = 0; + u16 burn_addr = start_addr; + u16 frame_length = 0; + u16 burn_length = 0; + u8 wr_buf[PACK_SIZE + GTP_ADDR_LENGTH]; + u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; + u8 retry = 0; + + GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length/1024), start_addr); + while(burn_length < total_length) { + GTP_DEBUG("B/T:%04d/%04d", burn_length, total_length); + frame_length = ((total_length - burn_length) > PACK_SIZE) ? PACK_SIZE : (total_length - burn_length); + wr_buf[0] = (u8)(burn_addr>>8); + rd_buf[0] = wr_buf[0]; + wr_buf[1] = (u8)burn_addr; + rd_buf[1] = wr_buf[1]; + memcpy(&wr_buf[GTP_ADDR_LENGTH], &burn_buf[burn_length], frame_length); + + for(retry = 0; retry < MAX_FRAME_CHECK_TIME; retry++) { + ret = gup_i2c_write(client, wr_buf, GTP_ADDR_LENGTH + frame_length); + if(ret <= 0) { + GTP_ERROR("Write frame data i2c error."); + continue; + } + ret = gup_i2c_read(client, rd_buf, GTP_ADDR_LENGTH + frame_length); + if(ret <= 0) { + GTP_ERROR("Read back frame data i2c error."); + continue; + } + + if(memcmp(&wr_buf[GTP_ADDR_LENGTH], &rd_buf[GTP_ADDR_LENGTH], frame_length)) { + GTP_ERROR("Check frame data fail,not equal."); + GTP_DEBUG("write array:"); + GTP_DEBUG_ARRAY(&wr_buf[GTP_ADDR_LENGTH], frame_length); + GTP_DEBUG("read array:"); + GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length); + continue; + }else { + //GTP_DEBUG("Check frame data success."); + break; + } + } + + if(retry >= MAX_FRAME_CHECK_TIME) { + GTP_ERROR("Burn frame data time out,exit."); + return FAIL; + } + burn_length += frame_length; + burn_addr += frame_length; + } + + return SUCCESS; +} + +static u8 gup_load_section_file(u8* buf, u16 offset, u16 length) +{ + s32 ret = 0; + + if(update_msg.file == NULL) { + GTP_ERROR("cannot find update file,load section file fail."); + return FAIL; + } + update_msg.file->f_pos = FW_HEAD_LENGTH + offset; + + ret = update_msg.file->f_op->read(update_msg.file, (char*)buf, length, &update_msg.file->f_pos); + if(ret < 0) { + GTP_ERROR("Read update file fail."); + return FAIL; + } + + return SUCCESS; +} + +static u8 gup_recall_check(struct i2c_client *client, u8* chk_src, u16 start_rd_addr, u16 chk_length) +{ + u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; + s32 ret = 0; + u16 recall_addr = start_rd_addr; + u16 recall_length = 0; + u16 frame_length = 0; + + while(recall_length < chk_length) { + frame_length = ((chk_length - recall_length) > PACK_SIZE) ? PACK_SIZE : (chk_length - recall_length); + ret = gup_get_ic_msg(client, recall_addr, rd_buf, frame_length); + if(ret <= 0) { + GTP_ERROR("recall i2c error,exit"); + return FAIL; + } + + if(memcmp(&rd_buf[GTP_ADDR_LENGTH], &chk_src[recall_length], frame_length)) { + GTP_ERROR("Recall frame data fail,not equal."); + GTP_DEBUG("chk_src array:"); + GTP_DEBUG_ARRAY(&chk_src[recall_length], frame_length); + GTP_DEBUG("recall array:"); + GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length); + return FAIL; + } + + recall_length += frame_length; + recall_addr += frame_length; + } + GTP_DEBUG("Recall check %dk firmware success.", (chk_length/1024)); + + return SUCCESS; +} + +static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section, u16 start_addr, u8 bank_cmd ) +{ + s32 ret = 0; + u8 rd_buf[5]; + + //step1:hold ss51 & dsp + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail."); + return FAIL; + } + + //step2:set scramble + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]set scramble fail."); + return FAIL; + } + + //step3:select bank + ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4)&0x0F); + return FAIL; + } + + //step4:enable accessing code + ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]enable accessing code fail."); + return FAIL; + } + + //step5:burn 8k fw section + ret = gup_burn_proc(client, fw_section, start_addr, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_section]burn fw_section fail."); + return FAIL; + } + + //step6:hold ss51 & release dsp + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail."); + return FAIL; + } + //must delay + msleep(1); + + //step7:send burn cmd to move data to flash from sram + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd&0x0f); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]send burn cmd fail."); + return FAIL; + } + GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......"); + do{ + ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]Get burn state fail"); + return FAIL; + } + msleep(10); + //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); + }while(rd_buf[GTP_ADDR_LENGTH]); + + //step8:select bank + ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4)&0x0F); + return FAIL; + } + + //step9:enable accessing code + ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]enable accessing code fail."); + return FAIL; + } + + //step10:recall 8k fw section + ret = gup_recall_check(client, fw_section, start_addr, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_section]recall check 8k firmware fail."); + return FAIL; + } + + //step11:disable accessing code + ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_fw_section]disable accessing code fail."); + return FAIL; + } + + return SUCCESS; +} + +static u8 gup_burn_dsp_isp(struct i2c_client *client) +{ + s32 ret = 0; + u8* fw_dsp_isp = NULL; + u8 retry = 0; + + GTP_DEBUG("[burn_dsp_isp]Begin burn dsp isp---->>"); + + //step1:alloc memory + GTP_DEBUG("[burn_dsp_isp]step1:alloc memory"); + while(retry++ < 5) { + fw_dsp_isp = (u8*)kzalloc(FW_DSP_ISP_LENGTH, GFP_KERNEL); + if(fw_dsp_isp == NULL) { + continue; + }else { + GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH/1024)); + break; + } + } + + if(retry >= 5) { + GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit."); + return FAIL; + } + + //step2:load dsp isp file data + GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data"); + ret = gup_load_section_file(fw_dsp_isp, (4*FW_SECTION_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH), FW_DSP_ISP_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail."); + goto exit_burn_dsp_isp; + } + + //step3:disable wdt,clear cache enable + GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable"); + ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]disable wdt fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]clear cache enable fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step4:hold ss51 & dsp + GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step5:set boot from sram + GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]set boot from sram fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step6:software reboot + GTP_DEBUG("[burn_dsp_isp]step6:software reboot"); + ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]software reboot fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step7:select bank2 + GTP_DEBUG("[burn_dsp_isp]step7:select bank2"); + ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]select bank2 fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step8:enable accessing code + GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code"); + ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]enable accessing code fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + + //step9:burn 4k dsp_isp + GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp"); + ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail."); + goto exit_burn_dsp_isp; + } + + //step10:set scramble + GTP_DEBUG("[burn_dsp_isp]step10:set scramble"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_dsp_isp]set scramble fail."); + ret = FAIL; + goto exit_burn_dsp_isp; + } + ret = SUCCESS; + +exit_burn_dsp_isp: + kfree(fw_dsp_isp); + return ret; +} + +static u8 gup_burn_fw_ss51(struct i2c_client *client) +{ + u8* fw_ss51 = NULL; + u8 retry = 0; + s32 ret = 0; + + GTP_DEBUG("[burn_fw_ss51]Begin burn ss51 firmware---->>"); + + //step1:alloc memory + GTP_DEBUG("[burn_fw_ss51]step1:alloc memory"); + while(retry++ < 5) { + fw_ss51 = (u8*)kzalloc(FW_SECTION_LENGTH, GFP_KERNEL); + if(fw_ss51 == NULL) { + continue; + }else { + GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); + break; + } + } + + if(retry >= 5) { + GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit."); + return FAIL; + } + + //step2:load ss51 firmware section 1 file data + GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data"); + ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail."); + goto exit_burn_fw_ss51; + } + + //step3:clear control flag + GTP_DEBUG("[burn_fw_ss51]step3:clear control flag"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_fw_ss51]clear control flag fail."); + ret = FAIL; + goto exit_burn_fw_ss51; + } + + //step4:burn ss51 firmware section 1 + GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1"); + ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail."); + goto exit_burn_fw_ss51; + } + + //step5:load ss51 firmware section 2 file data + GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data"); + ret = gup_load_section_file(fw_ss51, FW_SECTION_LENGTH, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail."); + goto exit_burn_fw_ss51; + } + + //step6:burn ss51 firmware section 2 + GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2"); + ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail."); + goto exit_burn_fw_ss51; + } + + //step7:load ss51 firmware section 3 file data + GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data"); + ret = gup_load_section_file(fw_ss51, 2*FW_SECTION_LENGTH, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail."); + goto exit_burn_fw_ss51; + } + + //step8:burn ss51 firmware section 3 + GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3"); + ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail."); + goto exit_burn_fw_ss51; + } + + //step9:load ss51 firmware section 4 file data + GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data"); + ret = gup_load_section_file(fw_ss51, 3*FW_SECTION_LENGTH, FW_SECTION_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail."); + goto exit_burn_fw_ss51; + } + + //step10:burn ss51 firmware section 4 + GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4"); + ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail."); + goto exit_burn_fw_ss51; + } + + ret = SUCCESS; + +exit_burn_fw_ss51: + kfree(fw_ss51); + return ret; +} + +static u8 gup_burn_fw_dsp(struct i2c_client *client) +{ + s32 ret = 0; + u8* fw_dsp = NULL; + u8 retry = 0; + u8 rd_buf[5]; + + GTP_DEBUG("[burn_fw_dsp]Begin burn dsp firmware---->>"); + //step1:alloc memory + GTP_DEBUG("[burn_fw_dsp]step1:alloc memory"); + while(retry++ < 5) { + fw_dsp = (u8*)kzalloc(FW_DSP_LENGTH, GFP_KERNEL); + if(fw_dsp == NULL) { + continue; + }else { + GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); + break; + } + } + + if(retry >= 5) { + GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit."); + return FAIL; + } + + //step2:load firmware dsp + GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp"); + ret = gup_load_section_file(fw_dsp, 4*FW_SECTION_LENGTH, FW_DSP_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_dsp]load firmware dsp fail."); + goto exit_burn_fw_dsp; + } + + //step3:select bank3 + GTP_DEBUG("[burn_fw_dsp]step3:select bank3"); + ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]select bank3 fail."); + ret = FAIL; + goto exit_burn_fw_dsp; + } + + //step4:hold ss51 & dsp + GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_dsp; + } + + //step5:set scramble + GTP_DEBUG("[burn_fw_dsp]step5:set scramble"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]set scramble fail."); + ret = FAIL; + goto exit_burn_fw_dsp; + } + + //step6:release ss51 & dsp + GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); //20121211 + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_dsp; + } + //must delay + msleep(1); + + //step7:burn 4k dsp firmware + GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware"); + ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_dsp]burn fw_section fail."); + goto exit_burn_fw_dsp; + } + + //step8:send burn cmd to move data to flash from sram + GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05); + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]send burn cmd fail."); + goto exit_burn_fw_dsp; + } + GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......"); + do{ + ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); + if(ret <= 0) { + GTP_ERROR("[burn_fw_dsp]Get burn state fail"); + goto exit_burn_fw_dsp; + } + msleep(10); + //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); + }while(rd_buf[GTP_ADDR_LENGTH]); + + //step9:recall check 4k dsp firmware + GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware"); + ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail."); + goto exit_burn_fw_dsp; + } + + ret = SUCCESS; + +exit_burn_fw_dsp: + kfree(fw_dsp); + return ret; +} + +static u8 gup_burn_fw_boot(struct i2c_client *client) +{ + s32 ret = 0; + u8* fw_boot = NULL; + u8 retry = 0; + u8 rd_buf[5]; + + GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>"); + + //step1:Alloc memory + GTP_DEBUG("[burn_fw_boot]step1:Alloc memory"); + while(retry++ < 5) { + fw_boot = (u8*)kzalloc(FW_BOOT_LENGTH, GFP_KERNEL); + if(fw_boot == NULL) { + continue; + }else { + GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH/1024)); + break; + } + } + if(retry >= 5) { + GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit."); + return FAIL; + } + + //step2:load firmware bootloader + GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader"); + ret = gup_load_section_file(fw_boot, (4*FW_SECTION_LENGTH+FW_DSP_LENGTH), FW_BOOT_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_boot]load firmware dsp fail."); + goto exit_burn_fw_boot; + } + + //step3:hold ss51 & dsp + GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + + //step4:set scramble + GTP_DEBUG("[burn_fw_boot]step4:set scramble"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]set scramble fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + + //step5:release ss51 & dsp + GTP_DEBUG("[burn_fw_boot]step5:release ss51 & dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); //20121211 + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + //must delay + msleep(1); + + //step6:select bank3 + GTP_DEBUG("[burn_fw_boot]step6:select bank3"); + ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]select bank3 fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + + //step7:burn 2k bootloader firmware + GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware"); + ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_boot]burn fw_section fail."); + goto exit_burn_fw_boot; + } + + //step7:send burn cmd to move data to flash from sram + GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]send burn cmd fail."); + goto exit_burn_fw_boot; + } + GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......"); + do{ + ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]Get burn state fail"); + goto exit_burn_fw_boot; + } + msleep(10); + //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); + }while(rd_buf[GTP_ADDR_LENGTH]); + + //step8:recall check 2k bootloader firmware + GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware"); + ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH); + if(FAIL == ret) { + GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail."); + goto exit_burn_fw_boot; + } + + //step9:enable download DSP code + GTP_DEBUG("[burn_fw_boot]step9:enable download DSP code "); + ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]enable download DSP code fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + + //step10:release ss51 & hold dsp + GTP_DEBUG("[burn_fw_boot]step10:release ss51 & hold dsp"); + ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08); + if(ret <= 0) { + GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + + ret = SUCCESS; + +exit_burn_fw_boot: + kfree(fw_boot); + return ret; +} + +s32 gup_update_proc(void *dir) +{ + s32 ret = 0; + u8 retry = 0; + st_fw_head fw_head; + struct goodix_ts_data *ts = NULL; + + GTP_DEBUG("[update_proc]Begin update ......"); + + show_len = 1; + total_len = 100; + if(dir == NULL) + { + msleep(3000); //wait main thread to be completed + } + + ts = i2c_get_clientdata(i2c_connect_client); + + update_msg.file = NULL; + ret = gup_check_update_file(i2c_connect_client, &fw_head, (u8*)dir); //20121211 + if(FAIL == ret) { + GTP_ERROR("[update_proc]check update file fail."); + goto update_fail; + } + + ts->enter_update = 1; // Shield interrupt handler + gtp_irq_disable(ts); + gtp_io_init(20); + gtp_set_io_int(); + ret = gup_get_ic_fw_msg(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]get ic message fail."); + goto update_fail; + } + + ret = gup_enter_update_judge(&fw_head); + if(FAIL == ret) { + GTP_ERROR("[update_proc]Check *.bin file fail."); + goto update_fail; + } + + ret = gup_enter_update_mode(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]enter update mode fail."); + goto update_fail; + } + + while(retry++ < 5) { + show_len = 10; + total_len = 100; + ret = gup_burn_dsp_isp(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]burn dsp isp fail."); + continue; + } + + show_len += 10; + ret = gup_burn_fw_ss51(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]burn ss51 firmware fail."); + continue; + } + + show_len += 40; + ret = gup_burn_fw_dsp(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]burn dsp firmware fail."); + continue; + } + + show_len += 20; + ret = gup_burn_fw_boot(i2c_connect_client); + if(FAIL == ret) { + GTP_ERROR("[update_proc]burn bootloader firmware fail."); + continue; + } + show_len += 10; + GTP_INFO("[update_proc]UPDATE SUCCESS."); + break; + } + + if(retry >= 5) { + GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL."); + goto update_fail; + } + + GTP_DEBUG("[update_proc]leave update mode."); + gup_leave_update_mode(); + + + msleep(100); + GTP_DEBUG("[update_proc]send config."); + //ret = gtp_send_cfg(i2c_connect_client); + // if(ret < 0) { + // GTP_ERROR("[update_proc]send config fail."); + // } + show_len = 100; + total_len = 100; + ts->enter_update = 0; + gtp_irq_enable(ts); + filp_close(update_msg.file, NULL); + return SUCCESS; + +update_fail: + ts->enter_update = 0; + gtp_irq_enable(ts); + if(update_msg.file && !IS_ERR(update_msg.file)) { + filp_close(update_msg.file, NULL); + } + show_len = 200; + total_len = 100; + return FAIL; +} + +#if GTP_AUTO_UPDATE +u8 gup_init_update_proc(struct goodix_ts_data *ts) +{ + struct task_struct *thread = NULL; + + GTP_INFO("Ready to run update thread."); + thread = kthread_run(gup_update_proc, (void*)NULL, "guitar_update"); + if (IS_ERR(thread)) { + GTP_ERROR("Failed to create update thread.\n"); + return -1; + } + + return 0; +} +#endif \ No newline at end of file