From: Maurizio Casciano <mauriziocasciano7@gmail.com>
To: linux-media@vger.kernel.org
Cc: Maurizio Casciano <mauriziocasciano7@gmail.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Nicholas Roth <nicholas@rothemail.net>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Bingbu Cao <bingbu.cao@amd.com>,
Dan Scally <dan.scally@ideasonboard.com>,
Hans de Goede <hansg@kernel.org>,
Andy Shevchenko <andy@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andy Shevchenko <andriy.shevchenko@intel.com>,
linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: [PATCH v11 09/14] media: atomisp: Derive CSI-2 timing from the sensor link frequency
Date: Sat, 21 Nov 2026 14:31:39 +0100 [thread overview]
Message-ID: <2070d23e030ce5ddb27402caa3672490e058b84d.1795267528.git.mauriziocasciano7@gmail.com> (raw)
In-Reply-To: <cover.1795267528.git.mauriziocasciano7@gmail.com>
The ISP2401 CSI-2 receiver timing depends on the sensor link frequency.
Query it through v4l2_get_link_freq() instead of reading a 32-bit
control value directly.
Keep the frequency as s64 to avoid an arbitrary S32_MAX limit. Use
div64_s64() so 32-bit builds use the kernel division helper. Fall
back to the default timings when the frequency query or divisor is
invalid.
Sashiko identified the 32-bit division issue. Codex reproduced it
and drafted the division helper change.
Link: https://linuxtv.org/mailman3/hyperkitty/list/media-ci@linuxtv.org/message/X3S2EI4364O5ARJK5JLDHTTXCW6TPSLE/
Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com>
---
.../staging/media/atomisp/pci/atomisp_csi2.c | 24 ++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2.c b/drivers/staging/media/atomisp/pci/atomisp_csi2.c
index 71df4ef62..f72fd0c3c 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2.c
@@ -5,6 +5,9 @@
* Copyright (c) 2010 Intel Corporation. All Rights Reserved.
*/
+#include <linux/math64.h>
+
+#include <media/v4l2-common.h>
#include <media/v4l2-event.h>
#include <media/v4l2-mediabus.h>
#include "atomisp_cmd.h"
@@ -210,7 +213,7 @@ int atomisp_mipi_csi2_register_entities(struct atomisp_mipi_csi2_device *csi2,
static const int LIMIT_SHIFT = 6; /* Limit numeric range into 31 bits */
static int
-atomisp_csi2_configure_calc(const short int coeffs[2], int mipi_freq, int def)
+atomisp_csi2_configure_calc(const short int coeffs[2], s64 mipi_freq, int def)
{
/* Delay counter accuracy, 1/0.0625 for ANN/CHT, 1/0.125 for BXT */
static const int accinv = 16; /* 1 / COUNT_ACC */
@@ -220,7 +223,7 @@ atomisp_csi2_configure_calc(const short int coeffs[2], int mipi_freq, int def)
return def;
r = accinv * coeffs[1] * (500000000 >> LIMIT_SHIFT);
- r /= mipi_freq >> LIMIT_SHIFT;
+ r = div64_s64(r, mipi_freq >> LIMIT_SHIFT);
r += accinv * coeffs[0];
return r;
@@ -289,18 +292,18 @@ static void atomisp_csi2_configure_isp2401(struct atomisp_sub_device *asd)
int dat_termen;
int dat_settle;
- struct v4l2_control ctrl;
struct atomisp_device *isp = asd->isp;
- int mipi_freq = 0;
enum atomisp_camera_port port;
+ struct v4l2_subdev *sensor;
+ s64 mipi_freq;
int n;
port = isp->inputs[asd->input_curr].port;
- ctrl.id = V4L2_CID_LINK_FREQ;
- if (v4l2_g_ctrl
- (isp->inputs[asd->input_curr].sensor->ctrl_handler, &ctrl) == 0)
- mipi_freq = ctrl.value;
+ sensor = isp->inputs[asd->input_curr].sensor;
+ mipi_freq = v4l2_get_link_freq(&sensor->entity.pads[0], 0, 0);
+ if (mipi_freq < 0)
+ mipi_freq = 0;
clk_termen = atomisp_csi2_configure_calc(coeff_clk_termen, mipi_freq,
TERMEN_DEFAULT);
@@ -311,6 +314,11 @@ static void atomisp_csi2_configure_isp2401(struct atomisp_sub_device *asd)
dat_settle = atomisp_csi2_configure_calc(coeff_dat_settle, mipi_freq,
SETTLE_DEFAULT);
+ dev_dbg(isp->dev,
+ "CSI port %u link frequency %lld Hz, clk timing %d/%d, data timing %d/%d\n",
+ port, mipi_freq, clk_termen, clk_settle,
+ dat_termen, dat_settle);
+
for (n = 0; n < csi2_port_lanes[port] + 1; n++) {
hrt_address base = csi2_port_base[port] + csi2_lane_base[n];
--
2.53.0
next prev parent reply other threads:[~2026-11-21 13:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 13:31 [PATCH v11 00/14] media: Add Lenovo Yoga Book camera support Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 01/14] media: v4l2-core: Preserve existing subdevice nodes on rollback Maurizio Casciano
2026-11-21 13:53 ` Laurent Pinchart
2026-11-21 16:24 ` Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 02/14] media: ov8858: Extract digital gain programming Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 03/14] media: ov8858: Support a 19.2 MHz input clock on four-lane R2A Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 04/14] media: ov2740: Add OVTI2740 ACPI ID Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 05/14] media: intel: ipu-bridge: Add the Yoga Book OVTI2740 entry Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 06/14] media: atomisp: Add Yoga Book camera configuration Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 07/14] media: ov2740: support 288 MHz link frequency Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 08/14] media: intel: ipu-bridge: select OV2740 frequency by IPU ID Maurizio Casciano
2026-11-21 13:31 ` Maurizio Casciano [this message]
2026-11-21 13:31 ` [PATCH v11 10/14] media: ov2740: release group hold after gain write errors Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 11/14] media: atomisp: Use struct v4l2_area for padding Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 12/14] media: atomisp: Allow raw Bayer capture Maurizio Casciano
2026-11-21 13:31 ` [PATCH v11 13/14] media: i2c: Add WV517S lens actuator driver Maurizio Casciano
2026-11-23 10:40 ` Andy Shevchenko
2026-11-21 13:31 ` [PATCH v11 14/14] media: atomisp: Preserve the capture graph when a lens rebinds Maurizio Casciano
2026-11-23 10:42 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2070d23e030ce5ddb27402caa3672490e058b84d.1795267528.git.mauriziocasciano7@gmail.com \
--to=mauriziocasciano7@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=bingbu.cao@amd.com \
--cc=dan.scally@ideasonboard.com \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=nicholas@rothemail.net \
--cc=sakari.ailus@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®