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"
57 #define GUP_REG_HW_INFO 0x4220
58 #define GUP_REG_FW_MSG 0x41E4
59 #define GUP_REG_PID_VID 0x8140
61 #define GUP_SEARCH_FILE_TIMES 50
62 #define UPDATE_FILE_PATH_1 "/data/_goodix_update_.bin"
63 #define UPDATE_FILE_PATH_2 "/sdcard/_goodix_update_.bin"
65 #define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg"
66 #define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg"
68 #define FW_HEAD_LENGTH 14
69 #define FW_DOWNLOAD_LENGTH 0x4000
70 #define FW_SECTION_LENGTH 0x2000
71 #define FW_DSP_ISP_LENGTH 0x1000
72 #define FW_DSP_LENGTH 0x1000
73 #define FW_BOOT_LENGTH 0x800
74 #define FW_SS51_LENGTH (4 * FW_SECTION_LENGTH)
75 #define FW_BOOT_ISP_LENGTH 0x800 // 2k
76 #define FW_LINK_LENGTH 0x3000 // 12k
77 #define FW_APP_CODE_LENGTH (4 * FW_SECTION_LENGTH) // 32k
79 #define FIRMWARE_LENGTH (FW_SS51_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH + FW_DSP_ISP_LENGTH + FW_BOOT_ISP_LENGTH + FW_APP_CODE_LENGTH)
81 #define FW_HOTKNOT_LENGTH 0x3000
83 #define MAX_FRAME_CHECK_TIME 5
86 #define _bRW_MISCTL__SRAM_BANK 0x4048
87 #define _bRW_MISCTL__MEM_CD_EN 0x4049
88 #define _bRW_MISCTL__CACHE_EN 0x404B
89 #define _bRW_MISCTL__TMR0_EN 0x40B0
90 #define _rRW_MISCTL__SWRST_B0_ 0x4180
91 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
92 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
93 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
94 #define _rRW_MISCTL__BOOT_CTL_ 0x5094
96 #define AUTO_SEARCH_BIN 0x01
97 #define AUTO_SEARCH_CFG 0x02
98 #define BIN_FILE_READY 0x80
99 #define CFG_FILE_READY 0x08
100 #define HEADER_FW_READY 0x01
105 #define MAIN_SYSTEM_PATH "/sdcard/goodix/_main_.bin"
106 #define HOTKNOT_SYSTEM_PATH "/sdcard/goodix/_hotknot_.bin"
107 #define FX_SYSTEM_PATH "/sdcard/goodix/_authorization_.bin"
112 u8 hw_info
[4]; //hardware info//
113 u8 pid
[8]; //product id //
114 u16 vid
; //version id //
123 struct file
*cfg_file
;
124 st_fw_head ic_fw_msg
;
130 st_update_msg update_msg
;
131 extern struct i2c_client
*i2c_client_point
;
134 extern u8 fw_updating
;
136 extern struct mutex i2c_access
;
137 u8 searching_file
= 0;
138 u8 got_file_flag
= 0;
139 u8 load_fw_process
= 0;
142 extern void gtp_esd_switch(struct i2c_client
*client
, s32 on
);
145 #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE)
146 extern u8 is_reseting
;
150 #if GTP_COMPATIBLE_MODE
151 extern CHIP_TYPE_T gtp_chip_type
;
152 extern u8 rqst_processing
;
153 extern u8
gtp_fw_startup(struct i2c_client
*client
);
154 static u8
gup_check_and_repair(struct i2c_client
*, s32
, u8
*, u32
);
155 s32
gup_recovery_main_system(void);
156 s32
gup_load_main_system(char *filepath
);
157 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
);
158 char * gup_load_fw_from_file(char *filepath
);
159 s32
gup_load_system(char *firmware
, s32 length
, u8 need_check
);
162 #define _CLOSE_FILE(p_file) if (p_file && !IS_ERR(p_file)) \
164 filp_close(p_file, NULL); \
168 static u8
gup_burn_fw_app_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
);
170 static s32
gup_i2c_read(struct i2c_client
*client
, u8
*buf
, s32 len
)
173 u16 addr
= (buf
[0] << 8) + buf
[1];
175 ret
= i2c_read_bytes(client
, addr
, &buf
[2], len
- 2);
187 static s32
gup_i2c_write(struct i2c_client
*client
, u8
*buf
, s32 len
)
190 u16 addr
= (buf
[0] << 8) + buf
[1];
192 ret
= i2c_write_bytes(client
, addr
, &buf
[2], len
- 2);
204 static u8
gup_get_ic_msg(struct i2c_client
*client
, u16 addr
, u8
*msg
, s32 len
)
208 msg
[0] = (addr
>> 8) & 0xff;
209 msg
[1] = addr
& 0xff;
211 for (i
= 0; i
< 5; i
++)
213 if (gup_i2c_read(client
, msg
, GTP_ADDR_LENGTH
+ len
) > 0)
221 GTP_ERROR("Read data from 0x%02x%02x failed!", msg
[0], msg
[1]);
228 static u8
gup_set_ic_msg(struct i2c_client
*client
, u16 addr
, u8 val
)
233 msg
[0] = (addr
>> 8) & 0xff;
234 msg
[1] = addr
& 0xff;
237 for (i
= 0; i
< 5; i
++)
239 if (gup_i2c_write(client
, msg
, GTP_ADDR_LENGTH
+ 1) > 0)
247 GTP_ERROR("Set data to 0x%02x%02x failed!", msg
[0], msg
[1]);
254 static u8
gup_get_ic_fw_msg(struct i2c_client
*client
)
261 //step1:get hardware info
262 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_HW_INFO
, &buf
[GTP_ADDR_LENGTH
], 4);
265 GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit");
269 // buf[2~5]: 00 06 90 00
270 // hw_info: 00 90 06 00
271 for (i
= 0; i
< 4; i
++)
273 update_msg
.ic_fw_msg
.hw_info
[i
] = buf
[GTP_ADDR_LENGTH
+ 3 - i
];
276 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],
277 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
279 //step2:get firmware message
280 for (retry
= 0; retry
< 2; retry
++)
282 ret
= gup_get_ic_msg(client
, GUP_REG_FW_MSG
, buf
, 1);
286 GTP_ERROR("Read firmware message fail.");
290 update_msg
.force_update
= buf
[GTP_ADDR_LENGTH
];
292 if ((0xBE != update_msg
.force_update
) && (!retry
))
294 GTP_INFO("The check sum in ic is error.");
295 GTP_INFO("The IC will be updated by force.");
301 GTP_INFO("IC force update flag:0x%x", update_msg
.force_update
);
303 //step3:get pid & vid
304 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_PID_VID
, &buf
[GTP_ADDR_LENGTH
], 6);
307 GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit");
311 memset(update_msg
.ic_fw_msg
.pid
, 0, sizeof(update_msg
.ic_fw_msg
.pid
));
312 memcpy(update_msg
.ic_fw_msg
.pid
, &buf
[GTP_ADDR_LENGTH
], 4);
316 /*|-----FLASH-----RAM-----|
317 |------918------918-----|
318 |------968------968-----|
319 |------913------913-----|
320 |------913P-----913P----|
321 |------927------927-----|
322 |------927P-----927P----|
323 |------9110-----9110----|
324 |------9110P----9111----|*/
325 if(update_msg
.ic_fw_msg
.pid
[0] != 0)
327 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "9111", 4))
329 GTP_INFO("IC Mapping Product id:%s", update_msg
.ic_fw_msg
.pid
);
330 memcpy(update_msg
.ic_fw_msg
.pid
, "9110P", 5);
334 update_msg
.ic_fw_msg
.vid
= buf
[GTP_ADDR_LENGTH
+ 4] + (buf
[GTP_ADDR_LENGTH
+ 5] << 8);
338 s32
gup_enter_update_mode(struct i2c_client
*client
)
344 //step1:RST output low last at least 2ms
345 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
348 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
349 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
352 //step3:RST output high reset guitar
353 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
355 //20121211 modify start
359 //step4:Hold ss51 & dsp
360 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
363 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
368 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
371 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
374 if(0x0C == rd_buf
[GTP_ADDR_LENGTH
])
376 GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
379 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
383 GTP_ERROR("Enter update Hold ss51 failed.");
387 //step6:DSP_CK and DSP_ALU_CK PowerOn
388 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
390 //20121211 modify end
394 void gup_leave_update_mode(void)
396 GTP_GPIO_AS_INT(GTP_INT_PORT
);
398 GTP_DEBUG("[leave_update_mode]reset chip.");
399 #if GTP_COMPATIBLE_MODE
400 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
402 force_reset_guitar();
403 GTP_INFO("User layer reset GT9XXF.");
407 gtp_reset_guitar(i2c_client_point
, 20);
410 static u8
gup_enter_update_judge(st_fw_head
*fw_head
)
416 //Get the correct nvram data
417 //The correct conditions:
418 //1. the hardware info is the same
419 //2. the product id is the same
420 //3. the firmware version in update file is greater than the firmware version in ic
421 //or the check sum in ic is wrong
423 u16_tmp
= fw_head
->vid
;
424 fw_head
->vid
= (u16
)(u16_tmp
>> 8) + (u16
)(u16_tmp
<< 8);
426 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]);
427 GTP_INFO("FILE PID:%s", fw_head
->pid
);
428 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
429 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],
430 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
431 GTP_INFO("IC PID:%s", update_msg
.ic_fw_msg
.pid
);
432 GTP_INFO("IC VID:%04x", update_msg
.ic_fw_msg
.vid
);
434 if (!memcmp(fw_head
->hw_info
, update_msg
.ic_fw_msg
.hw_info
, sizeof(update_msg
.ic_fw_msg
.hw_info
)))
440 fw_len
= fw_head
->hw_info
[3];
441 fw_len
+= (((u32
)fw_head
->hw_info
[2]) << 8);
442 fw_len
+= (((u32
)fw_head
->hw_info
[1]) << 16);
443 fw_len
+= (((u32
)fw_head
->hw_info
[0]) << 24);
445 if (update_msg
.fw_total_len
!= fw_len
)
447 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);
450 if ((update_msg
.fw_total_len
< 36*1024) || (update_msg
.fw_total_len
> 128*1024))
452 GTP_ERROR("Invalid firmware length(%d), update aborted!", update_msg
.fw_total_len
);
455 GTP_INFO("Firmware length:%d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
457 if (update_msg
.force_update
!= 0xBE)
459 GTP_INFO("FW chksum error,need enter update.");
464 if (strlen(update_msg
.ic_fw_msg
.pid
) < 3)
466 GTP_INFO("Illegal IC pid, need enter update");
471 for (i
= 0; i
< 3; i
++)
473 if ((update_msg
.ic_fw_msg
.pid
[i
] < 0x30) || (update_msg
.ic_fw_msg
.pid
[i
] > 0x39))
475 GTP_INFO("Illegal IC pid, out of bound, need enter update");
482 pid_cmp_len
= strlen(fw_head
->pid
);
483 if (pid_cmp_len
< strlen(update_msg
.ic_fw_msg
.pid
))
485 pid_cmp_len
= strlen(update_msg
.ic_fw_msg
.pid
);
488 if ((!memcmp(fw_head
->pid
, update_msg
.ic_fw_msg
.pid
, pid_cmp_len
)) ||
489 (!memcmp(update_msg
.ic_fw_msg
.pid
, "91XX", 4))||
490 (!memcmp(fw_head
->pid
, "91XX", 4)))
492 if(!memcmp(fw_head
->pid
, "91XX", 4))
494 GTP_DEBUG("Force none same pid update mode.");
498 GTP_DEBUG("Get the same pid.");
501 //The third condition
502 if (fw_head
->vid
> update_msg
.ic_fw_msg
.vid
)
505 GTP_INFO("Need enter update.");
509 GTP_INFO("Don't meet the third condition.");
510 GTP_ERROR("File VID <= IC VID, update aborted!");
514 GTP_ERROR("File PID != IC PID, update aborted!");
520 #if GTP_AUTO_UPDATE_CFG
521 static u8
ascii2hex(u8 a
)
525 if(a
>= '0' && a
<= '9')
529 else if(a
>= 'A' && a
<= 'F')
531 value
= a
- 'A' + 0x0A;
533 else if(a
>= 'a' && a
<= 'f')
535 value
= a
- 'a' + 0x0A;
545 static s8
gup_update_config(struct i2c_client
*client
)
550 s32 file_cfg_len
= 0;
551 s32 chip_cfg_len
= 0;
558 if(NULL
== update_msg
.cfg_file
)
560 GTP_ERROR("[update_cfg]No need to upgrade config!");
563 file_len
= update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_END
);
565 chip_cfg_len
= cfg_len
;
567 GTP_DEBUG("[update_cfg]config file len:%d", file_len
);
568 GTP_DEBUG("[update_cfg]need config len:%d",chip_cfg_len
);
569 if((file_len
+5) < chip_cfg_len
*5)
571 GTP_ERROR("Config length error");
575 buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
576 pre_buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
577 file_config
= (u8
*)kzalloc(chip_cfg_len
+ GTP_ADDR_LENGTH
, GFP_KERNEL
);
578 update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_SET
);
580 GTP_DEBUG("[update_cfg]Read config from file.");
581 ret
= update_msg
.cfg_file
->f_op
->read(update_msg
.cfg_file
, (char*)pre_buf
, file_len
, &update_msg
.cfg_file
->f_pos
);
584 GTP_ERROR("[update_cfg]Read config file failed.");
585 goto update_cfg_file_failed
;
588 GTP_DEBUG("[update_cfg]Delete illgal charactor.");
589 for(i
=0,count
=0; i
<file_len
; i
++)
591 if (pre_buf
[i
] == ' ' || pre_buf
[i
] == '\r' || pre_buf
[i
] == '\n')
595 buf
[count
++] = pre_buf
[i
];
598 GTP_DEBUG("[update_cfg]Ascii to hex.");
599 file_config
[0] = GTP_REG_CONFIG_DATA
>> 8;
600 file_config
[1] = GTP_REG_CONFIG_DATA
& 0xff;
601 for(i
=0,file_cfg_len
=GTP_ADDR_LENGTH
; i
<count
; i
+=5)
603 if((buf
[i
]=='0') && ((buf
[i
+1]=='x') || (buf
[i
+1]=='X')))
606 high
= ascii2hex(buf
[i
+2]);
607 low
= ascii2hex(buf
[i
+3]);
609 if((high
== 0xFF) || (low
== 0xFF))
612 GTP_ERROR("[update_cfg]Illegal config file.");
613 goto update_cfg_file_failed
;
615 file_config
[file_cfg_len
++] = (high
<<4) + low
;
620 GTP_ERROR("[update_cfg]Illegal config file.");
621 goto update_cfg_file_failed
;
626 GTP_DEBUG("config:");
627 GTP_DEBUG_ARRAY(file_config
+2, file_cfg_len
);
632 ret
= gup_i2c_write(client
, file_config
, file_cfg_len
);
635 GTP_INFO("[update_cfg]Send config SUCCESS.");
638 GTP_ERROR("[update_cfg]Send config i2c error.");
641 update_cfg_file_failed
:
649 #if (GTP_AUTO_UPDATE && (!GTP_HEADER_FW_UPDATE || GTP_AUTO_UPDATE_CFG))
650 static void gup_search_file(s32 search_type
)
653 struct file
*pfile
= NULL
;
655 got_file_flag
= 0x00;
658 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
660 if (0 == searching_file
)
662 GTP_INFO("Force exiting file searching");
663 got_file_flag
= 0x00;
667 if (search_type
& AUTO_SEARCH_BIN
)
669 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
);
670 pfile
= filp_open(UPDATE_FILE_PATH_1
, O_RDONLY
, 0);
673 pfile
= filp_open(UPDATE_FILE_PATH_2
, O_RDONLY
, 0);
676 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_2
);
677 got_file_flag
|= BIN_FILE_READY
;
678 update_msg
.file
= pfile
;
683 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_1
);
684 got_file_flag
|= BIN_FILE_READY
;
685 update_msg
.file
= pfile
;
687 if (got_file_flag
& BIN_FILE_READY
)
689 #if GTP_AUTO_UPDATE_CFG
690 if (search_type
& AUTO_SEARCH_CFG
)
692 i
= GUP_SEARCH_FILE_TIMES
; // Bin & Cfg File required to be in the same directory
703 #if GTP_AUTO_UPDATE_CFG
704 if ( (search_type
& AUTO_SEARCH_CFG
) && !(got_file_flag
& CFG_FILE_READY
) )
706 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
);
707 pfile
= filp_open(CONFIG_FILE_PATH_1
, O_RDONLY
, 0);
710 pfile
= filp_open(CONFIG_FILE_PATH_2
, O_RDONLY
, 0);
713 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_2
);
714 got_file_flag
|= CFG_FILE_READY
;
715 update_msg
.cfg_file
= pfile
;
720 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_1
);
721 got_file_flag
|= CFG_FILE_READY
;
722 update_msg
.cfg_file
= pfile
;
724 if (got_file_flag
& CFG_FILE_READY
)
737 static u8
gup_check_update_file(struct i2c_client
*client
, st_fw_head
*fw_head
, u8
*path
)
742 u8 buf
[FW_HEAD_LENGTH
];
744 got_file_flag
= 0x00;
747 GTP_DEBUG("Update File path:%s, %d", path
, strlen(path
));
748 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
750 if (IS_ERR(update_msg
.file
))
752 GTP_ERROR("Open update file(%s) error!", path
);
755 got_file_flag
= BIN_FILE_READY
;
760 #if GTP_HEADER_FW_UPDATE
761 GTP_INFO("Update by default firmware array");
762 update_msg
.fw_total_len
= sizeof(gtp_default_FW
) - FW_HEAD_LENGTH
;
763 if (sizeof(gtp_default_FW
) < (FW_HEAD_LENGTH
+ FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
))
765 GTP_INFO("[check_update_file]default firmware array is INVALID!");
768 GTP_DEBUG("Firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
769 memcpy(fw_head
, >p_default_FW
[0], FW_HEAD_LENGTH
);
771 //check firmware legality
773 for (i
= 0; i
< update_msg
.fw_total_len
; i
+= 2)
775 fw_checksum
+= (gtp_default_FW
[FW_HEAD_LENGTH
+ i
] << 8) + gtp_default_FW
[FW_HEAD_LENGTH
+ i
+ 1];
777 if(fw_checksum
&0xFFFF)
779 GTP_ERROR("Illegal firmware with checksum(0x%04X)", fw_checksum
& 0xFFFF);
782 got_file_flag
= HEADER_FW_READY
;
786 #if GTP_AUTO_UPDATE_CFG
787 gup_search_file(AUTO_SEARCH_BIN
| AUTO_SEARCH_CFG
);
788 if (got_file_flag
& CFG_FILE_READY
)
790 ret
= gup_update_config(client
);
793 GTP_ERROR("Update config failed!");
795 _CLOSE_FILE(update_msg
.cfg_file
);
796 msleep(500); //waiting config to be stored in FLASH.
799 gup_search_file(AUTO_SEARCH_BIN
);
802 if (!(got_file_flag
& BIN_FILE_READY
))
804 GTP_ERROR("No bin file for fw Update");
810 GTP_ERROR("NULL file for fw update!");
816 update_msg
.old_fs
= get_fs();
819 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
820 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
822 update_msg
.fw_total_len
-= FW_HEAD_LENGTH
;
824 GTP_DEBUG("Bin firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
826 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
827 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
831 GTP_ERROR("Read firmware head in update file error.");
835 memcpy(fw_head
, buf
, FW_HEAD_LENGTH
);
837 //check firmware legality
839 for(i
=0; i
< update_msg
.fw_total_len
; i
+=2)
842 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char*)buf
, 2, &update_msg
.file
->f_pos
);
845 GTP_ERROR("Read firmware file error.");
848 //GTP_DEBUG("BUF[0]:%x", buf[0]);
849 temp
= (buf
[0]<<8) + buf
[1];
853 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
854 if(fw_checksum
&0xFFFF)
856 GTP_ERROR("Illegal firmware file.");
863 set_fs(update_msg
.old_fs
);
864 _CLOSE_FILE(update_msg
.file
);
868 static u8
gup_burn_proc(struct i2c_client
*client
, u8
*burn_buf
, u16 start_addr
, u16 total_length
)
871 u16 burn_addr
= start_addr
;
872 u16 frame_length
= 0;
874 u8 wr_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
875 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
878 GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length
/ 1024), start_addr
);
880 while (burn_length
< total_length
)
882 GTP_DEBUG("B/T:%04d/%04d", burn_length
, total_length
);
883 frame_length
= ((total_length
- burn_length
) > PACK_SIZE
) ? PACK_SIZE
: (total_length
- burn_length
);
884 wr_buf
[0] = (u8
)(burn_addr
>> 8);
885 rd_buf
[0] = wr_buf
[0];
886 wr_buf
[1] = (u8
)burn_addr
;
887 rd_buf
[1] = wr_buf
[1];
888 memcpy(&wr_buf
[GTP_ADDR_LENGTH
], &burn_buf
[burn_length
], frame_length
);
890 for (retry
= 0; retry
< MAX_FRAME_CHECK_TIME
; retry
++)
892 ret
= gup_i2c_write(client
, wr_buf
, GTP_ADDR_LENGTH
+ frame_length
);
896 GTP_ERROR("Write frame data i2c error.");
900 ret
= gup_i2c_read(client
, rd_buf
, GTP_ADDR_LENGTH
+ frame_length
);
904 GTP_ERROR("Read back frame data i2c error.");
908 if (memcmp(&wr_buf
[GTP_ADDR_LENGTH
], &rd_buf
[GTP_ADDR_LENGTH
], frame_length
))
910 GTP_ERROR("Check frame data fail,not equal.");
911 GTP_DEBUG("write array:");
912 GTP_DEBUG_ARRAY(&wr_buf
[GTP_ADDR_LENGTH
], frame_length
);
913 GTP_DEBUG("read array:");
914 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
919 //GTP_DEBUG("Check frame data success.");
924 if (retry
> MAX_FRAME_CHECK_TIME
)
926 GTP_ERROR("Burn frame data time out,exit.");
930 burn_length
+= frame_length
;
931 burn_addr
+= frame_length
;
937 static u8
gup_load_section_file(u8
*buf
, u32 offset
, u16 length
, u8 set_or_end
)
939 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE)
940 if (HEADER_FW_READY
== got_file_flag
)
942 if(SEEK_SET
== set_or_end
)
944 memcpy(buf
, >p_default_FW
[FW_HEAD_LENGTH
+ offset
], length
);
948 memcpy(buf
, >p_default_FW
[update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
], length
);
956 if ( (update_msg
.file
== NULL
) || IS_ERR(update_msg
.file
))
958 GTP_ERROR("cannot find update file,load section file fail.");
962 if(SEEK_SET
== set_or_end
)
964 update_msg
.file
->f_pos
= FW_HEAD_LENGTH
+ offset
;
968 update_msg
.file
->f_pos
= update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
;
971 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, length
, &update_msg
.file
->f_pos
);
975 GTP_ERROR("Read update file fail.");
983 static u8
gup_recall_check(struct i2c_client
*client
, u8
*chk_src
, u16 start_rd_addr
, u16 chk_length
)
985 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
987 u16 recall_addr
= start_rd_addr
;
988 u16 recall_length
= 0;
989 u16 frame_length
= 0;
991 while (recall_length
< chk_length
)
993 frame_length
= ((chk_length
- recall_length
) > PACK_SIZE
) ? PACK_SIZE
: (chk_length
- recall_length
);
994 ret
= gup_get_ic_msg(client
, recall_addr
, rd_buf
, frame_length
);
998 GTP_ERROR("recall i2c error,exit");
1002 if (memcmp(&rd_buf
[GTP_ADDR_LENGTH
], &chk_src
[recall_length
], frame_length
))
1004 GTP_ERROR("Recall frame data fail,not equal.");
1005 GTP_DEBUG("chk_src array:");
1006 GTP_DEBUG_ARRAY(&chk_src
[recall_length
], frame_length
);
1007 GTP_DEBUG("recall array:");
1008 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
1012 recall_length
+= frame_length
;
1013 recall_addr
+= frame_length
;
1016 GTP_DEBUG("Recall check %dk firmware success.", (chk_length
/ 1024));
1021 static u8
gup_burn_fw_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u8 bank_cmd
)
1026 //step1:hold ss51 & dsp
1027 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1031 GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
1035 //step2:set scramble
1036 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1040 GTP_ERROR("[burn_fw_section]set scramble fail.");
1045 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1049 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1053 //step4:enable accessing code
1054 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1058 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1062 //step5:burn 8k fw section
1063 ret
= gup_burn_proc(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1067 GTP_ERROR("[burn_fw_section]burn fw_section fail.");
1071 //step6:hold ss51 & release dsp
1072 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1076 GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
1083 //step7:send burn cmd to move data to flash from sram
1084 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
& 0x0f);
1088 GTP_ERROR("[burn_fw_section]send burn cmd fail.");
1092 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1096 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1100 GTP_ERROR("[burn_fw_section]Get burn state fail");
1105 //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1107 while (rd_buf
[GTP_ADDR_LENGTH
]);
1110 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1114 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1118 //step9:enable accessing code
1119 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1123 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1127 //step10:recall 8k fw section
1128 ret
= gup_recall_check(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1132 GTP_ERROR("[burn_fw_section]recall check %dk firmware fail.", FW_SECTION_LENGTH
/1024);
1136 //step11:disable accessing code
1137 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x00);
1141 GTP_ERROR("[burn_fw_section]disable accessing code fail.");
1148 static u8
gup_burn_dsp_isp(struct i2c_client
*client
)
1151 u8
*fw_dsp_isp
= NULL
;
1155 GTP_INFO("[burn_dsp_isp]Begin burn dsp isp---->>");
1157 //step1:alloc memory
1158 GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
1162 fw_dsp_isp
= (u8
*)kzalloc(FW_DSP_ISP_LENGTH
, GFP_KERNEL
);
1164 if (fw_dsp_isp
== NULL
)
1170 GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH
/ 1024));
1177 GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
1181 //step2:load dsp isp file data
1182 GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
1183 ret
= gup_load_section_file(fw_dsp_isp
, FW_DSP_ISP_LENGTH
, FW_DSP_ISP_LENGTH
, SEEK_END
);
1187 GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
1188 goto exit_burn_dsp_isp
;
1191 //step3:disable wdt,clear cache enable
1192 GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
1193 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1197 GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
1199 goto exit_burn_dsp_isp
;
1202 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1206 GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
1208 goto exit_burn_dsp_isp
;
1211 //step4:hold ss51 & dsp
1212 GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
1213 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1217 GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
1219 goto exit_burn_dsp_isp
;
1222 //step5:set boot from sram
1223 GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
1224 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1228 GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
1230 goto exit_burn_dsp_isp
;
1233 //step6:software reboot
1234 GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
1235 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1239 GTP_ERROR("[burn_dsp_isp]software reboot fail.");
1241 goto exit_burn_dsp_isp
;
1244 //step7:select bank2
1245 GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
1246 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1250 GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
1252 goto exit_burn_dsp_isp
;
1255 //step8:enable accessing code
1256 GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
1257 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1261 GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
1263 goto exit_burn_dsp_isp
;
1266 //step9:burn 4k dsp_isp
1267 GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
1268 ret
= gup_burn_proc(client
, fw_dsp_isp
, 0xC000, FW_DSP_ISP_LENGTH
);
1272 GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
1273 goto exit_burn_dsp_isp
;
1276 //step10:set scramble
1277 GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
1278 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1282 GTP_ERROR("[burn_dsp_isp]set scramble fail.");
1284 goto exit_burn_dsp_isp
;
1287 update_msg
.fw_burned_len
+= FW_DSP_ISP_LENGTH
;
1288 GTP_DEBUG("[burn_dsp_isp]Burned length:%d", update_msg
.fw_burned_len
);
1296 static u8
gup_burn_fw_ss51(struct i2c_client
*client
)
1302 GTP_INFO("[burn_fw_ss51]Begin burn ss51 firmware---->>");
1304 //step1:alloc memory
1305 GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
1309 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1311 if (fw_ss51
== NULL
)
1317 GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1324 GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
1328 //step2:load ss51 firmware section 1 file data
1329 //GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
1330 //ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH, SEEK_SET);
1334 // GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
1335 // goto exit_burn_fw_ss51;
1337 GTP_INFO("[burn_fw_ss51]Reset first 8K of ss51 to 0xFF.");
1338 GTP_DEBUG("[burn_fw_ss51]step2: reset bank0 0xC000~0xD000");
1339 memset(fw_ss51
, 0xFF, FW_SECTION_LENGTH
);
1341 //step3:clear control flag
1342 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
1343 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1347 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
1349 goto exit_burn_fw_ss51
;
1352 //step4:burn ss51 firmware section 1
1353 GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
1354 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
1358 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
1359 goto exit_burn_fw_ss51
;
1362 //step5:load ss51 firmware section 2 file data
1363 GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
1364 ret
= gup_load_section_file(fw_ss51
, FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1368 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
1369 goto exit_burn_fw_ss51
;
1372 //step6:burn ss51 firmware section 2
1373 GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
1374 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x02);
1378 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
1379 goto exit_burn_fw_ss51
;
1382 //step7:load ss51 firmware section 3 file data
1383 GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
1384 ret
= gup_load_section_file(fw_ss51
, 2 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1388 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
1389 goto exit_burn_fw_ss51
;
1392 //step8:burn ss51 firmware section 3
1393 GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
1394 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x13);
1398 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
1399 goto exit_burn_fw_ss51
;
1402 //step9:load ss51 firmware section 4 file data
1403 GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
1404 ret
= gup_load_section_file(fw_ss51
, 3 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1408 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
1409 goto exit_burn_fw_ss51
;
1412 //step10:burn ss51 firmware section 4
1413 GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
1414 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x14);
1418 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
1419 goto exit_burn_fw_ss51
;
1422 update_msg
.fw_burned_len
+= (FW_SECTION_LENGTH
*4);
1423 GTP_DEBUG("[burn_fw_ss51]Burned length:%d", update_msg
.fw_burned_len
);
1431 static u8
gup_burn_fw_dsp(struct i2c_client
*client
)
1438 GTP_INFO("[burn_fw_dsp]Begin burn dsp firmware---->>");
1439 //step1:alloc memory
1440 GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
1444 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1452 GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1459 GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
1463 //step2:load firmware dsp
1464 GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
1465 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
, SEEK_SET
);
1469 GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
1470 goto exit_burn_fw_dsp
;
1473 //step3:select bank3
1474 GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
1475 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1479 GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
1481 goto exit_burn_fw_dsp
;
1484 //step4:hold ss51 & dsp
1485 GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
1486 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1490 GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
1492 goto exit_burn_fw_dsp
;
1495 //step5:set scramble
1496 GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
1497 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1501 GTP_ERROR("[burn_fw_dsp]set scramble fail.");
1503 goto exit_burn_fw_dsp
;
1506 //step6:release ss51 & dsp
1507 GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
1508 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121212
1512 GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
1514 goto exit_burn_fw_dsp
;
1520 //step7:burn 4k dsp firmware
1521 GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
1522 ret
= gup_burn_proc(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1526 GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
1527 goto exit_burn_fw_dsp
;
1530 //step8:send burn cmd to move data to flash from sram
1531 GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
1532 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x05);
1536 GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
1537 goto exit_burn_fw_dsp
;
1540 GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
1544 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1548 GTP_ERROR("[burn_fw_dsp]Get burn state fail");
1549 goto exit_burn_fw_dsp
;
1553 //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1555 while (rd_buf
[GTP_ADDR_LENGTH
]);
1557 //step9:recall check 4k dsp firmware
1558 GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
1559 ret
= gup_recall_check(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1563 GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
1564 goto exit_burn_fw_dsp
;
1567 update_msg
.fw_burned_len
+= FW_DSP_LENGTH
;
1568 GTP_DEBUG("[burn_fw_dsp]Burned length:%d", update_msg
.fw_burned_len
);
1576 static u8
gup_burn_fw_boot(struct i2c_client
*client
)
1583 GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>");
1585 //step1:Alloc memory
1586 GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
1590 fw_boot
= (u8
*)kzalloc(FW_BOOT_LENGTH
, GFP_KERNEL
);
1598 GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH
/1024));
1605 GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
1609 //step2:load firmware bootloader
1610 GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
1611 ret
= gup_load_section_file(fw_boot
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
), FW_BOOT_LENGTH
, SEEK_SET
);
1615 GTP_ERROR("[burn_fw_boot]load firmware bootcode fail.");
1616 goto exit_burn_fw_boot
;
1619 //step3:hold ss51 & dsp
1620 GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
1621 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1624 GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
1626 goto exit_burn_fw_boot
;
1629 //step4:set scramble
1630 GTP_DEBUG("[burn_fw_boot]step4:set scramble");
1631 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1634 GTP_ERROR("[burn_fw_boot]set scramble fail.");
1636 goto exit_burn_fw_boot
;
1639 //step5:hold ss51 & release dsp
1640 GTP_DEBUG("[burn_fw_boot]step5:hold ss51 & release dsp");
1641 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1644 GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
1646 goto exit_burn_fw_boot
;
1651 //step6:select bank3
1652 GTP_DEBUG("[burn_fw_boot]step6:select bank3");
1653 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1656 GTP_ERROR("[burn_fw_boot]select bank3 fail.");
1658 goto exit_burn_fw_boot
;
1661 //step7:burn 2k bootloader firmware
1662 GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware");
1663 ret
= gup_burn_proc(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1666 GTP_ERROR("[burn_fw_boot]burn fw_boot fail.");
1667 goto exit_burn_fw_boot
;
1670 //step7:send burn cmd to move data to flash from sram
1671 GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
1672 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x06);
1675 GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
1676 goto exit_burn_fw_boot
;
1678 GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
1680 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1683 GTP_ERROR("[burn_fw_boot]Get burn state fail");
1684 goto exit_burn_fw_boot
;
1687 //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1688 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1690 //step8:recall check 2k bootloader firmware
1691 GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
1692 ret
= gup_recall_check(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1695 GTP_ERROR("[burn_fw_boot]recall check 2k bootcode firmware fail.");
1696 goto exit_burn_fw_boot
;
1699 update_msg
.fw_burned_len
+= FW_BOOT_LENGTH
;
1700 GTP_DEBUG("[burn_fw_boot]Burned length:%d", update_msg
.fw_burned_len
);
1708 static u8
gup_burn_fw_boot_isp(struct i2c_client
*client
)
1711 u8
* fw_boot_isp
= NULL
;
1715 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1717 GTP_INFO("No need to upgrade the boot_isp code!");
1720 GTP_DEBUG("[burn_fw_boot_isp]Begin burn bootloader firmware---->>");
1722 //step1:Alloc memory
1723 GTP_DEBUG("[burn_fw_boot_isp]step1:Alloc memory");
1726 fw_boot_isp
= (u8
*)kzalloc(FW_BOOT_ISP_LENGTH
, GFP_KERNEL
);
1727 if(fw_boot_isp
== NULL
)
1733 GTP_INFO("[burn_fw_boot_isp]Alloc %dk byte memory success.", (FW_BOOT_ISP_LENGTH
/1024));
1739 GTP_ERROR("[burn_fw_boot_isp]Alloc memory fail,exit.");
1743 //step2:load firmware bootloader
1744 GTP_DEBUG("[burn_fw_boot_isp]step2:load firmware bootloader isp");
1745 //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);
1746 ret
= gup_load_section_file(fw_boot_isp
, (update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
), FW_BOOT_ISP_LENGTH
, SEEK_SET
);
1749 GTP_ERROR("[burn_fw_boot_isp]load firmware boot_isp fail.");
1750 goto exit_burn_fw_boot_isp
;
1753 //step3:hold ss51 & dsp
1754 GTP_DEBUG("[burn_fw_boot_isp]step3:hold ss51 & dsp");
1755 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1758 GTP_ERROR("[burn_fw_boot_isp]hold ss51 & dsp fail.");
1760 goto exit_burn_fw_boot_isp
;
1763 //step4:set scramble
1764 GTP_DEBUG("[burn_fw_boot_isp]step4:set scramble");
1765 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1768 GTP_ERROR("[burn_fw_boot_isp]set scramble fail.");
1770 goto exit_burn_fw_boot_isp
;
1774 //step5:hold ss51 & release dsp
1775 GTP_DEBUG("[burn_fw_boot_isp]step5:hold ss51 & release dsp");
1776 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1779 GTP_ERROR("[burn_fw_boot_isp]release ss51 & dsp fail.");
1781 goto exit_burn_fw_boot_isp
;
1786 //step6:select bank3
1787 GTP_DEBUG("[burn_fw_boot_isp]step6:select bank3");
1788 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1791 GTP_ERROR("[burn_fw_boot_isp]select bank3 fail.");
1793 goto exit_burn_fw_boot_isp
;
1796 //step7:burn 2k bootload_isp firmware
1797 GTP_DEBUG("[burn_fw_boot_isp]step7:burn 2k bootloader firmware");
1798 ret
= gup_burn_proc(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1801 GTP_ERROR("[burn_fw_boot_isp]burn fw_section fail.");
1802 goto exit_burn_fw_boot_isp
;
1805 //step7:send burn cmd to move data to flash from sram
1806 GTP_DEBUG("[burn_fw_boot_isp]step7:send burn cmd to move data to flash from sram");
1807 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x07);
1810 GTP_ERROR("[burn_fw_boot_isp]send burn cmd fail.");
1811 goto exit_burn_fw_boot_isp
;
1813 GTP_DEBUG("[burn_fw_boot_isp]Wait for the burn is complete......");
1815 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1818 GTP_ERROR("[burn_fw_boot_isp]Get burn state fail");
1819 goto exit_burn_fw_boot_isp
;
1822 //GTP_DEBUG("[burn_fw_boot_isp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1823 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1825 //step8:recall check 2k bootload_isp firmware
1826 GTP_DEBUG("[burn_fw_boot_isp]step8:recall check 2k bootloader firmware");
1827 ret
= gup_recall_check(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1830 GTP_ERROR("[burn_fw_boot_isp]recall check 2k bootcode_isp firmware fail.");
1831 goto exit_burn_fw_boot_isp
;
1834 update_msg
.fw_burned_len
+= FW_BOOT_ISP_LENGTH
;
1835 GTP_DEBUG("[burn_fw_boot_isp]Burned length:%d", update_msg
.fw_burned_len
);
1838 exit_burn_fw_boot_isp
:
1843 static u8
gup_burn_fw_link(struct i2c_client
*client
)
1850 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1852 GTP_INFO("No need to upgrade the link code!");
1855 GTP_DEBUG("[burn_fw_link]Begin burn link firmware---->>");
1857 //step1:Alloc memory
1858 GTP_DEBUG("[burn_fw_link]step1:Alloc memory");
1861 fw_link
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1868 GTP_INFO("[burn_fw_link]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
1874 GTP_ERROR("[burn_fw_link]Alloc memory fail,exit.");
1878 //step2:load firmware link section 1
1879 GTP_DEBUG("[burn_fw_link]step2:load firmware link section 1");
1880 offset
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
1881 ret
= gup_load_section_file(fw_link
, offset
, FW_SECTION_LENGTH
, SEEK_SET
);
1884 GTP_ERROR("[burn_fw_link]load firmware link section 1 fail.");
1885 goto exit_burn_fw_link
;
1889 //step3:burn link firmware section 1
1890 GTP_DEBUG("[burn_fw_link]step3:burn link firmware section 1");
1891 ret
= gup_burn_fw_app_section(client
, fw_link
, 0x9000, FW_SECTION_LENGTH
, 0x38);
1895 GTP_ERROR("[burn_fw_link]burn link firmware section 1 fail.");
1896 goto exit_burn_fw_link
;
1899 //step4:load link firmware section 2 file data
1900 GTP_DEBUG("[burn_fw_link]step4:load link firmware section 2 file data");
1901 offset
+= FW_SECTION_LENGTH
;
1902 ret
= gup_load_section_file(fw_link
, offset
, FW_LINK_LENGTH
- FW_SECTION_LENGTH
, SEEK_SET
);
1906 GTP_ERROR("[burn_fw_link]load link firmware section 2 fail.");
1907 goto exit_burn_fw_link
;
1910 //step5:burn link firmware section 2
1911 GTP_DEBUG("[burn_fw_link]step4:burn link firmware section 2");
1912 ret
= gup_burn_fw_app_section(client
, fw_link
, 0x9000, FW_LINK_LENGTH
- FW_SECTION_LENGTH
, 0x39);
1916 GTP_ERROR("[burn_fw_link]burn link firmware section 2 fail.");
1917 goto exit_burn_fw_link
;
1920 update_msg
.fw_burned_len
+= FW_LINK_LENGTH
;
1921 GTP_DEBUG("[burn_fw_link]Burned length:%d", update_msg
.fw_burned_len
);
1929 static u8
gup_burn_fw_app_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
)
1934 //step1:hold ss51 & dsp
1935 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1938 GTP_ERROR("[burn_fw_app_section]hold ss51 & dsp fail.");
1942 //step2:set scramble
1943 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1946 GTP_ERROR("[burn_fw_app_section]set scramble fail.");
1950 //step3:hold ss51 & release dsp
1951 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1954 GTP_ERROR("[burn_fw_app_section]hold ss51 & release dsp fail.");
1961 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4)&0x0F);
1964 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4)&0x0F);
1968 //step5:burn fw section
1969 ret
= gup_burn_proc(client
, fw_section
, start_addr
, len
);
1972 GTP_ERROR("[burn_fw_app_section]burn fw_section fail.");
1976 //step6:send burn cmd to move data to flash from sram
1977 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
&0x0F);
1980 GTP_ERROR("[burn_fw_app_section]send burn cmd fail.");
1983 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1985 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1988 GTP_ERROR("[burn_fw_app_section]Get burn state fail");
1992 //GTP_DEBUG("[burn_fw_app_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1993 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1995 //step7:recall fw section
1996 ret
= gup_recall_check(client
, fw_section
, start_addr
, len
);
1999 GTP_ERROR("[burn_fw_app_section]recall check %dk firmware fail.", len
/1024);
2006 static u8
gup_burn_fw_app_code(struct i2c_client
*client
)
2008 u8
* fw_app_code
= NULL
;
2011 //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
2014 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
2016 GTP_INFO("No need to upgrade the app code!");
2019 start_index
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
2020 GTP_DEBUG("[burn_fw_app_code]Begin burn app_code firmware---->>");
2022 //step1:alloc memory
2023 GTP_DEBUG("[burn_fw_app_code]step1:alloc memory");
2026 fw_app_code
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2027 if(fw_app_code
== NULL
)
2033 GTP_INFO("[burn_fw_app_code]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2039 GTP_ERROR("[burn_fw_app_code]Alloc memory fail,exit.");
2043 //step2:load app_code firmware section 1 file data
2044 GTP_DEBUG("[burn_fw_app_code]step2:load app_code firmware section 1 file data");
2045 ret
= gup_load_section_file(fw_app_code
, start_index
, FW_SECTION_LENGTH
, SEEK_SET
);
2048 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 1 fail.");
2049 goto exit_burn_fw_app_code
;
2052 //step3:burn app_code firmware section 1
2053 GTP_DEBUG("[burn_fw_app_code]step3:burn app_code firmware section 1");
2054 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3A);
2057 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 1 fail.");
2058 goto exit_burn_fw_app_code
;
2061 //step5:load app_code firmware section 2 file data
2062 GTP_DEBUG("[burn_fw_app_code]step5:load app_code firmware section 2 file data");
2063 ret
= gup_load_section_file(fw_app_code
, start_index
+FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2066 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 2 fail.");
2067 goto exit_burn_fw_app_code
;
2070 //step6:burn app_code firmware section 2
2071 GTP_DEBUG("[burn_fw_app_code]step6:burn app_code firmware section 2");
2072 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3B);
2075 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 2 fail.");
2076 goto exit_burn_fw_app_code
;
2079 //step7:load app_code firmware section 3 file data
2080 GTP_DEBUG("[burn_fw_app_code]step7:load app_code firmware section 3 file data");
2081 ret
= gup_load_section_file(fw_app_code
, start_index
+2*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2084 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 3 fail.");
2085 goto exit_burn_fw_app_code
;
2088 //step8:burn app_code firmware section 3
2089 GTP_DEBUG("[burn_fw_app_code]step8:burn app_code firmware section 3");
2090 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3C);
2093 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 3 fail.");
2094 goto exit_burn_fw_app_code
;
2097 //step9:load app_code firmware section 4 file data
2098 GTP_DEBUG("[burn_fw_app_code]step9:load app_code firmware section 4 file data");
2099 ret
= gup_load_section_file(fw_app_code
, start_index
+ 3*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2102 GTP_ERROR("[burn_fw_app_code]load app_code firmware section 4 fail.");
2103 goto exit_burn_fw_app_code
;
2106 //step10:burn app_code firmware section 4
2107 GTP_DEBUG("[burn_fw_app_code]step10:burn app_code firmware section 4");
2108 ret
= gup_burn_fw_app_section(client
, fw_app_code
, 0x9000, FW_SECTION_LENGTH
, 0x3D);
2111 GTP_ERROR("[burn_fw_app_code]burn app_code firmware section 4 fail.");
2112 goto exit_burn_fw_app_code
;
2115 update_msg
.fw_burned_len
+= FW_APP_CODE_LENGTH
;
2116 GTP_DEBUG("[burn_fw_gwake]Burned length:%d", update_msg
.fw_burned_len
);
2119 exit_burn_fw_app_code
:
2124 static u8
gup_burn_fw_finish(struct i2c_client
*client
)
2130 GTP_INFO("[burn_fw_finish]burn first 8K of ss51 and finish update.");
2131 //step1:alloc memory
2132 GTP_DEBUG("[burn_fw_finish]step1:alloc memory");
2135 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2142 GTP_DEBUG("[burn_fw_finish]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2148 GTP_ERROR("[burn_fw_finish]Alloc memory fail,exit.");
2152 GTP_DEBUG("[burn_fw_finish]step2: burn ss51 first 8K.");
2153 ret
= gup_load_section_file(fw_ss51
, 0, FW_SECTION_LENGTH
, SEEK_SET
);
2156 GTP_ERROR("[burn_fw_finish]load ss51 firmware section 1 fail.");
2157 goto exit_burn_fw_finish
;
2160 GTP_DEBUG("[burn_fw_finish]step3:clear control flag");
2161 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2164 GTP_ERROR("[burn_fw_finish]clear control flag fail.");
2165 goto exit_burn_fw_finish
;
2168 GTP_DEBUG("[burn_fw_finish]step4:burn ss51 firmware section 1");
2169 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
2172 GTP_ERROR("[burn_fw_finish]burn ss51 firmware section 1 fail.");
2173 goto exit_burn_fw_finish
;
2176 //step11:enable download DSP code
2177 GTP_DEBUG("[burn_fw_finish]step5:enable download DSP code ");
2178 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x99);
2181 GTP_ERROR("[burn_fw_finish]enable download DSP code fail.");
2182 goto exit_burn_fw_finish
;
2185 //step12:release ss51 & hold dsp
2186 GTP_DEBUG("[burn_fw_finish]step6:release ss51 & hold dsp");
2187 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x08);
2190 GTP_ERROR("[burn_fw_finish]release ss51 & hold dsp fail.");
2191 goto exit_burn_fw_finish
;
2200 exit_burn_fw_finish
:
2208 s32
gup_update_proc(void *dir
)
2212 s32 update_ret
= FAIL
;
2215 GTP_INFO("[update_proc]Begin update ......");
2218 if (1 == searching_file
)
2221 searching_file
= 0; // exit .bin update file searching
2222 GTP_INFO("Exiting searching file for auto update.");
2223 while ((show_len
!= 200) && (show_len
!= 100) && (timeout
++ < 150)) // wait for auto update quitted completely
2233 #if GTP_COMPATIBLE_MODE
2234 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2236 return gup_fw_download_proc(dir
, GTP_FL_FW_BURN
);
2239 update_msg
.file
= NULL
;
2240 ret
= gup_check_update_file(i2c_client_point
, &fw_head
, (u8
*)dir
); //20121212
2244 GTP_ERROR("[update_proc]check update file fail.");
2248 //gtp_reset_guitar(i2c_client_point, 20);
2249 ret
= gup_get_ic_fw_msg(i2c_client_point
);
2253 GTP_ERROR("[update_proc]get ic message fail.");
2257 ret
= gup_enter_update_judge(&fw_head
); //20121212
2261 GTP_ERROR("[update_proc]Check *.bin file fail.");
2265 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
2267 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
2269 ret
= gup_enter_update_mode(i2c_client_point
);
2273 GTP_ERROR("[update_proc]enter update mode fail.");
2281 update_msg
.fw_burned_len
= 0;
2282 GTP_DEBUG("[update_proc]Burned length:%d", update_msg
.fw_burned_len
);
2283 ret
= gup_burn_dsp_isp(i2c_client_point
);
2286 GTP_ERROR("[update_proc]burn dsp isp fail.");
2291 ret
= gup_burn_fw_ss51(i2c_client_point
);
2294 GTP_ERROR("[update_proc]burn ss51 firmware fail.");
2299 ret
= gup_burn_fw_dsp(i2c_client_point
);
2302 GTP_ERROR("[update_proc]burn dsp firmware fail.");
2307 ret
= gup_burn_fw_boot(i2c_client_point
);
2310 GTP_ERROR("[update_proc]burn bootloader firmware fail.");
2315 ret
= gup_burn_fw_boot_isp(i2c_client_point
);
2318 GTP_ERROR("[update_proc]burn boot_isp firmware fail.");
2323 ret
= gup_burn_fw_link(i2c_client_point
);
2326 GTP_ERROR("[update_proc]burn link firmware fail.");
2331 ret
= gup_burn_fw_app_code(i2c_client_point
);
2334 GTP_ERROR("[update_proc]burn app_code firmware fail.");
2338 ret
= gup_burn_fw_finish(i2c_client_point
);
2341 GTP_ERROR("[update_proc]burn finish fail.");
2345 GTP_INFO("[update_proc]UPDATE SUCCESS.");
2351 GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
2356 update_ret
= SUCCESS
;
2360 GTP_DEBUG("[update_proc]leave update mode.");
2361 gup_leave_update_mode();
2363 if (SUCCESS
== update_ret
)
2365 GTP_DEBUG("[update_proc]send config.");
2366 ret
= gtp_send_cfg(i2c_client_point
);
2369 GTP_ERROR("[update_proc]send config fail.");
2374 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
2378 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2380 if (update_msg
.file
&& !IS_ERR(update_msg
.file
))
2382 if (update_msg
.old_fs
)
2384 set_fs(update_msg
.old_fs
);
2386 filp_close(update_msg
.file
, NULL
);
2388 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE && GTP_AUTO_UPDATE_CFG)
2391 gup_search_file(AUTO_SEARCH_CFG
);
2392 if (got_file_flag
& CFG_FILE_READY
)
2394 ret
= gup_update_config(i2c_client_point
);
2397 GTP_ERROR("Update config failed!");
2404 if (SUCCESS
== update_ret
)
2416 u8
gup_init_update_proc(struct i2c_client
*client
)
2418 struct task_struct
*thread
= NULL
;
2420 GTP_INFO("Ready to run auto update thread");
2422 #if GTP_COMPATIBLE_MODE
2423 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2425 thread
= kthread_run(gup_update_proc
, "update", "fl_auto_update");
2430 thread
= kthread_run(gup_update_proc
, (void *)NULL
, "guitar_update");
2434 GTP_ERROR("Failed to create update thread.\n");
2442 //******************* For GT9XXF Start ********************//
2444 #define FL_UPDATE_PATH "/data/_fl_update_.bin"
2445 #define FL_UPDATE_PATH_SD "/sdcard/_fl_update_.bin"
2447 #define GUP_FW_CHK_SIZE 256
2448 #define MAX_CHECK_TIMES 128 // max: 2 * (16 * 1024) / 256 = 128
2451 #define PULSE_LENGTH (200)
2452 #define INIT_CLK_DAC (50)
2453 #define MAX_CLK_DAC (120)
2454 #define CLK_AVG_TIME (1)
2455 #define MILLION 1000000
2457 #define _wRW_MISCTL__RG_DMY 0x4282
2458 #define _bRW_MISCTL__RG_OSC_CALIB 0x4268
2459 #define _fRW_MISCTL__GIO0 0x41e9
2460 #define _fRW_MISCTL__GIO1 0x41ed
2461 #define _fRW_MISCTL__GIO2 0x41f1
2462 #define _fRW_MISCTL__GIO3 0x41f5
2463 #define _fRW_MISCTL__GIO4 0x41f9
2464 #define _fRW_MISCTL__GIO5 0x41fd
2465 #define _fRW_MISCTL__GIO6 0x4201
2466 #define _fRW_MISCTL__GIO7 0x4205
2467 #define _fRW_MISCTL__GIO8 0x4209
2468 #define _fRW_MISCTL__GIO9 0x420d
2469 #define _fRW_MISCTL__MEA 0x41a0
2470 #define _bRW_MISCTL__MEA_MODE 0x41a1
2471 #define _wRW_MISCTL__MEA_MAX_NUM 0x41a4
2472 #define _dRO_MISCTL__MEA_VAL 0x41b0
2473 #define _bRW_MISCTL__MEA_SRCSEL 0x41a3
2474 #define _bRO_MISCTL__MEA_RDY 0x41a8
2475 #define _rRW_MISCTL__ANA_RXADC_B0_ 0x4250
2476 #define _bRW_MISCTL__RG_LDO_A18_PWD 0x426f
2477 #define _bRW_MISCTL__RG_BG_PWD 0x426a
2478 #define _bRW_MISCTL__RG_CLKGEN_PWD 0x4269
2479 #define _fRW_MISCTL__RG_RXADC_PWD 0x426a
2480 #define _bRW_MISCTL__OSC_CK_SEL 0x4030
2481 #define _rRW_MISCTL_RG_DMY83 0x4283
2482 #define _rRW_MISCTL__GIO1CTL_B2_ 0x41ee
2483 #define _rRW_MISCTL__GIO1CTL_B1_ 0x41ed
2485 #if GTP_COMPATIBLE_MODE
2487 u8
gup_check_fs_mounted(char *path_name
)
2489 struct path root_path
;
2492 err
= kern_path("/", LOOKUP_FOLLOW
, &root_path
);
2497 err
= kern_path(path_name
, LOOKUP_FOLLOW
, &path
);
2502 if (path
.mnt
->mnt_sb
== root_path
.mnt
->mnt_sb
)
2513 s32
gup_hold_ss51_dsp(struct i2c_client
*client
)
2519 while(retry
++ < 200)
2521 // step4:Hold ss51 & dsp
2522 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
2525 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2529 // step5:Confirm hold
2530 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
2533 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2536 if (0x0C == rd_buf
[GTP_ADDR_LENGTH
])
2538 GTP_DEBUG("[enter_update_mode]Hold ss51 & dsp confirm SUCCESS");
2541 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
2545 GTP_ERROR("Enter update Hold ss51 failed.");
2548 //DSP_CK and DSP_ALU_CK PowerOn
2549 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
2552 GTP_ERROR("[enter_update_mode]DSP_CK and DSP_ALU_CK PowerOn fail.");
2557 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
2561 GTP_ERROR("[enter_update_mode]disable wdt fail.");
2565 //clear cache enable
2566 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
2570 GTP_ERROR("[enter_update_mode]clear cache enable fail.");
2574 //set boot from sram
2575 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
2579 GTP_ERROR("[enter_update_mode]set boot from sram fail.");
2584 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
2587 GTP_ERROR("[enter_update_mode]software reboot fail.");
2594 s32
gup_enter_update_mode_fl(struct i2c_client
*client
)
2600 //step1:RST output low last at least 2ms
2601 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
2604 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
2605 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
2608 //step3:RST output high reset guitar
2609 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
2613 //select addr & hold ss51_dsp
2614 ret
= gup_hold_ss51_dsp(client
);
2617 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
2621 //clear control flag
2622 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2626 GTP_ERROR("[enter_update_mode]clear control flag fail.");
2631 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
2635 GTP_ERROR("[enter_update_mode]set scramble fail.");
2639 //enable accessing code
2640 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
2644 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
2652 static s32
gup_prepare_fl_fw(char *path
, st_fw_head
*fw_head
)
2658 if (!memcmp(path
, "update", 6))
2660 GTP_INFO("Search for Flashless firmware file to update");
2662 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
2664 if (0 == searching_file
)
2666 GTP_INFO("Force terminate searching file auto update.");
2669 update_msg
.file
= filp_open(FL_UPDATE_PATH
, O_RDONLY
, 0);
2670 if (IS_ERR(update_msg
.file
))
2672 update_msg
.file
= filp_open(FL_UPDATE_PATH_SD
, O_RDONLY
, 0);
2673 if (IS_ERR(update_msg
.file
))
2680 path
= FL_UPDATE_PATH_SD
;
2686 path
= FL_UPDATE_PATH
;
2693 GTP_ERROR("Search timeout, update aborted");
2698 _CLOSE_FILE(update_msg
.file
);
2700 while (rqst_processing
&& (timeout
++ < 15))
2702 GTP_INFO("wait for request process completed!");
2707 GTP_INFO("Firmware update file path: %s", path
);
2708 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
2710 if (IS_ERR(update_msg
.file
))
2712 GTP_ERROR("Open update file(%s) error!", path
);
2716 update_msg
.old_fs
= get_fs();
2718 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2719 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
2720 if (sizeof(gtp_default_FW_fl
) != update_msg
.fw_total_len
)
2722 GTP_ERROR("Inconsistent firmware size. File size: %d, default fw size: %d", update_msg
.fw_total_len
, sizeof(gtp_default_FW_fl
));
2723 set_fs(update_msg
.old_fs
);
2724 _CLOSE_FILE(update_msg
.file
);
2728 GTP_DEBUG("Firmware size: %d", update_msg
.fw_total_len
);
2729 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2730 update_msg
.file
->f_op
->read(update_msg
.file
, (char*)fw_head
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
2731 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2732 //copy fw file to gtp_default_FW_fl array
2733 ret
= update_msg
.file
->f_op
->read(update_msg
.file
,
2734 (char*)gtp_default_FW_fl
,
2735 update_msg
.fw_total_len
,
2736 &update_msg
.file
->f_pos
);
2739 GTP_ERROR("Failed to read firmware data from %s, err-code: %d", path
, ret
);
2746 set_fs(update_msg
.old_fs
);
2747 _CLOSE_FILE(update_msg
.file
);
2751 static u8
gup_check_update_file_fl(struct i2c_client
*client
, st_fw_head
*fw_head
, char *path
)
2754 s32 fw_checksum
= 0;
2759 ret
= gup_prepare_fl_fw(path
, fw_head
);
2767 memcpy(fw_head
, gtp_default_FW_fl
, FW_HEAD_LENGTH
);
2768 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]);
2769 GTP_INFO("FILE PID:%s", fw_head
->pid
);
2770 fw_head
->vid
= ((fw_head
->vid
& 0xFF00) >> 8) + ((fw_head
->vid
& 0x00FF) << 8);
2771 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
2774 //check firmware legality
2776 for (i
= FW_HEAD_LENGTH
; i
< (FW_HEAD_LENGTH
+ update_msg
.fw_total_len
); i
+= 2)
2778 fw_checksum
= (gtp_default_FW_fl
[i
]<<8) + gtp_default_FW_fl
[i
+1];
2781 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
2782 if(fw_checksum
&0xFFFF)
2784 GTP_ERROR("Illegal firmware file.");
2791 static u8
gup_download_fw_ss51(struct i2c_client
*client
, u8 dwn_mode
)
2795 if(GTP_FL_FW_BURN
== dwn_mode
)
2797 GTP_INFO("[download_fw_ss51]Begin download ss51 firmware---->>");
2801 GTP_INFO("[download_fw_ss51]Begin check ss51 firmware----->>");
2803 //step1:download FW section 1
2804 GTP_DEBUG("[download_fw_ss51]step1:download FW section 1");
2805 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x00);
2809 GTP_ERROR("[download_fw_ss51]select bank0 fail.");
2811 goto exit_download_fw_ss51
;
2815 ret
= i2c_write_bytes(client
, 0xC000,
2816 >p_default_FW_fl
[FW_HEAD_LENGTH
], FW_DOWNLOAD_LENGTH
); // write the first bank
2820 GTP_ERROR("[download_fw_ss51]download FW section 1 fail.");
2822 goto exit_download_fw_ss51
;
2826 if (GTP_FL_FW_BURN
== dwn_mode
)
2828 ret
= gup_check_and_repair(i2c_client_point
,
2830 >p_default_FW_fl
[FW_HEAD_LENGTH
],
2831 FW_DOWNLOAD_LENGTH
);
2834 GTP_ERROR("[download_fw_ss51]Checked FW section 1 fail.");
2835 goto exit_download_fw_ss51
;
2839 //step2:download FW section 2
2840 GTP_DEBUG("[download_fw_ss51]step2:download FW section 1");
2841 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x01);
2845 GTP_ERROR("[download_fw_ss51]select bank1 fail.");
2847 goto exit_download_fw_ss51
;
2850 ret
= i2c_write_bytes(client
, 0xC000, >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],FW_DOWNLOAD_LENGTH
); // write the second bank
2854 GTP_ERROR("[download_fw_ss51]download FW section 2 fail.");
2856 goto exit_download_fw_ss51
;
2859 if (GTP_FL_FW_BURN
== dwn_mode
)
2861 ret
= gup_check_and_repair(i2c_client_point
,
2863 >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],
2864 FW_DOWNLOAD_LENGTH
);
2868 GTP_ERROR("[download_fw_ss51]Checked FW section 2 fail.");
2869 goto exit_download_fw_ss51
;
2874 exit_download_fw_ss51
:
2878 #if (!GTP_SUPPORT_I2C_DMA)
2879 static s32
i2c_auto_read(struct i2c_client
*client
,u8
*rxbuf
, int len
)
2885 struct i2c_msg msg
=
2887 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
2888 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
2890 .timing
= I2C_MASTER_CLOCK
2900 msg
.buf
= &rxbuf
[offset
];
2902 if (left
> MAX_TRANSACTION_LENGTH
)
2904 msg
.len
= MAX_TRANSACTION_LENGTH
;
2905 left
-= MAX_TRANSACTION_LENGTH
;
2906 offset
+= MAX_TRANSACTION_LENGTH
;
2916 while (i2c_transfer(client
->adapter
, &msg
, 1) != 1)
2922 GTP_ERROR("I2C read 0x%X length=%d failed\n", offset
, len
);
2931 static u8
gup_check_and_repair(struct i2c_client
*client
, s32 chk_start_addr
, u8
*target_fw
, u32 chk_total_length
)
2937 u8 chk_buf
[GUP_FW_CHK_SIZE
];
2942 chk_addr
= chk_start_addr
;
2943 while((chked_times
< MAX_CHECK_TIMES
) && (chked_len
< chk_total_length
))
2945 rd_size
= chk_total_length
- chked_len
;
2946 if(rd_size
>= GUP_FW_CHK_SIZE
)
2948 rd_size
= GUP_FW_CHK_SIZE
;
2950 #if GTP_SUPPORT_I2C_DMA
2951 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
2955 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
2959 ret
= i2c_auto_read(client
, chk_buf
, rd_size
);
2965 GTP_ERROR("Read chk ram fw i2c error");
2970 for(i
=0; i
<rd_size
; i
++)
2972 if(chk_buf
[i
] != target_fw
[i
])
2974 GTP_ERROR("Ram pos[0x%04x] checked failed,rewrite.", chk_addr
+ i
);
2975 i2c_write_bytes(client
, chk_addr
+i
, &target_fw
[i
], rd_size
-i
);
2984 GTP_DEBUG("Ram pos[0x%04X] check pass!", chk_addr
);
2985 chked_len
+= rd_size
;
2986 target_fw
+= rd_size
;
2987 chk_addr
+= rd_size
;
2996 if(chked_times
>= MAX_CHECK_TIMES
)
2998 GTP_ERROR("Ram data check failed.");
3004 static u8
gup_download_fw_dsp(struct i2c_client
*client
, u8 dwn_mode
)
3008 if(GTP_FL_FW_BURN
== dwn_mode
)
3010 GTP_INFO("[download_fw_dsp]Begin download dsp fw---->>");
3014 GTP_INFO("[download_fw_dsp]Begin check dsp fw---->>");
3017 //step1:select bank2
3018 GTP_DEBUG("[download_fw_dsp]step1:select bank2");
3019 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
3023 GTP_ERROR("[download_fw_dsp]select bank2 fail.");
3025 goto exit_download_fw_dsp
;
3028 ret
= i2c_write_bytes(client
,
3030 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3031 FW_DSP_LENGTH
); // write the second bank
3034 GTP_ERROR("[download_fw_dsp]download FW dsp fail.");
3036 goto exit_download_fw_dsp
;
3039 if (GTP_FL_FW_BURN
== dwn_mode
)
3041 ret
= gup_check_and_repair(client
,
3043 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3048 GTP_ERROR("[download_fw_dsp]Checked FW dsp fail.");
3049 goto exit_download_fw_dsp
;
3055 exit_download_fw_dsp
:
3060 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
)
3066 if(GTP_FL_FW_BURN
== dwn_mode
)
3068 GTP_INFO("[fw_download_proc]Begin fw download ......");
3072 GTP_INFO("[fw_download_proc]Begin fw check ......");
3077 ret
= gup_check_update_file_fl(i2c_client_point
, &fw_head
, (char *)dir
);
3083 GTP_ERROR("[fw_download_proc]check update file fail.");
3087 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3091 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3095 ret
= gup_enter_update_mode_fl(i2c_client_point
);
3100 GTP_ERROR("[fw_download_proc]enter update mode fail.");
3106 ret
= gup_download_fw_ss51(i2c_client_point
, dwn_mode
);
3110 GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
3114 ret
= gup_download_fw_dsp(i2c_client_point
, dwn_mode
);
3118 GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
3122 GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
3128 GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
3134 gtp_fw_startup(i2c_client_point
);
3136 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3140 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3146 gtp_fw_startup(i2c_client_point
);
3148 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3154 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3159 static void gup_bit_write(s32 addr
, s32 bit
, s32 val
)
3162 i2c_read_bytes(i2c_client_point
, addr
, &buf
, 1);
3164 buf
= (buf
& (~((u8
)1 << bit
))) | ((u8
)val
<< bit
);
3166 i2c_write_bytes(i2c_client_point
, addr
, &buf
, 1);
3169 static void gup_clk_count_init(s32 bCh
, s32 bCNT
)
3173 //_fRW_MISCTL__MEA_EN = 0; //Frequency measure enable
3174 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3175 //_fRW_MISCTL__MEA_CLR = 1; //Frequency measure clear
3176 gup_bit_write(_fRW_MISCTL__MEA
, 1, 1);
3177 //_bRW_MISCTL__MEA_MODE = 0; //Pulse mode
3179 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_MODE
, &buf
, 1);
3180 //_bRW_MISCTL__MEA_SRCSEL = 8 + bCh; //From GIO1
3182 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_SRCSEL
, &buf
, 1);
3183 //_wRW_MISCTL__MEA_MAX_NUM = bCNT; //Set the Measure Counts = 1
3185 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__MEA_MAX_NUM
, &buf
, 1);
3186 //_fRW_MISCTL__MEA_CLR = 0; //Frequency measure not clear
3187 gup_bit_write(_fRW_MISCTL__MEA
, 1, 0);
3188 //_fRW_MISCTL__MEA_EN = 1;
3189 gup_bit_write(_fRW_MISCTL__MEA
, 0, 1);
3192 static u32
gup_clk_count_get(void)
3198 while ((ready
== 0)) //Wait for measurement complete
3200 i2c_read_bytes(i2c_client_point
, _bRO_MISCTL__MEA_RDY
, buf
, 1);
3206 //_fRW_MISCTL__MEA_EN = 0;
3207 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3208 i2c_read_bytes(i2c_client_point
, _dRO_MISCTL__MEA_VAL
, buf
, 4);
3209 GTP_INFO("Clk_count 0: %2X", buf
[0]);
3210 GTP_INFO("Clk_count 1: %2X", buf
[1]);
3211 GTP_INFO("Clk_count 2: %2X", buf
[2]);
3212 GTP_INFO("Clk_count 3: %2X", buf
[3]);
3214 temp
= (s32
)buf
[0] + ((s32
)buf
[1] << 8) + ((s32
)buf
[2] << 16) + ((s32
)buf
[3] << 24);
3215 GTP_INFO("Clk_count : %d", temp
);
3218 u8
gup_clk_dac_setting(int dac
)
3222 i2c_read_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3223 i2c_read_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3225 buf1
= (buf1
& 0xFFCF) | ((dac
& 0x03) << 4);
3226 buf2
= (dac
>> 2) & 0x3f;
3228 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3229 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3234 static u8
gup_clk_calibration_pin_select(s32 bCh
)
3241 i2c_addr
= _fRW_MISCTL__GIO0
;
3245 i2c_addr
= _fRW_MISCTL__GIO1
;
3249 i2c_addr
= _fRW_MISCTL__GIO2
;
3253 i2c_addr
= _fRW_MISCTL__GIO3
;
3257 i2c_addr
= _fRW_MISCTL__GIO4
;
3261 i2c_addr
= _fRW_MISCTL__GIO5
;
3265 i2c_addr
= _fRW_MISCTL__GIO6
;
3269 i2c_addr
= _fRW_MISCTL__GIO7
;
3273 i2c_addr
= _fRW_MISCTL__GIO8
;
3277 i2c_addr
= _fRW_MISCTL__GIO9
;
3281 gup_bit_write(i2c_addr
, 1, 0);
3286 void gup_output_pulse(int t
)
3288 unsigned long flags
;
3291 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3294 local_irq_save(flags
);
3296 mt_set_gpio_out(GTP_INT_PORT
, 1);
3298 mt_set_gpio_out(GTP_INT_PORT
, 0);
3300 mt_set_gpio_out(GTP_INT_PORT
, 1);
3302 local_irq_restore(flags
);
3305 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3308 static void gup_sys_clk_init(void)
3312 //_fRW_MISCTL__RG_RXADC_CKMUX = 0;
3313 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 5, 0);
3314 //_bRW_MISCTL__RG_LDO_A18_PWD = 0; //DrvMISCTL_A18_PowerON
3316 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_LDO_A18_PWD
, &buf
, 1);
3317 //_bRW_MISCTL__RG_BG_PWD = 0; //DrvMISCTL_BG_PowerON
3319 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_BG_PWD
, &buf
, 1);
3320 //_bRW_MISCTL__RG_CLKGEN_PWD = 0; //DrvMISCTL_CLKGEN_PowerON
3322 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_CLKGEN_PWD
, &buf
, 1);
3323 //_fRW_MISCTL__RG_RXADC_PWD = 0; //DrvMISCTL_RX_ADC_PowerON
3324 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 0, 0);
3325 //_fRW_MISCTL__RG_RXADC_REF_PWD = 0; //DrvMISCTL_RX_ADCREF_PowerON
3326 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 1, 0);
3327 //gup_clk_dac_setting(60);
3328 //_bRW_MISCTL__OSC_CK_SEL = 1;;
3330 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__OSC_CK_SEL
, &buf
, 1);
3333 u8
gup_clk_calibration(void)
3338 struct timeval start
, end
;
3344 //unsigned long flags;
3346 //buf = 0x0C; // hold ss51 and dsp
3347 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3348 ret
= gup_hold_ss51_dsp(i2c_client_point
);
3351 GTP_ERROR("[gup_clk_calibration]hold ss51 & dsp failed.");
3355 //_fRW_MISCTL__CLK_BIAS = 0; //disable clock bias
3356 gup_bit_write(_rRW_MISCTL_RG_DMY83
, 7, 0);
3358 //_fRW_MISCTL__GIO1_PU = 0; //set TOUCH INT PIN MODE as input
3359 gup_bit_write(_rRW_MISCTL__GIO1CTL_B2_
, 0, 0);
3361 //_fRW_MISCTL__GIO1_OE = 0; //set TOUCH INT PIN MODE as input
3362 gup_bit_write(_rRW_MISCTL__GIO1CTL_B1_
, 1, 0);
3365 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3368 GTP_INFO("CLK calibration GO");
3370 gup_clk_calibration_pin_select(1);//use GIO1 to do the calibration
3372 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3374 for (i
= INIT_CLK_DAC
; i
< MAX_CLK_DAC
; i
++)
3378 i
= 80; // if sleeping while calibrating main clock, set it default 80
3381 GTP_INFO("CLK calibration DAC %d", i
);
3383 gup_clk_dac_setting(i
);
3384 gup_clk_count_init(1, CLK_AVG_TIME
);
3387 gup_output_pulse(PULSE_LENGTH
);
3388 count
= gup_clk_count_get();
3390 if (count
> PULSE_LENGTH
* 60)//60= 60Mhz * 1us
3396 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3398 //local_irq_save(flags);
3399 do_gettimeofday(&start
);
3400 mt_set_gpio_out(GTP_INT_PORT
, 1);
3401 //local_irq_restore(flags);
3404 mt_set_gpio_out(GTP_INT_PORT
, 0);
3407 //local_irq_save(flags);
3408 do_gettimeofday(&end
);
3409 mt_set_gpio_out(GTP_INT_PORT
, 1);
3410 //local_irq_restore(flags);
3412 count
= gup_clk_count_get();
3414 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3416 usec
= end
.tv_usec
- start
.tv_usec
;
3417 sec
= end
.tv_sec
- start
.tv_sec
;
3418 count_ref
= 60 * (usec
+ sec
* MILLION
);//60= 60Mhz * 1us
3420 GTP_DEBUG("== time %d, %d, %d", sec
, usec
, count_ref
);
3422 if (count
> count_ref
)
3424 GTP_DEBUG("== count_diff %d", count
- count_ref
);
3433 //gtp_reset_guitar(i2c_client_point, 20);
3436 //-- ouput clk to GPIO 4
3438 i2c_write_bytes(i2c_client_point
, 0x41FA, &buf
, 1);
3440 i2c_write_bytes(i2c_client_point
, 0x4104, &buf
, 1);
3442 i2c_write_bytes(i2c_client_point
, 0x4105, &buf
, 1);
3444 i2c_write_bytes(i2c_client_point
, 0x4106, &buf
, 1);
3446 i2c_write_bytes(i2c_client_point
, 0x4107, &buf
, 1);
3448 i2c_write_bytes(i2c_client_point
, 0x41F8, &buf
, 1);
3450 i2c_write_bytes(i2c_client_point
, 0x41F9, &buf
, 1);
3453 GTP_GPIO_AS_INT(GTP_INT_PORT
);
3458 #define BANK_LENGTH (16*1024)
3459 #define FIRMWARE_HEADER_LEN 14
3461 static u32 current_system_length
= 0;
3463 char * gup_load_fw_from_file(char *filepath
)
3465 struct file
*fw_file
= NULL
;
3466 mm_segment_t old_fs
;
3468 char *buffer
= NULL
;
3470 if(filepath
== NULL
)
3472 GTP_ERROR("[Load_firmware]filepath: NULL");
3473 goto load_firmware_exit
;
3479 fw_file
= filp_open(filepath
, O_RDONLY
, 0);
3480 if (fw_file
== NULL
|| IS_ERR(fw_file
))
3482 GTP_ERROR("[Load_firmware]Failed to open: %s", filepath
);
3483 goto load_firmware_exit
;
3485 fw_file
->f_op
->llseek(fw_file
, 0, SEEK_SET
);
3486 len
= fw_file
->f_op
->llseek(fw_file
, 0, SEEK_END
);
3489 GTP_ERROR("[Load_firmware]Firmware is too short: %ld", len
);
3490 goto load_firmware_failed
;
3492 buffer
= (char *)kmalloc(sizeof(char) * len
, GFP_KERNEL
);
3495 GTP_ERROR("[Load_firmware]Failed to allocate buffer: %ld", len
);
3496 goto load_firmware_failed
;
3499 memset(buffer
, 0, sizeof(char) * len
);
3501 fw_file
->f_op
->llseek(fw_file
, 0, SEEK_SET
);
3502 fw_file
->f_op
->read(fw_file
, buffer
, len
, &fw_file
->f_pos
);
3504 GTP_ERROR("[Load_firmware]Load from file success: %ld %s", len
, filepath
);
3507 load_firmware_failed
:
3508 filp_close(fw_file
, NULL
);
3515 s32
gup_check_firmware(char *fw
, u32 length
)
3518 u32 fw_checksum
= 0;
3521 for(i
=0; i
<length
; i
+=2)
3523 temp
= (fw
[i
]<<8) + fw
[i
+1];
3524 fw_checksum
+= temp
;
3527 GTP_DEBUG("firmware checksum: %4X", fw_checksum
&0xFFFF);
3528 if(fw_checksum
&0xFFFF)
3535 s32
gup_enter_update_mode_noreset(void)
3540 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__TMR0_EN
, 0x00);
3543 GTP_ERROR("[enter_update_mode]disable wdt fail.");
3546 //select addr & hold ss51_dsp
3547 ret
= gup_hold_ss51_dsp(i2c_client_point
);
3550 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
3554 //clear control flag
3555 ret
= gup_set_ic_msg(i2c_client_point
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
3559 GTP_ERROR("[enter_update_mode]clear control flag fail.");
3564 ret
= gup_set_ic_msg(i2c_client_point
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
3568 GTP_ERROR("[enter_update_mode]set scramble fail.");
3572 //enable accessing code
3573 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
3577 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
3584 s32
gup_load_by_bank(u8 bank
, u8 need_check
, u8
*fw
, u32 length
)
3589 GTP_DEBUG("[load_by_bank]begin download [bank:%d,length:%d].",bank
,length
);
3592 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, bank
);
3595 GTP_ERROR("[load_by_bank]select bank fail.");
3599 ret
= i2c_write_bytes(i2c_client_point
, 0xC000,fw
, length
);
3602 GTP_ERROR("[load_by_bank]download bank fail.");
3608 ret
= gup_check_and_repair(i2c_client_point
, 0xC000, fw
, length
);
3611 GTP_ERROR("[load_by_bank]checked FW bank fail.");
3627 s32
gup_load_system(char *firmware
, s32 length
, u8 need_check
)
3632 //disable irq & ESD protect
3633 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3635 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3637 ret
= gup_enter_update_mode_noreset();
3640 goto gup_load_system_exit
;
3642 GTP_DEBUG("enter update mode success.");
3645 u32 len
= length
>BANK_LENGTH
? BANK_LENGTH
:length
;
3646 ret
= gup_load_by_bank(bank
, need_check
, &firmware
[bank
*BANK_LENGTH
], len
);
3649 goto gup_load_system_exit
;
3651 GTP_DEBUG("load bank%d length:%d success.", bank
, len
);
3656 ret
= gtp_fw_startup(i2c_client_point
);
3658 gup_load_system_exit
:
3660 #if FLASHLESS_FLASH_WORKROUND
3663 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3666 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3670 s32
gup_load_fx_system(void)
3673 char *firmware
= NULL
;
3674 u32 is_load_from_file
= 0;
3677 GTP_INFO("[load_fx_system] Load authorization system.");
3679 firmware
= gtp_default_FW_hotknot2
;
3682 firmware
= gup_load_fw_from_file( FX_SYSTEM_PATH
);
3683 if(firmware
== NULL
)
3685 firmware
= gtp_default_FW_hotknot2
;
3686 GTP_INFO("[load_fx_system] Use default firmware.");
3690 is_load_from_file
= 1;
3694 length
= firmware
[0]*256*256*256+
3695 firmware
[1]*256*256+
3699 if(length
> 32*1024 || length
< 4*1024 )
3701 GTP_ERROR("[load_fx_system]firmware's length is invalid.");
3705 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3708 GTP_ERROR("[load_fx_system]firmware's checksum is error.");
3712 current_system_length
= length
;
3714 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 1);
3718 if(is_load_from_file
)
3727 s32
gup_load_hotknot_system(void)
3730 char *firmware
= NULL
;
3731 u32 is_load_from_file
= 0;
3734 load_fw_process
= 1;
3736 if(gtp_chip_type == CHIP_TYPE_GT9)
3739 u8 wr_buf[3] = {0x80, 0x46, 0x22};
3740 u8 rd_buf[4] = {0x81, 0xA8, 0x00, 0x00};
3744 ret = gup_i2c_write(i2c_client_point, wr_buf, sizeof(wr_buf));
3750 ret = gup_i2c_write(i2c_client_point, wr_buf, sizeof(wr_buf));
3756 ret = gup_i2c_read(i2c_client_point, rd_buf, sizeof(rd_buf));
3761 if(rd_buf[GTP_ADDR_LENGTH] == 0xAA &&
3762 rd_buf[GTP_ADDR_LENGTH] == rd_buf[GTP_ADDR_LENGTH + 1])
3764 GTP_INFO("[load_hotknot_system]Hotknot switch system success.");
3768 GTP_ERROR("[load_hotknot_system]Hotknot switch system failed.");
3772 GTP_INFO("[load_hotknot_system] Load hotknot system.");
3774 firmware
= gtp_default_FW_hotknot
;
3777 firmware
= gup_load_fw_from_file( HOTKNOT_SYSTEM_PATH
);
3778 if(firmware
== NULL
)
3780 firmware
= gtp_default_FW_hotknot
;
3781 GTP_INFO("[load_hotknot_system] Use default firmware.");
3785 is_load_from_file
= 1;
3789 length
= firmware
[0]*256*256*256+
3790 firmware
[1]*256*256+
3793 if(length
> 32*1024 || length
< 4*1024 )
3795 GTP_ERROR("[load_hotknot_system]firmware's length is invalid.");
3796 goto load_hotknot_exit
;
3799 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3802 GTP_ERROR("[load_hotknot_system]firmware's checksum is error.");
3803 goto load_hotknot_exit
;
3806 current_system_length
= length
;
3808 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 0);
3812 if(is_load_from_file
)
3822 s32
gup_recovery_main_system(void)
3825 char *firmware
= NULL
;
3826 u32 is_load_from_file
= 0;
3829 GTP_INFO("[recovery_main_system] Recovery main system.");
3831 if(gtp_chip_type
== CHIP_TYPE_GT9
)
3833 gtp_reset_guitar(i2c_client_point
,10);
3834 load_fw_process
= 0;
3838 firmware
= gtp_default_FW_fl
;
3841 firmware
= gup_load_fw_from_file(MAIN_SYSTEM_PATH
);
3842 if(firmware
== NULL
)
3844 firmware
= gtp_default_FW_fl
;
3845 GTP_INFO("[recovery_main_system]Use default firmware.");
3849 is_load_from_file
= 1;
3853 if(firmware
[0]==0x00&&firmware
[1]==0x90&&firmware
[2]==0x06&&firmware
[3]==0x00)
3859 length
= firmware
[0]*256*256*256+
3860 firmware
[1]*256*256+
3864 if(length
> 36*1024 || length
< 16*1024 )
3866 GTP_ERROR("[recovery_main_system]firmware's length is invalid.");
3867 goto recovery_main_system_exit
;
3870 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3873 GTP_ERROR("[recovery_main_system]firmware's checksum is error.");
3874 goto recovery_main_system_exit
;
3877 if(current_system_length
== 0)
3879 current_system_length
= length
;
3882 GTP_INFO("[recovery_main_system] Recovery length: %d.", current_system_length
);
3884 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], current_system_length
, 0);
3886 #if (FLASHLESS_FLASH_WORKROUND && GTP_ESD_PROTECT)
3887 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3890 recovery_main_system_exit
:
3892 if(is_load_from_file
)
3897 load_fw_process
= 0;
3902 s32
gup_load_main_system(char *filepath
)
3905 char *firmware
= NULL
;
3906 u32 is_load_from_file
= 0;
3909 GTP_INFO("[load_main_system] Load main system.");
3911 if(filepath
!= NULL
)
3913 firmware
= gup_load_fw_from_file(filepath
);
3914 if(firmware
== NULL
)
3916 GTP_INFO("[load_main_system]can not open file: %s", filepath
);
3917 goto load_main_system_exit
;
3921 is_load_from_file
= 1;
3926 firmware
= gtp_default_FW_fl
;
3929 firmware
= gup_load_fw_from_file(filepath
);
3930 if(firmware
== NULL
)
3932 if(gtp_chip_type
== CHIP_TYPE_GT9
)
3933 firmware
= gtp_default_FW
;
3935 firmware
= gtp_default_FW_fl
;
3936 GTP_INFO("[load_main_system]Use default firmware. type:%d", gtp_chip_type
);
3940 is_load_from_file
= 1;
3944 if(firmware
[0]==0x00&&firmware
[1]==0x90&&firmware
[2]==0x06&&firmware
[3]==0x00)
3950 length
= firmware
[0]*256*256*256+
3951 firmware
[1]*256*256+
3954 if(length
> 36*1024)
3959 ret
= gup_check_firmware(&firmware
[FIRMWARE_HEADER_LEN
],length
);
3962 GTP_ERROR("[load_main_system]firmware's checksum is error.");
3963 goto load_main_system_exit
;
3965 GTP_INFO("[load_main_system] Firmware length: %d.", length
);
3967 //memcpy(gtp_default_FW_fl, firmware, length);
3969 ret
= gup_load_system(&firmware
[FIRMWARE_HEADER_LEN
], length
, 1);
3972 #if (FLASHLESS_FLASH_WORKROUND && GTP_ESD_PROTECT)
3973 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3976 load_main_system_exit
:
3978 if(is_load_from_file
)
3986 //*************** For GT9XXF End ***********************//