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