[PATCH 2/2 i2c-tools] sensors-detect: Refactor manufacturer decoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of reencoding pre-DDR3 manufacturer code to DDR3 manufacturer
code, move the common decoding to a separate function.
---
 eeprom/decode-dimms |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

--- i2c-tools.orig/eeprom/decode-dimms	2015-06-01 09:14:30.899898763 +0200
+++ i2c-tools/eeprom/decode-dimms	2015-06-01 09:19:01.931673815 +0200
@@ -336,6 +336,21 @@ sub parity($)
 	return ($parity & 1);
 }
 
+# The code byte includes parity, the count byte does not.
+sub manufacturer_common($$)
+{
+	my ($count, $code) = @_;
+	my $manufacturer;
+
+	return "Invalid" if parity($code) != 1
+			 or ($code &= 0x7F) == 0;
+	return "Unknown" if $count >= @vendors
+			 or $code - 1 >= @{$vendors[$count]};
+	$manufacturer = $vendors[$count][$code - 1];
+	$manufacturer =~ s/ \(former .*\)$// if $opt_side_by_side;
+	return $manufacturer;
+}
+
 # New encoding format (as of DDR3) for manufacturer just has a count of
 # leading 0x7F rather than all the individual bytes.  The count bytes includes
 # parity!
@@ -346,12 +361,7 @@ sub manufacturer_ddr3($$)
 
 	return "Undefined" unless spd_written($count, $code);
 
-	return "Invalid" if parity($code) != 1
-			 or ($code & 0x7F) == 0;
-	return "Unknown" if ($count & 0x7F) >= @vendors
-			 or ($code & 0x7F) - 1 >= @{$vendors[$count & 0x7F]};
-	$manufacturer = $vendors[$count & 0x7F][($code & 0x7F) - 1];
-	$manufacturer =~ s/ \(former .*\)$// if $opt_side_by_side;
+	$manufacturer = manufacturer_common($count & 0x7F, $code);
 	$manufacturer .= "? (Invalid parity)" if parity($count) != 1;
 	return $manufacturer;
 }
@@ -369,11 +379,7 @@ sub manufacturer(@)
 	}
 
 	return ("Invalid", []) unless defined $first;
-	return ("Invalid", [$first, @bytes]) if parity($first) != 1;
-	if (parity($ai) == 0) {
-		$ai |= 0x80;
-	}
-	return (manufacturer_ddr3($ai, $first), \@bytes);
+	return (manufacturer_common($ai, $first), \@bytes);
 }
 
 sub manufacturer_data(@)


-- 
Jean Delvare
SUSE L3 Support
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux