diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-05-01 17:26:27 -0400 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2007-05-01 17:26:27 -0400 |
commit | fccb56e4d82132ac15359efc9e419371e4533437 (patch) | |
tree | 15bca8fcf2d5b521f9b18979dc1e98e93f29442a /drivers | |
parent | dc87c3985e9b442c60994308a96f887579addc39 (diff) |
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: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/busses/i2c-isa.c | 18 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 34 |
2 files changed, 2 insertions, 50 deletions
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c index 5f33bc9c1e02..a2e75bc9178b 100644 --- a/drivers/i2c/busses/i2c-isa.c +++ b/drivers/i2c/busses/i2c-isa.c | |||
@@ -141,6 +141,7 @@ static int __init i2c_isa_init(void) | |||
141 | sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); | 141 | sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); |
142 | isa_adapter.dev.driver = &i2c_adapter_driver; | 142 | isa_adapter.dev.driver = &i2c_adapter_driver; |
143 | isa_adapter.dev.release = &i2c_adapter_dev_release; | 143 | isa_adapter.dev.release = &i2c_adapter_dev_release; |
144 | isa_adapter.dev.class = &i2c_adapter_class; | ||
144 | err = device_register(&isa_adapter.dev); | 145 | err = device_register(&isa_adapter.dev); |
145 | if (err) { | 146 | if (err) { |
146 | printk(KERN_ERR "i2c-isa: Failed to register device\n"); | 147 | printk(KERN_ERR "i2c-isa: Failed to register device\n"); |
@@ -152,24 +153,10 @@ static int __init i2c_isa_init(void) | |||
152 | goto exit_unregister; | 153 | goto exit_unregister; |
153 | } | 154 | } |
154 | 155 | ||
155 | /* Add this adapter to the i2c_adapter class */ | ||
156 | memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); | ||
157 | isa_adapter.class_dev.dev = &isa_adapter.dev; | ||
158 | isa_adapter.class_dev.class = &i2c_adapter_class; | ||
159 | strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, | ||
160 | BUS_ID_SIZE); | ||
161 | err = class_device_register(&isa_adapter.class_dev); | ||
162 | if (err) { | ||
163 | printk(KERN_ERR "i2c-isa: Failed to register class device\n"); | ||
164 | goto exit_remove_name; | ||
165 | } | ||
166 | |||
167 | dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); | 156 | dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); |
168 | 157 | ||
169 | return 0; | 158 | return 0; |
170 | 159 | ||
171 | exit_remove_name: | ||
172 | device_remove_file(&isa_adapter.dev, &dev_attr_name); | ||
173 | exit_unregister: | 160 | exit_unregister: |
174 | init_completion(&isa_adapter.dev_released); /* Needed? */ | 161 | init_completion(&isa_adapter.dev_released); /* Needed? */ |
175 | device_unregister(&isa_adapter.dev); | 162 | device_unregister(&isa_adapter.dev); |
@@ -201,15 +188,12 @@ static void __exit i2c_isa_exit(void) | |||
201 | /* Clean up the sysfs representation */ | 188 | /* Clean up the sysfs representation */ |
202 | dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); | 189 | dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); |
203 | init_completion(&isa_adapter.dev_released); | 190 | init_completion(&isa_adapter.dev_released); |
204 | init_completion(&isa_adapter.class_dev_released); | ||
205 | class_device_unregister(&isa_adapter.class_dev); | ||
206 | device_remove_file(&isa_adapter.dev, &dev_attr_name); | 191 | device_remove_file(&isa_adapter.dev, &dev_attr_name); |
207 | device_unregister(&isa_adapter.dev); | 192 | device_unregister(&isa_adapter.dev); |
208 | 193 | ||
209 | /* Wait for sysfs to drop all references */ | 194 | /* Wait for sysfs to drop all references */ |
210 | dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); | 195 | dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); |
211 | wait_for_completion(&isa_adapter.dev_released); | 196 | wait_for_completion(&isa_adapter.dev_released); |
212 | wait_for_completion(&isa_adapter.class_dev_released); | ||
213 | 197 | ||
214 | dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); | 198 | dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); |
215 | } | 199 | } |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 21fe1406c8b4..40a744d73e8c 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 | ||
126 | static 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 | |||
132 | static 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 | |||
138 | static struct class_device_attribute i2c_adapter_attrs[] = { | ||
139 | __ATTR(name, S_IRUGO, i2c_adapter_show_name, NULL), | ||
140 | { }, | ||
141 | }; | ||
142 | |||
143 | struct class i2c_adapter_class = { | 126 | struct 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 | ||
150 | static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | 131 | 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 | 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 | ||
256 | out_remove_name: | ||
257 | device_remove_file(&adap->dev, &dev_attr_name); | ||
258 | out_unregister: | 229 | out_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); |