[i2c] [PATCH 4/6] i2c: Kill i2c_adapter.class_dev

Jean Delvare khali at linux-fr.org
Sat Feb 10 18:04:14 CET 2007


Kill i2c_adapter.class_dev. Instead, set the class of i2c_adapter.dev
to i2c_adapter_class, so that a symlink will be created for every
i2c_adapter in /sys/class/i2c-adapter.

The same change must be mirrored to i2c-isa as it duplicates some
of the i2c-core functionalities.

User-space tools and libraries such as libsensors might need some
adjustments.

Sigend-off-by: Jean Delvare <khali at linux-fr.org>
---
 Documentation/feature-removal-schedule.txt |   14 +++---------
 drivers/i2c/busses/i2c-isa.c               |   18 +--------------
 drivers/i2c/i2c-core.c                     |   34 +---------------------------
 include/linux/i2c.h                        |    3 --
 4 files changed, 5 insertions(+), 64 deletions(-)

--- linux-2.6.21-pre.orig/drivers/i2c/busses/i2c-isa.c	2007-02-10 10:38:11.000000000 +0100
+++ linux-2.6.21-pre/drivers/i2c/busses/i2c-isa.c	2007-02-10 12:35:55.000000000 +0100
@@ -141,6 +141,7 @@ static int __init i2c_isa_init(void)
 	sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
 	isa_adapter.dev.driver = &i2c_adapter_driver;
 	isa_adapter.dev.release = &i2c_adapter_dev_release;
+	isa_adapter.dev.class = &i2c_adapter_class;
 	err = device_register(&isa_adapter.dev);
 	if (err) {
 		printk(KERN_ERR "i2c-isa: Failed to register device\n");
@@ -152,24 +153,10 @@ static int __init i2c_isa_init(void)
 		goto exit_unregister;
 	}
 
-	/* Add this adapter to the i2c_adapter class */
-	memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
-	isa_adapter.class_dev.dev = &isa_adapter.dev;
-	isa_adapter.class_dev.class = &i2c_adapter_class;
-	strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
-		BUS_ID_SIZE);
-	err = class_device_register(&isa_adapter.class_dev);
-	if (err) {
-		printk(KERN_ERR "i2c-isa: Failed to register class device\n");
-		goto exit_remove_name;
-	}
-
 	dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
 
 	return 0;
 
-exit_remove_name:
-	device_remove_file(&isa_adapter.dev, &dev_attr_name);
 exit_unregister:
 	init_completion(&isa_adapter.dev_released); /* Needed? */
 	device_unregister(&isa_adapter.dev);
@@ -201,15 +188,12 @@ static void __exit i2c_isa_exit(void)
 	/* Clean up the sysfs representation */
 	dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
 	init_completion(&isa_adapter.dev_released);
-	init_completion(&isa_adapter.class_dev_released);
-	class_device_unregister(&isa_adapter.class_dev);
 	device_remove_file(&isa_adapter.dev, &dev_attr_name);
 	device_unregister(&isa_adapter.dev);
 
 	/* Wait for sysfs to drop all references */
 	dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
 	wait_for_completion(&isa_adapter.dev_released);
-	wait_for_completion(&isa_adapter.class_dev_released);
 
 	dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
 }
--- linux-2.6.21-pre.orig/drivers/i2c/i2c-core.c	2007-02-10 10:38:12.000000000 +0100
+++ linux-2.6.21-pre/drivers/i2c/i2c-core.c	2007-02-10 12:35:55.000000000 +0100
@@ -123,28 +123,9 @@ struct device_driver i2c_adapter_driver 
 
 /* I2C bus adapters -- one roots each I2C or SMBUS segment */
 
-static void i2c_adapter_class_dev_release(struct class_device *dev)
-{
-	struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev);
-	complete(&adap->class_dev_released);
-}
-
-static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf)
-{
-	struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev);
-	return sprintf(buf, "%s\n", adap->name);
-}
-
-static struct class_device_attribute i2c_adapter_attrs[] = {
-	__ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL),
-	{ },
-};
-
 struct class i2c_adapter_class = {
 	.owner			= THIS_MODULE,
 	.name			= "i2c-adapter",
-	.class_dev_attrs	= i2c_adapter_attrs,
-	.release		= &i2c_adapter_class_dev_release,
 };
 
 static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
