Skip to contentSkip to conversation

Add driver for Dallas DS1682 elapsed time recorder

PATCH In review Grant Likely 3 participants 8 messages May 13, 2007 – May 15, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add driver for Dallas DS1682 elapsed time recorder

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.

 drivers/i2c/chips/ds1682.c |  270 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 0 deletions(-)
drivers/i2c/chips/ds1682.c new file +270 -0
new file mode 100644
index 0000000..0a4a89e
@@ -0,0 +1,270 @@
+/*
+ * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
+ *
+ * Written by: Grant Likely <[email protected]>
+ *
+ * Copyright (C) 2007 Secret Lab Technologies Ltd.
+ * Copyright (C) 2005 James Chapman <[email protected]>
+ * Copyright (C) 2000 Russell King
+ *
+ * Derived from ds1337 real time clock device driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * The DS1682 elapsed timer recorder is a simple device that implements
+ * one elapsed time counter, one event counter, an alarm signal and 10
+ * bytes of general purpose EEPROM.
+ *
+ * This driver provides access to the DS1682 counters and user data via
+ * the sysfs.  The following attributes are added to the device node:
+ *     elapsed_time (u32): Total elapsed event time in ms resolution
+ *     alarm_time (u32): When elapsed time exceeds the value in alarm_time,
+ *                       then the alarm pin is asserted.
+ *     event_count (u16): number of times the event pin has gone low.
+ *     eeprom (u8[10]): general purpose EEPROM
+ *
+ * Counter registers and user data are both read/write unless the device
+ * has been write protected.  This driver does not support turning off write
+ * protection.  Once write protection is turned on, it is impossible to
+ * turn it off again, so I have left the feature out of this driver to avoid
+ * accidental enabling, but it is trivial to add write protect support.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/string.h>
+#include <linux/list.h>
+#include <linux/sysfs.h>
+#include <linux/ctype.h>
+#include <linux/hwmon-sysfs.h>
+
+/* Device registers */
+#define DS1682_REG_CONFIG		0x00
+#define DS1682_REG_ALARM		0x01
+#define DS1682_REG_ELAPSED		0x05
+#define DS1682_REG_EVT_CNTR		0x09
+#define DS1682_REG_EEPROM		0x0b
+#define DS1682_REG_RESET		0x1d
+#define DS1682_REG_WRITE_DISABLE	0x1e
+#define DS1682_REG_WRITE_MEM_DISABLE	0x1f
+
+#define DS1682_EEPROM_SIZE		10
+
+/*
+ * Generic counter attributes
+ */
+static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	__le32 val = 0;
+	int rc;
+
+	dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
+
+	/* Read the register */
+	rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
+					   (u8 *) & val);
+	if (rc < 0)
+		return -EIO;
+
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale them up to milliseconds */
+	if (sattr->nr == 4)
+		return sprintf(buf, "%lli\n", ((u64) le32_to_cpu(val)) * 250);
+
+	/* Format the output string and return # of bytes */
+	return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
+}
+
+static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	char *endp;
+	u64 val;
+	__le32 val_le;
+	int rc;
+
+	dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
+
+	/* Decode input */
+	val = simple_strtoull(buf, &endp, 0);
+	if (buf == endp) {
+		dev_dbg(dev, "input string not a number\n");
+		return -EIO;
+	}
+
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale input down to quarter-seconds */
+	if (sattr->nr == 4)
+		do_div(val, 250);
+
+	/* write out the value */
+	val_le = cpu_to_le32(val);
+	rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
+					    (u8 *) & val);
+	if (rc < 0) {
+		dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
+			sattr->index, sattr->nr);
+		return -EIO;
+	}
+
+	return count;
+}
+
+/*
+ * Simple register attributes
+ */
+SENSOR_DEVICE_ATTR_2(config, S_IRUGO, ds1682_show, NULL, DS1682_REG_CONFIG, 1);
+SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ELAPSED);
+SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ALARM);
+SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     2, DS1682_REG_EVT_CNTR);
+
+static const struct attribute_group ds1682_group = {
+	.attrs = (struct attribute *[]) {
+		&sensor_dev_attr_config.dev_attr.attr,
+		&sensor_dev_attr_elapsed_time.dev_attr.attr,
+		&sensor_dev_attr_alarm_time.dev_attr.attr,
+		&sensor_dev_attr_event_count.dev_attr.attr,
+		NULL,
+	},
+};
+
+/*
+ * User data attribute
+ */
+static ssize_t ds1682_eeprom_read(struct kobject *kobj, char *buf, loff_t off,
+				  size_t count)
+{
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
+	int rc;
+
+	dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
+
+	if (off > DS1682_EEPROM_SIZE)
+		return 0;
+
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
+
+	rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf);
+	if (rc < 0)
+		return -EIO;
+
+	return count;
+}
+
+static ssize_t ds1682_eeprom_write(struct kobject *kobj, char *buf, loff_t off,
+				   size_t count)
+{
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
+
+	dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
+
+	if (off >= DS1682_EEPROM_SIZE)
+		return -ENOSPC;
+
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
+
+	/* Write out to the device */
+	if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf) < 0)
+		return -EIO;
+
+	return count;
+}
+
+static struct bin_attribute ds1682_eeprom_attr = {
+	.attr = {
+		.name = "eeprom",
+		.mode = S_IRUGO | S_IWUSR,
+		.owner = THIS_MODULE,
+	},
+	.size = DS1682_EEPROM_SIZE,
+	.read = ds1682_eeprom_read,
+	.write = ds1682_eeprom_write,
+};
+
+/*
+ * Called when a device is found at the ds1682 address
+ */
+static int ds1682_probe(struct i2c_client *client)
+{
+	int err = 0;
+
+	if (client->addr != 0x6b) {
+		dev_err(&client->dev, "%x is not a valid address\n",
+			client->addr);
+		return -ENODEV;
+	}
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_BYTE_DATA |
+				     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		dev_err(&client->dev, "i2c bus does not support the ds1682\n");
+		goto exit;
+	}
+
+	if (sysfs_create_group(&client->dev.kobj, &ds1682_group))
+		goto exit;
+
+	if (sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr))
+		goto exit_bin_attr;
+
+	return 0;
+
+      exit_bin_attr:
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
+      exit:
+	return err;
+}
+
+static int ds1682_remove(struct i2c_client *client)
+{
+	sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
+
+	return 0;
+}
+
+static struct i2c_driver ds1682_driver = {
+	.driver = {
+		.name = "ds1682",
+	},
+	.probe = ds1682_probe,
+	.remove = ds1682_remove,
+};
+
+static int __init ds1682_init(void)
+{
+	return i2c_add_driver(&ds1682_driver);
+}
+
+static void __exit ds1682_exit(void)
+{
+	i2c_del_driver(&ds1682_driver);
+}
+
+MODULE_AUTHOR("Grant Likely <[email protected]>");
+MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds1682_init);
+module_exit(ds1682_exit);
#1 lore raw

