mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 14:25:39 +00:00
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
This commit is contained in:
@@ -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<max for voltages, hyst<max for temperature). Since it is still
|
||||
# possible that the chip is an LM80 with limits not properly set,
|
||||
# a few "errors" are tolerated.
|
||||
my $confidence = 0;
|
||||
for ($i = 0x2a; $i <= 0x3a; $i++) {
|
||||
$confidence++
|
||||
if i2c_smbus_read_byte_data($file,$i) < i2c_smbus_read_byte_data($file,$i+1);
|
||||
}
|
||||
|
||||
return;
|
||||
# hot temp<OS temp
|
||||
$confidence++
|
||||
if i2c_smbus_read_byte_data($file,0x38) < i2c_smbus_read_byte_data($file,0x3a);
|
||||
|
||||
# Negative temperature limits are unlikely.
|
||||
for ($i = 0x3a; $i <= 0x3d; $i++) {
|
||||
$confidence++ if (i2c_smbus_read_byte_data($file,$i) & 0x80) == 0;
|
||||
}
|
||||
|
||||
# $confidence is between 0 and 14
|
||||
$confidence = ($confidence >> 1) - 4;
|
||||
# $confidence is now between -4 and 3
|
||||
|
||||
return unless $confidence > 0;
|
||||
|
||||
return $confidence;
|
||||
}
|
||||
|
||||
# $_[0]: Chip to detect
|
||||
|
Reference in New Issue
Block a user