diff options
| author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2010-06-21 10:11:44 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-05 16:53:34 -0400 |
| commit | 44f28bdea09415d40b4d73a7668db5961362ec53 (patch) | |
| tree | 7f36eedff7cdfba9d9d0b77f9a4227d3bb0b190f /drivers/base | |
| parent | 3e61dfd8509a52d165726831c57b4c8a015d626c (diff) | |
Driver core: reduce duplicated code for platform_device creation
This makes the two similar functions platform_device_register_simple
and platform_device_register_data one line inline functions using a new
generic function platform_device_register_resndata.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/platform.c | 104 |
1 files changed, 26 insertions, 78 deletions
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) | |||
| 344 | EXPORT_SYMBOL_GPL(platform_device_unregister); | 344 | EXPORT_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 | */ | ||
| 368 | struct 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 | |||
| 394 | error: | ||
| 395 | platform_device_put(pdev); | ||
| 396 | return ERR_PTR(retval); | ||
| 397 | } | ||
| 398 | EXPORT_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 | */ |
| 416 | struct platform_device *platform_device_register_data( | 360 | struct 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) { | ||
| 389 | err: | ||
| 390 | platform_device_put(pdev); | ||
| 391 | return ERR_PTR(ret); | ||
| 392 | } | ||
| 443 | 393 | ||
| 444 | error: | 394 | return pdev; |
| 445 | platform_device_put(pdev); | ||
| 446 | return ERR_PTR(retval); | ||
| 447 | } | 395 | } |
| 448 | EXPORT_SYMBOL_GPL(platform_device_register_data); | 396 | EXPORT_SYMBOL_GPL(platform_device_register_resndata); |
| 449 | 397 | ||
| 450 | static int platform_drv_probe(struct device *_dev) | 398 | static int platform_drv_probe(struct device *_dev) |
| 451 | { | 399 | { |
