Changeset 255

Show
Ignore:
Timestamp:
02/19/99 19:11:03 (10 years ago)
Author:
frodo
Message:

Detect now ouputs an overview of what drivers to load and which you

definitely should not load.

Also fixed GL520 detection bug. Some other bugs are probably still there.

The report is generated using a very intricate data structure. There
can easily be hidden problems. Just test, test, test :-)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/TODO

    r219 r255  
    11Many, many things. Most notably: 
    22 
    3 * Check CDROM insert-remove error of Matt Mueller 
     3* bit-lp increases module count stupidly 
     4* Library: reload does not work (Bison/Flex problem?) 
    45* Create wait-queues for bus locking instead of pure semaphores, to make 
    56  it more interactive 
  • lm-sensors/trunk/prog/detect/detect.pl

    r254 r255  
    4141# Function) and procid (string as appears in /proc/pci; see linux/driver/pci, 
    4242# either pci.c or oldproc.c). If no driver is written yet, omit the  
    43 # driver (Driver Name) field. 
     43# driver (Driver Name) field. The match (Match Description) field should 
     44# contain a function which returns zero if its first parameter matches 
     45# the text as it would appear in /proc/bus/i2c. 
    4446@pci_adapters = (  
    4547     {  
     
    4850       func => 3, 
    4951       procid => "Intel 82371AB PIIX4 ACPI", 
    50        driver => "i2c-piix4" 
     52       driver => "i2c-piix4", 
     53       match => sub { $_[0] =~ /^SMBus PIIX4 adapter at [0-9,a-f]{4}/ }, 
    5154     } ,  
    5255     {  
     
    5558       func => 3, 
    5659       procid => "VIA Technologies VT 82C586B Apollo ACPI", 
    57        driver => "i2c-via" 
     60       driver => "i2c-via", 
     61       match => sub { $_[0] =~ /^VIA i2c/ }, 
    5862     } , 
    5963     { 
     
    6266       func => 0, 
    6367       procid => "Silicon Integrated Systems 85C503", 
     68       match => sub { 0 }, 
    6469     } , 
    6570     { 
     
    6873       funcid => 0, 
    6974       procid => "Acer Labs M7101", 
    70        driver => "i2c-ali15x3" 
     75       driver => "i2c-ali15x3", 
     76       match => sub { $_[0] =~ /^SMBus ALI15X3 adapter at [0-9,a-f]{4}/ }, 
    7177     } 
    7278); 
     
    138144       name => "Genesys Logic GL520SM", 
    139145       i2c_addrs => [0x4c, 0x4d], 
    140        i2c_detect => sub { gl520sm_detect 1, @_} , 
     146       i2c_detect => sub { gl520sm_detect @_} , 
    141147     }, 
    142148     { 
     
    313319} 
    314320 
     321# $_[0]: Description as found in /proc/bus/i2c 
     322sub find_adapter_driver 
     323{ 
     324  my $adapter; 
     325  for $adapter (@pci_adapters) { 
     326    return $adapter->{driver} if &{$adapter->{match}} ($_[0]); 
     327  } 
     328  return "?????"; 
     329} 
     330 
    315331############################# 
    316332# I2C AND SMBUS /DEV ACCESS # 
     
    526542#################### 
    527543 
     544use vars qw(@chips_detected); 
     545 
     546# We will build a complicated structure @chips_detected here, being: 
     547# A list of 
     548#  references to hashes 
     549#    with field 'driver', being a string with the driver name for this chip; 
     550#    with field 'detected' 
     551#      being a reference to a list of 
     552#        references to hashes 
     553#          with field 'description' containing an adapter string as appearing 
     554#               in /proc/bus/i2c 
     555#          with field 'driver', containing the driver name for this adapter; 
     556#          with field 'address', containing the I2C address of the detection; 
     557#          with field 'confidence', containing the confidence level of this 
     558#               detection 
     559#          with field 'chipname", containing the chip name 
     560#           
     561#    with field 'misdetected' 
     562#      being a reference to a list of 
     563#        references to hashes 
     564#          with field 'description' containing an adapter string as appearing 
     565#               in /proc/bus/i2c 
     566#          with field 'driver', containing the driver name for this adapter; 
     567#          with field 'address', containing the I2C address of the detection; 
     568#          with field 'confidence', containing the confidence level of this 
     569#               detection 
     570#          with field 'chipname", containing the chip name 
     571 
     572# $_[0]: chip driver 
     573# $_[1]: reference to data hash 
     574sub add_to_chips_detected 
     575{ 
     576  my ($chipdriver,$datahash,$detected_ref,$misdetected_ref, 
     577      $new_detected_ref,$new_misdetected_ref) = @_; 
     578  my ($i,$j,$found_it); 
     579  for ($i = 0; $i < @chips_detected; $i++) { 
     580    last if ($chips_detected[$i]->{driver} eq $chipdriver); 
     581  } 
     582  if ($i == @chips_detected) { 
     583    push @chips_detected, { driver => $chipdriver, 
     584                            detected => [], 
     585                            misdetected => [] }; 
     586  } 
     587 
     588  $new_detected_ref = $chips_detected[$i]->{detected}; 
     589  $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 
     590 
     591  # This is tricky, mostly because of the datastructures involved. We walk 
     592  # through all previous detections for this address. If the to-be-inserted 
     593  # detection matches an item in it, we look at the confidence values. 
     594  # If the to-be-inserted detections's confidence is greater, we delegate 
     595  # the previous detection to the misdetections, and replace it with this 
     596  # detection. If it is equal or less, we add the to-be-inserted detection 
     597  # to the misdetections. As soon as a match is found, we break. If no 
     598  # matches are found at all, add the to-be-inserted detection with the 
     599  # detections. 
     600  $found_it = 0; 
     601  LOOP: for ($i = 0; $i < @chips_detected; $i++) { 
     602    $detected_ref = $chips_detected[$i]->{detected}; 
     603    $misdetected_ref = $chips_detected[$i]->{misdetected}; 
     604    for ($j = 0; $j < @$detected_ref ; $j++) { 
     605      if ($detected_ref->[$j]->{driver} eq $datahash->{driver} and 
     606          $detected_ref->[$j]->{description} eq $datahash->{description} and 
     607          $detected_ref->[$j]->{address} eq $datahash->{address}) { 
     608        if ($detected_ref->[$j]->{confidence} > $datahash->{confidence}) { 
     609          push @$misdetected_ref, $detected_ref->[$j]; 
     610          splice @$detected_ref, $j, 1; 
     611          push @$new_detected_ref, $datahash; 
     612          $found_it = 1; 
     613          last LOOP; 
     614        } else { 
     615          push @$new_misdetected_ref, $datahash; 
     616          $found_it = 1; 
     617          last LOOP; 
     618        } 
     619      } 
     620    } 
     621  } 
     622  push @$new_detected_ref, $datahash if not $found_it 
     623} 
     624 
    528625# $_[0]: The number of the adapter to scan 
     626# $_[1]: The name of the adapter, as appearing in /proc/bus/i2c 
     627# $_[2]: The driver of the adapter 
    529628sub scan_adapter 
    530629{ 
     630  my ( $adapter_nr,$adapter_name,$adapter_driver) = @_; 
    531631  my ($chip, $addr, $conf,@chips); 
    532   open FILE,"/dev/i2c-$_[0]" or print ("Can't open /dev/i2c-$_[0] ($!)\n"),  
    533                                return; 
     632  open FILE,"/dev/i2c-$adapter_nr" or  
     633       print ("Can't open /dev/i2c-$adapter_nr ($!)\n"), return; 
    534634  foreach $addr (0..0x7f) { 
    535635    i2c_set_slave_addr(\*FILE,$addr) or print("Can't set address to $_?!?\n"),  
     
    537637    next unless i2c_smbus_read_byte(\*FILE) >= 0; 
    538638    printf "Client found at address 0x%02x\n",$addr; 
     639    my @detection_list = (); 
     640    my $highest_conf = 0; 
     641    my $double_conf = 0; 
    539642    foreach $chip (@chip_ids) { 
    540643      if (contains $addr, @{$$chip{i2c_addrs}}) { 
     
    548651            print ")\n"; 
    549652          } 
     653          add_to_chips_detected $$chip{driver}, 
     654                                { confidence => $conf, 
     655                                  address => $addr, 
     656                                  chipname =>  $$chip{name}, 
     657                                  description => $adapter_name, 
     658                                  driver => $adapter_driver, 
     659                                }; 
    550660        } else { 
    551           print "Failed!\n"  
     661          print "Failed!\n"; 
    552662        } 
    553663      } 
     
    887997              "module. If not,", 
    888998              " you won't be able to open any /dev/i2c-* file.\n"; 
    889       } elsif (system "modprobe","i2c-proc") { 
     999      } elsif (system "modprobe","i2c-dev") { 
    8901000        print " Loading failed ($!), aborting.\n"; 
    8911001        exit; 
     
    9061016    print "\n"; 
    9071017    my ($dev_nr,$description) = /^i2c-(\S+)\s+\S+\s+(.*)$/; 
     1018    $description =~ s/\t/ /; 
    9081019    print "Next adapter: $description\n"; 
    909     print "Do you want to scan it? (YES/no):"; 
    910     scan_adapter $dev_nr unless <STDIN> =~ /^\s*[Nn]/; 
     1020    print "Do you want to scan it? (YES/no): "; 
     1021    scan_adapter $dev_nr, $description, find_adapter_driver($description) 
     1022                                              unless <STDIN> =~ /^\s*[Nn]/; 
     1023  } 
     1024 
     1025  print "\n Now follows a summary of the probes I have just done.\n"; 
     1026  my ($chip,$data); 
     1027  foreach $chip (@chips_detected) { 
     1028    print "\nDriver `$$chip{driver}' "; 
     1029    if (@{$$chip{detected}}) { 
     1030      if (@{$$chip{misdetected}}) { 
     1031        print "(should be inserted but causes problems):\n"; 
     1032      } else { 
     1033        print "(should be inserted):\n"; 
     1034      } 
     1035    } else { 
     1036      if (@{$$chip{misdetected}}) { 
     1037        print "(may not be inserted):\n"; 
     1038      } else { 
     1039        print "(should not be inserted, but is harmless):\n"; 
     1040      } 
     1041    } 
     1042    if (@{$$chip{detected}}) { 
     1043      print " Detects correctly:\n"; 
     1044      foreach $data (@{$$chip{detected}}) { 
     1045        printf "  * Bus `%s'\n". 
     1046               "    Busdriver `%s', I2C address 0x%02x\n". 
     1047               "    Chip `%s' (confidence: %d)\n", 
     1048               $data->{description}, $data->{driver}, $data->{address}, 
     1049               $data->{chipname}, $data->{address}, $data->{confidence}; 
     1050      } 
     1051    } 
     1052    if (@{$$chip{misdetected}}) { 
     1053      print "  Misdetects:\n"; 
     1054      foreach $data (@{$$chip{misdetected}}) { 
     1055        printf "  * Bus: %s\n". 
     1056               "    Busdriver `%s', I2C address 0x%02x\n". 
     1057               "    Chip `%s' (confidence: %d)\n", 
     1058               $data->{description}, $data->{driver}, $data->{address}, 
     1059               $data->{chipname}, $data->{address}, $data->{confidence}; 
     1060      } 
     1061    } 
    9111062  } 
    9121063} 
    9131064 
    9141065main; 
    915  
    916  
    917        
    918  
    919  
    920 # TEST! 
    921 # scan_adapter 0; 
    922 #} 
    923  
    924 # 
  • lm-sensors/trunk/prog/detect/sensors-detect

    r254 r255  
    4141# Function) and procid (string as appears in /proc/pci; see linux/driver/pci, 
    4242# either pci.c or oldproc.c). If no driver is written yet, omit the  
    43 # driver (Driver Name) field. 
     43# driver (Driver Name) field. The match (Match Description) field should 
     44# contain a function which returns zero if its first parameter matches 
     45# the text as it would appear in /proc/bus/i2c. 
    4446@pci_adapters = (  
    4547     {  
     
    4850       func => 3, 
    4951       procid => "Intel 82371AB PIIX4 ACPI", 
    50        driver => "i2c-piix4" 
     52       driver => "i2c-piix4", 
     53       match => sub { $_[0] =~ /^SMBus PIIX4 adapter at [0-9,a-f]{4}/ }, 
    5154     } ,  
    5255     {  
     
    5558       func => 3, 
    5659       procid => "VIA Technologies VT 82C586B Apollo ACPI", 
    57        driver => "i2c-via" 
     60       driver => "i2c-via", 
     61       match => sub { $_[0] =~ /^VIA i2c/ }, 
    5862     } , 
    5963     { 
     
    6266       func => 0, 
    6367       procid => "Silicon Integrated Systems 85C503", 
     68       match => sub { 0 }, 
    6469     } , 
    6570     { 
     
    6873       funcid => 0, 
    6974       procid => "Acer Labs M7101", 
    70        driver => "i2c-ali15x3" 
     75       driver => "i2c-ali15x3", 
     76       match => sub { $_[0] =~ /^SMBus ALI15X3 adapter at [0-9,a-f]{4}/ }, 
    7177     } 
    7278); 
     
    138144       name => "Genesys Logic GL520SM", 
    139145       i2c_addrs => [0x4c, 0x4d], 
    140        i2c_detect => sub { gl520sm_detect 1, @_} , 
     146       i2c_detect => sub { gl520sm_detect @_} , 
    141147     }, 
    142148     { 
     
    313319} 
    314320 
     321# $_[0]: Description as found in /proc/bus/i2c 
     322sub find_adapter_driver 
     323{ 
     324  my $adapter; 
     325  for $adapter (@pci_adapters) { 
     326    return $adapter->{driver} if &{$adapter->{match}} ($_[0]); 
     327  } 
     328  return "?????"; 
     329} 
     330 
    315331############################# 
    316332# I2C AND SMBUS /DEV ACCESS # 
     
    526542#################### 
    527543 
     544use vars qw(@chips_detected); 
     545 
     546# We will build a complicated structure @chips_detected here, being: 
     547# A list of 
     548#  references to hashes 
     549#    with field 'driver', being a string with the driver name for this chip; 
     550#    with field 'detected' 
     551#      being a reference to a list of 
     552#        references to hashes 
     553#          with field 'description' containing an adapter string as appearing 
     554#               in /proc/bus/i2c 
     555#          with field 'driver', containing the driver name for this adapter; 
     556#          with field 'address', containing the I2C address of the detection; 
     557#          with field 'confidence', containing the confidence level of this 
     558#               detection 
     559#          with field 'chipname", containing the chip name 
     560#           
     561#    with field 'misdetected' 
     562#      being a reference to a list of 
     563#        references to hashes 
     564#          with field 'description' containing an adapter string as appearing 
     565#               in /proc/bus/i2c 
     566#          with field 'driver', containing the driver name for this adapter; 
     567#          with field 'address', containing the I2C address of the detection; 
     568#          with field 'confidence', containing the confidence level of this 
     569#               detection 
     570#          with field 'chipname", containing the chip name 
     571 
     572# $_[0]: chip driver 
     573# $_[1]: reference to data hash 
     574sub add_to_chips_detected 
     575{ 
     576  my ($chipdriver,$datahash,$detected_ref,$misdetected_ref, 
     577      $new_detected_ref,$new_misdetected_ref) = @_; 
     578  my ($i,$j,$found_it); 
     579  for ($i = 0; $i < @chips_detected; $i++) { 
     580    last if ($chips_detected[$i]->{driver} eq $chipdriver); 
     581  } 
     582  if ($i == @chips_detected) { 
     583    push @chips_detected, { driver => $chipdriver, 
     584                            detected => [], 
     585                            misdetected => [] }; 
     586  } 
     587 
     588  $new_detected_ref = $chips_detected[$i]->{detected}; 
     589  $new_misdetected_ref = $chips_detected[$i]->{misdetected}; 
     590 
     591  # This is tricky, mostly because of the datastructures involved. We walk 
     592  # through all previous detections for this address. If the to-be-inserted 
     593  # detection matches an item in it, we look at the confidence values. 
     594  # If the to-be-inserted detections's confidence is greater, we delegate 
     595  # the previous detection to the misdetections, and replace it with this 
     596  # detection. If it is equal or less, we add the to-be-inserted detection 
     597  # to the misdetections. As soon as a match is found, we break. If no 
     598  # matches are found at all, add the to-be-inserted detection with the 
     599  # detections. 
     600  $found_it = 0; 
     601  LOOP: for ($i = 0; $i < @chips_detected; $i++) { 
     602    $detected_ref = $chips_detected[$i]->{detected}; 
     603    $misdetected_ref = $chips_detected[$i]->{misdetected}; 
     604    for ($j = 0; $j < @$detected_ref ; $j++) { 
     605      if ($detected_ref->[$j]->{driver} eq $datahash->{driver} and 
     606          $detected_ref->[$j]->{description} eq $datahash->{description} and 
     607          $detected_ref->[$j]->{address} eq $datahash->{address}) { 
     608        if ($detected_ref->[$j]->{confidence} > $datahash->{confidence}) { 
     609          push @$misdetected_ref, $detected_ref->[$j]; 
     610          splice @$detected_ref, $j, 1; 
     611          push @$new_detected_ref, $datahash; 
     612          $found_it = 1; 
     613          last LOOP; 
     614        } else { 
     615          push @$new_misdetected_ref, $datahash; 
     616          $found_it = 1; 
     617          last LOOP; 
     618        } 
     619      } 
     620    } 
     621  } 
     622  push @$new_detected_ref, $datahash if not $found_it 
     623} 
     624 
    528625# $_[0]: The number of the adapter to scan 
     626# $_[1]: The name of the adapter, as appearing in /proc/bus/i2c 
     627# $_[2]: The driver of the adapter 
    529628sub scan_adapter 
    530629{ 
     630  my ( $adapter_nr,$adapter_name,$adapter_driver) = @_; 
    531631  my ($chip, $addr, $conf,@chips); 
    532   open FILE,"/dev/i2c-$_[0]" or print ("Can't open /dev/i2c-$_[0] ($!)\n"),  
    533                                return; 
     632  open FILE,"/dev/i2c-$adapter_nr" or  
     633       print ("Can't open /dev/i2c-$adapter_nr ($!)\n"), return; 
    534634  foreach $addr (0..0x7f) { 
    535635    i2c_set_slave_addr(\*FILE,$addr) or print("Can't set address to $_?!?\n"),  
     
    537637    next unless i2c_smbus_read_byte(\*FILE) >= 0; 
    538638    printf "Client found at address 0x%02x\n",$addr; 
     639    my @detection_list = (); 
     640    my $highest_conf = 0; 
     641    my $double_conf = 0; 
    539642    foreach $chip (@chip_ids) { 
    540643      if (contains $addr, @{$$chip{i2c_addrs}}) { 
     
    548651            print ")\n"; 
    549652          } 
     653          add_to_chips_detected $$chip{driver}, 
     654                                { confidence => $conf, 
     655                                  address => $addr, 
     656                                  chipname =>  $$chip{name}, 
     657                                  description => $adapter_name, 
     658                                  driver => $adapter_driver, 
     659                                }; 
    550660        } else { 
    551           print "Failed!\n"  
     661          print "Failed!\n"; 
    552662        } 
    553663      } 
     
    887997              "module. If not,", 
    888998              " you won't be able to open any /dev/i2c-* file.\n"; 
    889       } elsif (system "modprobe","i2c-proc") { 
     999      } elsif (system "modprobe","i2c-dev") { 
    8901000        print " Loading failed ($!), aborting.\n"; 
    8911001        exit; 
     
    9061016    print "\n"; 
    9071017    my ($dev_nr,$description) = /^i2c-(\S+)\s+\S+\s+(.*)$/; 
     1018    $description =~ s/\t/ /; 
    9081019    print "Next adapter: $description\n"; 
    909     print "Do you want to scan it? (YES/no):"; 
    910     scan_adapter $dev_nr unless <STDIN> =~ /^\s*[Nn]/; 
     1020    print "Do you want to scan it? (YES/no): "; 
     1021    scan_adapter $dev_nr, $description, find_adapter_driver($description) 
     1022                                              unless <STDIN> =~ /^\s*[Nn]/; 
     1023  } 
     1024 
     1025  print "\n Now follows a summary of the probes I have just done.\n"; 
     1026  my ($chip,$data); 
     1027  foreach $chip (@chips_detected) { 
     1028    print "\nDriver `$$chip{driver}' "; 
     1029    if (@{$$chip{detected}}) { 
     1030      if (@{$$chip{misdetected}}) { 
     1031        print "(should be inserted but causes problems):\n"; 
     1032      } else { 
     1033        print "(should be inserted):\n"; 
     1034      } 
     1035    } else { 
     1036      if (@{$$chip{misdetected}}) { 
     1037        print "(may not be inserted):\n"; 
     1038      } else { 
     1039        print "(should not be inserted, but is harmless):\n"; 
     1040      } 
     1041    } 
     1042    if (@{$$chip{detected}}) { 
     1043      print " Detects correctly:\n"; 
     1044      foreach $data (@{$$chip{detected}}) { 
     1045        printf "  * Bus `%s'\n". 
     1046               "    Busdriver `%s', I2C address 0x%02x\n". 
     1047               "    Chip `%s' (confidence: %d)\n", 
     1048               $data->{description}, $data->{driver}, $data->{address}, 
     1049               $data->{chipname}, $data->{address}, $data->{confidence}; 
     1050      } 
     1051    } 
     1052    if (@{$$chip{misdetected}}) { 
     1053      print "  Misdetects:\n"; 
     1054      foreach $data (@{$$chip{misdetected}}) { 
     1055        printf "  * Bus: %s\n". 
     1056               "    Busdriver `%s', I2C address 0x%02x\n". 
     1057               "    Chip `%s' (confidence: %d)\n", 
     1058               $data->{description}, $data->{driver}, $data->{address}, 
     1059               $data->{chipname}, $data->{address}, $data->{confidence}; 
     1060      } 
     1061    } 
    9111062  } 
    9121063} 
    9131064 
    9141065main; 
    915  
    916  
    917        
    918  
    919  
    920 # TEST! 
    921 # scan_adapter 0; 
    922 #} 
    923  
    924 #