aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 12:18:08 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-07-20 12:18:08 -0400
commit2cb7e714229681408e323852bed939989faf6991 (patch)
tree552b78fa5830a0337594f9fbab5f1dc0306e93cd /arch/sparc
parentd638d4990bfb99998420e78e8fd4607bca5cf8d0 (diff)
parent3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons
* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/sfr/ofcons: Create drivers/of/platform.c Create linux/of_platorm.h [SPARC/64] Rename some functions like PowerPC Begin consolidation of of_device.h Begin to consolidate of_device.c Consolidate of_find_node_by routines Consolidate of_get_next_child Consolidate of_get_parent Consolidate of_find_property Consolidate of_device_is_compatible Start split out of common open firmware code Split out common parts of prom.h
Diffstat (limited to 'arch/sparc')
-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
4 files changed, 19 insertions, 381 deletions
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