1 /* drivers/input/touchscreen/gt9xx_update.c
3 * 2010 - 2012 Goodix Technology.
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.
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.
18 * V1.0: first release. by Andrew, 2012/08/27.
19 * V1.2: modify gt9110p pid map, by Andrew, 2012/10/15
21 * 1. modify gup_enter_update_mode,
22 * 2. rewrite i2c read/write func
23 * 3. check update file checksum
24 * by Andrew, 2012/12/12
26 * 1. delete GTP_FW_DOWNLOAD related things.
27 * 2. add GTP_HEADER_FW_UPDATE switch to update fw by gtp_default_fw in *.h directly
30 * 1. GT9XXF main clock calibration
31 * 2. header fw update no fs related
32 * 3. update file searching optimization
33 * 4. config update as module, switchable
37 #include <linux/interrupt.h>
38 #include <cust_eint.h>
39 #include <linux/i2c.h>
40 #include <linux/sched.h>
41 #include <linux/kthread.h>
42 #include <linux/rtpm_prio.h>
43 #include <linux/wait.h>
44 #include <linux/time.h>
45 #include <linux/delay.h>
46 #include <linux/namei.h>
47 #include <linux/mount.h>
48 #include "cust_gpio_usage.h"
49 #include <asm/uaccess.h>
51 #include "tpd_custom_gt9xx.h"
53 #if ( (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE) || GTP_COMPATIBLE_MODE )
54 #include "gt9xx_firmware.h"
58 #define GUP_REG_HW_INFO 0x4220
59 #define GUP_REG_FW_MSG 0x41E4
60 #define GUP_REG_PID_VID 0x8140
62 #define GUP_SEARCH_FILE_TIMES 50
63 #define UPDATE_FILE_PATH_1 "/data/_goodix_update_.bin"
64 #define UPDATE_FILE_PATH_2 "/sdcard/_goodix_update_.bin"
66 #define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg"
67 #define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg"
69 #define FW_HEAD_LENGTH 14
70 #define FW_DOWNLOAD_LENGTH 0x4000
71 #define FW_SECTION_LENGTH 0x2000
72 #define FW_DSP_ISP_LENGTH 0x1000
73 #define FW_DSP_LENGTH 0x1000
74 #define FW_BOOT_LENGTH 0x800
75 #define FW_SS51_LENGTH (4 * FW_SECTION_LENGTH)
76 #define FW_BOOT_ISP_LENGTH 0x800 // 2k
77 #define FW_LINK_LENGTH 0x3000 // 12k
78 #define FW_APP_CODE_LENGTH (4 * FW_SECTION_LENGTH) // 32k
80 #define FIRMWARE_LENGTH (FW_SS51_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH + FW_DSP_ISP_LENGTH + FW_BOOT_ISP_LENGTH + FW_APP_CODE_LENGTH)
82 #define FW_HOTKNOT_LENGTH 0x3000
84 #define MAX_FRAME_CHECK_TIME 5
87 #define _bRW_MISCTL__SRAM_BANK 0x4048
88 #define _bRW_MISCTL__MEM_CD_EN 0x4049
89 #define _bRW_MISCTL__CACHE_EN 0x404B
90 #define _bRW_MISCTL__TMR0_EN 0x40B0
91 #define _rRW_MISCTL__SWRST_B0_ 0x4180
92 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
93 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
94 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
95 #define _rRW_MISCTL__BOOT_CTL_ 0x5094
97 #define AUTO_SEARCH_BIN 0x01
98 #define AUTO_SEARCH_CFG 0x02
99 #define BIN_FILE_READY 0x80
100 #define CFG_FILE_READY 0x08
101 #define HEADER_FW_READY 0x01
106 #define MAIN_SYSTEM_PATH "/sdcard/goodix/_main_.bin"
107 #define HOTKNOT_SYSTEM_PATH "/sdcard/goodix/_hotknot_.bin"
108 #define FX_SYSTEM_PATH "/sdcard/goodix/_authorization_.bin"
110 #define GTP_FORCE_UPDATE_FW 0
111 #define GT917S_UPDATE_RULE 1
116 u8 hw_info
[4]; //hardware info//
117 u8 pid
[8]; //product id //
118 u16 vid
; //version id //
127 struct file
*cfg_file
;
128 st_fw_head ic_fw_msg
;
134 st_update_msg update_msg
;
135 extern struct i2c_client
*i2c_client_point
;
136 extern unsigned int touch_irq
;
139 extern u8 fw_updating
;
141 extern struct mutex i2c_access
;
142 u8 searching_file
= 0;
143 u8 got_file_flag
= 0;
144 u8 load_fw_process
= 0;
147 extern void gtp_esd_switch(struct i2c_client
*client
, s32 on
);
150 #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE)
151 extern u8 is_reseting
;
155 #if GTP_COMPATIBLE_MODE
156 extern CHIP_TYPE_T gtp_chip_type
;
157 extern u8 rqst_processing
;
158 extern u8
gtp_fw_startup(struct i2c_client
*client
);
159 static u8
gup_check_and_repair(struct i2c_client
*, s32
, u8
*, u32
);
160 s32
gup_recovery_main_system(void);
161 s32
gup_load_main_system(char *filepath
);
162 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
);
163 char * gup_load_fw_from_file(char *filepath
);
164 s32
gup_load_system(char *firmware
, s32 length
, u8 need_check
);
167 #define _CLOSE_FILE(p_file) if (p_file && !IS_ERR(p_file)) \
169 filp_close(p_file, NULL); \
173 static u8
gup_burn_fw_app_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
);
175 static s32
gup_i2c_read(struct i2c_client
*client
, u8
*buf
, s32 len
)
178 u16 addr
= (buf
[0] << 8) + buf
[1];
180 ret
= i2c_read_bytes(client
, addr
, &buf
[2], len
- 2);
192 static s32
gup_i2c_write(struct i2c_client
*client
, u8
*buf
, s32 len
)
195 u16 addr
= (buf
[0] << 8) + buf
[1];
197 ret
= i2c_write_bytes(client
, addr
, &buf
[2], len
- 2);
209 static u8
gup_get_ic_msg(struct i2c_client
*client
, u16 addr
, u8
*msg
, s32 len
)
213 msg
[0] = (addr
>> 8) & 0xff;
214 msg
[1] = addr
& 0xff;
216 for (i
= 0; i
< 5; i
++)
218 if (gup_i2c_read(client
, msg
, GTP_ADDR_LENGTH
+ len
) > 0)
226 GTP_ERROR("Read data from 0x%02x%02x failed!", msg
[0], msg
[1]);
233 static u8
gup_set_ic_msg(struct i2c_client
*client
, u16 addr
, u8 val
)
238 msg
[0] = (addr
>> 8) & 0xff;
239 msg
[1] = addr
& 0xff;
242 for (i
= 0; i
< 5; i
++)
244 if (gup_i2c_write(client
, msg
, GTP_ADDR_LENGTH
+ 1) > 0)
252 GTP_ERROR("Set data to 0x%02x%02x failed!", msg
[0], msg
[1]);
259 static u8
gup_get_ic_fw_msg(struct i2c_client
*client
)
266 //step1:get hardware info
267 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_HW_INFO
, &buf
[GTP_ADDR_LENGTH
], 4);
270 GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit");
274 // buf[2~5]: 00 06 90 00
275 // hw_info: 00 90 06 00
276 for (i
= 0; i
< 4; i
++)
278 update_msg
.ic_fw_msg
.hw_info
[i
] = buf
[GTP_ADDR_LENGTH
+ 3 - i
];
281 GTP_INFO("IC Hardware info:%02x%02x%02x%02x", update_msg
.ic_fw_msg
.hw_info
[0], update_msg
.ic_fw_msg
.hw_info
[1],
282 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
284 //step2:get firmware message
285 for (retry
= 0; retry
< 2; retry
++)
287 ret
= gup_get_ic_msg(client
, GUP_REG_FW_MSG
, buf
, 1);
291 GTP_ERROR("Read firmware message fail.");
295 update_msg
.force_update
= buf
[GTP_ADDR_LENGTH
];
297 if ((0xBE != update_msg
.force_update
) && (!retry
))
299 GTP_INFO("The check sum in ic is error.");
300 GTP_INFO("The IC will be updated by force.");
306 GTP_INFO("IC force update flag:0x%x", update_msg
.force_update
);
308 //step3:get pid & vid
309 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_PID_VID
, &buf
[GTP_ADDR_LENGTH
], 6);
312 GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit");
316 memset(update_msg
.ic_fw_msg
.pid
, 0, sizeof(update_msg
.ic_fw_msg
.pid
));
317 memcpy(update_msg
.ic_fw_msg
.pid
, &buf
[GTP_ADDR_LENGTH
], 4);
321 /*|-----FLASH-----RAM-----|
322 |------918------918-----|
323 |------968------968-----|
324 |------913------913-----|
325 |------913P-----913P----|
326 |------927------927-----|
327 |------927P-----927P----|
328 |------9110-----9110----|
329 |------9110P----9111----|*/
330 if(update_msg
.ic_fw_msg
.pid
[0] != 0)
332 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "9111", 4))
334 GTP_INFO("IC Mapping Product id:%s", update_msg
.ic_fw_msg
.pid
);
335 memcpy(update_msg
.ic_fw_msg
.pid
, "9110P", 5);
339 update_msg
.ic_fw_msg
.vid
= buf
[GTP_ADDR_LENGTH
+ 4] + (buf
[GTP_ADDR_LENGTH
+ 5] << 8);
343 s32
gup_enter_update_mode(struct i2c_client
*client
)
349 //step1:RST output low last at least 2ms
350 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
353 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
354 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
357 //step3:RST output high reset guitar
358 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
360 //20121211 modify start
364 //step4:Hold ss51 & dsp
365 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
368 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
373 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
376 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
379 if(0x0C == rd_buf
[GTP_ADDR_LENGTH
])
381 GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
384 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
388 GTP_ERROR("Enter update Hold ss51 failed.");
392 //step6:DSP_CK and DSP_ALU_CK PowerOn
393 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
395 //20121211 modify end
399 void gup_leave_update_mode(void)
401 GTP_GPIO_AS_INT(GTP_INT_PORT
);
403 GTP_DEBUG("[leave_update_mode]reset chip.");
404 #if GTP_COMPATIBLE_MODE
405 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
407 force_reset_guitar();
408 GTP_INFO("User layer reset GT9XXF.");
412 gtp_reset_guitar(i2c_client_point
, 20);
415 static u8
gup_enter_update_judge(st_fw_head
*fw_head
)
422 //Get the correct nvram data
423 //The correct conditions:
424 //1. the hardware info is the same
425 //2. the product id is the same
426 //3. the firmware version in update file is greater than the firmware version in ic
427 //or the check sum in ic is wrong
429 u16_tmp
= fw_head
->vid
;
430 fw_head
->vid
= (u16
)(u16_tmp
>> 8) + (u16
)(u16_tmp
<< 8);
432 GTP_INFO("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]);
433 GTP_INFO("FILE PID:%s", fw_head
->pid
);
434 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
435 GTP_INFO("IC HARDWARE INFO:%02x%02x%02x%02x", update_msg
.ic_fw_msg
.hw_info
[0], update_msg
.ic_fw_msg
.hw_info
[1],
436 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
437 GTP_INFO("IC PID:%s", update_msg
.ic_fw_msg
.pid
);
438 GTP_INFO("IC VID:%04x", update_msg
.ic_fw_msg
.vid
);
440 if (!memcmp(fw_head
->hw_info
, update_msg
.ic_fw_msg
.hw_info
, sizeof(update_msg
.ic_fw_msg
.hw_info
)))
446 fw_len
= fw_head
->hw_info
[3];
447 fw_len
+= (((u32
)fw_head
->hw_info
[2]) << 8);
448 fw_len
+= (((u32
)fw_head
->hw_info
[1]) << 16);
449 fw_len
+= (((u32
)fw_head
->hw_info
[0]) << 24);
451 if (update_msg
.fw_total_len
!= fw_len
)
453 //GTP_ERROR("Inconsistent firmware size, Update aborted! Default size: %d(%dK), actual size: %d(%dK)", fw_len, fw_len/1024, update_msg.fw_total_len, update_msg.fw_total_len/1024);
456 if ((update_msg
.fw_total_len
< 36*1024) || (update_msg
.fw_total_len
> 128*1024))
458 GTP_ERROR("Invalid firmware length(%d), update aborted!", update_msg
.fw_total_len
);
461 GTP_INFO("Firmware length:%d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
463 if (update_msg
.force_update
!= 0xBE)
465 GTP_INFO("FW chksum error,need enter update.");
470 if (strlen(update_msg
.ic_fw_msg
.pid
) < 3)
472 GTP_INFO("Illegal IC pid, need enter update");
477 for (i
= 0; i
< 3; i
++)
479 if ((update_msg
.ic_fw_msg
.pid
[i
] < 0x30) || (update_msg
.ic_fw_msg
.pid
[i
] > 0x39))
481 GTP_INFO("Illegal IC pid, out of bound, need enter update");
488 pid_cmp_len
= strlen(fw_head
->pid
);
489 if (pid_cmp_len
< strlen(update_msg
.ic_fw_msg
.pid
))
491 pid_cmp_len
= strlen(update_msg
.ic_fw_msg
.pid
);
494 if ((!memcmp(fw_head
->pid
, update_msg
.ic_fw_msg
.pid
, pid_cmp_len
)) ||
495 (!memcmp(update_msg
.ic_fw_msg
.pid
, "91XX", 4))||
496 (!memcmp(fw_head
->pid
, "91XX", 4)))
498 if(!memcmp(fw_head
->pid
, "91XX", 4))
500 GTP_DEBUG("Force none same pid update mode.");
504 GTP_DEBUG("Get the same pid.");
507 //The third condition
508 if (fw_head
->vid
> update_msg
.ic_fw_msg
.vid
)
511 GTP_INFO("Need enter update.");
515 GTP_INFO("Don't meet the third condition.");
516 GTP_ERROR("File VID <= IC VID, update aborted!");
520 GTP_ERROR("File PID != IC PID, update aborted!");
526 #if GTP_AUTO_UPDATE_CFG
527 static u8
ascii2hex(u8 a
)
531 if(a
>= '0' && a
<= '9')
535 else if(a
>= 'A' && a
<= 'F')
537 value
= a
- 'A' + 0x0A;
539 else if(a
>= 'a' && a
<= 'f')
541 value
= a
- 'a' + 0x0A;
550 static s8
gup_update_config(struct i2c_client
*client
)
555 s32 file_cfg_len
= 0;
556 s32 chip_cfg_len
= 0;
563 if(NULL
== update_msg
.cfg_file
)
565 GTP_ERROR("[update_cfg]No need to upgrade config!");
568 file_len
= update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_END
);
570 chip_cfg_len
= cfg_len
;
572 GTP_DEBUG("[update_cfg]config file len:%d", file_len
);
573 GTP_DEBUG("[update_cfg]need config len:%d",chip_cfg_len
);
574 if((file_len
+5) < chip_cfg_len
*5)
576 GTP_ERROR("Config length error");
580 buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
581 pre_buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
582 file_config
= (u8
*)kzalloc(chip_cfg_len
+ GTP_ADDR_LENGTH
, GFP_KERNEL
);
583 update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_SET
);
585 GTP_DEBUG("[update_cfg]Read config from file.");
586 ret
= update_msg
.cfg_file
->f_op
->read(update_msg
.cfg_file
, (char*)pre_buf
, file_len
, &update_msg
.cfg_file
->f_pos
);
589 GTP_ERROR("[update_cfg]Read config file failed.");
590 goto update_cfg_file_failed
;
593 GTP_DEBUG("[update_cfg]Delete illgal charactor.");
594 for(i
=0,count
=0; i
<file_len
; i
++)
596 if (pre_buf
[i
] == ' ' || pre_buf
[i
] == '\r' || pre_buf
[i
] == '\n')
600 buf
[count
++] = pre_buf
[i
];
603 GTP_DEBUG("[update_cfg]Ascii to hex.");
604 file_config
[0] = GTP_REG_CONFIG_DATA
>> 8;
605 file_config
[1] = GTP_REG_CONFIG_DATA
& 0xff;
606 for(i
=0,file_cfg_len
=GTP_ADDR_LENGTH
; i
<count
; i
+=5)
608 if((buf
[i
]=='0') && ((buf
[i
+1]=='x') || (buf
[i
+1]=='X')))
611 high
= ascii2hex(buf
[i
+2]);
612 low
= ascii2hex(buf
[i
+3]);
614 if((high
== 0xFF) || (low
== 0xFF))
617 GTP_ERROR("[update_cfg]Illegal config file.");
618 goto update_cfg_file_failed
;
620 file_config
[file_cfg_len
++] = (high
<<4) + low
;
625 GTP_ERROR("[update_cfg]Illegal config file.");
626 goto update_cfg_file_failed
;
631 GTP_DEBUG("config:");
632 GTP_DEBUG_ARRAY(file_config
+2, file_cfg_len
);
637 ret
= gup_i2c_write(client
, file_config
, file_cfg_len
);
640 GTP_INFO("[update_cfg]Send config SUCCESS.");
643 GTP_ERROR("[update_cfg]Send config i2c error.");
646 update_cfg_file_failed
:
654 #if (GTP_AUTO_UPDATE && (!GTP_HEADER_FW_UPDATE || GTP_AUTO_UPDATE_CFG))
655 static void gup_search_file(s32 search_type
)
658 struct file
*pfile
= NULL
;
660 got_file_flag
= 0x00;
663 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
665 if (0 == searching_file
)
667 GTP_INFO("Force exiting file searching");
668 got_file_flag
= 0x00;
672 if (search_type
& AUTO_SEARCH_BIN
)
674 GTP_DEBUG("Search for %s, %s for fw update.(%d/%d)", UPDATE_FILE_PATH_1
, UPDATE_FILE_PATH_2
, i
+1, GUP_SEARCH_FILE_TIMES
);
675 pfile
= filp_open(UPDATE_FILE_PATH_1
, O_RDONLY
, 0);
678 pfile
= filp_open(UPDATE_FILE_PATH_2
, O_RDONLY
, 0);
681 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_2
);
682 got_file_flag
|= BIN_FILE_READY
;
683 update_msg
.file
= pfile
;
688 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_1
);
689 got_file_flag
|= BIN_FILE_READY
;
690 update_msg
.file
= pfile
;
692 if (got_file_flag
& BIN_FILE_READY
)
694 #if GTP_AUTO_UPDATE_CFG
695 if (search_type
& AUTO_SEARCH_CFG
)
697 i
= GUP_SEARCH_FILE_TIMES
; // Bin & Cfg File required to be in the same directory
708 #if GTP_AUTO_UPDATE_CFG
709 if ( (search_type
& AUTO_SEARCH_CFG
) && !(got_file_flag
& CFG_FILE_READY
) )
711 GTP_DEBUG("Search for %s, %s for config update.(%d/%d)", CONFIG_FILE_PATH_1
, CONFIG_FILE_PATH_2
, i
+1, GUP_SEARCH_FILE_TIMES
);
712 pfile
= filp_open(CONFIG_FILE_PATH_1
, O_RDONLY
, 0);
715 pfile
= filp_open(CONFIG_FILE_PATH_2
, O_RDONLY
, 0);
718 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_2
);
719 got_file_flag
|= CFG_FILE_READY
;
720 update_msg
.cfg_file
= pfile
;
725 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_1
);
726 got_file_flag
|= CFG_FILE_READY
;
727 update_msg
.cfg_file
= pfile
;
729 if (got_file_flag
& CFG_FILE_READY
)
742 static u8
gup_check_update_file(struct i2c_client
*client
, st_fw_head
*fw_head
, u8
*path
)
747 u8 buf
[FW_HEAD_LENGTH
];
749 got_file_flag
= 0x00;
752 GTP_DEBUG("Update File path:%s, %zu", path
, strlen(path
));
753 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
755 if (IS_ERR(update_msg
.file
))
757 GTP_ERROR("Open update file(%s) error!", path
);
760 got_file_flag
= BIN_FILE_READY
;
765 #if GTP_HEADER_FW_UPDATE
766 GTP_INFO("Update by default firmware array");
767 update_msg
.fw_total_len
= sizeof(gtp_default_FW
) - FW_HEAD_LENGTH
;
768 if (sizeof(gtp_default_FW
) < (FW_HEAD_LENGTH
+ FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
))
770 GTP_INFO("[check_update_file]default firmware array is INVALID!");
773 GTP_DEBUG("Firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
774 memcpy(fw_head
, >p_default_FW
[0], FW_HEAD_LENGTH
);
776 //check firmware legality
778 for (i
= 0; i
< update_msg
.fw_total_len
; i
+= 2)
780 fw_checksum
+= (gtp_default_FW
[FW_HEAD_LENGTH
+ i
] << 8) + gtp_default_FW
[FW_HEAD_LENGTH
+ i
+ 1];
782 if(fw_checksum
&0xFFFF)
784 GTP_ERROR("Illegal firmware with checksum(0x%04X)", fw_checksum
& 0xFFFF);
787 got_file_flag
= HEADER_FW_READY
;
791 #if GTP_AUTO_UPDATE_CFG
792 gup_search_file(AUTO_SEARCH_BIN
| AUTO_SEARCH_CFG
);
793 if (got_file_flag
& CFG_FILE_READY
)
795 ret
= gup_update_config(client
);
798 GTP_ERROR("Update config failed!");
800 _CLOSE_FILE(update_msg
.cfg_file
);
801 msleep(500); //waiting config to be stored in FLASH.
804 gup_search_file(AUTO_SEARCH_BIN
);
807 if (!(got_file_flag
& BIN_FILE_READY
))
809 GTP_ERROR("No bin file for fw Update");
815 GTP_ERROR("NULL file for fw update!");
821 update_msg
.old_fs
= get_fs();
824 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
825 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
827 update_msg
.fw_total_len
-= FW_HEAD_LENGTH
;
829 GTP_DEBUG("Bin firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
831 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
832 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
836 GTP_ERROR("Read firmware head in update file error.");
840 memcpy(fw_head
, buf
, FW_HEAD_LENGTH
);
842 //check firmware legality
844 for(i
=0; i
< update_msg
.fw_total_len
; i
+=2)
847 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char*)buf
, 2, &update_msg
.file
->f_pos
);
850 GTP_ERROR("Read firmware file error.");
853 //GTP_DEBUG("BUF[0]:%x", buf[0]);
854 temp
= (buf
[0]<<8) + buf
[1];
858 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
859 if(fw_checksum
&0xFFFF)
861 GTP_ERROR("Illegal firmware file.");
868 set_fs(update_msg
.old_fs
);
869 _CLOSE_FILE(update_msg
.file
);
873 static u8
gup_burn_proc(struct i2c_client
*client
, u8
*burn_buf
, u16 start_addr
, u16 total_length
)
876 u16 burn_addr
= start_addr
;
877 u16 frame_length
= 0;
879 u8 wr_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
880 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
883 GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length
/ 1024), start_addr
);
885 while (burn_length
< total_length
)
887 GTP_DEBUG("B/T:%04d/%04d", burn_length
, total_length
);
888 frame_length
= ((total_length
- burn_length
) > PACK_SIZE
) ? PACK_SIZE
: (total_length
- burn_length
);
889 wr_buf
[0] = (u8
)(burn_addr
>> 8);
890 rd_buf
[0] = wr_buf
[0];
891 wr_buf
[1] = (u8
)burn_addr
;
892 rd_buf
[1] = wr_buf
[1];
893 memcpy(&wr_buf
[GTP_ADDR_LENGTH
], &burn_buf
[burn_length
], frame_length
);
895 for (retry
= 0; retry
< MAX_FRAME_CHECK_TIME
; retry
++)
897 ret
= gup_i2c_write(client
, wr_buf
, GTP_ADDR_LENGTH
+ frame_length
);
901 GTP_ERROR("Write frame data i2c error.");
905 ret
= gup_i2c_read(client
, rd_buf
, GTP_ADDR_LENGTH
+ frame_length
);
909 GTP_ERROR("Read back frame data i2c error.");
913 if (memcmp(&wr_buf
[GTP_ADDR_LENGTH
], &rd_buf
[GTP_ADDR_LENGTH
], frame_length
))
915 GTP_ERROR("Check frame data fail,not equal.");
916 GTP_DEBUG("write array:");
917 GTP_DEBUG_ARRAY(&wr_buf
[GTP_ADDR_LENGTH
], frame_length
);
918 GTP_DEBUG("read array:");
919 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
924 //GTP_DEBUG("Check frame data success.");
929 if (retry
> MAX_FRAME_CHECK_TIME
)
931 GTP_ERROR("Burn frame data time out,exit.");
935 burn_length
+= frame_length
;
936 burn_addr
+= frame_length
;
942 static u8
gup_load_section_file(u8
*buf
, u32 offset
, u16 length
, u8 set_or_end
)
944 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE)
945 if (HEADER_FW_READY
== got_file_flag
)
947 if(SEEK_SET
== set_or_end
)
949 memcpy(buf
, >p_default_FW
[FW_HEAD_LENGTH
+ offset
], length
);
953 memcpy(buf
, >p_default_FW
[update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
], length
);
961 if ( (update_msg
.file
== NULL
) || IS_ERR(update_msg
.file
))
963 GTP_ERROR("cannot find update file,load section file fail.");
967 if(SEEK_SET
== set_or_end
)
969 update_msg
.file
->f_pos
= FW_HEAD_LENGTH
+ offset
;
973 update_msg
.file
->f_pos
= update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
;
976 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, length
, &update_msg
.file
->f_pos
);
980 GTP_ERROR("Read update file fail.");
988 static u8
gup_recall_check(struct i2c_client
*client
, u8
*chk_src
, u16 start_rd_addr
, u16 chk_length
)
990 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
992 u16 recall_addr
= start_rd_addr
;
993 u16 recall_length
= 0;
994 u16 frame_length
= 0;
996 while (recall_length
< chk_length
)
998 frame_length
= ((chk_length
- recall_length
) > PACK_SIZE
) ? PACK_SIZE
: (chk_length
- recall_length
);
999 ret
= gup_get_ic_msg(client
, recall_addr
, rd_buf
, frame_length
);
1003 GTP_ERROR("recall i2c error,exit");
1007 if (memcmp(&rd_buf
[GTP_ADDR_LENGTH
], &chk_src
[recall_length
], frame_length
))
1009 GTP_ERROR("Recall frame data fail,not equal.");
1010 GTP_DEBUG("chk_src array:");
1011 GTP_DEBUG_ARRAY(&chk_src
[recall_length
], frame_length
);
1012 GTP_DEBUG("recall array:");
1013 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
1017 recall_length
+= frame_length
;
1018 recall_addr
+= frame_length
;
1021 GTP_DEBUG("Recall check %dk firmware success.", (chk_length
/ 1024));
1026 static u8
gup_burn_fw_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u8 bank_cmd
)
1031 //step1:hold ss51 & dsp
1032 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1036 GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
1040 //step2:set scramble
1041 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1045 GTP_ERROR("[burn_fw_section]set scramble fail.");
1050 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1054 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1058 //step4:enable accessing code
1059 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1063 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1067 //step5:burn 8k fw section
1068 ret
= gup_burn_proc(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1072 GTP_ERROR("[burn_fw_section]burn fw_section fail.");
1076 //step6:hold ss51 & release dsp
1077 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1081 GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
1088 //step7:send burn cmd to move data to flash from sram
1089 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
& 0x0f);
1093 GTP_ERROR("[burn_fw_section]send burn cmd fail.");
1097 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1101 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1105 GTP_ERROR("[burn_fw_section]Get burn state fail");
1110 //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1112 while (rd_buf
[GTP_ADDR_LENGTH
]);
1115 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1119 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1123 //step9:enable accessing code
1124 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1128 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1132 //step10:recall 8k fw section
1133 ret
= gup_recall_check(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1137 GTP_ERROR("[burn_fw_section]recall check %dk firmware fail.", FW_SECTION_LENGTH
/1024);
1141 //step11:disable accessing code
1142 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x00);
1146 GTP_ERROR("[burn_fw_section]disable accessing code fail.");
1153 static u8
gup_burn_dsp_isp(struct i2c_client
*client
)
1156 u8
*fw_dsp_isp
= NULL
;
1160 GTP_INFO("[burn_dsp_isp]Begin burn dsp isp---->>");
1162 //step1:alloc memory
1163 GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
1167 fw_dsp_isp
= (u8
*)kzalloc(FW_DSP_ISP_LENGTH
, GFP_KERNEL
);
1169 if (fw_dsp_isp
== NULL
)
1175 GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH
/ 1024));
1182 GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
1186 //step2:load dsp isp file data
1187 GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
1188 ret
= gup_load_section_file(fw_dsp_isp
, FW_DSP_ISP_LENGTH
, FW_DSP_ISP_LENGTH
, SEEK_END
);
1192 GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
1193 goto exit_burn_dsp_isp
;
1196 //step3:disable wdt,clear cache enable
1197 GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
1198 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1202 GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
1204 goto exit_burn_dsp_isp
;
1207 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1211 GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
1213 goto exit_burn_dsp_isp
;
1216 //step4:hold ss51 & dsp
1217 GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
1218 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1222 GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
1224 goto exit_burn_dsp_isp
;
1227 //step5:set boot from sram
1228 GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
1229 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1233 GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
1235 goto exit_burn_dsp_isp
;
1238 //step6:software reboot
1239 GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
1240 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1244 GTP_ERROR("[burn_dsp_isp]software reboot fail.");
1246 goto exit_burn_dsp_isp
;
1249 //step7:select bank2
1250 GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
1251 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1255 GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
1257 goto exit_burn_dsp_isp
;
1260 //step8:enable accessing code
1261 GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
1262 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1266 GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
1268 goto exit_burn_dsp_isp
;
1271 //step9:burn 4k dsp_isp
1272 GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
1273 ret
= gup_burn_proc(client
, fw_dsp_isp
, 0xC000, FW_DSP_ISP_LENGTH
);
1277 GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
1278 goto exit_burn_dsp_isp
;
1281 //step10:set scramble
1282 GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
1283 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1287 GTP_ERROR("[burn_dsp_isp]set scramble fail.");
1289 goto exit_burn_dsp_isp
;
1292 update_msg
.fw_burned_len
+= FW_DSP_ISP_LENGTH
;
1293 GTP_DEBUG("[burn_dsp_isp]Burned length:%d", update_msg
.fw_burned_len
);
1301 static u8
gup_burn_fw_ss51(struct i2c_client
*client
)
1307 GTP_INFO("[burn_fw_ss51]Begin burn ss51 firmware---->>");
1309 //step1:alloc memory
1310 GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
1314 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1316 if (fw_ss51
== NULL
)
1322 GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1329 GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
1333 //step2:load ss51 firmware section 1 file data
1334 //GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
1335 //ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH, SEEK_SET);
1339 // GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
1340 // goto exit_burn_fw_ss51;
1342 GTP_INFO("[burn_fw_ss51]Reset first 8K of ss51 to 0xFF.");
1343 GTP_DEBUG("[burn_fw_ss51]step2: reset bank0 0xC000~0xD000");
1344 memset(fw_ss51
, 0xFF, FW_SECTION_LENGTH
);
1346 //step3:clear control flag
1347 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
1348 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1352 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
1354 goto exit_burn_fw_ss51
;
1357 //step4:burn ss51 firmware section 1
1358 GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
1359 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
1363 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
1364 goto exit_burn_fw_ss51
;
1367 //step5:load ss51 firmware section 2 file data
1368 GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
1369 ret
= gup_load_section_file(fw_ss51
, FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1373 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
1374 goto exit_burn_fw_ss51
;
1377 //step6:burn ss51 firmware section 2
1378 GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
1379 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x02);
1383 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
1384 goto exit_burn_fw_ss51
;
1387 //step7:load ss51 firmware section 3 file data
1388 GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
1389 ret
= gup_load_section_file(fw_ss51
, 2 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1393 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
1394 goto exit_burn_fw_ss51
;
1397 //step8:burn ss51 firmware section 3
1398 GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
1399 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x13);
1403 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
1404 goto exit_burn_fw_ss51
;
1407 //step9:load ss51 firmware section 4 file data
1408 GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
1409 ret
= gup_load_section_file(fw_ss51
, 3 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1413 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
1414 goto exit_burn_fw_ss51
;
1417 //step10:burn ss51 firmware section 4
1418 GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
1419 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x14);
1423 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
1424 goto exit_burn_fw_ss51
;
1427 update_msg
.fw_burned_len
+= (FW_SECTION_LENGTH
*4);
1428 GTP_DEBUG("[burn_fw_ss51]Burned length:%d", update_msg
.fw_burned_len
);
1436 static u8
gup_burn_fw_dsp(struct i2c_client
*client
)
1443 GTP_INFO("[burn_fw_dsp]Begin burn dsp firmware---->>");
1444 //step1:alloc memory
1445 GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
1449 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1457 GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1464 GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
1468 //step2:load firmware dsp
1469 GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
1470 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
, SEEK_SET
);
1474 GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
1475 goto exit_burn_fw_dsp
;
1478 //step3:select bank3
1479 GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
1480 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1484 GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
1486 goto exit_burn_fw_dsp
;
1489 //step4:hold ss51 & dsp
1490 GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
1491 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1495 GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
1497 goto exit_burn_fw_dsp
;
1500 //step5:set scramble
1501 GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
1502 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1506 GTP_ERROR("[burn_fw_dsp]set scramble fail.");
1508 goto exit_burn_fw_dsp
;
1511 //step6:release ss51 & dsp
1512 GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
1513 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121212
1517 GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
1519 goto exit_burn_fw_dsp
;
1525 //step7:burn 4k dsp firmware
1526 GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
1527 ret
= gup_burn_proc(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1531 GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
1532 goto exit_burn_fw_dsp
;
1535 //step8:send burn cmd to move data to flash from sram
1536 GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
1537 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x05);
1541 GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
1542 goto exit_burn_fw_dsp
;
1545 GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
1549 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1553 GTP_ERROR("[burn_fw_dsp]Get burn state fail");
1554 goto exit_burn_fw_dsp
;
1558 //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1560 while (rd_buf
[GTP_ADDR_LENGTH
]);
1562 //step9:recall check 4k dsp firmware
1563 GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
1564 ret
= gup_recall_check(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1568 GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
1569 goto exit_burn_fw_dsp
;
1572 update_msg
.fw_burned_len
+= FW_DSP_LENGTH
;
1573 GTP_DEBUG("[burn_fw_dsp]Burned length:%d", update_msg
.fw_burned_len
);
1581 static u8
gup_burn_fw_boot(struct i2c_client
*client
)
1588 GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>");
1590 //step1:Alloc memory
1591 GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
1595 fw_boot
= (u8
*)kzalloc(FW_BOOT_LENGTH
, GFP_KERNEL
);
1603 GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH
/1024));
1610 GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
1614 //step2:load firmware bootloader
1615 GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
1616 ret
= gup_load_section_file(fw_boot
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
), FW_BOOT_LENGTH
, SEEK_SET
);
1620 GTP_ERROR("[burn_fw_boot]load firmware bootcode fail.");
1621 goto exit_burn_fw_boot
;
1624 //step3:hold ss51 & dsp
1625 GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
1626 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1629 GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
1631 goto exit_burn_fw_boot
;
1634 //step4:set scramble
1635 GTP_DEBUG("[burn_fw_boot]step4:set scramble");
1636 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1639 GTP_ERROR("[burn_fw_boot]set scramble fail.");
1641 goto exit_burn_fw_boot
;
1644 //step5:hold ss51 & release dsp
1645 GTP_DEBUG("[burn_fw_boot]step5:hold ss51 & release dsp");
1646 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1649 GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
1651 goto exit_burn_fw_boot
;
1656 //step6:select bank3
1657 GTP_DEBUG("[burn_fw_boot]step6:select bank3");
1658 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1661 GTP_ERROR("[burn_fw_boot]select bank3 fail.");
1663 goto exit_burn_fw_boot
;
1666 //step7:burn 2k bootloader firmware
1667 GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware");
1668 ret
= gup_burn_proc(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1671 GTP_ERROR("[burn_fw_boot]burn fw_boot fail.");
1672 goto exit_burn_fw_boot
;
1675 //step7:send burn cmd to move data to flash from sram
1676 GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
1677 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x06);
1680 GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
1681 goto exit_burn_fw_boot
;
1683 GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
1685 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1688 GTP_ERROR("[burn_fw_boot]Get burn state fail");
1689 goto exit_burn_fw_boot
;
1692 //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1693 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1695 //step8:recall check 2k bootloader firmware
1696 GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
1697 ret
= gup_recall_check(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1700 GTP_ERROR("[burn_fw_boot]recall check 2k bootcode firmware fail.");
1701 goto exit_burn_fw_boot
;
1704 update_msg
.fw_burned_len
+= FW_BOOT_LENGTH
;
1705 GTP_DEBUG("[burn_fw_boot]Burned length:%d", update_msg
.fw_burned_len
);
1713 static u8
gup_burn_fw_boot_isp(struct i2c_client
*client
)
1716 u8
* fw_boot_isp
= NULL
;
1720 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1722 GTP_INFO("No need to upgrade the boot_isp code!");
1725 GTP_DEBUG("[burn_fw_boot_isp]Begin burn bootloader firmware---->>");
1727 //step1:Alloc memory
1728 GTP_DEBUG("[burn_fw_boot_isp]step1:Alloc memory");
1731 fw_boot_isp
= (u8
*)kzalloc(FW_BOOT_ISP_LENGTH
, GFP_KERNEL
);
1732 if(fw_boot_isp
== NULL
)
1738 GTP_INFO("[burn_fw_boot_isp]Alloc %dk byte memory success.", (FW_BOOT_ISP_LENGTH
/1024));
1744 GTP_ERROR("[burn_fw_boot_isp]Alloc memory fail,exit.");
1748 //step2:load firmware bootloader
1749 GTP_DEBUG("[burn_fw_boot_isp]step2:load firmware bootloader isp");
1750 //ret = gup_load_section_file(fw_boot_isp, (4*FW_SECTION_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH+FW_DSP_ISP_LENGTH), FW_BOOT_ISP_LENGTH, SEEK_SET);
1751 ret
= gup_load_section_file(fw_boot_isp
, (update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
), FW_BOOT_ISP_LENGTH
, SEEK_SET
);
1754 GTP_ERROR("[burn_fw_boot_isp]load firmware boot_isp fail.");
1755 goto exit_burn_fw_boot_isp
;
1758 //step3:hold ss51 & dsp
1759 GTP_DEBUG("[burn_fw_boot_isp]step3:hold ss51 & dsp");
1760 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1763 GTP_ERROR("[burn_fw_boot_isp]hold ss51 & dsp fail.");
1765 goto exit_burn_fw_boot_isp
;
1768 //step4:set scramble
1769 GTP_DEBUG("[burn_fw_boot_isp]step4:set scramble");
1770 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1773 GTP_ERROR("[burn_fw_boot_isp]set scramble fail.");
1775 goto exit_burn_fw_boot_isp
;
1779 //step5:hold ss51 & release dsp
1780 GTP_DEBUG("[burn_fw_boot_isp]step5:hold ss51 & release dsp");
1781 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1784 GTP_ERROR("[burn_fw_boot_isp]release ss51 & dsp fail.");
1786 goto exit_burn_fw_boot_isp
;
1791 //step6:select bank3
1792 GTP_DEBUG("[burn_fw_boot_isp]step6:select bank3");
1793 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1796 GTP_ERROR("[burn_fw_boot_isp]select bank3 fail.");
1798 goto exit_burn_fw_boot_isp
;
1801 //step7:burn 2k bootload_isp firmware
1802 GTP_DEBUG("[burn_fw_boot_isp]step7:burn 2k bootloader firmware");
1803 ret
= gup_burn_proc(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1806 GTP_ERROR("[burn_fw_boot_isp]burn fw_section fail.");
1807 goto exit_burn_fw_boot_isp
;
1810 //step7:send burn cmd to move data to flash from sram
1811 GTP_DEBUG("[burn_fw_boot_isp]step7:send burn cmd to move data to flash from sram");
1812 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x07);
1815 GTP_ERROR("[burn_fw_boot_isp]send burn cmd fail.");
1816 goto exit_burn_fw_boot_isp
;
1818 GTP_DEBUG("[burn_fw_boot_isp]Wait for the burn is complete......");
1820 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1823 GTP_ERROR("[burn_fw_boot_isp]Get burn state fail");
1824 goto exit_burn_fw_boot_isp
;
1827 //GTP_DEBUG("[burn_fw_boot_isp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1828 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1830 //step8:recall check 2k bootload_isp firmware
1831 GTP_DEBUG("[burn_fw_boot_isp]step8:recall check 2k bootloader firmware");
1832 ret
= gup_recall_check(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1835 GTP_ERROR("[burn_fw_boot_isp]recall check 2k bootcode_isp firmware fail.");
1836 goto exit_burn_fw_boot_isp
;
1839 update_msg
.fw_burned_len
+= FW_BOOT_ISP_LENGTH
;
1840 GTP_DEBUG("[burn_fw_boot_isp]Burned length:%d", update_msg
.fw_burned_len
);
1843 exit_burn_fw_boot_isp
:
1848 static u8
gup_burn_fw_link(struct i2c_client
*client
)
1855 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1857 GTP_INFO("No need to upgrade the link code!");
1860 GTP_DEBUG("[burn_fw_link]Begin burn link firmware---->>");
1862 //step1:Alloc memory
1863 GTP_DEBUG("[burn_fw_link]step1:Alloc memory");
1866 fw_link
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1873 GTP_INFO("[burn_fw_link]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
1879 GTP_ERROR("[burn_fw_link]Alloc memory fail,exit.");
1883 //step2:load firmware link section 1
1884 GTP_DEBUG("[burn_fw_link]step2:load firmware link section 1");
1885 offset
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
1886 ret
= gup_load_section_file(fw_link
, offset
, FW_SECTION_LENGTH
, SEEK_SET
);
1889 GTP_ERROR("[burn_fw_link]load firmware link section 1 fail.");
1890 goto exit_burn_fw_link
;
1894 //step3:burn link firmware section 1
1895 GTP_DEBUG("[burn_fw_link]step3:burn link firmware section 1");
1896 ret
= gup_burn_fw_app_section(client
, fw_link
, 0x9000, FW_SECTION_LENGTH
, 0x38);
1900 GTP_ERROR("[burn_fw_link]burn link firmware section 1 fail.");
1901 goto exit_burn_fw_link
;
1904 //step4:load link firmware section 2 file data
1905 GTP_DEBUG("[burn_fw_link]step4:load link firmware section 2 file data");
1906 offset
+= FW_SECTION_LENGTH
;
1907 ret
= gup_load_section_file(fw_link
, offset
, FW_LINK_LENGTH
- FW_SECTION_LENGTH
, SEEK_SET
);
1911 GTP_ERROR("[burn_fw_link]load link firmware section 2 fail.");
1912 goto exit_burn_fw_link
;
1915 //step5:burn link firmware section 2
1916 GTP_DEBUG("[burn_fw_link]step4:burn link firmware section 2");
1917 ret
= gup_burn_fw_app_section(client
, fw_link
, 0x9000, FW_LINK_LENGTH
- FW_SECTION_LENGTH
, 0x39);
1921 GTP_ERROR("[burn_fw_link]burn link firmware section 2 fail.");
1922 goto exit_burn_fw_link
;
1925 update_msg
.fw_burned_len
+= FW_LINK_LENGTH
;
1926 GTP_DEBUG("[burn_fw_link]Burned length:%d", update_msg
.fw_burned_len
);
1934 static u8
gup_burn_fw_app_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
)
1939 //step1:hold ss51 & dsp
1940 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1943 GTP_ERROR("[burn_fw_app_section]hold ss51 & dsp fail.");
1947 //step2:set scramble
1948 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1951 GTP_ERROR("[burn_fw_app_section]set scramble fail.");
1955 //step3:hold ss51 & release dsp
1956 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1959 GTP_ERROR("[burn_fw_app_section]hold ss51 & release dsp fail.");
1966 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4)&0x0F);
1969 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4)&0x0F);
1973 //step5:burn fw section
1974 ret
= gup_burn_proc(client
, fw_section
, start_addr
, len
);
1977 GTP_ERROR("[burn_fw_app_section]burn fw_section fail.");
1981 //step6:send burn cmd to move data to flash from sram
1982 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
&0x0F);
1985 GTP_ERROR("[burn_fw_app_section]send burn cmd fail.");
1988 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1990 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1993 GTP_ERROR("[burn_fw_app_section]Get burn state fail");
1997 //GTP_DEBUG("[burn_fw_app_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1998 }while(rd_buf
[GTP_ADDR_LENGTH
]);
2000 //step7:recall fw section
2001 ret
= gup_recall_check(client
, fw_section
, start_addr
, len
);
2004 GTP_ERROR("[burn_fw_app_section]recall check %dk firmware fail.", len
/1024);
2011 static u8
gup_burn_fw_app_code(struct i2c_client
*client
)
2013 u8
* fw_app_code
= NULL
;
2016 //u16 start_index = 4*FW_SECTION_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH + FW_DSP_ISP_LENGTH + FW_BOOT_ISP_LENGTH; // 32 + 4 + 2 + 4 = 42K
2019 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
2021 GTP_INFO("No need to upgrade the app code!");
2024 start_index
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
2025 GTP_DEBUG("[burn_fw_app_code]Begin burn app_code firmware---->>");
2027 //step1:alloc memory
2028 GTP_DEBUG("[burn_fw_app_code]step1:alloc memory");
2031 fw_app_code
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2032 if(fw_app_code
== NULL
)
2038 GTP_INFO("[burn_fw_app_code]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2044 GTP_ERROR("[burn_fw_app_code]Alloc memory fail,exit.");
2048 //step2:load app_code firmware section 1 file data
2049 GTP_DEBUG("[burn_fw_app_code]step2:load app_code firmware section 1 file data");
2050 ret
= gup_load_section_file(fw_app_code
, start_index
, FW_SECTION_LENGTH
, SEEK_SET
);
2053 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 1 fail.");
2054 goto exit_burn_fw_app_code
;
2057 //step3:burn app_code firmware section 1
2058 GTP_DEBUG("[burn_fw_app_code]step3:burn app_code firmware section 1");
2059 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3A);
2062 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 1 fail.");
2063 goto exit_burn_fw_app_code
;
2066 //step5:load app_code firmware section 2 file data
2067 GTP_DEBUG("[burn_fw_app_code]step5:load app_code firmware section 2 file data");
2068 ret
= gup_load_section_file(fw_app_code
, start_index
+FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2071 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 2 fail.");
2072 goto exit_burn_fw_app_code
;
2075 //step6:burn app_code firmware section 2
2076 GTP_DEBUG("[burn_fw_app_code]step6:burn app_code firmware section 2");
2077 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3B);
2080 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 2 fail.");
2081 goto exit_burn_fw_app_code
;
2084 //step7:load app_code firmware section 3 file data
2085 GTP_DEBUG("[burn_fw_app_code]step7:load app_code firmware section 3 file data");
2086 ret
= gup_load_section_file(fw_app_code
, start_index
+2*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2089 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 3 fail.");
2090 goto exit_burn_fw_app_code
;
2093 //step8:burn app_code firmware section 3
2094 GTP_DEBUG("[burn_fw_app_code]step8:burn app_code firmware section 3");
2095 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3C);
2098 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 3 fail.");
2099 goto exit_burn_fw_app_code
;
2102 //step9:load app_code firmware section 4 file data
2103 GTP_DEBUG("[burn_fw_app_code]step9:load app_code firmware section 4 file data");
2104 ret
= gup_load_section_file(fw_app_code
, start_index
+ 3*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2107 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 4 fail.");
2108 goto exit_burn_fw_app_code
;
2111 //step10:burn app_code firmware section 4
2112 GTP_DEBUG("[burn_fw_app_code]step10:burn app_code firmware section 4");
2113 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3D);
2116 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 4 fail.");
2117 goto exit_burn_fw_app_code
;
2120 update_msg
.fw_burned_len
+= FW_APP_CODE_LENGTH
;
2121 GTP_DEBUG("[burn_fw_gwake]Burned length:%d", update_msg
.fw_burned_len
);
2124 exit_burn_fw_app_code
:
2129 static u8
gup_burn_fw_finish(struct i2c_client
*client
)
2135 GTP_INFO("[burn_fw_finish]burn first 8K of ss51 and finish update.");
2136 //step1:alloc memory
2137 GTP_DEBUG("[burn_fw_finish]step1:alloc memory");
2140 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2147 GTP_DEBUG("[burn_fw_finish]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2153 GTP_ERROR("[burn_fw_finish]Alloc memory fail,exit.");
2157 GTP_DEBUG("[burn_fw_finish]step2: burn ss51 first 8K.");
2158 ret
= gup_load_section_file(fw_ss51
, 0, FW_SECTION_LENGTH
, SEEK_SET
);
2161 GTP_ERROR("[burn_fw_finish]load ss51 firmware section 1 fail.");
2162 goto exit_burn_fw_finish
;
2165 GTP_DEBUG("[burn_fw_finish]step3:clear control flag");
2166 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2169 GTP_ERROR("[burn_fw_finish]clear control flag fail.");
2170 goto exit_burn_fw_finish
;
2173 GTP_DEBUG("[burn_fw_finish]step4:burn ss51 firmware section 1");
2174 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
2177 GTP_ERROR("[burn_fw_finish]burn ss51 firmware section 1 fail.");
2178 goto exit_burn_fw_finish
;
2181 //step11:enable download DSP code
2182 GTP_DEBUG("[burn_fw_finish]step5:enable download DSP code ");
2183 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x99);
2186 GTP_ERROR("[burn_fw_finish]enable download DSP code fail.");
2187 goto exit_burn_fw_finish
;
2190 //step12:release ss51 & hold dsp
2191 GTP_DEBUG("[burn_fw_finish]step6:release ss51 & hold dsp");
2192 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x08);
2195 GTP_ERROR("[burn_fw_finish]release ss51 & hold dsp fail.");
2196 goto exit_burn_fw_finish
;
2205 exit_burn_fw_finish
:
2213 s32
gup_update_proc(void *dir
)
2217 s32 update_ret
= FAIL
;
2219 #if GT917S_UPDATE_RULE
2220 char temp_data
[6] = {0};
2223 GTP_INFO("[update_proc]Begin update ......");
2226 if (1 == searching_file
)
2229 searching_file
= 0; // exit .bin update file searching
2230 GTP_INFO("Exiting searching file for auto update.");
2231 while ((show_len
!= 200) && (show_len
!= 100) && (timeout
++ < 150)) // wait for auto update quitted completely
2241 #if GTP_COMPATIBLE_MODE
2242 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2244 return gup_fw_download_proc(dir
, GTP_FL_FW_BURN
);
2247 update_msg
.file
= NULL
;
2248 ret
= gup_check_update_file(i2c_client_point
, &fw_head
, (u8
*)dir
); //20121212
2252 GTP_ERROR("[update_proc]check update file fail.");
2256 //gtp_reset_guitar(i2c_client_point, 20);
2257 ret
= gup_get_ic_fw_msg(i2c_client_point
);
2261 GTP_ERROR("[update_proc]get ic message fail.");
2265 ret
= gup_enter_update_judge(&fw_head
); //20121212
2267 #if GT917S_UPDATE_RULE
2268 i2c_read_bytes(i2c_client_point
, 0x8140, temp_data
, 6);
2269 GTP_INFO("917S firmware detect add function temp_data = (%c, %c, %c, %c)!",temp_data
[0], temp_data
[1],temp_data
[2],temp_data
[3]);
2270 if(temp_data
[0]==57 && temp_data
[1]==49 && temp_data
[2]==55 && temp_data
[3]==83)
2272 GTP_INFO("GT917S firmware detect Force Update!");
2277 #ifdef GTP_FORCE_UPDATE_FW_K92
2281 #if GTP_FORCE_UPDATE_FW
2282 ret
= SUCCESS
; //for test
2287 GTP_ERROR("[update_proc]Check *.bin file fail.");
2291 #ifdef CONFIG_OF_TOUCH
2292 disable_irq(touch_irq
);
2294 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
2298 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
2300 ret
= gup_enter_update_mode(i2c_client_point
);
2304 GTP_ERROR("[update_proc]enter update mode fail.");
2312 update_msg
.fw_burned_len
= 0;
2313 GTP_DEBUG("[update_proc]Burned length:%d", update_msg
.fw_burned_len
);
2314 ret
= gup_burn_dsp_isp(i2c_client_point
);
2317 GTP_ERROR("[update_proc]burn dsp isp fail.");
2322 ret
= gup_burn_fw_ss51(i2c_client_point
);
2325 GTP_ERROR("[update_proc]burn ss51 firmware fail.");
2330 ret
= gup_burn_fw_dsp(i2c_client_point
);
2333 GTP_ERROR("[update_proc]burn dsp firmware fail.");
2338 ret
= gup_burn_fw_boot(i2c_client_point
);
2341 GTP_ERROR("[update_proc]burn bootloader firmware fail.");
2346 ret
= gup_burn_fw_boot_isp(i2c_client_point
);
2349 GTP_ERROR("[update_proc]burn boot_isp firmware fail.");
2354 ret
= gup_burn_fw_link(i2c_client_point
);
2357 GTP_ERROR("[update_proc]burn link firmware fail.");
2362 ret
= gup_burn_fw_app_code(i2c_client_point
);
2365 GTP_ERROR("[update_proc]burn app_code firmware fail.");
2369 ret
= gup_burn_fw_finish(i2c_client_point
);
2372 GTP_ERROR("[update_proc]burn finish fail.");
2376 GTP_INFO("[update_proc]UPDATE SUCCESS.");
2382 GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
2387 update_ret
= SUCCESS
;
2391 GTP_DEBUG("[update_proc]leave update mode.");
2392 gup_leave_update_mode();
2394 if (SUCCESS
== update_ret
)
2396 GTP_DEBUG("[update_proc]send config.");
2397 ret
= gtp_send_cfg(i2c_client_point
);
2400 GTP_ERROR("[update_proc]send config fail.");
2405 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
2410 #ifdef CONFIG_OF_TOUCH
2411 enable_irq(touch_irq
);
2413 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2417 if (update_msg
.file
&& !IS_ERR(update_msg
.file
))
2419 if (update_msg
.old_fs
)
2421 set_fs(update_msg
.old_fs
);
2423 filp_close(update_msg
.file
, NULL
);
2425 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE && GTP_AUTO_UPDATE_CFG)
2428 gup_search_file(AUTO_SEARCH_CFG
);
2429 if (got_file_flag
& CFG_FILE_READY
)
2431 ret
= gup_update_config(i2c_client_point
);
2434 GTP_ERROR("Update config failed!");
2441 if (SUCCESS
== update_ret
)
2453 u8
gup_init_update_proc(struct i2c_client
*client
)
2455 struct task_struct
*thread
= NULL
;
2457 GTP_INFO("Ready to run auto update thread");
2459 #if GTP_COMPATIBLE_MODE
2460 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2462 thread
= kthread_run(gup_update_proc
, "update", "fl_auto_update");
2467 thread
= kthread_run(gup_update_proc
, (void *)NULL
, "guitar_update");
2471 GTP_ERROR("Failed to create update thread.\n");
2479 //******************* For GT9XXF Start ********************//
2481 #define FL_UPDATE_PATH "/data/_fl_update_.bin"
2482 #define FL_UPDATE_PATH_SD "/sdcard/_fl_update_.bin"
2484 #define GUP_FW_CHK_SIZE 256
2485 #define MAX_CHECK_TIMES 128 // max: 2 * (16 * 1024) / 256 = 128
2488 #define PULSE_LENGTH (200)
2489 #define INIT_CLK_DAC (50)
2490 #define MAX_CLK_DAC (120)
2491 #define CLK_AVG_TIME (1)
2492 #define MILLION 1000000
2494 #define _wRW_MISCTL__RG_DMY 0x4282
2495 #define _bRW_MISCTL__RG_OSC_CALIB 0x4268
2496 #define _fRW_MISCTL__GIO0 0x41e9
2497 #define _fRW_MISCTL__GIO1 0x41ed
2498 #define _fRW_MISCTL__GIO2 0x41f1
2499 #define _fRW_MISCTL__GIO3 0x41f5
2500 #define _fRW_MISCTL__GIO4 0x41f9
2501 #define _fRW_MISCTL__GIO5 0x41fd
2502 #define _fRW_MISCTL__GIO6 0x4201
2503 #define _fRW_MISCTL__GIO7 0x4205
2504 #define _fRW_MISCTL__GIO8 0x4209
2505 #define _fRW_MISCTL__GIO9 0x420d
2506 #define _fRW_MISCTL__MEA 0x41a0
2507 #define _bRW_MISCTL__MEA_MODE 0x41a1
2508 #define _wRW_MISCTL__MEA_MAX_NUM 0x41a4
2509 #define _dRO_MISCTL__MEA_VAL 0x41b0
2510 #define _bRW_MISCTL__MEA_SRCSEL 0x41a3
2511 #define _bRO_MISCTL__MEA_RDY 0x41a8
2512 #define _rRW_MISCTL__ANA_RXADC_B0_ 0x4250
2513 #define _bRW_MISCTL__RG_LDO_A18_PWD 0x426f
2514 #define _bRW_MISCTL__RG_BG_PWD 0x426a
2515 #define _bRW_MISCTL__RG_CLKGEN_PWD 0x4269
2516 #define _fRW_MISCTL__RG_RXADC_PWD 0x426a
2517 #define _bRW_MISCTL__OSC_CK_SEL 0x4030
2518 #define _rRW_MISCTL_RG_DMY83 0x4283
2519 #define _rRW_MISCTL__GIO1CTL_B2_ 0x41ee
2520 #define _rRW_MISCTL__GIO1CTL_B1_ 0x41ed
2522 #if GTP_COMPATIBLE_MODE
2524 u8
gup_check_fs_mounted(char *path_name
)
2526 struct path root_path
;
2529 err
= kern_path("/", LOOKUP_FOLLOW
, &root_path
);
2532 path_put(&root_path
);
2536 err
= kern_path(path_name
, LOOKUP_FOLLOW
, &path
);
2538 path_put(&root_path
);
2543 if (path
.mnt
->mnt_sb
== root_path
.mnt
->mnt_sb
)
2546 path_put(&root_path
);
2552 path_put(&root_path
);
2558 s32
gup_hold_ss51_dsp(struct i2c_client
*client
)
2564 while(retry
++ < 200)
2566 // step4:Hold ss51 & dsp
2567 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
2570 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2574 // step5:Confirm hold
2575 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
2578 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2581 if (0x0C == rd_buf
[GTP_ADDR_LENGTH
])
2583 GTP_DEBUG("[enter_update_mode]Hold ss51 & dsp confirm SUCCESS");
2586 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
2590 GTP_ERROR("Enter update Hold ss51 failed.");
2593 //DSP_CK and DSP_ALU_CK PowerOn
2594 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
2597 GTP_ERROR("[enter_update_mode]DSP_CK and DSP_ALU_CK PowerOn fail.");
2602 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
2606 GTP_ERROR("[enter_update_mode]disable wdt fail.");
2610 //clear cache enable
2611 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
2615 GTP_ERROR("[enter_update_mode]clear cache enable fail.");
2619 //set boot from sram
2620 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
2624 GTP_ERROR("[enter_update_mode]set boot from sram fail.");
2629 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
2632 GTP_ERROR("[enter_update_mode]software reboot fail.");
2639 s32
gup_enter_update_mode_fl(struct i2c_client
*client
)
2645 //step1:RST output low last at least 2ms
2646 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
2649 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
2650 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
2653 //step3:RST output high reset guitar
2654 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
2658 //select addr & hold ss51_dsp
2659 ret
= gup_hold_ss51_dsp(client
);
2662 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
2666 //clear control flag
2667 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2671 GTP_ERROR("[enter_update_mode]clear control flag fail.");
2676 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
2680 GTP_ERROR("[enter_update_mode]set scramble fail.");
2684 //enable accessing code
2685 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
2689 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
2697 static s32
gup_prepare_fl_fw(char *path
, st_fw_head
*fw_head
)
2703 if (!memcmp(path
, "update", 6))
2705 GTP_INFO("Search for Flashless firmware file to update");
2707 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
2709 if (0 == searching_file
)
2711 GTP_INFO("Force terminate searching file auto update.");
2714 update_msg
.file
= filp_open(FL_UPDATE_PATH
, O_RDONLY
, 0);
2715 if (IS_ERR(update_msg
.file
))
2717 update_msg
.file
= filp_open(FL_UPDATE_PATH_SD
, O_RDONLY
, 0);
2718 if (IS_ERR(update_msg
.file
))
2725 path
= FL_UPDATE_PATH_SD
;
2731 path
= FL_UPDATE_PATH
;
2738 GTP_ERROR("Search timeout, update aborted");
2743 _CLOSE_FILE(update_msg
.file
);
2745 while (rqst_processing
&& (timeout
++ < 15))
2747 GTP_INFO("wait for request process completed!");
2752 GTP_INFO("Firmware update file path: %s", path
);
2753 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
2755 if (IS_ERR(update_msg
.file
))
2757 GTP_ERROR("Open update file(%s) error!", path
);
2761 update_msg
.old_fs
= get_fs();
2763 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2764 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
2765 if (sizeof(gtp_default_FW_fl
) != update_msg
.fw_total_len
)
2767 //GTP_ERROR("Inconsistent firmware size. File size: %du, default fw size: %lu", update_msg.fw_total_len, sizeof(gtp_default_FW_fl));
2768 set_fs(update_msg
.old_fs
);
2769 _CLOSE_FILE(update_msg
.file
);
2773 GTP_DEBUG("Firmware size: %d", update_msg
.fw_total_len
);
2774 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2775 update_msg
.file
->f_op
->read(update_msg
.file
, (char*)fw_head
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
2776 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2777 //copy fw file to gtp_default_FW_fl array
2778 ret
= update_msg
.file
->f_op
->read(update_msg
.file
,
2779 (char*)gtp_default_FW_fl
,
2780 update_msg
.fw_total_len
,
2781 &update_msg
.file
->f_pos
);
2784 GTP_ERROR("Failed to read firmware data from %s, err-code: %d", path
, ret
);
2791 set_fs(update_msg
.old_fs
);
2792 _CLOSE_FILE(update_msg
.file
);
2796 static u8
gup_check_update_file_fl(struct i2c_client
*client
, st_fw_head
*fw_head
, char *path
)
2799 s32 fw_checksum
= 0;
2804 ret
= gup_prepare_fl_fw(path
, fw_head
);
2812 memcpy(fw_head
, gtp_default_FW_fl
, FW_HEAD_LENGTH
);
2813 GTP_INFO("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]);
2814 GTP_INFO("FILE PID:%s", fw_head
->pid
);
2815 fw_head
->vid
= ((fw_head
->vid
& 0xFF00) >> 8) + ((fw_head
->vid
& 0x00FF) << 8);
2816 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
2819 //check firmware legality
2821 for (i
= FW_HEAD_LENGTH
; i
< (FW_HEAD_LENGTH
+ update_msg
.fw_total_len
); i
+= 2)
2823 fw_checksum
= (gtp_default_FW_fl
[i
]<<8) + gtp_default_FW_fl
[i
+1];
2826 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
2827 if(fw_checksum
&0xFFFF)
2829 GTP_ERROR("Illegal firmware file.");
2837 static u8
gup_download_fw_ss51(struct i2c_client
*client
, u8 dwn_mode
)
2841 if(GTP_FL_FW_BURN
== dwn_mode
)
2843 GTP_INFO("[download_fw_ss51]Begin download ss51 firmware---->>");
2847 GTP_INFO("[download_fw_ss51]Begin check ss51 firmware----->>");
2849 //step1:download FW section 1
2850 GTP_DEBUG("[download_fw_ss51]step1:download FW section 1");
2851 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x00);
2855 GTP_ERROR("[download_fw_ss51]select bank0 fail.");
2857 goto exit_download_fw_ss51
;
2861 ret
= i2c_write_bytes(client
, 0xC000,
2862 >p_default_FW_fl
[FW_HEAD_LENGTH
], FW_DOWNLOAD_LENGTH
); // write the first bank
2866 GTP_ERROR("[download_fw_ss51]download FW section 1 fail.");
2868 goto exit_download_fw_ss51
;
2872 if (GTP_FL_FW_BURN
== dwn_mode
)
2874 ret
= gup_check_and_repair(i2c_client_point
,
2876 >p_default_FW_fl
[FW_HEAD_LENGTH
],
2877 FW_DOWNLOAD_LENGTH
);
2880 GTP_ERROR("[download_fw_ss51]Checked FW section 1 fail.");
2881 goto exit_download_fw_ss51
;
2885 //step2:download FW section 2
2886 GTP_DEBUG("[download_fw_ss51]step2:download FW section 1");
2887 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x01);
2891 GTP_ERROR("[download_fw_ss51]select bank1 fail.");
2893 goto exit_download_fw_ss51
;
2896 ret
= i2c_write_bytes(client
, 0xC000, >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],FW_DOWNLOAD_LENGTH
); // write the second bank
2900 GTP_ERROR("[download_fw_ss51]download FW section 2 fail.");
2902 goto exit_download_fw_ss51
;
2905 if (GTP_FL_FW_BURN
== dwn_mode
)
2907 ret
= gup_check_and_repair(i2c_client_point
,
2909 >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],
2910 FW_DOWNLOAD_LENGTH
);
2914 GTP_ERROR("[download_fw_ss51]Checked FW section 2 fail.");
2915 goto exit_download_fw_ss51
;
2920 exit_download_fw_ss51
:
2924 #if (!GTP_SUPPORT_I2C_DMA)
2925 static s32
i2c_auto_read(struct i2c_client
*client
,u8
*rxbuf
, int len
)
2931 struct i2c_msg msg
=
2933 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
2934 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
2936 .timing
= I2C_MASTER_CLOCK
2946 msg
.buf
= &rxbuf
[offset
];
2948 if (left
> MAX_TRANSACTION_LENGTH
)
2950 msg
.len
= MAX_TRANSACTION_LENGTH
;
2951 left
-= MAX_TRANSACTION_LENGTH
;
2952 offset
+= MAX_TRANSACTION_LENGTH
;
2962 while (i2c_transfer(client
->adapter
, &msg
, 1) != 1)
2968 GTP_ERROR("I2C read 0x%X length=%d failed\n", offset
, len
);
2977 static u8
gup_check_and_repair(struct i2c_client
*client
, s32 chk_start_addr
, u8
*target_fw
, u32 chk_total_length
)
2983 u8 chk_buf
[GUP_FW_CHK_SIZE
];
2988 chk_addr
= chk_start_addr
;
2989 while((chked_times
< MAX_CHECK_TIMES
) && (chked_len
< chk_total_length
))
2991 rd_size
= chk_total_length
- chked_len
;
2992 if(rd_size
>= GUP_FW_CHK_SIZE
)
2994 rd_size
= GUP_FW_CHK_SIZE
;
2996 #if GTP_SUPPORT_I2C_DMA
2997 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
3001 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
3005 ret
= i2c_auto_read(client
, chk_buf
, rd_size
);
3011 GTP_ERROR("Read chk ram fw i2c error");
3016 for(i
=0; i
<rd_size
; i
++)
3018 if(chk_buf
[i
] != target_fw
[i
])
3020 GTP_ERROR("chk_buf[%d] = 0x%x, target_fw[%d] = 0x%x.", i
,chk_buf
[i
],i
,target_fw
[i
]);
3021 GTP_ERROR("Ram pos[0x%04x] checked failed,rewrite.", chk_addr
+ i
);
3022 i2c_write_bytes(client
, chk_addr
+i
, &target_fw
[i
], rd_size
-i
);
3031 GTP_DEBUG("Ram pos[0x%04X] check pass!", chk_addr
);
3032 chked_len
+= rd_size
;
3033 target_fw
+= rd_size
;
3034 chk_addr
+= rd_size
;
3043 if(chked_times
>= MAX_CHECK_TIMES
)
3045 GTP_ERROR("Ram data check failed.");
3051 static u8
gup_download_fw_dsp(struct i2c_client
*client
, u8 dwn_mode
)
3055 if(GTP_FL_FW_BURN
== dwn_mode
)
3057 GTP_INFO("[download_fw_dsp]Begin download dsp fw---->>");
3061 GTP_INFO("[download_fw_dsp]Begin check dsp fw---->>");
3064 //step1:select bank2
3065 GTP_DEBUG("[download_fw_dsp]step1:select bank2");
3066 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
3070 GTP_ERROR("[download_fw_dsp]select bank2 fail.");
3072 goto exit_download_fw_dsp
;
3075 ret
= i2c_write_bytes(client
,
3077 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3078 FW_DSP_LENGTH
); // write the second bank
3081 GTP_ERROR("[download_fw_dsp]download FW dsp fail.");
3083 goto exit_download_fw_dsp
;
3086 if (GTP_FL_FW_BURN
== dwn_mode
)
3088 ret
= gup_check_and_repair(client
,
3090 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3095 GTP_ERROR("[download_fw_dsp]Checked FW dsp fail.");
3096 goto exit_download_fw_dsp
;
3102 exit_download_fw_dsp
:
3107 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
)
3113 if(GTP_FL_FW_BURN
== dwn_mode
)
3115 GTP_INFO("[fw_download_proc]Begin fw download ......");
3119 GTP_INFO("[fw_download_proc]Begin fw check ......");
3124 ret
= gup_check_update_file_fl(i2c_client_point
, &fw_head
, (char *)dir
);
3130 GTP_ERROR("[fw_download_proc]check update file fail.");
3134 #ifdef CONFIG_OF_TOUCH
3135 disable_irq(touch_irq
);
3137 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3143 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3147 ret
= gup_enter_update_mode_fl(i2c_client_point
);
3152 GTP_ERROR("[fw_download_proc]enter update mode fail.");
3158 ret
= gup_download_fw_ss51(i2c_client_point
, dwn_mode
);
3162 GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
3166 ret
= gup_download_fw_dsp(i2c_client_point
, dwn_mode
);
3170 GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
3174 GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
3180 GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
3186 gtp_fw_startup(i2c_client_point
);
3188 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3193 #ifdef CONFIG_OF_TOUCH
3194 enable_irq(touch_irq
);
3196 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3204 gtp_fw_startup(i2c_client_point
);
3206 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3213 #ifdef CONFIG_OF_TOUCH
3214 enable_irq(touch_irq
);
3216 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3223 static void gup_bit_write(s32 addr
, s32 bit
, s32 val
)
3226 i2c_read_bytes(i2c_client_point
, addr
, &buf
, 1);
3228 buf
= (buf
& (~((u8
)1 << bit
))) | ((u8
)val
<< bit
);
3230 i2c_write_bytes(i2c_client_point
, addr
, &buf
, 1);
3233 static void gup_clk_count_init(s32 bCh
, s32 bCNT
)
3237 //_fRW_MISCTL__MEA_EN = 0; //Frequency measure enable
3238 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3239 //_fRW_MISCTL__MEA_CLR = 1; //Frequency measure clear
3240 gup_bit_write(_fRW_MISCTL__MEA
, 1, 1);
3241 //_bRW_MISCTL__MEA_MODE = 0; //Pulse mode
3243 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_MODE
, &buf
, 1);
3244 //_bRW_MISCTL__MEA_SRCSEL = 8 + bCh; //From GIO1
3246 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_SRCSEL
, &buf
, 1);
3247 //_wRW_MISCTL__MEA_MAX_NUM = bCNT; //Set the Measure Counts = 1
3249 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__MEA_MAX_NUM
, &buf
, 1);
3250 //_fRW_MISCTL__MEA_CLR = 0; //Frequency measure not clear
3251 gup_bit_write(_fRW_MISCTL__MEA
, 1, 0);
3252 //_fRW_MISCTL__MEA_EN = 1;
3253 gup_bit_write(_fRW_MISCTL__MEA
, 0, 1);
3256 static u32
gup_clk_count_get(void)
3262 while ((ready
== 0)) //Wait for measurement complete
3264 i2c_read_bytes(i2c_client_point
, _bRO_MISCTL__MEA_RDY
, buf
, 1);
3270 //_fRW_MISCTL__MEA_EN = 0;
3271 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3272 i2c_read_bytes(i2c_client_point
, _dRO_MISCTL__MEA_VAL
, buf
, 4);
3273 GTP_INFO("Clk_count 0: %2X", buf
[0]);
3274 GTP_INFO("Clk_count 1: %2X", buf
[1]);
3275 GTP_INFO("Clk_count 2: %2X", buf
[2]);
3276 GTP_INFO("Clk_count 3: %2X", buf
[3]);
3278 temp
= (s32
)buf
[0] + ((s32
)buf
[1] << 8) + ((s32
)buf
[2] << 16) + ((s32
)buf
[3] << 24);
3279 GTP_INFO("Clk_count : %d", temp
);
3282 u8
gup_clk_dac_setting(int dac
)
3286 i2c_read_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3287 i2c_read_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3289 buf1
= (buf1
& 0xFFCF) | ((dac
& 0x03) << 4);
3290 buf2
= (dac
>> 2) & 0x3f;
3292 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3293 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3298 static u8
gup_clk_calibration_pin_select(s32 bCh
)
3305 i2c_addr
= _fRW_MISCTL__GIO0
;
3309 i2c_addr
= _fRW_MISCTL__GIO1
;
3313 i2c_addr
= _fRW_MISCTL__GIO2
;
3317 i2c_addr
= _fRW_MISCTL__GIO3
;
3321 i2c_addr
= _fRW_MISCTL__GIO4
;
3325 i2c_addr
= _fRW_MISCTL__GIO5
;
3329 i2c_addr
= _fRW_MISCTL__GIO6
;
3333 i2c_addr
= _fRW_MISCTL__GIO7
;
3337 i2c_addr
= _fRW_MISCTL__GIO8
;
3341 i2c_addr
= _fRW_MISCTL__GIO9
;
3345 gup_bit_write(i2c_addr
, 1, 0);
3350 void gup_output_pulse(int t
)
3352 unsigned long flags
;
3355 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3358 local_irq_save(flags
);
3360 mt_set_gpio_out(GTP_INT_PORT
, 1);
3362 mt_set_gpio_out(GTP_INT_PORT
, 0);
3364 mt_set_gpio_out(GTP_INT_PORT
, 1);
3366 local_irq_restore(flags
);
3369 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3372 static void gup_sys_clk_init(void)
3376 //_fRW_MISCTL__RG_RXADC_CKMUX = 0;
3377 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 5, 0);
3378 //_bRW_MISCTL__RG_LDO_A18_PWD = 0; //DrvMISCTL_A18_PowerON
3380 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_LDO_A18_PWD
, &buf
, 1);
3381 //_bRW_MISCTL__RG_BG_PWD = 0; //DrvMISCTL_BG_PowerON
3383 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_BG_PWD
, &buf
, 1);
3384 //_bRW_MISCTL__RG_CLKGEN_PWD = 0; //DrvMISCTL_CLKGEN_PowerON
3386 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_CLKGEN_PWD
, &buf
, 1);
3387 //_fRW_MISCTL__RG_RXADC_PWD = 0; //DrvMISCTL_RX_ADC_PowerON
3388 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 0, 0);
3389 //_fRW_MISCTL__RG_RXADC_REF_PWD = 0; //DrvMISCTL_RX_ADCREF_PowerON
3390 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 1, 0);
3391 //gup_clk_dac_setting(60);
3392 //_bRW_MISCTL__OSC_CK_SEL = 1;;
3394 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__OSC_CK_SEL
, &buf
, 1);
3397 u8
gup_clk_calibration(void)
3402 struct timeval start
, end
;
3408 //unsigned long flags;
3410 //buf = 0x0C; // hold ss51 and dsp
3411 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3412 ret
= gup_hold_ss51_dsp(i2c_client_point
);
3415 GTP_ERROR("[gup_clk_calibration]hold ss51 & dsp failed.");
3419 //_fRW_MISCTL__CLK_BIAS = 0; //disable clock bias
3420 gup_bit_write(_rRW_MISCTL_RG_DMY83
, 7, 0);
3422 //_fRW_MISCTL__GIO1_PU = 0; //set TOUCH INT PIN MODE as input
3423 gup_bit_write(_rRW_MISCTL__GIO1CTL_B2_
, 0, 0);
3425 //_fRW_MISCTL__GIO1_OE = 0; //set TOUCH INT PIN MODE as input
3426 gup_bit_write(_rRW_MISCTL__GIO1CTL_B1_
, 1, 0);
3429 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3432 GTP_INFO("CLK calibration GO");
3434 gup_clk_calibration_pin_select(1);//use GIO1 to do the calibration
3436 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3438 for (i
= INIT_CLK_DAC
; i
< MAX_CLK_DAC
; i
++)
3442 i
= 80; // if sleeping while calibrating main clock, set it default 80
3445 GTP_INFO("CLK calibration DAC %d", i
);
3447 gup_clk_dac_setting(i
);
3448 gup_clk_count_init(1, CLK_AVG_TIME
);
3451 gup_output_pulse(PULSE_LENGTH
);
3452 count
= gup_clk_count_get();
3454 if (count
> PULSE_LENGTH
* 60)//60= 60Mhz * 1us
3460 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3462 //local_irq_save(flags);
3463 do_gettimeofday(&start
);
3464 mt_set_gpio_out(GTP_INT_PORT
, 1);
3465 //local_irq_restore(flags);
3468 mt_set_gpio_out(GTP_INT_PORT
, 0);
3471 //local_irq_save(flags);
3472 do_gettimeofday(&end
);
3473 mt_set_gpio_out(GTP_INT_PORT
, 1);
3474 //local_irq_restore(flags);
3476 count
= gup_clk_count_get();
3478 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3480 usec
= end
.tv_usec
- start
.tv_usec
;
3481 sec
= end
.tv_sec
- start
.tv_sec
;
3482 count_ref
= 60 * (usec
+ sec
* MILLION
);//60= 60Mhz * 1us
3484 GTP_DEBUG("== time %d, %d, %d", sec
, usec
, count_ref
);
3486 if (count
> count_ref
)
3488 GTP_DEBUG("== count_diff %d", count
- count_ref
);
3497 //gtp_reset_guitar(i2c_client_point, 20);
3500 //-- ouput clk to GPIO 4
3502 i2c_write_bytes(i2c_client_point
, 0x41FA, &buf
, 1);
3504 i2c_write_bytes(i2c_client_point
, 0x4104, &buf
, 1);
3506 i2c_write_bytes(i2c_client_point
, 0x4105, &buf
, 1);
3508 i2c_write_bytes(i2c_client_point
, 0x4106, &buf
, 1);
3510 i2c_write_bytes(i2c_client_point
, 0x4107, &buf
, 1);
3512 i2c_write_bytes(i2c_client_point
, 0x41F8, &buf
, 1);
3514 i2c_write_bytes(i2c_client_point
, 0x41F9, &buf
, 1);
3517 GTP_GPIO_AS_INT(GTP_INT_PORT
);
3522 #define BANK_LENGTH (16*1024)
3523 #define FIRMWARE_HEADER_LEN 14
3525 static u32 current_system_length
= 0;
3527 char * gup_load_fw_from_file(char *filepath
)
3529 struct file
*fw_file
= NULL
;
3530 mm_segment_t old_fs
;
3532 char *buffer
= NULL
;
3534 if(filepath
== NULL
)
3536 GTP_ERROR("[Load_firmware]filepath: NULL");
3537 goto load_firmware_exit
;
3543 fw_file
= filp_open(filepath
, O_RDONLY
, 0);
3544 if (fw_file
== NULL
|| IS_ERR(fw_file
))
3546 GTP_ERROR("[Load_firmware]Failed to open: %s", filepath
);
3547 goto load_firmware_exit
;
3549 fw_file
->f_op
->llseek(fw_file
, 0, SEEK_SET
);
3550 len
= fw_file
->f_op
->llseek(fw_file
, 0, SEEK_END
);
3553 GTP_ERROR("[Load_firmware]Firmware is too short: %ld", len
);
3554 goto load_firmware_failed
;
3556 buffer
= (char *)kmalloc(sizeof(char) * len
, GFP_KERNEL
);
3559 GTP_ERROR("[Load_firmware]Failed to allocate buffer: %ld", len
);
3560 goto load_firmware_failed
;
3563 memset(buffer
, 0, sizeof(char) * len
);
3565 fw_file
->f_op
->llseek(fw_file
, 0, SEEK_SET
);
3566 fw_file
->f_op
->read(fw_file
, buffer
, len
, &fw_file
->f_pos
);
3568 GTP_ERROR("[Load_firmware]Load from file success: %ld %s", len
, filepath
);
3571 load_firmware_failed
:
3572 filp_close(fw_file
, NULL
);
3579 s32
gup_check_firmware(char *fw
, u32 length
)
3582 u32 fw_checksum
= 0;
3585 for(i
=0; i
<length
; i
+=2)
3587 temp
= (fw
[i
]<<8) + fw
[i
+1];
3588 fw_checksum
+= temp
;
3591 GTP_DEBUG("firmware checksum: %4X", fw_checksum
&0xFFFF);
3592 if(fw_checksum
&0xFFFF)
3599 s32
gup_enter_update_mode_noreset(void)
3604 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__TMR0_EN
, 0x00);
3607 GTP_ERROR("[enter_update_mode]disable wdt fail.");
3610 //select addr & hold ss51_dsp
3611 ret
= gup_hold_ss51_dsp(i2c_client_point
);
3614 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
3618 //clear control flag
3619 ret
= gup_set_ic_msg(i2c_client_point
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
3623 GTP_ERROR("[enter_update_mode]clear control flag fail.");
3628 ret
= gup_set_ic_msg(i2c_client_point
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
3632 GTP_ERROR("[enter_update_mode]set scramble fail.");
3636 //enable accessing code
3637 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
3641 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
3648 s32
gup_load_by_bank(u8 bank
, u8 need_check
, u8
*fw
, u32 length
)
3653 GTP_DEBUG("[load_by_bank]begin download [bank:%d,length:%d].",bank
,length
);
3656 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, bank
);
3659 GTP_ERROR("[load_by_bank]select bank fail.");
3663 ret
= i2c_write_bytes(i2c_client_point
, 0xC000,fw
, length
);
3666 GTP_ERROR("[load_by_bank]download bank fail.");
3672 ret
= gup_check_and_repair(i2c_client_point
, 0xC000, fw
, length
);
3675 GTP_ERROR("[load_by_bank]checked FW bank fail.");
3691 s32
gup_load_system(char *firmware
, s32 length
, u8 need_check
)
3696 #ifdef CONFIG_OF_TOUCH
3697 disable_irq(touch_irq
);
3699 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3703 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3705 ret
= gup_enter_update_mode_noreset();
3708 goto gup_load_system_exit
;
3710 GTP_DEBUG("enter update mode success.");
3713 u32 len
= length
>BANK_LENGTH
? BANK_LENGTH
:length
;
3714 ret
= gup_load_by_bank(bank
, need_check
, &firmware
[bank
*BANK_LENGTH
], len
);
3717 goto gup_load_system_exit
;
3719 GTP_DEBUG("load bank%d length:%d success.", bank
, len
);
3724 ret
= gtp_fw_startup(i2c_client_point
);
3726 gup_load_system_exit
:
3728 #if FLASHLESS_FLASH_WORKROUND
3731 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3735 #ifdef CONFIG_OF_TOUCH
3736 enable_irq(touch_irq
);
3738 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3744 s32
gup_load_fx_system(void)
3747 char *firmware
= NULL
;
3748 u32 is_load_from_file
= 0;
3751 GTP_INFO("[load_fx_system] Load authorization system.");
3753 firmware
= gtp_default_FW_hotknot2
;
3756 firmware
= gup_load_fw_from_file( FX_SYSTEM_PATH
);
3757 if(firmware
== NULL
)
3759 firmware
= gtp_default_FW_hotknot2
;
3760 GTP_INFO("[load_fx_system] Use default firmware.");
3764 is_load_from_file
= 1;
3768 length
= firmware
[0]*256*256*256+
3769 firmware
[1]*256*256+
3773 if(length
> 32*1024 || length
< 4*1024 )
3775 GTP_ERROR("[load_fx_system]firmware's length is invalid.");
3779 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3782 GTP_ERROR("[load_fx_system]firmware's checksum is error.");
3786 current_system_length
= length
;
3788 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 1);
3792 if(is_load_from_file
)
3801 s32
gup_load_hotknot_system(void)
3804 char *firmware
= NULL
;
3805 u32 is_load_from_file
= 0;
3808 GTP_INFO("[load_hotknot_system] Load hotknot system.");
3809 load_fw_process
= 1;
3811 firmware
= gtp_default_FW_hotknot
;
3814 firmware
= gup_load_fw_from_file( HOTKNOT_SYSTEM_PATH
);
3815 if(firmware
== NULL
)
3817 firmware
= gtp_default_FW_hotknot
;
3818 GTP_INFO("[load_hotknot_system] Use default firmware.");
3822 is_load_from_file
= 1;
3826 length
= firmware
[0]*256*256*256+
3827 firmware
[1]*256*256+
3830 if(length
> 32*1024 || length
< 4*1024 )
3832 GTP_ERROR("[load_hotknot_system]firmware's length is invalid.");
3833 goto load_hotknot_exit
;
3836 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3839 GTP_ERROR("[load_hotknot_system]firmware's checksum is error.");
3840 goto load_hotknot_exit
;
3843 current_system_length
= length
;
3845 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 0);
3849 if(is_load_from_file
)
3859 s32
gup_recovery_main_system(void)
3862 char *firmware
= NULL
;
3863 u32 is_load_from_file
= 0;
3866 GTP_INFO("[recovery_main_system] Recovery main system.");
3868 if(gtp_chip_type
== CHIP_TYPE_GT9
)
3870 gtp_reset_guitar(i2c_client_point
,10);
3871 load_fw_process
= 0;
3874 firmware
= gtp_default_FW_fl
;
3877 firmware
= gup_load_fw_from_file(MAIN_SYSTEM_PATH
);
3878 if(firmware
== NULL
)
3880 firmware
= gtp_default_FW_fl
;
3881 GTP_INFO("[recovery_main_system]Use default firmware.");
3885 is_load_from_file
= 1;
3889 if(firmware
[0]==0x00&&firmware
[1]==0x90&&firmware
[2]==0x06&&firmware
[3]==0x00)
3895 length
= firmware
[0]*256*256*256+
3896 firmware
[1]*256*256+
3900 if(length
> 36*1024 || length
< 16*1024 )
3902 GTP_ERROR("[recovery_main_system]firmware's length is invalid.");
3903 goto recovery_main_system_exit
;
3906 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3909 GTP_ERROR("[recovery_main_system]firmware's checksum is error.");
3910 goto recovery_main_system_exit
;
3913 if(current_system_length
== 0)
3915 current_system_length
= length
;
3918 GTP_INFO("[recovery_main_system] Recovery length: %d.", current_system_length
);
3920 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], current_system_length
, 0);
3922 #if (FLASHLESS_FLASH_WORKROUND && GTP_ESD_PROTECT)
3923 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3926 recovery_main_system_exit
:
3928 if(is_load_from_file
)
3933 load_fw_process
= 0;
3938 s32
gup_load_main_system(char *filepath
)
3941 char *firmware
= NULL
;
3942 u32 is_load_from_file
= 0;
3945 GTP_INFO("[load_main_system] Load main system.");
3947 if(filepath
!= NULL
)
3949 firmware
= gup_load_fw_from_file(filepath
);
3950 if(firmware
== NULL
)
3952 GTP_INFO("[load_main_system]can not open file: %s", filepath
);
3953 goto load_main_system_exit
;
3957 is_load_from_file
= 1;
3962 firmware
= gtp_default_FW_fl
;
3965 firmware
= gup_load_fw_from_file(filepath
);
3966 if(firmware
== NULL
)
3968 if(gtp_chip_type
== CHIP_TYPE_GT9
)
3969 firmware
= gtp_default_FW
;
3971 firmware
= gtp_default_FW_fl
;
3972 GTP_INFO("[load_main_system]Use default firmware. type:%d", gtp_chip_type
);
3976 is_load_from_file
= 1;
3980 if(firmware
[0]==0x00&&firmware
[1]==0x90&&firmware
[2]==0x06&&firmware
[3]==0x00)
3986 length
= firmware
[0]*256*256*256+
3987 firmware
[1]*256*256+
3990 if(length
> 36*1024)
3995 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3998 GTP_ERROR("[load_main_system]firmware's checksum is error.");
3999 goto load_main_system_exit
;
4001 GTP_INFO("[load_main_system] Firmware length: %d.", length
);
4003 //memcpy(gtp_default_FW_fl, firmware, length);
4005 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 1);
4008 #if (FLASHLESS_FLASH_WORKROUND && GTP_ESD_PROTECT)
4009 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
4012 load_main_system_exit
:
4014 if(is_load_from_file
)
4022 //*************** For GT9XXF End ***********************//