From patchwork Mon Jan 2 08:51:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martin X-Patchwork-Id: 9292 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1Rhdcl-0007l2-LY; Mon, 02 Jan 2012 09:52:31 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-4) with esmtp id 1Rhdcj-0005OO-Bb; Mon, 02 Jan 2012 09:52:06 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751354Ab2ABIvs (ORCPT + 4 others); Mon, 2 Jan 2012 03:51:48 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:55139 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009Ab2ABIvr (ORCPT ); Mon, 2 Jan 2012 03:51:47 -0500 Received: by wgbdr13 with SMTP id dr13so26391173wgb.1 for ; Mon, 02 Jan 2012 00:51:46 -0800 (PST) Received: by 10.227.60.135 with SMTP id p7mr47506746wbh.16.1325494306448; Mon, 02 Jan 2012 00:51:46 -0800 (PST) Received: from localhost.localdomain (220.51.18.95.dynamic.jazztel.es. [95.18.51.220]) by mx.google.com with ESMTPS id ba4sm17092605wib.5.2012.01.02.00.51.44 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 02 Jan 2012 00:51:45 -0800 (PST) From: Javier Martin To: linux-media@vger.kernel.org Cc: mchehab@infradead.org, g.liakhovetski@gmx.de, lethal@linux-sh.org, hans.verkuil@cisco.com, s.hauer@pengutronix.de, Javier Martin Subject: [PATCH] media i.MX27 camera: properly detect frame loss. Date: Mon, 2 Jan 2012 09:51:33 +0100 Message-Id: <1325494293-3968-1-git-send-email-javier.martin@vista-silicon.com> X-Mailer: git-send-email 1.7.0.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.1.2.84215 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, BODY_SIZE_4000_4999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, __ANY_URI 0, __CP_MEDIA_BODY 0, __CP_URI_IN_BODY 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' X-LSpam-Score: -1.9 (-) X-LSpam-Report: No, score=-1.9 required=5.0 tests=BAYES_00=-1.9 autolearn=ham As V4L2 specification states, frame_count must also regard lost frames so that the user can handle that case properly. This patch adds a mechanism to increment the frame counter even when a video buffer is not available and a discard buffer is used. Signed-off-by: Javier Martin --- drivers/media/video/mx2_camera.c | 54 ++++++++++++++++++++++++-------------- 1 files changed, 34 insertions(+), 20 deletions(-) diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c index ca76dd2..b244714 100644 --- a/drivers/media/video/mx2_camera.c +++ b/drivers/media/video/mx2_camera.c @@ -256,6 +256,7 @@ struct mx2_camera_dev { size_t discard_size; struct mx2_fmt_cfg *emma_prp; u32 frame_count; + unsigned int firstirq; }; /* buffer for one video frame */ @@ -370,6 +371,7 @@ static int mx2_camera_add_device(struct soc_camera_device *icd) pcdev->icd = icd; pcdev->frame_count = 0; + pcdev->firstirq = 1; dev_info(icd->parent, "Camera driver attached to camera %d\n", icd->devnum); @@ -572,6 +574,7 @@ static void mx2_videobuf_queue(struct videobuf_queue *vq, struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct mx2_camera_dev *pcdev = ici->priv; + struct mx2_fmt_cfg *prp = pcdev->emma_prp; struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb); unsigned long flags; @@ -584,6 +587,26 @@ static void mx2_videobuf_queue(struct videobuf_queue *vq, list_add_tail(&vb->queue, &pcdev->capture); if (mx27_camera_emma(pcdev)) { + if (prp->cfg.channel == 1) { + writel(PRP_CNTL_CH1EN | + PRP_CNTL_CSIEN | + prp->cfg.in_fmt | + prp->cfg.out_fmt | + PRP_CNTL_CH1_LEN | + PRP_CNTL_CH1BYP | + PRP_CNTL_CH1_TSKIP(0) | + PRP_CNTL_IN_TSKIP(0), + pcdev->base_emma + PRP_CNTL); + } else { + writel(PRP_CNTL_CH2EN | + PRP_CNTL_CSIEN | + prp->cfg.in_fmt | + prp->cfg.out_fmt | + PRP_CNTL_CH2_LEN | + PRP_CNTL_CH2_TSKIP(0) | + PRP_CNTL_IN_TSKIP(0), + pcdev->base_emma + PRP_CNTL); + } goto out; } else { /* cpu_is_mx25() */ u32 csicr3, dma_inten = 0; @@ -747,16 +770,6 @@ static void mx27_camera_emma_buf_init(struct soc_camera_device *icd, writel(pcdev->discard_buffer_dma, pcdev->base_emma + PRP_DEST_RGB2_PTR); - writel(PRP_CNTL_CH1EN | - PRP_CNTL_CSIEN | - prp->cfg.in_fmt | - prp->cfg.out_fmt | - PRP_CNTL_CH1_LEN | - PRP_CNTL_CH1BYP | - PRP_CNTL_CH1_TSKIP(0) | - PRP_CNTL_IN_TSKIP(0), - pcdev->base_emma + PRP_CNTL); - writel((icd->user_width << 16) | icd->user_height, pcdev->base_emma + PRP_SRC_FRAME_SIZE); writel((icd->user_width << 16) | icd->user_height, @@ -784,15 +797,6 @@ static void mx27_camera_emma_buf_init(struct soc_camera_device *icd, pcdev->base_emma + PRP_SOURCE_CR_PTR); } - writel(PRP_CNTL_CH2EN | - PRP_CNTL_CSIEN | - prp->cfg.in_fmt | - prp->cfg.out_fmt | - PRP_CNTL_CH2_LEN | - PRP_CNTL_CH2_TSKIP(0) | - PRP_CNTL_IN_TSKIP(0), - pcdev->base_emma + PRP_CNTL); - writel((icd->user_width << 16) | icd->user_height, pcdev->base_emma + PRP_SRC_FRAME_SIZE); @@ -1214,7 +1218,6 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev, vb->state = state; do_gettimeofday(&vb->ts); vb->field_count = pcdev->frame_count * 2; - pcdev->frame_count++; wake_up(&vb->done); } @@ -1239,6 +1242,17 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev, return; } + /* + * According to V4L2 specification, first valid sequence number must + * be 0. However, by design the first received frame is written to the + * discard buffer even when a video buffer is available. For that reason + * we don't increment frame_count the first time. + */ + if (pcdev->firstirq) + pcdev->firstirq = 0; + else + pcdev->frame_count++; + buf = list_entry(pcdev->capture.next, struct mx2_buffer, vb.queue);