From patchwork Tue Jan 5 15:28:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 357176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15657C433E0 for ; Tue, 5 Jan 2021 15:35:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEBB922B45 for ; Tue, 5 Jan 2021 15:35:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728197AbhAEPfB (ORCPT ); Tue, 5 Jan 2021 10:35:01 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:38064 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727514AbhAEPe4 (ORCPT ); Tue, 5 Jan 2021 10:34:56 -0500 Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 67B911878; Tue, 5 Jan 2021 16:29:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1609860596; bh=VPPGRmcoHXolXt+v7I43YyrL0OKFyiraFxgQbtRl1bE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVvjrqS9v3+q2drmSel2A+u7Nz3Ck0YsQxY68pNZU8m80NMY52v3uByazbL34dQLr wDJl3k6UmUVpZDg1PSUgckoZCks+Jzuhvim46DzoYmCimdnMBnqbcOAqqZMZjPrMdN L2C/bD78Dwc2INaM46VUjGtiFaxvSR7vihTDcwfM= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Steve Longerbeam , Philipp Zabel , Ezequiel Garcia Subject: [PATCH 33/75] media: imx: imx7-media-csi: Move (de)init from link setup to .s_stream() Date: Tue, 5 Jan 2021 17:28:10 +0200 Message-Id: <20210105152852.5733-34-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210105152852.5733-1-laurent.pinchart@ideasonboard.com> References: <20210105152852.5733-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org There's no need to initialize the CSI every time a link is enabled (and de-initialize it when a link is disabled). Move initialization to .s_stream() instead. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx7-media-csi.c | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 69ff491671a3..60202f56343e 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -184,7 +184,6 @@ struct imx7_csi { u32 frame_sequence; bool last_eof; - bool is_init; bool is_streaming; bool is_csi2; @@ -402,9 +401,6 @@ static int imx7_csi_init(struct imx7_csi *csi) { int ret; - if (csi->is_init) - return 0; - ret = clk_prepare_enable(csi->mclk); if (ret < 0) return ret; @@ -412,22 +408,15 @@ static int imx7_csi_init(struct imx7_csi *csi) imx7_csi_init_interface(csi); imx7_csi_dmareq_rff_enable(csi); - csi->is_init = true; - return 0; } static void imx7_csi_deinit(struct imx7_csi *csi) { - if (!csi->is_init) - return; - imx7_csi_hw_reset(csi); imx7_csi_init_interface(csi); imx7_csi_dmareq_rff_disable(csi); clk_disable_unprepare(csi->mclk); - - csi->is_init = false; } static int imx7_csi_link_setup(struct media_entity *entity, @@ -462,7 +451,7 @@ static int imx7_csi_link_setup(struct media_entity *entity, csi->src_sd = NULL; } - goto init; + goto unlock; } /* source pad */ @@ -476,12 +465,6 @@ static int imx7_csi_link_setup(struct media_entity *entity, csi->sink = NULL; } -init: - if (csi->sink || csi->src_sd) - ret = imx7_csi_init(csi); - else - imx7_csi_deinit(csi); - unlock: mutex_unlock(&csi->lock); @@ -857,19 +840,28 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable) goto out_unlock; if (enable) { + ret = imx7_csi_init(csi); + if (ret < 0) + goto out_unlock; + ret = v4l2_subdev_call(csi->src_sd, video, s_stream, 1); - if (ret < 0) + if (ret < 0) { + imx7_csi_deinit(csi); goto out_unlock; + } ret = imx7_csi_streaming_start(csi); if (ret < 0) { v4l2_subdev_call(csi->src_sd, video, s_stream, 0); + imx7_csi_deinit(csi); goto out_unlock; } } else { imx7_csi_streaming_stop(csi); v4l2_subdev_call(csi->src_sd, video, s_stream, 0); + + imx7_csi_deinit(csi); } csi->is_streaming = !!enable;