aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/platform.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2009-12-29 23:11:20 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-07 20:04:46 -0500
commitecdf6ceb8cf4756bd4214bf9755755752b6015f5 (patch)
tree828af56bdfe60396e77bbc05f28e231ffe70fe9b /drivers/base/platform.c
parent20ef9f46a9abe3c25d9f2834f6cc86bfab46d609 (diff)
Driver core: add platform_create_bundle() helper
Many legacy-style module create singleton platform devices themselves, along with corresponding platform driver. Instead of replicating error handling code in all such drivers, provide a helper that allocates and registers a single platform device and a driver and binds them together. Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/platform.c')
-rw-r--r--drivers/base/platform.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 58efaf2f125..937d58021d1 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -548,6 +548,64 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
548} 548}
549EXPORT_SYMBOL_GPL(platform_driver_probe); 549EXPORT_SYMBOL_GPL(platform_driver_probe);
550 550
551/**
552 * platform_create_bundle - register driver and create corresponding device
553 * @driver: platform driver structure
554 * @probe: the driver probe routine, probably from an __init section
555 * @res: set of resources that needs to be allocated for the device
556 * @n_res: number of resources
557 * @data: platform specific data for this platform device
558 * @size: size of platform specific data
559 *
560 * Use this in legacy-style modules that probe hardware directly and
561 * register a single platform device and corresponding platform driver.
562 */
563struct platform_device * __init_or_module platform_create_bundle(
564 struct platform_driver *driver,
565 int (*probe)(struct platform_device *),
566 struct resource *res, unsigned int n_res,
567 const void *data, size_t size)
568{
569 struct platform_device *pdev;
570 int error;
571
572 pdev = platform_device_alloc(driver->driver.name, -1);
573 if (!pdev) {
574 error = -ENOMEM;
575 goto err_out;
576 }
577
578 if (res) {
579 error = platform_device_add_resources(pdev, res, n_res);
580 if (error)
581 goto err_pdev_put;
582 }
583
584 if (data) {
585 error = platform_device_add_data(pdev, data, size);
586 if (error)
587 goto err_pdev_put;
588 }
589
590 error = platform_device_add(pdev);
591 if (error)
592 goto err_pdev_put;
593
594 error = platform_driver_probe(driver, probe);
595 if (error)
596 goto err_pdev_del;
597
598 return pdev;
599
600err_pdev_del:
601 platform_device_del(pdev);
602err_pdev_put:
603 platform_device_put(pdev);
604err_out:
605 return ERR_PTR(error);
606}
607EXPORT_SYMBOL_GPL(platform_create_bundle);
608
551/* modalias support enables more hands-off userspace setup: 609/* modalias support enables more hands-off userspace setup:
552 * (a) environment variable lets new-style hotplug events work once system is 610 * (a) environment variable lets new-style hotplug events work once system is
553 * fully running: "modprobe $MODALIAS" 611 * fully running: "modprobe $MODALIAS"