Commit 3795b173 authored by Patrick Mochel's avatar Patrick Mochel

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.
parent 9a2fd7ec
...@@ -6,6 +6,7 @@ extern int devices_init(void); ...@@ -6,6 +6,7 @@ extern int devices_init(void);
extern int buses_init(void); extern int buses_init(void);
extern int classes_init(void); extern int classes_init(void);
extern int firmware_init(void); extern int firmware_init(void);
extern int platform_bus_init(void);
extern int sys_bus_init(void); extern int sys_bus_init(void);
extern int cpu_dev_init(void); extern int cpu_dev_init(void);
...@@ -27,6 +28,7 @@ void __init driver_init(void) ...@@ -27,6 +28,7 @@ void __init driver_init(void)
/* These are also core pieces, but must come after the /* These are also core pieces, but must come after the
* core core pieces. * core core pieces.
*/ */
platform_bus_init();
sys_bus_init(); sys_bus_init();
cpu_dev_init(); cpu_dev_init();
} }
...@@ -42,8 +42,28 @@ void platform_device_unregister(struct platform_device * pdev) ...@@ -42,8 +42,28 @@ void platform_device_unregister(struct platform_device * pdev)
device_unregister(&pdev->dev); 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) 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; return 0;
} }
...@@ -52,13 +72,11 @@ struct bus_type platform_bus_type = { ...@@ -52,13 +72,11 @@ struct bus_type platform_bus_type = {
.match = platform_match, .match = platform_match,
}; };
static int __init platform_bus_init(void) int __init platform_bus_init(void)
{ {
device_register(&legacy_bus); device_register(&legacy_bus);
return bus_register(&platform_bus_type); return bus_register(&platform_bus_type);
} }
postcore_initcall(platform_bus_init);
EXPORT_SYMBOL(platform_device_register); EXPORT_SYMBOL(platform_device_register);
EXPORT_SYMBOL(platform_device_unregister); EXPORT_SYMBOL(platform_device_unregister);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment