Show
Ignore:
Timestamp:
04/03/07 14:55:30 (6 years ago)
Author:
mmh
Message:

Merge from trunk (4303:4355) out to 3.0.0 branch.

Files:
1 modified

Legend:

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

    r4271 r4357  
    4848######################### 
    4949 
    50 use vars qw(@pci_adapters @chip_ids @superio_ids @cpu_ids $revision); 
     50use vars qw(@pci_adapters @chip_ids $i2c_addresses_to_scan @superio_ids 
     51            @cpu_ids $revision); 
    5152 
    5253$revision = '$Revision$ ($Date$)'; 
     
    247248     } , 
    248249     { 
     250       vendid => 0x1106, 
     251       devid  => 0x8324, 
     252       procid => "VIA Technologies CX700 South Bridge", 
     253       driver => "i2c-viapro", 
     254       match => qr/^SMBus V(IA|ia) Pro adapter at/, 
     255     }, 
     256     { 
    249257       vendid => 0x1039, 
    250258       devid  => 0x5597, 
     
    530538       devid => 0x03eb, 
    531539       procid => "nVidia Corporation nForce4 SMBus (MCP61)", 
    532        driver => "to-be-tested", 
     540       driver => "i2c-nforce2", 
    533541       match => qr/^SMBus nForce2 adapter at /, 
    534542     }, 
     
    537545       devid => 0x0446, 
    538546       procid => "nVidia Corporation nForce4 SMBus (MCP65)", 
    539        driver => "to-be-tested", 
     547       driver => "i2c-nforce2", 
    540548       match => qr/^SMBus nForce2 adapter at /, 
    541549     }, 
     
    812820       driver => "lm75", 
    813821       i2c_addrs => [0x48..0x4f], 
    814        i2c_detect => sub { lm75_detect(@_); }, 
    815      } , 
     822       i2c_detect => sub { lm75_detect(0, @_); }, 
     823     }, 
     824     { 
     825       name => "Dallas Semiconductor DS75", 
     826       driver => "lm75", 
     827       i2c_addrs => [0x48..0x4f], 
     828       i2c_detect => sub { lm75_detect(1, @_); }, 
     829     }, 
    816830     { 
    817831       name => "National Semiconductor LM77", 
     
    968982     { 
    969983       name => "Winbond W83627HF", 
    970        driver => "w83781d", 
    971        i2c_addrs => [0x20..0x2f],  
     984       driver => "use-isa-instead", 
     985       i2c_addrs => [0x28..0x2f], 
    972986       i2c_detect => sub { w83781d_detect(3, @_); }, 
    973        isa_addrs => [0x290], 
    974        isa_detect => sub { w83781d_isa_detect(3, @_); }, 
    975        alias_detect => sub { w83781d_alias_detect(3, @_); }, 
    976      } , 
     987     }, 
    977988     { 
    978989       name => "Winbond W83627EHF", 
     
    11381149     }, 
    11391150     { 
     1151       name => "Maxim MAX1668", 
     1152       driver => "max1668", 
     1153       i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], 
     1154       i2c_detect => sub { max1668_detect(0, @_); }, 
     1155     }, 
     1156     { 
     1157       name => "Maxim MAX1805", 
     1158       driver => "max1668", 
     1159       i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], 
     1160       i2c_detect => sub { max1668_detect(1, @_); }, 
     1161     }, 
     1162     { 
     1163       name => "Maxim MAX1989", 
     1164       driver => "max1668", 
     1165       i2c_addrs => [0x18..0x1a,0x29..0x2b,0x4c..0x4e], 
     1166       i2c_detect => sub { max1668_detect(2, @_); }, 
     1167     }, 
     1168     { 
    11401169       name => "Maxim MAX6650/MAX6651", 
    11411170       driver => "max6650", 
     
    11441173     }, 
    11451174     { 
     1175       name => "Maxim MAX6655/MAX6656", 
     1176       driver => "max6655", 
     1177       i2c_addrs => [0x18..0x1a, 0x29..0x2b, 0x4c..0x4e], 
     1178       i2c_detect => sub { max6655_detect(0, @_); }, 
     1179     }, 
     1180     { 
    11461181       name => "TI THMC10", 
    11471182       driver => "adm1021", 
     
    13531388       i2c_detect => sub { eeprom_detect(1, @_); }, 
    13541389     }, 
    1355 # Disabled by default (potentially dangerous) 
    1356 #     { 
    1357 #       name => "SPD EEPROM with Software Write-Protect", 
    1358 #       driver => "eeprom", 
    1359 #       i2c_addrs => [0x50..0x57], 
    1360 #       i2c_detect => sub { eeprom_detect(2, @_); }, 
    1361 #     }, 
    13621390     { 
    13631391       name => "EDID EEPROM", 
     
    13911419     }, 
    13921420     { 
    1393        name => "SMSC LPC47M15x, LPC47M192 or LPC47M997", 
     1421       name => "SMSC LPC47M15x/192/292/997", 
    13941422       driver => "smsc47m192", 
    13951423       i2c_addrs => [0x2c..0x2d], 
     
    13981426     { 
    13991427       name => "SMSC DME1737", 
    1400        driver => "to-be-written", 
     1428       driver => "dme1737", 
    14011429       i2c_addrs => [0x2c..0x2e], 
    14021430       i2c_detect => sub { dme1737_detect(@_); }, 
     
    14701498     { 
    14711499       name => "Maxim MAX6900", 
    1472        driver => "to-be-written", 
     1500       driver => "not-a-sensor", 
    14731501       i2c_addrs => [0x50], 
    14741502       i2c_detect => sub { max6900_detect(@_); }, 
    1475      }, 
    1476      { 
    1477        name => "SMBus 2.0 ARP-Capable Device", 
    1478        driver => "not-a-sensor", 
    1479        i2c_addrs => [0x61], 
    1480        i2c_detect => sub { arp_detect(@_); }, 
    14811503     }, 
    14821504     { 
     
    15371559#      capabilities (listing such chips here removes the need of manual 
    15381560#      lookup when people report them). 
     1561#      Put in exactly "via-smbus-only" if this is a Super-I/O chip whose 
     1562#      hardware monitoring registers can only be accessed via the SMBus. 
    15391563#  devid: The device ID(s) we have to match (base device) 
    15401564#  devid_mask (optional): Bitmask to apply before checking the device ID 
     
    15501574#  enter: The password sequence to write to the address register 
    15511575#  chips: Array of chips 
     1576# The order of families matters, because we stop as soon as one family 
     1577# succeeds. So we have to list families with shorter password sequences 
     1578# first. 
    15521579@superio_ids = ( 
    1553   { 
    1554     family => "ITE", 
    1555     guess => 0x290, 
    1556     enter => 
    1557     { 
    1558       0x2e => [0x87, 0x01, 0x55, 0x55], 
    1559       0x4e => [0x87, 0x01, 0x55, 0xaa], 
    1560     }, 
    1561     chips => 
    1562     [ 
    1563       { 
    1564         name => "ITE IT8702F Super IO Sensors", 
    1565         driver => "to-be-written", 
    1566         devid => 0x8702, 
    1567         logdev => 0x04, 
    1568       }, 
    1569       { 
    1570         name => "ITE IT8705F Super IO Sensors", 
    1571         driver => "it87", 
    1572         devid => 0x8705, 
    1573         logdev => 0x04, 
    1574       }, 
    1575       { 
    1576         name => "ITE IT8712F Super IO Sensors", 
    1577         driver => "it87", 
    1578         devid => 0x8712, 
    1579         logdev => 0x04, 
    1580         alias_detect => sub { ite_alias_detect(0, @_); }, 
    1581       }, 
    1582       { 
    1583         name => "ITE IT8716F Super IO Sensors", 
    1584         driver => "it87", 
    1585         devid => 0x8716, 
    1586         logdev => 0x04, 
    1587       }, 
    1588       { 
    1589         name => "ITE IT8718F Super IO Sensors", 
    1590         driver => "it87", 
    1591         devid => 0x8718, 
    1592         logdev => 0x04, 
    1593       }, 
    1594     ], 
    1595   }, 
    15961580  { 
    15971581    family => "National Semiconductor", 
     
    16031587    chips => 
    16041588    [ 
     1589      { 
     1590        name => "Nat. Semi. PC8374L Super IO Sensors", 
     1591        driver => "to-be-written", 
     1592        devid => 0xf1, 
     1593        logdev => 0x08, 
     1594      }, 
    16051595      { 
    16061596        name => "Nat. Semi. PC87351 Super IO Fan Sensors", 
     
    17491739      }, 
    17501740      { 
     1741        name => "SMSC LPC47M292 Super IO Fan Sensors", 
     1742        driver => "smsc47m1", 
     1743        devid => 0x6b, 
     1744        logdev => 0x0a, 
     1745      }, 
     1746      { 
    17511747        name => "SMSC LPC47S42x Super IO Fan Sensors", 
    17521748        driver => "to-be-written", 
     
    17851781      }, 
    17861782      { 
     1783        name => "SMSC SCH5504-NS Super IO", 
     1784        # No datasheet 
     1785        driver => "not-a-sensor", 
     1786        devid => 0x79, 
     1787      }, 
     1788      { 
    17871789        name => "SMSC LPC47M584-NC Super IO", 
    17881790        # No datasheet 
     
    17921794        name => "SMSC DME1737 Super IO", 
    17931795        # Hardware monitoring features are accessed on the SMBus 
    1794         driver => "not-a-sensor", 
     1796        driver => "via-smbus-only", 
    17951797        devid => 0x78, 
     1798      }, 
     1799      { 
     1800        name => "SMSC DME1737 Super IO", 
     1801        # The DME1737 shows up twice in this list because it can return either 
     1802        # 0x78 or 0x77 as its device ID. 
     1803        # Hardware monitoring features are accessed on the SMBus 
     1804        driver => "via-smbus-only", 
     1805        devid => 0x77, 
    17961806      }, 
    17971807    ], 
     
    18191829        devid => 0x52, 
    18201830        logdev => 0x0b, 
     1831        alias_detect => sub { w83781d_alias_detect(3, @_); }, 
    18211832      }, 
    18221833      { 
     
    19041915    ], 
    19051916  }, 
     1917  { 
     1918    family => "ITE", 
     1919    guess => 0x290, 
     1920    enter => 
     1921    { 
     1922      0x2e => [0x87, 0x01, 0x55, 0x55], 
     1923      0x4e => [0x87, 0x01, 0x55, 0xaa], 
     1924    }, 
     1925    chips => 
     1926    [ 
     1927      { 
     1928        name => "ITE IT8702F Super IO Sensors", 
     1929        driver => "to-be-written", 
     1930        devid => 0x8702, 
     1931        logdev => 0x04, 
     1932      }, 
     1933      { 
     1934        name => "ITE IT8705F Super IO Sensors", 
     1935        driver => "it87", 
     1936        devid => 0x8705, 
     1937        logdev => 0x04, 
     1938      }, 
     1939      { 
     1940        name => "ITE IT8712F Super IO Sensors", 
     1941        driver => "it87", 
     1942        devid => 0x8712, 
     1943        logdev => 0x04, 
     1944        alias_detect => sub { ite_alias_detect(0, @_); }, 
     1945      }, 
     1946      { 
     1947        name => "ITE IT8716F Super IO Sensors", 
     1948        driver => "it87", 
     1949        devid => 0x8716, 
     1950        logdev => 0x04, 
     1951      }, 
     1952      { 
     1953        name => "ITE IT8718F Super IO Sensors", 
     1954        driver => "it87", 
     1955        devid => 0x8718, 
     1956        logdev => 0x04, 
     1957      }, 
     1958    ], 
     1959  }, 
    19061960); 
    19071961 
     
    24782532{ 
    24792533  my ($file,$addr) = @_; 
     2534  $addr += 0; # Make sure it's a number not a string 
    24802535  ioctl $file, IOCTL_I2C_SLAVE, $addr or return 0; 
    24812536  return 1; 
     
    28202875} 
    28212876 
     2877# From the list of known I2C/SMBus devices, build a list of I2C addresses 
     2878# which are worth probing. There's no point in probing an address for which 
     2879# we don't know a single device, and probing some addresses has caused 
     2880# random trouble in the past. 
     2881sub i2c_addresses_to_scan() 
     2882{ 
     2883  my @used; 
     2884  my @addresses; 
     2885  my $addr; 
     2886 
     2887  foreach my $chip (@chip_ids) { 
     2888    next unless defined $chip->{'i2c_addrs'}; 
     2889    next if $chip->{'driver'} eq 'not-a-sensor'; 
     2890    foreach $addr (@{$chip->{'i2c_addrs'}}) { 
     2891      $used[$addr]++; 
     2892    } 
     2893  } 
     2894 
     2895  for ($addr = 0x03; $addr <= 0x77; $addr++) { 
     2896    push @addresses, $addr if $used[$addr]; 
     2897  } 
     2898  return \@addresses; 
     2899} 
     2900 
    28222901# $_[0]: The number of the adapter to scan 
    28232902# $_[1]: The name of the adapter, as appearing in /proc/bus/i2c 
     
    28522931 
    28532932  # Now scan each address in turn 
    2854   foreach $addr (0x03..0x77) { 
     2933  foreach $addr (@{$i2c_addresses_to_scan}) { 
    28552934    # As the not_to_scan list is sorted, we can check it fast 
    28562935    if (@not_to_scan and $not_to_scan[0] == $addr) { 
     
    29012980    printf "Client found at address 0x%02x\n",$addr; 
    29022981 
     2982    $| = 1; 
    29032983    foreach $chip (@chip_ids) { 
    29042984      if (exists $chip->{i2c_addrs} and contains $addr, @{$chip->{i2c_addrs}}) { 
     
    29323012      } 
    29333013    } 
     3014    $| = 0; 
    29343015  } 
    29353016} 
     
    29383019{ 
    29393020  my ($chip,$addr,$conf); 
     3021  $| = 1; 
    29403022  foreach $chip (@chip_ids) { 
    29413023    next if not exists $chip->{isa_addrs} or not exists $chip->{isa_detect}; 
     
    29593041    } 
    29603042  } 
     3043  $| = 0; 
    29613044} 
    29623045 
     
    30383121    return; 
    30393122  } 
     3123  if ($chip->{driver} eq "via-smbus-only") { 
     3124    print "\n    (hardware monitoring capabilities accessible via SMBus only)\n"; 
     3125    return; 
     3126  } 
    30403127 
    30413128  # Switch to the sensor logical device 
     
    30773164  printf("Probing for Super-I/O at 0x\%x/0x\%x\n", $addrreg, $datareg); 
    30783165 
     3166  $| = 1; 
     3167# reset state to avoid false positives 
     3168  exit_superio($addrreg, $datareg); 
    30793169  FAMILY:  
    30803170  foreach my $family (@superio_ids) { 
     
    31003190       || ($chip->{devid} <= 0xff && ($val >> 8) == $chip->{devid})) { 
    31013191        probe_superio($addrreg, $datareg, $chip); 
    3102         $found++; 
     3192        $found++; 
    31033193      } 
    31043194    } 
     
    31123202 
    31133203    exit_superio($addrreg, $datareg); 
    3114   } 
     3204    last FAMILY; 
     3205  } 
     3206  $| = 0; 
    31153207} 
    31163208 
     
    31713263 
    31723264# $_[0]: A reference to the file descriptor to access this chip. 
    3173 #        We may assume an i2c_set_slave_addr was already done. 
    31743265# $_[1]: Address 
    31753266# Returns: undef if not detected, (7) if detected. 
     
    31843275# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) 
    31853276# $_[1]: A reference to the file descriptor to access this chip. 
    3186 #        We may assume an i2c_set_slave_addr was already done. 
    31873277# $_[2]: Address 
    31883278# Returns: undef if not detected, (6) if detected. 
     
    32173307            inb ($addr + 7) != $val; 
    32183308 
    3219   $val = inb($addr + 5) & 0x7f; 
    3220   outb($addr + 5, ~$val & 0xff); 
     3309  $val = inb($addr + 5); 
     3310  outb($addr + 5, ~$val & 0x7f); 
    32213311  if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 
    32223312    outb($addr+5,$val); 
     
    32303320                ($chip == 2 and ($reg & 0xfe) == 0xc0); 
    32313321 
    3232   # Explicitely prevent misdetection of Winbond chips 
     3322  # Explicitly prevent misdetection of Winbond chips 
    32333323  $reg = &$readproc(0x4f); 
    32343324  return if $reg == 0xa3 || $reg == 0x5c; 
    32353325 
    3236   # Explicitely prevent misdetection of ITE chips 
     3326  # Explicitly prevent misdetection of ITE chips 
    32373327  $reg = &$readproc(0x58); 
    32383328  return if $reg == 0x90; 
     
    32583348} 
    32593349 
    3260 # $_[0]: A reference to the file descriptor to access this chip. 
    3261 #        We assume an i2c_set_slave_addr was already done. 
    3262 # $_[1]: Address 
     3350# $_[0]: Chip to detect (0 = LM75, 1 = DS75) 
     3351# $_[1]: A reference to the file descriptor to access this chip. 
     3352# $_[2]: Address (unused) 
    32633353# Returns: undef if not detected, 3 or 6 if detected; 
    32643354#   6 means that the temperatures make sense; 
     
    32763366# documented. 
    32773367# Note that register 0x00 may change, so we can't use the modulo trick on it. 
     3368# The DS75 is a bit different, it doesn't cycle over 8-byte boundaries, and 
     3369# all register addresses from 0x04 to 0x0f behave like 0x04-0x07 do for 
     3370# the LM75. 
    32783371sub lm75_detect 
    32793372{ 
    32803373  my $i; 
    3281   my ($file,$addr) = @_; 
     3374  my ($chip, $file, $addr) = @_; 
    32823375  my $cur = i2c_smbus_read_word_data($file,0x00); 
    3283   my $cur_varies = 0; 
    32843376  my $conf = i2c_smbus_read_byte_data($file,0x01); 
    32853377 
    32863378  my $hyst = i2c_smbus_read_word_data($file,0x02); 
    3287   return if i2c_smbus_read_word_data($file,0x04) != $hyst; 
    3288   return if i2c_smbus_read_word_data($file,0x05) != $hyst; 
    3289   return if i2c_smbus_read_word_data($file,0x06) != $hyst; 
    3290   return if i2c_smbus_read_word_data($file,0x07) != $hyst; 
     3379  my $maxreg = $chip == 1 ? 0x0f : 0x07; 
     3380  for $i (0x04 .. $maxreg) { 
     3381    return if i2c_smbus_read_word_data($file, $i) != $hyst; 
     3382  } 
    32913383 
    32923384  my $os = i2c_smbus_read_word_data($file,0x03); 
    3293   return if i2c_smbus_read_word_data($file,0x04) != $os; 
    3294   return if i2c_smbus_read_word_data($file,0x05) != $os; 
    3295   return if i2c_smbus_read_word_data($file,0x06) != $os; 
    3296   return if i2c_smbus_read_word_data($file,0x07) != $os; 
    3297  
    3298   for ($i = 0x00; $i < 0xff; $i += 8) { 
    3299     return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf; 
    3300     return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst; 
    3301     return if i2c_smbus_read_word_data($file, $i + 0x04) != $hyst; 
    3302     return if i2c_smbus_read_word_data($file, $i + 0x05) != $hyst; 
    3303     return if i2c_smbus_read_word_data($file, $i + 0x06) != $hyst; 
    3304     return if i2c_smbus_read_word_data($file, $i + 0x07) != $hyst; 
    3305     return if i2c_smbus_read_word_data($file, $i + 0x03) != $os; 
    3306     return if i2c_smbus_read_word_data($file, $i + 0x04) != $os; 
    3307     return if i2c_smbus_read_word_data($file, $i + 0x05) != $os; 
    3308     return if i2c_smbus_read_word_data($file, $i + 0x06) != $os; 
    3309     return if i2c_smbus_read_word_data($file, $i + 0x07) != $os; 
    3310         $cur_varies = 1 
    3311       if (! $cur_varies) and 
    3312         i2c_smbus_read_word_data($file, $i) != $cur; 
     3385  for $i (0x04 .. $maxreg) { 
     3386    return if i2c_smbus_read_word_data($file, $i) != $os; 
     3387  } 
     3388 
     3389  if ($chip == 0) { 
     3390    for ($i = 8; $i <= 248; $i += 40) { 
     3391      return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf 
     3392             or i2c_smbus_read_word_data($file, $i + 0x02) != $hyst 
     3393             or i2c_smbus_read_word_data($file, $i + 0x03) != $os; 
     3394    } 
    33133395  } 
    33143396 
    33153397  # All registers hold the same value, obviously a misdetection 
    3316   return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst 
     3398  return if $conf == ($cur & 0xff) and $cur == $hyst 
    33173399    and $cur == $os; 
    33183400 
     
    33213403  $os = swap_bytes($os); 
    33223404  # Unused bits 
    3323   return if ($conf & 0xe0); 
     3405  return if $chip == 0 and ($conf & 0xe0); 
     3406  return if $chip == 1 and ($conf & 0x80); 
    33243407 
    33253408  $cur = $cur >> 8; 
     
    33333416 
    33343417# $_[0]: A reference to the file descriptor to access this chip. 
    3335 #        We assume an i2c_set_slave_addr was already done. 
    33363418# $_[1]: Address 
    33373419# Returns: undef if not detected, 3 or 6 if detected; 
     
    33573439  my ($file,$addr) = @_; 
    33583440  my $cur = i2c_smbus_read_word_data($file,0x00); 
    3359   my $cur_varies = 0; 
    33603441  my $conf = i2c_smbus_read_byte_data($file,0x01); 
    33613442  my $hyst = i2c_smbus_read_word_data($file,0x02); 
     
    33703451  return if i2c_smbus_read_word_data($file,0x07) != $high; 
    33713452 
    3372   for ($i = 0x00; $i < 0xff; $i += 8) { 
     3453  for ($i = 8; $i <= 248; $i += 40) { 
    33733454    return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf; 
    33743455    return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst; 
    33753456    return if i2c_smbus_read_word_data($file, $i + 0x03) != $os; 
    33763457    return if i2c_smbus_read_word_data($file, $i + 0x04) != $low; 
    3377     return if i2c_smbus_read_word_data($file, $i + 0x06) != $low; 
    3378     return if i2c_smbus_read_word_data($file, $i + 0x07) != $low; 
    33793458    return if i2c_smbus_read_word_data($file, $i + 0x05) != $high; 
    3380     return if i2c_smbus_read_word_data($file, $i + 0x06) != $high; 
    3381     return if i2c_smbus_read_word_data($file, $i + 0x07) != $high; 
    3382     $cur_varies = 1 
    3383       if (! $cur_varies) and 
    3384         i2c_smbus_read_word_data($file, $i) != $cur; 
    33853459  } 
    33863460 
    33873461  # All registers hold the same value, obviously a misdetection 
    3388   return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst 
     3462  return if $conf == ($cur & 0xff) and $cur == $hyst 
    33893463    and $cur == $os and $cur == $low and $cur == $high; 
    33903464 
     
    34163490# $_[0]: Chip to detect (0 = LM92, 1 = LM76, 2 = MAX6633/MAX6634/MAX6635) 
    34173491# $_[1]: A reference to the file descriptor to access this chip. 
    3418 #        We may assume an i2c_set_slave_addr was already done. 
    34193492# $_[2]: Address 
    34203493# Returns: undef if not detected, 2 or 4 if detected; 
     
    34663539   
    34673540# $_[0]: A reference to the file descriptor to access this chip. 
    3468 #        We may assume an i2c_set_slave_addr was already done. 
    34693541# $_[1]: Address 
    34703542# Returns: undef if not detected, 3 if detected 
     
    34933565 
    34943566# $_[0]: A reference to the file descriptor to access this chip. 
    3495 #        We may assume an i2c_set_slave_addr was already done. 
    34963567# $_[1]: Address 
    34973568# Returns: undef if not detected, 1 to 3 if detected. 
     
    35563627#   (0 = LM82/LM83) 
    35573628# $_[1]: A reference to the file descriptor to access this chip. 
    3558 #        We may assume an i2c_set_slave_addr was already done. 
    35593629# $_[2]: Address 
    35603630# Returns: undef if not detected, 4 to 8 if detected. 
     
    35983668#    5 = ADT7461, 6 = MAX6648/MAX6692) 
    35993669# $_[1]: A reference to the file descriptor to access this chip. 
    3600 #        We may assume an i2c_set_slave_addr was already done. 
    36013670# $_[2]: Address 
    36023671# Returns: undef if not detected, 4, 6 or 8 if detected. 
     
    36713740#   (1 = LM63, 2 = F75363SG) 
    36723741# $_[1]: A reference to the file descriptor to access this chip. 
    3673 #        We may assume an i2c_set_slave_addr was already done. 
    36743742# $_[2]: Address (unused) 
    36753743# Returns: undef if not detected, 8 if detected. 
     
    37523820#   (0 = ADM1030, 1=ADM1031) 
    37533821# $_[1]: A reference to the file descriptor to access this chip. 
    3754 #        We may assume an i2c_set_slave_addr was already done. 
    37553822# $_[2]: Address 
    37563823# Returns: undef if not detected, 3 to 7 (ADM1031) or 9 (ADM1030) 
     
    38383905#    4 = ADT7470) 
    38393906# $_[1]: A reference to the file descriptor to access this chip. 
    3840 #        We may assume an i2c_set_slave_addr was already done. 
    38413907# $_[2]: Address 
    38423908# Returns: undef if not detected, 5 or 7 if detected. 
     
    40064072 
    40074073# $_[0]: A reference to the file descriptor to access this chip. 
    4008 #        We may assume an i2c_set_slave_addr was already done. 
    40094074# $_[1]: Address 
    40104075# Returns: undef if not detected, (7) if detected. 
     
    40244089#                        8 = W83792D, 9 = W83627EHF 10 = W83627DHG) 
    40254090# $_[1]: A reference to the file descriptor to access this chip. 
    4026 #        We may assume an i2c_set_slave_addr was already done. 
    40274091# $_[2]: Address 
    40284092# Returns: undef if not detected, (8,addr1,addr2) if detected, but only 
     
    41234187 
    41244188# $_[0]: A reference to the file descriptor to access this chip. 
    4125 #        We assume an i2c_set_slave_addr was already done. 
    41264189# $_[1]: Address 
    41274190# Returns: undef if not detected, 3 if detected 
     
    41974260} 
    41984261 
    4199 # $_[0]: Chip to detect (0 = W83781D, 1 = W83782D, 3 = W83627HF) 
     4262# $_[0]: Chip to detect (0 = W83781D, 1 = W83782D) 
    42004263# $_[1]: Address 
    42014264# Returns: undef if not detected, (8) if detected. 
     
    42084271            inb ($addr + 7) != $val; 
    42094272 
    4210   $val = inb($addr + 5) & 0x7f; 
    4211   outb($addr+5, ~$val & 0xff); 
     4273  $val = inb($addr + 5); 
     4274  outb($addr+5, ~$val & 0x7f); 
    42124275  if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 
    42134276    outb($addr+5,$val); 
     
    42244287  return if $chip == 0 and  ($reg1 & 0xfe) != 0x10; 
    42254288  return if $chip == 1 and  ($reg1 & 0xfe) != 0x30; 
    4226   return if $chip == 3 and  ($reg1 & 0xfe) != 0x20; 
    42274289 
    42284290  return 8; 
     
    42314293# $_[0]: Chip to detect (0 = Revision 0x00, 1 = Revision 0x80) 
    42324294# $_[1]: A reference to the file descriptor to access this chip. 
    4233 #        We may assume an i2c_set_slave_addr was already done. 
    42344295# $_[2]: Address 
    42354296# Returns: undef if not detected, (6) if detected. 
     
    42524313 
    42534314# $_[0]: A reference to the file descriptor to access this chip. 
    4254 #        We may assume an i2c_set_slave_addr was already done. 
    42554315# $_[1]: Address 
    42564316# Returns: undef if not detected, (5) if detected. 
     
    42714331 
    42724332# $_[0]: A reference to the file descriptor to access this chip. 
    4273 #        We may assume an i2c_set_slave_addr was already done. 
    42744333# $_[1]: Address 
    42754334# Returns: undef if not detected, (5) if detected. 
     
    42864345# $_[0]: Chip to detect (0 = ADM9240, 1 = DS1780, 2 = LM81) 
    42874346# $_[1]: A reference to the file descriptor to access this chip. 
    4288 #        We may assume an i2c_set_slave_addr was already done. 
    42894347# $_[2]: Address 
    42904348# Returns: undef if not detected, (7) if detected. 
     
    43104368# $_[0]: Chip to detect (0 = ADM1022, 1 = THMC50, 2 = ADM1028) 
    43114369# $_[1]: A reference to the file descriptor to access this chip. 
    4312 #        We may assume an i2c_set_slave_addr was already done. 
    43134370# $_[2]: Address 
    43144371# Returns: undef if not detected, (8) if detected. 
     
    43274384                ($chip == 2 and $reg == 0x41); 
    43284385  return unless (i2c_smbus_read_byte_data($file,0x40) & 0x80) == 0x00; 
    4329   $reg = i2c_smbus_read_byte_data($file, 0x3f); 
    4330   return unless ($reg & 0xc0) == 0xc0; 
    4331   return if $chip == 0 and ($reg & 0xc0) != 0xc0; 
    4332   return if $chip == 2 and ($reg & 0xc0) == 0xc0; 
     4386  $reg = i2c_smbus_read_byte_data($file, 0x3f) & 0xf0; 
     4387  return unless ($chip == 0 and $reg == 0xc0) or 
     4388                ($chip == 1 and $reg == 0xc0) or 
     4389                ($chip == 2 and $reg == 0xd0); 
    43334390  return (8); 
    43344391} 
     
    43364393# $_[0]: Chip to detect (0 = ADM1025, 1 = NE1619) 
    43374394# $_[1]: A reference to the file descriptor to access this chip. 
    4338 #        We may assume an i2c_set_slave_addr was already done. 
    43394395# $_[2]: Address 
    43404396# Returns: undef if not detected, (8) if detected. 
     
    43654421# $_[0]: Chip to detect (0 = ADM1026) 
    43664422# $_[1]: A reference to the file descriptor to access this chip. 
    4367 #        We may assume an i2c_set_slave_addr was already done. 
    43684423# $_[2]: Address 
    43694424# Returns: undef if not detected, (8) if detected. 
     
    43834438# $_[0]: Chip to detect (0 = ADM1024) 
    43844439# $_[1]: A reference to the file descriptor to access this chip. 
    4385 #        We may assume an i2c_set_slave_addr was already done. 
    43864440# $_[2]: Address 
    43874441# Returns: undef if not detected, (8) if detected. 
     
    44054459#    5 = LM84, 6 = GL523, 7 = MC1066) 
    44064460# $_[1]: A reference to the file descriptor to access this chip. 
    4407 #        We may assume an i2c_set_slave_addr was already done. 
    44084461# $_[2]: Address 
    44094462# Returns: undef if not detected, 3 if simply detected, 5 if detected and 
     
    44904543 
    44914544# $_[0]: Chip to detect 
     4545#   (0 = MAX1668, 1 = MAX1805, 2 = MAX1989) 
     4546# $_[1]: A reference to the file descriptor to access this chip. 
     4547#        We may assume an i2c_set_slave_addr was already done. 
     4548# $_[2]: Address 
     4549# Returns: undef if not detected, 7 if detected 
     4550# Registers used: 
     4551#   0xfe: Company ID 
     4552#   0xff: Device ID 
     4553sub max1668_detect 
     4554{ 
     4555  my ($chip, $file, $addr) = @_; 
     4556  my $man_id = i2c_smbus_read_byte_data($file, 0xfe); 
     4557  my $dev_id = i2c_smbus_read_byte_data($file, 0xff); 
     4558 
     4559  return if $man_id != 0x4d; 
     4560  return if $chip == 0 and $dev_id != 0x03; 
     4561  return if $chip == 1 and $dev_id != 0x05; 
     4562  return if $chip == 2 and $dev_id != 0x0b; 
     4563 
     4564  return 7; 
     4565} 
     4566 
     4567# $_[0]: Chip to detect 
    44924568#   (0 = MAX1619) 
    44934569# $_[1]: A reference to the file descriptor to access this chip. 
    4494 #        We may assume an i2c_set_slave_addr was already done. 
    44954570# $_[2]: Address 
    44964571# Returns: undef if not detected, 7 if detected 
     
    45414616# $_[0]: Chip to detect (0 = IT8712F) 
    45424617# $_[1]: A reference to the file descriptor to access this chip. 
    4543 #        We may assume an i2c_set_slave_addr was already done. 
    45444618# $_[2]: Address 
    45454619# Returns: undef if not detected, 7 or 8 if detected (tops LM78). 
     
    45794653} 
    45804654 
    4581 # $_[0]: Chip to detect (0 = SPD EEPROM, 1 = Sony Vaio EEPROM, 
    4582 #                        2 = SPD EEPROM with Software Write Protect) 
     4655# $_[0]: Chip to detect (0 = SPD EEPROM, 1 = Sony Vaio EEPROM) 
    45834656# $_[1]: A reference to the file descriptor to access this chip 
    45844657# $_[2]: Address 
    4585 # Returns: 8 for a memory eeprom (9 if write-protect register found), 
    4586 #          4 to 9 for a Sony Vaio eeprom, 
    4587 #          1 for an unknown eeprom (2 if write-protect register found) 
     4658# Returns: 8 for a memory eeprom 
     4659#          4 to 9 for a Sony Vaio eeprom 
    45884660# Registers used: 
    45894661#   0-63: SPD Data and Checksum 
     
    45994671 
    46004672  # Check the checksum for validity (works for most DIMMs and RIMMs) 
    4601   if ($chip != 1) { 
    4602           for (my $i = 0; $i <= 62; $i ++) { 
    4603             $checksum += i2c_smbus_read_byte_data($file,$i); 
    4604           } 
    4605           $checksum &= 255; 
    4606           $checksum -= i2c_smbus_read_byte_data($file,63); 
    4607   }      
    46084673  if ($chip == 0) { 
    4609         if($checksum == 0) { 
    4610                 return 8; 
    4611         } else { 
    4612                 return 1; 
     4674        for (my $i = 0; $i <= 62; $i++) { 
     4675          $checksum += i2c_smbus_read_byte_data($file, $i); 
    46134676        } 
    4614   }      
    4615   if ($chip == 2) { 
    4616         # check for 'shadow' write-protect register at 0x30-0x37 
    4617         # could be dangerous 
    4618         i2c_set_slave_addr($file,$addr - 0x20); 
    4619         if(i2c_smbus_write_quick($file, SMBUS_WRITE) >= 0 && 
    4620            i2c_smbus_read_byte_data($file,0x80) == -1) { 
    4621                 i2c_set_slave_addr($file,$addr); 
    4622                 if($checksum == 0) { 
    4623                         return (9, $addr - 0x20); 
    4624                 } else { 
    4625                         return (2, $addr - 0x20); 
    4626                 } 
    4627         } 
    4628         i2c_set_slave_addr($file,$addr); 
     4677        $checksum &= 255; 
     4678 
     4679        return 8 
     4680          if $checksum == i2c_smbus_read_byte_data($file, 63); 
    46294681        return; 
    46304682  } 
     
    46574709 
    46584710# $_[0]: A reference to the file descriptor to access this chip. 
    4659 #        We may assume an i2c_set_slave_addr was already done. 
    46604711# $_[1]: Address 
    4661 # Returns: undef if not detected, (1) if detected. 
     4712# Returns: undef if not detected, 8 if detected. 
    46624713# Registers used: 
    46634714#   0x00..0x07: DDC signature 
    4664 #   0x08..0x7E: checksumed area 
    4665 #   0x7F:       checksum 
    46664715sub ddcmonitor_detect 
    46674716{ 
    46684717  my ($file,$addr) = @_; 
    4669   my $i; 
    46704718 
    46714719  return unless 
     
    46794727    i2c_smbus_read_byte_data($file,0x07) == 0x00; 
    46804728 
    4681   # Check the checksum for validity. 
    4682   my $checksum = 0; 
    4683   for ($i = 0; $i <= 127; $i = $i + 1) { 
    4684     $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); 
    4685   } 
    4686   $checksum=$checksum & 255; 
    4687   if ($checksum != 0) { 
    4688     # I have one such monitor... 
    4689     return (2,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7); 
    4690   } 
    46914729  return (8,$addr+1,$addr+2,$addr+3,$addr+4,$addr+5,$addr+6,$addr+7); 
    46924730} 
    46934731 
    46944732# $_[0]: A reference to the file descriptor to access this chip. 
    4695 #        We may assume an i2c_set_slave_addr was already done. 
    46964733# $_[1]: Address 
    46974734# Returns: undef if not detected, (8) if detected. 
     
    47154752 
    47164753# $_[0]: A reference to the file descriptor to access this chip. 
    4717 #        We may assume an i2c_set_slave_addr was already done. 
    47184754# $_[1]: Address 
    47194755# Returns: undef if not detected, (8) if detected. 
     
    47374773 
    47384774# $_[0]: A reference to the file descriptor to access this chip. 
    4739 #        We may assume an i2c_set_slave_addr was already done. 
    47404775# $_[1]: Address 
    47414776# Returns: undef if not detected, (8) if detected. 
     
    47594794 
    47604795# $_[0]: A reference to the file descriptor to access this chip. 
    4761 #        We assume an i2c_set_slave_addr was already done. 
    47624796# $_[1]: Address (unused) 
    47634797# Returns: undef if not detected, 5 if detected. 
     
    47744808 
    47754809# $_[0]: A reference to the file descriptor to access this chip. 
    4776 #        We may assume an i2c_set_slave_addr was already done. 
    47774810# $_[1]: Address 
    47784811# Returns: undef if not detected, (7) if detected. 
     
    48044837 
    48054838# $_[0]: A reference to the file descriptor to access this chip. 
    4806 #        We assume an i2c_set_slave_addr was already done. 
    48074839# $_[1]: Address 
    48084840# Returns: undef if not detected, 5 or 6 if detected. 
     
    48234855 
    48244856# $_[0]: A reference to the file descriptor to access this chip. 
    4825 #        We assume an i2c_set_slave_addr was already done. 
    48264857# $_[1]: Address 
    48274858# Returns: undef if not detected, 5 or 6 if detected. 
     
    48294860#   0x3E: Manufacturer ID 
    48304861#   0x3F: Version/Stepping 
    4831 #   0x40: Configuration (2 reserved bits) 
    4832 #   0x42: Interrupt Status 2 (1 reserved bit) 
    4833 #   0x43: VID (2 reserved bits) 
     4862#   0x73: Read-only test register (4 test bits) 
     4863#   0x8A: Read-only test register (7 test bits) 
    48344864sub dme1737_detect 
    48354865{ 
    48364866  my ($file, $addr) = @_; 
    4837   return unless i2c_smbus_read_byte_data($file, 0x3E) == 0x55 
     4867  return unless i2c_smbus_read_byte_data($file, 0x3E) == 0x5c 
    48384868           and (i2c_smbus_read_byte_data($file, 0x3F) & 0xF8) == 0x88 
    4839            and (i2c_smbus_read_byte_data($file, 0x40) & 0xC4) == 0x04 
    4840            and (i2c_smbus_read_byte_data($file, 0x42) & 0x02) == 0x00 
    4841            and (i2c_smbus_read_byte_data($file, 0x43) & 0xC0) == 0x00; 
     4869           and (i2c_smbus_read_byte_data($file, 0x73) & 0x0F) == 0x09 
     4870           and (i2c_smbus_read_byte_data($file, 0x8A) & 0x7F) == 0x4D; 
    48424871  return ($addr == 0x2e ? 6 : 5); 
    48434872} 
     
    48484877#    7 = custom power control IC) 
    48494878# $_[1]: A reference to the file descriptor to access this chip. 
    4850 #        We assume an i2c_set_slave_addr was already done. 
    48514879# $_[2]: Address (unused) 
    48524880# Returns: undef if not detected, 7 if detected. 
     
    48854913 
    48864914# $_[0]: A reference to the file descriptor to access this chip. 
    4887 #        We may assume an i2c_set_slave_addr was already done. 
    48884915# $_[1]: Address 
    48894916# Returns: undef if not detected, 4 or 7 if detected 
     
    49084935 
    49094936# $_[0]: A reference to the file descriptor to access this chip. 
    4910 #        We may assume an i2c_set_slave_addr was already done. 
    49114937# $_[1]: Address 
    49124938# Returns: undef if not detected, 1 if detected 
     
    49274953 
    49284954# $_[0]: A reference to the file descriptor to access this chip. 
    4929 #        We assume an i2c_set_slave_addr was already done. 
    49304955# $_[1]: Address (unused) 
    49314956# Returns: undef if not detected, 1 if detected 
     
    49564981 
    49574982# $_[0]: A reference to the file descriptor to access this chip. 
    4958 #        We may assume an i2c_set_slave_addr was already done. 
    49594983# $_[1]: Address 
    49604984# Returns: undef if not detected, 3 if detected 
     
    50225046} 
    50235047 
    5024 # $_[0]: A reference to the file descriptor to access this chip. 
    5025 #        We may assume an i2c_set_slave_addr was already done. 
    5026 # $_[1]: Address 
    5027 # Returns: 1 
    5028 # This is a placeholder so we get a report if any device responds 
    5029 # to the SMBus Device Default Address (0x61), which is used for 
    5030 # ARP in SMBus 2.0. 
    5031 sub arp_detect 
    5032 { 
    5033   return (1); 
    5034 } 
    5035  
    50365048# This checks for non-FFFF values for SpecInfo and Status. 
    50375049# The address (0x09) is specified by the SMBus standard so it's likely 
    50385050# that this really is a smart battery charger. 
    50395051# $_[0]: A reference to the file descriptor to access this chip. 
    5040 #        We may assume an i2c_set_slave_addr was already done. 
    50415052# $_[1]: Address 
    50425053# Returns: 5 
     
    50585069# that this really is a smart battery manager/selector. 
    50595070# $_[0]: A reference to the file descriptor to access this chip. 
    5060 #        We may assume an i2c_set_slave_addr was already done. 
    50615071# $_[1]: Address 
    50625072# Returns: 5 
     
    50785088# that this really is a smart battery. 
    50795089# $_[0]: A reference to the file descriptor to access this chip. 
    5080 #        We may assume an i2c_set_slave_addr was already done. 
    50815090# $_[1]: Address 
    50825091# Returns: 5 
     
    51535162# $_[0]: Chip to detect (0 = W83L785TS-S) 
    51545163# $_[1]: A reference to the file descriptor to access this chip. 
    5155 #        We may assume an i2c_set_slave_addr was already done. 
    51565164# $_[2]: Address 
    51575165# Returns: undef if not detected, 8 if detected 
     
    51725180#        if somebody finds a way to distinguish MAX6650 and MAX6651. 
    51735181# $_[1]: A reference to the file descriptor to access this chip. 
    5174 #        We may assume an i2c_set_slave_addr was already done. 
    51755182# $_[2]: Address 
    51765183# Returns: undef if not detected, 4 if detected. 
     
    52045211} 
    52055212 
     5213# $_[0]: Chip to detect. Always zero. 
     5214# $_[1]: A reference to the file descriptor to access this chip. 
     5215# $_[2]: Address. 
     5216# 
     5217# Returns: undef if not detected, 6 if detected. 
     5218sub max6655_detect 
     5219{ 
     5220  my ($chip, $file, $addr) = @_; 
     5221 
     5222  # checking RDID (Device ID) 
     5223  return unless i2c_smbus_read_byte_data($file, 0xfe) == 0x0a; 
     5224  # checking RDRV (Manufacturer ID) 
     5225  return unless i2c_smbus_read_byte_data($file, 0xff) == 0x4d; 
     5226  # checking unused bits (conversion rate, extended temperature) 
     5227  return unless i2c_smbus_read_byte_data($file, 0x04) & 0xf8; 
     5228  return unless i2c_smbus_read_byte_data($file, 0x10) & 0x1f; 
     5229  return unless i2c_smbus_read_byte_data($file, 0x11) & 0x1f; 
     5230  return unless i2c_smbus_read_byte_data($file, 0x12) & 0x1f; 
     5231 
     5232  return 6; 
     5233} 
     5234 
    52065235# $_[0]: Chip to detect (0 = VT1211) 
    52075236# $_[1]: A reference to the file descriptor to access this chip. 
    5208 #        We may assume an i2c_set_slave_addr was already done. 
    52095237# $_[2]: Address 
    52105238# 
     
    55825610  # added to the chip_ids list 
    55835611  chip_special_cases(); 
     5612  $i2c_addresses_to_scan = i2c_addresses_to_scan(); 
    55845613 
    55855614  print "We are now going to do the I2C/SMBus adapter probings. Some chips may\n", 
     
    56425671  print "Do you want to scan for them? (YES/no): "; 
    56435672  unless (<STDIN> =~ /^\s*n/i) { 
     5673    $| = 1; 
    56445674    foreach my $entry (@cpu_ids) { 
    56455675      scan_cpu($entry); 
    56465676    } 
     5677    $| = 0; 
    56475678  } 
    56485679  print "\n";