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