From 68730b9590a586dd0ee97eff1b9b40b9cf138132 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 11 Feb 2004 22:07:02 +0000 Subject: [PATCH] Add heuristics to the LM80 detection function. Should prevent misdetections. Thanks to Lennard Klein for testing. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2283 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/detect/sensors-detect | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index eb374e11..747476f9 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -2600,15 +2600,30 @@ sub ds1621_detect # $_[0]: A reference to the file descriptor to access this chip. # We may assume an i2c_set_slave_addr was already done. # $_[1]: Address -# Returns: undef if not detected, (3) if detected. +# Returns: undef if not detected, 1 to 3 if detected. # Registers used: +# 0x00: Configuration register # 0x02: Interrupt state register -# How to detect this beast? +# 0x2a-0x3d: Limits registers +# This one is easily misdetected since it doesn't provide identification +# registers. So we have to use some tricks: +# - 6-bit addressing, so limits readings modulo 0x40 should be unchanged +# - positive temperature limits +# - limits order correctness +# Hopefully this should limit the rate of false positives, without increasing +# the rate of false negatives. +# Thanks to Lennard Klein for testing on a non-LM80 chip, which was +# previously misdetected, and isn't anymore. For reference, it scored +# a final confidence of 0, and changing from strict limit comparisons +# to loose comparisons did not change the score. sub lm80_detect { my ($i,$reg); my ($file,$addr) = @_; + + return if (i2c_smbus_read_byte_data($file,0x00) & 0x80) != 0; return if (i2c_smbus_read_byte_data($file,0x02) & 0xc0) != 0; + for ($i = 0x2a; $i <= 0x3d; $i++) { $reg = i2c_smbus_read_byte_data($file,$i); return if i2c_smbus_read_byte_data($file,$i+0x40) != $reg; @@ -2616,13 +2631,31 @@ sub lm80_detect return if i2c_smbus_read_byte_data($file,$i+0xc0) != $reg; } - # If all limits and readings have the same value, it's obviously - # a misdetection - for ($i = 0x2a; $i < 0x3d; $i++) { - return 3 if i2c_smbus_read_byte_data($file,$i) != $reg; + # Refine a bit by checking wether limits are in the correct order + # (min> 1) - 4; + # $confidence is now between -4 and 3 + + return unless $confidence > 0; + + return $confidence; } # $_[0]: Chip to detect