// File: goodix[P]gdix_hid_firmware_update/gtx9/gtx9_i2c_update.cpp
// Function: gdix_load_isp(firmware_data*)
static int gdix_load_isp(struct firmware_data *fw_data)
{
	struct goodix_fw_version isp_fw_version;
	struct fw_subsys_info *fw_isp;
	uint8_t reg_val[8] = {0x00};
	int r;

	fw_isp = &fw_data->fw_summary.subsys[0];

	gdix_dbg("Loading ISP start\n");
	r = i2c_write(0x57000, fw_isp->data, fw_isp->size);
	if (r < 0) {
		gdix_err("Loading ISP error\n");
		return r;
	}

	gdix_dbg("Success send ISP data\n");

	/* SET BOOT OPTION TO 0X55 */
	memset(reg_val, 0x55, 8);
	r = i2c_write(0x10000, reg_val, 8);
	if (r < 0) {
		gdix_err("Failed set REG_CPU_RUN_FROM flag\n");
		return r;
	}
	gdix_dbg("Success write [8]0x55 to 0x%x\n", 0x10000);

	gdix_soft_reset(100);
	/*check isp state */
	if (gdix_read_version(&isp_fw_version)) {
		gdix_err("failed read isp version\n");
		return -2;
	}
	if (memcmp(&isp_fw_version.patch_pid[3], "ISP", 3)) {
		gdix_err("patch id error %c%c%c != %s\n", isp_fw_version.patch_pid[3],
				 isp_fw_version.patch_pid[4], isp_fw_version.patch_pid[5],
				 "ISP");
		return -3;
	}
	gdix_dbg("ISP running successfully\n");
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x50a0
movq -0x10(%rbp), %rax
addq $0x22, %rax
movq %rax, -0x38(%rbp)
leaq 0xf65a(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16c68
movq 0xf36d(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x8c95(%rip), %rsi      # 0x1f8ea
leaq 0x8cb2(%rip), %rdx      # 0x1f90e
movl $0x1e6, %ecx            # imm = 0x1E6
movb $0x0, %al
callq 0x5190
jmp 0x16c6a
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x38(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x57000, %edi          # imm = 0x57000
callq 0x15870
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x16ccb
jmp 0x16c8e
leaq 0xf604(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16cbe
movq 0xf337(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x8c71(%rip), %rsi      # 0x1f91c
leaq 0x8c5c(%rip), %rdx      # 0x1f90e
movl $0x1e9, %ecx            # imm = 0x1E9
movb $0x0, %al
callq 0x5190
jmp 0x16cc0
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x16eb8
jmp 0x16ccd
leaq 0xf5c5(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16cfd
movq 0xf2d8(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x8c56(%rip), %rsi      # 0x1f940
leaq 0x8c1d(%rip), %rdx      # 0x1f90e
movl $0x1ed, %ecx            # imm = 0x1ED
movb $0x0, %al
callq 0x5190
jmp 0x16cff
leaq -0x40(%rbp), %rdi
movl $0x55, %esi
movl $0x8, %edx
callq 0x50a0
leaq -0x40(%rbp), %rsi
movl $0x10000, %edi          # imm = 0x10000
movl $0x8, %edx
callq 0x15870
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x16d6d
jmp 0x16d30
leaq 0xf562(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16d60
movq 0xf295(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x8c1b(%rip), %rsi      # 0x1f968
leaq 0x8bba(%rip), %rdx      # 0x1f90e
movl $0x1f3, %ecx            # imm = 0x1F3
movb $0x0, %al
callq 0x5190
jmp 0x16d62
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x16eb8
jmp 0x16d6f
leaq 0xf523(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16da5
movq 0xf236(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x8c0f(%rip), %rsi      # 0x1f99b
leaq 0x8b7b(%rip), %rdx      # 0x1f90e
movl $0x1f6, %ecx            # imm = 0x1F6
movl $0x10000, %r8d          # imm = 0x10000
movb $0x0, %al
callq 0x5190
jmp 0x16da7
movl $0x64, %edi
callq 0x16bd0
leaq -0x2c(%rbp), %rdi
callq 0x15b50
cmpl $0x0, %eax
je 0x16dff
jmp 0x16dc1
leaq 0xf4d1(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16df1
movq 0xf204(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
leaq 0x8bed(%rip), %rsi      # 0x1f9cb
leaq 0x8b29(%rip), %rdx      # 0x1f90e
movl $0x1fb, %ecx            # imm = 0x1FB
movb $0x0, %al
callq 0x5190
jmp 0x16df3
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x16eb8
leaq -0x2c(%rbp), %rdi
addq $0xa, %rdi
addq $0x3, %rdi
leaq 0x8be3(%rip), %rsi      # 0x1f9f5
movl $0x3, %edx
callq 0x5090
cmpl $0x0, %eax
je 0x16e7d
jmp 0x16e23
leaq 0xf46f(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16e72
movq 0xf1a2(%rip), %rax      # 0x25fd8
movq (%rax), %rdi
movzbl -0x1f(%rbp), %r8d
movzbl -0x1e(%rbp), %r9d
movzbl -0x1d(%rbp), %r10d
leaq 0x8baa(%rip), %rsi      # 0x1f9f9
leaq 0x8ab8(%rip), %rdx      # 0x1f90e
movl $0x201, %ecx            # imm = 0x201
leaq 0x8b93(%rip), %rax      # 0x1f9f5
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x5190
jmp 0x16e74
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x16eb8
jmp 0x16e7f
leaq 0xf413(%rip), %rax      # 0x26299
testb $0x1, (%rax)
je 0x16eaf
movq 0xf126(%rip), %rax      # 0x25fb8
movq (%rax), %rdi
leaq 0x8b8b(%rip), %rsi      # 0x1fa27
leaq 0x8a6b(%rip), %rdx      # 0x1f90e
movl $0x204, %ecx            # imm = 0x204
movb $0x0, %al
callq 0x5190
jmp 0x16eb1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)