summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorPatrick Mochel <mochel@osdl.org>2002-09-23 04:23:04 -0700
committerPatrick Mochel <mochel@osdl.org>2002-09-23 04:23:04 -0700
commitf6bec0e641f80b097536fc4f8a1d8e7d2cc5c30b (patch)
tree4bb4a9f9c1a8a2da19661cbeb4d0811a7840f434 /drivers/base
parentd668723c965730a4d3518f28fb8334e0fa65cbb0 (diff)
driver model: add better platform device support.
Platform devices are devices commonly found on the motherboard of systems. This includes legacy devices (serial ports, floppy controllers, parallel ports, etc) and host bridges to peripheral buses. We already had a platform bus type, which gives a way to group platform devices and drivers, and allow each to be bound to each other dynamically. Though before, it didn't do anything. It still doesn't do much, but we now have: - struct platform_device, which generically describes platform deviecs. This only includes a name and id in addition to a struct device, but more may be added later. - implelemnt platform_device_register() and platform_device_unregister() to handle adding and removing these devices. - Create legacy_bus - a default parent device for legacy devices. - Change the floppy driver to define a platform_device (instead of a sys_device). In driverfs, this gives us now: a# tree -d /sys/bus/platform/ /sys/bus/platform/ |-- devices | `-- floppy0 -> ../../../root/legacy/floppy0 `-- drivers and # tree -d /sys/root/legacy/ /sys/root/legacy/ `-- floppy0
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/Makefile2
-rw-r--r--drivers/base/platform.c41
2 files changed, 40 insertions, 3 deletions
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 0c6dbb2abd98..f609ddee181e 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -7,6 +7,6 @@ obj-y := core.o sys.o interface.o power.o bus.o \
obj-y += fs/
export-objs := core.o power.o sys.o bus.o driver.o \
- class.o intf.o cpu.o
+ class.o intf.o platform.o cpu.o
include $(TOPDIR)/Rules.make
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index f637a25937cb..29c90e34e67e 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -9,19 +9,56 @@
#include <linux/module.h>
#include <linux/init.h>
+static struct device legacy_bus = {
+ .name = "legacy bus",
+ .bus_id = "legacy",
+};
+
+/**
+ * platform_device_register - add a platform-level device
+ * @dev: platform device we're adding
+ *
+ */
+int platform_device_register(struct platform_device * pdev)
+{
+ if (!pdev)
+ return -EINVAL;
+
+ if (!pdev->dev.parent)
+ pdev->dev.parent = &legacy_bus;
+
+ pdev->dev.bus = &platform_bus_type;
+
+ snprintf(pdev->dev.bus_id,BUS_ID_SIZE,"%s%u",pdev->name,pdev->id);
+
+ pr_debug("Registering platform device '%s'. Parent at %s\n",
+ pdev->dev.bus_id,pdev->dev.parent->bus_id);
+ return device_register(&pdev->dev);
+}
+
+void platform_device_unregister(struct platform_device * pdev)
+{
+ if (pdev)
+ put_device(&pdev->dev);
+}
+
static int platform_match(struct device * dev, struct device_driver * drv)
{
return 0;
}
-struct bus_type platform_bus = {
+struct bus_type platform_bus_type = {
.name = "platform",
.match = platform_match,
};
static int __init platform_bus_init(void)
{
- return bus_register(&platform_bus);
+ device_register(&legacy_bus);
+ return bus_register(&platform_bus_type);
}
postcore_initcall(platform_bus_init);
+
+EXPORT_SYMBOL(platform_device_register);
+EXPORT_SYMBOL(platform_device_unregister);