All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
@ 2013-05-09  5:45 Robert Coulson
  2013-05-13  1:27 ` Guenter Roeck
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Robert Coulson @ 2013-05-09  5:45 UTC (permalink / raw)
  To: lm-sensors

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

Signed-off-by: Robert Coulson <rob.coulson@gmail.com>
---
 Documentation/hwmon/ds1621 |   26 +++++++---
 drivers/hwmon/Kconfig      |    9 ++--
 drivers/hwmon/ds1621.c     |  120 ++++++++++++++++++++++++++++++++++++++------
 3 files changed, 132 insertions(+), 23 deletions(-)

diff --git a/Documentation/hwmon/ds1621 b/Documentation/hwmon/ds1621
index 5e97f33..ee7bc01 100644
--- a/Documentation/hwmon/ds1621
+++ b/Documentation/hwmon/ds1621
@@ -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 <zany@triq.net>
@@ -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.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 89ac1cb..92e784e 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -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.
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 1c56873..04a3b12 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -6,6 +6,19 @@
  * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
  * the help of Jean Delvare <khali@linux-fr.org>
  *
+ * The DS1621 device is a digital temperature/thermometer with 9-bit
+ * resolution, a thermal alarm output (Tout), and user-defined minimum
+ * and maximum temperature thresholds (TH & TL).
+ *
+ * The DS1625 & DS1721 are pin compatible with the DS1621 and similar
+ * in operation, with slight variations as noted in the device
+ * datasheets (please refer to www.maximintegrated.com for specific
+ * device information).
+ *
+ * Since the DS1621 was the first chipset supported by this driver,
+ * most comments will refer to this chipset, but are actually general
+ * and concern all supported chipsets, unless mentioned otherwise.
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -31,27 +44,62 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
-#include "lm75.h"
+#include <linux/kernel.h>
 
 /* Addresses to scan */
 static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
 					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
 
+/* Supported devices */
+enum chips { ds1621, ds1625, ds1721 };
+
 /* Insmod parameters */
 static int polarity = -1;
 module_param(polarity, int, 0);
 MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
 
-/* Many DS1621 constants specified below */
-/* Config register used for detection         */
-/*  7    6    5    4    3    2    1    0      */
-/* |Done|THF |TLF |NVB | X  | X  |POL |1SHOT| */
+/*
+ * The Configuration/Status register
+ *
+ * - DS1621:
+ *   7    6    5    4    3    2    1    0
+ * |Done|THF |TLF |NVB | X  | X  |POL |1SHOT|
+ *
+ * - DS1625:
+ *   7    6    5    4    3    2    1    0
+ * |Done|THF |TLF |NVB | 1  | 0  |POL |1SHOT|
+ *
+ * - DS1721:
+ *   7    6    5    4    3    2    1    0
+ * |Done| X  | X  | U  | R1 | R0 |POL |1SHOT|
+ *
+ * Where:
+ * - 'X' is Reserved
+ * - 'U' is Undefined
+ */
 #define DS1621_REG_CONFIG_NVB		0x10
+#define DS1621_REG_CONFIG_RESOL		0x0C
 #define DS1621_REG_CONFIG_POLARITY	0x02
 #define DS1621_REG_CONFIG_1SHOT		0x01
 #define DS1621_REG_CONFIG_DONE		0x80
 
-/* The DS1621 registers */
+#define DS1621_REG_CONFIG_RESOL_SHIFT	2
+
+/* ds1721 conversion rates: {C/LSB, time(ms), resolution bit setting} */
+static const unsigned short ds1721_convrates[] = {
+	94,	/*  9-bits (0.5,  93.75, RES[0..1] = 0 */
+	188,	/* 10-bits (0.25, 187.5, RES[0..1] = 1 */
+	375,	/* 11-bits (0.125,  375, RES[0..1] = 2 */
+	750,	/* 12-bits (0.0625, 750, RES[0..1] = 3 */
+};
+
+#define DS1621_CONVERSION_MAX	750
+#define DS1625_CONVERSION_MAX	500
+
+#define DS1621_TEMP_MAX	125000
+#define DS1621_TEMP_MIN	(-55000)
+
+/* The DS1621 temperature registers */
 static const u8 DS1621_REG_TEMP[3] = {
 	0xAA,		/* input, word, RO */
 	0xA2,		/* min, word, RW */
@@ -59,6 +107,7 @@ static const u8 DS1621_REG_TEMP[3] = {
 };
 #define DS1621_REG_CONF			0xAC /* byte, RW */
 #define DS1621_COM_START		0xEE /* no data */
+#define DS1721_COM_START		0x51 /* no data */
 #define DS1621_COM_STOP			0x22 /* no data */
 
 /* The DS1621 configuration register */
@@ -75,14 +124,37 @@ struct ds1621_data {
 	struct mutex update_lock;
 	char valid;			/* !=0 if following fields are valid */
 	unsigned long last_updated;	/* In jiffies */
+	enum chips kind;		/* device type */
 
 	u16 temp[3];			/* Register values, word */
 	u8 conf;			/* Register encoding, combined */
+	u16 update_interval;		/* Conversion rate in milliseconds */
 };
 
+static inline int DS1621_TEMP_FROM_REG(u16 reg)
+{
+	return DIV_ROUND_CLOSEST(((s16)reg / 16) * 625, 10);
+}
+
+/*
+ * 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;
+	return (u16)ntemp;
+}
+
 static void ds1621_init_client(struct i2c_client *client)
 {
-	u8 conf, new_conf;
+	u8 conf, new_conf, sreg, resol;
+	struct ds1621_data *data = i2c_get_clientdata(client);
 
 	new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
 	/* switch to continuous conversion mode */
@@ -97,8 +169,25 @@ static void ds1621_init_client(struct i2c_client *client)
 	if (conf != new_conf)
 		i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf);
 
+	switch (data->kind) {
+	case ds1625:
+		data->update_interval = DS1625_CONVERSION_MAX;
+		sreg = DS1621_COM_START;
+		break;
+	case ds1721:
+		resol = (new_conf & DS1621_REG_CONFIG_RESOL) >>
+			 DS1621_REG_CONFIG_RESOL_SHIFT;
+		data->update_interval = ds1721_convrates[resol];
+		sreg = DS1721_COM_START;
+		break;
+	default:
+		data->update_interval = DS1621_CONVERSION_MAX;
+		sreg = DS1621_COM_START;
+		break;
+	}
+
 	/* start conversion */
-	i2c_smbus_write_byte(client, DS1621_COM_START);
+	i2c_smbus_write_byte(client, sreg);
 }
 
 static struct ds1621_data *ds1621_update_client(struct device *dev)
@@ -109,8 +198,8 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
 
 	mutex_lock(&data->update_lock);
 
-	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
-	    || !data->valid) {
+	if (time_after(jiffies, data->last_updated + data->update_interval) ||
+	    !data->valid) {
 		int i;
 
 		dev_dbg(&client->dev, "Starting ds1621 update\n");
@@ -146,7 +235,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
 	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
 	struct ds1621_data *data = ds1621_update_client(dev);
 	return sprintf(buf, "%d\n",
-		       LM75_TEMP_FROM_REG(data->temp[attr->index]));
+		       DS1621_TEMP_FROM_REG(data->temp[attr->index]));
 }
 
 static ssize_t set_temp(struct device *dev, struct device_attribute *da,
@@ -163,7 +252,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
 		return err;
 
 	mutex_lock(&data->update_lock);
-	data->temp[attr->index] = LM75_TEMP_TO_REG(val);
+	data->temp[attr->index] = DS1621_TEMP_TO_REG(val);
 	i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
 				     data->temp[attr->index]);
 	mutex_unlock(&data->update_lock);
@@ -257,6 +346,8 @@ static int ds1621_probe(struct i2c_client *client,
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->update_lock);
 
+	data->kind = id->driver_data;
+
 	/* Initialize the DS1621 chip */
 	ds1621_init_client(client);
 
@@ -289,8 +380,9 @@ static int ds1621_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id ds1621_id[] = {
-	{ "ds1621", 0 },
-	{ "ds1625", 0 },
+	{ "ds1621", ds1621 },
+	{ "ds1625", ds1625 },
+	{ "ds1721", ds1721 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, ds1621_id);
-- 
1.7.9.5


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
@ 2013-05-13  1:27 ` Guenter Roeck
  2013-06-27  8:36 ` Jean Delvare
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2013-05-13  1:27 UTC (permalink / raw)
  To: lm-sensors

On Wed, May 08, 2013 at 10:45:53PM -0700, Robert Coulson wrote:
> Update the ds1621 documentation, driver, & Kconfig with ds1721 chip support.
> 
> Signed-off-by: Robert Coulson <rob.coulson@gmail.com>

Applied to hwmon-next.

Thanks,
Guenter

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
  2013-05-13  1:27 ` Guenter Roeck
