Changeset 4077

Show
Ignore:
Timestamp:
07/29/06 17:58:26 (7 years ago)
Author:
khali
Message:

sensors-detect: Get driver information for busy addresses from
sysfs (2.6 only).

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r4075 r4077  
    5555                          Add AMD Geode devices detection 
    5656                          Add NatSemi/Winbond PC87427 detection 
     57                          Get driver information for busy addresses from 
     58                           sysfs (2.6 only) 
    5759 
    5860 
  • lm-sensors/trunk/prog/detect/sensors-detect

    r4076 r4077  
    3232use Fcntl; 
    3333use POSIX; 
     34use File::Basename; 
    3435 
    3536# Just in case a root user doesn't have /sbin in his/her path for some reason 
     
    21762177################# 
    21772178 
    2178 use vars qw($modules_conf $dev_i2c); 
     2179use vars qw($modules_conf $dev_i2c $sysfs_root); 
    21792180 
    21802181sub initialize_conf 
     
    21872188      $use_devfs = 1; 
    21882189      $dev_i2c = '/dev/i2c/'; 
    2189       last; 
     2190    } 
     2191    if (m@^\S+ (/\w+) sysfs @) { 
     2192      $sysfs_root = $1; 
    21902193    } 
    21912194  } 
     
    22612264########### 
    22622265 
    2263 use vars qw(%modules_list); 
     2266use vars qw(%modules_list %modules_supported); 
    22642267 
    22652268sub initialize_modules_list 
     
    22712274    $modules_list{$1} = 1 if m/^(\S*)/; 
    22722275  } 
     2276} 
     2277 
     2278sub initialize_modules_supported 
     2279{ 
     2280  foreach my $chip (@chip_ids) { 
     2281    $modules_supported{$chip->{driver}}++; 
     2282  } 
     2283} 
     2284 
     2285################# 
     2286# SYSFS HELPERS # 
     2287################# 
     2288 
     2289# From a sysfs device path, return the driver name, or undef 
     2290sub sysfs_device_driver($) 
     2291{ 
     2292  my $device = shift; 
     2293   
     2294  my $link = readlink("$device/driver"); 
     2295  return unless defined $link; 
     2296  return basename($link); 
     2297} 
     2298 
     2299# From a sysfs device path and an attribute name, return the attribute 
     2300# value, or undef 
     2301sub sysfs_device_attribute($$) 
     2302{ 
     2303  my ($device, $attr) = @_; 
     2304  my $value; 
     2305 
     2306  open(local *FILE, "$device/$attr") or return; 
     2307  return unless defined($value = <FILE>); 
     2308  close(FILE); 
     2309 
     2310  chomp($value); 
     2311  return $value; 
    22732312} 
    22742313 
     
    27992838    } 
    28002839 
    2801     i2c_set_slave_addr(\*FILE,$addr) or  
    2802         printf("Client at address 0x%02x can not be probed - unload all client drivers first!\n",$addr), next; 
     2840    if (!i2c_set_slave_addr(\*FILE, $addr)) { 
     2841      # If the address is busy, in Linux 2.6 we can find out which driver 
     2842      # is using it, and we assume it is the right one. In Linux 2.4 we 
     2843      # just give up and warn the user. 
     2844      my ($device, $driver); 
     2845      if (defined($sysfs_root)) { 
     2846        $device = sprintf("/sys/bus/i2c/devices/\%d-\%04x", 
     2847                             $adapter_nr, $addr); 
     2848        $driver = sysfs_device_driver($device); 
     2849      } 
     2850      if (defined($driver)) { 
     2851        $new_hash = { 
     2852          conf => 6, # Arbitrary confidence 
     2853          i2c_addr => $addr, 
     2854          chipname => sysfs_device_attribute($device, "name") || "unknown", 
     2855          i2c_adap => $adapter_name, 
     2856          i2c_driver => $adapter_driver, 
     2857          i2c_devnr => $adapter_nr, 
     2858        }; 
     2859        $new_hash->{i2c_extra} = 0  
     2860            if exists $chip->{i2c_driver_addrs} and 
     2861               not contains($addr, @{$chip->{i2c_driver_addrs}}); 
     2862 
     2863        printf "Client found at address 0x\%02x\n", $addr; 
     2864        printf "Handled by driver `\%s' (already loaded), chip type `\%s'\n", 
     2865               $driver, $new_hash->{chipname}; 
     2866 
     2867        # Only add it to the list if this is something we would have 
     2868        # detected, else we end up with random i2c chip drivers listed 
     2869        # (for example media/video drivers.) 
     2870        if (exists $modules_supported{$driver}) { 
     2871          add_i2c_to_chips_detected($driver, $new_hash); 
     2872        } else { 
     2873          print "    (note: this is NOT a sensor chip!)\n"; 
     2874        }     
     2875      } else { 
     2876        printf("Client at address 0x%02x can not be probed - ". 
     2877               "unload all client drivers first!\n", $addr); 
     2878      } 
     2879      next; 
     2880    } 
    28032881 
    28042882    next unless i2c_probe(\*FILE, $addr); 
     
    52855363  initialize_proc_pci; 
    52865364  initialize_modules_list; 
     5365  initialize_modules_supported; 
    52875366  initialize_kernel_version; 
    52885367