linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: emilgoode@gmail.com (Emil Goode)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] ARM: imx: convert camera init to use platform_device_register_full()
Date: Sun, 18 May 2014 22:51:00 +0200	[thread overview]
Message-ID: <1400446261-27085-3-git-send-email-emilgoode@gmail.com> (raw)
In-Reply-To: <1400446261-27085-1-git-send-email-emilgoode@gmail.com>

This converts the imx camera allocation and initialization functions
to use platform_device_register_full() thus simplifying the code.

Signed-off-by: Emil Goode <emilgoode@gmail.com>
---
Only build tested, unfortunately I currently don't have the hardware.

 arch/arm/mach-imx/devices/platform-ipu-core.c |   43 +++++++++----------------
 arch/arm/mach-imx/mach-mx31_3ds.c             |    5 ++-
 arch/arm/mach-imx/mach-mx31moboard.c          |    6 ++--
 arch/arm/mach-imx/mach-mx35_3ds.c             |    5 ++-
 arch/arm/mach-imx/mach-pcm037.c               |    5 ++-
 5 files changed, 23 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-imx/devices/platform-ipu-core.c b/arch/arm/mach-imx/devices/platform-ipu-core.c
index 6bd7c3f..13ea542 100644
--- a/arch/arm/mach-imx/devices/platform-ipu-core.c
+++ b/arch/arm/mach-imx/devices/platform-ipu-core.c
@@ -69,42 +69,29 @@ struct platform_device *__init imx_alloc_mx3_camera(
 			.flags = IORESOURCE_MEM,
 		},
 	};
-	int ret = -ENOMEM;
-	struct platform_device *pdev;
+	struct platform_device_info pdevinfo;
+	struct mx3_camera_pdata tmppdata;
 
 	if (IS_ERR_OR_NULL(imx_ipu_coredev))
 		return ERR_PTR(-ENODEV);
 
-	pdev = platform_device_alloc("mx3-camera", 0);
-	if (!pdev)
-		return ERR_PTR(-ENOMEM);
-
-	pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
-	if (!pdev->dev.dma_mask)
-		goto err;
-
-	*pdev->dev.dma_mask = DMA_BIT_MASK(32);
-	pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
-
-	ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
-	if (ret)
-		goto err;
+	memset(&pdevinfo, 0, sizeof(pdevinfo));
+	pdevinfo.name = "mx3-camera";
+	pdevinfo.id = 0;
+	pdevinfo.res = res;
+	pdevinfo.num_res = ARRAY_SIZE(res);
+	pdevinfo.dma_mask = DMA_BIT_MASK(32);
 
 	if (pdata) {
-		struct mx3_camera_pdata *copied_pdata;
-
-		ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
-		if (ret) {
-err:
-			kfree(pdev->dev.dma_mask);
-			platform_device_put(pdev);
-			return ERR_PTR(-ENODEV);
-		}
-		copied_pdata = dev_get_platdata(&pdev->dev);
-		copied_pdata->dma_dev = &imx_ipu_coredev->dev;
+		tmppdata = *pdata;
+		tmppdata.dma_dev = &imx_ipu_coredev->dev;
+
+		pdata = &tmppdata;
+		pdevinfo.data = pdata;
+		pdevinfo.size_data = sizeof(*pdata);
 	}
 
-	return pdev;
+	return platform_device_register_full(&pdevinfo);
 }
 
 struct platform_device *__init imx_add_mx3_sdc_fb(
diff --git a/arch/arm/mach-imx/mach-mx31_3ds.c b/arch/arm/mach-imx/mach-mx31_3ds.c
index 4217871..a73a933 100644
--- a/arch/arm/mach-imx/mach-mx31_3ds.c
+++ b/arch/arm/mach-imx/mach-mx31_3ds.c
@@ -199,10 +199,9 @@ static int __init mx31_3ds_init_camera(void)
 	if (!(dma & DMA_MEMORY_MAP))
 		goto err;
 
-	ret = platform_device_add(pdev);
-	if (ret)
+	return 0;
 err:
-		platform_device_put(pdev);
+	platform_device_put(pdev);
 
 	return ret;
 }
diff --git a/arch/arm/mach-imx/mach-mx31moboard.c b/arch/arm/mach-imx/mach-mx31moboard.c
index 08730f2..14ca3b8 100644
--- a/arch/arm/mach-imx/mach-mx31moboard.c
+++ b/arch/arm/mach-imx/mach-mx31moboard.c
@@ -492,13 +492,11 @@ static int __init mx31moboard_init_cam(void)
 	if (!(dma & DMA_MEMORY_MAP))
 		goto err;
 
-	ret = platform_device_add(pdev);
-	if (ret)
+	return 0;
 err:
-		platform_device_put(pdev);
+	platform_device_put(pdev);
 
 	return ret;
-
 }
 
 static void mx31moboard_poweroff(void)
diff --git a/arch/arm/mach-imx/mach-mx35_3ds.c b/arch/arm/mach-imx/mach-mx35_3ds.c
index 4e8b184..c5a1b44 100644
--- a/arch/arm/mach-imx/mach-mx35_3ds.c
+++ b/arch/arm/mach-imx/mach-mx35_3ds.c
@@ -282,10 +282,9 @@ static int __init imx35_3ds_init_camera(void)
 	if (!(dma & DMA_MEMORY_MAP))
 		goto err;
 
-	ret = platform_device_add(pdev);
-	if (ret)
+	return 0;
 err:
-		platform_device_put(pdev);
+	platform_device_put(pdev);
 
 	return ret;
 }
diff --git a/arch/arm/mach-imx/mach-pcm037.c b/arch/arm/mach-imx/mach-pcm037.c
index 81b8aff..fa00e6d 100644
--- a/arch/arm/mach-imx/mach-pcm037.c
+++ b/arch/arm/mach-imx/mach-pcm037.c
@@ -425,10 +425,9 @@ static int __init pcm037_init_camera(void)
 	if (!(dma & DMA_MEMORY_MAP))
 		goto err;
 
-	ret = platform_device_add(pdev);
-	if (ret)
+	return 0;
 err:
-		platform_device_put(pdev);
+	platform_device_put(pdev);
 
 	return ret;
 }
-- 
1.7.10.4

  parent reply	other threads:[~2014-05-18 20:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-18 20:50 [PATCH 0/2] ARM: imx: bug fix and convertion to platform_device_register_full() Emil Goode
2014-05-18 20:50 ` [PATCH 1/2 v4] ARM: imx: fix error handling in ipu device registration Emil Goode
2014-05-19  6:31   ` Uwe Kleine-König
2014-05-19  6:47     ` Shawn Guo
2014-05-18 20:51 ` Emil Goode [this message]
2014-05-19  6:27   ` [PATCH 2/2] ARM: imx: convert camera init to use platform_device_register_full() Uwe Kleine-König
2014-05-20 11:43     ` Emil Goode
2014-05-22 10:32     ` Emil Goode

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=1400446261-27085-3-git-send-email-emilgoode@gmail.com \
    --to=emilgoode@gmail.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 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).