Skip to contentSkip to conversation

hwmon: (ds1621) Add ds1721 chip support

PATCH Applied Robert Coulson 3 participants 9 messages May 9, 2013 – Jun 28, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hwmon: (ds1621) Add ds1721 chip support

Update the ds1621 documentation, driver, & Kconfig with ds1721 chip support.

---
 Documentation/hwmon/ds1621 |   26 +++++++---
 drivers/hwmon/Kconfig      |    9 ++--
 drivers/hwmon/ds1621.c     |  120 ++++++++++++++++++++++++++++++++++++++------
 3 files changed, 132 insertions(+), 23 deletions(-)
Documentation/hwmon/ds1621 +20 -6
index 5e97f33..ee7bc01 100644
@@ -2,16 +2,22 @@ Kernel driver ds1621
 ==========
 
 Supported chips:
-  * Dallas Semiconductor DS1621
+  * Dallas Semiconductor & Maxim Integrated DS1621
     Prefix: 'ds1621'
     Addresses scanned: I2C 0x48 - 0x4f
-    Datasheet: Publicly available at the Dallas Semiconductor website
-               http://www.dalsemi.com/
+    Datasheet: Publicly available from www.maximintegrated.com
+
   * Dallas Semiconductor DS1625
-    Prefix: 'ds1621'
+    Prefix:
+     'ds1621' - if binding via _detect function
+     'ds1625' - explicit instantiation
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available from www.datasheetarchive.com
+
+  * Maxim Integrated DS1721
+    Prefix: 'ds1721'
     Addresses scanned: I2C 0x48 - 0x4f
-    Datasheet: Publicly available at the Dallas Semiconductor website
-               http://www.dalsemi.com/
+    Datasheet: Publicly available from www.maximintegrated.com
 
 Authors:
         Christian W. Zuckschwerdt <[email protected]>
@@ -61,3 +67,11 @@ with neither of the alarms set.
 
 Temperature conversion of the DS1621 takes up to 1000ms; internal access to
 non-volatile registers may last for 10ms or below.
+
+The DS1625 is pin compatible and functionally equivalent with the DS1621,
+but the DS1621 is meant to replace it.
+
+The DS1721 is pin compatible with the DS1621, has an accuracy of +/- 1.0
+degree Celius over a -10 to +85 degree range, a minimum/maximum alarm
+default setting of 75 and 80 degrees respectifully, and a maximum conversion
+time of 750ms.
drivers/hwmon/Kconfig +6 -3
index 89ac1cb..92e784e 100644
@@ -315,11 +315,14 @@ config SENSORS_DS620
 	  will be called ds620.
 
 config SENSORS_DS1621
-	tristate "Dallas Semiconductor DS1621 and DS1625"
+	tristate "Dallas Semiconductor DS1621 and compatibles"
 	depends on I2C
 	help
-	  If you say yes here you get support for Dallas Semiconductor
-	  DS1621 and DS1625 sensor chips.
+	  If you say yes here you get support for Dallas Semiconductor/Maxim
+	  Integrated DS1621 sensor chips and compatible models including:
+
+	  - Dallas Semiconductor DS1625
+	  - Maxim Integrated DS1721
 
 	  This driver can also be built as a module.  If so, the module
 	  will be called ds1621.
drivers/hwmon/ds1621.c +106 -14

203 lines not on this page · raw message

Signature · 7 lines
1.7.9.5


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Robert Coulson

SSdtIG9uY2UgYWdhaW4gbGF0ZSwgYnV0IEkgY291bGQgbm90IGZpbmQgdGhlIHRpbWUgdG8gdGVz dCB5b3VyIGRzMTYyMQpwYXRjaGVzIGJlZm9yZSB0b2RheS4KCk9uIFdlZCwgOCBNYXkgMjAxMyAy Mjo0NTo1MyAtMDcwMCwgUm9iZXJ0IENvdWxzb24gd3JvdGU6Cj4gLS0tIGEvZHJpdmVycy9od21v bi9kczE2MjEuYwo+ICsrKyBiL2RyaXZlcnMvaHdtb24vZHMxNjIxLmMKPiAoLi4uKQo+ICsvKgo+ ICsgKiBURU1QOiAwLjAwMUMvYml0ICgtNTVDIHRvICsxMjVDKQo+ICsgKiBSRUc6Cj4gKyAqICAt IDE2MjEsIDE2MjU6IHggPSAwLjVDCj4gKyAqICAtIDE3MjE6ICAgICAgIHggPSAwLjA2MjVDCj4g KyAqIEFzc3VtZSBoaWdoZXN0IHJlc29sdXRpb24gYW5kIGxldCB0aGUgYml0cyBmYWxsIHdoZXJl IHRoZXkgbWF5Li4KPiArICovCj4gK3N0YXRpYyBpbmxpbmUgdTE2IERTMTYyMV9URU1QX1RPX1JF Ryhsb25nIHRlbXApCj4gK3sKPiArCWludCBudGVtcCA9IGNsYW1wX3ZhbCh0ZW1wLCBEUzE2MjFf VEVNUF9NSU4sIERTMTYyMV9URU1QX01BWCk7Cj4gKwludGVtcCArPSAobnRlbXAgPCAwID8gLTMx IDogMzEpOwo+ICsJbnRlbXAgPSBESVZfUk9VTkRfQ0xPU0VTVChudGVtcCAqIDEwLCA2MjUpIDw8 IDQ7Cj4gKwlyZXR1cm4gKHUxNiludGVtcDsKPiArfQoKVGhpcyBicmVha3MgbGltaXQgcm91bmRp bmcgb24gdGhlIERTMTYyMS4gTGltaXRzIGhhdmUgYSByZXNvbHV0aW9uIG9mCjAuNcKwQyBvbiB0 aGF0IGNoaXAsIHNvIGxpbWl0IHZhbHVlcyBzaG91bGQgcm91bmRlZCB0byB0aGUgY2xvc2VzdApo YWxmLWRlZ3JlZS4gSXQgdXNlZCB0byB3b3JrIGJ1dCBubyBsb25nZXI6IGlmIEkgd3JpdGUgMjAz MDAgdG8KdGVtcDFfbWluLCBpdCBpcyByb3VuZGVkIGRvd24gdG8gMjAwMDAsIHdoaWxlIGl0IHNo b3VsZCBiZSByb3VuZGVkIHVwCnRvIDIwNTAwLgoKLS0gCkplYW4gRGVsdmFyZQoKX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29ycyBtYWlsaW5n IGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0tc2Vuc29ycy5v cmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

maintainer
#3 lore raw
In reply to Robert Coulson
Quoted 19 lines · Jean Delvare

I'm once again late, but I could not find the time to test your ds1621 patches before today.

Quoted 15 lines · Robert Coulson
drivers/hwmon/ds1621.c +12 -0
(...)
+/*
+ * TEMP: 0.001C/bit (-55C to +125C)
+ * REG:
+ *  - 1621, 1625: x = 0.5C
+ *  - 1721:       x = 0.0625C
+ * Assume highest resolution and let the bits fall where they may..
+ */
+static inline u16 DS1621_TEMP_TO_REG(long temp)
+{
+	int ntemp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
+	ntemp += (ntemp < 0 ? -31 : 31);
+	ntemp = DIV_ROUND_CLOSEST(ntemp * 10, 625) << 4;
Quoted 9 lines

drivers/hwmon/ds1621.c struct ds1621_data { · line 152

Quoted 2 lines
drivers/hwmon/ds1621.c +2 -0
+	return (u16)ntemp;
+}

This breaks limit rounding on the DS1621. Limits have a resolution of 0.5°C on that chip, so limit values should rounded to the closest half-degree. It used to work but no longer: if I write 20300 to temp1_min, it is rounded down to 20000, while it should be rounded up to 20500.

My fault, since I proposed that approach. Didn't I have the same problem with some other driver ? Makes it even worse. I'll have to look up my notes.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw
In reply to Robert Coulson

T24gVGh1LCAyNyBKdW4gMjAxMyAwNzozMToyNSAtMDcwMCwgR3VlbnRlciBSb2VjayB3cm90ZToK PiBPbiBUaHUsIEp1biAyNywgMjAxMyBhdCAxMDozNjozMUFNICswMjAwLCBKZWFuIERlbHZhcmUg d3JvdGU6Cj4gPiBJJ20gb25jZSBhZ2FpbiBsYXRlLCBidXQgSSBjb3VsZCBub3QgZmluZCB0aGUg dGltZSB0byB0ZXN0IHlvdXIgZHMxNjIxCj4gPiBwYXRjaGVzIGJlZm9yZSB0b2RheS4KPiA+IAo+ ID4gT24gV2VkLCA4IE1heSAyMDEzIDIyOjQ1OjUzIC0wNzAwLCBSb2JlcnQgQ291bHNvbiB3cm90 ZToKPiA+ID4gLS0tIGEvZHJpdmVycy9od21vbi9kczE2MjEuYwo+ID4gPiArKysgYi9kcml2ZXJz L2h3bW9uL2RzMTYyMS5jCj4gPiA+ICguLi4pCj4gPiA+ICsvKgo+ID4gPiArICogVEVNUDogMC4w MDFDL2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kIHRoYXQgYXBwcm9hY2guIERpZG4ndCBJIGhhdmUgdGhlIHNhbWUgcHJvYmxlbQo+IHdp dGggc29tZSBvdGhlciBkcml2ZXIgPyBNYWtlcyBpdCBldmVuIHdvcnNlLiBJJ2xsIGhhdmUgdG8g bG9vayB1cCBteSBub3Rlcy4KClllcyBJIGFtIGFsbW9zdCBjZXJ0YWluIHdlIGRpc2N1c3NlZCB0 aGlzIHZlcnkgdG9waWMgZm9yIGFub3RoZXIgZHJpdmVyCnJlY2VudGx5LCBJIHRoaW5rIGl0IHdh cyB0bXA0MDEuCgotLSAKSmVhbiBEZWx2YXJlCgpfX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fXwpsbS1zZW5zb3JzIG1haWxpbmcgbGlzdApsbS1zZW5zb3JzQGxt LXNlbnNvcnMub3JnCmh0dHA6Ly9saXN0cy5sbS1zZW5zb3JzLm9yZy9tYWlsbWFuL2xpc3RpbmZv L2xtLXNlbnNvcnM

maintainer
#5 lore raw
In reply to Robert Coulson
Quoted 30 lines · Jean Delvare
Quoted 29 lines · Guenter Roeck
Quoted 28 lines · Jean Delvare

I'm once again late, but I could not find the time to test your ds1621 patches before today.

Quoted 7 lines · Robert Coulson
drivers/hwmon/ds1621.c +4 -0
(...)
+/*
+ * TEMP: 0.001C/bit (-55C to +125C)
+ * REG:
+ *  - 1621, 1625: x = 0.5C

drivers/hwmon/ds1621.c

Quoted 10 lines
drivers/hwmon/ds1621.c +10 -0
+ *  - 1721:       x = 0.0625C
+ * Assume highest resolution and let the bits fall where they may..
+ */
+static inline u16 DS1621_TEMP_TO_REG(long temp)
+{
+	int ntemp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
+	ntemp += (ntemp < 0 ? -31 : 31);
+	ntemp = DIV_ROUND_CLOSEST(ntemp * 10, 625) << 4;
+	return (u16)ntemp;
+}

This breaks limit rounding on the DS1621. Limits have a resolution of 0.5°C on that chip, so limit values should rounded to the closest half-degree. It used to work but no longer: if I write 20300 to temp1_min, it is rounded down to 20000, while it should be rounded up to 20500.

Quoted 6 lines
Quoted 2 lines

My fault, since I proposed that approach. Didn't I have the same problem with some other driver ? Makes it even worse. I'll have to look up my notes.

Yes I am almost certain we discussed this very topic for another driver recently, I think it was tmp401.

You are right.

Can you test the following patch ? It follows the logic implemented in the tmp401 driver.

Thanks,
Guenter

---
From 007a7f590ae0e34368314f2acd9574aa2e701505 Mon Sep 17 00:00:00 2001
From: Guenter Roeck <[email protected]>
Date: Thu, 27 Jun 2013 10:07:19 -0700
Subject: [PATCH] hwmon: (ds1621) Fix temperature rounding operations

Commit "hwmon: (ds1621) Add ds1721 chip support" broke rounding for chips or configurations with less than 12 bit resolution.

---
 drivers/hwmon/ds1621.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/hwmon/ds1621.c +12 -9
index 317f683..9192225 100644
@@ -128,6 +128,8 @@ struct ds1621_data {
 
 	u16 temp[3];			/* Register values, word */
 	u8 conf;			/* Register encoding, combined */
+	u8 zbits;			/* Resolution encoded as number of
+					 * zero bits */
 	u16 update_interval;		/* Conversion rate in milliseconds */
 };
 
@@ -139,16 +141,14 @@ static inline int DS1621_TEMP_FROM_REG(u16 reg)
 /*
  * TEMP: 0.001C/bit (-55C to +125C)
  * REG:
- *  - 1621, 1625: 0.5C/bit
- *  - 1631, 1721, 1731: 0.0625C/bit
- * Assume highest resolution and let the bits fall where they may..
+ *  - 1621, 1625: 0.5C/bit, 7 zero-bits
+ *  - 1631, 1721, 1731: 0.0625C/bit, 4 zero-bits
  */
-static inline u16 DS1621_TEMP_TO_REG(long temp)
+static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits)
 {
-	int ntemp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
-	ntemp += (ntemp < 0 ? -31 : 31);
-	ntemp = DIV_ROUND_CLOSEST(ntemp * 10, 625) << 4;
-	return (u16)ntemp;
+	temp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
+	temp = DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits;
+	return temp;
 }
 
 static void ds1621_init_client(struct i2c_client *client)
@@ -172,6 +172,7 @@ static void ds1621_init_client(struct i2c_client *client)
 	switch (data->kind) {
 	case ds1625:
 		data->update_interval = DS1625_CONVERSION_MAX;
+		data->zbits = 7;
 		sreg = DS1621_COM_START;
 		break;
 	case ds1631:
@@ -180,10 +181,12 @@ static void ds1621_init_client(struct i2c_client *client)
 		resol = (new_conf & DS1621_REG_CONFIG_RESOL) >>
 			 DS1621_REG_CONFIG_RESOL_SHIFT;
 		data->update_interval = ds1721_convrates[resol];
+		data->zbits = 7 - resol;
 		sreg = DS1721_COM_START;
 		break;
 	default:
 		data->update_interval = DS1621_CONVERSION_MAX;
+		data->zbits = 7;
 		sreg = DS1621_COM_START;
 		break;
 	}
@@ -254,7 +257,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
 		return err;
 
 	mutex_lock(&data->update_lock);
-	data->temp[attr->index] = DS1621_TEMP_TO_REG(val);
+	data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits);
 	i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
 				     data->temp[attr->index]);
 	mutex_unlock(&data->update_lock);
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#6 lore raw
In reply to Robert Coulson

T24gVGh1LCAyNyBKdW4gMjAxMyAxMDoxMjo1MSAtMDcwMCwgR3VlbnRlciBSb2VjayB3cm90ZToK PiBPbiBUaHUsIEp1biAyNywgMjAxMyBhdCAxMDozNjozMUFNICswMjAwLCBKZWFuIERlbHZhcmUg d3JvdGU6Cj4gPiBUaGlzIGJyZWFrcyBsaW1pdCByb3VuZGluZyBvbiB0aGUgRFMxNjIxLiBMaW1p dHMgaGF2ZSBhIHJlc29sdXRpb24gb2YKPiA+IDAuNcKwQyBvbiB0aGF0IGNoaXAsIHNvIGxpbWl0 IHZhbHVlcyBzaG91bGQgcm91bmRlZCB0byB0aGUgY2xvc2VzdAo+ID4gaGFsZi1kZWdyZWUuIEl0 IHVzZWQgdG8gd29yayBidXQgbm8gbG9uZ2VyOiBpZiBJIHdyaXRlIDIwMzAwIHRvCj4gPiB0ZW1w MV9taW4sIGl0IGlzIHJvdW5kZWQgZG93biB0byAyMDAwMCwgd2hpbGUgaXQgc2hvdWxkIGJlIHJv dW5kZWQgdXAKPiA+IHRvIDIwNTAwLgo+IAo+IENhbiB5b3UgdGVzdCB0aGUgZm9sbG93aW5nIHBh dGNoID8gSXQgZm9sbG93cyB0aGUgbG9naWMgaW1wbGVtZW50ZWQgaW4gdGhlCj4gdG1wNDAxIGRy aXZlci4KClRlc3RlZCBPSywgdGhhbmtzIDopCgpUZXN0ZWQtYnk6IEplYW4gRGVsdmFyZSA8a2hh bGlAbGludXgtZnIub3JnPgoKQW5kIGFzIHRoZSBjb2RlIGxvb2tzIHNhbmUgdG9vOgoKQWNrZWQt Ynk6IEplYW4gRGVsdmFyZSA8a2hhbGlAbGludXgtZnIub3JnPgoKLS0gCkplYW4gRGVsdmFyZQoK X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29y cyBtYWlsaW5nIGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0t c2Vuc29ycy5vcmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

maintainer
#7 lore raw
In reply to Robert Coulson
Quoted 11 lines · Jean Delvare
Quoted 9 lines · Guenter Roeck
Quoted 5 lines · Jean Delvare

This breaks limit rounding on the DS1621. Limits have a resolution of 0.5°C on that chip, so limit values should rounded to the closest half-degree. It used to work but no longer: if I write 20300 to temp1_min, it is rounded down to 20000, while it should be rounded up to 20500.

Can you test the following patch ? It follows the logic implemented in the tmp401 driver.

Quoted 8 lines

Tested OK, thanks :)

And as the code looks sane too:

Thanks, to keep simple I'll add it on top of my -next tree instead of merging it.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#8 lore raw
In reply to Robert Coulson

Again, thank you both. (-:

Quoted 17 lines · Guenter Roeck
Quoted 9 lines · Jean Delvare
Quoted 8 lines · Guenter Roeck
Quoted 5 lines · Jean Delvare

This breaks limit rounding on the DS1621. Limits have a resolution of 0.5°C on that chip, so limit values should rounded to the closest half-degree. It used to work but no longer: if I write 20300 to temp1_min, it is rounded down to 20000, while it should be rounded up to 20500.

Can you test the following patch ? It follows the logic implemented in

the

Quoted 6 lines
Quoted 1 line

tmp401 driver.

Tested OK, thanks :)

Quoted 9 lines
Quoted 4 lines

And as the code looks sane too:

Thanks, to keep simple I'll add it on top of my -next tree instead of merging it.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors