From: Patrick Mochel Date: Tue, 4 Mar 2003 04:20:36 +0000 (-0600) Subject: driver model: implement platform_match() X-Git-Tag: v2.5.64~5^2~1 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=3795b173a7660f9a45d36035549a659003ee5a6c;p=history.git driver model: implement platform_match() - For matching registered platform devices with platform drivers. - Also, make sure platform_bus is initialized early, with the rest of the core stuff. --- diff --git a/drivers/base/init.c b/drivers/base/init.c index e3739cd11da8..cbfd88864e70 100644 --- a/drivers/base/init.c +++ b/drivers/base/init.c @@ -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(); } diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 3856bc52b411..4bdbe88fd88c 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -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: + * "", where is a short description of the + * type of device, like "pci" or "floppy", and is the + * enumerated instance of the device, like '0' or '42'. + * Driver IDs are simply "". + * So, extract the 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);