public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@arm.linux.org.uk>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH RFC 42/51] DMA-API: usb: musb: use platform_device_register_full() to avoid directly messing with dma masks
Date: Thu, 01 Aug 2013 23:16:13 +0100	[thread overview]
Message-ID: <E1V51AL-0006tr-8k@rmk-PC.arm.linux.org.uk> (raw)
In-Reply-To: <20130801213420.GL23006@n2100.arm.linux.org.uk>

Use platform_device_register_full() for those drivers which can, to
avoid messing directly with DMA masks.  This can only be done when
the driver does not need to access the allocated musb platform device
from within its callbacks, which may be called during the musb
device probing.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
---
 drivers/usb/musb/am35x.c    |   50 ++++++++++++++----------------------------
 drivers/usb/musb/da8xx.c    |   49 ++++++++++++++---------------------------
 drivers/usb/musb/davinci.c  |   48 ++++++++++++++--------------------------
 drivers/usb/musb/tusb6010.c |   49 ++++++++++++++---------------------------
 4 files changed, 68 insertions(+), 128 deletions(-)

diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 2231850..a8d3eb3 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -89,7 +89,6 @@ struct am35x_glue {
 	struct clk		*phy_clk;
 	struct clk		*clk;
 };
-#define glue_to_musb(g)		platform_get_drvdata(g->musb)
 
 /*
  * am35x_musb_enable - enable interrupts
@@ -452,14 +451,18 @@ static const struct musb_platform_ops am35x_ops = {
 	.set_vbus	= am35x_musb_set_vbus,
 };
 
-static u64 am35x_dmamask = DMA_BIT_MASK(32);
+static const struct platform_device_info am35x_dev_info = {
+	.name		= "musb-hdrc",
+	.id		= PLATFORM_DEVID_AUTO,
+	.dma_mask	= DMA_BIT_MASK(32),
+};
 
 static int am35x_probe(struct platform_device *pdev)
 {
 	struct musb_hdrc_platform_data	*pdata = pdev->dev.platform_data;
 	struct platform_device		*musb;
 	struct am35x_glue		*glue;
-
+	struct platform_device_info	pinfo;
 	struct clk			*phy_clk;
 	struct clk			*clk;
 
@@ -471,12 +474,6 @@ static int am35x_probe(struct platform_device *pdev)
 		goto err0;
 	}
 
-	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
-	if (!musb) {
-		dev_err(&pdev->dev, "failed to allocate musb device\n");
-		goto err1;
-	}
-
 	phy_clk = clk_get(&pdev->dev, "fck");
 	if (IS_ERR(phy_clk)) {
 		dev_err(&pdev->dev, "failed to get PHY clock\n");
@@ -503,12 +500,7 @@ static int am35x_probe(struct platform_device *pdev)
 		goto err6;
 	}
 
-	musb->dev.parent		= &pdev->dev;
-	musb->dev.dma_mask		= &am35x_dmamask;
-	musb->dev.coherent_dma_mask	= am35x_dmamask;
-
 	glue->dev			= &pdev->dev;
-	glue->musb			= musb;
 	glue->phy_clk			= phy_clk;
 	glue->clk			= clk;
 
@@ -516,22 +508,17 @@ static int am35x_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, glue);
 
-	ret = platform_device_add_resources(musb, pdev->resource,
-			pdev->num_resources);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add resources\n");
-		goto err7;
-	}
-
-	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add platform_data\n");
-		goto err7;
-	}
-
-	ret = platform_device_add(musb);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register musb device\n");
+	pinfo = am35x_dev_info;
+	pinfo.parent = &pdev->dev;
+	pinfo.res = pdev->resource;
+	pinfo.num_res = pdev->num_resources;
+	pinfo.data = pdata;
+	pinfo.size_data = sizeof(*pdata);
+
+	glue->musb = musb = platform_device_register_full(&pinfo);
+	if (IS_ERR(musb)) {
+		ret = PTR_ERR(musb);
+		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
 		goto err7;
 	}
 
@@ -550,9 +537,6 @@ static int am35x_probe(struct platform_device *pdev)
 	clk_put(phy_clk);
 
 err3:
-	platform_device_put(musb);
-
-err1:
 	kfree(glue);
 
 err0:
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 0da6f64..57402e3 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -472,7 +472,11 @@ static const struct musb_platform_ops da8xx_ops = {
 	.set_vbus	= da8xx_musb_set_vbus,
 };
 
-static u64 da8xx_dmamask = DMA_BIT_MASK(32);
+static const struct platform_device_info da8xx_dev_info = {
+	.name		= "musb-hdrc",
+	.id		= PLATFORM_DEVID_AUTO,
+	.dma_mask	= DMA_BIT_MASK(32),
+};
 
 static int da8xx_probe(struct platform_device *pdev)
 {
@@ -480,7 +484,7 @@ static int da8xx_probe(struct platform_device *pdev)
 	struct musb_hdrc_platform_data	*pdata = pdev->dev.platform_data;
 	struct platform_device		*musb;
 	struct da8xx_glue		*glue;
-
+	struct platform_device_info	pinfo;
 	struct clk			*clk;
 
 	int				ret = -ENOMEM;
@@ -491,12 +495,6 @@ static int da8xx_probe(struct platform_device *pdev)
 		goto err0;
 	}
 
-	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
-	if (!musb) {
-		dev_err(&pdev->dev, "failed to allocate musb device\n");
-		goto err1;
-	}
-
 	clk = clk_get(&pdev->dev, "usb20");
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
@@ -510,12 +508,7 @@ static int da8xx_probe(struct platform_device *pdev)
 		goto err4;
 	}
 
-	musb->dev.parent		= &pdev->dev;
-	musb->dev.dma_mask		= &da8xx_dmamask;
-	musb->dev.coherent_dma_mask	= da8xx_dmamask;
-
 	glue->dev			= &pdev->dev;
-	glue->musb			= musb;
 	glue->clk			= clk;
 
 	pdata->platform_ops		= &da8xx_ops;
@@ -535,22 +528,17 @@ static int da8xx_probe(struct platform_device *pdev)
 	musb_resources[1].end = pdev->resource[1].end;
 	musb_resources[1].flags = pdev->resource[1].flags;
 
-	ret = platform_device_add_resources(musb, musb_resources,
-			ARRAY_SIZE(musb_resources));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add resources\n");
-		goto err5;
-	}
-
-	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add platform_data\n");
-		goto err5;
-	}
-
-	ret = platform_device_add(musb);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register musb device\n");
+	pinfo = da8xx_dev_info;
+	pinfo.parent = &pdev->dev;
+	pinfo.res = musb_resources;
+	pinfo.num_res = ARRAY_SIZE(musb_resources);
+	pinfo.data = pdata;
+	pinfo.size_data = sizeof(*pdata);
+
+	glue->musb = musb = platform_device_register_full(&pinfo);
+	if (IS_ERR(musb)) {
+		ret = PTR_ERR(musb);
+		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
 		goto err5;
 	}
 
@@ -563,9 +551,6 @@ static int da8xx_probe(struct platform_device *pdev)
 	clk_put(clk);
 
 err3:
-	platform_device_put(musb);
-
-err1:
 	kfree(glue);
 
 err0:
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index f8aeaf2..a55f2e3 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -505,7 +505,11 @@ static const struct musb_platform_ops davinci_ops = {
 	.set_vbus	= davinci_musb_set_vbus,
 };
 
-static u64 davinci_dmamask = DMA_BIT_MASK(32);
+static const struct platform_device_info davinci_dev_info = {
+	.name		= "musb-hdrc",
+	.id		= PLATFORM_DEVID_AUTO,
+	.dma_mask	= DMA_BIT_MASK(32),
+};
 
 static int davinci_probe(struct platform_device *pdev)
 {
@@ -513,6 +517,7 @@ static int davinci_probe(struct platform_device *pdev)
 	struct musb_hdrc_platform_data	*pdata = pdev->dev.platform_data;
 	struct platform_device		*musb;
 	struct davinci_glue		*glue;
+	struct platform_device_info	pinfo;
 	struct clk			*clk;
 
 	int				ret = -ENOMEM;
@@ -523,12 +528,6 @@ static int davinci_probe(struct platform_device *pdev)
 		goto err0;
 	}
 
-	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
-	if (!musb) {
-		dev_err(&pdev->dev, "failed to allocate musb device\n");
-		goto err1;
-	}
-
 	clk = clk_get(&pdev->dev, "usb");
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
@@ -542,12 +541,7 @@ static int davinci_probe(struct platform_device *pdev)
 		goto err4;
 	}
 
-	musb->dev.parent		= &pdev->dev;
-	musb->dev.dma_mask		= &davinci_dmamask;
-	musb->dev.coherent_dma_mask	= davinci_dmamask;
-
 	glue->dev			= &pdev->dev;
-	glue->musb			= musb;
 	glue->clk			= clk;
 
 	pdata->platform_ops		= &davinci_ops;
@@ -567,22 +561,17 @@ static int davinci_probe(struct platform_device *pdev)
 	musb_resources[1].end = pdev->resource[1].end;
 	musb_resources[1].flags = pdev->resource[1].flags;
 
-	ret = platform_device_add_resources(musb, musb_resources,
-			ARRAY_SIZE(musb_resources));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add resources\n");
-		goto err5;
-	}
-
-	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add platform_data\n");
-		goto err5;
-	}
-
-	ret = platform_device_add(musb);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register musb device\n");
+	pinfo = davinci_dev_info;
+	pinfo.parent = &pdev->dev;
+	pinfo.res = musb_resources;
+	pinfo.num_res = ARRAY_SIZE(musb_resources);
+	pinfo.data = pdata;
+	pinfo.size_data = sizeof(*pdata);
+
+	glue->musb = musb = platform_device_register_full(&pinfo);
+	if (IS_ERR(musb)) {
+		ret = PTR_ERR(musb);
+		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
 		goto err5;
 	}
 
@@ -595,9 +584,6 @@ static int davinci_probe(struct platform_device *pdev)
 	clk_put(clk);
 
 err3:
-	platform_device_put(musb);
-
-err1:
 	kfree(glue);
 
 err0:
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 2c06a89..021c00e8 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1152,7 +1152,11 @@ static const struct musb_platform_ops tusb_ops = {
 	.set_vbus	= tusb_musb_set_vbus,
 };
 
-static u64 tusb_dmamask = DMA_BIT_MASK(32);
+static const struct platform_device_info tusb_dev_info = {
+	.name		= "musb-hdrc",
+	.id		= PLATFORM_DEVID_AUTO,
+	.dma_mask	= DMA_BIT_MASK(32),
+};
 
 static int tusb_probe(struct platform_device *pdev)
 {
@@ -1160,7 +1164,7 @@ static int tusb_probe(struct platform_device *pdev)
 	struct musb_hdrc_platform_data	*pdata = pdev->dev.platform_data;
 	struct platform_device		*musb;
 	struct tusb6010_glue		*glue;
-
+	struct platform_device_info	pinfo;
 	int				ret = -ENOMEM;
 
 	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
@@ -1169,18 +1173,7 @@ static int tusb_probe(struct platform_device *pdev)
 		goto err0;
 	}
 
-	musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO);
-	if (!musb) {
-		dev_err(&pdev->dev, "failed to allocate musb device\n");
-		goto err1;
-	}
-
-	musb->dev.parent		= &pdev->dev;
-	musb->dev.dma_mask		= &tusb_dmamask;
-	musb->dev.coherent_dma_mask	= tusb_dmamask;
-
 	glue->dev			= &pdev->dev;
-	glue->musb			= musb;
 
 	pdata->platform_ops		= &tusb_ops;
 
@@ -1199,31 +1192,23 @@ static int tusb_probe(struct platform_device *pdev)
 	musb_resources[1].end = pdev->resource[1].end;
 	musb_resources[1].flags = pdev->resource[1].flags;
 
-	ret = platform_device_add_resources(musb, musb_resources,
-			ARRAY_SIZE(musb_resources));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add resources\n");
-		goto err3;
-	}
-
-	ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to add platform_data\n");
-		goto err3;
-	}
-
-	ret = platform_device_add(musb);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register musb device\n");
+	pinfo = tusb_dev_info;
+	pinfo.parent = &pdev->dev;
+	pinfo.res = musb_resources;
+	pinfo.num_res = ARRAY_SIZE(musb_resources);
+	pinfo.data = pdata;
+	pinfo.size_data = sizeof(*pdata);
+
+	glue->musb = musb = platform_device_register_full(&pinfo);
+	if (IS_ERR(musb)) {
+		ret = PTR_ERR(musb);
+		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
 		goto err3;
 	}
 
 	return 0;
 
 err3:
-	platform_device_put(musb);
-
-err1:
 	kfree(glue);
 
 err0:
-- 
1.7.4.4


  parent reply	other threads:[~2013-08-01 22:16 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01 21:34 [PATCH RFC 00/51] Preview of DMA mask changes Russell King - ARM Linux
2013-08-01 21:35 ` [PATCH RFC 01/51] DMA-API: provide a helper to set both DMA and coherent DMA masks Russell King
2013-08-01 21:36 ` [PATCH RFC 02/51] DMA-API: net: brocade/bna/bnad.c: fix 32-bit DMA mask handling Russell King
2013-08-01 21:37 ` [PATCH RFC 03/51] DMA-API: net: intel/e1000e: " Russell King
2013-08-01 21:38 ` [PATCH RFC 04/51] DMA-API: net: intel/igb: " Russell King
2013-08-01 21:39 ` [PATCH RFC 05/51] DMA-API: net: intel/igbvf: " Russell King
2013-08-01 21:40 ` [PATCH RFC 06/51] DMA-API: net: intel/ixgb: " Russell King
2013-08-01 21:41 ` [PATCH RFC 07/51] DMA-API: net: intel/ixgbe: " Russell King
2013-08-01 21:42 ` [PATCH RFC 08/51] DMA-API: net: intel/ixgbevf: " Russell King
2013-08-01 21:43 ` [PATCH RFC 09/51] DMA-API: net: broadcom/b44: replace dma_set_mask()+dma_set_coherent_mask() with new helper Russell King
2013-08-01 21:44 ` [PATCH RFC 10/51] DMA-API: net: broadcom/bnx2x: " Russell King
2013-08-01 21:45 ` [PATCH RFC 11/51] DMA-API: net: emulex/benet: " Russell King
2013-08-01 21:46 ` [PATCH RFC 12/51] DMA-API: net: intel/e1000: " Russell King
2013-08-01 21:47 ` [PATCH RFC 13/51] DMA-API: net: sfc/efx.c: " Russell King
2013-08-01 21:48 ` [PATCH RFC 14/51] DMA-API: net: b43: " Russell King
2013-08-01 21:49 ` [PATCH RFC 15/51] DMA-API: net: b43legacy: " Russell King
2013-08-01 21:50 ` [PATCH RFC 16/51] DMA-API: ppc: vio.c: " Russell King
2013-08-01 21:51 ` [PATCH RFC 17/51] DMA-API: block: nvme-core: " Russell King
2013-08-01 21:52 ` [PATCH RFC 18/51] DMA-API: staging: et131x: " Russell King
2013-08-01 21:53 ` [PATCH RFC 19/51] DMA-API: media: dt3155v4l: " Russell King
2013-08-01 21:54 ` [PATCH RFC 20/51] DMA-API: usb: bcma: " Russell King
2013-08-01 21:55 ` [PATCH RFC 21/51] DMA-API: usb: ssb-hcd: " Russell King
2013-08-01 21:56 ` [PATCH RFC 22/51] DMA-API: amba: get rid of separate dma_mask Russell King
2013-08-01 21:57 ` [PATCH RFC 23/51] DMA-API: dma: pl08x: add dma_set_mask_and_coherent() call Russell King
2013-08-01 21:58 ` [PATCH RFC 24/51] DMA-API: dma: pl330: " Russell King
2013-08-01 21:59 ` [PATCH RFC 25/51] DMA-API: video: clcd: " Russell King
2013-08-01 22:00 ` [PATCH RFC 26/51] DMA-API: usb: ohci-sa1111: add a note about DMA masks Russell King
2013-08-01 22:01 ` [PATCH RFC 27/51] DMA-API: provide a helper to setup " Russell King
2013-08-01 22:02 ` [PATCH RFC 28/51] DMA-API: sound: fix dma mask handling in a lot of drivers Russell King
2013-08-01 22:03 ` [PATCH RFC 29/51] DMA-API: ata: pata_octeon_cf: convert to use dma_coerce_mask_and_coherent() Russell King
2013-08-01 22:04 ` [PATCH RFC 30/51] DMA-API: dma: dw_dmac.c: " Russell King
2013-08-01 22:05 ` [PATCH RFC 31/51] DMA-API: media: omap3isp: " Russell King
2013-08-01 22:06 ` [PATCH RFC 32/51] DMA-API: mmc: sdhci-acpi: " Russell King
2013-08-01 22:07 ` [PATCH RFC 33/51] DMA-API: net: nxp/lpc_eth: " Russell King
2013-08-01 22:08 ` [PATCH RFC 34/51] DMA-API: net: octeon: " Russell King
2013-08-01 22:09 ` [PATCH RFC 35/51] DMA-API: parport: parport_pc.c: " Russell King
2013-08-01 22:10 ` [PATCH RFC 36/51] DMA-API: usb: use dma_set_coherent_mask() Russell King
2013-08-01 22:11 ` [PATCH RFC 37/51] DMA-API: usb: use new dma_coerce_mask_and_coherent() Russell King
2013-08-01 22:12 ` [PATCH RFC 38/51] DMA-API: staging: use dma_set_coherent_mask() Russell King
2013-08-01 22:13 ` [PATCH RFC 39/51] DMA-API: others: " Russell King
2013-08-01 22:14 ` [PATCH RFC 40/51] DMA-API: crypto: fix ixp4xx crypto platform device support Russell King
2013-08-01 22:15 ` [PATCH RFC 41/51] DMA-API: crypto: remove last references to 'static struct device *dev' Russell King
2013-08-01 22:16 ` Russell King [this message]
2013-08-01 22:17 ` [PATCH RFC 43/51] DMA-API: dma: edma.c: no need to explicitly initialize DMA masks Russell King
2013-08-01 22:18 ` [PATCH RFC 44/51] DMA-API: dcdbas: update DMA mask handing Russell King
2013-08-01 22:19 ` [PATCH RFC 45/51] DMA-API: firmware/google/gsmi.c: avoid direct access to DMA masks Russell King
2013-08-01 22:20 ` [PATCH RFC 46/51] ARM: DMA-API: better handing of DMA masks for coherent allocations Russell King
2013-08-05 22:43   ` Rob Herring
2013-08-05 23:44     ` Russell King - ARM Linux
2013-08-09 11:35   ` Tushar Behera
2013-08-01 22:21 ` [PATCH RFC 47/51] ARM: 7794/1: block: Rename parameter dma_mask to max_addr for blk_queue_bounce_limit() Santosh Shilimkar
2013-08-01 22:37   ` Russell King - ARM Linux
2013-08-01 22:22 ` [PATCH RFC 48/51] ARM: 7795/1: mm: dma-mapping: Add dma_max_pfn(dev) helper function Santosh Shilimkar
2013-08-01 22:23 ` [PATCH RFC 49/51] ARM: 7796/1: scsi: Use dma_max_pfn(dev) helper for bounce_limit calculations Santosh Shilimkar
2013-08-01 22:24 ` [PATCH RFC 50/51] ARM: 7797/1: mmc: " Santosh Shilimkar
2013-08-01 22:25 ` [PATCH RFC 51/51] ARM: 7805/1: mm: change max*pfn to include the physical offset of memory Santosh Shilimkar
2013-08-06  3:15   ` Rob Herring
2013-08-06  8:51     ` Russell King - ARM Linux
2013-08-14 10:38 ` [PATCH RFC 00/51] Preview of DMA mask changes Russell King - ARM Linux

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=E1V51AL-0006tr-8k@rmk-PC.arm.linux.org.uk \
    --to=rmk+kernel@arm.linux.org.uk \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.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