Skip to contentSkip to conversation

Add support for Diolan U2C-12 USB/I2C adapter.

PATCH Superseded Guenter Roeck 3 participants 10 messages Jan 19, 2011 – Jan 26, 2011 5 messages not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for Diolan U2C-12 USB/I2C adapter.

v2 changes:
- Moved receive and transmit buffers to allocated driver memory
- diolan_usb_transfer() no longer requires buffer and length arguments
- Pass "struct i2c_diolan_u2c *" instead of "struct i2c_adapter *" to many of the internal usb access functions.
- Introduced diolan_usb_cmd(), diolan_usb_cmd_data(), and diolan_usb_cmd_data2() as front-end functions for actual commands.
- Function prefix is now diolan_ for all functions.
- Removed diolan_scan().
- Fixed race conditions in diolan_u2c_probe().
- Use i2c_{set,get}_adapdata instead of misusing adapter.algo_data.
- Driver name is now i2c-diolan-u2c (instead of i2c-u2c-usb).
- Added support for "frequency" module parameter to set i2c clock frequency
- Enabled I2C clock stretching support
- Support sending multiple commands in single usb transfer
- Several other minor changes to address review comments.

A message that is not in the archive (sent off-list or not yet received): 1295472398-705-1-git-send-email-guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]

#2 lore raw

PATCH v2 1/2 i2c/busses: Diolan U2C-12 USB/I2C adapter driver

---
 drivers/i2c/busses/Kconfig          |   10 +
 drivers/i2c/busses/Makefile         |    1 +
 drivers/i2c/busses/i2c-diolan-u2c.c |  529 +++++++++++++++++++++++++++++++++++
 3 files changed, 540 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-diolan-u2c.c
drivers/i2c/busses/Kconfig +10 -0
index 113505a..30f8dbd 100644
@@ -648,6 +648,16 @@ config I2C_EG20T
 
 comment "External I2C/SMBus adapter drivers"
 
+config I2C_DIOLAN_U2C
+	tristate "Diolan U2C-12 USB adapter"
+	depends on USB
+	help
+	  If you say yes to this option, support will be included for Diolan
+	  U2C-12, a USB to I2C interface.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-diolan-u2c.
+
 config I2C_PARPORT
 	tristate "Parallel port adapter"
 	depends on PARPORT
drivers/i2c/busses/Makefile +1 -0
index 9d2d0ec..3c630b7 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_EG20T)         += i2c-eg20t.o
 
 # External I2C/SMBus adapter drivers
+obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PARPORT_LIGHT)	+= i2c-parport-light.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
drivers/i2c/busses/i2c-diolan-u2c.c new file +529 -0

529 lines not on this page · raw message

Signature · 1 line
1.7.3.1

A message that is not in the archive (sent off-list or not yet received): 1295472398-705-2-git-send-email-guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]

#4 lore raw

Re: [PATCH v2 1/2] i2c/busses: Diolan U2C-12 USB/I2C adapter driver

Quoted 64 lines · Guenter Roeck
---
 drivers/i2c/busses/Kconfig          |   10 +
 drivers/i2c/busses/Makefile         |    1 +
 drivers/i2c/busses/i2c-diolan-u2c.c |  529 +++++++++++++++++++++++++++++++++++
 3 files changed, 540 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-diolan-u2c.c
drivers/i2c/busses/Kconfig +10 -0
index 113505a..30f8dbd 100644
@@ -648,6 +648,16 @@ config I2C_EG20T
 
 comment "External I2C/SMBus adapter drivers"
 
+config I2C_DIOLAN_U2C
+	tristate "Diolan U2C-12 USB adapter"
+	depends on USB
+	help
+	  If you say yes to this option, support will be included for Diolan
+	  U2C-12, a USB to I2C interface.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-diolan-u2c.
+
 config I2C_PARPORT
 	tristate "Parallel port adapter"
 	depends on PARPORT
drivers/i2c/busses/Makefile +1 -0
index 9d2d0ec..3c630b7 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_EG20T)         += i2c-eg20t.o
 
 # External I2C/SMBus adapter drivers
+obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PARPORT_LIGHT)	+= i2c-parport-light.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
drivers/i2c/busses/i2c-diolan-u2c.c new file +17 -0
new file mode 100644
index 0000000..44905ce
@@ -0,0 +1,529 @@
+/*
+ * Driver for the Diolan u2c-12 USB-I2C adapter
+ *
+ * Copyright (c) 2010-2011 Ericsson AB
+ *
+ * Derived from:
+ *  i2c-tiny-usb.c
+ *  Copyright (C) 2006-2007 Till Harbaum ([email protected])
+ *
+ * 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, version 2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>

drivers/i2c/busses/i2c-diolan-u2c.c line 27

Quoted 10 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +10 -0
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/i2c.h>
+
+#define DRIVER_NAME		"i2c-diolan-u2c"
+
+#define USB_VENDOR_ID_DIOLAN		0x0abf
+#define USB_DEVICE_ID_DIOLAN_U2C	0x3370
+

might be worth type-defing the commands and responses, but not especially importnant.

drivers/i2c/busses/i2c-diolan-u2c.c line 70

Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+#define U2C_I2C_SPEED_FAST	0	/* 400 kHz */
+#define U2C_I2C_SPEED_STD	1	/* 100 kHz */
+#define U2C_I2C_SPEED_2KHZ	242	/* 2 kHz, minimum speed */
+#define U2C_I2C_SPEED(f)	((DIV_ROUND_CLOSEST(1000000, (f)) - 10) / 2 + 1)

how about rounding down? surely the speed requested is the maximum?

drivers/i2c/busses/i2c-diolan-u2c.c line 91

Quoted 9 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +9 -0
+/* Structure to hold all of our device specific stuff */
+struct i2c_diolan_u2c {
+	struct usb_device *usb_dev;	/* the usb device for this device */
+	struct usb_interface *interface;/* the interface for this device */
+	struct i2c_adapter adapter;	/* i2c related things */
+	int olen;			/* Output buffer length */
+	int ocount;			/* Number of enqueued messages */
+	u8 obuffer[DIOLAN_OUTBUF_LEN];	/* output buffer */
+	u8 ibuffer[DIOLAN_INBUF_LEN];	/* input buffer */

you should cache-line align the buffers to avoid any problems with dma-vs-cache, etc.

Quoted 35 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +35 -0
+/* Send command to device, and get response. */
+static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
+{
+	int ret = 0;
+	int actual;
+	int i;
+
+	if (!dev->olen || !dev->ocount)
+		return -EINVAL;
+
+	ret = usb_bulk_msg(dev->usb_dev,
+			   usb_sndbulkpipe(dev->usb_dev, DIOLAN_OUT_EP),
+			   dev->obuffer, dev->olen, &actual,
+			   DIOLAN_USB_TIMEOUT);
+	if (!ret) {
+		for (i = 0; i < dev->ocount; i++) {
+			int tmpret;
+
+			tmpret = usb_bulk_msg(dev->usb_dev,
+					      usb_rcvbulkpipe(dev->usb_dev,
+							      DIOLAN_IN_EP),
+					      dev->ibuffer,
+					      sizeof(dev->ibuffer), &actual,
+					      DIOLAN_USB_TIMEOUT);
+			if (tmpret < 0 && ret == 0)
+				ret = tmpret;
+			else if (ret >= 0 && tmpret == 0 && actual > 0) {
+				switch (dev->ibuffer[actual - 1]) {
+				case RESP_NACK:
+					ret = -ENXIO;
+					break;
+				case RESP_TIMEOUT:
+					ret = -ETIMEDOUT;
+					break;
+				case RESP_OK:

drivers/i2c/busses/i2c-diolan-u2c.c line 145

Quoted 10 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +10 -0
+					/* strip off return code */
+					ret = actual - 1;
+					break;
+				default:
+					ret = -EIO;
+					break;
+				}
+			}
+		}
+	}

this looks a little complicated with ret and tmpret.

Quoted 9 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +8 -0
+	dev->olen = 0;
+	dev->ocount = 0;
+	return ret;
+}
+
 
+static int diolan_usb_cmd_data2(struct i2c_diolan_u2c *dev, u8 command, u8 d1,
+				u8 d2, bool flush)
+{

drivers/i2c/busses/i2c-diolan-u2c.c line 190

Quoted 10 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +10 -0
+	int ret = 0;
+
+	dev->obuffer[dev->olen++] = command;
+	dev->obuffer[dev->olen++] = d1;
+	dev->obuffer[dev->olen++] = d2;
+	dev->ocount++;
+	if (flush || dev->olen >= DIOLAN_FLUSH_LEN)
+		ret = diolan_usb_transfer(dev);
+	return ret;
+}

how about wrapping the check for usb_transfer into one call? say diolan_written_cmd(dev, flush) and then just use that as a return and remove any need for 'int ret = 0' as well.

Quoted 23 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +23 -0
+/*
+ * Flush input queue.
+ * If we don't do this at startup and the controller has queued up
+ * messages which were not retrieved, it will stop responding
+ * at some point.
+ */
+static void diolan_flush_input(struct i2c_diolan_u2c *dev)
+{
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		int actual = 0;
+		int ret;
+
+		ret = usb_bulk_msg(dev->usb_dev,
+				   usb_rcvbulkpipe(dev->usb_dev, DIOLAN_IN_EP),
+				   dev->ibuffer, sizeof(dev->ibuffer), &actual,
+				   DIOLAN_USB_TIMEOUT);
+		if (ret < 0 || actual == 0)
+			break;
+	}
+	if (i == 10)
+		dev_err(&dev->interface->dev, "Failed to flush input buffer\n");

[snip]

drivers/i2c/busses/i2c-diolan-u2c.c line 320

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+		 "Diolan U2C at USB bus %03d address %03d speed %d Hz\n",
+		 dev->usb_dev->bus->busnum, dev->usb_dev->devnum, frequency);
+
+	diolan_flush_input(dev);
+	diolan_fw_version(dev);

