int mms100_ISP_download_binary_data(int dl_mode)
{
	int nRet = 0;
	int retry_cnt = 0;

#if 0
	#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
	#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

#endif

	//------------------------
	// Run Download
	//------------------------

	for (retry_cnt = 0; retry_cnt < 5; retry_cnt++) {
        if(dl_mode == 0x01) //MELFAS_ISP_DOWNLOAD
    		nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0);
        else //MELFAS_ISC_DOWNLOAD
        {
			nRet = mcsdl_download( (const UINT8*) MELFAS_MMS100_Initial_binary, (const UINT16)MELFAS_MMS100_Initial_nLength , 0);
        }

#if MELFAS_2CHIP_DOWNLOAD_ENABLE
        if(!nRet)
        {
            if(dl_mode == 0x01) //MELFAS_ISP_DOWNLOAD
                nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength, 1); // Slave Binary data download
            else //MELFAS_ISC_DOWNLOAD
                nRet = mcsdl_download( (const UINT8*) MELFAS_MMS100_Initial_binary, (const UINT16)MELFAS_MMS100_Initial_nLength , 1);
        }
#endif

		if (!nRet)
			break;
	}

	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer

// wcjeong - unused code
//fw_error:
	if (nRet) {
		mcsdl_erase_flash(0);
		mcsdl_erase_flash(1);
	}
	return nRet;
}
예제 #2
0
int mcsdl_download_binary_data(bool touch_id)
{
	int nRet = 0;
	int retry_cnt = 0;
	long fw1_size = 0;
	unsigned char *fw_data1;

	//------------------------
	// Run Download
	//------------------------
	for (retry_cnt = 0; retry_cnt < 5; retry_cnt++) {
		if (touch_id)
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 0);
		else
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_1, (const UINT16)MELFAS_binary_nLength_1 , 0);

		if (nRet)
			continue;
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
		if (touch_id)
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 1); // Slave Binary data download
		else
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_1, (const UINT16)MELFAS_binary_nLength_1, 1); // Slave Binary data download
		if (nRet)
			continue;
#endif
		break;
	}

fw_error:
	if (nRet) {
		mcsdl_erase_flash(0);
		mcsdl_erase_flash(1);
	}

	return nRet;
}
예제 #3
0
static int mcsdl_download(const UINT8 *pBianry, const UINT16 unLength, INT8 IdxNum )
{
	int nRet;

	//---------------------------------
	// Check Binary Size
	//---------------------------------
	if( unLength >= MELFAS_FIRMWARE_MAX_SIZE ){

		nRet = MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
		goto MCSDL_DOWNLOAD_FINISH;
	}


	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" - Starting download...\n");
	#endif


	//---------------------------------
	// Make it ready
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Ready\n");
	#endif

	mcsdl_set_ready();

//	mcsdl_delay(MCSDL_DELAY_1MS);

	//---------------------------------
	// Erase Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Erase\n");
	#endif

	nRet = mcsdl_erase_flash(IdxNum);

	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

//	mcsdl_delay(MCSDL_DELAY_1MS);
	//---------------------------------
	// Program Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Program   ");
	#endif

//	if(IdxNum > 0)
//		mcsdl_set_ready();

	nRet = mcsdl_program_flash( (UINT8*)pBianry, (UINT16)unLength, IdxNum );
	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

//	mcsdl_delay(MCSDL_DELAY_1MS);
    //---------------------------------
    // Verify flash
    //---------------------------------
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" > Verify    ");
#endif
    nRet = mcsdl_verify_flash((UINT8*)pBianry, (UINT16)unLength, IdxNum);
    if (nRet != MCSDL_RET_SUCCESS)
        goto MCSDL_DOWNLOAD_FINISH;


//	mcsdl_delay(MCSDL_DELAY_1MS);
	nRet = MCSDL_RET_SUCCESS;


