Commit | Line | Data |
---|---|---|
d7a30103 HS |
1 | /* |
2 | * IBM PowerPC IBM eBus Infrastructure Support. | |
3 | * | |
4 | * Copyright (c) 2005 IBM Corporation | |
6bccf755 | 5 | * Joachim Fenkes <fenkes@de.ibm.com> |
d7a30103 | 6 | * Heiko J Schick <schickhj@de.ibm.com> |
a8308800 | 7 | * |
d7a30103 HS |
8 | * All rights reserved. |
9 | * | |
a8308800 JF |
10 | * This source code is distributed under a dual license of GPL v2.0 and OpenIB |
11 | * BSD. | |
d7a30103 HS |
12 | * |
13 | * OpenIB BSD License | |
14 | * | |
a8308800 JF |
15 | * Redistribution and use in source and binary forms, with or without |
16 | * modification, are permitted provided that the following conditions are met: | |
d7a30103 | 17 | * |
a8308800 JF |
18 | * Redistributions of source code must retain the above copyright notice, this |
19 | * list of conditions and the following disclaimer. | |
d7a30103 | 20 | * |
a8308800 JF |
21 | * Redistributions in binary form must reproduce the above copyright notice, |
22 | * this list of conditions and the following disclaimer in the documentation | |
d7a30103 | 23 | * and/or other materials |
a8308800 | 24 | * provided with the distribution. |
d7a30103 | 25 | * |
a8308800 JF |
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
30 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
d7a30103 HS |
32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
33 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | |
a8308800 JF |
34 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
d7a30103 HS |
36 | * POSSIBILITY OF SUCH DAMAGE. |
37 | */ | |
38 | ||
39 | #include <linux/init.h> | |
40 | #include <linux/console.h> | |
41 | #include <linux/kobject.h> | |
42 | #include <linux/dma-mapping.h> | |
43 | #include <linux/interrupt.h> | |
283029d1 | 44 | #include <linux/of.h> |
5a0e3ad6 | 45 | #include <linux/slab.h> |
a988c0a6 | 46 | #include <linux/of_platform.h> |
d7a30103 HS |
47 | #include <asm/ibmebus.h> |
48 | #include <asm/abs_addr.h> | |
49 | ||
6bccf755 | 50 | static struct device ibmebus_bus_device = { /* fake "parent" device */ |
aab0d375 | 51 | .init_name = "ibmebus", |
d7a30103 HS |
52 | }; |
53 | ||
6bccf755 JF |
54 | struct bus_type ibmebus_bus_type; |
55 | ||
55347cc9 | 56 | /* These devices will automatically be added to the bus during init */ |
1b17adf1 | 57 | static struct of_device_id __initdata ibmebus_matches[] = { |
55347cc9 JF |
58 | { .compatible = "IBM,lhca" }, |
59 | { .compatible = "IBM,lhea" }, | |
60 | {}, | |
61 | }; | |
62 | ||
d7a30103 HS |
63 | static void *ibmebus_alloc_coherent(struct device *dev, |
64 | size_t size, | |
65 | dma_addr_t *dma_handle, | |
66 | gfp_t flag) | |
67 | { | |
68 | void *mem; | |
a8308800 | 69 | |
d7a30103 HS |
70 | mem = kmalloc(size, flag); |
71 | *dma_handle = (dma_addr_t)mem; | |
72 | ||
73 | return mem; | |
74 | } | |
75 | ||
76 | static void ibmebus_free_coherent(struct device *dev, | |
a8308800 | 77 | size_t size, void *vaddr, |
d7a30103 HS |
78 | dma_addr_t dma_handle) |
79 | { | |
80 | kfree(vaddr); | |
81 | } | |
82 | ||
f9226d57 MN |
83 | static dma_addr_t ibmebus_map_page(struct device *dev, |
84 | struct page *page, | |
85 | unsigned long offset, | |
86 | size_t size, | |
87 | enum dma_data_direction direction, | |
88 | struct dma_attrs *attrs) | |
d7a30103 | 89 | { |
f9226d57 | 90 | return (dma_addr_t)(page_address(page) + offset); |
d7a30103 HS |
91 | } |
92 | ||
f9226d57 MN |
93 | static void ibmebus_unmap_page(struct device *dev, |
94 | dma_addr_t dma_addr, | |
95 | size_t size, | |
96 | enum dma_data_direction direction, | |
97 | struct dma_attrs *attrs) | |
d7a30103 HS |
98 | { |
99 | return; | |
100 | } | |
101 | ||
102 | static int ibmebus_map_sg(struct device *dev, | |
78bdc310 | 103 | struct scatterlist *sgl, |
3affedc4 MN |
104 | int nents, enum dma_data_direction direction, |
105 | struct dma_attrs *attrs) | |
d7a30103 | 106 | { |
78bdc310 | 107 | struct scatterlist *sg; |
d7a30103 | 108 | int i; |
a8308800 | 109 | |
78bdc310 | 110 | for_each_sg(sgl, sg, nents, i) { |
58b053e4 | 111 | sg->dma_address = (dma_addr_t) sg_virt(sg); |
78bdc310 | 112 | sg->dma_length = sg->length; |
d7a30103 | 113 | } |
a8308800 | 114 | |
d7a30103 HS |
115 | return nents; |
116 | } | |
117 | ||
118 | static void ibmebus_unmap_sg(struct device *dev, | |
119 | struct scatterlist *sg, | |
3affedc4 MN |
120 | int nents, enum dma_data_direction direction, |
121 | struct dma_attrs *attrs) | |
d7a30103 HS |
122 | { |
123 | return; | |
124 | } | |
125 | ||
126 | static int ibmebus_dma_supported(struct device *dev, u64 mask) | |
127 | { | |
128 | return 1; | |
129 | } | |
130 | ||
45223c54 | 131 | static struct dma_map_ops ibmebus_dma_ops = { |
d7a30103 HS |
132 | .alloc_coherent = ibmebus_alloc_coherent, |
133 | .free_coherent = ibmebus_free_coherent, | |
d7a30103 HS |
134 | .map_sg = ibmebus_map_sg, |
135 | .unmap_sg = ibmebus_unmap_sg, | |
136 | .dma_supported = ibmebus_dma_supported, | |
f9226d57 MN |
137 | .map_page = ibmebus_map_page, |
138 | .unmap_page = ibmebus_unmap_page, | |
d7a30103 HS |
139 | }; |
140 | ||
55347cc9 JF |
141 | static int ibmebus_match_path(struct device *dev, void *data) |
142 | { | |
a454dc50 | 143 | struct device_node *dn = to_platform_device(dev)->dev.of_node; |
55347cc9 JF |
144 | return (dn->full_name && |
145 | (strcasecmp((char *)data, dn->full_name) == 0)); | |
146 | } | |
147 | ||
148 | static int ibmebus_match_node(struct device *dev, void *data) | |
149 | { | |
a454dc50 | 150 | return to_platform_device(dev)->dev.of_node == data; |
55347cc9 JF |
151 | } |
152 | ||
153 | static int ibmebus_create_device(struct device_node *dn) | |
154 | { | |
a454dc50 | 155 | struct platform_device *dev; |
55347cc9 JF |
156 | int ret; |
157 | ||
158 | dev = of_device_alloc(dn, NULL, &ibmebus_bus_device); | |
159 | if (!dev) | |
160 | return -ENOMEM; | |
161 | ||
162 | dev->dev.bus = &ibmebus_bus_type; | |
163 | dev->dev.archdata.dma_ops = &ibmebus_dma_ops; | |
164 | ||
7096d042 GL |
165 | ret = of_device_add(dev); |
166 | if (ret) | |
167 | platform_device_put(dev); | |
168 | return ret; | |
55347cc9 JF |
169 | } |
170 | ||
171 | static int ibmebus_create_devices(const struct of_device_id *matches) | |
172 | { | |
173 | struct device_node *root, *child; | |
174 | int ret = 0; | |
175 | ||
176 | root = of_find_node_by_path("/"); | |
177 | ||
85e99b9f | 178 | for_each_child_of_node(root, child) { |
55347cc9 JF |
179 | if (!of_match_node(matches, child)) |
180 | continue; | |
181 | ||
182 | if (bus_find_device(&ibmebus_bus_type, NULL, child, | |
183 | ibmebus_match_node)) | |
184 | continue; | |
185 | ||
186 | ret = ibmebus_create_device(child); | |
187 | if (ret) { | |
188 | printk(KERN_ERR "%s: failed to create device (%i)", | |
e48b1b45 | 189 | __func__, ret); |
55347cc9 JF |
190 | of_node_put(child); |
191 | break; | |
192 | } | |
193 | } | |
194 | ||
195 | of_node_put(root); | |
196 | return ret; | |
197 | } | |
198 | ||
6b08f3ae | 199 | int ibmebus_register_driver(struct of_platform_driver *drv) |
d7a30103 | 200 | { |
6b08f3ae | 201 | /* If the driver uses devices that ibmebus doesn't know, add them */ |
597b9d1e | 202 | ibmebus_create_devices(drv->driver.of_match_table); |
6b08f3ae | 203 | |
710ac54b GL |
204 | drv->driver.bus = &ibmebus_bus_type; |
205 | return driver_register(&drv->driver); | |
d7a30103 HS |
206 | } |
207 | EXPORT_SYMBOL(ibmebus_register_driver); | |
208 | ||
6b08f3ae | 209 | void ibmebus_unregister_driver(struct of_platform_driver *drv) |
a8308800 | 210 | { |
710ac54b | 211 | driver_unregister(&drv->driver); |
d7a30103 HS |
212 | } |
213 | EXPORT_SYMBOL(ibmebus_unregister_driver); | |
214 | ||
6b08f3ae JF |
215 | int ibmebus_request_irq(u32 ist, irq_handler_t handler, |
216 | unsigned long irq_flags, const char *devname, | |
d7a30103 HS |
217 | void *dev_id) |
218 | { | |
6e99e458 | 219 | unsigned int irq = irq_create_mapping(NULL, ist); |
a8308800 | 220 | |
d7a30103 HS |
221 | if (irq == NO_IRQ) |
222 | return -EINVAL; | |
a8308800 | 223 | |
6b08f3ae | 224 | return request_irq(irq, handler, irq_flags, devname, dev_id); |
d7a30103 HS |
225 | } |
226 | EXPORT_SYMBOL(ibmebus_request_irq); | |
227 | ||
6b08f3ae | 228 | void ibmebus_free_irq(u32 ist, void *dev_id) |
d7a30103 | 229 | { |
0ebfff14 | 230 | unsigned int irq = irq_find_mapping(NULL, ist); |
a8308800 | 231 | |
d7a30103 | 232 | free_irq(irq, dev_id); |
6358d6cb | 233 | irq_dispose_mapping(irq); |
d7a30103 HS |
234 | } |
235 | EXPORT_SYMBOL(ibmebus_free_irq); | |
236 | ||
0727702a JF |
237 | static char *ibmebus_chomp(const char *in, size_t count) |
238 | { | |
61a564fd JJ |
239 | char *out = kmalloc(count + 1, GFP_KERNEL); |
240 | ||
0727702a JF |
241 | if (!out) |
242 | return NULL; | |
243 | ||
244 | memcpy(out, in, count); | |
245 | out[count] = '\0'; | |
246 | if (out[count - 1] == '\n') | |
247 | out[count - 1] = '\0'; | |
248 | ||
249 | return out; | |
6bccf755 JF |
250 | } |
251 | ||
252 | static ssize_t ibmebus_store_probe(struct bus_type *bus, | |
253 | const char *buf, size_t count) | |
254 | { | |
255 | struct device_node *dn = NULL; | |
0727702a | 256 | char *path; |
55347cc9 | 257 | ssize_t rc = 0; |
0727702a JF |
258 | |
259 | path = ibmebus_chomp(buf, count); | |
260 | if (!path) | |
261 | return -ENOMEM; | |
262 | ||
263 | if (bus_find_device(&ibmebus_bus_type, NULL, path, | |
74c9b99d | 264 | ibmebus_match_path)) { |
0727702a | 265 | printk(KERN_WARNING "%s: %s has already been probed\n", |
e48b1b45 | 266 | __func__, path); |
74c9b99d | 267 | rc = -EEXIST; |
0727702a | 268 | goto out; |
6bccf755 JF |
269 | } |
270 | ||
0727702a | 271 | if ((dn = of_find_node_by_path(path))) { |
55347cc9 | 272 | rc = ibmebus_create_device(dn); |
0727702a | 273 | of_node_put(dn); |
0727702a JF |
274 | } else { |
275 | printk(KERN_WARNING "%s: no such device node: %s\n", | |
e48b1b45 | 276 | __func__, path); |
0727702a | 277 | rc = -ENODEV; |
6bccf755 JF |
278 | } |
279 | ||
0727702a JF |
280 | out: |
281 | kfree(path); | |
55347cc9 JF |
282 | if (rc) |
283 | return rc; | |
284 | return count; | |
6bccf755 JF |
285 | } |
286 | ||
287 | static ssize_t ibmebus_store_remove(struct bus_type *bus, | |
288 | const char *buf, size_t count) | |
289 | { | |
290 | struct device *dev; | |
0727702a | 291 | char *path; |
6bccf755 | 292 | |
0727702a JF |
293 | path = ibmebus_chomp(buf, count); |
294 | if (!path) | |
295 | return -ENOMEM; | |
296 | ||
297 | if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path, | |
298 | ibmebus_match_path))) { | |
a454dc50 | 299 | of_device_unregister(to_platform_device(dev)); |
0727702a JF |
300 | |
301 | kfree(path); | |
302 | return count; | |
6bccf755 | 303 | } else { |
0727702a | 304 | printk(KERN_WARNING "%s: %s not on the bus\n", |
e48b1b45 | 305 | __func__, path); |
0727702a JF |
306 | |
307 | kfree(path); | |
6bccf755 JF |
308 | return -ENODEV; |
309 | } | |
6bccf755 JF |
310 | } |
311 | ||
710ac54b | 312 | |
6bccf755 JF |
313 | static struct bus_attribute ibmebus_bus_attrs[] = { |
314 | __ATTR(probe, S_IWUSR, NULL, ibmebus_store_probe), | |
315 | __ATTR(remove, S_IWUSR, NULL, ibmebus_store_remove), | |
316 | __ATTR_NULL | |
317 | }; | |
318 | ||
710ac54b GL |
319 | static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv) |
320 | { | |
321 | const struct of_device_id *matches = drv->of_match_table; | |
322 | ||
323 | if (!matches) | |
324 | return 0; | |
325 | ||
326 | return of_match_device(matches, dev) != NULL; | |
327 | } | |
328 | ||
329 | static int ibmebus_bus_device_probe(struct device *dev) | |
330 | { | |
331 | int error = -ENODEV; | |
332 | struct of_platform_driver *drv; | |
333 | struct platform_device *of_dev; | |
334 | const struct of_device_id *match; | |
335 | ||
336 | drv = to_of_platform_driver(dev->driver); | |
337 | of_dev = to_platform_device(dev); | |
338 | ||
339 | if (!drv->probe) | |
340 | return error; | |
341 | ||
342 | of_dev_get(of_dev); | |
343 | ||
344 | match = of_match_device(drv->driver.of_match_table, dev); | |
345 | if (match) | |
346 | error = drv->probe(of_dev, match); | |
347 | if (error) | |
348 | of_dev_put(of_dev); | |
349 | ||
350 | return error; | |
351 | } | |
352 | ||
353 | static int ibmebus_bus_device_remove(struct device *dev) | |
354 | { | |
355 | struct platform_device *of_dev = to_platform_device(dev); | |
356 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
357 | ||
358 | if (dev->driver && drv->remove) | |
359 | drv->remove(of_dev); | |
360 | return 0; | |
361 | } | |
362 | ||
363 | static void ibmebus_bus_device_shutdown(struct device *dev) | |
364 | { | |
365 | struct platform_device *of_dev = to_platform_device(dev); | |
366 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
367 | ||
368 | if (dev->driver && drv->shutdown) | |
369 | drv->shutdown(of_dev); | |
370 | } | |
371 | ||
372 | /* | |
373 | * ibmebus_bus_device_attrs | |
374 | */ | |
375 | static ssize_t devspec_show(struct device *dev, | |
376 | struct device_attribute *attr, char *buf) | |
377 | { | |
378 | struct platform_device *ofdev; | |
379 | ||
380 | ofdev = to_platform_device(dev); | |
381 | return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name); | |
382 | } | |
383 | ||
384 | static ssize_t name_show(struct device *dev, | |
385 | struct device_attribute *attr, char *buf) | |
386 | { | |
387 | struct platform_device *ofdev; | |
388 | ||
389 | ofdev = to_platform_device(dev); | |
390 | return sprintf(buf, "%s\n", ofdev->dev.of_node->name); | |
391 | } | |
392 | ||
393 | static ssize_t modalias_show(struct device *dev, | |
394 | struct device_attribute *attr, char *buf) | |
395 | { | |
396 | ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2); | |
397 | buf[len] = '\n'; | |
398 | buf[len+1] = 0; | |
399 | return len+1; | |
400 | } | |
401 | ||
402 | struct device_attribute ibmebus_bus_device_attrs[] = { | |
403 | __ATTR_RO(devspec), | |
404 | __ATTR_RO(name), | |
405 | __ATTR_RO(modalias), | |
406 | __ATTR_NULL | |
407 | }; | |
408 | ||
409 | #ifdef CONFIG_PM_SLEEP | |
410 | static int ibmebus_bus_legacy_suspend(struct device *dev, pm_message_t mesg) | |
411 | { | |
412 | struct platform_device *of_dev = to_platform_device(dev); | |
413 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
414 | int ret = 0; | |
415 | ||
416 | if (dev->driver && drv->suspend) | |
417 | ret = drv->suspend(of_dev, mesg); | |
418 | return ret; | |
419 | } | |
420 | ||
421 | static int ibmebus_bus_legacy_resume(struct device *dev) | |
422 | { | |
423 | struct platform_device *of_dev = to_platform_device(dev); | |
424 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
425 | int ret = 0; | |
426 | ||
427 | if (dev->driver && drv->resume) | |
428 | ret = drv->resume(of_dev); | |
429 | return ret; | |
430 | } | |
431 | ||
432 | static int ibmebus_bus_pm_prepare(struct device *dev) | |
433 | { | |
434 | struct device_driver *drv = dev->driver; | |
435 | int ret = 0; | |
436 | ||
437 | if (drv && drv->pm && drv->pm->prepare) | |
438 | ret = drv->pm->prepare(dev); | |
439 | ||
440 | return ret; | |
441 | } | |
442 | ||
443 | static void ibmebus_bus_pm_complete(struct device *dev) | |
444 | { | |
445 | struct device_driver *drv = dev->driver; | |
446 | ||
447 | if (drv && drv->pm && drv->pm->complete) | |
448 | drv->pm->complete(dev); | |
449 | } | |
450 | ||
451 | #ifdef CONFIG_SUSPEND | |
452 | ||
453 | static int ibmebus_bus_pm_suspend(struct device *dev) | |
454 | { | |
455 | struct device_driver *drv = dev->driver; | |
456 | int ret = 0; | |
457 | ||
458 | if (!drv) | |
459 | return 0; | |
460 | ||
461 | if (drv->pm) { | |
462 | if (drv->pm->suspend) | |
463 | ret = drv->pm->suspend(dev); | |
464 | } else { | |
465 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_SUSPEND); | |
466 | } | |
467 | ||
468 | return ret; | |
469 | } | |
470 | ||
471 | static int ibmebus_bus_pm_suspend_noirq(struct device *dev) | |
472 | { | |
473 | struct device_driver *drv = dev->driver; | |
474 | int ret = 0; | |
475 | ||
476 | if (!drv) | |
477 | return 0; | |
478 | ||
479 | if (drv->pm) { | |
480 | if (drv->pm->suspend_noirq) | |
481 | ret = drv->pm->suspend_noirq(dev); | |
482 | } | |
483 | ||
484 | return ret; | |
485 | } | |
486 | ||
487 | static int ibmebus_bus_pm_resume(struct device *dev) | |
488 | { | |
489 | struct device_driver *drv = dev->driver; | |
490 | int ret = 0; | |
491 | ||
492 | if (!drv) | |
493 | return 0; | |
494 | ||
495 | if (drv->pm) { | |
496 | if (drv->pm->resume) | |
497 | ret = drv->pm->resume(dev); | |
498 | } else { | |
499 | ret = ibmebus_bus_legacy_resume(dev); | |
500 | } | |
501 | ||
502 | return ret; | |
503 | } | |
504 | ||
505 | static int ibmebus_bus_pm_resume_noirq(struct device *dev) | |
506 | { | |
507 | struct device_driver *drv = dev->driver; | |
508 | int ret = 0; | |
509 | ||
510 | if (!drv) | |
511 | return 0; | |
512 | ||
513 | if (drv->pm) { | |
514 | if (drv->pm->resume_noirq) | |
515 | ret = drv->pm->resume_noirq(dev); | |
516 | } | |
517 | ||
518 | return ret; | |
519 | } | |
520 | ||
521 | #else /* !CONFIG_SUSPEND */ | |
522 | ||
523 | #define ibmebus_bus_pm_suspend NULL | |
524 | #define ibmebus_bus_pm_resume NULL | |
525 | #define ibmebus_bus_pm_suspend_noirq NULL | |
526 | #define ibmebus_bus_pm_resume_noirq NULL | |
527 | ||
528 | #endif /* !CONFIG_SUSPEND */ | |
529 | ||
530 | #ifdef CONFIG_HIBERNATION | |
531 | ||
532 | static int ibmebus_bus_pm_freeze(struct device *dev) | |
533 | { | |
534 | struct device_driver *drv = dev->driver; | |
535 | int ret = 0; | |
536 | ||
537 | if (!drv) | |
538 | return 0; | |
539 | ||
540 | if (drv->pm) { | |
541 | if (drv->pm->freeze) | |
542 | ret = drv->pm->freeze(dev); | |
543 | } else { | |
544 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_FREEZE); | |
545 | } | |
546 | ||
547 | return ret; | |
548 | } | |
549 | ||
550 | static int ibmebus_bus_pm_freeze_noirq(struct device *dev) | |
551 | { | |
552 | struct device_driver *drv = dev->driver; | |
553 | int ret = 0; | |
554 | ||
555 | if (!drv) | |
556 | return 0; | |
557 | ||
558 | if (drv->pm) { | |
559 | if (drv->pm->freeze_noirq) | |
560 | ret = drv->pm->freeze_noirq(dev); | |
561 | } | |
562 | ||
563 | return ret; | |
564 | } | |
565 | ||
566 | static int ibmebus_bus_pm_thaw(struct device *dev) | |
567 | { | |
568 | struct device_driver *drv = dev->driver; | |
569 | int ret = 0; | |
570 | ||
571 | if (!drv) | |
572 | return 0; | |
573 | ||
574 | if (drv->pm) { | |
575 | if (drv->pm->thaw) | |
576 | ret = drv->pm->thaw(dev); | |
577 | } else { | |
578 | ret = ibmebus_bus_legacy_resume(dev); | |
579 | } | |
580 | ||
581 | return ret; | |
582 | } | |
583 | ||
584 | static int ibmebus_bus_pm_thaw_noirq(struct device *dev) | |
585 | { | |
586 | struct device_driver *drv = dev->driver; | |
587 | int ret = 0; | |
588 | ||
589 | if (!drv) | |
590 | return 0; | |
591 | ||
592 | if (drv->pm) { | |
593 | if (drv->pm->thaw_noirq) | |
594 | ret = drv->pm->thaw_noirq(dev); | |
595 | } | |
596 | ||
597 | return ret; | |
598 | } | |
599 | ||
600 | static int ibmebus_bus_pm_poweroff(struct device *dev) | |
601 | { | |
602 | struct device_driver *drv = dev->driver; | |
603 | int ret = 0; | |
604 | ||
605 | if (!drv) | |
606 | return 0; | |
607 | ||
608 | if (drv->pm) { | |
609 | if (drv->pm->poweroff) | |
610 | ret = drv->pm->poweroff(dev); | |
611 | } else { | |
612 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_HIBERNATE); | |
613 | } | |
614 | ||
615 | return ret; | |
616 | } | |
617 | ||
618 | static int ibmebus_bus_pm_poweroff_noirq(struct device *dev) | |
619 | { | |
620 | struct device_driver *drv = dev->driver; | |
621 | int ret = 0; | |
622 | ||
623 | if (!drv) | |
624 | return 0; | |
625 | ||
626 | if (drv->pm) { | |
627 | if (drv->pm->poweroff_noirq) | |
628 | ret = drv->pm->poweroff_noirq(dev); | |
629 | } | |
630 | ||
631 | return ret; | |
632 | } | |
633 | ||
634 | static int ibmebus_bus_pm_restore(struct device *dev) | |
635 | { | |
636 | struct device_driver *drv = dev->driver; | |
637 | int ret = 0; | |
638 | ||
639 | if (!drv) | |
640 | return 0; | |
641 | ||
642 | if (drv->pm) { | |
643 | if (drv->pm->restore) | |
644 | ret = drv->pm->restore(dev); | |
645 | } else { | |
646 | ret = ibmebus_bus_legacy_resume(dev); | |
647 | } | |
648 | ||
649 | return ret; | |
650 | } | |
651 | ||
652 | static int ibmebus_bus_pm_restore_noirq(struct device *dev) | |
653 | { | |
654 | struct device_driver *drv = dev->driver; | |
655 | int ret = 0; | |
656 | ||
657 | if (!drv) | |
658 | return 0; | |
659 | ||
660 | if (drv->pm) { | |
661 | if (drv->pm->restore_noirq) | |
662 | ret = drv->pm->restore_noirq(dev); | |
663 | } | |
664 | ||
665 | return ret; | |
666 | } | |
667 | ||
668 | #else /* !CONFIG_HIBERNATION */ | |
669 | ||
670 | #define ibmebus_bus_pm_freeze NULL | |
671 | #define ibmebus_bus_pm_thaw NULL | |
672 | #define ibmebus_bus_pm_poweroff NULL | |
673 | #define ibmebus_bus_pm_restore NULL | |
674 | #define ibmebus_bus_pm_freeze_noirq NULL | |
675 | #define ibmebus_bus_pm_thaw_noirq NULL | |
676 | #define ibmebus_bus_pm_poweroff_noirq NULL | |
677 | #define ibmebus_bus_pm_restore_noirq NULL | |
678 | ||
679 | #endif /* !CONFIG_HIBERNATION */ | |
680 | ||
681 | static struct dev_pm_ops ibmebus_bus_dev_pm_ops = { | |
682 | .prepare = ibmebus_bus_pm_prepare, | |
683 | .complete = ibmebus_bus_pm_complete, | |
684 | .suspend = ibmebus_bus_pm_suspend, | |
685 | .resume = ibmebus_bus_pm_resume, | |
686 | .freeze = ibmebus_bus_pm_freeze, | |
687 | .thaw = ibmebus_bus_pm_thaw, | |
688 | .poweroff = ibmebus_bus_pm_poweroff, | |
689 | .restore = ibmebus_bus_pm_restore, | |
690 | .suspend_noirq = ibmebus_bus_pm_suspend_noirq, | |
691 | .resume_noirq = ibmebus_bus_pm_resume_noirq, | |
692 | .freeze_noirq = ibmebus_bus_pm_freeze_noirq, | |
693 | .thaw_noirq = ibmebus_bus_pm_thaw_noirq, | |
694 | .poweroff_noirq = ibmebus_bus_pm_poweroff_noirq, | |
695 | .restore_noirq = ibmebus_bus_pm_restore_noirq, | |
696 | }; | |
697 | ||
698 | #define IBMEBUS_BUS_PM_OPS_PTR (&ibmebus_bus_dev_pm_ops) | |
699 | ||
700 | #else /* !CONFIG_PM_SLEEP */ | |
701 | ||
702 | #define IBMEBUS_BUS_PM_OPS_PTR NULL | |
703 | ||
704 | #endif /* !CONFIG_PM_SLEEP */ | |
705 | ||
d7a30103 | 706 | struct bus_type ibmebus_bus_type = { |
710ac54b | 707 | .name = "ibmebus", |
55347cc9 | 708 | .uevent = of_device_uevent, |
710ac54b GL |
709 | .bus_attrs = ibmebus_bus_attrs, |
710 | .match = ibmebus_bus_bus_match, | |
711 | .probe = ibmebus_bus_device_probe, | |
712 | .remove = ibmebus_bus_device_remove, | |
713 | .shutdown = ibmebus_bus_device_shutdown, | |
714 | .dev_attrs = ibmebus_bus_device_attrs, | |
715 | .pm = IBMEBUS_BUS_PM_OPS_PTR, | |
d7a30103 HS |
716 | }; |
717 | EXPORT_SYMBOL(ibmebus_bus_type); | |
718 | ||
719 | static int __init ibmebus_bus_init(void) | |
720 | { | |
721 | int err; | |
a8308800 | 722 | |
d7a30103 | 723 | printk(KERN_INFO "IBM eBus Device Driver\n"); |
a8308800 | 724 | |
710ac54b | 725 | err = bus_register(&ibmebus_bus_type); |
d7a30103 | 726 | if (err) { |
a988c0a6 | 727 | printk(KERN_ERR "%s: failed to register IBM eBus.\n", |
e48b1b45 | 728 | __func__); |
d7a30103 HS |
729 | return err; |
730 | } | |
a8308800 | 731 | |
6bccf755 | 732 | err = device_register(&ibmebus_bus_device); |
d7a30103 | 733 | if (err) { |
a8308800 | 734 | printk(KERN_WARNING "%s: device_register returned %i\n", |
e48b1b45 | 735 | __func__, err); |
d7a30103 HS |
736 | bus_unregister(&ibmebus_bus_type); |
737 | ||
738 | return err; | |
739 | } | |
a8308800 | 740 | |
1b17adf1 | 741 | err = ibmebus_create_devices(ibmebus_matches); |
55347cc9 JF |
742 | if (err) { |
743 | device_unregister(&ibmebus_bus_device); | |
744 | bus_unregister(&ibmebus_bus_type); | |
745 | return err; | |
746 | } | |
747 | ||
d7a30103 HS |
748 | return 0; |
749 | } | |
a988c0a6 | 750 | postcore_initcall(ibmebus_bus_init); |