aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/attribute_container.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/attribute_container.c')
-rw-r--r--drivers/base/attribute_container.c77
1 files changed, 38 insertions, 39 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 3b43e8a9f87e..f57652db0a2a 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -27,21 +27,21 @@
27struct internal_container { 27struct internal_container {
28 struct klist_node node; 28 struct klist_node node;
29 struct attribute_container *cont; 29 struct attribute_container *cont;
30 struct class_device classdev; 30 struct device classdev;
31}; 31};
32 32
33static void internal_container_klist_get(struct klist_node *n) 33static void internal_container_klist_get(struct klist_node *n)
34{ 34{
35 struct internal_container *ic = 35 struct internal_container *ic =
36 container_of(n, struct internal_container, node); 36 container_of(n, struct internal_container, node);
37 class_device_get(&ic->classdev); 37 get_device(&ic->classdev);
38} 38}
39 39
40static void internal_container_klist_put(struct klist_node *n) 40static void internal_container_klist_put(struct klist_node *n)
41{ 41{
42 struct internal_container *ic = 42 struct internal_container *ic =
43 container_of(n, struct internal_container, node); 43 container_of(n, struct internal_container, node);
44 class_device_put(&ic->classdev); 44 put_device(&ic->classdev);
45} 45}
46 46
47 47
@@ -53,7 +53,7 @@ static void internal_container_klist_put(struct klist_node *n)
53 * Returns the container associated with this classdev. 53 * Returns the container associated with this classdev.
54 */ 54 */
55struct attribute_container * 55struct attribute_container *
56attribute_container_classdev_to_container(struct class_device *classdev) 56attribute_container_classdev_to_container(struct device *classdev)
57{ 57{
58 struct internal_container *ic = 58 struct internal_container *ic =
59 container_of(classdev, struct internal_container, classdev); 59 container_of(classdev, struct internal_container, classdev);
@@ -110,11 +110,11 @@ attribute_container_unregister(struct attribute_container *cont)
110EXPORT_SYMBOL_GPL(attribute_container_unregister); 110EXPORT_SYMBOL_GPL(attribute_container_unregister);
111 111
112/* private function used as class release */ 112/* private function used as class release */
113static void attribute_container_release(struct class_device *classdev) 113static void attribute_container_release(struct device *classdev)
114{ 114{
115 struct internal_container *ic 115 struct internal_container *ic
116 = container_of(classdev, struct internal_container, classdev); 116 = container_of(classdev, struct internal_container, classdev);
117 struct device *dev = classdev->dev; 117 struct device *dev = classdev->parent;
118 118
119 kfree(ic); 119 kfree(ic);
120 put_device(dev); 120 put_device(dev);
@@ -129,12 +129,12 @@ static void attribute_container_release(struct class_device *classdev)
129 * This function allocates storage for the class device(s) to be 129 * This function allocates storage for the class device(s) to be
130 * attached to dev (one for each matching attribute_container). If no 130 * attached to dev (one for each matching attribute_container). If no
131 * fn is provided, the code will simply register the class device via 131 * fn is provided, the code will simply register the class device via
132 * class_device_add. If a function is provided, it is expected to add 132 * device_add. If a function is provided, it is expected to add
133 * the class device at the appropriate time. One of the things that 133 * the class device at the appropriate time. One of the things that
134 * might be necessary is to allocate and initialise the classdev and 134 * might be necessary is to allocate and initialise the classdev and
135 * then add it a later time. To do this, call this routine for 135 * then add it a later time. To do this, call this routine for
136 * allocation and initialisation and then use 136 * allocation and initialisation and then use
137 * attribute_container_device_trigger() to call class_device_add() on 137 * attribute_container_device_trigger() to call device_add() on
138 * it. Note: after this, the class device contains a reference to dev 138 * it. Note: after this, the class device contains a reference to dev
139 * which is not relinquished until the release of the classdev. 139 * which is not relinquished until the release of the classdev.
140 */ 140 */
@@ -142,7 +142,7 @@ void
142attribute_container_add_device(struct device *dev, 142attribute_container_add_device(struct device *dev,
143 int (*fn)(struct attribute_container *, 143 int (*fn)(struct attribute_container *,
144 struct device *, 144 struct device *,
145 struct class_device *)) 145 struct device *))
146{ 146{
147 struct attribute_container *cont; 147 struct attribute_container *cont;
148 148
@@ -163,11 +163,11 @@ attribute_container_add_device(struct device *dev,
163 } 163 }
164 164
165 ic->cont = cont; 165 ic->cont = cont;
166 class_device_initialize(&ic->classdev); 166 device_initialize(&ic->classdev);
167 ic->classdev.dev = get_device(dev); 167 ic->classdev.parent = get_device(dev);
168 ic->classdev.class = cont->class; 168 ic->classdev.class = cont->class;
169 cont->class->release = attribute_container_release; 169 cont->class->dev_release = attribute_container_release;
170 strcpy(ic->classdev.class_id, dev->bus_id); 170 strcpy(ic->classdev.bus_id, dev->bus_id);
171 if (fn) 171 if (fn)
172 fn(cont, dev, &ic->classdev); 172 fn(cont, dev, &ic->classdev);
173 else 173 else
@@ -195,20 +195,19 @@ attribute_container_add_device(struct device *dev,
195 * @fn: A function to call to remove the device 195 * @fn: A function to call to remove the device
196 * 196 *
197 * This routine triggers device removal. If fn is NULL, then it is 197 * This routine triggers device removal. If fn is NULL, then it is
198 * simply done via class_device_unregister (note that if something 198 * simply done via device_unregister (note that if something
199 * still has a reference to the classdev, then the memory occupied 199 * still has a reference to the classdev, then the memory occupied
200 * will not be freed until the classdev is released). If you want a 200 * will not be freed until the classdev is released). If you want a
201 * two phase release: remove from visibility and then delete the 201 * two phase release: remove from visibility and then delete the
202 * device, then you should use this routine with a fn that calls 202 * device, then you should use this routine with a fn that calls
203 * class_device_del() and then use 203 * device_del() and then use attribute_container_device_trigger()
204 * attribute_container_device_trigger() to do the final put on the 204 * to do the final put on the classdev.
205 * classdev.
206 */ 205 */
207void 206void
208attribute_container_remove_device(struct device *dev, 207attribute_container_remove_device(struct device *dev,
209 void (*fn)(struct attribute_container *, 208 void (*fn)(struct attribute_container *,
210 struct device *, 209 struct device *,
211 struct class_device *)) 210 struct device *))
212{ 211{
213 struct attribute_container *cont; 212 struct attribute_container *cont;
214 213
@@ -224,14 +223,14 @@ attribute_container_remove_device(struct device *dev,
224 continue; 223 continue;
225 224
226 klist_for_each_entry(ic, &cont->containers, node, &iter) { 225 klist_for_each_entry(ic, &cont->containers, node, &iter) {
227 if (dev != ic->classdev.dev) 226 if (dev != ic->classdev.parent)
228 continue; 227 continue;
229 klist_del(&ic->node); 228 klist_del(&ic->node);
230 if (fn) 229 if (fn)
231 fn(cont, dev, &ic->classdev); 230 fn(cont, dev, &ic->classdev);
232 else { 231 else {
233 attribute_container_remove_attrs(&ic->classdev); 232 attribute_container_remove_attrs(&ic->classdev);
234 class_device_unregister(&ic->classdev); 233 device_unregister(&ic->classdev);
235 } 234 }
236 } 235 }
237 } 236 }
@@ -252,7 +251,7 @@ void
252attribute_container_device_trigger(struct device *dev, 251attribute_container_device_trigger(struct device *dev,
253 int (*fn)(struct attribute_container *, 252 int (*fn)(struct attribute_container *,
254 struct device *, 253 struct device *,
255 struct class_device *)) 254 struct device *))
256{ 255{
257 struct attribute_container *cont; 256 struct attribute_container *cont;
258 257
@@ -270,7 +269,7 @@ attribute_container_device_trigger(struct device *dev,
270 } 269 }
271 270
272 klist_for_each_entry(ic, &cont->containers, node, &iter) { 271 klist_for_each_entry(ic, &cont->containers, node, &iter) {
273 if (dev == ic->classdev.dev) 272 if (dev == ic->classdev.parent)
274 fn(cont, dev, &ic->classdev); 273 fn(cont, dev, &ic->classdev);
275 } 274 }
276 } 275 }
@@ -313,11 +312,11 @@ attribute_container_trigger(struct device *dev,
313 * attributes listed in the container 312 * attributes listed in the container
314 */ 313 */
315int 314int
316attribute_container_add_attrs(struct class_device *classdev) 315attribute_container_add_attrs(struct device *classdev)
317{ 316{
318 struct attribute_container *cont = 317 struct attribute_container *cont =
319 attribute_container_classdev_to_container(classdev); 318 attribute_container_classdev_to_container(classdev);
320 struct class_device_attribute **attrs = cont->attrs; 319 struct device_attribute **attrs = cont->attrs;
321 int i, error; 320 int i, error;
322 321
323 BUG_ON(attrs && cont->grp); 322 BUG_ON(attrs && cont->grp);
@@ -329,7 +328,7 @@ attribute_container_add_attrs(struct class_device *classdev)
329 return sysfs_create_group(&classdev->kobj, cont->grp); 328 return sysfs_create_group(&classdev->kobj, cont->grp);
330 329
331 for (i = 0; attrs[i]; i++) { 330 for (i = 0; attrs[i]; i++) {
332 error = class_device_create_file(classdev, attrs[i]); 331 error = device_create_file(classdev, attrs[i]);
333 if (error) 332 if (error)
334 return error; 333 return error;
335 } 334 }
@@ -338,18 +337,18 @@ attribute_container_add_attrs(struct class_device *classdev)
338} 337}
339 338
340/** 339/**
341 * attribute_container_add_class_device - same function as class_device_add 340 * attribute_container_add_class_device - same function as device_add
342 * 341 *
343 * @classdev: the class device to add 342 * @classdev: the class device to add
344 * 343 *
345 * This performs essentially the same function as class_device_add except for 344 * This performs essentially the same function as device_add except for
346 * attribute containers, namely add the classdev to the system and then 345 * attribute containers, namely add the classdev to the system and then
347 * create the attribute files 346 * create the attribute files
348 */ 347 */
349int 348int
350attribute_container_add_class_device(struct class_device *classdev) 349attribute_container_add_class_device(struct device *classdev)
351{ 350{
352 int error = class_device_add(classdev); 351 int error = device_add(classdev);
353 if (error) 352 if (error)
354 return error; 353 return error;
355 return attribute_container_add_attrs(classdev); 354 return attribute_container_add_attrs(classdev);
@@ -364,7 +363,7 @@ attribute_container_add_class_device(struct class_device *classdev)
364int 363int
365attribute_container_add_class_device_adapter(struct attribute_container *cont, 364attribute_container_add_class_device_adapter(struct attribute_container *cont,
366 struct device *dev, 365 struct device *dev,
367 struct class_device *classdev) 366 struct device *classdev)
368{ 367{
369 return attribute_container_add_class_device(classdev); 368 return attribute_container_add_class_device(classdev);
370} 369}
@@ -376,11 +375,11 @@ attribute_container_add_class_device_adapter(struct attribute_container *cont,
376 * 375 *
377 */ 376 */
378void 377void
379attribute_container_remove_attrs(struct class_device *classdev) 378attribute_container_remove_attrs(struct device *classdev)
380{ 379{
381 struct attribute_container *cont = 380 struct attribute_container *cont =
382 attribute_container_classdev_to_container(classdev); 381 attribute_container_classdev_to_container(classdev);
383 struct class_device_attribute **attrs = cont->attrs; 382 struct device_attribute **attrs = cont->attrs;
384 int i; 383 int i;
385 384
386 if (!attrs && !cont->grp) 385 if (!attrs && !cont->grp)
@@ -392,7 +391,7 @@ attribute_container_remove_attrs(struct class_device *classdev)
392 } 391 }
393 392
394 for (i = 0; attrs[i]; i++) 393 for (i = 0; attrs[i]; i++)
395 class_device_remove_file(classdev, attrs[i]); 394 device_remove_file(classdev, attrs[i]);
396} 395}
397 396
398/** 397/**
@@ -401,13 +400,13 @@ attribute_container_remove_attrs(struct class_device *classdev)
401 * @classdev: the class device 400 * @classdev: the class device
402 * 401 *
403 * This function simply removes all the attribute files and then calls 402 * This function simply removes all the attribute files and then calls
404 * class_device_del. 403 * device_del.
405 */ 404 */
406void 405void
407attribute_container_class_device_del(struct class_device *classdev) 406attribute_container_class_device_del(struct device *classdev)
408{ 407{
409 attribute_container_remove_attrs(classdev); 408 attribute_container_remove_attrs(classdev);
410 class_device_del(classdev); 409 device_del(classdev);
411} 410}
412 411
413/** 412/**
@@ -419,16 +418,16 @@ attribute_container_class_device_del(struct class_device *classdev)
419 * Looks up the device in the container's list of class devices and returns 418 * Looks up the device in the container's list of class devices and returns
420 * the corresponding class_device. 419 * the corresponding class_device.
421 */ 420 */
422struct class_device * 421struct device *
423attribute_container_find_class_device(struct attribute_container *cont, 422attribute_container_find_class_device(struct attribute_container *cont,
424 struct device *dev) 423 struct device *dev)
425{ 424{
426 struct class_device *cdev = NULL; 425 struct device *cdev = NULL;
427 struct internal_container *ic; 426 struct internal_container *ic;
428 struct klist_iter iter; 427 struct klist_iter iter;
429 428
430 klist_for_each_entry(ic, &cont->containers, node, &iter) { 429 klist_for_each_entry(ic, &cont->containers, node, &iter) {
431 if (ic->classdev.dev == dev) { 430 if (ic->classdev.parent == dev) {
432 cdev = &ic->classdev; 431 cdev = &ic->classdev;
433 /* FIXME: must exit iterator then break */ 432 /* FIXME: must exit iterator then break */
434 klist_iter_exit(&iter); 433 klist_iter_exit(&iter);