Show
Ignore:
Timestamp:
02/01/00 22:12:43 (13 years ago)
Author:
frodo
Message:

sensors-detect should cope better now with adapters with multiple

busses

The changes are large and tricky, so it is almost certain there are
many bugs. Please run sensors-detect and tell me whether it works
correctly or not.

All changes are in the routines that print the modprobe statements at
the end, so if it fails, it will fail there.

Files:
1 modified

Legend:

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

    r714 r720  
    17831783 
    17841784# $_[0]: 1 if ISA bus is prefered, 0 for SMBus 
     1785# We build here an array adapters, indexed on the number the adapter has 
     1786# at this moment (we assume only loaded adapters are interesting at all; 
     1787# everything that got scanned also got loaded). Each entry is a reference 
     1788# to a hash containing: 
     1789#  driver: Name of the adapter driver 
     1790#  nr_now: Number of the bus now 
     1791#  nr_later: Number of the bus when the modprobes are done (not included if the 
     1792#        driver should not be loaded) 
     1793# A second array, called  
    17851794sub generate_modprobes 
    17861795{ 
    17871796  my ($prefer_isa) = @_; 
    17881797 
    1789   my ($chip,$detection,%adapters,$nr,$i,@optionlist,@probelist); 
     1798  my ($chip,$detection,$nr,$i,@optionlist,@probelist,$driver,$isa,$adap); 
     1799  my @adapters; 
    17901800  my $modprobes = ""; 
    17911801  my $configfile = ""; 
     
    17951805  $configfile .= "alias char-major-89 i2c-dev\n"; 
    17961806 
    1797   # Collect all adapters 
     1807  # Collect all loaded adapters 
     1808  open INPUTFILE,"/proc/bus/i2c" or die "Couldn't open /proc/bus/i2c?!?"; 
     1809  while (<INPUTFILE>) { 
     1810    my ($dev_nr,$type,$adap,$algo) = /^i2c-(\S+)\s+(\S+)\s+(.*?)\s*\t\s*(.*?)\s+$/; 
     1811    next if ($type eq "dummy"); 
     1812    $adapters[$dev_nr]->{driver} = find_adapter_driver($adap,$algo); 
     1813  } 
     1814  close INPUTFILE; 
     1815 
     1816  # Collect all adapters used 
    17981817  $nr = 0; 
     1818  $isa = 0; 
    17991819  $modprobes .= "# I2C adapter drivers\n"; 
    18001820  foreach $chip (@chips_detected) { 
    18011821    foreach $detection (@{$chip->{detected}}) { 
    1802       %adapters->{$detection->{i2c_driver}} = $nr ++ 
    1803             if exists $detection->{i2c_driver} and  
    1804                not exists %adapters->{$detection->{i2c_driver}} and 
    1805                not (exists $detection->{isa_addr} and $prefer_isa); 
    1806       %adapters->{"i2c-isa"} = $nr ++  
    1807             if exists $detection->{isa_addr} and  
    1808                not exists %adapters->{"i2c-isa"} and 
    1809                not (exists $detection->{i2c_driver} and not $prefer_isa); 
    1810     } 
    1811   } 
    1812   for ($i = 0; $i < $nr; $i ++) { 
    1813     foreach $detection (keys %adapters) { 
    1814       $modprobes .= "modprobe $detection\n", last  
    1815                  if $adapters{$detection} == $i; 
    1816     } 
    1817   } 
     1822      # If there is more than one bus detected by a driver, they are 
     1823      # still all added. So we number them in the correct order 
     1824      if (exists $detection->{i2c_driver} and 
     1825          not exists $adapters[$detection->{i2c_devnr}]->{nr} and  
     1826          not (exists $detection->{isa_addr} and $prefer_isa)) { 
     1827         foreach $adap (@adapters) { 
     1828           $adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver}; 
     1829         } 
     1830      } 
     1831      if (exists $detection->{isa_addr} and 
     1832          not (exists $detection->{i2c_driver} and not $prefer_isa)) { 
     1833           $isa=1; 
     1834      } 
     1835    } 
     1836  } 
     1837 
     1838  for ($i = 0; $i < $nr; $i++) { 
     1839    foreach $adap (@adapters) { 
     1840      $modprobes .= "modprobe $adap->{driver}\n" if (defined($adap->{nr_later}) and $adap->{nr_later} == $i); 
     1841    } 
     1842  } 
     1843  $modprobes .= "modprobe i2c-isa\n" if ($isa); 
    18181844 
    18191845  # Now determine the chip probe lines 
     
    18251851    @probelist = (); 
    18261852 
    1827     # Handle detects out-of-range 
     1853    # Handle detects at addresses normally not probed 
    18281854    foreach $detection (@{$chip->{detected}}) { 
    1829       push @probelist, %adapters->{$detection->{i2c_driver}}, 
     1855      push @probelist, $adapters[$detection->{i2c_devnr}]->{nr_later}, 
    18301856                       $detection->{i2c_addr} 
    1831            if exists $detection->{i2c_driver} and 
    1832               exists %adapters->{$detection->{i2c_driver}} and 
     1857           if exists $detection->{i2c_addr} and 
    18331858              exists $detection->{i2c_extra}; 
    18341859      push @probelist, -1, $detection->{isa_addr} 
    18351860           if exists $detection->{isa_addr} and 
    1836               exists %adapters->{"i2c-isa"} and 
    18371861              exists $detection->{isa_extra}; 
    18381862    } 
     
    18401864    # Handle misdetects 
    18411865    foreach $detection (@{$chip->{misdetected}}) { 
    1842       push @optionlist, %adapters->{$detection->{i2c_driver}}, 
     1866      push @optionlist, $adapters[$detection->{i2c_devnr}]->{nr_later}, 
    18431867                       $detection->{i2c_addr} 
    1844            if exists $detection->{i2c_driver} and 
    1845               exists %adapters->{$detection->{i2c_driver}}; 
     1868           if exists $detection->{i2c_addr} and 
     1869              exists $adapters[$detection->{i2c_devnr}]->{nr_later}; 
    18461870      push @optionlist, -1, $detection->{isa_addr} 
    1847            if exists $detection->{isa_addr} and 
    1848               exists %adapters->{"i2c-isa"}; 
     1871           if exists $detection->{isa_addr} and $isa; 
    18491872    } 
    18501873 
     
    18531876      if (exists $detection->{i2c_driver} and  
    18541877          exists $detection->{isa_addr} and 
    1855           exists %adapters->{$detection->{i2c_driver}} and 
    1856           exists %adapters->{"i2c-isa"}) { 
     1878          exists $adapters[$detection->{i2c_devnr}]->{nr_later} and 
     1879          $isa) { 
    18571880        if ($prefer_isa) { 
    1858           push @optionlist,%adapters->{$detection->{i2c_driver}}, 
     1881          push @optionlist,$adapters[$detection->{i2c_devnr}]->{nr_later}, 
    18591882                           $detection->{i2c_addr}; 
    18601883        } else {