From f70ea5658585ba21435d44353e9b4e12a5e7c0bc Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sat, 22 Nov 2008 16:05:13 +0000 Subject: [PATCH] Merge LM87 and ADM1024 detection in a single function. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5400 7894878c-1315-0410-8ee3-d5d059ff63e0 --- prog/detect/sensors-detect | 53 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index 7e81df54..06a8aa2b 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -757,13 +757,13 @@ use vars qw(@pci_adapters_sis5595 @pci_adapters_sis96x); name => "National Semiconductor LM87", driver => "lm87", i2c_addrs => [0x2c..0x2e], - i2c_detect => sub { lm87_detect(@_); }, + i2c_detect => sub { lm87_detect(0, @_); }, }, { name => "Analog Devices ADM1024", driver => "lm87", i2c_addrs => [0x2c..0x2e], - i2c_detect => sub { adm1024_detect(0, @_); }, + i2c_detect => sub { lm87_detect(1, @_); }, }, { name => "National Semiconductor LM93", @@ -4428,16 +4428,32 @@ sub lm85_detect return (7); } -# $_[0]: A reference to the file descriptor to access this chip. -# $_[1]: Address +# $_[0]: Chip to detect (0 = LM87, 1 = ADM1024) +# $_[1]: A reference to the file descriptor to access this chip. +# $_[2]: Address # Returns: undef if not detected, (7) if detected. -# Registers used: 0x3E, 0x3F -# Assume lower 2 bits of reg 0x3F are for revisions. +# Registers used: +# 0x3e: Company ID +# 0x3f: Revision +# 0x40: Configuration sub lm87_detect { - my ($file, $addr) = @_; - return if i2c_smbus_read_byte_data($file, 0x3e) != 0x02; - return if (i2c_smbus_read_byte_data($file, 0x3f) & 0xfc) != 0x04; + my ($chip, $file, $addr) = @_; + my $cid = i2c_smbus_read_byte_data($file, 0x3e); + my $rev = i2c_smbus_read_byte_data($file, 0x3f); + + if ($chip == 0) { + return if $cid != 0x02; # National Semiconductor + return if ($rev & 0xfc) != 0x04; + } + if ($chip == 1) { + return if $cid != 0x41; # Analog Devices + return if ($rev & 0xf0) != 0x10; + } + + my $cfg = i2c_smbus_read_byte_data($file, 0x40); + return if ($cfg & 0x80) != 0x00; + return (7); } @@ -4798,25 +4814,6 @@ sub adm1026_detect return (8); } -# $_[0]: Chip to detect (0 = ADM1024) -# $_[1]: A reference to the file descriptor to access this chip. -# $_[2]: Address -# Returns: undef if not detected, (8) if detected. -# Registers used: -# 0x3e: Company ID -# 0x3f: Revision -# 0x40: Configuration -sub adm1024_detect -{ - my $reg; - my ($chip, $file, $addr) = @_; - $reg = i2c_smbus_read_byte_data($file, 0x3e); - return unless ($reg == 0x41); - return unless (i2c_smbus_read_byte_data($file, 0x40) & 0x80) == 0x00; - return unless (i2c_smbus_read_byte_data($file, 0x3f) & 0xf0) == 0x10; - return (8); -} - # $_[0]: Chip to detect # (0 = ADM1021, 1 = ADM1021A/ADM1023, 2 = MAX1617, 3 = MAX1617A, 4 = THMC10, # 5 = LM84, 6 = GL523, 7 = MC1066)