From 697dd4f4ec9289ec18a57b658058109c171021ad Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 2 Dec 2008 22:08:45 +0000 Subject: [PATCH] Do not scan I2C adapters on multimedia cards by default. I've never seen a hardware monitoring chip on such boards, and probing them can cause problems. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5504 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/detect/sensors-detect | 43 ++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 44673eea..1086ae41 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,7 @@ SVN-HEAD Probe chip types from safest to more risky (#2322) Add an option to skip ISA probes except IPMI Skip ISA detection by default if a Super I/O was found (#2322) + Do not scan I2C adapters on multimedia cards by default 3.0.3 (2008-09-28) libsensors: Avoid namespace pollution diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index f867e1d5..e06c31e0 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2064,6 +2064,16 @@ sub sysfs_device_driver return basename($link); } +# From a sysfs device path, return the subsystem name, or undef +sub sysfs_device_subsystem +{ + my $device = shift; + + my $link = readlink("$device/subsystem"); + return unless defined $link; + return basename($link); +} + # From a sysfs device path and an attribute name, return the attribute # value, or undef sub sysfs_device_attribute @@ -2702,17 +2712,42 @@ sub probe_free_i2c_address } } +# $_[0]: The number of the adapter to check +# Returns: 1 if the I2C adapter is on a PCI multimedia adapter, 0 otherwise +sub is_multimedia_i2c_adapter +{ + my ($adapter_nr) = @_; + my ($adapter, $subsystem, $class); + + $adapter = "$sysfs_root/class/i2c-adapter/i2c-$adapter_nr"; + $subsystem = sysfs_device_subsystem("$adapter/device"); + return 0 unless defined $subsystem && $subsystem eq "pci"; + + $class = sysfs_device_attribute("$adapter/device", "class"); + return 0 unless defined $class; + $class = oct($class) if $class =~ /^0/; + return ($class & 0xff0000) == 0x040000; +} + # $_[0]: The number of the adapter to scan sub scan_i2c_adapter { my ($adapter_nr) = @_; - my ($funcs, $chip, $addr, $input, @not_to_scan); + my ($funcs, $chip, $addr, $multimedia, $input, @not_to_scan); - print "Next adapter: $i2c_adapters[$adapter_nr]->{name} (i2c-$adapter_nr)\n". - "Do you want to scan it? (YES/no/selectively): "; + # Do not probe adapters on PCI multimedia cards by default + $multimedia = is_multimedia_i2c_adapter($adapter_nr); + + printf "Next adapter: $i2c_adapters[$adapter_nr]->{name} (i2c-$adapter_nr)\n". + "Do you want to scan it? (\%s): ", + $multimedia ? "yes/NO/selectively" : "YES/no/selectively"; $input = ; - return if $input =~ /^\s*n/i; + if ($input =~ /^\s*n/i + || ($multimedia && $input !~ /^\s*[ys]/i)) { + print "\n"; + return; + } if ($input =~ /^\s*s/i) { print "Please enter one or more addresses not to scan. Separate them with commas.\n",