aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/platform.c')
-rw-r--r--drivers/base/platform.c76
1 files changed, 67 insertions, 9 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 58efaf2f1259..1ba9d617d241 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -128,7 +128,7 @@ struct platform_object {
128}; 128};
129 129
130/** 130/**
131 * platform_device_put 131 * platform_device_put - destroy a platform device
132 * @pdev: platform device to free 132 * @pdev: platform device to free
133 * 133 *
134 * Free all memory associated with a platform device. This function must 134 * Free all memory associated with a platform device. This function must
@@ -152,7 +152,7 @@ static void platform_device_release(struct device *dev)
152} 152}
153 153
154/** 154/**
155 * platform_device_alloc 155 * platform_device_alloc - create a platform device
156 * @name: base name of the device we're adding 156 * @name: base name of the device we're adding
157 * @id: instance id 157 * @id: instance id
158 * 158 *
@@ -177,7 +177,7 @@ struct platform_device *platform_device_alloc(const char *name, int id)
177EXPORT_SYMBOL_GPL(platform_device_alloc); 177EXPORT_SYMBOL_GPL(platform_device_alloc);
178 178
179/** 179/**
180 * platform_device_add_resources 180 * platform_device_add_resources - add resources to a platform device
181 * @pdev: platform device allocated by platform_device_alloc to add resources to 181 * @pdev: platform device allocated by platform_device_alloc to add resources to
182 * @res: set of resources that needs to be allocated for the device 182 * @res: set of resources that needs to be allocated for the device
183 * @num: number of resources 183 * @num: number of resources
@@ -202,7 +202,7 @@ int platform_device_add_resources(struct platform_device *pdev,
202EXPORT_SYMBOL_GPL(platform_device_add_resources); 202EXPORT_SYMBOL_GPL(platform_device_add_resources);
203 203
204/** 204/**
205 * platform_device_add_data 205 * platform_device_add_data - add platform-specific data to a platform device
206 * @pdev: platform device allocated by platform_device_alloc to add resources to 206 * @pdev: platform device allocated by platform_device_alloc to add resources to
207 * @data: platform specific data for this platform device 207 * @data: platform specific data for this platform device
208 * @size: size of platform specific data 208 * @size: size of platform specific data
@@ -344,7 +344,7 @@ 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 347 * platform_device_register_simple - add a platform-level device and its resources
348 * @name: base name of the device we're adding 348 * @name: base name of the device we're adding
349 * @id: instance id 349 * @id: instance id
350 * @res: set of resources that needs to be allocated for the device 350 * @res: set of resources that needs to be allocated for the device
@@ -396,7 +396,7 @@ error:
396EXPORT_SYMBOL_GPL(platform_device_register_simple); 396EXPORT_SYMBOL_GPL(platform_device_register_simple);
397 397
398/** 398/**
399 * platform_device_register_data 399 * platform_device_register_data - add a platform-level device with platform-specific data
400 * @parent: parent device for the device we're adding 400 * @parent: parent device for the device we're adding
401 * @name: base name of the device we're adding 401 * @name: base name of the device we're adding
402 * @id: instance id 402 * @id: instance id
@@ -473,7 +473,7 @@ static void platform_drv_shutdown(struct device *_dev)
473} 473}
474 474
475/** 475/**
476 * platform_driver_register 476 * platform_driver_register - register a driver for platform-level devices
477 * @drv: platform driver structure 477 * @drv: platform driver structure
478 */ 478 */
479int platform_driver_register(struct platform_driver *drv) 479int platform_driver_register(struct platform_driver *drv)
@@ -491,7 +491,7 @@ int platform_driver_register(struct platform_driver *drv)
491EXPORT_SYMBOL_GPL(platform_driver_register); 491EXPORT_SYMBOL_GPL(platform_driver_register);
492 492
493/** 493/**
494 * platform_driver_unregister 494 * platform_driver_unregister - unregister a driver for platform-level devices
495 * @drv: platform driver structure 495 * @drv: platform driver structure
496 */ 496 */
497void platform_driver_unregister(struct platform_driver *drv) 497void platform_driver_unregister(struct platform_driver *drv)
@@ -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"
@@ -578,7 +636,7 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
578} 636}
579 637
580static const struct platform_device_id *platform_match_id( 638static const struct platform_device_id *platform_match_id(
581 struct platform_device_id *id, 639 const struct platform_device_id *id,
582 struct platform_device *pdev) 640 struct platform_device *pdev)
583{ 641{
584 while (id->name[0]) { 642 while (id->name[0]) {