linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sowjanya Komatineni <skomatineni@nvidia.com>
To: <skomatineni@nvidia.com>, <thierry.reding@gmail.com>,
	<jonathanh@nvidia.com>, <frankc@nvidia.com>, <hverkuil@xs4all.nl>,
	<sakari.ailus@iki.fi>, <robh+dt@kernel.org>,
	<helen.koike@collabora.com>
Cc: <digetx@gmail.com>, <sboyd@kernel.org>,
	<gregkh@linuxfoundation.org>, <linux-media@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <linux-i2c@vger.kernel.org>
Subject: [RFC PATCH v5 13/14] media: tegra-video: Add CSI MIPI pads calibration
Date: Mon, 27 Jul 2020 13:57:31 -0700	[thread overview]
Message-ID: <1595883452-17343-14-git-send-email-skomatineni@nvidia.com> (raw)
In-Reply-To: <1595883452-17343-1-git-send-email-skomatineni@nvidia.com>

CSI MIPI pads need to be enabled and calibrated for capturing from
the external sensor or transmitter.

MIPI CAL unit calibrates MIPI pads pull-up, pull-down and termination
impedances. Calibration is done by co-work of MIPI BIAS pad and MIPI
CAL control unit.

Triggering calibration start can happen any time after MIPI pads are
enabled but calibration results will be latched and applied to MIPI
pads by MIPI CAL unit only when the link is in LP11 state and then
calibration status register gets updated.

This patch enables CSI MIPI pads and calibrates them during streaming.

Tegra CSI receiver is able to catch the very first clock transition.
So, CSI receiver is always enabled prior to sensor streaming and
trigger of calibration start is done during CSI subdev streaming and
status of calibration is verified after sensor stream on.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
---
 drivers/staging/media/tegra-video/TODO  |  1 -
 drivers/staging/media/tegra-video/csi.c | 55 +++++++++++++++++++++++++++++++--
 drivers/staging/media/tegra-video/csi.h |  2 ++
 drivers/staging/media/tegra-video/vi.c  | 25 ++++++++++++++-
 4 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/tegra-video/TODO b/drivers/staging/media/tegra-video/TODO
index 97a19b4..98d3c7d 100644
--- a/drivers/staging/media/tegra-video/TODO
+++ b/drivers/staging/media/tegra-video/TODO
@@ -1,5 +1,4 @@
 TODO list
-* Add Tegra CSI MIPI pads calibration.
 * Add MIPI clock Settle time computation based on the data rate.
 * Add support for Ganged mode.
 * Add RAW10 packed video format support to Tegra210 video formats.
diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index c21dd09..752ebe8 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -252,15 +252,51 @@ static int tegra_csi_s_stream(struct v4l2_subdev *subdev, int enable)
 			return ret;
 		}
 
+		if (csi_chan->mipi) {
+			ret = tegra_mipi_enable(csi_chan->mipi);
+			if (ret < 0) {
+				dev_err(csi->dev,
+					"failed to enable MIPI pads: %d\n",
+					ret);
+				goto rpm_put;
+			}
+
+			/*
+			 * CSI MIPI pads PULLUP, PULLDN and TERM impedances
+			 * need to be calibrated after power on.
+			 * So, trigger the calibration start here and results
+			 * will be latched and applied to the pads when link is
+			 * in LP11 state during start of sensor streaming.
+			 */
+			ret = tegra_mipi_start_calibration(csi_chan->mipi);
+			if (ret < 0) {
+				dev_err(csi->dev,
+					"failed to start MIPI calibration: %d\n",
+					ret);
+				goto disable_mipi;
+			}
+		}
+
 		ret = csi->ops->csi_start_streaming(csi_chan);
-		if (ret < 0)
-			goto rpm_put;
+		if (ret < 0) {
+			if (csi_chan->mipi)
+				tegra_mipi_cancel_calibration(csi_chan->mipi);
+			goto disable_mipi;
+		}
 
 		return 0;
 	}
 
 	csi->ops->csi_stop_streaming(csi_chan);
 