MCSDL_DOWNLOAD_FINISH :

	#if MELFAS_ENABLE_DBG_PRINT
	mcsdl_print_result( nRet );								// Show result
	#endif

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Rebooting\n");
	printk(" - Fin.\n\n");
	#endif

    mcsdl_reboot_mcs();

	return nRet;
}
예제 #4
0
int mcsdl_download_binary_file(void)
{
		int nRet = 0;
		int retry_cnt = 0;
		long fw1_size = 0;
		unsigned char *fw_data1;
	struct file *filp;
	loff_t  pos;
	int     ret = 0;
	mm_segment_t oldfs;
	spinlock_t	lock;

	oldfs = get_fs();
	set_fs(get_ds());

	filp = filp_open(MELFAS_FW1, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw1_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw1_size);

	fw_data1 = kmalloc(fw1_size, GFP_KERNEL);
	memset(fw_data1, 0, fw1_size);

	pos = 0;
	memset(fw_data1, 0, fw1_size);
	ret = vfs_read(filp, (char __user *)fw_data1, fw1_size, &pos);

	if(ret != fw1_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW1, ret);
		kfree(fw_data1);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	set_fs(oldfs);
	spin_lock_init(&lock);
	spin_lock(&lock);


	//------------------------
	// Run Download
	//------------------------

	for (retry_cnt = 0; retry_cnt < 3; retry_cnt++) {
		pr_info("[TSP] ADB - MASTER CHIP Firmware update! try : %d",retry_cnt+1);
	nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 0);
	if (nRet)
			continue;
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
		pr_info("[TSP] ADB - SLAVE CHIP Firmware update! try : %d",retry_cnt+1);
		nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 1);
	if (nRet)
		continue;
#endif
	break;	
	}
	
	if (nRet) {
	mcsdl_erase_flash(0);
	mcsdl_erase_flash(1);
	}
	kfree(fw_data1);
	spin_unlock(&lock);
	return nRet;

}
예제 #5
0
int mcsdl_download_binary_data(UINT8 master_dl_retry, int val,unsigned char fw_ver, unsigned char comp_ver)
{
	int nRet;
#ifdef FW_FROM_FILE
	struct file *filp;
	spinlock_t           lock;
	loff_t  pos;
	int     ret = 0;
	long fw1_size = 0;
	long fw2_size = 0;
	mm_segment_t oldfs;
	unsigned char *fw_data1;
	unsigned char *fw_data2;

	oldfs = get_fs();
	set_fs(get_ds());

	filp = filp_open(MELFAS_FW1, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw1_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw1_size);

	fw_data1 = kmalloc(fw1_size, GFP_KERNEL);
	memset(fw_data1, 0, fw1_size);

	pos = 0;
	memset(fw_data1, 0, fw1_size);
	ret = vfs_read(filp, (char __user *)fw_data1, fw1_size, &pos);

	if(ret != fw1_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW1, ret);
		kfree(fw_data1);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	filp = filp_open(MELFAS_FW2, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw2_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw2_size);

	fw_data2 = kmalloc(fw2_size, GFP_KERNEL);
	memset(fw_data2, 0, fw2_size);

	pos = 0;
	memset(fw_data2, 0, fw2_size);
	ret = vfs_read(filp, (char __user *)fw_data2, fw2_size, &pos);

	if(ret != fw2_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW2, ret);
		kfree(fw_data2);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	set_fs(oldfs);
	spin_lock_init(&lock);
	spin_lock(&lock);
#endif

	#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
	#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

	//------------------------
	// Run Download
	//------------------------
#ifdef FW_FROM_FILE
    if(MELFAS_ISP_DOWNLOAD || master_dl_retry)
	{
	nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 0);
	if (nRet)
		goto fw_error;
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
    nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 1);
	if (nRet)
		goto fw_error;
	spin_unlock(&lock);
#endif
	}
#else
	/* For F/W Download by using ISC Mode */
	/* We need to implement some conditions */

    if (MELFAS_ISP_DOWNLOAD || master_dl_retry) {
	if (val == 1) {
		if(comp_ver==0){ //for M3C EVB 사용안함
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary1, (const UINT16)MELFAS_binary_nLength1, 0);
		}
		else if(comp_ver==1) //for M4 EU suntel,Telus suntel
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary2, (const UINT16)MELFAS_binary_nLength2, 0);
		else if(comp_ver==2) //for M4 EU Inotek,Telus inotek
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary3, (const UINT16)MELFAS_binary_nLength3, 0);
		else if(comp_ver==3) // for M4 dual, Bell 초기 버전
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary4, (const UINT16)MELFAS_binary_nLength4, 0);
		else if(comp_ver==4)//E617(Bell 최신 버전) 
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary5, (const UINT16)MELFAS_binary_nLength5, 0);
		else //for M4 dual 초기 버전 펌웨어 업데이트 진행 안함
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary6, (const UINT16)MELFAS_binary_nLength6, 0);
		if (nRet)
			goto fw_error;
	}
    	#if MELFAS_2CHIP_DOWNLOAD_ENABLE
    		//nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength, 1); // Slave Binary data download
		//if (nRet)
		//	goto fw_error;
    	#endif
	}
    
#endif
	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer
	//return 0;
	
	return nRet;
fw_error:
	mcsdl_erase_flash(0);
	mcsdl_erase_flash(1);
#ifdef FW_FROM_FILE
	spin_unlock(&lock);
