All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/11] media: davinci: vpif driver cleanup
@ 2013-06-17 15:20 Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 01/11] media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically Prabhakar Lad
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

This patch series cleans the VPIF driver, uses devm_* api wherever
required and uses module_platform_driver() to simplify the code.

This patch series applies on http://git.linuxtv.org/hverkuil/media_tree.git/
shortlog/refs/heads/for-v3.11 and is tested on OMAP-L138 EVM.

Changes for v2:
1: Rebased on v3.11 branch of Hans.
2: Dropped the patches which removed headers as mentioned by Laurent.

Changes for v3:
1: Splitted the patches logically as mentioned by Laurent.
2: Fixed review comments pointed by Laurent.
3: Included Ack's.

Changes for v4:
1: Rebased on v3.11 branch of Hans.
2: Fixed review comments pointed by Laurent and Sergei.
3: Included Ack's.
4: Removed unnecessary loop for IRQ resource.


Lad, Prabhakar (11):
  media: davinci: vpif: remove unwanted header mach/hardware.h and sort
    the includes alphabetically
  media: davinci: vpif: Convert to devm_* api
  media: davinci: vpif: remove unnecessary braces around defines
  media: davinci: vpif_capture: move the freeing of irq and global
    variables to remove()
  media: davinci: vpif_capture: use module_platform_driver()
  media: davinci: vpif_capture: Convert to devm_* api
  media: davinci: vpif_capture: remove unnecessary loop for IRQ
    resource
  media: davinci: vpif_display: move the freeing of irq and global
    variables to remove()
  media: davinci: vpif_display: use module_platform_driver()
  media: davinci: vpif_display: Convert to devm_* api
  media: davinci: vpif_display: remove unnecessary loop for IRQ
    resource

 drivers/media/platform/davinci/vpif.c         |   45 ++++-----------
 drivers/media/platform/davinci/vpif_capture.c |   76 +++++--------------------
 drivers/media/platform/davinci/vpif_display.c |   65 +++++----------------
 3 files changed, 39 insertions(+), 147 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v4 01/11] media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 02/11] media: davinci: vpif: Convert to devm_* api Prabhakar Lad
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

This patch removes unwanted header include of mach/hardware.h
and along side sorts the header inclusion alphabetically.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c
index ea82a8b..761c825 100644
--- a/drivers/media/platform/davinci/vpif.c
+++ b/drivers/media/platform/davinci/vpif.c
@@ -17,18 +17,16 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/err.h>
 #include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
-#include <linux/spinlock.h>
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/err.h>
 #include <linux/pm_runtime.h>
+#include <linux/spinlock.h>
 #include <linux/v4l2-dv-timings.h>
 
-#include <mach/hardware.h>
-
 #include "vpif.h"
 
 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 02/11] media: davinci: vpif: Convert to devm_* api
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 01/11] media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 03/11] media: davinci: vpif: remove unnecessary braces around defines Prabhakar Lad
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

Use devm_ioremap_resource instead of reques_mem_region()/ioremap().
This ensures more consistent error values and simplifies error paths.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif.c |   27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c
index 761c825..164c1b7 100644
--- a/drivers/media/platform/davinci/vpif.c
+++ b/drivers/media/platform/davinci/vpif.c
@@ -37,8 +37,6 @@ MODULE_LICENSE("GPL");
 #define VPIF_CH2_MAX_MODES	(15)
 #define VPIF_CH3_MAX_MODES	(02)
 
-static resource_size_t	res_len;
-static struct resource	*res;
 spinlock_t vpif_lock;
 
 void __iomem *vpif_base;
