From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 01/31] ARM: amba: add amba_device allocation/add/put functions
Date: Fri, 20 Jan 2012 09:22:43 +0000 [thread overview]
Message-ID: <E1RoAgF-0005EI-Sg@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20120120092207.GD1068@n2100.arm.linux.org.uk>
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>
---
drivers/amba/bus.c | 100 ++++++++++++++++++++++++++++++++++-----------
include/linux/amba/bus.h | 3 +
2 files changed, 78 insertions(+), 25 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 54eaf96..82b65e1 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -497,38 +497,20 @@ static void amba_device_release(struct device *dev)
}
/**
- * amba_device_register - register an AMBA device
- * @dev: AMBA device to register
- * @parent: parent memory resource
+ * amba_device_add - add a previously allocated AMBA device structure
+ * @dev: AMBA device allocated by amba_device_alloc
+ * @parent: resource parent for this devices resources
*
- * Setup the AMBA device, reading the cell ID if present.
- * Claim the resource, and register the AMBA device with
- * the Linux device manager.
+ * Claim the resource, and read the device cell ID if not already
+ * initialized. Register the AMBA device with the Linux device
+ * manager.
*/
-int amba_device_register(struct amba_device *dev, struct resource *parent)
+int amba_device_add(struct amba_device *dev, struct resource *parent)
{
u32 size;
void __iomem *tmp;
int i, ret;
- device_initialize(&dev->dev);
-
- /*
- * Copy from device_add
- */
- if (dev->dev.init_name) {
- dev_set_name(&dev->dev, "%s", dev->dev.init_name);
- dev->dev.init_name = NULL;
- }
-
- dev->dev.release = amba_device_release;
- dev->dev.bus = &amba_bustype;
- dev->dev.dma_mask = &dev->dma_mask;
- dev->res.name = dev_name(&dev->dev);
-
- if (!dev->dev.coherent_dma_mask && dev->dma_mask)
- dev_warn(&dev->dev, "coherent dma mask is unset\n");
-
ret = request_resource(parent, &dev->res);
if (ret)
goto err_out;
@@ -596,6 +578,74 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
err_out:
return ret;
}
+EXPORT_SYMBOL_GPL(amba_device_add);
+
+static void amba_device_initialize(struct amba_device *dev, const char *name)
+{
+ device_initialize(&dev->dev);
+ if (name)
+ dev_set_name(&dev->dev, "%s", name);
+ dev->dev.release = amba_device_release;
+ dev->dev.bus = &amba_bustype;
+ dev->dev.dma_mask = &dev->dma_mask;
+ dev->res.name = dev_name(&dev->dev);
+}
+
+/**
+ * amba_device_alloc - allocate an AMBA device
+ * @name: sysfs name of the AMBA device
+ * @base: base of AMBA device
+ * @size: size of AMBA device
+ *
+ * Allocate and initialize an AMBA device structure. Returns %NULL
+ * on failure.
+ */
+struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
+ size_t size)
+{
+ struct amba_device *dev;
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (dev) {
+ amba_device_initialize(dev, name);
+ dev->res.start = base;
+ dev->res.end = base + size - 1;
+ dev->res.flags = IORESOURCE_MEM;
+ }
+
+ return dev;
+}
+EXPORT_SYMBOL_GPL(amba_device_alloc);
+
+/**
+ * amba_device_register - register an AMBA device
+ * @dev: AMBA device to register
+ * @parent: parent memory resource
+ *
+ * Setup the AMBA device, reading the cell ID if present.
+ * Claim the resource, and register the AMBA device with
+ * the Linux device manager.
+ */
+int amba_device_register(struct amba_device *dev, struct resource *parent)
+{
+ amba_device_initialize(dev, dev->dev.init_name);
+ dev->dev.init_name = NULL;
+
+ if (!dev->dev.coherent_dma_mask && dev->dma_mask)
+ dev_warn(&dev->dev, "coherent dma mask is unset\n");
+
+ return amba_device_add(dev, parent);
+}
+
+/**
+ * amba_device_put - put an AMBA device
+ * @dev: AMBA device to put
+ */
+void amba_device_put(struct amba_device *dev)
+{
+ put_device(&dev->dev);
+}
+EXPORT_SYMBOL_GPL(amba_device_put);
/**
* amba_device_unregister - unregister an AMBA device
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 724c69c..e192962 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -60,6 +60,9 @@ extern struct bus_type amba_bustype;
int amba_driver_register(struct amba_driver *);
void amba_driver_unregister(struct amba_driver *);
+struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
+void amba_device_put(struct amba_device *);
+int amba_device_add(struct amba_device *, struct resource *);
int amba_device_register(struct amba_device *, struct resource *);
void amba_device_unregister(struct amba_device *);
struct amba_device *amba_find_device(const char *, struct device *, unsigned int, unsigned int);
--
1.7.4.4
next prev parent reply other threads:[~2012-01-20 9:22 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-20 9:22 [PATCH 00/31] Clean up amba/primecell bus support Russell King - ARM Linux
2012-01-20 9:22 ` Russell King - ARM Linux [this message]
2012-01-20 9:23 ` [PATCH 02/31] ARM: amba: of: convert to use amba_device_alloc Russell King - ARM Linux
2012-01-20 13:58 ` Rob Herring
2012-01-20 9:23 ` [PATCH 03/31] ARM: amba: ux500: " Russell King - ARM Linux
2012-01-21 16:21 ` Srinidhi KASAGAR
2012-01-23 19:03 ` Linus Walleij
2012-01-20 9:23 ` [PATCH 04/31] ARM: amba: integrator: " Russell King - ARM Linux
2012-01-20 9:24 ` [PATCH 05/31] ARM: amba: mxs: " Russell King - ARM Linux
2012-01-20 12:25 ` Shawn Guo
2012-01-20 12:39 ` Russell King - ARM Linux
2012-01-20 9:24 ` [PATCH 06/31] ARM: amba: make irq 0 invalid Russell King - ARM Linux
2012-01-20 9:24 ` [PATCH 07/31] ARM: amba: ux500: get rid of NO_IRQ Russell King - ARM Linux
2012-01-21 16:19 ` Srinidhi KASAGAR
2012-01-23 19:04 ` Linus Walleij
2012-01-20 9:25 ` [PATCH 08/31] ARM: amba: get rid of NO_IRQ initializers Russell King - ARM Linux
2012-01-20 9:25 ` [PATCH 09/31] ARM: amba: samsung: " Russell King - ARM Linux
2012-01-21 0:28 ` Kukjin Kim
2012-01-20 9:25 ` [PATCH 10/31] ARM: amba: integrator/realview/versatile/vexpress: " Russell King - ARM Linux
2012-01-20 9:26 ` [PATCH 11/31] ARM: amba: lpc32xx: " Russell King - ARM Linux
2012-01-20 9:26 ` [PATCH 12/31] ARM: amba: mxs: " Russell King - ARM Linux
2012-01-20 12:27 ` Shawn Guo
2012-01-20 9:26 ` [PATCH 13/31] ARM: amba: nomadik: " Russell King - ARM Linux
2012-01-23 19:02 ` Linus Walleij
2012-01-20 9:27 ` [PATCH 14/31] ARM: amba: netx: " Russell King - ARM Linux
2012-01-20 9:27 ` [PATCH 15/31] ARM: amba: spear: " Russell King - ARM Linux
2012-01-20 9:30 ` Viresh Kumar
2012-01-20 9:27 ` [PATCH 16/31] ARM: amba: u300: " Russell King - ARM Linux
2012-01-23 19:04 ` Linus Walleij
2012-01-20 9:28 ` [PATCH 17/31] ARM: amba: make use of -1 IRQs warn Russell King - ARM Linux
2012-01-20 9:28 ` [PATCH 18/31] ARM: amba: provide common initializers for static amba devices Russell King - ARM Linux
2012-01-20 17:58 ` H Hartley Sweeten
2012-01-20 9:28 ` [PATCH 19/31] ARM: amba: vexpress: get rid of private platform amba_device initializer Russell King - ARM Linux
2012-01-24 14:27 ` Will Deacon
2012-01-20 9:29 ` [PATCH 20/31] ARM: amba: versatile: " Russell King - ARM Linux
2012-01-24 15:06 ` Will Deacon
2012-01-20 9:29 ` [PATCH 21/31] ARM: amba: realview: " Russell King - ARM Linux
2012-01-24 16:00 ` Will Deacon
2012-01-24 16:23 ` Russell King - ARM Linux
2012-01-24 17:26 ` Will Deacon
2012-01-24 21:23 ` Linus Walleij
2012-01-24 21:45 ` Russell King - ARM Linux
2012-01-25 9:58 ` Will Deacon
2012-01-25 10:22 ` Russell King - ARM Linux
2012-01-25 10:39 ` Will Deacon
2012-01-25 11:06 ` Russell King - ARM Linux
2012-01-26 17:25 ` Russell King - ARM Linux
2012-01-26 17:37 ` Will Deacon
2012-01-26 17:41 ` Russell King - ARM Linux
2012-01-20 9:29 ` [PATCH 22/31] ARM: amba: integrator: use common amba device initializers Russell King - ARM Linux
2012-01-24 16:13 ` Will Deacon
2012-01-20 9:30 ` [PATCH 23/31] ARM: amba: omap2: " Russell King - ARM Linux
2012-01-20 14:37 ` Tony Lindgren
2012-01-20 9:30 ` [PATCH 24/31] ARM: amba: ep93xx: " Russell King - ARM Linux
2012-01-20 16:56 ` H Hartley Sweeten
2012-01-20 9:30 ` [PATCH 25/31] ARM: amba: bcmring: " Russell King - ARM Linux
2012-01-20 9:31 ` [PATCH 26/31] ARM: amba: netx: " Russell King - ARM Linux
2012-01-20 9:31 ` [PATCH 27/31] ARM: amba: lpc32xx: " Russell King - ARM Linux
2012-01-20 9:31 ` [PATCH 28/31] ARM: amba: u300: " Russell King - ARM Linux
2012-01-23 19:05 ` Linus Walleij
2012-01-20 9:32 ` [PATCH 29/31] ARM: amba: nomadik: " Russell King - ARM Linux
2012-01-23 19:02 ` Linus Walleij
2012-01-20 9:32 ` [PATCH 30/31] ARM: amba: spear: " Russell King - ARM Linux
2012-01-20 9:38 ` Viresh Kumar
2012-01-20 9:32 ` [PATCH 31/31] ARM: amba: samsung: " Russell King - ARM Linux
2012-01-21 0:45 ` Kukjin Kim
2012-01-20 22:33 ` [PATCH 13/31] ARM: amba: nomadik: get rid of NO_IRQ initializers Alessandro Rubini
2012-01-20 22:33 ` [PATCH 29/31] ARM: amba: nomadik: use common amba device initializers Alessandro Rubini
2012-01-21 0:59 ` [PATCH 00/31] Clean up amba/primecell bus support Kukjin Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1RoAgF-0005EI-Sg@rmk-PC.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).