aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/platform.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:21 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-24 11:57:51 -0400
commiteca3930163ba8884060ce9d9ff5ef0d9b7c7b00f (patch)
tree5774d6d53b5f7d8f069e82b3937cdff7b3d45bbe /drivers/of/platform.c
parent05212157e94ccf4cf458413bbba509cfa95ff92b (diff)
of: Merge of_platform_bus_type with platform_bus_type
of_platform_bus was being used in the same manner as the platform_bus. The only difference being that of_platform_bus devices are generated from data in the device tree, and platform_bus devices are usually statically allocated in platform code. Having them separate causes the problem of device drivers having to be registered twice if it was possible for the same device to appear on either bus. This patch removes of_platform_bus_type and registers all of_platform bus devices and drivers on the platform bus instead. A previous patch made the of_device structure an alias for the platform_device structure, and a shim is used to adapt of_platform_drivers to the platform bus. After all of of_platform_bus drivers are converted to be normal platform drivers, the shim code can be removed. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/of/platform.c')
-rw-r--r--drivers/of/platform.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 9d3d932bcb6f..712dfd866df0 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -20,6 +20,54 @@
20#include <linux/of_device.h> 20#include <linux/of_device.h>
21#include <linux/of_irq.h> 21#include <linux/of_irq.h>
22#include <linux/of_platform.h> 22#include <linux/of_platform.h>
23#include <linux/platform_device.h>
24
25static int platform_driver_probe_shim(struct platform_device *pdev)
26{
27 struct platform_driver *pdrv;
28 struct of_platform_driver *ofpdrv;
29 const struct of_device_id *match;
30
31 pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
32 ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
33 match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
34 return ofpdrv->probe(pdev, match);
35}
36
37static void platform_driver_shutdown_shim(struct platform_device *pdev)
38{
39 struct platform_driver *pdrv;
40 struct of_platform_driver *ofpdrv;
41
42 pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
43 ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
44 ofpdrv->shutdown(pdev);
45}
46
47/**
48 * of_register_platform_driver
49 */
50int of_register_platform_driver(struct of_platform_driver *drv)
51{
52 /* setup of_platform_driver to platform_driver adaptors */
53 drv->platform_driver.driver = drv->driver;
54 if (drv->probe)
55 drv->platform_driver.probe = platform_driver_probe_shim;
56 drv->platform_driver.remove = drv->remove;
57 if (drv->shutdown)
58 drv->platform_driver.shutdown = platform_driver_shutdown_shim;
59 drv->platform_driver.suspend = drv->suspend;
60 drv->platform_driver.resume = drv->resume;
61
62 return platform_driver_register(&drv->platform_driver);
63}
64EXPORT_SYMBOL(of_register_platform_driver);
65
66void of_unregister_platform_driver(struct of_platform_driver *drv)
67{
68 platform_driver_unregister(&drv->platform_driver);
69}
70EXPORT_SYMBOL(of_unregister_platform_driver);
23 71
24#if defined(CONFIG_PPC_DCR) 72#if defined(CONFIG_PPC_DCR)
25#include <asm/dcr.h> 73#include <asm/dcr.h>
@@ -392,16 +440,29 @@ int of_bus_type_init(struct bus_type *bus, const char *name)
392 440
393int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus) 441int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
394{ 442{
395 drv->driver.bus = bus; 443 /*
444 * Temporary: of_platform_bus used to be distinct from the platform
445 * bus. It isn't anymore, and so drivers on the platform bus need
446 * to be registered in a special way.
447 *
448 * After all of_platform_bus_type drivers are converted to
449 * platform_drivers, this exception can be removed.
450 */
451 if (bus == &platform_bus_type)
452 return of_register_platform_driver(drv);
396 453
397 /* register with core */ 454 /* register with core */
455 drv->driver.bus = bus;
398 return driver_register(&drv->driver); 456 return driver_register(&drv->driver);
399} 457}
400EXPORT_SYMBOL(of_register_driver); 458EXPORT_SYMBOL(of_register_driver);
401 459
402void of_unregister_driver(struct of_platform_driver *drv) 460void of_unregister_driver(struct of_platform_driver *drv)
403{ 461{
404 driver_unregister(&drv->driver); 462 if (drv->driver.bus == &platform_bus_type)
463 of_unregister_platform_driver(drv);
464 else
465 driver_unregister(&drv->driver);
405} 466}
406EXPORT_SYMBOL(of_unregister_driver); 467EXPORT_SYMBOL(of_unregister_driver);
407 468
@@ -548,7 +609,7 @@ struct of_device *of_platform_device_create(struct device_node *np,
548 dev->archdata.dma_mask = 0xffffffffUL; 609 dev->archdata.dma_mask = 0xffffffffUL;
549#endif 610#endif
550 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); 611 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
551 dev->dev.bus = &of_platform_bus_type; 612 dev->dev.bus = &platform_bus_type;
552 613
553 /* We do not fill the DMA ops for platform devices by default. 614 /* We do not fill the DMA ops for platform devices by default.
554 * This is currently the responsibility of the platform code 615 * This is currently the responsibility of the platform code