Ejemplo n.º 1
0
int
GetMpuType(struct wacom_i2c *wac_i2c, int* pMpuType)
{
	int rv;

	if (!flash_query(wac_i2c))
	{
		if (!wacom_i2c_flash_cmd_g9(wac_i2c))
		{
			return EXIT_FAIL_ENTER_FLASH_MODE;
		}
		else{
			msleep(100);
			if (!flash_query(wac_i2c))
			{
				return EXIT_FAIL_FLASH_QUERY;
			}
		}
	}

	rv = flash_mputype(wac_i2c, pMpuType);
	if (rv)
		return EXIT_OK;
	else
		return EXIT_FAIL_GET_MPU_TYPE;
}
int wacom_i2c_flash_w9012(struct wacom_i2c *wac_i2c, unsigned char *fw_data)
{
	bool bRet = false;
	int result, i;
	int eraseBlock[200], eraseBlockNum;
	int iBLVer, iMpuType;
	unsigned long max_address = 0;	/* Max.address of Load data */
	unsigned long start_address = 0x2000;	/* Start.address of Load data */

	/*Obtain boot loader version */
	if (!flash_blver(wac_i2c, &iBLVer)) {
		printk(KERN_DEBUG"epen:%s failed to get Boot Loader version \n", __func__);
		return -EXIT_FAIL_GET_BOOT_LOADER_VERSION;
	}
	printk(KERN_DEBUG"epen:BL version: %x \n", iBLVer);

	/*Obtain MPU type: this can be manually done in user space */
	if (!flash_mputype(wac_i2c, &iMpuType)) {
		printk(KERN_DEBUG"epen:%s failed to get MPU type \n", __func__);
		return -EXIT_FAIL_GET_MPU_TYPE;
	}
	if (iMpuType != MPU_W9012) {
		printk(KERN_DEBUG"epen:MPU is not for W9012 : %x \n", iMpuType);
		return -EXIT_FAIL_GET_MPU_TYPE;
	}
	printk(KERN_DEBUG"epen:MPU type: %x \n", iMpuType);

	/*-----------------------------------*/
	/*Flashing operation starts from here */

	/*Set start and end address and block numbers */
	eraseBlockNum = 0;
	start_address = W9012_START_ADDR;
	max_address = W9012_END_ADDR;
	for (i = BLOCK_NUM; i >= 8; i--) {
		eraseBlock[eraseBlockNum] = i;
		eraseBlockNum++;
	}

	msleep(300);

	/*Erase the old program */
	printk(KERN_DEBUG"epen:%s erasing the current firmware \n", __func__);
	bRet = flash_erase(wac_i2c, eraseBlock, eraseBlockNum);
	if (!bRet) {
		printk(KERN_DEBUG"epen:%s failed to erase the user program \n", __func__);
		result = -EXIT_FAIL_ERASE;
		goto fail;
	}

	/*Write the new program */
	printk(KERN_DEBUG"epen:%s writing new firmware \n", __func__);
	bRet = flash_write(wac_i2c, fw_data, start_address, &max_address);
	if (!bRet) {
		printk(KERN_DEBUG"epen:%s failed to write firmware \n", __func__);
		result = -EXIT_FAIL_WRITE_FIRMWARE;
		goto fail;
	}

	/*Return to the user mode */
	printk(KERN_DEBUG"epen:%s closing the boot mode \n", __func__);
	bRet = flash_end(wac_i2c);
	if (!bRet) {
		printk(KERN_DEBUG"epen:%s closing boot mode failed  \n", __func__);
		result = -EXIT_FAIL_WRITING_MARK_NOT_SET;
		goto fail;
	}

	printk(KERN_DEBUG"epen:%s write and verify completed \n", __func__);
	result = EXIT_OK;

 fail:
	return result;
}