#endif
	return nRet;
}
int mms100_ISP_download_binary_data(int dl_mode)
{
	int nRet = 0;
	int retry_cnt = 0;

	mt_set_gpio_mode(GPIO_I2C1_SDA_PIN, GPIO_I2C1_SDA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C1_SDA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SDA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SDA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_I2C1_SCA_PIN, GPIO_I2C1_SCA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C1_SCA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SCA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SCA_PIN, GPIO_PULL_DOWN);

	mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, 2);

#if 0
	#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
	#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

#endif

	//------------------------
	// Run Download
	//------------------------

	for (retry_cnt = 0; retry_cnt < 5; retry_cnt++) {
        if(dl_mode == 0x01) //MELFAS_ISP_DOWNLOAD
    		nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0);
        else //MELFAS_ISC_DOWNLOAD
        {
            //nRet = mcsdl_download( (const UINT8*) MELFAS_MMS100_Initial_binary, (const UINT16)MELFAS_MMS100_Initial_nLength , 0);
        }

		if (!nRet)
			break;
	}

	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer

	mt_set_gpio_mode(GPIO_I2C1_SDA_PIN, GPIO_I2C1_SDA_PIN_M_SDA);
	mt_set_gpio_dir(GPIO_I2C1_SDA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SDA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SDA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_I2C1_SCA_PIN, GPIO_I2C1_SCA_PIN_M_SCL);
	mt_set_gpio_dir(GPIO_I2C1_SCA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SCA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SCA_PIN, GPIO_PULL_UP);

fw_error:
	if (nRet) {
		mcsdl_erase_flash(0);
		mcsdl_erase_flash(1);
	}

	return nRet;
}
예제 #7
0
static int mcsdl_download(const UINT8 *pBianry, const UINT16 unLength, INT8 IdxNum )
{
	int nRet;

	//---------------------------------
	// Check Binary Size
	//---------------------------------
	if( unLength >= MELFAS_FIRMWARE_MAX_SIZE ){

		nRet = MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
		goto MCSDL_DOWNLOAD_FINISH;
	}


	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" - Starting download...\n");
	#endif


	//---------------------------------
	// Make it ready
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Ready\n");
	#endif

	mcsdl_set_ready();

//	mcsdl_delay(MCSDL_DELAY_1MS);    	
	
	//---------------------------------
	// Erase Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Erase\n");
	#endif

	nRet = mcsdl_erase_flash(IdxNum);

	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

//	mcsdl_delay(MCSDL_DELAY_1MS);   	
	//---------------------------------
	// Program Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Program   ");
	#endif

	nRet = mcsdl_program_flash( (UINT8*)pBianry, (UINT16)unLength, IdxNum );
	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;
	//---------------------------------
	// Verify flash
	//---------------------------------
	/*if (IdxNum == 0)*/ {
		#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
		printk(" > Verify===   \n");
		#endif
		nRet = mcsdl_verify_flash( (UINT8*)pBianry, (UINT16)unLength, IdxNum );

		if( nRet != MCSDL_RET_SUCCESS )
			goto MCSDL_DOWNLOAD_FINISH;
	}

	nRet = MCSDL_RET_SUCCESS;