+disable_mipi:
+	if (csi_chan->mipi) {
+		ret = tegra_mipi_disable(csi_chan->mipi);
+		if (ret < 0)
+			dev_err(csi->dev,
+				"failed to disable MIPI pads: %d\n", ret);
+	}
+
 rpm_put:
 	pm_runtime_put(csi->dev);
 	return ret;
@@ -294,6 +330,7 @@ static int tegra_csi_channel_alloc(struct tegra_csi *csi,
 				   unsigned int num_pads)
 {
 	struct tegra_csi_channel *chan;
+	int ret = 0;
 
 	chan = kzalloc(sizeof(*chan), GFP_KERNEL);
 	if (!chan)
@@ -312,7 +349,16 @@ static int tegra_csi_channel_alloc(struct tegra_csi *csi,
 		chan->pads[0].flags = MEDIA_PAD_FL_SOURCE;
 	}
 
-	return 0;
+	if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+		return 0;
+
+	chan->mipi = tegra_mipi_request(csi->dev, node);
+	if (IS_ERR(chan->mipi)) {
+		ret = PTR_ERR(chan->mipi);
+		dev_err(csi->dev, "failed to get mipi device: %d\n", ret);
+	}
+
+	return ret;
 }
 
 static int tegra_csi_tpg_channels_alloc(struct tegra_csi *csi)