Hi Grant,

Quoted 5 lines · Grant Likely

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work

Can we see the corresponding architecture patch (device declaration)?

Quoted 5 lines

- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.

 drivers/i2c/chips/ds1682.c |  270 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 0 deletions(-)

Where have the changes to Kconfig and Makefile gone? Without them, this patch is a no-op.

BTW, the config option shouldn't be named SENSORS_DS1682 as your original patch had - this device isn't a sensor. It should be just "DS1682".

Quoted 7 lines
drivers/i2c/chips/ds1682.c new file +0 -0
new file mode 100644
index 0000000..0a4a89e

drivers/i2c/chips/ds1682.c line 10

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
@@ -0,0 +1,270 @@
+/*
+ * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
+ *
+ * Written by: Grant Likely <[email protected]>
+ *
+ * Copyright (C) 2007 Secret Lab Technologies Ltd.
+ * Copyright (C) 2005 James Chapman <[email protected]>
+ * Copyright (C) 2000 Russell King
+ *
+ * Derived from ds1337 real time clock device driver

Technically, this is the ds1337 driver on which James and Russell have a copyright, not yours. I don't think there is anything left from the code you originally copied from, BTW.

Quoted 62 lines
drivers/i2c/chips/ds1682.c new file +62 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * The DS1682 elapsed timer recorder is a simple device that implements
+ * one elapsed time counter, one event counter, an alarm signal and 10
+ * bytes of general purpose EEPROM.
+ *
+ * This driver provides access to the DS1682 counters and user data via
+ * the sysfs.  The following attributes are added to the device node:
+ *     elapsed_time (u32): Total elapsed event time in ms resolution
+ *     alarm_time (u32): When elapsed time exceeds the value in alarm_time,
+ *                       then the alarm pin is asserted.
+ *     event_count (u16): number of times the event pin has gone low.
+ *     eeprom (u8[10]): general purpose EEPROM
+ *
+ * Counter registers and user data are both read/write unless the device
+ * has been write protected.  This driver does not support turning off write
+ * protection.  Once write protection is turned on, it is impossible to
+ * turn it off again, so I have left the feature out of this driver to avoid
+ * accidental enabling, but it is trivial to add write protect support.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/string.h>
+#include <linux/list.h>
+#include <linux/sysfs.h>
+#include <linux/ctype.h>
+#include <linux/hwmon-sysfs.h>
+
+/* Device registers */
+#define DS1682_REG_CONFIG		0x00
+#define DS1682_REG_ALARM		0x01
+#define DS1682_REG_ELAPSED		0x05
+#define DS1682_REG_EVT_CNTR		0x09
+#define DS1682_REG_EEPROM		0x0b
+#define DS1682_REG_RESET		0x1d
+#define DS1682_REG_WRITE_DISABLE	0x1e
+#define DS1682_REG_WRITE_MEM_DISABLE	0x1f
+
+#define DS1682_EEPROM_SIZE		10
+
+/*
+ * Generic counter attributes
+ */
+static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	__le32 val = 0;
+	int rc;
+
+	dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
+

drivers/i2c/chips/ds1682.c line 82

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+	/* Read the register */
+	rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
+					   (u8 *) & val);
+	if (rc < 0)
+		return -EIO;
+
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale them up to milliseconds */
+	if (sattr->nr == 4)
+		return sprintf(buf, "%lli\n", ((u64) le32_to_cpu(val)) * 250);

%llu

Quoted 12 lines
drivers/i2c/chips/ds1682.c new file +12 -0
+
+	/* Format the output string and return # of bytes */
+	return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
+}
+
+static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	char *endp;
+	u64 val;