@@ -421,23 +419,12 @@ EXPORT_SYMBOL(vpif_channel_getfid);
 
 static int vpif_probe(struct platform_device *pdev)
 {
-	int status = 0;
+	static struct resource	*res;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENOENT;
-
-	res_len = resource_size(res);
-
-	res = request_mem_region(res->start, res_len, res->name);
-	if (!res)
-		return -EBUSY;
-
-	vpif_base = ioremap(res->start, res_len);
-	if (!vpif_base) {
-		status = -EBUSY;
-		goto fail;
-	}
+	vpif_base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(vpif_base))
+		return PTR_ERR(vpif_base);
 
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_get(&pdev->dev);
@@ -445,17 +432,11 @@ static int vpif_probe(struct platform_device *pdev)
 	spin_lock_init(&vpif_lock);
 	dev_info(&pdev->dev, "vpif probe success\n");
 	return 0;
-
-fail:
-	release_mem_region(res->start, res_len);
-	return status;
 }
 
 static int vpif_remove(struct platform_device *pdev)
 {
 	pm_runtime_disable(&pdev->dev);
-	iounmap(vpif_base);
-	release_mem_region(res->start, res_len);
 	return 0;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 03/11] media: davinci: vpif: remove unnecessary braces around defines
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 01/11] media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 02/11] media: davinci: vpif: Convert to devm_* api Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 04/11] media: davinci: vpif_capture: move the freeing of irq and global variables to remove() Prabhakar Lad
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

This patch removes unnecessary braces around defines.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c
index 164c1b7..cd08e52 100644
--- a/drivers/media/platform/davinci/vpif.c
+++ b/drivers/media/platform/davinci/vpif.c
@@ -32,10 +32,10 @@
 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
 MODULE_LICENSE("GPL");
 
-#define VPIF_CH0_MAX_MODES	(22)
-#define VPIF_CH1_MAX_MODES	(02)
-#define VPIF_CH2_MAX_MODES	(15)
-#define VPIF_CH3_MAX_MODES	(02)
+#define VPIF_CH0_MAX_MODES	22
+#define VPIF_CH1_MAX_MODES	2
+#define VPIF_CH2_MAX_MODES	15
+#define VPIF_CH3_MAX_MODES	2
 
 spinlock_t vpif_lock;
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 04/11] media: davinci: vpif_capture: move the freeing of irq and global variables to remove()
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (2 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 03/11] media: davinci: vpif: remove unnecessary braces around defines Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 05/11] media: davinci: vpif_capture: use module_platform_driver() Prabhakar Lad
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

Ideally the freeing of irq's and the global variables needs to be
done in the remove() rather than module_exit(), this patch moves
the freeing up of irq's and freeing the memory allocated to channel
objects to remove() callback of struct platform_driver.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   29 ++++++++++---------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index d004531..7d3c449 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2159,17 +2159,27 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	int i;
 	struct channel_obj *ch;
+	struct resource *res;
+	int irq_num, i = 0;
+
+	while ((res = platform_get_resource(device, IORESOURCE_IRQ, i))) {
+		for (irq_num = res->start; irq_num <= res->end; irq_num++)
+			free_irq(irq_num,
+				 (void *)(&vpif_obj.dev[i]->channel_id));
+		i++;
+	}
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
+	kfree(vpif_obj.sd);
 	/* un-register device */
 	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
 		/* Get the pointer to the channel object */
 		ch = vpif_obj.dev[i];
 		/* Unregister video device */
 		video_unregister_device(ch->video_dev);
+		kfree(vpif_obj.dev[i]);
 	}
 	return 0;
 }
@@ -2281,24 +2291,7 @@ static __init int vpif_init(void)
  */
 static void vpif_cleanup(void)
 {
-	struct platform_device *pdev;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	platform_driver_unregister(&vpif_driver);
-
-	kfree(vpif_obj.sd);
-	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
-		kfree(vpif_obj.dev[i]);
 }
 
 /* Function for module initialization and cleanup */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 05/11] media: davinci: vpif_capture: use module_platform_driver()
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (3 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 04/11] media: davinci: vpif_capture: move the freeing of irq and global variables to remove() Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 06/11] media: davinci: vpif_capture: Convert to devm_* api Prabhakar Lad
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

This patch uses module_platform_driver() to simplify the code.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   28 +------------------------
 1 file changed, 1 insertion(+), 27 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 7d3c449..091c7a4 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2270,30 +2270,4 @@ static __refdata struct platform_driver vpif_driver = {
 	.remove = vpif_remove,
 };
 
