From: Grant Likely <grant.likely@secretlab.ca>
To: linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org,
paulus@samba.org, axboe@kernel.dk
Subject: [PATCH v2 3/6] Sysace: Move structure allocation from bus binding into common code
Date: Sun, 30 Sep 2007 16:57:15 -0600 [thread overview]
Message-ID: <20070930225714.2476.37031.stgit@trillian.cg.shawcable.net> (raw)
In-Reply-To: <20070930225112.2476.49914.stgit@trillian.cg.shawcable.net>
From: Grant Likely <grant.likely@secretlab.ca>
Split the determination of device registers/irqs/etc from the actual
allocation and initialization of the device structure. This cleans
up the code a bit in preparation to add an of_platform bus binding
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
drivers/block/xsysace.c | 99 +++++++++++++++++++++++++++++------------------
1 files changed, 61 insertions(+), 38 deletions(-)
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index b104476..555939b 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -1033,7 +1033,7 @@ static int __devinit ace_setup(struct ace_device *ace)
if (ace->irq != NO_IRQ)
free_irq(ace->irq, ace);
err_ioremap:
- printk(KERN_INFO "xsysace: error initializing device at 0x%lx\n",
+ dev_info(ace->dev, "xsysace: error initializing device at 0x%lx\n",
ace->physaddr);
return -ENOMEM;
}
@@ -1056,68 +1056,91 @@ static void __devexit ace_teardown(struct ace_device *ace)
iounmap(ace->baseaddr);
}
-/* ---------------------------------------------------------------------
- * Platform Bus Support
- */
-
-static int __devinit ace_probe(struct platform_device *dev)
+static int __devinit
+ace_alloc(struct device *dev, int id, unsigned long physaddr,
+ int irq, int bus_width)
{
struct ace_device *ace;
- int i;
+ int rc;
+ dev_dbg(dev, "ace_alloc(%p)\n", dev);
- dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
+ if (!physaddr) {
+ rc = -ENODEV;
+ goto err_noreg;
+ }
- /*
- * Allocate the ace device structure
- */
+ /* Allocate and initialize the ace device structure */
ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL);
- if (!ace)
+ if (!ace) {
+ rc = -ENOMEM;
goto err_alloc;
-
- ace->dev = &dev->dev;
- ace->id = dev->id;
- ace->irq = NO_IRQ;
-
- for (i = 0; i < dev->num_resources; i++) {
- if (dev->resource[i].flags & IORESOURCE_MEM)
- ace->physaddr = dev->resource[i].start;
- if (dev->resource[i].flags & IORESOURCE_IRQ)
- ace->irq = dev->resource[i].start;
}
- /* FIXME: Should get bus_width from the platform_device struct */
- ace->bus_width = 1;
-
- platform_set_drvdata(dev, ace);
+ ace->dev = dev;
+ ace->id = id;
+ ace->physaddr = physaddr;
+ ace->irq = irq;
+ ace->bus_width = bus_width;
- /* Call the bus-independant setup code */
- if (ace_setup(ace) != 0)
+ /* Call the setup code */
+ if ((rc = ace_setup(ace)) != 0)
goto err_setup;
+ dev_set_drvdata(dev, ace);
return 0;
err_setup:
- platform_set_drvdata(dev, NULL);
+ dev_set_drvdata(dev, NULL);
kfree(ace);
err_alloc:
- printk(KERN_ERR "xsysace: could not initialize device\n");
- return -ENOMEM;
+ err_noreg:
+ dev_err(dev, "could not initialize device, err=%i\n", rc);
+ return rc;
}
-/*
- * Platform bus remove() method
- */
-static int __devexit ace_remove(struct platform_device *dev)
+static void __devexit ace_free(struct device *dev)
{
- struct ace_device *ace = platform_get_drvdata(dev);
- dev_dbg(&dev->dev, "ace_remove(%p)\n", dev);
+ struct ace_device *ace = dev_get_drvdata(dev);
+ dev_dbg(dev, "ace_free(%p)\n", dev);
if (ace) {
ace_teardown(ace);
- platform_set_drvdata(dev, NULL);
+ dev_set_drvdata(dev, NULL);
kfree(ace);
}
+}
+
+/* ---------------------------------------------------------------------
+ * Platform Bus Support
+ */
+
+static int __devinit ace_probe(struct platform_device *dev)
+{
+ unsigned long physaddr = 0;
+ int bus_width = 1; /* FIXME: should not be hard coded */
+ int id = dev->id;
+ int irq = NO_IRQ;
+ int i;
+
+ dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
+
+ for (i = 0; i < dev->num_resources; i++) {
+ if (dev->resource[i].flags & IORESOURCE_MEM)
+ physaddr = dev->resource[i].start;
+ if (dev->resource[i].flags & IORESOURCE_IRQ)
+ irq = dev->resource[i].start;
+ }
+
+ /* Call the bus-independant setup code */
+ return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);
+}
+/*
+ * Platform bus remove() method
+ */
+static int __devexit ace_remove(struct platform_device *dev)
+{
+ ace_free(&dev->dev);
return 0;
}
next prev parent reply other threads:[~2007-09-30 22:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-30 22:56 [PATCH v2 0/6] SystemACE: rework and of_platform bus binding patches Grant Likely
2007-09-30 22:57 ` [PATCH v2 1/6] Add Xilinx SystemACE entry to maintainers Grant Likely
2007-09-30 22:57 ` [PATCH v2 2/6] Sysace: Use the established platform bus api Grant Likely
2007-09-30 23:05 ` Christoph Hellwig
2007-09-30 23:33 ` Grant Likely
2007-10-01 11:59 ` Jens Axboe
2007-10-01 13:17 ` Grant Likely
2007-10-02 5:58 ` Benjamin Herrenschmidt
2007-10-02 6:35 ` Jens Axboe
2007-10-02 13:52 ` Grant Likely
2007-09-30 22:57 ` Grant Likely [this message]
2007-09-30 22:57 ` [PATCH v2 4/6] Sysace: minor rework and cleanup changes Grant Likely
2007-09-30 22:57 ` [PATCH v2 5/6] Sysace: Move IRQ handler registration to occur after FSM is initialized Grant Likely
2007-10-02 5:55 ` Benjamin Herrenschmidt
2007-10-02 13:57 ` Grant Likely
2007-09-30 22:57 ` [PATCH v2 6/6] Sysace: Add of_platform_bus binding Grant Likely
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=20070930225714.2476.37031.stgit@trillian.cg.shawcable.net \
--to=grant.likely@secretlab.ca \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@samba.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
Powered by JetHome