MCSDL_DOWNLOAD_FINISH :

	#if MELFAS_ENABLE_DBG_PRINT
	mcsdl_print_result( nRet );								// Show result
	#endif

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Rebooting\n");
	printk(" - Fin.\n\n");
	printk(" - IdxNum =[%d] \n",IdxNum);   
	#endif

	if(IdxNum == 0)
		mcsdl_reboot_mcs();
	else
	{
		MCSDL_RESETB_SET_LOW();
		MCSDL_RESETB_SET_OUTPUT(1);
		
		mcsdl_delay(MCSDL_DELAY_25MS);						// Delay for Stable VDD
		
		MCSDL_RESETB_SET_INPUT();
		MCSDL_VDD_SET_HIGH();
        msleep(25);
	}
	return nRet;
}
예제 #8
0
static int mcsdl_download(uint8_t *pgm_data,  uint16_t length )
{
	int i;
	int ret;
	uint8_t   cLength;
	uint16_t  nStart_address=0;
	uint8_t   buffer[MCSDL_TRANSFER_LENGTH];

	/* Enter Download mode */
	ret = mcsdl_enter_download_mode();
	if (0 != ret) {
		return -1;
	} 
	printk("mcsdl enter download mode success!\n");
	mdelay(1);

	/* erase flash */
	printk("Erasing...\n");
	ret = mcsdl_erase_flash();
	if (0 != ret) {
		return -1;
	}
	printk("Erase OK!\n");
	mdelay(1);

	/* Verify erase */
	printk("Verifying erase...\n");
	ret = mcsdl_read_flash(buffer, 0x00, 16);		/* Must be '0xFF' after erase */
	if (0 != ret) {
		return -1;
	}
	for(i=0; i<16; i++){
		if( buffer[i] != 0xFF ){
			printk("Verify flash error\n");
			return -1;
		}
	}
	mdelay(1);

	/* Prepare for Program flash */
	printk("Preparing Program...\n");
	ret = mcsdl_prepare_program();
	if (0 != ret) {
		return -1;
	}
	mdelay(1);

	/* Program flash */
	printk("Programing flash...");
	nStart_address = 0;
	cLength  = MCSDL_TRANSFER_LENGTH;
	for( nStart_address = 0; nStart_address < length; nStart_address+=cLength ){
		printk("#");
		if( ( length - nStart_address ) < MCSDL_TRANSFER_LENGTH ){
			cLength  = (uint8_t)(length - nStart_address);
			cLength += (cLength%2);									/* For odd length */
		}
		ret = mcsdl_program_flash(&pgm_data[nStart_address], nStart_address, cLength);
		if (0 != ret) {
			printk("\nProgram flash failed.\n");
			return -1;
		}
		ndelay(500);
	}

	/* Verify flash */
	printk("\nVerifying flash...");
	nStart_address = 0;
	cLength  = MCSDL_TRANSFER_LENGTH;
	for( nStart_address = 0; nStart_address < length; nStart_address+=cLength ){
		printk("#");
		if( ( length - nStart_address ) < MCSDL_TRANSFER_LENGTH ){
			cLength  = (uint8_t)(length - nStart_address);
			cLength += (cLength%2);									/* For odd length */
		}
		ret = mcsdl_read_flash(buffer, nStart_address, cLength);

		if (0 != ret) {
			printk("\nVerify flash read failed.\n");
			return -1;
		}
		for(i=0; i<(int)cLength; i++){
			if( buffer[i] != pgm_data[nStart_address+i] ){
				printk("\nVerify flash compare failed.\n");
				return -1;
			}
		}
		ndelay(500);
	}
	printk("\n");

	/* Reset command */
	mdelay(1);
	ret = i2c_smbus_write_byte(g_client, 0x07);						/* 0x07 is reset cmd */
	if( 0 != ret ){
		printk("reset error\n");
		return -1;
	}
	mdelay(180);

	return 0;
}
예제 #9
0
        Check_IC = readBuffer[3];
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
        printk("\IC Information :0x%02X,  0x%02X\n", readBuffer[3], Check_IC);
#endif
        mcsdl_delay(MCSDL_DELAY_1MS);
    }
#endif

    //---------------------------------
    // Erase Flash
    //---------------------------------
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" > Erase\n");
#endif
	preempt_disable();
    nRet = mcsdl_erase_flash(IdxNum);
	preempt_enable();
    if (nRet != MCSDL_RET_SUCCESS)
        goto MCSDL_DOWNLOAD_FINISH;

