Changeset 5400

Show
Ignore:
Timestamp:
11/22/08 17:05:13 (5 years ago)
Author:
khali
Message:

Merge LM87 and ADM1024 detection in a single function.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r5399 r5400  
    758758       driver => "lm87", 
    759759       i2c_addrs => [0x2c..0x2e], 
    760        i2c_detect => sub { lm87_detect(@_); }, 
     760       i2c_detect => sub { lm87_detect(0, @_); }, 
    761761     }, 
    762762     { 
     
    764764       driver => "lm87", 
    765765       i2c_addrs => [0x2c..0x2e], 
    766        i2c_detect => sub { adm1024_detect(0, @_); }, 
     766       i2c_detect => sub { lm87_detect(1, @_); }, 
    767767     }, 
    768768     { 
     
    44294429} 
    44304430 
    4431 # $_[0]: A reference to the file descriptor to access this chip. 
    4432 # $_[1]: Address 
     4431# $_[0]: Chip to detect (0 = LM87, 1 = ADM1024) 
     4432# $_[1]: A reference to the file descriptor to access this chip. 
     4433# $_[2]: Address 
    44334434# Returns: undef if not detected, (7) if detected. 
    4434 # Registers used: 0x3E, 0x3F 
    4435 #        Assume lower 2 bits of reg 0x3F are for revisions. 
     4435# Registers used: 
     4436#   0x3e: Company ID 
     4437#   0x3f: Revision 
     4438#   0x40: Configuration 
    44364439sub lm87_detect 
    44374440{ 
    4438   my ($file, $addr) = @_; 
    4439   return if i2c_smbus_read_byte_data($file, 0x3e) != 0x02; 
    4440   return if (i2c_smbus_read_byte_data($file, 0x3f) & 0xfc) != 0x04; 
     4441  my ($chip, $file, $addr) = @_; 
     4442  my $cid = i2c_smbus_read_byte_data($file, 0x3e); 
     4443  my $rev = i2c_smbus_read_byte_data($file, 0x3f); 
     4444 
     4445  if ($chip == 0) { 
     4446    return if $cid != 0x02;     # National Semiconductor 
     4447    return if ($rev & 0xfc) != 0x04; 
     4448  } 
     4449  if ($chip == 1) { 
     4450    return if $cid != 0x41;     # Analog Devices 
     4451    return if ($rev & 0xf0) != 0x10; 
     4452  } 
     4453 
     4454  my $cfg = i2c_smbus_read_byte_data($file, 0x40); 
     4455  return if ($cfg & 0x80) != 0x00; 
     4456 
    44414457  return (7); 
    44424458} 
     
    47964812  return unless ($reg == 0x41); 
    47974813  return unless (i2c_smbus_read_byte_data($file, 0x17) & 0xf0) == 0x40; 
    4798   return (8); 
    4799 } 
    4800  
    4801 # $_[0]: Chip to detect (0 = ADM1024) 
    4802 # $_[1]: A reference to the file descriptor to access this chip. 
    4803 # $_[2]: Address 
    4804 # Returns: undef if not detected, (8) if detected. 
    4805 # Registers used: 
    4806 #   0x3e: Company ID 
    4807 #   0x3f: Revision 
    4808 #   0x40: Configuration 
    4809 sub adm1024_detect 
    4810 { 
    4811   my $reg; 
    4812   my ($chip, $file, $addr) = @_; 
    4813   $reg = i2c_smbus_read_byte_data($file, 0x3e); 
    4814   return unless ($reg == 0x41); 
    4815   return unless (i2c_smbus_read_byte_data($file, 0x40) & 0x80) == 0x00; 
    4816   return unless (i2c_smbus_read_byte_data($file, 0x3f) & 0xf0) == 0x10; 
    48174814  return (8); 
    48184815}