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 || defined(SELF_APK_UPGRADE) )
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
76 #define MAX_FRAME_CHECK_TIME 5
78 #define _bRW_MISCTL__SRAM_BANK 0x4048
79 #define _bRW_MISCTL__MEM_CD_EN 0x4049
80 #define _bRW_MISCTL__CACHE_EN 0x404B
81 #define _bRW_MISCTL__TMR0_EN 0x40B0
82 #define _rRW_MISCTL__SWRST_B0_ 0x4180
83 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
84 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
85 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
86 #define _rRW_MISCTL__BOOT_CTL_ 0x5094
88 #define AUTO_SEARCH_BIN 0x01
89 #define AUTO_SEARCH_CFG 0x02
90 #define BIN_FILE_READY 0x80
91 #define CFG_FILE_READY 0x08
92 #define HEADER_FW_READY 0x01
100 u8 hw_info
[4]; //hardware info//
101 u8 pid
[8]; //product id //
102 u16 vid
; //version id //
111 struct file
*cfg_file
;
112 st_fw_head ic_fw_msg
;
116 st_update_msg update_msg
;
117 extern struct i2c_client
*i2c_client_point
;
120 extern u8 fw_updating
;
122 u8 searching_file
= 0;
123 u8 got_file_flag
= 0;
126 extern void gtp_esd_switch(struct i2c_client
*client
, s32 on
);
129 #if GTP_COMPATIBLE_MODE
130 extern CHIP_TYPE_T gtp_chip_type
;
131 extern u8 rqst_processing
;
133 extern u8
gtp_fw_startup(struct i2c_client
*client
);
134 static u8
gup_check_and_repair(struct i2c_client
*, s32
, u8
*, u32
);
135 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
);
138 #define _CLOSE_FILE(p_file) if (p_file && !IS_ERR(p_file)) \
140 filp_close(p_file, NULL); \
143 static s32
gup_i2c_read(struct i2c_client
*client
, u8
*buf
, s32 len
)
146 u16 addr
= (buf
[0] << 8) + buf
[1];
148 ret
= i2c_read_bytes(client
, addr
, &buf
[2], len
- 2);
160 static s32
gup_i2c_write(struct i2c_client
*client
, u8
*buf
, s32 len
)
163 u16 addr
= (buf
[0] << 8) + buf
[1];
165 ret
= i2c_write_bytes(client
, addr
, &buf
[2], len
- 2);
177 static u8
gup_get_ic_msg(struct i2c_client
*client
, u16 addr
, u8
*msg
, s32 len
)
181 msg
[0] = (addr
>> 8) & 0xff;
182 msg
[1] = addr
& 0xff;
184 for (i
= 0; i
< 5; i
++)
186 if (gup_i2c_read(client
, msg
, GTP_ADDR_LENGTH
+ len
) > 0)
194 GTP_ERROR("Read data from 0x%02x%02x failed!", msg
[0], msg
[1]);
201 static u8
gup_set_ic_msg(struct i2c_client
*client
, u16 addr
, u8 val
)
206 msg
[0] = (addr
>> 8) & 0xff;
207 msg
[1] = addr
& 0xff;
210 for (i
= 0; i
< 5; i
++)
212 if (gup_i2c_write(client
, msg
, GTP_ADDR_LENGTH
+ 1) > 0)
220 GTP_ERROR("Set data to 0x%02x%02x failed!", msg
[0], msg
[1]);
227 static u8
gup_get_ic_fw_msg(struct i2c_client
*client
)
234 //step1:get hardware info
235 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_HW_INFO
, &buf
[GTP_ADDR_LENGTH
], 4);
238 GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit");
242 // buf[2~5]: 00 06 90 00
243 // hw_info: 00 90 06 00
244 for (i
= 0; i
< 4; i
++)
246 update_msg
.ic_fw_msg
.hw_info
[i
] = buf
[GTP_ADDR_LENGTH
+ 3 - i
];
249 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],
250 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
252 //step2:get firmware message
253 for (retry
= 0; retry
< 2; retry
++)
255 ret
= gup_get_ic_msg(client
, GUP_REG_FW_MSG
, buf
, 1);
259 GTP_ERROR("Read firmware message fail.");
263 update_msg
.force_update
= buf
[GTP_ADDR_LENGTH
];
265 if ((0xBE != update_msg
.force_update
) && (!retry
))
267 GTP_INFO("The check sum in ic is error.");
268 GTP_INFO("The IC will be updated by force.");
274 GTP_INFO("IC force update flag:0x%x", update_msg
.force_update
);
276 //step3:get pid & vid
277 ret
= gtp_i2c_read_dbl_check(client
, GUP_REG_PID_VID
, &buf
[GTP_ADDR_LENGTH
], 6);
280 GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit");
284 memset(update_msg
.ic_fw_msg
.pid
, 0, sizeof(update_msg
.ic_fw_msg
.pid
));
285 memcpy(update_msg
.ic_fw_msg
.pid
, &buf
[GTP_ADDR_LENGTH
], 4);
289 /*|-----FLASH-----RAM-----|
290 |------918------918-----|
291 |------968------968-----|
292 |------913------913-----|
293 |------913P-----913P----|
294 |------927------927-----|
295 |------927P-----927P----|
296 |------9110-----9110----|
297 |------9110P----9111----|*/
298 if(update_msg
.ic_fw_msg
.pid
[0] != 0)
300 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "9111", 4))
302 GTP_INFO("IC Mapping Product id:%s", update_msg
.ic_fw_msg
.pid
);
303 memcpy(update_msg
.ic_fw_msg
.pid
, "9110P", 5);
307 update_msg
.ic_fw_msg
.vid
= buf
[GTP_ADDR_LENGTH
+ 4] + (buf
[GTP_ADDR_LENGTH
+ 5] << 8);
311 // add by anxiang.xiao 20131114
313 function : get file firmware version in firmware.h
315 void get_file_fw_version(u16
*file_fw_version
)
317 st_fw_head file_fw_head
;
319 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
321 memcpy(&file_fw_head
, gtp_default_FW_fl
, FW_HEAD_LENGTH
);
325 memcpy(&file_fw_head
, gtp_default_FW
, FW_HEAD_LENGTH
);
327 *file_fw_version
= ((file_fw_head
.vid
& 0xFF00) >> 8) + ((file_fw_head
.vid
& 0x00FF) << 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
)
400 //Get the correct nvram data
401 //The correct conditions:
402 //1. the hardware info is the same
403 //2. the product id is the same
404 //3. the firmware version in update file is greater than the firmware version in ic
405 //or the check sum in ic is wrong
407 u16_tmp
= fw_head
->vid
;
408 fw_head
->vid
= (u16
)(u16_tmp
>> 8) + (u16
)(u16_tmp
<< 8);
410 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]);
411 GTP_INFO("FILE PID:%s", fw_head
->pid
);
412 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
413 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],
414 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
415 GTP_INFO("IC PID:%s", update_msg
.ic_fw_msg
.pid
);
416 GTP_INFO("IC VID:%04x", update_msg
.ic_fw_msg
.vid
);
418 //First two conditions
419 if (!memcmp(fw_head
->hw_info
, update_msg
.ic_fw_msg
.hw_info
, sizeof(update_msg
.ic_fw_msg
.hw_info
)))
421 GTP_INFO("Get the same hardware info.");
422 if (update_msg
.force_update
!= 0xBE)
424 GTP_INFO("FW chksum error,need enter update.");
429 if (strlen(update_msg
.ic_fw_msg
.pid
) < 3)
431 GTP_INFO("Illegal IC pid, need enter update");
436 for (i
= 0; i
< 3; i
++)
438 if ((update_msg
.ic_fw_msg
.pid
[i
] < 0x30) || (update_msg
.ic_fw_msg
.pid
[i
] > 0x39))
440 GTP_INFO("Illegal IC pid, out of bound, need enter update");
447 pid_cmp_len
= strlen(fw_head
->pid
);
448 if (pid_cmp_len
< strlen(update_msg
.ic_fw_msg
.pid
))
450 pid_cmp_len
= strlen(update_msg
.ic_fw_msg
.pid
);
453 if ((!memcmp(fw_head
->pid
, update_msg
.ic_fw_msg
.pid
, pid_cmp_len
)) ||
454 (!memcmp(update_msg
.ic_fw_msg
.pid
, "91XX", 4)) ||
455 (!memcmp(fw_head
->pid
, "91XX", 4)))
457 if(!memcmp(fw_head
->pid
, "91XX", 4))
459 GTP_DEBUG("Force none same pid update mode.");
463 GTP_DEBUG("Get the same pid.");
466 //The third condition
467 if (fw_head
->vid
> update_msg
.ic_fw_msg
.vid
)
470 GTP_INFO("Need enter update.");
474 GTP_INFO("Don't meet the third condition.");
475 GTP_ERROR("File VID <= IC VID, update aborted!");
479 GTP_ERROR("File PID != IC PID, update aborted!");
484 GTP_ERROR("Different Hardware, update aborted!");
490 #if GTP_AUTO_UPDATE_CFG
491 static s32
gup_update_config(struct i2c_client
*client
)
493 struct file
*cfg_filp
;
498 u8 gt_config
[228] = {0};
499 char *sconfig
= NULL
;
502 cfg_filp
= update_msg
.cfg_file
;
504 if (IS_ERR(cfg_filp
))
506 GTP_ERROR("Config file is Invalid");
510 cfg_filp
->f_op
->llseek(cfg_filp
, 0, SEEK_SET
);
511 file_len
= cfg_filp
->f_op
->llseek(cfg_filp
, 0, SEEK_END
);
513 GTP_DEBUG("file len: %d", file_len
);
514 if (file_len
< (cfg_len
* 3))
516 GTP_ERROR("invalid config file, config update aborted!");
517 _CLOSE_FILE(cfg_filp
);
521 sconfig
= (char *)kmalloc(sizeof(char) * (file_len
+ 1), GFP_KERNEL
);
522 memset(sconfig
, 0, sizeof(char) * (file_len
+ 1));
524 cfg_filp
->f_op
->llseek(cfg_filp
, 0, SEEK_SET
);
525 ret
= cfg_filp
->f_op
->read(cfg_filp
, sconfig
, file_len
, &cfg_filp
->f_pos
);
526 _CLOSE_FILE(cfg_filp
);
529 GTP_ERROR("failed to read config file");
533 GTP_DEBUG("sconfig: %s", sconfig
);
535 for (ret
= 0, i
= 0; ret
< file_len
; ++ret
)
537 if ((sconfig
[ret
] == ' ') ||
538 (sconfig
[ret
] == '\n') ||
539 (sconfig
[ret
] == '\r') ||
540 (sconfig
[ret
] == '\t') ||
541 (sconfig
[ret
] == '\\')
546 sconfig
[i
++] = sconfig
[ret
];
548 GTP_DEBUG("After cleanup: %d", i
);
551 sscanf(sconfig
, "0x%02X", &cfg
);
552 gt_config
[0] = (u8
)cfg
;
553 for (ret
= 4, i
= 1; ret
< file_len
; ret
+= 5)
555 sscanf(sconfig
+ret
, ",0x%02X", &cfg
);
556 gt_config
[i
] = (u8
)cfg
;
562 GTP_INFO("File config len: %d", i
);
563 GTP_DEBUG_ARRAY(gt_config
, i
);
566 for (ret
= 0; ret
< (i
-2); ++ret
)
568 chksum
+= gt_config
[ret
];
570 chksum
= (~chksum
) + 1;
571 if (chksum
!= gt_config
[i
-2])
573 GTP_ERROR("Wrong checksum, config update aborted!");
577 if (gt_config
[i
-1] != 0x01)
579 GTP_ERROR("Unsetted config update flag, config update aborted!");
583 ret
= i2c_write_bytes(client
, GTP_REG_CONFIG_DATA
, gt_config
, i
);
587 GTP_ERROR("write config data failed, config update failed!");
590 GTP_INFO("Config update successfully!");
591 msleep(500); // ic store config info into flash
598 #if GTP_AUTO_UPDATE || defined(SELF_APK_UPGRADE)
599 static void gup_search_file(s32 search_type
)
602 struct file
*pfile
= NULL
;
604 got_file_flag
= 0x00;
607 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
609 if (0 == searching_file
)
611 GTP_INFO("Force exiting file searching");
612 got_file_flag
= 0x00;
616 if (search_type
& AUTO_SEARCH_BIN
)
618 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
);
619 pfile
= filp_open(UPDATE_FILE_PATH_1
, O_RDONLY
, 0);
622 pfile
= filp_open(UPDATE_FILE_PATH_2
, O_RDONLY
, 0);
625 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_2
);
626 got_file_flag
|= BIN_FILE_READY
;
627 update_msg
.file
= pfile
;
632 GTP_INFO("Bin file: %s for fw update.", UPDATE_FILE_PATH_1
);
633 got_file_flag
|= BIN_FILE_READY
;
634 update_msg
.file
= pfile
;
636 if (got_file_flag
& BIN_FILE_READY
)
638 #if GTP_AUTO_UPDATE_CFG
639 if (search_type
& AUTO_SEARCH_CFG
)
641 i
= GUP_SEARCH_FILE_TIMES
; // Bin & Cfg File required to be in the same directory
652 #if GTP_AUTO_UPDATE_CFG
653 if ( (search_type
& AUTO_SEARCH_CFG
) && !(got_file_flag
& CFG_FILE_READY
) )
655 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
);
656 pfile
= filp_open(CONFIG_FILE_PATH_1
, O_RDONLY
, 0);
659 pfile
= filp_open(CONFIG_FILE_PATH_2
, O_RDONLY
, 0);
662 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_2
);
663 got_file_flag
|= CFG_FILE_READY
;
664 update_msg
.cfg_file
= pfile
;
669 GTP_INFO("Cfg file: %s for config update.", CONFIG_FILE_PATH_1
);
670 got_file_flag
|= CFG_FILE_READY
;
671 update_msg
.cfg_file
= pfile
;
673 if (got_file_flag
& CFG_FILE_READY
)
686 static u8
gup_check_update_file(struct i2c_client
*client
, st_fw_head
*fw_head
, u8
*path
)
691 u8 buf
[FW_HEAD_LENGTH
];
693 got_file_flag
= 0x00;
696 GTP_DEBUG("Update File path:%s, %d", path
, strlen(path
));
697 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
699 if (IS_ERR(update_msg
.file
))
701 GTP_ERROR("Open update file(%s) error!", path
);
704 got_file_flag
= BIN_FILE_READY
;
708 #if GTP_AUTO_UPDATE || defined(SELF_APK_UPGRADE)
709 #if GTP_HEADER_FW_UPDATE
710 GTP_INFO("Update by default firmware array");
711 if (sizeof(gtp_default_FW
) < (FW_HEAD_LENGTH
+ FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
))
713 GTP_INFO("[check_update_file]default firmware array is INVALID!");
716 memcpy(buf
, >p_default_FW
[0], FW_HEAD_LENGTH
);
717 memcpy(fw_head
, buf
, FW_HEAD_LENGTH
);
718 //check firmware legality
720 for(i
=0; i
<FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
; i
+=2)
723 memcpy(buf
, >p_default_FW
[FW_HEAD_LENGTH
+ i
], 2);
724 temp
= (buf
[0]<<8) + buf
[1];
728 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
729 if(fw_checksum
&0xFFFF)
731 GTP_ERROR("Illegal firmware file.");
734 got_file_flag
= HEADER_FW_READY
;
738 #if GTP_AUTO_UPDATE_CFG
739 gup_search_file(AUTO_SEARCH_BIN
| AUTO_SEARCH_CFG
);
740 if (got_file_flag
& CFG_FILE_READY
)
742 ret
= gup_update_config(client
);
745 GTP_ERROR("Update config failed!");
749 gup_search_file(AUTO_SEARCH_BIN
);
752 if (!(got_file_flag
& BIN_FILE_READY
))
754 GTP_ERROR("No bin file for fw Update");
760 GTP_ERROR("NULL file for fw update!");
766 update_msg
.old_fs
= get_fs();
769 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
771 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
775 GTP_ERROR("Read firmware head in update file error.");
779 memcpy(fw_head
, buf
, FW_HEAD_LENGTH
);
781 //check firmware legality
783 for(i
=0; i
<FW_SECTION_LENGTH
*4+FW_DSP_ISP_LENGTH
+FW_DSP_LENGTH
+FW_BOOT_LENGTH
; i
+=2)
786 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char*)buf
, 2, &update_msg
.file
->f_pos
);
789 GTP_ERROR("Read firmware file error.");
792 //GTP_DEBUG("BUF[0]:%x", buf[0]);
793 temp
= (buf
[0]<<8) + buf
[1];
797 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
798 if(fw_checksum
&0xFFFF)
800 GTP_ERROR("Illegal firmware file.");
807 set_fs(update_msg
.old_fs
);
808 _CLOSE_FILE(update_msg
.file
);
812 static u8
gup_burn_proc(struct i2c_client
*client
, u8
*burn_buf
, u16 start_addr
, u16 total_length
)
815 u16 burn_addr
= start_addr
;
816 u16 frame_length
= 0;
818 u8 wr_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
819 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
822 GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length
/ 1024), start_addr
);
824 while (burn_length
< total_length
)
826 GTP_DEBUG("B/T:%04d/%04d", burn_length
, total_length
);
827 frame_length
= ((total_length
- burn_length
) > PACK_SIZE
) ? PACK_SIZE
: (total_length
- burn_length
);
828 wr_buf
[0] = (u8
)(burn_addr
>> 8);
829 rd_buf
[0] = wr_buf
[0];
830 wr_buf
[1] = (u8
)burn_addr
;
831 rd_buf
[1] = wr_buf
[1];
832 memcpy(&wr_buf
[GTP_ADDR_LENGTH
], &burn_buf
[burn_length
], frame_length
);
834 for (retry
= 0; retry
< MAX_FRAME_CHECK_TIME
; retry
++)
836 ret
= gup_i2c_write(client
, wr_buf
, GTP_ADDR_LENGTH
+ frame_length
);
840 GTP_ERROR("Write frame data i2c error.");
844 ret
= gup_i2c_read(client
, rd_buf
, GTP_ADDR_LENGTH
+ frame_length
);
848 GTP_ERROR("Read back frame data i2c error.");
852 if (memcmp(&wr_buf
[GTP_ADDR_LENGTH
], &rd_buf
[GTP_ADDR_LENGTH
], frame_length
))
854 GTP_ERROR("Check frame data fail,not equal.");
855 GTP_DEBUG("write array:");
856 GTP_DEBUG_ARRAY(&wr_buf
[GTP_ADDR_LENGTH
], frame_length
);
857 GTP_DEBUG("read array:");
858 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
863 //GTP_DEBUG("Check frame data success.");
868 if (retry
> MAX_FRAME_CHECK_TIME
)
870 GTP_ERROR("Burn frame data time out,exit.");
874 burn_length
+= frame_length
;
875 burn_addr
+= frame_length
;
881 static u8
gup_load_section_file(u8
*buf
, u16 offset
, u16 length
)
883 #if ((GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE) || defined(SELF_APK_UPGRADE) )
884 if (HEADER_FW_READY
== got_file_flag
)
886 memcpy(buf
, >p_default_FW
[FW_HEAD_LENGTH
+ offset
], length
);
893 if (update_msg
.file
== NULL
)
895 GTP_ERROR("cannot find update file,load section file fail.");
899 update_msg
.file
->f_pos
= FW_HEAD_LENGTH
+ offset
;
901 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)buf
, length
, &update_msg
.file
->f_pos
);
905 GTP_ERROR("Read update file fail.");
913 static u8
gup_recall_check(struct i2c_client
*client
, u8
*chk_src
, u16 start_rd_addr
, u16 chk_length
)
915 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
917 u16 recall_addr
= start_rd_addr
;
918 u16 recall_length
= 0;
919 u16 frame_length
= 0;
921 while (recall_length
< chk_length
)
923 frame_length
= ((chk_length
- recall_length
) > PACK_SIZE
) ? PACK_SIZE
: (chk_length
- recall_length
);
924 ret
= gup_get_ic_msg(client
, recall_addr
, rd_buf
, frame_length
);
928 GTP_ERROR("recall i2c error,exit");
932 if (memcmp(&rd_buf
[GTP_ADDR_LENGTH
], &chk_src
[recall_length
], frame_length
))
934 GTP_ERROR("Recall frame data fail,not equal.");
935 GTP_DEBUG("chk_src array:");
936 GTP_DEBUG_ARRAY(&chk_src
[recall_length
], frame_length
);
937 GTP_DEBUG("recall array:");
938 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
942 recall_length
+= frame_length
;
943 recall_addr
+= frame_length
;
946 GTP_DEBUG("Recall check %dk firmware success.", (chk_length
/ 1024));
951 static u8
gup_burn_fw_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u8 bank_cmd
)
956 //step1:hold ss51 & dsp
957 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
961 GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
966 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
970 GTP_ERROR("[burn_fw_section]set scramble fail.");
975 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
979 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
983 //step4:enable accessing code
984 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
988 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
992 //step5:burn 8k fw section
993 ret
= gup_burn_proc(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
997 GTP_ERROR("[burn_fw_section]burn fw_section fail.");
1001 //step6:hold ss51 & release dsp
1002 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
1006 GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
1013 //step7:send burn cmd to move data to flash from sram
1014 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
& 0x0f);
1018 GTP_ERROR("[burn_fw_section]send burn cmd fail.");
1022 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
1026 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1030 GTP_ERROR("[burn_fw_section]Get burn state fail");
1035 //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1037 while (rd_buf
[GTP_ADDR_LENGTH
]);
1040 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
1044 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
1048 //step9:enable accessing code
1049 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1053 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
1057 //step10:recall 8k fw section
1058 ret
= gup_recall_check(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
1062 GTP_ERROR("[burn_fw_section]recall check 8k firmware fail.");
1066 //step11:disable accessing code
1067 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x00);
1071 GTP_ERROR("[burn_fw_section]disable accessing code fail.");
1078 static u8
gup_burn_dsp_isp(struct i2c_client
*client
)
1081 u8
*fw_dsp_isp
= NULL
;
1084 GTP_INFO("[burn_dsp_isp]Begin burn dsp isp---->>");
1086 //step1:alloc memory
1087 GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
1091 fw_dsp_isp
= (u8
*)kzalloc(FW_DSP_ISP_LENGTH
, GFP_KERNEL
);
1093 if (fw_dsp_isp
== NULL
)
1099 GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH
/ 1024));
1106 GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
1110 //step2:load dsp isp file data
1111 GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
1112 ret
= gup_load_section_file(fw_dsp_isp
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
+ FW_BOOT_LENGTH
), FW_DSP_ISP_LENGTH
);
1116 GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
1117 goto exit_burn_dsp_isp
;
1120 //step3:disable wdt,clear cache enable
1121 GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
1122 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1126 GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
1128 goto exit_burn_dsp_isp
;
1131 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1135 GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
1137 goto exit_burn_dsp_isp
;
1140 //step4:hold ss51 & dsp
1141 GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
1142 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1146 GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
1148 goto exit_burn_dsp_isp
;
1151 //step5:set boot from sram
1152 GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
1153 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1157 GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
1159 goto exit_burn_dsp_isp
;
1162 //step6:software reboot
1163 GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
1164 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1168 GTP_ERROR("[burn_dsp_isp]software reboot fail.");
1170 goto exit_burn_dsp_isp
;
1173 //step7:select bank2
1174 GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
1175 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1179 GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
1181 goto exit_burn_dsp_isp
;
1184 //step8:enable accessing code
1185 GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
1186 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1190 GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
1192 goto exit_burn_dsp_isp
;
1195 //step9:burn 4k dsp_isp
1196 GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
1197 ret
= gup_burn_proc(client
, fw_dsp_isp
, 0xC000, FW_DSP_ISP_LENGTH
);
1201 GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
1202 goto exit_burn_dsp_isp
;
1205 //step10:set scramble
1206 GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
1207 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1211 GTP_ERROR("[burn_dsp_isp]set scramble fail.");
1213 goto exit_burn_dsp_isp
;
1223 static u8
gup_burn_fw_ss51(struct i2c_client
*client
)
1229 GTP_INFO("[burn_fw_ss51]Begin burn ss51 firmware---->>");
1231 //step1:alloc memory
1232 GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
1236 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1238 if (fw_ss51
== NULL
)
1244 GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1251 GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
1255 //step2:load ss51 firmware section 1 file data
1256 GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
1257 ret
= gup_load_section_file(fw_ss51
, 0, FW_SECTION_LENGTH
);
1261 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
1262 goto exit_burn_fw_ss51
;
1265 //step3:clear control flag
1266 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
1267 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1271 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
1273 goto exit_burn_fw_ss51
;
1276 //step4:burn ss51 firmware section 1
1277 GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
1278 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
1282 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
1283 goto exit_burn_fw_ss51
;
1286 //step5:load ss51 firmware section 2 file data
1287 GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
1288 ret
= gup_load_section_file(fw_ss51
, FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1292 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
1293 goto exit_burn_fw_ss51
;
1296 //step6:burn ss51 firmware section 2
1297 GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
1298 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x02);
1302 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
1303 goto exit_burn_fw_ss51
;
1306 //step7:load ss51 firmware section 3 file data
1307 GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
1308 ret
= gup_load_section_file(fw_ss51
, 2 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1312 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
1313 goto exit_burn_fw_ss51
;
1316 //step8:burn ss51 firmware section 3
1317 GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
1318 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x13);
1322 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
1323 goto exit_burn_fw_ss51
;
1326 //step9:load ss51 firmware section 4 file data
1327 GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
1328 ret
= gup_load_section_file(fw_ss51
, 3 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1332 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
1333 goto exit_burn_fw_ss51
;
1336 //step10:burn ss51 firmware section 4
1337 GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
1338 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x14);
1342 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
1343 goto exit_burn_fw_ss51
;
1353 static u8
gup_burn_fw_dsp(struct i2c_client
*client
)
1360 GTP_INFO("[burn_fw_dsp]Begin burn dsp firmware---->>");
1361 //step1:alloc memory
1362 GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
1366 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1374 GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1381 GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
1385 //step2:load firmware dsp
1386 GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
1387 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
);
1391 GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
1392 goto exit_burn_fw_dsp
;
1395 //step3:select bank3
1396 GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
1397 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1401 GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
1403 goto exit_burn_fw_dsp
;
1406 //step4:hold ss51 & dsp
1407 GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
1408 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1412 GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
1414 goto exit_burn_fw_dsp
;
1417 //step5:set scramble
1418 GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
1419 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1423 GTP_ERROR("[burn_fw_dsp]set scramble fail.");
1425 goto exit_burn_fw_dsp
;
1428 //step6:release ss51 & dsp
1429 GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
1430 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121212
1434 GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
1436 goto exit_burn_fw_dsp
;
1442 //step7:burn 4k dsp firmware
1443 GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
1444 ret
= gup_burn_proc(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1448 GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
1449 goto exit_burn_fw_dsp
;
1452 //step8:send burn cmd to move data to flash from sram
1453 GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
1454 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x05);
1458 GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
1459 goto exit_burn_fw_dsp
;
1462 GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
1466 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1470 GTP_ERROR("[burn_fw_dsp]Get burn state fail");
1471 goto exit_burn_fw_dsp
;
1475 //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1477 while (rd_buf
[GTP_ADDR_LENGTH
]);
1479 //step9:recall check 4k dsp firmware
1480 GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
1481 ret
= gup_recall_check(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1485 GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
1486 goto exit_burn_fw_dsp
;
1496 static u8
gup_burn_fw_boot(struct i2c_client
*client
)
1503 GTP_INFO("[burn_fw_boot]Begin burn bootloader firmware---->>");
1505 //step1:Alloc memory
1506 GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
1510 fw_boot
= (u8
*)kzalloc(FW_BOOT_LENGTH
, GFP_KERNEL
);
1512 if (fw_boot
== NULL
)
1518 GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH
/ 1024));
1525 GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
1529 //step2:load firmware bootloader
1530 GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
1531 ret
= gup_load_section_file(fw_boot
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
), FW_BOOT_LENGTH
);
1535 GTP_ERROR("[burn_fw_boot]load firmware dsp fail.");
1536 goto exit_burn_fw_boot
;
1539 //step3:hold ss51 & dsp
1540 GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
1541 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1545 GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
1547 goto exit_burn_fw_boot
;
1550 //step4:set scramble
1551 GTP_DEBUG("[burn_fw_boot]step4:set scramble");
1552 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1556 GTP_ERROR("[burn_fw_boot]set scramble fail.");
1558 goto exit_burn_fw_boot
;
1561 //step5:release ss51 & dsp
1562 GTP_DEBUG("[burn_fw_boot]step5:release ss51 & dsp");
1563 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04); //20121212
1567 GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
1569 goto exit_burn_fw_boot
;
1575 //step6:burn 2k bootloader firmware
1576 GTP_DEBUG("[burn_fw_boot]step6:burn 2k bootloader firmware");
1577 ret
= gup_burn_proc(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1581 GTP_ERROR("[burn_fw_boot]burn fw_section fail.");
1582 goto exit_burn_fw_boot
;
1585 //step7:send burn cmd to move data to flash from sram
1586 GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
1587 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x06);
1591 GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
1592 goto exit_burn_fw_boot
;
1595 GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
1599 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1603 GTP_ERROR("[burn_fw_boot]Get burn state fail");
1604 goto exit_burn_fw_boot
;
1608 //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1610 while (rd_buf
[GTP_ADDR_LENGTH
]);
1612 //step8:recall check 2k bootloader firmware
1613 GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
1614 ret
= gup_recall_check(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1618 GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail.");
1619 goto exit_burn_fw_boot
;
1622 //step9:enable download DSP code
1623 GTP_DEBUG("[burn_fw_boot]step9:enable download DSP code ");
1624 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x99);
1628 GTP_ERROR("[burn_fw_boot]enable download DSP code fail.");
1630 goto exit_burn_fw_boot
;
1633 //step10:release ss51 & hold dsp
1634 GTP_DEBUG("[burn_fw_boot]step10:release ss51 & hold dsp");
1635 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x08);
1639 GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail.");
1641 goto exit_burn_fw_boot
;
1651 s32
gup_update_proc(void *dir
)
1655 s32 update_ret
= FAIL
;
1658 GTP_INFO("[update_proc]Begin update ......");
1660 #if GTP_AUTO_UPDATE || defined(SELF_APK_UPGRADE)
1661 if (1 == searching_file
)
1664 searching_file
= 0; // exit .bin update file searching
1665 GTP_INFO("Exiting searching file for auto update.");
1666 while ((show_len
!= 200) && (show_len
!= 100) && (timeout
++ < 150)) // wait for auto update quitted completely
1676 #if GTP_COMPATIBLE_MODE
1677 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1679 return gup_fw_download_proc(dir
, GTP_FL_FW_BURN
);
1682 ret
= gup_check_update_file(i2c_client_point
, &fw_head
, (u8
*)dir
); //20121212
1686 GTP_ERROR("[update_proc]check update file fail.");
1690 //gtp_reset_guitar(i2c_client_point, 20);
1691 ret
= gup_get_ic_fw_msg(i2c_client_point
);
1695 GTP_ERROR("[update_proc]get ic message fail.");
1699 ret
= gup_enter_update_judge(&fw_head
); //20121212
1703 GTP_ERROR("[update_proc]Check *.bin file fail.");
1707 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1709 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
1711 ret
= gup_enter_update_mode(i2c_client_point
);
1715 GTP_ERROR("[update_proc]enter update mode fail.");
1723 ret
= gup_burn_dsp_isp(i2c_client_point
);
1727 GTP_ERROR("[update_proc]burn dsp isp fail.");
1732 ret
= gup_burn_fw_ss51(i2c_client_point
);
1736 GTP_ERROR("[update_proc]burn ss51 firmware fail.");
1741 ret
= gup_burn_fw_dsp(i2c_client_point
);
1745 GTP_ERROR("[update_proc]burn dsp firmware fail.");
1750 ret
= gup_burn_fw_boot(i2c_client_point
);
1753 GTP_ERROR("[update_proc]burn bootloader firmware fail.");
1758 GTP_INFO("[update_proc]UPDATE SUCCESS.");
1764 GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
1769 update_ret
= SUCCESS
;
1773 if (got_file_flag
& BIN_FILE_READY
)
1775 if (update_msg
.old_fs
)
1777 set_fs(update_msg
.old_fs
);
1780 GTP_DEBUG("[update_proc]leave update mode.");
1781 gup_leave_update_mode();
1783 if (SUCCESS
== update_ret
)
1785 GTP_DEBUG("[update_proc]send config.");
1786 ret
= gtp_send_cfg(i2c_client_point
);
1789 GTP_ERROR("[update_proc]send config fail.");
1793 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1795 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
1800 _CLOSE_FILE(update_msg
.file
);
1802 #if (GTP_AUTO_UPDATE && GTP_HEADER_FW_UPDATE && GTP_AUTO_UPDATE_CFG)
1805 gup_search_file(AUTO_SEARCH_CFG
);
1806 if (got_file_flag
& CFG_FILE_READY
)
1808 ret
= gup_update_config(i2c_client_point
);
1811 GTP_ERROR("Update config failed!");
1818 if (SUCCESS
== update_ret
)
1830 u8
gup_init_update_proc(struct i2c_client
*client
)
1832 struct task_struct
*thread
= NULL
;
1834 GTP_INFO("Ready to run auto update thread");
1836 #if GTP_COMPATIBLE_MODE
1837 if (CHIP_TYPE_GT9F
== gtp_chip_type
)
1839 thread
= kthread_run(gup_update_proc
, "update", "fl_auto_update");
1844 thread
= kthread_run(gup_update_proc
, (void *)NULL
, "guitar_update");
1848 GTP_ERROR("Failed to create update thread.\n");
1856 //******************* For GT9XXF Start ********************//
1858 #define FL_UPDATE_PATH "/data/_fl_update_.bin"
1859 #define FL_UPDATE_PATH_SD "/sdcard/_fl_update_.bin"
1861 #define GUP_FW_CHK_SIZE 256
1862 #define MAX_CHECK_TIMES 128 // max: 2 * (16 * 1024) / 256 = 128
1865 #define PULSE_LENGTH (200)
1866 #define INIT_CLK_DAC (50)
1867 #define MAX_CLK_DAC (120)
1868 #define CLK_AVG_TIME (1)
1869 #define MILLION 1000000
1871 #define _wRW_MISCTL__RG_DMY 0x4282
1872 #define _bRW_MISCTL__RG_OSC_CALIB 0x4268
1873 #define _fRW_MISCTL__GIO0 0x41e9
1874 #define _fRW_MISCTL__GIO1 0x41ed
1875 #define _fRW_MISCTL__GIO2 0x41f1
1876 #define _fRW_MISCTL__GIO3 0x41f5
1877 #define _fRW_MISCTL__GIO4 0x41f9
1878 #define _fRW_MISCTL__GIO5 0x41fd
1879 #define _fRW_MISCTL__GIO6 0x4201
1880 #define _fRW_MISCTL__GIO7 0x4205
1881 #define _fRW_MISCTL__GIO8 0x4209
1882 #define _fRW_MISCTL__GIO9 0x420d
1883 #define _fRW_MISCTL__MEA 0x41a0
1884 #define _bRW_MISCTL__MEA_MODE 0x41a1
1885 #define _wRW_MISCTL__MEA_MAX_NUM 0x41a4
1886 #define _dRO_MISCTL__MEA_VAL 0x41b0
1887 #define _bRW_MISCTL__MEA_SRCSEL 0x41a3
1888 #define _bRO_MISCTL__MEA_RDY 0x41a8
1889 #define _rRW_MISCTL__ANA_RXADC_B0_ 0x4250
1890 #define _bRW_MISCTL__RG_LDO_A18_PWD 0x426f
1891 #define _bRW_MISCTL__RG_BG_PWD 0x426a
1892 #define _bRW_MISCTL__RG_CLKGEN_PWD 0x4269
1893 #define _fRW_MISCTL__RG_RXADC_PWD 0x426a
1894 #define _bRW_MISCTL__OSC_CK_SEL 0x4030
1895 #define _rRW_MISCTL_RG_DMY83 0x4283
1896 #define _rRW_MISCTL__GIO1CTL_B2_ 0x41ee
1897 #define _rRW_MISCTL__GIO1CTL_B1_ 0x41ed
1899 #if GTP_COMPATIBLE_MODE
1901 u8
gup_check_fs_mounted(char *path_name
)
1903 struct path root_path
;
1906 err
= kern_path("/", LOOKUP_FOLLOW
, &root_path
);
1911 err
= kern_path(path_name
, LOOKUP_FOLLOW
, &path
);
1916 if (path
.mnt
->mnt_sb
== root_path
.mnt
->mnt_sb
)
1927 s32
gup_hold_ss51_dsp(struct i2c_client
*client
)
1933 while(retry
++ < 200)
1935 // step4:Hold ss51 & dsp
1936 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1939 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
1943 // step5:Confirm hold
1944 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
1947 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
1950 if (0x0C == rd_buf
[GTP_ADDR_LENGTH
])
1952 GTP_DEBUG("[enter_update_mode]Hold ss51 & dsp confirm SUCCESS");
1955 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
1959 GTP_ERROR("Enter update Hold ss51 failed.");
1962 //DSP_CK and DSP_ALU_CK PowerOn
1963 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
1966 GTP_ERROR("[enter_update_mode]DSP_CK and DSP_ALU_CK PowerOn fail.");
1971 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1975 GTP_ERROR("[enter_update_mode]disable wdt fail.");
1979 //clear cache enable
1980 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1984 GTP_ERROR("[enter_update_mode]clear cache enable fail.");
1988 //set boot from sram
1989 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1993 GTP_ERROR("[enter_update_mode]set boot from sram fail.");
1998 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
2001 GTP_ERROR("[enter_update_mode]software reboot fail.");
2008 s32
gup_enter_update_mode_fl(struct i2c_client
*client
)
2014 //step1:RST output low last at least 2ms
2015 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
2018 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
2019 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
2022 //step3:RST output high reset guitar
2023 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
2027 //select addr & hold ss51_dsp
2028 ret
= gup_hold_ss51_dsp(client
);
2031 GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
2035 //clear control flag
2036 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
2040 GTP_ERROR("[enter_update_mode]clear control flag fail.");
2045 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
2049 GTP_ERROR("[enter_update_mode]set scramble fail.");
2053 //enable accessing code
2054 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
2058 GTP_ERROR("[enter_update_mode]enable accessing code fail.");
2066 static s32
gup_prepare_fl_fw(char *path
, st_fw_head
*fw_head
)
2072 if (!memcmp(path
, "update", 6))
2074 GTP_INFO("Search for Flashless firmware file to update");
2076 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; ++i
)
2078 if (0 == searching_file
)
2080 GTP_INFO("Force terminate searching file auto update.");
2083 update_msg
.file
= filp_open(FL_UPDATE_PATH
, O_RDONLY
, 0);
2084 if (IS_ERR(update_msg
.file
))
2086 update_msg
.file
= filp_open(FL_UPDATE_PATH_SD
, O_RDONLY
, 0);
2087 if (IS_ERR(update_msg
.file
))
2094 path
= FL_UPDATE_PATH_SD
;
2100 path
= FL_UPDATE_PATH
;
2107 GTP_ERROR("Search timeout, update aborted");
2112 _CLOSE_FILE(update_msg
.file
);
2114 while (rqst_processing
&& (timeout
++ < 15))
2116 GTP_INFO("wait for request process completed!");
2121 GTP_INFO("Firmware update file path: %s", path
);
2122 update_msg
.file
= filp_open(path
, O_RDONLY
, 0);
2124 if (IS_ERR(update_msg
.file
))
2126 GTP_ERROR("Open update file(%s) error!", path
);
2130 ret
= gup_get_ic_fw_msg(i2c_client_point
);
2133 GTP_ERROR("failed to get ic firmware info");
2134 _CLOSE_FILE(update_msg
.file
);
2138 update_msg
.old_fs
= get_fs();
2140 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2141 update_msg
.file
->f_op
->read(update_msg
.file
, (char*)fw_head
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
2143 ret
= gup_enter_update_judge(fw_head
);
2146 set_fs(update_msg
.old_fs
);
2147 _CLOSE_FILE(update_msg
.file
);
2151 update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
2152 //copy fw file to gtp_default_FW_fl array
2153 ret
= update_msg
.file
->f_op
->read(update_msg
.file
,
2154 (char*)gtp_default_FW_fl
,
2155 FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
+FW_DSP_LENGTH
,
2156 &update_msg
.file
->f_pos
);
2159 GTP_ERROR("Failed to read firmware data from %s, err-code: %d", path
, ret
);
2166 set_fs(update_msg
.old_fs
);
2167 _CLOSE_FILE(update_msg
.file
);
2171 static u8
gup_check_update_file_fl(struct i2c_client
*client
, st_fw_head
*fw_head
, char *path
)
2174 s32 fw_checksum
= 0;
2179 ret
= gup_prepare_fl_fw(path
, fw_head
);
2187 memcpy(fw_head
, gtp_default_FW_fl
, FW_HEAD_LENGTH
);
2188 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]);
2189 GTP_INFO("FILE PID:%s", fw_head
->pid
);
2190 fw_head
->vid
= ((fw_head
->vid
& 0xFF00) >> 8) + ((fw_head
->vid
& 0x00FF) << 8);
2191 GTP_INFO("FILE VID:%04x", fw_head
->vid
);
2194 //check firmware legality
2196 for(i
=FW_HEAD_LENGTH
; i
<FW_HEAD_LENGTH
+FW_SECTION_LENGTH
*4+FW_DSP_LENGTH
; i
+=2)
2200 //GTP_DEBUG("BUF[0]:%x", buf[0]);
2201 temp
= (gtp_default_FW_fl
[i
]<<8) + gtp_default_FW_fl
[i
+1];
2202 fw_checksum
+= temp
;
2205 GTP_DEBUG("firmware checksum:%x", fw_checksum
&0xFFFF);
2206 if(fw_checksum
&0xFFFF)
2208 GTP_ERROR("Illegal firmware file.");
2216 static u8
gup_download_fw_ss51(struct i2c_client
*client
, u8 dwn_mode
)
2220 if(GTP_FL_FW_BURN
== dwn_mode
)
2222 GTP_INFO("[download_fw_ss51]Begin download ss51 firmware---->>");
2226 GTP_INFO("[download_fw_ss51]Begin check ss51 firmware----->>");
2228 //step1:download FW section 1
2229 GTP_DEBUG("[download_fw_ss51]step1:download FW section 1");
2230 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x00);
2234 GTP_ERROR("[download_fw_ss51]select bank0 fail.");
2236 goto exit_download_fw_ss51
;
2240 ret
= i2c_write_bytes(client
, 0xC000,
2241 >p_default_FW_fl
[FW_HEAD_LENGTH
], FW_DOWNLOAD_LENGTH
); // write the first bank
2245 GTP_ERROR("[download_fw_ss51]download FW section 1 fail.");
2247 goto exit_download_fw_ss51
;
2251 if (GTP_FL_FW_BURN
== dwn_mode
)
2253 ret
= gup_check_and_repair(i2c_client_point
,
2255 >p_default_FW_fl
[FW_HEAD_LENGTH
],
2256 FW_DOWNLOAD_LENGTH
);
2259 GTP_ERROR("[download_fw_ss51]Checked FW section 1 fail.");
2260 goto exit_download_fw_ss51
;
2264 //step2:download FW section 2
2265 GTP_DEBUG("[download_fw_ss51]step2:download FW section 1");
2266 ret
= gup_set_ic_msg(i2c_client_point
, _bRW_MISCTL__SRAM_BANK
, 0x01);
2270 GTP_ERROR("[download_fw_ss51]select bank1 fail.");
2272 goto exit_download_fw_ss51
;
2275 ret
= i2c_write_bytes(client
, 0xC000, >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],FW_DOWNLOAD_LENGTH
); // write the second bank
2279 GTP_ERROR("[download_fw_ss51]download FW section 2 fail.");
2281 goto exit_download_fw_ss51
;
2284 if (GTP_FL_FW_BURN
== dwn_mode
)
2286 ret
= gup_check_and_repair(i2c_client_point
,
2288 >p_default_FW_fl
[FW_HEAD_LENGTH
+FW_DOWNLOAD_LENGTH
],
2289 FW_DOWNLOAD_LENGTH
);
2293 GTP_ERROR("[download_fw_ss51]Checked FW section 2 fail.");
2294 goto exit_download_fw_ss51
;
2299 exit_download_fw_ss51
:
2303 #if (!GTP_SUPPORT_I2C_DMA)
2304 static s32
i2c_auto_read(struct i2c_client
*client
,u8
*rxbuf
, int len
)
2310 struct i2c_msg msg
=
2312 //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
2313 .addr
= ((client
->addr
&I2C_MASK_FLAG
) | (I2C_PUSHPULL_FLAG
)),
2315 .timing
= I2C_MASTER_CLOCK
2325 msg
.buf
= &rxbuf
[offset
];
2327 if (left
> MAX_TRANSACTION_LENGTH
)
2329 msg
.len
= MAX_TRANSACTION_LENGTH
;
2330 left
-= MAX_TRANSACTION_LENGTH
;
2331 offset
+= MAX_TRANSACTION_LENGTH
;
2341 while (i2c_transfer(client
->adapter
, &msg
, 1) != 1)
2347 GTP_ERROR("I2C read 0x%X length=%d failed\n", offset
, len
);
2356 static u8
gup_check_and_repair(struct i2c_client
*client
, s32 chk_start_addr
, u8
*target_fw
, u32 chk_total_length
)
2362 u8 chk_buf
[GUP_FW_CHK_SIZE
];
2367 chk_addr
= chk_start_addr
;
2368 while((chked_times
< MAX_CHECK_TIMES
) && (chked_len
< chk_total_length
))
2370 rd_size
= chk_total_length
- chked_len
;
2371 if(rd_size
>= GUP_FW_CHK_SIZE
)
2373 rd_size
= GUP_FW_CHK_SIZE
;
2375 #if GTP_SUPPORT_I2C_DMA
2376 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
2380 ret
= i2c_read_bytes(client
, chk_addr
, chk_buf
, rd_size
);
2384 ret
= i2c_auto_read(client
, chk_buf
, rd_size
);
2390 GTP_ERROR("Read chk ram fw i2c error");
2395 for(i
=0; i
<rd_size
; i
++)
2397 if(chk_buf
[i
] != target_fw
[i
])
2399 GTP_ERROR("Ram pos[0x%04x] checked failed,rewrite.", chk_addr
+ i
);
2400 i2c_write_bytes(client
, chk_addr
+i
, &target_fw
[i
], rd_size
-i
);
2409 GTP_DEBUG("Ram pos[0x%04X] check pass!", chk_addr
);
2410 chked_len
+= rd_size
;
2411 target_fw
+= rd_size
;
2412 chk_addr
+= rd_size
;
2421 if(chked_times
>= MAX_CHECK_TIMES
)
2423 GTP_ERROR("Ram data check failed.");
2429 static u8
gup_download_fw_dsp(struct i2c_client
*client
, u8 dwn_mode
)
2433 if(GTP_FL_FW_BURN
== dwn_mode
)
2435 GTP_INFO("[download_fw_dsp]Begin download dsp fw---->>");
2439 GTP_INFO("[download_fw_dsp]Begin check dsp fw---->>");
2442 //step1:select bank2
2443 GTP_DEBUG("[download_fw_dsp]step1:select bank2");
2444 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
2448 GTP_ERROR("[download_fw_dsp]select bank2 fail.");
2450 goto exit_download_fw_dsp
;
2453 ret
= i2c_write_bytes(client
,
2455 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
2456 FW_DSP_LENGTH
); // write the second bank
2459 GTP_ERROR("[download_fw_dsp]download FW dsp fail.");
2461 goto exit_download_fw_dsp
;
2464 if (GTP_FL_FW_BURN
== dwn_mode
)
2466 ret
= gup_check_and_repair(client
,
2468 >p_default_FW_fl
[FW_HEAD_LENGTH
+2*FW_DOWNLOAD_LENGTH
],
2473 GTP_ERROR("[download_fw_dsp]Checked FW dsp fail.");
2474 goto exit_download_fw_dsp
;
2480 exit_download_fw_dsp
:
2485 s32
gup_fw_download_proc(void *dir
, u8 dwn_mode
)
2491 if(GTP_FL_FW_BURN
== dwn_mode
)
2493 GTP_INFO("[fw_download_proc]Begin fw download ......");
2497 GTP_INFO("[fw_download_proc]Begin fw check ......");
2502 ret
= gup_check_update_file_fl(i2c_client_point
, &fw_head
, (char *)dir
);
2508 GTP_ERROR("[fw_download_proc]check update file fail.");
2512 if (!memcmp(fw_head
.pid
, "950", 3))
2515 GTP_DEBUG("GT9XXF IC Type: gt950");
2522 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
2526 gtp_esd_switch(i2c_client_point
, SWITCH_OFF
);
2530 ret
= gup_enter_update_mode_fl(i2c_client_point
);
2535 GTP_ERROR("[fw_download_proc]enter update mode fail.");
2541 ret
= gup_download_fw_ss51(i2c_client_point
, dwn_mode
);
2545 GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
2549 ret
= gup_download_fw_dsp(i2c_client_point
, dwn_mode
);
2553 GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
2557 GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
2563 GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
2569 gtp_fw_startup(i2c_client_point
);
2571 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
2575 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2581 gtp_fw_startup(i2c_client_point
);
2583 gtp_esd_switch(i2c_client_point
, SWITCH_ON
);
2589 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
2594 static void gup_bit_write(s32 addr
, s32 bit
, s32 val
)
2597 i2c_read_bytes(i2c_client_point
, addr
, &buf
, 1);
2599 buf
= (buf
& (~((u8
)1 << bit
))) | ((u8
)val
<< bit
);
2601 i2c_write_bytes(i2c_client_point
, addr
, &buf
, 1);
2604 static void gup_clk_count_init(s32 bCh
, s32 bCNT
)
2608 //_fRW_MISCTL__MEA_EN = 0; //Frequency measure enable
2609 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
2610 //_fRW_MISCTL__MEA_CLR = 1; //Frequency measure clear
2611 gup_bit_write(_fRW_MISCTL__MEA
, 1, 1);
2612 //_bRW_MISCTL__MEA_MODE = 0; //Pulse mode
2614 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_MODE
, &buf
, 1);
2615 //_bRW_MISCTL__MEA_SRCSEL = 8 + bCh; //From GIO1
2617 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__MEA_SRCSEL
, &buf
, 1);
2618 //_wRW_MISCTL__MEA_MAX_NUM = bCNT; //Set the Measure Counts = 1
2620 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__MEA_MAX_NUM
, &buf
, 1);
2621 //_fRW_MISCTL__MEA_CLR = 0; //Frequency measure not clear
2622 gup_bit_write(_fRW_MISCTL__MEA
, 1, 0);
2623 //_fRW_MISCTL__MEA_EN = 1;
2624 gup_bit_write(_fRW_MISCTL__MEA
, 0, 1);
2627 static u32
gup_clk_count_get(void)
2633 while ((ready
== 0)) //Wait for measurement complete
2635 i2c_read_bytes(i2c_client_point
, _bRO_MISCTL__MEA_RDY
, buf
, 1);
2641 //_fRW_MISCTL__MEA_EN = 0;
2642 gup_bit_write(_fRW_MISCTL__MEA
, 0, 0);
2643 i2c_read_bytes(i2c_client_point
, _dRO_MISCTL__MEA_VAL
, buf
, 4);
2644 GTP_INFO("Clk_count 0: %2X", buf
[0]);
2645 GTP_INFO("Clk_count 1: %2X", buf
[1]);
2646 GTP_INFO("Clk_count 2: %2X", buf
[2]);
2647 GTP_INFO("Clk_count 3: %2X", buf
[3]);
2649 temp
= (s32
)buf
[0] + ((s32
)buf
[1] << 8) + ((s32
)buf
[2] << 16) + ((s32
)buf
[3] << 24);
2650 GTP_INFO("Clk_count : %d", temp
);
2653 u8
gup_clk_dac_setting(int dac
)
2657 i2c_read_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
2658 i2c_read_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
2660 buf1
= (buf1
& 0xFFCF) | ((dac
& 0x03) << 4);
2661 buf2
= (dac
>> 2) & 0x3f;
2663 i2c_write_bytes(i2c_client_point
, _wRW_MISCTL__RG_DMY
, &buf1
, 1);
2664 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_OSC_CALIB
, &buf2
, 1);
2669 static u8
gup_clk_calibration_pin_select(s32 bCh
)
2676 i2c_addr
= _fRW_MISCTL__GIO0
;
2680 i2c_addr
= _fRW_MISCTL__GIO1
;
2684 i2c_addr
= _fRW_MISCTL__GIO2
;
2688 i2c_addr
= _fRW_MISCTL__GIO3
;
2692 i2c_addr
= _fRW_MISCTL__GIO4
;
2696 i2c_addr
= _fRW_MISCTL__GIO5
;
2700 i2c_addr
= _fRW_MISCTL__GIO6
;
2704 i2c_addr
= _fRW_MISCTL__GIO7
;
2708 i2c_addr
= _fRW_MISCTL__GIO8
;
2712 i2c_addr
= _fRW_MISCTL__GIO9
;
2716 gup_bit_write(i2c_addr
, 1, 0);
2721 void gup_output_pulse(int t
)
2723 unsigned long flags
;
2726 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2729 local_irq_save(flags
);
2731 mt_set_gpio_out(GTP_INT_PORT
, 1);
2733 mt_set_gpio_out(GTP_INT_PORT
, 0);
2735 mt_set_gpio_out(GTP_INT_PORT
, 1);
2737 local_irq_restore(flags
);
2740 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2743 static void gup_sys_clk_init(void)
2747 //_fRW_MISCTL__RG_RXADC_CKMUX = 0;
2748 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 5, 0);
2749 //_bRW_MISCTL__RG_LDO_A18_PWD = 0; //DrvMISCTL_A18_PowerON
2751 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_LDO_A18_PWD
, &buf
, 1);
2752 //_bRW_MISCTL__RG_BG_PWD = 0; //DrvMISCTL_BG_PowerON
2754 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_BG_PWD
, &buf
, 1);
2755 //_bRW_MISCTL__RG_CLKGEN_PWD = 0; //DrvMISCTL_CLKGEN_PowerON
2757 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__RG_CLKGEN_PWD
, &buf
, 1);
2758 //_fRW_MISCTL__RG_RXADC_PWD = 0; //DrvMISCTL_RX_ADC_PowerON
2759 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 0, 0);
2760 //_fRW_MISCTL__RG_RXADC_REF_PWD = 0; //DrvMISCTL_RX_ADCREF_PowerON
2761 gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_
, 1, 0);
2762 //gup_clk_dac_setting(60);
2763 //_bRW_MISCTL__OSC_CK_SEL = 1;;
2765 i2c_write_bytes(i2c_client_point
, _bRW_MISCTL__OSC_CK_SEL
, &buf
, 1);
2768 u8
gup_clk_calibration(void)
2773 struct timeval start
, end
;
2779 //unsigned long flags;
2781 //buf = 0x0C; // hold ss51 and dsp
2782 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
2783 ret
= gup_hold_ss51_dsp(i2c_client_point
);
2786 GTP_ERROR("[gup_clk_calibration]hold ss51 & dsp failed.");
2790 //_fRW_MISCTL__CLK_BIAS = 0; //disable clock bias
2791 gup_bit_write(_rRW_MISCTL_RG_DMY83
, 7, 0);
2793 //_fRW_MISCTL__GIO1_PU = 0; //set TOUCH INT PIN MODE as input
2794 gup_bit_write(_rRW_MISCTL__GIO1CTL_B2_
, 0, 0);
2796 //_fRW_MISCTL__GIO1_OE = 0; //set TOUCH INT PIN MODE as input
2797 gup_bit_write(_rRW_MISCTL__GIO1CTL_B1_
, 1, 0);
2800 //i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
2803 GTP_INFO("CLK calibration GO");
2805 gup_clk_calibration_pin_select(1);//use GIO1 to do the calibration
2807 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2809 for (i
= INIT_CLK_DAC
; i
< MAX_CLK_DAC
; i
++)
2813 i
= 80; // if sleeping while calibrating main clock, set it default 80
2816 GTP_INFO("CLK calibration DAC %d", i
);
2818 gup_clk_dac_setting(i
);
2819 gup_clk_count_init(1, CLK_AVG_TIME
);
2822 gup_output_pulse(PULSE_LENGTH
);
2823 count
= gup_clk_count_get();
2825 if (count
> PULSE_LENGTH
* 60)//60= 60Mhz * 1us
2831 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2833 //local_irq_save(flags);
2834 do_gettimeofday(&start
);
2835 mt_set_gpio_out(GTP_INT_PORT
, 1);
2836 //local_irq_restore(flags);
2839 mt_set_gpio_out(GTP_INT_PORT
, 0);
2842 //local_irq_save(flags);
2843 do_gettimeofday(&end
);
2844 mt_set_gpio_out(GTP_INT_PORT
, 1);
2845 //local_irq_restore(flags);
2847 count
= gup_clk_count_get();
2849 GTP_GPIO_OUTPUT(GTP_INT_PORT
, 0);
2851 usec
= end
.tv_usec
- start
.tv_usec
;
2852 sec
= end
.tv_sec
- start
.tv_sec
;
2853 count_ref
= 60 * (usec
+ sec
* MILLION
);//60= 60Mhz * 1us
2855 GTP_DEBUG("== time %d, %d, %d", sec
, usec
, count_ref
);
2857 if (count
> count_ref
)
2859 GTP_DEBUG("== count_diff %d", count
- count_ref
);
2868 //gtp_reset_guitar(i2c_client_point, 20);
2871 //-- ouput clk to GPIO 4
2873 i2c_write_bytes(i2c_client_point
, 0x41FA, &buf
, 1);
2875 i2c_write_bytes(i2c_client_point
, 0x4104, &buf
, 1);
2877 i2c_write_bytes(i2c_client_point
, 0x4105, &buf
, 1);
2879 i2c_write_bytes(i2c_client_point
, 0x4106, &buf
, 1);
2881 i2c_write_bytes(i2c_client_point
, 0x4107, &buf
, 1);
2883 i2c_write_bytes(i2c_client_point
, 0x41F8, &buf
, 1);
2885 i2c_write_bytes(i2c_client_point
, 0x41F9, &buf
, 1);
2888 GTP_GPIO_AS_INT(GTP_INT_PORT
);
2893 //*************** For GT9XXF End ***********************//