Commit 6026aa907b16677d32593c5b7dea134380f51f7f

Authored by Linus Walleij
Committed by Russell King
1 parent e816b57a33

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>

Showing 2 changed files with 57 additions and 0 deletions Side-by-side Diff

... ... @@ -543,6 +543,55 @@
543 543 }
544 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 595 static void amba_device_initialize(struct amba_device *dev, const char *name)
547 596 {
548 597 device_initialize(&dev->dev);
include/linux/amba/bus.h
... ... @@ -63,6 +63,14 @@
63 63 void amba_device_put(struct amba_device *);
64 64 int amba_device_add(struct amba_device *, struct resource *);
65 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 74 void amba_device_unregister(struct amba_device *);
67 75 struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
68 76 int amba_request_regions(struct amba_device *, const char *);