-/**
- * vpif_init: initialize the vpif driver
- *
- * This function registers device and driver to the kernel, requests irq
- * handler and allocates memory
- * for channel objects
- */
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/**
- * vpif_cleanup : This function clean up the vpif capture resources
- *
- * This will un-registers device and driver to the kernel, frees
- * requested irq handler and de-allocates memory allocated for channel
- * objects.
- */
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-/* Function for module initialization and cleanup */
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 06/11] media: davinci: vpif_capture: Convert to devm_* api
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (4 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 05/11] media: davinci: vpif_capture: use module_platform_driver() Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 07/11] media: davinci: vpif_capture: remove unnecessary loop for IRQ resource Prabhakar Lad
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

use devm_request_irq() instead of request_irq(). This ensures
more consistent error values and simplifies error paths.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   36 +++++++++----------------
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 091c7a4..a4e0eab 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2016,14 +2016,14 @@ static __init int vpif_probe(struct platform_device *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Capture", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
-				goto vpif_int_err;
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Capture",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
+				goto vpif_unregister;
+
 			}
 		}
 		res_idx++;
@@ -2040,7 +2040,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 				video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -2141,13 +2141,9 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
+
 	return err;
 }
 
@@ -2160,15 +2156,7 @@ vpif_int_err:
 static int vpif_remove(struct platform_device *device)
 {
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num, i = 0;
-
-	while ((res = platform_get_resource(device, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
+	int i;
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 07/11] media: davinci: vpif_capture: remove unnecessary loop for IRQ resource
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (5 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 06/11] media: davinci: vpif_capture: Convert to devm_* api Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 08/11] media: davinci: vpif_display: move the freeing of irq and global variables to remove() Prabhakar Lad
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

For vpif capture driver each IRQ resource contains a single IRQ
so drop the second loop.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
---
 drivers/media/platform/davinci/vpif_capture.c |   17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index a4e0eab..5514175 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -2015,16 +2015,13 @@ static __init int vpif_probe(struct platform_device *pdev)
 	}
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
-		for (i = res->start; i <= res->end; i++) {
-			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
-					     IRQF_SHARED, "VPIF_Capture",
-					     (void *)(&vpif_obj.dev[res_idx]->
-					     channel_id));
-			if (err) {
-				err = -EINVAL;
-				goto vpif_unregister;
-
-			}
+		err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
+					IRQF_SHARED, "VPIF_Capture",
+					(void *)(&vpif_obj.dev[res_idx]->
+					channel_id));
+		if (err) {
+			err = -EINVAL;
+			goto vpif_unregister;
 		}
 		res_idx++;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 08/11] media: davinci: vpif_display: move the freeing of irq and global variables to remove()
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (6 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 07/11] media: davinci: vpif_capture: remove unnecessary loop for IRQ resource Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 09/11] media: davinci: vpif_display: use module_platform_driver() Prabhakar Lad
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

Ideally the freeing of irq's and the global variables needs to be
done in the remove() rather than module_exit(), this patch moves
the freeing up of irq's and freeing the memory allocated to channel
objects to remove() callback of struct platform_driver.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
---
 drivers/media/platform/davinci/vpif_display.c |   30 ++++++++++---------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 6c521f2..371af34 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1829,10 +1829,20 @@ vpif_int_err:
 static int vpif_remove(struct platform_device *device)
 {
 	struct channel_obj *ch;
-	int i;
+	struct resource *res;
+	int irq_num;
+	int i = 0;
+
+	while ((res = platform_get_resource(device, IORESOURCE_IRQ, i))) {
+		for (irq_num = res->start; irq_num <= res->end; irq_num++)
+			free_irq(irq_num,
+				 (void *)(&vpif_obj.dev[i]->channel_id));
+		i++;
+	}
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
+	kfree(vpif_obj.sd);
 	/* un-register device */
 	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
 		/* Get the pointer to the channel object */
@@ -1841,6 +1851,7 @@ static int vpif_remove(struct platform_device *device)
 		video_unregister_device(ch->video_dev);
 
 		ch->video_dev = NULL;
+		kfree(vpif_obj.dev[i]);
 	}
 
 	return 0;
