All of lore.kernel.org
 help / color / mirror / Atom feed
From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/30] dma: mv_xor: split initialization/cleanup of XOR channels
Date: Mon, 19 Nov 2012 11:04:41 +0100	[thread overview]
Message-ID: <1353319508-30566-4-git-send-email-thomas.petazzoni@free-electrons.com> (raw)
In-Reply-To: <1353319508-30566-1-git-send-email-thomas.petazzoni@free-electrons.com>

Instead of doing the initialization/cleanup of the XOR channels
directly in the ->probe() and ->remove() hooks, we create separate
utility functions mv_xor_channel_add() and mv_xor_channel_remove().

This will allow to easily introduce in a future patch a different way
of registering XOR channels: instead of having one platform_device per
channel, we'll trigger the registration of all XOR channels of a given
XOR engine directly from the XOR engine ->probe() function.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 drivers/dma/mv_xor.c |   75 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 48 insertions(+), 27 deletions(-)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 7042772..f7b9919 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -1077,19 +1077,18 @@ out:
 	return err;
 }
 
-static int __devexit mv_xor_remove(struct platform_device *dev)
+static int mv_xor_channel_remove(struct mv_xor_device *device)
 {
-	struct mv_xor_device *device = platform_get_drvdata(dev);
 	struct dma_chan *chan, *_chan;
 	struct mv_xor_chan *mv_chan;
 
 	dma_async_device_unregister(&device->common);
 
-	dma_free_coherent(&dev->dev, device->pool_size,
-			device->dma_desc_pool_virt, device->dma_desc_pool);
+	dma_free_coherent(&device->pdev->dev, device->pool_size,
+			  device->dma_desc_pool_virt, device->dma_desc_pool);
 
 	list_for_each_entry_safe(chan, _chan, &device->common.channels,
-				device_node) {
+				 device_node) {
 		mv_chan = to_mv_xor_chan(chan);
 		list_del(&chan->device_node);
 	}
@@ -1097,19 +1096,20 @@ static int __devexit mv_xor_remove(struct platform_device *dev)
 	return 0;
 }
 
-static int __devinit mv_xor_probe(struct platform_device *pdev)
+static struct mv_xor_device *
+mv_xor_channel_add(struct mv_xor_shared_private *msp,
+		   struct platform_device *pdev,
+		   int hw_id, dma_cap_mask_t cap_mask,
+		   size_t pool_size, int irq)
 {
 	int ret = 0;
-	int irq;
 	struct mv_xor_device *adev;
 	struct mv_xor_chan *mv_chan;
 	struct dma_device *dma_dev;
-	struct mv_xor_platform_data *plat_data = pdev->dev.platform_data;
-
 
 	adev = devm_kzalloc(&pdev->dev, sizeof(*adev), GFP_KERNEL);
 	if (!adev)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	dma_dev = &adev->common;
 
@@ -1117,22 +1117,20 @@ static int __devinit mv_xor_probe(struct platform_device *pdev)
 	 * note: writecombine gives slightly better performance, but
 	 * requires that we explicitly flush the writes
 	 */
-	adev->pool_size = plat_data->pool_size;
+	adev->pool_size = pool_size;
 	adev->dma_desc_pool_virt = dma_alloc_writecombine(&pdev->dev,
 							  adev->pool_size,
 							  &adev->dma_desc_pool,
 							  GFP_KERNEL);
 	if (!adev->dma_desc_pool_virt)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
-	adev->id = plat_data->hw_id;
+	adev->id = hw_id;
 
 	/* discover transaction capabilites from the platform data */
-	dma_dev->cap_mask = plat_data->cap_mask;
+	dma_dev->cap_mask = cap_mask;
 	adev->pdev = pdev;
-	platform_set_drvdata(pdev, adev);
-
-	adev->shared = platform_get_drvdata(plat_data->shared);
+	adev->shared = msp;
 
 	INIT_LIST_HEAD(&dma_dev->channels);
 
@@ -1159,7 +1157,7 @@ static int __devinit mv_xor_probe(struct platform_device *pdev)
 		goto err_free_dma;
 	}
 	mv_chan->device = adev;
-	mv_chan->idx = plat_data->hw_id;
+	mv_chan->idx = hw_id;
 	mv_chan->mmr_base = adev->shared->xor_base;
 
 	if (!mv_chan->mmr_base) {
@@ -1172,11 +1170,6 @@ static int __devinit mv_xor_probe(struct platform_device *pdev)
 	/* clear errors before enabling interrupts */
 	mv_xor_device_clear_err_status(mv_chan);
 
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0) {
-		ret = irq;
-		goto err_free_dma;
-	}
 	ret = devm_request_irq(&pdev->dev, irq,
 			       mv_xor_interrupt_handler,
 			       0, dev_name(&pdev->dev), mv_chan);
