aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/platform.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 83f5c5984d1a..f8071976fe07 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -452,6 +452,37 @@ void platform_driver_unregister(struct platform_driver *drv)
452EXPORT_SYMBOL_GPL(platform_driver_unregister); 452EXPORT_SYMBOL_GPL(platform_driver_unregister);
453 453
454 454
455/* modalias support enables more hands-off userspace setup:
456 * (a) environment variable lets new-style hotplug events work once system is
457 * fully running: "modprobe $MODALIAS"
458 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
459 * mishandled before system is fully running: "modprobe $(cat modalias)"
460 */
461static ssize_t
462modalias_show(struct device *dev, struct device_attribute *a, char *buf)
463{
464 struct platform_device *pdev = to_platform_device(dev);
465 int len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->name);
466
467 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
468}
469
470static struct device_attribute platform_dev_attrs[] = {
471 __ATTR_RO(modalias),
472 __ATTR_NULL,
473};
474
475static int platform_uevent(struct device *dev, char **envp, int num_envp,
476 char *buffer, int buffer_size)
477{
478 struct platform_device *pdev = to_platform_device(dev);
479
480 envp[0] = buffer;
481 snprintf(buffer, buffer_size, "MODALIAS=%s", pdev->name);
482 return 0;
483}
484
485
455/** 486/**
456 * platform_match - bind platform device to platform driver. 487 * platform_match - bind platform device to platform driver.
457 * @dev: device. 488 * @dev: device.
@@ -496,7 +527,9 @@ static int platform_resume(struct device * dev)
496 527
497struct bus_type platform_bus_type = { 528struct bus_type platform_bus_type = {
498 .name = "platform", 529 .name = "platform",
530 .dev_attrs = platform_dev_attrs,
499 .match = platform_match, 531 .match = platform_match,
532 .uevent = platform_uevent,
500 .suspend = platform_suspend, 533 .suspend = platform_suspend,
501 .resume = platform_resume, 534 .resume = platform_resume,
502}; 535};