From patchwork Wed Jan 31 05:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 194495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1692861dyb; Tue, 30 Jan 2024 21:55:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzRmBFq9y9Gdugn2qJoivSlacamlEHT9EZlfRdfqQfgcp07Zx83qtH7A8ChEmfN2T7Smx9 X-Received: by 2002:a81:72c2:0:b0:5fb:da77:af07 with SMTP id n185-20020a8172c2000000b005fbda77af07mr496362ywc.32.1706680512326; Tue, 30 Jan 2024 21:55:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706680512; cv=pass; d=google.com; s=arc-20160816; b=DqmgGOVkoiSKmy59kDOWImni4VFkDJNKCWjFHvQRJjXdxFeWc0X5DfQ4vMWXX+27cX q5QFQhs43PbmmthCanYlPoTqqWYpCV9tDIfdFTQXi3IptQP5/JzF60UGGDUA05J7FKJ7 BfPFIG2/eeqt08LjFV8yDb4ufi/3l8z83V6Gp8CGHu0Enf+Y5jcJaNS+0D0o6YG9YxxH Bn7a/MB1kARPILJK8hkRv7OdZUacyCGaaoDti4cfRNgcfUceNagz6RsdcJEOXBivu4ZV 4w4VCUKDc10X/1asQtlPrNrL0ko3qoE+MDFpYi+mZwaVKjePkThRgcgUhRpL2T/XkkN9 alAg== 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=ftbLP5hAGtYHA2CennUXgBypmGvFUddMtohhylnbJ9I=; fh=uMoo6AE94P/xAsYMqdDxJBeqW1iBLd8ufc7bdFOmgfM=; b=HiY3sQJbmQX13CUVcNwfjq9VmLXRhPJl+2EZJDxKEphDMLDpbjoEhq+s2KxYxfF3ny foK86vgjh7Awyn3aTYZLyqjC2eGdteSmVpf6by67oIj9QoEkd/pmAYoBJw4BU5zDumuz KOdPNxwTdchhyeFRLbNisVJY5YjPF7CRWmaBMB42cIKW/CjQslfSQ9T0s5bc//EWHcW6 cJyrxzyeqccfyIYBXYX+1FjlkSWuasbBR0mgb9JsuZXsWQrhZK9KZeuR0eYeduHMurMi m9XwKdzG1KkraXG3XYSbTULl9pbDCFn7RcDzsniQlSLlMEIKYd4bFFTyo/vhgzwVPcKg 9z9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Q6A6S9nu; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-45794-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45794-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUC5fFrzPaY7ZKr6W8HXW4kUnN1MaH2pPeIDdnkDSQZ4mlvbyG/fxD9sHkjpptWAUeC+dxO+K/LL6ZqrVvPkJO7/Nr+bg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d30-20020a63735e000000b005d8c2880a7fsi5870469pgn.59.2024.01.30.21.55.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 21:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45794-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Q6A6S9nu; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-45794-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45794-ouuuleilei=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1484E281FD9 for ; Wed, 31 Jan 2024 05:55:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A48B45BED; Wed, 31 Jan 2024 05:52:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Q6A6S9nu" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC0B43FB14; Wed, 31 Jan 2024 05:52:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706680352; cv=none; b=qKWf1PNmilGFaFmtF8GZ+T991mHMlGZqhA1dffCiAfLyXqsi+qOA8Tj7QAYIsD51g0zB8tclC+jhLQ7JylRVkIt7lGpZ3gZhihOX0YiVcPcubLEh6x3PqgN7NqB5tL2jsjTuSUHgtYFy6wyORpEeP9mg1HYPsiRMyO1UrAuramg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706680352; c=relaxed/simple; bh=vdKoqMvA7LSgk/e2WNUBvI9QcKVaD8d7AAKwOmSxsjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DagYPte9GoseZmiakUi2PPZAHjXfXtYsXc/2VjtdiCwT1Wai6myK+yDTZ2KfC2q9JIgXAjxAowdzSs8pummhoV5E3iNALqmnpFlO7mDy5ssyzHframuGxzghPNwpg0vFRhJYWL4/obJ2PAm5FZNxbWyLHdLntvZU8DKwhfUVfWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=Q6A6S9nu; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.Jain (unknown [103.86.18.206]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 716C6613C; Wed, 31 Jan 2024 06:51:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706680266; bh=vdKoqMvA7LSgk/e2WNUBvI9QcKVaD8d7AAKwOmSxsjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6A6S9nu04THOw1LPI+7w0Haoocb3VyKrhOGuNiOodzrEKkipxJdhFtg/1GIJtbH4 LeXABsvHztmnAh/JuJRIVxFPmbCieK/VL8ci02cmAyvimeL5hjhjedlSV5EYIfdkBI s7dl5dYzU4UqR3r5xtT6eLSvAtlgKkoJ9d3VfhAc= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Umang Jain Subject: [PATCH v2 4/5] media: i2c: imx335: Refactor power sequence to set controls Date: Wed, 31 Jan 2024 11:22:07 +0530 Message-ID: <20240131055208.170934-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240131055208.170934-1-umang.jain@ideasonboard.com> References: <20240131055208.170934-1-umang.jain@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789584224921525352 X-GMAIL-MSGID: 1789584224921525352 Additional controls might require the sensor to be powered up to set the control value. Currently, only the exposure control powers up the sensor. Move the power up sequence out of the switch-case block. In a subsequent patch, test pattern control will be added that needs the sensor to be powered up. Hence, refactor the power sequence to be present outside the switch-case block. The VBLANK control is also moved out of the switch-case in order to be handled early on, to propagate the changes to other controls. Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index ca3eab50f714..250b7136048d 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -526,26 +526,31 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) u32 exposure; int ret; - switch (ctrl->id) { - case V4L2_CID_VBLANK: + /* Propagate change of current control to all related controls */ + if (ctrl->id == V4L2_CID_VBLANK) { imx335->vblank = imx335->vblank_ctrl->val; dev_dbg(imx335->dev, "Received vblank %u, new lpfr %u\n", imx335->vblank, imx335->vblank + imx335->cur_mode->height); - ret = __v4l2_ctrl_modify_range(imx335->exp_ctrl, - IMX335_EXPOSURE_MIN, - imx335->vblank + - imx335->cur_mode->height - - IMX335_EXPOSURE_OFFSET, - 1, IMX335_EXPOSURE_DEFAULT); - break; - case V4L2_CID_EXPOSURE: - /* Set controls only if sensor is in power on state */ - if (!pm_runtime_get_if_in_use(imx335->dev)) - return 0; + return __v4l2_ctrl_modify_range(imx335->exp_ctrl, + IMX335_EXPOSURE_MIN, + imx335->vblank + + imx335->cur_mode->height - + IMX335_EXPOSURE_OFFSET, + 1, IMX335_EXPOSURE_DEFAULT); + } + + /* + * Applying V4L2 control value only happens + * when power is up for streaming. + */ + if (pm_runtime_get_if_in_use(imx335->dev) == 0) + return 0; + switch (ctrl->id) { + case V4L2_CID_EXPOSURE: exposure = ctrl->val; analog_gain = imx335->again_ctrl->val; @@ -554,14 +559,14 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx335_update_exp_gain(imx335, exposure, analog_gain); - pm_runtime_put(imx335->dev); - break; default: dev_err(imx335->dev, "Invalid control %d\n", ctrl->id); ret = -EINVAL; } + pm_runtime_put(imx335->dev); + return ret; }