Commit fccb56e4 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

i2c: Kill i2c_adapter.class_dev

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 might need some adjustments. In
particular, libsensors from lm_sensors 2.10.3 or later is required for
proper discovery of i2c adapter names after this change.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent dc87c398
...@@ -190,18 +190,10 @@ Who: Jean Delvare <khali@linux-fr.org> ...@@ -190,18 +190,10 @@ Who: Jean Delvare <khali@linux-fr.org>
--------------------------- ---------------------------
What: i2c_adapter.dev What: i2c_adapter.list
i2c_adapter.list
When: July 2007 When: July 2007
Why: Superfluous, given i2c_adapter.class_dev: Why: Superfluous, this list duplicates the one maintained by the driver
* The "dev" was a stand-in for the physical device node that legacy core.
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.)
Who: Jean Delvare <khali@linux-fr.org>, Who: Jean Delvare <khali@linux-fr.org>,
David Brownell <dbrownell@users.sourceforge.net> David Brownell <dbrownell@users.sourceforge.net>
......
...@@ -141,6 +141,7 @@ static int __init i2c_isa_init(void) ...@@ -141,6 +141,7 @@ static int __init i2c_isa_init(void)
sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
isa_adapter.dev.driver = &i2c_adapter_driver; isa_adapter.dev.driver = &i2c_adapter_driver;
isa_adapter.dev.release = &i2c_adapter_dev_release; isa_adapter.dev.release = &i2c_adapter_dev_release;
isa_adapter.dev.class = &i2c_adapter_class;
err = device_register(&isa_adapter.dev); err = device_register(&isa_adapter.dev);
if (err) { if (err) {
printk(KERN_ERR "i2c-isa: Failed to register device\n"); printk(KERN_ERR "i2c-isa: Failed to register device\n");
...@@ -152,24 +153,10 @@ static int __init i2c_isa_init(void) ...@@ -152,24 +153,10 @@ static int __init i2c_isa_init(void)
goto exit_unregister; 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); dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
return 0; return 0;
exit_remove_name:
device_remove_file(&isa_adapter.dev, &dev_attr_name);
exit_unregister: exit_unregister:
init_completion(&isa_adapter.dev_released); /* Needed? */ init_completion(&isa_adapter.dev_released); /* Needed? */
device_unregister(&isa_adapter.dev); device_unregister(&isa_adapter.dev);
...@@ -201,15 +188,12 @@ static void __exit i2c_isa_exit(void) ...@@ -201,15 +188,12 @@ static void __exit i2c_isa_exit(void)
/* Clean up the sysfs representation */ /* Clean up the sysfs representation */
dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
init_completion(&isa_adapter.dev_released); 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_remove_file(&isa_adapter.dev, &dev_attr_name);
device_unregister(&isa_adapter.dev); device_unregister(&isa_adapter.dev);
/* Wait for sysfs to drop all references */ /* Wait for sysfs to drop all references */
dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
wait_for_completion(&isa_adapter.dev_released); 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); dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
} }
......
...@@ -123,28 +123,9 @@ struct device_driver i2c_adapter_driver = { ...@@ -123,28 +123,9 @@ struct device_driver i2c_adapter_driver = {
/* I2C bus adapters -- one roots each I2C or SMBUS segment */ /* 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 = { struct class i2c_adapter_class = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "i2c-adapter", .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) static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
...@@ -223,6 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -223,6 +204,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
adap->dev.driver = &i2c_adapter_driver; adap->dev.driver = &i2c_adapter_driver;
adap->dev.release = &i2c_adapter_dev_release; adap->dev.release = &i2c_adapter_dev_release;
adap->dev.class = &i2c_adapter_class;
res = device_register(&adap->dev); res = device_register(&adap->dev);
if (res) if (res)
goto out_list; goto out_list;
...@@ -230,15 +212,6 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -230,15 +212,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
if (res) if (res)
goto out_unregister; 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); dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
/* inform drivers of new adapters */ /* inform drivers of new adapters */
...@@ -253,8 +226,6 @@ out_unlock: ...@@ -253,8 +226,6 @@ out_unlock:
mutex_unlock(&core_lists); mutex_unlock(&core_lists);
return res; return res;
out_remove_name:
device_remove_file(&adap->dev, &dev_attr_name);
out_unregister: out_unregister:
init_completion(&adap->dev_released); /* Needed? */ init_completion(&adap->dev_released); /* Needed? */
device_unregister(&adap->dev); device_unregister(&adap->dev);
...@@ -314,15 +285,12 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -314,15 +285,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
/* clean up the sysfs representation */ /* clean up the sysfs representation */
init_completion(&adap->dev_released); 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_remove_file(&adap->dev, &dev_attr_name);
device_unregister(&adap->dev); device_unregister(&adap->dev);
list_del(&adap->list); list_del(&adap->list);
/* wait for sysfs to drop all references */ /* wait for sysfs to drop all references */
wait_for_completion(&adap->dev_released); wait_for_completion(&adap->dev_released);
wait_for_completion(&adap->class_dev_released);
/* free dynamically allocated bus id */ /* free dynamically allocated bus id */
idr_remove(&i2c_adapter_idr, adap->nr); idr_remove(&i2c_adapter_idr, adap->nr);
......
...@@ -228,17 +228,14 @@ struct i2c_adapter { ...@@ -228,17 +228,14 @@ struct i2c_adapter {
int timeout; int timeout;
int retries; int retries;
struct device dev; /* the adapter device */ struct device dev; /* the adapter device */
struct class_device class_dev; /* the class device */
int nr; int nr;
struct list_head clients; struct list_head clients;
struct list_head list; struct list_head list;
char name[I2C_NAME_SIZE]; char name[I2C_NAME_SIZE];
struct completion dev_released; struct completion dev_released;
struct completion class_dev_released;
}; };
#define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) #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) static inline void *i2c_get_adapdata (struct i2c_adapter *dev)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment