Changeset 4086 for lm-sensors/trunk/prog/detect/sensors-detect
- Timestamp:
- 08/09/06 08:45:48 (7 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/prog/detect/sensors-detect (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/detect/sensors-detect
r4085 r4086 2438 2438 2439 2439 use constant IOCTL_I2C_SLAVE => 0x0703; 2440 use constant IOCTL_I2C_FUNCS => 0x0705; 2440 2441 use constant IOCTL_I2C_SMBUS => 0x0720; 2441 2442 … … 2447 2448 use constant SMBUS_BYTE_DATA => 2; 2448 2449 use constant SMBUS_WORD_DATA => 3; 2450 2451 use constant I2C_FUNC_SMBUS_QUICK => 0x00010000; 2452 use constant I2C_FUNC_SMBUS_READ_BYTE => 0x00020000; 2453 2454 # Get the i2c adapter's functionalities 2455 # $_[0]: Reference to an opened filehandle 2456 # Returns: -1 on failure, functionality bitfield on success. 2457 sub i2c_get_funcs($) 2458 { 2459 my $file = shift; 2460 my $funcs; 2461 2462 ioctl $file, IOCTL_I2C_FUNCS, $funcs='' or return -1; 2463 $funcs = unpack "L", $funcs; 2464 2465 return $funcs; 2466 } 2449 2467 2450 2468 # Select the device to communicate with through its address. … … 2533 2551 # $_[0]: Reference to an opened filehandle 2534 2552 # $_[1]: Address 2553 # $_[2]: Functionalities of this i2c adapter 2535 2554 # Returns: 1 on successful probing, 0 else. 2536 2555 # This function is meant to prevent AT24RF08 corruption and write-only 2537 2556 # chips locks. This is done by choosing the best probing method depending 2538 2557 # on the address range. 2539 sub i2c_probe 2540 { 2541 my ($file, $addr ) = @_;2558 sub i2c_probe($$$) 2559 { 2560 my ($file, $addr, $funcs) = @_; 2542 2561 my $data = []; 2543 2562 if (($addr >= 0x50 && $addr <= 0x5F) … … 2548 2567 # some EEPROMs write-protect themselves permanently on almost any write to 2549 2568 # their page protection address. 2569 return 0 unless ($funcs & I2C_FUNC_SMBUS_READ_BYTE); 2550 2570 return i2c_smbus_access($file, SMBUS_READ, 0, SMBUS_BYTE, $data); 2551 2571 } else { 2572 return 0 unless ($funcs & I2C_FUNC_SMBUS_QUICK); 2552 2573 return i2c_smbus_access($file, SMBUS_WRITE, 0, SMBUS_QUICK, $data); 2553 2574 } … … 2800 2821 { 2801 2822 my ($adapter_nr, $adapter_name, $adapter_driver, $not_to_scan) = @_; 2802 my ($ chip, $addr, $conf,@chips,$new_hash,$other_addr);2823 my ($funcs, $chip, $addr, $conf, @chips, $new_hash, $other_addr); 2803 2824 2804 2825 # As we modify it, we need a copy … … 2808 2829 (print "Can't open $dev_i2c$adapter_nr\n"), return; 2809 2830 binmode FILE; 2831 2832 # Can we probe this adapter? 2833 $funcs = i2c_get_funcs(\*FILE); 2834 if ($funcs < 0) { 2835 print "Adapter failed to provide its functionalities, skipping.\n"; 2836 return; 2837 } 2838 if (!($funcs & (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_READ_BYTE))) { 2839 print "Adapter cannot be probed, skipping.\n"; 2840 return; 2841 } 2842 if (~$funcs & (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_READ_BYTE)) { 2843 print "Adapter doesn't support all probing functions.\n", 2844 "Some addresses won't be probed.\n"; 2845 } 2810 2846 2811 2847 # Now scan each address in turn … … 2856 2892 } 2857 2893 2858 next unless i2c_probe(\*FILE, $addr );2894 next unless i2c_probe(\*FILE, $addr, $funcs); 2859 2895 printf "Client found at address 0x%02x\n",$addr; 2860 2896
