All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] Support for DS620
@ 2010-12-20 20:07 Roland Stigge
  2010-12-23 19:55 ` Guenter Roeck
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: Roland Stigge @ 2010-12-20 20:07 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

I'm attaching a patch with support for the temperature sensor DS620
(ds620.c). It is based on ds1621.c but the device is sufficiently
different to warrant a separate driver. E.g., configuration registers is
different and includes 16bit values instead of 8bit.

Thanks for considering.

bye,
  Roland

[-- Attachment #2: hwmon-ds620.patch --]
[-- Type: text/x-patch, Size: 11463 bytes --]

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..b68c0e2
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,343 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
+    
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
+
+/* Many DS620 constants specified below */
+/* Config register used for detection          */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1 		0x0800
+#define DS620_REG_CONFIG_R0 		0x0400
+#define DS620_REG_CONFIG_AUTOC          0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,		/* input, word, RO */
+	0xA2,		/* min, word, RW */
+	0xA0,		/* max, word, RW */
+};
+#define DS620_REG_CONF		0xAC /* word, RW */
+#define DS620_COM_START		0x51 /* no data */
+#define DS620_COM_STOP		0x22 /* no data */
+
+/* Conversions */
+#define ALARMS_FROM_REG(val) ((val) & \
+                              (DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;			/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];			/* Register values, word */
+	u16 conf;			/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	u16 conf, new_conf;
+
+	new_conf = conf = swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf)
+		i2c_smbus_write_word_data(client, DS620_REG_CONF, swab16(new_conf));
+	
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	u16 new_conf;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		data->conf = swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++)
+			data->temp[i] = ds620_read_temp(client,
+							 DS620_REG_TEMP[i]);
+
+		/* reset alarms if necessary */
+		new_conf = data->conf;
+		if (data->temp[0] > data->temp[1])	/* input > min */
+			new_conf &= ~DS620_REG_CONFIG_TLF;
+		if (data->temp[0] < data->temp[2])	/* input < max */
+			new_conf &= ~DS620_REG_CONFIG_THF;
+		if (data->conf != new_conf)
+			i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						  swab16(new_conf));
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+
+	mutex_unlock(&data->update_lock);
+
+	return data;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	u16 val = (simple_strtol(buf, NULL, 10) * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			  data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarms(struct device *dev, struct device_attribute *da,
+			   char *buf)
+{
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf));
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+		DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+		DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	&dev_attr_alarms.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int ds620_detect(struct i2c_client *client,
+			 struct i2c_board_info *info)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	int result, conf, temp;
+	int i;
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 
+				     | I2C_FUNC_SMBUS_WORD_DATA 
+				     | I2C_FUNC_SMBUS_WRITE_BYTE))
+		return -ENODEV;
+
+	/* Now, we do the remaining detection. */
+	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	conf = swab16(result);
+	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
+			((conf & DS620_REG_CONFIG_DONE) &&
+			 (conf & DS620_REG_CONFIG_AUTOC)) ||
+			!((conf & DS620_REG_CONFIG_DONE) &&
+			       	!(conf & DS620_REG_CONFIG_AUTOC)) )
+		return -ENODEV;
+	/* The 3 lowest bits of a temperature should always be 0. */
+	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
+		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
+		if (temp < 0 || (temp & 0x0700))
+			return -ENODEV;
+	}
+
+	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+static int ds620_probe(struct i2c_client *client,
+			const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	if ((err = sysfs_create_group(&client->dev.kobj, &ds620_group)))
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+      exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+      exit_free:
+	kfree(data);
+      exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{ "ds620", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class		= I2C_CLASS_HWMON,
+	.driver = {
+		.name	= "ds620",
+	},
+	.probe		= ds620_probe,
+	.remove		= ds620_remove,
+	.id_table	= ds620_id,
+	.detect		= ds620_detect,
+	.address_list	= normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
@ 2010-12-23 19:55 ` Guenter Roeck
  2010-12-25 13:24 ` Roland Stigge
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2010-12-23 19:55 UTC (permalink / raw)
  To: lm-sensors

On Mon, Dec 20, 2010 at 03:07:49PM -0500, Roland Stigge wrote:
> Hi,
> 
> I'm attaching a patch with support for the temperature sensor DS620
> (ds620.c). It is based on ds1621.c but the device is sufficiently
> different to warrant a separate driver. E.g., configuration registers is
> different and includes 16bit values instead of 8bit.
> 
> Thanks for considering.
> 
> bye,
>   Roland

Please run your patch through scripts/checkpatch.pl and ensure it reports
no errors or warnings. Also please provide Documentation/hwmon/ds620.

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] 22+ messages in thread

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
  2010-12-23 19:55 ` Guenter Roeck
@ 2010-12-25 13:24 ` Roland Stigge
  2010-12-25 18:34 ` Guenter Roeck
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2010-12-25 13:24 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 23/12/10 20:55, Guenter Roeck wrote:
> Please run your patch through scripts/checkpatch.pl and ensure it reports
> no errors or warnings. Also please provide Documentation/hwmon/ds620.

Thanks for the hint!

I revised the patch and included Documentation/hwmon/ds620. See attachment.

bye,
  Roland

[-- Attachment #2: hwmon-ds620.patch --]
[-- Type: text/x-patch, Size: 12520 bytes --]

Signed-off-by: Roland Stigge <stigge@antcom.de>
diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..ba4c6bc
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,24 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..2fbd193
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,357 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
+
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
+
+/* Many DS620 constants specified below */
+/* Config register used for detection          */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC          0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,		/* input, word, RO */
+	0xA2,		/* min, word, RW */
+	0xA0,		/* max, word, RW */
+};
+#define DS620_REG_CONF		0xAC /* word, RW */
+#define DS620_COM_START		0x51 /* no data */
+#define DS620_COM_STOP		0x22 /* no data */
+
+/* Conversions */
+#define ALARMS_FROM_REG(val) ((val) & \
+				(DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;			/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];			/* Register values, word */
+	u16 conf;			/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	u16 conf, new_conf;
+
+	new_conf = conf =
+		swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf) {
+		i2c_smbus_write_word_data(
+				client, DS620_REG_CONF, swab16(new_conf));
+	}
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	u16 new_conf;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		data->conf = swab16(i2c_smbus_read_word_data(client,
+							     DS620_REG_CONF));
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++)
+			data->temp[i] = ds620_read_temp(client,
+							 DS620_REG_TEMP[i]);
+
+		/* reset alarms if necessary */
+		new_conf = data->conf;
+		if (data->temp[0] > data->temp[1])	/* input > min */
+			new_conf &= ~DS620_REG_CONFIG_TLF;
+		if (data->temp[0] < data->temp[2])	/* input < max */
+			new_conf &= ~DS620_REG_CONFIG_THF;
+		if (data->conf != new_conf)
+			i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						  swab16(new_conf));
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+
+	mutex_unlock(&data->update_lock);
+
+	return data;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n",
+			((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (!res) {
+		val = (val * 10 / 625) * 8;
+
+		mutex_lock(&data->update_lock);
+		data->temp[attr->index] = val;
+		ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+				  data->temp[attr->index]);
+		mutex_unlock(&data->update_lock);
+	}
+	return count;
+}
+
+static ssize_t show_alarms(struct device *dev, struct device_attribute *da,
+			   char *buf)
+{
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf));
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+		DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+		DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	&dev_attr_alarms.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int ds620_detect(struct i2c_client *client,
+			 struct i2c_board_info *info)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	int result, conf, temp;
+	int i;
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
+				     | I2C_FUNC_SMBUS_WORD_DATA
+				     | I2C_FUNC_SMBUS_WRITE_BYTE))
+		return -ENODEV;
+
+	/* Now, we do the remaining detection. */
+	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	conf = swab16(result);
+	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
+			((conf & DS620_REG_CONFIG_DONE) &&
+			 (conf & DS620_REG_CONFIG_AUTOC)) ||
+			!((conf & DS620_REG_CONFIG_DONE) &&
+			!(conf & DS620_REG_CONFIG_AUTOC)))
+		return -ENODEV;
+	/* The 3 lowest bits of a temperature should always be 0. */
+	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
+		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
+		if (temp < 0 || (temp & 0x0700))
+			return -ENODEV;
+	}
+
+	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+static int ds620_probe(struct i2c_client *client,
+			const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{ "ds620", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class		= I2C_CLASS_HWMON,
+	.driver = {
+		.name	= "ds620",
+	},
+	.probe		= ds620_probe,
+	.remove		= ds620_remove,
+	.id_table	= ds620_id,
+	.detect		= ds620_detect,
+	.address_list	= normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
  2010-12-23 19:55 ` Guenter Roeck
  2010-12-25 13:24 ` Roland Stigge
@ 2010-12-25 18:34 ` Guenter Roeck
  2010-12-25 21:10 ` Roland Stigge
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2010-12-25 18:34 UTC (permalink / raw)
  To: lm-sensors

On Sat, Dec 25, 2010 at 08:24:55AM -0500, Roland Stigge wrote:
> Hi,
> 
> On 23/12/10 20:55, Guenter Roeck wrote:
> > Please run your patch through scripts/checkpatch.pl and ensure it reports
> > no errors or warnings. Also please provide Documentation/hwmon/ds620.
> 
> Thanks for the hint!
> 
> I revised the patch and included Documentation/hwmon/ds620. See attachment.
> 
> bye,
>   Roland

> Signed-off-by: Roland Stigge <stigge@antcom.de>

Did you apply your patch ? All the above will show up in the patch log,
which isn't really a good idea. Also, you still have a whitespace error 
(blank line at end of the Documentation/hwmon/ds620).

Formatting isn't always consistent, mostly where you replaced ds1620 with ds620.
Best might be to run ds620.c through scripts/Lindent and do a little post-cleanup
(Lindent tends to screw up static initializations for some reason).

Couple of other comments inline.

> diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
> new file mode 100644
> index 0000000..ba4c6bc
> --- /dev/null
> +++ b/Documentation/hwmon/ds620
> @@ -0,0 +1,24 @@
> +Kernel driver ds620
> +=========> +
> +Supported chips:
> +  * Dallas Semiconductor DS620
> +    Prefix: 'ds620'
> +    Addresses scanned: I2C 0x48 - 0x4f
> +    Datasheet: Publicly available at the Dallas Semiconductor website
> +               http://www.dalsemi.com/
> +
> +Authors:
> +        Roland Stigge <stigge@antcom.de>
> +        based on ds1621.c by
> +        Christian W. Zuckschwerdt <zany@triq.net>
> +
> +Description
> +-----------
> +
> +The DS620 is a (one instance) digital thermometer and thermostat. It has both
> +high and low temperature limits which can be user defined (i.e.  programmed
> +into non-volatile on-chip registers). Temperature range is -55 degree Celsius
> +to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
> +returned via sysfs displays post decimal positions.
> +
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index a56f6ad..700389a 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -274,6 +274,16 @@ config SENSORS_ATXP1
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called atxp1.
>  
> +config SENSORS_DS620
> +	tristate "Dallas Semiconductor DS620"
> +	depends on I2C
> +	help
> +	  If you say yes here you get support for Dallas Semiconductor
> +	  DS620 sensor chip.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called ds620.
> +
>  config SENSORS_DS1621
>  	tristate "Dallas Semiconductor DS1621 and DS1625"
>  	depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 2479b3d..42542d7 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
> +obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
>  obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
>  obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
> diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
> new file mode 100644
> index 0000000..2fbd193
> --- /dev/null
> +++ b/drivers/hwmon/ds620.c
> @@ -0,0 +1,357 @@
> +/*
> +    ds620.c - Support for temperature sensor and thermostat DS620
> +
> +    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
> +
> +    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
> +
> +    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
> +    (at your option) any later version.
> +
> +    This program is distributed in the hope that it will be useful,
> +    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +    GNU General Public License for more details.
> +
> +    You should have received a copy of the GNU General Public License
> +    along with this program; if not, write to the Free Software
> +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +*/
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/jiffies.h>
> +#include <linux/i2c.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/err.h>
> +#include <linux/mutex.h>
> +#include <linux/sysfs.h>
> +
> +/* Addresses to scan */
> +static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
> +					0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
> +
> +/* Many DS620 constants specified below */
> +/* Config register used for detection          */
> +/*  15   14   13   12   11   10   09    08     */
> +/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
> +
> +/*  07   06   05   04   03   02   01    00     */
> +/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
> +#define DS620_REG_CONFIG_DONE		0x8000
> +#define DS620_REG_CONFIG_NVB		0x4000
> +#define DS620_REG_CONFIG_THF		0x2000
> +#define DS620_REG_CONFIG_TLF		0x1000
> +#define DS620_REG_CONFIG_R1		0x0800
> +#define DS620_REG_CONFIG_R0		0x0400
> +#define DS620_REG_CONFIG_AUTOC          0x0200
> +#define DS620_REG_CONFIG_1SHOT		0x0100
> +#define DS620_REG_CONFIG_PO2		0x0080
> +#define DS620_REG_CONFIG_PO1		0x0040
> +#define DS620_REG_CONFIG_A2		0x0020
> +#define DS620_REG_CONFIG_A1		0x0010
> +#define DS620_REG_CONFIG_A0		0x0008
> +
> +/* The DS620 registers */
> +static const u8 DS620_REG_TEMP[3] = {
> +	0xAA,		/* input, word, RO */
> +	0xA2,		/* min, word, RW */
> +	0xA0,		/* max, word, RW */
> +};
> +#define DS620_REG_CONF		0xAC /* word, RW */
> +#define DS620_COM_START		0x51 /* no data */
> +#define DS620_COM_STOP		0x22 /* no data */
> +
> +/* Conversions */
> +#define ALARMS_FROM_REG(val) ((val) & \
> +				(DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
> +
> +/* Each client has this additional data */
> +struct ds620_data {
> +	struct device *hwmon_dev;
> +	struct mutex update_lock;
> +	char valid;			/* !=0 if following fields are valid */
> +	unsigned long last_updated;	/* In jiffies */
> +
> +	u16 temp[3];			/* Register values, word */
> +	u16 conf;			/* Register encoding, combined */
> +};
> +
> +/* Temperature registers are word-sized.
> +   DS620 uses a high-byte first convention, which is exactly opposite to
> +   the SMBus standard. */
> +static int ds620_read_temp(struct i2c_client *client, u8 reg)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_read_word_data(client, reg);
> +	if (ret < 0)
> +		return ret;
> +	return swab16(ret);
> +}
> +
> +static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
> +{
> +	return i2c_smbus_write_word_data(client, reg, swab16(value));
> +}
> +
> +static void ds620_init_client(struct i2c_client *client)
> +{
> +	u16 conf, new_conf;
> +
> +	new_conf = conf > +		swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
> +
> +	/* switch to continuous conversion mode */
> +	new_conf &= ~DS620_REG_CONFIG_1SHOT;
> +	/* with highest precision */
> +	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
> +
> +	if (conf != new_conf) {
> +		i2c_smbus_write_word_data(
> +				client, DS620_REG_CONF, swab16(new_conf));
> +	}
> +
> +	/* start conversion */
> +	i2c_smbus_write_byte(client, DS620_COM_START);
> +}
> +
> +static struct ds620_data *ds620_update_client(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +	u16 new_conf;
> +
> +	mutex_lock(&data->update_lock);
> +
> +	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
> +	    || !data->valid) {
> +		int i;
> +
> +		dev_dbg(&client->dev, "Starting ds620 update\n");
> +
> +		data->conf = swab16(i2c_smbus_read_word_data(client,
> +							     DS620_REG_CONF));
> +
> +		for (i = 0; i < ARRAY_SIZE(data->temp); i++)
> +			data->temp[i] = ds620_read_temp(client,
> +							 DS620_REG_TEMP[i]);
> +
I know this is code matches exactly the ds1621 code. Yet, it ignores errors
returned by ds620_read_temp() and i2c_smbus_read_word_data(), so it is not
really clean. Worth thinking about a fix. One possible solution might be
to keep conf and temp[i] as int and return its value as error if it is below 0.
Another solution would be to return the error from ds620_update_client()
using ERR_PTR() and handle the condition in the calling code; see
drivers/hwmon/ltc4261.c for an example.


> +		/* reset alarms if necessary */
> +		new_conf = data->conf;
> +		if (data->temp[0] > data->temp[1])	/* input > min */
> +			new_conf &= ~DS620_REG_CONFIG_TLF;
> +		if (data->temp[0] < data->temp[2])	/* input < max */
> +			new_conf &= ~DS620_REG_CONFIG_THF;
> +		if (data->conf != new_conf)
> +			i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +						  swab16(new_conf));

This code resets alarms even if those are not shown to the user.
The idea is for the alarms to be reset only after the matching alarm
has been shown. So the above code should be moved to the show_alarm().

> +
> +		data->last_updated = jiffies;
> +		data->valid = 1;
> +	}
> +
> +	mutex_unlock(&data->update_lock);
> +
> +	return data;
> +}
> +
> +static ssize_t show_temp(struct device *dev, struct device_attribute *da,
> +			 char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +	return sprintf(buf, "%d\n",
> 			((data->temp[attr->index] / 8) * 625) / 10);
> +}
> +
> +static ssize_t set_temp(struct device *dev, struct device_attribute *da,
> +			const char *buf, size_t count)
> +{
> +	int res;
> +	long val;
> +
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	res = strict_strtol(buf, 10, &val);
> +
Should be
	if (res)
		return res;

	val = (val * 10 / 625) * 8;
	...

> +	if (!res) {
> +		val = (val * 10 / 625) * 8;
> +
> +		mutex_lock(&data->update_lock);
> +		data->temp[attr->index] = val;
> +		ds620_write_temp(client, DS620_REG_TEMP[attr->index],
> +				  data->temp[attr->index]);
> +		mutex_unlock(&data->update_lock);
> +	}
> +	return count;
> +}
> +
> +static ssize_t show_alarms(struct device *dev, struct device_attribute *da,
> +			   char *buf)
> +{
> +	struct ds620_data *data = ds620_update_client(dev);
> +	return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf));
> +}
> +
_alarms is deprecated. Please remove.

