aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/amba/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/amba/bus.c')
-rw-r--r--drivers/amba/bus.c105
1 files changed, 79 insertions, 26 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 54eaf96ab217..01c2cf4efcdd 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -497,37 +497,22 @@ static void amba_device_release(struct device *dev)
497} 497}
498 498
499/** 499/**
500 * amba_device_register - register an AMBA device 500 * amba_device_add - add a previously allocated AMBA device structure
501 * @dev: AMBA device to register 501 * @dev: AMBA device allocated by amba_device_alloc
502 * @parent: parent memory resource 502 * @parent: resource parent for this devices resources
503 * 503 *
504 * Setup the AMBA device, reading the cell ID if present. 504 * Claim the resource, and read the device cell ID if not already
505 * Claim the resource, and register the AMBA device with 505 * initialized. Register the AMBA device with the Linux device
506 * the Linux device manager. 506 * manager.
507 */ 507 */
508int amba_device_register(struct amba_device *dev, struct resource *parent) 508int amba_device_add(struct amba_device *dev, struct resource *parent)
509{ 509{
510 u32 size; 510 u32 size;
511 void __iomem *tmp; 511 void __iomem *tmp;
512 int i, ret; 512 int i, ret;
513 513
514 device_initialize(&dev->dev); 514 WARN_ON(dev->irq[0] == (unsigned int)-1);
515 515 WARN_ON(dev->irq[1] == (unsigned int)-1);
516 /*
517 * Copy from device_add
518 */
519 if (dev->dev.init_name) {
520 dev_set_name(&dev->dev, "%s", dev->dev.init_name);
521 dev->dev.init_name = NULL;
522 }
523
524 dev->dev.release = amba_device_release;
525 dev->dev.bus = &amba_bustype;
526 dev->dev.dma_mask = &dev->dma_mask;
527 dev->res.name = dev_name(&dev->dev);
528
529 if (!dev->dev.coherent_dma_mask && dev->dma_mask)
530 dev_warn(&dev->dev, "coherent dma mask is unset\n");
531 516
532 ret = request_resource(parent, &dev->res); 517 ret = request_resource(parent, &dev->res);
533 if (ret) 518 if (ret)
@@ -582,9 +567,9 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
582 if (ret) 567 if (ret)
583 goto err_release; 568 goto err_release;
584 569
585 if (dev->irq[0] != NO_IRQ) 570 if (dev->irq[0] && dev->irq[0] != NO_IRQ)
586 ret = device_create_file(&dev->dev, &dev_attr_irq0); 571 ret = device_create_file(&dev->dev, &dev_attr_irq0);
587 if (ret == 0 && dev->irq[1] != NO_IRQ) 572 if (ret == 0 && dev->irq[1] && dev->irq[1] != NO_IRQ)
588 ret = device_create_file(&dev->dev, &dev_attr_irq1); 573 ret = device_create_file(&dev->dev, &dev_attr_irq1);
589 if (ret == 0) 574 if (ret == 0)
590 return ret; 575 return ret;
@@ -596,6 +581,74 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
596 err_out: 581 err_out:
597 return ret; 582 return ret;
598} 583}
584EXPORT_SYMBOL_GPL(amba_device_add);
585
586static void amba_device_initialize(struct amba_device *dev, const char *name)
587{
588 device_initialize(&dev->dev);
589 if (name)
590 dev_set_name(&dev->dev, "%s", name);
591 dev->dev.release = amba_device_release;
592 dev->dev.bus = &amba_bustype;
593 dev->dev.dma_mask = &dev->dma_mask;
594 dev->res.name = dev_name(&dev->dev);
595}
596
597/**
598 * amba_device_alloc - allocate an AMBA device
599 * @name: sysfs name of the AMBA device
600 * @base: base of AMBA device
601 * @size: size of AMBA device
602 *
603 * Allocate and initialize an AMBA device structure. Returns %NULL
604 * on failure.
605 */
606struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
607 size_t size)
608{
609 struct amba_device *dev;
610
611 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
612 if (dev) {
613 amba_device_initialize(dev, name);
614 dev->res.start = base;
615 dev->res.end = base + size - 1;
616 dev->res.flags = IORESOURCE_MEM;
617 }
618
619 return dev;
620}
621EXPORT_SYMBOL_GPL(amba_device_alloc);
622
623/**
624 * amba_device_register - register an AMBA device
625 * @dev: AMBA device to register
626 * @parent: parent memory resource
627 *
628 * Setup the AMBA device, reading the cell ID if present.
629 * Claim the resource, and register the AMBA device with
630 * the Linux device manager.
631 */
632int amba_device_register(struct amba_device *dev, struct resource *parent)
633{
634 amba_device_initialize(dev, dev->dev.init_name);
635 dev->dev.init_name = NULL;
636
637 if (!dev->dev.coherent_dma_mask && dev->dma_mask)
638 dev_warn(&dev->dev, "coherent dma mask is unset\n");
639
640 return amba_device_add(dev, parent);
641}
642
643/**
644 * amba_device_put - put an AMBA device
645 * @dev: AMBA device to put
646 */
647void amba_device_put(struct amba_device *dev)
648{
649 put_device(&dev->dev);
650}
651EXPORT_SYMBOL_GPL(amba_device_put);
599 652
600/** 653/**
601 * amba_device_unregister - unregister an AMBA device 654 * amba_device_unregister - unregister an AMBA device