From patchwork Fri Aug 31 08:11:03 2012
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Philipp Zabel
X-Patchwork-Id: 1391441
Return-Path:
X-Original-To: patchwork-linux-media@patchwork.kernel.org
Delivered-To: patchwork-process-083081@patchwork2.kernel.org
Received: from vger.kernel.org (vger.kernel.org [209.132.180.67])
by patchwork2.kernel.org (Postfix) with ESMTP id 9AC7BDF215
for ;
Fri, 31 Aug 2012 08:11:45 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
id S1751667Ab2HaILf (ORCPT
);
Fri, 31 Aug 2012 04:11:35 -0400
Received: from metis.ext.pengutronix.de ([92.198.50.35]:37001 "EHLO
metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
with ESMTP id S1751315Ab2HaIL1 (ORCPT
);
Fri, 31 Aug 2012 04:11:27 -0400
Received: from dude.hi.pengutronix.de ([10.1.0.7] helo=dude.pengutronix.de)
by metis.ext.pengutronix.de with esmtp (Exim 4.72)
(envelope-from )
id 1T7MK3-0004rl-Ai; Fri, 31 Aug 2012 10:11:23 +0200
From: Philipp Zabel
To: linux-media@vger.kernel.org
Cc: Javier Martin ,
Mauro Carvalho Chehab ,
Richard Zhao ,
Laurent Pinchart ,
Sylwester Nawrocki ,
Kyungmin Park ,
Hans Verkuil , kernel@pengutronix.de,
Philipp Zabel
Subject: [PATCH v3 09/16] media: coda: wait for picture run completion in
start/stop_streaming
Date: Fri, 31 Aug 2012 10:11:03 +0200
Message-Id: <1346400670-16002-10-git-send-email-p.zabel@pengutronix.de>
X-Mailer: git-send-email 1.7.10.4
In-Reply-To: <1346400670-16002-1-git-send-email-p.zabel@pengutronix.de>
References: <1346400670-16002-1-git-send-email-p.zabel@pengutronix.de>
X-SA-Exim-Connect-IP: 10.1.0.7
X-SA-Exim-Mail-From: p.zabel@pengutronix.de
X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de);
SAEximRunCond expanded to false
X-PTX-Original-Recipient: linux-media@vger.kernel.org
Sender: linux-media-owner@vger.kernel.org
Precedence: bulk
List-ID:
X-Mailing-List: linux-media@vger.kernel.org
While the CODA is running a PIC_RUN command, its registers are
not to be touched.
Signed-off-by: Philipp Zabel
---
Changes since v2:
- Properly move the call to coda_free_framebuffers in coda_stop_streaming,
to avoid introducing a memory leak.
---
drivers/media/platform/coda.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 2e357394..de66579 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -138,6 +138,7 @@ struct coda_dev {
struct list_head instances;
unsigned long instance_mask;
struct delayed_work timeout;
+ struct completion done;
};
struct coda_params {
@@ -727,6 +728,7 @@ static void coda_device_run(void *m2m_priv)
/* 1 second timeout in case CODA locks up */
schedule_delayed_work(&dev->timeout, HZ);
+ INIT_COMPLETION(dev->done);
coda_command_async(ctx, CODA_COMMAND_PIC_RUN);
}
@@ -971,6 +973,10 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
if (!(ctx->rawstreamon & ctx->compstreamon))
return 0;
+ if (coda_isbusy(dev))
+ if (wait_for_completion_interruptible_timeout(&dev->done, HZ) <= 0)
+ return -EBUSY;
+
ctx->gopcounter = ctx->params.gop_size - 1;
q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
@@ -1213,6 +1219,7 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
static int coda_stop_streaming(struct vb2_queue *q)
{
struct coda_ctx *ctx = vb2_get_drv_priv(q);
+ struct coda_dev *dev = ctx->dev;
if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
@@ -1224,20 +1231,29 @@ static int coda_stop_streaming(struct vb2_queue *q)
ctx->compstreamon = 0;
}
- if (!ctx->rawstreamon && !ctx->compstreamon) {
- cancel_delayed_work(&dev->timeout);
+ /* Don't stop the coda unless both queues are off */
+ if (ctx->rawstreamon || ctx->compstreamon)
+ return 0;
- v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
- "%s: sent command 'SEQ_END' to coda\n", __func__);
- if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
- v4l2_err(&ctx->dev->v4l2_dev,
- "CODA_COMMAND_SEQ_END failed\n");
- return -ETIMEDOUT;
+ if (coda_isbusy(dev)) {
+ if (wait_for_completion_interruptible_timeout(&dev->done, HZ) <= 0) {
+ v4l2_warn(&dev->v4l2_dev,
+ "%s: timeout, sending SEQ_END anyway\n", __func__);
}
+ }
- coda_free_framebuffers(ctx);
+ cancel_delayed_work(&dev->timeout);
+
+ v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
+ "%s: sent command 'SEQ_END' to coda\n", __func__);
+ if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
+ v4l2_err(&dev->v4l2_dev,
+ "CODA_COMMAND_SEQ_END failed\n");
+ return -ETIMEDOUT;
}
+ coda_free_framebuffers(ctx);
+
return 0;
}
@@ -1522,6 +1538,8 @@ static irqreturn_t coda_irq_handler(int irq, void *data)
return IRQ_NONE;
}
+ complete(&dev->done);
+
src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
@@ -1857,6 +1875,8 @@ static int __devinit coda_probe(struct platform_device *pdev)
spin_lock_init(&dev->irqlock);
INIT_LIST_HEAD(&dev->instances);
INIT_DELAYED_WORK(&dev->timeout, coda_timeout);
+ init_completion(&dev->done);
+ complete(&dev->done);
dev->plat_dev = pdev;
dev->clk_per = devm_clk_get(&pdev->dev, "per");