> +static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
> +			  char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
> +}
> +
> +static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
> +static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
> +static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
> +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
> +		DS620_REG_CONFIG_TLF);
> +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
> +		DS620_REG_CONFIG_THF);
> +
> +static struct attribute *ds620_attributes[] = {
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
> +	&dev_attr_alarms.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ds620_group = {
> +	.attrs = ds620_attributes,
> +};
> +
> +
Extra blank line (Lindent would take care of that).

> +/* Return 0 if detection is successful, -ENODEV otherwise */
> +static int ds620_detect(struct i2c_client *client,
> +			 struct i2c_board_info *info)
> +{
> +	struct i2c_adapter *adapter = client->adapter;
> +	int result, conf, temp;
> +	int i;
> +
> +	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
> +				     | I2C_FUNC_SMBUS_WORD_DATA
> +				     | I2C_FUNC_SMBUS_WRITE_BYTE))
> +		return -ENODEV;
> +
> +	/* Now, we do the remaining detection. */
> +	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
> +	conf = swab16(result);
> +	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
> +			((conf & DS620_REG_CONFIG_DONE) &&
> +			 (conf & DS620_REG_CONFIG_AUTOC)) ||
> +			!((conf & DS620_REG_CONFIG_DONE) &&
> +			!(conf & DS620_REG_CONFIG_AUTOC)))
> +		return -ENODEV;
> +	/* The 3 lowest bits of a temperature should always be 0. */
> +	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
> +		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
> +		if (temp < 0 || (temp & 0x0700))
> +			return -ENODEV;
> +	}
> +
> +	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
> +
> +	return 0;
> +}
> +
> +static int ds620_probe(struct i2c_client *client,
> +			const struct i2c_device_id *id)
> +{
> +	struct ds620_data *data;
> +	int err;
> +
> +	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
> +	if (!data) {
> +		err = -ENOMEM;
> +		goto exit;
> +	}
> +
> +	i2c_set_clientdata(client, data);
> +	mutex_init(&data->update_lock);
> +
> +	/* Initialize the DS620 chip */
> +	ds620_init_client(client);
> +
> +	/* Register sysfs hooks */
> +	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
> +	if (err)
> +		goto exit_free;
> +
> +	data->hwmon_dev = hwmon_device_register(&client->dev);
> +	if (IS_ERR(data->hwmon_dev)) {
> +		err = PTR_ERR(data->hwmon_dev);
> +		goto exit_remove_files;
> +	}
> +
> +	dev_info(&client->dev, "temperature sensor found\n");
> +
> +	return 0;
> +
> +exit_remove_files:
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +exit_free:
> +	kfree(data);
> +exit:
> +	return err;
> +}
> +
> +static int ds620_remove(struct i2c_client *client)
> +{
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	hwmon_device_unregister(data->hwmon_dev);
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +
> +	kfree(data);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id ds620_id[] = {
> +	{ "ds620", 0 },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, ds620_id);
> +
> +/* This is the driver that will be inserted */
> +static struct i2c_driver ds620_driver = {
> +	.class		= I2C_CLASS_HWMON,
> +	.driver = {
> +		.name	= "ds620",
> +	},
> +	.probe		= ds620_probe,
> +	.remove		= ds620_remove,
> +	.id_table	= ds620_id,
> +	.detect		= ds620_detect,
> +	.address_list	= normal_i2c,
> +};
> +
> +static int __init ds620_init(void)
> +{
> +	return i2c_add_driver(&ds620_driver);
> +}
> +
> +static void __exit ds620_exit(void)
> +{
> +	i2c_del_driver(&ds620_driver);
> +}
> +
> +
> +MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
> +MODULE_DESCRIPTION("DS620 driver");
> +MODULE_LICENSE("GPL");
> +
> +module_init(ds620_init);
> +module_exit(ds620_exit);


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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (2 preceding siblings ...)
  2010-12-25 18:34 ` Guenter Roeck
@ 2010-12-25 21:10 ` Roland Stigge
  2010-12-25 22:13 ` Guenter Roeck
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2010-12-25 21:10 UTC (permalink / raw)
  To: lm-sensors

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

Hi!

Thanks for your advice!

On 25/12/10 19:34, Guenter Roeck wrote:
>> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
> Did you apply your patch ? All the above will show up in the patch log,
> which isn't really a good idea.

Please only consider the attached patch file (including the one line
description plus the "Signed-off-by:" line.

I included all your suggestions and attached the new patch.

Thanks for considering!

bye,
  Roland

[-- Attachment #2: hwmon-ds620.patch --]
[-- Type: text/x-patch, Size: 12501 bytes --]

Added support for Dallas Semiconductor DS620

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..824d01d
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,23 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..1025f74
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,362 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
+
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
+};
+
+/* Many DS620 constants specified below */
+/* Config register used for detection          */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC          0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Conversions */
+#define ALARMS_FROM_REG(val) ((val) & \
+				(DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+	u16 conf;		/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf) {
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+	}
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0)
+				return ERR_PTR(res);
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+
+	mutex_unlock(&data->update_lock);
+
+	return data;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 new_conf;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	data->conf = swab16(i2c_smbus_read_word_data(client,
+						     DS620_REG_CONF));
+	new_conf = data->conf;
+	if (data->temp[0] > data->temp[1])	/* input > min */
+		new_conf &= ~DS620_REG_CONFIG_TLF;
+	if (data->temp[0] < data->temp[2])	/* input < max */
+		new_conf &= ~DS620_REG_CONFIG_THF;
+	if (data->conf != new_conf)
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int ds620_detect(struct i2c_client *client, struct i2c_board_info *info)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	int result, conf, temp;
+	int i;
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
+				     | I2C_FUNC_SMBUS_WORD_DATA
+				     | I2C_FUNC_SMBUS_WRITE_BYTE))
+		return -ENODEV;
+
+	/* Now, we do the remaining detection. */
+	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	conf = swab16(result);
+	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
+	    ((conf & DS620_REG_CONFIG_DONE) &&
+	     (conf & DS620_REG_CONFIG_AUTOC)) ||
+	    !((conf & DS620_REG_CONFIG_DONE) &&
+	      !(conf & DS620_REG_CONFIG_AUTOC)))
+		return -ENODEV;
+	/* The 3 lowest bits of a temperature should always be 0. */
+	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
+		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
+		if (temp < 0 || (temp & 0x0700))
+			return -ENODEV;
+	}
+
+	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+	.detect = ds620_detect,
+	.address_list = normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (3 preceding siblings ...)
  2010-12-25 21:10 ` Roland Stigge
@ 2010-12-25 22:13 ` Guenter Roeck
  2010-12-25 23:05 ` Roland Stigge
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2010-12-25 22:13 UTC (permalink / raw)
  To: lm-sensors

On Sat, Dec 25, 2010 at 04:10:44PM -0500, Roland Stigge wrote:
> Hi!
> 
> Thanks for your advice!
> 
> On 25/12/10 19:34, Guenter Roeck wrote:
> >> Signed-off-by: Roland Stigge <stigge@antcom.de>
> > 
> > Did you apply your patch ? All the above will show up in the patch log,
> > which isn't really a good idea.
> 
> Please only consider the attached patch file (including the one line
> description plus the "Signed-off-by:" line.
> 
> I included all your suggestions and attached the new patch.
> 
> Thanks for considering!
> 
> bye,
>   Roland

> Added support for Dallas Semiconductor DS620
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
Almost there. See below.

Guenter

> diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
> new file mode 100644
> index 0000000..824d01d
> --- /dev/null
> +++ b/Documentation/hwmon/ds620
> @@ -0,0 +1,23 @@
> +Kernel driver ds620
> +=========> +
> +Supported chips:
> +  * Dallas Semiconductor DS620
> +    Prefix: 'ds620'
> +    Addresses scanned: I2C 0x48 - 0x4f
> +    Datasheet: Publicly available at the Dallas Semiconductor website
> +               http://www.dalsemi.com/
> +
> +Authors:
> +        Roland Stigge <stigge@antcom.de>
> +        based on ds1621.c by
> +        Christian W. Zuckschwerdt <zany@triq.net>
> +
> +Description
> +-----------
> +
> +The DS620 is a (one instance) digital thermometer and thermostat. It has both
> +high and low temperature limits which can be user defined (i.e.  programmed
> +into non-volatile on-chip registers). Temperature range is -55 degree Celsius
> +to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
> +returned via sysfs displays post decimal positions.
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index a56f6ad..700389a 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -274,6 +274,16 @@ config SENSORS_ATXP1
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called atxp1.
>  
> +config SENSORS_DS620
> +	tristate "Dallas Semiconductor DS620"
> +	depends on I2C
> +	help
> +	  If you say yes here you get support for Dallas Semiconductor
> +	  DS620 sensor chip.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called ds620.
> +
>  config SENSORS_DS1621
>  	tristate "Dallas Semiconductor DS1621 and DS1625"
>  	depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 2479b3d..42542d7 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
> +obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
>  obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
>  obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
> diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
> new file mode 100644
> index 0000000..1025f74
> --- /dev/null
> +++ b/drivers/hwmon/ds620.c
> @@ -0,0 +1,362 @@
> +/*
> +    ds620.c - Support for temperature sensor and thermostat DS620
> +
> +    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
> +
> +    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
> +
> +    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
> +    (at your option) any later version.
> +
> +    This program is distributed in the hope that it will be useful,
> +    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +    GNU General Public License for more details.
> +
> +    You should have received a copy of the GNU General Public License
> +    along with this program; if not, write to the Free Software
> +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +*/
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/jiffies.h>
> +#include <linux/i2c.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/err.h>
> +#include <linux/mutex.h>
> +#include <linux/sysfs.h>
> +
> +/* Addresses to scan */
> +static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
> +					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
> +};
> +
> +/* Many DS620 constants specified below */
> +/* Config register used for detection          */
> +/*  15   14   13   12   11   10   09    08     */
> +/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
> +
> +/*  07   06   05   04   03   02   01    00     */
> +/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
> +#define DS620_REG_CONFIG_DONE		0x8000
> +#define DS620_REG_CONFIG_NVB		0x4000
> +#define DS620_REG_CONFIG_THF		0x2000
> +#define DS620_REG_CONFIG_TLF		0x1000
> +#define DS620_REG_CONFIG_R1		0x0800
> +#define DS620_REG_CONFIG_R0		0x0400
> +#define DS620_REG_CONFIG_AUTOC          0x0200

Some blanks got in here. Odd - I thought checkpatch would complain about that.

> +#define DS620_REG_CONFIG_1SHOT		0x0100
> +#define DS620_REG_CONFIG_PO2		0x0080
> +#define DS620_REG_CONFIG_PO1		0x0040
> +#define DS620_REG_CONFIG_A2		0x0020
> +#define DS620_REG_CONFIG_A1		0x0010
> +#define DS620_REG_CONFIG_A0		0x0008
> +
> +/* The DS620 registers */
> +static const u8 DS620_REG_TEMP[3] = {
> +	0xAA,			/* input, word, RO */
> +	0xA2,			/* min, word, RW */
> +	0xA0,			/* max, word, RW */
> +};
> +
> +#define DS620_REG_CONF		0xAC	/* word, RW */
> +#define DS620_COM_START		0x51	/* no data */
> +#define DS620_COM_STOP		0x22	/* no data */
> +
> +/* Conversions */
> +#define ALARMS_FROM_REG(val) ((val) & \
> +				(DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
> +
> +/* Each client has this additional data */
> +struct ds620_data {
> +	struct device *hwmon_dev;
> +	struct mutex update_lock;
> +	char valid;		/* !=0 if following fields are valid */
> +	unsigned long last_updated;	/* In jiffies */
> +
> +	u16 temp[3];		/* Register values, word */
> +	u16 conf;		/* Register encoding, combined */
> +};
> +
> +/* Temperature registers are word-sized.
> +   DS620 uses a high-byte first convention, which is exactly opposite to
> +   the SMBus standard. */
> +static int ds620_read_temp(struct i2c_client *client, u8 reg)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_read_word_data(client, reg);
> +	if (ret < 0)
> +		return ret;
> +	return swab16(ret);
> +}
> +
> +static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
> +{
> +	return i2c_smbus_write_word_data(client, reg, swab16(value));
> +}
> +
> +static void ds620_init_client(struct i2c_client *client)
> +{
> +	u16 conf, new_conf;
> +
> +	new_conf = conf > +	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
> +
> +	/* switch to continuous conversion mode */
> +	new_conf &= ~DS620_REG_CONFIG_1SHOT;
> +	/* with highest precision */
> +	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
> +
> +	if (conf != new_conf) {
> +		i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +					  swab16(new_conf));
> +	}
> +
> +	/* start conversion */
> +	i2c_smbus_write_byte(client, DS620_COM_START);
> +}
> +
> +static struct ds620_data *ds620_update_client(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	mutex_lock(&data->update_lock);
> +
> +	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
> +	    || !data->valid) {
> +		int i;
> +		int res;
> +
> +		dev_dbg(&client->dev, "Starting ds620 update\n");
> +
> +		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
> +			res = ds620_read_temp(client,
> +					      DS620_REG_TEMP[i]);
> +			if (res < 0)
> +				return ERR_PTR(res);
> +
Mutex is still locked here. Look at how I implemented this in ltc4261.c.

> +			data->temp[i] = res;
> +		}
> +
> +		data->last_updated = jiffies;
> +		data->valid = 1;
> +	}
> +
> +	mutex_unlock(&data->update_lock);
> +
> +	return data;
> +}
> +
> +static ssize_t show_temp(struct device *dev, struct device_attribute *da,
> +			 char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
> +}
> +
> +static ssize_t set_temp(struct device *dev, struct device_attribute *da,
> +			const char *buf, size_t count)
> +{
> +	int res;
> +	long val;
> +
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	res = strict_strtol(buf, 10, &val);
> +
> +	if (res)
> +		return res;
> +
> +	val = (val * 10 / 625) * 8;
> +
> +	mutex_lock(&data->update_lock);
> +	data->temp[attr->index] = val;
> +	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
> +			 data->temp[attr->index]);
> +	mutex_unlock(&data->update_lock);
> +	return count;
> +}
> +
> +static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
> +			  char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	u16 new_conf;
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	/* reset alarms if necessary */
> +	data->conf = swab16(i2c_smbus_read_word_data(client,
> +						     DS620_REG_CONF));

You might want to check the error code from i2c_smbus_read_word_data() as well.

> +	new_conf = data->conf;
> +	if (data->temp[0] > data->temp[1])	/* input > min */
> +		new_conf &= ~DS620_REG_CONFIG_TLF;
> +	if (data->temp[0] < data->temp[2])	/* input < max */
> +		new_conf &= ~DS620_REG_CONFIG_THF;
> +	if (data->conf != new_conf)
> +		i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +					  swab16(new_conf));
> +
> +	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
> +}
> +
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
> +static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
> +static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
> +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_TLF);
> +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_THF);
> +
> +static struct attribute *ds620_attributes[] = {
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ds620_group = {
> +	.attrs = ds620_attributes,
> +};
> +
> +/* Return 0 if detection is successful, -ENODEV otherwise */
> +static int ds620_detect(struct i2c_client *client, struct i2c_board_info *info)
> +{
> +	struct i2c_adapter *adapter = client->adapter;
> +	int result, conf, temp;
> +	int i;
> +
> +	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
> +				     | I2C_FUNC_SMBUS_WORD_DATA
> +				     | I2C_FUNC_SMBUS_WRITE_BYTE))
> +		return -ENODEV;
> +
> +	/* Now, we do the remaining detection. */
> +	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
> +	conf = swab16(result);
> +	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
> +	    ((conf & DS620_REG_CONFIG_DONE) &&
> +	     (conf & DS620_REG_CONFIG_AUTOC)) ||
> +	    !((conf & DS620_REG_CONFIG_DONE) &&
> +	      !(conf & DS620_REG_CONFIG_AUTOC)))
> +		return -ENODEV;
> +	/* The 3 lowest bits of a temperature should always be 0. */
> +	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
> +		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
> +		if (temp < 0 || (temp & 0x0700))
> +			return -ENODEV;
> +	}
> +
> +	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
> +
> +	return 0;
> +}
> +
> +static int ds620_probe(struct i2c_client *client,
> +		       const struct i2c_device_id *id)
> +{
> +	struct ds620_data *data;
> +	int err;
> +
> +	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
> +	if (!data) {
> +		err = -ENOMEM;
> +		goto exit;
> +	}
> +
> +	i2c_set_clientdata(client, data);
> +	mutex_init(&data->update_lock);
> +
> +	/* Initialize the DS620 chip */
> +	ds620_init_client(client);
> +
> +	/* Register sysfs hooks */
> +	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
> +	if (err)
> +		goto exit_free;
> +
> +	data->hwmon_dev = hwmon_device_register(&client->dev);
> +	if (IS_ERR(data->hwmon_dev)) {
> +		err = PTR_ERR(data->hwmon_dev);
> +		goto exit_remove_files;
> +	}
> +
> +	dev_info(&client->dev, "temperature sensor found\n");
> +
> +	return 0;
> +
> +exit_remove_files:
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +exit_free:
> +	kfree(data);
> +exit:
> +	return err;
> +}
> +
> +static int ds620_remove(struct i2c_client *client)
> +{
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	hwmon_device_unregister(data->hwmon_dev);
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +
> +	kfree(data);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id ds620_id[] = {
> +	{"ds620", 0},
> +	{}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, ds620_id);
> +
> +/* This is the driver that will be inserted */
> +static struct i2c_driver ds620_driver = {
> +	.class = I2C_CLASS_HWMON,
> +	.driver = {
> +		   .name = "ds620",
> +	},
> +	.probe = ds620_probe,
> +	.remove = ds620_remove,
> +	.id_table = ds620_id,
> +	.detect = ds620_detect,
> +	.address_list = normal_i2c,
> +};
> +
> +static int __init ds620_init(void)
> +{
> +	return i2c_add_driver(&ds620_driver);
> +}
> +
> +static void __exit ds620_exit(void)
> +{
> +	i2c_del_driver(&ds620_driver);
> +}
> +
> +MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
> +MODULE_DESCRIPTION("DS620 driver");
> +MODULE_LICENSE("GPL");
> +
> +module_init(ds620_init);
> +module_exit(ds620_exit);


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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (4 preceding siblings ...)
  2010-12-25 22:13 ` Guenter Roeck
@ 2010-12-25 23:05 ` Roland Stigge
  2010-12-26  3:18 ` Guenter Roeck
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2010-12-25 23:05 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

thanks again for your valuable feedback!

Attaching the updated patch including your proposed changes.

bye,
  Roland

[-- Attachment #2: hwmon-ds620.patch --]
[-- Type: text/x-patch, Size: 12642 bytes --]

Added support for Dallas Semiconductor DS620

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..824d01d
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,23 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..6d2c0f7
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,372 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010 Roland Stigge <stigge@antcom.de>
+
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
+};
+
+/* Many DS620 constants specified below */
+/* Config register used for detection          */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Conversions */
+#define ALARMS_FROM_REG(val) ((val) & \
+				(DS620_REG_CONFIG_THF | DS620_REG_CONFIG_TLF))
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+	u16 conf;		/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf) {
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+	}
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	data->conf = swab16(res);
+	new_conf = data->conf;
+	if (data->temp[0] > data->temp[1])	/* input > min */
+		new_conf &= ~DS620_REG_CONFIG_TLF;
+	if (data->temp[0] < data->temp[2])	/* input < max */
+		new_conf &= ~DS620_REG_CONFIG_THF;
+	if (data->conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int ds620_detect(struct i2c_client *client, struct i2c_board_info *info)
+{
+	struct i2c_adapter *adapter = client->adapter;
+	int result, conf, temp;
+	int i;
+
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
+				     | I2C_FUNC_SMBUS_WORD_DATA
+				     | I2C_FUNC_SMBUS_WRITE_BYTE))
+		return -ENODEV;
+
+	/* Now, we do the remaining detection. */
+	result = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	conf = swab16(result);
+	if (result < 0 || conf & DS620_REG_CONFIG_NVB ||
+	    ((conf & DS620_REG_CONFIG_DONE) &&
+	     (conf & DS620_REG_CONFIG_AUTOC)) ||
+	    !((conf & DS620_REG_CONFIG_DONE) &&
+	      !(conf & DS620_REG_CONFIG_AUTOC)))
+		return -ENODEV;
+	/* The 3 lowest bits of a temperature should always be 0. */
+	for (i = 0; i < ARRAY_SIZE(DS620_REG_TEMP); i++) {
+		temp = i2c_smbus_read_word_data(client, DS620_REG_TEMP[i]);
+		if (temp < 0 || (temp & 0x0700))
+			return -ENODEV;
+	}
+
+	strlcpy(info->type, "ds620", I2C_NAME_SIZE);
+
+	return 0;
+}
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+	.detect = ds620_detect,
+	.address_list = normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (5 preceding siblings ...)
  2010-12-25 23:05 ` Roland Stigge
@ 2010-12-26  3:18 ` Guenter Roeck
  2010-12-26 23:20 ` Roland Stigge
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2010-12-26  3:18 UTC (permalink / raw)
  To: lm-sensors

On Sat, Dec 25, 2010 at 06:05:59PM -0500, Roland Stigge wrote:
> Hi,
> 
> thanks again for your valuable feedback!
> 
> Attaching the updated patch including your proposed changes.
> 
> bye,
>   Roland

> Added support for Dallas Semiconductor DS620
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
Queued for -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] 22+ messages in thread

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (6 preceding siblings ...)
  2010-12-26  3:18 ` Guenter Roeck
@ 2010-12-26 23:20 ` Roland Stigge
  2011-01-02 23:31 ` Guenter Roeck
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2010-12-26 23:20 UTC (permalink / raw)
  To: lm-sensors

On 26/12/10 04:18, Guenter Roeck wrote:
>> Added support for Dallas Semiconductor DS620
>>
>> Signed-off-by: Roland Stigge <stigge@antcom.de>
>>
> Queued for -next.

Thanks in advance!

Another question: I will need to write a driver for the MAX518 DAC. What
is the appropriate place?

* hwmon (well, it is an analog _output_, not a monioring input)
* gpio (it is an analog, not _digital_ 0/1 output)
* misc

?

bye,
  Roland

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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (7 preceding siblings ...)
  2010-12-26 23:20 ` Roland Stigge
@ 2011-01-02 23:31 ` Guenter Roeck
  2011-01-06 18:03 ` Jean Delvare
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-02 23:31 UTC (permalink / raw)
  To: lm-sensors

On Sun, Dec 26, 2010 at 06:20:48PM -0500, Roland Stigge wrote:
> On 26/12/10 04:18, Guenter Roeck wrote:
> >> Added support for Dallas Semiconductor DS620
> >>
> >> Signed-off-by: Roland Stigge <stigge@antcom.de>
> >>
> > Queued for -next.
> 
> Thanks in advance!
> 
> Another question: I will need to write a driver for the MAX518 DAC. What
> is the appropriate place?
> 
> * hwmon (well, it is an analog _output_, not a monioring input)
> * gpio (it is an analog, not _digital_ 0/1 output)
> * misc
> 
> ?
> 
Sorry, I was out for a few days. iio (in staging) might be the best fit.

Guenter

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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (8 preceding siblings ...)
  2011-01-02 23:31 ` Guenter Roeck
@ 2011-01-06 18:03 ` Jean Delvare
  2011-01-07  0:05 ` Roland Stigge
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Jean Delvare @ 2011-01-06 18:03 UTC (permalink / raw)
  To: lm-sensors

On Sun, 26 Dec 2010 00:05:59 +0100, Roland Stigge wrote:
> Hi,
> 
> thanks again for your valuable feedback!
> 
> Attaching the updated patch including your proposed changes.

Do you actually need the detection function? It's pretty weak, the DS620
has no ID registers, detection can't be reliable, I'd rather not have
it at all.

(The DS1621 is detected for historical reasons, but quite frankly, it
shouldn't have been either, and we might drop that someday.)

-- 
Jean Delvare

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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (9 preceding siblings ...)
  2011-01-06 18:03 ` Jean Delvare
@ 2011-01-07  0:05 ` Roland Stigge
  2011-01-07  1:39 ` Guenter Roeck
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-07  0:05 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 06/01/11 19:03, Jean Delvare wrote:
> On Sun, 26 Dec 2010 00:05:59 +0100, Roland Stigge wrote:
>> Hi,
>>
>> thanks again for your valuable feedback!
>>
>> Attaching the updated patch including your proposed changes.
> 
> Do you actually need the detection function? It's pretty weak, the DS620
> has no ID registers, detection can't be reliable, I'd rather not have
> it at all.
> 
> (The DS1621 is detected for historical reasons, but quite frankly, it
> shouldn't have been either, and we might drop that someday.)

Thanks for your hint!

I'm attaching my updated patch. You can also merge from git.antcom.de,
repo linux-2.6, branch ds620.

I also added a runtime configuration device attribute for the thermostat
functionality.

Thanks,

bye,
  Roland

[-- Attachment #2: ds620.patch --]
[-- Type: text/x-patch, Size: 13344 bytes --]

HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..1acd21e
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,34 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
+The thermostat function works as follows: When configured via the sysfs
+attribute temp1_thmode == 0 (default), the thermostat is in TH_LOW mode. I.e.
+the alarm becomes active when the temperature falls below temp1_min and stays
+active until the temperature goes above temp1_max.
+
+Likewise, with temp1_thmode == 1, the thermostat is in TH_HIGH mode. I.e., the
+alarm becomes active when the temperature goes above temp1_max and stays active
+until the temperature falls below temp1_min.
+
+The PO output pin is always active-low.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..bad80e4
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,382 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
+
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
+};
+
+/* Many DS620 constants specified below        */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+	u16 conf;		/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode, thermostat PO_LOW */
+	new_conf &= ~(DS620_REG_CONFIG_1SHOT | DS620_REG_CONFIG_PO1);
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf) {
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+	}
+
+	data->conf = new_conf;
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	data->conf = swab16(res);
+	new_conf = data->conf;
+	if (data->temp[0] > data->temp[1])	/* input > min */
+		new_conf &= ~DS620_REG_CONFIG_TLF;
+	if (data->temp[0] < data->temp[2])	/* input < max */
+		new_conf &= ~DS620_REG_CONFIG_THF;
+	if (data->conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static ssize_t show_thmode(struct device *dev, struct device_attribute *da,
+			   char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static ssize_t store_thmode(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t count)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	u16 new_conf = data->conf;
+	int res;
+	long val;
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	mutex_lock(&data->update_lock);
+	new_conf = data->conf = ds620_read_temp(client, DS620_REG_CONF);
+
+	if (val == 0) {
+		new_conf &= ~DS620_REG_CONFIG_PO1;
+	} else if (val == 1) {
+		new_conf |= DS620_REG_CONFIG_PO1;
+	}
+
+	if (new_conf != data->conf) {
+		data->conf = new_conf;
+		ds620_write_temp(client, DS620_REG_CONF, data->conf);
+	}
+
+	mutex_unlock(&data->update_lock);
+
+	return count;
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+static SENSOR_DEVICE_ATTR(temp1_thmode, S_IWUSR | S_IRUGO, show_thmode,
+			  store_thmode, DS620_REG_CONFIG_PO1);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_thmode.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+	.address_list = normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (10 preceding siblings ...)
  2011-01-07  0:05 ` Roland Stigge
@ 2011-01-07  1:39 ` Guenter Roeck
  2011-01-07 10:24 ` Roland Stigge
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-07  1:39 UTC (permalink / raw)
  To: lm-sensors

On Thu, Jan 06, 2011 at 07:05:24PM -0500, Roland Stigge wrote:
> Hi,
> 
> On 06/01/11 19:03, Jean Delvare wrote:
> > On Sun, 26 Dec 2010 00:05:59 +0100, Roland Stigge wrote:
> >> Hi,
> >>
> >> thanks again for your valuable feedback!
> >>
> >> Attaching the updated patch including your proposed changes.
> > 
> > Do you actually need the detection function? It's pretty weak, the DS620
> > has no ID registers, detection can't be reliable, I'd rather not have
> > it at all.
> > 
> > (The DS1621 is detected for historical reasons, but quite frankly, it
> > shouldn't have been either, and we might drop that someday.)
> 
> Thanks for your hint!
> 
> I'm attaching my updated patch. You can also merge from git.antcom.de,
> repo linux-2.6, branch ds620.
> 
> I also added a runtime configuration device attribute for the thermostat
> functionality.
> 
Unfortunately, that adds a non-standard and non-documented ABI attribute, so no one
will be able to use it. Also, from reading the specification, it seems like it would more
appropriate to set this through platform data (if it really has to be configurable).

Btw, can you write Documentation/hwmon/ds620 ? I completely forgot to ask for that.

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] 22+ messages in thread

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (11 preceding siblings ...)
  2011-01-07  1:39 ` Guenter Roeck
@ 2011-01-07 10:24 ` Roland Stigge
  2011-01-07 11:34 ` Guenter Roeck
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-07 10:24 UTC (permalink / raw)
  To: lm-sensors

Hi,

On 01/07/2011 02:39 AM, Guenter Roeck wrote:
>> I'm attaching my updated patch. You can also merge from git.antcom.de,
>> repo linux-2.6, branch ds620.
>>
>> I also added a runtime configuration device attribute for the thermostat
>> functionality.
>>
> Unfortunately, that adds a non-standard and non-documented ABI attribute, so no one
> will be able to use it. Also, from reading the specification, it seems like it would more
> appropriate to set this through platform data (if it really has to be configurable).

Oops, sorry!

What can we do if we want to make it configurable at runtime? I'm not
using it currently this way, but users could be. Or should we just make
ist platform data to adhere to spec restrictions?

> Btw, can you write Documentation/hwmon/ds620 ? I completely forgot to ask for that.

It was already included in the last patches, since you already asked
about it. :-)

bye,
  Roland

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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (12 preceding siblings ...)
  2011-01-07 10:24 ` Roland Stigge
@ 2011-01-07 11:34 ` Guenter Roeck
  2011-01-08 17:56 ` Roland Stigge
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-07 11:34 UTC (permalink / raw)
  To: lm-sensors

On Fri, Jan 07, 2011 at 05:24:21AM -0500, Roland Stigge wrote:
> Hi,
> 
> On 01/07/2011 02:39 AM, Guenter Roeck wrote:
> >> I'm attaching my updated patch. You can also merge from git.antcom.de,
> >> repo linux-2.6, branch ds620.
> >>
> >> I also added a runtime configuration device attribute for the thermostat
> >> functionality.
> >>
> > Unfortunately, that adds a non-standard and non-documented ABI attribute, so no one
> > will be able to use it. Also, from reading the specification, it seems like it would more
> > appropriate to set this through platform data (if it really has to be configurable).
> 
> Oops, sorry!
> 
> What can we do if we want to make it configurable at runtime? I'm not
> using it currently this way, but users could be. Or should we just make
> ist platform data to adhere to spec restrictions?
> 
I would suggest to implement it as platform data. If anyone ever needs it runtime-configurable,
we can still think about some way to do it.

> > Btw, can you write Documentation/hwmon/ds620 ? I completely forgot to ask for that.
> 
> It was already included in the last patches, since you already asked
> about it. :-)
> 
I must be blind :(.

Guenter

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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (13 preceding siblings ...)
  2011-01-07 11:34 ` Guenter Roeck
@ 2011-01-08 17:56 ` Roland Stigge
  2011-01-08 18:54 ` Guenter Roeck
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-08 17:56 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 07/01/11 12:34, Guenter Roeck wrote:
>> What can we do if we want to make it configurable at runtime? I'm not
>> using it currently this way, but users could be. Or should we just make
>> ist platform data to adhere to spec restrictions?
>>
> I would suggest to implement it as platform data. If anyone ever needs it runtime-configurable,
> we can still think about some way to do it.

I'm attaching the updated patch according to your suggestions, including
Documentation updates. :-)

Thanks,

Roland

