From patchwork Fri Jun 19 17:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rodin X-Patchwork-Id: 11614777 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1985113A0 for ; Fri, 19 Jun 2020 17:47:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 036C2217D8 for ; Fri, 19 Jun 2020 17:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403790AbgFSRrT (ORCPT ); Fri, 19 Jun 2020 13:47:19 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:44817 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391317AbgFSRrQ (ORCPT ); Fri, 19 Jun 2020 13:47:16 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 4D5453C057C; Fri, 19 Jun 2020 19:47:13 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Vk8qxqVgzSCj; Fri, 19 Jun 2020 19:47:07 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 67C663C00BA; Fri, 19 Jun 2020 19:47:07 +0200 (CEST) Received: from vmlxhi-121.localdomain (10.72.92.132) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 19 Jun 2020 19:47:06 +0200 From: Michael Rodin To: =?utf-8?q?Niklas_S=C3=B6derlund?= , Mauro Carvalho Chehab , , , CC: Michael Rodin , , , Subject: [PATCH 1/2] [RFC] media: rcar-vin: send a V4L2 event to vdev if no frame captured after a timeout Date: Fri, 19 Jun 2020 19:46:10 +0200 Message-ID: <1592588777-100596-1-git-send-email-mrodin@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.72.92.132] Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Data flow from an upstream subdevice can stop permanently due to: - CSI2 transmission errors - silent failure of the source subdevice - disconnection of the source subdevice In those cases userspace waits for new buffers for an infinitely long time. In order to address this issue, use a timer to monitor, that rvin_irq() is capturing at least one frame within a IRQ_TIMEOUT_MS period. Otherwise send a new private v4l2 event to userspace. This event is exported to userspace via a new uapi header. Signed-off-by: Michael Rodin --- drivers/media/platform/rcar-vin/rcar-dma.c | 21 +++++++++++++++++++++ drivers/media/platform/rcar-vin/rcar-v4l2.c | 1 + drivers/media/platform/rcar-vin/rcar-vin.h | 6 ++++++ include/uapi/linux/rcar-vin.h | 10 ++++++++++ 4 files changed, 38 insertions(+) create mode 100644 include/uapi/linux/rcar-vin.h diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index 1a30cd0..bf8d733 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -937,6 +937,20 @@ static void rvin_capture_stop(struct rvin_dev *vin) #define RVIN_TIMEOUT_MS 100 #define RVIN_RETRIES 10 +static const struct v4l2_event rvin_irq_timeout = { + .type = V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT, +}; + +static void rvin_irq_timer_function(struct timer_list *timer) +{ + struct rvin_dev *vin = container_of(timer, struct rvin_dev, + irq_timer); + + vin_err(vin, "%s: frame completion timeout after %i ms!\n", + __func__, IRQ_TIMEOUT_MS); + v4l2_event_queue(&vin->vdev, &rvin_irq_timeout); +} + static irqreturn_t rvin_irq(int irq, void *data) { struct rvin_dev *vin = data; @@ -1008,6 +1022,8 @@ static irqreturn_t rvin_irq(int irq, void *data) vin_dbg(vin, "Dropping frame %u\n", vin->sequence); } + mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); + vin->sequence++; /* Prepare for next frame */ @@ -1252,6 +1268,8 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) if (ret) dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); + else + mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); return ret; } @@ -1305,6 +1323,8 @@ static void rvin_stop_streaming(struct vb2_queue *vq) /* Free scratch buffer. */ dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); + + del_timer_sync(&vin->irq_timer); } static const struct vb2_ops rvin_qops = { @@ -1370,6 +1390,7 @@ int rvin_dma_register(struct rvin_dev *vin, int irq) goto error; } + timer_setup(&vin->irq_timer, rvin_irq_timer_function, 0); return 0; error: rvin_dma_unregister(vin); diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c index f421e25..c644134 100644 --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c @@ -581,6 +581,7 @@ static int rvin_subscribe_event(struct v4l2_fh *fh, { switch (sub->type) { case V4L2_EVENT_SOURCE_CHANGE: + case V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT: return v4l2_event_subscribe(fh, sub, 4, NULL); } return v4l2_ctrl_subscribe_event(fh, sub); diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index c19d077..7408f67 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -14,12 +14,14 @@ #define __RCAR_VIN__ #include +#include #include #include #include #include #include +#include /* Number of HW buffers */ #define HW_BUFFER_NUM 3 @@ -30,6 +32,8 @@ /* Max number on VIN instances that can be in a system */ #define RCAR_VIN_NUM 8 +#define IRQ_TIMEOUT_MS 1000 + struct rvin_group; enum model_id { @@ -196,6 +200,7 @@ struct rvin_info { * @compose: active composing * @src_rect: active size of the video source * @std: active video standard of the video source + * @irq_timer: monitors regular capturing of frames in rvin_irq() * * @alpha: Alpha component to fill in for supported pixel formats */ @@ -240,6 +245,7 @@ struct rvin_dev { struct v4l2_rect src_rect; v4l2_std_id std; + struct timer_list irq_timer; unsigned int alpha; }; diff --git a/include/uapi/linux/rcar-vin.h b/include/uapi/linux/rcar-vin.h new file mode 100644 index 00000000..4eb7f5e --- /dev/null +++ b/include/uapi/linux/rcar-vin.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef RCAR_VIN_USER_H +#define RCAR_VIN_USER_H + +/* class for events sent by the rcar-vin driver */ +#define V4L2_EVENT_RCAR_VIN_CLASS V4L2_EVENT_PRIVATE_START +#define V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT (V4L2_EVENT_RCAR_VIN_CLASS | 0x1) + +#endif /* RCAR_VIN_USER_H */ From patchwork Fri Jun 19 17:46:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rodin X-Patchwork-Id: 11614781 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 628B713A0 for ; Fri, 19 Jun 2020 17:47:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53E3A20786 for ; Fri, 19 Jun 2020 17:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403921AbgFSRrY (ORCPT ); Fri, 19 Jun 2020 13:47:24 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:44825 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403903AbgFSRrX (ORCPT ); Fri, 19 Jun 2020 13:47:23 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id B88DA3C057C; Fri, 19 Jun 2020 19:47:20 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PJi1VxIm3hlR; Fri, 19 Jun 2020 19:47:15 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id AF3FF3C00BA; Fri, 19 Jun 2020 19:47:15 +0200 (CEST) Received: from vmlxhi-121.localdomain (10.72.92.132) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 19 Jun 2020 19:47:15 +0200 From: Michael Rodin To: =?utf-8?q?Niklas_S=C3=B6derlund?= , Mauro Carvalho Chehab , , , CC: Michael Rodin , , , Subject: [PATCH 2/2] [RFC] media: rcar-vin: make timeout of the irq timer configurable via v4l2 control Date: Fri, 19 Jun 2020 19:46:11 +0200 Message-ID: <1592588777-100596-2-git-send-email-mrodin@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592588777-100596-1-git-send-email-mrodin@de.adit-jv.com> References: <1592588777-100596-1-git-send-email-mrodin@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.92.132] Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Different framerates imply different periods between successive frames. Therefore it is reasonable to make the timeout of the irq_timer configurable at the run time so userspace can avoid unnecessary long waiting times. Therefore this commit adds a new custom control to rcar-vin. This allows to change the timeout before the start of streaming. Signed-off-by: Michael Rodin --- drivers/media/platform/rcar-vin/rcar-core.c | 17 ++++++++++++++++- drivers/media/platform/rcar-vin/rcar-dma.c | 14 +++++++++----- drivers/media/platform/rcar-vin/rcar-vin.h | 5 +++++ include/uapi/linux/rcar-vin.h | 7 +++++++ include/uapi/linux/v4l2-controls.h | 6 ++++++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 7440c89..81faa87 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -884,6 +884,17 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin) return 0; } +static const struct v4l2_ctrl_config rvin_ctrl_irq_timeout = { + .ops = &rvin_ctrl_ops, + .id = V4L2_CID_RCAR_VIN_IRQ_TIMEOUT, + .name = "frame completion timeout", + .type = V4L2_CTRL_TYPE_INTEGER, + .min = 0, + .max = S32_MAX, + .step = 1, + .def = IRQ_TIMEOUT_MS, +}; + static int rvin_mc_init(struct rvin_dev *vin) { int ret; @@ -901,13 +912,17 @@ static int rvin_mc_init(struct rvin_dev *vin) if (ret) rvin_group_put(vin); - ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 1); + ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 2); if (ret < 0) return ret; v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops, V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255); + vin->ctrl_irq_timeout = v4l2_ctrl_new_custom(&vin->ctrl_handler, + &rvin_ctrl_irq_timeout, + NULL); + if (vin->ctrl_handler.error) { ret = vin->ctrl_handler.error; v4l2_ctrl_handler_free(&vin->ctrl_handler); diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c index bf8d733..062f338 100644 --- a/drivers/media/platform/rcar-vin/rcar-dma.c +++ b/drivers/media/platform/rcar-vin/rcar-dma.c @@ -947,7 +947,7 @@ static void rvin_irq_timer_function(struct timer_list *timer) irq_timer); vin_err(vin, "%s: frame completion timeout after %i ms!\n", - __func__, IRQ_TIMEOUT_MS); + __func__, jiffies_to_msecs(vin->irq_timeout)); v4l2_event_queue(&vin->vdev, &rvin_irq_timeout); } @@ -1022,7 +1022,7 @@ static irqreturn_t rvin_irq(int irq, void *data) vin_dbg(vin, "Dropping frame %u\n", vin->sequence); } - mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); + mod_timer(&vin->irq_timer, jiffies + vin->irq_timeout); vin->sequence++; @@ -1233,6 +1233,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) struct rvin_dev *vin = vb2_get_drv_priv(vq); unsigned long flags; int ret; + s32 irq_timeout = v4l2_ctrl_g_ctrl(vin->ctrl_irq_timeout); /* Allocate scratch buffer. */ vin->scratch = dma_alloc_coherent(vin->dev, vin->format.sizeimage, @@ -1265,11 +1266,14 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count) spin_unlock_irqrestore(&vin->qlock, flags); out: - if (ret) + if (ret) { dma_free_coherent(vin->dev, vin->format.sizeimage, vin->scratch, vin->scratch_phys); - else - mod_timer(&vin->irq_timer, jiffies + msecs_to_jiffies(IRQ_TIMEOUT_MS)); + } else { + vin->irq_timeout = msecs_to_jiffies(irq_timeout); + mod_timer(&vin->irq_timer, jiffies + vin->irq_timeout); + vin_dbg(vin, "%s: set irq timer to %i ms\n", __func__, irq_timeout); + } return ret; } diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index 7408f67..4e514e7 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -201,6 +201,9 @@ struct rvin_info { * @src_rect: active size of the video source * @std: active video standard of the video source * @irq_timer: monitors regular capturing of frames in rvin_irq() + * @irq_timeout: timeout value in jiffies, which is currently used by + * @irq_timer and can be changed via @ctrl_irq_timeout + * @ctrl_irq_timeout: controls value of @irq_timeout * * @alpha: Alpha component to fill in for supported pixel formats */ @@ -246,6 +249,8 @@ struct rvin_dev { v4l2_std_id std; struct timer_list irq_timer; + unsigned long irq_timeout; + struct v4l2_ctrl *ctrl_irq_timeout; unsigned int alpha; }; diff --git a/include/uapi/linux/rcar-vin.h b/include/uapi/linux/rcar-vin.h index 4eb7f5e..6c72584 100644 --- a/include/uapi/linux/rcar-vin.h +++ b/include/uapi/linux/rcar-vin.h @@ -3,8 +3,15 @@ #ifndef RCAR_VIN_USER_H #define RCAR_VIN_USER_H +#include + /* class for events sent by the rcar-vin driver */ #define V4L2_EVENT_RCAR_VIN_CLASS V4L2_EVENT_PRIVATE_START #define V4L2_EVENT_RCAR_VIN_IRQ_TIMEOUT (V4L2_EVENT_RCAR_VIN_CLASS | 0x1) +/* private controls for rcar-vin */ +enum rcar_vin_ctrl_id { + V4L2_CID_RCAR_VIN_IRQ_TIMEOUT = V4L2_CID_USER_RCAR_VIN_BASE +}; + #endif /* RCAR_VIN_USER_H */ diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 6227141..cf4f085 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -198,6 +198,12 @@ enum v4l2_colorfx { */ #define V4L2_CID_USER_ATMEL_ISC_BASE (V4L2_CID_USER_BASE + 0x10c0) +/* + * The base for the rcar-vin driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_RCAR_VIN_BASE (V4L2_CID_USER_BASE + 0x10d0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */