From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Sowjanya Komatineni <skomatineni@nvidia.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Svyatoslav Ryhel <clamor95@gmail.com>,
Mikko Perttunen <mperttunen@nvidia.com>,
Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: linux-media@vger.kernel.org, linux-tegra@vger.kernel.org,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH v2 3/7] media: tegra-video: Move Tegra210-specific functions from common CSI
Date: Wed, 25 Nov 2026 13:26:09 +0200 [thread overview]
Message-ID: <20261125112613.237333-4-clamor95@gmail.com> (raw)
In-Reply-To: <20261125112613.237333-1-clamor95@gmail.com>
Move and staticize the tegra_csi_error_recover() and
tegra_csi_calc_settle_time() helpers from the common CSI file into the
Tegra210-specific code, since they are used exclusively by the HW rev. 3
Video Input found in Tegra210.
The tegra_csi_calc_settle_time() helper uses a custom MHZ definition
which corresponds to the standard HZ_PER_MHZ. The custom MHZ macro is
replaced by HZ_PER_MHZ, with this change folded into this commit.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
.../media/platform/nvidia/tegra-video/csi.c | 72 -------------------
.../media/platform/nvidia/tegra-video/csi.h | 5 --
.../platform/nvidia/tegra-video/tegra210.c | 70 ++++++++++++++++++
3 files changed, 70 insertions(+), 77 deletions(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/csi.c b/drivers/media/platform/nvidia/tegra-video/csi.c
index aaab884d99f54..fb4b4c0c7cfcd 100644
--- a/drivers/media/platform/nvidia/tegra-video/csi.c
+++ b/drivers/media/platform/nvidia/tegra-video/csi.c
@@ -19,8 +19,6 @@
#include "csi.h"
#include "video.h"
-#define MHZ 1000000
-
/*
* Test pattern generator configuration
*/
@@ -263,65 +261,6 @@ static int tegra_csi_tpg_init_state(struct v4l2_subdev *sd,
return 0;
}
-static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan)
-{
- struct v4l2_subdev *subdev = &csi_chan->subdev;
- struct v4l2_subdev *src_subdev;
- struct v4l2_ctrl *ctrl;
- struct media_pad *pad;
-
- pad = media_entity_remote_source_pad_unique(&subdev->entity);
- if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
- dev_err_probe(csi_chan->csi->dev, -ENODEV,
- "failed to get source entity\n");
-
- src_subdev = media_entity_to_v4l2_subdev(pad->entity);
- ctrl = v4l2_ctrl_find(src_subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
- if (ctrl)
- return v4l2_ctrl_g_ctrl_int64(ctrl);
-
- return 0;
-}
-
-void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan,
- u8 csi_port_num,
- u8 *clk_settle_time,
- u8 *ths_settle_time)
-{
- struct tegra_csi *csi = csi_chan->csi;
- unsigned int cil_clk_mhz;
- unsigned int pix_clk_mhz;
- int clk_idx = (csi_port_num >> 1) + 1;
-
- cil_clk_mhz = clk_get_rate(csi->clks[clk_idx].clk) / MHZ;
- pix_clk_mhz = csi_get_pixel_rate(csi_chan) / MHZ;
-
- /*
- * CLK Settle time is the interval during which HS receiver should
- * ignore any clock lane HS transitions, starting from the beginning
- * of T-CLK-PREPARE.
- * Per DPHY specification, T-CLK-SETTLE should be between 95ns ~ 300ns
- *
- * 95ns < (clk-settle-programmed + 7) * lp clk period < 300ns
- * midpoint = 197.5 ns
- */
- *clk_settle_time = ((95 + 300) * cil_clk_mhz - 14000) / 2000;
-
- /*
- * THS Settle time is the interval during which HS receiver should
- * ignore any data lane HS transitions, starting from the beginning
- * of THS-PREPARE.
- *
- * Per DPHY specification, T-HS-SETTLE should be between 85ns + 6UI
- * and 145ns+10UI.
- * 85ns + 6UI < (Ths-settle-prog + 5) * lp_clk_period < 145ns + 10UI
- * midpoint = 115ns + 8UI
- */
- if (pix_clk_mhz)
- *ths_settle_time = (115 * cil_clk_mhz + 8000 * cil_clk_mhz
- / (2 * pix_clk_mhz) - 5000) / 1000;
-}
-
/*
* Proper CSI configuration
*/
@@ -867,17 +806,6 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)
return 0;
}
-void tegra_csi_error_recover(struct v4l2_subdev *sd)
-{
- struct tegra_csi_channel *csi_chan = to_csi_chan(sd);
- struct tegra_csi *csi = csi_chan->csi;
-
- /* stop streaming during error recovery */
- csi->ops->csi_stop_streaming(csi_chan);
- csi->ops->csi_err_recover(csi_chan);
- csi->ops->csi_start_streaming(csi_chan);
-}
-
static int tegra_csi_channels_init(struct tegra_csi *csi)
{
struct tegra_csi_channel *chan;
diff --git a/drivers/media/platform/nvidia/tegra-video/csi.h b/drivers/media/platform/nvidia/tegra-video/csi.h
index 25aff2581f069..addd1b82685e9 100644
--- a/drivers/media/platform/nvidia/tegra-video/csi.h
+++ b/drivers/media/platform/nvidia/tegra-video/csi.h
@@ -175,9 +175,4 @@ static inline struct tegra_csi_channel *to_csi_chan(struct v4l2_subdev *subdev)
return container_of(subdev, struct tegra_csi_channel, subdev);
}
-void tegra_csi_error_recover(struct v4l2_subdev *subdev);
-void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan,
- u8 csi_port_num,
- u8 *clk_settle_time,
- u8 *ths_settle_time);
#endif
diff --git a/drivers/media/platform/nvidia/tegra-video/tegra210.c b/drivers/media/platform/nvidia/tegra-video/tegra210.c
index 90d984790696f..474f906e8bcc6 100644
--- a/drivers/media/platform/nvidia/tegra-video/tegra210.c
+++ b/drivers/media/platform/nvidia/tegra-video/tegra210.c
@@ -13,6 +13,7 @@
#include <linux/delay.h>
#include <linux/host1x.h>
#include <linux/kthread.h>
+#include <linux/units.h>
#include "csi.h"
#include "vi.h"
@@ -334,6 +335,17 @@ static void tegra_channel_vi_soft_reset(struct tegra_vi_channel *chan,
tegra_vi_write(chan, TEGRA_VI_CFG_CG_CTRL, VI_CG_2ND_LEVEL_EN);
}
+static void tegra_csi_error_recover(struct v4l2_subdev *sd)
+{
+ struct tegra_csi_channel *csi_chan = to_csi_chan(sd);
+ struct tegra_csi *csi = csi_chan->csi;
+
+ /* stop streaming during error recovery */
+ csi->ops->csi_stop_streaming(csi_chan);
+ csi->ops->csi_err_recover(csi_chan);
+ csi->ops->csi_start_streaming(csi_chan);
+}
+
static void tegra_channel_capture_error_recover(struct tegra_vi_channel *chan,
u8 portno)
{
@@ -979,6 +991,64 @@ static void tegra210_csi_error_recover(struct tegra_csi_channel *csi_chan)
tegra210_csi_port_recover(csi_chan, portnos[i]);
}
+static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan)
+{
+ struct v4l2_subdev *subdev = &csi_chan->subdev;
+ struct v4l2_subdev *src_subdev;
+ struct v4l2_ctrl *ctrl;
+ struct media_pad *pad;
+
+ pad = media_entity_remote_source_pad_unique(&subdev->entity);
+ if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
+ dev_err_probe(csi_chan->csi->dev, -ENODEV,
+ "failed to get source entity\n");
+
+ src_subdev = media_entity_to_v4l2_subdev(pad->entity);
+ ctrl = v4l2_ctrl_find(src_subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
+ if (ctrl)
+ return v4l2_ctrl_g_ctrl_int64(ctrl);
+
+ return 0;
+}
+
+static void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan,
+ u8 csi_port_num, u8 *clk_settle_time,
+ u8 *ths_settle_time)
+{
+ struct tegra_csi *csi = csi_chan->csi;
+ unsigned int cil_clk_mhz;
+ unsigned int pix_clk_mhz;
+ int clk_idx = (csi_port_num >> 1) + 1;
+
+ cil_clk_mhz = clk_get_rate(csi->clks[clk_idx].clk) / HZ_PER_MHZ;
+ pix_clk_mhz = csi_get_pixel_rate(csi_chan) / HZ_PER_MHZ;
+
+ /*
+ * CLK Settle time is the interval during which HS receiver should
+ * ignore any clock lane HS transitions, starting from the beginning
+ * of T-CLK-PREPARE.
+ * Per DPHY specification, T-CLK-SETTLE should be between 95ns ~ 300ns
+ *
+ * 95ns < (clk-settle-programmed + 7) * lp clk period < 300ns
+ * midpoint = 197.5 ns
+ */
+ *clk_settle_time = ((95 + 300) * cil_clk_mhz - 14000) / 2000;
+
+ /*
+ * THS Settle time is the interval during which HS receiver should
+ * ignore any data lane HS transitions, starting from the beginning
+ * of THS-PREPARE.
+ *
+ * Per DPHY specification, T-HS-SETTLE should be between 85ns + 6UI
+ * and 145ns+10UI.
+ * 85ns + 6UI < (Ths-settle-prog + 5) * lp_clk_period < 145ns + 10UI
+ * midpoint = 115ns + 8UI
+ */
+ if (pix_clk_mhz)
+ *ths_settle_time = (115 * cil_clk_mhz + 8000 * cil_clk_mhz
+ / (2 * pix_clk_mhz) - 5000) / 1000;
+}
+
static int
tegra210_csi_port_start_streaming(struct tegra_csi_channel *csi_chan,
u8 portno)
--
2.53.0
next prev parent reply other threads:[~2026-11-25 11:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 11:26 [PATCH v2 0/7] Tegra SoC specific Video Input updates Svyatoslav Ryhel
2026-11-25 11:26 ` [PATCH v2 1/7] dt-bindings: display: tegra: Remove Tegra30 fallback Svyatoslav Ryhel
2026-11-25 11:26 ` [PATCH v2 2/7] media: tegra-video: vi: Diverge Tegra20 and Tegra30 VI SoC descriptions Svyatoslav Ryhel
2026-11-25 11:26 ` Svyatoslav Ryhel [this message]
2026-11-25 11:26 ` [PATCH v2 4/7] dt-bindings: display: tegra: Document Tegra114 CSI Svyatoslav Ryhel
2026-11-25 11:26 ` [PATCH v2 5/7] media: tegra-video: Add CSI support for Tegra114 Svyatoslav Ryhel
2026-11-25 11:26 ` [PATCH v2 6/7] ARM: tegra: Remove fallback compatible from Tegra30 VI node Svyatoslav Ryhel
2026-11-25 11:26 ` [PATCH v2 7/7] ARM: tegra: Add CSI node for Tegra114 Svyatoslav Ryhel
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=20261125112613.237333-4-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil+cisco@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=mchehab@kernel.org \
--cc=mperttunen@nvidia.com \
--cc=robh@kernel.org \
--cc=skomatineni@nvidia.com \
--cc=thierry.reding@kernel.org \
/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®