diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2012-04-03 06:58:42 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-04-19 14:31:33 -0400 |
commit | 6026aa907b16677d32593c5b7dea134380f51f7f (patch) | |
tree | 89506b4f6d409e498886410bbf4f8518fb6a1d63 | |
parent | e816b57a337ea3b755de72bec38c10c864f23015 (diff) |
ARM: 7369/1: amba: add functions to add devices dynamically
Add two functions to add APB and AHB devices to the amba (PrimeCell)
bus dynamically. This is modeled after the static definition
macros recently introduced into <linux/amba/bus.h> and can
help us in factoring out a bunch of code across the kernel.
Since a lot of call sites seem to be using a returned struct
amba device* pointer, let's use that.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | drivers/amba/bus.c | 49 | ||||
-rw-r--r-- | include/linux/amba/bus.h | 8 |
2 files changed, 57 insertions, 0 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index cc273226dbd0..9469d8722038 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c | |||
@@ -543,6 +543,55 @@ int amba_device_add(struct amba_device *dev, struct resource *parent) | |||
543 | } | 543 | } |
544 | EXPORT_SYMBOL_GPL(amba_device_add); | 544 | EXPORT_SYMBOL_GPL(amba_device_add); |
545 | 545 | ||
546 | static struct amba_device * | ||
547 | amba_aphb_device_add(struct device *parent, const char *name, | ||
548 | resource_size_t base, size_t size, int irq1, int irq2, | ||
549 | void *pdata, unsigned int periphid, u64 dma_mask) | ||
550 | { | ||
551 | struct amba_device *dev; | ||
552 | int ret; | ||
553 | |||
554 | dev = amba_device_alloc(name, base, size); | ||
555 | if (!dev) | ||
556 | return ERR_PTR(-ENOMEM); | ||
557 | |||
558 | dev->dma_mask = dma_mask; | ||
559 | dev->dev.coherent_dma_mask = dma_mask; | ||
560 | dev->irq[0] = irq1; | ||
561 | dev->irq[1] = irq2; | ||
562 | dev->periphid = periphid; | ||
563 | dev->dev.platform_data = pdata; | ||
564 | dev->dev.parent = parent; | ||
565 | |||
566 | ret = amba_device_add(dev, &iomem_resource); | ||
567 | if (ret) { | ||
568 | amba_device_put(dev); | ||
569 | return ERR_PTR(ret); | ||
570 | } | ||
571 | |||
572 | return dev; | ||
573 | } | ||
574 | |||
575 | struct amba_device * | ||
576 | amba_apb_device_add(struct device *parent, const char *name, | ||
577 | resource_size_t base, size_t size, int irq1, int irq2, | ||
578 | void *pdata, unsigned int periphid) | ||
579 | { | ||
580 | return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata, | ||
581 | periphid, 0); | ||
582 | } | ||
583 | EXPORT_SYMBOL_GPL(amba_apb_device_add); | ||
584 | |||
585 | struct amba_device * | ||
586 | amba_ahb_device_add(struct device *parent, const char *name, | ||
587 | resource_size_t base, size_t size, int irq1, int irq2, | ||
588 | void *pdata, unsigned int periphid) | ||
589 | { | ||
590 | return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata, | ||
591 | periphid, ~0ULL); | ||
592 | } | ||
593 | EXPORT_SYMBOL_GPL(amba_ahb_device_add); | ||
594 | |||
546 | static void amba_device_initialize(struct amba_device *dev, const char *name) | 595 | static void amba_device_initialize(struct amba_device *dev, const char *name) |
547 | { | 596 | { |
548 | device_initialize(&dev->dev); | 597 | device_initialize(&dev->dev); |
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h index 8d54f79457ba..d36417158d8f 100644 --- a/include/linux/amba/bus.h +++ b/include/linux/amba/bus.h | |||
@@ -63,6 +63,14 @@ struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t); | |||
63 | void amba_device_put(struct amba_device *); | 63 | void amba_device_put(struct amba_device *); |
64 | int amba_device_add(struct amba_device *, struct resource *); | 64 | int amba_device_add(struct amba_device *, struct resource *); |
65 | int amba_device_register(struct amba_device *, struct resource *); | 65 | int amba_device_register(struct amba_device *, struct resource *); |
66 | struct amba_device *amba_apb_device_add(struct device *parent, const char *name, | ||
67 | resource_size_t base, size_t size, | ||
68 | int irq1, int irq2, void *pdata, | ||
69 | unsigned int periphid); | ||
70 | struct amba_device *amba_ahb_device_add(struct device *parent, const char *name, | ||
71 | resource_size_t base, size_t size, | ||
72 | int irq1, int irq2, void *pdata, | ||
73 | unsigned int periphid); | ||
66 | void amba_device_unregister(struct amba_device *); | 74 | void amba_device_unregister(struct amba_device *); |
67 | struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int); | 75 | struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int); |
68 | int amba_request_regions(struct amba_device *, const char *); | 76 | int amba_request_regions(struct amba_device *, const char *); |