linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Archit Taneja <archit@ti.com>
To: k.debski@samsung.com
Cc: linux-media@vger.kernel.org, linux-omap@vger.kernel.org,
	hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com,
	Archit Taneja <archit@ti.com>
Subject: [PATCH 2/7] v4l: ti-vpe: register video device only when firmware is loaded
Date: Mon, 3 Mar 2014 13:03:23 +0530	[thread overview]
Message-ID: <1393832008-22174-3-git-send-email-archit@ti.com> (raw)
In-Reply-To: <1393832008-22174-1-git-send-email-archit@ti.com>

vpe fops(vpe_open in particular) should be called only when VPDMA firmware
is loaded. File operations on the video device are possible the moment it is
registered.

Currently, we register the video device for VPE at driver probe, after calling
a vpdma helper to initialize VPDMA and load firmware. This function is
non-blocking(it calls request_firmware_nowait()), and doesn't ensure that the
firmware is actually loaded when it returns.

We remove the device registration from vpe probe, and move it to a callback
provided by the vpe driver to the vpdma library, through vpdma_create().

The ready field in vpdma_data is no longer needed since we always have firmware
loaded before the device is registered.

A minor problem with this approach is that if the video_register_device
fails(which doesn't really happen), the vpe platform device would be registered.
however, there won't be any v4l2 device corresponding to it.

Signed-off-by: Archit Taneja <archit@ti.com>
---
 drivers/media/platform/ti-vpe/vpdma.c |  8 +++--
 drivers/media/platform/ti-vpe/vpdma.h |  7 +++--
 drivers/media/platform/ti-vpe/vpe.c   | 55 ++++++++++++++++++++---------------
 3 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c b/drivers/media/platform/ti-vpe/vpdma.c
index e8175e7..73dd38e 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -781,7 +781,7 @@ static void vpdma_firmware_cb(const struct firmware *f, void *context)
 	/* already initialized */
 	if (read_field_reg(vpdma, VPDMA_LIST_ATTR, VPDMA_LIST_RDY_MASK,
 			VPDMA_LIST_RDY_SHFT)) {
-		vpdma->ready = true;
+		vpdma->cb(vpdma->pdev);
 		return;
 	}
 
@@ -811,7 +811,7 @@ static void vpdma_firmware_cb(const struct firmware *f, void *context)
 		goto free_buf;
 	}
 
-	vpdma->ready = true;
+	vpdma->cb(vpdma->pdev);
 
 free_buf:
 	vpdma_unmap_desc_buf(vpdma, &fw_dma_buf);
@@ -839,7 +839,8 @@ static int vpdma_load_firmware(struct vpdma_data *vpdma)
 	return 0;
 }
 
-struct vpdma_data *vpdma_create(struct platform_device *pdev)
+struct vpdma_data *vpdma_create(struct platform_device *pdev,
+		void (*cb)(struct platform_device *pdev))
 {
 	struct resource *res;
 	struct vpdma_data *vpdma;
@@ -854,6 +855,7 @@ struct vpdma_data *vpdma_create(struct platform_device *pdev)
 	}
 
 	vpdma->pdev = pdev;