why bother returning ret from some of these when they're not checked?

drivers/i2c/busses/i2c-diolan-u2c.c line 359

Quoted 11 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +11 -0
+	ret = diolan_i2c_start(dev);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < num; i++) {
+		pmsg = &msgs[i];
+		if (i) {
+			ret = diolan_i2c_repeated_start(dev);
+			if (ret < 0)
+				goto abort;
+		}

i think this is ok.

drivers/i2c/busses/i2c-diolan-u2c.c line 449

Quoted 6 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +6 -0
+	int ret;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (dev == NULL) {
+		dev_err(&interface->dev, "Out of memory\n");

how about "no memory for device state"

Quoted 15 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +15 -0
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
+	dev->interface = interface;
+
+	/* save our data pointer in this interface device */
+	usb_set_intfdata(interface, dev);
+
+	/* setup i2c adapter description */
+	dev->adapter.owner = THIS_MODULE;
+	dev->adapter.class = I2C_CLASS_HWMON;
+	dev->adapter.algo = &diolan_usb_algorithm;
+	i2c_set_adapdata(&dev->adapter, dev);

drivers/i2c/busses/i2c-diolan-u2c.c line 474

Quoted 10 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +10 -0
+	snprintf(dev->adapter.name, sizeof(dev->adapter.name),
+		 DRIVER_NAME " at bus %03d device %03d",
+		 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
+
+	dev->adapter.dev.parent = &dev->interface->dev;
+
+	/* initialize diolan i2c interface */
+	ret = diolan_init(dev);
+	if (ret < 0)
+		goto error_free;

do all return paths of diolan_init() print error?

Quoted 19 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +19 -0
+
+	/* and finally attach to i2c layer */
+	ret = i2c_add_adapter(&dev->adapter);
+	if (ret < 0) {
+		dev_err(&interface->dev, "failed to add I2C adapter\n");
+		goto error_free;
+	}
+
+	dev_dbg(&interface->dev, "connected " DRIVER_NAME "\n");
+
+	return 0;
+
+error_free:
+	usb_set_intfdata(interface, NULL);
+	diolan_u2c_free(dev);
+error:
+	return ret;
+}
+
Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.

A message that is not in the archive (sent off-list or not yet received): 20110119211403.GM5432-SMNkleLxa3Z6Wcw2j4pizdi2O/[email protected]

#6 lore raw

Re: [PATCH v2 1/2] i2c/busses: Diolan U2C-12 USB/I2C adapter driver

Quoted 70 lines · Ben Dooks
Quoted 69 lines · Guenter Roeck
---
 drivers/i2c/busses/Kconfig          |   10 +
 drivers/i2c/busses/Makefile         |    1 +
 drivers/i2c/busses/i2c-diolan-u2c.c |  529 +++++++++++++++++++++++++++++++++++
 3 files changed, 540 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-diolan-u2c.c
drivers/i2c/busses/Kconfig +10 -0
index 113505a..30f8dbd 100644
@@ -648,6 +648,16 @@ config I2C_EG20T
 
 comment "External I2C/SMBus adapter drivers"
 
+config I2C_DIOLAN_U2C
+	tristate "Diolan U2C-12 USB adapter"
+	depends on USB
+	help
+	  If you say yes to this option, support will be included for Diolan
+	  U2C-12, a USB to I2C interface.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-diolan-u2c.
+
 config I2C_PARPORT
 	tristate "Parallel port adapter"
 	depends on PARPORT
drivers/i2c/busses/Makefile +1 -0
index 9d2d0ec..3c630b7 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_EG20T)         += i2c-eg20t.o
 
 # External I2C/SMBus adapter drivers
+obj-$(CONFIG_I2C_DIOLAN_U2C)	+= i2c-diolan-u2c.o
 obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PARPORT_LIGHT)	+= i2c-parport-light.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
drivers/i2c/busses/i2c-diolan-u2c.c new file +22 -0
new file mode 100644
index 0000000..44905ce
@@ -0,0 +1,529 @@
+/*
+ * Driver for the Diolan u2c-12 USB-I2C adapter
+ *
+ * Copyright (c) 2010-2011 Ericsson AB
+ *
+ * Derived from:
+ *  i2c-tiny-usb.c
+ *  Copyright (C) 2006-2007 Till Harbaum ([email protected])
+ *
+ * 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, version 2.
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/i2c.h>
+
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 27

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+#define DRIVER_NAME		"i2c-diolan-u2c"
+
+#define USB_VENDOR_ID_DIOLAN		0x0abf
+#define USB_DEVICE_ID_DIOLAN_U2C	0x3370
+

might be worth type-defing the commands and responses, but not especially important.

I think it is useful.

Quoted 7 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 70

Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+#define U2C_I2C_SPEED_FAST	0	/* 400 kHz */
+#define U2C_I2C_SPEED_STD	1	/* 100 kHz */
+#define U2C_I2C_SPEED_2KHZ	242	/* 2 kHz, minimum speed */
+#define U2C_I2C_SPEED(f)	((DIV_ROUND_CLOSEST(1000000, (f)) - 10) / 2 + 1)

how about rounding down? surely the speed requested is the maximum?

