aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64')
-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
6 files changed, 25 insertions, 395 deletions
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