+	vpdma->cb = cb;
 
 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vpdma");
 	if (res == NULL) {
diff --git a/drivers/media/platform/ti-vpe/vpdma.h b/drivers/media/platform/ti-vpe/vpdma.h
index cf40f11..bf5f8bb 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -35,8 +35,8 @@ struct vpdma_data {
 
 	struct platform_device	*pdev;
 
-	/* tells whether vpdma firmware is loaded or not */
-	bool ready;
+	/* callback to VPE driver when the firmware is loaded */
+	void (*cb)(struct platform_device *pdev);
 };
 
 enum vpdma_data_format_type {
@@ -208,6 +208,7 @@ void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
 void vpdma_dump_regs(struct vpdma_data *vpdma);
 
 /* initialize vpdma, passed with VPE's platform device pointer */
-struct vpdma_data *vpdma_create(struct platform_device *pdev);
+struct vpdma_data *vpdma_create(struct platform_device *pdev,
+		void (*cb)(struct platform_device *pdev));
 
 #endif
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index 623e59e..4243687 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -1815,11 +1815,6 @@ static int vpe_open(struct file *file)
 
 	vpe_dbg(dev, "vpe_open\n");
 
-	if (!dev->vpdma->ready) {
-		vpe_err(dev, "vpdma firmware not loaded\n");
-		return -ENODEV;
-	}
-
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
@@ -2037,10 +2032,40 @@ static void vpe_runtime_put(struct platform_device *pdev)
 	WARN_ON(r < 0 && r != -ENOSYS);
 }
 
+static void vpe_fw_cb(struct platform_device *pdev)
+{
+	struct vpe_dev *dev = platform_get_drvdata(pdev);
+	struct video_device *vfd;
+	int ret;
+
+	vfd = &dev->vfd;
+	*vfd = vpe_videodev;
+	vfd->lock = &dev->dev_mutex;
+	vfd->v4l2_dev = &dev->v4l2_dev;
+
+	ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
+	if (ret) {
+		vpe_err(dev, "Failed to register video device\n");
+
+		vpe_set_clock_enable(dev, 0);
+		vpe_runtime_put(pdev);
+		pm_runtime_disable(&pdev->dev);
+		v4l2_m2m_release(dev->m2m_dev);
+		vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
+		v4l2_device_unregister(&dev->v4l2_dev);
+
+		return;
+	}
+
+	video_set_drvdata(vfd, dev);
+	snprintf(vfd->name, sizeof(vfd->name), "%s", vpe_videodev.name);
+	dev_info(dev->v4l2_dev.dev, "Device registered as /dev/video%d\n",
+		vfd->num);
+}
+
 static int vpe_probe(struct platform_device *pdev)
 {
 	struct vpe_dev *dev;
-	struct video_device *vfd;
 	int ret, irq, func;
 
 	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -2121,28 +2146,12 @@ static int vpe_probe(struct platform_device *pdev)
 		goto runtime_put;
 	}
 
-	dev->vpdma = vpdma_create(pdev);
+	dev->vpdma = vpdma_create(pdev, vpe_fw_cb);
 	if (IS_ERR(dev->vpdma)) {
 		ret = PTR_ERR(dev->vpdma);
 		goto runtime_put;
 	}
 
-	vfd = &dev->vfd;
-	*vfd = vpe_videodev;
-	vfd->lock = &dev->dev_mutex;
-	vfd->v4l2_dev = &dev->v4l2_dev;
-
-	ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
-	if (ret) {
-		vpe_err(dev, "Failed to register video device\n");
-		goto runtime_put;
-	}
-
-	video_set_drvdata(vfd, dev);
-	snprintf(vfd->name, sizeof(vfd->name), "%s", vpe_videodev.name);
-	dev_info(dev->v4l2_dev.dev, "Device registered as /dev/video%d\n",
-		vfd->num);
-
 	return 0;
 
 runtime_put:
-- 
1.8.3.2


  parent reply	other threads:[~2014-03-03  7:34 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-03  7:33 [PATCH 0/7] v4l: ti-vpe: Some VPE fixes and enhancements Archit Taneja
2014-03-03  7:33 ` [PATCH 1/7] v4l: ti-vpe: Make sure in job_ready that we have the needed number of dst_bufs Archit Taneja
2014-03-03  7:33 ` Archit Taneja [this message]
2014-03-03  7:33 ` [PATCH 3/7] v4l: ti-vpe: Use video_device_release_empty Archit Taneja
2014-03-03  7:33 ` [PATCH 4/7] v4l: ti-vpe: Allow DMABUF buffer type support Archit Taneja
2014-03-03  7:33 ` [PATCH 5/7] v4l: ti-vpe: Allow usage of smaller images Archit Taneja
2014-03-03 12:14   ` Kamil Debski
2014-03-03 12:41     ` Archit Taneja
2014-03-03  7:33 ` [PATCH 6/7] v4l: ti-vpe: Fix some params in VPE data descriptors Archit Taneja
2014-03-03  7:33 ` [PATCH 7/7] v4l: ti-vpe: Add crop support in VPE driver Archit Taneja
2014-03-03  7:50   ` Hans Verkuil
2014-03-03  8:26     ` Archit Taneja
2014-03-03 12:21       ` Kamil Debski
2014-03-03 12:36         ` Archit Taneja
2014-03-04  7:38     ` Archit Taneja
2014-03-04  7:43       ` Hans Verkuil
2014-03-04  8:26         ` Archit Taneja
2014-03-04  8:49 ` [PATCH v2 0/7] v4l: ti-vpe: Some VPE fixes and enhancements Archit Taneja
2014-03-04  8:49   ` [PATCH v2 1/7] v4l: ti-vpe: Make sure in job_ready that we have the needed number of dst_bufs Archit Taneja
2014-03-04  8:49   ` [PATCH v2 2/7] v4l: ti-vpe: register video device only when firmware is loaded Archit Taneja
2014-03-04  8:49   ` [PATCH v2 3/7] v4l: ti-vpe: Use video_device_release_empty Archit Taneja
2014-03-04  8:49   ` [PATCH v2 4/7] v4l: ti-vpe: Allow DMABUF buffer type support Archit Taneja
2014-03-04  8:49   ` [PATCH v2 5/7] v4l: ti-vpe: Allow usage of smaller images Archit Taneja
2014-03-04  8:49   ` [PATCH v2 6/7] v4l: ti-vpe: Fix some params in VPE data descriptors Archit Taneja
2014-03-04  8:49   ` [PATCH v2 7/7] v4l: ti-vpe: Add selection API in VPE driver Archit Taneja
2014-03-04  9:40     ` Hans Verkuil
2014-03-04 11:25       ` Archit Taneja
2014-03-04 11:35         ` Hans Verkuil
2014-03-07 11:50           ` Archit Taneja
2014-03-07 12:59             ` Hans Verkuil
2014-03-07 13:22               ` Archit Taneja
2014-03-07 13:32                 ` Hans Verkuil
2014-03-07 13:47                   ` Archit Taneja
2014-03-10 12:12                     ` Archit Taneja
2014-03-10 12:33                       ` Hans Verkuil
2014-03-04 13:28         ` Kamil Debski
2014-03-11  8:33   ` [PATCH v3 00/14] v4l: ti-vpe: Some VPE fixes and enhancements Archit Taneja
2014-03-11  8:33     ` [PATCH v3 01/14] v4l: ti-vpe: Make sure in job_ready that we have the needed number of dst_bufs Archit Taneja
2014-03-13 14:36       ` Kamil Debski
2014-03-11  8:33     ` [PATCH v3 02/14] v4l: ti-vpe: register video device only when firmware is loaded Archit Taneja
2014-03-13 11:48       ` Kamil Debski
2014-03-13 12:09         ` Archit Taneja
2014-03-13 14:29           ` Kamil Debski
2014-03-14  9:51             ` Archit Taneja
2014-03-11  8:33     ` [PATCH v3 03/14] v4l: ti-vpe: Use video_device_release_empty Archit Taneja
2014-03-11 12:02       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 04/14] v4l: ti-vpe: Allow DMABUF buffer type support Archit Taneja
2014-03-11 12:03       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 05/14] v4l: ti-vpe: Allow usage of smaller images Archit Taneja
2014-03-11 12:03       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 06/14] v4l: ti-vpe: Fix some params in VPE data descriptors Archit Taneja
2014-03-11  8:33     ` [PATCH v3 07/14] v4l: ti-vpe: Add selection API in VPE driver Archit Taneja
2014-03-11 12:21       ` Hans Verkuil
2014-03-11 12:46         ` Archit Taneja
2014-03-11 12:49           ` Hans Verkuil
2014-03-11 13:10             ` Archit Taneja
2014-03-11  8:33     ` [PATCH v3 08/14] v4l: ti-vpe: Rename csc memory resource name Archit Taneja
2014-03-11  8:33     ` [PATCH v3 09/14] v4l: ti-vpe: report correct capabilities in querycap Archit Taneja
2014-03-11 12:23       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 10/14] v4l: ti-vpe: Use correct bus_info name for the device " Archit Taneja
2014-03-11 12:23       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 11/14] v4l: ti-vpe: Fix initial configuration queue data Archit Taneja
2014-03-11 12:24       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 12/14] v4l: ti-vpe: zero out reserved fields in try_fmt Archit Taneja
2014-03-11 12:25       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 13/14] v4l: ti-vpe: Set correct field parameter for output and capture buffers Archit Taneja
2014-03-11 12:29       ` Hans Verkuil
2014-03-11  8:33     ` [PATCH v3 14/14] v4l: ti-vpe: retain v4l2_buffer flags for captured buffers Archit Taneja
2014-03-11 12:31       ` Hans Verkuil
2014-03-13 11:44     ` [PATCH v4 00/14] v4l: ti-vpe: Some VPE fixes and enhancements Archit Taneja
2014-03-13 11:44       ` [PATCH v4 01/14] v4l: ti-vpe: Make sure in job_ready that we have the needed number of dst_bufs Archit Taneja
2014-03-13 14:38         ` Kamil Debski
2014-03-13 11:44       ` [PATCH v4 02/14] v4l: ti-vpe: register video device only when firmware is loaded Archit Taneja
2014-03-13 11:44       ` [PATCH v4 03/14] v4l: ti-vpe: Use video_device_release_empty Archit Taneja
2014-03-13 11:44       ` [PATCH v4 04/14] v4l: ti-vpe: Allow DMABUF buffer type support Archit Taneja
2014-03-13 11:44       ` [PATCH v4 05/14] v4l: ti-vpe: Allow usage of smaller images Archit Taneja
2014-03-13 11:44       ` [PATCH v4 06/14] v4l: ti-vpe: Fix some params in VPE data descriptors Archit Taneja
2014-03-13 15:01         ` Kamil Debski
2014-03-13 11:44       ` [PATCH v4 07/14] v4l: ti-vpe: Add selection API in VPE driver Archit Taneja
2014-03-13 11:44       ` [PATCH v4 08/14] v4l: ti-vpe: Rename csc memory resource name Archit Taneja
2014-03-13 14:44         ` Kamil Debski
2014-03-14  6:18           ` Archit Taneja
2014-03-13 11:44       ` [PATCH v4 09/14] v4l: ti-vpe: report correct capabilities in querycap Archit Taneja
2014-03-13 11:44       ` [PATCH v4 10/14] v4l: ti-vpe: Use correct bus_info name for the device " Archit Taneja
2014-03-13 11:44       ` [PATCH v4 11/14] v4l: ti-vpe: Fix initial configuration queue data Archit Taneja
2014-03-13 11:44       ` [PATCH v4 12/14] v4l: ti-vpe: zero out reserved fields in try_fmt Archit Taneja
2014-03-13 11:44       ` [PATCH v4 13/14] v4l: ti-vpe: Set correct field parameter for output and capture buffers Archit Taneja
2014-03-13 11:44       ` [PATCH v4 14/14] v4l: ti-vpe: retain v4l2_buffer flags for captured buffers Archit Taneja

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=1393832008-22174-3-git-send-email-archit@ti.com \
    --to=archit@ti.com \
    --cc=hverkuil@xs4all.nl \
    --cc=k.debski@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-omap@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;
as well as URLs for NNTP newsgroup(s).