From f1a8ba3d1df521bd81a666f6c2b7d0074ac873c1 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 25 Jan 2007 09:18:23 +0000 Subject: [PATCH] sensors-detect: Speed up the LM75 and LM77 detection. The previous code was using a brute force approach, quite reliable but very slow. The new code should be just as reliable but about ten times faster. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4312 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/detect/sensors-detect | 28 ++++------------------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/CHANGES b/CHANGES index 1483ba2a..0b8f4611 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ SVN HEAD Add VIA CX700 detection Drop legacy W83627HF ISA detection Don't bufferize stdout during probes + Speed up the LM75 and LM77 detection 2.10.2 (20070115) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index 124d1ad3..91333457 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -3314,7 +3314,6 @@ sub lm75_detect my $i; my ($file,$addr) = @_; my $cur = i2c_smbus_read_word_data($file,0x00); - my $cur_varies = 0; my $conf = i2c_smbus_read_byte_data($file,0x01); my $hyst = i2c_smbus_read_word_data($file,0x02); @@ -3329,25 +3328,14 @@ sub lm75_detect return if i2c_smbus_read_word_data($file,0x06) != $os; return if i2c_smbus_read_word_data($file,0x07) != $os; - for ($i = 0x00; $i < 0xff; $i += 8) { + for ($i = 8; $i <= 248; $i += 40) { return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf; return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst; - return if i2c_smbus_read_word_data($file, $i + 0x04) != $hyst; - return if i2c_smbus_read_word_data($file, $i + 0x05) != $hyst; - return if i2c_smbus_read_word_data($file, $i + 0x06) != $hyst; - return if i2c_smbus_read_word_data($file, $i + 0x07) != $hyst; return if i2c_smbus_read_word_data($file, $i + 0x03) != $os; - return if i2c_smbus_read_word_data($file, $i + 0x04) != $os; - return if i2c_smbus_read_word_data($file, $i + 0x05) != $os; - return if i2c_smbus_read_word_data($file, $i + 0x06) != $os; - return if i2c_smbus_read_word_data($file, $i + 0x07) != $os; - $cur_varies = 1 - if (! $cur_varies) and - i2c_smbus_read_word_data($file, $i) != $cur; } # All registers hold the same value, obviously a misdetection - return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst + return if $conf == ($cur & 0xff) and $cur == $hyst and $cur == $os; $cur = swap_bytes($cur); @@ -3389,7 +3377,6 @@ sub lm77_detect my $i; my ($file,$addr) = @_; my $cur = i2c_smbus_read_word_data($file,0x00); - my $cur_varies = 0; my $conf = i2c_smbus_read_byte_data($file,0x01); my $hyst = i2c_smbus_read_word_data($file,0x02); my $os = i2c_smbus_read_word_data($file,0x03); @@ -3402,23 +3389,16 @@ sub lm77_detect return if i2c_smbus_read_word_data($file,0x06) != $high; return if i2c_smbus_read_word_data($file,0x07) != $high; - for ($i = 0x00; $i < 0xff; $i += 8) { + for ($i = 8; $i <= 248; $i += 40) { return if i2c_smbus_read_byte_data($file, $i + 0x01) != $conf; return if i2c_smbus_read_word_data($file, $i + 0x02) != $hyst; return if i2c_smbus_read_word_data($file, $i + 0x03) != $os; return if i2c_smbus_read_word_data($file, $i + 0x04) != $low; - return if i2c_smbus_read_word_data($file, $i + 0x06) != $low; - return if i2c_smbus_read_word_data($file, $i + 0x07) != $low; return if i2c_smbus_read_word_data($file, $i + 0x05) != $high; - return if i2c_smbus_read_word_data($file, $i + 0x06) != $high; - return if i2c_smbus_read_word_data($file, $i + 0x07) != $high; - $cur_varies = 1 - if (! $cur_varies) and - i2c_smbus_read_word_data($file, $i) != $cur; } # All registers hold the same value, obviously a misdetection - return if (! $cur_varies) and $conf == ($cur & 0xff) and $cur == $hyst + return if $conf == ($cur & 0xff) and $cur == $hyst and $cur == $os and $cur == $low and $cur == $high; $cur = swap_bytes($cur);