]>
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 | { | |
d24f9c69 MM |
128 | return mask == DMA_BIT_MASK(64); |
129 | } | |
130 | ||
131 | static u64 ibmebus_dma_get_required_mask(struct device *dev) | |
132 | { | |
133 | return DMA_BIT_MASK(64); | |
d7a30103 HS |
134 | } |
135 | ||
45223c54 | 136 | static struct dma_map_ops ibmebus_dma_ops = { |
d7a30103 HS |
137 | .alloc_coherent = ibmebus_alloc_coherent, |
138 | .free_coherent = ibmebus_free_coherent, | |
d7a30103 HS |
139 | .map_sg = ibmebus_map_sg, |
140 | .unmap_sg = ibmebus_unmap_sg, | |
141 | .dma_supported = ibmebus_dma_supported, | |
d24f9c69 | 142 | .get_required_mask = ibmebus_dma_get_required_mask, |
f9226d57 MN |
143 | .map_page = ibmebus_map_page, |
144 | .unmap_page = ibmebus_unmap_page, | |
d7a30103 HS |
145 | }; |
146 | ||
55347cc9 JF |
147 | static int ibmebus_match_path(struct device *dev, void *data) |
148 | { | |
a454dc50 | 149 | struct device_node *dn = to_platform_device(dev)->dev.of_node; |
55347cc9 JF |
150 | return (dn->full_name && |
151 | (strcasecmp((char *)data, dn->full_name) == 0)); | |
152 | } | |
153 | ||
154 | static int ibmebus_match_node(struct device *dev, void *data) | |
155 | { | |
a454dc50 | 156 | return to_platform_device(dev)->dev.of_node == data; |
55347cc9 JF |
157 | } |
158 | ||
159 | static int ibmebus_create_device(struct device_node *dn) | |
160 | { | |
a454dc50 | 161 | struct platform_device *dev; |
55347cc9 JF |
162 | int ret; |
163 | ||
164 | dev = of_device_alloc(dn, NULL, &ibmebus_bus_device); | |
165 | if (!dev) | |
166 | return -ENOMEM; | |
167 | ||
168 | dev->dev.bus = &ibmebus_bus_type; | |
169 | dev->dev.archdata.dma_ops = &ibmebus_dma_ops; | |
170 | ||
7096d042 GL |
171 | ret = of_device_add(dev); |
172 | if (ret) | |
173 | platform_device_put(dev); | |
174 | return ret; | |
55347cc9 JF |
175 | } |
176 | ||
177 | static int ibmebus_create_devices(const struct of_device_id *matches) | |
178 | { | |
179 | struct device_node *root, *child; | |
180 | int ret = 0; | |
181 | ||
182 | root = of_find_node_by_path("/"); | |
183 | ||
85e99b9f | 184 | for_each_child_of_node(root, child) { |
55347cc9 JF |
185 | if (!of_match_node(matches, child)) |
186 | continue; | |
187 | ||
188 | if (bus_find_device(&ibmebus_bus_type, NULL, child, | |
189 | ibmebus_match_node)) | |
190 | continue; | |
191 | ||
192 | ret = ibmebus_create_device(child); | |
193 | if (ret) { | |
194 | printk(KERN_ERR "%s: failed to create device (%i)", | |
e48b1b45 | 195 | __func__, ret); |
55347cc9 JF |
196 | of_node_put(child); |
197 | break; | |
198 | } | |
199 | } | |
200 | ||
201 | of_node_put(root); | |
202 | return ret; | |
203 | } | |
204 | ||
6b08f3ae | 205 | int ibmebus_register_driver(struct of_platform_driver *drv) |
d7a30103 | 206 | { |
6b08f3ae | 207 | /* If the driver uses devices that ibmebus doesn't know, add them */ |
597b9d1e | 208 | ibmebus_create_devices(drv->driver.of_match_table); |
6b08f3ae | 209 | |
710ac54b GL |
210 | drv->driver.bus = &ibmebus_bus_type; |
211 | return driver_register(&drv->driver); | |
d7a30103 HS |
212 | } |
213 | EXPORT_SYMBOL(ibmebus_register_driver); | |
214 | ||
6b08f3ae | 215 | void ibmebus_unregister_driver(struct of_platform_driver *drv) |
a8308800 | 216 | { |
710ac54b | 217 | driver_unregister(&drv->driver); |
d7a30103 HS |
218 | } |
219 | EXPORT_SYMBOL(ibmebus_unregister_driver); | |
220 | ||
6b08f3ae JF |
221 | int ibmebus_request_irq(u32 ist, irq_handler_t handler, |
222 | unsigned long irq_flags, const char *devname, | |
d7a30103 HS |
223 | void *dev_id) |
224 | { | |
6e99e458 | 225 | unsigned int irq = irq_create_mapping(NULL, ist); |
a8308800 | 226 | |
d7a30103 HS |
227 | if (irq == NO_IRQ) |
228 | return -EINVAL; | |
a8308800 | 229 | |
6b08f3ae | 230 | return request_irq(irq, handler, irq_flags, devname, dev_id); |
d7a30103 HS |
231 | } |
232 | EXPORT_SYMBOL(ibmebus_request_irq); | |
233 | ||
6b08f3ae | 234 | void ibmebus_free_irq(u32 ist, void *dev_id) |
d7a30103 | 235 | { |
0ebfff14 | 236 | unsigned int irq = irq_find_mapping(NULL, ist); |
a8308800 | 237 | |
d7a30103 | 238 | free_irq(irq, dev_id); |
6358d6cb | 239 | irq_dispose_mapping(irq); |
d7a30103 HS |
240 | } |
241 | EXPORT_SYMBOL(ibmebus_free_irq); | |
242 | ||
0727702a JF |
243 | static char *ibmebus_chomp(const char *in, size_t count) |
244 | { | |
61a564fd JJ |
245 | char *out = kmalloc(count + 1, GFP_KERNEL); |
246 | ||
0727702a JF |
247 | if (!out) |
248 | return NULL; | |
249 | ||
250 | memcpy(out, in, count); | |
251 | out[count] = '\0'; | |
252 | if (out[count - 1] == '\n') | |
253 | out[count - 1] = '\0'; | |
254 | ||
255 | return out; | |
6bccf755 JF |
256 | } |
257 | ||
258 | static ssize_t ibmebus_store_probe(struct bus_type *bus, | |
259 | const char *buf, size_t count) | |
260 | { | |
261 | struct device_node *dn = NULL; | |
0727702a | 262 | char *path; |
55347cc9 | 263 | ssize_t rc = 0; |
0727702a JF |
264 | |
265 | path = ibmebus_chomp(buf, count); | |
266 | if (!path) | |
267 | return -ENOMEM; | |
268 | ||
269 | if (bus_find_device(&ibmebus_bus_type, NULL, path, | |
74c9b99d | 270 | ibmebus_match_path)) { |
0727702a | 271 | printk(KERN_WARNING "%s: %s has already been probed\n", |
e48b1b45 | 272 | __func__, path); |
74c9b99d | 273 | rc = -EEXIST; |
0727702a | 274 | goto out; |
6bccf755 JF |
275 | } |
276 | ||
0727702a | 277 | if ((dn = of_find_node_by_path(path))) { |
55347cc9 | 278 | rc = ibmebus_create_device(dn); |
0727702a | 279 | of_node_put(dn); |
0727702a JF |
280 | } else { |
281 | printk(KERN_WARNING "%s: no such device node: %s\n", | |
e48b1b45 | 282 | __func__, path); |
0727702a | 283 | rc = -ENODEV; |
6bccf755 JF |
284 | } |
285 | ||
0727702a JF |
286 | out: |
287 | kfree(path); | |
55347cc9 JF |
288 | if (rc) |
289 | return rc; | |
290 | return count; | |
6bccf755 JF |
291 | } |
292 | ||
293 | static ssize_t ibmebus_store_remove(struct bus_type *bus, | |
294 | const char *buf, size_t count) | |
295 | { | |
296 | struct device *dev; | |
0727702a | 297 | char *path; |
6bccf755 | 298 | |
0727702a JF |
299 | path = ibmebus_chomp(buf, count); |
300 | if (!path) | |
301 | return -ENOMEM; | |
302 | ||
303 | if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path, | |
304 | ibmebus_match_path))) { | |
a454dc50 | 305 | of_device_unregister(to_platform_device(dev)); |
0727702a JF |
306 | |
307 | kfree(path); | |
308 | return count; | |
6bccf755 | 309 | } else { |
0727702a | 310 | printk(KERN_WARNING "%s: %s not on the bus\n", |
e48b1b45 | 311 | __func__, path); |
0727702a JF |
312 | |
313 | kfree(path); | |
6bccf755 JF |
314 | return -ENODEV; |
315 | } | |
6bccf755 JF |
316 | } |
317 | ||
710ac54b | 318 | |
6bccf755 JF |
319 | static struct bus_attribute ibmebus_bus_attrs[] = { |
320 | __ATTR(probe, S_IWUSR, NULL, ibmebus_store_probe), | |
321 | __ATTR(remove, S_IWUSR, NULL, ibmebus_store_remove), | |
322 | __ATTR_NULL | |
323 | }; | |
324 | ||
710ac54b GL |
325 | static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv) |
326 | { | |
327 | const struct of_device_id *matches = drv->of_match_table; | |
328 | ||
329 | if (!matches) | |
330 | return 0; | |
331 | ||
332 | return of_match_device(matches, dev) != NULL; | |
333 | } | |
334 | ||
335 | static int ibmebus_bus_device_probe(struct device *dev) | |
336 | { | |
337 | int error = -ENODEV; | |
338 | struct of_platform_driver *drv; | |
339 | struct platform_device *of_dev; | |
340 | const struct of_device_id *match; | |
341 | ||
342 | drv = to_of_platform_driver(dev->driver); | |
343 | of_dev = to_platform_device(dev); | |
344 | ||
345 | if (!drv->probe) | |
346 | return error; | |
347 | ||
348 | of_dev_get(of_dev); | |
349 | ||
350 | match = of_match_device(drv->driver.of_match_table, dev); | |
351 | if (match) | |
352 | error = drv->probe(of_dev, match); | |
353 | if (error) | |
354 | of_dev_put(of_dev); | |
355 | ||
356 | return error; | |
357 | } | |
358 | ||
359 | static int ibmebus_bus_device_remove(struct device *dev) | |
360 | { | |
361 | struct platform_device *of_dev = to_platform_device(dev); | |
362 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
363 | ||
364 | if (dev->driver && drv->remove) | |
365 | drv->remove(of_dev); | |
366 | return 0; | |
367 | } | |
368 | ||
369 | static void ibmebus_bus_device_shutdown(struct device *dev) | |
370 | { | |
371 | struct platform_device *of_dev = to_platform_device(dev); | |
372 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
373 | ||
374 | if (dev->driver && drv->shutdown) | |
375 | drv->shutdown(of_dev); | |
376 | } | |
377 | ||
378 | /* | |
379 | * ibmebus_bus_device_attrs | |
380 | */ | |
381 | static ssize_t devspec_show(struct device *dev, | |
382 | struct device_attribute *attr, char *buf) | |
383 | { | |
384 | struct platform_device *ofdev; | |
385 | ||
386 | ofdev = to_platform_device(dev); | |
387 | return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name); | |
388 | } | |
389 | ||
390 | static ssize_t name_show(struct device *dev, | |
391 | struct device_attribute *attr, char *buf) | |
392 | { | |
393 | struct platform_device *ofdev; | |
394 | ||
395 | ofdev = to_platform_device(dev); | |
396 | return sprintf(buf, "%s\n", ofdev->dev.of_node->name); | |
397 | } | |
398 | ||
399 | static ssize_t modalias_show(struct device *dev, | |
400 | struct device_attribute *attr, char *buf) | |
401 | { | |
402 | ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2); | |
403 | buf[len] = '\n'; | |
404 | buf[len+1] = 0; | |
405 | return len+1; | |
406 | } | |
407 | ||
408 | struct device_attribute ibmebus_bus_device_attrs[] = { | |
409 | __ATTR_RO(devspec), | |
410 | __ATTR_RO(name), | |
411 | __ATTR_RO(modalias), | |
412 | __ATTR_NULL | |
413 | }; | |
414 | ||
415 | #ifdef CONFIG_PM_SLEEP | |
416 | static int ibmebus_bus_legacy_suspend(struct device *dev, pm_message_t mesg) | |
417 | { | |
418 | struct platform_device *of_dev = to_platform_device(dev); | |
419 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
420 | int ret = 0; | |
421 | ||
422 | if (dev->driver && drv->suspend) | |
423 | ret = drv->suspend(of_dev, mesg); | |
424 | return ret; | |
425 | } | |
426 | ||
427 | static int ibmebus_bus_legacy_resume(struct device *dev) | |
428 | { | |
429 | struct platform_device *of_dev = to_platform_device(dev); | |
430 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | |
431 | int ret = 0; | |
432 | ||
433 | if (dev->driver && drv->resume) | |
434 | ret = drv->resume(of_dev); | |
435 | return ret; | |
436 | } | |
437 | ||
438 | static int ibmebus_bus_pm_prepare(struct device *dev) | |
439 | { | |
440 | struct device_driver *drv = dev->driver; | |
441 | int ret = 0; | |
442 | ||
443 | if (drv && drv->pm && drv->pm->prepare) | |
444 | ret = drv->pm->prepare(dev); | |
445 | ||
446 | return ret; | |
447 | } | |
448 | ||
449 | static void ibmebus_bus_pm_complete(struct device *dev) | |
450 | { | |
451 | struct device_driver *drv = dev->driver; | |
452 | ||
453 | if (drv && drv->pm && drv->pm->complete) | |
454 | drv->pm->complete(dev); | |
455 | } | |
456 | ||
457 | #ifdef CONFIG_SUSPEND | |
458 | ||
459 | static int ibmebus_bus_pm_suspend(struct device *dev) | |
460 | { | |
461 | struct device_driver *drv = dev->driver; | |
462 | int ret = 0; | |
463 | ||
464 | if (!drv) | |
465 | return 0; | |
466 | ||
467 | if (drv->pm) { | |
468 | if (drv->pm->suspend) | |
469 | ret = drv->pm->suspend(dev); | |
470 | } else { | |
471 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_SUSPEND); | |
472 | } | |
473 | ||
474 | return ret; | |
475 | } | |
476 | ||
477 | static int ibmebus_bus_pm_suspend_noirq(struct device *dev) | |
478 | { | |
479 | struct device_driver *drv = dev->driver; | |
480 | int ret = 0; | |
481 | ||
482 | if (!drv) | |
483 | return 0; | |
484 | ||
485 | if (drv->pm) { | |
486 | if (drv->pm->suspend_noirq) | |
487 | ret = drv->pm->suspend_noirq(dev); | |
488 | } | |
489 | ||
490 | return ret; | |
491 | } | |
492 | ||
493 | static int ibmebus_bus_pm_resume(struct device *dev) | |
494 | { | |
495 | struct device_driver *drv = dev->driver; | |
496 | int ret = 0; | |
497 | ||
498 | if (!drv) | |
499 | return 0; | |
500 | ||
501 | if (drv->pm) { | |
502 | if (drv->pm->resume) | |
503 | ret = drv->pm->resume(dev); | |
504 | } else { | |
505 | ret = ibmebus_bus_legacy_resume(dev); | |
506 | } | |
507 | ||
508 | return ret; | |
509 | } | |
510 | ||
511 | static int ibmebus_bus_pm_resume_noirq(struct device *dev) | |
512 | { | |
513 | struct device_driver *drv = dev->driver; | |
514 | int ret = 0; | |
515 | ||
516 | if (!drv) | |
517 | return 0; | |
518 | ||
519 | if (drv->pm) { | |
520 | if (drv->pm->resume_noirq) | |
521 | ret = drv->pm->resume_noirq(dev); | |
522 | } | |
523 | ||
524 | return ret; | |
525 | } | |
526 | ||
527 | #else /* !CONFIG_SUSPEND */ | |
528 | ||
529 | #define ibmebus_bus_pm_suspend NULL | |
530 | #define ibmebus_bus_pm_resume NULL | |
531 | #define ibmebus_bus_pm_suspend_noirq NULL | |
532 | #define ibmebus_bus_pm_resume_noirq NULL | |
533 | ||
534 | #endif /* !CONFIG_SUSPEND */ | |
535 | ||
1f112cee | 536 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
710ac54b GL |
537 | |
538 | static int ibmebus_bus_pm_freeze(struct device *dev) | |
539 | { | |
540 | struct device_driver *drv = dev->driver; | |
541 | int ret = 0; | |
542 | ||
543 | if (!drv) | |
544 | return 0; | |
545 | ||
546 | if (drv->pm) { | |
547 | if (drv->pm->freeze) | |
548 | ret = drv->pm->freeze(dev); | |
549 | } else { | |
550 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_FREEZE); | |
551 | } | |
552 | ||
553 | return ret; | |
554 | } | |
555 | ||
556 | static int ibmebus_bus_pm_freeze_noirq(struct device *dev) | |
557 | { | |
558 | struct device_driver *drv = dev->driver; | |
559 | int ret = 0; | |
560 | ||
561 | if (!drv) | |
562 | return 0; | |
563 | ||
564 | if (drv->pm) { | |
565 | if (drv->pm->freeze_noirq) | |
566 | ret = drv->pm->freeze_noirq(dev); | |
567 | } | |
568 | ||
569 | return ret; | |
570 | } | |
571 | ||
572 | static int ibmebus_bus_pm_thaw(struct device *dev) | |
573 | { | |
574 | struct device_driver *drv = dev->driver; | |
575 | int ret = 0; | |
576 | ||
577 | if (!drv) | |
578 | return 0; | |
579 | ||
580 | if (drv->pm) { | |
581 | if (drv->pm->thaw) | |
582 | ret = drv->pm->thaw(dev); | |
583 | } else { | |
584 | ret = ibmebus_bus_legacy_resume(dev); | |
585 | } | |
586 | ||
587 | return ret; | |
588 | } | |
589 | ||
590 | static int ibmebus_bus_pm_thaw_noirq(struct device *dev) | |
591 | { | |
592 | struct device_driver *drv = dev->driver; | |
593 | int ret = 0; | |
594 | ||
595 | if (!drv) | |
596 | return 0; | |
597 | ||
598 | if (drv->pm) { | |
599 | if (drv->pm->thaw_noirq) | |
600 | ret = drv->pm->thaw_noirq(dev); | |
601 | } | |
602 | ||
603 | return ret; | |
604 | } | |
605 | ||
606 | static int ibmebus_bus_pm_poweroff(struct device *dev) | |
607 | { | |
608 | struct device_driver *drv = dev->driver; | |
609 | int ret = 0; | |
610 | ||
611 | if (!drv) | |
612 | return 0; | |
613 | ||
614 | if (drv->pm) { | |
615 | if (drv->pm->poweroff) | |
616 | ret = drv->pm->poweroff(dev); | |
617 | } else { | |
618 | ret = ibmebus_bus_legacy_suspend(dev, PMSG_HIBERNATE); | |
619 | } | |
620 | ||
621 | return ret; | |
622 | } | |
623 | ||
624 | static int ibmebus_bus_pm_poweroff_noirq(struct device *dev) | |
625 | { | |
626 | struct device_driver *drv = dev->driver; | |
627 | int ret = 0; | |
628 | ||
629 | if (!drv) | |
630 | return 0; | |
631 | ||
632 | if (drv->pm) { | |
633 | if (drv->pm->poweroff_noirq) | |
634 | ret = drv->pm->poweroff_noirq(dev); | |
635 | } | |
636 | ||
637 | return ret; | |
638 | } | |
639 | ||
640 | static int ibmebus_bus_pm_restore(struct device *dev) | |
641 | { | |
642 | struct device_driver *drv = dev->driver; | |
643 | int ret = 0; | |
644 | ||
645 | if (!drv) | |
646 | return 0; | |
647 | ||
648 | if (drv->pm) { | |
649 | if (drv->pm->restore) | |
650 | ret = drv->pm->restore(dev); | |
651 | } else { | |
652 | ret = ibmebus_bus_legacy_resume(dev); | |
653 | } | |
654 | ||
655 | return ret; | |
656 | } | |
657 | ||
658 | static int ibmebus_bus_pm_restore_noirq(struct device *dev) | |
659 | { | |
660 | struct device_driver *drv = dev->driver; | |
661 | int ret = 0; | |
662 | ||
663 | if (!drv) | |
664 | return 0; | |
665 | ||
666 | if (drv->pm) { | |
667 | if (drv->pm->restore_noirq) | |
668 | ret = drv->pm->restore_noirq(dev); | |
669 | } | |
670 | ||
671 | return ret; | |
672 | } | |
673 | ||
1f112cee | 674 | #else /* !CONFIG_HIBERNATE_CALLBACKS */ |
710ac54b GL |
675 | |
676 | #define ibmebus_bus_pm_freeze NULL | |
677 | #define ibmebus_bus_pm_thaw NULL | |
678 | #define ibmebus_bus_pm_poweroff NULL | |
679 | #define ibmebus_bus_pm_restore NULL | |
680 | #define ibmebus_bus_pm_freeze_noirq NULL | |
681 | #define ibmebus_bus_pm_thaw_noirq NULL | |
682 | #define ibmebus_bus_pm_poweroff_noirq NULL | |
683 | #define ibmebus_bus_pm_restore_noirq NULL | |
684 | ||
1f112cee | 685 | #endif /* !CONFIG_HIBERNATE_CALLBACKS */ |
710ac54b GL |
686 | |
687 | static struct dev_pm_ops ibmebus_bus_dev_pm_ops = { | |
688 | .prepare = ibmebus_bus_pm_prepare, | |
689 | .complete = ibmebus_bus_pm_complete, | |
690 | .suspend = ibmebus_bus_pm_suspend, | |
691 | .resume = ibmebus_bus_pm_resume, | |
692 | .freeze = ibmebus_bus_pm_freeze, | |
693 | .thaw = ibmebus_bus_pm_thaw, | |
694 | .poweroff = ibmebus_bus_pm_poweroff, | |
695 | .restore = ibmebus_bus_pm_restore, | |
696 | .suspend_noirq = ibmebus_bus_pm_suspend_noirq, | |
697 | .resume_noirq = ibmebus_bus_pm_resume_noirq, | |
698 | .freeze_noirq = ibmebus_bus_pm_freeze_noirq, | |
699 | .thaw_noirq = ibmebus_bus_pm_thaw_noirq, | |
700 | .poweroff_noirq = ibmebus_bus_pm_poweroff_noirq, | |
701 | .restore_noirq = ibmebus_bus_pm_restore_noirq, | |
702 | }; | |
703 | ||
704 | #define IBMEBUS_BUS_PM_OPS_PTR (&ibmebus_bus_dev_pm_ops) | |
705 | ||
706 | #else /* !CONFIG_PM_SLEEP */ | |
707 | ||
708 | #define IBMEBUS_BUS_PM_OPS_PTR NULL | |
709 | ||
710 | #endif /* !CONFIG_PM_SLEEP */ | |
711 | ||
d7a30103 | 712 | struct bus_type ibmebus_bus_type = { |
710ac54b | 713 | .name = "ibmebus", |
55347cc9 | 714 | .uevent = of_device_uevent, |
710ac54b GL |
715 | .bus_attrs = ibmebus_bus_attrs, |
716 | .match = ibmebus_bus_bus_match, | |
717 | .probe = ibmebus_bus_device_probe, | |
718 | .remove = ibmebus_bus_device_remove, | |
719 | .shutdown = ibmebus_bus_device_shutdown, | |
720 | .dev_attrs = ibmebus_bus_device_attrs, | |
721 | .pm = IBMEBUS_BUS_PM_OPS_PTR, | |
d7a30103 HS |
722 | }; |
723 | EXPORT_SYMBOL(ibmebus_bus_type); | |
724 | ||
725 | static int __init ibmebus_bus_init(void) | |
726 | { | |
727 | int err; | |
a8308800 | 728 | |
d7a30103 | 729 | printk(KERN_INFO "IBM eBus Device Driver\n"); |
a8308800 | 730 | |
710ac54b | 731 | err = bus_register(&ibmebus_bus_type); |
d7a30103 | 732 | if (err) { |
a988c0a6 | 733 | printk(KERN_ERR "%s: failed to register IBM eBus.\n", |
e48b1b45 | 734 | __func__); |
d7a30103 HS |
735 | return err; |
736 | } | |
a8308800 | 737 | |
6bccf755 | 738 | err = device_register(&ibmebus_bus_device); |
d7a30103 | 739 | if (err) { |
a8308800 | 740 | printk(KERN_WARNING "%s: device_register returned %i\n", |
e48b1b45 | 741 | __func__, err); |
d7a30103 HS |
742 | bus_unregister(&ibmebus_bus_type); |
743 | ||
744 | return err; | |
745 | } | |
a8308800 | 746 | |
1b17adf1 | 747 | err = ibmebus_create_devices(ibmebus_matches); |
55347cc9 JF |
748 | if (err) { |
749 | device_unregister(&ibmebus_bus_device); | |
750 | bus_unregister(&ibmebus_bus_type); | |
751 | return err; | |
752 | } | |
753 | ||
d7a30103 HS |
754 | return 0; |
755 | } | |
a988c0a6 | 756 | postcore_initcall(ibmebus_bus_init); |