]> git.neil.brown.name Git - history.git/commitdiff
driver model: implement platform_match()
authorPatrick Mochel <mochel@osdl.org>
Tue, 4 Mar 2003 04:20:36 +0000 (22:20 -0600)
committerPatrick Mochel <mochel@osdl.org>
Tue, 4 Mar 2003 04:20:36 +0000 (22:20 -0600)
- For matching registered platform devices with platform drivers.

- Also, make sure platform_bus is initialized early, with the rest of the
  core stuff.

drivers/base/init.c
drivers/base/platform.c

index e3739cd11da8668fa6a37372c806210dbbd3cdd2..cbfd88864e70b5aa3b0c682edc4cc381dd3eb6bb 100644 (file)
@@ -6,6 +6,7 @@ extern int devices_init(void);
 extern int buses_init(void);
 extern int classes_init(void);
 extern int firmware_init(void);
+extern int platform_bus_init(void);
 extern int sys_bus_init(void);
 extern int cpu_dev_init(void);
 
@@ -27,6 +28,7 @@ void __init driver_init(void)
        /* These are also core pieces, but must come after the 
         * core core pieces.
         */
+       platform_bus_init();
        sys_bus_init();
        cpu_dev_init();
 }
index 3856bc52b411e6199225a133321256a38569f6a8..4bdbe88fd88cceba7f348f0e1d43e3a9203a9fbc 100644 (file)
@@ -41,9 +41,29 @@ void platform_device_unregister(struct platform_device * pdev)
        if (pdev)
                device_unregister(&pdev->dev);
 }
-       
+
+
+/**
+ *     platform_match - bind platform device to platform driver.
+ *     @dev:   device.
+ *     @drv:   driver.
+ *
+ *     Platform device IDs are assumed to be encoded like this: 
+ *     "<name><instance>", where <name> is a short description of the 
+ *     type of device, like "pci" or "floppy", and <instance> is the 
+ *     enumerated instance of the device, like '0' or '42'.
+ *     Driver IDs are simply "<name>". 
+ *     So, extract the <name> from the device, and compare it against 
+ *     the name of the driver. Return whether they match or not.
+ */
+
 static int platform_match(struct device * dev, struct device_driver * drv)
 {
+       char name[BUS_ID_SIZE];
+
+       if (sscanf(dev->bus_id,"%s",name))
+               return (strcmp(name,drv->name) == 0);
+
        return 0;
 }
 
@@ -52,13 +72,11 @@ struct bus_type platform_bus_type = {
        .match          = platform_match,
 };
 
-static int __init platform_bus_init(void)
+int __init platform_bus_init(void)
 {
        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);