// File: chenhn123[P]wdt_util_src/wdt_ct/func_i2c.cpp
// Function: wh_i2c_scan_adaptor_path(WdtDevice*, int*)
int wh_i2c_scan_adaptor_path(WDT_DEV* pdev, int *adaptor_no)
{
	DIR *d;
	struct dirent *dir = NULL;
	int found = 0;
	int adp_no = 0;
	char dev_path[64];			

	/* i2c device path in sysfs */
	char dev_sysfs_adapter_path[] = "/sys/bus/i2c/devices";	

	if (pdev->pparam->argus & OPTION_INFO)
		printf("Scan I2C device in adapter path...\n");		
	int i2c_max_count = get_i2c_dev_count();
        

	wh_printf("i2c_cnt %d \n", i2c_max_count);
	adp_no = 0;
	while (adp_no < i2c_max_count) {
		sprintf(dev_path, "%s/i2c-%d", dev_sysfs_adapter_path, adp_no);
		d = opendir(dev_path);	
		if (d) {	
			wh_printf("scan %s\n", dev_path);
			while ((dir = readdir(d)) != NULL) {
				if (memcmp(dir->d_name, ACPI_NAME_HID, strlen(ACPI_NAME_HID)) == 0) {
					char* reg_gen_hid  = strdup(&dir->d_name[4]);
					wh_printf("current reg_gen_hid:%s \n", reg_gen_hid);
					pdev->board_info.i2c_address = get_i2c_address_map(reg_gen_hid);
					wh_printf("i2c_address %x\n", pdev->board_info.i2c_address);
					found = 1;
					break;	
				}				
			}
		}
		closedir(d);
	
		if (found)
			break;
		
		adp_no ++;
	}

	*adaptor_no = adp_no;

	return found;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq 0x4da0(%rip), %rax      # 0x10870
movq %rax, -0x90(%rbp)
movq 0x4d9a(%rip), %rax      # 0x10878
movq %rax, -0x88(%rbp)
movl 0x4d95(%rip), %eax      # 0x10880
movl %eax, -0x80(%rbp)
movb 0x4d90(%rip), %al       # 0x10884
movb %al, -0x7c(%rbp)
movq -0x8(%rbp), %rax
movq 0x280(%rax), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xbb1a
leaq 0x4de7(%rip), %rdi      # 0x108fa
movb $0x0, %al
callq 0x2050
callq 0xb9d0
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %esi
leaq 0x4dec(%rip), %rdi      # 0x1091e
movb $0x0, %al
callq 0x24e0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x94(%rbp), %eax
jge 0xbc5c
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
movl -0x28(%rbp), %ecx
leaq 0x4dc7(%rip), %rsi      # 0x1092b
movb $0x0, %al
callq 0x2080
leaq -0x70(%rbp), %rdi
callq 0x2240
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xbc3d
leaq -0x70(%rbp), %rsi
leaq 0x4da7(%rip), %rdi      # 0x10935
movb $0x0, %al
callq 0x24e0
movq -0x18(%rbp), %rdi
callq 0x2250
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0xbc3b
movq -0x20(%rbp), %rax
addq $0x13, %rax
movq (%rax), %rax
movabsq $0x544844572d633269, %rcx # imm = 0x544844572D633269
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xbc36
movq -0x20(%rbp), %rdi
addq $0x13, %rdi
addq $0x4, %rdi
callq 0x22b0
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rsi
leaq 0x4d49(%rip), %rdi      # 0x1093e
movb $0x0, %al
callq 0x24e0
movq -0xa0(%rbp), %rdi
callq 0xb830
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x1d6(%rax)
movq -0x8(%rbp), %rax
movzbl 0x1d6(%rax), %esi
leaq 0x437a(%rip), %rdi      # 0xffa0
movb $0x0, %al
callq 0x24e0
movl $0x1, -0x24(%rbp)
jmp 0xbc3b
jmp 0xbb95
jmp 0xbc3d
movq -0x18(%rbp), %rdi
callq 0x2280
cmpl $0x0, -0x24(%rbp)
je 0xbc4e
jmp 0xbc5c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xbb40
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)