diff options
author | Dmitry Baryshkov <dbaryshkov@gmail.com> | 2008-09-22 17:41:40 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-10-16 12:24:51 -0400 |
commit | d8bf254089a6c31d7d01a4d1d2f1861662900855 (patch) | |
tree | 646ec36e10982958e6bd3385dbbaee34c5061251 /drivers | |
parent | 45c076c5d71e6e644e2eae64f80922d162c900ac (diff) |
platform: add new device registration helper
Add a helper that registers simple platform_device w/o resources but with
parent and device data.
This is usefull to cleanup platform code from code that registers such
simple devices as leds-gpio, generic-bl, etc.
Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/platform.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index e621dade7eaa..9e60f7c739c6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -391,6 +391,53 @@ error: | |||
391 | } | 391 | } |
392 | EXPORT_SYMBOL_GPL(platform_device_register_simple); | 392 | EXPORT_SYMBOL_GPL(platform_device_register_simple); |
393 | 393 | ||
394 | /** | ||
395 | * platform_device_register_data | ||
396 | * @parent: parent device for the device we're adding | ||
397 | * @name: base name of the device we're adding | ||
398 | * @id: instance id | ||
399 | * @data: platform specific data for this platform device | ||
400 | * @size: size of platform specific data | ||
401 | * | ||
402 | * This function creates a simple platform device that requires minimal | ||
403 | * resource and memory management. Canned release function freeing memory | ||
404 | * allocated for the device allows drivers using such devices to be | ||
405 | * unloaded without waiting for the last reference to the device to be | ||
406 | * dropped. | ||
407 | */ | ||
408 | struct platform_device *platform_device_register_data( | ||
409 | struct device *parent, | ||
410 | const char *name, int id, | ||
411 | const void *data, size_t size) | ||
412 | { | ||
413 | struct platform_device *pdev; | ||
414 | int retval; | ||
415 | |||
416 | pdev = platform_device_alloc(name, id); | ||
417 | if (!pdev) { | ||
418 | retval = -ENOMEM; | ||
419 | goto error; | ||
420 | } | ||
421 | |||
422 | pdev->dev.parent = parent; | ||
423 | |||
424 | if (size) { | ||
425 | retval = platform_device_add_data(pdev, data, size); | ||
426 | if (retval) | ||
427 | goto error; | ||
428 | } | ||
429 | |||
430 | retval = platform_device_add(pdev); | ||
431 | if (retval) | ||
432 | goto error; | ||
433 | |||
434 | return pdev; | ||
435 | |||
436 | error: | ||
437 | platform_device_put(pdev); | ||
438 | return ERR_PTR(retval); | ||
439 | } | ||
440 | |||
394 | static int platform_drv_probe(struct device *_dev) | 441 | static int platform_drv_probe(struct device *_dev) |
395 | { | 442 | { |
396 | struct platform_driver *drv = to_platform_driver(_dev->driver); | 443 | struct platform_driver *drv = to_platform_driver(_dev->driver); |