diff options
author | Shantanu Jain <shjain@codeaurora.org> | 2013-07-18 17:34:31 +0530 |
---|---|---|
committer | Abinaya P <abinayap@codeaurora.org> | 2016-08-10 13:33:31 +0530 |
commit | d80c9df9bc0ed6a33a2bbf9e2ed6a15ec482924f (patch) | |
tree | c8a9b3002f3146d52b6e504be71fa35111a0ddcd /drivers/input | |
parent | b1bafc4fd8f77ab2320c8511b3aea9643e117d9d (diff) |
input: touchscreen: Goodix gt915 driver cleanup
Cleanup the gt915 goodix driver from checkpatch failures.
Also have cleared the checkpatch errors on 4.4
This patch is propagated from 3.18 kernel
'commit 9ccc3ab159ba ("input: touchscreen: Goodix gt915
driver cleanup")'
Change-Id: Id841423f229b6abc674cc1e3c6441d55062b6ab4
Signed-off-by: Shantanu Jain <shjain@codeaurora.org>
Signed-off-by: Bingzhe Cai <bingzhec@codeaurora.org>
Signed-off-by: Sudhakar Manapati <smanap@codeaurora.org>
[abinayap@codeaurora.org: fix checkpatch errors for 4.4 kernel
Use of the '__DATE__' macro makes the build non-deterministic
Also including it in the output does not provide any value.
So remove its usage.]
Signed-off-by: Abinaya P <abinayap@codeaurora.org>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/gt9xx/goodix_tool.c | 1166 | ||||
-rw-r--r-- | drivers/input/touchscreen/gt9xx/gt9xx_firmware.h | 12 | ||||
-rw-r--r-- | drivers/input/touchscreen/gt9xx/gt9xx_update.c | 3308 |
3 files changed, 2140 insertions, 2346 deletions
diff --git a/drivers/input/touchscreen/gt9xx/goodix_tool.c b/drivers/input/touchscreen/gt9xx/goodix_tool.c index 3dfe4e1d334e..bef080671ab0 100644 --- a/drivers/input/touchscreen/gt9xx/goodix_tool.c +++ b/drivers/input/touchscreen/gt9xx/goodix_tool.c @@ -1,615 +1,551 @@ -/* 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.6
- * V1.0:2012/05/01,create file.
- * V1.2:2012/06/08,modify some warning.
- * V1.4:2012/08/28,modified to support GT9XX
- * V1.6:new proc name
- */
-
-#include "gt9xx.h"
-
-#define DATA_LENGTH_UINT 512
-#define CMD_HEAD_LENGTH (sizeof(st_cmd_head) - sizeof(u8*))
-static char procname[20] = {0};
-
-#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);
-
-#if GTP_ESD_PROTECT
-extern void gtp_esd_switch(struct i2c_client *, s32);
-#endif
-s32 DATA_LENGTH = 0;
-s8 IC_TYPE[16] = {0};
-
-static void tool_set_proc_name(char * procname)
-{
- char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- char date[20] = {0};
- char month[4] = {0};
- int i = 0, n_month = 1, n_day = 0, n_year = 0;
-
- sprintf(date, "%s", __DATE__);
-
- //GTP_DEBUG("compile date: %s", date);
-
- sscanf(date, "%s %d %d", month, &n_day, &n_year);
-
- for (i = 0; i < 12; ++i)
- {
- if (!memcmp(months[i], month, 3))
- {
- n_month = i+1;
- break;
- }
- }
-
- sprintf(procname, "gmnode%04d%02d%02d", n_year, n_month, n_day);
-
- //GTP_DEBUG("procname = %s", procname);
-}
-
-
-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!");
-}
-
-
-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();
-
- tool_set_proc_name(procname);
- goodix_proc_entry = create_proc_entry(procname, 0666, NULL);
- if (goodix_proc_entry == NULL)
- {
- GTP_ERROR("Couldn't create proc entry!");
- return FAIL;
- }
- else
- {
- GTP_INFO("Create proc entry success!");
- goodix_proc_entry->write_proc = goodix_tool_write;
- goodix_proc_entry->read_proc = goodix_tool_read;
- }
-
- return SUCCESS;
-}
-
-void uninit_wr_node(void)
-{
- kfree(cmd_head.data);
- cmd_head.data = NULL;
- unregister_i2c_func();
- remove_proc_entry(procname, 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));
-
- #if GTP_ESD_PROTECT
- gtp_esd_switch(gt_client, SWITCH_OFF);
- #endif
- return CMD_HEAD_LENGTH;
- }
- else if (9 == cmd_head.wr) //enable irq!
- {
- gtp_irq_enable(i2c_get_clientdata(gt_client));
-
- #if GTP_ESD_PROTECT
- gtp_esd_switch(gt_client, SWITCH_ON);
- #endif
- 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;
-}
+/* drivers/input/touchscreen/goodix_tool.c + * + * 2010 - 2012 Goodix Technology. + * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. + * + * 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.6 + * V1.0:2012/05/01,create file. + * V1.2:2012/06/08,modify some warning. + * V1.4:2012/08/28,modified to support GT9XX + * V1.6:new proc name + */ + +#include "gt9xx.h" + +#define DATA_LENGTH_UINT 512 +#define CMD_HEAD_LENGTH (sizeof(st_cmd_head) - sizeof(u8 *)) +static char procname[20] = {0}; + +#define UPDATE_FUNCTIONS + +#pragma pack(1) +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 before 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; + +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; +s8 IC_TYPE[16] = {0}; + +static void tool_set_proc_name(char *procname) +{ + char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", + "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + char date[20] = {0}; + char month[4] = {0}; + int i = 0, n_month = 1, n_day = 0, n_year = 0, ret; + + ret = sscanf(date, "%s %d %d", month, &n_day, &n_year); + if (!ret) + return; + for (i = 0; i < 12; ++i) { + if (!memcmp(months[i], month, 3)) { + n_month = i+1; + break; + } + } + + snprintf(procname, 20, "gmnode%04d%02d%02d", n_year, n_month, n_day); + /* GTP_DEBUG("procname = %s", procname); */ +} + +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 (strcmp(IC_TYPE, "GT8110") && strcmp(IC_TYPE, "GT8105") + && strcmp(IC_TYPE, "GT801") && strcmp(IC_TYPE, "GT800") + && strcmp(IC_TYPE, "GT801PLUS") && strcmp(IC_TYPE, "GT811") + && strcmp(IC_TYPE, "GTxxx")) { + 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!"); +} + +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 (cmd_head.data != NULL) + 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(); + + tool_set_proc_name(procname); + goodix_proc_entry = create_proc_entry(procname, 0666, NULL); + if (goodix_proc_entry == NULL) { + GTP_ERROR("Couldn't create proc entry!"); + return FAIL; + } + GTP_INFO("Create proc entry success!"); + goodix_proc_entry->write_proc = goodix_tool_write; + dix_proc_entry->read_proc = goodix_tool_read; + + return SUCCESS; +} + +void uninit_wr_node(void) +{ + kfree(cmd_head.data); + cmd_head.data = NULL; + unregister_i2c_func(); + remove_proc_entry(procname, 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 (cmd_head.wr == 1) { + /* 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 (cmd_head.flag == 1) { + if (comfirm() == FAIL) { + GTP_ERROR("[WRITE]Comfirm fail!"); + return FAIL; + } + } else if (cmd_head.flag == 2) { + /* 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 (cmd_head.wr == 3) { /* 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 (cmd_head.wr == 3) { + + /* memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len); */ + + return cmd_head.data_len + CMD_HEAD_LENGTH; + } else if (cmd_head.wr == 7) { /* disable irq! */ + gtp_irq_disable(i2c_get_clientdata(gt_client)); + + #if GTP_ESD_PROTECT + gtp_esd_switch(gt_client, SWITCH_OFF); + #endif + return CMD_HEAD_LENGTH; + } else if (cmd_head.wr == 9) { /* enable irq! */ + gtp_irq_enable(i2c_get_clientdata(gt_client)); + + #if GTP_ESD_PROTECT + gtp_esd_switch(gt_client, SWITCH_ON); + #endif + return CMD_HEAD_LENGTH; + } else if (cmd_head.wr == 17) { + 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 (cmd_head.wr == 11) { /* Enter update mode! */ + if (gup_enter_update_mode(gt_client) == FAIL) + return FAIL; + } else if (cmd_head.wr == 13) { /* Leave update mode! */ + gup_leave_update_mode(); + } else if (cmd_head.wr == 15) { /* 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 (gup_update_proc((void *)cmd_head.data) == FAIL) + 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 (cmd_head.flag == 1) { + if (comfirm() == FAIL) { + GTP_ERROR("[READ]Comfirm fail!"); + return FAIL; + } + } else if (cmd_head.flag == 2) { + /* 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 (cmd_head.wr == 2) { + /* 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 (cmd_head.wr == 4) { + 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 (cmd_head.wr == 6) { + /* Read error code! */ + } else if (cmd_head.wr == 8) { /*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_firmware.h b/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h index 3998bf0023f8..81e3affe62e9 100644 --- a/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h +++ b/drivers/input/touchscreen/gt9xx/gt9xx_firmware.h @@ -1,6 +1,6 @@ -// make sense only when GTP_HEADER_FW_UPDATE & GTP_AUTO_UPDATE are enabled
-// define your own firmware array here
-const unsigned char header_fw_array[] =
-{
-
-};
\ No newline at end of file +/* + * make sense only when GTP_HEADER_FW_UPDATE & GTP_AUTO_UPDATE are enabled + * define your own firmware array here +*/ +const unsigned char header_fw_array[] = { +}; diff --git a/drivers/input/touchscreen/gt9xx/gt9xx_update.c b/drivers/input/touchscreen/gt9xx/gt9xx_update.c index f564a6b3aaed..29459b6d9ad1 100644 --- a/drivers/input/touchscreen/gt9xx/gt9xx_update.c +++ b/drivers/input/touchscreen/gt9xx/gt9xx_update.c @@ -1,21 +1,22 @@ /* drivers/input/touchscreen/gt9xx_update.c - * + * * 2010 - 2012 Goodix Technology. - * + * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. + * * 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 + * + * 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: + * Revision Record: * V1.0: * first release. By Andrew, 2012/08/31 * V1.2: @@ -25,7 +26,7 @@ * 2. modify enter_update_mode; * 3. add update file cal checksum. * By Andrew, 2012/12/12 - * V1.6: + * V1.6: * 1. replace guitar_client with i2c_connect_client; * 2. support firmware header array update. * By Meta, 2013/03/11 @@ -47,8 +48,8 @@ #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 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 @@ -73,39 +74,27 @@ #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; +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; +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; -u8 searching_file = 0; -extern u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]; -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 s32 gtp_i2c_read_dbl_check(struct i2c_client *, u16, u8 *, int); -#if GTP_ESD_PROTECT -extern void gtp_esd_switch(struct i2c_client *, s32); -#endif +u8 got_file_flag; +u8 searching_file; /******************************************************* Function: Read data from the i2c slave device. @@ -115,37 +104,37 @@ Input: buf[2~len-1]: read data buffer. len: GTP_ADDR_LENGTH + read bytes count Output: - numbers of i2c_msgs to transfer: + 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[0].scl_rate = 300 * 1000; // for Rockchip - - 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]; - //msgs[1].scl_rate = 300 * 1000; - - while(retries < 5) - { - ret = i2c_transfer(client->adapter, msgs, 2); - if(ret == 2)break; - retries++; - } - - return ret; + 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[0].scl_rate = 300 * 1000; (for Rockchip) */ + + 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]; + /* msgs[1].scl_rate = 300 * 1000; */ + + while (retries < 5) { + ret = i2c_transfer(client->adapter, msgs, 2); + if (ret == 2) + break; + retries++; + } + + return ret; } /******************************************************* @@ -157,1774 +146,1643 @@ Input: buf[2~len-1]: data buffer len: GTP_ADDR_LENGTH + write bytes count Output: - numbers of i2c_msgs to transfer: - 1: succeed, otherwise: failed + numbers of i2c_msgs to transfer: + 1: succeed, otherwise: failed *********************************************************/ -s32 gup_i2c_write(struct i2c_client *client,u8 *buf,s32 len) +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; - //msg.scl_rate = 300 * 1000; // for Rockchip - - while(retries < 5) - { - ret = i2c_transfer(client->adapter, &msg, 1); - if (ret == 1)break; - retries++; - } - - return ret; + 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; + /* msg.scl_rate = 300 * 1000; (for Rockchip) */ + + while (retries < 5) { + ret = i2c_transfer(client->adapter, &msg, 1); + if (ret == 1) + break; + retries++; + } + + return ret; } static s32 gup_init_panel(struct goodix_ts_data *ts) { - s32 ret = 0; - s32 i = 0; - u8 check_sum = 0; - u8 opr_buf[16]; - u8 sensor_id = 0; - - u8 cfg_info_group1[] = CTP_CFG_GROUP1; - u8 cfg_info_group2[] = CTP_CFG_GROUP2; - u8 cfg_info_group3[] = CTP_CFG_GROUP3; - u8 cfg_info_group4[] = CTP_CFG_GROUP4; - u8 cfg_info_group5[] = CTP_CFG_GROUP5; - u8 cfg_info_group6[] = CTP_CFG_GROUP6; - u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3, - cfg_info_group4, cfg_info_group5, cfg_info_group6}; - u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1), - CFG_GROUP_LEN(cfg_info_group2), - CFG_GROUP_LEN(cfg_info_group3), - CFG_GROUP_LEN(cfg_info_group4), - CFG_GROUP_LEN(cfg_info_group5), - CFG_GROUP_LEN(cfg_info_group6)}; - - if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && - (!cfg_info_len[3]) && (!cfg_info_len[4]) && - (!cfg_info_len[5])) - { - sensor_id = 0; - } - else - { - ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1); - if (SUCCESS == ret) - { - if (sensor_id >= 0x06) - { - GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id); - return -1; - } - } - else - { - GTP_ERROR("Failed to get sensor_id, No config sent!"); - return -1; - } - } - - GTP_DEBUG("Sensor_ID: %d", sensor_id); - - ts->gtp_cfg_len = cfg_info_len[sensor_id]; - - if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) - { - GTP_ERROR("Sensor_ID(%d) matches with NULL or INVALID CONFIG GROUP! NO Config Sent! You need to check you header file CFG_GROUP section!", sensor_id); - return -1; - } - - ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1); - - if (ret == SUCCESS) - { - GTP_DEBUG("CFG_GROUP%d Config Version: %d, IC Config Version: %d", sensor_id+1, - send_cfg_buf[sensor_id][0], opr_buf[0]); - - send_cfg_buf[sensor_id][0] = opr_buf[0]; - ts->fixed_cfg = 0; - /* - if (opr_buf[0] < 90) - { - grp_cfg_version = send_cfg_buf[sensor_id][0]; // backup group config version - send_cfg_buf[sensor_id][0] = 0x00; - ts->fixed_cfg = 0; - } - else // treated as fixed config, not send config - { - GTP_INFO("Ic fixed config with config version(%d)", opr_buf[0]); - ts->fixed_cfg = 1; - }*/ - } - else - { - GTP_ERROR("Failed to get ic config version!No config sent!"); - return -1; - } - - memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); - memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len); - - GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", - ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type); - - 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; - } - - 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; - - GTP_DEBUG_FUNC(); - ret = gtp_send_cfg(ts->client); - if (ret < 0) - { - GTP_ERROR("Send config error."); - } - - msleep(10); - return 0; + s32 ret = 0; + s32 i = 0; + u8 check_sum = 0; + u8 opr_buf[16]; + u8 sensor_id = 0; + + u8 cfg_info_group1[] = CTP_CFG_GROUP1; + u8 cfg_info_group2[] = CTP_CFG_GROUP2; + u8 cfg_info_group3[] = CTP_CFG_GROUP3; + u8 cfg_info_group4[] = CTP_CFG_GROUP4; + u8 cfg_info_group5[] = CTP_CFG_GROUP5; + u8 cfg_info_group6[] = CTP_CFG_GROUP6; + u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3, + cfg_info_group4, cfg_info_group5, cfg_info_group6}; + u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1), + CFG_GROUP_LEN(cfg_info_group2), + CFG_GROUP_LEN(cfg_info_group3), + CFG_GROUP_LEN(cfg_info_group4), + CFG_GROUP_LEN(cfg_info_group5), + CFG_GROUP_LEN(cfg_info_group6)}; + + if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && + (!cfg_info_len[3]) && (!cfg_info_len[4]) && + (!cfg_info_len[5])) { + sensor_id = 0; + } else { + ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, + &sensor_id, 1); + if (ret == SUCCESS) { + if (sensor_id >= 0x06) { + GTP_ERROR( + "Invalid sensor_id(0x%02X), No Config Sent!", + sensor_id); + return -EINVAL; + } + } else { + GTP_ERROR("Failed to get sensor_id, No config sent!"); + return -EINVAL; + } + } + + GTP_DEBUG("Sensor_ID: %d", sensor_id); + + ts->gtp_cfg_len = cfg_info_len[sensor_id]; + + if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) { + GTP_ERROR("Sensor_ID(%d) matches with NULL or INVALID CONFIG", + " GROUP! NO Config Sent! You need to check you header", + " file CFG_GROUP section!", sensor_id); + return -EINVAL; + } + + ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, + &opr_buf[0], 1); + + if (ret == SUCCESS) { + GTP_DEBUG("CFG_GROUP%d Config Version: %d, IC Config Version:", + " %d", sensor_id+1, send_cfg_buf[sensor_id][0], opr_buf[0]); + + send_cfg_buf[sensor_id][0] = opr_buf[0]; + ts->fixed_cfg = 0; + /* + * if (opr_buf[0] < 90) { + * grp_cfg_version = send_cfg_buf[sensor_id][0]; + * *** backup group config version *** + * send_cfg_buf[sensor_id][0] = 0x00; + * ts->fixed_cfg = 0; + * } else { *** treated as fixed config, not send config *** + * GTP_INFO("Ic fixed config with config version(%d)", + * opr_buf[0]); + * ts->fixed_cfg = 1; + * } + */ + } else { + GTP_ERROR("Failed to get ic config version!No config sent!"); + return -EINVAL; + } + + memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); + memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], + ts->gtp_cfg_len); + + GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", + ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type); + + 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; + + 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; + + GTP_DEBUG_FUNC(); + ret = gtp_send_cfg(ts->client); + if (ret < 0) + GTP_ERROR("Send config error."); + + msleep(20); + return 0; } -static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8* msg, s32 len) +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; + 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; + 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 = gtp_i2c_read_dbl_check(client, GUP_REG_HW_INFO, &buf[GTP_ADDR_LENGTH], 4); - if (FAIL == ret) - { - GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit"); - return FAIL; - } - - // buf[2~5]: 00 06 90 00 - // hw_info: 00 90 06 00 - 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 = gtp_i2c_read_dbl_check(client, GUP_REG_PID_VID, &buf[GTP_ADDR_LENGTH], 6); - if (FAIL == ret) - { - GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit"); - return FAIL; - } - - 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 ret = -1; + u8 retry = 0; + u8 buf[16]; + u8 i; + + /* step1:get hardware info */ + ret = gtp_i2c_read_dbl_check(client, GUP_REG_HW_INFO, + &buf[GTP_ADDR_LENGTH], 4); + if (ret == FAIL) { + GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit"); + return FAIL; + } + + /* buf[2~5]: 00 06 90 00 */ + /* hw_info: 00 90 06 00 */ + 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 (ret == FAIL) { + GTP_ERROR("Read firmware message fail."); + return ret; + } + + update_msg.force_update = buf[GTP_ADDR_LENGTH]; + if ((update_msg.force_update != 0xBE) && (!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 = gtp_i2c_read_dbl_check(client, GUP_REG_PID_VID, + &buf[GTP_ADDR_LENGTH], 6); + if (ret == FAIL) { + GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit"); + return FAIL; + } + + 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 - GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); - msleep(2); - - //step2:select I2C slave addr,INT:0--0xBA;1--0x28. - GTP_GPIO_OUTPUT(GTP_INT_PORT, (client->addr == 0x14)); - msleep(2); - - //step3:RST output high reset guitar - GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); - - //20121211 modify start - msleep(5); - 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; + s32 ret = -1; + s32 retry = 0; + u8 rd_buf[3]; + + /* step1:RST output low last at least 2ms */ + GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); + msleep(20); + + /* step2:select I2C slave addr,INT:0--0xBA;1--0x28. */ + GTP_GPIO_OUTPUT(GTP_INT_PORT, (client->addr == 0x14)); + msleep(20); + + /* step3:RST output high reset guitar */ + GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); + + /* 20121211 modify start */ + msleep(20); + 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 (rd_buf[GTP_ADDR_LENGTH] == 0x0C) { + 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_GPIO_AS_INT(GTP_INT_PORT); - - GTP_DEBUG("[leave_update_mode]reset chip."); - gtp_reset_guitar(i2c_connect_client, 20); + GTP_GPIO_AS_INT(GTP_INT_PORT); + + GTP_DEBUG("[leave_update_mode]reset chip."); + gtp_reset_guitar(i2c_connect_client, 20); } -// 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 -/* Update Conditions: - 1. Same hardware info - 2. Same PID - 3. File PID > IC PID - Force Update Conditions: - 1. Wrong ic firmware checksum - 2. INVALID IC PID or VID - 3. IC PID == 91XX || File PID == 91XX -*/ +/* 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 + + * Update Conditions: + * 1. Same hardware info + * 2. Same PID + * 3. File PID > IC PID + + * Force Update Conditions: + * 1. Wrong ic firmware checksum + * 2. INVALID IC PID or VID + * 3. IC PID == 91XX || File PID == 91XX + */ static u8 gup_enter_update_judge(st_fw_head *fw_head) { - u16 u16_tmp; - s32 i = 0; - - 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; - } - - // 20130523 start - if (strlen(update_msg.ic_fw_msg.pid) < 3) - { - GTP_INFO("Illegal IC pid, need enter update"); - return SUCCESS; - } - else - { - for (i = 0; i < 3; i++) - { - if ((update_msg.ic_fw_msg.pid[i] < 0x30) || (update_msg.ic_fw_msg.pid[i] > 0x39)) - { - GTP_INFO("Illegal IC pid, out of bound, need enter update"); - return SUCCESS; - } - } - } - // 20130523 end - - - 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."); - } - //The third condition - if (fw_head->vid > update_msg.ic_fw_msg.vid) - { - - GTP_INFO("Need enter update."); - return SUCCESS; - } - GTP_ERROR("Don't meet the third condition."); - GTP_ERROR("File VID <= Ic VID, update aborted!"); - } - else - { - GTP_ERROR("File PID != Ic PID, update aborted!"); - } - } - else - { - GTP_ERROR("Different Hardware, update aborted!"); - } - return FAIL; + u16 u16_tmp; + s32 i = 0; + + 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]); + TP_DEBUG("FILE PID:%s", fw_head->pid); + TP_DEBUG("FILE VID:%04x", fw_head->vid); + + TP_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]); + TP_DEBUG("IC PID:%s", update_msg.ic_fw_msg.pid); + TP_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; + } + + /* 20130523 start */ + if (strlen(update_msg.ic_fw_msg.pid) < 3) { + GTP_INFO("Illegal IC pid, need enter update"); + return SUCCESS; + } + for (i = 0; i < 3; i++) { + if ((update_msg.ic_fw_msg.pid[i] < 0x30) || + (update_msg.ic_fw_msg.pid[i] > 0x39)) { + GTP_INFO("Illegal IC pid, out of ", + "bound, need enter update"); + return SUCCESS; + } + } + /* 20130523 end */ + + 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."); + + /* The third condition */ + if (fw_head->vid > update_msg.ic_fw_msg.vid) { + GTP_INFO("Need enter update."); + return SUCCESS; + } + GTP_ERROR("Don't meet the third condition."); + GTP_ERROR("File VID <= Ic VID, update aborted!"); + } else { + GTP_ERROR("File PID != Ic PID, update aborted!"); + } + } else { + GTP_ERROR("Different Hardware, update aborted!"); + } + + 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; + 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) || - !memcmp(&pid[GTP_ADDR_LENGTH], "910", 3) || - !memcmp(&pid[GTP_ADDR_LENGTH], "960", 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<file_len; i++) - { - if (pre_buf[i] == ' ' || pre_buf[i] == '\r' || pre_buf[i] == '\n') - { - continue; - } - buf[count++] = pre_buf[i]; - } - - GTP_DEBUG("[update_cfg]Ascii to hex."); - file_config[0] = GTP_REG_CONFIG_DATA >> 8; - file_config[1] = GTP_REG_CONFIG_DATA & 0xff; - for(i=0,file_cfg_len=GTP_ADDR_LENGTH; i<count; i+=5) - { - if((buf[i]=='0') && ((buf[i+1]=='x') || (buf[i+1]=='X'))) - { - u8 high,low; - high = ascii2hex(buf[i+2]); - low = ascii2hex(buf[i+3]); - - if((high == 0xFF) || (low == 0xFF)) - { - ret = 0; - GTP_ERROR("[update_cfg]Illegal config file."); - goto update_cfg_file_failed; - } - file_config[file_cfg_len++] = (high<<4) + low; - } - else - { - ret = 0; - GTP_ERROR("[update_cfg]Illegal config file."); - goto update_cfg_file_failed; - } - } - -// //cal checksum -// for(i=GTP_ADDR_LENGTH; i<chip_cfg_len; i++) -// { -// checksum += file_config[i]; -// } -// file_config[chip_cfg_len] = (~checksum) + 1; -// file_config[chip_cfg_len+1] = 0x01; - - GTP_DEBUG("config:"); - GTP_DEBUG_ARRAY(file_config+2, file_cfg_len); - - i = 0; - while(i++ < 5) - { - ret = gup_i2c_write(client, file_config, file_cfg_len); - if(ret > 0) - { - GTP_INFO("[update_cfg]Send config SUCCESS."); - break; - } - GTP_ERROR("[update_cfg]Send config i2c error."); - } - + 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 (update_msg.cfg_file == NULL) { + 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 (ret == FAIL) { + 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) || + !memcmp(&pid[GTP_ADDR_LENGTH], "910", 3) || + !memcmp(&pid[GTP_ADDR_LENGTH], "960", 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 -EINVAL; + } + + buf = kzalloc(file_len, GFP_KERNEL); + pre_buf = kzalloc(file_len, GFP_KERNEL); + file_config = 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 illegal character."); + for (i = 0, count = 0; i < file_len; i++) { + if (pre_buf[i] == ' ' || pre_buf[i] == '\r' + || pre_buf[i] == '\n') + continue; + buf[count++] = pre_buf[i]; + } + + GTP_DEBUG("[update_cfg]Ascii to hex."); + file_config[0] = GTP_REG_CONFIG_DATA >> 8; + file_config[1] = GTP_REG_CONFIG_DATA & 0xff; + for (i = 0, file_cfg_len = GTP_ADDR_LENGTH; i < count; i + = 5) { + if ((buf[i] == '0') && ((buf[i+1] == 'x') || + (buf[i+1] == 'X'))) { + u8 high, low; + + high = ascii2hex(buf[i+2]); + low = ascii2hex(buf[i+3]); + + if ((high == 0xFF) || (low == 0xFF)) { + ret = 0; + GTP_ERROR("[update_cfg]Illegal config file."); + goto update_cfg_file_failed; + } + file_config[file_cfg_len++] = (high<<4) + low; + } else { + ret = 0; + GTP_ERROR("[update_cfg]Illegal config file."); + goto update_cfg_file_failed; + } + } + + /* cal checksum */ + /* for (i=GTP_ADDR_LENGTH; i<chip_cfg_len; i++) + * checksum += file_config[i]; + * file_config[chip_cfg_len] = (~checksum) + 1; + * file_config[chip_cfg_len+1] = 0x01; + */ + + GTP_DEBUG("config:"); + GTP_DEBUG_ARRAY(file_config+2, file_cfg_len); + + i = 0; + while (i++ < 5) { + ret = gup_i2c_write(client, file_config, file_cfg_len); + if (ret > 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; + 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; - - /* - if (path.mnt->mnt_sb == root_path.mnt->mnt_sb) - { - //-- not mounted - return FAIL; - } - else - { - return SUCCESS; - }*/ - + 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; + + /* if (path.mnt->mnt_sb == root_path.mnt->mnt_sb) + * return FAIL; + * else + * return SUCCESS; + */ } #endif -static u8 gup_check_update_file(struct i2c_client *client, st_fw_head* fw_head, u8* path) + +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, 0); - - if (IS_ERR(update_msg.file)) - { - GTP_ERROR("Open update file(%s) error!", path); - return FAIL; - } - } - else - { + 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 = file_open(path, O_RDONLY, 0); + + 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 mounted timeout!"); - return FAIL; - } - - // update config - update_msg.cfg_file = filp_open(CONFIG_FILE_PATH_1, O_RDONLY, 0); - if (IS_ERR(update_msg.cfg_file)) - { - GTP_DEBUG("%s is unavailable", CONFIG_FILE_PATH_1); - } - else - { - GTP_INFO("Update Config File: %s", CONFIG_FILE_PATH_1); - ret = gup_update_config(client); - if(ret <= 0) - { - GTP_ERROR("Update config failed."); - } - filp_close(update_msg.cfg_file, NULL); - } - - if (sizeof(header_fw_array) < (FW_HEAD_LENGTH+FW_SECTION_LENGTH*4+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH)) - { - GTP_ERROR("INVALID header_fw_array, check your gt9xx_firmware.h file!"); - 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 file: %s for fw_header!", UPDATE_FILE_PATH_2); - 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_RDONLY, 0); + 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 mounted timeout!"); + return FAIL; + } + + /* update config */ + update_msg.cfg_file = file_open(CONFIG_FILE_PATH_1, + O_RDONLY, 0); + + if (IS_ERR(update_msg.cfg_file)) { + GTP_DEBUG("%s is unavailable", CONFIG_FILE_PATH_1); + } else { + GTP_INFO("Update Config File: %s", CONFIG_FILE_PATH_1); + ret = gup_update_config(client); + if (ret <= 0) + GTP_ERROR("Update config failed."); + filp_close(update_msg.cfg_file, NULL); + } + + if (sizeof(header_fw_array) < (FW_HEAD_LENGTH+FW_SECTION_LENGTH + *4 + FW_DSP_ISP_LENGTH+FW_DSP_LENGTH + FW_BOOT_LENGTH)) { + GTP_ERROR("INVALID header_fw_array, check your ", + "gt9xx_firmware.h file!"); + return FAIL; + } + update_msg.file = file_open(UPDATE_FILE_PATH_2, O_CREAT | + O_RDWR, 0666); + if ((IS_ERR(update_msg.file))) { + GTP_ERROR("Failed to Create file: %s for fw_header!", + UPDATE_FILE_PATH_2); + 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); + file_close(update_msg.file, NULL); + update_msg.file = file_open(UPDATE_FILE_PATH_2, O_RDONLY, 0); #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. - searching_file = 1; - for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) - { - if (searching_file == 0) - { - kfree(search_update_path); - kfree(search_cfg_path); - GTP_INFO(".bin/.cfg update file search forcely terminated!"); - return FAIL; - } - 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_RDONLY, 0); - 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_RDONLY, 0); - 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); - } - searching_file = 0; - 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; - } + 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 = kzalloc(fp_len, GFP_KERNEL); + u8 *search_cfg_path = kzalloc(cfp_len, GFP_KERNEL); + /* Begin to search update file,the config file & firmware + * file must be in the same path,single or double. + */ + searching_file = 1; + for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) { + if (searching_file == 0) { + kfree(search_update_path); + kfree(search_cfg_path); + GTP_INFO(".bin/.cfg update file search ", + "forcely terminated!"); + return FAIL; + } + 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 = file_open(search_update_path, + O_RDONLY, 0); + 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 = file_open(search_cfg_path, + O_RDONLY, 0); + 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; + i += 4; + } + GTP_DEBUG("%3d:Searching %s %s file...", i, + (got_file_flag & 0x0F) ? "" : "bin", + (got_file_flag & 0xF0) ? "" : "cfg"); + + msleep(3000); + } + + searching_file = 0; + 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; i<FW_SECTION_LENGTH*4+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH; i+=2) - { - u16 temp; - ret = update_msg.file->f_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; + } + + 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; i < FW_SECTION_LENGTH * 4 + FW_DSP_ISP_LENGTH + + FW_DSP_LENGTH + FW_BOOT_LENGTH; i + = 2) { + u16 temp; + + ret = update_msg.file->f_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; + 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) +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; + 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 (ret == SUCCESS) + return SUCCESS; + return FAIL; } #endif -static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr, u16 total_length) +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; + 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) +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; + 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) +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; + 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 ) +static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section, + u16 start_addr, u8 bank_cmdi) { - 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; + 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 (ret == FAIL) { + 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(20); + + /* 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(20); + /* 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 (ret == FAIL) { + 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; + 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 = 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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; + 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; - + 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 = 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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 (ret == FAIL) { + 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; + 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; - + 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 = 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 (ret == FAIL) { + 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); + if (ret <= 0) { + GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_dsp; + } + /* must delay */ + msleep(20); + + /* 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 (ret == FAIL) { + 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(20); + /* 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 (ret == FAIL) { + 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; + 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; - + 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 = 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 (ret == FAIL) { + 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); + if (ret <= 0) { + GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail."); + ret = FAIL; + goto exit_burn_fw_boot; + } + /* must delay */ + msleep(20); + + /* 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 (ret == FAIL) { + 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(20); + /* 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 (ret == FAIL) { + 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; + 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); - - if (searching_file) - { - searching_file = 0; // exit .bin update file searching - GTP_INFO("Exiting searching .bin update file..."); - while ((show_len != 200) && (show_len != 100)) // wait for auto update quitted completely - { - msleep(100); - } - } - - 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 file_fail; - } - - //gtp_reset_guitar(i2c_connect_client, 20); - ret = gup_get_ic_fw_msg(i2c_connect_client); - if(FAIL == ret) - { - GTP_ERROR("[update_proc]get ic message fail."); - goto file_fail; - } - - ret = gup_enter_update_judge(&fw_head); - if(FAIL == ret) - { - GTP_ERROR("[update_proc]Check *.bin file fail."); - goto file_fail; - } - - ts->enter_update = 1; - gtp_irq_disable(ts); + 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) + /* wait main thread to be completed */ + msleep(3000); + + ts = i2c_get_clientdata(i2c_connect_client); + + if (searching_file) { + /* exit .bin update file searching */ + searching_file = 0; + GTP_INFO("Exiting searching .bin update file..."); + /* wait for auto update quitted completely */ + while ((show_len != 200) && (show_len != 100)) + msleep(100); + } + + update_msg.file = NULL; + ret = gup_check_update_file(i2c_connect_client, &fw_head, (u8 *)dir); + if (ret == FAIL) { + GTP_ERROR("[update_proc]check update file fail."); + goto file_fail; + } + + /* gtp_reset_guitar(i2c_connect_client, 20); */ + ret = gup_get_ic_fw_msg(i2c_connect_client); + if (ret == FAIL) { + GTP_ERROR("[update_proc]get ic message fail."); + goto file_fail; + } + + ret = gup_enter_update_judge(&fw_head); + if (ret == FAIL) { + GTP_ERROR("[update_proc]Check *.bin file fail."); + goto file_fail; + } + + ts->enter_update = 1; + gtp_irq_disable(ts); #if GTP_ESD_PROTECT - gtp_esd_switch(ts->client, SWITCH_OFF); + gtp_esd_switch(ts->client, SWITCH_OFF); #endif - 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."); -// } - if (ts->fw_error) - { - GTP_INFO("firmware error auto update, resent config!"); - gup_init_panel(ts); - } - show_len = 100; - total_len = 100; - ts->enter_update = 0; - gtp_irq_enable(ts); - + ret = gup_enter_update_mode(i2c_connect_client); + if (ret == FAIL) { + 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 (ret == FAIL) { + GTP_ERROR("[update_proc]burn dsp isp fail."); + continue; + } + + show_len += 10; + ret = gup_burn_fw_ss51(i2c_connect_client); + if (ret == FAIL) { + GTP_ERROR("[update_proc]burn ss51 firmware fail."); + continue; + } + + show_len += 40; + ret = gup_burn_fw_dsp(i2c_connect_client); + if (ret == FAIL) { + GTP_ERROR("[update_proc]burn dsp firmware fail."); + continue; + } + + show_len += 20; + ret = gup_burn_fw_boot(i2c_connect_client); + if (ret == FAIL) { + GTP_ERROR("[update_proc]burn bootloader fw 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."); + * } + */ + + if (ts->fw_error) { + GTP_INFO("firmware error auto update, resent config!"); + gup_init_panel(ts); + } + show_len = 100; + total_len = 100; + ts->enter_update = 0; + gtp_irq_enable(ts); + #if GTP_ESD_PROTECT - gtp_esd_switch(ts->client, SWITCH_ON); + gtp_esd_switch(ts->client, SWITCH_ON); #endif - filp_close(update_msg.file, NULL); - return SUCCESS; - + filp_close(update_msg.file, NULL); + return SUCCESS; + update_fail: - ts->enter_update = 0; - gtp_irq_enable(ts); - + ts->enter_update = 0; + gtp_irq_enable(ts); + #if GTP_ESD_PROTECT - gtp_esd_switch(ts->client, SWITCH_ON); + gtp_esd_switch(ts->client, SWITCH_ON); #endif file_fail: - if(update_msg.file && !IS_ERR(update_msg.file)) - { - filp_close(update_msg.file, NULL); - } - show_len = 200; - total_len = 100; - return FAIL; + 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; + 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; - } + 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 -EINVAL; + } - return 0; + return 0; } -#endif
\ No newline at end of file +#endif |