2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 Copyright (c) 2011 Synaptics, Inc.
5 Permission is hereby granted, free of charge, to any person obtaining a copy of
6 this software and associated documentation files (the "Software"), to deal in
7 the Software without restriction, including without limitation the rights to use,
8 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 Software, and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include <linux/module.h>
26 #include <linux/delay.h>
27 #include <linux/hrtimer.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/interrupt.h>
32 #include <linux/platform_device.h>
33 #include <linux/gpio.h>
34 #include <linux/slab.h>
35 #include <linux/jiffies.h>
36 #include <linux/syscalls.h>
37 #include <linux/uaccess.h>
39 #include <mach/mt_gpio.h>
41 #include "s3528_driver.h"
43 /* Variables for F34 functionality */
44 unsigned short SynaF34DataBase
;
45 unsigned short SynaF34QueryBase
;
46 unsigned short SynaF01DataBase
;
47 unsigned short SynaF01CommandBase
;
48 unsigned short SynaF01QueryBase
;
50 unsigned short SynaF34Reflash_BlockNum
;
51 unsigned short SynaF34Reflash_BlockData
;
52 unsigned short SynaF34ReflashQuery_BootID
;
53 unsigned short SynaF34ReflashQuery_FlashPropertyQuery
;
54 unsigned short SynaF34ReflashQuery_BlockSize
;
55 unsigned short SynaF34ReflashQuery_FirmwareBlockCount
;
56 unsigned short SynaF34ReflashQuery_ConfigBlockCount
;
58 unsigned char SynaF01Query43Length
;
60 unsigned short SynaFirmwareBlockSize
;
61 unsigned short SynaFirmwareBlockCount
;
62 unsigned long SynaImageSize
;
64 unsigned short SynaConfigBlockSize
;
65 unsigned short SynaConfigBlockCount
;
66 unsigned long SynaConfigImageSize
;
68 unsigned short SynaBootloadID
;
70 unsigned short SynaF34_FlashControl
;
71 unsigned short SynaF34_FlashStatus
;
73 unsigned char *SynafirmwareImgData
;
74 unsigned char *SynaconfigImgData
;
75 unsigned char *SynalockImgData
;
76 unsigned int SynafirmwareImgVersion
;
78 unsigned char * ConfigBlock
;
82 m_uF34ReflashCmd_FirmwareCrc
= 0x01, // prior to V2 bootloaders
83 m_uF34ReflashCmd_FirmwareWrite
= 0x02,
84 m_uF34ReflashCmd_EraseAll
= 0x03,
85 m_uF34ReflashCmd_LockDown
= 0x04, // V2 and later bootloaders
86 m_uF34ReflashCmd_ConfigRead
= 0x05,
87 m_uF34ReflashCmd_ConfigWrite
= 0x06,
88 m_uF34ReflashCmd_EraseUIConfig
= 0x07,
89 m_uF34ReflashCmd_Enable
= 0x0F,
90 m_uF34ReflashCmd_QuerySensorID
= 0x08,
91 m_uF34ReflashCmd_EraseBLConfig
= 0x09,
92 m_uF34ReflashCmd_EraseDisplayConfig
= 0x0A,
95 char SynaFlashCommandStr
[0x0C][0x20] =
108 "EraseDisplayConfig",
110 /* Variables for F34 functionality */
118 unsigned char *my_image_bin
;
119 unsigned long my_image_size
;
122 int CompleteReflash(struct i2c_client
*client
);
123 //int ConfigBlockReflash(struct i2c_client *client);
124 //int CompleteReflash_Lockdown(struct i2c_client *client);
125 void SynaInitialize(struct i2c_client
*client
);
126 //void SynaReadConfigInfo(struct i2c_client *client);
127 void SynaReadFirmwareInfo(struct i2c_client
*client
);
128 void SynaEnableFlashing(struct i2c_client
*client
);
129 void SynaProgramFirmware(struct i2c_client
*client
);
130 //int SynaProgramConfiguration(struct i2c_client *client);
131 void SynaFinalizeReflash(struct i2c_client
*client
);
132 //int SynaWaitForATTN(int time);
133 unsigned int SynaWaitForATTN(int timeout
, struct i2c_client
*client
);
134 void eraseAllBlock(struct i2c_client
*client
);
135 void EraseConfigBlock(struct i2c_client
*client
);
136 bool CheckTouchControllerType(struct i2c_client
*client
);
138 extern int synaptics_ts_write(struct i2c_client
*client
, u8 reg
, u8
* buf
, int len
);
139 extern int synaptics_ts_read(struct i2c_client
*client
, u8 reg
, int num
, u8
*buf
);
142 int FirmwareUpgrade(struct i2c_client
*client
, const char* fw_path
, unsigned long fw_size
, unsigned char* fw_start
)
146 mm_segment_t old_fs
= 0;
147 struct stat fw_bin_stat
;
148 unsigned long read_bytes
;
150 if(unlikely(fw_path
[0] != 0)) {
154 if ((fd
= sys_open((const char __user
*) fw_path
, O_RDONLY
, 0)) < 0) {
155 TPD_ERR("Can not read FW binary from %s\n", fw_path
);
160 if ((ret
= sys_newstat((char __user
*) fw_path
, (struct stat
*)&fw_bin_stat
)) < 0) {
161 TPD_ERR("Can not read FW binary stat from %s\n", fw_path
);
162 goto fw_mem_alloc_fail
;
165 my_image_size
= fw_bin_stat
.st_size
;
166 my_image_bin
= kzalloc(sizeof(char) * (my_image_size
+1), GFP_KERNEL
);
167 if (my_image_bin
== NULL
) {
168 TPD_ERR("Can not allocate memory\n");
170 goto fw_mem_alloc_fail
;
173 read_bytes
= sys_read(fd
, (char __user
*)my_image_bin
, my_image_size
);
176 *(my_image_bin
+my_image_size
) = 0xFF;
178 TPD_LOG("Touch FW image read %ld bytes from %s\n", read_bytes
, fw_path
);
181 my_image_size
= fw_size
-1;
182 my_image_bin
= (unsigned char *)(&fw_start
[0]);
186 ret
= CompleteReflash(client
);
188 TPD_ERR("CompleteReflash fail\n");
191 ret
= CompleteReflash_Lockdown(client
);
193 TPD_ERR("CompleteReflash_Lockdown fail\n");
197 if(unlikely(fw_path
[0] != 0))
208 static int writeRMI(struct i2c_client
*client
, u8 uRmiAddress
, u8
*data
, unsigned int length
)
210 return synaptics_ts_write(client
, uRmiAddress
, data
, length
);
213 static int readRMI(struct i2c_client
*client
, u8 uRmiAddress
, u8
*data
, unsigned int length
)
215 return synaptics_ts_read(client
, uRmiAddress
, length
, data
);
218 bool CheckFlashStatus(enum FlashCommand command
, struct i2c_client
*client
)
220 unsigned char uData
= 0;
221 // Read the "Program Enabled" bit of the F34 Control register, and proceed only if the
223 readRMI(client
, SynaF34_FlashStatus
, &uData
, 1);
225 //if ((uData & 0x3F) != 0)
226 //printf("Command %s failed.\n\tFlash status : 0x%X\n", SynaFlashCommandStr[command], uData & 0x3F);
228 return !(uData
& 0x3F);
231 void SynaImageParser(struct i2c_client
*client
)
233 TPD_LOG("%s\n", __FUNCTION__
);
235 SynaImageSize
= ( (unsigned int)my_image_bin
[0x08] |
236 (unsigned int)my_image_bin
[0x09] <<8 |
237 (unsigned int)my_image_bin
[0x0A] <<16|
238 (unsigned int)my_image_bin
[0x0B] <<24);
239 SynafirmwareImgData
= (unsigned char *)((&my_image_bin
[0]) + 0x100);
240 SynaconfigImgData
= (unsigned char *)(SynafirmwareImgData
+ SynaImageSize
);
241 SynafirmwareImgVersion
= (unsigned int)(my_image_bin
[7]);
243 switch (SynafirmwareImgVersion
)
246 SynalockImgData
= (unsigned char *)((&my_image_bin
[0]) + 0xD0);
250 SynalockImgData
= (unsigned char *)((&my_image_bin
[0])+ 0xC0);
254 SynalockImgData
= (unsigned char *)((&my_image_bin
[0]) + 0xB0);
259 void SynaBootloaderLock(struct i2c_client
*client
)
261 unsigned short lockBlockCount
= 0;
262 unsigned char uData
[2] = {0,};
263 unsigned short uBlockNum
= 0;
264 enum FlashCommand cmd
;
266 TPD_LOG("%s\n", __FUNCTION__
);
268 if (my_image_bin
[0x1E] == 0)
270 TPD_LOG("Skip lockdown process with this .img\n");
273 // Check if device is in unlocked state
274 readRMI(client
, (SynaF34QueryBase
+ 1), &uData
[0], 1);
279 TPD_LOG("Device unlocked. Lock it first...\n");
280 // Different bootloader version has different block count for the lockdown data
281 // Need to check the bootloader version from the image file being reflashed
282 switch (SynafirmwareImgVersion
)
300 // Write the lockdown info block by block
301 // This reference code of lockdown process does not check for bootloader version
302 // currently programmed on the ASIC against the bootloader version of the image to
303 // be reflashed. Such case should not happen in practice. Reflashing cross different
304 // bootloader versions is not supported.
305 for (uBlockNum
= 0; uBlockNum
< lockBlockCount
; ++uBlockNum
)
307 uData
[0] = uBlockNum
& 0xff;
308 uData
[1] = (uBlockNum
& 0xff00) >> 8;
310 /* Write Block Number */
311 writeRMI(client
, SynaF34Reflash_BlockNum
, &uData
[0], 2);
313 /* Write Data Block */
314 writeRMI(client
, SynaF34Reflash_BlockData
, SynalockImgData
, SynaFirmwareBlockSize
);
316 /* Move to next data block */
317 SynalockImgData
+= SynaFirmwareBlockSize
;
319 /* Issue Write Lockdown Block command */
320 cmd
= m_uF34ReflashCmd_LockDown
;
321 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
323 /* Wait ATTN until device is done writing the block and is ready for the next. */
324 SynaWaitForATTN(1000, client
);
325 CheckFlashStatus(cmd
, client
);
328 // Enable reflash again to finish the lockdown process.
329 // Since this lockdown process is part of the reflash process, we are enabling
330 // reflash instead, rather than resetting the device to finish the unlock procedure.
331 SynaEnableFlashing(client
);
333 else TPD_LOG("Device already locked.\n");
337 /* SynaScanPDT scans the Page Description Table (PDT) and sets up the necessary variables
338 * for the reflash process. This function is a "slim" version of the PDT scan function in
339 * in PDT.c, since only F34 and F01 are needed for reflash.
341 void SynaScanPDT(struct i2c_client
*client
)
343 unsigned char address
=0;
344 unsigned char uData
[2]={0,};
345 unsigned char buffer
[6]={0,};
346 TPD_LOG("%s\n", __FUNCTION__
);
348 for (address
= 0xe9; address
> 0xc0; address
= address
- 6)
350 readRMI(client
, address
, buffer
, 6);
355 SynaF34DataBase
= buffer
[3];
356 SynaF34QueryBase
= buffer
[0];
359 SynaF01DataBase
= buffer
[3];
360 SynaF01CommandBase
= buffer
[1];
361 SynaF01QueryBase
= buffer
[0];
366 SynaF34Reflash_BlockNum
= SynaF34DataBase
;
367 SynaF34Reflash_BlockData
= SynaF34DataBase
+ 1;
368 SynaF34ReflashQuery_BootID
= SynaF34QueryBase
;
369 SynaF34ReflashQuery_FlashPropertyQuery
= SynaF34QueryBase
+ 1;
370 SynaF34ReflashQuery_BlockSize
= SynaF34QueryBase
+ 2;
371 SynaF34ReflashQuery_FirmwareBlockCount
= SynaF34QueryBase
+ 3;
372 SynaF34_FlashControl
= SynaF34DataBase
+ 2;
373 SynaF34_FlashStatus
= SynaF34DataBase
+ 3;
375 readRMI(client
, SynaF34ReflashQuery_FirmwareBlockCount
, buffer
, 4);
376 SynaFirmwareBlockCount
= buffer
[0] | (buffer
[1] << 8);
377 SynaConfigBlockCount
= buffer
[2] | (buffer
[3] << 8);
379 readRMI(client
, SynaF34ReflashQuery_BlockSize
, &uData
[0], 2);
380 SynaConfigBlockSize
= SynaFirmwareBlockSize
= uData
[0] | (uData
[1] << 8);
383 readRMI(client
, (SynaF01DataBase
+ 1), buffer
, 1);
385 /* SynaSetup scans the Page Description Table (PDT) and sets up the necessary variables
386 * for the reflash process. This function is a "slim" version of the PDT scan function in
387 * in PDT.c, since only F34 and F01 are needed for reflash.
397 /* SynaInitialize sets up the reflahs process
399 void SynaInitialize(struct i2c_client
*client
)
403 TPD_LOG("%s\n", __FUNCTION__
);
404 TPD_LOG("\nInitializing Reflash Process...\n");
407 writeRMI(client
, 0xff, &data
, 1);
409 SynaImageParser(client
);
413 /* SynaInitialize sets up the reflahs process
420 //Set all interrupt enable
424 /* SynaReadFirmwareInfo reads the F34 query registers and retrieves the block size and count
425 * of the firmware section of the image to be reflashed
427 void SynaReadFirmwareInfo(struct i2c_client
*client
)
429 unsigned char uData
[3] = {0,};
430 unsigned char product_id
[11] = {0,};
431 int firmware_version
= 0;
432 TPD_LOG("%s\n", __FUNCTION__
);
434 readRMI(client
, SynaF01QueryBase
+ 11, product_id
, 10);
435 product_id
[10] = '\0';
436 TPD_LOG("Read Product ID %s\n", product_id
);
438 readRMI(client
, SynaF01QueryBase
+ 18, uData
, 3);
439 firmware_version
= uData
[2] << 16 | uData
[1] << 8 | uData
[0];
440 TPD_LOG("Read Firmware Info %d\n", firmware_version
);
442 CheckTouchControllerType(client
);
443 //CheckFimrwareRevision();//APK_TEST
446 /* SynaReadBootloadID reads the F34 query registers and retrieves the bootloader ID of the firmware
448 void SynaReadBootloadID(struct i2c_client
*client
)
450 unsigned char uData
[2] = {0,};
451 TPD_LOG("%s\n", __FUNCTION__
);
453 readRMI(client
, SynaF34ReflashQuery_BootID
, &uData
[0], 2);
454 SynaBootloadID
= uData
[0] | (uData
[1] << 8);
457 /* SynaWriteBootloadID writes the bootloader ID to the F34 data register to unlock the reflash process
459 void SynaWriteBootloadID(struct i2c_client
*client
)
461 unsigned char uData
[2];
462 TPD_LOG("%s\n", __FUNCTION__
);
464 uData
[0] = SynaBootloadID
% 0x100;
465 uData
[1] = SynaBootloadID
/ 0x100;
467 writeRMI(client
, SynaF34Reflash_BlockData
, &uData
[0], 2);
470 /* SynaReadFirmwareInfo reads the F34 query registers and retrieves the block size and count
471 * of the firmware section of the image to be reflashed
478 /* SynaReadConfigInfo reads the F34 query registers and retrieves the block size and count
479 * of the configuration section of the image to be reflashed
485 /* SynaReadBootloadID reads the F34 query registers and retrieves the bootloader ID of the firmware
489 /* SynaWriteBootloadID writes the bootloader ID to the F34 data register to unlock the reflash process
494 /* SynaEnableFlashing kicks off the reflash process
496 void SynaEnableFlashing(struct i2c_client
*client
)
498 unsigned char uStatus
= 0;
499 enum FlashCommand cmd
;
500 TPD_LOG("%s\n", __FUNCTION__
);
501 TPD_LOG("Enable Reflash...\n");
503 readRMI (client
, SynaF01DataBase
, &uStatus
, 1);
506 TPD_LOG("APK_TEST uStatus= 0x%02x\n", uStatus
);
508 if ((uStatus
&0x40) == 0 /*|| force*/)
510 // Reflash is enabled by first reading the bootloader ID from the firmware and write it back
511 SynaReadBootloadID(client
);
512 SynaWriteBootloadID(client
);
514 // Write the "Enable Flash Programming command to F34 Control register
515 // Wait for ATTN and then clear the ATTN.
516 cmd
= m_uF34ReflashCmd_Enable
;
517 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
518 SynaWaitForATTN(1000,client
);
520 //I2C addrss may change
521 //ConfigCommunication();//APK_TEST
523 // Scan the PDT again to ensure all register offsets are correct
526 // Read the "Program Enabled" bit of the F34 Control register, and proceed only if the
528 CheckFlashStatus(cmd
,client
);
532 /* SynaWaitForATTN waits for ATTN to be asserted within a certain time threshold.
534 unsigned int SynaWaitForATTN(int timeout
, struct i2c_client
*client
)
536 unsigned char uStatus
;
538 //int retry = timeout/duration;
543 readRMI((SynaF01DataBase
+ 1), &uStatus
, 1);
548 } while (times
< retry
);
553 //if (Line_WaitForAttention(timeout) == EErrorTimeout)
559 while((mt_get_gpio_in(GPIO_CTP_EINT_PIN
) != 0) && (trial_us
< (timeout
* 1000))) {
564 if (mt_get_gpio_in(GPIO_CTP_EINT_PIN
) != 0){
565 TPD_LOG("interrupt pin is busy...");
569 readRMI(client
, (SynaF01DataBase
+ 1), &uStatus
, 1);
573 /* SynaWaitForATTN waits for ATTN to be asserted within a certain time threshold.
579 /* SynaWaitATTN waits for ATTN to be asserted within a certain time threshold.
580 * The function also checks for the F34 "Program Enabled" bit and clear ATTN accordingly.
586 /* SynaEnableFlashing kicks off the reflash process
590 // Reflash is enabled by first reading the bootloader ID from the firmware and write it back
592 // Make sure Reflash is not already enabled
598 // Write the "Enable Flash Programming command to F34 Control register
599 // Wait for ATTN and then clear the ATTN.
600 // Scan the PDT again to ensure all register offsets are correct
601 // Read the "Program Enabled" bit of the F34 Control register, and proceed only if the
603 // In practice, if uData!=0x80 happens for multiple counts, it indicates reflash
604 // is failed to be enabled, and program should quit
606 //TPD_LOG("APK_TEST uData= 0x%02x\n", uData);
609 /* SynaFinalizeReflash finalizes the reflash process
611 void SynaFinalizeReflash(struct i2c_client
*client
)
615 char deviceStatusStr
[7][20] = {
621 "firmware CRC failed",
625 TPD_LOG("%s\n", __FUNCTION__
);
626 TPD_LOG("\nFinalizing Reflash...\n");
628 // Issue the "Reset" command to F01 command register to reset the chip
629 // This command will also test the new firmware image and check if its is valid
631 writeRMI(client
, SynaF01CommandBase
, &uData
, 1);
633 // After command reset, there will be 2 interrupt to be asserted
634 // Simply sleep 150 ms to skip first attention
636 SynaWaitForATTN(1000, client
);
640 readRMI(client
, SynaF01DataBase
, &uData
, 1);
642 if ((uData
& 0x40) != 0)
644 TPD_LOG("\nDevice is in bootloader mode (status: %s).\n", deviceStatusStr
[uData
& 0xF]);
648 TPD_LOG("\nReflash Completed and Succeed.\n");
652 /* SynaFlashFirmwareWrite writes the firmware section of the image block by block
654 void SynaFlashFirmwareWrite(struct i2c_client
*client
)
656 unsigned char *puFirmwareData
= SynafirmwareImgData
;
657 unsigned char uData
[2];
658 unsigned short blockNum
;
659 enum FlashCommand cmd
;
661 TPD_LOG("%s\n", __FUNCTION__
);
662 for (blockNum
= 0; blockNum
< SynaFirmwareBlockCount
; ++blockNum
)
666 //Block by blcok, write the block number and data to the corresponding F34 data registers
667 uData
[0] = blockNum
& 0xff;
668 uData
[1] = (blockNum
& 0xff00) >> 8;
669 writeRMI(client
, SynaF34Reflash_BlockNum
, &uData
[0], 2);
672 writeRMI(client
, SynaF34Reflash_BlockData
, puFirmwareData
, SynaFirmwareBlockSize
);
673 puFirmwareData
+= SynaFirmwareBlockSize
;
675 // Issue the "Write Firmware Block" command
676 cmd
= m_uF34ReflashCmd_FirmwareWrite
;
677 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
679 SynaWaitForATTN(1000, client
);
680 CheckFlashStatus(cmd
, client
);
681 //#ifdef SHOW_PROGRESS
683 if (blockNum
% 100 == 0)
684 TPD_LOG("blk %d / %d\n", blockNum
, SynaFirmwareBlockCount
);
687 //#ifdef SHOW_PROGRESS
689 TPD_LOG("blk %d / %d\n", SynaFirmwareBlockCount
, SynaFirmwareBlockCount
);
693 /* SynaFlashFirmwareWrite writes the firmware section of the image block by block
695 void SynaFlashConfigWrite(struct i2c_client
*client
)
697 unsigned char *puConfigData
= SynaconfigImgData
;
698 unsigned char uData
[2];
699 unsigned short blockNum
;
700 enum FlashCommand cmd
;
702 TPD_LOG("%s\n", __FUNCTION__
);
703 for (blockNum
= 0; blockNum
< SynaConfigBlockCount
; ++blockNum
)
705 //Block by blcok, write the block number and data to the corresponding F34 data registers
706 uData
[0] = blockNum
& 0xff;
707 uData
[1] = (blockNum
& 0xff00) >> 8;
708 writeRMI(client
, SynaF34Reflash_BlockNum
, &uData
[0], 2);
710 writeRMI(client
, SynaF34Reflash_BlockData
, puConfigData
, SynaConfigBlockSize
);
711 puConfigData
+= SynaConfigBlockSize
;
713 // Issue the "Write Config Block" command
714 cmd
= m_uF34ReflashCmd_ConfigWrite
;
715 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
717 SynaWaitForATTN(1000, client
);
718 CheckFlashStatus(cmd
, client
);
720 if (blockNum
% 100 == 0)
721 TPD_LOG("blk %d / %d\n", blockNum
, SynaConfigBlockCount
);
725 TPD_LOG("blk %d / %d\n", SynaConfigBlockCount
, SynaConfigBlockCount
);
729 /* SynaProgramFirmware prepares the firmware writing process
731 void SynaProgramFirmware(struct i2c_client
*client
)
733 TPD_LOG("%s\n", __FUNCTION__
);
734 TPD_LOG("\nProgram Firmware Section...\n");
736 eraseAllBlock(client
);
738 SynaFlashFirmwareWrite(client
);
740 SynaFlashConfigWrite(client
);
743 /* SynaProgramFirmware prepares the firmware writing process
745 void SynaUpdateConfig(struct i2c_client
*client
)
747 TPD_LOG("%s\n", __FUNCTION__
);
748 TPD_LOG("\nUpdate Config Section...\n");
750 EraseConfigBlock(client
);
752 SynaFlashConfigWrite(client
);
755 /* EraseConfigBlock erases the config block
757 void eraseAllBlock(struct i2c_client
*client
)
759 enum FlashCommand cmd
;
761 TPD_LOG("%s\n", __FUNCTION__
);
762 // Erase of config block is done by first entering into bootloader mode
763 SynaReadBootloadID(client
);
764 SynaWriteBootloadID(client
);
766 // Command 7 to erase config block
767 cmd
= m_uF34ReflashCmd_EraseAll
;
768 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
770 SynaWaitForATTN(6000, client
);
771 CheckFlashStatus(cmd
, client
);
774 /* EraseConfigBlock erases the config block
776 void EraseConfigBlock(struct i2c_client
*client
)
778 enum FlashCommand cmd
;
780 TPD_LOG("%s\n", __FUNCTION__
);
781 // Erase of config block is done by first entering into bootloader mode
782 SynaReadBootloadID(client
);
783 SynaWriteBootloadID(client
);
785 // Command 7 to erase config block
786 cmd
= m_uF34ReflashCmd_EraseUIConfig
;
787 writeRMI(client
, SynaF34_FlashControl
, (unsigned char*)&cmd
, 1);
789 SynaWaitForATTN(2000, client
);
790 CheckFlashStatus(cmd
, client
);
793 // This function is to check the touch controller type of the touch controller matches with the firmware image
794 bool CheckTouchControllerType(struct i2c_client
*client
)
798 char controllerType
[20]={0,};
799 unsigned char uData
[4]={0,};
801 TPD_LOG("%s\n", __FUNCTION__
);
802 readRMI(client
, (SynaF01QueryBase
+ 22), &SynaF01Query43Length
, 1); //43
804 if ((SynaF01Query43Length
& 0x0f) > 0)
806 readRMI(client
, (SynaF01QueryBase
+ 23), &uData
[0], 1);
809 readRMI(client
, (SynaF01QueryBase
+ 17), &uData
[0], 2);
811 ID
= ((int)uData
[0] | ((int)uData
[1] << 8));
812 //sprintf_s(buffer, "%d\0", ID);//APK_TEST
814 if (strstr(controllerType
, buffer
) != 0) return true;
823 bool CheckFimrwareRevision(struct i2c_client
*client
)
825 unsigned char uData
[16];
828 TPD_LOG("%s\n", __FUNCTION__
);
829 readRMI((SynaF01QueryBase
+ 28 + SynaF01Query43Length
), &uData
[0], 16);
831 for (int i
= 0; i
< 0; i
++)
833 while (uData
[i
] != NULL
)
835 revision
[i
] = char(uData
[0]);
839 if (strcmp(revision
, FW_REVISION
) == 0) return true;
844 /* SynaProgramConfiguration writes the configuration section of the image block by block
850 //Block by blcok, write the block number and data to the corresponding F34 data registers
852 // Issue the "Write Configuration Block" command
854 /* SynaFinalizeReflash finalizes the reflash process
858 // Issue the "Reset" command to F01 command register to reset the chip
859 // This command will also test the new firmware image and check if its is valid
862 // Sanity check that the reflash process is still enabled
865 // Check if the "Program Enabled" bit in F01 data register is cleared
866 // Reflash is completed, and the image passes testing when the bit is cleared
868 // Rescan PDT the update any changed register offsets
872 /* SynaFlashFirmwareWrite writes the firmware section of the image block by block
875 //Block by blcok, write the block number and data to the corresponding F34 data registers
878 // Issue the "Write Firmware Block" command
882 /* SynaProgramFirmware prepares the firmware writing process
893 /* eraseConfigBlock erases the config block
896 // Erase of config block is done by first entering into bootloader mode
898 // Command 7 to erase config block
902 // CRC_Calculate illustates how to calculate a checksum from the config block data.
903 // With DS4, the config block checksum is calculated and applies towards the end of
904 // the config block data automatically
905 // Variable data to this function represents the data only portion of the config block
906 // Varaible len represents the length of the variable data.
912 // Check if device is in unlocked state
915 // Different bootloader version has different block count for the lockdown data
916 // Need to check the bootloader version from the image file being reflashed
918 // Write the lockdown info block by block
919 // This reference code of lockdown process does not check for bootloader version
920 // currently programmed on the ASIC against the bootloader version of the image to
921 // be reflashed. Such case should not happen in practice. Reflashing cross different
922 // bootloader versions is not supported.
924 /* Write Block Number */
926 /* Write Data Block */
928 /* Move to next data block */
930 /* Issue Write Lockdown Block command */
932 /* Wait ATTN until device is done writing the block and is ready for the next. */
934 // Enable reflash again to finish the lockdown process.
935 // Since this lockdown process is part of the reflash process, we are enabling
936 // reflash instead, rather than resetting the device to finish the unlock procedure.
939 /* ConfigBlockReflash reflashes the config block only
948 // Check if device is in unlocked state
951 // Do not reflash config block if not locked.
957 /* CompleteReflash reflashes the entire user image, including the configuration block and firmware
959 int CompleteReflash(struct i2c_client
*client
)
961 bool bFlashAll
= true;
963 SynaInitialize(client
);
965 SynaReadFirmwareInfo(client
);
967 SynaEnableFlashing(client
);
969 SynaBootloaderLock(client
);
972 SynaProgramFirmware(client
);
974 SynaUpdateConfig(client
);
976 SynaFinalizeReflash(client
);
981 /* CompleteReflash reflashes the entire user image, including the configuration block and firmware