#if 1
    mcsdl_delay(MCSDL_DELAY_1MS);
    //--------------------------------------------------------------
    // IC Information write
    //--------------------------------------------------------------
    if (IdxNum == 0)
    {
        mcsdl_select_isp_mode(ISP_MODE_SERIAL_WRITE);

        wordData = ((0x1F00 & 0x1FFF) << 1) | 0x0 ;
        wordData = wordData << 14;
static int mcsdl_download(const UINT8 *pBianry, const UINT16 unLength, INT8 IdxNum )
{
	int nRet;

	//---------------------------------
	// Check Binary Size
	//---------------------------------
	// wcjeong - modified
	//if( unLength >= MELFAS_FIRMWARE_MAX_SIZE ){
	if( unLength >= MELFAS_FIRMWARE_MAX_SIZE ){

		dbg("ISP - mcsdl firmware size error: %u(0x%X) [limit: %u(0x%X)] \n", 
			unLength, unLength, MELFAS_FIRMWARE_MAX_SIZE, MELFAS_FIRMWARE_MAX_SIZE );
		nRet = MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
		goto MCSDL_DOWNLOAD_FINISH;
	}


#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	dbg(" - Starting ISP download...\n");
#endif


	//---------------------------------
	// Make it ready
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	dbg(" > Ready\n");
	#endif

	mcsdl_set_ready();


	//---------------------------------
	// Erase Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	dbg(" > Erase: %d\n", IdxNum);
	#endif

	nRet = mcsdl_erase_flash(IdxNum);

	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

	//---------------------------------
	// Program Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Program   ");
	#endif

//	if(IdxNum > 0)
//		mcsdl_set_ready();

	nRet = mcsdl_program_flash( (UINT8*)pBianry, (UINT16)unLength, IdxNum );
	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

    //---------------------------------
    // Verify flash
    //---------------------------------
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" > Verify    ");
#endif
    nRet = mcsdl_verify_flash((UINT8*)pBianry, (UINT16)unLength, IdxNum);
    if (nRet != MCSDL_RET_SUCCESS)
        goto MCSDL_DOWNLOAD_FINISH;

	nRet = MCSDL_RET_SUCCESS;

MCSDL_DOWNLOAD_FINISH :

#if MELFAS_ENABLE_DBG_PRINT
	mcsdl_print_result( nRet );								// Show result
#endif

#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	dbg(" > Rebooting\n");
	dbg(" - Fin.\n\n");
#endif

    mcsdl_reboot_mcs();

	return nRet;
}
예제 #11
0
int mms100_ISP_download_binary_data(int dl_mode)
{
	int nRet = 0;
	int retry_cnt = 0;

	/*
	//get gpio info _S


	printk("[JHLog] SDA GPIO INFO : Mode = %d, Dir = %d, PullEn = %d, PullSelect = %d",

	mt_get_gpio_mode(GPIO_I2C0_SDA_PIN),

	mt_get_gpio_dir(GPIO_I2C0_SDA_PIN),

	mt_get_gpio_pull_enable(GPIO_I2C0_SDA_PIN),

	mt_get_gpio_pull_select(GPIO_I2C0_SDA_PIN)

	);



	printk("[JHLog] SCA GPIO INFO : Mode = %d, Dir = %d, PullEn = %d, PullSelect = %d",

	mt_get_gpio_mode(GPIO_I2C0_SCA_PIN),

	mt_get_gpio_dir(GPIO_I2C0_SCA_PIN),

	mt_get_gpio_pull_enable(GPIO_I2C0_SCA_PIN),

	mt_get_gpio_pull_select(GPIO_I2C0_SCA_PIN)

	);



	printk("[JHLog] EINT GPIO INFO : Mode = %d, Dir = %d, PullEn = %d, PullSelect = %d",

	mt_get_gpio_mode(GPIO_CTP_EINT_PIN),


	mt_get_gpio_dir(GPIO_CTP_EINT_PIN),

	mt_get_gpio_pull_enable(GPIO_CTP_EINT_PIN),

	mt_get_gpio_pull_select(GPIO_CTP_EINT_PIN)

	);
	//get gpio info _E

	*/

	//set GPIO SDA/SCA/EINT_S

//                                                                   
#if 0 // ori
	mt_set_gpio_mode(GPIO_I2C0_SDA_PIN, GPIO_I2C0_SDA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C0_SDA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C0_SDA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C0_SDA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_I2C0_SCA_PIN, GPIO_I2C0_SCA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C0_SCA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C0_SCA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C0_SCA_PIN, GPIO_PULL_DOWN);

	mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, 2);
#else // blood V3 RevA test
	mt_set_gpio_mode(GPIO_I2C1_SDA_PIN, GPIO_I2C1_SDA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C1_SDA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SDA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SDA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_I2C1_SCA_PIN, GPIO_I2C1_SCA_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_I2C1_SCA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C1_SCA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C1_SCA_PIN, GPIO_PULL_DOWN);

	mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_GPIO);
	mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, 2);
#endif
//                                                                   

	//set GPIO SDA/SCA/EINT_E

#if 0
	#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
	#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

#endif

	//------------------------
	// Run Download
	//------------------------
	//nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0);
	//printk("mmsdownload ret =%d", nRet);

	for (retry_cnt = 0; retry_cnt < 5; retry_cnt++) {
        if(dl_mode == 0x01) //MELFAS_ISP_DOWNLOAD
    		nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0);
        else //MELFAS_ISC_DOWNLOAD
            {
//                nRet = mcsdl_download( (const UINT8*) MELFAS_MMS100_Initial_binary, (const UINT16)MELFAS_MMS100_Initial_nLength , 0);
            }
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
        if(!nRet)
        {
            if(dl_mode == 0x01) //MELFAS_ISP_DOWNLOAD
                nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength, 1); // Slave Binary data download
            else //MELFAS_ISC_DOWNLOAD
//                nRet = mcsdl_download( (const UINT8*) MELFAS_MMS100_Initial_binary, (const UINT16)MELFAS_MMS100_Initial_nLength , 1);
        }
#endif
		if (!nRet)
			break;
	}


	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer

	//Restore GPIO Setting_S

