// File: goodix[P]gdix_hid_firmware_update/gtx9/gtx9_i2c_update.cpp
// Function: gdix_read_version(goodix_fw_version*)
static int gdix_read_version(struct goodix_fw_version *version)
{
	int ret;
	uint8_t temp_pid[8] = {0};
	uint8_t buf[sizeof(struct goodix_fw_version)] = {0};

	ret = i2c_read(0x10014, buf, sizeof(buf));
	if (ret < 0) {
		gdix_err("read version failed\n");
		return ret;
	}

	if (checksum_cmp(buf, sizeof(buf), CHECKSUM_MODE_U8_LE)) {
		gdix_err("invalid fw version, checksum err\n");
		return -1;
	}

	memcpy(version, buf, sizeof(*version));
	memcpy(temp_pid, version->rom_pid, sizeof(version->rom_pid));
	gdix_dbg("rom_pid:%s\n", temp_pid);
	gdix_dbg("rom_vid:%*ph\n", (int)sizeof(version->rom_vid), version->rom_vid);
	gdix_dbg("pid:%s\n", version->patch_pid);
	gdix_dbg("vid:%*ph\n", (int)sizeof(version->patch_vid), version->patch_vid);
	gdix_dbg("sensor_id:%d\n", version->sensor_id);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x1c(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x50a0
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x50a0
leaq -0x40(%rbp), %rsi
movl $0x10014, %edi          # imm = 0x10014
movl $0x1c, %edx
callq 0x168d0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x15bd7
jmp 0x15b9a
leaq 0x106f8(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15bca
movq 0x1042b(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x98ec(%rip), %rsi      # 0x1f4a3
leaq 0x990b(%rip), %rdx      # 0x1f4c9
movl $0x1c9, %ecx            # imm = 0x1C9
movb $0x0, %al
callq 0x5190
jmp 0x15bcc
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x15d98
leaq -0x40(%rbp), %rdi
movl $0x1c, %esi
xorl %edx, %edx
callq 0x14e40
cmpl $0x0, %eax
je 0x15c2c
jmp 0x15bee
leaq 0x106a4(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15c1e
movq 0x103d7(%rip), %rax     # 0x25fd8
movq (%rax), %rdi
leaq 0x98d0(%rip), %rsi      # 0x1f4db
leaq 0x98b7(%rip), %rdx      # 0x1f4c9
movl $0x1ce, %ecx            # imm = 0x1CE
movb $0x0, %al
callq 0x5190
jmp 0x15c20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15d98
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x28(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -0x1c(%rbp)
movw 0x4(%rax), %ax
movw %ax, -0x18(%rbp)
leaq 0x10634(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15c92
movq 0x10347(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
leaq -0x1c(%rbp), %r8
leaq 0x988f(%rip), %rsi      # 0x1f50e
leaq 0x9843(%rip), %rdx      # 0x1f4c9
movl $0x1d4, %ecx            # imm = 0x1D4
movb $0x0, %al
callq 0x5190
jmp 0x15c94
jmp 0x15c96
leaq 0x105fc(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15cd4
movq 0x1030f(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movq -0x10(%rbp), %r9
addq $0x6, %r9
leaq 0x9870(%rip), %rsi      # 0x1f52b
leaq 0x9807(%rip), %rdx      # 0x1f4c9
movl $0x1d5, %ecx            # imm = 0x1D5
movl $0x3, %r8d
movb $0x0, %al
callq 0x5190
jmp 0x15cd6
jmp 0x15cd8
leaq 0x105ba(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15d10
movq 0x102cd(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movq -0x10(%rbp), %r8
addq $0xa, %r8
leaq 0x7172(%rip), %rsi      # 0x1ce6f
leaq 0x97c5(%rip), %rdx      # 0x1f4c9
movl $0x1d6, %ecx            # imm = 0x1D6
movb $0x0, %al
callq 0x5190
jmp 0x15d12
jmp 0x15d14
leaq 0x1057e(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15d52
movq 0x10291(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movq -0x10(%rbp), %r9
addq $0x12, %r9
leaq 0x9811(%rip), %rsi      # 0x1f54a
leaq 0x9789(%rip), %rdx      # 0x1f4c9
movl $0x1d7, %ecx            # imm = 0x1D7
movl $0x4, %r8d
movb $0x0, %al
callq 0x5190
jmp 0x15d54
jmp 0x15d56
leaq 0x1053c(%rip), %rax     # 0x26299
testb $0x1, (%rax)
je 0x15d8f
movq 0x1024f(%rip), %rax     # 0x25fb8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x17(%rax), %r8d
leaq 0x97e9(%rip), %rsi      # 0x1f565
leaq 0x9746(%rip), %rdx      # 0x1f4c9
movl $0x1d8, %ecx            # imm = 0x1D8
movb $0x0, %al
callq 0x5190
jmp 0x15d91
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)