@@ -1938,24 +1949,7 @@ static __init int vpif_init(void)
  */
 static void vpif_cleanup(void)
 {
-	struct platform_device *pdev;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	platform_driver_unregister(&vpif_driver);
-	kfree(vpif_obj.sd);
-	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++)
-		kfree(vpif_obj.dev[i]);
 }
 
 module_init(vpif_init);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 09/11] media: davinci: vpif_display: use module_platform_driver()
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (7 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 08/11] media: davinci: vpif_display: move the freeing of irq and global variables to remove() Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 10/11] media: davinci: vpif_display: Convert to devm_* api Prabhakar Lad
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

This patch uses module_platform_driver() to simplify the code.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif_display.c |   18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 371af34..473d1a9 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1937,20 +1937,4 @@ static __refdata struct platform_driver vpif_driver = {
 	.remove	= vpif_remove,
 };
 
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/*
- * vpif_cleanup: This function un-registers device and driver to the kernel,
- * frees requested irq handler and de-allocates memory allocated for channel
- * objects.
- */
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 10/11] media: davinci: vpif_display: Convert to devm_* api
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (8 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 09/11] media: davinci: vpif_display: use module_platform_driver() Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 15:20 ` [PATCH v4 11/11] media: davinci: vpif_display: remove unnecessary loop for IRQ resource Prabhakar Lad
  2013-06-17 17:20 ` [PATCH v4 00/11] media: davinci: vpif driver cleanup Laurent Pinchart
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

use devm_request_irq() instead of request_irq(). This ensures
more consistent error values and simplifies error paths.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/platform/davinci/vpif_display.c |   35 +++++++------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 473d1a9..1bf289d 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1652,15 +1652,14 @@ static __init int vpif_probe(struct platform_device *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Display", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Display",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
 				vpif_err("VPIF IRQ request failed\n");
-				goto vpif_int_err;
+				goto vpif_unregister;
 			}
 		}
 		res_idx++;
@@ -1678,7 +1677,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 				video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -1812,13 +1811,8 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
 
 	return err;
 }
@@ -1829,16 +1823,7 @@ vpif_int_err:
 static int vpif_remove(struct platform_device *device)
 {
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	while ((res = platform_get_resource(device, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
+	int i;
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v4 11/11] media: davinci: vpif_display: remove unnecessary loop for IRQ resource
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (9 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 10/11] media: davinci: vpif_display: Convert to devm_* api Prabhakar Lad
@ 2013-06-17 15:20 ` Prabhakar Lad
  2013-06-17 17:20 ` [PATCH v4 00/11] media: davinci: vpif driver cleanup Laurent Pinchart
  11 siblings, 0 replies; 13+ messages in thread
From: Prabhakar Lad @ 2013-06-17 15:20 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, Laurent Pinchart
  Cc: LKML, Lad, Prabhakar

From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>

For vpif display driver each IRQ resource contains a single IRQ
so drop the second loop.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
---
 drivers/media/platform/davinci/vpif_display.c |   18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 1bf289d..e6e5736 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -1651,16 +1651,14 @@ static __init int vpif_probe(struct platform_device *pdev)
 	}
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
-		for (i = res->start; i <= res->end; i++) {
-			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
-					     IRQF_SHARED, "VPIF_Display",
-					     (void *)(&vpif_obj.dev[res_idx]->
-					     channel_id));
-			if (err) {
-				err = -EINVAL;
-				vpif_err("VPIF IRQ request failed\n");
-				goto vpif_unregister;
-			}
+		err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
+					IRQF_SHARED, "VPIF_Display",
+					(void *)(&vpif_obj.dev[res_idx]->
+					channel_id));
+		if (err) {
+			err = -EINVAL;
+			vpif_err("VPIF IRQ request failed\n");
+			goto vpif_unregister;
 		}
 		res_idx++;
 	}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v4 00/11] media: davinci: vpif driver cleanup
  2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
                   ` (10 preceding siblings ...)
  2013-06-17 15:20 ` [PATCH v4 11/11] media: davinci: vpif_display: remove unnecessary loop for IRQ resource Prabhakar Lad
