Changeset 4472

Show
Ignore:
Timestamp:
06/26/07 09:47:30 (6 years ago)
Author:
khali
Message:

Make sensors-detect no longer depend on i2cdetect. Parsing /proc/bus/i2c or
walking sysfs for the same information (i2c adapter names) is not that
difficult.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r4469 r4472  
    4747                          Fix IPMI support for 2.6 kernels 
    4848                          Add detection for non-standard SMSC Super-I/Os 
     49                          No longer depend on i2cdetect 
    4950 
    5051 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/detect/sensors-detect

    r4469 r4472  
    3535use File::Basename; 
    3636 
    37 # We will call modprobe and i2cdetect, which typically live in either /sbin, 
     37# We will call modprobe, which typically lives in either /sbin, 
    3838# /usr/sbin or /usr/local/bin. So make sure these are all in the PATH. 
    3939foreach ('/usr/sbin', '/usr/local/sbin', '/sbin') { 
     
    22982298} 
    22992299 
     2300# @i2c_adapters is a list of references to hashes, one hash per I2C/SMBus 
     2301# adapter present on the system. Each entry has the following keys: name 
     2302# (directly taken from either /proc/bus/i2c or /sys/class/i2c-adapter) and 
     2303# driver. 
     2304use vars qw(@i2c_adapters); 
     2305 
     2306sub initialize_i2c_adapters_list 
     2307{ 
     2308  my $entry; 
     2309  local $_; 
     2310 
     2311  if (defined $sysfs_root) { 
     2312    my $class_dir = "${sysfs_root}/class/i2c-adapter"; 
     2313    opendir(local *ADAPTERS, $class_dir) or return; 
     2314 
     2315    while (defined($_ = readdir(ADAPTERS))) { 
     2316      next unless m/^i2c-(\d+)$/; 
     2317      $entry = {}; # New entry 
     2318      $entry->{'name'} = sysfs_device_attribute("${class_dir}/i2c-$1", "name") 
     2319                      || sysfs_device_attribute("${class_dir}/i2c-$1/device", "name"); 
     2320      $entry->{'driver'} = find_adapter_driver($entry->{'name'}); 
     2321      $i2c_adapters[$1] = $entry; 
     2322    } 
     2323    closedir(ADAPTERS); 
     2324  } else { 
     2325    open(local *INPUTFILE, "/proc/bus/i2c") or return; 
     2326 
     2327    while (<INPUTFILE>) { 
     2328      my ($nr, $type, $name) = /^i2c-(\d+)\s+(\S+)\s+(.*?) *(\t|$)/; 
     2329      next if ($type eq "dummy" || $type eq "isa"); 
     2330      $entry = {}; # New entry 
     2331      $entry->{'name'} = $name; 
     2332      $entry->{'driver'} = find_adapter_driver($name); 
     2333      $i2c_adapters[$nr] = $entry; 
     2334    } 
     2335    close(INPUTFILE); 
     2336  } 
     2337} 
     2338 
    23002339########### 
    23012340# MODULES # 
     
    25432582} 
    25442583 
    2545 # $_[0]: Adapter description as found in /proc/bus/i2c 
     2584# $_[0]: Adapter description as found in /proc/bus/i2c or sysfs 
    25462585sub find_adapter_driver 
    25472586{ 
     
    54965535  my ($chip,$detection,$nr,$i,@optionlist,@probelist,$driver,$isa,$adap); 
    54975536  my $ipmi = 0; 
    5498   my @adapters; 
    54995537  my $modprobes = ""; 
    55005538  my $configfile = ""; 
     
    55035541  $configfile .= "# I2C module options\n"; 
    55045542  $configfile .= "alias char-major-89 i2c-dev\n"; 
    5505  
    5506   # Collect all loaded adapters 
    5507   # i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information 
    5508   open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!"; 
    5509   local $_; 
    5510   while (<INPUTFILE>) { 
    5511     my ($dev_nr, $type, $adap) = /^i2c-(\d+)\s+(\S+)\s+(.*?) *(\t|$)/; 
    5512     next if ($type eq "dummy" || $type eq "isa"); 
    5513     $adapters[$dev_nr]->{driver} = find_adapter_driver($adap); 
    5514     $adapters[$dev_nr]->{adapname} = $adap; 
    5515   } 
    5516   close INPUTFILE; 
    55175543 
    55185544  # Collect all adapters used 
     
    55245550      # still all added. So we number them in the correct order 
    55255551      if (exists $detection->{i2c_driver} and 
    5526           not exists $adapters[$detection->{i2c_devnr}]->{nr_later} and  
     5552          not exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later} and  
    55275553          not (exists $detection->{isa_addr} and $prefer_isa)) { 
    5528          foreach $adap (@adapters) { 
     5554         foreach $adap (@i2c_adapters) { 
    55295555           next unless exists $adap->{driver}; 
    55305556           $adap->{nr_later} = $nr++ if $adap->{driver} eq $detection->{i2c_driver}; 
     
    55445570  $modprobes .= "# I2C adapter drivers\n" if $nr; 
    55455571  for ($i = 0; $i < $nr; $i++) { 
    5546     foreach $adap (@adapters) { 
     5572    foreach $adap (@i2c_adapters) { 
    55475573      next unless exists $adap->{nr_later} and $adap->{nr_later} == $i; 
    55485574      if ($adap->{driver} eq "UNKNOWN") { 
    5549         $modprobes .= "# modprobe unknown adapter ".$adap->{adapname}."\n"; 
     5575        $modprobes .= "# modprobe unknown adapter ".$adap->{name}."\n"; 
    55505576      } elsif ($adap->{driver} eq "DISABLED") { 
    5551         $modprobes .= "# modprobe disabled adapter ".$adap->{adapname}."\n"; 
     5577        $modprobes .= "# modprobe disabled adapter ".$adap->{name}."\n"; 
    55525578      } elsif ($adap->{driver} eq "to-be-written") { 
    5553         $modprobes .= "# no driver available for adapter ".$adap->{adapname}."\n"; 
     5579        $modprobes .= "# no driver available for adapter ".$adap->{name}."\n"; 
    55545580      } else { 
    55555581        $modprobes .= "modprobe $adap->{driver}\n" 
     
    56035629    # Handle misdetects 
    56045630    foreach $detection (@{$chip->{misdetected}}) { 
    5605       push @optionlist, $adapters[$detection->{i2c_devnr}]->{nr_later}, 
     5631      push @optionlist, $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}, 
    56065632                       $detection->{i2c_addr} 
    56075633           if exists $detection->{i2c_addr} and 
    5608               exists $adapters[$detection->{i2c_devnr}]->{nr_later}; 
     5634              exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}; 
    56095635      push @optionlist, -1, $detection->{isa_addr} 
    56105636           if exists $detection->{isa_addr} and $isa; 
     
    56155641      if (exists $detection->{i2c_driver} and  
    56165642          exists $detection->{isa_addr} and 
    5617           exists $adapters[$detection->{i2c_devnr}]->{nr_later} and 
     5643          exists $i2c_adapters[$detection->{i2c_devnr}]->{nr_later} and 
    56185644          $isa) { 
    56195645        if ($prefer_isa) { 
    5620           push @optionlist,$adapters[$detection->{i2c_devnr}]->{nr_later}, 
     5646          push @optionlist, $i2c_adapters[$detection->{i2c_devnr}]->{nr_later}, 
    56215647                           $detection->{i2c_addr}; 
    56225648        } else { 
     
    57045730  print "If you have undetectable or unsupported adapters, you can have them\n". 
    57055731        "scanned by manually loading the modules before running this script.\n\n"; 
     5732  initialize_i2c_adapters_list(); 
    57065733 
    57075734  if (!exists($modules_list{"i2c-dev"}) 
     
    57335760 
    57345761  my ($inp,@not_to_scan,$inp2); 
    5735   # i2cdetect -l either cats /proc/bus/i2c or scans sysfs for the same information 
    5736   open(local *INPUTFILE, "i2cdetect -l |") or die "Couldn't find i2cdetect program!!"; 
    5737   local $_; 
    5738   while (<INPUTFILE>) { 
    5739     my ($dev_nr, $type, $adap) = /^i2c-(\d+)\s+(\S+)\s+(.*?) *(\t|$)/; 
    5740     next if ($type eq "dummy" || $type eq "isa"); 
     5762  for (my $dev_nr = 0; $dev_nr < @i2c_adapters; $dev_nr++) { 
     5763    next unless exists $i2c_adapters[$dev_nr]; 
     5764    my $adap = $i2c_adapters[$dev_nr]->{'name'}; 
    57415765    print "\n"; 
    57425766    print "Next adapter: $adap (i2c-$dev_nr)\n"; 
     
    57555779      @not_to_scan = parse_not_to_scan 0,0x7f,$inp2; 
    57565780    } 
    5757     scan_adapter $dev_nr, $adap, find_adapter_driver($adap), 
     5781    scan_adapter $dev_nr, $adap, $i2c_adapters[$dev_nr]->{'driver'}, 
    57585782                 \@not_to_scan   unless $inp =~ /^\s*[Nn]/; 
    57595783  }