40 #include <linux/export.h>
46 #include <linux/slab.h>
47 #include <linux/stat.h>
51 static struct device ibmebus_bus_device = {
52 .init_name =
"ibmebus",
59 { .compatible =
"IBM,lhca" },
60 { .compatible =
"IBM,lhea" },
64 static void *ibmebus_alloc_coherent(
struct device *
dev,
78 static void ibmebus_free_coherent(
struct device *
dev,
96 static void ibmebus_unmap_page(
struct device *dev,
105 static int ibmebus_map_sg(
struct device *dev,
115 sg->dma_length = sg->
length;
121 static void ibmebus_unmap_sg(
struct device *dev,
129 static int ibmebus_dma_supported(
struct device *dev,
u64 mask)
134 static u64 ibmebus_dma_get_required_mask(
struct device *dev)
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,
150 static int ibmebus_match_path(
struct device *dev,
void *
data)
157 static int ibmebus_match_node(
struct device *dev,
void *data)
162 static int ibmebus_create_device(
struct device_node *dn)
167 dev = of_device_alloc(dn,
NULL, &ibmebus_bus_device);
172 dev->
dev.archdata.dma_ops = &ibmebus_dma_ops;
180 static int ibmebus_create_devices(
const struct of_device_id *matches)
195 ret = ibmebus_create_device(child);
211 ibmebus_create_devices(drv->driver.of_match_table);
225 unsigned long irq_flags,
const char *devname,
233 return request_irq(irq, handler, irq_flags, devname, dev_id);
246 static char *ibmebus_chomp(
const char *
in,
size_t count)
255 if (out[count - 1] ==
'\n')
256 out[count - 1] =
'\0';
262 const char *
buf,
size_t count)
268 path = ibmebus_chomp(buf, count);
273 ibmebus_match_path)) {
281 rc = ibmebus_create_device(dn);
297 const char *buf,
size_t count)
302 path = ibmebus_chomp(buf, count);
307 ibmebus_match_path))) {
338 static int ibmebus_bus_device_probe(
struct device *dev)
341 struct of_platform_driver *drv;
345 drv = to_of_platform_driver(dev->
driver);
355 error = drv->probe(of_dev, match);
362 static int ibmebus_bus_device_remove(
struct device *dev)
365 struct of_platform_driver *drv = to_of_platform_driver(dev->
driver);
367 if (dev->
driver && drv->remove)
372 static void ibmebus_bus_device_shutdown(
struct device *dev)
375 struct of_platform_driver *drv = to_of_platform_driver(dev->
driver);
377 if (dev->
driver && drv->shutdown)
378 drv->shutdown(of_dev);
390 return sprintf(buf,
"%s\n", ofdev->
dev.of_node->full_name);
399 return sprintf(buf,
"%s\n", ofdev->
dev.of_node->name);
418 #ifdef CONFIG_PM_SLEEP
422 struct of_platform_driver *drv = to_of_platform_driver(dev->
driver);
425 if (dev->
driver && drv->suspend)
426 ret = drv->suspend(of_dev, mesg);
430 static int ibmebus_bus_legacy_resume(
struct device *dev)
433 struct of_platform_driver *drv = to_of_platform_driver(dev->
driver);
436 if (dev->
driver && drv->resume)
437 ret = drv->resume(of_dev);
441 static int ibmebus_bus_pm_prepare(
struct device *dev)
446 if (drv && drv->
pm && drv->
pm->prepare)
447 ret = drv->
pm->prepare(dev);
452 static void ibmebus_bus_pm_complete(
struct device *dev)
456 if (drv && drv->
pm && drv->
pm->complete)
457 drv->
pm->complete(dev);
460 #ifdef CONFIG_SUSPEND
462 static int ibmebus_bus_pm_suspend(
struct device *dev)
471 if (drv->
pm->suspend)
472 ret = drv->
pm->suspend(dev);
480 static int ibmebus_bus_pm_suspend_noirq(
struct device *dev)
489 if (drv->
pm->suspend_noirq)
490 ret = drv->
pm->suspend_noirq(dev);
496 static int ibmebus_bus_pm_resume(
struct device *dev)
506 ret = drv->
pm->resume(dev);
508 ret = ibmebus_bus_legacy_resume(dev);
514 static int ibmebus_bus_pm_resume_noirq(
struct device *dev)
523 if (drv->
pm->resume_noirq)
524 ret = drv->
pm->resume_noirq(dev);
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
539 #ifdef CONFIG_HIBERNATE_CALLBACKS
541 static int ibmebus_bus_pm_freeze(
struct device *dev)
551 ret = drv->
pm->freeze(dev);
553 ret = ibmebus_bus_legacy_suspend(dev,
PMSG_FREEZE);
559 static int ibmebus_bus_pm_freeze_noirq(
struct device *dev)
568 if (drv->
pm->freeze_noirq)
569 ret = drv->
pm->freeze_noirq(dev);
575 static int ibmebus_bus_pm_thaw(
struct device *dev)
585 ret = drv->
pm->thaw(dev);
587 ret = ibmebus_bus_legacy_resume(dev);
593 static int ibmebus_bus_pm_thaw_noirq(
struct device *dev)
602 if (drv->
pm->thaw_noirq)
603 ret = drv->
pm->thaw_noirq(dev);
609 static int ibmebus_bus_pm_poweroff(
struct device *dev)
618 if (drv->
pm->poweroff)
619 ret = drv->
pm->poweroff(dev);
627 static int ibmebus_bus_pm_poweroff_noirq(
struct device *dev)
636 if (drv->
pm->poweroff_noirq)
637 ret = drv->
pm->poweroff_noirq(dev);
643 static int ibmebus_bus_pm_restore(
struct device *dev)
652 if (drv->
pm->restore)
653 ret = drv->
pm->restore(dev);
655 ret = ibmebus_bus_legacy_resume(dev);
661 static int ibmebus_bus_pm_restore_noirq(
struct device *dev)
670 if (drv->
pm->restore_noirq)
671 ret = drv->
pm->restore_noirq(dev);
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
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,
707 #define IBMEBUS_BUS_PM_OPS_PTR (&ibmebus_bus_dev_pm_ops)
711 #define IBMEBUS_BUS_PM_OPS_PTR NULL
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,
728 static int __init ibmebus_bus_init(
void)
750 err = ibmebus_create_devices(ibmebus_matches);