Commit eca3930163ba8884060ce9d9ff5ef0d9b7c7b00f

Authored by Grant Likely
1 parent 05212157e9

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>

Showing 16 changed files with 102 additions and 103 deletions Side-by-side Diff

arch/microblaze/kernel/of_platform.c
... ... @@ -26,17 +26,6 @@
26 26 #include <linux/topology.h>
27 27 #include <asm/atomic.h>
28 28  
29   -struct bus_type of_platform_bus_type = {
30   - .uevent = of_device_uevent,
31   -};
32   -EXPORT_SYMBOL(of_platform_bus_type);
33   -
34   -static int __init of_bus_driver_init(void)
35   -{
36   - return of_bus_type_init(&of_platform_bus_type, "of_platform");
37   -}
38   -postcore_initcall(of_bus_driver_init);
39   -
40 29 /*
41 30 * The list of OF IDs below is used for matching bus types in the
42 31 * system whose devices are to be exposed as of_platform_devices.
arch/microblaze/kernel/setup.c
... ... @@ -213,15 +213,9 @@
213 213 .priority = INT_MAX,
214 214 };
215 215  
216   -static struct notifier_block dflt_of_bus_notifier = {
217   - .notifier_call = dflt_bus_notify,
218   - .priority = INT_MAX,
219   -};
220   -
221 216 static int __init setup_bus_notifier(void)
222 217 {
223 218 bus_register_notifier(&platform_bus_type, &dflt_plat_bus_notifier);
224   - bus_register_notifier(&of_platform_bus_type, &dflt_of_bus_notifier);
225 219  
226 220 return 0;
227 221 }
arch/powerpc/kernel/dma-swiotlb.c
... ... @@ -82,18 +82,10 @@
82 82 .priority = 0,
83 83 };
84 84  
85   -static struct notifier_block ppc_swiotlb_of_bus_notifier = {
86   - .notifier_call = ppc_swiotlb_bus_notify,
87   - .priority = 0,
88   -};
89   -
90 85 int __init swiotlb_setup_bus_notifier(void)
91 86 {
92 87 bus_register_notifier(&platform_bus_type,
93 88 &ppc_swiotlb_plat_bus_notifier);
94   - bus_register_notifier(&of_platform_bus_type,
95   - &ppc_swiotlb_of_bus_notifier);
96   -
97 89 return 0;
98 90 }
arch/powerpc/kernel/of_platform.c
... ... @@ -52,18 +52,6 @@
52 52 {},
53 53 };
54 54  
55   -struct bus_type of_platform_bus_type = {
56   - .uevent = of_device_uevent,
57   -};
58   -EXPORT_SYMBOL(of_platform_bus_type);
59   -
60   -static int __init of_bus_driver_init(void)
61   -{
62   - return of_bus_type_init(&of_platform_bus_type, "of_platform");
63   -}
64   -
65   -postcore_initcall(of_bus_driver_init);
66   -
67 55 static int of_dev_node_match(struct device *dev, void *data)
68 56 {
69 57 return to_of_device(dev)->dev.of_node == data;
arch/powerpc/kernel/setup-common.c
... ... @@ -701,16 +701,9 @@
701 701 .priority = INT_MAX,
702 702 };
703 703  
704   -static struct notifier_block ppc_dflt_of_bus_notifier = {
705   - .notifier_call = ppc_dflt_bus_notify,
706   - .priority = INT_MAX,
707   -};
708   -
709 704 static int __init setup_bus_notifier(void)
710 705 {
711 706 bus_register_notifier(&platform_bus_type, &ppc_dflt_plat_bus_notifier);
712   - bus_register_notifier(&of_platform_bus_type, &ppc_dflt_of_bus_notifier);
713   -
714 707 return 0;
715 708 }
716 709  
arch/powerpc/platforms/cell/beat_iommu.c
... ... @@ -108,7 +108,7 @@
108 108 celleb_init_direct_mapping();
109 109 set_pci_dma_ops(&dma_direct_ops);
110 110 ppc_md.pci_dma_dev_setup = celleb_pci_dma_dev_setup;
111   - bus_register_notifier(&of_platform_bus_type, &celleb_of_bus_notifier);
  111 + bus_register_notifier(&platform_bus_type, &celleb_of_bus_notifier);
112 112  
113 113 return 0;
114 114 }
arch/powerpc/platforms/cell/iommu.c
... ... @@ -1204,7 +1204,7 @@
1204 1204 /* Register callbacks on OF platform device addition/removal
1205 1205 * to handle linking them to the right DMA operations
1206 1206 */
1207   - bus_register_notifier(&of_platform_bus_type, &cell_of_bus_notifier);
  1207 + bus_register_notifier(&platform_bus_type, &cell_of_bus_notifier);