//                                                                   
#if 0 // ori
	mt_set_gpio_mode(GPIO_I2C0_SDA_PIN, GPIO_I2C0_SDA_PIN_M_SDA);	// joohyung.lee
	mt_set_gpio_dir(GPIO_I2C0_SDA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C0_SDA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C0_SDA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_I2C0_SCA_PIN, GPIO_I2C0_SCA_PIN_M_SCL);	// joohyung.lee
	mt_set_gpio_dir(GPIO_I2C0_SCA_PIN, GPIO_DIR_OUT);
	mt_set_gpio_pull_enable(GPIO_I2C0_SCA_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_I2C0_SCA_PIN, GPIO_PULL_UP);

	mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT);	// joohyung.lee
	mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN);
	mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
	mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
#else // blood V3 RevA test
mt_set_gpio_mode(GPIO_I2C1_SDA_PIN, GPIO_I2C1_SDA_PIN_M_SDA);   // joohyung.lee
mt_set_gpio_dir(GPIO_I2C1_SDA_PIN, GPIO_DIR_OUT);
mt_set_gpio_pull_enable(GPIO_I2C1_SDA_PIN, GPIO_PULL_ENABLE);
mt_set_gpio_pull_select(GPIO_I2C1_SDA_PIN, GPIO_PULL_UP);

mt_set_gpio_mode(GPIO_I2C1_SCA_PIN, GPIO_I2C1_SCA_PIN_M_SCL);   // joohyung.lee
mt_set_gpio_dir(GPIO_I2C1_SCA_PIN, GPIO_DIR_OUT);
mt_set_gpio_pull_enable(GPIO_I2C1_SCA_PIN, GPIO_PULL_ENABLE);
mt_set_gpio_pull_select(GPIO_I2C1_SCA_PIN, GPIO_PULL_UP);

mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT);  // joohyung.lee
mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN);
mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
#endif
//                                                                   

	//Restore GPIO Setting_E

fw_error:
	if (nRet) {
		mcsdl_erase_flash(0);
		mcsdl_erase_flash(1);
	}
	return nRet;
}

int mms100_ISP_download_binary_file(void)
{
	int nRet;
    int i;

	UINT8  *pBinary[2] = {NULL,NULL};
	UINT16 nBinary_length[2] ={0,0};
    UINT8 IdxNum = MELFAS_2CHIP_DOWNLOAD_ENABLE;
	//==================================================
	//
	//	1. Read '.bin file'
	//   2. *pBinary[0]       : Binary data(Core + Private Custom)
	//       *pBinary[1]       : Binary data(Public Custom)
	//	   nBinary_length[0] : Firmware size(Core + Private Custom)
	//	   nBinary_length[1] : Firmware size(Public Custom)
	//	3. Run mcsdl_download( pBinary[IdxNum], nBinary_length[IdxNum], IdxNum);
    //       IdxNum : 0 (Master Chip Download)
    //       IdxNum : 1 (2Chip Download)
	//
	//==================================================

	#if 0

		// TO DO : File Process & Get file Size(== Binary size)
		//			This is just a simple sample

		FILE *fp;
		INT  nRead;

		//------------------------------
		// Open a file
		//------------------------------

    if (fopen(fp, "MELFAS_FIRMWARE.bin", "rb") == NULL)
    {
        return MCSDL_RET_FILE_ACCESS_FAILED;
    }

		//------------------------------
		// Get Binary Size
		//------------------------------

		fseek( fp, 0, SEEK_END );

		nBinary_length = (UINT16)ftell(fp);

		//------------------------------
		// Memory allocation
		//------------------------------

		pBinary = (UINT8*)malloc( (INT)nBinary_length );

    if (pBinary == NULL)
    {

        return MCSDL_RET_FILE_ACCESS_FAILED;
    }

		//------------------------------
		// Read binary file
		//------------------------------

		fseek( fp, 0, SEEK_SET );

		nRead = fread( pBinary, 1, (INT)nBinary_length, fp );		// Read binary file

    if (nRead != (INT)nBinary_length)
    {

        fclose(fp);												// Close file

        if (pBinary != NULL)										// free memory alloced.
            free(pBinary);

        return MCSDL_RET_FILE_ACCESS_FAILED;
    }

		//------------------------------
		// Close file
		//------------------------------

		fclose(fp);

	#endif

#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
    melfas_send_download_enable_command();
    mcsdl_delay(MCSDL_DELAY_100US);
#endif

    MELFAS_DISABLE_BASEBAND_ISR();                  // Disable Baseband touch interrupt ISR.
    MELFAS_DISABLE_WATCHDOG_TIMER_RESET();          // Disable Baseband watchdog timer

    for (i = 0;i <= IdxNum;i++)
    {
        if (pBinary[0] != NULL && nBinary_length[0] > 0 && nBinary_length[0] < MELFAS_FIRMWARE_MAX_SIZE)
        {
            //------------------------
            // Run Download
            //------------------------
            nRet = mcsdl_download((const UINT8 *)pBinary[0], (const UINT16)nBinary_length[0], i);
        }
        else
        {
            nRet = MCSDL_RET_WRONG_BINARY;
        }
    }

    MELFAS_ROLLBACK_BASEBAND_ISR();                 // Roll-back Baseband touch interrupt ISR.
    MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();         // Roll-back Baseband watchdog timer

	#if MELFAS_ENABLE_DBG_PRINT
	mcsdl_print_result( nRet );
	#endif

	return ( nRet == MCSDL_RET_SUCCESS );

}
예제 #12
0
static int mcsdl_download(const UINT8 *pBianry, const UINT16 unLength, INT8 IdxNum )
{
	int nRet;

	//---------------------------------
	// Check Binary Size
	//---------------------------------
	if( unLength > MELFAS_FIRMWARE_MAX_SIZE ){

		nRet = MCSDL_RET_PROGRAM_SIZE_IS_WRONG;
		goto MCSDL_DOWNLOAD_FINISH;
	}


	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" - Starting download...\n");
	#endif


	//---------------------------------
	// Make it ready
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Ready start \n");
	#endif

	mcsdl_set_ready();

//	printk("[JHLog]set ready finished \n");

	//---------------------------------
	// Erase Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Erase start : IdxNum = %d\n", IdxNum);
	#endif

	nRet = mcsdl_erase_flash(IdxNum);
	printk(" > Erase end %d\n", nRet);
	//return 0;
	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

	printk(" > Erase succes\n");

	//---------------------------------
	// Program Flash
	//---------------------------------
	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Program   ");
	#endif

//	if(IdxNum > 0)
//		mcsdl_set_ready();

	nRet = mcsdl_program_flash( (UINT8*)pBianry, (UINT16)unLength, IdxNum );
	if( nRet != MCSDL_RET_SUCCESS )
		goto MCSDL_DOWNLOAD_FINISH;

    //---------------------------------
    // Verify flash
    //---------------------------------
//                                                                          
#if 0 // Desc : skip verify to reduce down load time.
#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
    printk(" > Verify    ");
#endif
    nRet = mcsdl_verify_flash((UINT8*)pBianry, (UINT16)unLength, IdxNum);
    if (nRet != MCSDL_RET_SUCCESS)
        goto MCSDL_DOWNLOAD_FINISH;
#endif
//                                           

	nRet = MCSDL_RET_SUCCESS;


MCSDL_DOWNLOAD_FINISH :

	#if MELFAS_ENABLE_DBG_PRINT
	mcsdl_print_result( nRet );								// Show result
	#endif

	#if MELFAS_ENABLE_DBG_PROGRESS_PRINT
	printk(" > Rebooting\n");
	printk(" - Fin.\n\n");
	#endif

    mcsdl_reboot_mcs();

	return nRet;
}
예제 #13
0
int mcsdl_download_binary_data(bool touch_id)
{
	int nRet = 0;
	int retry_cnt = 0;
	long fw1_size = 0;
	unsigned char *fw_data1;
#ifdef FW_FROM_FILE
	struct file *filp;
	loff_t  pos;
	int     ret = 0;
	mm_segment_t oldfs;
	spinlock_t	lock;

	oldfs = get_fs();
	set_fs(get_ds());

	filp = filp_open(MELFAS_FW1, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw1_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw1_size);

	fw_data1 = kmalloc(fw1_size, GFP_KERNEL);
	memset(fw_data1, 0, fw1_size);

	pos = 0;
	memset(fw_data1, 0, fw1_size);
	ret = vfs_read(filp, (char __user *)fw_data1, fw1_size, &pos);

	if(ret != fw1_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW1, ret);
		kfree(fw_data1);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	set_fs(oldfs);
	spin_lock_init(&lock);
	spin_lock(&lock);
#endif

#if 0
	#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
	#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

#endif

	//------------------------
	// Run Download
	//------------------------

#ifdef FW_FROM_FILE
	for (retry_cnt = 0; retry_cnt < 3; retry_cnt++) {
		pr_info("[TSP] ADB - MASTER CHIP Firmware update! try : %d",retry_cnt+1);
		nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 0);
		if (nRet)
			continue;
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
		pr_info("[TSP] ADB - SLAVE CHIP Firmware update! try : %d",retry_cnt+1);
		nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 1);
	if (nRet)
		continue;
