aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2011-12-18 06:07:47 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2012-01-25 06:02:01 -0500
commitd5dc9271b25822f36d299f8cab985379743424b9 (patch)
tree8fd978632dd624356e1686b1e081868427a46655
parentdffcb9c5f854b485a07a3620eba4e560c77b0032 (diff)
ARM: amba: add amba_device allocation/add/put functions
Add functions to allocate and initialize AMBA device structures, and add them to the Linux device manager. This allows us to kill this type of operation from individual platforms, moving it to core code. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--drivers/amba/bus.c100
-rw-r--r--include/linux/amba/bus.h3
2 files changed, 78 insertions, 25 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 54eaf96ab21..82b65e1e12b 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -497,38 +497,20 @@ 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);
515
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
532 ret = request_resource(parent, &dev->res); 514 ret = request_resource(parent, &dev->res);
533 if (ret) 515 if (ret)
534 goto err_out; 516 goto err_out;
@@ -596,6 +578,74 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
596 err_out: 578 err_out:
597 return ret; 579 return ret;
598} 580}
581EXPORT_SYMBOL_GPL(amba_device_add);
582
583static void amba_device_initialize(struct amba_device *dev, const char *name)
584{
585 device_initialize(&dev->dev);
586 if (name)
587 dev_set_name(&dev->dev, "%s", name);
588 dev->dev.release = amba_device_release;
589 dev->dev.bus = &amba_bustype;
590 dev->dev.dma_mask = &dev->dma_mask;
591 dev->res.name = dev_name(&dev->dev);
592}
593
594/**
595 * amba_device_alloc - allocate an AMBA device
596 * @name: sysfs name of the AMBA device
597 * @base: base of AMBA device
598 * @size: size of AMBA device
599 *
600 * Allocate and initialize an AMBA device structure. Returns %NULL
601 * on failure.
602 */
603struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
604 size_t size)
605{
606 struct amba_device *dev;
607
608 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
609 if (dev) {
610 amba_device_initialize(dev, name);
611 dev->res.start = base;
612 dev->res.end = base + size - 1;
613 dev->res.flags = IORESOURCE_MEM;
614 }
615
616 return dev;
617}
618EXPORT_SYMBOL_GPL(amba_device_alloc);
619
620/**
621 * amba_device_register - register an AMBA device
622 * @dev: AMBA device to register
623 * @parent: parent memory resource
624 *
625 * Setup the AMBA device, reading the cell ID if present.
626 * Claim the resource, and register the AMBA device with
627 * the Linux device manager.
628 */
629int amba_device_register(struct amba_device *dev, struct resource *parent)
630{
631 amba_device_initialize(dev, dev->dev.init_name);
632 dev->dev.init_name = NULL;
633
634 if (!dev->dev.coherent_dma_mask && dev->dma_mask)
635 dev_warn(&dev->dev, "coherent dma mask is unset\n");
636
637 return amba_device_add(dev, parent);
638}
639
640/**
641 * amba_device_put - put an AMBA device
642 * @dev: AMBA device to put
643 */
644void amba_device_put(struct amba_device *dev)
645{
646 put_device(&dev->dev);
647}
648EXPORT_SYMBOL_GPL(amba_device_put);
599 649
600/** 650/**
601 * amba_device_unregister - unregister an AMBA device 651 * amba_device_unregister - unregister an AMBA device
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 724c69c40bb..e1929620e5a 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -60,6 +60,9 @@ extern struct bus_type amba_bustype;
60 60
61int amba_driver_register(struct amba_driver *); 61int amba_driver_register(struct amba_driver *);
62void amba_driver_unregister(struct amba_driver *); 62void amba_driver_unregister(struct amba_driver *);
63struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
64void amba_device_put(struct amba_device *);
65int amba_device_add(struct amba_device *, struct resource *);
63int amba_device_register(struct amba_device *, struct resource *); 66int amba_device_register(struct amba_device *, struct resource *);
64void amba_device_unregister(struct amba_device *); 67void amba_device_unregister(struct amba_device *);
65struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int); 68struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);