From 09d912a45f6112c3cb3d1889d0469786bb49c005 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 22 Jul 2009 12:20:58 +0000 Subject: [PATCH] Support upcoming sysfs path to i2c adapters. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5758 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/detect/sensors-detect | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index bb209a17..77a2b521 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ SVN-HEAD Report unsupported Access Bus adapters Add detection for TI's TMP421, TMP422 and TMP423 chips The SMSC LPC47M233 isn't currently supported + Support upcoming sysfs path to i2c adapters sysconfig-lm_sensors-convert: Fix exit code 3.1.1 (2009-06-21) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index ea966b53..bbab62c1 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2150,11 +2150,17 @@ sub device_driver_autoloads sub initialize_i2c_adapters_list { - my $entry; + my ($entry, $base_dir, $have_i2c_adapter_class); local $_; - my $class_dir = "${sysfs_root}/class/i2c-adapter"; - opendir(local *ADAPTERS, $class_dir) or return; + if (-d "${sysfs_root}/class/i2c-adapter") { + $base_dir = "${sysfs_root}/class/i2c-adapter"; + $have_i2c_adapter_class = 1; + } else { + $base_dir = "${sysfs_root}/bus/i2c/devices"; + $have_i2c_adapter_class = 0; + } + opendir(local *ADAPTERS, $base_dir) or return; while (defined($_ = readdir(ADAPTERS))) { next unless m/^i2c-(\d+)$/; @@ -2162,13 +2168,20 @@ sub initialize_i2c_adapters_list $entry = {}; # New entry # The layout in sysfs has changed over the years - my $link = readlink("${class_dir}/i2c-$nr/device"); - if ($link =~ m/^(.*)\/i2c-$nr$/) { - $entry->{path} = "${class_dir}/i2c-$nr/device"; - $entry->{parent} = "${class_dir}/i2c-$nr/$1"; + if ($have_i2c_adapter_class) { + my $link = readlink("${base_dir}/i2c-$nr/device"); + if ($link =~ m/^(.*)\/i2c-$nr$/) { + $entry->{path} = "${base_dir}/i2c-$nr/device"; + $entry->{parent} = "${base_dir}/i2c-$nr/$1"; + } else { + $entry->{path} = "${base_dir}/i2c-$nr"; + $entry->{parent} = "$entry->{path}/device"; + } } else { - $entry->{path} = "${class_dir}/i2c-$nr"; - $entry->{parent} = "$entry->{path}/device"; + my $link = readlink("${base_dir}/i2c-$nr"); + $link =~ s/\/i2c-$nr$//; + $entry->{path} = "${base_dir}/i2c-$nr"; + $entry->{parent} = "${base_dir}/$link"; } $entry->{name} = sysfs_device_attribute($entry->{path}, "name");