aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/device-drivers.tmpl1
-rw-r--r--drivers/base/platform.c104
-rw-r--r--include/linux/platform_device.h62
3 files changed, 85 insertions, 82 deletions
diff --git a/Documentation/DocBook/device-drivers.tmpl b/Documentation/DocBook/device-drivers.tmpl
index 1b2dd4fc3db2..ecd35e9d4410 100644
--- a/Documentation/DocBook/device-drivers.tmpl
+++ b/Documentation/DocBook/device-drivers.tmpl
@@ -111,6 +111,7 @@ X!Edrivers/base/attribute_container.c
111<!-- 111<!--
112X!Edrivers/base/interface.c 112X!Edrivers/base/interface.c
113--> 113-->
114!Iinclude/linux/platform_device.h
114!Edrivers/base/platform.c 115!Edrivers/base/platform.c
115!Edrivers/base/bus.c 116!Edrivers/base/bus.c
116 </sect1> 117 </sect1>
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 26eb69d88eb6..ffcfd73fe8a6 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -344,108 +344,56 @@ void platform_device_unregister(struct platform_device *pdev)
344EXPORT_SYMBOL_GPL(platform_device_unregister); 344EXPORT_SYMBOL_GPL(platform_device_unregister);
345 345
346/** 346/**
347 * platform_device_register_simple - add a platform-level device and its resources 347 * platform_device_register_resndata - add a platform-level device with
348 * @name: base name of the device we're adding 348 * resources and platform-specific data
349 * @id: instance id
350 * @res: set of resources that needs to be allocated for the device
351 * @num: number of resources
352 *
353 * This function creates a simple platform device that requires minimal
354 * resource and memory management. Canned release function freeing memory
355 * allocated for the device allows drivers using such devices to be
356 * unloaded without waiting for the last reference to the device to be
357 * dropped.
358 * 349 *
359 * This interface is primarily intended for use with legacy drivers which
360 * probe hardware directly. Because such drivers create sysfs device nodes
361 * themselves, rather than letting system infrastructure handle such device
362 * enumeration tasks, they don't fully conform to the Linux driver model.
363 * In particular, when such drivers are built as modules, they can't be
364 * "hotplugged".
365 *
366 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
367 */
368struct platform_device *platform_device_register_simple(const char *name,
369 int id,
370 const struct resource *res,
371 unsigned int num)
372{
373 struct platform_device *pdev;
374 int retval;
375
376 pdev = platform_device_alloc(name, id);
377 if (!pdev) {
378 retval = -ENOMEM;
379 goto error;
380 }
381
382 if (num) {
383 retval = platform_device_add_resources(pdev, res, num);
384 if (retval)
385 goto error;
386 }
387
388 retval = platform_device_add(pdev);
389 if (retval)
390 goto error;
391
392 return pdev;
393
394error:
395 platform_device_put(pdev);
396 return ERR_PTR(retval);
397}
398EXPORT_SYMBOL_GPL(platform_device_register_simple);
399
400/**
401 * platform_device_register_data - add a platform-level device with platform-specific data
402 * @parent: parent device for the device we're adding 350 * @parent: parent device for the device we're adding
403 * @name: base name of the device we're adding 351 * @name: base name of the device we're adding
404 * @id: instance id 352 * @id: instance id
353 * @res: set of resources that needs to be allocated for the device
354 * @num: number of resources
405 * @data: platform specific data for this platform device 355 * @data: platform specific data for this platform device
406 * @size: size of platform specific data 356 * @size: size of platform specific data
407 * 357 *
408 * This function creates a simple platform device that requires minimal
409 * resource and memory management. Canned release function freeing memory
410 * allocated for the device allows drivers using such devices to be
411 * unloaded without waiting for the last reference to the device to be
412 * dropped.
413 *
414 * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 358 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
415 */ 359 */
416struct platform_device *platform_device_register_data( 360struct platform_device *platform_device_register_resndata(
417 struct device *parent, 361 struct device *parent,
418 const char *name, int id, 362 const char *name, int id,
363 const struct resource *res, unsigned int num,
419 const void *data, size_t size) 364 const void *data, size_t size)
420{ 365{
366 int ret = -ENOMEM;
421 struct platform_device *pdev; 367 struct platform_device *pdev;
422 int retval;
423 368
424 pdev = platform_device_alloc(name, id); 369 pdev = platform_device_alloc(name, id);
425 if (!pdev) { 370 if (!pdev)
426 retval = -ENOMEM; 371 goto err;
427 goto error;
428 }
429 372
430 pdev->dev.parent = parent; 373 pdev->dev.parent = parent;
431 374
432 if (size) { 375 if (res) {
433 retval = platform_device_add_data(pdev, data, size); 376 ret = platform_device_add_resources(pdev, res, num);
434 if (retval) 377 if (ret)
435 goto error; 378 goto err;
436 } 379 }
437 380
438 retval = platform_device_add(pdev); 381 if (data) {
439 if (retval) 382 ret = platform_device_add_data(pdev, data, size);
440 goto error; 383 if (ret)
384 goto err;
385 }
441 386
442 return pdev; 387 ret = platform_device_add(pdev);
388 if (ret) {
389err:
390 platform_device_put(pdev);
391 return ERR_PTR(ret);
392 }
443 393
444error: 394 return pdev;
445 platform_device_put(pdev);
446 return ERR_PTR(retval);
447} 395}
448EXPORT_SYMBOL_GPL(platform_device_register_data); 396EXPORT_SYMBOL_GPL(platform_device_register_resndata);
449 397
450static int platform_drv_probe(struct device *_dev) 398static int platform_drv_probe(struct device *_dev)
451{ 399{
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 5417944d3687..d7ecad0093bb 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -43,10 +43,64 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
43extern int platform_get_irq_byname(struct platform_device *, const char *); 43extern int platform_get_irq_byname(struct platform_device *, const char *);
44extern int platform_add_devices(struct platform_device **, int); 44extern int platform_add_devices(struct platform_device **, int);
45 45
46extern struct platform_device *platform_device_register_simple(const char *, int id, 46extern struct platform_device *platform_device_register_resndata(
47 const struct resource *, unsigned int); 47 struct device *parent, const char *name, int id,
48extern struct platform_device *platform_device_register_data(struct device *, 48 const struct resource *res, unsigned int num,
49 const char *, int, const void *, size_t); 49 const void *data, size_t size);
50
51/**
52 * platform_device_register_simple - add a platform-level device and its resources
53 * @name: base name of the device we're adding
54 * @id: instance id
55 * @res: set of resources that needs to be allocated for the device
56 * @num: number of resources
57 *
58 * This function creates a simple platform device that requires minimal
59 * resource and memory management. Canned release function freeing memory
60 * allocated for the device allows drivers using such devices to be
61 * unloaded without waiting for the last reference to the device to be
62 * dropped.
63 *
64 * This interface is primarily intended for use with legacy drivers which
65 * probe hardware directly. Because such drivers create sysfs device nodes
66 * themselves, rather than letting system infrastructure handle such device
67 * enumeration tasks, they don't fully conform to the Linux driver model.
68 * In particular, when such drivers are built as modules, they can't be
69 * "hotplugged".
70 *
71 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
72 */
73static inline struct platform_device *platform_device_register_simple(
74 const char *name, int id,
75 const struct resource *res, unsigned int num)
76{
77 return platform_device_register_resndata(NULL, name, id,
78 res, num, NULL, 0);
79}
80
81/**
82 * platform_device_register_data - add a platform-level device with platform-specific data
83 * @parent: parent device for the device we're adding
84 * @name: base name of the device we're adding
85 * @id: instance id
86 * @data: platform specific data for this platform device
87 * @size: size of platform specific data
88 *
89 * This function creates a simple platform device that requires minimal
90 * resource and memory management. Canned release function freeing memory
91 * allocated for the device allows drivers using such devices to be
92 * unloaded without waiting for the last reference to the device to be
93 * dropped.
94 *
95 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
96 */
97static inline struct platform_device *platform_device_register_data(
98 struct device *parent, const char *name, int id,
99 const void *data, size_t size)
100{
101 return platform_device_register_resndata(parent, name, id,
102 NULL, 0, data, size);
103}
50 104
51extern struct platform_device *platform_device_alloc(const char *name, int id); 105extern struct platform_device *platform_device_alloc(const char *name, int id);
52extern int platform_device_add_resources(struct platform_device *pdev, 106extern int platform_device_add_resources(struct platform_device *pdev,