@ 2013-06-27  8:36 ` Jean Delvare
  2013-06-27 14:31 ` Guenter Roeck
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2013-06-27  8:36 UTC (permalink / raw)
  To: lm-sensors

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
  2013-05-13  1:27 ` Guenter Roeck
  2013-06-27  8:36 ` Jean Delvare
@ 2013-06-27 14:31 ` Guenter Roeck
  2013-06-27 14:50 ` Jean Delvare
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2013-06-27 14:31 UTC (permalink / raw)
  To: lm-sensors

On Thu, Jun 27, 2013 at 10:36:31AM +0200, Jean Delvare wrote:
> I'm once again late, but I could not find the time to test your ds1621
> patches before today.
> 
> On Wed, 8 May 2013 22:45:53 -0700, Robert Coulson wrote:
> > --- a/drivers/hwmon/ds1621.c
> > +++ b/drivers/hwmon/ds1621.c
> > (...)
> > +/*
> > + * 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;
> > +	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
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
                   ` (2 preceding siblings ...)
  2013-06-27 14:31 ` Guenter Roeck
@ 2013-06-27 14:50 ` Jean Delvare
  2013-06-27 17:12 ` Guenter Roeck
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2013-06-27 14:50 UTC (permalink / raw)
  To: lm-sensors

T24gVGh1LCAyNyBKdW4gMjAxMyAwNzozMToyNSAtMDcwMCwgR3VlbnRlciBSb2VjayB3cm90ZToK
PiBPbiBUaHUsIEp1biAyNywgMjAxMyBhdCAxMDozNjozMUFNICswMjAwLCBKZWFuIERlbHZhcmUg
d3JvdGU6Cj4gPiBJJ20gb25jZSBhZ2FpbiBsYXRlLCBidXQgSSBjb3VsZCBub3QgZmluZCB0aGUg
dGltZSB0byB0ZXN0IHlvdXIgZHMxNjIxCj4gPiBwYXRjaGVzIGJlZm9yZSB0b2RheS4KPiA+IAo+
ID4gT24gV2VkLCA4IE1heSAyMDEzIDIyOjQ1OjUzIC0wNzAwLCBSb2JlcnQgQ291bHNvbiB3cm90
ZToKPiA+ID4gLS0tIGEvZHJpdmVycy9od21vbi9kczE2MjEuYwo+ID4gPiArKysgYi9kcml2ZXJz
L2h3bW9uL2RzMTYyMS5jCj4gPiA+ICguLi4pCj4gPiA+ICsvKgo+ID4gPiArICogVEVNUDogMC4w
MDFDL2JpdCAoLTU1QyB0byArMTI1QykKPiA+ID4gKyAqIFJFRzoKPiA+ID4gKyAqICAtIDE2MjEs
IDE2MjU6IHggPSAwLjVDCj4gPiA+ICsgKiAgLSAxNzIxOiAgICAgICB4ID0gMC4wNjI1Qwo+ID4g
PiArICogQXNzdW1lIGhpZ2hlc3QgcmVzb2x1dGlvbiBhbmQgbGV0IHRoZSBiaXRzIGZhbGwgd2hl
cmUgdGhleSBtYXkuLgo+ID4gPiArICovCj4gPiA+ICtzdGF0aWMgaW5saW5lIHUxNiBEUzE2MjFf
VEVNUF9UT19SRUcobG9uZyB0ZW1wKQo+ID4gPiArewo+ID4gPiArCWludCBudGVtcCA9IGNsYW1w
X3ZhbCh0ZW1wLCBEUzE2MjFfVEVNUF9NSU4sIERTMTYyMV9URU1QX01BWCk7Cj4gPiA+ICsJbnRl
bXAgKz0gKG50ZW1wIDwgMCA/IC0zMSA6IDMxKTsKPiA+ID4gKwludGVtcCA9IERJVl9ST1VORF9D
TE9TRVNUKG50ZW1wICogMTAsIDYyNSkgPDwgNDsKPiA+ID4gKwlyZXR1cm4gKHUxNiludGVtcDsK
PiA+ID4gK30KPiA+IAo+ID4gVGhpcyBicmVha3MgbGltaXQgcm91bmRpbmcgb24gdGhlIERTMTYy
MS4gTGltaXRzIGhhdmUgYSByZXNvbHV0aW9uIG9mCj4gPiAwLjXCsEMgb24gdGhhdCBjaGlwLCBz
byBsaW1pdCB2YWx1ZXMgc2hvdWxkIHJvdW5kZWQgdG8gdGhlIGNsb3Nlc3QKPiA+IGhhbGYtZGVn
cmVlLiBJdCB1c2VkIHRvIHdvcmsgYnV0IG5vIGxvbmdlcjogaWYgSSB3cml0ZSAyMDMwMCB0bwo+
ID4gdGVtcDFfbWluLCBpdCBpcyByb3VuZGVkIGRvd24gdG8gMjAwMDAsIHdoaWxlIGl0IHNob3Vs
ZCBiZSByb3VuZGVkIHVwCj4gPiB0byAyMDUwMC4KPiA+IAo+IE15IGZhdWx0LCBzaW5jZSBJIHBy
b3Bvc2VkIHRoYXQgYXBwcm9hY2guIERpZG4ndCBJIGhhdmUgdGhlIHNhbWUgcHJvYmxlbQo+IHdp
dGggc29tZSBvdGhlciBkcml2ZXIgPyBNYWtlcyBpdCBldmVuIHdvcnNlLiBJJ2xsIGhhdmUgdG8g
bG9vayB1cCBteSBub3Rlcy4KClllcyBJIGFtIGFsbW9zdCBjZXJ0YWluIHdlIGRpc2N1c3NlZCB0
aGlzIHZlcnkgdG9waWMgZm9yIGFub3RoZXIgZHJpdmVyCnJlY2VudGx5LCBJIHRoaW5rIGl0IHdh
cyB0bXA0MDEuCgotLSAKSmVhbiBEZWx2YXJlCgpfX19fX19fX19fX19fX19fX19fX19fX19fX19f
X19fX19fX19fX19fX19fX19fXwpsbS1zZW5zb3JzIG1haWxpbmcgbGlzdApsbS1zZW5zb3JzQGxt
LXNlbnNvcnMub3JnCmh0dHA6Ly9saXN0cy5sbS1zZW5zb3JzLm9yZy9tYWlsbWFuL2xpc3RpbmZv
L2xtLXNlbnNvcnM

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
                   ` (3 preceding siblings ...)
  2013-06-27 14:50 ` Jean Delvare
@ 2013-06-27 17:12 ` Guenter Roeck
  2013-06-28 12:05 ` Jean Delvare
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2013-06-27 17:12 UTC (permalink / raw)
  To: lm-sensors

On Thu, Jun 27, 2013 at 04:50:05PM +0200, Jean Delvare wrote:
> On Thu, 27 Jun 2013 07:31:25 -0700, Guenter Roeck wrote:
> > On Thu, Jun 27, 2013 at 10:36:31AM +0200, Jean Delvare wrote:
> > > I'm once again late, but I could not find the time to test your ds1621
> > > patches before today.
> > > 
> > > On Wed, 8 May 2013 22:45:53 -0700, Robert Coulson wrote:
> > > > --- a/drivers/hwmon/ds1621.c
> > > > +++ b/drivers/hwmon/ds1621.c
> > > > (...)
> > > > +/*
> > > > + * 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;
> > > > +	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.
> 
> 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 <linux@roeck-us.net>
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.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/ds1621.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 317f683..9192225 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -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);
-- 
1.7.9.7


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
                   ` (4 preceding siblings ...)
  2013-06-27 17:12 ` Guenter Roeck
@ 2013-06-28 12:05 ` Jean Delvare
  2013-06-28 13:41 ` Guenter Roeck
  2013-06-28 13:45 ` Robert Coulson
  7 siblings, 0 replies; 9+ messages in thread
From: Jean Delvare @ 2013-06-28 12:05 UTC (permalink / raw)
  To: lm-sensors

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
                   ` (5 preceding siblings ...)
  2013-06-28 12:05 ` Jean Delvare
@ 2013-06-28 13:41 ` Guenter Roeck
  2013-06-28 13:45 ` Robert Coulson
  7 siblings, 0 replies; 9+ messages in thread
From: Guenter Roeck @ 2013-06-28 13:41 UTC (permalink / raw)
  To: lm-sensors

On Fri, Jun 28, 2013 at 02:05:26PM +0200, Jean Delvare wrote:
> On Thu, 27 Jun 2013 10:12:51 -0700, Guenter Roeck wrote:
> > On Thu, Jun 27, 2013 at 10:36:31AM +0200, Jean Delvare wrote:
> > > 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.
> 
> Tested OK, thanks :)
> 
> Tested-by: Jean Delvare <khali@linux-fr.org>
> 
> And as the code looks sane too:
> 
> Acked-by: Jean Delvare <khali@linux-fr.org>
> 
Thanks, to keep simple I'll add it on top of my -next tree instead of merging it.

Guenter

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support
  2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
                   ` (6 preceding siblings ...)
  2013-06-28 13:41 ` Guenter Roeck
@ 2013-06-28 13:45 ` Robert Coulson
  7 siblings, 0 replies; 9+ messages in thread
From: Robert Coulson @ 2013-06-28 13:45 UTC (permalink / raw)
  To: lm-sensors


[-- Attachment #1.1: Type: text/plain, Size: 1037 bytes --]

Again, thank you both. (-:


On Fri, Jun 28, 2013 at 6:41 AM, Guenter Roeck <linux@roeck-us.net> wrote:

> On Fri, Jun 28, 2013 at 02:05:26PM +0200, Jean Delvare wrote:
> > On Thu, 27 Jun 2013 10:12:51 -0700, Guenter Roeck wrote:
> > > On Thu, Jun 27, 2013 at 10:36:31AM +0200, Jean Delvare wrote:
> > > > 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.
> >
> > Tested OK, thanks :)
> >
> > Tested-by: Jean Delvare <khali@linux-fr.org>
> >
> > And as the code looks sane too:
> >
> > Acked-by: Jean Delvare <khali@linux-fr.org>
> >
> Thanks, to keep simple I'll add it on top of my -next tree instead of
> merging it.
>
> Guenter
>

[-- Attachment #1.2: Type: text/html, Size: 1668 bytes --]

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

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-06-28 13:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-09  5:45 [lm-sensors] [lm-sensors 1/2] hwmon: (ds1621) Add ds1721 chip support Robert Coulson
2013-05-13  1:27 ` Guenter Roeck
2013-06-27  8:36 ` Jean Delvare
2013-06-27 14:31 ` Guenter Roeck
2013-06-27 14:50 ` Jean Delvare
2013-06-27 17:12 ` Guenter Roeck
2013-06-28 12:05 ` Jean Delvare
2013-06-28 13:41 ` Guenter Roeck
2013-06-28 13:45 ` Robert Coulson

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.