linux-kernel.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 v2 15/18] media: tegra-video: Add CSI MIPI pads calibration
Date: Tue, 16 Jun 2020 18:41:31 -0700	[thread overview]
Message-ID: <1592358094-23459-16-git-send-email-skomatineni@nvidia.com> (raw)
In-Reply-To: <1592358094-23459-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/csi.c | 44 +++++++++++++++++++++++++++++++--
 drivers/staging/media/tegra-video/csi.h |  2 ++
 drivers/staging/media/tegra-video/vi.c  | 18 ++++++++++++++
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 3959d17..f598b76 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -252,15 +252,42 @@ 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.
+			 */
+			tegra_mipi_calibrate(csi_chan->mipi);
+		}
+
 		ret = csi->ops->csi_start_streaming(csi_chan);
 		if (ret < 0)
-			goto rpm_put;
+			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 +321,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 +340,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)
@@ -473,6 +510,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 f9eb96b..8dc23f3 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -187,6 +187,7 @@ tegra_channel_get_remote_subdev(struct tegra_vi_channel *chan, bool sensor)
 int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on)
 {
 	struct v4l2_subdev *subdev;
+	struct tegra_csi_channel *csi_chan;
 	int ret;
 
 	/* stream CSI */
@@ -198,11 +199,28 @@ int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on)
 	if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
 		return 0;
 
+	if (on)
+		csi_chan = v4l2_get_subdevdata(subdev);
+
 	subdev = tegra_channel_get_remote_subdev(chan, on);
 	ret = v4l2_subdev_call(subdev, video, s_stream, on);
 	if (on && ret < 0 && ret != -ENOIOCTLCMD)
 		return ret;
 
+	/*
+	 * CSI subdev stream on triggers start of MIPI pads calibration.
+	 * Calibration results are latched and applied to the pads when
+	 * link is in LP11 state which will hapen during sensor streaming.
+	 * So, wait for calibration to complete here.
+	 */
+	if (on && csi_chan->mipi) {
+		ret = tegra_mipi_wait(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-06-17  1:40 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17  1:41 [RFC PATCH v2 00/18] Support for Tegra video capture from external sensor Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 01/18] dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and power-domains Sowjanya Komatineni
2020-07-13 23:49   ` Rob Herring
2020-06-17  1:41 ` [RFC PATCH v2 02/18] arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 03/18] i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 04/18] i2c: tegra: Fix the error path in tegra_i2c_runtime_resume Sowjanya Komatineni
2020-06-17  4:52   ` Dmitry Osipenko
2020-06-17  1:41 ` [RFC PATCH v2 05/18] i2c: tegra: Fix runtime resume to re-init VI I2C Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 06/18] i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 07/18] media: tegra-video: Fix channel format alignment Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 08/18] media: tegra-video: Enable TPG based on kernel config Sowjanya Komatineni
2020-06-29  9:28   ` Hans Verkuil
2020-06-29 14:48     ` Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 09/18] media: tegra-video: Update format lookup to offset based Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 10/18] dt-bindings: tegra: Update VI and CSI bindings with port info Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 11/18] media: tegra-video: Add support for external sensor capture Sowjanya Komatineni
2020-07-06  9:10   ` Hans Verkuil
2020-07-06 16:53     ` Sowjanya Komatineni
     [not found]     ` <6e09f5d3-85ca-5bf9-8617-b9c8bec36615@nvidia.com>
2020-07-07  9:51       ` Hans Verkuil
2020-07-07 10:32         ` Sowjanya Komatineni
     [not found]     ` <6ee18b4d-b63b-8053-1b7e-c3ec7c1d4956@nvidia.com>
     [not found]       ` <6846e5bb-db1d-c2ff-c52c-70a2094c5b50@nvidia.com>
2020-07-07 19:35         ` Hans Verkuil
2020-07-07 20:29           ` Sowjanya Komatineni
2020-07-07 20:41             ` Sowjanya Komatineni
2020-07-07 21:15               ` Sowjanya Komatineni
2020-07-06 11:49   ` Hans Verkuil
2020-06-17  1:41 ` [RFC PATCH v2 12/18] media: tegra-video: Add support for selection ioctl ops Sowjanya Komatineni
2020-07-02 13:54   ` Hans Verkuil
2020-07-02 21:20     ` Sowjanya Komatineni
2020-07-03  8:06       ` Hans Verkuil
2020-07-03 17:12         ` Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 13/18] gpu: host1x: mipi: Update tegra_mipi_request() to be node based Sowjanya Komatineni
2020-06-18  0:27   ` Dmitry Osipenko
2020-06-17  1:41 ` [RFC PATCH v2 14/18] gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait Sowjanya Komatineni
2020-06-18  0:35   ` Dmitry Osipenko
2020-06-17  1:41 ` Sowjanya Komatineni [this message]
2020-06-17  1:41 ` [RFC PATCH v2 16/18] media: tegra-video: Compute settle times based on the clock rate Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 17/18] arm64: tegra: jetson-tx1: Add camera supplies Sowjanya Komatineni
2020-06-17  1:41 ` [RFC PATCH v2 18/18] arm64: tegra: Enable Tegra VI CSI support for Jetson Nano Sowjanya Komatineni
2020-06-30  9:21 ` [RFC PATCH v2 00/18] Support for Tegra video capture from external sensor Hans Verkuil
2020-06-30 14:58   ` Sowjanya Komatineni
2020-06-30 15:13     ` Hans Verkuil
2020-06-30 15:44       ` Sowjanya Komatineni
2020-06-30 16:17         ` Sowjanya Komatineni
2020-06-30 16:34           ` Sowjanya Komatineni
2020-07-01 16:54             ` Hans Verkuil
2020-07-01 17:07               ` Sowjanya Komatineni
2020-07-02 10:49               ` Hans Verkuil
2020-07-02 14:08 ` Hans Verkuil
2020-07-02 21:21   ` 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=1592358094-23459-16-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).