aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/enclosure.c118
1 files changed, 64 insertions, 54 deletions
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 6fcb0e96adf4..fafb57fed761 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -40,16 +40,16 @@ static struct class enclosure_component_class;
40 * Looks through the list of registered enclosures to see 40 * Looks through the list of registered enclosures to see
41 * if it can find a match for a device. Returns NULL if no 41 * if it can find a match for a device. Returns NULL if no
42 * enclosure is found. Obtains a reference to the enclosure class 42 * enclosure is found. Obtains a reference to the enclosure class
43 * device which must be released with class_device_put(). 43 * device which must be released with device_put().
44 */ 44 */
45struct enclosure_device *enclosure_find(struct device *dev) 45struct enclosure_device *enclosure_find(struct device *dev)
46{ 46{
47 struct enclosure_device *edev = NULL; 47 struct enclosure_device *edev;
48 48
49 mutex_lock(&container_list_lock); 49 mutex_lock(&container_list_lock);
50 list_for_each_entry(edev, &container_list, node) { 50 list_for_each_entry(edev, &container_list, node) {
51 if (edev->cdev.dev == dev) { 51 if (edev->edev.parent == dev) {
52 class_device_get(&edev->cdev); 52 get_device(&edev->edev);
53 mutex_unlock(&container_list_lock); 53 mutex_unlock(&container_list_lock);
54 return edev; 54 return edev;
55 } 55 }
@@ -117,11 +117,11 @@ enclosure_register(struct device *dev, const char *name, int components,
117 117
118 edev->components = components; 118 edev->components = components;
119 119
120 edev->cdev.class = &enclosure_class; 120 edev->edev.class = &enclosure_class;
121 edev->cdev.dev = get_device(dev); 121 edev->edev.parent = get_device(dev);
122 edev->cb = cb; 122 edev->cb = cb;
123 snprintf(edev->cdev.class_id, BUS_ID_SIZE, "%s", name); 123 snprintf(edev->edev.bus_id, BUS_ID_SIZE, "%s", name);
124 err = class_device_register(&edev->cdev); 124 err = device_register(&edev->edev);
125 if (err) 125 if (err)
126 goto err; 126 goto err;
127 127
@@ -135,7 +135,7 @@ enclosure_register(struct device *dev, const char *name, int components,
135 return edev; 135 return edev;
136 136
137 err: 137 err:
138 put_device(edev->cdev.dev); 138 put_device(edev->edev.parent);
139 kfree(edev); 139 kfree(edev);
140 return ERR_PTR(err); 140 return ERR_PTR(err);
141} 141}
@@ -158,27 +158,28 @@ void enclosure_unregister(struct enclosure_device *edev)
158 158
159 for (i = 0; i < edev->components; i++) 159 for (i = 0; i < edev->components; i++)
160 if (edev->component[i].number != -1) 160 if (edev->component[i].number != -1)
161 class_device_unregister(&edev->component[i].cdev); 161 device_unregister(&edev->component[i].cdev);
162 162
163 /* prevent any callbacks into service user */ 163 /* prevent any callbacks into service user */
164 edev->cb = &enclosure_null_callbacks; 164 edev->cb = &enclosure_null_callbacks;
165 class_device_unregister(&edev->cdev); 165 device_unregister(&edev->edev);
166} 166}
167EXPORT_SYMBOL_GPL(enclosure_unregister); 167EXPORT_SYMBOL_GPL(enclosure_unregister);
168 168
169static void enclosure_release(struct class_device *cdev) 169static void enclosure_release(struct device *cdev)
170{ 170{
171 struct enclosure_device *edev = to_enclosure_device(cdev); 171 struct enclosure_device *edev = to_enclosure_device(cdev);
172 172
173 put_device(cdev->dev); 173 put_device(cdev->parent);
174 kfree(edev); 174 kfree(edev);
175} 175}
176 176
177static void enclosure_component_release(struct class_device *cdev) 177static void enclosure_component_release(struct device *dev)
178{ 178{
179 if (cdev->dev) 179 struct enclosure_component *cdev = to_enclosure_component(dev);
180 put_device(cdev->dev); 180
181 class_device_put(cdev->parent); 181 put_device(cdev->dev);
182 put_device(dev->parent);
182} 183}
183 184
184/** 185/**
@@ -201,7 +202,7 @@ enclosure_component_register(struct enclosure_device *edev,
201 const char *name) 202 const char *name)
202{ 203{
203 struct enclosure_component *ecomp; 204 struct enclosure_component *ecomp;
204 struct class_device *cdev; 205 struct device *cdev;
205 int err; 206 int err;
206 207
207 if (number >= edev->components) 208 if (number >= edev->components)
@@ -215,14 +216,14 @@ enclosure_component_register(struct enclosure_device *edev,
215 ecomp->type = type; 216 ecomp->type = type;
216 ecomp->number = number; 217 ecomp->number = number;
217 cdev = &ecomp->cdev; 218 cdev = &ecomp->cdev;
218 cdev->parent = class_device_get(&edev->cdev); 219 cdev->parent = get_device(&edev->edev);
219 cdev->class = &enclosure_component_class; 220 cdev->class = &enclosure_component_class;
220 if (name) 221 if (name)
221 snprintf(cdev->class_id, BUS_ID_SIZE, "%s", name); 222 snprintf(cdev->bus_id, BUS_ID_SIZE, "%s", name);
222 else 223 else
223 snprintf(cdev->class_id, BUS_ID_SIZE, "%u", number); 224 snprintf(cdev->bus_id, BUS_ID_SIZE, "%u", number);
224 225
225 err = class_device_register(cdev); 226 err = device_register(cdev);
226 if (err) 227 if (err)
227 ERR_PTR(err); 228 ERR_PTR(err);
228 229
@@ -247,18 +248,17 @@ EXPORT_SYMBOL_GPL(enclosure_component_register);
247int enclosure_add_device(struct enclosure_device *edev, int component, 248int enclosure_add_device(struct enclosure_device *edev, int component,
248 struct device *dev) 249 struct device *dev)
249{ 250{
250 struct class_device *cdev; 251 struct enclosure_component *cdev;
251 252
252 if (!edev || component >= edev->components) 253 if (!edev || component >= edev->components)
253 return -EINVAL; 254 return -EINVAL;
254 255
255 cdev = &edev->component[component].cdev; 256 cdev = &edev->component[component];
256 257
257 class_device_del(cdev); 258 device_del(&cdev->cdev);
258 if (cdev->dev) 259 put_device(cdev->dev);
259 put_device(cdev->dev);
260 cdev->dev = get_device(dev); 260 cdev->dev = get_device(dev);
261 return class_device_add(cdev); 261 return device_add(&cdev->cdev);
262} 262}
263EXPORT_SYMBOL_GPL(enclosure_add_device); 263EXPORT_SYMBOL_GPL(enclosure_add_device);
264 264
@@ -272,18 +272,17 @@ EXPORT_SYMBOL_GPL(enclosure_add_device);
272 */ 272 */
273int enclosure_remove_device(struct enclosure_device *edev, int component) 273int enclosure_remove_device(struct enclosure_device *edev, int component)
274{ 274{
275 struct class_device *cdev; 275 struct enclosure_component *cdev;
276 276
277 if (!edev || component >= edev->components) 277 if (!edev || component >= edev->components)
278 return -EINVAL; 278 return -EINVAL;
279 279
280 cdev = &edev->component[component].cdev; 280 cdev = &edev->component[component];
281 281
282 class_device_del(cdev); 282 device_del(&cdev->cdev);
283 if (cdev->dev) 283 put_device(cdev->dev);
284 put_device(cdev->dev);
285 cdev->dev = NULL; 284 cdev->dev = NULL;
286 return class_device_add(cdev); 285 return device_add(&cdev->cdev);
287} 286}
288EXPORT_SYMBOL_GPL(enclosure_remove_device); 287EXPORT_SYMBOL_GPL(enclosure_remove_device);
289 288
@@ -291,14 +290,16 @@ EXPORT_SYMBOL_GPL(enclosure_remove_device);
291 * sysfs pieces below 290 * sysfs pieces below
292 */ 291 */
293 292
294static ssize_t enclosure_show_components(struct class_device *cdev, char *buf) 293static ssize_t enclosure_show_components(struct device *cdev,
294 struct device_attribute *attr,
295 char *buf)
295{ 296{
296 struct enclosure_device *edev = to_enclosure_device(cdev); 297 struct enclosure_device *edev = to_enclosure_device(cdev);
297 298
298 return snprintf(buf, 40, "%d\n", edev->components); 299 return snprintf(buf, 40, "%d\n", edev->components);
299} 300}
300 301
301static struct class_device_attribute enclosure_attrs[] = { 302static struct device_attribute enclosure_attrs[] = {
302 __ATTR(components, S_IRUGO, enclosure_show_components, NULL), 303 __ATTR(components, S_IRUGO, enclosure_show_components, NULL),
303 __ATTR_NULL 304 __ATTR_NULL
304}; 305};
@@ -306,8 +307,8 @@ static struct class_device_attribute enclosure_attrs[] = {
306static struct class enclosure_class = { 307static struct class enclosure_class = {
307 .name = "enclosure", 308 .name = "enclosure",
308 .owner = THIS_MODULE, 309 .owner = THIS_MODULE,
309 .release = enclosure_release, 310 .dev_release = enclosure_release,
310 .class_dev_attrs = enclosure_attrs, 311 .dev_attrs = enclosure_attrs,
311}; 312};
312 313
313static const char *const enclosure_status [] = { 314static const char *const enclosure_status [] = {
@@ -326,7 +327,8 @@ static const char *const enclosure_type [] = {
326 [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device", 327 [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device",
327}; 328};
328 329
329static ssize_t get_component_fault(struct class_device *cdev, char *buf) 330static ssize_t get_component_fault(struct device *cdev,
331 struct device_attribute *attr, char *buf)
330{ 332{
331 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 333 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
332 struct enclosure_component *ecomp = to_enclosure_component(cdev); 334 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -336,8 +338,9 @@ static ssize_t get_component_fault(struct class_device *cdev, char *buf)
336 return snprintf(buf, 40, "%d\n", ecomp->fault); 338 return snprintf(buf, 40, "%d\n", ecomp->fault);
337} 339}
338 340
339static ssize_t set_component_fault(struct class_device *cdev, const char *buf, 341static ssize_t set_component_fault(struct device *cdev,
340 size_t count) 342 struct device_attribute *attr,
343 const char *buf, size_t count)
341{ 344{
342 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 345 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
343 struct enclosure_component *ecomp = to_enclosure_component(cdev); 346 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -348,7 +351,8 @@ static ssize_t set_component_fault(struct class_device *cdev, const char *buf,
348 return count; 351 return count;
349} 352}
350 353
351static ssize_t get_component_status(struct class_device *cdev, char *buf) 354static ssize_t get_component_status(struct device *cdev,
355 struct device_attribute *attr,char *buf)
352{ 356{
353 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 357 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
354 struct enclosure_component *ecomp = to_enclosure_component(cdev); 358 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -358,8 +362,9 @@ static ssize_t get_component_status(struct class_device *cdev, char *buf)
358 return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]); 362 return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]);
359} 363}
360 364
361static ssize_t set_component_status(struct class_device *cdev, const char *buf, 365static ssize_t set_component_status(struct device *cdev,
362 size_t count) 366 struct device_attribute *attr,
367 const char *buf, size_t count)
363{ 368{
364 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 369 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
365 struct enclosure_component *ecomp = to_enclosure_component(cdev); 370 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -380,7 +385,8 @@ static ssize_t set_component_status(struct class_device *cdev, const char *buf,
380 return -EINVAL; 385 return -EINVAL;
381} 386}
382 387
383static ssize_t get_component_active(struct class_device *cdev, char *buf) 388static ssize_t get_component_active(struct device *cdev,
389 struct device_attribute *attr, char *buf)
384{ 390{
385 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 391 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
386 struct enclosure_component *ecomp = to_enclosure_component(cdev); 392 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -390,8 +396,9 @@ static ssize_t get_component_active(struct class_device *cdev, char *buf)
390 return snprintf(buf, 40, "%d\n", ecomp->active); 396 return snprintf(buf, 40, "%d\n", ecomp->active);
391} 397}
392 398
393static ssize_t set_component_active(struct class_device *cdev, const char *buf, 399static ssize_t set_component_active(struct device *cdev,
394 size_t count) 400 struct device_attribute *attr,
401 const char *buf, size_t count)
395{ 402{
396 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 403 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
397 struct enclosure_component *ecomp = to_enclosure_component(cdev); 404 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -402,7 +409,8 @@ static ssize_t set_component_active(struct class_device *cdev, const char *buf,
402 return count; 409 return count;
403} 410}
404 411
405static ssize_t get_component_locate(struct class_device *cdev, char *buf) 412static ssize_t get_component_locate(struct device *cdev,
413 struct device_attribute *attr, char *buf)
406{ 414{
407 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 415 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
408 struct enclosure_component *ecomp = to_enclosure_component(cdev); 416 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -412,8 +420,9 @@ static ssize_t get_component_locate(struct class_device *cdev, char *buf)
412 return snprintf(buf, 40, "%d\n", ecomp->locate); 420 return snprintf(buf, 40, "%d\n", ecomp->locate);
413} 421}
414 422
415static ssize_t set_component_locate(struct class_device *cdev, const char *buf, 423static ssize_t set_component_locate(struct device *cdev,
416 size_t count) 424 struct device_attribute *attr,
425 const char *buf, size_t count)
417{ 426{
418 struct enclosure_device *edev = to_enclosure_device(cdev->parent); 427 struct enclosure_device *edev = to_enclosure_device(cdev->parent);
419 struct enclosure_component *ecomp = to_enclosure_component(cdev); 428 struct enclosure_component *ecomp = to_enclosure_component(cdev);
@@ -424,7 +433,8 @@ static ssize_t set_component_locate(struct class_device *cdev, const char *buf,
424 return count; 433 return count;
425} 434}
426 435
427static ssize_t get_component_type(struct class_device *cdev, char *buf) 436static ssize_t get_component_type(struct device *cdev,
437 struct device_attribute *attr, char *buf)
428{ 438{
429 struct enclosure_component *ecomp = to_enclosure_component(cdev); 439 struct enclosure_component *ecomp = to_enclosure_component(cdev);
430 440
@@ -432,7 +442,7 @@ static ssize_t get_component_type(struct class_device *cdev, char *buf)
432} 442}
433 443
434 444
435static struct class_device_attribute enclosure_component_attrs[] = { 445static struct device_attribute enclosure_component_attrs[] = {
436 __ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault, 446 __ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
437 set_component_fault), 447 set_component_fault),
438 __ATTR(status, S_IRUGO | S_IWUSR, get_component_status, 448 __ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
@@ -448,8 +458,8 @@ static struct class_device_attribute enclosure_component_attrs[] = {
448static struct class enclosure_component_class = { 458static struct class enclosure_component_class = {
449 .name = "enclosure_component", 459 .name = "enclosure_component",
450 .owner = THIS_MODULE, 460 .owner = THIS_MODULE,
451 .class_dev_attrs = enclosure_component_attrs, 461 .dev_attrs = enclosure_component_attrs,
452 .release = enclosure_component_release, 462 .dev_release = enclosure_component_release,
453}; 463};
454 464
455static int __init enclosure_init(void) 465static int __init enclosure_init(void)