summaryrefslogtreecommitdiff
path: root/drivers/base/platform.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2006-05-29 10:37:33 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-21 12:40:48 -0700
commita0245f7ad5214cb00131d7cd176446e067c913dc (patch)
tree78f138afefa3114cb587561e464ddc6a8b6a7805 /drivers/base/platform.c
parent05967118a6c354eaa5950429c70ad4c8daca94bf (diff)
[PATCH] platform_bus learns about modalias
This patch adds modalias support to platform devices, for simpler hotplug/coldplug driven driver setup. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/platform.c')
-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)
EXPORT_SYMBOL_GPL(platform_driver_unregister);
+/* modalias support enables more hands-off userspace setup:
+ * (a) environment variable lets new-style hotplug events work once system is
+ * fully running: "modprobe $MODALIAS"
+ * (b) sysfs attribute lets new-style coldplug recover from hotplug events
+ * mishandled before system is fully running: "modprobe $(cat modalias)"
+ */
+static ssize_t
+modalias_show(struct device *dev, struct device_attribute *a, char *buf)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+ int len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->name);
+
+ return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
+}
+
+static struct device_attribute platform_dev_attrs[] = {
+ __ATTR_RO(modalias),
+ __ATTR_NULL,
+};
+
+static int platform_uevent(struct device *dev, char **envp, int num_envp,
+ char *buffer, int buffer_size)
+{
+ struct platform_device *pdev = to_platform_device(dev);
+
+ envp[0] = buffer;
+ snprintf(buffer, buffer_size, "MODALIAS=%s", pdev->name);
+ return 0;
+}
+
+
/**
* platform_match - bind platform device to platform driver.
* @dev: device.
@@ -496,7 +527,9 @@ static int platform_resume(struct device * dev)
struct bus_type platform_bus_type = {
.name = "platform",
+ .dev_attrs = platform_dev_attrs,
.match = platform_match,
+ .uevent = platform_uevent,
.suspend = platform_suspend,
.resume = platform_resume,
};