All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] [PATCH 2/2] sensors-detect: Add detection of NCT7802Y
Date: Wed, 25 Jun 2014 20:42:26 +0000	[thread overview]
Message-ID: <1403728946-6653-2-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1359434448-21181-2-git-send-email-linux@roeck-us.net>

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 CHANGES                    |  1 +
 prog/detect/sensors-detect | 68 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/CHANGES b/CHANGES
index 3390942..a16e7be 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ SVN HEAD
                   Add detection of ITE IT8620E and IT8623E
                   Add detection of TMP441, TMP442, LM95233, LM95234,
                   and LM95235
+                  Add detection of NCT7802Y
 
 3.3.5 "Happy Birthday Beddy" (2014-01-22)
   libsensors: Improve documentation of two functions
diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect
index df9a408..159d2cb 100755
--- a/prog/detect/sensors-detect
+++ b/prog/detect/sensors-detect
@@ -733,6 +733,11 @@ use vars qw(@i2c_adapter_names);
 		i2c_addrs => [0x2c..0x2f],
 		i2c_detect => sub { w83795_detect(@_); },
 	}, {
+		name => "Nuvoton NCT7802Y",
+		driver => "to-be-written",
+		i2c_addrs => [0x28..0x2f],
+		i2c_detect => sub { nct7802_detect(@_); },
+	}, {
 		name => "Winbond W83627HF",
 		driver => "use-isa-instead",
 		i2c_addrs => [0x28..0x2f],
@@ -5483,6 +5488,69 @@ sub w83795_detect
 }
 
 # Registers used:
+#   0x00: bank selection (Bank 0, 1)
+#   0x40, 0x80, 0xc0: bank selection (Bank 1)
+#   0x01, 0x41, 0x81, 0xc1: PECI control register 1 (Bank 1)
+#   0x02, 0x42, 0x82, 0xc2: PECI control register 2 (Bank 1)
+#   0x03, 0x43, 0x83, 0xc3: PECI control register 3 (Bank 1)
+#   0xfd: Vendor ID (Bank 0)
+#   0xfe: Device ID (Bank 0)
+#   0xff: Device Revision (Bank 0)
+sub nct7802_detect
+{
+	my ($bank, $reg, $pc1, $pc2, $pc3);
+	my ($file, $addr) = @_;
+
+	$bank = i2c_smbus_read_byte_data($file, 0x00);
+	return unless ($bank = 0x00 or $bank = 0x01);
+
+	# we can not do much if bank 1 is selected
+	if ($bank = 0x01) {
+		# We can not use bit masks since all bits
+		# (including reserved bits) can be set.
+		$pc1 = i2c_smbus_read_byte_data($file, 0x01);
+		$pc2 = i2c_smbus_read_byte_data($file, 0x02);
+		$pc3 = i2c_smbus_read_byte_data($file, 0x03);
+
+		# Register values repeat every 64 registers on bank 1.
+		# Check the first four registers of each group.
+		for (my $i = 0x40; $i <= 0xc0; $i += 0x40) {
+			$reg = i2c_smbus_read_byte_data($file, $i);
+			return if $reg != 0x01;
+			$reg = i2c_smbus_read_byte_data($file, $i + 1);
+			return if $reg != $pc1;
+			$reg = i2c_smbus_read_byte_data($file, $i + 2);
+			return if $reg != $pc2;
+			$reg = i2c_smbus_read_byte_data($file, $i + 3);
+			return if $reg != $pc3;
+		}
+		return 3;
+	}
+
+	# bank 0, can support real chip detection
+
+	$reg = i2c_smbus_read_byte_data($file, 0xfd);
+	return unless ($reg = 0x50);
+
+	$reg = i2c_smbus_read_byte_data($file, 0xfe);
+	return unless $reg = 0xc3;
+
+	$reg = i2c_smbus_read_byte_data($file, 0xff);
+	return unless ($reg & 0xf0) = 0x20;
+
+	$reg = i2c_smbus_read_byte_data($file, 0x05);
+	return unless ($reg & 0x1f) = 0x00;
+
+	$reg = i2c_smbus_read_byte_data($file, 0x08);
+	return unless ($reg & 0x3f) = 0x00;
+
+	$reg = i2c_smbus_read_byte_data($file, 0x0f);
+	return unless ($reg & 0x3f) = 0x00;
+
+	return 8;
+}
+
+# Registers used:
 #   0x48: Full I2C Address
 #   0x4e: Vendor ID byte selection
 #   0x4f: Vendor ID
-- 
1.9.1


_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

  parent reply	other threads:[~2014-06-25 20:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-29  4:40 [lm-sensors] [PATCH 2/2] sensors-detect: Add detection of MCP98244 Guenter Roeck
2013-03-16 18:30 ` [lm-sensors] [PATCH 2/2] sensors-detect: Add detection of TMP431 and TMP432 Guenter Roeck
2013-03-17 13:12 ` Jean Delvare
2014-06-25 20:42 ` Guenter Roeck [this message]
2014-06-25 20:45 ` [lm-sensors] [PATCH 2/2] sensors-detect: Add detection of NCT7802Y Guenter Roeck
2014-06-26  9:40 ` Jean Delvare
2014-06-26 13:13 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403728946-6653-2-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.