No strong opinion either way. Rounding down would mean rounding up the speed, though (higher number is lower speed). I'll round it up.

Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+/* Structure to hold all of our device specific stuff */
+struct i2c_diolan_u2c {
+	struct usb_device *usb_dev;	/* the usb device for this device */
+	struct usb_interface *interface;/* the interface for this device */
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 91

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+	struct i2c_adapter adapter;	/* i2c related things */
+	int olen;			/* Output buffer length */
+	int ocount;			/* Number of enqueued messages */
+	u8 obuffer[DIOLAN_OUTBUF_LEN];	/* output buffer */
+	u8 ibuffer[DIOLAN_INBUF_LEN];	/* input buffer */

you should cache-line align the buffers to avoid any problems with dma-vs-cache, etc.

Can you point me to some code doing that ? Or do you mean I should allocate the buffers separately ?

Quoted 39 lines
Quoted 39 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +39 -0
+/* Send command to device, and get response. */
+static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
+{
+	int ret = 0;
+	int actual;
+	int i;
+
+	if (!dev->olen || !dev->ocount)
+		return -EINVAL;
+
+	ret = usb_bulk_msg(dev->usb_dev,
+			   usb_sndbulkpipe(dev->usb_dev, DIOLAN_OUT_EP),
+			   dev->obuffer, dev->olen, &actual,
+			   DIOLAN_USB_TIMEOUT);
+	if (!ret) {
+		for (i = 0; i < dev->ocount; i++) {
+			int tmpret;
+
+			tmpret = usb_bulk_msg(dev->usb_dev,
+					      usb_rcvbulkpipe(dev->usb_dev,
+							      DIOLAN_IN_EP),
+					      dev->ibuffer,
+					      sizeof(dev->ibuffer), &actual,
+					      DIOLAN_USB_TIMEOUT);
+			if (tmpret < 0 && ret == 0)
+				ret = tmpret;
+			else if (ret >= 0 && tmpret == 0 && actual > 0) {
+				switch (dev->ibuffer[actual - 1]) {
+				case RESP_NACK:
+					ret = -ENXIO;
+					break;
+				case RESP_TIMEOUT:
+					ret = -ETIMEDOUT;
+					break;
+				case RESP_OK:
+					/* strip off return code */
+					ret = actual - 1;
+					break;
+				default:
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 145

Quoted 6 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +6 -0
+					ret = -EIO;
+					break;
+				}
+			}
+		}
+	}

this looks a little complicated with ret and tmpret.

Yes. Problem is that I have to retrieve all messages one by one even if there was an error. I'll see if I can come up with something better, but right now I have no idea how to simplify it.

Quoted 15 lines
Quoted 15 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +14 -0
+	dev->olen = 0;
+	dev->ocount = 0;
+	return ret;
+}
+
 
+static int diolan_usb_cmd_data2(struct i2c_diolan_u2c *dev, u8 command, u8 d1,
+				u8 d2, bool flush)
+{
+	int ret = 0;
+
+	dev->obuffer[dev->olen++] = command;
+	dev->obuffer[dev->olen++] = d1;
+	dev->obuffer[dev->olen++] = d2;
+	dev->ocount++;
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 161

Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+	if (flush || dev->olen >= DIOLAN_FLUSH_LEN)
+		ret = diolan_usb_transfer(dev);
+	return ret;
+}

how about wrapping the check for usb_transfer into one call? say diolan_written_cmd(dev, flush) and then just use that as a return and remove any need for 'int ret = 0' as well.

Ok.

Quoted 27 lines
Quoted 23 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +23 -0
+/*
+ * Flush input queue.
+ * If we don't do this at startup and the controller has queued up
+ * messages which were not retrieved, it will stop responding
+ * at some point.
+ */
+static void diolan_flush_input(struct i2c_diolan_u2c *dev)
+{
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		int actual = 0;
+		int ret;
+
+		ret = usb_bulk_msg(dev->usb_dev,
+				   usb_rcvbulkpipe(dev->usb_dev, DIOLAN_IN_EP),
+				   dev->ibuffer, sizeof(dev->ibuffer), &actual,
+				   DIOLAN_USB_TIMEOUT);
+		if (ret < 0 || actual == 0)
+			break;
+	}
+	if (i == 10)
+		dev_err(&dev->interface->dev, "Failed to flush input buffer\n");

[snip]

Quoted 8 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 320

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+		 "Diolan U2C at USB bus %03d address %03d speed %d Hz\n",
+		 dev->usb_dev->bus->busnum, dev->usb_dev->devnum, frequency);
+
+	diolan_flush_input(dev);
+	diolan_fw_version(dev);

why bother returning ret from some of these when they're not checked?

Good point. Made it void.

Quoted 14 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 359

Quoted 11 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +11 -0
+	ret = diolan_i2c_start(dev);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < num; i++) {
+		pmsg = &msgs[i];
+		if (i) {
+			ret = diolan_i2c_repeated_start(dev);
+			if (ret < 0)
+				goto abort;
+		}

i think this is ok.

Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 449

Quoted 6 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +6 -0
+	int ret;
+
+	/* allocate memory for our device state and initialize it */
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (dev == NULL) {
+		dev_err(&interface->dev, "Out of memory\n");

how about "no memory for device state"

Ok.

Quoted 19 lines
Quoted 19 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +19 -0
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
+	dev->interface = interface;
+
+	/* save our data pointer in this interface device */
+	usb_set_intfdata(interface, dev);
+
+	/* setup i2c adapter description */
+	dev->adapter.owner = THIS_MODULE;
+	dev->adapter.class = I2C_CLASS_HWMON;
+	dev->adapter.algo = &diolan_usb_algorithm;
+	i2c_set_adapdata(&dev->adapter, dev);
+	snprintf(dev->adapter.name, sizeof(dev->adapter.name),
+		 DRIVER_NAME " at bus %03d device %03d",
+		 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
+
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 474

Quoted 6 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +6 -0
+	dev->adapter.dev.parent = &dev->interface->dev;
+
+	/* initialize diolan i2c interface */
+	ret = diolan_init(dev);
+	if (ret < 0)
+		goto error_free;

do all return paths of diolan_init() print error?

No. I'll add a message.

Quoted 11 lines
Quoted 11 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +11 -0
+
+	/* and finally attach to i2c layer */
+	ret = i2c_add_adapter(&dev->adapter);
+	if (ret < 0) {
+		dev_err(&interface->dev, "failed to add I2C adapter\n");
+		goto error_free;
+	}
+
+	dev_dbg(&interface->dev, "connected " DRIVER_NAME "\n");
+
+	return 0;
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 493

Quoted 8 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +8 -0
+
+error_free:
+	usb_set_intfdata(interface, NULL);
+	diolan_u2c_free(dev);
+error:
+	return ret;
+}
+

Thanks a lot for the review!

Guenter

#7 lore raw

Re: [PATCH v2 1/2] i2c/busses: Diolan U2C-12 USB/I2C adapter driver

In reply to a message not in the archive
Quoted 2 lines · Ben Dooks
Quoted 1 line · Guenter Roeck

[ ... ]

Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+/* Structure to hold all of our device specific stuff */
+struct i2c_diolan_u2c {
+	struct usb_device *usb_dev;	/* the usb device for this device */
+	struct usb_interface *interface;/* the interface for this device */
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 91

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+	struct i2c_adapter adapter;	/* i2c related things */
+	int olen;			/* Output buffer length */
+	int ocount;			/* Number of enqueued messages */
+	u8 obuffer[DIOLAN_OUTBUF_LEN];	/* output buffer */
+	u8 ibuffer[DIOLAN_INBUF_LEN];	/* input buffer */

you should cache-line align the buffers to avoid any problems with dma-vs-cache, etc.

There are several other drivers which don't cache-align the buffers used with usb_bulk_msg(). Do those all have potential problems, or is this only relevant for optimization ?

If it is just for optimization, I'd argue that the speed here is so slow that it won't make much of a difference, if any, if the buffers were aligned.

Thanks,
Guenter

#8 lore raw

Re: [PATCH v2 1/2] i2c/busses: Diolan U2C-12 USB/I2C adapter driver

Quoted 18 lines · Guenter Roeck
Quoted 2 lines · Ben Dooks
Quoted 1 line · Guenter Roeck

[ ... ]

Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +4 -0
+/* Structure to hold all of our device specific stuff */
+struct i2c_diolan_u2c {
+	struct usb_device *usb_dev;	/* the usb device for this device */
+	struct usb_interface *interface;/* the interface for this device */
Quoted 9 lines

drivers/i2c/busses/i2c-diolan-u2c.c line 91

Quoted 5 lines
drivers/i2c/busses/i2c-diolan-u2c.c new file +5 -0
+	struct i2c_adapter adapter;	/* i2c related things */
+	int olen;			/* Output buffer length */
+	int ocount;			/* Number of enqueued messages */
+	u8 obuffer[DIOLAN_OUTBUF_LEN];	/* output buffer */
+	u8 ibuffer[DIOLAN_INBUF_LEN];	/* input buffer */

you should cache-line align the buffers to avoid any problems with dma-vs-cache, etc.

Quoted 7 lines

There are several other drivers which don't cache-align the buffers used with usb_bulk_msg(). Do those all have potential problems, or is this only relevant for optimization ?

If it is just for optimization, I'd argue that the speed here is so slow that it won't make much of a difference, if any, if the buffers were aligned.

It is more to do with the way some architectures/cpus deal with cache coherency with resepect to DMA... in some cases it is possible for hardware to be dealing with a buffer that the cpu may still be using if they are not appropriately aligned. I forget the exact case, but losing a few bytes in a buffer is preferable to the other case.

I also believe that X86 style architectures do not have this problem.

Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.
#9 lore raw

PATCH v2 2/2 MAINTAINERS: Add maintainer for Diolan U2C-12 I2C adapter driver

In reply to a message not in the archive
---
 MAINTAINERS |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
index 1af022e..12b0be3 100644
@@ -2089,6 +2089,12 @@ F:	Documentation/serial/digiepca.txt
 F:	drivers/char/epca*
 F:	drivers/char/digi*
 
+DIOLAN U2C-12 I2C DRIVER
+M:	Guenter Roeck <guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/i2c/busses/i2c-diolan-u2c.c
+
 DIRECTORY NOTIFICATION (DNOTIFY)
 M:	Eric Paris <[email protected]>
 S:	Maintained
Signature · 1 line
1.7.3.1

A message that is not in the archive (sent off-list or not yet received): 1295472398-705-3-git-send-email-guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]

#11 lore raw

Re: [PATCH v2 2/2] MAINTAINERS: Add maintainer for Diolan U2C-12 I2C adapter driver

Quoted 1 line · Guenter Roeck

meaningful commit messages please.

Quoted 24 lines
---
 MAINTAINERS |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
index 1af022e..12b0be3 100644
@@ -2089,6 +2089,12 @@ F:	Documentation/serial/digiepca.txt
 F:	drivers/char/epca*
 F:	drivers/char/digi*
 
+DIOLAN U2C-12 I2C DRIVER
+M:	Guenter Roeck <guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/i2c/busses/i2c-diolan-u2c.c
+
 DIRECTORY NOTIFICATION (DNOTIFY)
 M:	Eric Paris <[email protected]>
 S:	Maintained
Signature · 1 line
1.7.3.1
Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.

A message that is not in the archive (sent off-list or not yet received): 20110119205631.GL5432-SMNkleLxa3Z6Wcw2j4pizdi2O/[email protected]

#13 lore raw

Re: [PATCH v2 2/2] MAINTAINERS: Add maintainer for Diolan U2C-12 I2C adapter driver

Quoted 5 lines · Ben Dooks
Quoted 1 line · Guenter Roeck

meaningful commit messages please.

In general I agree, only if the headline says everything what else do you want me to say here ? That I am adding myself as maintainer ?

Guenter

Quoted 25 lines
Quoted 24 lines
---
 MAINTAINERS |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +6 -0
index 1af022e..12b0be3 100644
@@ -2089,6 +2089,12 @@ F:	Documentation/serial/digiepca.txt
 F:	drivers/char/epca*
 F:	drivers/char/digi*
 
+DIOLAN U2C-12 I2C DRIVER
+M:	Guenter Roeck <guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/i2c/busses/i2c-diolan-u2c.c
+
 DIRECTORY NOTIFICATION (DNOTIFY)
 M:	Eric Paris <[email protected]>
 S:	Maintained
Signature · 1 line
1.7.3.1
#14 lore raw

Re: [PATCH v2 2/2] MAINTAINERS: Add maintainer for Diolan U2C-12 I2C adapter driver

Quoted 8 lines · Guenter Roeck
Quoted 5 lines · Ben Dooks
Quoted 1 line · Guenter Roeck

meaningful commit messages please.

In general I agree, only if the headline says everything what else do you want me to say here ? That I am adding myself as maintainer ?

I would also like to see information about the maintainer, such as is this a work related or personal project, and anything else that may be relevant.

Quoted 33 lines

Guenter

Quoted 12 lines
Quoted 12 lines
---
 MAINTAINERS |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
MAINTAINERS +0 -0
index 1af022e..12b0be3 100644
@@ -2089,6 +2089,12 @@ F:	Documentation/serial/digiepca.txt
 F:	drivers/char/epca*
 F:	drivers/char/digi*
 
Quoted 13 lines
Quoted 12 lines
MAINTAINERS +6 -0
+DIOLAN U2C-12 I2C DRIVER
+M:	Guenter Roeck <guenter.roeck-IzeFyvvaP7pWk0Htik3J/[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/i2c/busses/i2c-diolan-u2c.c
+
 DIRECTORY NOTIFICATION (DNOTIFY)
 M:	Eric Paris <[email protected]>
 S:	Maintained
Signature · 1 line
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Ben Dooks, [email protected], http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.