[-- Attachment #2: ds620.patch --]
[-- Type: text/x-patch, Size: 12912 bytes --]

HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..c0edc34
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,34 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Addresses scanned: I2C 0x48 - 0x4f
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
+The thermostat function works as follows: When configured via platform_data
+(struct ds620_platform_data) .thmode == 0 (default), the thermostat is in
+TH_LOW mode. I.e., the alarm becomes active when the temperature falls below
+temp1_min and stays active until the temperature goes above temp1_max.
+
+Likewise, with .thmode == 1, the thermostat is in TH_HIGH mode. I.e., the alarm
+becomes active when the temperature goes above temp1_max and stays active until
+the temperature falls below temp1_min.
+
+The PO output pin is always active-low.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..62e4f0d
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,344 @@
+/*
+    ds620.c - Support for temperature sensor and thermostat DS620
+
+    Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
+
+    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+
+    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
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/i2c/ds620.h>
+
+/* Addresses to scan */
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
+					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
+};
+
+/* Many DS620 constants specified below        */
+/*  15   14   13   12   11   10   09    08     */
+/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
+
+/*  07   06   05   04   03   02   01    00     */
+/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+	u16 conf;		/* Register encoding, combined */
+};
+
+/* Temperature registers are word-sized.
+   DS620 uses a high-byte first convention, which is exactly opposite to
+   the SMBus standard. */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_platform_data *ds620_info =
+		(struct ds620_platform_data *)&client->dev.platform_data;
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~(DS620_REG_CONFIG_1SHOT);
+	/* thermostat mode according to platform data */
+	if (ds620_info && ds620_info->thmode)
+		new_conf |= DS620_REG_CONFIG_PO1; /* TH_HIGH */
+	else
+		new_conf &= ~DS620_REG_CONFIG_PO1; /* TH_LOW */
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf) {
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+	}
+
+	data->conf = new_conf;
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	data->conf = swab16(res);
+	new_conf = data->conf;
+	if (data->temp[0] > data->temp[1])	/* input > min */
+		new_conf &= ~DS620_REG_CONFIG_TLF;
+	if (data->temp[0] < data->temp[2])	/* input < max */
+		new_conf &= ~DS620_REG_CONFIG_THF;
+	if (data->conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+	.address_list = normal_i2c,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);
diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
new file mode 100644
index 0000000..e9a4dcc
--- /dev/null
+++ b/include/linux/i2c/ds620.h
@@ -0,0 +1,15 @@
+#ifndef _LINUX_DS620_H
+#define _LINUX_DS620_H
+
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+/* platform data for the DS620 temperature sensor and thermostat */
+
+struct ds620_platform_data {
+	/* Thermostat Mode: 0 = TH_LOW, 1 = TH_HIGH */
+	/* (see Documentation/hwmon/ds620) */
+	bool thmode;
+};
+
+#endif /* _LINUX_DS620_H */

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (14 preceding siblings ...)
  2011-01-08 17:56 ` Roland Stigge
@ 2011-01-08 18:54 ` Guenter Roeck
  2011-01-09  0:01 ` Roland Stigge
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-08 18:54 UTC (permalink / raw)
  To: lm-sensors

On Sat, Jan 08, 2011 at 12:56:35PM -0500, Roland Stigge wrote:
> Hi,
> 
> On 07/01/11 12:34, Guenter Roeck wrote:
> >> What can we do if we want to make it configurable at runtime? I'm not
> >> using it currently this way, but users could be. Or should we just make
> >> ist platform data to adhere to spec restrictions?
> >>
> > I would suggest to implement it as platform data. If anyone ever needs it runtime-configurable,
> > we can still think about some way to do it.
> 
> I'm attaching the updated patch according to your suggestions, including
> Documentation updates. :-)
> 
> Thanks,
> 
> Roland

> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
Hi Roland,

couple of comments below.

> diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
> new file mode 100644
> index 0000000..c0edc34
> --- /dev/null
> +++ b/Documentation/hwmon/ds620
> @@ -0,0 +1,34 @@
> +Kernel driver ds620
> +=========> +
> +Supported chips:
> +  * Dallas Semiconductor DS620
> +    Prefix: 'ds620'
> +    Addresses scanned: I2C 0x48 - 0x4f

None anymore, really.

> +    Datasheet: Publicly available at the Dallas Semiconductor website
> +               http://www.dalsemi.com/
> +
> +Authors:
> +        Roland Stigge <stigge@antcom.de>
> +        based on ds1621.c by
> +        Christian W. Zuckschwerdt <zany@triq.net>
> +
> +Description
> +-----------
> +
> +The DS620 is a (one instance) digital thermometer and thermostat. It has both
> +high and low temperature limits which can be user defined (i.e.  programmed
> +into non-volatile on-chip registers). Temperature range is -55 degree Celsius
> +to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
> +returned via sysfs displays post decimal positions.
> +
> +The thermostat function works as follows: When configured via platform_data
> +(struct ds620_platform_data) .thmode = 0 (default), the thermostat is in
> +TH_LOW mode. I.e., the alarm becomes active when the temperature falls below
> +temp1_min and stays active until the temperature goes above temp1_max.
> +
> +Likewise, with .thmode = 1, the thermostat is in TH_HIGH mode. I.e., the alarm
> +becomes active when the temperature goes above temp1_max and stays active until
> +the temperature falls below temp1_min.

"the alarm" ? I don't think that is accurate. Alarms bits are independent of the PO mode.
You are trying to configure the PO pin. thmode and the description above is thus
a bit misleading.

If anything, you might want to define .pomode, such as:
	.pomode = 0: always low (PO1 = x, PO2 = 0)
	.pomode = 1: po_low (PO1 = 0, PO2 = 1)
	.pomode = 2: po_high (PO1 = 1, PO2 = 1)

> +
> +The PO output pin is always active-low.

What is the point of configuring PO1 if you set PO2 such that PO is always low ?
Datasheet says that if PO2=low, PO will always be low independent of PO1.

> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index a56f6ad..700389a 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -274,6 +274,16 @@ config SENSORS_ATXP1
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called atxp1.
>  
> +config SENSORS_DS620
> +	tristate "Dallas Semiconductor DS620"
> +	depends on I2C
> +	help
> +	  If you say yes here you get support for Dallas Semiconductor
> +	  DS620 sensor chip.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called ds620.
> +
>  config SENSORS_DS1621
>  	tristate "Dallas Semiconductor DS1621 and DS1625"
>  	depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 2479b3d..42542d7 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
> +obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
>  obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
>  obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
> diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
> new file mode 100644
> index 0000000..62e4f0d
> --- /dev/null
> +++ b/drivers/hwmon/ds620.c
> @@ -0,0 +1,344 @@
> +/*
> +    ds620.c - Support for temperature sensor and thermostat DS620
> +
> +    Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
> +
> +    based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
> +
> +    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
> +    (at your option) any later version.
> +
> +    This program is distributed in the hope that it will be useful,
> +    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +    GNU General Public License for more details.
> +
> +    You should have received a copy of the GNU General Public License
> +    along with this program; if not, write to the Free Software
> +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +*/
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/jiffies.h>
> +#include <linux/i2c.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/err.h>
> +#include <linux/mutex.h>
> +#include <linux/sysfs.h>
> +#include <linux/i2c/ds620.h>
> +
> +/* Addresses to scan */
> +static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
> +					0x4d, 0x4e, 0x4f, I2C_CLIENT_END
> +};

No longer needed since addresses are not scanned anymore.

> +
> +/* Many DS620 constants specified below        */
> +/*  15   14   13   12   11   10   09    08     */
> +/* |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT| */
> +
> +/*  07   06   05   04   03   02   01    00     */
> +/* |PO2 |PO1 |A2  |A1  |A0  |    |     |     | */
> +#define DS620_REG_CONFIG_DONE		0x8000
> +#define DS620_REG_CONFIG_NVB		0x4000
> +#define DS620_REG_CONFIG_THF		0x2000
> +#define DS620_REG_CONFIG_TLF		0x1000
> +#define DS620_REG_CONFIG_R1		0x0800
> +#define DS620_REG_CONFIG_R0		0x0400
> +#define DS620_REG_CONFIG_AUTOC		0x0200
> +#define DS620_REG_CONFIG_1SHOT		0x0100
> +#define DS620_REG_CONFIG_PO2		0x0080
> +#define DS620_REG_CONFIG_PO1		0x0040
> +#define DS620_REG_CONFIG_A2		0x0020
> +#define DS620_REG_CONFIG_A1		0x0010
> +#define DS620_REG_CONFIG_A0		0x0008
> +
> +/* The DS620 registers */
> +static const u8 DS620_REG_TEMP[3] = {
> +	0xAA,			/* input, word, RO */
> +	0xA2,			/* min, word, RW */
> +	0xA0,			/* max, word, RW */
> +};
> +
> +#define DS620_REG_CONF		0xAC	/* word, RW */
> +#define DS620_COM_START		0x51	/* no data */
> +#define DS620_COM_STOP		0x22	/* no data */
> +
> +/* Each client has this additional data */
> +struct ds620_data {
> +	struct device *hwmon_dev;
> +	struct mutex update_lock;
> +	char valid;		/* !=0 if following fields are valid */
> +	unsigned long last_updated;	/* In jiffies */
> +
> +	u16 temp[3];		/* Register values, word */
> +	u16 conf;		/* Register encoding, combined */
> +};
> +
> +/* Temperature registers are word-sized.
> +   DS620 uses a high-byte first convention, which is exactly opposite to
> +   the SMBus standard. */

Please use multi-line comment format as described in Documentation/CodingStyle.

> +static int ds620_read_temp(struct i2c_client *client, u8 reg)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_read_word_data(client, reg);
> +	if (ret < 0)
> +		return ret;
> +	return swab16(ret);
> +}
> +
> +static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
> +{
> +	return i2c_smbus_write_word_data(client, reg, swab16(value));
> +}
> +
> +static void ds620_init_client(struct i2c_client *client)
> +{
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +	struct ds620_platform_data *ds620_info > +		(struct ds620_platform_data *)&client->dev.platform_data;

platform_data is a void *, so you don't need a typecast here.

> +	u16 conf, new_conf;
> +
> +	new_conf = conf > +	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
> +
> +	/* switch to continuous conversion mode */
> +	new_conf &= ~(DS620_REG_CONFIG_1SHOT);

		( ) is really unnecessary here.

> +	/* thermostat mode according to platform data */
> +	if (ds620_info && ds620_info->thmode)
> +		new_conf |= DS620_REG_CONFIG_PO1; /* TH_HIGH */
> +	else
> +		new_conf &= ~DS620_REG_CONFIG_PO1; /* TH_LOW */
> +	/* with highest precision */
> +	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
> +
> +	if (conf != new_conf) {
> +		i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +					  swab16(new_conf));
> +	}

		{ } is unnecessary here.

> +
> +	data->conf = new_conf;
> +
> +	/* start conversion */
> +	i2c_smbus_write_byte(client, DS620_COM_START);
> +}
> +
> +static struct ds620_data *ds620_update_client(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +	struct ds620_data *ret = data;
> +
> +	mutex_lock(&data->update_lock);
> +
> +	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
> +	    || !data->valid) {
> +		int i;
> +		int res;
> +
> +		dev_dbg(&client->dev, "Starting ds620 update\n");
> +
> +		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
> +			res = ds620_read_temp(client,
> +					      DS620_REG_TEMP[i]);
> +			if (res < 0) {
> +				ret = ERR_PTR(res);
> +				goto abort;
> +			}
> +
> +			data->temp[i] = res;
> +		}
> +
> +		data->last_updated = jiffies;
> +		data->valid = 1;
> +	}
> +abort:
> +	mutex_unlock(&data->update_lock);
> +
> +	return ret;
> +}
> +
> +static ssize_t show_temp(struct device *dev, struct device_attribute *da,
> +			 char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
> +}
> +
> +static ssize_t set_temp(struct device *dev, struct device_attribute *da,
> +			const char *buf, size_t count)
> +{
> +	int res;
> +	long val;
> +
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	res = strict_strtol(buf, 10, &val);
> +
> +	if (res)
> +		return res;
> +
> +	val = (val * 10 / 625) * 8;
> +
> +	mutex_lock(&data->update_lock);
> +	data->temp[attr->index] = val;
> +	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
> +			 data->temp[attr->index]);
> +	mutex_unlock(&data->update_lock);
> +	return count;
> +}
> +
> +static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
> +			  char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	u16 new_conf;
> +	int res;
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	/* reset alarms if necessary */
> +	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
> +	if (res < 0)
> +		return res;
> +
> +	data->conf = swab16(res);
> +	new_conf = data->conf;
> +	if (data->temp[0] > data->temp[1])	/* input > min */
> +		new_conf &= ~DS620_REG_CONFIG_TLF;
> +	if (data->temp[0] < data->temp[2])	/* input < max */
> +		new_conf &= ~DS620_REG_CONFIG_THF;

After reading the datasheet, I think you can simplify this and just reset the bit
if it was set. If the condition still applies, the chip should set it again.
Also, as written, one of the alarms may not be reported at all.
Example: If both alarms are set, and the lower alarm is read first, the code
here will also reset the upper alarm without reporting it. As such,
	new_conf &= ~attr->index;
would be simpler and should accomplish the same.

Also, from looking through the code again, you don't need data->conf in the first place,
since it is never used outside its local context. A local variable should do it.

> +	if (data->conf != new_conf) {
> +		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +						swab16(new_conf));
> +		if (res < 0)
> +			return res;
> +	}
> +
> +	return sprintf(buf, "%d\n", !!(data->conf & attr->index));
> +}
> +
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
> +static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
> +static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
> +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_TLF);
> +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_THF);
> +
> +static struct attribute *ds620_attributes[] = {
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ds620_group = {
> +	.attrs = ds620_attributes,
> +};
> +
> +static int ds620_probe(struct i2c_client *client,
> +		       const struct i2c_device_id *id)
> +{
> +	struct ds620_data *data;
> +	int err;
> +
> +	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
> +	if (!data) {
> +		err = -ENOMEM;
> +		goto exit;
> +	}
> +
> +	i2c_set_clientdata(client, data);
> +	mutex_init(&data->update_lock);
> +
> +	/* Initialize the DS620 chip */
> +	ds620_init_client(client);
> +
> +	/* Register sysfs hooks */
> +	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
> +	if (err)
> +		goto exit_free;
> +
> +	data->hwmon_dev = hwmon_device_register(&client->dev);
> +	if (IS_ERR(data->hwmon_dev)) {
> +		err = PTR_ERR(data->hwmon_dev);
> +		goto exit_remove_files;
> +	}
> +
> +	dev_info(&client->dev, "temperature sensor found\n");
> +
> +	return 0;
> +
> +exit_remove_files:
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +exit_free:
> +	kfree(data);
> +exit:
> +	return err;
> +}
> +
> +static int ds620_remove(struct i2c_client *client)
> +{
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	hwmon_device_unregister(data->hwmon_dev);
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +
> +	kfree(data);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id ds620_id[] = {
> +	{"ds620", 0},
> +	{}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, ds620_id);
> +
> +/* This is the driver that will be inserted */
> +static struct i2c_driver ds620_driver = {
> +	.class = I2C_CLASS_HWMON,
> +	.driver = {
> +		   .name = "ds620",
> +	},
> +	.probe = ds620_probe,
> +	.remove = ds620_remove,
> +	.id_table = ds620_id,
> +	.address_list = normal_i2c,

Address list is no longer needed and can be removed.

> +};
> +
> +static int __init ds620_init(void)
> +{
> +	return i2c_add_driver(&ds620_driver);
> +}
> +
> +static void __exit ds620_exit(void)
> +{
> +	i2c_del_driver(&ds620_driver);
> +}
> +
> +MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
> +MODULE_DESCRIPTION("DS620 driver");
> +MODULE_LICENSE("GPL");
> +
> +module_init(ds620_init);
> +module_exit(ds620_exit);
> diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
> new file mode 100644
> index 0000000..e9a4dcc
> --- /dev/null
> +++ b/include/linux/i2c/ds620.h
> @@ -0,0 +1,15 @@
> +#ifndef _LINUX_DS620_H
> +#define _LINUX_DS620_H
> +
> +#include <linux/types.h>
> +#include <linux/i2c.h>
> +
> +/* platform data for the DS620 temperature sensor and thermostat */
> +
> +struct ds620_platform_data {
> +	/* Thermostat Mode: 0 = TH_LOW, 1 = TH_HIGH */
> +	/* (see Documentation/hwmon/ds620) */
> +	bool thmode;
> +};
> +
> +#endif /* _LINUX_DS620_H */


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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (15 preceding siblings ...)
  2011-01-08 18:54 ` Guenter Roeck
@ 2011-01-09  0:01 ` Roland Stigge
  2011-01-09  3:59 ` Guenter Roeck
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-09  0:01 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 08/01/11 19:54, Guenter Roeck wrote:
> couple of comments below.

Thanks again for your suggestions! I'm attaching the latest version with
your ideas included.

>> +The PO output pin is always active-low.
> 
> What is the point of configuring PO1 if you set PO2 such that PO is always low ?

Maybe the above was a bit misleading, though correct: "always
active-low" wasn't intended to mean "always low", but instead "low when
active". :-) Nevertheless, I clarified it. ("The PO output pin of the
DS620 operates active-low.").

Thanks,

Roland

[-- Attachment #2: ds620.patch --]
[-- Type: text/x-patch, Size: 12616 bytes --]

HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..0c765b0
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,34 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
+The thermostat function works as follows: When configured via platform_data
+(struct ds620_platform_data) .pomode == 0 (default), the thermostat output pin
+PO is always low. If .pomode == 1, the thermostat is in TH_LOW mode. I.e., the
+output pin PO becomes active when the temperature falls below temp1_min and
+stays active until the temperature goes above temp1_max.
+
+Likewise, with .pomode == 2, the thermostat is in TH_HIGH mode. I.e., the PO
+output pin becomes active when the temperature goes above temp1_max and stays
+active until the temperature falls below temp1_min.
+
+The PO output pin of the DS620 operates active-low.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..624950d
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,335 @@
+/*
+ *  ds620.c - Support for temperature sensor and thermostat DS620
+ *
+ *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
+ *
+ *  based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/i2c/ds620.h>
+
+/*
+ * Many DS620 constants specified below
+ *  15   14   13   12   11   10   09    08
+ * |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT|
+ *
+ *  07   06   05   04   03   02   01    00
+ * |PO2 |PO1 |A2  |A1  |A0  |    |     |     |
+ */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+};
+
+/*
+ *  Temperature registers are word-sized.
+ *  DS620 uses a high-byte first convention, which is exactly opposite to
+ *  the SMBus standard.
+ */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	struct ds620_platform_data *ds620_info = client->dev.platform_data;
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* thermostat mode according to platform data */
+	if (ds620_info && ds620_info->pomode == 1)
+		new_conf &= ~DS620_REG_CONFIG_PO1; /* TH_LOW */
+	else if (ds620_info && ds620_info->pomode == 2)
+		new_conf |= DS620_REG_CONFIG_PO1; /* TH_HIGH */
+	else
+		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf)
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 conf, new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	conf = swab16(res);
+	new_conf = conf;
+	new_conf &= ~attr->index;
+	if (conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);
diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
new file mode 100644
index 0000000..141c043
--- /dev/null
+++ b/include/linux/i2c/ds620.h
@@ -0,0 +1,21 @@
+#ifndef _LINUX_DS620_H
+#define _LINUX_DS620_H
+
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+/* platform data for the DS620 temperature sensor and thermostat */
+
+struct ds620_platform_data {
+	/*
+	 *  Thermostat output pin PO mode:
+	 *  0 = always low (default)
+	 *  1 = TH_LOW
+	 *  2 = TH_HIGH
+	 *
+	 * (see Documentation/hwmon/ds620)
+	 */
+	bool pomode;
+};
+
+#endif /* _LINUX_DS620_H */

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (16 preceding siblings ...)
  2011-01-09  0:01 ` Roland Stigge
@ 2011-01-09  3:59 ` Guenter Roeck
  2011-01-09 11:34 ` Roland Stigge
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-09  3:59 UTC (permalink / raw)
  To: lm-sensors

On Sat, Jan 08, 2011 at 07:01:14PM -0500, Roland Stigge wrote:
> Hi,
> 
> On 08/01/11 19:54, Guenter Roeck wrote:
> > couple of comments below.
> 
> Thanks again for your suggestions! I'm attaching the latest version with
> your ideas included.
> 
> >> +The PO output pin is always active-low.
> > 
> > What is the point of configuring PO1 if you set PO2 such that PO is always low ?
> 
> Maybe the above was a bit misleading, though correct: "always
> active-low" wasn't intended to mean "always low", but instead "low when
> active". :-) Nevertheless, I clarified it. ("The PO output pin of the
> DS620 operates active-low.").
> 
> Thanks,
> 
> Roland

> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
Almost ... see below.

> diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
> new file mode 100644
> index 0000000..0c765b0
> --- /dev/null
> +++ b/Documentation/hwmon/ds620
> @@ -0,0 +1,34 @@
> +Kernel driver ds620
> +=========> +
> +Supported chips:
> +  * Dallas Semiconductor DS620
> +    Prefix: 'ds620'
> +    Datasheet: Publicly available at the Dallas Semiconductor website
> +               http://www.dalsemi.com/
> +
> +Authors:
> +        Roland Stigge <stigge@antcom.de>
> +        based on ds1621.c by
> +        Christian W. Zuckschwerdt <zany@triq.net>
> +
> +Description
> +-----------
> +
> +The DS620 is a (one instance) digital thermometer and thermostat. It has both
> +high and low temperature limits which can be user defined (i.e.  programmed
> +into non-volatile on-chip registers). Temperature range is -55 degree Celsius
> +to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
> +returned via sysfs displays post decimal positions.
> +
> +The thermostat function works as follows: When configured via platform_data
> +(struct ds620_platform_data) .pomode = 0 (default), the thermostat output pin
> +PO is always low. If .pomode = 1, the thermostat is in TH_LOW mode. I.e., the
> +output pin PO becomes active when the temperature falls below temp1_min and
> +stays active until the temperature goes above temp1_max.
> +
> +Likewise, with .pomode = 2, the thermostat is in TH_HIGH mode. I.e., the PO
> +output pin becomes active when the temperature goes above temp1_max and stays
> +active until the temperature falls below temp1_min.
> +
Datasheet does not say TH_HIGH or TH_LOW, but uses PO-HIGH and PO-LOW. Might be better
to use that terminology to avoid confusion.

> +The PO output pin of the DS620 operates active-low.
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index a56f6ad..700389a 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -274,6 +274,16 @@ config SENSORS_ATXP1
>  	  This driver can also be built as a module.  If so, the module
>  	  will be called atxp1.
>  
> +config SENSORS_DS620
> +	tristate "Dallas Semiconductor DS620"
> +	depends on I2C
> +	help
> +	  If you say yes here you get support for Dallas Semiconductor
> +	  DS620 sensor chip.
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called ds620.
> +
>  config SENSORS_DS1621
>  	tristate "Dallas Semiconductor DS1621 and DS1625"
>  	depends on I2C
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 2479b3d..42542d7 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
>  obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
>  obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
>  obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
> +obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
>  obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
>  obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
>  obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
> diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
> new file mode 100644
> index 0000000..624950d
> --- /dev/null
> +++ b/drivers/hwmon/ds620.c
> @@ -0,0 +1,335 @@
> +/*
> + *  ds620.c - Support for temperature sensor and thermostat DS620
> + *
> + *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
> + *
> + *  based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
> + *
> + *  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
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, write to the Free Software
> + *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/jiffies.h>
> +#include <linux/i2c.h>
> +#include <linux/hwmon.h>
> +#include <linux/hwmon-sysfs.h>
> +#include <linux/err.h>
> +#include <linux/mutex.h>
> +#include <linux/sysfs.h>
> +#include <linux/i2c/ds620.h>
> +
> +/*
> + * Many DS620 constants specified below
> + *  15   14   13   12   11   10   09    08
> + * |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT|
> + *
> + *  07   06   05   04   03   02   01    00
> + * |PO2 |PO1 |A2  |A1  |A0  |    |     |     |
> + */
> +#define DS620_REG_CONFIG_DONE		0x8000
> +#define DS620_REG_CONFIG_NVB		0x4000
> +#define DS620_REG_CONFIG_THF		0x2000
> +#define DS620_REG_CONFIG_TLF		0x1000
> +#define DS620_REG_CONFIG_R1		0x0800
> +#define DS620_REG_CONFIG_R0		0x0400
> +#define DS620_REG_CONFIG_AUTOC		0x0200
> +#define DS620_REG_CONFIG_1SHOT		0x0100
> +#define DS620_REG_CONFIG_PO2		0x0080
> +#define DS620_REG_CONFIG_PO1		0x0040
> +#define DS620_REG_CONFIG_A2		0x0020
> +#define DS620_REG_CONFIG_A1		0x0010
> +#define DS620_REG_CONFIG_A0		0x0008
> +
> +/* The DS620 registers */
> +static const u8 DS620_REG_TEMP[3] = {
> +	0xAA,			/* input, word, RO */
> +	0xA2,			/* min, word, RW */
> +	0xA0,			/* max, word, RW */
> +};
> +
> +#define DS620_REG_CONF		0xAC	/* word, RW */
> +#define DS620_COM_START		0x51	/* no data */
> +#define DS620_COM_STOP		0x22	/* no data */
> +
> +/* Each client has this additional data */
> +struct ds620_data {
> +	struct device *hwmon_dev;
> +	struct mutex update_lock;
> +	char valid;		/* !=0 if following fields are valid */
> +	unsigned long last_updated;	/* In jiffies */
> +
> +	u16 temp[3];		/* Register values, word */
> +};
> +
> +/*
> + *  Temperature registers are word-sized.
> + *  DS620 uses a high-byte first convention, which is exactly opposite to
> + *  the SMBus standard.
> + */
> +static int ds620_read_temp(struct i2c_client *client, u8 reg)
> +{
> +	int ret;
> +
> +	ret = i2c_smbus_read_word_data(client, reg);
> +	if (ret < 0)
> +		return ret;
> +	return swab16(ret);
> +}
> +
> +static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
> +{
> +	return i2c_smbus_write_word_data(client, reg, swab16(value));
> +}
> +
> +static void ds620_init_client(struct i2c_client *client)
> +{
> +	struct ds620_platform_data *ds620_info = client->dev.platform_data;
> +	u16 conf, new_conf;
> +
> +	new_conf = conf > +	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
> +
> +	/* switch to continuous conversion mode */
> +	new_conf &= ~DS620_REG_CONFIG_1SHOT;
> +	/* thermostat mode according to platform data */
> +	if (ds620_info && ds620_info->pomode = 1)
> +		new_conf &= ~DS620_REG_CONFIG_PO1; /* TH_LOW */
> +	else if (ds620_info && ds620_info->pomode = 2)
> +		new_conf |= DS620_REG_CONFIG_PO1; /* TH_HIGH */
> +	else
> +		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */

Hmm .. this code never sets PO2, but only resets it.
Sure, it is high by default, but you don't really know if it was set to low
by the BIOS. To be sure, you might want to set it high if enabled.


> +	/* with highest precision */
> +	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
> +
> +	if (conf != new_conf)
> +		i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +					  swab16(new_conf));
> +
> +	/* start conversion */
> +	i2c_smbus_write_byte(client, DS620_COM_START);
> +}
> +
> +static struct ds620_data *ds620_update_client(struct device *dev)
> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +	struct ds620_data *ret = data;
> +
> +	mutex_lock(&data->update_lock);
> +
> +	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
> +	    || !data->valid) {
> +		int i;
> +		int res;
> +
> +		dev_dbg(&client->dev, "Starting ds620 update\n");
> +
> +		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
> +			res = ds620_read_temp(client,
> +					      DS620_REG_TEMP[i]);
> +			if (res < 0) {
> +				ret = ERR_PTR(res);
> +				goto abort;
> +			}
> +
> +			data->temp[i] = res;
> +		}
> +
> +		data->last_updated = jiffies;
> +		data->valid = 1;
> +	}
> +abort:
> +	mutex_unlock(&data->update_lock);
> +
> +	return ret;
> +}
> +
> +static ssize_t show_temp(struct device *dev, struct device_attribute *da,
> +			 char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
> +}
> +
> +static ssize_t set_temp(struct device *dev, struct device_attribute *da,
> +			const char *buf, size_t count)
> +{
> +	int res;
> +	long val;
> +
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	res = strict_strtol(buf, 10, &val);
> +
> +	if (res)
> +		return res;
> +
> +	val = (val * 10 / 625) * 8;
> +
> +	mutex_lock(&data->update_lock);
> +	data->temp[attr->index] = val;
> +	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
> +			 data->temp[attr->index]);
> +	mutex_unlock(&data->update_lock);
> +	return count;
> +}
> +
> +static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
> +			  char *buf)
> +{
> +	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
> +	struct ds620_data *data = ds620_update_client(dev);
> +	struct i2c_client *client = to_i2c_client(dev);
> +	u16 conf, new_conf;
> +	int res;
> +
> +	if (IS_ERR(data))
> +		return PTR_ERR(data);
> +
> +	/* reset alarms if necessary */
> +	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
> +	if (res < 0)
> +		return res;
> +
> +	conf = swab16(res);
> +	new_conf = conf;
> +	new_conf &= ~attr->index;
> +	if (conf != new_conf) {
> +		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
> +						swab16(new_conf));
> +		if (res < 0)
> +			return res;
> +	}
> +
> +	return sprintf(buf, "%d\n", !!(conf & attr->index));
> +}
> +
> +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
> +static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
> +static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
> +static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_TLF);
> +static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
> +			  DS620_REG_CONFIG_THF);
> +
> +static struct attribute *ds620_attributes[] = {
> +	&sensor_dev_attr_temp1_input.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max.dev_attr.attr,
> +	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
> +	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group ds620_group = {
> +	.attrs = ds620_attributes,
> +};
> +
> +static int ds620_probe(struct i2c_client *client,
> +		       const struct i2c_device_id *id)
> +{
> +	struct ds620_data *data;
> +	int err;
> +
> +	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
> +	if (!data) {
> +		err = -ENOMEM;
> +		goto exit;
> +	}
> +
> +	i2c_set_clientdata(client, data);
> +	mutex_init(&data->update_lock);
> +
> +	/* Initialize the DS620 chip */
> +	ds620_init_client(client);
> +
> +	/* Register sysfs hooks */
> +	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
> +	if (err)
> +		goto exit_free;
> +
> +	data->hwmon_dev = hwmon_device_register(&client->dev);
> +	if (IS_ERR(data->hwmon_dev)) {
> +		err = PTR_ERR(data->hwmon_dev);
> +		goto exit_remove_files;
> +	}
> +
> +	dev_info(&client->dev, "temperature sensor found\n");
> +
> +	return 0;
> +
> +exit_remove_files:
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +exit_free:
> +	kfree(data);
> +exit:
> +	return err;
> +}
> +
> +static int ds620_remove(struct i2c_client *client)
> +{
> +	struct ds620_data *data = i2c_get_clientdata(client);
> +
> +	hwmon_device_unregister(data->hwmon_dev);
> +	sysfs_remove_group(&client->dev.kobj, &ds620_group);
> +
> +	kfree(data);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id ds620_id[] = {
> +	{"ds620", 0},
> +	{}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, ds620_id);
> +
> +/* This is the driver that will be inserted */
> +static struct i2c_driver ds620_driver = {
> +	.class = I2C_CLASS_HWMON,
> +	.driver = {
> +		   .name = "ds620",
> +	},
> +	.probe = ds620_probe,
> +	.remove = ds620_remove,
> +	.id_table = ds620_id,
> +};
> +
> +static int __init ds620_init(void)
> +{
> +	return i2c_add_driver(&ds620_driver);
> +}
> +
> +static void __exit ds620_exit(void)
> +{
> +	i2c_del_driver(&ds620_driver);
> +}
> +
> +MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
> +MODULE_DESCRIPTION("DS620 driver");
> +MODULE_LICENSE("GPL");
> +
> +module_init(ds620_init);
> +module_exit(ds620_exit);
> diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
> new file mode 100644
> index 0000000..141c043
> --- /dev/null
> +++ b/include/linux/i2c/ds620.h
> @@ -0,0 +1,21 @@
> +#ifndef _LINUX_DS620_H
> +#define _LINUX_DS620_H
> +
> +#include <linux/types.h>
> +#include <linux/i2c.h>
> +
> +/* platform data for the DS620 temperature sensor and thermostat */
> +
> +struct ds620_platform_data {
> +	/*
> +	 *  Thermostat output pin PO mode:
> +	 *  0 = always low (default)
> +	 *  1 = TH_LOW
> +	 *  2 = TH_HIGH
> +	 *
> +	 * (see Documentation/hwmon/ds620)
> +	 */
> +	bool pomode;

Difficult to assign 2 to a bool ... needs int here.

> +};
> +
> +#endif /* _LINUX_DS620_H */


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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (17 preceding siblings ...)
  2011-01-09  3:59 ` Guenter Roeck
@ 2011-01-09 11:34 ` Roland Stigge
  2011-01-09 14:31 ` Roland Stigge
  2011-01-09 15:55 ` Guenter Roeck
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-09 11:34 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 09/01/11 04:59, Guenter Roeck wrote:
>> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
>>
>> Signed-off-by: Roland Stigge <stigge@antcom.de>
>>
> Almost ... see below.

Update attached. :-)

bye,
  Roland

[-- Attachment #2: ds620.patch --]
[-- Type: text/x-patch, Size: 12583 bytes --]

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..1fbe3cd
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,34 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
+The thermostat function works as follows: When configured via platform_data
+(struct ds620_platform_data) .pomode == 0 (default), the thermostat output pin
+PO is always low. If .pomode == 1, the thermostat is in PO_LOW mode. I.e., the
+output pin PO becomes active when the temperature falls below temp1_min and
+stays active until the temperature goes above temp1_max.
+
+Likewise, with .pomode == 2, the thermostat is in PO_HIGH mode. I.e., the PO
+output pin becomes active when the temperature goes above temp1_max and stays
+active until the temperature falls below temp1_min.
+
+The PO output pin of the DS620 operates active-low.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..257957c
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,337 @@
+/*
+ *  ds620.c - Support for temperature sensor and thermostat DS620
+ *
+ *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
+ *
+ *  based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/i2c/ds620.h>
+
+/*
+ * Many DS620 constants specified below
+ *  15   14   13   12   11   10   09    08
+ * |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT|
+ *
+ *  07   06   05   04   03   02   01    00
+ * |PO2 |PO1 |A2  |A1  |A0  |    |     |     |
+ */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+};
+
+/*
+ *  Temperature registers are word-sized.
+ *  DS620 uses a high-byte first convention, which is exactly opposite to
+ *  the SMBus standard.
+ */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	struct ds620_platform_data *ds620_info = client->dev.platform_data;
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* already high at power-on, but don't trust the BIOS! */
+	new_conf |= DS620_REG_CONFIG_PO2;
+	/* thermostat mode according to platform data */
+	if (ds620_info && ds620_info->pomode == 1)
+		new_conf &= ~DS620_REG_CONFIG_PO1; /* PO_LOW */
+	else if (ds620_info && ds620_info->pomode == 2)
+		new_conf |= DS620_REG_CONFIG_PO1; /* PO_HIGH */
+	else
+		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf)
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 conf, new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	conf = swab16(res);
+	new_conf = conf;
+	new_conf &= ~attr->index;
+	if (conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);
diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
new file mode 100644
index 0000000..736bb87
--- /dev/null
+++ b/include/linux/i2c/ds620.h
@@ -0,0 +1,21 @@
+#ifndef _LINUX_DS620_H
+#define _LINUX_DS620_H
+
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+/* platform data for the DS620 temperature sensor and thermostat */
+
+struct ds620_platform_data {
+	/*
+	 *  Thermostat output pin PO mode:
+	 *  0 = always low (default)
+	 *  1 = PO_LOW
+	 *  2 = PO_HIGH
+	 *
+	 * (see Documentation/hwmon/ds620)
+	 */
+	int pomode;
+};
+
+#endif /* _LINUX_DS620_H */

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (18 preceding siblings ...)
  2011-01-09 11:34 ` Roland Stigge
@ 2011-01-09 14:31 ` Roland Stigge
  2011-01-09 15:55 ` Guenter Roeck
  20 siblings, 0 replies; 22+ messages in thread
From: Roland Stigge @ 2011-01-09 14:31 UTC (permalink / raw)
  To: lm-sensors

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

Hi,

On 09/01/11 04:59, Guenter Roeck wrote:
>> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
>>
>> Signed-off-by: Roland Stigge <stigge@antcom.de>
>>
> Almost ... see below.

Update attached. :-)

bye,
  Roland


[-- Attachment #2: ds620.patch --]
[-- Type: text/x-patch, Size: 12711 bytes --]

HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat

Signed-off-by: Roland Stigge <stigge@antcom.de>

diff --git a/Documentation/hwmon/ds620 b/Documentation/hwmon/ds620
new file mode 100644
index 0000000..1fbe3cd
--- /dev/null
+++ b/Documentation/hwmon/ds620
@@ -0,0 +1,34 @@
+Kernel driver ds620
+===================
+
+Supported chips:
+  * Dallas Semiconductor DS620
+    Prefix: 'ds620'
+    Datasheet: Publicly available at the Dallas Semiconductor website
+               http://www.dalsemi.com/
+
+Authors:
+        Roland Stigge <stigge@antcom.de>
+        based on ds1621.c by
+        Christian W. Zuckschwerdt <zany@triq.net>
+
+Description
+-----------
+
+The DS620 is a (one instance) digital thermometer and thermostat. It has both
+high and low temperature limits which can be user defined (i.e.  programmed
+into non-volatile on-chip registers). Temperature range is -55 degree Celsius
+to +125. Between 0 and 70 degree Celsius, accuracy is 0.5 Kelvin. The value
+returned via sysfs displays post decimal positions.
+
+The thermostat function works as follows: When configured via platform_data
+(struct ds620_platform_data) .pomode == 0 (default), the thermostat output pin
+PO is always low. If .pomode == 1, the thermostat is in PO_LOW mode. I.e., the
+output pin PO becomes active when the temperature falls below temp1_min and
+stays active until the temperature goes above temp1_max.
+
+Likewise, with .pomode == 2, the thermostat is in PO_HIGH mode. I.e., the PO
+output pin becomes active when the temperature goes above temp1_max and stays
+active until the temperature falls below temp1_min.
+
+The PO output pin of the DS620 operates active-low.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index a56f6ad..700389a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -274,6 +274,16 @@ config SENSORS_ATXP1
 	  This driver can also be built as a module.  If so, the module
 	  will be called atxp1.
 
+config SENSORS_DS620
+	tristate "Dallas Semiconductor DS620"
+	depends on I2C
+	help
+	  If you say yes here you get support for Dallas Semiconductor
+	  DS620 sensor chip.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds620.
+
 config SENSORS_DS1621
 	tristate "Dallas Semiconductor DS1621 and DS1625"
 	depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2479b3d..42542d7 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_ATXP1)	+= atxp1.o
 obj-$(CONFIG_SENSORS_CORETEMP)	+= coretemp.o
 obj-$(CONFIG_SENSORS_PKGTEMP)	+= pkgtemp.o
 obj-$(CONFIG_SENSORS_DME1737)	+= dme1737.o
+obj-$(CONFIG_SENSORS_DS620)	+= ds620.o
 obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644
index 0000000..257957c
--- /dev/null
+++ b/drivers/hwmon/ds620.c
@@ -0,0 +1,337 @@
+/*
+ *  ds620.c - Support for temperature sensor and thermostat DS620
+ *
+ *  Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
+ *
+ *  based on ds1621.c by Christian W. Zuckschwerdt  <zany@triq.net>
+ *
+ *  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
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/i2c/ds620.h>
+
+/*
+ * Many DS620 constants specified below
+ *  15   14   13   12   11   10   09    08
+ * |Done|NVB |THF |TLF |R1  |R0  |AUTOC|1SHOT|
+ *
+ *  07   06   05   04   03   02   01    00
+ * |PO2 |PO1 |A2  |A1  |A0  |    |     |     |
+ */
+#define DS620_REG_CONFIG_DONE		0x8000
+#define DS620_REG_CONFIG_NVB		0x4000
+#define DS620_REG_CONFIG_THF		0x2000
+#define DS620_REG_CONFIG_TLF		0x1000
+#define DS620_REG_CONFIG_R1		0x0800
+#define DS620_REG_CONFIG_R0		0x0400
+#define DS620_REG_CONFIG_AUTOC		0x0200
+#define DS620_REG_CONFIG_1SHOT		0x0100
+#define DS620_REG_CONFIG_PO2		0x0080
+#define DS620_REG_CONFIG_PO1		0x0040
+#define DS620_REG_CONFIG_A2		0x0020
+#define DS620_REG_CONFIG_A1		0x0010
+#define DS620_REG_CONFIG_A0		0x0008
+
+/* The DS620 registers */
+static const u8 DS620_REG_TEMP[3] = {
+	0xAA,			/* input, word, RO */
+	0xA2,			/* min, word, RW */
+	0xA0,			/* max, word, RW */
+};
+
+#define DS620_REG_CONF		0xAC	/* word, RW */
+#define DS620_COM_START		0x51	/* no data */
+#define DS620_COM_STOP		0x22	/* no data */
+
+/* Each client has this additional data */
+struct ds620_data {
+	struct device *hwmon_dev;
+	struct mutex update_lock;
+	char valid;		/* !=0 if following fields are valid */
+	unsigned long last_updated;	/* In jiffies */
+
+	u16 temp[3];		/* Register values, word */
+};
+
+/*
+ *  Temperature registers are word-sized.
+ *  DS620 uses a high-byte first convention, which is exactly opposite to
+ *  the SMBus standard.
+ */
+static int ds620_read_temp(struct i2c_client *client, u8 reg)
+{
+	int ret;
+
+	ret = i2c_smbus_read_word_data(client, reg);
+	if (ret < 0)
+		return ret;
+	return swab16(ret);
+}
+
+static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
+{
+	return i2c_smbus_write_word_data(client, reg, swab16(value));
+}
+
+static void ds620_init_client(struct i2c_client *client)
+{
+	struct ds620_platform_data *ds620_info = client->dev.platform_data;
+	u16 conf, new_conf;
+
+	new_conf = conf =
+	    swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF));
+
+	/* switch to continuous conversion mode */
+	new_conf &= ~DS620_REG_CONFIG_1SHOT;
+	/* already high at power-on, but don't trust the BIOS! */
+	new_conf |= DS620_REG_CONFIG_PO2;
+	/* thermostat mode according to platform data */
+	if (ds620_info && ds620_info->pomode == 1)
+		new_conf &= ~DS620_REG_CONFIG_PO1; /* PO_LOW */
+	else if (ds620_info && ds620_info->pomode == 2)
+		new_conf |= DS620_REG_CONFIG_PO1; /* PO_HIGH */
+	else
+		new_conf &= ~DS620_REG_CONFIG_PO2; /* always low */
+	/* with highest precision */
+	new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
+
+	if (conf != new_conf)
+		i2c_smbus_write_word_data(client, DS620_REG_CONF,
+					  swab16(new_conf));
+
+	/* start conversion */
+	i2c_smbus_write_byte(client, DS620_COM_START);
+}
+
+static struct ds620_data *ds620_update_client(struct device *dev)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+	struct ds620_data *ret = data;
+
+	mutex_lock(&data->update_lock);
+
+	if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+	    || !data->valid) {
+		int i;
+		int res;
+
+		dev_dbg(&client->dev, "Starting ds620 update\n");
+
+		for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
+			res = ds620_read_temp(client,
+					      DS620_REG_TEMP[i]);
+			if (res < 0) {
+				ret = ERR_PTR(res);
+				goto abort;
+			}
+
+			data->temp[i] = res;
+		}
+
+		data->last_updated = jiffies;
+		data->valid = 1;
+	}
+abort:
+	mutex_unlock(&data->update_lock);
+
+	return ret;
+}
+
+static ssize_t show_temp(struct device *dev, struct device_attribute *da,
+			 char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	return sprintf(buf, "%d\n", ((data->temp[attr->index] / 8) * 625) / 10);
+}
+
+static ssize_t set_temp(struct device *dev, struct device_attribute *da,
+			const char *buf, size_t count)
+{
+	int res;
+	long val;
+
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct i2c_client *client = to_i2c_client(dev);
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	res = strict_strtol(buf, 10, &val);
+
+	if (res)
+		return res;
+
+	val = (val * 10 / 625) * 8;
+
+	mutex_lock(&data->update_lock);
+	data->temp[attr->index] = val;
+	ds620_write_temp(client, DS620_REG_TEMP[attr->index],
+			 data->temp[attr->index]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
+			  char *buf)
+{
+	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+	struct ds620_data *data = ds620_update_client(dev);
+	struct i2c_client *client = to_i2c_client(dev);
+	u16 conf, new_conf;
+	int res;
+
+	if (IS_ERR(data))
+		return PTR_ERR(data);
+
+	/* reset alarms if necessary */
+	res = i2c_smbus_read_word_data(client, DS620_REG_CONF);
+	if (res < 0)
+		return res;
+
+	conf = swab16(res);
+	new_conf = conf;
+	new_conf &= ~attr->index;
+	if (conf != new_conf) {
+		res = i2c_smbus_write_word_data(client, DS620_REG_CONF,
+						swab16(new_conf));
+		if (res < 0)
+			return res;
+	}
+
+	return sprintf(buf, "%d\n", !!(conf & attr->index));
+}
+
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_TLF);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
+			  DS620_REG_CONFIG_THF);
+
+static struct attribute *ds620_attributes[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp1_min.dev_attr.attr,
+	&sensor_dev_attr_temp1_max.dev_attr.attr,
+	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group ds620_group = {
+	.attrs = ds620_attributes,
+};
+
+static int ds620_probe(struct i2c_client *client,
+		       const struct i2c_device_id *id)
+{
+	struct ds620_data *data;
+	int err;
+
+	data = kzalloc(sizeof(struct ds620_data), GFP_KERNEL);
+	if (!data) {
+		err = -ENOMEM;
+		goto exit;
+	}
+
+	i2c_set_clientdata(client, data);
+	mutex_init(&data->update_lock);
+
+	/* Initialize the DS620 chip */
+	ds620_init_client(client);
+
+	/* Register sysfs hooks */
+	err = sysfs_create_group(&client->dev.kobj, &ds620_group);
+	if (err)
+		goto exit_free;
+
+	data->hwmon_dev = hwmon_device_register(&client->dev);
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_remove_files;
+	}
+
+	dev_info(&client->dev, "temperature sensor found\n");
+
+	return 0;
+
+exit_remove_files:
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+exit_free:
+	kfree(data);
+exit:
+	return err;
+}
+
+static int ds620_remove(struct i2c_client *client)
+{
+	struct ds620_data *data = i2c_get_clientdata(client);
+
+	hwmon_device_unregister(data->hwmon_dev);
+	sysfs_remove_group(&client->dev.kobj, &ds620_group);
+
+	kfree(data);
+
+	return 0;
+}
+
+static const struct i2c_device_id ds620_id[] = {
+	{"ds620", 0},
+	{}
+};
+
+MODULE_DEVICE_TABLE(i2c, ds620_id);
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ds620_driver = {
+	.class = I2C_CLASS_HWMON,
+	.driver = {
+		   .name = "ds620",
+	},
+	.probe = ds620_probe,
+	.remove = ds620_remove,
+	.id_table = ds620_id,
+};
+
+static int __init ds620_init(void)
+{
+	return i2c_add_driver(&ds620_driver);
+}
+
+static void __exit ds620_exit(void)
+{
+	i2c_del_driver(&ds620_driver);
+}
+
+MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
+MODULE_DESCRIPTION("DS620 driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds620_init);
+module_exit(ds620_exit);
diff --git a/include/linux/i2c/ds620.h b/include/linux/i2c/ds620.h
new file mode 100644
index 0000000..736bb87
--- /dev/null
+++ b/include/linux/i2c/ds620.h
@@ -0,0 +1,21 @@
+#ifndef _LINUX_DS620_H
+#define _LINUX_DS620_H
+
+#include <linux/types.h>
+#include <linux/i2c.h>
+
+/* platform data for the DS620 temperature sensor and thermostat */
+
+struct ds620_platform_data {
+	/*
+	 *  Thermostat output pin PO mode:
+	 *  0 = always low (default)
+	 *  1 = PO_LOW
+	 *  2 = PO_HIGH
+	 *
+	 * (see Documentation/hwmon/ds620)
+	 */
+	int pomode;
+};
+
+#endif /* _LINUX_DS620_H */

[-- 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

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

* Re: [lm-sensors] [PATCH] Support for DS620
  2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
                   ` (19 preceding siblings ...)
  2011-01-09 14:31 ` Roland Stigge
@ 2011-01-09 15:55 ` Guenter Roeck
  20 siblings, 0 replies; 22+ messages in thread
From: Guenter Roeck @ 2011-01-09 15:55 UTC (permalink / raw)
  To: lm-sensors

On Sun, Jan 09, 2011 at 09:31:39AM -0500, Roland Stigge wrote:
> Hi,
> 
> On 09/01/11 04:59, Guenter Roeck wrote:
> >> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
> >>
> >> Signed-off-by: Roland Stigge <stigge@antcom.de>
> >>
> > Almost ... see below.
> 
> Update attached. :-)
> 
> bye,
>   Roland
> 

> HWMON driver for Dallas Semiconductor DS620 temperature sensor and thermostat
> 
> Signed-off-by: Roland Stigge <stigge@antcom.de>
> 
Applied to -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] 22+ messages in thread

end of thread, other threads:[~2011-01-09 15:55 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 20:07 [lm-sensors] [PATCH] Support for DS620 Roland Stigge
2010-12-23 19:55 ` Guenter Roeck
2010-12-25 13:24 ` Roland Stigge
2010-12-25 18:34 ` Guenter Roeck
2010-12-25 21:10 ` Roland Stigge
2010-12-25 22:13 ` Guenter Roeck
2010-12-25 23:05 ` Roland Stigge
2010-12-26  3:18 ` Guenter Roeck
2010-12-26 23:20 ` Roland Stigge
2011-01-02 23:31 ` Guenter Roeck
2011-01-06 18:03 ` Jean Delvare
2011-01-07  0:05 ` Roland Stigge
2011-01-07  1:39 ` Guenter Roeck
2011-01-07 10:24 ` Roland Stigge
2011-01-07 11:34 ` Guenter Roeck
2011-01-08 17:56 ` Roland Stigge
2011-01-08 18:54 ` Guenter Roeck
2011-01-09  0:01 ` Roland Stigge
2011-01-09  3:59 ` Guenter Roeck
2011-01-09 11:34 ` Roland Stigge
2011-01-09 14:31 ` Roland Stigge
2011-01-09 15:55 ` Guenter Roeck

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.