aboutsummaryrefslogtreecommitdiffstats
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
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
-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
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/of/Kconfig3
-rw-r--r--drivers/of/Makefile2
-rw-r--r--drivers/of/base.c275
-rw-r--r--drivers/of/device.c131
-rw-r--r--drivers/of/platform.c96
-rw-r--r--include/asm-powerpc/of_device.h22
-rw-r--r--include/asm-powerpc/of_platform.h38
-rw-r--r--include/asm-powerpc/prom.h50
-rw-r--r--include/asm-sparc/of_device.h49
-rw-r--r--include/asm-sparc/of_platform.h32
-rw-r--r--include/asm-sparc/prom.h62
-rw-r--r--include/asm-sparc64/of_device.h50
-rw-r--r--include/asm-sparc64/of_platform.h33
-rw-r--r--include/asm-sparc64/prom.h62
-rw-r--r--include/linux/of.h61
-rw-r--r--include/linux/of_device.h26
-rw-r--r--include/linux/of_platform.h57
33 files changed, 846 insertions, 1483 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
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 707650ab77a7..3e1c442deff9 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -8,6 +8,8 @@ source "drivers/connector/Kconfig"
8 8
9source "drivers/mtd/Kconfig" 9source "drivers/mtd/Kconfig"
10 10
11source "drivers/of/Kconfig"
12
11source "drivers/parport/Kconfig" 13source "drivers/parport/Kconfig"
12 14
13source "drivers/pnp/Kconfig" 15source "drivers/pnp/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 0ea8e3237c0d..a9e4c5f922a0 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -86,3 +86,4 @@ obj-$(CONFIG_GENERIC_TIME) += clocksource/
86obj-$(CONFIG_DMA_ENGINE) += dma/ 86obj-$(CONFIG_DMA_ENGINE) += dma/
87obj-$(CONFIG_HID) += hid/ 87obj-$(CONFIG_HID) += hid/
88obj-$(CONFIG_PPC_PS3) += ps3/ 88obj-$(CONFIG_PPC_PS3) += ps3/
89obj-$(CONFIG_OF) += of/
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
new file mode 100644
index 000000000000..c03072b12f42
--- /dev/null
+++ b/drivers/of/Kconfig
@@ -0,0 +1,3 @@
1config OF_DEVICE
2 def_bool y
3 depends on OF && (SPARC || PPC_OF)
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
new file mode 100644
index 000000000000..ab9be5d5255b
--- /dev/null
+++ b/drivers/of/Makefile
@@ -0,0 +1,2 @@
1obj-y = base.o
2obj-$(CONFIG_OF_DEVICE) += device.o platform.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
new file mode 100644
index 000000000000..9377f3bc410a
--- /dev/null
+++ b/drivers/of/base.c
@@ -0,0 +1,275 @@
1/*
2 * Procedures for creating, accessing and interpreting the device tree.
3 *
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
6 *
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
9 *
10 * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
11 *
12 * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
18 */
19#include <linux/module.h>
20#include <linux/of.h>
21#include <linux/spinlock.h>
22
23struct device_node *allnodes;
24
25/* use when traversing tree through the allnext, child, sibling,
26 * or parent members of struct device_node.
27 */
28DEFINE_RWLOCK(devtree_lock);
29
30int of_n_addr_cells(struct device_node *np)
31{
32 const int *ip;
33
34 do {
35 if (np->parent)
36 np = np->parent;
37 ip = of_get_property(np, "#address-cells", NULL);
38 if (ip)
39 return *ip;
40 } while (np->parent);
41 /* No #address-cells property for the root node */
42 return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
43}
44EXPORT_SYMBOL(of_n_addr_cells);
45
46int of_n_size_cells(struct device_node *np)
47{
48 const int *ip;
49
50 do {
51 if (np->parent)
52 np = np->parent;
53 ip = of_get_property(np, "#size-cells", NULL);
54 if (ip)
55 return *ip;
56 } while (np->parent);
57 /* No #size-cells property for the root node */
58 return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
59}
60EXPORT_SYMBOL(of_n_size_cells);
61
62struct property *of_find_property(const struct device_node *np,
63 const char *name,
64 int *lenp)
65{
66 struct property *pp;
67
68 read_lock(&devtree_lock);
69 for (pp = np->properties; pp != 0; pp = pp->next) {
70 if (of_prop_cmp(pp->name, name) == 0) {
71 if (lenp != 0)
72 *lenp = pp->length;
73 break;
74 }
75 }
76 read_unlock(&devtree_lock);
77
78 return pp;
79}
80EXPORT_SYMBOL(of_find_property);
81
82/*
83 * Find a property with a given name for a given node
84 * and return the value.
85 */
86const void *of_get_property(const struct device_node *np, const char *name,
87 int *lenp)
88{
89 struct property *pp = of_find_property(np, name, lenp);
90
91 return pp ? pp->value : NULL;
92}
93EXPORT_SYMBOL(of_get_property);
94
95/** Checks if the given "compat" string matches one of the strings in
96 * the device's "compatible" property
97 */
98int of_device_is_compatible(const struct device_node *device,
99 const char *compat)
100{
101 const char* cp;
102 int cplen, l;
103
104 cp = of_get_property(device, "compatible", &cplen);
105 if (cp == NULL)
106 return 0;
107 while (cplen > 0) {
108 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
109 return 1;
110 l = strlen(cp) + 1;
111 cp += l;
112 cplen -= l;
113 }
114
115 return 0;
116}
117EXPORT_SYMBOL(of_device_is_compatible);
118
119/**
120 * of_get_parent - Get a node's parent if any
121 * @node: Node to get parent
122 *
123 * Returns a node pointer with refcount incremented, use
124 * of_node_put() on it when done.
125 */
126struct device_node *of_get_parent(const struct device_node *node)
127{
128 struct device_node *np;
129
130 if (!node)
131 return NULL;
132
133 read_lock(&devtree_lock);
134 np = of_node_get(node->parent);
135 read_unlock(&devtree_lock);
136 return np;
137}
138EXPORT_SYMBOL(of_get_parent);
139
140/**
141 * of_get_next_child - Iterate a node childs
142 * @node: parent node
143 * @prev: previous child of the parent node, or NULL to get first
144 *
145 * Returns a node pointer with refcount incremented, use
146 * of_node_put() on it when done.
147 */
148struct device_node *of_get_next_child(const struct device_node *node,
149 struct device_node *prev)
150{
151 struct device_node *next;
152
153 read_lock(&devtree_lock);
154 next = prev ? prev->sibling : node->child;
155 for (; next; next = next->sibling)
156 if (of_node_get(next))
157 break;
158 of_node_put(prev);
159 read_unlock(&devtree_lock);
160 return next;
161}
162EXPORT_SYMBOL(of_get_next_child);
163
164/**
165 * of_find_node_by_path - Find a node matching a full OF path
166 * @path: The full path to match
167 *
168 * Returns a node pointer with refcount incremented, use
169 * of_node_put() on it when done.
170 */
171struct device_node *of_find_node_by_path(const char *path)
172{
173 struct device_node *np = allnodes;
174
175 read_lock(&devtree_lock);
176 for (; np; np = np->allnext) {
177 if (np->full_name && (of_node_cmp(np->full_name, path) == 0)
178 && of_node_get(np))
179 break;
180 }
181 read_unlock(&devtree_lock);
182 return np;
183}
184EXPORT_SYMBOL(of_find_node_by_path);
185
186/**
187 * of_find_node_by_name - Find a node by its "name" property
188 * @from: The node to start searching from or NULL, the node
189 * you pass will not be searched, only the next one
190 * will; typically, you pass what the previous call
191 * returned. of_node_put() will be called on it
192 * @name: The name string to match against
193 *
194 * Returns a node pointer with refcount incremented, use
195 * of_node_put() on it when done.
196 */
197struct device_node *of_find_node_by_name(struct device_node *from,
198 const char *name)
199{
200 struct device_node *np;
201
202 read_lock(&devtree_lock);
203 np = from ? from->allnext : allnodes;
204 for (; np; np = np->allnext)
205 if (np->name && (of_node_cmp(np->name, name) == 0)
206 && of_node_get(np))
207 break;
208 of_node_put(from);
209 read_unlock(&devtree_lock);
210 return np;
211}
212EXPORT_SYMBOL(of_find_node_by_name);
213
214/**
215 * of_find_node_by_type - Find a node by its "device_type" property
216 * @from: The node to start searching from, or NULL to start searching
217 * the entire device tree. The node you pass will not be
218 * searched, only the next one will; typically, you pass
219 * what the previous call returned. of_node_put() will be
220 * called on from for you.
221 * @type: The type string to match against
222 *
223 * Returns a node pointer with refcount incremented, use
224 * of_node_put() on it when done.
225 */
226struct device_node *of_find_node_by_type(struct device_node *from,
227 const char *type)
228{
229 struct device_node *np;
230
231 read_lock(&devtree_lock);
232 np = from ? from->allnext : allnodes;
233 for (; np; np = np->allnext)
234 if (np->type && (of_node_cmp(np->type, type) == 0)
235 && of_node_get(np))
236 break;
237 of_node_put(from);
238 read_unlock(&devtree_lock);
239 return np;
240}
241EXPORT_SYMBOL(of_find_node_by_type);
242
243/**
244 * of_find_compatible_node - Find a node based on type and one of the
245 * tokens in its "compatible" property
246 * @from: The node to start searching from or NULL, the node
247 * you pass will not be searched, only the next one
248 * will; typically, you pass what the previous call
249 * returned. of_node_put() will be called on it
250 * @type: The type string to match "device_type" or NULL to ignore
251 * @compatible: The string to match to one of the tokens in the device
252 * "compatible" list.
253 *
254 * Returns a node pointer with refcount incremented, use
255 * of_node_put() on it when done.
256 */
257struct device_node *of_find_compatible_node(struct device_node *from,
258 const char *type, const char *compatible)
259{
260 struct device_node *np;
261
262 read_lock(&devtree_lock);
263 np = from ? from->allnext : allnodes;
264 for (; np; np = np->allnext) {
265 if (type
266 && !(np->type && (of_node_cmp(np->type, type) == 0)))
267 continue;
268 if (of_device_is_compatible(np, compatible) && of_node_get(np))
269 break;
270 }
271 of_node_put(from);
272 read_unlock(&devtree_lock);
273 return np;
274}
275EXPORT_SYMBOL(of_find_compatible_node);
diff --git a/drivers/of/device.c b/drivers/of/device.c
new file mode 100644
index 000000000000..6245f060fb77
--- /dev/null
+++ b/drivers/of/device.c
@@ -0,0 +1,131 @@
1#include <linux/string.h>
2#include <linux/kernel.h>
3#include <linux/of.h>
4#include <linux/of_device.h>
5#include <linux/init.h>
6#include <linux/module.h>
7#include <linux/mod_devicetable.h>
8#include <linux/slab.h>
9
10#include <asm/errno.h>
11
12/**
13 * of_match_node - Tell if an device_node has a matching of_match structure
14 * @ids: array of of device match structures to search in
15 * @node: the of device structure to match against
16 *
17 * Low level utility function used by device matching.
18 */
19const struct of_device_id *of_match_node(const struct of_device_id *matches,
20 const struct device_node *node)
21{
22 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
23 int match = 1;
24 if (matches->name[0])
25 match &= node->name
26 && !strcmp(matches->name, node->name);
27 if (matches->type[0])
28 match &= node->type
29 && !strcmp(matches->type, node->type);
30 if (matches->compatible[0])
31 match &= of_device_is_compatible(node,
32 matches->compatible);
33 if (match)
34 return matches;
35 matches++;
36 }
37 return NULL;
38}
39EXPORT_SYMBOL(of_match_node);
40
41/**
42 * of_match_device - Tell if an of_device structure has a matching
43 * of_match structure
44 * @ids: array of of device match structures to search in
45 * @dev: the of device structure to match against
46 *
47 * Used by a driver to check whether an of_device present in the
48 * system is in its list of supported devices.
49 */
50const struct of_device_id *of_match_device(const struct of_device_id *matches,
51 const struct of_device *dev)
52{
53 if (!dev->node)
54 return NULL;
55 return of_match_node(matches, dev->node);
56}
57EXPORT_SYMBOL(of_match_device);
58
59struct of_device *of_dev_get(struct of_device *dev)
60{
61 struct device *tmp;
62
63 if (!dev)
64 return NULL;
65 tmp = get_device(&dev->dev);
66 if (tmp)
67 return to_of_device(tmp);
68 else
69 return NULL;
70}
71EXPORT_SYMBOL(of_dev_get);
72
73void of_dev_put(struct of_device *dev)
74{
75 if (dev)
76 put_device(&dev->dev);
77}
78EXPORT_SYMBOL(of_dev_put);
79
80static ssize_t dev_show_devspec(struct device *dev,
81 struct device_attribute *attr, char *buf)
82{
83 struct of_device *ofdev;
84
85 ofdev = to_of_device(dev);
86 return sprintf(buf, "%s", ofdev->node->full_name);
87}
88
89static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
90
91/**
92 * of_release_dev - free an of device structure when all users of it are finished.
93 * @dev: device that's been disconnected
94 *
95 * Will be called only by the device core when all users of this of device are
96 * done.
97 */
98void of_release_dev(struct device *dev)
99{
100 struct of_device *ofdev;
101
102 ofdev = to_of_device(dev);
103 of_node_put(ofdev->node);
104 kfree(ofdev);
105}
106EXPORT_SYMBOL(of_release_dev);
107
108int of_device_register(struct of_device *ofdev)
109{
110 int rc;
111
112 BUG_ON(ofdev->node == NULL);
113
114 rc = device_register(&ofdev->dev);
115 if (rc)
116 return rc;
117
118 rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
119 if (rc)
120 device_unregister(&ofdev->dev);
121
122 return rc;
123}
124EXPORT_SYMBOL(of_device_register);
125
126void of_device_unregister(struct of_device *ofdev)
127{
128 device_remove_file(&ofdev->dev, &dev_attr_devspec);
129 device_unregister(&ofdev->dev);
130}
131EXPORT_SYMBOL(of_device_unregister);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
new file mode 100644
index 000000000000..864f09fd9f86
--- /dev/null
+++ b/drivers/of/platform.c
@@ -0,0 +1,96 @@
1/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org>
4 * and Arnd Bergmann, IBM Corp.
5 * Merged from powerpc/kernel/of_platform.c and
6 * sparc{,64}/kernel/of_device.c by Stephen Rothwell
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 */
14#include <linux/errno.h>
15#include <linux/device.h>
16#include <linux/of_device.h>
17#include <linux/of_platform.h>
18
19static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
20{
21 struct of_device *of_dev = to_of_device(dev);
22 struct of_platform_driver *of_drv = to_of_platform_driver(drv);
23 const struct of_device_id *matches = of_drv->match_table;
24
25 if (!matches)
26 return 0;
27
28 return of_match_device(matches, of_dev) != NULL;
29}
30
31static int of_platform_device_probe(struct device *dev)
32{
33 int error = -ENODEV;
34 struct of_platform_driver *drv;
35 struct of_device *of_dev;
36 const struct of_device_id *match;
37
38 drv = to_of_platform_driver(dev->driver);
39 of_dev = to_of_device(dev);
40
41 if (!drv->probe)
42 return error;
43
44 of_dev_get(of_dev);
45
46 match = of_match_device(drv->match_table, of_dev);
47 if (match)
48 error = drv->probe(of_dev, match);
49 if (error)
50 of_dev_put(of_dev);
51
52 return error;
53}
54
55static int of_platform_device_remove(struct device *dev)
56{
57 struct of_device *of_dev = to_of_device(dev);
58 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
59
60 if (dev->driver && drv->remove)
61 drv->remove(of_dev);
62 return 0;
63}
64
65static int of_platform_device_suspend(struct device *dev, pm_message_t state)
66{
67 struct of_device *of_dev = to_of_device(dev);
68 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
69 int error = 0;
70
71 if (dev->driver && drv->suspend)
72 error = drv->suspend(of_dev, state);
73 return error;
74}
75
76static int of_platform_device_resume(struct device * dev)
77{
78 struct of_device *of_dev = to_of_device(dev);
79 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
80 int error = 0;
81
82 if (dev->driver && drv->resume)
83 error = drv->resume(of_dev);
84 return error;
85}
86
87int of_bus_type_init(struct bus_type *bus, const char *name)
88{
89 bus->name = name;
90 bus->match = of_platform_bus_match;
91 bus->probe = of_platform_device_probe;
92 bus->remove = of_platform_device_remove;
93 bus->suspend = of_platform_device_suspend;
94 bus->resume = of_platform_device_resume;
95 return bus_register(bus);
96}
diff --git a/include/asm-powerpc/of_device.h b/include/asm-powerpc/of_device.h
index e9af49eb1aa8..ec2a8a2c737c 100644
--- a/include/asm-powerpc/of_device.h
+++ b/include/asm-powerpc/of_device.h
@@ -3,14 +3,12 @@
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/mod_devicetable.h> 6#include <linux/of.h>
7#include <asm/prom.h>
8
9 7
10/* 8/*
11 * The of_device is a kind of "base class" that is a superset of 9 * The of_device is a kind of "base class" that is a superset of
12 * struct device for use by devices attached to an OF node and 10 * struct device for use by devices attached to an OF node and
13 * probed using OF properties 11 * probed using OF properties.
14 */ 12 */
15struct of_device 13struct of_device
16{ 14{
@@ -18,24 +16,14 @@ struct of_device
18 u64 dma_mask; /* DMA mask */ 16 u64 dma_mask; /* DMA mask */
19 struct device dev; /* Generic device interface */ 17 struct device dev; /* Generic device interface */
20}; 18};
21#define to_of_device(d) container_of(d, struct of_device, dev)
22
23extern const struct of_device_id *of_match_node(
24 const struct of_device_id *matches, const struct device_node *node);
25extern const struct of_device_id *of_match_device(
26 const struct of_device_id *matches, const struct of_device *dev);
27
28extern struct of_device *of_dev_get(struct of_device *dev);
29extern void of_dev_put(struct of_device *dev);
30
31extern int of_device_register(struct of_device *ofdev);
32extern void of_device_unregister(struct of_device *ofdev);
33extern void of_release_dev(struct device *dev);
34 19
35extern ssize_t of_device_get_modalias(struct of_device *ofdev, 20extern ssize_t of_device_get_modalias(struct of_device *ofdev,
36 char *str, ssize_t len); 21 char *str, ssize_t len);
37extern int of_device_uevent(struct device *dev, 22extern int of_device_uevent(struct device *dev,
38 char **envp, int num_envp, char *buffer, int buffer_size); 23 char **envp, int num_envp, char *buffer, int buffer_size);
39 24
25/* This is just here during the transition */
26#include <linux/of_device.h>
27
40#endif /* __KERNEL__ */ 28#endif /* __KERNEL__ */
41#endif /* _ASM_POWERPC_OF_DEVICE_H */ 29#endif /* _ASM_POWERPC_OF_DEVICE_H */
diff --git a/include/asm-powerpc/of_platform.h b/include/asm-powerpc/of_platform.h
index 217eafb167e9..80e6fad28b4f 100644
--- a/include/asm-powerpc/of_platform.h
+++ b/include/asm-powerpc/of_platform.h
@@ -1,3 +1,5 @@
1#ifndef _ASM_POWERPC_OF_PLATFORM_H
2#define _ASM_POWERPC_OF_PLATFORM_H
1/* 3/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. 4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org> 5 * <benh@kernel.crashing.org>
@@ -9,37 +11,8 @@
9 * 11 *
10 */ 12 */
11 13
12#include <asm/of_device.h> 14/* This is just here during the transition */
13 15#include <linux/of_platform.h>
14/*
15 * The of_platform_bus_type is a bus type used by drivers that do not
16 * attach to a macio or similar bus but still use OF probing
17 * mechanism
18 */
19extern struct bus_type of_platform_bus_type;
20
21/*
22 * An of_platform_driver driver is attached to a basic of_device on
23 * the "platform bus" (of_platform_bus_type)
24 */
25struct of_platform_driver
26{
27 char *name;
28 struct of_device_id *match_table;
29 struct module *owner;
30
31 int (*probe)(struct of_device* dev,
32 const struct of_device_id *match);
33 int (*remove)(struct of_device* dev);
34
35 int (*suspend)(struct of_device* dev, pm_message_t state);
36 int (*resume)(struct of_device* dev);
37 int (*shutdown)(struct of_device* dev);
38
39 struct device_driver driver;
40};
41#define to_of_platform_driver(drv) \
42 container_of(drv,struct of_platform_driver, driver)
43 16
44/* Platform drivers register/unregister */ 17/* Platform drivers register/unregister */
45extern int of_register_platform_driver(struct of_platform_driver *drv); 18extern int of_register_platform_driver(struct of_platform_driver *drv);
@@ -56,5 +29,6 @@ extern int of_platform_bus_probe(struct device_node *root,
56 struct of_device_id *matches, 29 struct of_device_id *matches,
57 struct device *parent); 30 struct device *parent);
58 31
59extern struct of_device *of_find_device_by_node(struct device_node *np);
60extern struct of_device *of_find_device_by_phandle(phandle ph); 32extern struct of_device *of_find_device_by_phandle(phandle ph);
33
34#endif /* _ASM_POWERPC_OF_PLATFORM_H */
diff --git a/include/asm-powerpc/prom.h b/include/asm-powerpc/prom.h
index 1632baa17dc6..6e391c9894ce 100644
--- a/include/asm-powerpc/prom.h
+++ b/include/asm-powerpc/prom.h
@@ -21,6 +21,13 @@
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <asm/atomic.h> 22#include <asm/atomic.h>
23 23
24#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
25#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
26
27#define of_compat_cmp(s1, s2, l) strncasecmp((s1), (s2), (l))
28#define of_prop_cmp(s1, s2) strcmp((s1), (s2))
29#define of_node_cmp(s1, s2) strcasecmp((s1), (s2))
30
24/* Definitions used by the flattened device tree */ 31/* Definitions used by the flattened device tree */
25#define OF_DT_HEADER 0xd00dfeed /* marker */ 32#define OF_DT_HEADER 0xd00dfeed /* marker */
26#define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */ 33#define OF_DT_BEGIN_NODE 0x1 /* Start of node, full name */
@@ -97,10 +104,6 @@ struct device_node {
97 104
98extern struct device_node *of_chosen; 105extern struct device_node *of_chosen;
99 106
100/* flag descriptions */
101#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
102#define OF_DETACHED 2 /* node has been detached from the device tree */
103
104static inline int of_node_check_flag(struct device_node *n, unsigned long flag) 107static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
105{ 108{
106 return test_bit(flag, &n->_flags); 109 return test_bit(flag, &n->_flags);
@@ -120,31 +123,7 @@ static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_e
120} 123}
121 124
122 125
123/* New style node lookup */
124extern struct device_node *of_find_node_by_name(struct device_node *from,
125 const char *name);
126#define for_each_node_by_name(dn, name) \
127 for (dn = of_find_node_by_name(NULL, name); dn; \
128 dn = of_find_node_by_name(dn, name))
129extern struct device_node *of_find_node_by_type(struct device_node *from,
130 const char *type);
131#define for_each_node_by_type(dn, type) \
132 for (dn = of_find_node_by_type(NULL, type); dn; \
133 dn = of_find_node_by_type(dn, type))
134extern struct device_node *of_find_compatible_node(struct device_node *from,
135 const char *type, const char *compat);
136#define for_each_compatible_node(dn, type, compatible) \
137 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
138 dn = of_find_compatible_node(dn, type, compatible))
139extern struct device_node *of_find_node_by_path(const char *path);
140extern struct device_node *of_find_node_by_phandle(phandle handle);
141extern struct device_node *of_find_all_nodes(struct device_node *prev); 126extern struct device_node *of_find_all_nodes(struct device_node *prev);
142extern struct device_node *of_get_parent(const struct device_node *node);
143extern struct device_node *of_get_next_child(const struct device_node *node,
144 struct device_node *prev);
145extern struct property *of_find_property(const struct device_node *np,
146 const char *name,
147 int *lenp);
148extern struct device_node *of_node_get(struct device_node *node); 127extern struct device_node *of_node_get(struct device_node *node);
149extern void of_node_put(struct device_node *node); 128extern void of_node_put(struct device_node *node);
150 129
@@ -166,17 +145,9 @@ extern void of_detach_node(const struct device_node *);
166extern void finish_device_tree(void); 145extern void finish_device_tree(void);
167extern void unflatten_device_tree(void); 146extern void unflatten_device_tree(void);
168extern void early_init_devtree(void *); 147extern void early_init_devtree(void *);
169extern int of_device_is_compatible(const struct device_node *device,
170 const char *);
171#define device_is_compatible(d, c) of_device_is_compatible((d), (c)) 148#define device_is_compatible(d, c) of_device_is_compatible((d), (c))
172extern int machine_is_compatible(const char *compat); 149extern int machine_is_compatible(const char *compat);
173extern const void *of_get_property(const struct device_node *node,
174 const char *name,
175 int *lenp);
176#define get_property(a, b, c) of_get_property((a), (b), (c))
177extern void print_properties(struct device_node *node); 150extern void print_properties(struct device_node *node);
178extern int of_n_addr_cells(struct device_node* np);
179extern int of_n_size_cells(struct device_node* np);
180extern int prom_n_intr_cells(struct device_node* np); 151extern int prom_n_intr_cells(struct device_node* np);
181extern void prom_get_irq_senses(unsigned char *senses, int off, int max); 152extern void prom_get_irq_senses(unsigned char *senses, int off, int max);
182extern int prom_add_property(struct device_node* np, struct property* prop); 153extern int prom_add_property(struct device_node* np, struct property* prop);
@@ -230,7 +201,6 @@ static inline unsigned long of_read_ulong(const u32 *cell, int size)
230 201
231/* Translate an OF address block into a CPU physical address 202/* Translate an OF address block into a CPU physical address
232 */ 203 */
233#define OF_BAD_ADDR ((u64)-1)
234extern u64 of_translate_address(struct device_node *np, const u32 *addr); 204extern u64 of_translate_address(struct device_node *np, const u32 *addr);
235 205
236/* Extract an address from a device, returns the region size and 206/* Extract an address from a device, returns the region size and
@@ -357,5 +327,11 @@ extern int of_irq_to_resource(struct device_node *dev, int index,
357 */ 327 */
358extern void __iomem *of_iomap(struct device_node *device, int index); 328extern void __iomem *of_iomap(struct device_node *device, int index);
359 329
330/*
331 * NB: This is here while we transition from using asm/prom.h
332 * to linux/of.h
333 */
334#include <linux/of.h>
335
360#endif /* __KERNEL__ */ 336#endif /* __KERNEL__ */
361#endif /* _POWERPC_PROM_H */ 337#endif /* _POWERPC_PROM_H */
diff --git a/include/asm-sparc/of_device.h b/include/asm-sparc/of_device.h
index 7cb00c1b09c6..e5f5aedc2293 100644
--- a/include/asm-sparc/of_device.h
+++ b/include/asm-sparc/of_device.h
@@ -3,13 +3,9 @@
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/of.h>
6#include <linux/mod_devicetable.h> 7#include <linux/mod_devicetable.h>
7#include <asm/openprom.h> 8#include <asm/openprom.h>
8#include <asm/prom.h>
9
10extern struct bus_type ebus_bus_type;
11extern struct bus_type sbus_bus_type;
12extern struct bus_type of_bus_type;
13 9
14/* 10/*
15 * The of_device is a kind of "base class" that is a superset of 11 * The of_device is a kind of "base class" that is a superset of
@@ -30,50 +26,13 @@ struct of_device
30 int portid; 26 int portid;
31 int clock_freq; 27 int clock_freq;
32}; 28};
33#define to_of_device(d) container_of(d, struct of_device, dev)
34 29
35extern void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name); 30extern void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name);
36extern void of_iounmap(struct resource *res, void __iomem *base, unsigned long size); 31extern void of_iounmap(struct resource *res, void __iomem *base, unsigned long size);
37 32
38extern struct of_device *of_find_device_by_node(struct device_node *); 33/* These are just here during the transition */
39 34#include <linux/of_device.h>
40extern const struct of_device_id *of_match_device( 35#include <linux/of_platform.h>
41 const struct of_device_id *matches, const struct of_device *dev);
42
43extern struct of_device *of_dev_get(struct of_device *dev);
44extern void of_dev_put(struct of_device *dev);
45
46/*
47 * An of_platform_driver driver is attached to a basic of_device on
48 * the ISA, EBUS, and SBUS busses on sparc64.
49 */
50struct of_platform_driver
51{
52 char *name;
53 struct of_device_id *match_table;
54 struct module *owner;
55
56 int (*probe)(struct of_device* dev, const struct of_device_id *match);
57 int (*remove)(struct of_device* dev);
58
59 int (*suspend)(struct of_device* dev, pm_message_t state);
60 int (*resume)(struct of_device* dev);
61 int (*shutdown)(struct of_device* dev);
62
63 struct device_driver driver;
64};
65#define to_of_platform_driver(drv) container_of(drv,struct of_platform_driver, driver)
66
67extern int of_register_driver(struct of_platform_driver *drv,
68 struct bus_type *bus);
69extern void of_unregister_driver(struct of_platform_driver *drv);
70extern int of_device_register(struct of_device *ofdev);
71extern void of_device_unregister(struct of_device *ofdev);
72extern struct of_device *of_platform_device_create(struct device_node *np,
73 const char *bus_id,
74 struct device *parent,
75 struct bus_type *bus);
76extern void of_release_dev(struct device *dev);
77 36
78#endif /* __KERNEL__ */ 37#endif /* __KERNEL__ */
79#endif /* _ASM_SPARC_OF_DEVICE_H */ 38#endif /* _ASM_SPARC_OF_DEVICE_H */
diff --git a/include/asm-sparc/of_platform.h b/include/asm-sparc/of_platform.h
new file mode 100644
index 000000000000..64a230064ef2
--- /dev/null
+++ b/include/asm-sparc/of_platform.h
@@ -0,0 +1,32 @@
1#ifndef _ASM_SPARC_OF_PLATFORM_H
2#define _ASM_SPARC_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h
7 * by Stephen Rothwell
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type ebus_bus_type;
20extern struct bus_type sbus_bus_type;
21extern struct bus_type of_platform_bus_type;
22#define of_bus_type of_platform_bus_type /* for compatibility */
23
24extern int of_register_driver(struct of_platform_driver *drv,
25 struct bus_type *bus);
26extern void of_unregister_driver(struct of_platform_driver *drv);
27extern struct of_device *of_platform_device_create(struct device_node *np,
28 const char *bus_id,
29 struct device *parent,
30 struct bus_type *bus);
31
32#endif /* _ASM_SPARC_OF_PLATFORM_H */
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h
index 9ea105ebe2ff..db9feb75bd86 100644
--- a/include/asm-sparc/prom.h
+++ b/include/asm-sparc/prom.h
@@ -2,7 +2,6 @@
2#define _SPARC_PROM_H 2#define _SPARC_PROM_H
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5
6/* 5/*
7 * Definitions for talking to the Open Firmware PROM on 6 * Definitions for talking to the Open Firmware PROM on
8 * Power Macintosh computers. 7 * Power Macintosh computers.
@@ -17,11 +16,17 @@
17 * as published by the Free Software Foundation; either version 16 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version. 17 * 2 of the License, or (at your option) any later version.
19 */ 18 */
20
21#include <linux/types.h> 19#include <linux/types.h>
22#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
23#include <asm/atomic.h> 21#include <asm/atomic.h>
24 22
23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
25
26#define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l))
27#define of_prop_cmp(s1, s2) strcasecmp((s1), (s2))
28#define of_node_cmp(s1, s2) strcmp((s1), (s2))
29
25typedef u32 phandle; 30typedef u32 phandle;
26typedef u32 ihandle; 31typedef u32 ihandle;
27 32
@@ -55,53 +60,30 @@ struct device_node {
55 unsigned int unique_id; 60 unsigned int unique_id;
56}; 61};
57 62
58/* flag descriptions */
59#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
60
61#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 63#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
62#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) 64#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
63 65
64#define OF_BAD_ADDR ((u64)-1)
65
66static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
67{
68 dn->pde = de;
69}
70
71extern struct device_node *of_find_node_by_name(struct device_node *from,
72 const char *name);
73#define for_each_node_by_name(dn, name) \
74 for (dn = of_find_node_by_name(NULL, name); dn; \
75 dn = of_find_node_by_name(dn, name))
76extern struct device_node *of_find_node_by_type(struct device_node *from,
77 const char *type);
78#define for_each_node_by_type(dn, type) \
79 for (dn = of_find_node_by_type(NULL, type); dn; \
80 dn = of_find_node_by_type(dn, type))
81extern struct device_node *of_find_compatible_node(struct device_node *from,
82 const char *type, const char *compat);
83extern struct device_node *of_find_node_by_path(const char *path);
84extern struct device_node *of_find_node_by_phandle(phandle handle);
85extern struct device_node *of_get_parent(const struct device_node *node);
86extern struct device_node *of_get_next_child(const struct device_node *node,
87 struct device_node *prev);
88extern struct property *of_find_property(const struct device_node *np,
89 const char *name,
90 int *lenp);
91extern int of_device_is_compatible(const struct device_node *device,
92 const char *);
93extern const void *of_get_property(const struct device_node *node,
94 const char *name,
95 int *lenp);
96#define get_property(node,name,lenp) of_get_property(node,name,lenp)
97extern int of_set_property(struct device_node *node, const char *name, void *val, int len); 66extern int of_set_property(struct device_node *node, const char *name, void *val, int len);
98extern int of_getintprop_default(struct device_node *np, 67extern int of_getintprop_default(struct device_node *np,
99 const char *name, 68 const char *name,
100 int def); 69 int def);
101extern int of_n_addr_cells(struct device_node *np);
102extern int of_n_size_cells(struct device_node *np);
103 70
104extern void prom_build_devicetree(void); 71extern void prom_build_devicetree(void);
105 72
73/* Dummy ref counting routines - to be implemented later */
74static inline struct device_node *of_node_get(struct device_node *node)
75{
76 return node;
77}
78static inline void of_node_put(struct device_node *node)
79{
80}
81
82/*
83 * NB: This is here while we transition from using asm/prom.h
84 * to linux/of.h
85 */
86#include <linux/of.h>
87
106#endif /* __KERNEL__ */ 88#endif /* __KERNEL__ */
107#endif /* _SPARC_PROM_H */ 89#endif /* _SPARC_PROM_H */
diff --git a/include/asm-sparc64/of_device.h b/include/asm-sparc64/of_device.h
index 60e9173c9acb..46d69b3223c5 100644
--- a/include/asm-sparc64/of_device.h
+++ b/include/asm-sparc64/of_device.h
@@ -3,14 +3,9 @@
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/of.h>
6#include <linux/mod_devicetable.h> 7#include <linux/mod_devicetable.h>
7#include <asm/openprom.h> 8#include <asm/openprom.h>
8#include <asm/prom.h>
9
10extern struct bus_type isa_bus_type;
11extern struct bus_type ebus_bus_type;
12extern struct bus_type sbus_bus_type;
13extern struct bus_type of_bus_type;
14 9
15/* 10/*
16 * The of_device is a kind of "base class" that is a superset of 11 * The of_device is a kind of "base class" that is a superset of
@@ -31,50 +26,13 @@ struct of_device
31 int portid; 26 int portid;
32 int clock_freq; 27 int clock_freq;
33}; 28};
34#define to_of_device(d) container_of(d, struct of_device, dev)
35 29
36extern void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name); 30extern void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name);
37extern void of_iounmap(struct resource *res, void __iomem *base, unsigned long size); 31extern void of_iounmap(struct resource *res, void __iomem *base, unsigned long size);
38 32
39extern struct of_device *of_find_device_by_node(struct device_node *); 33/* These are just here during the transition */
40 34#include <linux/of_device.h>
41extern const struct of_device_id *of_match_device( 35#include <linux/of_platform.h>
42 const struct of_device_id *matches, const struct of_device *dev);
43
44extern struct of_device *of_dev_get(struct of_device *dev);
45extern void of_dev_put(struct of_device *dev);
46
47/*
48 * An of_platform_driver driver is attached to a basic of_device on
49 * the ISA, EBUS, and SBUS busses on sparc64.
50 */
51struct of_platform_driver
52{
53 char *name;
54 struct of_device_id *match_table;
55 struct module *owner;
56
57 int (*probe)(struct of_device* dev, const struct of_device_id *match);
58 int (*remove)(struct of_device* dev);
59
60 int (*suspend)(struct of_device* dev, pm_message_t state);
61 int (*resume)(struct of_device* dev);
62 int (*shutdown)(struct of_device* dev);
63
64 struct device_driver driver;
65};
66#define to_of_platform_driver(drv) container_of(drv,struct of_platform_driver, driver)
67
68extern int of_register_driver(struct of_platform_driver *drv,
69 struct bus_type *bus);
70extern void of_unregister_driver(struct of_platform_driver *drv);
71extern int of_device_register(struct of_device *ofdev);
72extern void of_device_unregister(struct of_device *ofdev);
73extern struct of_device *of_platform_device_create(struct device_node *np,
74 const char *bus_id,
75 struct device *parent,
76 struct bus_type *bus);
77extern void of_release_dev(struct device *dev);
78 36
79#endif /* __KERNEL__ */ 37#endif /* __KERNEL__ */
80#endif /* _ASM_SPARC64_OF_DEVICE_H */ 38#endif /* _ASM_SPARC64_OF_DEVICE_H */
diff --git a/include/asm-sparc64/of_platform.h b/include/asm-sparc64/of_platform.h
new file mode 100644
index 000000000000..f7c1f17c7d52
--- /dev/null
+++ b/include/asm-sparc64/of_platform.h
@@ -0,0 +1,33 @@
1#ifndef _ASM_SPARC64_OF_PLATFORM_H
2#define _ASM_SPARC64_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 * Modified for Sparc by merging parts of asm-sparc/of_device.h
7 * by Stephen Rothwell
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16/* This is just here during the transition */
17#include <linux/of_platform.h>
18
19extern struct bus_type isa_bus_type;
20extern struct bus_type ebus_bus_type;
21extern struct bus_type sbus_bus_type;
22extern struct bus_type of_platform_bus_type;
23#define of_bus_type of_platform_bus_type /* for compatibility */
24
25extern int of_register_driver(struct of_platform_driver *drv,
26 struct bus_type *bus);
27extern void of_unregister_driver(struct of_platform_driver *drv);
28extern struct of_device *of_platform_device_create(struct device_node *np,
29 const char *bus_id,
30 struct device *parent,
31 struct bus_type *bus);
32
33#endif /* _ASM_SPARC64_OF_PLATFORM_H */
diff --git a/include/asm-sparc64/prom.h b/include/asm-sparc64/prom.h
index b4df3042add0..2b9e0d795faf 100644
--- a/include/asm-sparc64/prom.h
+++ b/include/asm-sparc64/prom.h
@@ -2,7 +2,6 @@
2#define _SPARC64_PROM_H 2#define _SPARC64_PROM_H
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5
6/* 5/*
7 * Definitions for talking to the Open Firmware PROM on 6 * Definitions for talking to the Open Firmware PROM on
8 * Power Macintosh computers. 7 * Power Macintosh computers.
@@ -17,11 +16,17 @@
17 * as published by the Free Software Foundation; either version 16 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version. 17 * 2 of the License, or (at your option) any later version.
19 */ 18 */
20
21#include <linux/types.h> 19#include <linux/types.h>
22#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
23#include <asm/atomic.h> 21#include <asm/atomic.h>
24 22
23#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 2
24#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
25
26#define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l))
27#define of_prop_cmp(s1, s2) strcasecmp((s1), (s2))
28#define of_node_cmp(s1, s2) strcmp((s1), (s2))
29
25typedef u32 phandle; 30typedef u32 phandle;
26typedef u32 ihandle; 31typedef u32 ihandle;
27 32
@@ -63,54 +68,31 @@ struct of_irq_controller {
63 void *data; 68 void *data;
64}; 69};
65 70
66/* flag descriptions */
67#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
68
69#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags) 71#define OF_IS_DYNAMIC(x) test_bit(OF_DYNAMIC, &x->_flags)
70#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags) 72#define OF_MARK_DYNAMIC(x) set_bit(OF_DYNAMIC, &x->_flags)
71 73
72#define OF_BAD_ADDR ((u64)-1)
73
74static inline void set_node_proc_entry(struct device_node *dn, struct proc_dir_entry *de)
75{
76 dn->pde = de;
77}
78
79extern struct device_node *of_find_node_by_name(struct device_node *from,
80 const char *name);
81#define for_each_node_by_name(dn, name) \
82 for (dn = of_find_node_by_name(NULL, name); dn; \
83 dn = of_find_node_by_name(dn, name))
84extern struct device_node *of_find_node_by_type(struct device_node *from,
85 const char *type);
86#define for_each_node_by_type(dn, type) \
87 for (dn = of_find_node_by_type(NULL, type); dn; \
88 dn = of_find_node_by_type(dn, type))
89extern struct device_node *of_find_compatible_node(struct device_node *from,
90 const char *type, const char *compat);
91extern struct device_node *of_find_node_by_path(const char *path);
92extern struct device_node *of_find_node_by_phandle(phandle handle);
93extern struct device_node *of_find_node_by_cpuid(int cpuid); 74extern struct device_node *of_find_node_by_cpuid(int cpuid);
94extern struct device_node *of_get_parent(const struct device_node *node);
95extern struct device_node *of_get_next_child(const struct device_node *node,
96 struct device_node *prev);
97extern struct property *of_find_property(const struct device_node *np,
98 const char *name,
99 int *lenp);
100extern int of_device_is_compatible(const struct device_node *device,
101 const char *);
102extern const void *of_get_property(const struct device_node *node,
103 const char *name,
104 int *lenp);
105#define get_property(node,name,lenp) of_get_property(node,name,lenp)
106extern int of_set_property(struct device_node *node, const char *name, void *val, int len); 75extern int of_set_property(struct device_node *node, const char *name, void *val, int len);
107extern int of_getintprop_default(struct device_node *np, 76extern int of_getintprop_default(struct device_node *np,
108 const char *name, 77 const char *name,
109 int def); 78 int def);
110extern int of_n_addr_cells(struct device_node *np);
111extern int of_n_size_cells(struct device_node *np);
112 79
113extern void prom_build_devicetree(void); 80extern void prom_build_devicetree(void);
114 81
82/* Dummy ref counting routines - to be implemented later */
83static inline struct device_node *of_node_get(struct device_node *node)
84{
85 return node;
86}
87static inline void of_node_put(struct device_node *node)
88{
89}
90
91/*
92 * NB: This is here while we transition from using asm/prom.h
93 * to linux/of.h
94 */
95#include <linux/of.h>
96
115#endif /* __KERNEL__ */ 97#endif /* __KERNEL__ */
116#endif /* _SPARC64_PROM_H */ 98#endif /* _SPARC64_PROM_H */
diff --git a/include/linux/of.h b/include/linux/of.h
new file mode 100644
index 000000000000..47734ffd9745
--- /dev/null
+++ b/include/linux/of.h
@@ -0,0 +1,61 @@
1#ifndef _LINUX_OF_H
2#define _LINUX_OF_H
3/*
4 * Definitions for talking to the Open Firmware PROM on
5 * Power Macintosh and other computers.
6 *
7 * Copyright (C) 1996-2005 Paul Mackerras.
8 *
9 * Updates for PPC64 by Peter Bergner & David Engebretsen, IBM Corp.
10 * Updates for SPARC64 by David S. Miller
11 * Derived from PowerPC and Sparc prom.h files by Stephen Rothwell, IBM Corp.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 */
18#include <linux/types.h>
19
20#include <asm/bitops.h>
21#include <asm/prom.h>
22
23/* flag descriptions */
24#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */
25#define OF_DETACHED 2 /* node has been detached from the device tree */
26
27#define OF_BAD_ADDR ((u64)-1)
28
29extern struct device_node *of_find_node_by_name(struct device_node *from,
30 const char *name);
31#define for_each_node_by_name(dn, name) \
32 for (dn = of_find_node_by_name(NULL, name); dn; \
33 dn = of_find_node_by_name(dn, name))
34extern struct device_node *of_find_node_by_type(struct device_node *from,
35 const char *type);
36#define for_each_node_by_type(dn, type) \
37 for (dn = of_find_node_by_type(NULL, type); dn; \
38 dn = of_find_node_by_type(dn, type))
39extern struct device_node *of_find_compatible_node(struct device_node *from,
40 const char *type, const char *compat);
41#define for_each_compatible_node(dn, type, compatible) \
42 for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
43 dn = of_find_compatible_node(dn, type, compatible))
44extern struct device_node *of_find_node_by_path(const char *path);
45extern struct device_node *of_find_node_by_phandle(phandle handle);
46extern struct device_node *of_get_parent(const struct device_node *node);
47extern struct device_node *of_get_next_child(const struct device_node *node,
48 struct device_node *prev);
49extern struct property *of_find_property(const struct device_node *np,
50 const char *name,
51 int *lenp);
52extern int of_device_is_compatible(const struct device_node *device,
53 const char *);
54extern const void *of_get_property(const struct device_node *node,
55 const char *name,
56 int *lenp);
57#define get_property(a, b, c) of_get_property((a), (b), (c))
58extern int of_n_addr_cells(struct device_node *np);
59extern int of_n_size_cells(struct device_node *np);
60
61#endif /* _LINUX_OF_H */
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
new file mode 100644
index 000000000000..91bf84b9d144
--- /dev/null
+++ b/include/linux/of_device.h
@@ -0,0 +1,26 @@
1#ifndef _LINUX_OF_DEVICE_H
2#define _LINUX_OF_DEVICE_H
3#ifdef __KERNEL__
4
5#include <linux/device.h>
6#include <linux/of.h>
7#include <linux/mod_devicetable.h>
8
9#include <asm/of_device.h>
10
11#define to_of_device(d) container_of(d, struct of_device, dev)
12
13extern const struct of_device_id *of_match_node(
14 const struct of_device_id *matches, const struct device_node *node);
15extern const struct of_device_id *of_match_device(
16 const struct of_device_id *matches, const struct of_device *dev);
17
18extern struct of_device *of_dev_get(struct of_device *dev);
19extern void of_dev_put(struct of_device *dev);
20
21extern int of_device_register(struct of_device *ofdev);
22extern void of_device_unregister(struct of_device *ofdev);
23extern void of_release_dev(struct device *dev);
24
25#endif /* __KERNEL__ */
26#endif /* _LINUX_OF_DEVICE_H */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
new file mode 100644
index 000000000000..5fd44e63fb26
--- /dev/null
+++ b/include/linux/of_platform.h
@@ -0,0 +1,57 @@
1#ifndef _LINUX_OF_PLATFORM_H
2#define _LINUX_OF_PLATFORM_H
3/*
4 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
5 * <benh@kernel.crashing.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/device.h>
16#include <linux/mod_devicetable.h>
17#include <linux/pm.h>
18#include <linux/of_device.h>
19
20/*
21 * The of_platform_bus_type is a bus type used by drivers that do not
22 * attach to a macio or similar bus but still use OF probing
23 * mechanism
24 */
25extern struct bus_type of_platform_bus_type;
26
27/*
28 * An of_platform_driver driver is attached to a basic of_device on
29 * the "platform bus" (of_platform_bus_type) (or ISA, EBUS and SBUS
30 * busses on sparc).
31 */
32struct of_platform_driver
33{
34 char *name;
35 struct of_device_id *match_table;
36 struct module *owner;
37
38 int (*probe)(struct of_device* dev,
39 const struct of_device_id *match);
40 int (*remove)(struct of_device* dev);
41
42 int (*suspend)(struct of_device* dev, pm_message_t state);
43 int (*resume)(struct of_device* dev);
44 int (*shutdown)(struct of_device* dev);
45
46 struct device_driver driver;
47};
48#define to_of_platform_driver(drv) \
49 container_of(drv,struct of_platform_driver, driver)
50
51#include <asm/of_platform.h>
52
53extern struct of_device *of_find_device_by_node(struct device_node *np);
54
55extern int of_bus_type_init(struct bus_type *bus, const char *name);
56
57#endif /* _LINUX_OF_PLATFORM_H */