From patchwork Wed Dec 20 12:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13500043 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 BDF212554D; Wed, 20 Dec 2023 12:40:28 +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="Z5UnaQr/" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-553e22940a3so679582a12.1; Wed, 20 Dec 2023 04:40:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076027; x=1703680827; 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=PWwFXzxbsWD+eQjlH7n7kgrlKUOxZZeQ7Eomxz4YCo4=; b=Z5UnaQr/HdRHA1eQFkaE68RA7ya68TpG2RIyCF2+wnXbSDC8ZDcKmWNMwe6uRncuuq beZuJYLLU0e0+r5jnmSiKvzjduYBEUugluNRPnbGkMlpJeTXKSe/HP8JUzDUHrQdIsJL cZOqB9F6tzwDgZ0i2GgfzEXnSh3lAKy0ArnbLIoOS5NbNp1jVqPQgoahVQUAXHhTej0P INutTStSnwSfZgayJRsGPlExnqRk2T4zZ7ekIIXUNBYD6/Dq7ZLCDYj0Lrqro2GPe1uP 29hCEt3AaxeFDQduoQpFezsuE2OhczOQPJVo4Cs3rrEF4/RT6GndbC//KgKTlJCEPJqx ALUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076027; x=1703680827; 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=PWwFXzxbsWD+eQjlH7n7kgrlKUOxZZeQ7Eomxz4YCo4=; b=FXJMT1bmCqA6KRr7xRJ3FnxndPvR/jg6t4UI15CMzVtxJqo+Rt69WIcEhyvjhtfstZ d9BBdZ5WYxhEFLpF5c+2y2Iw94Rt3Du1AhUml3zGfMosxcxFmK4HvGiDVbkpT2q9vTC6 3iT/8AjU9K7/l8aAPaRjZiLXrIQnflIlQUEC1aUUUvtJKb1HH7y3vIjDV62JY/3l7+xa B4uMEIkz20zeasp5MVfLAmIa0fmg4hjEJWaO2bOWtDmL9DlLui6FChi3J5CQds2tqFry fkwyZ4eW409rfYN1gdx/FUjT26oaKMVt09sypEiW0ai1xHM+OHdITPvL7yf56NAkNjDZ TMVg== X-Gm-Message-State: AOJu0Yw1fAmzsoAwLNnEW2b53AjIW762CulEOdZetfLkK5Ig2E0KIcwg YtnFfLNQMqyJLQS3SgZyd28= X-Google-Smtp-Source: AGHT+IHUWqxbR0nJod7+isZAgxPzMZ14Bc06V9NidblLYHUio4wotzNWyRMIK4uplPjI9kJDNjoRRQ== X-Received: by 2002:a17:907:e8f:b0:a1c:9738:2235 with SMTP id ho15-20020a1709070e8f00b00a1c97382235mr14670778ejc.118.1703076027037; Wed, 20 Dec 2023 04:40:27 -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 d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:26 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.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 v3 1/5] media: i2c: alvium: removal of dft_fr, min_fr and max_fr Date: Wed, 20 Dec 2023 13:40:19 +0100 Message-Id: <20231220124023.2801417-2-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-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 Changes Since v2: - Collected tag from 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 12:40:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13500044 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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 5277F34CFB; Wed, 20 Dec 2023 12:40:30 +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="CooCuy7F" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-50e51a7545dso757715e87.2; Wed, 20 Dec 2023 04:40:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076029; x=1703680829; 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=fXBdGMYmMHVBCFYQFP2cAUD5aZM2nwh97dasVmKARbo=; b=CooCuy7Fksw0QQjXHNwDfpYgdAOXBvL535PR9jwB3qmrliCqWnYrRB4+DnTUpxb68Z hNIyc4W5/rWMbmOP8TkjCWc8sCui9Rum+qZsB1qbJ+8tKiV+cLz6rIyV3w8UE7RQ2B4H SlOI/pHHepu05uixSbXdTuS0QPrylGLx2XybNN6x/BrvZShiIK+8Ejp2NaatfHOq7aLr B2jxc9kbQTO4/9q/4kkA7BsV1qd7DLebCJtooKyexkEw4yasd6uFpRQtw7yoaqCG6abq 7X6aOoEIpxSMUUha7pwlSqOypCviqqq6N5o70hunLTVvWEG8MUIKy4ILN9b9blYj90gm plOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076029; x=1703680829; 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=fXBdGMYmMHVBCFYQFP2cAUD5aZM2nwh97dasVmKARbo=; b=btXYkcdsN/GcE98pXyKxYfQFqHac7LzsZIw+rewXHiXNQJIX8sKebK2svXni76mP6i JALf2SEjAKcxqgCsmZptwILGAG4YVpFPLXqSI/IKjI5sjRnJxqX7uaJDPUqax3KL5mtn NqF7QS0E7GaSx5IBQmFf9sdBiTgbaIYTtdv9MHfyJOrn2spFHdnfmjEMoIE6Dx225HYj yboUEVmHXq5ZyZY8Cm3gCgyDPBgAs5EFVEXJ+O5ff53UjkSnxdkR/3hvGJP6oPmuyR+Z +n3w/U5mdbbxJj70LV/8usi13ycQMXv2BiGOrUcPkAEEPePCudlnRgRaA7NDUQQgwfo+ ROAQ== X-Gm-Message-State: AOJu0YwPGbpRvIGhyzHcL1AHrG1+8VcK1p74g43UCmAce8+snqZM6Kg9 GTtbTx6ac2LsoWl0WkKSx7Q= X-Google-Smtp-Source: AGHT+IEXT3zbVQPdznjTdLbH2SAlmB9+OqBvIQzvgjroFyRyg8ldWeebsKVH5aASbGIKS4vXqanIpw== X-Received: by 2002:a05:6512:791:b0:50e:35e8:806f with SMTP id x17-20020a056512079100b0050e35e8806fmr2445373lfr.47.1703076028597; Wed, 20 Dec 2023 04:40:28 -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 d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:28 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.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 v3 2/5] media: i2c: alvium: remove the fr field of the alvium_dev structure Date: Wed, 20 Dec 2023 13:40:20 +0100 Message-Id: <20231220124023.2801417-3-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-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 it with a function parameter. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- Changes Since v2: - Removed req_fr initializzation as suggested by LPinchart - Collected tag from LPinchart - Fixed commit msg and body as suggested by LPinchart 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..994372030be9 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; 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 12:40:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13500045 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 0663236AFC; Wed, 20 Dec 2023 12:40:31 +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="XlpSaHlY" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-54c77e0835bso7035914a12.2; Wed, 20 Dec 2023 04:40:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076030; x=1703680830; 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=f1+J3MJbe6MF9SpStiPnGtAPzoLLgmQl4VRPW/1tgxQ=; b=XlpSaHlYpchzXtGkcAJdmai0rUofRjl/aFSK9mYoZRsKqSMLry7taKJdsW02+4zDgN JKgFdJFeVkGKNTThFNnOiQYAnuWl3xjzuPIpCHv5lkXhQon72HaGoex5qDlLAYEBDx7+ mWBsKubF3zwqzOUrLrehgv22zsF7QFzmx8zPFa2kCiZfpa+yG8O/n79cfkXkAkgGIB0c +9dia1ROvm68P98tYV2WfmagbfE4w9psCrEXkao2wVneirTAi/BKWRjeS0x69PICAkzG QurxdMTvYxFHkKjVYy0B8gJ9UhLTpNQNlsIF9Y8SY0YS2TLHL1fmK1vPJkCK97L5PzgG osaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076030; x=1703680830; 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=f1+J3MJbe6MF9SpStiPnGtAPzoLLgmQl4VRPW/1tgxQ=; b=jQJXYA3iKHF5qMWLx4rPghn85jZaN0jcaE+5DMaTU+339WqGbAlqq9mNfqCdBGp2Vf imIzfFDDXwseu1HS8HtQMXbM4onOeAfErrVdXCRmU/RqaCexKlFLC97sv6hynIcp8oC+ tZIR11MVbXqO/TNU91A48g4tfgHbPp+FO+52rR+acfDt0Mn5rUqaZKN+qNvzuRT69kqG qIKfikm9BRw5xNmANLw/hzQmR3XnfKRq/0+7yB0FYQhvFylsLQylkprBQHOGs0SkA7Is kwB4r+ejzCeWxI2NRR33546BuhUUP/DiEakJqVeuylS0G/I3ZMSiQ+tBfMTo6ia3cY9/ EBzA== X-Gm-Message-State: AOJu0YzuPE5XRsn4Hg96rba4aQYyopnMsfZGHnvzGLnMx3s88CE9WSsa vPpemuM5Kom8+aZ44aQmzKI= X-Google-Smtp-Source: AGHT+IEE98HodO2AD8+mijr1sF+n/30cm466JNlWXVHm5yqEretfJkovm7hMxLiFQLSQKUgfT4fGtw== X-Received: by 2002:a17:906:208d:b0:a23:3753:c64c with SMTP id 13-20020a170906208d00b00a233753c64cmr3567114ejq.57.1703076030054; Wed, 20 Dec 2023 04:40:30 -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 d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:29 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.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 v3 3/5] media: i2c: alvium: inline set_frame_interval into s_frame_interval Date: Wed, 20 Dec 2023 13:40:21 +0100 Message-Id: <20231220124023.2801417-4-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-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 Changes Since v2: - Removed req_fr initializzation as suggested by LPinchart - Collected tag from LPinchart drivers/media/i2c/alvium-csi2.c | 52 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index 994372030be9..ef137e6a2811 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1660,14 +1660,25 @@ 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 dft_fr, min_fr, max_fr; + u64 req_fr, 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 +1693,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; - 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 12:40:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13500046 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 914CE2554D; Wed, 20 Dec 2023 12:40:33 +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="mpaUlPBR" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-54f4f7e88feso7763207a12.3; Wed, 20 Dec 2023 04:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076032; x=1703680832; 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=SxRqSeGzX02JEgJLfNTXcC5rilET35Ihn8r4o8gFqV8=; b=mpaUlPBR8R28Qa1un9ZZ9suIx2AZWxLxHwjLa46HUmQ71eu71qJvR9Y6MpZrl1bhVb MwM/IsK9Gob/RLNdXDF2uA+nX7nmxOktkmAjWgxyh72/SUTmTUErlBpbRS7ZBv0x5rjv BGROh5Uw0A7ms+iwnjbeTry9XbK8VHASjjY00d23CvWxDlpwdbQNWf0MkrzD6C1p6PfY xaMf4nDbygvYc6HSx0JcZ+jR9ImSSCusdiDPijnd0VRyHn7+eoPCMTmifL3ivIsL6+F1 8RJ/hLDIloxWISaYc/y48bsEZeV31jNl/bgJ+8aGAjWMt3LOAt14OMq76kAATVXe5Ddv bdvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076032; x=1703680832; 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=SxRqSeGzX02JEgJLfNTXcC5rilET35Ihn8r4o8gFqV8=; b=w4QzgHyaJqi4bPGEXS6L58BHGB2tqxNcptdrbkaiTvpKJGRimd1zDP3x+AqY0mDIxQ 5CsA2eN2R3B6CXhzv57MI0D7F+OONSGYZ/KHVRX0EjLbI5A6BucJSgkjT79rKC8tCQjU B501QvsB7p71d/hRFQMkZaJNb/o/SurNP6oAa7FRQKhqR6f51wwvBabeOUT5Fnrlldfi esbkG4SJV08Lm3T8PKfnK++cCOvMw6X8yIW9EqQk8CjN6vgxUbXCABJAX6lxxD0lM4JP dK28NaRhw+VFAUcBzeqHgHHCDhDGJNfGxrZL0KZW7dUVhG7bp5KCcAxqUX3hZewBmleH ZnhQ== X-Gm-Message-State: AOJu0YyfCHTadytNOd6DAiswH+wzlrKQijDCFC0VUrSxNSqiodkFzVQs s6wPvIoP6Ib3jvS6BO9NuG0= X-Google-Smtp-Source: AGHT+IFc194CyjndQWvUJB6ENPNZtvGbOdf5FJ+ccq08DrmYdW9fRQz61yllo+akG4LZ7dEg4G/Y3w== X-Received: by 2002:a17:906:1042:b0:a22:e690:f09f with SMTP id j2-20020a170906104200b00a22e690f09fmr7025864ejj.143.1703076031569; Wed, 20 Dec 2023 04:40:31 -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 d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:31 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.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 v3 4/5] media: i2c: alvium: store frame interval in subdev state Date: Wed, 20 Dec 2023 13:40:22 +0100 Message-Id: <20231220124023.2801417-5-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-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. Changes Since v2: - Collected tag from LPinchart drivers/media/i2c/alvium-csi2.c | 48 +++++++++++---------------------- drivers/media/i2c/alvium-csi2.h | 1 - 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index ef137e6a2811..240bf991105e 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1641,25 +1641,6 @@ 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) @@ -1667,15 +1648,9 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, struct alvium_dev *alvium = sd_to_alvium(sd); struct device *dev = &alvium->i2c_client->dev; 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; @@ -1699,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); } @@ -1850,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, @@ -1867,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; } @@ -2236,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, }; @@ -2257,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; From patchwork Wed Dec 20 12:40:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tommaso Merciai X-Patchwork-Id: 13500047 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 CE33238DE9; Wed, 20 Dec 2023 12:40:34 +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="CzQKicn2" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-55372c1338bso3720585a12.2; Wed, 20 Dec 2023 04:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703076033; x=1703680833; 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=d/8vsrFsmIdkN6wX+xgjZzrqJBCn9bwK4adiKoP4ah4=; b=CzQKicn2MIokPQ0Qtpcr/iiB7dAvWxlQPI9p69Cwc9t4vVyR+Y9y2fj0qv2EHsTJ0b +SZwStExf2fhCJ1IW2LnY+1S9TcGGskBCQDfdL9ntaXFIqTSc0aW8GjqBTUtDNkvYnrl WXeJ2xH98+cQj77BMGqTbNe5fSboO8c23xO7qaQuNipzZANR/D60WJjzw/CIYf7yGh7B QISuFB0Ka8hCXMxf2QweVmK4GVXSefwAYCt5uypqNQ+G5PbY+A3ovFwBdaQmSKSKe/Jm 2OGbRdK7pY+BhuyXfhYYnJ8XgG8q4MXJnZWDSK5X4QBbZj3nyenzlAQzR759piZgS8oX nV5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703076033; x=1703680833; 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=d/8vsrFsmIdkN6wX+xgjZzrqJBCn9bwK4adiKoP4ah4=; b=lTcqJf5OQoJKy7vEIvd8haz1iYg94+iRJrc0WnoGXQXLwZwgGjy+FpvniDOwGZTv1C slPE/qeK19uswI67SAYtZJy6HETdgsCGTHlKF4FDcq95nzliXz38TwwyyGuc/5d4xdfg gom4YwRW2Vwj1G6XjCpgeBTe/Rp35w9DITrnDJ+pvRxFkcJVPLZ7+PH7W1cnCd8PSmZC tJnzPmA50TEb1NoJULgUZGq5Vs/O2Px5P0UvNZXQuZYn64pW3b9zYT9z/BIp9SKbJRBs KyPKL/yS4/OLQ+17oI5CEEkZJM6b7N7hiJpit4AsGbXj66wEysLjwvDTHggQYP5eFrOE PHjQ== X-Gm-Message-State: AOJu0YxeoWD81w/kFiqYWVMQSd/mdVDJi4V0T7dwWLPlIiHwGPGc2eeK 7v0kds6PaC+nazfngLhfnss= X-Google-Smtp-Source: AGHT+IEddufbwv0CffqXBbRkP0gjGsls1zIkKQt72ukCuasMEuDugArS5PCYwMpWd6ZKRUv64IooIw== X-Received: by 2002:a17:906:fa84:b0:a19:a19a:eac2 with SMTP id lt4-20020a170906fa8400b00a19a19aeac2mr8418440ejb.123.1703076033051; Wed, 20 Dec 2023 04:40:33 -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 d22-20020a170906345600b00a269597d173sm604258ejb.135.2023.12.20.04.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 04:40:32 -0800 (PST) From: Tommaso Merciai To: Cc: linuxfancy@googlegroups.com, sakari.ailus@linux.intel.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 v3 5/5] media: i2c: alvium: fix req_fr check into alvium_s_frame_interval() Date: Wed, 20 Dec 2023 13:40:23 +0100 Message-Id: <20231220124023.2801417-6-tomm.merciai@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231220124023.2801417-1-tomm.merciai@gmail.com> References: <20231220124023.2801417-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 Actually req_fr check into alvium_s_frame_interval() is wrong. In particular req_fr can't be >=max and <= min at the same time. Fix this using clamp and remove dft_fr parameter from alvium_get_frame_interval() not more used. Signed-off-by: Tommaso Merciai Reviewed-by: Laurent Pinchart --- drivers/media/i2c/alvium-csi2.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/media/i2c/alvium-csi2.c b/drivers/media/i2c/alvium-csi2.c index 240bf991105e..01111a00902d 100644 --- a/drivers/media/i2c/alvium-csi2.c +++ b/drivers/media/i2c/alvium-csi2.c @@ -1171,12 +1171,10 @@ static int alvium_set_bayer_pattern(struct alvium_dev *alvium, } static int alvium_get_frame_interval(struct alvium_dev *alvium, - u64 *dft_fr, u64 *min_fr, u64 *max_fr) + u64 *min_fr, u64 *max_fr) { int ret = 0; - alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_RW, - dft_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MIN_R, min_fr, &ret); alvium_read(alvium, REG_BCRM_ACQUISITION_FRAME_RATE_MAX_R, @@ -1647,7 +1645,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, { struct alvium_dev *alvium = sd_to_alvium(sd); struct device *dev = &alvium->i2c_client->dev; - u64 req_fr, dft_fr, min_fr, max_fr; + u64 req_fr, min_fr, max_fr; struct v4l2_fract *interval; int ret; @@ -1657,7 +1655,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, if (fi->interval.denominator == 0) return -EINVAL; - ret = alvium_get_frame_interval(alvium, &dft_fr, &min_fr, &max_fr); + ret = alvium_get_frame_interval(alvium, &min_fr, &max_fr); if (ret) { dev_err(dev, "Fail to get frame interval\n"); return ret; @@ -1670,9 +1668,7 @@ static int alvium_s_frame_interval(struct v4l2_subdev *sd, 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; + req_fr = clamp(req_fr, min_fr, max_fr); interval = v4l2_subdev_state_get_interval(sd_state, 0);