1 /* drivers/input/touchscreen/gt813_827_828_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.
17 * V1.0:2012/08/31,first release.
18 * V1.2:2012/10/15,add force update,GT9110P pid map
21 #include <linux/interrupt.h>
22 #include <cust_eint.h>
23 #include <linux/i2c.h>
24 #include <linux/sched.h>
25 #include <linux/kthread.h>
26 #include <linux/rtpm_prio.h>
27 #include <linux/wait.h>
28 #include <linux/time.h>
29 #include <linux/delay.h>
30 #include <linux/namei.h>
31 #include <linux/mount.h>
32 #include "cust_gpio_usage.h"
33 #include <asm/uaccess.h>
36 #include "tpd_custom_gt9xx.h"
38 #define GUP_REG_HW_INFO 0x4220
39 #define GUP_REG_FW_MSG 0x41E4
40 #define GUP_REG_PID_VID 0x8140
42 //#define GTP_BOOT_FW_CONFIG_SD_UPDATE
43 #define GUP_SEARCH_FILE_TIMES 50
44 #define UPDATE_FILE_PATH_2 "/data/goodix/_goodix_update_.bin"
45 #define UPDATE_FILE_PATH_1 "/sdcard/goodix/_goodix_update_.bin"
47 #define CONFIG_FILE_PATH_2 "/data/goodix/_goodix_config_.cfg"
48 #define CONFIG_FILE_PATH_1 "/sdcard/goodix/_goodix_config_.cfg"
50 #define FW_HEAD_LENGTH 14
51 #define FW_SECTION_LENGTH 0x2000
52 #define FW_DSP_ISP_LENGTH 0x1000
53 #define FW_DSP_LENGTH 0x1000
54 #define FW_BOOT_LENGTH 0x800
55 #define FW_DOWNLOAD_LENGTH 0x4000
56 #define FW_LENGTH (4*FW_SECTION_LENGTH+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH)
59 #define MAX_FRAME_CHECK_TIME 5
61 #define _bRW_MISCTL__SRAM_BANK 0x4048
62 #define _bRW_MISCTL__MEM_CD_EN 0x4049
63 #define _bRW_MISCTL__CACHE_EN 0x404B
64 #define _bRW_MISCTL__TMR0_EN 0x40B0
65 #define _rRW_MISCTL__SWRST_B0_ 0x4180
66 #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
67 #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
68 #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
69 #define _rRW_MISCTL__BOOT_CTL_ 0x5094
77 u8 hw_info
[4]; //hardware info//
78 u8 pid
[8]; //product id //
79 u16 vid
; //version id //
88 struct file
*cfg_file
;
93 st_update_msg update_msg
;
94 struct i2c_client
*guitar_client
= NULL
;
95 extern struct i2c_client
*i2c_client_point
;
100 extern s32
gtp_i2c_read(struct i2c_client
*client
, uint8_t *buf
, s32 len
);
101 extern s32
gtp_i2c_write(struct i2c_client
*client
, uint8_t *data
, s32 len
);
102 extern void gtp_reset_guitar(struct i2c_client
*client
, s32 ms
);
103 extern s32
gtp_send_cfg(struct i2c_client
*client
);
105 static u8
gup_get_ic_msg(struct i2c_client
*client
, u16 addr
, u8
*msg
, s32 len
)
109 msg
[0] = (addr
>> 8) & 0xff;
110 msg
[1] = addr
& 0xff;
112 for (i
= 0; i
< 5; i
++)
114 if (gtp_i2c_read(client
, msg
, GTP_ADDR_LENGTH
+ len
) > 0)
122 GTP_ERROR("Read data from 0x%02x%02x failed!", msg
[0], msg
[1]);
129 static u8
gup_set_ic_msg(struct i2c_client
*client
, u16 addr
, u8 val
)
134 msg
[0] = (addr
>> 8) & 0xff;
135 msg
[1] = addr
& 0xff;
138 for (i
= 0; i
< 5; i
++)
140 if (gtp_i2c_write(client
, msg
, GTP_ADDR_LENGTH
+ 1) > 0)
148 GTP_ERROR("Set data to 0x%02x%02x failed!", msg
[0], msg
[1]);
155 static u8
gup_get_ic_fw_msg(struct i2c_client
*client
)
162 //step1:get hardware info
163 ret
= gup_get_ic_msg(client
, GUP_REG_HW_INFO
, buf
, 4);
167 GTP_ERROR("Read hardware info fail.");
171 memcpy(update_msg
.ic_fw_msg
.hw_info
, &buf
[GTP_ADDR_LENGTH
], 4);
173 for (i
= 0; i
< 4; i
++)
175 update_msg
.ic_fw_msg
.hw_info
[i
] = buf
[GTP_ADDR_LENGTH
+ 3 - i
];
178 GTP_DEBUG("IC Hardware info:%02x%02x%02x%02x", update_msg
.ic_fw_msg
.hw_info
[0], update_msg
.ic_fw_msg
.hw_info
[1],
179 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
181 //step2:get firmware message
182 for (retry
= 0; retry
< 2; retry
++)
184 ret
= gup_get_ic_msg(client
, GUP_REG_FW_MSG
, buf
, 1);
188 GTP_ERROR("Read firmware message fail.");
192 update_msg
.force_update
= buf
[GTP_ADDR_LENGTH
];
194 if ((0xBE != update_msg
.force_update
) && (!retry
))
196 GTP_INFO("The check sum in ic is error.");
197 GTP_INFO("The IC will be updated by force.");
204 GTP_DEBUG("IC force update flag:0x%x", update_msg
.force_update
);
206 //step3:get pid & vid
207 ret
= gup_get_ic_msg(client
, GUP_REG_PID_VID
, buf
, 6);
211 GTP_ERROR("Read product id & version id fail.");
215 memset(update_msg
.ic_fw_msg
.pid
, 0, sizeof(update_msg
.ic_fw_msg
.pid
));
216 memcpy(update_msg
.ic_fw_msg
.pid
, &buf
[GTP_ADDR_LENGTH
], 4);
217 GTP_DEBUG("IC Product id:%s", update_msg
.ic_fw_msg
.pid
);
220 /*|-----FLASH-----RAM-----|
221 |------918------918-----|
222 |------968------968-----|
223 |------913------913-----|
224 |------913P-----913P----|
225 |------927------927-----|
226 |------927P-----927P----|
227 |------9110-----9110----|
228 |------9110P----9111----|*/
229 if (update_msg
.ic_fw_msg
.pid
[0] != 0)
231 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "9111", 4))
233 GTP_DEBUG("IC Mapping Product id:%s", update_msg
.ic_fw_msg
.pid
);
234 memcpy(update_msg
.ic_fw_msg
.pid
, "9110P", 5);
238 update_msg
.ic_fw_msg
.vid
= buf
[GTP_ADDR_LENGTH
+ 4] + (buf
[GTP_ADDR_LENGTH
+ 5] << 8);
239 GTP_DEBUG("IC version id:%04x", update_msg
.ic_fw_msg
.vid
);
244 s32
gup_enter_update_mode(struct i2c_client
*client
)
250 //step1:RST output low last at least 2ms
251 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 0);
254 //step2:select I2C slave addr,INT:0--0xBA;1--0x28.
255 GTP_GPIO_OUTPUT(GTP_INT_PORT
, (client
->addr
== 0x14));
258 //step3:RST output high reset guitar
259 GTP_GPIO_OUTPUT(GTP_RST_PORT
, 1);
261 //20121211 modify start
264 while (retry
++ < 200)
266 //step4:Hold ss51 & dsp
267 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
271 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
276 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, rd_buf
, 1);
280 GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry
);
284 if (0x0C == rd_buf
[GTP_ADDR_LENGTH
])
286 GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
290 GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", rd_buf
[GTP_ADDR_LENGTH
]);
295 GTP_ERROR("Enter update Hold ss51 failed.");
299 //step6:DSP_CK and DSP_ALU_CK PowerOn
300 ret
= gup_set_ic_msg(client
, 0x4010, 0x00);
302 //20121211 modify end
307 void gup_leave_update_mode(void)
310 //GTP_GPIO_AS_INT(GTP_INT_PORT);
312 GTP_DEBUG("[leave_update_mode]reset chip.");
313 gtp_reset_guitar(guitar_client
, 20);
316 GTP_DEBUG("[update_proc]send config.");
317 ret
= gtp_send_cfg(guitar_client
);
321 GTP_ERROR("[update_proc]send config fail.");
325 static u8
gup_enter_upadte_judge(st_fw_head
*fw_head
)
328 //Get the correct nvram data
329 //The correct conditions:
330 //1. the hardware info is the same
331 //2. the product id is the same
332 //3. the firmware version in update file is greater than the firmware version in ic
333 //or the check sum in ic is wrong
335 u16_tmp
= fw_head
->vid
;
336 fw_head
->vid
= (u16
)(u16_tmp
>> 8) + (u16
)(u16_tmp
<< 8);
338 GTP_DEBUG("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head
->hw_info
[0], fw_head
->hw_info
[1], fw_head
->hw_info
[2], fw_head
->hw_info
[3]);
339 GTP_DEBUG("FILE PID:%s", fw_head
->pid
);
340 GTP_DEBUG("FILE VID:%04x", fw_head
->vid
);
342 GTP_DEBUG("IC HARDWARE INFO:%02x%02x%02x%02x", update_msg
.ic_fw_msg
.hw_info
[0], update_msg
.ic_fw_msg
.hw_info
[1],
343 update_msg
.ic_fw_msg
.hw_info
[2], update_msg
.ic_fw_msg
.hw_info
[3]);
344 GTP_DEBUG("IC PID:%s", update_msg
.ic_fw_msg
.pid
);
345 GTP_DEBUG("IC VID:%04x", update_msg
.ic_fw_msg
.vid
);
347 //First two conditions
348 if (!memcmp(fw_head
->hw_info
, update_msg
.ic_fw_msg
.hw_info
, sizeof(update_msg
.ic_fw_msg
.hw_info
)))
350 GTP_DEBUG("Get the same hardware info.");
352 if (update_msg
.force_update
!= 0xBE)
354 GTP_INFO("FW chksum error,need enter update.");
358 if ((!memcmp(fw_head
->pid
, update_msg
.ic_fw_msg
.pid
, strlen(update_msg
.ic_fw_msg
.pid
))) ||
359 (!memcmp(update_msg
.ic_fw_msg
.pid
, "91XX", 4)) ||
360 (!memcmp(fw_head
->pid
, "91XX", 4)))
362 if (!memcmp(fw_head
->pid
, "91XX", 4))
364 GTP_DEBUG("Force none same pid update mode.");
368 GTP_DEBUG("Get the same pid.");
371 //The third condition
372 if (fw_head
->vid
> update_msg
.ic_fw_msg
.vid
)
375 GTP_INFO("Need enter update.");
379 GTP_ERROR("Don't meet the third condition.");
387 #ifdef GTP_BOOT_FW_CONFIG_SD_UPDATE
388 static u8
ascii2hex(u8 a
)
392 if (a
>= '0' && a
<= '9')
396 else if (a
>= 'A' && a
<= 'F')
398 value
= a
- 'A' + 0x0A;
400 else if (a
>= 'a' && a
<= 'f')
402 value
= a
- 'a' + 0x0A;
412 static s8
gup_update_config(struct i2c_client
*client
)
417 s32 file_cfg_len
= 0;
418 s32 chip_cfg_len
= 0;
425 if (IS_ERR(update_msg
.cfg_file
))
427 GTP_ERROR("[update_cfg]No need to upgrade config!");
431 file_len
= update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_END
);
435 if (!memcmp(update_msg
.ic_fw_msg
.pid
, "968", 3))
440 GTP_DEBUG("[update_cfg]config file len:%d", file_len
);
441 GTP_DEBUG("[update_cfg]need config len:%d", chip_cfg_len
);
443 if ((file_len
+ 5) < chip_cfg_len
* 5)
445 GTP_ERROR("Config length error");
449 buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
450 pre_buf
= (u8
*)kzalloc(file_len
, GFP_KERNEL
);
451 file_config
= (u8
*)kzalloc(chip_cfg_len
+ GTP_ADDR_LENGTH
, GFP_KERNEL
);
452 update_msg
.cfg_file
->f_op
->llseek(update_msg
.cfg_file
, 0, SEEK_SET
);
454 GTP_DEBUG("[update_cfg]Read config from file.");
455 ret
= update_msg
.cfg_file
->f_op
->read(update_msg
.cfg_file
, (char *)pre_buf
, file_len
, &update_msg
.cfg_file
->f_pos
);
459 GTP_ERROR("[update_cfg]Read config file failed.");
460 goto update_cfg_file_failed
;
463 GTP_DEBUG("[update_cfg]Delete illgal charactor.");
465 for (i
= 0, count
= 0; i
< file_len
; i
++)
467 if (pre_buf
[i
] == ' ' || pre_buf
[i
] == '\r' || pre_buf
[i
] == '\n')
472 buf
[count
++] = pre_buf
[i
];
475 GTP_DEBUG("[update_cfg]Ascii to hex.");
476 file_config
[0] = GTP_REG_CONFIG_DATA
>> 8;
477 file_config
[1] = GTP_REG_CONFIG_DATA
& 0xff;
479 for (i
= 0, file_cfg_len
= GTP_ADDR_LENGTH
; i
< count
; i
+= 5)
481 if ((buf
[i
] == '0') && ((buf
[i
+ 1] == 'x') || (buf
[i
+ 1] == 'X')))
484 high
= ascii2hex(buf
[i
+ 2]);
485 low
= ascii2hex(buf
[i
+ 3]);
487 if ((high
== 0xFF) || (low
== 0xFF))
490 GTP_ERROR("[update_cfg]Illegal config file.");
491 goto update_cfg_file_failed
;
494 file_config
[file_cfg_len
++] = (high
<< 4) + low
;
499 GTP_ERROR("[update_cfg]Illegal config file.");
500 goto update_cfg_file_failed
;
504 GTP_DEBUG("config:");
505 GTP_DEBUG_ARRAY(file_config
, file_cfg_len
);
510 for (i
= GTP_ADDR_LENGTH
; i
< chip_cfg_len
; i
++)
512 checksum
+= file_config
[i
];
515 file_config
[chip_cfg_len
] = (~checksum
) + 1;
522 ret
= gtp_i2c_write(client
, file_config
, file_cfg_len
);
526 GTP_INFO("[update_cfg]Send config SUCCESS.");
530 GTP_ERROR("[update_cfg]Send config i2c error.");
533 update_cfg_file_failed
:
541 static u8
gup_load_update_file(st_fw_head
*fw_head
)
545 mm_segment_t fs
= get_fs();
548 ret
= update_msg
.file
->f_op
->llseek(update_msg
.file
, 0, SEEK_SET
);
549 //update_msg.file->f_pos = 0;
550 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)fw_head
, FW_HEAD_LENGTH
, &update_msg
.file
->f_pos
);
554 GTP_ERROR("Read firmware head in update file error.");
559 //memcpy(fw_head, buf, FW_HEAD_LENGTH);
560 update_msg
.file
->f_pos
= FW_HEAD_LENGTH
+ 0;
561 ret
= update_msg
.file
->f_op
->read(update_msg
.file
, (char *)fw_buf
, FW_LENGTH
, &update_msg
.file
->f_pos
);
565 GTP_ERROR("Read firmware file fail.");
575 static u8
gup_check_update_file(struct i2c_client
*client
, st_fw_head
*fw_head
, u8
*path
)
582 update_msg
.file
= NULL
;
586 GTP_DEBUG("Update File path:%s, %d", path
, strlen(path
));
587 update_msg
.file
= filp_open(path
, O_RDONLY
, 0644);
589 if (IS_ERR(update_msg
.file
))
591 GTP_ERROR("Open update file(%s) error!", path
);
596 #ifdef GTP_BOOT_FW_CONFIG_SD_UPDATE
600 //Begin to search update file,the config file & firmware file must be in the same path,single or double.
601 for (i
= 0; i
< GUP_SEARCH_FILE_TIMES
; i
++)
603 update_msg
.file
= filp_open(UPDATE_FILE_PATH_1
, O_RDWR
, 0444);
605 if (IS_ERR(update_msg
.file
))
607 update_msg
.file
= filp_open(UPDATE_FILE_PATH_2
, O_RDWR
, 0664);
609 if (IS_ERR(update_msg
.file
))
611 GTP_DEBUG("%3d:Searching file...", i
);
617 GTP_DEBUG("Find UPDATE_FILE_PATH_2");
623 GTP_DEBUG("Find UPDATE_FILE_PATH_1");
625 i
= GUP_SEARCH_FILE_TIMES
;
630 // make sure check config file at least once
631 if (i
== GUP_SEARCH_FILE_TIMES
)
636 for (; i
< GUP_SEARCH_FILE_TIMES
; i
++)
638 update_msg
.cfg_file
= filp_open(CONFIG_FILE_PATH_1
, O_RDWR
, 0444);
640 if (IS_ERR(update_msg
.cfg_file
))
642 update_msg
.cfg_file
= filp_open(CONFIG_FILE_PATH_2
, O_RDWR
, 0664);
644 if (IS_ERR(update_msg
.cfg_file
))
646 GTP_DEBUG("%3d:Searching file...", i
);
652 GTP_DEBUG("Find CONFIG_FILE_PATH_2");
658 GTP_DEBUG("Find CONFIG_FILE_PATH_1");
664 if (!IS_ERR(update_msg
.cfg_file
))
666 GTP_DEBUG("Got the update config file.");
667 ret
= gup_update_config(client
);
671 GTP_ERROR("Update config failed.");
674 filp_close(update_msg
.cfg_file
, NULL
);
680 #endif //end BOOT_FW_CONFIG_SD_UPDATE
682 if ((!IS_ERR(update_msg
.file
)) && (update_msg
.file
!= NULL
))
684 ret
= gup_load_update_file(fw_head
);
685 filp_close(update_msg
.file
, NULL
);
697 GTP_DEBUG("Load Default FW.");
698 memcpy(fw_head
, gtp_default_FW
, FW_HEAD_LENGTH
);
699 memcpy(fw_buf
, gtp_default_FW
+ FW_HEAD_LENGTH
, FW_LENGTH
);
702 //check firmware legality
705 for (i
= 0; i
< FW_SECTION_LENGTH
* 4 + FW_DSP_ISP_LENGTH
+ FW_DSP_LENGTH
+ FW_BOOT_LENGTH
; i
+= 2)
708 //GTP_DEBUG("BUF[0]:%x", buf[0]);
709 empty_test
|= fw_buf
[i
];
710 empty_test
|= fw_buf
[i
+ 1];
711 temp
= (fw_buf
[i
] << 8) + fw_buf
[i
+ 1];
715 GTP_DEBUG("firmware checksum:%x empty_test:%x", (fw_checksum
& 0xFFFF), empty_test
);
717 if ((fw_checksum
& 0xFFFF) || (empty_test
== 0))
719 GTP_ERROR("Illegal or empty firmware file.");
720 GTP_ERROR("Load Default FW.");
721 memcpy(fw_head
, gtp_default_FW
, FW_HEAD_LENGTH
);
722 memcpy(fw_buf
, gtp_default_FW
+ FW_HEAD_LENGTH
, FW_LENGTH
);
731 static u8
gup_burn_proc(struct i2c_client
*client
, u8
*burn_buf
, u16 start_addr
, u16 total_length
)
734 u16 burn_addr
= start_addr
;
735 u16 frame_length
= 0;
737 u8 wr_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
738 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
741 GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length
/ 1024), start_addr
);
743 while (burn_length
< total_length
)
745 GTP_DEBUG("B/T:%04d/%04d", burn_length
, total_length
);
746 frame_length
= ((total_length
- burn_length
) > PACK_SIZE
) ? PACK_SIZE
: (total_length
- burn_length
);
747 wr_buf
[0] = (u8
)(burn_addr
>> 8);
748 rd_buf
[0] = wr_buf
[0];
749 wr_buf
[1] = (u8
)burn_addr
;
750 rd_buf
[1] = wr_buf
[1];
751 memcpy(&wr_buf
[GTP_ADDR_LENGTH
], &burn_buf
[burn_length
], frame_length
);
753 for (retry
= 0; retry
< MAX_FRAME_CHECK_TIME
; retry
++)
755 ret
= gtp_i2c_write(client
, wr_buf
, GTP_ADDR_LENGTH
+ frame_length
);
759 GTP_ERROR("Write frame data i2c error.");
763 ret
= gtp_i2c_read(client
, rd_buf
, GTP_ADDR_LENGTH
+ frame_length
);
767 GTP_ERROR("Read back frame data i2c error.");
771 if (memcmp(&wr_buf
[GTP_ADDR_LENGTH
], &rd_buf
[GTP_ADDR_LENGTH
], frame_length
))
773 GTP_ERROR("Check frame data fail,not equal.");
774 GTP_DEBUG("write array:");
775 GTP_DEBUG_ARRAY(&wr_buf
[GTP_ADDR_LENGTH
], frame_length
);
776 GTP_DEBUG("read array:");
777 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
782 //GTP_DEBUG("Check frame data success.");
787 if (retry
>= MAX_FRAME_CHECK_TIME
)
789 GTP_ERROR("Burn frame data time out,exit.");
793 burn_length
+= frame_length
;
794 burn_addr
+= frame_length
;
800 static u8
gup_load_section_file(u8
*buf
, u16 offset
, u16 length
)
803 memcpy(buf
, fw_buf
+ offset
, length
);
807 static u8
gup_recall_check(struct i2c_client
*client
, u8
*chk_src
, u16 start_rd_addr
, u16 chk_length
)
809 u8 rd_buf
[PACK_SIZE
+ GTP_ADDR_LENGTH
];
811 u16 recall_addr
= start_rd_addr
;
812 u16 recall_length
= 0;
813 u16 frame_length
= 0;
815 while (recall_length
< chk_length
)
817 frame_length
= ((chk_length
- recall_length
) > PACK_SIZE
) ? PACK_SIZE
: (chk_length
- recall_length
);
818 ret
= gup_get_ic_msg(client
, recall_addr
, rd_buf
, frame_length
);
822 GTP_ERROR("recall i2c error,exit");
826 if (memcmp(&rd_buf
[GTP_ADDR_LENGTH
], &chk_src
[recall_length
], frame_length
))
828 GTP_ERROR("Recall frame data fail,not equal.");
829 GTP_DEBUG("chk_src array:");
830 GTP_DEBUG_ARRAY(&chk_src
[recall_length
], frame_length
);
831 GTP_DEBUG("recall array:");
832 GTP_DEBUG_ARRAY(&rd_buf
[GTP_ADDR_LENGTH
], frame_length
);
836 recall_length
+= frame_length
;
837 recall_addr
+= frame_length
;
840 GTP_DEBUG("Recall check %dk firmware success.", (chk_length
/ 1024));
845 static u8
gup_burn_fw_section(struct i2c_client
*client
, u8
*fw_section
, u16 start_addr
, u8 bank_cmd
)
850 //step1:hold ss51 & dsp
851 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
855 GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
860 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
864 GTP_ERROR("[burn_fw_section]set scramble fail.");
869 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
873 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
877 //step4:enable accessing code
878 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
882 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
886 //step5:burn 8k fw section
887 ret
= gup_burn_proc(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
891 GTP_ERROR("[burn_fw_section]burn fw_section fail.");
895 //step6:hold ss51 & release dsp
896 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x04);
900 GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
907 //step7:send burn cmd to move data to flash from sram
908 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, bank_cmd
& 0x0f);
912 GTP_ERROR("[burn_fw_section]send burn cmd fail.");
916 GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
920 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
924 GTP_ERROR("[burn_fw_section]Get burn state fail");
929 //GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
931 while (rd_buf
[GTP_ADDR_LENGTH
]);
934 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, (bank_cmd
>> 4) & 0x0F);
938 GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd
>> 4) & 0x0F);
942 //step9:enable accessing code
943 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
947 GTP_ERROR("[burn_fw_section]enable accessing code fail.");
951 //step10:recall 8k fw section
952 ret
= gup_recall_check(client
, fw_section
, start_addr
, FW_SECTION_LENGTH
);
956 GTP_ERROR("[burn_fw_section]recall check 8k firmware fail.");
960 //step11:disable accessing code
961 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x00);
965 GTP_ERROR("[burn_fw_section]disable accessing code fail.");
972 static u8
gup_burn_dsp_isp(struct i2c_client
*client
)
975 u8
*fw_dsp_isp
= NULL
;
978 GTP_DEBUG("[burn_dsp_isp]Begin burn dsp isp---->>");
981 GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
985 fw_dsp_isp
= (u8
*)kzalloc(FW_DSP_ISP_LENGTH
, GFP_KERNEL
);
987 if (fw_dsp_isp
== NULL
)
993 GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.", (FW_DSP_ISP_LENGTH
/ 1024));
1000 GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
1004 //step2:load dsp isp file data
1005 GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
1006 ret
= gup_load_section_file(fw_dsp_isp
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
+ FW_BOOT_LENGTH
), FW_DSP_ISP_LENGTH
);
1010 GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
1011 goto exit_burn_dsp_isp
;
1014 //step3:disable wdt,clear cache enable
1015 GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
1016 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1020 GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
1022 goto exit_burn_dsp_isp
;
1025 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1029 GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
1031 goto exit_burn_dsp_isp
;
1034 //step4:hold ss51 & dsp
1035 GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
1036 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1040 GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
1042 goto exit_burn_dsp_isp
;
1045 //step5:set boot from sram
1046 GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
1047 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1051 GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
1053 goto exit_burn_dsp_isp
;
1056 //step6:software reboot
1057 GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
1058 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1062 GTP_ERROR("[burn_dsp_isp]software reboot fail.");
1064 goto exit_burn_dsp_isp
;
1067 //step7:select bank2
1068 GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
1069 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1073 GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
1075 goto exit_burn_dsp_isp
;
1078 //step8:enable accessing code
1079 GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
1080 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1084 GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
1086 goto exit_burn_dsp_isp
;
1089 //step9:burn 4k dsp_isp
1090 GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
1091 ret
= gup_burn_proc(client
, fw_dsp_isp
, 0xC000, FW_DSP_ISP_LENGTH
);
1095 GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
1096 goto exit_burn_dsp_isp
;
1099 //step10:set scramble
1100 GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
1101 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1105 GTP_ERROR("[burn_dsp_isp]set scramble fail.");
1107 goto exit_burn_dsp_isp
;
1117 static u8
gup_burn_fw_ss51(struct i2c_client
*client
)
1123 GTP_DEBUG("[burn_fw_ss51]Begin burn ss51 firmware---->>");
1125 //step1:alloc memory
1126 GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
1130 fw_ss51
= (u8
*)kzalloc(FW_SECTION_LENGTH
, GFP_KERNEL
);
1132 if (fw_ss51
== NULL
)
1138 GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1145 GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
1149 //step2:load ss51 firmware section 1 file data
1150 GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
1151 ret
= gup_load_section_file(fw_ss51
, 0, FW_SECTION_LENGTH
);
1155 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
1156 goto exit_burn_fw_ss51
;
1159 //step3:clear control flag
1160 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
1161 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1165 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
1167 goto exit_burn_fw_ss51
;
1170 //step4:burn ss51 firmware section 1
1171 GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
1172 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x01);
1176 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
1177 goto exit_burn_fw_ss51
;
1180 //step5:load ss51 firmware section 2 file data
1181 GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
1182 ret
= gup_load_section_file(fw_ss51
, FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1186 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
1187 goto exit_burn_fw_ss51
;
1190 //step6:burn ss51 firmware section 2
1191 GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
1192 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x02);
1196 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
1197 goto exit_burn_fw_ss51
;
1200 //step7:load ss51 firmware section 3 file data
1201 GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
1202 ret
= gup_load_section_file(fw_ss51
, 2 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1206 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
1207 goto exit_burn_fw_ss51
;
1210 //step8:burn ss51 firmware section 3
1211 GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
1212 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xC000, 0x13);
1216 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
1217 goto exit_burn_fw_ss51
;
1220 //step9:load ss51 firmware section 4 file data
1221 GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
1222 ret
= gup_load_section_file(fw_ss51
, 3 * FW_SECTION_LENGTH
, FW_SECTION_LENGTH
);
1226 GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
1227 goto exit_burn_fw_ss51
;
1230 //step10:burn ss51 firmware section 4
1231 GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
1232 ret
= gup_burn_fw_section(client
, fw_ss51
, 0xE000, 0x14);
1236 GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
1237 goto exit_burn_fw_ss51
;
1247 static u8
gup_burn_fw_dsp(struct i2c_client
*client
)
1254 GTP_DEBUG("[burn_fw_dsp]Begin burn dsp firmware---->>");
1255 //step1:alloc memory
1256 GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
1260 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1268 GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1275 GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
1279 //step2:load firmware dsp
1280 GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
1281 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
);
1285 GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
1286 goto exit_burn_fw_dsp
;
1289 //step3:select bank3
1290 GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
1291 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x03);
1295 GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
1297 goto exit_burn_fw_dsp
;
1300 //step4:hold ss51 & dsp
1301 GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
1302 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1306 GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
1308 goto exit_burn_fw_dsp
;
1311 //step5:set scramble
1312 GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
1313 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1317 GTP_ERROR("[burn_fw_dsp]set scramble fail.");
1319 goto exit_burn_fw_dsp
;
1322 //step6:release ss51 & dsp
1323 GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
1324 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x00);
1328 GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
1330 goto exit_burn_fw_dsp
;
1336 //step7:burn 4k dsp firmware
1337 GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
1338 ret
= gup_burn_proc(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1342 GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
1343 goto exit_burn_fw_dsp
;
1346 //step8:send burn cmd to move data to flash from sram
1347 GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
1348 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x05);
1352 GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
1353 goto exit_burn_fw_dsp
;
1356 GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
1360 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1364 GTP_ERROR("[burn_fw_dsp]Get burn state fail");
1365 goto exit_burn_fw_dsp
;
1369 //GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1371 while (rd_buf
[GTP_ADDR_LENGTH
]);
1373 //step9:recall check 4k dsp firmware
1374 GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
1375 ret
= gup_recall_check(client
, fw_dsp
, 0x9000, FW_DSP_LENGTH
);
1379 GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
1380 goto exit_burn_fw_dsp
;
1390 static u8
gup_burn_fw_boot(struct i2c_client
*client
)
1397 GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>");
1399 //step1:Alloc memory
1400 GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
1404 fw_boot
= (u8
*)kzalloc(FW_BOOT_LENGTH
, GFP_KERNEL
);
1406 if (fw_boot
== NULL
)
1412 GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.", (FW_BOOT_LENGTH
/ 1024));
1419 GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
1423 //step2:load firmware bootloader
1424 GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
1425 ret
= gup_load_section_file(fw_boot
, (4 * FW_SECTION_LENGTH
+ FW_DSP_LENGTH
), FW_BOOT_LENGTH
);
1429 GTP_ERROR("[burn_fw_boot]load firmware dsp fail.");
1430 goto exit_burn_fw_boot
;
1433 //step3:hold ss51 & dsp
1434 GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
1435 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1439 GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
1441 goto exit_burn_fw_boot
;
1444 //step4:set scramble
1445 GTP_DEBUG("[burn_fw_boot]step4:set scramble");
1446 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
1450 GTP_ERROR("[burn_fw_boot]set scramble fail.");
1452 goto exit_burn_fw_boot
;
1455 //step5:release ss51 & dsp
1456 GTP_DEBUG("[burn_fw_boot]step5:release ss51 & dsp");
1457 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x00);
1461 GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
1463 goto exit_burn_fw_boot
;
1469 //step6:burn 2k bootloader firmware
1470 GTP_DEBUG("[burn_fw_boot]step6:burn 2k bootloader firmware");
1471 ret
= gup_burn_proc(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1475 GTP_ERROR("[burn_fw_boot]burn fw_section fail.");
1476 goto exit_burn_fw_boot
;
1479 //step7:send burn cmd to move data to flash from sram
1480 GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
1481 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x06);
1485 GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
1486 goto exit_burn_fw_boot
;
1489 GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
1493 ret
= gup_get_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, rd_buf
, 1);
1497 GTP_ERROR("[burn_fw_boot]Get burn state fail");
1498 goto exit_burn_fw_boot
;
1502 //GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]);
1504 while (rd_buf
[GTP_ADDR_LENGTH
]);
1506 //step8:recall check 2k bootloader firmware
1507 GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
1508 ret
= gup_recall_check(client
, fw_boot
, 0x9000, FW_BOOT_LENGTH
);
1512 GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail.");
1513 goto exit_burn_fw_boot
;
1516 //step9:enable download DSP code
1517 GTP_DEBUG("[burn_fw_boot]step9:enable download DSP code ");
1518 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x99);
1522 GTP_ERROR("[burn_fw_boot]enable download DSP code fail.");
1524 goto exit_burn_fw_boot
;
1527 //step10:release ss51 & hold dsp
1528 GTP_DEBUG("[burn_fw_boot]step10:release ss51 & hold dsp");
1529 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x08);
1533 GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail.");
1535 goto exit_burn_fw_boot
;
1545 s32
gup_update_proc(void *dir
)
1551 GTP_DEBUG("[update_proc]Begin update ......");
1553 fw_buf
= (u8
*)kzalloc(FW_LENGTH
, GFP_KERNEL
);
1560 msleep(3000); //wait main thread to be completed
1563 if (guitar_client
== NULL
) //20121212
1565 guitar_client
= i2c_client_point
;
1568 ret
= gup_check_update_file(guitar_client
, &fw_head
, (u8
*)dir
); //20121212
1571 GTP_ERROR("[update_proc]check update file fail.");
1575 //gtp_reset_guitar(guitar_client, 20); //no need 20130419
1576 ret
= gup_get_ic_fw_msg(guitar_client
);
1580 GTP_ERROR("[update_proc]get ic message fail.");
1584 ret
= gup_enter_upadte_judge(&fw_head
); //20121212
1585 #ifdef GTP_FORCE_UPDATE_FW
1586 ret
= SUCCESS
; //for test
1591 GTP_ERROR("[update_proc]check update file fail.");
1595 ret
= gup_enter_update_mode(guitar_client
);
1599 GTP_ERROR("[update_proc]enter update mode fail.");
1607 ret
= gup_burn_dsp_isp(guitar_client
);
1611 GTP_ERROR("[update_proc]burn dsp isp fail.");
1616 ret
= gup_burn_fw_ss51(guitar_client
);
1620 GTP_ERROR("[update_proc]burn ss51 firmware fail.");
1625 ret
= gup_burn_fw_dsp(guitar_client
);
1629 GTP_ERROR("[update_proc]burn dsp firmware fail.");
1634 ret
= gup_burn_fw_boot(guitar_client
);
1638 GTP_ERROR("[update_proc]burn bootloader firmware fail.");
1643 GTP_INFO("[update_proc]UPDATE SUCCESS.");
1649 GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
1653 //original source code
1655 GTP_DEBUG("[update_proc]leave update mode.");
1656 gup_leave_update_mode();
1658 //Modified by Andrew --start
1659 //GTP_DEBUG("[update_proc]reset chip.");
1660 //gtp_reset_guitar(guitar_client, 20);
1661 //Modified by Andrew --end
1665 GTP_DEBUG("[update_proc]send config.");
1666 ret
= gtp_send_cfg(guitar_client
);
1670 GTP_ERROR("[update_proc]send config fail.");
1677 //Modified by Andrew --start
1678 GTP_DEBUG("[update_proc]leave update mode.");
1679 gup_leave_update_mode();
1680 //Modified by Andrew --end
1691 u8
gup_init_update_proc(struct i2c_client
*client
)
1693 struct task_struct
*thread
= NULL
;
1695 GTP_INFO("Ready to run update thread.");
1697 guitar_client
= client
;
1698 GTP_INFO("Ready to run update thread");
1700 thread
= kthread_run(gup_update_proc
, (void *)NULL
, "guitar_update");
1704 GTP_ERROR("Failed to create update thread.\n");
1713 static u8
gup_download_fw_ss51(struct i2c_client
*client
)
1719 GTP_INFO("[download_fw_ss51]Begin burn ss51 firmware---->>");
1721 //step1:alloc memory
1722 GTP_DEBUG("[download_fw_ss51]step1:alloc memory");
1726 fw_ss51
= (u8
*)kzalloc(2 * FW_DOWNLOAD_LENGTH
, GFP_KERNEL
);
1728 if (fw_ss51
== NULL
)
1734 GTP_INFO("[download_fw_ss51]Alloc %dk byte memory success.", (FW_DOWNLOAD_LENGTH
/ 1024));
1741 GTP_ERROR("[download_fw_ss51]Alloc memory fail,exit.");
1745 //step2:clear control flag
1746 GTP_DEBUG("[download_fw_ss51]step2:clear control flag");
1747 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOT_CTL_
, 0x00);
1751 GTP_ERROR("[download_fw_ss51]clear control flag fail.");
1753 goto exit_download_fw_ss51
;
1756 //step3:disable wdt,clear cache enable
1757 GTP_DEBUG("[download_fw_ss51]step3:disable wdt,clear cache enable");
1758 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__TMR0_EN
, 0x00);
1762 GTP_ERROR("[download_fw_ss51]disable wdt fail.");
1764 goto exit_download_fw_ss51
;
1767 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__CACHE_EN
, 0x00);
1771 GTP_ERROR("[download_fw_ss51]clear cache enable fail.");
1773 goto exit_download_fw_ss51
;
1776 //step4:hold ss51 & dsp
1777 GTP_DEBUG("[download_fw_ss51]step4:hold ss51 & dsp");
1778 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__SWRST_B0_
, 0x0C);
1782 GTP_ERROR("[download_fw_ss51]hold ss51 & dsp fail.");
1784 goto exit_download_fw_ss51
;
1789 //step5:set boot from sram
1790 GTP_DEBUG("[download_fw_ss51]step5:set boot from sram");
1791 ret
= gup_set_ic_msg(client
, _rRW_MISCTL__BOOTCTL_B0_
, 0x02);
1795 GTP_ERROR("[download_fw_ss51]set boot from sram fail.");
1797 goto exit_download_fw_ss51
;
1800 //step6:software reboot
1801 GTP_DEBUG("[download_fw_ss51]step6:software reboot");
1802 ret
= gup_set_ic_msg(client
, _bWO_MISCTL__CPU_SWRST_PULSE
, 0x01);
1806 GTP_ERROR("[download_fw_ss51]software reboot fail.");
1808 goto exit_download_fw_ss51
;
1812 //step7:load ss51 firmware section 1 file data
1813 GTP_DEBUG("[download_fw_ss51]step7:load ss51 firmware section 1 file data");
1814 ret
= gup_load_section_file(fw_ss51
, 0, 2 * FW_DOWNLOAD_LENGTH
);
1818 GTP_ERROR("[download_fw_ss51]load ss51 firmware section 1 fail.");
1819 goto exit_download_fw_ss51
;
1824 ret
= gup_set_ic_msg(guitar_client
, _bRW_MISCTL__SRAM_BANK
, 0x00);
1825 ret
= gup_set_ic_msg(guitar_client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1827 ret
= i2c_write_bytes(client
, 0xC000, fw_ss51
, FW_DOWNLOAD_LENGTH
); // write the first bank
1831 GTP_ERROR("[download_fw_dsp]download FW section 1 fail.");
1832 goto exit_download_fw_ss51
;
1835 ret
= gup_set_ic_msg(guitar_client
, _bRW_MISCTL__SRAM_BANK
, 0x01);
1836 ret
= gup_set_ic_msg(guitar_client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1837 ret
= i2c_write_bytes(client
,
1839 &fw_ss51
[FW_DOWNLOAD_LENGTH
],
1840 FW_DOWNLOAD_LENGTH
); // write the second bank
1844 GTP_ERROR("[download_fw_dsp]download FW section 2 fail.");
1845 goto exit_download_fw_ss51
;
1852 exit_download_fw_ss51
:
1857 static u8
gup_download_fw_dsp(struct i2c_client
*client
)
1864 GTP_INFO("[download_fw_dsp]Begin download dsp firmware---->>");
1865 //step1:alloc memory
1866 GTP_DEBUG("[download_fw_dsp]step1:alloc memory");
1870 fw_dsp
= (u8
*)kzalloc(FW_DSP_LENGTH
, GFP_KERNEL
);
1878 GTP_INFO("[download_fw_dsp]Alloc %dk byte memory success.", (FW_SECTION_LENGTH
/ 1024));
1885 GTP_ERROR("[download_fw_dsp]Alloc memory fail,exit.");
1889 //step2:load firmware dsp
1890 GTP_DEBUG("[download_fw_dsp]step2:load firmware dsp");
1891 ret
= gup_load_section_file(fw_dsp
, 4 * FW_SECTION_LENGTH
, FW_DSP_LENGTH
);
1895 GTP_ERROR("[download_fw_dsp]load firmware dsp fail.");
1896 goto exit_download_fw_dsp
;
1900 //step3:select bank2
1901 GTP_DEBUG("[download_fw_dsp]step3:select bank2");
1902 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__SRAM_BANK
, 0x02);
1906 GTP_ERROR("[download_fw_dsp]select bank2 fail.");
1908 goto exit_download_fw_dsp
;
1911 //step4:enable accessing code
1912 ret
= gup_set_ic_msg(client
, _bRW_MISCTL__MEM_CD_EN
, 0x01);
1916 GTP_ERROR("[download_fw_dsp]enable accessing code fail.");
1918 goto exit_download_fw_dsp
;
1921 ret
= i2c_write_bytes(client
,
1924 FW_DSP_LENGTH
); // write the second bank
1928 exit_download_fw_dsp
:
1935 s32
gup_fw_download_proc(void *dir
)
1942 GTP_INFO("[fw_download_proc]Begin fw download ......");
1943 fw_buf
= (u8
*)kzalloc(FW_LENGTH
, GFP_KERNEL
);
1947 msleep(2000); //wait main thread to be completed
1950 if (guitar_client
== NULL
) //20121212
1952 guitar_client
= i2c_client_point
;
1956 ret
= gup_check_update_file(guitar_client
, &fw_head
, (u8
*)dir
);
1960 GTP_ERROR("[fw_download_proc]check update file fail.");
1964 //gtp_reset_guitar(guitar_client, 20); //no need 20130419
1965 ret
= gup_get_ic_fw_msg(guitar_client
);
1969 GTP_ERROR("[fw_download_proc]get ic message fail.");
1973 ret
= gup_enter_upadte_judge(&fw_head
); //20121212
1977 GTP_ERROR("[update_proc]Check *.bin file fail.");
1981 ret
= gup_enter_update_mode(guitar_client
); //20121212
1985 GTP_ERROR("[fw_download_proc]check update file fail.");
1992 ret
= gup_download_fw_ss51(guitar_client
);
1996 GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
2000 ret
= gup_download_fw_dsp(guitar_client
);
2004 GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
2009 GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
2015 GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
2020 GTP_DEBUG("[download_fw_dsp]step5:set scramble");
2021 ret
= gup_set_ic_msg(guitar_client
, _rRW_MISCTL__BOOT_OPT_B0_
, 0x00);
2025 GTP_ERROR("[download_fw_dsp]set scramble fail.");
2030 //-- clear control flag
2031 GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
2032 ret
= gup_set_ic_msg(guitar_client
, _rRW_MISCTL__BOOT_CTL_
, 0xAA);
2036 GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
2041 //-- hold ss51 & dsp
2042 GTP_DEBUG("[download_fw_dsp]step4:hold ss51 & dsp");
2043 ret
= gup_set_ic_msg(guitar_client
, _rRW_MISCTL__SWRST_B0_
, 0x00);
2047 GTP_ERROR("[download_fw_dsp]hold ss51 & dsp fail.");
2054 gup_get_ic_msg(guitar_client
, GUP_REG_FW_MSG
, buf
, 1);
2055 GTP_DEBUG("[fw_download_proc] BOOT Status %02X\n", buf
[2]);
2063 GTP_DEBUG("[fw_download_proc]send config.");
2064 ret
= gtp_send_cfg(guitar_client
);
2068 GTP_ERROR("[fw_download_proc]send config fail.");
2083 u8
gup_init_fw_proc(struct i2c_client
*client
)
2085 struct task_struct
*thread
= NULL
;
2087 GTP_INFO("Ready to run fw download thread.");
2089 guitar_client
= client
;
2090 GTP_INFO("Ready to run fw download thread.");
2092 thread
= kthread_run(gup_fw_download_proc
, (void *)NULL
, "guitar_fw_download");
2096 GTP_ERROR("Failed to create fw download thread.\n");