From patchwork Tue May 10 11:51:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15865 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B522EC3272 for ; Tue, 10 May 2022 11:52:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4343165675; Tue, 10 May 2022 13:52:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652183547; bh=FoyLYFnys/3AHuA1i8+u18sJF+/odDK5/oJembX9Pbs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=A8hgDSle0Ao2RCgDpGB9m4UO0xVcuNIWAgvWpvSxD7cVfdpmOwxIGJ4eHK/R7qt7I 4auceCHsGYQxfhRKeleYq2xKEakcQwBL09s3Ru+Ls6nly8ZvxFTCSHbsyDP84qonis AgWWUxLKqdiO5+RlB6Kavcpi66VRgsHjtMsPhdpWHJdRbjvHWSu+ARkz+ehU4cjSnf NyNFILzrRTF/3pBu3COzNP78JEaIf6r08+2JIiIwQApJrm/1TPPplCt4b0IjdNTSHm cSAHmX879v/7o9w4R5/6PTk+81a5kY+iwSvPe8tWk76kIWdEjRag9HT3uB8MS1L17U eewcFAyeNXN0A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7389C65680 for ; Tue, 10 May 2022 13:52:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ag6xtEXP"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 91FFEB9A; Tue, 10 May 2022 13:52:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652183538; bh=FoyLYFnys/3AHuA1i8+u18sJF+/odDK5/oJembX9Pbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ag6xtEXPE/rme2wp/0rCz8XE142LVeBm3N+8xqV03LnLPBiOw0zskdyQPY9RKxWsh VreiwKk5bo3WpYzBWhXKHSBC73n3H06rho57V+tSyK8rcrcUppggC8qDJHHtlXeufJ yuO1a90H8bbhKVw8PIr5sLYzojfcaDFzNASzh4RU= To: libcamera-devel@lists.libcamera.org Date: Tue, 10 May 2022 14:51:22 +0300 Message-Id: <20220510115147.19360-26-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> References: <20220510115147.19360-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 25/50] staging: media: imx: imx7-media-csi: Inline pipeline start/stop X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Martin Kepplinger , kernel@pengutronix.de, Dorota Czaplejewicz , Alexander Stein , Rui Miguel Silva , Philipp Zabel , Steve Longerbeam Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The imx7_csi_media_pipeline_set_stream() function has separate branches for the start and stop paths, surrounded by mutex lock/unlock. That is very little shared code, inline the locking and corresponding branch in each of the two callers. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx7-media-csi.c | 58 ++++++++-------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 8600fc4d6be2..44c19c73da97 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -1067,31 +1067,6 @@ static int imx7_csi_video_validate_fmt(struct imx7_csi *csi) return 0; } -static int imx7_csi_media_pipeline_set_stream(struct imx7_csi *csi, bool on) -{ - struct imx_media_dev *imxmd = &csi->imxmd; - int ret = 0; - - mutex_lock(&imxmd->md.graph_mutex); - - if (on) { - ret = __media_pipeline_start(&csi->sd.entity, &imxmd->pipe); - if (ret) - goto out; - ret = v4l2_subdev_call(&csi->sd, video, s_stream, 1); - if (ret) - __media_pipeline_stop(&csi->sd.entity); - } else { - v4l2_subdev_call(&csi->sd, video, s_stream, 0); - if (csi->sd.entity.pipe) - __media_pipeline_stop(&csi->sd.entity); - } - -out: - mutex_unlock(&imxmd->md.graph_mutex); - return ret; -} - static int imx7_csi_video_start_streaming(struct vb2_queue *vq, unsigned int count) { @@ -1103,18 +1078,29 @@ static int imx7_csi_video_start_streaming(struct vb2_queue *vq, ret = imx7_csi_video_validate_fmt(csi); if (ret) { dev_err(csi->dev, "capture format not valid\n"); - goto return_bufs; + goto err_buffers; } - ret = imx7_csi_media_pipeline_set_stream(csi, true); - if (ret) { - dev_err(csi->dev, "pipeline start failed with %d\n", ret); - goto return_bufs; - } + mutex_lock(&csi->imxmd.md.graph_mutex); + + ret = __media_pipeline_start(&csi->sd.entity, &csi->imxmd.pipe); + if (ret) + goto err_unlock; + + ret = v4l2_subdev_call(&csi->sd, video, s_stream, 1); + if (ret) + goto err_stop; + + mutex_unlock(&csi->imxmd.md.graph_mutex); return 0; -return_bufs: +err_stop: + __media_pipeline_stop(&csi->sd.entity); +err_unlock: + mutex_unlock(&csi->imxmd.md.graph_mutex); + dev_err(csi->dev, "pipeline start failed with %d\n", ret); +err_buffers: spin_lock_irqsave(&csi->q_lock, flags); list_for_each_entry_safe(buf, tmp, &csi->ready_q, list) { list_del(&buf->list); @@ -1130,11 +1116,11 @@ static void imx7_csi_video_stop_streaming(struct vb2_queue *vq) struct imx_media_buffer *frame; struct imx_media_buffer *tmp; unsigned long flags; - int ret; - ret = imx7_csi_media_pipeline_set_stream(csi, false); - if (ret) - dev_warn(csi->dev, "pipeline stop failed with %d\n", ret); + mutex_lock(&csi->imxmd.md.graph_mutex); + v4l2_subdev_call(&csi->sd, video, s_stream, 0); + __media_pipeline_stop(&csi->sd.entity); + mutex_unlock(&csi->imxmd.md.graph_mutex); /* release all active buffers */ spin_lock_irqsave(&csi->q_lock, flags);