aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c34
1 files changed, 1 insertions, 33 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 21fe1406c8b..40a744d73e8 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -123,28 +123,9 @@ struct device_driver i2c_adapter_driver = {
123 123
124/* I2C bus adapters -- one roots each I2C or SMBUS segment */ 124/* I2C bus adapters -- one roots each I2C or SMBUS segment */
125 125
126static void i2c_adapter_class_dev_release(struct class_device *dev)
127{
128 struct i2c_adapter *adap = class_dev_to_i2c_adapter(dev);
129 complete(&adap->class_dev_released);
130}
131
132static ssize_t i2c_adapter_show_name(struct class_device *cdev, char *buf)
133{
134 struct i2c_adapter *adap = class_dev_to_i2c_adapter(cdev);
135 return sprintf(buf, "%s\n", adap->name);
136}
137
138static struct class_device_attribute i2c_adapter_attrs[] = {
139 __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL),
140 { },
141};
142
143struct class i2c_adapter_class = { 126struct class i2c_adapter_class = {
144 .owner = THIS_MODULE, 127 .owner = THIS_MODULE,
145 .name = "i2c-adapter", 128 .name = "i2c-adapter",
146 .class_dev_attrs = i2c_adapter_attrs,
147 .release = &i2c_adapter_class_dev_release,
148}; 129};
149 130
150static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) 131static 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 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); 204 sprintf(adap->dev.bus_id, "i2c-%d", adap->nr);
224 adap->dev.driver = &i2c_adapter_driver; 205 adap->dev.driver = &i2c_adapter_driver;
225 adap->dev.release = &i2c_adapter_dev_release; 206 adap->dev.release = &i2c_adapter_dev_release;
207 adap->dev.class = &i2c_adapter_class;
226 res = device_register(&adap->dev); 208 res = device_register(&adap->dev);
227 if (res) 209 if (res)
228 goto out_list; 210 goto out_list;
@@ -230,15 +212,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
230 if (res) 212 if (res)
231 goto out_unregister; 213 goto out_unregister;
232 214
233 /* Add this adapter to the i2c_adapter class */
234 memset(&adap->class_dev, 0x00, sizeof(struct class_device));
235 adap->class_dev.dev = &adap->dev;
236 adap->class_dev.class = &i2c_adapter_class;
237 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
238 res = class_device_register(&adap->class_dev);
239 if (res)
240 goto out_remove_name;
241
242 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); 215 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
243 216
244 /* inform drivers of new adapters */ 217 /* inform drivers of new adapters */
@@ -253,8 +226,6 @@ out_unlock:
253 mutex_unlock(&core_lists); 226 mutex_unlock(&core_lists);
254 return res; 227 return res;
255 228
256out_remove_name:
257 device_remove_file(&adap->dev, &dev_attr_name);
258out_unregister: 229out_unregister:
259 init_completion(&adap->dev_released); /* Needed? */ 230 init_completion(&adap->dev_released); /* Needed? */
260 device_unregister(&adap->dev); 231 device_unregister(&adap->dev);
@@ -314,15 +285,12 @@ int i2c_del_adapter(struct i2c_adapter *adap)
314 285
315 /* clean up the sysfs representation */ 286 /* clean up the sysfs representation */
316 init_completion(&adap->dev_released); 287 init_completion(&adap->dev_released);
317 init_completion(&adap->class_dev_released);
318 class_device_unregister(&adap->class_dev);
319 device_remove_file(&adap->dev, &dev_attr_name); 288 device_remove_file(&adap->dev, &dev_attr_name);
320 device_unregister(&adap->dev); 289 device_unregister(&adap->dev);
321 list_del(&adap->list); 290 list_del(&adap->list);
322 291
323 /* wait for sysfs to drop all references */ 292 /* wait for sysfs to drop all references */
324 wait_for_completion(&adap->dev_released); 293 wait_for_completion(&adap->dev_released);
325 wait_for_completion(&adap->class_dev_released);
326 294
327 /* free dynamically allocated bus id */ 295 /* free dynamically allocated bus id */
328 idr_remove(&i2c_adapter_idr, adap->nr); 296 idr_remove(&i2c_adapter_idr, adap->nr);