| | 2276 | } |
| | 2277 | |
| | 2278 | sub 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 |
| | 2290 | sub 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 |
| | 2301 | sub 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; |
| 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 | } |