@@ -224,6 +205,7 @@ int i2c_add_adapter(struct i2c_adapter *
 	sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
 	adap->dev.driver = &i2c_adapter_driver;
 	adap->dev.release = &i2c_adapter_dev_release;
+	adap->dev.class = &i2c_adapter_class;
 	res = device_register(&adap->dev);
 	if (res)
 		goto out_list;
@@ -231,15 +213,6 @@ int i2c_add_adapter(struct i2c_adapter *
 	if (res)
 		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);
-	if (res)
-		goto out_remove_name;
-
 	dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
 
 	/* inform drivers of new adapters */
@@ -254,8 +227,6 @@ out_unlock:
 	mutex_unlock(&core_lists);
 	return res;
 
-out_remove_name:
-	device_remove_file(&adap->dev, &dev_attr_name);
 out_unregister:
 	init_completion(&adap->dev_released); /* Needed? */
 	device_unregister(&adap->dev);
@@ -315,15 +286,12 @@ int i2c_del_adapter(struct i2c_adapter *
 
 	/* clean up the sysfs representation */
 	init_completion(&adap->dev_released);
-	init_completion(&adap->class_dev_released);
-	class_device_unregister(&adap->class_dev);
 	device_remove_file(&adap->dev, &dev_attr_name);
 	device_unregister(&adap->dev);
 	list_del(&adap->list);
 
 	/* wait for sysfs to drop all references */
 	wait_for_completion(&adap->dev_released);
-	wait_for_completion(&adap->class_dev_released);
 
 	/* free dynamically allocated bus id */
 	idr_remove(&i2c_adapter_idr, adap->nr);
--- linux-2.6.21-pre.orig/include/linux/i2c.h	2007-02-10 10:38:12.000000000 +0100
+++ linux-2.6.21-pre/include/linux/i2c.h	2007-02-10 12:35:55.000000000 +0100
@@ -228,17 +228,14 @@ struct i2c_adapter {
 	int timeout;
 	int retries;
 	struct device dev;		/* the adapter device */
-	struct class_device class_dev;	/* the class device */
 
 	int nr;
 	struct list_head clients;
 	struct list_head list;
 	char name[I2C_NAME_SIZE];
 	struct completion dev_released;
-	struct completion class_dev_released;
 };
 #define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
-#define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev)
 
 static inline void *i2c_get_adapdata (struct i2c_adapter *dev)
 {
--- linux-2.6.21-pre.orig/Documentation/feature-removal-schedule.txt	2007-02-10 10:35:11.000000000 +0100
+++ linux-2.6.21-pre/Documentation/feature-removal-schedule.txt	2007-02-10 12:35:55.000000000 +0100
@@ -198,18 +198,10 @@ Who:	Jean Delvare <khali at linux-fr.org>
 
 ---------------------------
 
-What:	i2c_adapter.dev
-	i2c_adapter.list
+What:	i2c_adapter.list
 When:	July 2007
-Why:	Superfluous, given i2c_adapter.class_dev:
-	  * The "dev" was a stand-in for the physical device node that legacy
-	    drivers would not have; but now it's almost always present.  Any
-	    remaining legacy drivers must upgrade (they now trigger warnings).
-	  * The "list" duplicates class device children.
-	The delay in removing this is so upgraded lm_sensors and libsensors
-	can get deployed.  (Removal causes minor changes in the sysfs layout,
-	notably the location of the adapter type name and parenting the i2c
-	client hardware directly from their controller.)
+Why:	Superfluous, this list duplicates the one maintained by the driver
+	core.
 Who:	Jean Delvare <khali at linux-fr.org>,
 	David Brownell <dbrownell at users.sourceforge.net>
 

-- 
Jean Delvare



More information about the i2c mailing list