of/device: Merge of_platform_bus_probe()
[pandora-kernel.git] / arch / microblaze / kernel / of_platform.c
1 /*
2  *    Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3  *                       <benh@kernel.crashing.org>
4  *    and                Arnd Bergmann, IBM Corp.
5  *
6  *  This program is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU General Public License
8  *  as published by the Free Software Foundation; either version
9  *  2 of the License, or (at your option) any later version.
10  *
11  */
12
13 #undef DEBUG
14
15 #include <linux/string.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/mod_devicetable.h>
20 #include <linux/pci.h>
21 #include <linux/of.h>
22 #include <linux/of_device.h>
23 #include <linux/of_platform.h>
24
25 #include <linux/errno.h>
26 #include <linux/topology.h>
27 #include <asm/atomic.h>
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 /*
41  * The list of OF IDs below is used for matching bus types in the
42  * system whose devices are to be exposed as of_platform_devices.
43  *
44  * This is the default list valid for most platforms. This file provides
45  * functions who can take an explicit list if necessary though
46  *
47  * The search is always performed recursively looking for children of
48  * the provided device_node and recursively if such a children matches
49  * a bus type in the list
50  */
51
52 const struct of_device_id of_default_bus_ids[] = {
53         { .type = "soc", },
54         { .compatible = "soc", },
55         { .type = "plb5", },
56         { .type = "plb4", },
57         { .type = "opb", },
58         { .type = "simple", },
59         {},
60 };
61
62 static int of_dev_node_match(struct device *dev, void *data)
63 {
64         return to_of_device(dev)->dev.of_node == data;
65 }
66
67 struct of_device *of_find_device_by_node(struct device_node *np)
68 {
69         struct device *dev;
70
71         dev = bus_find_device(&of_platform_bus_type,
72                               NULL, np, of_dev_node_match);
73         if (dev)
74                 return to_of_device(dev);
75         return NULL;
76 }
77 EXPORT_SYMBOL(of_find_device_by_node);
78
79 static int of_dev_phandle_match(struct device *dev, void *data)
80 {
81         phandle *ph = data;
82         return to_of_device(dev)->dev.of_node->phandle == *ph;
83 }
84
85 struct of_device *of_find_device_by_phandle(phandle ph)
86 {
87         struct device *dev;
88
89         dev = bus_find_device(&of_platform_bus_type,
90                               NULL, &ph, of_dev_phandle_match);
91         if (dev)
92                 return to_of_device(dev);
93         return NULL;
94 }
95 EXPORT_SYMBOL(of_find_device_by_phandle);