[i2c] [patch 2.6.20-rc1 5/6] remove i2c_adapter.dev usage from adapters

Jean Delvare khali at linux-fr.org
Thu Jan 4 18:50:57 CET 2007


Hi David,

On Mon, 1 Jan 2007 12:46:50 -0800, David Brownell wrote:
> Change I2C adapter driver init:  they stop using i2c_adapter.dev.parent,
> and provide i2c_adapter.class_dev.dev instead.
> 
> Along with previous patches, this means almost all uses of i2c_adapter.dev
> (outside i2c-core, which won't change quite yet) are gone.

I've slightly modified the i2c-core part of this patch:

--- linux-2.6.20-rc3.orig/drivers/i2c/i2c-core.c	2007-01-04 16:30:24.000000000 +0100
+++ linux-2.6.20-rc3/drivers/i2c/i2c-core.c	2007-01-04 17:35:27.000000000 +0100
@@ -188,6 +188,14 @@ int i2c_add_adapter(struct i2c_adapter *
 	list_add_tail(&adap->list,&adapters);
 	INIT_LIST_HEAD(&adap->clients);
 
+	/* Until we get rid of i2c_adapter.dev, we use the real device
+	 * as its parent, and we overwrite class_dev.dev to point to it.
+	 * It is assumed that adap->class_dev has been zeroed by the
+	 * caller except for the dev field.
+	 */
+	adap->dev.parent = adap->class_dev.dev;
+	adap->class_dev.dev = &adap->dev;
+
 	/* Add the adapter to the driver core.
 	 * If the parent pointer is not set up,
 	 * we add this adapter to the host bus.
@@ -209,8 +217,6 @@ int i2c_add_adapter(struct i2c_adapter *
 		goto out_unregister;
 
 	/* Add this adapter to the i2c_adapter class */
-	memset(&adap->class_dev, 0x00, sizeof(struct class_device));
-	adap->class_dev.dev = &adap->dev;
 	adap->class_dev.class = &i2c_adapter_class;
 	strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
 	res = class_device_register(&adap->class_dev);
@@ -310,6 +316,12 @@ int i2c_del_adapter(struct i2c_adapter *
 	dev_dbg(dev, "adapter %s [%s] unregistered\n",
 		adap->class_dev.class_id, adap->name);
 
+	/* Temporary hack until i2c_adapter.dev is gone:
+	 * restore the original value of adap->class_dev.dev so
+	 * that adapters can register again. This is important for
+	 * some drivers. */
+	adap->class_dev.dev = adap->dev.parent;
+
  out_unlock:
 	mutex_unlock(&core_lists);
 	return res;

This last part is needed for at least the i2c-amd756-s4882 driver,
because it unregisters an i2c adapter when being loaded and registers it
again when being unloaded. As i2c_add_adapter() now overwrites the
class_dev.dev pointer, we have to restore it before we leave. This
should also help with hotplug, although I am not aware of any
hotpluggable i2c bus at the moment.

Hopefully this side effect of i2c_add_adapter() will not have other
nasty effects... The patch is on its way to -mm now anyway, so we'll
know soon enough if we broke something.

-- 
Jean Delvare



More information about the i2c mailing list