From patchwork Wed Dec 20 08:56:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13499689 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 1090F1D525; Wed, 20 Dec 2023 08:56:15 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HE4RapPL" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-50e1112b95cso6013306e87.0; Wed, 20 Dec 2023 00:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703062574; x=1703667374; 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=jcrj7N0as+K9JwFYGseO302P7BY3oZHdFmSWKg4fM4k=; b=HE4RapPLUK2XqJ7yHvegv+Kn4MT2OlRSMluAbP3RUhlHkxk34I0j3MCzhcs5MV9VNT 7DwHuoOsqCaBj1FOFRIHVXop7WTPtWGFNj6jKGL0OtsBGs2nBDLYp+cG1EOzjQcgQXCt +ncmJn9VGZoAoa5icByEbvcwKY6NYzluH/l/QVcu3jJnE6UGQtaAA5IRpYn1XsT8Kf9X El8Urz4pw6sTt50CDL5lHolMZzli890lghfOotjpuUd3pqu7NGOiCRS3bC1825OKLlDV 8ujTdgC+00gbzuGsXUtyaZN5eyYZ7TPyqMlY1lPlcyj/FaxUhSZt8zKQbo1owk4/qhCu OlcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703062574; x=1703667374; 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=jcrj7N0as+K9JwFYGseO302P7BY3oZHdFmSWKg4fM4k=; b=IioqPWKLQWaWNBS7Q/gNRHrGthPdJWlYj4g6dYEueiVcpM+toc5qKolX5YNY+iuddb LxHJB409V3vGpb8Iuo0zzE9XdvkNGebXHHzPvJnXJj86Mzdzp6Erv25QE7X/mTlQmBL+ jyHxlOuH9cRECGuC2bRAsZOXiijBAkrsExp4qpN/A8GpdS8hqTn9Wz0pGTO8PidYeJ+5 gLaOzJ0jB9kRsfRjfMY13wLT84VJPtJb7CIv628o+w3mwCG7Zq7G77/KEQVYPfKT8okZ VRYAnwcHUim+KxioOI/Td1QO11xcNh0KZjXuHQPHL6gnbdeDvIJ1zP3Cy+nqFke/A4Mz 4Dgw== X-Gm-Message-State: AOJu0Yx53XkATeIyJCKlAhB4Xa3Da/DI6UT17eKUiN7t4E1+b4SWBCXE 1hbPCaeHx5xJf0DebcZGmyU= X-Google-Smtp-Source: AGHT+IGdq1o9spxZDiWPDJb6CVtLH2IfiX76uDlX+qHaQHgnu8Hu9bLncaDJu3gsj31S0b+54YAFBA== X-Received: by 2002:a05:6512:a90:b0:50e:4b8a:df85 with SMTP id m16-20020a0565120a9000b0050e4b8adf85mr757640lfu.58.1703062573675; Wed, 20 Dec 2023 00:56:13 -0800 (PST) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation.station (net-188-217-59-229.cust.vodafonedsl.it. [188.217.59.229]) by smtp.gmail.com with ESMTPSA id cq12-20020a056402220c00b0055335e89ed8sm3532169edb.30.2023.12.20.00.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:56:13 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, laurent.pinchart@ideasonboard.com, martin.hecht@avnet.eu, tomm.merciai@gmail.com, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] media: i2c: alvium: removal of dft_fr, min_fr and max_fr Date: Wed, 20 Dec 2023 09:56:06 +0100 Message-Id: <20231220085609.2595732-2-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220085609.2595732-1-tomm.merciai@gmail.com> References: <20231220085609.2595732-1-tomm.merciai@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The dft_fr, min_fr and max_fr fields of the alvium_dev structure are only used to pass results from alvium_get_frame_interval() to its caller. Replace them with function parameters. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- Changes Since v1: - Fixed commit body as suggested by LPinchart - Fixed alvium_get_frame_interval just return ret as suggested by LPinchart - Removed unrelated chnages from the commit as suggested by LPinchart drivers/media/i2c/alvium-csi2.c | 27 +++++++++------------------ drivers/media/i2c/alvium-csi2.h | 3 --- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index 34ff7fad3877..0dcd69bf9f92 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1170,25 +1170,19 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium, return 0; } -static int alvium_get_frame_interval(struct alvium_dev *alvium) +static int alvium_get_frame_interval(struct alvium_dev *alvium, + u64 *dft_fr, u64 *min_fr, u64 *max_fr) { - u64 dft_fr, min_fr, max_fr; int ret = 0; alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, - &dft_fr, &ret); + dft_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R, - &min_fr, &ret); + min_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R, - &max_fr, &ret); - if (ret) - return ret; - - alvium->dft_fr = dft_fr; - alvium->min_fr = min_fr; - alvium->max_fr = max_fr; + max_fr, &ret); - return 0; + return ret; } static int alvium_set_frame_rate(struct alvium_dev *alvium) @@ -1670,21 +1664,18 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium, struct v4l2_subdev_frame_interval *fi) { struct device *dev = &alvium->i2c_client->dev; - u64 req_fr, min_fr, max_fr; + u64 req_fr, dft_fr, min_fr, max_fr; int ret; if (fi->interval.denominator == 0) return -EINVAL; - ret = alvium_get_frame_interval(alvium); + ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr); if (ret) { dev_err(dev, "Fail to get frame interval\n"); return ret; } - min_fr = alvium->min_fr; - max_fr = alvium->max_fr; - dev_dbg(dev, "fi->interval.numerator = %d\n", fi->interval.numerator); dev_dbg(dev, "fi->interval.denominator = %d\n", @@ -1694,7 +1685,7 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium, fi->interval.numerator); if (req_fr >= max_fr && req_fr <= min_fr) - req_fr = alvium->dft_fr; + req_fr = dft_fr; alvium->fr = req_fr; alvium->frame_interval.numerator = fi->interval.numerator; diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h index b85a25169e79..17f0bbbd1839 100644 --- a/drivers/media/i2c/alvium-csi2.h +++ b/drivers/media/i2c/alvium-csi2.h @@ -443,9 +443,6 @@ struct alvium_dev { struct alvium_mode mode; struct v4l2_fract frame_interval; - u64 dft_fr; - u64 min_fr; - u64 max_fr; u64 fr; u8 h_sup_csi_lanes; From patchwork Wed Dec 20 08:56:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13499690 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 342C21D6AE; Wed, 20 Dec 2023 08:56:17 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aZyZjVPe" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-553ba2f0c8fso761860a12.1; Wed, 20 Dec 2023 00:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703062575; x=1703667375; 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=1jIpVU9lsgBmtKqRr7Ozp3idnHWbKwd3zW4X8TzJVcM=; b=aZyZjVPefqdNn2j7Awh2BjuEvMiQivun/jLc8QC8hBHQMqFIC0ErAd5UOK4X3i8XoP yUFJaeMwLbOGaipjbz62PYYYsZd+SturHDUldPRlBItAw731oWphbxYYLlB9yRlnCZan iOfQDmfmclmBCXFriRu07rqyd0Rt0LtTMGDtD5Q9BC6Zp9qsgRP3L7NyCFuH0Al/5T5O uvxqXrz6pl44HiqyhMLlaEGL4NKqzGGe6GQI1ymlg3hN7A/Z+onzdwy6Q+OwTmMEobid P8jupxxiWuzBsa92Ig271bzEGP+1z/BpL2jj2BJm/toBMAbPnz0uOj9IsCk60OSqIhIK aZSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703062575; x=1703667375; 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=1jIpVU9lsgBmtKqRr7Ozp3idnHWbKwd3zW4X8TzJVcM=; b=VaFipnHrHFQU51b00hAkXjz9jf7dhVekh5A4uhKItidrxTdOEEMbNbiKSZg9VeqgtJ GDX1AKMYiJuoBJe/iyRWG7/8r0bi4bK4DrH2lmSsxpS44zTd7ZF157hZLITumiE/1L9p EwmV9JGUEKOcznnGl2E8GV5dK0GkkQUqVb5qqz+Wyu5Xzv+oINH7F+uhIzmzCEm21rH8 ZqWdDLoe1SZojxcN2AuJMyDLBek9gsEjdLUzdL3akBoloo756MLRITNUuHxMPWsChhay jtSERrELf/mQXLxl6O8olI6hLeX1FvGpf2odJtpDlG71kOImeO3Jx385hA6KHdH5yvK0 DF2Q== X-Gm-Message-State: AOJu0YwXtG4MByEcMAVLWcb+jC7Q1Gv8X34VLwDji0fuSat+jBn5ealT eNjGKKJwc3U/SMAGxb98Hi8= X-Google-Smtp-Source: AGHT+IF/L8rSeFC824o91YIxIVHp8hzrCeVTrWauPjnN5DlvT3StN0Mi01SKdFVTtYbc+Xn06dtQwA== X-Received: by 2002:a50:f689:0:b0:553:fbff:d2cd with SMTP id d9-20020a50f689000000b00553fbffd2cdmr1070edn.83.1703062575304; Wed, 20 Dec 2023 00:56:15 -0800 (PST) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation.station (net-188-217-59-229.cust.vodafonedsl.it. [188.217.59.229]) by smtp.gmail.com with ESMTPSA id cq12-20020a056402220c00b0055335e89ed8sm3532169edb.30.2023.12.20.00.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:56:14 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, laurent.pinchart@ideasonboard.com, martin.hecht@avnet.eu, tomm.merciai@gmail.com, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] media: i2c: alvium: removal of fr field Date: Wed, 20 Dec 2023 09:56:07 +0100 Message-Id: <20231220085609.2595732-3-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220085609.2595732-1-tomm.merciai@gmail.com> References: <20231220085609.2595732-1-tomm.merciai@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The fr (frame rate) field of the alvium_dev structure is only used to pass result from alvium_set_frame_interval() to alvium_set_frame_rate() that writes this info into the hw reg. Replace them with function parameter. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- drivers/media/i2c/alvium-csi2.c | 24 ++++++++++++------------ drivers/media/i2c/alvium-csi2.h | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index 0dcd69bf9f92..a9ff6cc97cff 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1185,19 +1185,19 @@ static int alvium_get_frame_interval(struct alvium_dev *alvium, return ret; } -static int alvium_set_frame_rate(struct alvium_dev *alvium) +static int alvium_set_frame_rate(struct alvium_dev *alvium, u64 fr) { struct device *dev = &alvium->i2c_client->dev; int ret; ret = alvium_write_hshake(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, - alvium->fr); + fr); if (ret) { dev_err(dev, "Fail to set frame rate lanes reg\n"); return ret; } - dev_dbg(dev, "set frame rate: %llu us\n", alvium->fr); + dev_dbg(dev, "set frame rate: %llu us\n", fr); return 0; } @@ -1661,10 +1661,11 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd, } static int alvium_set_frame_interval(struct alvium_dev *alvium, - struct v4l2_subdev_frame_interval *fi) + struct v4l2_subdev_frame_interval *fi, + u64 *req_fr) { struct device *dev = &alvium->i2c_client->dev; - u64 req_fr, dft_fr, min_fr, max_fr; + u64 dft_fr, min_fr, max_fr; int ret; if (fi->interval.denominator == 0) @@ -1681,13 +1682,12 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium, dev_dbg(dev, "fi->interval.denominator = %d\n", fi->interval.denominator); - req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / + *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / fi->interval.numerator); - if (req_fr >= max_fr && req_fr <= min_fr) - req_fr = dft_fr; + if (*req_fr >= max_fr && *req_fr <= min_fr) + *req_fr = dft_fr; - alvium->fr = req_fr; alvium->frame_interval.numerator = fi->interval.numerator; alvium->frame_interval.denominator = fi->interval.denominator; @@ -1699,6 +1699,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_frame_interval *fi) { struct alvium_dev *alvium = sd_to_alvium(sd); + u64 req_fr = ALVIUM_DEFAULT_FR_HZ; int ret; /* @@ -1711,9 +1712,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, if (alvium->streaming) return -EBUSY; - ret = alvium_set_frame_interval(alvium, fi); + ret = alvium_set_frame_interval(alvium, fi, &req_fr); if (!ret) - ret = alvium_set_frame_rate(alvium); + ret = alvium_set_frame_rate(alvium, req_fr); return ret; } @@ -2273,7 +2274,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium) /* Setup initial frame interval*/ alvium->frame_interval.numerator = 1; alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ; - alvium->fr = ALVIUM_DEFAULT_FR_HZ; /* Setup the initial mode */ alvium->mode.fmt = alvium_csi2_default_fmt; diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h index 17f0bbbd1839..80066ac25047 100644 --- a/drivers/media/i2c/alvium-csi2.h +++ b/drivers/media/i2c/alvium-csi2.h @@ -443,7 +443,6 @@ struct alvium_dev { struct alvium_mode mode; struct v4l2_fract frame_interval; - u64 fr; u8 h_sup_csi_lanes; u64 link_freq; From patchwork Wed Dec 20 08:56:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13499691 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 84D521DA5E; Wed, 20 Dec 2023 08:56:18 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Lf8zYxAT" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-553b3ee88c0so1142012a12.0; Wed, 20 Dec 2023 00:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703062577; x=1703667377; 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=afxqRg0BdzPXAqeEmb0814lNgbcWkJx4M3LyS7SIRlE=; b=Lf8zYxAT9PB+T77ilVlTE88tLKnHbHsUl7OX2CiZceS9Z4me37V6MnsLx5Hfme5l1V oy+W9gb6cf2ewhd92sZsUn0bKiNczFIfhsW+NL6hUtOpLVKqG9oRoQYIr5LwL/OrTN4f OemmhnFyAtFQB2CSZ8BO5q7S7K3b5RDiQRykFg9C5FvpF9C6QcQaTasj7eK8DZrXuYqZ i3DaASdL6KW6U5liqGWY57tgXfgYb1dHhPqX04cM6TgBLvAAYGqHUWN+i5fibKOMlmWY rlbX625rcMo12jyf8+VAOSeF4OqBx87iuVE8quF3IPwKfqgGKAYwT+RSAoTKjCl8We86 093g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703062577; x=1703667377; 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=afxqRg0BdzPXAqeEmb0814lNgbcWkJx4M3LyS7SIRlE=; b=LB8zCAosdXcSQo+PfbRp+ERexpocxZKkcD3f8DN7/0pSD94phzRNJcNOtnxUQNgcev vzJQwEfIlq9mGbNxatJM8HVAXMutqu0QoDxpn/pUlYbtvlQFftELIaPaFIs6mrPLjroH fMFEtnSpyUyyt4tR2g+0zvyIeO7iu2Jeg8mz7kp+pfIAvPuKju++4EmGh2iBjg/vh9Ce ieN9XjfY5fEnINXXXrsd2ufNELVs7ZC+JZwwLPFA5/yOBmx6HqDAXU7vLOOU162RvIS3 ORoioxYHFABpJNoQZ3yf0VA65odAq7aWsluijiKgaj/TNIXPPgXsBATmVKB9ni5pxaOl mkCA== X-Gm-Message-State: AOJu0Yx6aTjlWP/xh1tB6eNUzqUl5ScfpG4mQ+64PaRs5JlkttMcugqV A5A+BdvBAhIiQIax3zim9jo= X-Google-Smtp-Source: AGHT+IFraZjA1I+MpAWdI3cvbHqa2lA82OBgPoS3jakLWY53Us/2Nqyhv8I2jZDKhxR2gg6RmWlOvg== X-Received: by 2002:a05:6402:230f:b0:551:80b7:6b60 with SMTP id l15-20020a056402230f00b0055180b76b60mr7099528eda.36.1703062576831; Wed, 20 Dec 2023 00:56:16 -0800 (PST) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation.station (net-188-217-59-229.cust.vodafonedsl.it. [188.217.59.229]) by smtp.gmail.com with ESMTPSA id cq12-20020a056402220c00b0055335e89ed8sm3532169edb.30.2023.12.20.00.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:56:16 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, laurent.pinchart@ideasonboard.com, martin.hecht@avnet.eu, tomm.merciai@gmail.com, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] media: i2c: alvium: inline set_frame_interval into s_frame_interval Date: Wed, 20 Dec 2023 09:56:08 +0100 Message-Id: <20231220085609.2595732-4-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220085609.2595732-1-tomm.merciai@gmail.com> References: <20231220085609.2595732-1-tomm.merciai@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Inline alvium_set_frame_interval() into alvium_s_frame_interval(). The alvium_set_frame_interval() is called once only, by alvium_s_frame_interval(). The latter is a thin wrapper around the former. Inline the function in its caller to make the code more readable. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- Changes Since v1: - Now this commit is the 3/4 of the series - Fixed commit body as suggested by LPinchart drivers/media/i2c/alvium-csi2.c | 51 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index a9ff6cc97cff..b234d74454bf 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1660,14 +1660,26 @@ static int alvium_g_frame_interval(struct v4l2_subdev *sd, return 0; } -static int alvium_set_frame_interval(struct alvium_dev *alvium, - struct v4l2_subdev_frame_interval *fi, - u64 *req_fr) +static int alvium_s_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_frame_interval *fi) { + struct alvium_dev *alvium = sd_to_alvium(sd); struct device *dev = &alvium->i2c_client->dev; + u64 req_fr = ALVIUM_DEFAULT_FR_HZ; u64 dft_fr, min_fr, max_fr; int ret; + /* + * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2 + * subdev active state API. + */ + if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) + return -EINVAL; + + if (alvium->streaming) + return -EBUSY; + if (fi->interval.denominator == 0) return -EINVAL; @@ -1682,41 +1694,16 @@ static int alvium_set_frame_interval(struct alvium_dev *alvium, dev_dbg(dev, "fi->interval.denominator = %d\n", fi->interval.denominator); - *req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / + req_fr = (u64)((fi->interval.denominator * USEC_PER_SEC) / fi->interval.numerator); - if (*req_fr >= max_fr && *req_fr <= min_fr) - *req_fr = dft_fr; + if (req_fr >= max_fr && req_fr <= min_fr) + req_fr = dft_fr; alvium->frame_interval.numerator = fi->interval.numerator; alvium->frame_interval.denominator = fi->interval.denominator; - return 0; -} - -static int alvium_s_frame_interval(struct v4l2_subdev *sd, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_frame_interval *fi) -{ - struct alvium_dev *alvium = sd_to_alvium(sd); - u64 req_fr = ALVIUM_DEFAULT_FR_HZ; - int ret; - - /* - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2 - * subdev active state API. - */ - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - if (alvium->streaming) - return -EBUSY; - - ret = alvium_set_frame_interval(alvium, fi, &req_fr); - if (!ret) - ret = alvium_set_frame_rate(alvium, req_fr); - - return ret; + return alvium_set_frame_rate(alvium, req_fr); } static int alvium_enum_mbus_code(struct v4l2_subdev *sd, From patchwork Wed Dec 20 08:56:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13499692 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 424F81F932; Wed, 20 Dec 2023 08:56:20 +0000 (UTC) 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bL1r5uMd" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-55322dbabf6so4218288a12.0; Wed, 20 Dec 2023 00:56:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703062578; x=1703667378; 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=hYVOyNX8K/YP0tmvGryMk7eYWDrGsoqCCSsYGBM39r0=; b=bL1r5uMd7qtVkljpmwQZ22X/dgJuD1YNif4MUjsz1/EJXVmnJSWGHbN5mLg8NDKa8E MkIUDQ6YmczT2UTiVVEAt4EDhNVQl/e7EcKUaClG1rgRasG8O8q2daEkxlEIBOQ9m3HX Ox2tYToe/cRjKHvSxn0/SC/E9+91mRLk1xMALBqxf1VxhCsJwiAZ9URI8OO3v3Mq0ntL VCdywNOvZfP20oD24d6Zs7U/knLsZDy/VDqfqkx7K4Nc0+Tw1TORLqE54qQsVwV3UC4u gr/2pJA5t1+fO81DVc799I/9kFIV9oBQlJGphgbh1xWNbdL3uBJVp9oBRjjzJSiTIrbG jLfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703062578; x=1703667378; 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=hYVOyNX8K/YP0tmvGryMk7eYWDrGsoqCCSsYGBM39r0=; b=anzdTSTKCr/cJA8Jh6O9qXP5Oc1M2FBhBDPcnRACZgxIVO4jXm5cFNDxFOrX7O1uKt zcQgORR2uBcZV3TMrnHtjr2eY4Uc5QwYzjdg8mlPcC6KlK8QA7Ny2O6HWxl85Up/KnV6 p808AJR2IIRX+Tw3wSkyqydu2qX8UiwxyF4Pgi3NPNm0e3fRus0sgwYT4ZUkpTbfCVSo PpXp7+hpopypOfcDVnuhbbekj7CR7JqUeRPNr6+LGqXuSFv/hXkjnT0JZT4wUKD1O9d3 r3KYU226njtq/Db2WsDa31UntWbbEHuOWvKu7uqy0yCrXHZaRjBJClJ4jzytUdvB/jUt 41SA== X-Gm-Message-State: AOJu0YxfEwp+/lIt/WEZkyGdTcC0Jyhqdy+el8JqQLMLaXDutBZ1I10U p5h7w454yNLHP/s8dS7YcWQ= X-Google-Smtp-Source: AGHT+IGWpRBfBRp1cwdGts7GjNjyDFE0XrLq5MdwHJTHDsBASHsizgPsfIYpEtniVKUdW2ULxGphLg== X-Received: by 2002:a50:c25a:0:b0:553:9fab:6cb6 with SMTP id t26-20020a50c25a000000b005539fab6cb6mr1106828edf.74.1703062578516; Wed, 20 Dec 2023 00:56:18 -0800 (PST) Received: from tom-HP-ZBook-Fury-15-G7-Mobile-Workstation.station (net-188-217-59-229.cust.vodafonedsl.it. [188.217.59.229]) by smtp.gmail.com with ESMTPSA id cq12-20020a056402220c00b0055335e89ed8sm3532169edb.30.2023.12.20.00.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 00:56:18 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, laurent.pinchart@ideasonboard.com, martin.hecht@avnet.eu, tomm.merciai@gmail.com, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] media: i2c: alvium: store frame interval in subdev state Date: Wed, 20 Dec 2023 09:56:09 +0100 Message-Id: <20231220085609.2595732-5-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220085609.2595732-1-tomm.merciai@gmail.com> References: <20231220085609.2595732-1-tomm.merciai@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the newly added storage for frame interval in the subdev state to simplify the driver. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- Changes Since v1: - Removed FIXME comment and active state check into alvium_s_frame_interval as suggested by LPinchart. - Fixed call alvium_set_frame_rate() only for active state into alvium_s_frame_interval as suggested by LPinchart. drivers/media/i2c/alvium-csi2.c | 51 +++++++++++---------------------- drivers/media/i2c/alvium-csi2.h | 1 - 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index b234d74454bf..240bf991105e 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1641,42 +1641,16 @@ static int alvium_hw_init(struct alvium_dev *alvium) } /* --------------- Subdev Operations --------------- */ - -static int alvium_g_frame_interval(struct v4l2_subdev *sd, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_frame_interval *fi) -{ - struct alvium_dev *alvium = sd_to_alvium(sd); - - /* - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2 - * subdev active state API. - */ - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - - fi->interval = alvium->frame_interval; - - return 0; -} - static int alvium_s_frame_interval(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_interval *fi) { struct alvium_dev *alvium = sd_to_alvium(sd); struct device *dev = &alvium->i2c_client->dev; - u64 req_fr = ALVIUM_DEFAULT_FR_HZ; - u64 dft_fr, min_fr, max_fr; + u64 req_fr, dft_fr, min_fr, max_fr; + struct v4l2_fract *interval; int ret; - /* - * FIXME: Implement support for V4L2_SUBDEV_FORMAT_TRY, using the V4L2 - * subdev active state API. - */ - if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - if (alvium->streaming) return -EBUSY; @@ -1700,8 +1674,13 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, if (req_fr >= max_fr && req_fr <= min_fr) req_fr = dft_fr; - alvium->frame_interval.numerator = fi->interval.numerator; - alvium->frame_interval.denominator = fi->interval.denominator; + interval = v4l2_subdev_state_get_interval(sd_state, 0); + + interval->numerator = fi->interval.numerator; + interval->denominator = fi->interval.denominator; + + if (fi->which != V4L2_SUBDEV_FORMAT_ACTIVE) + return 0; return alvium_set_frame_rate(alvium, req_fr); } @@ -1851,6 +1830,7 @@ static int alvium_init_state(struct v4l2_subdev *sd, { struct alvium_dev *alvium = sd_to_alvium(sd); struct alvium_mode *mode = &alvium->mode; + struct v4l2_fract *interval; struct v4l2_subdev_format sd_fmt = { .which = V4L2_SUBDEV_FORMAT_TRY, .format = alvium_csi2_default_fmt, @@ -1868,6 +1848,11 @@ static int alvium_init_state(struct v4l2_subdev *sd, *v4l2_subdev_state_get_crop(state, 0) = sd_crop.rect; *v4l2_subdev_state_get_format(state, 0) = sd_fmt.format; + /* Setup initial frame interval*/ + interval = v4l2_subdev_state_get_interval(state, 0); + interval->numerator = 1; + interval->denominator = ALVIUM_DEFAULT_FR_HZ; + return 0; } @@ -2237,7 +2222,7 @@ static const struct v4l2_subdev_pad_ops alvium_pad_ops = { .set_fmt = alvium_set_fmt, .get_selection = alvium_get_selection, .set_selection = alvium_set_selection, - .get_frame_interval = alvium_g_frame_interval, + .get_frame_interval = v4l2_subdev_get_frame_interval, .set_frame_interval = alvium_s_frame_interval, }; @@ -2258,10 +2243,6 @@ static int alvium_subdev_init(struct alvium_dev *alvium) struct v4l2_subdev *sd = &alvium->sd; int ret; - /* Setup initial frame interval*/ - alvium->frame_interval.numerator = 1; - alvium->frame_interval.denominator = ALVIUM_DEFAULT_FR_HZ; - /* Setup the initial mode */ alvium->mode.fmt = alvium_csi2_default_fmt; alvium->mode.width = alvium_csi2_default_fmt.width; diff --git a/drivers/media/i2c/alvium-csi2.h b/drivers/media/i2c/alvium-csi2.h index 80066ac25047..9463f8604fbc 100644 --- a/drivers/media/i2c/alvium-csi2.h +++ b/drivers/media/i2c/alvium-csi2.h @@ -442,7 +442,6 @@ struct alvium_dev { s32 inc_sharp; struct alvium_mode mode; - struct v4l2_fract frame_interval; u8 h_sup_csi_lanes; u64 link_freq;