aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 12:18:08 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 12:18:08 -0400
commit2cb7e714229681408e323852bed939989faf6991 (patch)
tree552b78fa5830a0337594f9fbab5f1dc0306e93cd /arch
parentd638d4990bfb99998420e78e8fd4607bca5cf8d0 (diff)
parent3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons: Create drivers/of/platform.c Create linux/of_platorm.h [SPARC/64] Rename some functions like PowerPC Begin consolidation of of_device.h Begin to consolidate of_device.c Consolidate of_find_node_by routines Consolidate of_get_next_child Consolidate of_get_parent Consolidate of_find_property Consolidate of_device_is_compatible Start split out of common open firmware code Split out common parts of prom.h
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/Kconfig3
-rw-r--r--arch/powerpc/kernel/of_device.c122
-rw-r--r--arch/powerpc/kernel/of_platform.c82
-rw-r--r--arch/powerpc/kernel/prom.c250
-rw-r--r--arch/sparc/Kconfig3
-rw-r--r--arch/sparc/kernel/of_device.c222
-rw-r--r--arch/sparc/kernel/prom.c173
-rw-r--r--arch/sparc/kernel/time.c2
-rw-r--r--arch/sparc64/Kconfig3
-rw-r--r--arch/sparc64/kernel/auxio.c2
-rw-r--r--arch/sparc64/kernel/of_device.c238
-rw-r--r--arch/sparc64/kernel/power.c2
-rw-r--r--arch/sparc64/kernel/prom.c173
-rw-r--r--arch/sparc64/kernel/time.c2
14 files changed, 51 insertions, 1226 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index d860b640a140..853c282da22e 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -92,6 +92,9 @@ config ARCH_MAY_HAVE_PC_FDC
92config PPC_OF 92config PPC_OF
93 def_bool y 93 def_bool y
94 94
95config OF
96 def_bool y
97
95config PPC_UDBG_16550 98config PPC_UDBG_16550
96 bool 99 bool
97 default n 100 default n
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
index a464d67248df..89b911e83c04 100644
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -1,5 +1,6 @@
1#include <linux/string.h> 1#include <linux/string.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/of.h>
3#include <linux/init.h> 4#include <linux/init.h>
4#include <linux/module.h> 5#include <linux/module.h>
5#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
@@ -8,118 +9,6 @@
8#include <asm/errno.h> 9#include <asm/errno.h>
9#include <asm/of_device.h> 10#include <asm/of_device.h>
10 11
11/**
12 * of_match_node - Tell if an device_node has a matching of_match structure
13 * @ids: array of of device match structures to search in
14 * @node: the of device structure to match against
15 *
16 * Low level utility function used by device matching.
17 */
18const struct of_device_id *of_match_node(const struct of_device_id *matches,
19 const struct device_node *node)
20{
21 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
22 int match = 1;
23 if (matches->name[0])
24 match &= node->name
25 && !strcmp(matches->name, node->name);
26 if (matches->type[0])
27 match &= node->type
28 && !strcmp(matches->type, node->type);
29 if (matches->compatible[0])
30 match &= of_device_is_compatible(node,
31 matches->compatible);
32 if (match)
33 return matches;
34 matches++;
35 }
36 return NULL;
37}
38
39/**
40 * of_match_device - Tell if an of_device structure has a matching
41 * of_match structure
42 * @ids: array of of device match structures to search in
43 * @dev: the of device structure to match against
44 *
45 * Used by a driver to check whether an of_device present in the
46 * system is in its list of supported devices.
47 */
48const struct of_device_id *of_match_device(const struct of_device_id *matches,
49 const struct of_device *dev)
50{
51 if (!dev->node)
52 return NULL;
53 return of_match_node(matches, dev->node);
54}
55
56struct of_device *of_dev_get(struct of_device *dev)
57{
58 struct device *tmp;
59
60 if (!dev)
61 return NULL;
62 tmp = get_device(&dev->dev);
63 if (tmp)
64 return to_of_device(tmp);
65 else
66 return NULL;
67}
68
69void of_dev_put(struct of_device *dev)
70{
71 if (dev)
72 put_device(&dev->dev);
73}
74
75static ssize_t dev_show_devspec(struct device *dev,
76 struct device_attribute *attr, char *buf)
77{
78 struct of_device *ofdev;
79
80 ofdev = to_of_device(dev);
81 return sprintf(buf, "%s", ofdev->node->full_name);
82}
83
84static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
85
86/**
87 * of_release_dev - free an of device structure when all users of it are finished.
88 * @dev: device that's been disconnected
89 *
90 * Will be called only by the device core when all users of this of device are
91 * done.
92 */
93void of_release_dev(struct device *dev)
94{
95 struct of_device *ofdev;
96
97 ofdev = to_of_device(dev);
98 of_node_put(ofdev->node);
99 kfree(ofdev);
100}
101
102int of_device_register(struct of_device *ofdev)
103{
104 int rc;
105
106 BUG_ON(ofdev->node == NULL);
107
108 rc = device_register(&ofdev->dev);
109 if (rc)
110 return rc;
111
112 return device_create_file(&ofdev->dev, &dev_attr_devspec);
113}
114
115void of_device_unregister(struct of_device *ofdev)
116{
117 device_remove_file(&ofdev->dev, &dev_attr_devspec);
118
119 device_unregister(&ofdev->dev);
120}
121
122
123ssize_t of_device_get_modalias(struct of_device *ofdev, 12ssize_t of_device_get_modalias(struct of_device *ofdev,
124 char *str, ssize_t len) 13 char *str, ssize_t len)
125{ 14{
@@ -229,14 +118,5 @@ int of_device_uevent(struct device *dev,
229 118
230 return 0; 119 return 0;
231} 120}
232
233
234EXPORT_SYMBOL(of_match_node);
235EXPORT_SYMBOL(of_match_device);
236EXPORT_SYMBOL(of_device_register);
237EXPORT_SYMBOL(of_device_unregister);
238EXPORT_SYMBOL(of_dev_get);
239EXPORT_SYMBOL(of_dev_put);
240EXPORT_SYMBOL(of_release_dev);
241EXPORT_SYMBOL(of_device_uevent); 121EXPORT_SYMBOL(of_device_uevent);
242EXPORT_SYMBOL(of_device_get_modalias); 122EXPORT_SYMBOL(of_device_get_modalias);
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index 8ded4e7dc87e..f70e787d556f 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -55,94 +55,14 @@ static struct of_device_id of_default_bus_ids[] = {
55 55
56static atomic_t bus_no_reg_magic; 56static atomic_t bus_no_reg_magic;
57 57
58/*
59 *
60 * OF platform device type definition & base infrastructure
61 *
62 */
63
64static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
65{
66 struct of_device * of_dev = to_of_device(dev);
67 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
68 const struct of_device_id * matches = of_drv->match_table;
69
70 if (!matches)
71 return 0;
72
73 return of_match_device(matches, of_dev) != NULL;
74}
75
76static int of_platform_device_probe(struct device *dev)
77{
78 int error = -ENODEV;
79 struct of_platform_driver *drv;
80 struct of_device *of_dev;
81 const struct of_device_id *match;
82
83 drv = to_of_platform_driver(dev->driver);
84 of_dev = to_of_device(dev);
85
86 if (!drv->probe)
87 return error;
88
89 of_dev_get(of_dev);
90
91 match = of_match_device(drv->match_table, of_dev);
92 if (match)
93 error = drv->probe(of_dev, match);
94 if (error)
95 of_dev_put(of_dev);
96
97 return error;
98}
99
100static int of_platform_device_remove(struct device *dev)
101{
102 struct of_device * of_dev = to_of_device(dev);
103 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
104
105 if (dev->driver && drv->remove)
106 drv->remove(of_dev);
107 return 0;
108}
109
110static int of_platform_device_suspend(struct device *dev, pm_message_t state)
111{
112 struct of_device * of_dev = to_of_device(dev);
113 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
114 int error = 0;
115
116 if (dev->driver && drv->suspend)
117 error = drv->suspend(of_dev, state);
118 return error;
119}
120
121static int of_platform_device_resume(struct device * dev)
122{
123 struct of_device * of_dev = to_of_device(dev);
124 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
125 int error = 0;
126
127 if (dev->driver && drv->resume)
128 error = drv->resume(of_dev);
129 return error;
130}
131
132struct bus_type of_platform_bus_type = { 58struct bus_type of_platform_bus_type = {
133 .name = "of_platform",
134 .match = of_platform_bus_match,
135 .uevent = of_device_uevent, 59 .uevent = of_device_uevent,
136 .probe = of_platform_device_probe,
137 .remove = of_platform_device_remove,
138 .suspend = of_platform_device_suspend,
139 .resume = of_platform_device_resume,
140}; 60};
141EXPORT_SYMBOL(of_platform_bus_type); 61EXPORT_SYMBOL(of_platform_bus_type);
142 62
143static int __init of_bus_driver_init(void) 63static int __init of_bus_driver_init(void)
144{ 64{
145 return bus_register(&of_platform_bus_type); 65 return of_bus_type_init(&of_platform_bus_type, "of_platform");
146} 66}
147 67
148postcore_initcall(of_bus_driver_init); 68postcore_initcall(of_bus_driver_init);
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 37ff99bd98b4..bdcd23d8d8b9 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -78,12 +78,9 @@ static struct boot_param_header *initial_boot_params __initdata;
78struct boot_param_header *initial_boot_params; 78struct boot_param_header *initial_boot_params;
79#endif 79#endif
80 80
81static struct device_node *allnodes = NULL; 81extern struct device_node *allnodes; /* temporary while merging */
82 82
83/* use when traversing tree through the allnext, child, sibling, 83extern rwlock_t devtree_lock; /* temporary while merging */
84 * or parent members of struct device_node.
85 */
86static DEFINE_RWLOCK(devtree_lock);
87 84
88/* export that to outside world */ 85/* export that to outside world */
89struct device_node *of_chosen; 86struct device_node *of_chosen;
@@ -1056,60 +1053,6 @@ void __init early_init_devtree(void *params)
1056 DBG(" <- early_init_devtree()\n"); 1053 DBG(" <- early_init_devtree()\n");
1057} 1054}
1058 1055
1059int of_n_addr_cells(struct device_node* np)
1060{
1061 const int *ip;
1062 do {
1063 if (np->parent)
1064 np = np->parent;
1065 ip = of_get_property(np, "#address-cells", NULL);
1066 if (ip != NULL)
1067 return *ip;
1068 } while (np->parent);
1069 /* No #address-cells property for the root node, default to 1 */
1070 return 1;
1071}
1072EXPORT_SYMBOL(of_n_addr_cells);
1073
1074int of_n_size_cells(struct device_node* np)
1075{
1076 const int* ip;
1077 do {
1078 if (np->parent)
1079 np = np->parent;
1080 ip = of_get_property(np, "#size-cells", NULL);
1081 if (ip != NULL)
1082 return *ip;
1083 } while (np->parent);
1084 /* No #size-cells property for the root node, default to 1 */
1085 return 1;
1086}
1087EXPORT_SYMBOL(of_n_size_cells);
1088
1089/** Checks if the given "compat" string matches one of the strings in
1090 * the device's "compatible" property
1091 */
1092int of_device_is_compatible(const struct device_node *device,
1093 const char *compat)
1094{
1095 const char* cp;
1096 int cplen, l;
1097
1098 cp = of_get_property(device, "compatible", &cplen);
1099 if (cp == NULL)
1100 return 0;
1101 while (cplen > 0) {
1102 if (strncasecmp(cp, compat, strlen(compat)) == 0)
1103 return 1;
1104 l = strlen(cp) + 1;
1105 cp += l;
1106 cplen -= l;
1107 }
1108
1109 return 0;
1110}
1111EXPORT_SYMBOL(of_device_is_compatible);
1112
1113 1056
1114/** 1057/**
1115 * Indicates whether the root node has a given value in its 1058 * Indicates whether the root node has a given value in its
@@ -1141,119 +1084,6 @@ EXPORT_SYMBOL(machine_is_compatible);
1141 *******/ 1084 *******/
1142 1085
1143/** 1086/**
1144 * of_find_node_by_name - Find a node by its "name" property
1145 * @from: The node to start searching from or NULL, the node
1146 * you pass will not be searched, only the next one
1147 * will; typically, you pass what the previous call
1148 * returned. of_node_put() will be called on it
1149 * @name: The name string to match against
1150 *
1151 * Returns a node pointer with refcount incremented, use
1152 * of_node_put() on it when done.
1153 */
1154struct device_node *of_find_node_by_name(struct device_node *from,
1155 const char *name)
1156{
1157 struct device_node *np;
1158
1159 read_lock(&devtree_lock);
1160 np = from ? from->allnext : allnodes;
1161 for (; np != NULL; np = np->allnext)
1162 if (np->name != NULL && strcasecmp(np->name, name) == 0
1163 && of_node_get(np))
1164 break;
1165 of_node_put(from);
1166 read_unlock(&devtree_lock);
1167 return np;
1168}
1169EXPORT_SYMBOL(of_find_node_by_name);
1170
1171/**
1172 * of_find_node_by_type - Find a node by its "device_type" property
1173 * @from: The node to start searching from, or NULL to start searching
1174 * the entire device tree. The node you pass will not be
1175 * searched, only the next one will; typically, you pass
1176 * what the previous call returned. of_node_put() will be
1177 * called on from for you.
1178 * @type: The type string to match against
1179 *
1180 * Returns a node pointer with refcount incremented, use
1181 * of_node_put() on it when done.
1182 */
1183struct device_node *of_find_node_by_type(struct device_node *from,
1184 const char *type)
1185{
1186 struct device_node *np;
1187
1188 read_lock(&devtree_lock);
1189 np = from ? from->allnext : allnodes;
1190 for (; np != 0; np = np->allnext)
1191 if (np->type != 0 && strcasecmp(np->type, type) == 0
1192 && of_node_get(np))
1193 break;
1194 of_node_put(from);
1195 read_unlock(&devtree_lock);
1196 return np;
1197}
1198EXPORT_SYMBOL(of_find_node_by_type);
1199
1200/**
1201 * of_find_compatible_node - Find a node based on type and one of the
1202 * tokens in its "compatible" property
1203 * @from: The node to start searching from or NULL, the node
1204 * you pass will not be searched, only the next one
1205 * will; typically, you pass what the previous call
1206 * returned. of_node_put() will be called on it
1207 * @type: The type string to match "device_type" or NULL to ignore
1208 * @compatible: The string to match to one of the tokens in the device
1209 * "compatible" list.
1210 *
1211 * Returns a node pointer with refcount incremented, use
1212 * of_node_put() on it when done.
1213 */
1214struct device_node *of_find_compatible_node(struct device_node *from,
1215 const char *type, const char *compatible)
1216{
1217 struct device_node *np;
1218
1219 read_lock(&devtree_lock);
1220 np = from ? from->allnext : allnodes;
1221 for (; np != 0; np = np->allnext) {
1222 if (type != NULL
1223 && !(np->type != 0 && strcasecmp(np->type, type) == 0))
1224 continue;
1225 if (of_device_is_compatible(np, compatible) && of_node_get(np))
1226 break;
1227 }
1228 of_node_put(from);
1229 read_unlock(&devtree_lock);
1230 return np;
1231}
1232EXPORT_SYMBOL(of_find_compatible_node);
1233
1234/**
1235 * of_find_node_by_path - Find a node matching a full OF path
1236 * @path: The full path to match
1237 *
1238 * Returns a node pointer with refcount incremented, use
1239 * of_node_put() on it when done.
1240 */
1241struct device_node *of_find_node_by_path(const char *path)
1242{
1243 struct device_node *np = allnodes;
1244
1245 read_lock(&devtree_lock);
1246 for (; np != 0; np = np->allnext) {
1247 if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0
1248 && of_node_get(np))
1249 break;
1250 }
1251 read_unlock(&devtree_lock);
1252 return np;
1253}
1254EXPORT_SYMBOL(of_find_node_by_path);
1255
1256/**
1257 * of_find_node_by_phandle - Find a node given a phandle 1087 * of_find_node_by_phandle - Find a node given a phandle
1258 * @handle: phandle of the node to find 1088 * @handle: phandle of the node to find
1259 * 1089 *
@@ -1298,51 +1128,6 @@ struct device_node *of_find_all_nodes(struct device_node *prev)
1298EXPORT_SYMBOL(of_find_all_nodes); 1128EXPORT_SYMBOL(of_find_all_nodes);
1299 1129
1300/** 1130/**
1301 * of_get_parent - Get a node's parent if any
1302 * @node: Node to get parent
1303 *
1304 * Returns a node pointer with refcount incremented, use
1305 * of_node_put() on it when done.
1306 */
1307struct device_node *of_get_parent(const struct device_node *node)
1308{
1309 struct device_node *np;
1310
1311 if (!node)
1312 return NULL;
1313
1314 read_lock(&devtree_lock);
1315 np = of_node_get(node->parent);
1316 read_unlock(&devtree_lock);
1317 return np;
1318}
1319EXPORT_SYMBOL(of_get_parent);
1320
1321/**
1322 * of_get_next_child - Iterate a node childs
1323 * @node: parent node
1324 * @prev: previous child of the parent node, or NULL to get first
1325 *
1326 * Returns a node pointer with refcount incremented, use
1327 * of_node_put() on it when done.
1328 */
1329struct device_node *of_get_next_child(const struct device_node *node,
1330 struct device_node *prev)
1331{
1332 struct device_node *next;
1333
1334 read_lock(&devtree_lock);
1335 next = prev ? prev->sibling : node->child;
1336 for (; next != 0; next = next->sibling)
1337 if (of_node_get(next))
1338 break;
1339 of_node_put(prev);
1340 read_unlock(&devtree_lock);
1341 return next;
1342}
1343EXPORT_SYMBOL(of_get_next_child);
1344
1345/**
1346 * of_node_get - Increment refcount of a node 1131 * of_node_get - Increment refcount of a node
1347 * @node: Node to inc refcount, NULL is supported to 1132 * @node: Node to inc refcount, NULL is supported to
1348 * simplify writing of callers 1133 * simplify writing of callers
@@ -1543,37 +1328,6 @@ static int __init prom_reconfig_setup(void)
1543__initcall(prom_reconfig_setup); 1328__initcall(prom_reconfig_setup);
1544#endif 1329#endif
1545 1330
1546struct property *of_find_property(const struct device_node *np,
1547 const char *name,
1548 int *lenp)
1549{
1550 struct property *pp;
1551
1552 read_lock(&devtree_lock);
1553 for (pp = np->properties; pp != 0; pp = pp->next)
1554 if (strcmp(pp->name, name) == 0) {
1555 if (lenp != 0)
1556 *lenp = pp->length;
1557 break;
1558 }
1559 read_unlock(&devtree_lock);
1560
1561 return pp;
1562}
1563EXPORT_SYMBOL(of_find_property);
1564
1565/*
1566 * Find a property with a given name for a given node
1567 * and return the value.
1568 */
1569const void *of_get_property(const struct device_node *np, const char *name,
1570 int *lenp)
1571{
1572 struct property *pp = of_find_property(np,name,lenp);
1573 return pp ? pp->value : NULL;
1574}
1575EXPORT_SYMBOL(of_get_property);
1576
1577/* 1331/*
1578 * Add a property to a node 1332 * Add a property to a node
1579 */ 1333 */
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 603d83ad65c8..9d327ec59759 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -24,6 +24,9 @@ config GENERIC_ISA_DMA
24config ARCH_NO_VIRT_TO_BUS 24config ARCH_NO_VIRT_TO_BUS
25 def_bool y 25 def_bool y
26 26
27config OF
28 def_bool y
29
27source "init/Kconfig" 30source "init/Kconfig"
28 31
29menu "General machine setup" 32menu "General machine setup"
diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c
index fd7f8cb668a3..7176040caba0 100644
--- a/arch/sparc/kernel/of_device.c
+++ b/arch/sparc/kernel/of_device.c
@@ -1,132 +1,13 @@
1#include <linux/string.h> 1#include <linux/string.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/of.h>
3#include <linux/init.h> 4#include <linux/init.h>
4#include <linux/module.h> 5#include <linux/module.h>
5#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
6#include <linux/slab.h> 7#include <linux/slab.h>
7 8#include <linux/errno.h>
8#include <asm/errno.h> 9#include <linux/of_device.h>
9#include <asm/of_device.h> 10#include <linux/of_platform.h>
10
11/**
12 * of_match_device - Tell if an of_device structure has a matching
13 * of_match structure
14 * @ids: array of of device match structures to search in
15 * @dev: the of device structure to match against
16 *
17 * Used by a driver to check whether an of_device present in the
18 * system is in its list of supported devices.
19 */
20const struct of_device_id *of_match_device(const struct of_device_id *matches,
21 const struct of_device *dev)
22{
23 if (!dev->node)
24 return NULL;
25 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
26 int match = 1;
27 if (matches->name[0])
28 match &= dev->node->name
29 && !strcmp(matches->name, dev->node->name);
30 if (matches->type[0])
31 match &= dev->node->type
32 && !strcmp(matches->type, dev->node->type);
33 if (matches->compatible[0])
34 match &= of_device_is_compatible(dev->node,
35 matches->compatible);
36 if (match)
37 return matches;
38 matches++;
39 }
40 return NULL;
41}
42
43static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
44{
45 struct of_device * of_dev = to_of_device(dev);
46 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
47 const struct of_device_id * matches = of_drv->match_table;
48
49 if (!matches)
50 return 0;
51
52 return of_match_device(matches, of_dev) != NULL;
53}
54
55struct of_device *of_dev_get(struct of_device *dev)
56{
57 struct device *tmp;
58
59 if (!dev)
60 return NULL;
61 tmp = get_device(&dev->dev);
62 if (tmp)
63 return to_of_device(tmp);
64 else
65 return NULL;
66}
67
68void of_dev_put(struct of_device *dev)
69{
70 if (dev)
71 put_device(&dev->dev);
72}
73
74
75static int of_device_probe(struct device *dev)
76{
77 int error = -ENODEV;
78 struct of_platform_driver *drv;
79 struct of_device *of_dev;
80 const struct of_device_id *match;
81
82 drv = to_of_platform_driver(dev->driver);
83 of_dev = to_of_device(dev);
84
85 if (!drv->probe)
86 return error;
87
88 of_dev_get(of_dev);
89
90 match = of_match_device(drv->match_table, of_dev);
91 if (match)
92 error = drv->probe(of_dev, match);
93 if (error)
94 of_dev_put(of_dev);
95
96 return error;
97}
98
99static int of_device_remove(struct device *dev)
100{
101 struct of_device * of_dev = to_of_device(dev);
102 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
103
104 if (dev->driver && drv->remove)
105 drv->remove(of_dev);
106 return 0;
107}
108
109static int of_device_suspend(struct device *dev, pm_message_t state)
110{
111 struct of_device * of_dev = to_of_device(dev);
112 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
113 int error = 0;
114
115 if (dev->driver && drv->suspend)
116 error = drv->suspend(of_dev, state);
117 return error;
118}
119
120static int of_device_resume(struct device * dev)
121{
122 struct of_device * of_dev = to_of_device(dev);
123 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
124 int error = 0;
125
126 if (dev->driver && drv->resume)
127 error = drv->resume(of_dev);
128 return error;
129}
130 11
131static int node_match(struct device *dev, void *data) 12static int node_match(struct device *dev, void *data)
132{ 13{
@@ -138,7 +19,7 @@ static int node_match(struct device *dev, void *data)
138 19
139struct of_device *of_find_device_by_node(struct device_node *dp) 20struct of_device *of_find_device_by_node(struct device_node *dp)
140{ 21{
141 struct device *dev = bus_find_device(&of_bus_type, NULL, 22 struct device *dev = bus_find_device(&of_platform_bus_type, NULL,
142 dp, node_match); 23 dp, node_match);
143 24
144 if (dev) 25 if (dev)
@@ -149,38 +30,17 @@ struct of_device *of_find_device_by_node(struct device_node *dp)
149EXPORT_SYMBOL(of_find_device_by_node); 30EXPORT_SYMBOL(of_find_device_by_node);
150 31
151#ifdef CONFIG_PCI 32#ifdef CONFIG_PCI
152struct bus_type ebus_bus_type = { 33struct bus_type ebus_bus_type;
153 .name = "ebus",
154 .match = of_platform_bus_match,
155 .probe = of_device_probe,
156 .remove = of_device_remove,
157 .suspend = of_device_suspend,
158 .resume = of_device_resume,
159};
160EXPORT_SYMBOL(ebus_bus_type); 34EXPORT_SYMBOL(ebus_bus_type);
161#endif 35#endif
162 36
163#ifdef CONFIG_SBUS 37#ifdef CONFIG_SBUS
164struct bus_type sbus_bus_type = { 38struct bus_type sbus_bus_type;
165 .name = "sbus",
166 .match = of_platform_bus_match,
167 .probe = of_device_probe,
168 .remove = of_device_remove,
169 .suspend = of_device_suspend,
170 .resume = of_device_resume,
171};
172EXPORT_SYMBOL(sbus_bus_type); 39EXPORT_SYMBOL(sbus_bus_type);
173#endif 40#endif
174 41
175struct bus_type of_bus_type = { 42struct bus_type of_platform_bus_type;
176 .name = "of", 43EXPORT_SYMBOL(of_platform_bus_type);
177 .match = of_platform_bus_match,
178 .probe = of_device_probe,
179 .remove = of_device_remove,
180 .suspend = of_device_suspend,
181 .resume = of_device_resume,
182};
183EXPORT_SYMBOL(of_bus_type);
184 44
185static inline u64 of_read_addr(const u32 *cell, int size) 45static inline u64 of_read_addr(const u32 *cell, int size)
186{ 46{
@@ -646,7 +506,7 @@ build_resources:
646 build_device_resources(op, parent); 506 build_device_resources(op, parent);
647 507
648 op->dev.parent = parent; 508 op->dev.parent = parent;
649 op->dev.bus = &of_bus_type; 509 op->dev.bus = &of_platform_bus_type;
650 if (!parent) 510 if (!parent)
651 strcpy(op->dev.bus_id, "root"); 511 strcpy(op->dev.bus_id, "root");
652 else 512 else
@@ -690,14 +550,14 @@ static int __init of_bus_driver_init(void)
690{ 550{
691 int err; 551 int err;
692 552
693 err = bus_register(&of_bus_type); 553 err = of_bus_type_init(&of_platform_bus_type, "of");
694#ifdef CONFIG_PCI 554#ifdef CONFIG_PCI
695 if (!err) 555 if (!err)
696 err = bus_register(&ebus_bus_type); 556 err = of_bus_type_init(&ebus_bus_type, "ebus");
697#endif 557#endif
698#ifdef CONFIG_SBUS 558#ifdef CONFIG_SBUS
699 if (!err) 559 if (!err)
700 err = bus_register(&sbus_bus_type); 560 err = of_bus_type_init(&sbus_bus_type, "sbus");
701#endif 561#endif
702 562
703 if (!err) 563 if (!err)
@@ -735,56 +595,6 @@ void of_unregister_driver(struct of_platform_driver *drv)
735 driver_unregister(&drv->driver); 595 driver_unregister(&drv->driver);
736} 596}
737 597
738
739static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
740{
741 struct of_device *ofdev;
742
743 ofdev = to_of_device(dev);
744 return sprintf(buf, "%s", ofdev->node->full_name);
745}
746
747static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
748
749/**
750 * of_release_dev - free an of device structure when all users of it are finished.
751 * @dev: device that's been disconnected
752 *
753 * Will be called only by the device core when all users of this of device are
754 * done.
755 */
756void of_release_dev(struct device *dev)
757{
758 struct of_device *ofdev;
759
760 ofdev = to_of_device(dev);
761
762 kfree(ofdev);
763}
764
765int of_device_register(struct of_device *ofdev)
766{
767 int rc;
768
769 BUG_ON(ofdev->node == NULL);
770
771 rc = device_register(&ofdev->dev);
772 if (rc)
773 return rc;
774
775 rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
776 if (rc)
777 device_unregister(&ofdev->dev);
778
779 return rc;
780}
781
782void of_device_unregister(struct of_device *ofdev)
783{
784 device_remove_file(&ofdev->dev, &dev_attr_devspec);
785 device_unregister(&ofdev->dev);
786}
787
788struct of_device* of_platform_device_create(struct device_node *np, 598struct of_device* of_platform_device_create(struct device_node *np,
789 const char *bus_id, 599 const char *bus_id,
790 struct device *parent, 600 struct device *parent,
@@ -810,12 +620,6 @@ struct of_device* of_platform_device_create(struct device_node *np,
810 return dev; 620 return dev;
811} 621}
812 622
813EXPORT_SYMBOL(of_match_device);
814EXPORT_SYMBOL(of_register_driver); 623EXPORT_SYMBOL(of_register_driver);
815EXPORT_SYMBOL(of_unregister_driver); 624EXPORT_SYMBOL(of_unregister_driver);
816EXPORT_SYMBOL(of_device_register);
817EXPORT_SYMBOL(of_device_unregister);
818EXPORT_SYMBOL(of_dev_get);
819EXPORT_SYMBOL(of_dev_put);
820EXPORT_SYMBOL(of_platform_device_create); 625EXPORT_SYMBOL(of_platform_device_create);
821EXPORT_SYMBOL(of_release_dev);
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c
index eed140b3c739..012f98346bcd 100644
--- a/arch/sparc/kernel/prom.c
+++ b/arch/sparc/kernel/prom.c
@@ -25,73 +25,9 @@
25#include <asm/prom.h> 25#include <asm/prom.h>
26#include <asm/oplib.h> 26#include <asm/oplib.h>
27 27
28static struct device_node *allnodes; 28extern struct device_node *allnodes; /* temporary while merging */
29 29
30/* use when traversing tree through the allnext, child, sibling, 30extern rwlock_t devtree_lock; /* temporary while merging */
31 * or parent members of struct device_node.
32 */
33static DEFINE_RWLOCK(devtree_lock);
34
35int of_device_is_compatible(const struct device_node *device,
36 const char *compat)
37{
38 const char* cp;
39 int cplen, l;
40
41 cp = of_get_property(device, "compatible", &cplen);
42 if (cp == NULL)
43 return 0;
44 while (cplen > 0) {
45 if (strncmp(cp, compat, strlen(compat)) == 0)
46 return 1;
47 l = strlen(cp) + 1;
48 cp += l;
49 cplen -= l;
50 }
51
52 return 0;
53}
54EXPORT_SYMBOL(of_device_is_compatible);
55
56struct device_node *of_get_parent(const struct device_node *node)
57{
58 struct device_node *np;
59
60 if (!node)
61 return NULL;
62
63 np = node->parent;
64
65 return np;
66}
67EXPORT_SYMBOL(of_get_parent);
68
69struct device_node *of_get_next_child(const struct device_node *node,
70 struct device_node *prev)
71{
72 struct device_node *next;
73
74 next = prev ? prev->sibling : node->child;
75 for (; next != 0; next = next->sibling) {
76 break;
77 }
78
79 return next;
80}
81EXPORT_SYMBOL(of_get_next_child);
82
83struct device_node *of_find_node_by_path(const char *path)
84{
85 struct device_node *np = allnodes;
86
87 for (; np != 0; np = np->allnext) {
88 if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
89 break;
90 }
91
92 return np;
93}
94EXPORT_SYMBOL(of_find_node_by_path);
95 31
96struct device_node *of_find_node_by_phandle(phandle handle) 32struct device_node *of_find_node_by_phandle(phandle handle)
97{ 33{
@@ -105,81 +41,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
105} 41}
106EXPORT_SYMBOL(of_find_node_by_phandle); 42EXPORT_SYMBOL(of_find_node_by_phandle);
107 43
108struct device_node *of_find_node_by_name(struct device_node *from,
109 const char *name)
110{
111 struct device_node *np;
112
113 np = from ? from->allnext : allnodes;
114 for (; np != NULL; np = np->allnext)
115 if (np->name != NULL && strcmp(np->name, name) == 0)
116 break;
117
118 return np;
119}
120EXPORT_SYMBOL(of_find_node_by_name);
121
122struct device_node *of_find_node_by_type(struct device_node *from,
123 const char *type)
124{
125 struct device_node *np;
126
127 np = from ? from->allnext : allnodes;
128 for (; np != 0; np = np->allnext)
129 if (np->type != 0 && strcmp(np->type, type) == 0)
130 break;
131
132 return np;
133}
134EXPORT_SYMBOL(of_find_node_by_type);
135
136struct device_node *of_find_compatible_node(struct device_node *from,
137 const char *type, const char *compatible)
138{
139 struct device_node *np;
140
141 np = from ? from->allnext : allnodes;
142 for (; np != 0; np = np->allnext) {
143 if (type != NULL
144 && !(np->type != 0 && strcmp(np->type, type) == 0))
145 continue;
146 if (of_device_is_compatible(np, compatible))
147 break;
148 }
149
150 return np;
151}
152EXPORT_SYMBOL(of_find_compatible_node);
153
154struct property *of_find_property(const struct device_node *np,
155 const char *name,
156 int *lenp)
157{
158 struct property *pp;
159
160 for (pp = np->properties; pp != 0; pp = pp->next) {
161 if (strcasecmp(pp->name, name) == 0) {
162 if (lenp != 0)
163 *lenp = pp->length;
164 break;
165 }
166 }
167 return pp;
168}
169EXPORT_SYMBOL(of_find_property);
170
171/*
172 * Find a property with a given name for a given node
173 * and return the value.
174 */
175const void *of_get_property(const struct device_node *np, const char *name,
176 int *lenp)
177{
178 struct property *pp = of_find_property(np,name,lenp);
179 return pp ? pp->value : NULL;
180}
181EXPORT_SYMBOL(of_get_property);
182
183int of_getintprop_default(struct device_node *np, const char *name, int def) 44int of_getintprop_default(struct device_node *np, const char *name, int def)
184{ 45{
185 struct property *prop; 46 struct property *prop;
@@ -193,36 +54,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def)
193} 54}
194EXPORT_SYMBOL(of_getintprop_default); 55EXPORT_SYMBOL(of_getintprop_default);
195 56
196int of_n_addr_cells(struct device_node *np)
197{
198 const int* ip;
199 do {
200 if (np->parent)
201 np = np->parent;
202 ip = of_get_property(np, "#address-cells", NULL);
203 if (ip != NULL)
204 return *ip;
205 } while (np->parent);
206 /* No #address-cells property for the root node, default to 2 */
207 return 2;
208}
209EXPORT_SYMBOL(of_n_addr_cells);
210
211int of_n_size_cells(struct device_node *np)
212{
213 const int* ip;
214 do {
215 if (np->parent)
216 np = np->parent;
217 ip = of_get_property(np, "#size-cells", NULL);
218 if (ip != NULL)
219 return *ip;
220 } while (np->parent);
221 /* No #size-cells property for the root node, default to 1 */
222 return 1;
223}
224EXPORT_SYMBOL(of_n_size_cells);
225
226int of_set_property(struct device_node *dp, const char *name, void *val, int len) 57int of_set_property(struct device_node *dp, const char *name, void *val, int len)
227{ 58{
228 struct property **prevp; 59 struct property **prevp;
diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c
index 7b4612da74a6..f2fdbb3664d3 100644
--- a/arch/sparc/kernel/time.c
+++ b/arch/sparc/kernel/time.c
@@ -354,7 +354,7 @@ static struct of_platform_driver clock_driver = {
354/* Probe for the mostek real time clock chip. */ 354/* Probe for the mostek real time clock chip. */
355static int __init clock_init(void) 355static int __init clock_init(void)
356{ 356{
357 return of_register_driver(&clock_driver, &of_bus_type); 357 return of_register_driver(&clock_driver, &of_platform_bus_type);
358} 358}
359 359
360/* Must be after subsys_initcall() so that busses are probed. Must 360/* Must be after subsys_initcall() so that busses are probed. Must
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index df6ee71894d1..f1cc55677ff2 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -65,6 +65,9 @@ config AUDIT_ARCH
65config ARCH_NO_VIRT_TO_BUS 65config ARCH_NO_VIRT_TO_BUS
66 def_bool y 66 def_bool y
67 67
68config OF
69 def_bool y
70
68choice 71choice
69 prompt "Kernel page size" 72 prompt "Kernel page size"
70 default SPARC64_PAGE_SIZE_8KB 73 default SPARC64_PAGE_SIZE_8KB
diff --git a/arch/sparc64/kernel/auxio.c b/arch/sparc64/kernel/auxio.c
index 826118ee53d5..7b379761e9f8 100644
--- a/arch/sparc64/kernel/auxio.c
+++ b/arch/sparc64/kernel/auxio.c
@@ -155,7 +155,7 @@ static struct of_platform_driver auxio_driver = {
155 155
156static int __init auxio_init(void) 156static int __init auxio_init(void)
157{ 157{
158 return of_register_driver(&auxio_driver, &of_bus_type); 158 return of_register_driver(&auxio_driver, &of_platform_bus_type);
159} 159}
160 160
161/* Must be after subsys_initcall() so that busses are probed. Must 161/* Must be after subsys_initcall() so that busses are probed. Must
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index 6676b93219dc..7b0dce9604ee 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -1,132 +1,13 @@
1#include <linux/string.h> 1#include <linux/string.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/of.h>
3#include <linux/init.h> 4#include <linux/init.h>
4#include <linux/module.h> 5#include <linux/module.h>
5#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
6#include <linux/slab.h> 7#include <linux/slab.h>
7 8#include <linux/errno.h>
8#include <asm/errno.h> 9#include <linux/of_device.h>
9#include <asm/of_device.h> 10#include <linux/of_platform.h>
10
11/**
12 * of_match_device - Tell if an of_device structure has a matching
13 * of_match structure
14 * @ids: array of of device match structures to search in
15 * @dev: the of device structure to match against
16 *
17 * Used by a driver to check whether an of_device present in the
18 * system is in its list of supported devices.
19 */
20const struct of_device_id *of_match_device(const struct of_device_id *matches,
21 const struct of_device *dev)
22{
23 if (!dev->node)
24 return NULL;
25 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
26 int match = 1;
27 if (matches->name[0])
28 match &= dev->node->name
29 && !strcmp(matches->name, dev->node->name);
30 if (matches->type[0])
31 match &= dev->node->type
32 && !strcmp(matches->type, dev->node->type);
33 if (matches->compatible[0])
34 match &= of_device_is_compatible(dev->node,
35 matches->compatible);
36 if (match)
37 return matches;
38 matches++;
39 }
40 return NULL;
41}
42
43static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
44{
45 struct of_device * of_dev = to_of_device(dev);
46 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
47 const struct of_device_id * matches = of_drv->match_table;
48
49 if (!matches)
50 return 0;
51
52 return of_match_device(matches, of_dev) != NULL;
53}
54
55struct of_device *of_dev_get(struct of_device *dev)
56{
57 struct device *tmp;
58
59 if (!dev)
60 return NULL;
61 tmp = get_device(&dev->dev);
62 if (tmp)
63 return to_of_device(tmp);
64 else
65 return NULL;
66}
67
68void of_dev_put(struct of_device *dev)
69{
70 if (dev)
71 put_device(&dev->dev);
72}
73
74
75static int of_device_probe(struct device *dev)
76{
77 int error = -ENODEV;
78 struct of_platform_driver *drv;
79 struct of_device *of_dev;
80 const struct of_device_id *match;
81
82 drv = to_of_platform_driver(dev->driver);
83 of_dev = to_of_device(dev);
84
85 if (!drv->probe)
86 return error;
87
88 of_dev_get(of_dev);
89
90 match = of_match_device(drv->match_table, of_dev);
91 if (match)
92 error = drv->probe(of_dev, match);
93 if (error)
94 of_dev_put(of_dev);
95
96 return error;
97}
98
99static int of_device_remove(struct device *dev)
100{
101 struct of_device * of_dev = to_of_device(dev);
102 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
103
104 if (dev->driver && drv->remove)
105 drv->remove(of_dev);
106 return 0;
107}
108
109static int of_device_suspend(struct device *dev, pm_message_t state)
110{
111 struct of_device * of_dev = to_of_device(dev);
112 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
113 int error = 0;
114
115 if (dev->driver && drv->suspend)
116 error = drv->suspend(of_dev, state);
117 return error;
118}
119
120static int of_device_resume(struct device * dev)
121{
122 struct of_device * of_dev = to_of_device(dev);
123 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
124 int error = 0;
125
126 if (dev->driver && drv->resume)
127 error = drv->resume(of_dev);
128 return error;
129}
130 11
131void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name) 12void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name)
132{ 13{
@@ -163,7 +44,7 @@ static int node_match(struct device *dev, void *data)
163 44
164struct of_device *of_find_device_by_node(struct device_node *dp) 45struct of_device *of_find_device_by_node(struct device_node *dp)
165{ 46{
166 struct device *dev = bus_find_device(&of_bus_type, NULL, 47 struct device *dev = bus_find_device(&of_platform_bus_type, NULL,
167 dp, node_match); 48 dp, node_match);
168 49
169 if (dev) 50 if (dev)
@@ -174,48 +55,20 @@ struct of_device *of_find_device_by_node(struct device_node *dp)
174EXPORT_SYMBOL(of_find_device_by_node); 55EXPORT_SYMBOL(of_find_device_by_node);
175 56
176#ifdef CONFIG_PCI 57#ifdef CONFIG_PCI
177struct bus_type isa_bus_type = { 58struct bus_type isa_bus_type;
178 .name = "isa",
179 .match = of_platform_bus_match,
180 .probe = of_device_probe,
181 .remove = of_device_remove,
182 .suspend = of_device_suspend,
183 .resume = of_device_resume,
184};
185EXPORT_SYMBOL(isa_bus_type); 59EXPORT_SYMBOL(isa_bus_type);
186 60
187struct bus_type ebus_bus_type = { 61struct bus_type ebus_bus_type;
188 .name = "ebus",
189 .match = of_platform_bus_match,
190 .probe = of_device_probe,
191 .remove = of_device_remove,
192 .suspend = of_device_suspend,
193 .resume = of_device_resume,
194};
195EXPORT_SYMBOL(ebus_bus_type); 62EXPORT_SYMBOL(ebus_bus_type);
196#endif 63#endif
197 64
198#ifdef CONFIG_SBUS 65#ifdef CONFIG_SBUS
199struct bus_type sbus_bus_type = { 66struct bus_type sbus_bus_type;
200 .name = "sbus",
201 .match = of_platform_bus_match,
202 .probe = of_device_probe,
203 .remove = of_device_remove,
204 .suspend = of_device_suspend,
205 .resume = of_device_resume,
206};
207EXPORT_SYMBOL(sbus_bus_type); 67EXPORT_SYMBOL(sbus_bus_type);
208#endif 68#endif
209 69
210struct bus_type of_bus_type = { 70struct bus_type of_platform_bus_type;
211 .name = "of", 71EXPORT_SYMBOL(of_platform_bus_type);
212 .match = of_platform_bus_match,
213 .probe = of_device_probe,
214 .remove = of_device_remove,
215 .suspend = of_device_suspend,
216 .resume = of_device_resume,
217};
218EXPORT_SYMBOL(of_bus_type);
219 72
220static inline u64 of_read_addr(const u32 *cell, int size) 73static inline u64 of_read_addr(const u32 *cell, int size)
221{ 74{
@@ -933,7 +786,7 @@ static struct of_device * __init scan_one_device(struct device_node *dp,
933 op->irqs[i] = build_one_device_irq(op, parent, op->irqs[i]); 786 op->irqs[i] = build_one_device_irq(op, parent, op->irqs[i]);
934 787
935 op->dev.parent = parent; 788 op->dev.parent = parent;
936 op->dev.bus = &of_bus_type; 789 op->dev.bus = &of_platform_bus_type;
937 if (!parent) 790 if (!parent)
938 strcpy(op->dev.bus_id, "root"); 791 strcpy(op->dev.bus_id, "root");
939 else 792 else
@@ -977,16 +830,16 @@ static int __init of_bus_driver_init(void)
977{ 830{
978 int err; 831 int err;
979 832
980 err = bus_register(&of_bus_type); 833 err = of_bus_type_init(&of_platform_bus_type, "of");
981#ifdef CONFIG_PCI 834#ifdef CONFIG_PCI
982 if (!err) 835 if (!err)
983 err = bus_register(&isa_bus_type); 836 err = of_bus_type_init(&isa_bus_type, "isa");
984 if (!err) 837 if (!err)
985 err = bus_register(&ebus_bus_type); 838 err = of_bus_type_init(&ebus_bus_type, "ebus");
986#endif 839#endif
987#ifdef CONFIG_SBUS 840#ifdef CONFIG_SBUS
988 if (!err) 841 if (!err)
989 err = bus_register(&sbus_bus_type); 842 err = of_bus_type_init(&sbus_bus_type, "sbus");
990#endif 843#endif
991 844
992 if (!err) 845 if (!err)
@@ -1020,61 +873,13 @@ int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
1020 /* register with core */ 873 /* register with core */
1021 return driver_register(&drv->driver); 874 return driver_register(&drv->driver);
1022} 875}
876EXPORT_SYMBOL(of_register_driver);
1023 877
1024void of_unregister_driver(struct of_platform_driver *drv) 878void of_unregister_driver(struct of_platform_driver *drv)
1025{ 879{
1026 driver_unregister(&drv->driver); 880 driver_unregister(&drv->driver);
1027} 881}
1028 882EXPORT_SYMBOL(of_unregister_driver);
1029
1030static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
1031{
1032 struct of_device *ofdev;
1033
1034 ofdev = to_of_device(dev);
1035 return sprintf(buf, "%s", ofdev->node->full_name);
1036}
1037
1038static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
1039
1040/**
1041 * of_release_dev - free an of device structure when all users of it are finished.
1042 * @dev: device that's been disconnected
1043 *
1044 * Will be called only by the device core when all users of this of device are
1045 * done.
1046 */
1047void of_release_dev(struct device *dev)
1048{
1049 struct of_device *ofdev;
1050
1051 ofdev = to_of_device(dev);
1052
1053 kfree(ofdev);
1054}
1055
1056int of_device_register(struct of_device *ofdev)
1057{
1058 int rc;
1059
1060 BUG_ON(ofdev->node == NULL);
1061
1062 rc = device_register(&ofdev->dev);
1063 if (rc)
1064 return rc;
1065
1066 rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
1067 if (rc)
1068 device_unregister(&ofdev->dev);
1069
1070 return rc;
1071}
1072
1073void of_device_unregister(struct of_device *ofdev)
1074{
1075 device_remove_file(&ofdev->dev, &dev_attr_devspec);
1076 device_unregister(&ofdev->dev);
1077}
1078 883
1079struct of_device* of_platform_device_create(struct device_node *np, 884struct of_device* of_platform_device_create(struct device_node *np,
1080 const char *bus_id, 885 const char *bus_id,
@@ -1100,13 +905,4 @@ struct of_device* of_platform_device_create(struct device_node *np,
1100 905
1101 return dev; 906 return dev;
1102} 907}
1103
1104EXPORT_SYMBOL(of_match_device);
1105EXPORT_SYMBOL(of_register_driver);
1106EXPORT_SYMBOL(of_unregister_driver);
1107EXPORT_SYMBOL(of_device_register);
1108EXPORT_SYMBOL(of_device_unregister);
1109EXPORT_SYMBOL(of_dev_get);
1110EXPORT_SYMBOL(of_dev_put);
1111EXPORT_SYMBOL(of_platform_device_create); 908EXPORT_SYMBOL(of_platform_device_create);
1112EXPORT_SYMBOL(of_release_dev);
diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c
index 39f9f6494d4c..b00feb01c16f 100644
--- a/arch/sparc64/kernel/power.c
+++ b/arch/sparc64/kernel/power.c
@@ -112,6 +112,6 @@ static struct of_platform_driver power_driver = {
112 112
113void __init power_init(void) 113void __init power_init(void)
114{ 114{
115 of_register_driver(&power_driver, &of_bus_type); 115 of_register_driver(&power_driver, &of_platform_bus_type);
116 return; 116 return;
117} 117}
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c
index 5d220302cd50..2b2017ce2267 100644
--- a/arch/sparc64/kernel/prom.c
+++ b/arch/sparc64/kernel/prom.c
@@ -30,73 +30,9 @@
30#include <asm/upa.h> 30#include <asm/upa.h>
31#include <asm/smp.h> 31#include <asm/smp.h>
32 32
33static struct device_node *allnodes; 33extern struct device_node *allnodes; /* temporary while merging */
34 34
35/* use when traversing tree through the allnext, child, sibling, 35extern rwlock_t devtree_lock; /* temporary while merging */
36 * or parent members of struct device_node.
37 */
38static DEFINE_RWLOCK(devtree_lock);
39
40int of_device_is_compatible(const struct device_node *device,
41 const char *compat)
42{
43 const char* cp;
44 int cplen, l;
45
46 cp = of_get_property(device, "compatible", &cplen);
47 if (cp == NULL)
48 return 0;
49 while (cplen > 0) {
50 if (strncmp(cp, compat, strlen(compat)) == 0)
51 return 1;
52 l = strlen(cp) + 1;
53 cp += l;
54 cplen -= l;
55 }
56
57 return 0;
58}
59EXPORT_SYMBOL(of_device_is_compatible);
60
61struct device_node *of_get_parent(const struct device_node *node)
62{
63 struct device_node *np;
64
65 if (!node)
66 return NULL;
67
68 np = node->parent;
69
70 return np;
71}
72EXPORT_SYMBOL(of_get_parent);
73
74struct device_node *of_get_next_child(const struct device_node *node,
75 struct device_node *prev)
76{
77 struct device_node *next;
78
79 next = prev ? prev->sibling : node->child;
80 for (; next != 0; next = next->sibling) {
81 break;
82 }
83
84 return next;
85}
86EXPORT_SYMBOL(of_get_next_child);
87
88struct device_node *of_find_node_by_path(const char *path)
89{
90 struct device_node *np = allnodes;
91
92 for (; np != 0; np = np->allnext) {
93 if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
94 break;
95 }
96
97 return np;
98}
99EXPORT_SYMBOL(of_find_node_by_path);
100 36
101struct device_node *of_find_node_by_phandle(phandle handle) 37struct device_node *of_find_node_by_phandle(phandle handle)
102{ 38{
@@ -110,81 +46,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
110} 46}
111EXPORT_SYMBOL(of_find_node_by_phandle); 47EXPORT_SYMBOL(of_find_node_by_phandle);
112 48
113struct device_node *of_find_node_by_name(struct device_node *from,
114 const char *name)
115{
116 struct device_node *np;
117
118 np = from ? from->allnext : allnodes;
119 for (; np != NULL; np = np->allnext)
120 if (np->name != NULL && strcmp(np->name, name) == 0)
121 break;
122
123 return np;
124}
125EXPORT_SYMBOL(of_find_node_by_name);
126
127struct device_node *of_find_node_by_type(struct device_node *from,
128 const char *type)
129{
130 struct device_node *np;
131
132 np = from ? from->allnext : allnodes;
133 for (; np != 0; np = np->allnext)
134 if (np->type != 0 && strcmp(np->type, type) == 0)
135 break;
136
137 return np;
138}
139EXPORT_SYMBOL(of_find_node_by_type);
140
141struct device_node *of_find_compatible_node(struct device_node *from,
142 const char *type, const char *compatible)
143{
144 struct device_node *np;
145
146 np = from ? from->allnext : allnodes;
147 for (; np != 0; np = np->allnext) {
148 if (type != NULL
149 && !(np->type != 0 && strcmp(np->type, type) == 0))
150 continue;
151 if (of_device_is_compatible(np, compatible))
152 break;
153 }
154
155 return np;
156}
157EXPORT_SYMBOL(of_find_compatible_node);
158
159struct property *of_find_property(const struct device_node *np,
160 const char *name,
161 int *lenp)
162{
163 struct property *pp;
164
165 for (pp = np->properties; pp != 0; pp = pp->next) {
166 if (strcasecmp(pp->name, name) == 0) {
167 if (lenp != 0)
168 *lenp = pp->length;
169 break;
170 }
171 }
172 return pp;
173}
174EXPORT_SYMBOL(of_find_property);
175
176/*
177 * Find a property with a given name for a given node
178 * and return the value.
179 */
180const void *of_get_property(const struct device_node *np, const char *name,
181 int *lenp)
182{
183 struct property *pp = of_find_property(np,name,lenp);
184 return pp ? pp->value : NULL;
185}
186EXPORT_SYMBOL(of_get_property);
187
188int of_getintprop_default(struct device_node *np, const char *name, int def) 49int of_getintprop_default(struct device_node *np, const char *name, int def)
189{ 50{
190 struct property *prop; 51 struct property *prop;
@@ -198,36 +59,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def)
198} 59}
199EXPORT_SYMBOL(of_getintprop_default); 60EXPORT_SYMBOL(of_getintprop_default);
200 61
201int of_n_addr_cells(struct device_node *np)
202{
203 const int* ip;
204 do {
205 if (np->parent)
206 np = np->parent;
207 ip = of_get_property(np, "#address-cells", NULL);
208 if (ip != NULL)
209 return *ip;
210 } while (np->parent);
211 /* No #address-cells property for the root node, default to 2 */
212 return 2;
213}
214EXPORT_SYMBOL(of_n_addr_cells);
215
216int of_n_size_cells(struct device_node *np)
217{
218 const int* ip;
219 do {
220 if (np->parent)
221 np = np->parent;
222 ip = of_get_property(np, "#size-cells", NULL);
223 if (ip != NULL)
224 return *ip;
225 } while (np->parent);
226 /* No #size-cells property for the root node, default to 1 */
227 return 1;
228}
229EXPORT_SYMBOL(of_n_size_cells);
230
231int of_set_property(struct device_node *dp, const char *name, void *val, int len) 62int of_set_property(struct device_node *dp, const char *name, void *val, int len)
232{ 63{
233 struct property **prevp; 64 struct property **prevp;
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
index 62e316ab1339..592ffcd57605 100644
--- a/arch/sparc64/kernel/time.c
+++ b/arch/sparc64/kernel/time.c
@@ -835,7 +835,7 @@ static int __init clock_init(void)
835 return 0; 835 return 0;
836 } 836 }
837 837
838 return of_register_driver(&clock_driver, &of_bus_type); 838 return of_register_driver(&clock_driver, &of_platform_bus_type);
839} 839}
840 840
841/* Must be after subsys_initcall() so that busses are probed. Must 841/* Must be after subsys_initcall() so that busses are probed. Must