Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp4215670rba; Tue, 2 Apr 2024 10:22:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6XhotCjW8fDRNYroa4GMOM70lvah3IFwRB2jgTbHWpsAe7MNXQIZaKJN7VMTXCioIvXvExfTY6SO3gPlqpcme/3K40QVPqlXnL1E5Tw== X-Google-Smtp-Source: AGHT+IFdh2899UlYbrR++zC2y7x6Xhl15LLxJJpCn2QQXCCXSTw0R8AhlvDgTtF1O+oIt1ZNe/Mq X-Received: by 2002:a05:6a00:4b02:b0:6ea:b1f5:112c with SMTP id kq2-20020a056a004b0200b006eab1f5112cmr14042214pfb.27.1712078568609; Tue, 02 Apr 2024 10:22:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712078568; cv=pass; d=google.com; s=arc-20160816; b=y/cqu36hH8obRJ8gNRfoXtVsNLyN5SQMoFqkA8KMDLyAMrmvaVK4H4utX+Igb1p/wn qxOz6H0fOA5evVls/QzNZSOTG8damGubKMeth0RrnqUKcE1efBl73DQDhJ3DSIK/aYad cIcrGlZSlNit6EBLejCp0BZ4ySkVB2Moih0z6VhyrsRZPMhXYZ1mmu+QCPumZBHETjgg 702eh4UaA03o5oFBAo4Gx3juxwovJiTuM9RrMoSvrXu9Czxpvn2fq9uRoR/tbUUEXaAY Sub66boY0yUggQQEEefkncZazqjxjsHijK+Q+DzO39nFstcVBKoFcZeAG2qLUlp7+Kd1 ibMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wP6dhYTebLfn0dU0utzWWRiXR+PetY3yk82kLJ9TWMg=; fh=kjN2uVQwt6wWxsMIB0+tK2hv2kwvN+UfYuMT3E+f0Rs=; b=ZYlhmmNAhK0uPn2IJJPyLsfYGvG/107VeuZ/k4Z9zX2fOVi6gSGXPsn2T6xacO5V/5 njBEDkD1Sqjiwp6tWeesOKwzTibBuLeAVrT6SOrvt5n99lsWN+kTXh6yAOrBb9RHkQfX a/pJdvPpgvR1+L8Jre4DEtpr7PG0M0Fq+srsZwa5N6g2tJDQQKFaGxmC6mVBa7oPbzoe jiDMYJVEuIxfspVsEA0wX69v2f/7OsaZcOGLyDvrBxpeSogWKJclxSFLfEGUbjcRkf6Y SVUOytLMgwPWvC5yv/yJKOJFn2Rnf+9jQLUCLz3YsW0cNOWRWe7zbWRkqGnU6yf/3tTZ iZzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hfmzf294; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-128384-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128384-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 25-20020a631759000000b005e42b4bb9dasi11386577pgx.213.2024.04.02.10.22.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 10:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128384-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hfmzf294; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-128384-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128384-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D0BA8B28453 for ; Tue, 2 Apr 2024 16:51:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66B6215E1F2; Tue, 2 Apr 2024 16:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hfmzf294" Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99B1515DBCA; Tue, 2 Apr 2024 16:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712076412; cv=none; b=f87TBVL0jb4k7dMG3vb8jIM5naknIo79XLlA4qPnBPG4j25ex8tDnzNU4yWKgRMa2Uctbh5J+Y7F4ZrTuFFnQJT692P1eBTJ0qa7CQCgZCKbN4dFxpbiezGLGuPy1uq9//TTil1em2d7iHklq5isz/IJrkUPCYmsiOtd27Hb72A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712076412; c=relaxed/simple; bh=KeQZSc6qLuPCqKYTf+fXZ35RQcX3xbkDNgXZF0afbWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RTRfC8dYlMp4T3aPMXmdxN1XejR/PHvKa7WEKwsQZw5ew4K4C4Nrq5m+YY73mXabZjM7gxtvv3AzMnx3aVJDnUyPDDoBfI1fUTwEbsUvQGXQ81fOBoDTT++88xRfhLMHXRk1bG9invJA6z8F/10fBYgmKXtREWIVETrOiJo6G58= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hfmzf294; arc=none smtp.client-ip=209.85.208.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d6fd3cfaa6so74490611fa.2; Tue, 02 Apr 2024 09:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712076408; x=1712681208; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wP6dhYTebLfn0dU0utzWWRiXR+PetY3yk82kLJ9TWMg=; b=hfmzf294g1aomp5rJ1CgQO4g8oMdhNHdo1anXPwPricmff0YOEETgTaorhuXMRkP7W 1yzQYJmCfh8DOuNiu433cvvfYlay2Bud/a0aUM/uVIRhT806JNQfws+BlSTvD0NkgdkS 91z5m8Zkm8N8o60/vAECAhL54yGcjdbLSnkji8tjlPv4pXbDzFQi3smdRROyvjOghKFh hfXiWGIsbP/85+YD7snUc6J6l/8sd0rK+OQFvsMkWopQp1mAhf1epNf8ZcdnoTQMWd7S Oe2JHrlUIGVPDq6Q5HzEWnnfM62mKi7iPJLTjEheRD+g0tMqLM9vKsXkhlmH2JpXb4gl uJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712076408; x=1712681208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wP6dhYTebLfn0dU0utzWWRiXR+PetY3yk82kLJ9TWMg=; b=Y/mzhk/XhsYWyIuX/7CTx/ZPHPiSJ4oNNO7zBBeXAJ+SmUU1QkGsp2IHZADytX7cXB 5pos3LkFjaf43ddhSY3k5D1KtVUIoOwLnU4TO/jYC0Zh/cflQlRgHqnvlwZfvGrunjNS K/IB1+/fNz8EnIO7eMB8vlaAFpg+zitTrdoLc6dqmS2zhIb7pxY2HJqEVfkhJ56gRNVJ B3lO43S4uoaWcktW+ez7OwiTG66lcDHExItl3kQlBQu35CSm3k1oyAB8a5fHPjA8RzFM Q62PfCNvXdAaX9H64/FOY9MMkS32YGo0P9dmP7K5ihAbqhrz0dQHVBwwBLqNOwjpm1iW DXfA== X-Forwarded-Encrypted: i=1; AJvYcCVcsLc0VegQhrfBXuEVFjRE66yIPqO+/HFhK/E918pr6hzw85JnaVbfkDKehGSxi2FDJbNY7q1Im+T+gU19USHl8GrOrFxymckbXml5 X-Gm-Message-State: AOJu0Ywf4G+obevZ64nxTMndZjI5sof1YoBaHYfiQfSWjqrESWfJ1Ljw oUv1Ox4GRjsWnmlHRQt7PAMpsQcQAJ3vi2S7/DknEN9/XfrVrQQZnkW7ZWQw1ybrYg== X-Received: by 2002:a2e:be1e:0:b0:2d8:a71:b17a with SMTP id z30-20020a2ebe1e000000b002d80a71b17amr150576ljq.3.1712076408367; Tue, 02 Apr 2024 09:46:48 -0700 (PDT) Received: from localhost ([77.91.78.25]) by smtp.gmail.com with ESMTPSA id f10-20020a2e950a000000b002d45ad8efdesm1643033ljh.106.2024.04.02.09.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 09:46:48 -0700 (PDT) From: Mikhail Rudenko To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus , Laurent Pinchart , Jacopo Mondi , Tommaso Merciai , Christophe JAILLET , Dave Stevenson , Mauro Carvalho Chehab , Mikhail Rudenko Subject: [PATCH v4 19/20] media: i2c: ov4689: Refactor ov4689_s_stream Date: Tue, 2 Apr 2024 19:45:50 +0300 Message-ID: <20240402164552.19171-20-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402164552.19171-1-mike.rudenko@gmail.com> References: <20240402164552.19171-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Split ov4689_s_stream into ov4689_stream_on and ov4689_stream_off functions. Also remove repetitive pm_runtime_put calls and call pm_runtime_put once at the end of the ov4689_stream_on function if any error occurred. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 100 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index f43be255234b..e652d626f32f 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -537,61 +537,67 @@ static int ov4689_setup_blc_anchors(struct ov4689 *ov4689, return ret; } +static int ov4689_stream_on(struct ov4689 *ov4689, + struct v4l2_subdev_state *sd_state) +{ + int ret; + + ret = pm_runtime_resume_and_get(ov4689->dev); + if (ret < 0) + return ret; + + ret = cci_multi_reg_write(ov4689->regmap, ov4689_common_regs, + ARRAY_SIZE(ov4689_common_regs), NULL); + if (ret) + goto error; + + ret = ov4689_setup_timings(ov4689, sd_state); + if (ret) + goto error; + + ret = ov4689_setup_blc_anchors(ov4689, sd_state); + if (ret) + goto error; + + ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); + if (ret) + goto error; + + ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, + OV4689_MODE_STREAMING, NULL); + if (ret) + goto error; + + return 0; + +error: + pm_runtime_put(ov4689->dev); + return ret; +} + +static int ov4689_stream_off(struct ov4689 *ov4689) +{ + cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, + NULL); + pm_runtime_mark_last_busy(ov4689->dev); + pm_runtime_put_autosuspend(ov4689->dev); + + return 0; +} + static int ov4689_s_stream(struct v4l2_subdev *sd, int on) { struct ov4689 *ov4689 = to_ov4689(sd); struct v4l2_subdev_state *sd_state; - struct device *dev = ov4689->dev; - int ret = 0; + int ret; sd_state = v4l2_subdev_lock_and_get_active_state(&ov4689->subdev); - if (on) { - ret = pm_runtime_resume_and_get(dev); - if (ret < 0) - goto unlock_and_return; - - ret = cci_multi_reg_write(ov4689->regmap, - ov4689_common_regs, - ARRAY_SIZE(ov4689_common_regs), - NULL); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = ov4689_setup_timings(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = ov4689_setup_blc_anchors(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, - OV4689_MODE_STREAMING, NULL); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - } else { - cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, - OV4689_MODE_SW_STANDBY, NULL); - pm_runtime_mark_last_busy(dev); - pm_runtime_put_autosuspend(dev); - } + if (on) + ret = ov4689_stream_on(ov4689, sd_state); + else + ret = ov4689_stream_off(ov4689); -unlock_and_return: v4l2_subdev_unlock_state(sd_state); return ret; -- 2.44.0