Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1 | /* drivers/input/touchscreen/gt9xx_update.c |
| 2 | * |
| 3 | * 2010 - 2012 Goodix Technology. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be a reference |
| 11 | * to you, when you are integrating the GOODiX's CTP IC into your system, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * Latest Version:1.6 |
| 17 | * Author: andrew@goodix.com |
| 18 | * Revision Record: |
| 19 | * V1.0: |
| 20 | * first release. By Andrew, 2012/08/31 |
| 21 | * V1.2: |
| 22 | * add force update,GT9110P pid map. By Andrew, 2012/10/15 |
| 23 | * V1.4: |
| 24 | * 1. add config auto update function; |
| 25 | * 2. modify enter_update_mode; |
| 26 | * 3. add update file cal checksum. |
| 27 | * By Andrew, 2012/12/12 |
| 28 | * V1.6: |
| 29 | * 1. replace guitar_client with i2c_connect_client; |
| 30 | * 2. support firmware header array update. |
| 31 | * By Meta, 2013/03/11 |
| 32 | */ |
| 33 | #include <linux/kthread.h> |
| 34 | #include "gt9xx.h" |
| 35 | |
| 36 | #if GTP_HEADER_FW_UPDATE |
| 37 | #include <linux/namei.h> |
| 38 | #include <linux/mount.h> |
| 39 | #include "gt9xx_firmware.h" |
| 40 | #endif |
| 41 | |
| 42 | #define GUP_REG_HW_INFO 0x4220 |
| 43 | #define GUP_REG_FW_MSG 0x41E4 |
| 44 | #define GUP_REG_PID_VID 0x8140 |
| 45 | |
| 46 | #define GUP_SEARCH_FILE_TIMES 50 |
| 47 | #define UPDATE_FILE_PATH_2 "/data/_goodix_update_.bin" |
| 48 | #define UPDATE_FILE_PATH_1 "/sdcard/_goodix_update_.bin" |
| 49 | |
| 50 | #define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg" |
| 51 | #define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg" |
| 52 | |
| 53 | #define FW_HEAD_LENGTH 14 |
| 54 | #define FW_SECTION_LENGTH 0x2000 |
| 55 | #define FW_DSP_ISP_LENGTH 0x1000 |
| 56 | #define FW_DSP_LENGTH 0x1000 |
| 57 | #define FW_BOOT_LENGTH 0x800 |
| 58 | |
| 59 | #define PACK_SIZE 256 |
| 60 | #define MAX_FRAME_CHECK_TIME 5 |
| 61 | |
| 62 | #define _bRW_MISCTL__SRAM_BANK 0x4048 |
| 63 | #define _bRW_MISCTL__MEM_CD_EN 0x4049 |
| 64 | #define _bRW_MISCTL__CACHE_EN 0x404B |
| 65 | #define _bRW_MISCTL__TMR0_EN 0x40B0 |
| 66 | #define _rRW_MISCTL__SWRST_B0_ 0x4180 |
| 67 | #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184 |
| 68 | #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190 |
| 69 | #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218 |
| 70 | #define _rRW_MISCTL__BOOT_CTL_ 0x5094 |
| 71 | |
| 72 | #define FAIL 0 |
| 73 | #define SUCCESS 1 |
| 74 | |
| 75 | #pragma pack(1) |
| 76 | typedef struct |
| 77 | { |
| 78 | u8 hw_info[4]; //hardware info// |
| 79 | u8 pid[8]; //product id // |
| 80 | u16 vid; //version id // |
| 81 | }st_fw_head; |
| 82 | #pragma pack() |
| 83 | |
| 84 | typedef struct |
| 85 | { |
| 86 | u8 force_update; |
| 87 | u8 fw_flag; |
| 88 | struct file *file; |
| 89 | struct file *cfg_file; |
| 90 | st_fw_head ic_fw_msg; |
| 91 | mm_segment_t old_fs; |
| 92 | }st_update_msg; |
| 93 | |
| 94 | st_update_msg update_msg; |
| 95 | u16 show_len; |
| 96 | u16 total_len; |
| 97 | u8 got_file_flag = 0; |
| 98 | u8 searching_file = 0; |
| 99 | extern u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]; |
| 100 | extern void gtp_reset_guitar(struct i2c_client *client, s32 ms); |
| 101 | extern s32 gtp_send_cfg(struct i2c_client *client); |
| 102 | extern struct i2c_client * i2c_connect_client; |
| 103 | extern void gtp_irq_enable(struct goodix_ts_data *ts); |
| 104 | extern void gtp_irq_disable(struct goodix_ts_data *ts); |
| 105 | extern s32 gtp_i2c_read_dbl_check(struct i2c_client *, u16, u8 *, int); |
| 106 | #if GTP_ESD_PROTECT |
| 107 | extern void gtp_esd_switch(struct i2c_client *, s32); |
| 108 | #endif |
| 109 | /******************************************************* |
| 110 | Function: |
| 111 | Read data from the i2c slave device. |
| 112 | Input: |
| 113 | client: i2c device. |
| 114 | buf[0~1]: read start address. |
| 115 | buf[2~len-1]: read data buffer. |
| 116 | len: GTP_ADDR_LENGTH + read bytes count |
| 117 | Output: |
| 118 | numbers of i2c_msgs to transfer: |
| 119 | 2: succeed, otherwise: failed |
| 120 | *********************************************************/ |
| 121 | s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len) |
| 122 | { |
| 123 | struct i2c_msg msgs[2]; |
| 124 | s32 ret=-1; |
| 125 | s32 retries = 0; |
| 126 | |
| 127 | GTP_DEBUG_FUNC(); |
| 128 | |
| 129 | msgs[0].flags = !I2C_M_RD; |
| 130 | msgs[0].addr = client->addr; |
| 131 | msgs[0].len = GTP_ADDR_LENGTH; |
| 132 | msgs[0].buf = &buf[0]; |
| 133 | //msgs[0].scl_rate = 300 * 1000; // for Rockchip |
| 134 | |
| 135 | msgs[1].flags = I2C_M_RD; |
| 136 | msgs[1].addr = client->addr; |
| 137 | msgs[1].len = len - GTP_ADDR_LENGTH; |
| 138 | msgs[1].buf = &buf[GTP_ADDR_LENGTH]; |
| 139 | //msgs[1].scl_rate = 300 * 1000; |
| 140 | |
| 141 | while(retries < 5) |
| 142 | { |
| 143 | ret = i2c_transfer(client->adapter, msgs, 2); |
| 144 | if(ret == 2)break; |
| 145 | retries++; |
| 146 | } |
| 147 | |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | /******************************************************* |
| 152 | Function: |
| 153 | Write data to the i2c slave device. |
| 154 | Input: |
| 155 | client: i2c device. |
| 156 | buf[0~1]: write start address. |
| 157 | buf[2~len-1]: data buffer |
| 158 | len: GTP_ADDR_LENGTH + write bytes count |
| 159 | Output: |
| 160 | numbers of i2c_msgs to transfer: |
| 161 | 1: succeed, otherwise: failed |
| 162 | *********************************************************/ |
| 163 | s32 gup_i2c_write(struct i2c_client *client,u8 *buf,s32 len) |
| 164 | { |
| 165 | struct i2c_msg msg; |
| 166 | s32 ret=-1; |
| 167 | s32 retries = 0; |
| 168 | |
| 169 | GTP_DEBUG_FUNC(); |
| 170 | |
| 171 | msg.flags = !I2C_M_RD; |
| 172 | msg.addr = client->addr; |
| 173 | msg.len = len; |
| 174 | msg.buf = buf; |
| 175 | //msg.scl_rate = 300 * 1000; // for Rockchip |
| 176 | |
| 177 | while(retries < 5) |
| 178 | { |
| 179 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 180 | if (ret == 1)break; |
| 181 | retries++; |
| 182 | } |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | static s32 gup_init_panel(struct goodix_ts_data *ts) |
| 188 | { |
| 189 | s32 ret = 0; |
| 190 | s32 i = 0; |
| 191 | u8 check_sum = 0; |
| 192 | u8 opr_buf[16]; |
| 193 | u8 sensor_id = 0; |
| 194 | |
| 195 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; |
| 196 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; |
| 197 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; |
| 198 | u8 cfg_info_group4[] = CTP_CFG_GROUP4; |
| 199 | u8 cfg_info_group5[] = CTP_CFG_GROUP5; |
| 200 | u8 cfg_info_group6[] = CTP_CFG_GROUP6; |
| 201 | u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3, |
| 202 | cfg_info_group4, cfg_info_group5, cfg_info_group6}; |
| 203 | u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1), |
| 204 | CFG_GROUP_LEN(cfg_info_group2), |
| 205 | CFG_GROUP_LEN(cfg_info_group3), |
| 206 | CFG_GROUP_LEN(cfg_info_group4), |
| 207 | CFG_GROUP_LEN(cfg_info_group5), |
| 208 | CFG_GROUP_LEN(cfg_info_group6)}; |
| 209 | |
| 210 | if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && |
| 211 | (!cfg_info_len[3]) && (!cfg_info_len[4]) && |
| 212 | (!cfg_info_len[5])) |
| 213 | { |
| 214 | sensor_id = 0; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1); |
| 219 | if (SUCCESS == ret) |
| 220 | { |
| 221 | if (sensor_id >= 0x06) |
| 222 | { |
| 223 | GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id); |
| 224 | return -1; |
| 225 | } |
| 226 | } |
| 227 | else |
| 228 | { |
| 229 | GTP_ERROR("Failed to get sensor_id, No config sent!"); |
| 230 | return -1; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | GTP_DEBUG("Sensor_ID: %d", sensor_id); |
| 235 | |
| 236 | ts->gtp_cfg_len = cfg_info_len[sensor_id]; |
| 237 | |
| 238 | if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) |
| 239 | { |
| 240 | 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); |
| 241 | return -1; |
| 242 | } |
| 243 | |
| 244 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1); |
| 245 | |
| 246 | if (ret == SUCCESS) |
| 247 | { |
| 248 | GTP_DEBUG("CFG_GROUP%d Config Version: %d, IC Config Version: %d", sensor_id+1, |
| 249 | send_cfg_buf[sensor_id][0], opr_buf[0]); |
| 250 | |
| 251 | send_cfg_buf[sensor_id][0] = opr_buf[0]; |
| 252 | ts->fixed_cfg = 0; |
| 253 | /* |
| 254 | if (opr_buf[0] < 90) |
| 255 | { |
| 256 | grp_cfg_version = send_cfg_buf[sensor_id][0]; // backup group config version |
| 257 | send_cfg_buf[sensor_id][0] = 0x00; |
| 258 | ts->fixed_cfg = 0; |
| 259 | } |
| 260 | else // treated as fixed config, not send config |
| 261 | { |
| 262 | GTP_INFO("Ic fixed config with config version(%d)", opr_buf[0]); |
| 263 | ts->fixed_cfg = 1; |
| 264 | }*/ |
| 265 | } |
| 266 | else |
| 267 | { |
| 268 | GTP_ERROR("Failed to get ic config version!No config sent!"); |
| 269 | return -1; |
| 270 | } |
| 271 | |
| 272 | memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); |
| 273 | memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len); |
| 274 | |
| 275 | GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", |
| 276 | ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type); |
| 277 | |
| 278 | config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; |
| 279 | config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8); |
| 280 | config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; |
| 281 | config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8); |
| 282 | |
| 283 | if (GTP_INT_TRIGGER == 0) //RISING |
| 284 | { |
| 285 | config[TRIGGER_LOC] &= 0xfe; |
| 286 | } |
| 287 | else if (GTP_INT_TRIGGER == 1) //FALLING |
| 288 | { |
| 289 | config[TRIGGER_LOC] |= 0x01; |
| 290 | } |
| 291 | |
| 292 | check_sum = 0; |
| 293 | for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) |
| 294 | { |
| 295 | check_sum += config[i]; |
| 296 | } |
| 297 | config[ts->gtp_cfg_len] = (~check_sum) + 1; |
| 298 | |
| 299 | GTP_DEBUG_FUNC(); |
| 300 | ret = gtp_send_cfg(ts->client); |
| 301 | if (ret < 0) |
| 302 | { |
| 303 | GTP_ERROR("Send config error."); |
| 304 | } |
| 305 | |
| 306 | msleep(10); |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8* msg, s32 len) |
| 312 | { |
| 313 | s32 i = 0; |
| 314 | |
| 315 | msg[0] = (addr >> 8) & 0xff; |
| 316 | msg[1] = addr & 0xff; |
| 317 | |
| 318 | for (i = 0; i < 5; i++) |
| 319 | { |
| 320 | if (gup_i2c_read(client, msg, GTP_ADDR_LENGTH + len) > 0) |
| 321 | { |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (i >= 5) |
| 327 | { |
| 328 | GTP_ERROR("Read data from 0x%02x%02x failed!", msg[0], msg[1]); |
| 329 | return FAIL; |
| 330 | } |
| 331 | |
| 332 | return SUCCESS; |
| 333 | } |
| 334 | |
| 335 | static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val) |
| 336 | { |
| 337 | s32 i = 0; |
| 338 | u8 msg[3]; |
| 339 | |
| 340 | msg[0] = (addr >> 8) & 0xff; |
| 341 | msg[1] = addr & 0xff; |
| 342 | msg[2] = val; |
| 343 | |
| 344 | for (i = 0; i < 5; i++) |
| 345 | { |
| 346 | if (gup_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0) |
| 347 | { |
| 348 | break; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if (i >= 5) |
| 353 | { |
| 354 | GTP_ERROR("Set data to 0x%02x%02x failed!", msg[0], msg[1]); |
| 355 | return FAIL; |
| 356 | } |
| 357 | |
| 358 | return SUCCESS; |
| 359 | } |
| 360 | |
| 361 | static u8 gup_get_ic_fw_msg(struct i2c_client *client) |
| 362 | { |
| 363 | s32 ret = -1; |
| 364 | u8 retry = 0; |
| 365 | u8 buf[16]; |
| 366 | u8 i; |
| 367 | |
| 368 | // step1:get hardware info |
| 369 | ret = gtp_i2c_read_dbl_check(client, GUP_REG_HW_INFO, &buf[GTP_ADDR_LENGTH], 4); |
| 370 | if (FAIL == ret) |
| 371 | { |
| 372 | GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit"); |
| 373 | return FAIL; |
| 374 | } |
| 375 | |
| 376 | // buf[2~5]: 00 06 90 00 |
| 377 | // hw_info: 00 90 06 00 |
| 378 | for(i=0; i<4; i++) |
| 379 | { |
| 380 | update_msg.ic_fw_msg.hw_info[i] = buf[GTP_ADDR_LENGTH + 3 - i]; |
| 381 | } |
| 382 | 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], |
| 383 | update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); |
| 384 | // step2:get firmware message |
| 385 | for(retry=0; retry<2; retry++) |
| 386 | { |
| 387 | ret = gup_get_ic_msg(client, GUP_REG_FW_MSG, buf, 1); |
| 388 | if(FAIL == ret) |
| 389 | { |
| 390 | GTP_ERROR("Read firmware message fail."); |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | update_msg.force_update = buf[GTP_ADDR_LENGTH]; |
| 395 | if((0xBE != update_msg.force_update)&&(!retry)) |
| 396 | { |
| 397 | GTP_INFO("The check sum in ic is error."); |
| 398 | GTP_INFO("The IC will be updated by force."); |
| 399 | continue; |
| 400 | } |
| 401 | break; |
| 402 | } |
| 403 | GTP_DEBUG("IC force update flag:0x%x", update_msg.force_update); |
| 404 | |
| 405 | // step3:get pid & vid |
| 406 | ret = gtp_i2c_read_dbl_check(client, GUP_REG_PID_VID, &buf[GTP_ADDR_LENGTH], 6); |
| 407 | if (FAIL == ret) |
| 408 | { |
| 409 | GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit"); |
| 410 | return FAIL; |
| 411 | } |
| 412 | |
| 413 | memset(update_msg.ic_fw_msg.pid, 0, sizeof(update_msg.ic_fw_msg.pid)); |
| 414 | memcpy(update_msg.ic_fw_msg.pid, &buf[GTP_ADDR_LENGTH], 4); |
| 415 | GTP_DEBUG("IC Product id:%s", update_msg.ic_fw_msg.pid); |
| 416 | |
| 417 | //GT9XX PID MAPPING |
| 418 | /*|-----FLASH-----RAM-----| |
| 419 | |------918------918-----| |
| 420 | |------968------968-----| |
| 421 | |------913------913-----| |
| 422 | |------913P-----913P----| |
| 423 | |------927------927-----| |
| 424 | |------927P-----927P----| |
| 425 | |------9110-----9110----| |
| 426 | |------9110P----9111----|*/ |
| 427 | if(update_msg.ic_fw_msg.pid[0] != 0) |
| 428 | { |
| 429 | if(!memcmp(update_msg.ic_fw_msg.pid, "9111", 4)) |
| 430 | { |
| 431 | GTP_DEBUG("IC Mapping Product id:%s", update_msg.ic_fw_msg.pid); |
| 432 | memcpy(update_msg.ic_fw_msg.pid, "9110P", 5); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | update_msg.ic_fw_msg.vid = buf[GTP_ADDR_LENGTH+4] + (buf[GTP_ADDR_LENGTH+5]<<8); |
| 437 | GTP_DEBUG("IC version id:%04x", update_msg.ic_fw_msg.vid); |
| 438 | |
| 439 | return SUCCESS; |
| 440 | } |
| 441 | |
| 442 | s32 gup_enter_update_mode(struct i2c_client *client) |
| 443 | { |
| 444 | s32 ret = -1; |
| 445 | s32 retry = 0; |
| 446 | u8 rd_buf[3]; |
| 447 | |
| 448 | //step1:RST output low last at least 2ms |
| 449 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); |
| 450 | msleep(2); |
| 451 | |
| 452 | //step2:select I2C slave addr,INT:0--0xBA;1--0x28. |
| 453 | GTP_GPIO_OUTPUT(GTP_INT_PORT, (client->addr == 0x14)); |
| 454 | msleep(2); |
| 455 | |
| 456 | //step3:RST output high reset guitar |
| 457 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); |
| 458 | |
| 459 | //20121211 modify start |
| 460 | msleep(5); |
| 461 | while(retry++ < 200) |
| 462 | { |
| 463 | //step4:Hold ss51 & dsp |
| 464 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); |
| 465 | if(ret <= 0) |
| 466 | { |
| 467 | GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | //step5:Confirm hold |
| 472 | ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1); |
| 473 | if(ret <= 0) |
| 474 | { |
| 475 | GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); |
| 476 | continue; |
| 477 | } |
| 478 | if(0x0C == rd_buf[GTP_ADDR_LENGTH]) |
| 479 | { |
| 480 | GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS"); |
| 481 | break; |
| 482 | } |
| 483 | GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf[GTP_ADDR_LENGTH]); |
| 484 | } |
| 485 | if(retry >= 200) |
| 486 | { |
| 487 | GTP_ERROR("Enter update Hold ss51 failed."); |
| 488 | return FAIL; |
| 489 | } |
| 490 | |
| 491 | //step6:DSP_CK and DSP_ALU_CK PowerOn |
| 492 | ret = gup_set_ic_msg(client, 0x4010, 0x00); |
| 493 | |
| 494 | //20121211 modify end |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | void gup_leave_update_mode(void) |
| 499 | { |
| 500 | GTP_GPIO_AS_INT(GTP_INT_PORT); |
| 501 | |
| 502 | GTP_DEBUG("[leave_update_mode]reset chip."); |
| 503 | gtp_reset_guitar(i2c_connect_client, 20); |
| 504 | } |
| 505 | |
| 506 | // Get the correct nvram data |
| 507 | // The correct conditions: |
| 508 | // 1. the hardware info is the same |
| 509 | // 2. the product id is the same |
| 510 | // 3. the firmware version in update file is greater than the firmware version in ic |
| 511 | // or the check sum in ic is wrong |
| 512 | /* Update Conditions: |
| 513 | 1. Same hardware info |
| 514 | 2. Same PID |
| 515 | 3. File PID > IC PID |
| 516 | Force Update Conditions: |
| 517 | 1. Wrong ic firmware checksum |
| 518 | 2. INVALID IC PID or VID |
| 519 | 3. IC PID == 91XX || File PID == 91XX |
| 520 | */ |
| 521 | |
| 522 | static u8 gup_enter_update_judge(st_fw_head *fw_head) |
| 523 | { |
| 524 | u16 u16_tmp; |
| 525 | s32 i = 0; |
| 526 | |
| 527 | u16_tmp = fw_head->vid; |
| 528 | fw_head->vid = (u16)(u16_tmp>>8) + (u16)(u16_tmp<<8); |
| 529 | |
| 530 | 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]); |
| 531 | GTP_DEBUG("FILE PID:%s", fw_head->pid); |
| 532 | GTP_DEBUG("FILE VID:%04x", fw_head->vid); |
| 533 | |
| 534 | 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], |
| 535 | update_msg.ic_fw_msg.hw_info[2], update_msg.ic_fw_msg.hw_info[3]); |
| 536 | GTP_DEBUG("IC PID:%s", update_msg.ic_fw_msg.pid); |
| 537 | GTP_DEBUG("IC VID:%04x", update_msg.ic_fw_msg.vid); |
| 538 | |
| 539 | //First two conditions |
| 540 | if ( !memcmp(fw_head->hw_info, update_msg.ic_fw_msg.hw_info, sizeof(update_msg.ic_fw_msg.hw_info))) |
| 541 | { |
| 542 | GTP_DEBUG("Get the same hardware info."); |
| 543 | if( update_msg.force_update != 0xBE ) |
| 544 | { |
| 545 | GTP_INFO("FW chksum error,need enter update."); |
| 546 | return SUCCESS; |
| 547 | } |
| 548 | |
| 549 | // 20130523 start |
| 550 | if (strlen(update_msg.ic_fw_msg.pid) < 3) |
| 551 | { |
| 552 | GTP_INFO("Illegal IC pid, need enter update"); |
| 553 | return SUCCESS; |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | for (i = 0; i < 3; i++) |
| 558 | { |
| 559 | if ((update_msg.ic_fw_msg.pid[i] < 0x30) || (update_msg.ic_fw_msg.pid[i] > 0x39)) |
| 560 | { |
| 561 | GTP_INFO("Illegal IC pid, out of bound, need enter update"); |
| 562 | return SUCCESS; |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | // 20130523 end |
| 567 | |
| 568 | |
| 569 | if (( !memcmp(fw_head->pid, update_msg.ic_fw_msg.pid, (strlen(fw_head->pid)<3?3:strlen(fw_head->pid))))|| |
| 570 | (!memcmp(update_msg.ic_fw_msg.pid, "91XX", 4))|| |
| 571 | (!memcmp(fw_head->pid, "91XX", 4))) |
| 572 | { |
| 573 | if(!memcmp(fw_head->pid, "91XX", 4)) |
| 574 | { |
| 575 | GTP_DEBUG("Force none same pid update mode."); |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | GTP_DEBUG("Get the same pid."); |
| 580 | } |
| 581 | //The third condition |
| 582 | if (fw_head->vid > update_msg.ic_fw_msg.vid) |
| 583 | { |
| 584 | |
| 585 | GTP_INFO("Need enter update."); |
| 586 | return SUCCESS; |
| 587 | } |
| 588 | GTP_ERROR("Don't meet the third condition."); |
| 589 | GTP_ERROR("File VID <= Ic VID, update aborted!"); |
| 590 | } |
| 591 | else |
| 592 | { |
| 593 | GTP_ERROR("File PID != Ic PID, update aborted!"); |
| 594 | } |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | GTP_ERROR("Different Hardware, update aborted!"); |
| 599 | } |
| 600 | return FAIL; |
| 601 | } |
| 602 | |
| 603 | static u8 ascii2hex(u8 a) |
| 604 | { |
| 605 | s8 value = 0; |
| 606 | |
| 607 | if(a >= '0' && a <= '9') |
| 608 | { |
| 609 | value = a - '0'; |
| 610 | } |
| 611 | else if(a >= 'A' && a <= 'F') |
| 612 | { |
| 613 | value = a - 'A' + 0x0A; |
| 614 | } |
| 615 | else if(a >= 'a' && a <= 'f') |
| 616 | { |
| 617 | value = a - 'a' + 0x0A; |
| 618 | } |
| 619 | else |
| 620 | { |
| 621 | value = 0xff; |
| 622 | } |
| 623 | |
| 624 | return value; |
| 625 | } |
| 626 | |
| 627 | static s8 gup_update_config(struct i2c_client *client) |
| 628 | { |
| 629 | s32 file_len = 0; |
| 630 | s32 ret = 0; |
| 631 | s32 i = 0; |
| 632 | s32 file_cfg_len = 0; |
| 633 | s32 chip_cfg_len = 0; |
| 634 | s32 count = 0; |
| 635 | u8 *buf; |
| 636 | u8 *pre_buf; |
| 637 | u8 *file_config; |
| 638 | //u8 checksum = 0; |
| 639 | u8 pid[8]; |
| 640 | |
| 641 | if(NULL == update_msg.cfg_file) |
| 642 | { |
| 643 | GTP_ERROR("[update_cfg]No need to upgrade config!"); |
| 644 | return FAIL; |
| 645 | } |
| 646 | file_len = update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_END); |
| 647 | |
| 648 | ret = gup_get_ic_msg(client, GUP_REG_PID_VID, pid, 6); |
| 649 | if(FAIL == ret) |
| 650 | { |
| 651 | GTP_ERROR("[update_cfg]Read product id & version id fail."); |
| 652 | return FAIL; |
| 653 | } |
| 654 | pid[5] = '\0'; |
| 655 | GTP_DEBUG("update cfg get pid:%s", &pid[GTP_ADDR_LENGTH]); |
| 656 | |
| 657 | chip_cfg_len = 186; |
| 658 | if(!memcmp(&pid[GTP_ADDR_LENGTH], "968", 3) || |
| 659 | !memcmp(&pid[GTP_ADDR_LENGTH], "910", 3) || |
| 660 | !memcmp(&pid[GTP_ADDR_LENGTH], "960", 3)) |
| 661 | { |
| 662 | chip_cfg_len = 228; |
| 663 | } |
| 664 | GTP_DEBUG("[update_cfg]config file len:%d", file_len); |
| 665 | GTP_DEBUG("[update_cfg]need config len:%d",chip_cfg_len); |
| 666 | if((file_len+5) < chip_cfg_len*5) |
| 667 | { |
| 668 | GTP_ERROR("Config length error"); |
| 669 | return -1; |
| 670 | } |
| 671 | |
| 672 | buf = (u8*)kzalloc(file_len, GFP_KERNEL); |
| 673 | pre_buf = (u8*)kzalloc(file_len, GFP_KERNEL); |
| 674 | file_config = (u8*)kzalloc(chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL); |
| 675 | update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_SET); |
| 676 | |
| 677 | GTP_DEBUG("[update_cfg]Read config from file."); |
| 678 | ret = update_msg.cfg_file->f_op->read(update_msg.cfg_file, (char*)pre_buf, file_len, &update_msg.cfg_file->f_pos); |
| 679 | if(ret<0) |
| 680 | { |
| 681 | GTP_ERROR("[update_cfg]Read config file failed."); |
| 682 | goto update_cfg_file_failed; |
| 683 | } |
| 684 | |
| 685 | GTP_DEBUG("[update_cfg]Delete illgal charactor."); |
| 686 | for(i=0,count=0; i<file_len; i++) |
| 687 | { |
| 688 | if (pre_buf[i] == ' ' || pre_buf[i] == '\r' || pre_buf[i] == '\n') |
| 689 | { |
| 690 | continue; |
| 691 | } |
| 692 | buf[count++] = pre_buf[i]; |
| 693 | } |
| 694 | |
| 695 | GTP_DEBUG("[update_cfg]Ascii to hex."); |
| 696 | file_config[0] = GTP_REG_CONFIG_DATA >> 8; |
| 697 | file_config[1] = GTP_REG_CONFIG_DATA & 0xff; |
| 698 | for(i=0,file_cfg_len=GTP_ADDR_LENGTH; i<count; i+=5) |
| 699 | { |
| 700 | if((buf[i]=='0') && ((buf[i+1]=='x') || (buf[i+1]=='X'))) |
| 701 | { |
| 702 | u8 high,low; |
| 703 | high = ascii2hex(buf[i+2]); |
| 704 | low = ascii2hex(buf[i+3]); |
| 705 | |
| 706 | if((high == 0xFF) || (low == 0xFF)) |
| 707 | { |
| 708 | ret = 0; |
| 709 | GTP_ERROR("[update_cfg]Illegal config file."); |
| 710 | goto update_cfg_file_failed; |
| 711 | } |
| 712 | file_config[file_cfg_len++] = (high<<4) + low; |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | ret = 0; |
| 717 | GTP_ERROR("[update_cfg]Illegal config file."); |
| 718 | goto update_cfg_file_failed; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // //cal checksum |
| 723 | // for(i=GTP_ADDR_LENGTH; i<chip_cfg_len; i++) |
| 724 | // { |
| 725 | // checksum += file_config[i]; |
| 726 | // } |
| 727 | // file_config[chip_cfg_len] = (~checksum) + 1; |
| 728 | // file_config[chip_cfg_len+1] = 0x01; |
| 729 | |
| 730 | GTP_DEBUG("config:"); |
| 731 | GTP_DEBUG_ARRAY(file_config+2, file_cfg_len); |
| 732 | |
| 733 | i = 0; |
| 734 | while(i++ < 5) |
| 735 | { |
| 736 | ret = gup_i2c_write(client, file_config, file_cfg_len); |
| 737 | if(ret > 0) |
| 738 | { |
| 739 | GTP_INFO("[update_cfg]Send config SUCCESS."); |
| 740 | break; |
| 741 | } |
| 742 | GTP_ERROR("[update_cfg]Send config i2c error."); |
| 743 | } |
| 744 | |
| 745 | update_cfg_file_failed: |
| 746 | kfree(pre_buf); |
| 747 | kfree(buf); |
| 748 | kfree(file_config); |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | #if GTP_HEADER_FW_UPDATE |
| 753 | static u8 gup_check_fs_mounted(char *path_name) |
| 754 | { |
| 755 | struct path root_path; |
| 756 | struct path path; |
| 757 | int err; |
| 758 | err = kern_path("/", LOOKUP_FOLLOW, &root_path); |
| 759 | |
| 760 | if (err) |
| 761 | { |
| 762 | GTP_DEBUG("\"/\" NOT Mounted: %d", err); |
| 763 | return FAIL; |
| 764 | } |
| 765 | err = kern_path(path_name, LOOKUP_FOLLOW, &path); |
| 766 | |
| 767 | if (err) |
| 768 | { |
| 769 | GTP_DEBUG("/data/ NOT Mounted: %d", err); |
| 770 | return FAIL; |
| 771 | } |
| 772 | |
| 773 | return SUCCESS; |
| 774 | |
| 775 | /* |
| 776 | if (path.mnt->mnt_sb == root_path.mnt->mnt_sb) |
| 777 | { |
| 778 | //-- not mounted |
| 779 | return FAIL; |
| 780 | } |
| 781 | else |
| 782 | { |
| 783 | return SUCCESS; |
| 784 | }*/ |
| 785 | |
| 786 | } |
| 787 | #endif |
| 788 | static u8 gup_check_update_file(struct i2c_client *client, st_fw_head* fw_head, u8* path) |
| 789 | { |
| 790 | s32 ret = 0; |
| 791 | s32 i = 0; |
| 792 | s32 fw_checksum = 0; |
| 793 | u8 buf[FW_HEAD_LENGTH]; |
| 794 | |
| 795 | if (path) |
| 796 | { |
| 797 | GTP_DEBUG("Update File path:%s, %d", path, strlen(path)); |
| 798 | update_msg.file = filp_open(path, O_RDONLY, 0); |
| 799 | |
| 800 | if (IS_ERR(update_msg.file)) |
| 801 | { |
| 802 | GTP_ERROR("Open update file(%s) error!", path); |
| 803 | return FAIL; |
| 804 | } |
| 805 | } |
| 806 | else |
| 807 | { |
| 808 | #if GTP_HEADER_FW_UPDATE |
| 809 | for (i = 0; i < (GUP_SEARCH_FILE_TIMES); i++) |
| 810 | { |
| 811 | GTP_DEBUG("Waiting for /data mounted [%d]", i); |
| 812 | |
| 813 | if (gup_check_fs_mounted("/data") == SUCCESS) |
| 814 | { |
| 815 | GTP_DEBUG("/data Mounted!"); |
| 816 | break; |
| 817 | } |
| 818 | msleep(3000); |
| 819 | } |
| 820 | if (i >= (GUP_SEARCH_FILE_TIMES)) |
| 821 | { |
| 822 | GTP_ERROR("Wait for /data mounted timeout!"); |
| 823 | return FAIL; |
| 824 | } |
| 825 | |
| 826 | // update config |
| 827 | update_msg.cfg_file = filp_open(CONFIG_FILE_PATH_1, O_RDONLY, 0); |
| 828 | if (IS_ERR(update_msg.cfg_file)) |
| 829 | { |
| 830 | GTP_DEBUG("%s is unavailable", CONFIG_FILE_PATH_1); |
| 831 | } |
| 832 | else |
| 833 | { |
| 834 | GTP_INFO("Update Config File: %s", CONFIG_FILE_PATH_1); |
| 835 | ret = gup_update_config(client); |
| 836 | if(ret <= 0) |
| 837 | { |
| 838 | GTP_ERROR("Update config failed."); |
| 839 | } |
| 840 | filp_close(update_msg.cfg_file, NULL); |
| 841 | } |
| 842 | |
| 843 | if (sizeof(header_fw_array) < (FW_HEAD_LENGTH+FW_SECTION_LENGTH*4+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH)) |
| 844 | { |
| 845 | GTP_ERROR("INVALID header_fw_array, check your gt9xx_firmware.h file!"); |
| 846 | return FAIL; |
| 847 | } |
| 848 | update_msg.file = filp_open(UPDATE_FILE_PATH_2, O_CREAT | O_RDWR, 0666); |
| 849 | if ((IS_ERR(update_msg.file))) |
| 850 | { |
| 851 | GTP_ERROR("Failed to Create file: %s for fw_header!", UPDATE_FILE_PATH_2); |
| 852 | return FAIL; |
| 853 | } |
| 854 | update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET); |
| 855 | update_msg.file->f_op->write(update_msg.file, (char *)header_fw_array, sizeof(header_fw_array), &update_msg.file->f_pos); |
| 856 | filp_close(update_msg.file, NULL); |
| 857 | update_msg.file = filp_open(UPDATE_FILE_PATH_2, O_RDONLY, 0); |
| 858 | #else |
| 859 | u8 fp_len = max(sizeof(UPDATE_FILE_PATH_1), sizeof(UPDATE_FILE_PATH_2)); |
| 860 | u8 cfp_len = max(sizeof(CONFIG_FILE_PATH_1), sizeof(CONFIG_FILE_PATH_2)); |
| 861 | u8 *search_update_path = (u8*)kzalloc(fp_len, GFP_KERNEL); |
| 862 | u8 *search_cfg_path = (u8*)kzalloc(cfp_len, GFP_KERNEL); |
| 863 | //Begin to search update file,the config file & firmware file must be in the same path,single or double. |
| 864 | searching_file = 1; |
| 865 | for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) |
| 866 | { |
| 867 | if (searching_file == 0) |
| 868 | { |
| 869 | kfree(search_update_path); |
| 870 | kfree(search_cfg_path); |
| 871 | GTP_INFO(".bin/.cfg update file search forcely terminated!"); |
| 872 | return FAIL; |
| 873 | } |
| 874 | if(i%2) |
| 875 | { |
| 876 | memcpy(search_update_path, UPDATE_FILE_PATH_1, sizeof(UPDATE_FILE_PATH_1)); |
| 877 | memcpy(search_cfg_path, CONFIG_FILE_PATH_1, sizeof(CONFIG_FILE_PATH_1)); |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | memcpy(search_update_path, UPDATE_FILE_PATH_2, sizeof(UPDATE_FILE_PATH_2)); |
| 882 | memcpy(search_cfg_path, CONFIG_FILE_PATH_2, sizeof(CONFIG_FILE_PATH_2)); |
| 883 | } |
| 884 | |
| 885 | if(!(got_file_flag&0x0F)) |
| 886 | { |
| 887 | update_msg.file = filp_open(search_update_path, O_RDONLY, 0); |
| 888 | if(!IS_ERR(update_msg.file)) |
| 889 | { |
| 890 | GTP_DEBUG("Find the bin file"); |
| 891 | got_file_flag |= 0x0F; |
| 892 | } |
| 893 | } |
| 894 | if(!(got_file_flag&0xF0)) |
| 895 | { |
| 896 | update_msg.cfg_file = filp_open(search_cfg_path, O_RDONLY, 0); |
| 897 | if(!IS_ERR(update_msg.cfg_file)) |
| 898 | { |
| 899 | GTP_DEBUG("Find the cfg file"); |
| 900 | got_file_flag |= 0xF0; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | if(got_file_flag) |
| 905 | { |
| 906 | if(got_file_flag == 0xFF) |
| 907 | { |
| 908 | break; |
| 909 | } |
| 910 | else |
| 911 | { |
| 912 | i += 4; |
| 913 | } |
| 914 | } |
| 915 | GTP_DEBUG("%3d:Searching %s %s file...", i, (got_file_flag&0x0F)?"":"bin", (got_file_flag&0xF0)?"":"cfg"); |
| 916 | msleep(3000); |
| 917 | } |
| 918 | searching_file = 0; |
| 919 | kfree(search_update_path); |
| 920 | kfree(search_cfg_path); |
| 921 | |
| 922 | if(!got_file_flag) |
| 923 | { |
| 924 | GTP_ERROR("Can't find update file."); |
| 925 | goto load_failed; |
| 926 | } |
| 927 | |
| 928 | if(got_file_flag&0xF0) |
| 929 | { |
| 930 | GTP_DEBUG("Got the update config file."); |
| 931 | ret = gup_update_config(client); |
| 932 | if(ret <= 0) |
| 933 | { |
| 934 | GTP_ERROR("Update config failed."); |
| 935 | } |
| 936 | filp_close(update_msg.cfg_file, NULL); |
| 937 | msleep(500); //waiting config to be stored in FLASH. |
| 938 | } |
| 939 | if(got_file_flag&0x0F) |
| 940 | { |
| 941 | GTP_DEBUG("Got the update firmware file."); |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | GTP_ERROR("No need to upgrade firmware."); |
| 946 | goto load_failed; |
| 947 | } |
| 948 | #endif |
| 949 | } |
| 950 | |
| 951 | update_msg.old_fs = get_fs(); |
| 952 | set_fs(KERNEL_DS); |
| 953 | |
| 954 | update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET); |
| 955 | //update_msg.file->f_pos = 0; |
| 956 | |
| 957 | ret = update_msg.file->f_op->read(update_msg.file, (char*)buf, FW_HEAD_LENGTH, &update_msg.file->f_pos); |
| 958 | if (ret < 0) |
| 959 | { |
| 960 | GTP_ERROR("Read firmware head in update file error."); |
| 961 | goto load_failed; |
| 962 | } |
| 963 | memcpy(fw_head, buf, FW_HEAD_LENGTH); |
| 964 | |
| 965 | //check firmware legality |
| 966 | fw_checksum = 0; |
| 967 | for(i=0; i<FW_SECTION_LENGTH*4+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH; i+=2) |
| 968 | { |
| 969 | u16 temp; |
| 970 | ret = update_msg.file->f_op->read(update_msg.file, (char*)buf, 2, &update_msg.file->f_pos); |
| 971 | if (ret < 0) |
| 972 | { |
| 973 | GTP_ERROR("Read firmware file error."); |
| 974 | goto load_failed; |
| 975 | } |
| 976 | //GTP_DEBUG("BUF[0]:%x", buf[0]); |
| 977 | temp = (buf[0]<<8) + buf[1]; |
| 978 | fw_checksum += temp; |
| 979 | } |
| 980 | |
| 981 | GTP_DEBUG("firmware checksum:%x", fw_checksum&0xFFFF); |
| 982 | if(fw_checksum&0xFFFF) |
| 983 | { |
| 984 | GTP_ERROR("Illegal firmware file."); |
| 985 | goto load_failed; |
| 986 | } |
| 987 | |
| 988 | return SUCCESS; |
| 989 | |
| 990 | load_failed: |
| 991 | set_fs(update_msg.old_fs); |
| 992 | return FAIL; |
| 993 | } |
| 994 | |
| 995 | #if 0 |
| 996 | static u8 gup_check_update_header(struct i2c_client *client, st_fw_head* fw_head) |
| 997 | { |
| 998 | const u8* pos; |
| 999 | int i = 0; |
| 1000 | u8 mask_num = 0; |
| 1001 | s32 ret = 0; |
| 1002 | |
| 1003 | pos = HEADER_UPDATE_DATA; |
| 1004 | |
| 1005 | memcpy(fw_head, pos, FW_HEAD_LENGTH); |
| 1006 | pos += FW_HEAD_LENGTH; |
| 1007 | |
| 1008 | ret = gup_enter_update_judge(fw_head); |
| 1009 | if(SUCCESS == ret) |
| 1010 | { |
| 1011 | return SUCCESS; |
| 1012 | } |
| 1013 | return FAIL; |
| 1014 | } |
| 1015 | #endif |
| 1016 | |
| 1017 | static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr, u16 total_length) |
| 1018 | { |
| 1019 | s32 ret = 0; |
| 1020 | u16 burn_addr = start_addr; |
| 1021 | u16 frame_length = 0; |
| 1022 | u16 burn_length = 0; |
| 1023 | u8 wr_buf[PACK_SIZE + GTP_ADDR_LENGTH]; |
| 1024 | u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; |
| 1025 | u8 retry = 0; |
| 1026 | |
| 1027 | GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length/1024), start_addr); |
| 1028 | while(burn_length < total_length) |
| 1029 | { |
| 1030 | GTP_DEBUG("B/T:%04d/%04d", burn_length, total_length); |
| 1031 | frame_length = ((total_length - burn_length) > PACK_SIZE) ? PACK_SIZE : (total_length - burn_length); |
| 1032 | wr_buf[0] = (u8)(burn_addr>>8); |
| 1033 | rd_buf[0] = wr_buf[0]; |
| 1034 | wr_buf[1] = (u8)burn_addr; |
| 1035 | rd_buf[1] = wr_buf[1]; |
| 1036 | memcpy(&wr_buf[GTP_ADDR_LENGTH], &burn_buf[burn_length], frame_length); |
| 1037 | |
| 1038 | for(retry = 0; retry < MAX_FRAME_CHECK_TIME; retry++) |
| 1039 | { |
| 1040 | ret = gup_i2c_write(client, wr_buf, GTP_ADDR_LENGTH + frame_length); |
| 1041 | if(ret <= 0) |
| 1042 | { |
| 1043 | GTP_ERROR("Write frame data i2c error."); |
| 1044 | continue; |
| 1045 | } |
| 1046 | ret = gup_i2c_read(client, rd_buf, GTP_ADDR_LENGTH + frame_length); |
| 1047 | if(ret <= 0) |
| 1048 | { |
| 1049 | GTP_ERROR("Read back frame data i2c error."); |
| 1050 | continue; |
| 1051 | } |
| 1052 | |
| 1053 | if(memcmp(&wr_buf[GTP_ADDR_LENGTH], &rd_buf[GTP_ADDR_LENGTH], frame_length)) |
| 1054 | { |
| 1055 | GTP_ERROR("Check frame data fail,not equal."); |
| 1056 | GTP_DEBUG("write array:"); |
| 1057 | GTP_DEBUG_ARRAY(&wr_buf[GTP_ADDR_LENGTH], frame_length); |
| 1058 | GTP_DEBUG("read array:"); |
| 1059 | GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length); |
| 1060 | continue; |
| 1061 | } |
| 1062 | else |
| 1063 | { |
| 1064 | //GTP_DEBUG("Check frame data success."); |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | if(retry >= MAX_FRAME_CHECK_TIME) |
| 1069 | { |
| 1070 | GTP_ERROR("Burn frame data time out,exit."); |
| 1071 | return FAIL; |
| 1072 | } |
| 1073 | burn_length += frame_length; |
| 1074 | burn_addr += frame_length; |
| 1075 | } |
| 1076 | return SUCCESS; |
| 1077 | } |
| 1078 | |
| 1079 | static u8 gup_load_section_file(u8* buf, u16 offset, u16 length) |
| 1080 | { |
| 1081 | s32 ret = 0; |
| 1082 | |
| 1083 | if(update_msg.file == NULL) |
| 1084 | { |
| 1085 | GTP_ERROR("cannot find update file,load section file fail."); |
| 1086 | return FAIL; |
| 1087 | } |
| 1088 | update_msg.file->f_pos = FW_HEAD_LENGTH + offset; |
| 1089 | |
| 1090 | ret = update_msg.file->f_op->read(update_msg.file, (char*)buf, length, &update_msg.file->f_pos); |
| 1091 | if(ret < 0) |
| 1092 | { |
| 1093 | GTP_ERROR("Read update file fail."); |
| 1094 | return FAIL; |
| 1095 | } |
| 1096 | |
| 1097 | return SUCCESS; |
| 1098 | } |
| 1099 | |
| 1100 | static u8 gup_recall_check(struct i2c_client *client, u8* chk_src, u16 start_rd_addr, u16 chk_length) |
| 1101 | { |
| 1102 | u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH]; |
| 1103 | s32 ret = 0; |
| 1104 | u16 recall_addr = start_rd_addr; |
| 1105 | u16 recall_length = 0; |
| 1106 | u16 frame_length = 0; |
| 1107 | |
| 1108 | while(recall_length < chk_length) |
| 1109 | { |
| 1110 | frame_length = ((chk_length - recall_length) > PACK_SIZE) ? PACK_SIZE : (chk_length - recall_length); |
| 1111 | ret = gup_get_ic_msg(client, recall_addr, rd_buf, frame_length); |
| 1112 | if(ret <= 0) |
| 1113 | { |
| 1114 | GTP_ERROR("recall i2c error,exit"); |
| 1115 | return FAIL; |
| 1116 | } |
| 1117 | |
| 1118 | if(memcmp(&rd_buf[GTP_ADDR_LENGTH], &chk_src[recall_length], frame_length)) |
| 1119 | { |
| 1120 | GTP_ERROR("Recall frame data fail,not equal."); |
| 1121 | GTP_DEBUG("chk_src array:"); |
| 1122 | GTP_DEBUG_ARRAY(&chk_src[recall_length], frame_length); |
| 1123 | GTP_DEBUG("recall array:"); |
| 1124 | GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length); |
| 1125 | return FAIL; |
| 1126 | } |
| 1127 | |
| 1128 | recall_length += frame_length; |
| 1129 | recall_addr += frame_length; |
| 1130 | } |
| 1131 | GTP_DEBUG("Recall check %dk firmware success.", (chk_length/1024)); |
| 1132 | |
| 1133 | return SUCCESS; |
| 1134 | } |
| 1135 | |
| 1136 | static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section, u16 start_addr, u8 bank_cmd ) |
| 1137 | { |
| 1138 | s32 ret = 0; |
| 1139 | u8 rd_buf[5]; |
| 1140 | |
| 1141 | //step1:hold ss51 & dsp |
| 1142 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); |
| 1143 | if(ret <= 0) |
| 1144 | { |
| 1145 | GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail."); |
| 1146 | return FAIL; |
| 1147 | } |
| 1148 | |
| 1149 | //step2:set scramble |
| 1150 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); |
| 1151 | if(ret <= 0) |
| 1152 | { |
| 1153 | GTP_ERROR("[burn_fw_section]set scramble fail."); |
| 1154 | return FAIL; |
| 1155 | } |
| 1156 | |
| 1157 | //step3:select bank |
| 1158 | ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); |
| 1159 | if(ret <= 0) |
| 1160 | { |
| 1161 | GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4)&0x0F); |
| 1162 | return FAIL; |
| 1163 | } |
| 1164 | |
| 1165 | //step4:enable accessing code |
| 1166 | ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); |
| 1167 | if(ret <= 0) |
| 1168 | { |
| 1169 | GTP_ERROR("[burn_fw_section]enable accessing code fail."); |
| 1170 | return FAIL; |
| 1171 | } |
| 1172 | |
| 1173 | //step5:burn 8k fw section |
| 1174 | ret = gup_burn_proc(client, fw_section, start_addr, FW_SECTION_LENGTH); |
| 1175 | if(FAIL == ret) |
| 1176 | { |
| 1177 | GTP_ERROR("[burn_fw_section]burn fw_section fail."); |
| 1178 | return FAIL; |
| 1179 | } |
| 1180 | |
| 1181 | //step6:hold ss51 & release dsp |
| 1182 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); |
| 1183 | if(ret <= 0) |
| 1184 | { |
| 1185 | GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail."); |
| 1186 | return FAIL; |
| 1187 | } |
| 1188 | //must delay |
| 1189 | msleep(1); |
| 1190 | |
| 1191 | //step7:send burn cmd to move data to flash from sram |
| 1192 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd&0x0f); |
| 1193 | if(ret <= 0) |
| 1194 | { |
| 1195 | GTP_ERROR("[burn_fw_section]send burn cmd fail."); |
| 1196 | return FAIL; |
| 1197 | } |
| 1198 | GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......"); |
| 1199 | do{ |
| 1200 | ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); |
| 1201 | if(ret <= 0) |
| 1202 | { |
| 1203 | GTP_ERROR("[burn_fw_section]Get burn state fail"); |
| 1204 | return FAIL; |
| 1205 | } |
| 1206 | msleep(10); |
| 1207 | //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); |
| 1208 | }while(rd_buf[GTP_ADDR_LENGTH]); |
| 1209 | |
| 1210 | //step8:select bank |
| 1211 | ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4)&0x0F); |
| 1212 | if(ret <= 0) |
| 1213 | { |
| 1214 | GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4)&0x0F); |
| 1215 | return FAIL; |
| 1216 | } |
| 1217 | |
| 1218 | //step9:enable accessing code |
| 1219 | ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); |
| 1220 | if(ret <= 0) |
| 1221 | { |
| 1222 | GTP_ERROR("[burn_fw_section]enable accessing code fail."); |
| 1223 | return FAIL; |
| 1224 | } |
| 1225 | |
| 1226 | //step10:recall 8k fw section |
| 1227 | ret = gup_recall_check(client, fw_section, start_addr, FW_SECTION_LENGTH); |
| 1228 | if(FAIL == ret) |
| 1229 | { |
| 1230 | GTP_ERROR("[burn_fw_section]recall check 8k firmware fail."); |
| 1231 | return FAIL; |
| 1232 | } |
| 1233 | |
| 1234 | //step11:disable accessing code |
| 1235 | ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x00); |
| 1236 | if(ret <= 0) |
| 1237 | { |
| 1238 | GTP_ERROR("[burn_fw_section]disable accessing code fail."); |
| 1239 | return FAIL; |
| 1240 | } |
| 1241 | |
| 1242 | return SUCCESS; |
| 1243 | } |
| 1244 | |
| 1245 | static u8 gup_burn_dsp_isp(struct i2c_client *client) |
| 1246 | { |
| 1247 | s32 ret = 0; |
| 1248 | u8* fw_dsp_isp = NULL; |
| 1249 | u8 retry = 0; |
| 1250 | |
| 1251 | GTP_DEBUG("[burn_dsp_isp]Begin burn dsp isp---->>"); |
| 1252 | |
| 1253 | //step1:alloc memory |
| 1254 | GTP_DEBUG("[burn_dsp_isp]step1:alloc memory"); |
| 1255 | while(retry++ < 5) |
| 1256 | { |
| 1257 | fw_dsp_isp = (u8*)kzalloc(FW_DSP_ISP_LENGTH, GFP_KERNEL); |
| 1258 | if(fw_dsp_isp == NULL) |
| 1259 | { |
| 1260 | continue; |
| 1261 | } |
| 1262 | else |
| 1263 | { |
| 1264 | GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH/1024)); |
| 1265 | break; |
| 1266 | } |
| 1267 | } |
| 1268 | if(retry >= 5) |
| 1269 | { |
| 1270 | GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit."); |
| 1271 | return FAIL; |
| 1272 | } |
| 1273 | |
| 1274 | //step2:load dsp isp file data |
| 1275 | GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data"); |
| 1276 | ret = gup_load_section_file(fw_dsp_isp, (4*FW_SECTION_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH), FW_DSP_ISP_LENGTH); |
| 1277 | if(FAIL == ret) |
| 1278 | { |
| 1279 | GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail."); |
| 1280 | goto exit_burn_dsp_isp; |
| 1281 | } |
| 1282 | |
| 1283 | //step3:disable wdt,clear cache enable |
| 1284 | GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable"); |
| 1285 | ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00); |
| 1286 | if(ret <= 0) |
| 1287 | { |
| 1288 | GTP_ERROR("[burn_dsp_isp]disable wdt fail."); |
| 1289 | ret = FAIL; |
| 1290 | goto exit_burn_dsp_isp; |
| 1291 | } |
| 1292 | ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00); |
| 1293 | if(ret <= 0) |
| 1294 | { |
| 1295 | GTP_ERROR("[burn_dsp_isp]clear cache enable fail."); |
| 1296 | ret = FAIL; |
| 1297 | goto exit_burn_dsp_isp; |
| 1298 | } |
| 1299 | |
| 1300 | //step4:hold ss51 & dsp |
| 1301 | GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp"); |
| 1302 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); |
| 1303 | if(ret <= 0) |
| 1304 | { |
| 1305 | GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail."); |
| 1306 | ret = FAIL; |
| 1307 | goto exit_burn_dsp_isp; |
| 1308 | } |
| 1309 | |
| 1310 | //step5:set boot from sram |
| 1311 | GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram"); |
| 1312 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02); |
| 1313 | if(ret <= 0) |
| 1314 | { |
| 1315 | GTP_ERROR("[burn_dsp_isp]set boot from sram fail."); |
| 1316 | ret = FAIL; |
| 1317 | goto exit_burn_dsp_isp; |
| 1318 | } |
| 1319 | |
| 1320 | //step6:software reboot |
| 1321 | GTP_DEBUG("[burn_dsp_isp]step6:software reboot"); |
| 1322 | ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01); |
| 1323 | if(ret <= 0) |
| 1324 | { |
| 1325 | GTP_ERROR("[burn_dsp_isp]software reboot fail."); |
| 1326 | ret = FAIL; |
| 1327 | goto exit_burn_dsp_isp; |
| 1328 | } |
| 1329 | |
| 1330 | //step7:select bank2 |
| 1331 | GTP_DEBUG("[burn_dsp_isp]step7:select bank2"); |
| 1332 | ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02); |
| 1333 | if(ret <= 0) |
| 1334 | { |
| 1335 | GTP_ERROR("[burn_dsp_isp]select bank2 fail."); |
| 1336 | ret = FAIL; |
| 1337 | goto exit_burn_dsp_isp; |
| 1338 | } |
| 1339 | |
| 1340 | //step8:enable accessing code |
| 1341 | GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code"); |
| 1342 | ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01); |
| 1343 | if(ret <= 0) |
| 1344 | { |
| 1345 | GTP_ERROR("[burn_dsp_isp]enable accessing code fail."); |
| 1346 | ret = FAIL; |
| 1347 | goto exit_burn_dsp_isp; |
| 1348 | } |
| 1349 | |
| 1350 | //step9:burn 4k dsp_isp |
| 1351 | GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp"); |
| 1352 | ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH); |
| 1353 | if(FAIL == ret) |
| 1354 | { |
| 1355 | GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail."); |
| 1356 | goto exit_burn_dsp_isp; |
| 1357 | } |
| 1358 | |
| 1359 | //step10:set scramble |
| 1360 | GTP_DEBUG("[burn_dsp_isp]step10:set scramble"); |
| 1361 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); |
| 1362 | if(ret <= 0) |
| 1363 | { |
| 1364 | GTP_ERROR("[burn_dsp_isp]set scramble fail."); |
| 1365 | ret = FAIL; |
| 1366 | goto exit_burn_dsp_isp; |
| 1367 | } |
| 1368 | ret = SUCCESS; |
| 1369 | |
| 1370 | exit_burn_dsp_isp: |
| 1371 | kfree(fw_dsp_isp); |
| 1372 | return ret; |
| 1373 | } |
| 1374 | |
| 1375 | static u8 gup_burn_fw_ss51(struct i2c_client *client) |
| 1376 | { |
| 1377 | u8* fw_ss51 = NULL; |
| 1378 | u8 retry = 0; |
| 1379 | s32 ret = 0; |
| 1380 | |
| 1381 | GTP_DEBUG("[burn_fw_ss51]Begin burn ss51 firmware---->>"); |
| 1382 | |
| 1383 | //step1:alloc memory |
| 1384 | GTP_DEBUG("[burn_fw_ss51]step1:alloc memory"); |
| 1385 | while(retry++ < 5) |
| 1386 | { |
| 1387 | fw_ss51 = (u8*)kzalloc(FW_SECTION_LENGTH, GFP_KERNEL); |
| 1388 | if(fw_ss51 == NULL) |
| 1389 | { |
| 1390 | continue; |
| 1391 | } |
| 1392 | else |
| 1393 | { |
| 1394 | GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); |
| 1395 | break; |
| 1396 | } |
| 1397 | } |
| 1398 | if(retry >= 5) |
| 1399 | { |
| 1400 | GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit."); |
| 1401 | return FAIL; |
| 1402 | } |
| 1403 | |
| 1404 | //step2:load ss51 firmware section 1 file data |
| 1405 | GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data"); |
| 1406 | ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH); |
| 1407 | if(FAIL == ret) |
| 1408 | { |
| 1409 | GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail."); |
| 1410 | goto exit_burn_fw_ss51; |
| 1411 | } |
| 1412 | |
| 1413 | //step3:clear control flag |
| 1414 | GTP_DEBUG("[burn_fw_ss51]step3:clear control flag"); |
| 1415 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00); |
| 1416 | if(ret <= 0) |
| 1417 | { |
| 1418 | GTP_ERROR("[burn_fw_ss51]clear control flag fail."); |
| 1419 | ret = FAIL; |
| 1420 | goto exit_burn_fw_ss51; |
| 1421 | } |
| 1422 | |
| 1423 | //step4:burn ss51 firmware section 1 |
| 1424 | GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1"); |
| 1425 | ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01); |
| 1426 | if(FAIL == ret) |
| 1427 | { |
| 1428 | GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail."); |
| 1429 | goto exit_burn_fw_ss51; |
| 1430 | } |
| 1431 | |
| 1432 | //step5:load ss51 firmware section 2 file data |
| 1433 | GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data"); |
| 1434 | ret = gup_load_section_file(fw_ss51, FW_SECTION_LENGTH, FW_SECTION_LENGTH); |
| 1435 | if(FAIL == ret) |
| 1436 | { |
| 1437 | GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail."); |
| 1438 | goto exit_burn_fw_ss51; |
| 1439 | } |
| 1440 | |
| 1441 | //step6:burn ss51 firmware section 2 |
| 1442 | GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2"); |
| 1443 | ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02); |
| 1444 | if(FAIL == ret) |
| 1445 | { |
| 1446 | GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail."); |
| 1447 | goto exit_burn_fw_ss51; |
| 1448 | } |
| 1449 | |
| 1450 | //step7:load ss51 firmware section 3 file data |
| 1451 | GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data"); |
| 1452 | ret = gup_load_section_file(fw_ss51, 2*FW_SECTION_LENGTH, FW_SECTION_LENGTH); |
| 1453 | if(FAIL == ret) |
| 1454 | { |
| 1455 | GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail."); |
| 1456 | goto exit_burn_fw_ss51; |
| 1457 | } |
| 1458 | |
| 1459 | //step8:burn ss51 firmware section 3 |
| 1460 | GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3"); |
| 1461 | ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13); |
| 1462 | if(FAIL == ret) |
| 1463 | { |
| 1464 | GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail."); |
| 1465 | goto exit_burn_fw_ss51; |
| 1466 | } |
| 1467 | |
| 1468 | //step9:load ss51 firmware section 4 file data |
| 1469 | GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data"); |
| 1470 | ret = gup_load_section_file(fw_ss51, 3*FW_SECTION_LENGTH, FW_SECTION_LENGTH); |
| 1471 | if(FAIL == ret) |
| 1472 | { |
| 1473 | GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail."); |
| 1474 | goto exit_burn_fw_ss51; |
| 1475 | } |
| 1476 | |
| 1477 | //step10:burn ss51 firmware section 4 |
| 1478 | GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4"); |
| 1479 | ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14); |
| 1480 | if(FAIL == ret) |
| 1481 | { |
| 1482 | GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail."); |
| 1483 | goto exit_burn_fw_ss51; |
| 1484 | } |
| 1485 | |
| 1486 | ret = SUCCESS; |
| 1487 | |
| 1488 | exit_burn_fw_ss51: |
| 1489 | kfree(fw_ss51); |
| 1490 | return ret; |
| 1491 | } |
| 1492 | |
| 1493 | static u8 gup_burn_fw_dsp(struct i2c_client *client) |
| 1494 | { |
| 1495 | s32 ret = 0; |
| 1496 | u8* fw_dsp = NULL; |
| 1497 | u8 retry = 0; |
| 1498 | u8 rd_buf[5]; |
| 1499 | |
| 1500 | GTP_DEBUG("[burn_fw_dsp]Begin burn dsp firmware---->>"); |
| 1501 | //step1:alloc memory |
| 1502 | GTP_DEBUG("[burn_fw_dsp]step1:alloc memory"); |
| 1503 | while(retry++ < 5) |
| 1504 | { |
| 1505 | fw_dsp = (u8*)kzalloc(FW_DSP_LENGTH, GFP_KERNEL); |
| 1506 | if(fw_dsp == NULL) |
| 1507 | { |
| 1508 | continue; |
| 1509 | } |
| 1510 | else |
| 1511 | { |
| 1512 | GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH/1024)); |
| 1513 | break; |
| 1514 | } |
| 1515 | } |
| 1516 | if(retry >= 5) |
| 1517 | { |
| 1518 | GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit."); |
| 1519 | return FAIL; |
| 1520 | } |
| 1521 | |
| 1522 | //step2:load firmware dsp |
| 1523 | GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp"); |
| 1524 | ret = gup_load_section_file(fw_dsp, 4*FW_SECTION_LENGTH, FW_DSP_LENGTH); |
| 1525 | if(FAIL == ret) |
| 1526 | { |
| 1527 | GTP_ERROR("[burn_fw_dsp]load firmware dsp fail."); |
| 1528 | goto exit_burn_fw_dsp; |
| 1529 | } |
| 1530 | |
| 1531 | //step3:select bank3 |
| 1532 | GTP_DEBUG("[burn_fw_dsp]step3:select bank3"); |
| 1533 | ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); |
| 1534 | if(ret <= 0) |
| 1535 | { |
| 1536 | GTP_ERROR("[burn_fw_dsp]select bank3 fail."); |
| 1537 | ret = FAIL; |
| 1538 | goto exit_burn_fw_dsp; |
| 1539 | } |
| 1540 | |
| 1541 | //step4:hold ss51 & dsp |
| 1542 | GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp"); |
| 1543 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); |
| 1544 | if(ret <= 0) |
| 1545 | { |
| 1546 | GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail."); |
| 1547 | ret = FAIL; |
| 1548 | goto exit_burn_fw_dsp; |
| 1549 | } |
| 1550 | |
| 1551 | //step5:set scramble |
| 1552 | GTP_DEBUG("[burn_fw_dsp]step5:set scramble"); |
| 1553 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); |
| 1554 | if(ret <= 0) |
| 1555 | { |
| 1556 | GTP_ERROR("[burn_fw_dsp]set scramble fail."); |
| 1557 | ret = FAIL; |
| 1558 | goto exit_burn_fw_dsp; |
| 1559 | } |
| 1560 | |
| 1561 | //step6:release ss51 & dsp |
| 1562 | GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp"); |
| 1563 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); //20121211 |
| 1564 | if(ret <= 0) |
| 1565 | { |
| 1566 | GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail."); |
| 1567 | ret = FAIL; |
| 1568 | goto exit_burn_fw_dsp; |
| 1569 | } |
| 1570 | //must delay |
| 1571 | msleep(1); |
| 1572 | |
| 1573 | //step7:burn 4k dsp firmware |
| 1574 | GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware"); |
| 1575 | ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH); |
| 1576 | if(FAIL == ret) |
| 1577 | { |
| 1578 | GTP_ERROR("[burn_fw_dsp]burn fw_section fail."); |
| 1579 | goto exit_burn_fw_dsp; |
| 1580 | } |
| 1581 | |
| 1582 | //step8:send burn cmd to move data to flash from sram |
| 1583 | GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram"); |
| 1584 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05); |
| 1585 | if(ret <= 0) |
| 1586 | { |
| 1587 | GTP_ERROR("[burn_fw_dsp]send burn cmd fail."); |
| 1588 | goto exit_burn_fw_dsp; |
| 1589 | } |
| 1590 | GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......"); |
| 1591 | do{ |
| 1592 | ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); |
| 1593 | if(ret <= 0) |
| 1594 | { |
| 1595 | GTP_ERROR("[burn_fw_dsp]Get burn state fail"); |
| 1596 | goto exit_burn_fw_dsp; |
| 1597 | } |
| 1598 | msleep(10); |
| 1599 | //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); |
| 1600 | }while(rd_buf[GTP_ADDR_LENGTH]); |
| 1601 | |
| 1602 | //step9:recall check 4k dsp firmware |
| 1603 | GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware"); |
| 1604 | ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH); |
| 1605 | if(FAIL == ret) |
| 1606 | { |
| 1607 | GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail."); |
| 1608 | goto exit_burn_fw_dsp; |
| 1609 | } |
| 1610 | |
| 1611 | ret = SUCCESS; |
| 1612 | |
| 1613 | exit_burn_fw_dsp: |
| 1614 | kfree(fw_dsp); |
| 1615 | return ret; |
| 1616 | } |
| 1617 | |
| 1618 | static u8 gup_burn_fw_boot(struct i2c_client *client) |
| 1619 | { |
| 1620 | s32 ret = 0; |
| 1621 | u8* fw_boot = NULL; |
| 1622 | u8 retry = 0; |
| 1623 | u8 rd_buf[5]; |
| 1624 | |
| 1625 | GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>"); |
| 1626 | |
| 1627 | //step1:Alloc memory |
| 1628 | GTP_DEBUG("[burn_fw_boot]step1:Alloc memory"); |
| 1629 | while(retry++ < 5) |
| 1630 | { |
| 1631 | fw_boot = (u8*)kzalloc(FW_BOOT_LENGTH, GFP_KERNEL); |
| 1632 | if(fw_boot == NULL) |
| 1633 | { |
| 1634 | continue; |
| 1635 | } |
| 1636 | else |
| 1637 | { |
| 1638 | GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH/1024)); |
| 1639 | break; |
| 1640 | } |
| 1641 | } |
| 1642 | if(retry >= 5) |
| 1643 | { |
| 1644 | GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit."); |
| 1645 | return FAIL; |
| 1646 | } |
| 1647 | |
| 1648 | //step2:load firmware bootloader |
| 1649 | GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader"); |
| 1650 | ret = gup_load_section_file(fw_boot, (4*FW_SECTION_LENGTH+FW_DSP_LENGTH), FW_BOOT_LENGTH); |
| 1651 | if(FAIL == ret) |
| 1652 | { |
| 1653 | GTP_ERROR("[burn_fw_boot]load firmware dsp fail."); |
| 1654 | goto exit_burn_fw_boot; |
| 1655 | } |
| 1656 | |
| 1657 | //step3:hold ss51 & dsp |
| 1658 | GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp"); |
| 1659 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C); |
| 1660 | if(ret <= 0) |
| 1661 | { |
| 1662 | GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail."); |
| 1663 | ret = FAIL; |
| 1664 | goto exit_burn_fw_boot; |
| 1665 | } |
| 1666 | |
| 1667 | //step4:set scramble |
| 1668 | GTP_DEBUG("[burn_fw_boot]step4:set scramble"); |
| 1669 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00); |
| 1670 | if(ret <= 0) |
| 1671 | { |
| 1672 | GTP_ERROR("[burn_fw_boot]set scramble fail."); |
| 1673 | ret = FAIL; |
| 1674 | goto exit_burn_fw_boot; |
| 1675 | } |
| 1676 | |
| 1677 | //step5:release ss51 & dsp |
| 1678 | GTP_DEBUG("[burn_fw_boot]step5:release ss51 & dsp"); |
| 1679 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04); //20121211 |
| 1680 | if(ret <= 0) |
| 1681 | { |
| 1682 | GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail."); |
| 1683 | ret = FAIL; |
| 1684 | goto exit_burn_fw_boot; |
| 1685 | } |
| 1686 | //must delay |
| 1687 | msleep(1); |
| 1688 | |
| 1689 | //step6:select bank3 |
| 1690 | GTP_DEBUG("[burn_fw_boot]step6:select bank3"); |
| 1691 | ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03); |
| 1692 | if(ret <= 0) |
| 1693 | { |
| 1694 | GTP_ERROR("[burn_fw_boot]select bank3 fail."); |
| 1695 | ret = FAIL; |
| 1696 | goto exit_burn_fw_boot; |
| 1697 | } |
| 1698 | |
| 1699 | //step7:burn 2k bootloader firmware |
| 1700 | GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware"); |
| 1701 | ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH); |
| 1702 | if(FAIL == ret) |
| 1703 | { |
| 1704 | GTP_ERROR("[burn_fw_boot]burn fw_section fail."); |
| 1705 | goto exit_burn_fw_boot; |
| 1706 | } |
| 1707 | |
| 1708 | //step7:send burn cmd to move data to flash from sram |
| 1709 | GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram"); |
| 1710 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06); |
| 1711 | if(ret <= 0) |
| 1712 | { |
| 1713 | GTP_ERROR("[burn_fw_boot]send burn cmd fail."); |
| 1714 | goto exit_burn_fw_boot; |
| 1715 | } |
| 1716 | GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......"); |
| 1717 | do{ |
| 1718 | ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1); |
| 1719 | if(ret <= 0) |
| 1720 | { |
| 1721 | GTP_ERROR("[burn_fw_boot]Get burn state fail"); |
| 1722 | goto exit_burn_fw_boot; |
| 1723 | } |
| 1724 | msleep(10); |
| 1725 | //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); |
| 1726 | }while(rd_buf[GTP_ADDR_LENGTH]); |
| 1727 | |
| 1728 | //step8:recall check 2k bootloader firmware |
| 1729 | GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware"); |
| 1730 | ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH); |
| 1731 | if(FAIL == ret) |
| 1732 | { |
| 1733 | GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail."); |
| 1734 | goto exit_burn_fw_boot; |
| 1735 | } |
| 1736 | |
| 1737 | //step9:enable download DSP code |
| 1738 | GTP_DEBUG("[burn_fw_boot]step9:enable download DSP code "); |
| 1739 | ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99); |
| 1740 | if(ret <= 0) |
| 1741 | { |
| 1742 | GTP_ERROR("[burn_fw_boot]enable download DSP code fail."); |
| 1743 | ret = FAIL; |
| 1744 | goto exit_burn_fw_boot; |
| 1745 | } |
| 1746 | |
| 1747 | //step10:release ss51 & hold dsp |
| 1748 | GTP_DEBUG("[burn_fw_boot]step10:release ss51 & hold dsp"); |
| 1749 | ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08); |
| 1750 | if(ret <= 0) |
| 1751 | { |
| 1752 | GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail."); |
| 1753 | ret = FAIL; |
| 1754 | goto exit_burn_fw_boot; |
| 1755 | } |
| 1756 | |
| 1757 | ret = SUCCESS; |
| 1758 | |
| 1759 | exit_burn_fw_boot: |
| 1760 | kfree(fw_boot); |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
| 1764 | s32 gup_update_proc(void *dir) |
| 1765 | { |
| 1766 | s32 ret = 0; |
| 1767 | u8 retry = 0; |
| 1768 | st_fw_head fw_head; |
| 1769 | struct goodix_ts_data *ts = NULL; |
| 1770 | |
| 1771 | GTP_DEBUG("[update_proc]Begin update ......"); |
| 1772 | |
| 1773 | show_len = 1; |
| 1774 | total_len = 100; |
| 1775 | if(dir == NULL) |
| 1776 | { |
| 1777 | msleep(3000); //wait main thread to be completed |
| 1778 | } |
| 1779 | |
| 1780 | ts = i2c_get_clientdata(i2c_connect_client); |
| 1781 | |
| 1782 | if (searching_file) |
| 1783 | { |
| 1784 | searching_file = 0; // exit .bin update file searching |
| 1785 | GTP_INFO("Exiting searching .bin update file..."); |
| 1786 | while ((show_len != 200) && (show_len != 100)) // wait for auto update quitted completely |
| 1787 | { |
| 1788 | msleep(100); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | update_msg.file = NULL; |
| 1793 | ret = gup_check_update_file(i2c_connect_client, &fw_head, (u8*)dir); //20121211 |
| 1794 | if(FAIL == ret) |
| 1795 | { |
| 1796 | GTP_ERROR("[update_proc]check update file fail."); |
| 1797 | goto file_fail; |
| 1798 | } |
| 1799 | |
| 1800 | //gtp_reset_guitar(i2c_connect_client, 20); |
| 1801 | ret = gup_get_ic_fw_msg(i2c_connect_client); |
| 1802 | if(FAIL == ret) |
| 1803 | { |
| 1804 | GTP_ERROR("[update_proc]get ic message fail."); |
| 1805 | goto file_fail; |
| 1806 | } |
| 1807 | |
| 1808 | ret = gup_enter_update_judge(&fw_head); |
| 1809 | if(FAIL == ret) |
| 1810 | { |
| 1811 | GTP_ERROR("[update_proc]Check *.bin file fail."); |
| 1812 | goto file_fail; |
| 1813 | } |
| 1814 | |
| 1815 | ts->enter_update = 1; |
| 1816 | gtp_irq_disable(ts); |
| 1817 | #if GTP_ESD_PROTECT |
| 1818 | gtp_esd_switch(ts->client, SWITCH_OFF); |
| 1819 | #endif |
| 1820 | ret = gup_enter_update_mode(i2c_connect_client); |
| 1821 | if(FAIL == ret) |
| 1822 | { |
| 1823 | GTP_ERROR("[update_proc]enter update mode fail."); |
| 1824 | goto update_fail; |
| 1825 | } |
| 1826 | |
| 1827 | while(retry++ < 5) |
| 1828 | { |
| 1829 | show_len = 10; |
| 1830 | total_len = 100; |
| 1831 | ret = gup_burn_dsp_isp(i2c_connect_client); |
| 1832 | if(FAIL == ret) |
| 1833 | { |
| 1834 | GTP_ERROR("[update_proc]burn dsp isp fail."); |
| 1835 | continue; |
| 1836 | } |
| 1837 | |
| 1838 | show_len += 10; |
| 1839 | ret = gup_burn_fw_ss51(i2c_connect_client); |
| 1840 | if(FAIL == ret) |
| 1841 | { |
| 1842 | GTP_ERROR("[update_proc]burn ss51 firmware fail."); |
| 1843 | continue; |
| 1844 | } |
| 1845 | |
| 1846 | show_len += 40; |
| 1847 | ret = gup_burn_fw_dsp(i2c_connect_client); |
| 1848 | if(FAIL == ret) |
| 1849 | { |
| 1850 | GTP_ERROR("[update_proc]burn dsp firmware fail."); |
| 1851 | continue; |
| 1852 | } |
| 1853 | |
| 1854 | show_len += 20; |
| 1855 | ret = gup_burn_fw_boot(i2c_connect_client); |
| 1856 | if(FAIL == ret) |
| 1857 | { |
| 1858 | GTP_ERROR("[update_proc]burn bootloader firmware fail."); |
| 1859 | continue; |
| 1860 | } |
| 1861 | show_len += 10; |
| 1862 | GTP_INFO("[update_proc]UPDATE SUCCESS."); |
| 1863 | break; |
| 1864 | } |
| 1865 | if(retry >= 5) |
| 1866 | { |
| 1867 | GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL."); |
| 1868 | goto update_fail; |
| 1869 | } |
| 1870 | |
| 1871 | GTP_DEBUG("[update_proc]leave update mode."); |
| 1872 | gup_leave_update_mode(); |
| 1873 | |
| 1874 | msleep(100); |
| 1875 | // GTP_DEBUG("[update_proc]send config."); |
| 1876 | // ret = gtp_send_cfg(i2c_connect_client); |
| 1877 | // if(ret < 0) |
| 1878 | // { |
| 1879 | // GTP_ERROR("[update_proc]send config fail."); |
| 1880 | // } |
| 1881 | if (ts->fw_error) |
| 1882 | { |
| 1883 | GTP_INFO("firmware error auto update, resent config!"); |
| 1884 | gup_init_panel(ts); |
| 1885 | } |
| 1886 | show_len = 100; |
| 1887 | total_len = 100; |
| 1888 | ts->enter_update = 0; |
| 1889 | gtp_irq_enable(ts); |
| 1890 | |
| 1891 | #if GTP_ESD_PROTECT |
| 1892 | gtp_esd_switch(ts->client, SWITCH_ON); |
| 1893 | #endif |
| 1894 | filp_close(update_msg.file, NULL); |
| 1895 | return SUCCESS; |
| 1896 | |
| 1897 | update_fail: |
| 1898 | ts->enter_update = 0; |
| 1899 | gtp_irq_enable(ts); |
| 1900 | |
| 1901 | #if GTP_ESD_PROTECT |
| 1902 | gtp_esd_switch(ts->client, SWITCH_ON); |
| 1903 | #endif |
| 1904 | |
| 1905 | file_fail: |
| 1906 | if(update_msg.file && !IS_ERR(update_msg.file)) |
| 1907 | { |
| 1908 | filp_close(update_msg.file, NULL); |
| 1909 | } |
| 1910 | show_len = 200; |
| 1911 | total_len = 100; |
| 1912 | return FAIL; |
| 1913 | } |
| 1914 | |
| 1915 | #if GTP_AUTO_UPDATE |
| 1916 | u8 gup_init_update_proc(struct goodix_ts_data *ts) |
| 1917 | { |
| 1918 | struct task_struct *thread = NULL; |
| 1919 | |
| 1920 | GTP_INFO("Ready to run update thread."); |
| 1921 | thread = kthread_run(gup_update_proc, (void*)NULL, "guitar_update"); |
| 1922 | if (IS_ERR(thread)) |
| 1923 | { |
| 1924 | GTP_ERROR("Failed to create update thread.\n"); |
| 1925 | return -1; |
| 1926 | } |
| 1927 | |
| 1928 | return 0; |
| 1929 | } |
| 1930 | #endif |