@@ -1218,13 +1211,41 @@ static int __devinit mv_xor_probe(struct platform_device *pdev)
 	  dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
 
 	dma_async_device_register(dma_dev);
-	goto out;
+	return adev;
 
  err_free_dma:
-	dma_free_coherent(&adev->pdev->dev, plat_data->pool_size,
+	dma_free_coherent(&adev->pdev->dev, pool_size,
 			adev->dma_desc_pool_virt, adev->dma_desc_pool);
- out:
-	return ret;
+	return ERR_PTR(ret);
+}
+
+static int __devexit mv_xor_remove(struct platform_device *pdev)
+{
+	struct mv_xor_device *device = platform_get_drvdata(pdev);
+	return mv_xor_channel_remove(device);
+}
+
+static int __devinit mv_xor_probe(struct platform_device *pdev)
+{
+	struct mv_xor_platform_data *plat_data = pdev->dev.platform_data;
+	struct mv_xor_shared_private *msp =
+		platform_get_drvdata(plat_data->shared);
+	struct mv_xor_device *mv_xor_device;
+	int irq;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	mv_xor_device = mv_xor_channel_add(msp, pdev, plat_data->hw_id,
+					   plat_data->cap_mask,
+					   plat_data->pool_size, irq);
+	if (IS_ERR(mv_xor_device))
+		return PTR_ERR(mv_xor_device);
+
+	platform_set_drvdata(pdev, mv_xor_device);
+
+	return 0;
 }
 
 static void
-- 
1.7.9.5

  parent reply	other threads:[~2012-11-19 10:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19 10:04 [GIT PULL] Marvell XOR driver cleanup and DT binding Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 01/30] dma: mv_xor: use dev_(err|info|notice) instead of dev_printk Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 02/30] dma: mv_xor: do not use pool_size from platform_data within the driver Thomas Petazzoni
2012-11-19 10:04 ` Thomas Petazzoni [this message]
2012-11-19 10:04 ` [PATCH 04/30] dma: mv_xor: allow channels to be registered directly from the main device Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 05/30] arm: plat-orion: convert the registration of the xor0 engine to the single driver Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 06/30] arm: plat-orion: convert the registration of the xor1 " Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 07/30] arm: plat-orion: remove unused orion_xor_init_channels() Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 08/30] dma: mv_xor: remove sub-driver 'mv_xor' Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 09/30] dma: mv_xor: remove 'shared' from mv_xor_platform_data Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 10/30] dma: mv_xor: rename mv_xor_platform_data to mv_xor_channel_data Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 11/30] dma: mv_xor: rename mv_xor_shared_platform_data to mv_xor_platform_data Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 12/30] dma: mv_xor: change the driver name to 'mv_xor' Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 13/30] dma: mv_xor: rename many symbols to remove the 'shared' word Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 14/30] dma: mv_xor: remove unused id field in mv_xor_device structure Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 15/30] dma: mv_xor: remove unused to_mv_xor_device() macro Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 16/30] dma: mv_xor: simplify dma_sync_single_for_cpu() calls Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 17/30] dma: mv_xor: introduce a mv_chan_to_devp() helper Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 18/30] dma: mv_xor: get rid of the pdev pointer in mv_xor_device Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 19/30] dma: mv_xor: in mv_xor_chan, rename 'common' to 'dmachan' Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 20/30] dma: mv_xor: in mv_xor_device, rename 'common' to 'dmadev' Thomas Petazzoni
2012-11-19 10:04 ` [PATCH 21/30] dma: mv_xor: use mv_xor_chan pointers as arguments to self-test functions Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 22/30] dma: mv_xor: merge mv_xor_device and mv_xor_chan Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 23/30] dma: mv_xor: rename mv_xor_private to mv_xor_device Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 24/30] dma: mv_xor: remove useless backpointer from mv_xor_chan " Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 25/30] dma: mv_xor: remove hw_id field from platform_data Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 26/30] dma: mv_xor: remove the pool_size " Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 27/30] dma: mv_xor: add missing free_irq() call Thomas Petazzoni
     [not found] ` <1353319508-30566-1-git-send-email-thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2012-11-19 10:05   ` [PATCH 28/30] dma: mv_xor: add Device Tree binding Thomas Petazzoni
2012-11-19 10:05     ` Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 29/30] dma: mv_xor: add missing __devinit and __devexit qualifiers on probe and remove Thomas Petazzoni
2012-11-19 10:05 ` [PATCH 30/30] dma: mv_xor: Add a device_control function Thomas Petazzoni

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=1353319508-30566-4-git-send-email-thomas.petazzoni@free-electrons.com \
    --to=thomas.petazzoni@free-electrons.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.