From patchwork Mon Mar 14 10:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12780012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE008C433FE for ; Mon, 14 Mar 2022 10:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238616AbiCNKlE (ORCPT ); Mon, 14 Mar 2022 06:41:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236655AbiCNKlD (ORCPT ); Mon, 14 Mar 2022 06:41:03 -0400 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [IPv6:2001:4b98:dc4:8::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C468B43AEF for ; Mon, 14 Mar 2022 03:39:52 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 2DDD320000D; Mon, 14 Mar 2022 10:39:50 +0000 (UTC) From: Jacopo Mondi To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Jacopo Mondi , Rui Miguel Silva , kernel@pengutronix.de, linux-imx@nxp.com, Paul Elder , Sakari Ailus Subject: [PATCH 1/5] media: imx: imx-mipi-csis: Simplify mipi_csis_s_stream() Date: Mon, 14 Mar 2022 11:39:37 +0100 Message-Id: <20220314103941.46021-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314103941.46021-1-jacopo@jmondi.org> References: <20220314103941.46021-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Simplify the mipi_csis_s_stream() function. This actually fixes a bug, as if calling the subdev's s_stream(1) fails, mipi_csis_stop_stream() was not called. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/platform/imx/imx-mipi-csis.c | 58 ++++++++++++---------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index c4d1a6fe5007..60e7f0452582 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -910,43 +910,51 @@ static struct mipi_csis_device *sd_to_mipi_csis_device(struct v4l2_subdev *sdev) static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable) { struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd); - int ret = 0; + int ret; - if (enable) { - ret = mipi_csis_calculate_params(csis); - if (ret < 0) - return ret; + if (!enable) { + mutex_lock(&csis->lock); - mipi_csis_clear_counters(csis); + v4l2_subdev_call(csis->src_sd, video, s_stream, 0); - ret = pm_runtime_resume_and_get(csis->dev); - if (ret < 0) - return ret; + mipi_csis_stop_stream(csis); + if (csis->debug.enable) + mipi_csis_log_counters(csis, true); + + mutex_unlock(&csis->lock); + + pm_runtime_put(csis->dev); + + return 0; } - mutex_lock(&csis->lock); + ret = mipi_csis_calculate_params(csis); + if (ret < 0) + return ret; - if (enable) { - mipi_csis_start_stream(csis); - ret = v4l2_subdev_call(csis->src_sd, video, s_stream, 1); - if (ret < 0) - goto unlock; + mipi_csis_clear_counters(csis); - mipi_csis_log_counters(csis, true); - } else { - v4l2_subdev_call(csis->src_sd, video, s_stream, 0); + ret = pm_runtime_resume_and_get(csis->dev); + if (ret < 0) + return ret; - mipi_csis_stop_stream(csis); + mutex_lock(&csis->lock); - if (csis->debug.enable) - mipi_csis_log_counters(csis, true); - } + mipi_csis_start_stream(csis); + ret = v4l2_subdev_call(csis->src_sd, video, s_stream, 1); + if (ret < 0) + goto out; + + mipi_csis_log_counters(csis, true); -unlock: mutex_unlock(&csis->lock); - if (!enable || ret < 0) - pm_runtime_put(csis->dev); + return 0; + +out: + mipi_csis_stop_stream(csis); + mutex_unlock(&csis->lock); + pm_runtime_put(csis->dev); return ret; } From patchwork Mon Mar 14 10:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12780013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D8EBC433F5 for ; Mon, 14 Mar 2022 10:39:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238614AbiCNKlF (ORCPT ); Mon, 14 Mar 2022 06:41:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238619AbiCNKlE (ORCPT ); Mon, 14 Mar 2022 06:41:04 -0400 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AEA3EA8E for ; Mon, 14 Mar 2022 03:39:54 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 73634200010; Mon, 14 Mar 2022 10:39:51 +0000 (UTC) From: Jacopo Mondi To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Jacopo Mondi , Rui Miguel Silva , kernel@pengutronix.de, linux-imx@nxp.com, Paul Elder , Sakari Ailus Subject: [PATCH 2/5] media: imx: imx-mipi-csis: Drop powered flag Date: Mon, 14 Mar 2022 11:39:38 +0100 Message-Id: <20220314103941.46021-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314103941.46021-1-jacopo@jmondi.org> References: <20220314103941.46021-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The mipi_csis_device.powered flag only serves for the purpose of not accessing registers in mipi_csis_log_status() when the interface is not powered up. Instead of manually tracking the power state, rely on pm_runtime_get_if_in_use() to remove the 'powered' flag. Also remove the locking in the function as runtime_pm() is refcounted and there's no risk of the interface being powered down behind our backs. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/platform/imx/imx-mipi-csis.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index 60e7f0452582..b76bb129a416 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -327,10 +327,9 @@ struct mipi_csis_device { u32 hs_settle; u32 clk_settle; - struct mutex lock; /* Protect csis_fmt, format_mbus and powered */ + struct mutex lock; /* Protect csis_fmt and format_mbus */ const struct csis_pix_format *csis_fmt; struct v4l2_mbus_framefmt format_mbus[CSIS_PADS_NUM]; - bool powered; spinlock_t slock; /* Protect events */ struct mipi_csis_event events[MIPI_CSIS_NUM_EVENTS]; @@ -1174,11 +1173,11 @@ static int mipi_csis_log_status(struct v4l2_subdev *sd) { struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd); - mutex_lock(&csis->lock); mipi_csis_log_counters(csis, true); - if (csis->debug.enable && csis->powered) + if (csis->debug.enable && pm_runtime_get_if_in_use(csis->dev)) { mipi_csis_dump_regs(csis); - mutex_unlock(&csis->lock); + pm_runtime_put(csis->dev); + } return 0; } @@ -1344,8 +1343,6 @@ static int __maybe_unused mipi_csis_runtime_suspend(struct device *dev) mipi_csis_clk_disable(csis); - csis->powered = false; - unlock: mutex_unlock(&csis->lock); @@ -1366,8 +1363,6 @@ static int __maybe_unused mipi_csis_runtime_resume(struct device *dev) mipi_csis_clk_enable(csis); - csis->powered = true; - unlock: mutex_unlock(&csis->lock); From patchwork Mon Mar 14 10:39:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12780014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA44BC433EF for ; Mon, 14 Mar 2022 10:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238621AbiCNKlH (ORCPT ); Mon, 14 Mar 2022 06:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238617AbiCNKlF (ORCPT ); Mon, 14 Mar 2022 06:41:05 -0400 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2DD34348F for ; Mon, 14 Mar 2022 03:39:55 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 16D01200012; Mon, 14 Mar 2022 10:39:52 +0000 (UTC) From: Jacopo Mondi To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Jacopo Mondi , Rui Miguel Silva , kernel@pengutronix.de, linux-imx@nxp.com, Paul Elder , Sakari Ailus Subject: [PATCH 3/5] media: imx: imx-mipi-csis: Remove lock from s_stream Date: Mon, 14 Mar 2022 11:39:39 +0100 Message-Id: <20220314103941.46021-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314103941.46021-1-jacopo@jmondi.org> References: <20220314103941.46021-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The s_stream() operation implementation was locked to avoid races with the mipi_csis_log_status() which access the platform registers and needs the interface to be powered up. As powering is now handled by runtime_pm which is refcounted, it is not necessary to manually lock s_stream() anymore. As the error path is now simplified, we can inline it. Signed-off-by: Jacopo Mondi --- drivers/media/platform/imx/imx-mipi-csis.c | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index b76bb129a416..4a6152c13d52 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -912,16 +912,12 @@ static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable) int ret; if (!enable) { - mutex_lock(&csis->lock); - v4l2_subdev_call(csis->src_sd, video, s_stream, 0); mipi_csis_stop_stream(csis); if (csis->debug.enable) mipi_csis_log_counters(csis, true); - mutex_unlock(&csis->lock); - pm_runtime_put(csis->dev); return 0; @@ -937,25 +933,18 @@ static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable) if (ret < 0) return ret; - mutex_lock(&csis->lock); - mipi_csis_start_stream(csis); ret = v4l2_subdev_call(csis->src_sd, video, s_stream, 1); - if (ret < 0) - goto out; + if (ret < 0) { + mipi_csis_stop_stream(csis); + pm_runtime_put(csis->dev); - mipi_csis_log_counters(csis, true); + return ret; + } - mutex_unlock(&csis->lock); + mipi_csis_log_counters(csis, true); return 0; - -out: - mipi_csis_stop_stream(csis); - mutex_unlock(&csis->lock); - pm_runtime_put(csis->dev); - - return ret; } static struct v4l2_mbus_framefmt * From patchwork Mon Mar 14 10:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12780015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2073C433FE for ; Mon, 14 Mar 2022 10:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238624AbiCNKlI (ORCPT ); Mon, 14 Mar 2022 06:41:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238619AbiCNKlH (ORCPT ); Mon, 14 Mar 2022 06:41:07 -0400 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [IPv6:2001:4b98:dc4:8::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CCE93EA92 for ; Mon, 14 Mar 2022 03:39:57 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 9480E200009; Mon, 14 Mar 2022 10:39:54 +0000 (UTC) From: Jacopo Mondi To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Jacopo Mondi , Rui Miguel Silva , kernel@pengutronix.de, linux-imx@nxp.com, Paul Elder , Sakari Ailus Subject: [PATCH 4/5] media: imx: imx-mipi-csis: Remove duplicated check Date: Mon, 14 Mar 2022 11:39:40 +0100 Message-Id: <20220314103941.46021-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314103941.46021-1-jacopo@jmondi.org> References: <20220314103941.46021-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The mipi_csis_log_counters() function already checks for csis->debug.enable, it is not necessary to do the same in the caller. Compatc the code in the caller as well by removing an empty line. Signed-off-by: Jacopo Mondi --- drivers/media/platform/imx/imx-mipi-csis.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index 4a6152c13d52..4bb469fcb6b3 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -913,11 +913,8 @@ static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable) if (!enable) { v4l2_subdev_call(csis->src_sd, video, s_stream, 0); - mipi_csis_stop_stream(csis); - if (csis->debug.enable) - mipi_csis_log_counters(csis, true); - + mipi_csis_log_counters(csis, true); pm_runtime_put(csis->dev); return 0; From patchwork Mon Mar 14 10:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12780016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06465C433EF for ; Mon, 14 Mar 2022 10:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238619AbiCNKlJ (ORCPT ); Mon, 14 Mar 2022 06:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238617AbiCNKlI (ORCPT ); Mon, 14 Mar 2022 06:41:08 -0400 Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B321F43AD1 for ; Mon, 14 Mar 2022 03:39:58 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 3CF20200010; Mon, 14 Mar 2022 10:39:56 +0000 (UTC) From: Jacopo Mondi To: Laurent Pinchart , linux-media@vger.kernel.org Cc: Jacopo Mondi , Rui Miguel Silva , kernel@pengutronix.de, linux-imx@nxp.com, Paul Elder , Sakari Ailus Subject: [PATCH 5/5] media: imx: imx-mipi-csis: Protect mipi_csis_dump_regs() Date: Mon, 14 Mar 2022 11:39:41 +0100 Message-Id: <20220314103941.46021-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314103941.46021-1-jacopo@jmondi.org> References: <20220314103941.46021-1-jacopo@jmondi.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The mipi_csis_dump_regs() function accesses the interface registers in order to printout their values for debug purposes. As the function access the registers, it requires the interface to be powered up. Currently this is only enforced in one of the function's callers (mipi_csis_log_status)() but not when the function is called by the debugfs attribute handler. Make sure to access registers only if the interface is powered up and remove the same check from the caller. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/platform/imx/imx-mipi-csis.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index 4bb469fcb6b3..3437455b9c82 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -857,6 +857,9 @@ static int mipi_csis_dump_regs(struct mipi_csis_device *csis) unsigned int i; u32 cfg; + if (!pm_runtime_get_if_in_use(csis->dev)) + return 0; + dev_info(csis->dev, "--- REGISTERS ---\n"); for (i = 0; i < ARRAY_SIZE(registers); i++) { @@ -864,6 +867,8 @@ static int mipi_csis_dump_regs(struct mipi_csis_device *csis) dev_info(csis->dev, "%14s: 0x%08x\n", registers[i].name, cfg); } + pm_runtime_put(csis->dev); + return 0; } @@ -1160,10 +1165,8 @@ static int mipi_csis_log_status(struct v4l2_subdev *sd) struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd); mipi_csis_log_counters(csis, true); - if (csis->debug.enable && pm_runtime_get_if_in_use(csis->dev)) { + if (csis->debug.enable) mipi_csis_dump_regs(csis); - pm_runtime_put(csis->dev); - } return 0; }