drivers/i2c/chips/ds1682.c line 104

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+	__le32 val_le;
+	int rc;
+
+	dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
+
+	/* Decode input */
+	val = simple_strtoull(buf, &endp, 0);
+	if (buf == endp) {
+		dev_dbg(dev, "input string not a number\n");
+		return -EIO;

Rather -EINVAL, this isn't an I/O error.

drivers/i2c/chips/ds1682.c line 115

Quoted 11 lines
drivers/i2c/chips/ds1682.c new file +11 -0
+	}
+
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale input down to quarter-seconds */
+	if (sattr->nr == 4)
+		do_div(val, 250);
+
+	/* write out the value */
+	val_le = cpu_to_le32(val);
+	rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
+					    (u8 *) & val);

Shouldn't this be (u8 *)&val_le?

drivers/i2c/chips/ds1682.c line 128

Quoted 13 lines
drivers/i2c/chips/ds1682.c new file +13 -0
+	if (rc < 0) {
+		dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
+			sattr->index, sattr->nr);
+		return -EIO;
+	}
+
+	return count;
+}
+
+/*
+ * Simple register attributes
+ */
+SENSOR_DEVICE_ATTR_2(config, S_IRUGO, ds1682_show, NULL, DS1682_REG_CONFIG, 1);

Bug! The last two arguments are swapped.

Also, I don't see the point of exporting this value to user-space, as the format is proprietary.

Quoted 6 lines
drivers/i2c/chips/ds1682.c new file +6 -0
+SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ELAPSED);
+SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ALARM);
+SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     2, DS1682_REG_EVT_CNTR);

drivers/i2c/chips/ds1682.c line 144

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+
+static const struct attribute_group ds1682_group = {
+	.attrs = (struct attribute *[]) {
+		&sensor_dev_attr_config.dev_attr.attr,
+		&sensor_dev_attr_elapsed_time.dev_attr.attr,
+		&sensor_dev_attr_alarm_time.dev_attr.attr,
+		&sensor_dev_attr_event_count.dev_attr.attr,
+		NULL,
+	},
+};

I'm not sure if all compilers support this.

Quoted 4 lines
drivers/i2c/chips/ds1682.c new file +4 -0
+
+/*
+ * User data attribute
+ */

drivers/i2c/chips/ds1682.c line 158

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+static ssize_t ds1682_eeprom_read(struct kobject *kobj, char *buf, loff_t off,
+				  size_t count)
+{
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
+	int rc;
+
+	dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
+
+	if (off > DS1682_EEPROM_SIZE)

Should be ">=", otherwise you might end up doing a 0-length I2C block read, which is bad.

Quoted 39 lines
drivers/i2c/chips/ds1682.c new file +39 -0
+		return 0;
+
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
+
+	rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf);
+	if (rc < 0)
+		return -EIO;
+
+	return count;
+}
+
+static ssize_t ds1682_eeprom_write(struct kobject *kobj, char *buf, loff_t off,
+				   size_t count)
+{
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
+
+	dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
+
+	if (off >= DS1682_EEPROM_SIZE)
+		return -ENOSPC;
+
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
+
+	/* Write out to the device */
+	if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf) < 0)
+		return -EIO;
+
+	return count;
+}
+
+static struct bin_attribute ds1682_eeprom_attr = {
+	.attr = {
+		.name = "eeprom",
+		.mode = S_IRUGO | S_IWUSR,

drivers/i2c/chips/ds1682.c line 207

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+		.owner = THIS_MODULE,
+	},
+	.size = DS1682_EEPROM_SIZE,
+	.read = ds1682_eeprom_read,
+	.write = ds1682_eeprom_write,
+};
+
+/*
+ * Called when a device is found at the ds1682 address
+ */

This comment is no longer true.

drivers/i2c/chips/ds1682.c line 216

Quoted 9 lines
drivers/i2c/chips/ds1682.c new file +9 -0
+static int ds1682_probe(struct i2c_client *client)
+{
+	int err = 0;
+
+	if (client->addr != 0x6b) {
+		dev_err(&client->dev, "%x is not a valid address\n",
+			client->addr);
+		return -ENODEV;
+	}

Why check this? You should trust the person who wrote the device definition in the platform code. The only reason why the older i2c chip drivers did address checks is because that was one preliminary device identification step. With the new model, you don't need to identify the device, you already know what's there as per architecture-level device declaration.

Not checking the address even has a benefit: if a compatible device exists (today or in the future) with a different address, we don't need to patch the driver to support it.

drivers/i2c/chips/ds1682.c line 220

Quoted 4 lines
drivers/i2c/chips/ds1682.c new file +4 -0
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_BYTE_DATA |
+				     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {

This no longer reflects what the driver is using.

drivers/i2c/chips/ds1682.c line 225

Quoted 5 lines
drivers/i2c/chips/ds1682.c new file +5 -0
+		dev_err(&client->dev, "i2c bus does not support the ds1682\n");
+		goto exit;
+	}
+
+	if (sysfs_create_group(&client->dev.kobj, &ds1682_group))

Missing "err = ".

drivers/i2c/chips/ds1682.c line 228

Quoted 3 lines
drivers/i2c/chips/ds1682.c new file +3 -0
+		goto exit;
+
+	if (sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr))

Missing "err = ".

Quoted 42 lines
drivers/i2c/chips/ds1682.c new file +42 -0
+		goto exit_bin_attr;
+
+	return 0;
+
+      exit_bin_attr:
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
+      exit:
+	return err;
+}
+
+static int ds1682_remove(struct i2c_client *client)
+{
+	sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
+
+	return 0;
+}
+
+static struct i2c_driver ds1682_driver = {
+	.driver = {
+		.name = "ds1682",
+	},
+	.probe = ds1682_probe,
+	.remove = ds1682_remove,
+};
+
+static int __init ds1682_init(void)
+{
+	return i2c_add_driver(&ds1682_driver);
+}
+
+static void __exit ds1682_exit(void)
+{
+	i2c_del_driver(&ds1682_driver);
+}
+
+MODULE_AUTHOR("Grant Likely <[email protected]>");
+MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver");
+MODULE_LICENSE("GPL");
+
+module_init(ds1682_init);
+module_exit(ds1682_exit);
Signature · 1 line
Jean Delvare
#2 lore raw

Ugh. Well that was a rather sloppy patch on my part. I'll fix up and resubmit.

Quoted 10 lines · Jean Delvare

Hi Grant,

Quoted 5 lines · Grant Likely

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work

Can we see the corresponding architecture patch (device declaration)?

Yes, I'll include it in the commit comment. It is for a board that isn't in mainline (yet) so a seperate patch doesn't make much sense.

Quoted 9 lines
Quoted 6 lines

- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.

 drivers/i2c/chips/ds1682.c |  270 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 0 deletions(-)

Where have the changes to Kconfig and Makefile gone? Without them, this patch is a no-op.

Oops, eaten by stgit (or rather; eaten by my inexperience with stgit.

Quoted 4 lines

BTW, the config option shouldn't be named SENSORS_DS1682 as your original patch had - this device isn't a sensor. It should be just "DS1682".

Done.

BTW, I've just left the driver in drivers/i2c/chips. It seems sufficiently different from an rtc (and the interface is totally difference) that putting it in drivers/rtc seems wrong. If you disagree, I can change this.

Quoted 18 lines
Quoted 8 lines
drivers/i2c/chips/ds1682.c new file +0 -0
new file mode 100644
index 0000000..0a4a89e

drivers/i2c/chips/ds1682.c line 10

Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
@@ -0,0 +1,270 @@
+/*
+ * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
+ *
+ * Written by: Grant Likely <[email protected]>
+ *
+ * Copyright (C) 2007 Secret Lab Technologies Ltd.
+ * Copyright (C) 2005 James Chapman <[email protected]>
+ * Copyright (C) 2000 Russell King
+ *
+ * Derived from ds1337 real time clock device driver

j>

Quoted 3 lines

Technically, this is the ds1337 driver on which James and Russell have a copyright, not yours. I don't think there is anything left from the code you originally copied from, BTW.

ok, fixed. I like to err on the side of caution when it comes to copyright notices.

Quoted 8 lines

drivers/i2c/chips/ds1682.c line 128

Quoted 3 lines
drivers/i2c/chips/ds1682.c new file +3 -0
+ * Simple register attributes
+ */
+SENSOR_DEVICE_ATTR_2(config, S_IRUGO, ds1682_show, NULL, DS1682_REG_CONFIG, 1);

Bug! The last two arguments are swapped.

Also, I don't see the point of exporting this value to user-space, as the format is proprietary.

You're right. Removed.

Quoted 10 lines
Quoted 10 lines
drivers/i2c/chips/ds1682.c new file +10 -0
+SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+                  4, DS1682_REG_ELAPSED);
+SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+                  4, DS1682_REG_ALARM);
+SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+                  2, DS1682_REG_EVT_CNTR);
+
+static const struct attribute_group ds1682_group = {
+     .attrs = (struct attribute *[]) {
+             &sensor_dev_attr_config.dev_attr.attr,
Quoted 8 lines

drivers/i2c/chips/ds1682.c line 144

Quoted 6 lines
drivers/i2c/chips/ds1682.c new file +6 -0
+             &sensor_dev_attr_elapsed_time.dev_attr.attr,
+             &sensor_dev_attr_alarm_time.dev_attr.attr,
+             &sensor_dev_attr_event_count.dev_attr.attr,
+             NULL,
+     },
+};

I'm not sure if all compilers support this.

I think it should be okay. It is used abundantly in the arch/ppc/syslib/*_devices.c code, and that code is compiled with a lot of different compiler versions.

Quoted 5 lines
Quoted 5 lines
drivers/i2c/chips/ds1682.c new file +5 -0
+static ssize_t ds1682_eeprom_read(struct kobject *kobj, char *buf, loff_t off,
+                               size_t count)
+{
+     struct i2c_client *client = kobj_to_i2c_client(kobj);
+     int rc;
Quoted 8 lines

drivers/i2c/chips/ds1682.c line 158

Quoted 5 lines
drivers/i2c/chips/ds1682.c new file +5 -0
+
+     dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
+             buf, off, count);
+
+     if (off > DS1682_EEPROM_SIZE)

Should be ">=", otherwise you might end up doing a 0-length I2C block read, which is bad.

Right, good catch

Quoted 7 lines

drivers/i2c/chips/ds1682.c line 207

Quoted 4 lines
drivers/i2c/chips/ds1682.c new file +4 -0
+
+/*
+ * Called when a device is found at the ds1682 address
+ */

This comment is no longer true.

Quoted 16 lines

drivers/i2c/chips/ds1682.c line 216

Quoted 9 lines
drivers/i2c/chips/ds1682.c new file +9 -0
+static int ds1682_probe(struct i2c_client *client)
+{
+     int err = 0;
+
+     if (client->addr != 0x6b) {
+             dev_err(&client->dev, "%x is not a valid address\n",
+                     client->addr);
+             return -ENODEV;
+     }

Why check this? You should trust the person who wrote the device definition in the platform code. The only reason why the older i2c chip drivers did address checks is because that was one preliminary device identification step. With the new model, you don't need to identify the device, you already know what's there as per architecture-level device declaration.

Me being paranoid a guess. Removed.

Quoted 12 lines

Not checking the address even has a benefit: if a compatible device exists (today or in the future) with a different address, we don't need to patch the driver to support it.

drivers/i2c/chips/ds1682.c line 220

Quoted 4 lines
drivers/i2c/chips/ds1682.c new file +4 -0
+
+     if (!i2c_check_functionality(client->adapter,
+                                  I2C_FUNC_SMBUS_READ_BYTE_DATA |
+                                  I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {

This no longer reflects what the driver is using.

Quoted 7 lines

drivers/i2c/chips/ds1682.c line 225

Quoted 5 lines
drivers/i2c/chips/ds1682.c new file +5 -0
+             dev_err(&client->dev, "i2c bus does not support the ds1682\n");
+             goto exit;
+     }
+
+     if (sysfs_create_group(&client->dev.kobj, &ds1682_group))

Missing "err = ".

Gah!

Thanks for the comments,
g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#3 lore raw
Quoted 4 lines · Grant Likely

BTW, I've just left the driver in drivers/i2c/chips. It seems sufficiently different from an rtc (and the interface is totally difference) that putting it in drivers/rtc seems wrong. If you disagree, I can change this.

That's fine with me, I have no strong opinion on this.

Quoted 2 lines

Thanks for the comments,
g.

You're welcome.

Signature · 1 line
Jean Delvare
#4 lore raw
In reply to Grant Likely
Quoted 8 lines · On Sun, 13 May 2007 01:43:42 -0600 Grant Likely <[email protected]>…

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.

 drivers/i2c/chips/ds1682.c |  270 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 270 insertions(+), 0 deletions(-)

This version of the patch omitted the changes to drivers/i2c/chips/Kconfig and drivers/i2c/chips/Makefile, which I assume was accidental.

As usual, I generated the delta so we can see what was done:

From: Grant Likely <[email protected]>

- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.

---

 drivers/i2c/chips/ds1682.c |  333 ++++++++++++-----------------------
 1 files changed, 121 insertions(+), 212 deletions(-)
drivers/i2c/chips/ds1682.c renamed from drivers/i2c/chips/ds1682.c~i2c-add-driver-for-dallas-ds1682-elapsed-time-recorder-update +121 -212
diff -puN drivers/i2c/chips/ds1682.c~i2c-add-driver-for-dallas-ds1682-elapsed-time-recorder-update drivers/i2c/chips/ds1682.c
@@ -16,132 +16,106 @@
 
 /*
  * The DS1682 elapsed timer recorder is a simple device that implements
- * one elapsed time counters, one event counter, an alarm signal and 10
+ * one elapsed time counter, one event counter, an alarm signal and 10
  * bytes of general purpose EEPROM.
  *
  * This driver provides access to the DS1682 counters and user data via
  * the sysfs.  The following attributes are added to the device node:
- *     elapsed_time (u32): Total elapsed event time in 1/4s resolution
+ *     elapsed_time (u32): Total elapsed event time in ms resolution
  *     alarm_time (u32): When elapsed time exceeds the value in alarm_time,
  *                       then the alarm pin is asserted.
  *     event_count (u16): number of times the event pin has gone low.
- *     user_data (u8[10]): general purpose EEPROM
+ *     eeprom (u8[10]): general purpose EEPROM
  *
  * Counter registers and user data are both read/write unless the device
- * has been write protected.  This driver does not support turning on write
+ * has been write protected.  This driver does not support turning off write
  * protection.  Once write protection is turned on, it is impossible to
- * turn off so I have left the feature out of this driver to avoid
+ * turn it off again, so I have left the feature out of this driver to avoid
  * accidental enabling, but it is trivial to add write protect support.
  *
  */
 
-#include <linux/device.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/string.h>
-#include <linux/bcd.h>
 #include <linux/list.h>
 #include <linux/sysfs.h>
 #include <linux/ctype.h>
+#include <linux/hwmon-sysfs.h>
 
 /* Device registers */
-#define DS1682_ADDR			0x6B
-
 #define DS1682_REG_CONFIG		0x00
 #define DS1682_REG_ALARM		0x01
 #define DS1682_REG_ELAPSED		0x05
 #define DS1682_REG_EVT_CNTR		0x09
-#define DS1682_REG_USER_DATA		0x0b
+#define DS1682_REG_EEPROM		0x0b
 #define DS1682_REG_RESET		0x1d
 #define DS1682_REG_WRITE_DISABLE	0x1e
 #define DS1682_REG_WRITE_MEM_DISABLE	0x1f
 
-/*
- * Probing class
- */
-static unsigned short normal_i2c[] = { DS1682_ADDR, I2C_CLIENT_END };
-
-I2C_CLIENT_INSMOD;
-
-/*
- * Low level chip access functions
- */
-static int ds1682_read(struct i2c_client *client, int reg, void *buf, int len)
-{
-	u8 *bytes = buf;
-	int val;
-
-	while (len--) {
-		val = i2c_smbus_read_byte_data(client, reg++);
-		if (val < 0)
-			return -EIO;
-		*bytes++ = val;
-	}
-	return 0;
-}
+#define DS1682_EEPROM_SIZE		10
 
 /*
  * Generic counter attributes
  */
-static int ds1682_attr_to_reg(struct device_attribute *attr, int *regsize);
-
-static ssize_t ds1682_show(struct device *dev,
-			   struct device_attribute *attr, char *buf)
+static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
+			   char *buf)
 {
-	u32 val = 0;
-	int reg;
-	int regsize;
-
-	dev_dbg(dev, "ds1682_show() called for %s\n", attr->attr.name);
-
-	/* Get the register address */
-	reg = ds1682_attr_to_reg(attr, &regsize);
-	if (reg < 0)
-		return -EIO;
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct i2c_client *client = to_i2c_client(dev);
+	__le32 val = 0;
+	int rc;
+
+	dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
 
 	/* Read the register */
-	if (ds1682_read(to_i2c_client(dev), reg, &val, regsize))
+	rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
+					   (u8 *) & val);
+	if (rc < 0)
 		return -EIO;
 
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale them up to milliseconds */
+	if (sattr->nr == 4)
+		return sprintf(buf, "%lli\n", ((u64) le32_to_cpu(val)) * 250);
+
 	/* Format the output string and return # of bytes */
-	return sprintf(buf, "0x%.2x\n", le32_to_cpu(val));
+	return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
 }
 
-static ssize_t ds1682_store(struct device *dev,
-			    struct device_attribute *attr, const char *buf,
-			    size_t count)
+static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
+			    const char *buf, size_t count)
 {
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
 	struct i2c_client *client = to_i2c_client(dev);
-	int reg;
-	int regsize;
 	char *endp;
-	u32 val;
+	u64 val;
+	__le32 val_le;
 	int rc;
 
-	/* Sanitize the input */
-	reg = ds1682_attr_to_reg(attr, &regsize);
-
-	if ((reg < 0) || (count >= 16) || (buf[count] != '\0')) {
-		dev_dbg(dev, "insane input; reg=0x%i count=%zd%s\n",
-			reg, count, buf[count] == '\0' ? " unterminated" : "");
-		return -EIO;
-	}
+	dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
 
 	/* Decode input */
-	val = simple_strtoul(buf, &endp, 0);
+	val = simple_strtoull(buf, &endp, 0);
 	if (buf == endp) {
 		dev_dbg(dev, "input string not a number\n");
 		return -EIO;
 	}
 
+	/* Special case: the 32 bit regs are time values with 1/4s
+	 * resolution, scale input down to quarter-seconds */
+	if (sattr->nr == 4)
+		do_div(val, 250);
+
 	/* write out the value */
-	val = cpu_to_le32(val);
-	rc = i2c_smbus_write_i2c_block_data(client, reg, regsize, (void *)&val);
+	val_le = cpu_to_le32(val);
+	rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
+					    (u8 *) & val);
 	if (rc < 0) {
 		dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
-			reg, regsize);
+			sattr->index, sattr->nr);
 		return -EIO;
 	}
 
@@ -151,196 +125,131 @@ static ssize_t ds1682_store(struct devic
 /*
  * Simple register attributes
  */
-DEVICE_ATTR(config, S_IRUGO, ds1682_show, NULL);
-DEVICE_ATTR(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store);
-DEVICE_ATTR(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store);
-DEVICE_ATTR(event_count, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store);
-
-/* Get register size and address from device_attribute structure.  This
- * function must come after the DEVICE_ATTR() lines as it depends on the
- * device_attribute lines being declared */
-static int ds1682_attr_to_reg(struct device_attribute *attr, int *regsize)
-{
-	if (attr == &dev_attr_elapsed_time) {
-		*regsize = 4;
-		return DS1682_REG_ELAPSED;
-	}
-
-	if (attr == &dev_attr_alarm_time) {
-		*regsize = 4;
-		return DS1682_REG_ALARM;
-	}
-
-	if (attr == &dev_attr_event_count) {
-		*regsize = 2;
-		return DS1682_REG_EVT_CNTR;
-	}
-
-	if (attr == &dev_attr_config) {
-		*regsize = 1;
-		return DS1682_REG_CONFIG;
-	}
-
-	pr_debug("Cannot find registers for device_attribute %p\n", attr);
-	return -ENODEV;
-}
+SENSOR_DEVICE_ATTR_2(config, S_IRUGO, ds1682_show, NULL, DS1682_REG_CONFIG, 1);
+SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ELAPSED);
+SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     4, DS1682_REG_ALARM);
+SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show, ds1682_store,
+		     2, DS1682_REG_EVT_CNTR);
+
+static const struct attribute_group ds1682_group = {
+	.attrs = (struct attribute *[]) {
+		&sensor_dev_attr_config.dev_attr.attr,
+		&sensor_dev_attr_elapsed_time.dev_attr.attr,
+		&sensor_dev_attr_alarm_time.dev_attr.attr,
+		&sensor_dev_attr_event_count.dev_attr.attr,
+		NULL,
+	},
+};
 
 /*
  * User data attribute
  */
-static ssize_t ds1682_user_data_show(struct device *dev,
-				     struct device_attribute *attr, char *buf)
+static ssize_t ds1682_eeprom_read(struct kobject *kobj, char *buf, loff_t off,
+				  size_t count)
 {
-	char *end = buf;
-	u8 val[10];
-	int i;
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
+	int rc;
 
-	if (ds1682_read(to_i2c_client(dev), DS1682_REG_USER_DATA, &val, 10))
-		return -EIO;
+	dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
 
-	for (i = 0; i < 10; i++)
-		end += sprintf(end, "%.2x ", val[i]);
+	if (off > DS1682_EEPROM_SIZE)
+		return 0;
 
-	*(end - 1) = '\n';	/* Eliminate trailing space */
-	return end - buf;
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
+
+	rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf);
+	if (rc < 0)
+		return -EIO;
+
+	return count;
 }
 
-static ssize_t ds1682_user_data_store(struct device *dev,
-				      struct device_attribute *attr,
-				      const char *buf, size_t count)
+static ssize_t ds1682_eeprom_write(struct kobject *kobj, char *buf, loff_t off,
+				   size_t count)
 {
-	u8 data[10];
-	char *endp;
-	int bytecount = 0;
-
-	/* Check input for sanity */
-	if ((count >= 80) || (buf[count] != '\0')) {
-		dev_dbg(dev, "insane input; count=%zd%s\n",
-			count, buf[count] == '\0' ? " unterminated" : "");
-		return -EIO;
-	}
+	struct i2c_client *client = kobj_to_i2c_client(kobj);
 
-	/* Parse the data */
-	while (bytecount < 10) {
-		while (isspace(*buf))
-			buf++;
-
-		data[bytecount] = simple_strtoul(buf, &endp, 16);
-		if (endp == buf)	/* make sure it's a real data value */
-			break;
+	dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
+		buf, off, count);
 
-		buf = endp;
-		bytecount++;
-	}
-	while (isspace(*endp))
-		endp++;
+	if (off >= DS1682_EEPROM_SIZE)
+		return -ENOSPC;
 
-	/* Abort on invalid data */
-	if ((bytecount == 0) || (*endp != '\0')) {
-		dev_dbg(dev, "invalid input *buf=\"%s\" *endp=\"%s\"\n",
-			buf, endp);
-		return -EIO;
-	}
+	if (off + count > DS1682_EEPROM_SIZE)
+		count = DS1682_EEPROM_SIZE - off;
 
 	/* Write out to the device */
-	if (i2c_smbus_write_i2c_block_data(to_i2c_client(dev),
-					   DS1682_REG_USER_DATA, bytecount,
-					   data) < 0)
+	if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
+					   count, buf) < 0)
 		return -EIO;
+
 	return count;
 }
 
-DEVICE_ATTR(user_data, S_IRUGO | S_IWUSR, ds1682_user_data_show,
-	    ds1682_user_data_store);
+static struct bin_attribute ds1682_eeprom_attr = {
+	.attr = {
+		.name = "eeprom",
+		.mode = S_IRUGO | S_IWUSR,
+		.owner = THIS_MODULE,
+	},
+	.size = DS1682_EEPROM_SIZE,
+	.read = ds1682_eeprom_read,
+	.write = ds1682_eeprom_write,
+};
 
 /*
  * Called when a device is found at the ds1682 address
  */
-static struct i2c_driver ds1682_driver;
-static int ds1682_detect(struct i2c_adapter *adapter, int address, int kind)
+static int ds1682_probe(struct i2c_client *client)
 {
-	struct i2c_client *new_client;
 	int err = 0;
 
-	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
-				     I2C_FUNC_I2C))
-		goto exit;
+	if (client->addr != 0x6b) {
+		dev_err(&client->dev, "%x is not a valid address\n",
+			client->addr);
+		return -ENODEV;
+	}
 
-	if (!(new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
-		err = -ENOMEM;
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_BYTE_DATA |
+				     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		dev_err(&client->dev, "i2c bus does not support the ds1682\n");
 		goto exit;
 	}
 
-	new_client->addr = address;
-	new_client->adapter = adapter;
-	new_client->driver = &ds1682_driver;
-	new_client->flags = 0;
-
-	/* Note: Ignoring 'kind' value as the ds1682 uses a fixed address */
-
-	/* We can fill in the remaining client fields */
-	strlcpy(new_client->name, "ds1682", I2C_NAME_SIZE);
-
-	/* Tell the I2C layer a new client has arrived */
-	if ((err = i2c_attach_client(new_client)))
-		goto exit_free;
-
-	if (device_create_file(&new_client->dev, &dev_attr_config))
-		goto exit_attr_config;
-	if (device_create_file(&new_client->dev, &dev_attr_elapsed_time))
-		goto exit_attr_elapsed;
-	if (device_create_file(&new_client->dev, &dev_attr_alarm_time))
-		goto exit_attr_alarm;
-	if (device_create_file(&new_client->dev, &dev_attr_event_count))
-		goto exit_attr_event;
-	if (device_create_file(&new_client->dev, &dev_attr_user_data))
-		goto exit_attr_userdata;
+	if (sysfs_create_group(&client->dev.kobj, &ds1682_group))
+		goto exit;
+
+	if (sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr))
+		goto exit_bin_attr;
 
 	return 0;
 
-      exit_attr_userdata:
-	device_remove_file(&new_client->dev, &dev_attr_event_count);
-      exit_attr_event:
-	device_remove_file(&new_client->dev, &dev_attr_alarm_time);
-      exit_attr_alarm:
-	device_remove_file(&new_client->dev, &dev_attr_elapsed_time);
-      exit_attr_elapsed:
-	device_remove_file(&new_client->dev, &dev_attr_config);
-      exit_attr_config:
-	i2c_detach_client(new_client);
-      exit_free:
-	kfree(new_client);
+      exit_bin_attr:
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
       exit:
 	return err;
 }
 
-static int ds1682_attach_adapter(struct i2c_adapter *adapter)
+static int ds1682_remove(struct i2c_client *client)
 {
-	return i2c_probe(adapter, &addr_data, ds1682_detect);
-}
-
-static int ds1682_detach_client(struct i2c_client *client)
-{
-	int err;
-	device_remove_file(&client->dev, &dev_attr_user_data);
-	device_remove_file(&client->dev, &dev_attr_event_count);
-	device_remove_file(&client->dev, &dev_attr_alarm_time);
-	device_remove_file(&client->dev, &dev_attr_elapsed_time);
-	device_remove_file(&client->dev, &dev_attr_config);
-
-	if ((err = i2c_detach_client(client)))
-		return err;
+	sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
+	sysfs_remove_group(&client->dev.kobj, &ds1682_group);
 
-	kfree(client);
 	return 0;
 }
 
 static struct i2c_driver ds1682_driver = {
 	.driver = {
-		   .name = "ds1682",
-		   },
-	.attach_adapter = ds1682_attach_adapter,
-	.detach_client = ds1682_detach_client,
+		.name = "ds1682",
+	},
+	.probe = ds1682_probe,
+	.remove = ds1682_remove,
 };
 
 static int __init ds1682_init(void)

_

#5 lore raw
In reply to Grant Likely
Quoted 7 lines · On Sun, 13 May 2007 01:43:42 -0600 Grant Likely <[email protected]>…

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.\

What new prototype for i2c_smbus_read_i2c_block_data()?

drivers/i2c/chips/ds1682.c: In function 'ds1682_show':
drivers/i2c/chips/ds1682.c:75: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast drivers/i2c/chips/ds1682.c:75: error: too many arguments to function 'i2c_smbus_read_i2c_block_data'
drivers/i2c/chips/ds1682.c: In function 'ds1682_eeprom_read': drivers/i2c/chips/ds1682.c:165: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast
drivers/i2c/chips/ds1682.c:165: error: too many arguments to function 'i2c_smbus_read_i2c_block_data'

#6 lore raw
Quoted 10 lines · Andrew Morton
Quoted 7 lines · On Sun, 13 May 2007 01:43:42 -0600 Grant Likely <[email protected]>…

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.\

Quoted 7 lines

What new prototype for i2c_smbus_read_i2c_block_data()?

drivers/i2c/chips/ds1682.c: In function 'ds1682_show':
drivers/i2c/chips/ds1682.c:75: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast drivers/i2c/chips/ds1682.c:75: error: too many arguments to function 'i2c_smbus_read_i2c_block_data'
drivers/i2c/chips/ds1682.c: In function 'ds1682_eeprom_read': drivers/i2c/chips/ds1682.c:165: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast
drivers/i2c/chips/ds1682.c:165: error: too many arguments to function 'i2c_smbus_read_i2c_block_data'

Sorry. I forgot to drop linux-kernel when sending this patch. It depends on another patch that hasn't been merged yet.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#7 lore raw
In reply to Andrew Morton

Hi Andrew,

Quoted 10 lines · Andrew Morton
Quoted 7 lines · On Sun, 13 May 2007 01:43:42 -0600 Grant Likely <[email protected]>…

---

Here is the 3rd iteration with the following changes:
- Modified to be an i2c "new style" driver based on David Brownell's work
- uses the new prototype for i2c_smbus_read_i2c_block_data() for block data reads instead of a single byte at a time.\

Quoted 8 lines

What new prototype for i2c_smbus_read_i2c_block_data()?

drivers/i2c/chips/ds1682.c: In function 'ds1682_show':
drivers/i2c/chips/ds1682.c:75: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast drivers/i2c/chips/ds1682.c:75: error: too many arguments to function 'i2c_smbus_read_i2c_block_data' drivers/i2c/chips/ds1682.c: In function 'ds1682_eeprom_read':
drivers/i2c/chips/ds1682.c:165: warning: passing argument 3 of 'i2c_smbus_read_i2c_block_data' makes pointer from integer without a cast drivers/i2c/chips/ds1682.c:165: error: too many arguments to function 'i2c_smbus_read_i2c_block_data'

Please drop your version of the DS1682 patch, and refresh my jdelvare-i2c quilt tree. You'll get the i2c_smbus_read_i2c_block_data prototype update as well as the final version of Grant's DS1682 patch.

You would save yourself quite some work if you were waiting for i2c patches to come to you through my tree. I am paying attention to the dependencies, exactly in order to prevent problems like the one above. Not to say I am not grateful when you collect important i2c fixes which have been sent only to LKML and that I would otherwise have missed, but in the case of the DS1682 patch, it was pretty visible that I was taking care of it.

Thanks,

Signature · 1 line
Jean Delvare