@ 2013-06-17 17:20 ` Laurent Pinchart
  11 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2013-06-17 17:20 UTC (permalink / raw)
  To: Prabhakar Lad; +Cc: Mauro Carvalho Chehab, LMML, DLOS, Hans Verkuil, LKML

Hi Prabhakar,

Thank you for the patches.

On Monday 17 June 2013 20:50:40 Prabhakar Lad wrote:
> From: "Lad, Prabhakar" <prabhakar.csengg@gmail.com>
> 
> This patch series cleans the VPIF driver, uses devm_* api wherever
> required and uses module_platform_driver() to simplify the code.
> 
> This patch series applies on http://git.linuxtv.org/hverkuil/media_tree.git/
> shortlog/refs/heads/for-v3.11 and is tested on OMAP-L138 EVM.
> 
> Changes for v2:
> 1: Rebased on v3.11 branch of Hans.
> 2: Dropped the patches which removed headers as mentioned by Laurent.
> 
> Changes for v3:
> 1: Splitted the patches logically as mentioned by Laurent.
> 2: Fixed review comments pointed by Laurent.
> 3: Included Ack's.
> 
> Changes for v4:
> 1: Rebased on v3.11 branch of Hans.
> 2: Fixed review comments pointed by Laurent and Sergei.
> 3: Included Ack's.
> 4: Removed unnecessary loop for IRQ resource.

For the whole series,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> Lad, Prabhakar (11):
>   media: davinci: vpif: remove unwanted header mach/hardware.h and sort
>     the includes alphabetically
>   media: davinci: vpif: Convert to devm_* api
>   media: davinci: vpif: remove unnecessary braces around defines
>   media: davinci: vpif_capture: move the freeing of irq and global
>     variables to remove()
>   media: davinci: vpif_capture: use module_platform_driver()
>   media: davinci: vpif_capture: Convert to devm_* api
>   media: davinci: vpif_capture: remove unnecessary loop for IRQ
>     resource
>   media: davinci: vpif_display: move the freeing of irq and global
>     variables to remove()
>   media: davinci: vpif_display: use module_platform_driver()
>   media: davinci: vpif_display: Convert to devm_* api
>   media: davinci: vpif_display: remove unnecessary loop for IRQ
>     resource
> 
>  drivers/media/platform/davinci/vpif.c         |   45 ++++-----------
>  drivers/media/platform/davinci/vpif_capture.c |   76 +++++-----------------
>  drivers/media/platform/davinci/vpif_display.c |   65 +++++----------------
>  3 files changed, 39 insertions(+), 147 deletions(-)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-06-17 17:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-17 15:20 [PATCH v4 00/11] media: davinci: vpif driver cleanup Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 01/11] media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 02/11] media: davinci: vpif: Convert to devm_* api Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 03/11] media: davinci: vpif: remove unnecessary braces around defines Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 04/11] media: davinci: vpif_capture: move the freeing of irq and global variables to remove() Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 05/11] media: davinci: vpif_capture: use module_platform_driver() Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 06/11] media: davinci: vpif_capture: Convert to devm_* api Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 07/11] media: davinci: vpif_capture: remove unnecessary loop for IRQ resource Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 08/11] media: davinci: vpif_display: move the freeing of irq and global variables to remove() Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 09/11] media: davinci: vpif_display: use module_platform_driver() Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 10/11] media: davinci: vpif_display: Convert to devm_* api Prabhakar Lad
2013-06-17 15:20 ` [PATCH v4 11/11] media: davinci: vpif_display: remove unnecessary loop for IRQ resource Prabhakar Lad
2013-06-17 17:20 ` [PATCH v4 00/11] media: davinci: vpif driver cleanup Laurent Pinchart

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.