1208 1208  
1209 1209 return 0;
1210 1210 }
arch/powerpc/sysdev/mv64x60_dev.c
... ... @@ -20,12 +20,7 @@
20 20  
21 21 #include <asm/prom.h>
22 22  
23   -/*
24   - * These functions provide the necessary setup for the mv64x60 drivers.
25   - * These drivers are unusual in that they work on both the MIPS and PowerPC
26   - * architectures. Because of that, the drivers do not support the normal
27   - * PowerPC of_platform_bus_type. They support platform_bus_type instead.
28   - */
  23 +/* These functions provide the necessary setup for the mv64x60 drivers. */
29 24  
30 25 static struct of_device_id __initdata of_mv64x60_devices[] = {
31 26 { .compatible = "marvell,mv64306-devctrl", },
arch/sparc/kernel/of_device_32.c
... ... @@ -424,7 +424,7 @@
424 424 build_device_resources(op, parent);
425 425  
426 426 op->dev.parent = parent;
427   - op->dev.bus = &of_platform_bus_type;
  427 + op->dev.bus = &platform_bus_type;
428 428 if (!parent)
429 429 dev_set_name(&op->dev, "root");
430 430 else
431 431  
432 432  
433 433  
... ... @@ -452,30 +452,19 @@
452 452 }
453 453 }
454 454  
455   -static void __init scan_of_devices(void)
  455 +static int __init scan_of_devices(void)
456 456 {
457 457 struct device_node *root = of_find_node_by_path("/");
458 458 struct of_device *parent;
459 459  
460 460 parent = scan_one_device(root, NULL);
461 461 if (!parent)
462   - return;
  462 + return 0;
463 463  
464 464 scan_tree(root->child, &parent->dev);
  465 + return 0;
465 466 }
466   -
467   -static int __init of_bus_driver_init(void)
468   -{
469   - int err;
470   -
471   - err = of_bus_type_init(&of_platform_bus_type, "of");
472   - if (!err)
473   - scan_of_devices();
474   -
475   - return err;
476   -}
477   -
478   -postcore_initcall(of_bus_driver_init);
  467 +postcore_initcall(scan_of_devices);
479 468  
480 469 static int __init of_debug(char *str)
481 470 {
arch/sparc/kernel/of_device_64.c
... ... @@ -667,7 +667,7 @@
667 667 op->archdata.irqs[i] = build_one_device_irq(op, parent, op->archdata.irqs[i]);
668 668  
669 669 op->dev.parent = parent;
670   - op->dev.bus = &of_platform_bus_type;
  670 + op->dev.bus = &platform_bus_type;
671 671 if (!parent)
672 672 dev_set_name(&op->dev, "root");
673 673 else
674 674  
675 675  
676 676  
... ... @@ -695,30 +695,19 @@
695 695 }
696 696 }
697 697  
698   -static void __init scan_of_devices(void)
  698 +static int __init scan_of_devices(void)
699 699 {
700 700 struct device_node *root = of_find_node_by_path("/");
701 701 struct of_device *parent;
702 702  
703 703 parent = scan_one_device(root, NULL);
704 704 if (!parent)
705   - return;
  705 + return 0;
706 706  
707 707 scan_tree(root->child, &parent->dev);
  708 + return 0;
708 709 }
709   -
710   -static int __init of_bus_driver_init(void)
711   -{
712   - int err;
713   -
714   - err = of_bus_type_init(&of_platform_bus_type, "of");
715   - if (!err)
716   - scan_of_devices();
717   -
718   - return err;
719   -}
720   -
721   -postcore_initcall(of_bus_driver_init);
  710 +postcore_initcall(scan_of_devices);
