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
36 * 1. multi-system supported
37 * 2. flashless update no pid vid compare
40 * Special edition for GT910 flashless
44 #include <linux/interrupt.h>
45 #include <cust_eint.h>
46 #include <linux/i2c.h>
47 #include <linux/sched.h>
48 #include <linux/kthread.h>
49 #include <linux/rtpm_prio.h>
50 #include <linux/wait.h>
51 #include <linux/time.h>
52 #include <linux/delay.h>
53 #include <linux/namei.h>
54 #include <linux/mount.h>
55 #include "cust_gpio_usage.h"
56 #include <asm/uaccess.h>
58 #include "tpd_custom_gt9xx.h"
60 #if ( (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE) || GTP_COMPATIBLE_MODE )
61 #include "gt9xx_firmware.h"
64 #define GUP_REG_HW_INFO 0x4220
65 #define GUP_REG_FW_MSG 0x41E4
66 #define GUP_REG_PID_VID 0x8140
68 #define GUP_SEARCH_FILE_TIMES 50
69 #define UPDATE_FILE_PATH_1 "/data/_goodix_update_.bin"
70 #define UPDATE_FILE_PATH_2 "/sdcard/_goodix_update_.bin"
72 #define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg"
73 #define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg"
75 #define FW_HEAD_LENGTH 14
76 #define FW_DOWNLOAD_LENGTH 0x4000
77 #define FW_SECTION_LENGTH 0x2000
78 #define FW_DSP_ISP_LENGTH 0x1000
79 #define FW_DSP_LENGTH 0x1000
80 #define FW_BOOT_LENGTH 0x800
81 #define FW_SS51_LENGTH (4 * FW_SECTION_LENGTH)
82 #define FW_BOOT_ISP_LENGTH 0x800 // 2k
83 #define FW_GLINK_LENGTH 0x3000 // 12k
84 #define FW_GWAKE_LENGTH (4 * FW_SECTION_LENGTH) // 32k
87 #define MAX_FRAME_CHECK_TIME 5
90 #define _bRW_MISCTL__SRAM_BANK 0x4048
91 #define _bRW_MISCTL__MEM_CD_EN 0x4049
92 #define _bRW_MISCTL__CACHE_EN 0x404B
93 #define _bRW_MISCTL__TMR0_EN 0x40B0
94 #define _rRW_MISCTL__SWRST_B0_ 0x4180
95 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
96 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
97 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
98 #define _rRW_MISCTL__BOOT_CTL_ 0x5094
100 #define AUTO_SEARCH_BIN 0x01
101 #define AUTO_SEARCH_CFG 0x02
102 #define BIN_FILE_READY 0x80
103 #define CFG_FILE_READY 0x08
104 #define HEADER_FW_READY 0x01
109 u8 hw_info
[4]; //hardware info//
110 u8 pid
[8]; //product id //
111 u16 vid
; //version id //
120 struct file
*cfg_file
;
121 st_fw_head ic_fw_msg
;
127 st_update_msg update_msg
;
128 extern struct i2c_client
*i2c_client_point
;
131 extern u8 fw_updating
;
133 u8 searching_file
= 0;
134 u8 got_file_flag
= 0;
137 extern void gtp_esd_switch(struct i2c_client
*client
, s32 on
);
140 #if GTP_COMPATIBLE_MODE
141 extern CHIP_TYPE_T gtp_chip_type
;
142 extern u8 rqst_processing
;
144 extern u8 after_912_1020
;
145 extern u8
gtp_fw_startup(struct i2c_client
*client
);
146 static u8
gup_check_and_repair(struct i2c_client
*, s32
, u8
*, u32
);
147 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
);
149 #if GTP_FL_LITTLE_SYSTEM
150 extern u8 power_is_down
;
155 #define _CLOSE_FILE(p_file) if (p_file && !IS_ERR(p_file)) \
157 filp_close(p_file, NULL); \
161 static u8
gup_burn_fw_gwake_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
);
163 static s32
gup_i2c_read(struct i2c_client
*client
, u8
*buf
, s32 len
)
166 u16 addr
= (buf
[0] << 8) + buf
[1];
168 ret
= i2c_read_bytes(client
, addr
, &buf
[2], len
- 2);
180 static s32
gup_i2c_write(struct i2c_client
*client
, u8
*buf
, s32 len
)
183 u16 addr
= (buf
[0] << 8) + buf
[1];
185 ret
= i2c_write_bytes(client
, addr
, &buf
[2], len
- 2);
197 static u8
gup_get_ic_msg(struct i2c_client
*client
, u16 addr
, u8
*msg
, s32 len
)
201 msg
[0] = (addr
>> 8) & 0xff;
202 msg
[1] = addr
& 0xff;
204 for (i
= 0; i
< 5; i
++)
206 if (gup_i2c_read(client
, msg
, GTP_ADDR_LENGTH
+ len
) > 0)
214 GTP_ERROR("Read data from 0x%02x%02x failed!", msg
[0], msg
[1]);
221 static u8
gup_set_ic_msg(struct i2c_client
*client
, u16 addr
, u8 val
)
226 msg
[0] = (addr
>> 8) & 0xff;
227 msg
[1] = addr
& 0xff;
230 for (i
= 0; i
< 5; i
++)
232 if (gup_i2c_write(client
, msg
, GTP_ADDR_LENGTH
+ 1) > 0)
240 GTP_ERROR("Set data to 0x%02x%02x failed!", msg
[0], msg
[1]);
247 static u8
gup_get_ic_fw_msg(struct i2c_client
*client
)
254 //step1:get hardware info
255 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_HW_INFO
, &buf
[GTP_ADDR_LENGTH
], 4);
258 GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit");
262 // buf[2~5]: 00 06 90 00
263 // hw_info: 00 90 06 00
264 for (i
= 0; i
< 4; i
++)
266 update_msg
.ic_fw_msg
.hw_info
[i
] = buf
[GTP_ADDR_LENGTH
+ 3 - i
];
269 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],
270 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
272 //step2:get firmware message
273 for (retry
= 0; retry
< 2; retry
++)
275 ret
= gup_get_ic_msg(client
, GUP_REG_FW_MSG
, buf
, 1);
279 GTP_ERROR("Read firmware message fail.");
283 update_msg
.force_update
= buf
[GTP_ADDR_LENGTH
];
285 if ((0xBE != update_msg
.force_update
) && (!retry
))
287 GTP_ERROR("The check sum in ic is error.");
288 GTP_INFO("The IC will be updated by force.");
294 GTP_INFO("IC force update flag:0x%x", update_msg
.force_update
);
296 //step3:get pid & vid
297 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_PID_VID
, &buf
[GTP_ADDR_LENGTH
], 6);
300 GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit");
304 memset(update_msg
.ic_fw_msg
.pid
, 0, sizeof(update_msg
.ic_fw_msg
.pid
));
305 memcpy(update_msg
.ic_fw_msg
.pid
, &buf
[GTP_ADDR_LENGTH
], 4);
309 /*|-----FLASH-----RAM-----|
310 |------918------918-----|
311 |------968------968-----|
312 |------913------913-----|
313 |------913P-----913P----|
314 |------927------927-----|
315 |------927P-----927P----|
316 |------9110-----9110----|
317 |------9110P----9111----|*/
318 if(update_msg
.ic_fw_msg
.pid
[0] != 0)
320 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "9111", 4))
322 GTP_INFO("IC Mapping Product id:%s", update_msg
.ic_fw_msg
.pid
);
323 memcpy(update_msg
.ic_fw_msg
.pid
, "9110P", 5);
327 update_msg
.ic_fw_msg
.vid
= buf
[GTP_ADDR_LENGTH
+ 4] + (buf
[GTP_ADDR_LENGTH
+ 5] << 8);
331 s32
gup_enter_update_mode(struct i2c_client
*client
)
337 //step1:RST output low last at least 2ms
338 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
341 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
342 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
345 //step3:RST output high reset guitar
346 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
348 //20121211 modify start
352 //step4:Hold ss51 & dsp
353 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
356 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
361 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
364 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
367 if(0x0C == rd_buf
[GTP_ADDR_LENGTH
])
369 GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
372 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
376 GTP_ERROR("Enter update Hold ss51 failed.");
380 //step6:DSP_CK and DSP_ALU_CK PowerOn
381 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
383 //20121211 modify end
387 void gup_leave_update_mode(void)
389 GTP_GPIO_AS_INT(GTP_INT_PORT
);
391 GTP_DEBUG("[leave_update_mode]reset chip.");
392 gtp_reset_guitar(i2c_client_point
, 20);
395 static u8
gup_enter_update_judge(st_fw_head
*fw_head
)
401 //Get the correct nvram data
402 //The correct conditions:
403 //1. the hardware info is the same
404 //2. the product id is the same
405 //3. the firmware version in update file is greater than the firmware version in ic
406 //or the check sum in ic is wrong
408 u16_tmp
= fw_head
->vid
;
409 fw_head
->vid
= (u16
)(u16_tmp
>> 8) + (u16
)(u16_tmp
<< 8);
411 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]);
412 GTP_INFO("FILE PID:%s", fw_head
->pid
);
413 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
414 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],
415 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
416 GTP_INFO("IC PID:%s", update_msg
.ic_fw_msg
.pid
);
417 GTP_INFO("IC VID:%04x", update_msg
.ic_fw_msg
.vid
);
419 if (!memcmp(fw_head
->pid
, "9158", 4) && !memcmp(update_msg
.ic_fw_msg
.pid
, "915S", 4))
421 GTP_INFO("Update GT915S to GT9158 directly!");
425 if (!memcmp(fw_head
->hw_info
, update_msg
.ic_fw_msg
.hw_info
, sizeof(update_msg
.ic_fw_msg
.hw_info
)))
431 fw_len
= fw_head
->hw_info
[3];
432 fw_len
+= (((u32
)fw_head
->hw_info
[2]) << 8);
433 fw_len
+= (((u32
)fw_head
->hw_info
[1]) << 16);
434 fw_len
+= (((u32
)fw_head
->hw_info
[0]) << 24);
436 if (update_msg
.fw_total_len
!= fw_len
)
438 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);
441 GTP_INFO("Firmware length:%d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
443 if (update_msg
.force_update
!= 0xBE)
445 GTP_INFO("FW chksum error,need enter update.");
449 if (strlen(update_msg
.ic_fw_msg
.pid
) < 3)
451 GTP_INFO("Illegal IC pid, need enter update");
456 for (i
= 0; i
< 3; i
++)
458 if ((update_msg
.ic_fw_msg
.pid
[i
] < 0x30) || (update_msg
.ic_fw_msg
.pid
[i
] > 0x39))
460 GTP_INFO("Illegal IC pid, out of bound, need enter update");
467 pid_cmp_len
= strlen(fw_head
->pid
);
468 if (pid_cmp_len
< strlen(update_msg
.ic_fw_msg
.pid
))
470 pid_cmp_len
= strlen(update_msg
.ic_fw_msg
.pid
);
473 if ((!memcmp(fw_head
->pid
, update_msg
.ic_fw_msg
.pid
, pid_cmp_len
)) ||
474 (!memcmp(update_msg
.ic_fw_msg
.pid
, "91XX", 4))||
475 (!memcmp(fw_head
->pid
, "91XX", 4)))
477 if(!memcmp(fw_head
->pid
, "91XX", 4))
479 GTP_DEBUG("Force none same pid update mode.");
483 GTP_DEBUG("Get the same pid.");
486 //The third condition
487 if (fw_head
->vid
> update_msg
.ic_fw_msg
.vid
)
490 GTP_INFO("Need enter update.");
494 GTP_INFO("Don't meet the third condition.");
495 GTP_ERROR("File VID <= IC VID, update aborted!");
499 GTP_ERROR("File PID != IC PID, update aborted!");
505 #if GTP_AUTO_UPDATE_CFG
506 static u8
ascii2hex(u8 a
)
510 if(a
>= '0' && a
<= '9')
514 else if(a
>= 'A' && a
<= 'F')
516 value
= a
- 'A' + 0x0A;
518 else if(a
>= 'a' && a
<= 'f')
520 value
= a
- 'a' + 0x0A;
530 static s8
gup_update_config(struct i2c_client
*client
)
535 s32 file_cfg_len
= 0;
536 s32 chip_cfg_len
= 0;
543 if(NULL
== update_msg
.cfg_file
)
545 GTP_ERROR("[update_cfg]No need to upgrade config!");
548 file_len
= update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_END
);
550 chip_cfg_len
= cfg_len
;
552 GTP_DEBUG("[update_cfg]config file len:%d", file_len
);
553 GTP_DEBUG("[update_cfg]need config len:%d",chip_cfg_len
);
554 if((file_len
+5) < chip_cfg_len
*5)
556 GTP_ERROR("Config length error");
560 buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
561 pre_buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
562 file_config
= (u8
*)kzalloc(chip_cfg_len
+ GTP_ADDR_LENGTH
, GFP_KERNEL
);
563 update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_SET
);
565 GTP_DEBUG("[update_cfg]Read config from file.");
566 ret
= update_msg
.cfg_file
->f_op
->read(update_msg
.cfg_file
, (char*)pre_buf
, file_len
, &update_msg
.cfg_file
->f_pos
);
569 GTP_ERROR("[update_cfg]Read config file failed.");
570 goto update_cfg_file_failed
;
573 GTP_DEBUG("[update_cfg]Delete illgal charactor.");
574 for(i
=0,count
=0; i
<file_len
; i
++)
576 if (pre_buf
[i
] == ' ' || pre_buf
[i
] == '\r' || pre_buf
[i
] == '\n')
580 buf
[count
++] = pre_buf
[i
];
583 GTP_DEBUG("[update_cfg]Ascii to hex.");
584 file_config
[0] = GTP_REG_CONFIG_DATA
>> 8;
585 file_config
[1] = GTP_REG_CONFIG_DATA
& 0xff;
586 for(i
=0,file_cfg_len
=GTP_ADDR_LENGTH
; i
<count
; i
+=5)
588 if((buf
[i
]=='0') && ((buf
[i
+1]=='x') || (buf
[i
+1]=='X')))
591 high
= ascii2hex(buf
[i
+2]);
592 low
= ascii2hex(buf
[i
+3]);
594 if((high
== 0xFF) || (low
== 0xFF))
597 GTP_ERROR("[update_cfg]Illegal config file.");
598 goto update_cfg_file_failed
;
600 file_config
[file_cfg_len
++] = (high
<<4) + low
;
605 GTP_ERROR("[update_cfg]Illegal config file.");
606 goto update_cfg_file_failed
;
611 GTP_DEBUG("config:");
612 GTP_DEBUG_ARRAY(file_config
+2, file_cfg_len
);
617 ret
= gup_i2c_write(client
, file_config
, file_cfg_len
);
620 GTP_INFO("[update_cfg]Send config SUCCESS.");
623 GTP_ERROR("[update_cfg]Send config i2c error.");
626 update_cfg_file_failed
:
635 #if (GTP_AUTO_UPDATE && (!GTP_HEADER_FW_UPDATE || GTP_AUTO_UPDATE_CFG))
636 static void gup_search_file(s32 search_type
)
639 struct file
*pfile
= NULL
;
641 got_file_flag
= 0x00;
644 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
646 if (0 == searching_file
)
648 GTP_INFO("Force exiting file searching");
649 got_file_flag
= 0x00;
653 if (search_type
& AUTO_SEARCH_BIN
)
655 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
);
656 pfile
= filp_open(UPDATE_FILE_PATH_1
, O_RDONLY
, 0);
659 pfile
= filp_open(UPDATE_FILE_PATH_2
, O_RDONLY
, 0);
662 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_2
);
663 got_file_flag
|= BIN_FILE_READY
;
664 update_msg
.file
= pfile
;
669 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_1
);
670 got_file_flag
|= BIN_FILE_READY
;
671 update_msg
.file
= pfile
;
673 if (got_file_flag
& BIN_FILE_READY
)
675 #if GTP_AUTO_UPDATE_CFG
676 if (search_type
& AUTO_SEARCH_CFG
)
678 i
= GUP_SEARCH_FILE_TIMES
; // Bin & Cfg File required to be in the same directory
689 #if GTP_AUTO_UPDATE_CFG
690 if ( (search_type
& AUTO_SEARCH_CFG
) && !(got_file_flag
& CFG_FILE_READY
) )
692 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
);
693 pfile
= filp_open(CONFIG_FILE_PATH_1
, O_RDONLY
, 0);
696 pfile
= filp_open(CONFIG_FILE_PATH_2
, O_RDONLY
, 0);
699 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_2
);
700 got_file_flag
|= CFG_FILE_READY
;
701 update_msg
.cfg_file
= pfile
;
706 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_1
);
707 got_file_flag
|= CFG_FILE_READY
;
708 update_msg
.cfg_file
= pfile
;
710 if (got_file_flag
& CFG_FILE_READY
)
723 static u8
gup_check_update_file(struct i2c_client
*client
, st_fw_head
*fw_head
, u8
*path
)
728 u8 buf
[FW_HEAD_LENGTH
];
730 got_file_flag
= 0x00;
733 GTP_DEBUG("Update File path:%s, %d", path
, strlen(path
));
734 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
736 if (IS_ERR(update_msg
.file
))
738 GTP_ERROR("Open update file(%s) error!", path
);
741 got_file_flag
= BIN_FILE_READY
;
746 #if GTP_HEADER_FW_UPDATE
747 GTP_INFO("Update by default firmware array");
748 update_msg
.fw_total_len
= sizeof(gtp_default_FW
) - FW_HEAD_LENGTH
;
749 if (sizeof(gtp_default_FW
) < (FW_HEAD_LENGTH
+ FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
))
751 GTP_ERROR("INVALID gtp_default_FW, check your gt9xx_firmware.h file!");
754 GTP_DEBUG("Firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
755 memcpy(fw_head
, >p_default_FW
[0], FW_HEAD_LENGTH
);
757 //check firmware legality
759 for (i
= 0; i
< update_msg
.fw_total_len
; i
+= 2)
761 fw_checksum
+= (gtp_default_FW
[FW_HEAD_LENGTH
+ i
] << 8) + gtp_default_FW
[FW_HEAD_LENGTH
+ i
+ 1];
764 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
765 if(fw_checksum
&0xFFFF)
767 GTP_ERROR("Illegal firmware file.");
770 got_file_flag
= HEADER_FW_READY
;
774 #if GTP_AUTO_UPDATE_CFG
775 gup_search_file(AUTO_SEARCH_BIN
| AUTO_SEARCH_CFG
);
776 if (got_file_flag
& CFG_FILE_READY
)
778 ret
= gup_update_config(client
);
781 GTP_ERROR("Update config failed!");
783 _CLOSE_FILE(update_msg
.cfg_file
);
784 msleep(500); //waiting config to be stored in FLASH.
787 gup_search_file(AUTO_SEARCH_BIN
);
790 if (!(got_file_flag
& BIN_FILE_READY
))
792 GTP_ERROR("No bin file for fw Update");
798 GTP_ERROR("NULL file for fw update!");
804 update_msg
.old_fs
= get_fs();
807 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
808 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
810 if (update_msg
.fw_total_len
< (FW_HEAD_LENGTH
+ FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
))
812 GTP_ERROR("INVALID bin file(size: %d), update aborted.", update_msg
.fw_total_len
);
816 update_msg
.fw_total_len
-= FW_HEAD_LENGTH
;
818 GTP_DEBUG("Bin firmware actual size: %d(%dK)", update_msg
.fw_total_len
, update_msg
.fw_total_len
/1024);
820 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
821 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
824 GTP_ERROR("Read firmware head in update file error.");
828 memcpy(fw_head
, buf
, FW_HEAD_LENGTH
);
830 //check firmware legality
832 for(i
=0; i
< update_msg
.fw_total_len
; i
+=2)
835 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char*)buf
, 2, &update_msg
.file
->f_pos
);
838 GTP_ERROR("Read firmware file error.");
841 //GTP_DEBUG("BUF[0]:%x", buf[0]);
842 temp
= (buf
[0]<<8) + buf
[1];
846 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
847 if(fw_checksum
&0xFFFF)
849 GTP_ERROR("Illegal firmware file.");
856 static u8
gup_burn_proc(struct i2c_client
*client
, u8
*burn_buf
, u16 start_addr
, u16 total_length
)
859 u16 burn_addr
= start_addr
;
860 u16 frame_length
= 0;
862 u8 wr_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
863 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
866 GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length
/ 1024), start_addr
);
868 while (burn_length
< total_length
)
870 GTP_DEBUG("B/T:%04d/%04d", burn_length
, total_length
);
871 frame_length
= ((total_length
- burn_length
) > PACK_SIZE
) ? PACK_SIZE
: (total_length
- burn_length
);
872 wr_buf
[0] = (u8
)(burn_addr
>> 8);
873 rd_buf
[0] = wr_buf
[0];
874 wr_buf
[1] = (u8
)burn_addr
;
875 rd_buf
[1] = wr_buf
[1];
876 memcpy(&wr_buf
[GTP_ADDR_LENGTH
], &burn_buf
[burn_length
], frame_length
);
878 for (retry
= 0; retry
< MAX_FRAME_CHECK_TIME
; retry
++)
880 ret
= gup_i2c_write(client
, wr_buf
, GTP_ADDR_LENGTH
+ frame_length
);
884 GTP_ERROR("Write frame data i2c error.");
888 ret
= gup_i2c_read(client
, rd_buf
, GTP_ADDR_LENGTH
+ frame_length
);
892 GTP_ERROR("Read back frame data i2c error.");
896 if (memcmp(&wr_buf
[GTP_ADDR_LENGTH
], &rd_buf
[GTP_ADDR_LENGTH
], frame_length
))
898 GTP_ERROR("Check frame data fail,not equal.");
899 GTP_DEBUG("write array:");
900 GTP_DEBUG_ARRAY(&wr_buf
[GTP_ADDR_LENGTH
], frame_length
);
901 GTP_DEBUG("read array:");
902 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
907 //GTP_DEBUG("Check frame data success.");
911 if(retry
>= MAX_FRAME_CHECK_TIME
)
913 GTP_ERROR("Burn frame data time out,exit.");
916 burn_length
+= frame_length
;
917 burn_addr
+= frame_length
;
922 static u8
gup_load_section_file(u8
*buf
, u32 offset
, u16 length
, u8 set_or_end
)
924 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE)
925 if (HEADER_FW_READY
== got_file_flag
)
927 if(SEEK_SET
== set_or_end
)
929 memcpy(buf
, >p_default_FW
[FW_HEAD_LENGTH
+ offset
], length
);
933 memcpy(buf
, >p_default_FW
[update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
], length
);
941 if ( (update_msg
.file
== NULL
) || IS_ERR(update_msg
.file
))
943 GTP_ERROR("cannot find update file,load section file fail.");
947 if(SEEK_SET
== set_or_end
)
949 update_msg
.file
->f_pos
= FW_HEAD_LENGTH
+ offset
;
953 update_msg
.file
->f_pos
= update_msg
.fw_total_len
+ FW_HEAD_LENGTH
- offset
;
956 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, length
, &update_msg
.file
->f_pos
);
960 GTP_ERROR("Read update file fail.");
968 static u8
gup_recall_check(struct i2c_client
*client
, u8
*chk_src
, u16 start_rd_addr
, u16 chk_length
)
970 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
972 u16 recall_addr
= start_rd_addr
;
973 u16 recall_length
= 0;
974 u16 frame_length
= 0;
976 while (recall_length
< chk_length
)
978 frame_length
= ((chk_length
- recall_length
) > PACK_SIZE
) ? PACK_SIZE
: (chk_length
- recall_length
);
979 ret
= gup_get_ic_msg(client
, recall_addr
, rd_buf
, frame_length
);
983 GTP_ERROR("recall i2c error,exit");
987 if (memcmp(&rd_buf
[GTP_ADDR_LENGTH
], &chk_src
[recall_length
], frame_length
))
989 GTP_ERROR("Recall frame data fail,not equal.");
990 GTP_DEBUG("chk_src array:");
991 GTP_DEBUG_ARRAY(&chk_src
[recall_length
], frame_length
);
992 GTP_DEBUG("recall array:");
993 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
997 recall_length
+= frame_length
;
998 recall_addr
+= frame_length
;
1001 GTP_DEBUG("Recall check %dk firmware success.", (chk_length
/ 1024));
1006 static u8
gup_burn_fw_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u8 bank_cmd
)
1011 //step1:hold ss51 & dsp
1012 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1016 GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
1020 //step2:set scramble
1021 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1025 GTP_ERROR("[burn_fw_section]set scramble fail.");
1030 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1034 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1038 //step4:enable accessing code
1039 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1043 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1047 //step5:burn 8k fw section
1048 ret
= gup_burn_proc(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1052 GTP_ERROR("[burn_fw_section]burn fw_section fail.");
1056 //step6:hold ss51 & release dsp
1057 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1061 GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
1068 //step7:send burn cmd to move data to flash from sram
1069 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
& 0x0f);
1073 GTP_ERROR("[burn_fw_section]send burn cmd fail.");
1077 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1081 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1085 GTP_ERROR("[burn_fw_section]Get burn state fail");
1090 //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1092 while (rd_buf
[GTP_ADDR_LENGTH
]);
1095 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1099 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1103 //step9:enable accessing code
1104 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1108 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1112 //step10:recall 8k fw section
1113 ret
= gup_recall_check(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1117 GTP_ERROR("[burn_fw_section]recall check %dk firmware fail.", FW_SECTION_LENGTH
/1024);
1121 //step11:disable accessing code
1122 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x00);
1126 GTP_ERROR("[burn_fw_section]disable accessing code fail.");
1133 static u8
gup_burn_dsp_isp(struct i2c_client
*client
)
1136 u8
*fw_dsp_isp
= NULL
;
1140 GTP_INFO("[burn_dsp_isp]Begin burn dsp isp---->>");
1142 //step1:alloc memory
1143 GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
1147 fw_dsp_isp
= (u8
*)kzalloc(FW_DSP_ISP_LENGTH
, GFP_KERNEL
);
1149 if (fw_dsp_isp
== NULL
)
1155 GTP_DEBUG("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH
/ 1024));
1162 GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
1166 //step2:load dsp isp file data
1167 GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
1168 ret
= gup_load_section_file(fw_dsp_isp
, FW_DSP_ISP_LENGTH
, FW_DSP_ISP_LENGTH
, SEEK_END
);
1172 GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
1173 goto exit_burn_dsp_isp
;
1176 //step3:disable wdt,clear cache enable
1177 GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
1178 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1182 GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
1184 goto exit_burn_dsp_isp
;
1187 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1191 GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
1193 goto exit_burn_dsp_isp
;
1196 //step4:hold ss51 & dsp
1197 GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
1198 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1202 GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
1204 goto exit_burn_dsp_isp
;
1207 //step5:set boot from sram
1208 GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
1209 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1213 GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
1215 goto exit_burn_dsp_isp
;
1218 //step6:software reboot
1219 GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
1220 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1224 GTP_ERROR("[burn_dsp_isp]software reboot fail.");
1226 goto exit_burn_dsp_isp
;
1229 //step7:select bank2
1230 GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
1231 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1235 GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
1237 goto exit_burn_dsp_isp
;
1240 //step8:enable accessing code
1241 GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
1242 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1246 GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
1248 goto exit_burn_dsp_isp
;
1251 //step9:burn 4k dsp_isp
1252 GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
1253 ret
= gup_burn_proc(client
, fw_dsp_isp
, 0xC000, FW_DSP_ISP_LENGTH
);
1257 GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
1258 goto exit_burn_dsp_isp
;
1261 //step10:set scramble
1262 GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
1263 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1267 GTP_ERROR("[burn_dsp_isp]set scramble fail.");
1269 goto exit_burn_dsp_isp
;
1272 update_msg
.fw_burned_len
+= FW_DSP_ISP_LENGTH
;
1273 GTP_DEBUG("[burn_dsp_isp]Burned length:%d", update_msg
.fw_burned_len
);
1281 static u8
gup_burn_fw_ss51(struct i2c_client
*client
)
1287 GTP_INFO("[burn_fw_ss51]Begin burn ss51 firmware---->>");
1289 //step1:alloc memory
1290 GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
1294 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1296 if (fw_ss51
== NULL
)
1302 GTP_DEBUG("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1309 GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
1313 //step2:load ss51 firmware section 1 file data
1314 //GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
1315 //ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH, SEEK_SET);
1319 // GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
1320 // goto exit_burn_fw_ss51;
1322 GTP_INFO("[burn_fw_ss51]Reset first 8K of ss51 to 0xFF.");
1323 GTP_DEBUG("[burn_fw_ss51]step2: reset bank0 0xC000~0xD000");
1324 memset(fw_ss51
, 0xFF, FW_SECTION_LENGTH
);
1326 //step3:clear control flag
1327 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
1328 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1332 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
1334 goto exit_burn_fw_ss51
;
1337 //step4:burn ss51 firmware section 1
1338 GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
1339 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
1343 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
1344 goto exit_burn_fw_ss51
;
1347 //step5:load ss51 firmware section 2 file data
1348 GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
1349 ret
= gup_load_section_file(fw_ss51
, FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1353 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
1354 goto exit_burn_fw_ss51
;
1357 //step6:burn ss51 firmware section 2
1358 GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
1359 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x02);
1363 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
1364 goto exit_burn_fw_ss51
;
1367 //step7:load ss51 firmware section 3 file data
1368 GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
1369 ret
= gup_load_section_file(fw_ss51
, 2 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1373 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
1374 goto exit_burn_fw_ss51
;
1377 //step8:burn ss51 firmware section 3
1378 GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
1379 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x13);
1383 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
1384 goto exit_burn_fw_ss51
;
1387 //step9:load ss51 firmware section 4 file data
1388 GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
1389 ret
= gup_load_section_file(fw_ss51
, 3 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
1393 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
1394 goto exit_burn_fw_ss51
;
1397 //step10:burn ss51 firmware section 4
1398 GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
1399 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x14);
1403 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
1404 goto exit_burn_fw_ss51
;
1407 update_msg
.fw_burned_len
+= (FW_SECTION_LENGTH
*4);
1408 GTP_DEBUG("[burn_fw_ss51]Burned length:%d", update_msg
.fw_burned_len
);
1416 static u8
gup_burn_fw_dsp(struct i2c_client
*client
)
1423 GTP_INFO("[burn_fw_dsp]Begin burn dsp firmware---->>");
1424 //step1:alloc memory
1425 GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
1429 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1437 GTP_DEBUG("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1444 GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
1448 //step2:load firmware dsp
1449 GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
1450 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
, SEEK_SET
);
1454 GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
1455 goto exit_burn_fw_dsp
;
1458 //step3:select bank3
1459 GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
1460 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1464 GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
1466 goto exit_burn_fw_dsp
;
1469 //step4:hold ss51 & dsp
1470 GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
1471 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1475 GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
1477 goto exit_burn_fw_dsp
;
1480 //step5:set scramble
1481 GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
1482 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1486 GTP_ERROR("[burn_fw_dsp]set scramble fail.");
1488 goto exit_burn_fw_dsp
;
1491 //step6:release ss51 & dsp
1492 GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
1493 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121212
1497 GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
1499 goto exit_burn_fw_dsp
;
1505 //step7:burn 4k dsp firmware
1506 GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
1507 ret
= gup_burn_proc(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1511 GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
1512 goto exit_burn_fw_dsp
;
1515 //step8:send burn cmd to move data to flash from sram
1516 GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
1517 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x05);
1521 GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
1522 goto exit_burn_fw_dsp
;
1525 GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
1529 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1533 GTP_ERROR("[burn_fw_dsp]Get burn state fail");
1534 goto exit_burn_fw_dsp
;
1538 //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1540 while (rd_buf
[GTP_ADDR_LENGTH
]);
1542 //step9:recall check 4k dsp firmware
1543 GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
1544 ret
= gup_recall_check(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1548 GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
1549 goto exit_burn_fw_dsp
;
1552 update_msg
.fw_burned_len
+= FW_DSP_LENGTH
;
1553 GTP_DEBUG("[burn_fw_dsp]Burned length:%d", update_msg
.fw_burned_len
);
1561 static u8
gup_burn_fw_boot(struct i2c_client
*client
)
1568 GTP_INFO("[burn_fw_boot]Begin burn bootloader firmware---->>");
1570 //step1:Alloc memory
1571 GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
1575 fw_boot
= (u8
*)kzalloc(FW_BOOT_LENGTH
, GFP_KERNEL
);
1583 GTP_DEBUG("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH
/1024));
1590 GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
1594 //step2:load firmware bootloader
1595 GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
1596 ret
= gup_load_section_file(fw_boot
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
), FW_BOOT_LENGTH
, SEEK_SET
);
1600 GTP_ERROR("[burn_fw_boot]load firmware bootcode fail.");
1601 goto exit_burn_fw_boot
;
1604 //step3:hold ss51 & dsp
1605 GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
1606 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1609 GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
1611 goto exit_burn_fw_boot
;
1614 //step4:set scramble
1615 GTP_DEBUG("[burn_fw_boot]step4:set scramble");
1616 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1619 GTP_ERROR("[burn_fw_boot]set scramble fail.");
1621 goto exit_burn_fw_boot
;
1624 //step5:hold ss51 & release dsp
1625 GTP_DEBUG("[burn_fw_boot]step5:hold ss51 & release dsp");
1626 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1629 GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
1631 goto exit_burn_fw_boot
;
1636 //step6:select bank3
1637 GTP_DEBUG("[burn_fw_boot]step6:select bank3");
1638 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1641 GTP_ERROR("[burn_fw_boot]select bank3 fail.");
1643 goto exit_burn_fw_boot
;
1646 //step7:burn 2k bootloader firmware
1647 GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware");
1648 ret
= gup_burn_proc(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1651 GTP_ERROR("[burn_fw_boot]burn fw_boot fail.");
1652 goto exit_burn_fw_boot
;
1655 //step7:send burn cmd to move data to flash from sram
1656 GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
1657 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x06);
1660 GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
1661 goto exit_burn_fw_boot
;
1663 GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
1665 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1668 GTP_ERROR("[burn_fw_boot]Get burn state fail");
1669 goto exit_burn_fw_boot
;
1672 //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1673 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1675 //step8:recall check 2k bootloader firmware
1676 GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
1677 ret
= gup_recall_check(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1680 GTP_ERROR("[burn_fw_boot]recall check 2k bootcode firmware fail.");
1681 goto exit_burn_fw_boot
;
1684 update_msg
.fw_burned_len
+= FW_BOOT_LENGTH
;
1685 GTP_DEBUG("[burn_fw_boot]Burned length:%d", update_msg
.fw_burned_len
);
1694 static u8
gup_burn_fw_boot_isp(struct i2c_client
*client
)
1697 u8
* fw_boot_isp
= NULL
;
1701 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1703 GTP_DEBUG("No need to upgrade the boot_isp code!");
1706 GTP_INFO("[burn_fw_boot_isp]Begin burn boot_isp firmware---->>");
1708 //step1:Alloc memory
1709 GTP_DEBUG("[burn_fw_boot_isp]step1:Alloc memory");
1712 fw_boot_isp
= (u8
*)kzalloc(FW_BOOT_ISP_LENGTH
, GFP_KERNEL
);
1713 if(fw_boot_isp
== NULL
)
1719 GTP_DEBUG("[burn_fw_boot_isp]Alloc %dk byte memory success.", (FW_BOOT_ISP_LENGTH
/1024));
1725 GTP_ERROR("[burn_fw_boot_isp]Alloc memory fail,exit.");
1729 //step2:load firmware bootloader
1730 GTP_DEBUG("[burn_fw_boot_isp]step2:load firmware bootloader isp");
1731 //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);
1732 ret
= gup_load_section_file(fw_boot_isp
, (update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
), FW_BOOT_ISP_LENGTH
, SEEK_SET
);
1735 GTP_ERROR("[burn_fw_boot_isp]load firmware boot_isp fail.");
1736 goto exit_burn_fw_boot_isp
;
1739 //step3:hold ss51 & dsp
1740 GTP_DEBUG("[burn_fw_boot_isp]step3:hold ss51 & dsp");
1741 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1744 GTP_ERROR("[burn_fw_boot_isp]hold ss51 & dsp fail.");
1746 goto exit_burn_fw_boot_isp
;
1749 //step4:set scramble
1750 GTP_DEBUG("[burn_fw_boot_isp]step4:set scramble");
1751 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1754 GTP_ERROR("[burn_fw_boot_isp]set scramble fail.");
1756 goto exit_burn_fw_boot_isp
;
1760 //step5:hold ss51 & release dsp
1761 GTP_DEBUG("[burn_fw_boot_isp]step5:hold ss51 & release dsp");
1762 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121211
1765 GTP_ERROR("[burn_fw_boot_isp]release ss51 & dsp fail.");
1767 goto exit_burn_fw_boot_isp
;
1772 //step6:select bank3
1773 GTP_DEBUG("[burn_fw_boot_isp]step6:select bank3");
1774 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1777 GTP_ERROR("[burn_fw_boot_isp]select bank3 fail.");
1779 goto exit_burn_fw_boot_isp
;
1782 //step7:burn 2k bootload_isp firmware
1783 GTP_DEBUG("[burn_fw_boot_isp]step7:burn 2k bootloader firmware");
1784 ret
= gup_burn_proc(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1787 GTP_ERROR("[burn_fw_boot_isp]burn fw_section fail.");
1788 goto exit_burn_fw_boot_isp
;
1791 //step7:send burn cmd to move data to flash from sram
1792 GTP_DEBUG("[burn_fw_boot_isp]step8:send burn cmd to move data to flash from sram");
1793 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x07);
1796 GTP_ERROR("[burn_fw_boot_isp]send burn cmd fail.");
1797 goto exit_burn_fw_boot_isp
;
1799 GTP_DEBUG("[burn_fw_boot_isp]Wait for the burn is complete......");
1801 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1804 GTP_ERROR("[burn_fw_boot_isp]Get burn state fail");
1805 goto exit_burn_fw_boot_isp
;
1808 //GTP_DEBUG("[burn_fw_boot_isp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1809 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1811 //step8:recall check 2k bootload_isp firmware
1812 GTP_DEBUG("[burn_fw_boot_isp]step9:recall check 2k bootloader firmware");
1813 ret
= gup_recall_check(client
, fw_boot_isp
, 0x9000, FW_BOOT_ISP_LENGTH
);
1816 GTP_ERROR("[burn_fw_boot_isp]recall check 2k bootcode_isp firmware fail.");
1817 goto exit_burn_fw_boot_isp
;
1820 update_msg
.fw_burned_len
+= FW_BOOT_ISP_LENGTH
;
1821 GTP_DEBUG("[burn_fw_boot_isp]Burned length:%d", update_msg
.fw_burned_len
);
1824 exit_burn_fw_boot_isp
:
1829 static u8
gup_burn_fw_link(struct i2c_client
*client
)
1836 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
1838 GTP_DEBUG("No need to upgrade the link code!");
1841 GTP_INFO("[burn_fw_link]Begin burn link firmware---->>");
1843 //step1:Alloc memory
1844 GTP_DEBUG("[burn_fw_link]step1:Alloc memory");
1847 fw_link
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1854 GTP_DEBUG("[burn_fw_link]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
1860 GTP_ERROR("[burn_fw_link]Alloc memory fail,exit.");
1864 //step2:load firmware link section 1
1865 GTP_DEBUG("[burn_fw_link]step2:load firmware link section 1");
1866 offset
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
1867 ret
= gup_load_section_file(fw_link
, offset
, FW_SECTION_LENGTH
, SEEK_SET
);
1870 GTP_ERROR("[burn_fw_link]load firmware link section 1 fail.");
1871 goto exit_burn_fw_link
;
1874 //step3:burn link firmware section 1
1875 GTP_DEBUG("[burn_fw_link]step3:burn link firmware section 1");
1876 ret
= gup_burn_fw_gwake_section(client
, fw_link
, 0x9000, FW_SECTION_LENGTH
, 0x38);
1880 GTP_ERROR("[burn_fw_link]burn link firmware section 1 fail.");
1881 goto exit_burn_fw_link
;
1884 //step4:load link firmware section 2 file data
1885 GTP_DEBUG("[burn_fw_link]step4:load link firmware section 2 file data");
1886 offset
+= FW_SECTION_LENGTH
;
1887 ret
= gup_load_section_file(fw_link
, offset
, FW_GLINK_LENGTH
- FW_SECTION_LENGTH
, SEEK_SET
);
1891 GTP_ERROR("[burn_fw_link]load link firmware section 2 fail.");
1892 goto exit_burn_fw_link
;
1895 //step5:burn link firmware section 2
1896 GTP_DEBUG("[burn_fw_link]step4:burn link firmware section 2");
1897 ret
= gup_burn_fw_gwake_section(client
, fw_link
, 0x9000, FW_GLINK_LENGTH
- FW_SECTION_LENGTH
, 0x39);
1901 GTP_ERROR("[burn_fw_link]burn link firmware section 2 fail.");
1902 goto exit_burn_fw_link
;
1905 update_msg
.fw_burned_len
+= FW_GLINK_LENGTH
;
1906 GTP_DEBUG("[burn_fw_link]Burned length:%d", update_msg
.fw_burned_len
);
1914 static u8
gup_burn_fw_gwake_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u32 len
, u8 bank_cmd
)
1919 //step1:hold ss51 & dsp
1920 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1923 GTP_ERROR("[burn_fw_app_section]hold ss51 & dsp fail.");
1927 //step2:set scramble
1928 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1931 GTP_ERROR("[burn_fw_app_section]set scramble fail.");
1935 //step3:hold ss51 & release dsp
1936 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1939 GTP_ERROR("[burn_fw_app_section]hold ss51 & release dsp fail.");
1946 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4)&0x0F);
1949 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4)&0x0F);
1953 //step5:burn fw section
1954 ret
= gup_burn_proc(client
, fw_section
, start_addr
, len
);
1957 GTP_ERROR("[burn_fw_app_section]burn fw_section fail.");
1961 //step6:send burn cmd to move data to flash from sram
1962 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
&0x0F);
1965 GTP_ERROR("[burn_fw_app_section]send burn cmd fail.");
1968 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1970 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1973 GTP_ERROR("[burn_fw_app_section]Get burn state fail");
1977 //GTP_DEBUG("[burn_fw_app_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1978 }while(rd_buf
[GTP_ADDR_LENGTH
]);
1980 //step7:recall fw section
1981 ret
= gup_recall_check(client
, fw_section
, start_addr
, len
);
1984 GTP_ERROR("[burn_fw_app_section]recall check %dk firmware fail.", len
/1024);
1991 static u8
gup_burn_fw_gwake(struct i2c_client
*client
)
1993 u8
* fw_gwake
= NULL
;
1996 //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
1999 if(update_msg
.fw_burned_len
>= update_msg
.fw_total_len
)
2001 GTP_DEBUG("No need to upgrade the gwake code!");
2004 start_index
= update_msg
.fw_burned_len
- FW_DSP_ISP_LENGTH
;
2005 GTP_INFO("[burn_fw_gwake]Begin burn gwake firmware---->>");
2007 //step1:alloc memory
2008 GTP_DEBUG("[burn_fw_gwake]step1:alloc memory");
2011 fw_gwake
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2012 if(fw_gwake
== NULL
)
2018 GTP_DEBUG("[burn_fw_gwake]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2024 GTP_ERROR("[burn_fw_gwake]Alloc memory fail,exit.");
2028 //step2:load app_code firmware section 1 file data
2029 GTP_DEBUG("[burn_fw_gwake]step2:load app_code firmware section 1 file data");
2030 ret
= gup_load_section_file(fw_gwake
, start_index
, FW_SECTION_LENGTH
, SEEK_SET
);
2033 GTP_ERROR("[burn_fw_gwake]load app_code firmware section 1 fail.");
2034 goto exit_burn_fw_gwake
;
2037 //step3:burn app_code firmware section 1
2038 GTP_DEBUG("[burn_fw_gwake]step3:burn app_code firmware section 1");
2039 ret
= gup_burn_fw_gwake_section(client
, fw_gwake
, 0x9000, FW_SECTION_LENGTH
, 0x3A);
2042 GTP_ERROR("[burn_fw_gwake]burn app_code firmware section 1 fail.");
2043 goto exit_burn_fw_gwake
;
2046 //step5:load app_code firmware section 2 file data
2047 GTP_DEBUG("[burn_fw_gwake]step5:load app_code firmware section 2 file data");
2048 ret
= gup_load_section_file(fw_gwake
, start_index
+FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2051 GTP_ERROR("[burn_fw_gwake]load app_code firmware section 2 fail.");
2052 goto exit_burn_fw_gwake
;
2055 //step6:burn app_code firmware section 2
2056 GTP_DEBUG("[burn_fw_gwake]step6:burn app_code firmware section 2");
2057 ret
= gup_burn_fw_gwake_section(client
, fw_gwake
, 0x9000, FW_SECTION_LENGTH
, 0x3B);
2060 GTP_ERROR("[burn_fw_gwake]burn app_code firmware section 2 fail.");
2061 goto exit_burn_fw_gwake
;
2064 //step7:load app_code firmware section 3 file data
2065 GTP_DEBUG("[burn_fw_gwake]step7:load app_code firmware section 3 file data");
2066 ret
= gup_load_section_file(fw_gwake
, start_index
+2*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2069 GTP_ERROR("[burn_fw_gwake]load app_code firmware section 3 fail.");
2070 goto exit_burn_fw_gwake
;
2073 //step8:burn app_code firmware section 3
2074 GTP_DEBUG("[burn_fw_gwake]step8:burn app_code firmware section 3");
2075 ret
= gup_burn_fw_gwake_section(client
, fw_gwake
, 0x9000, FW_SECTION_LENGTH
, 0x3C);
2078 GTP_ERROR("[burn_fw_gwake]burn app_code firmware section 3 fail.");
2079 goto exit_burn_fw_gwake
;
2082 //step9:load app_code firmware section 4 file data
2083 GTP_DEBUG("[burn_fw_gwake]step9:load app_code firmware section 4 file data");
2084 ret
= gup_load_section_file(fw_gwake
, start_index
+ 3*FW_SECTION_LENGTH
, FW_SECTION_LENGTH
, SEEK_SET
);
2087 GTP_ERROR("[burn_fw_gwake]load app_code firmware section 4 fail.");
2088 goto exit_burn_fw_gwake
;
2091 //step10:burn app_code firmware section 4
2092 GTP_DEBUG("[burn_fw_gwake]step10:burn app_code firmware section 4");
2093 ret
= gup_burn_fw_gwake_section(client
, fw_gwake
, 0x9000, FW_SECTION_LENGTH
, 0x3D);
2096 GTP_ERROR("[burn_fw_gwake]burn app_code firmware section 4 fail.");
2097 goto exit_burn_fw_gwake
;
2100 update_msg
.fw_burned_len
+= FW_GWAKE_LENGTH
;
2101 GTP_DEBUG("[burn_fw_gwake]Burned length:%d", update_msg
.fw_burned_len
);
2109 static u8
gup_burn_fw_finish(struct i2c_client
*client
)
2115 GTP_INFO("[burn_fw_finish]burn first 8K of ss51 and finish update.");
2116 //step1:alloc memory
2117 GTP_DEBUG("[burn_fw_finish]step1:alloc memory");
2120 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
2127 GTP_DEBUG("[burn_fw_finish]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/1024));
2133 GTP_ERROR("[burn_fw_finish]Alloc memory fail,exit.");
2137 GTP_DEBUG("[burn_fw_finish]step2: burn ss51 first 8K.");
2138 ret
= gup_load_section_file(fw_ss51
, 0, FW_SECTION_LENGTH
, SEEK_SET
);
2141 GTP_ERROR("[burn_fw_finish]load ss51 firmware section 1 fail.");
2142 goto exit_burn_fw_finish
;
2145 GTP_DEBUG("[burn_fw_finish]step3:clear control flag");
2146 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2149 GTP_ERROR("[burn_fw_finish]clear control flag fail.");
2150 goto exit_burn_fw_finish
;
2153 GTP_DEBUG("[burn_fw_finish]step4:burn ss51 firmware section 1");
2154 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
2157 GTP_ERROR("[burn_fw_finish]burn ss51 firmware section 1 fail.");
2158 goto exit_burn_fw_finish
;
2161 //step11:enable download DSP code
2162 GTP_DEBUG("[burn_fw_finish]step5:enable download DSP code ");
2163 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x99);
2166 GTP_ERROR("[burn_fw_finish]enable download DSP code fail.");
2167 goto exit_burn_fw_finish
;
2170 //step12:release ss51 & hold dsp
2171 GTP_DEBUG("[burn_fw_finish]step6:release ss51 & hold dsp");
2172 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x08);
2175 GTP_ERROR("[burn_fw_finish]release ss51 & hold dsp fail.");
2176 goto exit_burn_fw_finish
;
2185 exit_burn_fw_finish
:
2193 s32
gup_update_proc(void *dir
)
2197 s32 update_ret
= FAIL
;
2200 GTP_INFO("[update_proc]Begin update ......");
2203 if (1 == searching_file
)
2206 searching_file
= 0; // exit .bin update file searching
2207 GTP_INFO("Exiting searching file for auto update.");
2208 while ((show_len
!= 200) && (show_len
!= 100) && (timeout
++ < 150)) // wait for auto update quitted completely
2218 #if GTP_COMPATIBLE_MODE
2219 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2221 return gup_fw_download_proc(dir
, GTP_FL_FW_BURN
);
2225 update_msg
.file
= NULL
;
2226 ret
= gup_check_update_file(i2c_client_point
, &fw_head
, (u8
*)dir
); //20121211
2229 GTP_ERROR("[update_proc]check update file fail.");
2233 //gtp_reset_guitar(i2c_client_point, 20);
2234 ret
= gup_get_ic_fw_msg(i2c_client_point
);
2238 GTP_ERROR("[update_proc]get ic message fail.");
2242 ret
= gup_enter_update_judge(&fw_head
); //20121212
2246 GTP_ERROR("[update_proc]Check *.bin file fail.");
2250 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
2252 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
2254 ret
= gup_enter_update_mode(i2c_client_point
);
2258 GTP_ERROR("[update_proc]enter update mode fail.");
2266 update_msg
.fw_burned_len
= 0;
2267 ret
= gup_burn_dsp_isp(i2c_client_point
);
2270 GTP_ERROR("[update_proc]burn dsp isp fail.");
2275 ret
= gup_burn_fw_ss51(i2c_client_point
);
2278 GTP_ERROR("[update_proc]burn ss51 firmware fail.");
2283 ret
= gup_burn_fw_dsp(i2c_client_point
);
2286 GTP_ERROR("[update_proc]burn dsp firmware fail.");
2291 ret
= gup_burn_fw_boot(i2c_client_point
);
2294 GTP_ERROR("[update_proc]burn bootloader firmware fail.");
2299 ret
= gup_burn_fw_boot_isp(i2c_client_point
);
2302 GTP_ERROR("[update_proc]burn boot_isp firmware fail.");
2307 ret
= gup_burn_fw_link(i2c_client_point
);
2310 GTP_ERROR("[update_proc]burn link firmware fail.");
2315 ret
= gup_burn_fw_gwake(i2c_client_point
);
2318 GTP_ERROR("[update_proc]burn app_code firmware fail.");
2323 ret
= gup_burn_fw_finish(i2c_client_point
);
2326 GTP_ERROR("[update_proc]burn finish fail.");
2330 GTP_INFO("[update_proc]UPDATE SUCCESS.");
2337 GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
2342 update_ret
= SUCCESS
;
2346 GTP_DEBUG("[update_proc]leave update mode.");
2347 gup_leave_update_mode();
2351 if (SUCCESS
== update_ret
)
2353 GTP_DEBUG("[update_proc]send config.");
2354 ret
= gtp_send_cfg(i2c_client_point
);
2357 GTP_ERROR("[update_proc]send config fail.");
2361 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2363 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
2368 if (update_msg
.file
&& !IS_ERR(update_msg
.file
))
2370 if (update_msg
.old_fs
)
2372 set_fs(update_msg
.old_fs
);
2374 filp_close(update_msg
.file
, NULL
);
2376 #if (GTP_AUTO_UPDATE && GTP_AUTO_UPDATE_CFG && GTP_HEADER_FW_UPDATE)
2379 gup_search_file(AUTO_SEARCH_CFG
);
2380 if (got_file_flag
& CFG_FILE_READY
)
2382 ret
= gup_update_config(i2c_client_point
);
2385 GTP_ERROR("Update config failed.");
2387 _CLOSE_FILE(update_msg
.cfg_file
);
2388 msleep(500); //waiting config to be stored in FLASH.
2394 if (SUCCESS
== update_ret
)
2407 u8
gup_init_update_proc(struct i2c_client
*client
)
2409 struct task_struct
*thread
= NULL
;
2411 GTP_INFO("Ready to run auto update thread");
2413 #if GTP_COMPATIBLE_MODE
2414 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
2416 thread
= kthread_run(gup_update_proc
, "update", "fl_auto_update");
2421 thread
= kthread_run(gup_update_proc
, (void *)NULL
, "guitar_update");
2425 GTP_ERROR("Failed to create update thread.\n");
2434 //******************* For GT9XXF Start ********************//
2436 #define FL_UPDATE_PATH "/data/_fl_update_.bin"
2437 #define FL_UPDATE_PATH_SD "/sdcard/_fl_update_.bin"
2439 #define FW_LITTLE_SS51_LENGTH (12 * 0x400) // 12K
2441 #define GUP_FW_CHK_SIZE 256
2442 #define MAX_CHECK_TIMES 128 // max: 2 * (16 * 1024) / 256 = 128
2445 #define PULSE_LENGTH (200)
2446 #define INIT_CLK_DAC (50)
2447 #define MAX_CLK_DAC (120)
2448 #define CLK_AVG_TIME (1)
2449 #define MILLION 1000000
2451 #define _wRW_MISCTL__RG_DMY 0x4282
2452 #define _bRW_MISCTL__RG_OSC_CALIB 0x4268
2453 #define _fRW_MISCTL__GIO0 0x41e9
2454 #define _fRW_MISCTL__GIO1 0x41ed
2455 #define _fRW_MISCTL__GIO2 0x41f1
2456 #define _fRW_MISCTL__GIO3 0x41f5
2457 #define _fRW_MISCTL__GIO4 0x41f9
2458 #define _fRW_MISCTL__GIO5 0x41fd
2459 #define _fRW_MISCTL__GIO6 0x4201
2460 #define _fRW_MISCTL__GIO7 0x4205
2461 #define _fRW_MISCTL__GIO8 0x4209
2462 #define _fRW_MISCTL__GIO9 0x420d
2463 #define _fRW_MISCTL__MEA 0x41a0
2464 #define _bRW_MISCTL__MEA_MODE 0x41a1
2465 #define _wRW_MISCTL__MEA_MAX_NUM 0x41a4
2466 #define _dRO_MISCTL__MEA_VAL 0x41b0
2467 #define _bRW_MISCTL__MEA_SRCSEL 0x41a3
2468 #define _bRO_MISCTL__MEA_RDY 0x41a8
2469 #define _rRW_MISCTL__ANA_RXADC_B0_ 0x4250
2470 #define _bRW_MISCTL__RG_LDO_A18_PWD 0x426f
2471 #define _bRW_MISCTL__RG_BG_PWD 0x426a
2472 #define _bRW_MISCTL__RG_CLKGEN_PWD 0x4269
2473 #define _fRW_MISCTL__RG_RXADC_PWD 0x426a
2474 #define _bRW_MISCTL__OSC_CK_SEL 0x4030
2475 #define _rRW_MISCTL_RG_DMY83 0x4283
2476 #define _rRW_MISCTL__GIO1CTL_B2_ 0x41ee
2477 #define _rRW_MISCTL__GIO1CTL_B1_ 0x41ed
2479 #if GTP_COMPATIBLE_MODE
2481 u8
gup_check_fs_mounted(char *path_name
)
2483 struct path root_path
;
2486 err
= kern_path("/", LOOKUP_FOLLOW
, &root_path
);
2491 err
= kern_path(path_name
, LOOKUP_FOLLOW
, &path
);
2496 if (path
.mnt
->mnt_sb
== root_path
.mnt
->mnt_sb
)
2500 path_put(&root_path
);
2506 path_put(&root_path
);
2511 s32
gup_hold_ss51_dsp(struct i2c_client
*client
)
2517 while(retry
++ < 200)
2519 #if GTP_FL_LITTLE_SYSTEM
2522 GTP_DEBUG("System power is down, exit hold ss51 & dsp.");
2526 // step4:Hold ss51 & dsp
2527 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
2530 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2534 // step5:Confirm hold
2535 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
2538 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
2541 if (0x0C == rd_buf
[GTP_ADDR_LENGTH
])
2543 GTP_DEBUG("[enter_update_mode]Hold ss51 & dsp confirm SUCCESS");
2546 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
2550 GTP_ERROR("Enter update Hold ss51 failed.");
2553 //DSP_CK and DSP_ALU_CK PowerOn
2554 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
2557 GTP_ERROR("[enter_update_mode]DSP_CK and DSP_ALU_CK PowerOn fail.");
2562 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
2566 GTP_ERROR("[enter_update_mode]disable wdt fail.");
2570 //clear cache enable
2571 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
2575 GTP_ERROR("[enter_update_mode]clear cache enable fail.");
2579 //set boot from sram
2580 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
2584 GTP_ERROR("[enter_update_mode]set boot from sram fail.");
2589 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
2592 GTP_ERROR("[enter_update_mode]software reboot fail.");
2599 s32
gup_enter_update_mode_fl(struct i2c_client
*client
)
2605 //step1:RST output low last at least 2ms
2606 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
2609 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
2610 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
2613 //step3:RST output high reset guitar
2614 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
2618 //select addr & hold ss51_dsp
2619 ret
= gup_hold_ss51_dsp(client
);
2622 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
2626 //clear control flag
2627 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2631 GTP_ERROR("[enter_update_mode]clear control flag fail.");
2636 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
2640 GTP_ERROR("[enter_update_mode]set scramble fail.");
2644 //enable accessing code
2645 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
2649 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
2657 static s32
gup_prepare_fl_fw(char *path
, st_fw_head
*fw_head
)
2663 if (!memcmp(path
, "update", 6))
2665 GTP_INFO("Search for Flashless firmware file to update");
2667 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
2669 if (0 == searching_file
)
2671 GTP_INFO("Force terminate searching file auto update.");
2674 update_msg
.file
= filp_open(FL_UPDATE_PATH
, O_RDONLY
, 0);
2675 if (IS_ERR(update_msg
.file
))
2677 update_msg
.file
= filp_open(FL_UPDATE_PATH_SD
, O_RDONLY
, 0);
2678 if (IS_ERR(update_msg
.file
))
2685 path
= FL_UPDATE_PATH_SD
;
2691 path
= FL_UPDATE_PATH
;
2698 GTP_ERROR("Search timeout, update aborted");
2703 _CLOSE_FILE(update_msg
.file
);
2705 while (rqst_processing
&& (timeout
++ < 15))
2707 GTP_INFO("wait for request process completed!");
2712 GTP_INFO("Firmware update file path: %s", path
);
2713 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
2715 if (IS_ERR(update_msg
.file
))
2717 GTP_ERROR("Open update file(%s) error!", path
);
2721 update_msg
.old_fs
= get_fs();
2723 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2724 update_msg
.fw_total_len
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_END
);
2725 if (sizeof(gtp_default_FW_fl
) != update_msg
.fw_total_len
)
2727 GTP_ERROR("Inconsistent firmware size. File size: %d, default fw size: %d", update_msg
.fw_total_len
, sizeof(gtp_default_FW_fl
));
2728 set_fs(update_msg
.old_fs
);
2729 _CLOSE_FILE(update_msg
.file
);
2733 GTP_DEBUG("Firmware size: %d", update_msg
.fw_total_len
);
2734 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2735 update_msg
.file
->f_op
->read(update_msg
.file
, (char*)fw_head
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
2737 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2738 //copy fw file to gtp_default_FW_fl array
2739 ret
= update_msg
.file
->f_op
->read(update_msg
.file
,
2740 (char*)gtp_default_FW_fl
,
2741 update_msg
.fw_total_len
,
2742 &update_msg
.file
->f_pos
);
2745 GTP_ERROR("Failed to read firmware data from %s, err-code: %d", path
, ret
);
2752 set_fs(update_msg
.old_fs
);
2753 _CLOSE_FILE(update_msg
.file
);
2757 static u8
gup_check_update_file_fl(struct i2c_client
*client
, st_fw_head
*fw_head
, char *path
)
2760 s32 fw_checksum
= 0;
2765 ret
= gup_prepare_fl_fw(path
, fw_head
);
2772 memcpy(fw_head
, gtp_default_FW_fl
, FW_HEAD_LENGTH
);
2773 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]);
2774 GTP_INFO("FILE PID:%s", fw_head
->pid
);
2775 fw_head
->vid
= ((fw_head
->vid
& 0xFF00) >> 8) + ((fw_head
->vid
& 0x00FF) << 8);
2776 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
2779 if (!memcmp(fw_head
->pid
, "912", 3))
2781 if (fw_head
->vid
> 0x1020)
2784 GTP_DEBUG("After 912_1020, config length set to 228");
2788 //check firmware legality
2790 for (i
= FW_HEAD_LENGTH
; i
< (FW_HEAD_LENGTH
+ update_msg
.fw_total_len
); i
+= 2)
2792 fw_checksum
= (gtp_default_FW_fl
[i
]<<8) + gtp_default_FW_fl
[i
+1];
2795 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
2796 if(fw_checksum
&0xFFFF)
2798 GTP_ERROR("Illegal firmware file.");
2805 #if GTP_FL_LITTLE_SYSTEM
2806 // blocksize: 256Bytes
2807 u8
gup_burn_ss51_block(struct i2c_client
*client
, s32 block_section
, s32 fw_block
, u16
*fw_chksum
)
2813 GTP_DEBUG("Burn big ss51 block%d section%d (size: 256Bytes)", fw_block
, block_section
);
2825 index
= FW_HEAD_LENGTH
+ (8 + fw_block
-1)* 1024 * 2 + (block_section
-1) * 256;
2831 index
= FW_HEAD_LENGTH
+ (16 - fw_block
) * 1024 * 2 + (block_section
-1) * 256;
2834 GTP_ERROR("Invalid firmware block: %d", fw_block
);
2838 ret
= i2c_write_bytes(client
, GTP_REG_BUFFER
+ (block_section
- 1) * 256,
2839 >p_default_FW_fl
[index
], 256);
2843 GTP_ERROR("Failed to burn ss51 block%d section%d (size: 256Bytes)!", fw_block
, block_section
);
2847 if (block_section
== 1)
2851 for (i
= 0; i
< (2 * 1024); i
+= 2)
2853 chksum
+= ((gtp_default_FW_fl
[index
+ i
]) << 8) + (gtp_default_FW_fl
[index
+ i
+ 1]);
2855 *fw_chksum
= chksum
;
2860 u8
gup_burn_ss51_seg_b(struct i2c_client
*client
, s32 size
, u16
*fw_chksum
)
2866 GTP_DEBUG("Burn big ss51 Seg B(size: %dK)", size
);
2868 ret
= i2c_write_bytes(client
, GTP_REG_SS51_SEG_B
,
2869 >p_default_FW_fl
[FW_HEAD_LENGTH
], size
* 1024);
2873 GTP_ERROR("Failed to Burn ss51 Seg B(size: %dK)", size
);
2877 for (i
= 0; i
< (size
* 1024); i
+= 2)
2879 chksum
+= ((gtp_default_FW_fl
[FW_HEAD_LENGTH
+ i
]) << 8) + gtp_default_FW_fl
[FW_HEAD_LENGTH
+ i
+ 1];
2881 *fw_chksum
= chksum
;
2885 static u8
gup_download_fw_little_ss51(struct i2c_client
*client
)
2888 GTP_INFO("Download little ss51");
2890 GTP_DEBUG("Select Bank0.");
2892 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x00);
2896 GTP_ERROR("Select bank0 fail.");
2901 ret
= i2c_write_bytes(client
, 0xC000,
2902 >p_default_FW_fl
[FW_HEAD_LENGTH
+ FW_SS51_LENGTH
+ FW_DSP_LENGTH
], FW_LITTLE_SS51_LENGTH
);
2907 GTP_ERROR("Failed to write little ss51.");
2916 static u8
gup_download_fw_ss51(struct i2c_client
*client
, u8 dwn_mode
)
2920 #if GTP_FL_LITTLE_SYSTEM
2921 if (GTP_FL_PWR_RESUME_BURN
== dwn_mode
)
2923 return gup_download_fw_little_ss51(client
);
2927 if (GTP_FL_FW_BURN
== dwn_mode
)
2929 GTP_DEBUG("[download_fw_ss51]Begin download ss51 firmware---->>");
2933 GTP_DEBUG("[download_fw_ss51]Begin check ss51 firmware----->>");
2935 //step1:download FW section 1
2936 GTP_DEBUG("[download_fw_ss51]step1:download FW section 1");
2937 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x00);
2941 GTP_ERROR("[download_fw_ss51]select bank0 fail.");
2943 goto exit_download_fw_ss51
;
2947 ret
= i2c_write_bytes(client
, 0xC000,
2948 >p_default_FW_fl
[FW_HEAD_LENGTH
], FW_DOWNLOAD_LENGTH
); // write the first bank
2952 GTP_ERROR("[download_fw_ss51]download FW section 1 fail.");
2954 goto exit_download_fw_ss51
;
2958 if (GTP_FL_FW_BURN
== dwn_mode
)
2960 ret
= gup_check_and_repair(i2c_client_point
,
2962 >p_default_FW_fl
[FW_HEAD_LENGTH
],
2963 FW_DOWNLOAD_LENGTH
);
2966 GTP_ERROR("[download_fw_ss51]Checked FW section 1 fail.");
2967 goto exit_download_fw_ss51
;
2971 //step2:download FW section 2
2972 GTP_DEBUG("[download_fw_ss51]step2:download FW section 1");
2973 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x01);
2977 GTP_ERROR("[download_fw_ss51]select bank1 fail.");
2979 goto exit_download_fw_ss51
;
2982 ret
= i2c_write_bytes(client
, 0xC000, >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],FW_DOWNLOAD_LENGTH
); // write the second bank
2986 GTP_ERROR("[download_fw_ss51]download FW section 2 fail.");
2988 goto exit_download_fw_ss51
;
2991 if (GTP_FL_FW_BURN
== dwn_mode
)
2993 ret
= gup_check_and_repair(i2c_client_point
,
2995 >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],
2996 FW_DOWNLOAD_LENGTH
);
3000 GTP_ERROR("[download_fw_ss51]Checked FW section 2 fail.");
3001 goto exit_download_fw_ss51
;
3006 exit_download_fw_ss51
:
3010 #if (!GTP_SUPPORT_I2C_DMA)
3011 static s32
i2c_auto_read(struct i2c_client
*client
,u8
*rxbuf
, int len
)
3017 struct i2c_msg msg
=
3019 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
3020 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
3022 .timing
= I2C_MASTER_CLOCK
3032 msg
.buf
= &rxbuf
[offset
];
3034 if (left
> MAX_TRANSACTION_LENGTH
)
3036 msg
.len
= MAX_TRANSACTION_LENGTH
;
3037 left
-= MAX_TRANSACTION_LENGTH
;
3038 offset
+= MAX_TRANSACTION_LENGTH
;
3048 while (i2c_transfer(client
->adapter
, &msg
, 1) != 1)
3054 GTP_ERROR("I2C read 0x%X length=%d failed\n", offset
, len
);
3064 static u8
gup_check_and_repair(struct i2c_client
*client
, s32 chk_start_addr
, u8
*target_fw
, u32 chk_total_length
)
3070 u8 chk_buf
[GUP_FW_CHK_SIZE
];
3075 chk_addr
= chk_start_addr
;
3076 while((chked_times
< MAX_CHECK_TIMES
) && (chked_len
< chk_total_length
))
3078 rd_size
= chk_total_length
- chked_len
;
3079 if(rd_size
>= GUP_FW_CHK_SIZE
)
3081 rd_size
= GUP_FW_CHK_SIZE
;
3083 #if GTP_SUPPORT_I2C_DMA
3084 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
3088 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
3092 ret
= i2c_auto_read(client
, chk_buf
, rd_size
);
3098 GTP_ERROR("Read chk ram fw i2c error");
3103 for(i
=0; i
<rd_size
; i
++)
3105 if(chk_buf
[i
] != target_fw
[i
])
3107 GTP_ERROR("Ram pos[0x%04x] checked failed,rewrite.", chk_addr
+ i
);
3108 i2c_write_bytes(client
, chk_addr
+i
, &target_fw
[i
], rd_size
-i
);
3117 GTP_DEBUG("Ram pos[0x%04X] check pass!", chk_addr
);
3118 chked_len
+= rd_size
;
3119 target_fw
+= rd_size
;
3120 chk_addr
+= rd_size
;
3129 if(chked_times
>= MAX_CHECK_TIMES
)
3131 GTP_ERROR("Ram data check failed.");
3137 static u8
__gup_download_fw_dsp(struct i2c_client
*client
, u8 dwn_mode
, int len
)
3141 if(GTP_FL_FW_BURN
== dwn_mode
)
3143 GTP_DEBUG("[download_fw_dsp]Begin download dsp fw---->>");
3147 GTP_DEBUG("[download_fw_dsp]Begin check dsp fw---->>");
3150 //step1:select bank2
3151 GTP_DEBUG("[download_fw_dsp]step1:select bank2");
3152 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
3156 GTP_ERROR("[download_fw_dsp]select bank2 fail.");
3158 goto exit_download_fw_dsp
;
3161 ret
= i2c_write_bytes(client
,
3163 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3164 len
); // write the second bank
3167 GTP_ERROR("[download_fw_dsp]download FW dsp fail.");
3169 goto exit_download_fw_dsp
;
3172 if (GTP_FL_FW_BURN
== dwn_mode
)
3174 ret
= gup_check_and_repair(client
,
3176 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
3181 GTP_ERROR("[download_fw_dsp]Checked FW dsp fail.");
3182 goto exit_download_fw_dsp
;
3188 exit_download_fw_dsp
:
3193 static u8
gup_download_fw_dsp(struct i2c_client
*client
, u8 dwn_mode
)
3195 return __gup_download_fw_dsp(client
, dwn_mode
, FW_DSP_LENGTH
);
3198 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
)
3204 #if GTP_FL_LITTLE_SYSTEM
3205 if (GTP_FL_PWR_RESUME_BURN
== dwn_mode
)
3207 GTP_INFO("[fw_download_proc]Begin poweron resume little system download.....");
3210 if(GTP_FL_FW_BURN
== dwn_mode
)
3212 GTP_INFO("[fw_download_proc]Begin fw download ......");
3216 GTP_INFO("[fw_download_proc]Begin fw check ......");
3222 ret
= gup_check_update_file_fl(i2c_client_point
, &fw_head
, (char *)dir
);
3228 GTP_ERROR("[fw_download_proc]check update file fail.");
3232 if (!memcmp(fw_head
.pid
, "950", 3))
3235 GTP_DEBUG("GT9XXF IC Type: gt950");
3244 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3246 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3250 ret
= gup_enter_update_mode_fl(i2c_client_point
);
3255 GTP_ERROR("[fw_download_proc]enter update mode fail.");
3261 ret
= gup_download_fw_ss51(i2c_client_point
, dwn_mode
);
3265 GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
3269 ret
= gup_download_fw_dsp(i2c_client_point
, dwn_mode
);
3273 GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
3276 GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
3283 GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
3289 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3290 gtp_fw_startup(i2c_client_point
);
3292 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3301 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3302 gtp_fw_startup(i2c_client_point
);
3304 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3314 static void gup_bit_write(s32 addr
, s32 bit
, s32 val
)
3317 i2c_read_bytes(i2c_client_point
, addr
, &buf
, 1);
3319 buf
= (buf
& (~((u8
)1 << bit
))) | ((u8
)val
<< bit
);
3321 i2c_write_bytes(i2c_client_point
, addr
, &buf
, 1);
3324 static void gup_clk_count_init(s32 bCh
, s32 bCNT
)
3328 //_fRW_MISCTL__MEA_EN = 0; //Frequency measure enable
3329 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3330 //_fRW_MISCTL__MEA_CLR = 1; //Frequency measure clear
3331 gup_bit_write(_fRW_MISCTL__MEA
, 1, 1);
3332 //_bRW_MISCTL__MEA_MODE = 0; //Pulse mode
3334 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_MODE
, &buf
, 1);
3335 //_bRW_MISCTL__MEA_SRCSEL = 8 + bCh; //From GIO1
3337 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_SRCSEL
, &buf
, 1);
3338 //_wRW_MISCTL__MEA_MAX_NUM = bCNT; //Set the Measure Counts = 1
3340 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__MEA_MAX_NUM
, &buf
, 1);
3341 //_fRW_MISCTL__MEA_CLR = 0; //Frequency measure not clear
3342 gup_bit_write(_fRW_MISCTL__MEA
, 1, 0);
3343 //_fRW_MISCTL__MEA_EN = 1;
3344 gup_bit_write(_fRW_MISCTL__MEA
, 0, 1);
3347 static u32
gup_clk_count_get(void)
3353 while ((ready
== 0)) //Wait for measurement complete
3355 i2c_read_bytes(i2c_client_point
, _bRO_MISCTL__MEA_RDY
, buf
, 1);
3361 //_fRW_MISCTL__MEA_EN = 0;
3362 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
3363 i2c_read_bytes(i2c_client_point
, _dRO_MISCTL__MEA_VAL
, buf
, 4);
3364 GTP_INFO("Clk_count 0: %2X", buf
[0]);
3365 GTP_INFO("Clk_count 1: %2X", buf
[1]);
3366 GTP_INFO("Clk_count 2: %2X", buf
[2]);
3367 GTP_INFO("Clk_count 3: %2X", buf
[3]);
3369 temp
= (s32
)buf
[0] + ((s32
)buf
[1] << 8) + ((s32
)buf
[2] << 16) + ((s32
)buf
[3] << 24);
3370 GTP_INFO("Clk_count : %d", temp
);
3373 u8
gup_clk_dac_setting(int dac
)
3377 i2c_read_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3378 i2c_read_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3380 buf1
= (buf1
& 0xFFCF) | ((dac
& 0x03) << 4);
3381 buf2
= (dac
>> 2) & 0x3f;
3383 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
3384 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
3389 static u8
gup_clk_calibration_pin_select(s32 bCh
)
3396 i2c_addr
= _fRW_MISCTL__GIO0
;
3400 i2c_addr
= _fRW_MISCTL__GIO1
;
3404 i2c_addr
= _fRW_MISCTL__GIO2
;
3408 i2c_addr
= _fRW_MISCTL__GIO3
;
3412 i2c_addr
= _fRW_MISCTL__GIO4
;
3416 i2c_addr
= _fRW_MISCTL__GIO5
;
3420 i2c_addr
= _fRW_MISCTL__GIO6
;
3424 i2c_addr
= _fRW_MISCTL__GIO7
;
3428 i2c_addr
= _fRW_MISCTL__GIO8
;
3432 i2c_addr
= _fRW_MISCTL__GIO9
;
3436 gup_bit_write(i2c_addr
, 1, 0);
3441 void gup_output_pulse(int t
)
3443 unsigned long flags
;
3446 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3449 local_irq_save(flags
);
3451 mt_set_gpio_out(GTP_INT_PORT
, 1);
3453 mt_set_gpio_out(GTP_INT_PORT
, 0);
3455 mt_set_gpio_out(GTP_INT_PORT
, 1);
3457 local_irq_restore(flags
);
3460 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3463 static void gup_sys_clk_init(void)
3467 //_fRW_MISCTL__RG_RXADC_CKMUX = 0;
3468 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 5, 0);
3469 //_bRW_MISCTL__RG_LDO_A18_PWD = 0; //DrvMISCTL_A18_PowerON
3471 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_LDO_A18_PWD
, &buf
, 1);
3472 //_bRW_MISCTL__RG_BG_PWD = 0; //DrvMISCTL_BG_PowerON
3474 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_BG_PWD
, &buf
, 1);
3475 //_bRW_MISCTL__RG_CLKGEN_PWD = 0; //DrvMISCTL_CLKGEN_PowerON
3477 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_CLKGEN_PWD
, &buf
, 1);
3478 //_fRW_MISCTL__RG_RXADC_PWD = 0; //DrvMISCTL_RX_ADC_PowerON
3479 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 0, 0);
3480 //_fRW_MISCTL__RG_RXADC_REF_PWD = 0; //DrvMISCTL_RX_ADCREF_PowerON
3481 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 1, 0);
3482 //gup_clk_dac_setting(60);
3483 //_bRW_MISCTL__OSC_CK_SEL = 1;;
3485 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__OSC_CK_SEL
, &buf
, 1);
3488 u8
gup_clk_calibration(void)
3493 struct timeval start
, end
;
3499 //unsigned long flags;
3501 //buf = 0x0C; // hold ss51 and dsp
3502 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3503 ret
= gup_hold_ss51_dsp(i2c_client_point
);
3506 GTP_ERROR("[gup_clk_calibration]hold ss51 & dsp failed.");
3510 //_fRW_MISCTL__CLK_BIAS = 0; //disable clock bias
3511 gup_bit_write(_rRW_MISCTL_RG_DMY83
, 7, 0);
3513 //_fRW_MISCTL__GIO1_PU = 0; //set TOUCH INT PIN MODE as input
3514 gup_bit_write(_rRW_MISCTL__GIO1CTL_B2_
, 0, 0);
3516 //_fRW_MISCTL__GIO1_OE = 0; //set TOUCH INT PIN MODE as input
3517 gup_bit_write(_rRW_MISCTL__GIO1CTL_B1_
, 1, 0);
3520 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
3523 GTP_INFO("CLK calibration GO");
3525 gup_clk_calibration_pin_select(1);//use GIO1 to do the calibration
3527 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3529 for (i
= INIT_CLK_DAC
; i
< MAX_CLK_DAC
; i
++)
3533 i
= 72; //80; // if sleeping while calibrating main clock, set it default 80
3536 GTP_INFO("CLK calibration DAC %d", i
);
3538 gup_clk_dac_setting(i
);
3539 gup_clk_count_init(1, CLK_AVG_TIME
);
3542 gup_output_pulse(PULSE_LENGTH
);
3543 count
= gup_clk_count_get();
3545 if (count
> PULSE_LENGTH
* 60)//60= 60Mhz * 1us
3551 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3553 //local_irq_save(flags);
3554 do_gettimeofday(&start
);
3555 mt_set_gpio_out(GTP_INT_PORT
, 1);
3556 //local_irq_restore(flags);
3559 mt_set_gpio_out(GTP_INT_PORT
, 0);
3562 //local_irq_save(flags);
3563 do_gettimeofday(&end
);
3564 mt_set_gpio_out(GTP_INT_PORT
, 1);
3565 //local_irq_restore(flags);
3567 count
= gup_clk_count_get();
3569 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
3571 usec
= end
.tv_usec
- start
.tv_usec
;
3572 sec
= end
.tv_sec
- start
.tv_sec
;
3573 count_ref
= 60 * (usec
+ sec
* MILLION
);//60= 60Mhz * 1us
3575 GTP_DEBUG("== time %d, %d, %d", sec
, usec
, count_ref
);
3577 if (count
> count_ref
)
3579 GTP_DEBUG("== count_diff %d", count
- count_ref
);
3588 //gtp_reset_guitar(i2c_client_point, 20);
3591 //-- ouput clk to GPIO 4
3593 i2c_write_bytes(i2c_client_point
, 0x41FA, &buf
, 1);
3595 i2c_write_bytes(i2c_client_point
, 0x4104, &buf
, 1);
3597 i2c_write_bytes(i2c_client_point
, 0x4105, &buf
, 1);
3599 i2c_write_bytes(i2c_client_point
, 0x4106, &buf
, 1);
3601 i2c_write_bytes(i2c_client_point
, 0x4107, &buf
, 1);
3603 i2c_write_bytes(i2c_client_point
, 0x41F8, &buf
, 1);
3605 i2c_write_bytes(i2c_client_point
, 0x41F9, &buf
, 1);
3608 GTP_GPIO_AS_INT(GTP_INT_PORT
);
3612 int gup_reload_fw_dsp(void *dir
, u8 dwn_mode
)
3619 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
3621 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
3625 ret
= gup_enter_update_mode_fl(i2c_client_point
);
3627 GTP_ERROR("[reload_fw_dsp]enter update mode fail.");
3631 while (retry
++ < 5) {
3632 ret
= __gup_download_fw_dsp(i2c_client_point
, dwn_mode
, FW_DSP_LENGTH
/ 2); //reload 2k dsp code
3634 GTP_ERROR("[reload_fw_dsp]burn dsp firmware fail.");
3637 GTP_DEBUG("[reload_fw_dsp]UPDATE SUCCESS.");
3643 GTP_ERROR("[reload_fw_dsp]retry timeout,RELOAD FW DSP FAIL.");
3648 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3649 gtp_fw_startup(i2c_client_point
);
3651 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3654 ret
= i2c_write_bytes(i2c_client_point
, 0x801F, &value
, 1); // clear gesture mode reg
3663 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
3664 gtp_fw_startup(i2c_client_point
);
3666 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
3672 //*************** For GT9XXF End ***********************//