#endif
	break;	
	}
	
#else	//FW_FROM_FILE

	for (retry_cnt = 0; retry_cnt < 5; retry_cnt++) {
		if (touch_id)
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 0);
		else
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_1, (const UINT16)MELFAS_binary_nLength_1 , 0);

		if (nRet)
			continue;
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
		if (touch_id)
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 1); // Slave Binary data download
		else
			nRet = mcsdl_download( (const UINT8*) MELFAS_binary_1, (const UINT16)MELFAS_binary_nLength_1, 1); // Slave Binary data download
		if (nRet)
			continue;
#endif
		break;
	}

#endif	//FW_FROM_FILE

	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer

fw_error:
	if (nRet) {
		mcsdl_erase_flash(0);
		mcsdl_erase_flash(1);
	}
#ifdef FW_FROM_FILE
	kfree(fw_data1);
	spin_unlock(&lock);
#endif
	return nRet;
}
//============================================================
//
//	Main Download furnction
//
//   1. Run mcsdl_download( pBinary[IdxNum], nBinary_length[IdxNum], IdxNum);
//       IdxNum : 0 (Master Chip Download)
//       IdxNum : 1 (2Chip Download)
//
//
//============================================================
int mcsdl_download_binary_data(UINT8 master_dl_retry)
{
    int nRet;
#ifdef FW_FROM_FILE
	struct file *filp;
	spinlock_t           lock;
	loff_t  pos;
	int     ret = 0;
	long fw1_size = 0;
	long fw2_size = 0;
	mm_segment_t oldfs;
	unsigned char *fw_data1;
	unsigned char *fw_data2;

	oldfs = get_fs();
	set_fs(get_ds());

	filp = filp_open(MELFAS_FW1, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw1_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw1_size);

	fw_data1 = kmalloc(fw1_size, GFP_KERNEL);
	memset(fw_data1, 0, fw1_size);

	pos = 0;
	memset(fw_data1, 0, fw1_size);
	ret = vfs_read(filp, (char __user *)fw_data1, fw1_size, &pos);

	if(ret != fw1_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW1, ret);
		kfree(fw_data1);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	filp = filp_open(MELFAS_FW2, O_RDONLY, 0);
	if (IS_ERR(filp)) {
		pr_err("file open error:%d\n", (s32)filp);
		return -1;
	}

	fw2_size = filp->f_path.dentry->d_inode->i_size;
	pr_info("Size of the file : %ld(bytes)\n", fw2_size);

	fw_data2 = kmalloc(fw2_size, GFP_KERNEL);
	memset(fw_data2, 0, fw2_size);

	pos = 0;
	memset(fw_data2, 0, fw2_size);
	ret = vfs_read(filp, (char __user *)fw_data2, fw2_size, &pos);

	if(ret != fw2_size) {
		pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW2, ret);
		kfree(fw_data2);
		filp_close(filp, current->files);
		return -1;
	}

	filp_close(filp, current->files);

	set_fs(oldfs);
	spin_lock_init(&lock);
	spin_lock(&lock);
#endif

#if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD
	melfas_send_download_enable_command();
	mcsdl_delay(MCSDL_DELAY_100US);
#endif

	MELFAS_DISABLE_BASEBAND_ISR();					// Disable Baseband touch interrupt ISR.
	MELFAS_DISABLE_WATCHDOG_TIMER_RESET();			// Disable Baseband watchdog timer

	//------------------------
	// Run Download
	//------------------------
#ifdef FW_FROM_FILE
	if(MELFAS_ISP_DOWNLOAD || master_dl_retry)
	{
		nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 0);
		if (nRet)
			goto fw_error;
	}
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
	nRet = mcsdl_download( (const UINT8*) fw_data2, (const UINT16)fw2_size, 1);
	if (nRet)
		goto fw_error;
	spin_unlock(&lock);
#endif
#else
	if(MELFAS_ISP_DOWNLOAD || master_dl_retry)
	{
		nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0);
		if (nRet)
			goto fw_error;
	}
#if MELFAS_2CHIP_DOWNLOAD_ENABLE
	nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 1); // Slave Binary data download
	if (nRet)
		goto fw_error;
#endif
#endif
	MELFAS_ROLLBACK_BASEBAND_ISR();					// Roll-back Baseband touch interrupt ISR.
	MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET();			// Roll-back Baseband watchdog timer
	return 0;
fw_error:
	mcsdl_erase_flash(0);
	mcsdl_erase_flash(1);
#ifdef FW_FROM_FILE
	spin_unlock(&lock);
#endif
	return nRet;
}