@@ -475,6 +521,9 @@ static void tegra_csi_channels_cleanup(struct tegra_csi *csi)
 	struct tegra_csi_channel *chan, *tmp;
 
 	list_for_each_entry_safe(chan, tmp, &csi->csi_chans, list) {
+		if (chan->mipi)
+			tegra_mipi_free(chan->mipi);
+
 		subdev = &chan->subdev;
 		if (subdev->dev) {
 			if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
diff --git a/drivers/staging/media/tegra-video/csi.h b/drivers/staging/media/tegra-video/csi.h
index 78a5110..0d50fc3 100644
--- a/drivers/staging/media/tegra-video/csi.h
+++ b/drivers/staging/media/tegra-video/csi.h
@@ -50,6 +50,7 @@ struct tegra_csi;
  * @framerate: active framerate for TPG
  * @h_blank: horizontal blanking for TPG active format
  * @v_blank: vertical blanking for TPG active format
+ * @mipi: mipi device for corresponding csi channel pads
  */
 struct tegra_csi_channel {
 	struct list_head list;
@@ -65,6 +66,7 @@ struct tegra_csi_channel {
 	unsigned int framerate;
 	unsigned int h_blank;
 	unsigned int v_blank;
+	struct tegra_mipi_device *mipi;
 };
 
 /**
diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index fc43629..9c01cc5 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -191,10 +191,12 @@ tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan)
 int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on)
 {
 	struct v4l2_subdev *subdev, *csi_subdev, *src_subdev;
+	struct tegra_csi_channel *csi_chan;
 	int ret;
 
 	csi_subdev = tegra_channel_get_remote_csi_subdev(chan);
 	src_subdev = tegra_channel_get_remote_source_subdev(chan);
+	csi_chan = v4l2_get_subdevdata(csi_subdev);
 	/*
 	 * Tegra CSI receiver can detect the first LP to HS transition.
 	 * So, start the CSI stream-on prior to sensor stream-on and
@@ -208,10 +210,31 @@ int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on)
 	if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
 		return 0;
 
+	/*
+	 * TRM has incorrectly documented to wait for done status from
+	 * calibration logic after CSI interface power on.
+	 * As per the design, calibration results are latched and applied
+	 * to the pads only when the link is in LP11 state which will happen
+	 * during the sensor stream-on.
+	 * CSI subdev stream-on triggers start of MIPI pads calibration.
+	 * Wait for calibration to finish here after sensor subdev stream-on
+	 * and in case of sensor stream-on failure, cancel the calibration.
+	 */
 	subdev = on ? src_subdev : csi_subdev;
 	ret = v4l2_subdev_call(subdev, video, s_stream, on);
-	if (ret < 0 && ret != -ENOIOCTLCMD)
+	if (ret < 0 && ret != -ENOIOCTLCMD) {
+		if (on && csi_chan->mipi)
+			tegra_mipi_cancel_calibration(csi_chan->mipi);
 		return ret;
+	}
+
+	if (on && csi_chan->mipi) {
+		ret = tegra_mipi_finish_calibration(csi_chan->mipi);
+		if (ret < 0)
+			dev_err(csi_chan->csi->dev,
+				"MIPI calibration failed: %d\n", ret);
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.7.4


  parent reply	other threads:[~2020-07-27 20:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27 20:57 [RFC PATCH v5 00/14] Support for Tegra video capture from external sensor Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 01/14] i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM Sowjanya Komatineni
2020-07-28 16:33   ` Wolfram Sang
2020-07-27 20:57 ` [RFC PATCH v5 02/14] i2c: tegra: Remove NULL pointer check before clk_enable/disable/prepare/unprepare Sowjanya Komatineni
2020-07-28 16:33   ` Wolfram Sang
2020-07-27 20:57 ` [RFC PATCH v5 03/14] i2c: tegra: Fix the error path in tegra_i2c_runtime_resume Sowjanya Komatineni
2020-07-28 16:33   ` Wolfram Sang
2020-07-27 20:57 ` [RFC PATCH v5 04/14] i2c: tegra: Fix runtime resume to re-init VI I2C Sowjanya Komatineni
2020-07-28 16:33   ` Wolfram Sang
2020-07-27 20:57 ` [RFC PATCH v5 05/14] i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c Sowjanya Komatineni
2020-07-28 16:34   ` Wolfram Sang
2020-07-27 20:57 ` [RFC PATCH v5 06/14] media: tegra-video: Fix channel format alignment Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 07/14] media: tegra-video: Enable TPG based on kernel config Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 08/14] media: tegra-video: Update format lookup to offset based Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 09/14] dt-bindings: tegra: Update VI and CSI bindings with port info Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 10/14] media: tegra-video: Add support for external sensor capture Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 11/14] media: tegra-video: Add support for selection ioctl ops Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 12/14] gpu: host1x: mipi: Keep MIPI clock enabled till calibration is done Sowjanya Komatineni
2020-07-28 11:03   ` Dmitry Osipenko
2020-07-28 16:04     ` Sowjanya Komatineni
2020-07-29 17:08       ` Dmitry Osipenko
2020-07-29 17:55         ` Sowjanya Komatineni
2020-07-29 23:42           ` Dmitry Osipenko
2020-07-29 23:54             ` Sowjanya Komatineni
2020-07-30  0:31               ` Dmitry Osipenko
2020-07-27 20:57 ` Sowjanya Komatineni [this message]
2020-07-28 10:30   ` [RFC PATCH v5 13/14] media: tegra-video: Add CSI MIPI pads calibration Dmitry Osipenko
2020-07-28 15:59     ` Sowjanya Komatineni
2020-07-28 19:43       ` Sowjanya Komatineni
2020-07-29 23:25       ` Dmitry Osipenko
2020-07-29 23:59         ` Sowjanya Komatineni
2020-07-30  0:27           ` Sowjanya Komatineni
2020-07-30  0:43             ` Dmitry Osipenko
2020-07-30  0:52               ` Sowjanya Komatineni
2020-07-30  0:55                 ` Sowjanya Komatineni
2020-07-30  0:53                   ` Dmitry Osipenko
2020-07-30  1:06                     ` Sowjanya Komatineni
2020-07-30  1:10                       ` Dmitry Osipenko
2020-07-30  0:47             ` Sowjanya Komatineni
2020-07-27 20:57 ` [RFC PATCH v5 14/14] media: tegra-video: Compute settle times based on the clock rate Sowjanya Komatineni

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=1595883452-17343-14-git-send-email-skomatineni@nvidia.com \
    --to=skomatineni@nvidia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=frankc@nvidia.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=helen.koike@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jonathanh@nvidia.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sboyd@kernel.org \
    --cc=thierry.reding@gmail.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;
as well as URLs for NNTP newsgroup(s).