aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel
diff options
context:
space:
mode:
authorDavid S. Miller <davem@sunset.davemloft.net>2006-06-23 04:44:10 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-06-24 02:15:43 -0400
commita2bd4fd17926d715a470fbe0ebe05128ba410984 (patch)
tree3e39a2f6aaf3a628b955067ef3668cae3456de03 /arch/sparc64/kernel
parent8cd24ed4f8031636fb5dacb04adee9e02556ecd5 (diff)
[SPARC64]: Add of_device layer and make ebus/isa use it.
Sparcspkr and power drivers are converted, to make sure it works. Eventually the SBUS device layer will use this as a sub-class. I really cannot cut loose on that bit until sparc32 is given the same infrastructure. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc64/kernel')
-rw-r--r--arch/sparc64/kernel/Makefile2
-rw-r--r--arch/sparc64/kernel/ebus.c21
-rw-r--r--arch/sparc64/kernel/isa.c37
-rw-r--r--arch/sparc64/kernel/of_device.c279
-rw-r--r--arch/sparc64/kernel/power.c109
5 files changed, 387 insertions, 61 deletions
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index 7f00189ed294..86c9fe3f3e4a 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -12,7 +12,7 @@ obj-y := process.o setup.o cpu.o idprom.o \
12 irq.o ptrace.o time.o sys_sparc.o signal.o \ 12 irq.o ptrace.o time.o sys_sparc.o signal.o \
13 unaligned.o central.o pci.o starfire.o semaphore.o \ 13 unaligned.o central.o pci.o starfire.o semaphore.o \
14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \ 14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \
15 visemul.o prom.o 15 visemul.o prom.o of_device.o
16 16
17obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \ 17obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \
18 pci_psycho.o pci_sabre.o pci_schizo.o \ 18 pci_psycho.o pci_sabre.o pci_schizo.o \
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index 33d79e10c653..b390a2f3a15e 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -475,6 +475,16 @@ probe_interrupts:
475 } 475 }
476 } 476 }
477 477
478 dev->ofdev.node = dp;
479 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
480 dev->ofdev.dev.bus = &ebus_bus_type;
481 strcpy(dev->ofdev.dev.bus_id, dp->path_component_name);
482
483 /* Register with core */
484 if (of_device_register(&dev->ofdev) != 0)
485 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
486 dev->ofdev.dev.bus_id);
487
478 dp = dp->child; 488 dp = dp->child;
479 if (dp) { 489 if (dp) {
480 printk(" ->"); 490 printk(" ->");
@@ -570,6 +580,17 @@ void __init ebus_init(void)
570 ebus->self = pdev; 580 ebus->self = pdev;
571 ebus->parent = pbm = cookie->pbm; 581 ebus->parent = pbm = cookie->pbm;
572 582
583 ebus->ofdev.node = dp;
584 ebus->ofdev.dev.parent = &pdev->dev;
585 ebus->ofdev.dev.bus = &ebus_bus_type;
586 strcpy(ebus->ofdev.dev.bus_id, dp->path_component_name);
587
588 /* Register with core */
589 if (of_device_register(&ebus->ofdev) != 0)
590 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
591 ebus->ofdev.dev.bus_id);
592
593
573 child = dp->child; 594 child = dp->child;
574 if (!child) 595 if (!child)
575 goto next_ebus; 596 goto next_ebus;
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index 2693f2de549c..6f16dee280a8 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -195,12 +195,25 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
195 195
196 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL); 196 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
197 if (!isa_dev) { 197 if (!isa_dev) {
198 fatal_err("cannot allocate isa_dev"); 198 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
199 prom_halt(); 199 return;
200 } 200 }
201 201
202 memset(isa_dev, 0, sizeof(*isa_dev)); 202 memset(isa_dev, 0, sizeof(*isa_dev));
203 203
204 isa_dev->ofdev.node = dp;
205 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
206 isa_dev->ofdev.dev.bus = &isa_bus_type;
207 strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
208
209 /* Register with core */
210 if (of_device_register(&isa_dev->ofdev) != 0) {
211 printk(KERN_DEBUG "isa: device registration error for %s!\n",
212 isa_dev->ofdev.dev.bus_id);
213 kfree(isa_dev);
214 goto next_sibling;
215 }
216
204 /* Link it in. */ 217 /* Link it in. */
205 isa_dev->next = NULL; 218 isa_dev->next = NULL;
206 if (isa_br->devices == NULL) { 219 if (isa_br->devices == NULL) {
@@ -226,6 +239,7 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
226 239
227 printk("]"); 240 printk("]");
228 241
242 next_sibling:
229 dp = dp->sibling; 243 dp = dp->sibling;
230 } 244 }
231} 245}
@@ -244,6 +258,7 @@ void __init isa_init(void)
244 struct pcidev_cookie *pdev_cookie; 258 struct pcidev_cookie *pdev_cookie;
245 struct pci_pbm_info *pbm; 259 struct pci_pbm_info *pbm;
246 struct sparc_isa_bridge *isa_br; 260 struct sparc_isa_bridge *isa_br;
261 struct device_node *dp;
247 262
248 pdev_cookie = pdev->sysdata; 263 pdev_cookie = pdev->sysdata;
249 if (!pdev_cookie) { 264 if (!pdev_cookie) {
@@ -252,15 +267,29 @@ void __init isa_init(void)
252 continue; 267 continue;
253 } 268 }
254 pbm = pdev_cookie->pbm; 269 pbm = pdev_cookie->pbm;
270 dp = pdev_cookie->prom_node;
255 271
256 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL); 272 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
257 if (!isa_br) { 273 if (!isa_br) {
258 fatal_err("cannot allocate sparc_isa_bridge"); 274 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
259 prom_halt(); 275 return;
260 } 276 }
261 277
262 memset(isa_br, 0, sizeof(*isa_br)); 278 memset(isa_br, 0, sizeof(*isa_br));
263 279
280 isa_br->ofdev.node = dp;
281 isa_br->ofdev.dev.parent = &pdev->dev;
282 isa_br->ofdev.dev.bus = &isa_bus_type;
283 strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
284
285 /* Register with core */
286 if (of_device_register(&isa_br->ofdev) != 0) {
287 printk(KERN_DEBUG "isa: device registration error for %s!\n",
288 isa_br->ofdev.dev.bus_id);
289 kfree(isa_br);
290 return;
291 }
292
264 /* Link it in. */ 293 /* Link it in. */
265 isa_br->next = isa_chain; 294 isa_br->next = isa_chain;
266 isa_chain = isa_br; 295 isa_chain = isa_br;
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
new file mode 100644
index 000000000000..566aa343aa62
--- /dev/null
+++ b/arch/sparc64/kernel/of_device.c
@@ -0,0 +1,279 @@
1#include <linux/config.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
4#include <linux/init.h>
5#include <linux/module.h>
6#include <linux/mod_devicetable.h>
7#include <linux/slab.h>
8
9#include <asm/errno.h>
10#include <asm/of_device.h>
11
12/**
13 * of_match_device - Tell if an of_device structure has a matching
14 * of_match structure
15 * @ids: array of of device match structures to search in
16 * @dev: the of device structure to match against
17 *
18 * Used by a driver to check whether an of_device present in the
19 * system is in its list of supported devices.
20 */
21const struct of_device_id *of_match_device(const struct of_device_id *matches,
22 const struct of_device *dev)
23{
24 if (!dev->node)
25 return NULL;
26 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
27 int match = 1;
28 if (matches->name[0])
29 match &= dev->node->name
30 && !strcmp(matches->name, dev->node->name);
31 if (matches->type[0])
32 match &= dev->node->type
33 && !strcmp(matches->type, dev->node->type);
34 if (matches->compatible[0])
35 match &= of_device_is_compatible(dev->node,
36 matches->compatible);
37 if (match)
38 return matches;
39 matches++;
40 }
41 return NULL;
42}
43
44static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
45{
46 struct of_device * of_dev = to_of_device(dev);
47 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
48 const struct of_device_id * matches = of_drv->match_table;
49
50 if (!matches)
51 return 0;
52
53 return of_match_device(matches, of_dev) != NULL;
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
75
76static int of_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_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_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_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
132#ifdef CONFIG_PCI
133struct bus_type isa_bus_type = {
134 .name = "isa",
135 .match = of_platform_bus_match,
136 .probe = of_device_probe,
137 .remove = of_device_remove,
138 .suspend = of_device_suspend,
139 .resume = of_device_resume,
140};
141
142struct bus_type ebus_bus_type = {
143 .name = "ebus",
144 .match = of_platform_bus_match,
145 .probe = of_device_probe,
146 .remove = of_device_remove,
147 .suspend = of_device_suspend,
148 .resume = of_device_resume,
149};
150#endif
151
152#ifdef CONFIG_SBUS
153struct bus_type sbus_bus_type = {
154 .name = "sbus",
155 .match = of_platform_bus_match,
156 .probe = of_device_probe,
157 .remove = of_device_remove,
158 .suspend = of_device_suspend,
159 .resume = of_device_resume,
160};
161#endif
162
163static int __init of_bus_driver_init(void)
164{
165 int err = 0;
166
167#ifdef CONFIG_PCI
168 if (!err)
169 err = bus_register(&isa_bus_type);
170 if (!err)
171 err = bus_register(&ebus_bus_type);
172#endif
173#ifdef CONFIG_SBUS
174 if (!err)
175 err = bus_register(&sbus_bus_type);
176#endif
177 return 0;
178}
179
180postcore_initcall(of_bus_driver_init);
181
182int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
183{
184 /* initialize common driver fields */
185 drv->driver.name = drv->name;
186 drv->driver.bus = bus;
187
188 /* register with core */
189 return driver_register(&drv->driver);
190}
191
192void of_unregister_driver(struct of_platform_driver *drv)
193{
194 driver_unregister(&drv->driver);
195}
196
197
198static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
199{
200 struct of_device *ofdev;
201
202 ofdev = to_of_device(dev);
203 return sprintf(buf, "%s", ofdev->node->full_name);
204}
205
206static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
207
208/**
209 * of_release_dev - free an of device structure when all users of it are finished.
210 * @dev: device that's been disconnected
211 *
212 * Will be called only by the device core when all users of this of device are
213 * done.
214 */
215void of_release_dev(struct device *dev)
216{
217 struct of_device *ofdev;
218
219 ofdev = to_of_device(dev);
220
221 kfree(ofdev);
222}
223
224int of_device_register(struct of_device *ofdev)
225{
226 int rc;
227
228 BUG_ON(ofdev->node == NULL);
229
230 rc = device_register(&ofdev->dev);
231 if (rc)
232 return rc;
233
234 device_create_file(&ofdev->dev, &dev_attr_devspec);
235
236 return 0;
237}
238
239void of_device_unregister(struct of_device *ofdev)
240{
241 device_remove_file(&ofdev->dev, &dev_attr_devspec);
242 device_unregister(&ofdev->dev);
243}
244
245struct of_device* of_platform_device_create(struct device_node *np,
246 const char *bus_id,
247 struct device *parent,
248 struct bus_type *bus)
249{
250 struct of_device *dev;
251
252 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
253 if (!dev)
254 return NULL;
255 memset(dev, 0, sizeof(*dev));
256
257 dev->dev.parent = parent;
258 dev->dev.bus = bus;
259 dev->dev.release = of_release_dev;
260
261 strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
262
263 if (of_device_register(dev) != 0) {
264 kfree(dev);
265 return NULL;
266 }
267
268 return dev;
269}
270
271EXPORT_SYMBOL(of_match_device);
272EXPORT_SYMBOL(of_register_driver);
273EXPORT_SYMBOL(of_unregister_driver);
274EXPORT_SYMBOL(of_device_register);
275EXPORT_SYMBOL(of_device_unregister);
276EXPORT_SYMBOL(of_dev_get);
277EXPORT_SYMBOL(of_dev_put);
278EXPORT_SYMBOL(of_platform_device_create);
279EXPORT_SYMBOL(of_release_dev);
diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c
index 75159a7843f1..9496c7734014 100644
--- a/arch/sparc64/kernel/power.c
+++ b/arch/sparc64/kernel/power.c
@@ -115,66 +115,15 @@ static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
115 return 1; 115 return 1;
116} 116}
117 117
118static int __init power_probe_ebus(struct resource **resp, unsigned int *irq_p, struct device_node **prom_node_p) 118static void __devinit power_probe_common(struct of_device *dev, struct resource *res, unsigned int irq)
119{ 119{
120 struct linux_ebus *ebus;
121 struct linux_ebus_device *edev;
122
123 for_each_ebus(ebus) {
124 for_each_ebusdev(edev, ebus) {
125 if (!strcmp(edev->prom_node->name, "power")) {
126 *resp = &edev->resource[0];
127 *irq_p = edev->irqs[0];
128 *prom_node_p = edev->prom_node;
129 return 0;
130 }
131 }
132 }
133 return -ENODEV;
134}
135
136static int __init power_probe_isa(struct resource **resp, unsigned int *irq_p, struct device_node **prom_node_p)
137{
138 struct sparc_isa_bridge *isa_bus;
139 struct sparc_isa_device *isa_dev;
140
141 for_each_isa(isa_bus) {
142 for_each_isadev(isa_dev, isa_bus) {
143 if (!strcmp(isa_dev->prom_node->name, "power")) {
144 *resp = &isa_dev->resource;
145 *irq_p = isa_dev->irq;
146 *prom_node_p = isa_dev->prom_node;
147 return 0;
148 }
149 }
150 }
151 return -ENODEV;
152}
153
154void __init power_init(void)
155{
156 struct resource *res = NULL;
157 unsigned int irq;
158 struct device_node *dp;
159 static int invoked;
160
161 if (invoked)
162 return;
163 invoked = 1;
164
165 if (!power_probe_ebus(&res, &irq, &dp))
166 goto found;
167
168 if (!power_probe_isa(&res, &irq, &dp))
169 goto found;
170
171 return;
172
173found:
174 power_reg = ioremap(res->start, 0x4); 120 power_reg = ioremap(res->start, 0x4);
121
175 printk("power: Control reg at %p ... ", power_reg); 122 printk("power: Control reg at %p ... ", power_reg);
123
176 poweroff_method = machine_halt; /* able to use the standard halt */ 124 poweroff_method = machine_halt; /* able to use the standard halt */
177 if (has_button_interrupt(irq, dp)) { 125
126 if (has_button_interrupt(irq, dev->node)) {
178 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) { 127 if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
179 printk("Failed to start power daemon.\n"); 128 printk("Failed to start power daemon.\n");
180 return; 129 return;
@@ -188,4 +137,52 @@ found:
188 printk("not using powerd.\n"); 137 printk("not using powerd.\n");
189 } 138 }
190} 139}
140
141static struct of_device_id power_match[] = {
142 {
143 .name = "power",
144 },
145 {},
146};
147
148static int __devinit ebus_power_probe(struct of_device *dev, const struct of_device_id *match)
149{
150 struct linux_ebus_device *edev = to_ebus_device(&dev->dev);
151 struct resource *res = &edev->resource[0];
152 unsigned int irq = edev->irqs[0];
153
154 power_probe_common(dev, res,irq);
155
156 return 0;
157}
158
159static struct of_platform_driver ebus_power_driver = {
160 .name = "power",
161 .match_table = power_match,
162 .probe = ebus_power_probe,
163};
164
165static int __devinit isa_power_probe(struct of_device *dev, const struct of_device_id *match)
166{
167 struct sparc_isa_device *idev = to_isa_device(&dev->dev);
168 struct resource *res = &idev->resource;
169 unsigned int irq = idev->irq;
170
171 power_probe_common(dev, res,irq);
172
173 return 0;
174}
175
176static struct of_platform_driver isa_power_driver = {
177 .name = "power",
178 .match_table = power_match,
179 .probe = isa_power_probe,
180};
181
182void __init power_init(void)
183{
184 of_register_driver(&ebus_power_driver, &ebus_bus_type);
185 of_register_driver(&isa_power_driver, &isa_bus_type);
186 return;
187}
191#endif /* CONFIG_PCI */ 188#endif /* CONFIG_PCI */