Changeset 298

Show
Ignore:
Timestamp:
03/09/99 17:19:30 (14 years ago)
Author:
frodo
Message:

Added automatic generation of modprobe lines. Also corrected SIS

detection bug

The lesson of today: the control variable in foreach loops is local to the
loop and regains his former value on exit of the loop. Oops.

Location:
lm-sensors/trunk/prog/detect
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/detect/detect.pl

    r296 r298  
    10371037# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) 
    10381038# $_[1]: Address 
    1039 # Returns: undef if not detected, (7) if detected. 
     1039# Returns: undef if not detected, 7 if detected. 
    10401040# Note: Only address 0x290 is scanned at this moment. 
    10411041sub lm78_isa_detect 
     
    12901290{ 
    12911291  my ($addr) = @_; 
    1292   my ($adapter,$try); 
     1292  my ($adapter,$try,$local_try); 
    12931293  my $found = 0; 
    1294   foreach $try (@pci_adapters) { 
    1295     if ($try->{procid} eq "Silicon Integrated Systems 85C503") { 
     1294  foreach $local_try (@pci_adapters) { 
     1295    if ($local_try->{procid} eq "Silicon Integrated Systems 85C503") { 
     1296      $try = $local_try; 
    12961297      $found = 1; 
    12971298      last; 
     
    13021303  $found = 0; 
    13031304  foreach $adapter (@pci_list) { 
    1304     if ((defined($try->{vendid}) and  
     1305    if ((defined($adapter->{vendid}) and  
    13051306         $try->{vendid} == $adapter->{vendid} and 
    13061307         $try->{devid} == $adapter->{devid} and 
     
    13151316  return if not $found; 
    13161317 
    1317   return (9); 
     1318  return 9; 
     1319} 
     1320 
     1321# $_[0]: A reference to the file descriptor to access this chip. 
     1322#        We may assume an i2c_set_slave_addr was already done. 
     1323# $_[1]: Address 
     1324# Returns: undef if not detected, (5) if detected. 
     1325# Registers used: 
     1326#   0x00-0x63: PC-100 Data and Checksum 
     1327sub eeprom_detect 
     1328{ 
     1329  my ($file,$addr) = @_; 
     1330  # Check the checksum for validity (only works for PC-100 DIMMs) 
     1331  my $checksum = 0; 
     1332  for (my $i = 0; $i <= 62; $i = $i + 1) { 
     1333    $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); 
     1334  } 
     1335  $checksum=$checksum & 255; 
     1336  if (i2c_smbus_read_byte_data($file,63) == $checksum) { 
     1337        return (8); 
     1338  } 
     1339  # Even if checksum test fails, it still may be an eeprom 
     1340  return (1); 
    13181341} 
    13191342 
     
    13601383} 
    13611384 
    1362 # $_[0]: A reference to the file descriptor to access this chip. 
    1363 #        We may assume an i2c_set_slave_addr was already done. 
    1364 # $_[1]: Address 
    1365 # Returns: undef if not detected, (5) if detected. 
    1366 # Registers used: 
    1367 #   0x00-0x63: PC-100 Data and Checksum 
    1368 sub eeprom_detect 
    1369 { 
    1370   my ($file,$addr) = @_; 
    1371   # Check the checksum for validity (only works for PC-100 DIMMs) 
    1372   my $checksum = 0; 
    1373   for (my $i = 0; $i <= 62; $i = $i + 1) { 
    1374     $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); 
    1375   } 
    1376   $checksum=$checksum & 255; 
    1377   if (i2c_smbus_read_byte_data($file,63) == $checksum) { 
    1378         return (8); 
    1379   } 
    1380   # Even if checksum test fails, it still may be an eeprom 
    1381   return (1); 
    1382 } 
    1383  
    1384 ################ 
    1385 # MAIN PROGRAM # 
    1386 ################ 
     1385sub generate_modprobes 
     1386{ 
     1387  my ($chip,$detection,%adapters,$nr,@optionlist); 
     1388  my $modprobes = ""; 
     1389  my $configfile = ""; 
     1390 
     1391  # These are always needed 
     1392  $modprobes .= "# General I2C modules\n"; 
     1393  $modprobes .= "modprobe i2c-proc\n"; 
     1394  $configfile .= "# I2C module options\n"; 
     1395  $configfile .= "alias char-major-89 i2c-dev\n"; 
     1396 
     1397  # Collect all adapters 
     1398  $nr = 0; 
     1399  $modprobes .= "# I2C adapter drivers\n"; 
     1400  foreach $chip (@chips_detected) { 
     1401    foreach $detection (@{$chip->{detected}}) { 
     1402      %adapters->{$detection->{i2c_driver}} = $nr ++ 
     1403            if exists $detection->{i2c_driver} and  
     1404               not exists %adapters->{$detection->{i2c_driver}}; 
     1405      %adapters->{"i2c-isa"} = $nr ++  
     1406            if exists $detection->{isa_addr} and  
     1407               not exists %adapters->{"i2c-isa"}; 
     1408    } 
     1409  } 
     1410  foreach $detection (keys %adapters) { 
     1411    $modprobes .= "modprobe $detection\n"; 
     1412  } 
     1413 
     1414  # Now determine the chip probe lines 
     1415  $modprobes .= "# I2C chip drivers\n"; 
     1416  foreach $chip (@chips_detected) { 
     1417    next if not @{$chip->{detected}}; 
     1418    $modprobes .= "modprobe $chip->{driver}\n"; 
     1419    @optionlist = (); 
     1420    foreach $detection (@{$chip->{misdetected}}) { 
     1421      push @optionlist, %adapters->{$detection->{i2c_driver}}, 
     1422                       $detection->{i2c_addr} 
     1423           if exists $detection->{i2c_driver} and 
     1424              exists %adapters->{$detection->{i2c_driver}}; 
     1425      push @optionlist, -1, $detection->{isa_addr} 
     1426           if exists $detection->{isa_addr} and 
     1427              exists %adapters->{"i2c-isa"}; 
     1428    } 
     1429    next if not @optionlist; 
     1430    $configfile .= "options $chip->{driver}"; 
     1431    $configfile .= sprintf " ignore=0x%02x",shift @optionlist  
     1432                if @optionlist; 
     1433    $configfile .= sprintf ",0x%02x",shift @optionlist  
     1434                while @optionlist; 
     1435    $configfile .= "\n"; 
     1436  } 
     1437 
     1438  return ($modprobes,$configfile); 
     1439   
     1440} 
    13871441 
    13881442sub main 
     
    15861640    } 
    15871641  } 
     1642 
     1643  my ($modprobes,$configfile) = generate_modprobes; 
     1644  print "\n\nTo load everything that is needed, add this to some /etc/rc* ", 
     1645        "file:\n\n"; 
     1646  print "#----cut here----\n"; 
     1647  print $modprobes; 
     1648  print "#----cut here----\n"; 
     1649  print "\nTo make the sensors modules behave correctly, add these lines to ", 
     1650        "either\n", 
     1651        "/etc/modules.conf or /etc/conf.modules:\n\n"; 
     1652  print "#----cut here----\n"; 
     1653  print $configfile; 
     1654  print "#----cut here----\n"; 
     1655   
    15881656} 
    15891657 
  • lm-sensors/trunk/prog/detect/sensors-detect

    r296 r298  
    10371037# $_[0]: Chip to detect (0 = LM78, 1 = LM78-J, 2 = LM79) 
    10381038# $_[1]: Address 
    1039 # Returns: undef if not detected, (7) if detected. 
     1039# Returns: undef if not detected, 7 if detected. 
    10401040# Note: Only address 0x290 is scanned at this moment. 
    10411041sub lm78_isa_detect 
     
    12901290{ 
    12911291  my ($addr) = @_; 
    1292   my ($adapter,$try); 
     1292  my ($adapter,$try,$local_try); 
    12931293  my $found = 0; 
    1294   foreach $try (@pci_adapters) { 
    1295     if ($try->{procid} eq "Silicon Integrated Systems 85C503") { 
     1294  foreach $local_try (@pci_adapters) { 
     1295    if ($local_try->{procid} eq "Silicon Integrated Systems 85C503") { 
     1296      $try = $local_try; 
    12961297      $found = 1; 
    12971298      last; 
     
    13021303  $found = 0; 
    13031304  foreach $adapter (@pci_list) { 
    1304     if ((defined($try->{vendid}) and  
     1305    if ((defined($adapter->{vendid}) and  
    13051306         $try->{vendid} == $adapter->{vendid} and 
    13061307         $try->{devid} == $adapter->{devid} and 
     
    13151316  return if not $found; 
    13161317 
    1317   return (9); 
     1318  return 9; 
     1319} 
     1320 
     1321# $_[0]: A reference to the file descriptor to access this chip. 
     1322#        We may assume an i2c_set_slave_addr was already done. 
     1323# $_[1]: Address 
     1324# Returns: undef if not detected, (5) if detected. 
     1325# Registers used: 
     1326#   0x00-0x63: PC-100 Data and Checksum 
     1327sub eeprom_detect 
     1328{ 
     1329  my ($file,$addr) = @_; 
     1330  # Check the checksum for validity (only works for PC-100 DIMMs) 
     1331  my $checksum = 0; 
     1332  for (my $i = 0; $i <= 62; $i = $i + 1) { 
     1333    $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); 
     1334  } 
     1335  $checksum=$checksum & 255; 
     1336  if (i2c_smbus_read_byte_data($file,63) == $checksum) { 
     1337        return (8); 
     1338  } 
     1339  # Even if checksum test fails, it still may be an eeprom 
     1340  return (1); 
    13181341} 
    13191342 
     
    13601383} 
    13611384 
    1362 # $_[0]: A reference to the file descriptor to access this chip. 
    1363 #        We may assume an i2c_set_slave_addr was already done. 
    1364 # $_[1]: Address 
    1365 # Returns: undef if not detected, (5) if detected. 
    1366 # Registers used: 
    1367 #   0x00-0x63: PC-100 Data and Checksum 
    1368 sub eeprom_detect 
    1369 { 
    1370   my ($file,$addr) = @_; 
    1371   # Check the checksum for validity (only works for PC-100 DIMMs) 
    1372   my $checksum = 0; 
    1373   for (my $i = 0; $i <= 62; $i = $i + 1) { 
    1374     $checksum = $checksum + i2c_smbus_read_byte_data($file,$i); 
    1375   } 
    1376   $checksum=$checksum & 255; 
    1377   if (i2c_smbus_read_byte_data($file,63) == $checksum) { 
    1378         return (8); 
    1379   } 
    1380   # Even if checksum test fails, it still may be an eeprom 
    1381   return (1); 
    1382 } 
    1383  
    1384 ################ 
    1385 # MAIN PROGRAM # 
    1386 ################ 
     1385sub generate_modprobes 
     1386{ 
     1387  my ($chip,$detection,%adapters,$nr,@optionlist); 
     1388  my $modprobes = ""; 
     1389  my $configfile = ""; 
     1390 
     1391  # These are always needed 
     1392  $modprobes .= "# General I2C modules\n"; 
     1393  $modprobes .= "modprobe i2c-proc\n"; 
     1394  $configfile .= "# I2C module options\n"; 
     1395  $configfile .= "alias char-major-89 i2c-dev\n"; 
     1396 
     1397  # Collect all adapters 
     1398  $nr = 0; 
     1399  $modprobes .= "# I2C adapter drivers\n"; 
     1400  foreach $chip (@chips_detected) { 
     1401    foreach $detection (@{$chip->{detected}}) { 
     1402      %adapters->{$detection->{i2c_driver}} = $nr ++ 
     1403            if exists $detection->{i2c_driver} and  
     1404               not exists %adapters->{$detection->{i2c_driver}}; 
     1405      %adapters->{"i2c-isa"} = $nr ++  
     1406            if exists $detection->{isa_addr} and  
     1407               not exists %adapters->{"i2c-isa"}; 
     1408    } 
     1409  } 
     1410  foreach $detection (keys %adapters) { 
     1411    $modprobes .= "modprobe $detection\n"; 
     1412  } 
     1413 
     1414  # Now determine the chip probe lines 
     1415  $modprobes .= "# I2C chip drivers\n"; 
     1416  foreach $chip (@chips_detected) { 
     1417    next if not @{$chip->{detected}}; 
     1418    $modprobes .= "modprobe $chip->{driver}\n"; 
     1419    @optionlist = (); 
     1420    foreach $detection (@{$chip->{misdetected}}) { 
     1421      push @optionlist, %adapters->{$detection->{i2c_driver}}, 
     1422                       $detection->{i2c_addr} 
     1423           if exists $detection->{i2c_driver} and 
     1424              exists %adapters->{$detection->{i2c_driver}}; 
     1425      push @optionlist, -1, $detection->{isa_addr} 
     1426           if exists $detection->{isa_addr} and 
     1427              exists %adapters->{"i2c-isa"}; 
     1428    } 
     1429    next if not @optionlist; 
     1430    $configfile .= "options $chip->{driver}"; 
     1431    $configfile .= sprintf " ignore=0x%02x",shift @optionlist  
     1432                if @optionlist; 
     1433    $configfile .= sprintf ",0x%02x",shift @optionlist  
     1434                while @optionlist; 
     1435    $configfile .= "\n"; 
     1436  } 
     1437 
     1438  return ($modprobes,$configfile); 
     1439   
     1440} 
    13871441 
    13881442sub main 
     
    15861640    } 
    15871641  } 
     1642 
     1643  my ($modprobes,$configfile) = generate_modprobes; 
     1644  print "\n\nTo load everything that is needed, add this to some /etc/rc* ", 
     1645        "file:\n\n"; 
     1646  print "#----cut here----\n"; 
     1647  print $modprobes; 
     1648  print "#----cut here----\n"; 
     1649  print "\nTo make the sensors modules behave correctly, add these lines to ", 
     1650        "either\n", 
     1651        "/etc/modules.conf or /etc/conf.modules:\n\n"; 
     1652  print "#----cut here----\n"; 
     1653  print $configfile; 
     1654  print "#----cut here----\n"; 
     1655   
    15881656} 
    15891657