722 711  
723 712 static int __init of_debug(char *str)
724 713 {
arch/sparc/kernel/of_device_common.c
... ... @@ -64,9 +64,6 @@
64 64 }
65 65 }
66 66  
67   -struct bus_type of_platform_bus_type;
68   -EXPORT_SYMBOL(of_platform_bus_type);
69   -
70 67 static void get_cells(struct device_node *dp, int *addrc, int *sizec)
71 68 {
72 69 if (addrc)
drivers/base/platform.c
... ... @@ -636,6 +636,12 @@
636 636 static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
637 637 {
638 638 struct platform_device *pdev = to_platform_device(dev);
  639 + int rc;
  640 +
  641 + /* Some devices have extra OF data and an OF-style MODALIAS */
  642 + rc = of_device_uevent(dev,env);
  643 + if (rc != -ENODEV)
  644 + return rc;
639 645  
640 646 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
641 647 (pdev->id_entry) ? pdev->id_entry->name : pdev->name);
... ... @@ -104,6 +104,11 @@
104 104  
105 105 device_initialize(&ofdev->dev);
106 106  
  107 + /* name and id have to be set so that the platform bus doesn't get
  108 + * confused on matching */
  109 + ofdev->name = dev_name(&ofdev->dev);
  110 + ofdev->id = -1;
  111 +
107 112 /* device_add will assume that this device is on the same node as
108 113 * the parent. If there is no parent defined, set the node
109 114 * explicitly */
drivers/of/platform.c
... ... @@ -20,7 +20,55 @@
20 20 #include <linux/of_device.h>
21 21 #include <linux/of_irq.h>
22 22 #include <linux/of_platform.h>
  23 +#include <linux/platform_device.h>
23 24  
  25 +static 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 +
  37 +static 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 + */
  50 +int 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 +}
  64 +EXPORT_SYMBOL(of_register_platform_driver);
  65 +
  66 +void of_unregister_platform_driver(struct of_platform_driver *drv)
  67 +{
  68 + platform_driver_unregister(&drv->platform_driver);
  69 +}
  70 +EXPORT_SYMBOL(of_unregister_platform_driver);
  71 +
24 72 #if defined(CONFIG_PPC_DCR)
25 73 #include <asm/dcr.h>
26 74 #endif
27 75  
28 76  
... ... @@ -392,16 +440,29 @@
392 440  
393 441 int 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 454 /* register with core */
  455 + drv->driver.bus = bus;
398 456 return driver_register(&drv->driver);
399 457 }
400 458 EXPORT_SYMBOL(of_register_driver);
401 459  
402 460 void 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 }
406 467 EXPORT_SYMBOL(of_unregister_driver);
407 468  
... ... @@ -548,7 +609,7 @@
548 609 dev->archdata.dma_mask = 0xffffffffUL;
549 610 #endif
550 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 614 /* We do not fill the DMA ops for platform devices by default.
554 615 * This is currently the responsibility of the platform code
include/linux/of_device.h
... ... @@ -65,6 +65,12 @@
65 65 return 0;
66 66 }
67 67  
  68 +static inline int of_device_uevent(struct device *dev,
  69 + struct kobj_uevent_env *env)
  70 +{
  71 + return -ENODEV;
  72 +}
  73 +
68 74 #endif /* CONFIG_OF_DEVICE */
69 75  
70 76 #endif /* _LINUX_OF_DEVICE_H */
include/linux/of_platform.h
... ... @@ -17,19 +17,19 @@
17 17 #include <linux/mod_devicetable.h>
18 18 #include <linux/pm.h>
19 19 #include <linux/of_device.h>
  20 +#include <linux/platform_device.h>
20 21  
21 22 /*
22   - * The of_platform_bus_type is a bus type used by drivers that do not
23   - * attach to a macio or similar bus but still use OF probing
24   - * mechanism
  23 + * of_platform_bus_type isn't it's own bus anymore. It's now just an alias
  24 + * for the platform bus.
25 25 */
26   -extern struct bus_type of_platform_bus_type;
  26 +#define of_platform_bus_type platform_bus_type
27 27  
28 28 extern const struct of_device_id of_default_bus_ids[];
29 29  
30 30 /*
31 31 * An of_platform_driver driver is attached to a basic of_device on
32   - * the "platform bus" (of_platform_bus_type).
  32 + * the "platform bus" (platform_bus_type).
33 33 */
34 34 struct of_platform_driver
35 35 {
... ... @@ -42,6 +42,7 @@
42 42 int (*shutdown)(struct of_device* dev);
43 43  
44 44 struct device_driver driver;
  45 + struct platform_driver platform_driver;
45 46 };
46 47 #define to_of_platform_driver(drv) \
47 48 container_of(drv,struct of_platform_driver, driver)
... ... @@ -51,14 +52,8 @@
51 52 extern void of_unregister_driver(struct of_platform_driver *drv);
52 53  
53 54 /* Platform drivers register/unregister */
54   -static inline int of_register_platform_driver(struct of_platform_driver *drv)
55   -{
56   - return of_register_driver(drv, &of_platform_bus_type);
57   -}
58   -static inline void of_unregister_platform_driver(struct of_platform_driver *drv)
59   -{
60   - of_unregister_driver(drv);
61   -}
  55 +extern int of_register_platform_driver(struct of_platform_driver *drv);
  56 +extern void of_unregister_platform_driver(struct of_platform_driver *drv);
62 57  
63 58 extern struct of_device *of_device_alloc(struct device_node *np,
64 59 const char *bus_id,