All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Per Dalén" <per.dalen@appeartv.com>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH v2] sensors-detect: Add detection of MAX6642
Date: Wed, 01 Jun 2011 08:02:25 +0000	[thread overview]
Message-ID: <4DE5F211.2090003@appeartv.com> (raw)
In-Reply-To: <4DDE1CFF.1020906@appeartv.com>

[-- Attachment #1: Type: text/plain, Size: 3569 bytes --]

Hi,

Here's the new patch for sensors-detect.

Changed according to the suggestions from Jean Delvare:

* Check the manufacturer ID directly. Fastens the test if it's not a
Maxim chip.
* Read the other non-existing registers after the manufacturer ID.
* Read the other non-existing registers after the status.
* Removed NO_CACHE from manufacturer ID, Status and Configuration registers.

BR
Per

On 05/26/2011 09:33 PM, Jean Delvare wrote:
> Hi Per,
> 
> On Thu, 26 May 2011 11:27:27 +0200, Per Dalén wrote:
>> Changed according to the suggestions from Guenter Roeck:
>>
>> * Check the manufacturer ID directly. Fastens the test if it's not a
>> Maxim chip.
>> * Read the other non-existing registers after the manufacturer ID.
> 
> THis is better but I'm not completely happy yet.
> 
>> This patch adds detection of MAX6642 to sensors-detect.
>>
>> Signed-off-by: Per Dalen <per.dalen@appeartv.com>
>> ---
>>
>> --- prog/detect/sensors-detect	(revision 5975)
>> +++ prog/detect/sensors-detect	(working copy)
>> @@ -848,6 +848,11 @@
>>  		i2c_addrs => [0x2c, 0x2e, 0x2f],
>>  		i2c_detect => sub { max6639_detect(@_); },
>>  	}, {
>> +		name => "Maxim MAX6642",
>> +		driver => "max6642",
>> +		i2c_addrs => [0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f],
> 
> Better written: [0x48..0x4f]
> 
>> +		i2c_detect => sub { max6642_detect(@_); },
>> +	}, {
>>  		name => "Maxim MAX6655/MAX6656",
>>  		driver => "max6655",
>>  		i2c_addrs => [0x18..0x1a, 0x29..0x2b, 0x4c..0x4e],
>> @@ -5779,6 +5784,36 @@
>>  	return 6;
>>  }
>>
>> +# Chip to detect: MAX6642
>> +# Registers used:
>> +#   0x02: Status register
>> +#   0x03: Configuration register
>> +#   0xfe: Manufacturer ID
>> +#   0x04,0x06,0xff: No registers
>> +# We use the 0x04,0x06 and 0xff addresses (unused) to improve the
> 
> Space after comma please.
> 
>> reliability.
> 
> Please disable line wrapping in your e-mail client before sending patches.
> 
>> +# These are not real registers and will always return the last returned
>> value.
>> +# This isn't documented.
>> +sub max6642_detect
>> +{
>> +	my ($file, $addr) = @_;
>> +	my ($man_id, $conf, $status);
>> +
>> +	$man_id = i2c_smbus_read_byte_data($file, 0xfe, NO_CACHE);
>> +	return unless $man_id == 0x4d;	# Maxim
>> +	return if i2c_smbus_read_byte_data($file, 0x04, NO_CACHE) != $man_id;
>> +	return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $man_id;
>> +	return if i2c_smbus_read_byte_data($file, 0xff, NO_CACHE) != $man_id;
>> +	$status = i2c_smbus_read_byte_data($file, 0x02, NO_CACHE);
> 
> At this point you should check the unused status bits immediately (so
> that you can exit if they don't meet the expectations.) Then you should
> read non-registers 0x04, 0x06 and 0xff again. This is the only reliable
> way to make sure that there are no registers at these addresses. It is
> perfectly possible (though unlikely) that a given chip does have values
> 0x4d for all of registers 0x04, 0x06, 0xfe and 0xff.
> 
> See max6657_detect() for an example.
> 
>> +	$conf = i2c_smbus_read_byte_data($file, 0x03, NO_CACHE);
> 
> NO_CACHE is not needed here, as this register 0x03 does exist. Only use
> NO_CACHE when you really need it, it's expensive!
> 
>> +
>> +	# Bit 5, 3, 1 and 0 should be zero
>> +	return unless ($status & 0x2b) == 0x00;
>> +	# The 4 lower bits should be zero
>> +	return unless ($conf & 0x0f) == 0x00;
>> +
>> +	return 6;
>> +}
>> +
>>  sub max6655_detect
>>  {
>>  	my ($file, $addr) = @_;
> 
> 


[-- Attachment #2: 0001-hwmon-sensors_detect-Add-detection-of-MAX6642.patch --]
[-- Type: text/plain, Size: 1995 bytes --]

This patch adds detection of MAX6642 to sensors-detect.

Signed-off-by: Per Dalen <per.dalen@appeartv.com>
---
Index: prog/detect/sensors-detect
===================================================================
--- prog/detect/sensors-detect	(revision 5977)
+++ prog/detect/sensors-detect	(working copy)
@@ -848,6 +848,11 @@
 		i2c_addrs => [0x2c, 0x2e, 0x2f],
 		i2c_detect => sub { max6639_detect(@_); },
 	}, {
+		name => "Maxim MAX6642",
+		driver => "max6642",
+		i2c_addrs => [0x48..0x4f],
+		i2c_detect => sub { max6642_detect(@_); },
+	}, {
 		name => "Maxim MAX6655/MAX6656",
 		driver => "max6655",
 		i2c_addrs => [0x18..0x1a, 0x29..0x2b, 0x4c..0x4e],
@@ -5789,6 +5794,40 @@
 	return 6;
 }
 
+# Chip to detect: MAX6642
+# Registers used:
+#   0x02: Status register
+#   0x03: Configuration register
+#   0xfe: Manufacturer ID
+#   0x04, 0x06, 0xff: No registers
+# We use the 0x04,0x06 and 0xff addresses (unused) to improve the reliability.
+# These are not real registers and will always return the last returned value.
+# This isn't documented.
+sub max6642_detect
+{
+	my ($file, $addr) = @_;
+	my ($man_id, $conf, $status);
+
+	$man_id = i2c_smbus_read_byte_data($file, 0xfe);
+	return unless $man_id == 0x4d;	# Maxim
+	return if i2c_smbus_read_byte_data($file, 0x04, NO_CACHE) != $man_id;
+	return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $man_id;
+	return if i2c_smbus_read_byte_data($file, 0xff, NO_CACHE) != $man_id;
+
+	$status = i2c_smbus_read_byte_data($file, 0x02);
+	# Bit 5, 3, 1 and 0 should be zero
+	return unless ($status & 0x2b) == 0x00;
+	return if i2c_smbus_read_byte_data($file, 0x04, NO_CACHE) != $status;
+	return if i2c_smbus_read_byte_data($file, 0x06, NO_CACHE) != $status;
+	return if i2c_smbus_read_byte_data($file, 0xff, NO_CACHE) != $status;
+
+	$conf = i2c_smbus_read_byte_data($file, 0x03);
+	# The 4 lower bits should be zero
+	return unless ($conf & 0x0f) == 0x00;
+
+	return 6;
+}
+
 sub max6655_detect
 {
 	my ($file, $addr) = @_;

[-- Attachment #3: Type: text/plain, Size: 153 bytes --]

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

  parent reply	other threads:[~2011-06-01  8:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-26  9:27 [lm-sensors] [PATCH v2] sensors-detect: Add detection of MAX6642 Per Dalén
2011-05-26 13:55 ` Guenter Roeck
2011-05-26 14:06 ` Jean Delvare
2011-05-26 19:33 ` Jean Delvare
2011-05-27  8:08 ` Per Dalén
2011-06-01  8:02 ` Per Dalén [this message]
2011-06-01 10:13 ` Jean Delvare
2011-06-01 16:21 ` Guenter Roeck
2014-01-26 19:02 ` [lm-sensors] [PATCH v2] sensors-detect: Add detection of TI ADC128D818 Guenter Roeck
2014-01-26 20:15 ` Jean Delvare
2014-06-26 13:28 ` [lm-sensors] [PATCH v2] sensors-detect: Add detection of NCT7802Y Guenter Roeck
2014-06-26 13:55 ` Jean Delvare
2014-06-26 15:11 ` 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=4DE5F211.2090003@appeartv.com \
    --to=per.dalen@appeartv.com \
    --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.