2020-07-15 04:22:25

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor

This series adds support for video capture from external camera sensor to
Tegra video driver.

Jetson TX1 has camera expansion connector and supports custom camera module
designed as per TX1 design specification.

This series also enables camera capture support for Jetson Nano which has
Raspberry PI camera header.

This series is tested with IMX219 camera sensor.

This series include,

VI I2C related fixes
- Camera sensor programming happens through VI I2C which is on host1x bus.
- These patches includes device tree and I2C driver fixes for VI I2C.

Tegra video driver updates
- TPG Vs Non-TPG based on Kconfig
- Support for external sensor video capture based on device graph from DT.
- Support for selection ioctl operations
- Tegra MIPI CSI pads calibration
- CSI T-CLK and T-HS settle time computation based on clock rates.

Host1x driver updates
- Adds API to allow creating mipi device for specific device node.
- Splits MIPI pads calibrate start and waiting for calibration to be done.

Device tree updates
- Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson TX1 DT.
- Enabled VI and CSI support in Jetson Nano DT.


Delta between patch versions:

[v3]: Includes v2 feedback
- Uses separate helper function for retrieving remote csi subdevice
and source subdevice.
- Added check for presence of subdevice ops set/get_selection
- dropped vb2_queue_release from driver and using
vb2_video_unregister_device instead of video_unregister_device.
- video device register should happen in the last after all video
device related setup is done in the driver. This is being addressed
in below RFC patch. Once proper implementation of this is available
will update Tegra video driver to use split APIs and do all setup
prior to device register. Added this as TODO in the driver.
https://www.spinics.net/lists/linux-media/msg172761.html

Note:
Patch-0012 has compilation dependency on
https://patchwork.kernel.org/patch/11659521/


[v2]: Includes below changes based on v1 feedback
- dt-binding document and the driver update for device graph to use
separate ports for sink endpoint and source endpoint for csi.
- Use data-lanes endpoint property for csi.
- Update tegra_mipi_request() to take device node pointer argument
rather than adding extra API.
- Remove checking for clk pointer before clk_disable.


Sowjanya Komatineni (18):
dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
power-domains
arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C
i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
i2c: tegra: Remove NULL pointer check before
clk_enable/disable/prepare/unprepare
i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
i2c: tegra: Fix runtime resume to re-init VI I2C
i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
media: tegra-video: Fix channel format alignment
media: tegra-video: Enable TPG based on kernel config
media: tegra-video: Update format lookup to offset based
dt-bindings: tegra: Update VI and CSI bindings with port info
media: tegra-video: Add support for external sensor capture
media: tegra-video: Add support for selection ioctl ops
gpu: host1x: mipi: Update tegra_mipi_request() to be node based
gpu: host1x: mipi: Use readl_relaxed_poll_timeout in tegra_mipi_wait
gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
media: tegra-video: Add CSI MIPI pads calibration
media: tegra-video: Compute settle times based on the clock rate

.../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
.../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
drivers/gpu/drm/tegra/dsi.c | 9 +-
drivers/gpu/host1x/mipi.c | 37 +-
drivers/i2c/busses/i2c-tegra.c | 101 +--
drivers/staging/media/tegra-video/Kconfig | 7 +
drivers/staging/media/tegra-video/csi.c | 247 ++++++-
drivers/staging/media/tegra-video/csi.h | 8 +
drivers/staging/media/tegra-video/tegra210.c | 25 +-
drivers/staging/media/tegra-video/vi.c | 793 +++++++++++++++++++--
drivers/staging/media/tegra-video/vi.h | 25 +-
drivers/staging/media/tegra-video/video.c | 23 +-
include/linux/host1x.h | 4 +-
14 files changed, 1242 insertions(+), 154 deletions(-)

--
2.7.4


2020-07-15 04:22:29

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 18/18] media: tegra-video: Compute settle times based on the clock rate

Settle time determines the number of cil clock cyles to wait after
LP00 when moving from LP to HS.

This patch computes T-CLK-SETTLE and T-HS-SETTLE times based on cil
clock rate and pixel rate from the sensor and programs them during
streaming.

T-CLK-SETTLE time is the interval during which receiver will ignore
any HS transitions on clock lane starting from the beginning of
T-CLK-PREPARE.

T-HS-SETTLE time is the interval during which recevier will ignore
any HS transitions on data lane starting from the beginning of
T-HS-PREPARE.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
drivers/staging/media/tegra-video/csi.c | 55 ++++++++++++++++++++++++++++
drivers/staging/media/tegra-video/csi.h | 5 +++
drivers/staging/media/tegra-video/tegra210.c | 17 ++++++++-
3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 75c844d..d9f9e3c 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -19,6 +19,8 @@
#include "csi.h"
#include "video.h"

+#define MHZ 1000000
+
static inline struct tegra_csi *
host1x_client_to_csi(struct host1x_client *client)
{
@@ -235,6 +237,59 @@ static int tegra_csi_g_frame_interval(struct v4l2_subdev *subdev,
return 0;
}

+static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan)
+{
+ struct tegra_vi_channel *chan;
+ struct v4l2_subdev *src_subdev;
+ struct v4l2_ctrl *ctrl;
+
+ chan = v4l2_get_subdev_hostdata(&csi_chan->subdev);
+ src_subdev = tegra_channel_get_remote_source_subdev(chan);
+ 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 *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_chan->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;
+}
+
static int tegra_csi_s_stream(struct v4l2_subdev *subdev, int enable)
{
struct tegra_vi_channel *chan = v4l2_get_subdev_hostdata(subdev);
diff --git a/drivers/staging/media/tegra-video/csi.h b/drivers/staging/media/tegra-video/csi.h
index 0d50fc3..c65ff73 100644
--- a/drivers/staging/media/tegra-video/csi.h
+++ b/drivers/staging/media/tegra-video/csi.h
@@ -51,6 +51,7 @@ struct tegra_csi;
* @h_blank: horizontal blanking for TPG active format
* @v_blank: vertical blanking for TPG active format
* @mipi: mipi device for corresponding csi channel pads
+ * @pixel_rate: active pixel rate from the sensor on this channel
*/
struct tegra_csi_channel {
struct list_head list;
@@ -67,6 +68,7 @@ struct tegra_csi_channel {
unsigned int h_blank;
unsigned int v_blank;
struct tegra_mipi_device *mipi;
+ unsigned int pixel_rate;
};

/**
@@ -147,4 +149,7 @@ extern const struct tegra_csi_soc tegra210_csi_soc;
#endif

void tegra_csi_error_recover(struct v4l2_subdev *subdev);
+void tegra_csi_calc_settle_time(struct tegra_csi_channel *csi_chan,
+ u8 *clk_settle_time,
+ u8 *ths_settle_time);
#endif
diff --git a/drivers/staging/media/tegra-video/tegra210.c b/drivers/staging/media/tegra-video/tegra210.c
index 253bf33..ac066c0 100644
--- a/drivers/staging/media/tegra-video/tegra210.c
+++ b/drivers/staging/media/tegra-video/tegra210.c
@@ -7,6 +7,7 @@
* This source file contains Tegra210 supported video formats,
* VI and CSI SoC specific data, operations and registers accessors.
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/clk/tegra.h>
#include <linux/delay.h>
@@ -98,6 +99,8 @@
#define BRICK_CLOCK_B_4X (0x2 << 16)
#define TEGRA_CSI_CIL_PAD_CONFIG1 0x004
#define TEGRA_CSI_CIL_PHY_CONTROL 0x008
+#define CLK_SETTLE_MASK GENMASK(13, 8)
+#define THS_SETTLE_MASK GENMASK(5, 0)
#define TEGRA_CSI_CIL_INTERRUPT_MASK 0x00c
#define TEGRA_CSI_CIL_STATUS 0x010
#define TEGRA_CSI_CILX_STATUS 0x014
@@ -770,8 +773,14 @@ static int tegra210_csi_start_streaming(struct tegra_csi_channel *csi_chan)
{
struct tegra_csi *csi = csi_chan->csi;
unsigned int portno = csi_chan->csi_port_num;
+ u8 clk_settle_time = 0;
+ u8 ths_settle_time = 10;
u32 val;

+ if (!csi_chan->pg_mode)
+ tegra_csi_calc_settle_time(csi_chan, &clk_settle_time,
+ &ths_settle_time);
+
csi_write(csi, portno, TEGRA_CSI_CLKEN_OVERRIDE, 0);

/* clean up status */
@@ -782,7 +791,9 @@ static int tegra210_csi_start_streaming(struct tegra_csi_channel *csi_chan)

/* CIL PHY registers setup */
cil_write(csi, portno, TEGRA_CSI_CIL_PAD_CONFIG0, 0x0);
- cil_write(csi, portno, TEGRA_CSI_CIL_PHY_CONTROL, 0xa);
+ cil_write(csi, portno, TEGRA_CSI_CIL_PHY_CONTROL,
+ FIELD_PREP(CLK_SETTLE_MASK, clk_settle_time) |
+ FIELD_PREP(THS_SETTLE_MASK, ths_settle_time));

/*
* The CSI unit provides for connection of up to six cameras in
@@ -801,7 +812,9 @@ static int tegra210_csi_start_streaming(struct tegra_csi_channel *csi_chan)
BRICK_CLOCK_A_4X);
cil_write(csi, portno + 1, TEGRA_CSI_CIL_PAD_CONFIG0, 0x0);
cil_write(csi, portno + 1, TEGRA_CSI_CIL_INTERRUPT_MASK, 0x0);
- cil_write(csi, portno + 1, TEGRA_CSI_CIL_PHY_CONTROL, 0xa);
+ cil_write(csi, portno + 1, TEGRA_CSI_CIL_PHY_CONTROL,
+ FIELD_PREP(CLK_SETTLE_MASK, clk_settle_time) |
+ FIELD_PREP(THS_SETTLE_MASK, ths_settle_time));
csi_write(csi, portno, TEGRA_CSI_PHY_CIL_COMMAND,
CSI_A_PHY_CIL_ENABLE | CSI_B_PHY_CIL_ENABLE);
} else {
--
2.7.4

2020-07-15 04:23:26

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 13/18] media: tegra-video: Add support for selection ioctl ops

This patch adds selection v4l2 ioctl operations to allow configuring
a selection rectangle in the sensor through the Tegra video device
node.

Some sensor drivers supporting crop uses try_crop rectangle from
v4l2_subdev_pad_config during try format for computing binning.

So with selection ops support, this patch also updates try format
to use try crop rectangle either from subdev frame size enumeration
or from subdev crop boundary.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
drivers/staging/media/tegra-video/vi.c | 106 +++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)

diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index 5e19bab..676e24e2 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -437,6 +437,13 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
struct v4l2_subdev *subdev;
struct v4l2_subdev_format fmt;
struct v4l2_subdev_pad_config *pad_cfg;
+ struct v4l2_subdev_frame_size_enum fse = {
+ .which = V4L2_SUBDEV_FORMAT_TRY,
+ };
+ struct v4l2_subdev_selection sdsel = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ .target = V4L2_SEL_TGT_CROP_BOUNDS,
+ };
int ret;

subdev = tegra_channel_get_remote_source_subdev(chan);
@@ -462,6 +469,24 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
fmt.which = V4L2_SUBDEV_FORMAT_TRY;
fmt.pad = 0;
v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
+
+ /*
+ * Attempt to obtain the format size from subdev.
+ * If not available, try to get crop boundary from subdev.
+ */
+ fse.code = fmtinfo->code;
+ ret = v4l2_subdev_call(subdev, pad, enum_frame_size, pad_cfg, &fse);
+ if (ret) {
+ ret = v4l2_subdev_call(subdev, pad, get_selection, NULL, &sdsel);
+ if (ret)
+ return -EINVAL;
+ pad_cfg->try_crop.width = sdsel.r.width;
+ pad_cfg->try_crop.height = sdsel.r.height;
+ } else {
+ pad_cfg->try_crop.width = fse.max_width;
+ pad_cfg->try_crop.height = fse.max_height;
+ }
+
ret = v4l2_subdev_call(subdev, pad, set_fmt, pad_cfg, &fmt);
if (ret < 0)
return ret;
@@ -551,6 +576,85 @@ static int tegra_channel_set_subdev_active_fmt(struct tegra_vi_channel *chan)
return 0;
}

+static int tegra_channel_g_selection(struct file *file, void *priv,
+ struct v4l2_selection *sel)
+{
+ struct tegra_vi_channel *chan = video_drvdata(file);
+ struct v4l2_subdev *subdev;
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+ struct v4l2_subdev_selection sdsel = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ .target = sel->target,
+ };
+ int ret;
+
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ if (!v4l2_subdev_has_op(subdev, pad, get_selection))
+ return -ENOTTY;
+
+ if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+ return -EINVAL;
+ /*
+ * Try the get selection operation and fallback to get format if not
+ * implemented.
+ */
+ ret = v4l2_subdev_call(subdev, pad, get_selection, NULL, &sdsel);
+ if (!ret)
+ sel->r = sdsel.r;
+ if (ret != -ENOIOCTLCMD)
+ return ret;
+
+ ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
+ if (ret < 0)
+ return ret;
+
+ sel->r.left = 0;
+ sel->r.top = 0;
+ sel->r.width = fmt.format.width;
+ sel->r.height = fmt.format.height;
+
+ return 0;
+}
+
+static int tegra_channel_s_selection(struct file *file, void *fh,
+ struct v4l2_selection *sel)
+{
+ struct tegra_vi_channel *chan = video_drvdata(file);
+ struct v4l2_subdev *subdev;
+ int ret;
+ struct v4l2_subdev_selection sdsel = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ .target = sel->target,
+ .flags = sel->flags,
+ .r = sel->r,
+ };
+
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ if (!v4l2_subdev_has_op(subdev, pad, set_selection))
+ return -ENOTTY;
+
+ if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+ return -EINVAL;
+
+ if (vb2_is_busy(&chan->queue))
+ return -EBUSY;
+
+ ret = v4l2_subdev_call(subdev, pad, set_selection, NULL, &sdsel);
+ if (!ret) {
+ sel->r = sdsel.r;
+ /*
+ * Subdev active format resolution may have changed during
+ * set selection operation. So, update channel format to
+ * the sub-device active format.
+ */
+ return tegra_channel_set_subdev_active_fmt(chan);
+ }
+
+ return ret;
+}
+
static int tegra_channel_enum_input(struct file *file, void *fh,
struct v4l2_input *inp)
{
@@ -608,6 +712,8 @@ static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = {
.vidioc_streamoff = vb2_ioctl_streamoff,
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+ .vidioc_g_selection = tegra_channel_g_selection,
+ .vidioc_s_selection = tegra_channel_s_selection,
};

/*
--
2.7.4

2020-07-15 04:23:48

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 11/18] dt-bindings: tegra: Update VI and CSI bindings with port info

Update VI and CSI bindings to add port and endpoint nodes as per
media video-interfaces DT binding document.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
.../display/tegra/nvidia,tegra20-host1x.txt | 92 +++++++++++++++++++++-
1 file changed, 90 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.txt b/Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.txt
index 4731921..ac63ae4a 100644
--- a/Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.txt
+++ b/Documentation/devicetree/bindings/display/tegra/nvidia,tegra20-host1x.txt
@@ -51,8 +51,16 @@ of the following host1x client modules:
- vi
- Tegra210:
- power-domains: Must include venc powergate node as vi is in VE partition.
- - Tegra210 has CSI part of VI sharing same host interface and register space.
- So, VI device node should have CSI child node.
+
+ ports (optional node)
+ vi can have optional ports node and max 6 ports are supported. Each port
+ should have single 'endpoint' child node. All port nodes are grouped under
+ ports node. Please refer to the bindings defined in
+ Documentation/devicetree/bindings/media/video-interfaces.txt
+
+ csi (required node)
+ Tegra210 has CSI part of VI sharing same host interface and register space.
+ So, VI device node should have CSI child node.

- csi: mipi csi interface to vi

@@ -65,6 +73,46 @@ of the following host1x client modules:
- power-domains: Must include sor powergate node as csicil is in
SOR partition.

+ channel (optional nodes)
+ Maximum 6 channels are supported with each csi brick as either x4 or x2
+ based on hw connectivity to sensor.
+
+ Required properties:
+ - reg: csi port number. Valid port numbers are 0 through 5.
+ - nvidia,mipi-calibrate: Should contain a phandle and a specifier
+ specifying which pads are used by this CSI port and need to be
+ calibrated. See also ../display/tegra/nvidia,tegra114-mipi.txt.
+
+ Each channel node must contain 2 port nodes which can be grouped
+ under 'ports' node and each port should have a single child 'endpoint'
+ node.
+
+ ports node
+ Please refer to the bindings defined in
+ Documentation/devicetree/bindings/media/video-interfaces.txt
+
+ ports node must contain below 2 port nodes.
+ port@0 with single child 'endpoint' node always a sink.
+ port@1 with single child 'endpoint' node always a source.
+
+ port@0 (required node)
+ Required properties:
+ - reg: 0
+
+ endpoint (required node)
+ Required properties:
+ - data-lanes: an array of data lane from 1 to 4. Valid array
+ lengths are 1/2/4.
+ - remote-endpoint: phandle to sensor 'endpoint' node.
+
+ port@1 (required node)
+ Required properties:
+ - reg: 1
+
+ endpoint (required node)
+ Required properties:
+ - remote-endpoint: phandle to vi port 'endpoint' node.
+
- epp: encoder pre-processor

Required properties:
@@ -340,6 +388,18 @@ Example:

ranges = <0x0 0x0 0x54080000 0x2000>;

+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ imx219_vi_in0: endpoint {
+ remote-endpoint = <&imx219_csi_out0>;
+ };
+ };
+ };
+
csi@838 {
compatible = "nvidia,tegra210-csi";
reg = <0x838 0x1300>;
@@ -362,6 +422,34 @@ Example:
<&tegra_car TEGRA210_CLK_CSI_TPG>;
clock-names = "csi", "cilab", "cilcd", "cile", "csi_tpg";
power-domains = <&pd_sor>;
+
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ channel@0 {
+ reg = <0>;
+ nvidia,mipi-calibrate = <&mipi 0x001>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ imx219_csi_in0: endpoint {
+ data-lanes = <1 2>;
+ remote-endpoint = <&imx219_out0>;
+ };
+ };
+
+ port@1 {
+ reg = <1>;
+ imx219_csi_out0: endpoint {
+ remote-endpoint = <&imx219_vi_in0>;
+ };
+ };
+ };
+ };
};
};

--
2.7.4

2020-07-15 04:23:51

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 05/18] i2c: tegra: Fix the error path in tegra_i2c_runtime_resume

tegra_i2c_runtime_resume does not disable prior enabled clocks
properly.

This patch fixes it.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
drivers/i2c/busses/i2c-tegra.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index c91307b9..7b93c45 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -665,18 +665,23 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev)
ret = clk_enable(i2c_dev->slow_clk);
if (ret < 0) {
dev_err(dev, "failed to enable slow clock: %d\n", ret);
- return ret;
+ goto disable_fast_clk;
}

ret = clk_enable(i2c_dev->div_clk);
if (ret < 0) {
dev_err(i2c_dev->dev,
"Enabling div clk failed, err %d\n", ret);
- clk_disable(i2c_dev->fast_clk);
- return ret;
+ goto disable_slow_clk;
}

return 0;
+
+disable_slow_clk:
+ clk_disable(i2c_dev->slow_clk);
+disable_fast_clk:
+ clk_disable(i2c_dev->fast_clk);
+ return ret;
}

static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev)
--
2.7.4

2020-07-15 04:23:57

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 04/18] i2c: tegra: Remove NULL pointer check before clk_enable/disable/prepare/unprepare

clk_enable, clk_disable, clk_prepare, and clk_unprepare APIs have
implementation for checking clk pointer not NULL and clock consumers
can safely call these APIs without NULL pointer check.

So, this patch cleans up Tegra i2c driver to remove explicit checks
before these APIs.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
drivers/i2c/busses/i2c-tegra.c | 64 +++++++++++++++---------------------------
1 file changed, 23 insertions(+), 41 deletions(-)

diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 3be1018..c91307b9 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -655,21 +655,17 @@ static int __maybe_unused tegra_i2c_runtime_resume(struct device *dev)
if (ret)
return ret;

- if (!i2c_dev->hw->has_single_clk_source) {
- ret = clk_enable(i2c_dev->fast_clk);
- if (ret < 0) {
- dev_err(i2c_dev->dev,
- "Enabling fast clk failed, err %d\n", ret);
- return ret;
- }
+ ret = clk_enable(i2c_dev->fast_clk);
+ if (ret < 0) {
+ dev_err(i2c_dev->dev,
+ "Enabling fast clk failed, err %d\n", ret);
+ return ret;
}

- if (i2c_dev->slow_clk) {
- ret = clk_enable(i2c_dev->slow_clk);
- if (ret < 0) {
- dev_err(dev, "failed to enable slow clock: %d\n", ret);
- return ret;
- }
+ ret = clk_enable(i2c_dev->slow_clk);
+ if (ret < 0) {
+ dev_err(dev, "failed to enable slow clock: %d\n", ret);
+ return ret;
}

ret = clk_enable(i2c_dev->div_clk);
@@ -688,12 +684,8 @@ static int __maybe_unused tegra_i2c_runtime_suspend(struct device *dev)
struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);

clk_disable(i2c_dev->div_clk);
-
- if (i2c_dev->slow_clk)
- clk_disable(i2c_dev->slow_clk);
-
- if (!i2c_dev->hw->has_single_clk_source)
- clk_disable(i2c_dev->fast_clk);
+ clk_disable(i2c_dev->slow_clk);
+ clk_disable(i2c_dev->fast_clk);

return pinctrl_pm_select_idle_state(i2c_dev->dev);
}
@@ -1716,20 +1708,16 @@ static int tegra_i2c_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, i2c_dev);

- if (!i2c_dev->hw->has_single_clk_source) {
- ret = clk_prepare(i2c_dev->fast_clk);
- if (ret < 0) {
- dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret);
- return ret;
- }
+ ret = clk_prepare(i2c_dev->fast_clk);
+ if (ret < 0) {
+ dev_err(i2c_dev->dev, "Clock prepare failed %d\n", ret);
+ return ret;
}

- if (i2c_dev->slow_clk) {
- ret = clk_prepare(i2c_dev->slow_clk);
- if (ret < 0) {
- dev_err(dev, "failed to prepare slow clock: %d\n", ret);
- goto unprepare_fast_clk;
- }
+ ret = clk_prepare(i2c_dev->slow_clk);
+ if (ret < 0) {
+ dev_err(dev, "failed to prepare slow clock: %d\n", ret);
+ goto unprepare_fast_clk;
}

if (i2c_dev->bus_clk_rate > I2C_MAX_FAST_MODE_FREQ &&
@@ -1843,12 +1831,10 @@ static int tegra_i2c_probe(struct platform_device *pdev)
clk_unprepare(i2c_dev->div_clk);

unprepare_slow_clk:
- if (i2c_dev->is_vi)
- clk_unprepare(i2c_dev->slow_clk);
+ clk_unprepare(i2c_dev->slow_clk);

unprepare_fast_clk:
- if (!i2c_dev->hw->has_single_clk_source)
- clk_unprepare(i2c_dev->fast_clk);
+ clk_unprepare(i2c_dev->fast_clk);

return ret;
}
@@ -1867,12 +1853,8 @@ static int tegra_i2c_remove(struct platform_device *pdev)
tegra_i2c_runtime_suspend(&pdev->dev);

clk_unprepare(i2c_dev->div_clk);
-
- if (i2c_dev->slow_clk)
- clk_unprepare(i2c_dev->slow_clk);
-
- if (!i2c_dev->hw->has_single_clk_source)
- clk_unprepare(i2c_dev->fast_clk);
+ clk_unprepare(i2c_dev->slow_clk);
+ clk_unprepare(i2c_dev->fast_clk);

tegra_i2c_release_dma(i2c_dev);
return 0;
--
2.7.4

2020-07-15 04:24:04

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 01/18] dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and power-domains

This patch documents missing clocks and power-domains of Tegra210 VI I2C.

Reviewed-by: Rob Herring <[email protected]>
Signed-off-by: Sowjanya Komatineni <[email protected]>
---
.../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.txt b/Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.txt
index 18c0de3..3f2f990 100644
--- a/Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/nvidia,tegra20-i2c.txt
@@ -35,12 +35,12 @@ Required properties:
Due to above changes, Tegra114 I2C driver makes incompatible with
previous hardware driver. Hence, tegra114 I2C controller is compatible
with "nvidia,tegra114-i2c".
- nvidia,tegra210-i2c-vi: Tegra210 has one I2C controller that is part of the
- host1x domain and typically used for camera use-cases. This VI I2C
- controller is mostly compatible with the programming model of the
- regular I2C controllers with a few exceptions. The I2C registers start
- at an offset of 0xc00 (instead of 0), registers are 16 bytes apart
- (rather than 4) and the controller does not support slave mode.
+ nvidia,tegra210-i2c-vi: Tegra210 has one I2C controller that is on host1x bus
+ and is part of VE power domain and typically used for camera use-cases.
+ This VI I2C controller is mostly compatible with the programming model
+ of the regular I2C controllers with a few exceptions. The I2C registers
+ start at an offset of 0xc00 (instead of 0), registers are 16 bytes
+ apart (rather than 4) and the controller does not support slave mode.
- reg: Should contain I2C controller registers physical address and length.
- interrupts: Should contain I2C controller interrupts.
- address-cells: Address cells for I2C device address.
@@ -53,10 +53,17 @@ Required properties:
- fast-clk
Tegra114:
- div-clk
+ Tegra210:
+ - div-clk
+ - slow (only for nvidia,tegra210-i2c-vi compatible node)
- resets: Must contain an entry for each entry in reset-names.
See ../reset/reset.txt for details.
- reset-names: Must include the following entries:
- i2c
+- power-domains: Only for nvidia,tegra210-i2c-vi compatible node and must
+ include venc powergate node as vi i2c is part of VE power domain.
+ tegra210-i2c-vi:
+ - pd_venc
- dmas: Must contain an entry for each entry in clock-names.
See ../dma/dma.txt for details.
- dma-names: Must include the following entries:
--
2.7.4

2020-07-15 04:24:04

by Sowjanya Komatineni

[permalink] [raw]
Subject: [RFC PATCH v3 12/18] media: tegra-video: Add support for external sensor capture

This patch adds support to capture from the external sensor
based on device graph in the device tree.

Driver walks through the device graph to create media links
between the entities and registers and unregisters video devices
when the corresponding sub-devices are bound and unbound.

Channel formats are enumerated based on available formats from
the sensor and the corresponding matched formats from the Tegra
supported video formats list.

Each Tegra CSI instance can be configured as 4-lane or 2-lane
based on supported lane configuration from the sensor through
the device tree.

Currently this driver supports V4L2 video node centric only.

Signed-off-by: Sowjanya Komatineni <[email protected]>
---
drivers/staging/media/tegra-video/Kconfig | 1 +
drivers/staging/media/tegra-video/csi.c | 130 +++++-
drivers/staging/media/tegra-video/csi.h | 1 +
drivers/staging/media/tegra-video/tegra210.c | 2 +-
drivers/staging/media/tegra-video/vi.c | 648 +++++++++++++++++++++++++--
drivers/staging/media/tegra-video/vi.h | 25 +-
6 files changed, 749 insertions(+), 58 deletions(-)

diff --git a/drivers/staging/media/tegra-video/Kconfig b/drivers/staging/media/tegra-video/Kconfig
index 566da62..1f35da4 100644
--- a/drivers/staging/media/tegra-video/Kconfig
+++ b/drivers/staging/media/tegra-video/Kconfig
@@ -5,6 +5,7 @@ config VIDEO_TEGRA
depends on VIDEO_V4L2
select MEDIA_CONTROLLER
select VIDEOBUF2_DMA_CONTIG
+ select V4L2_FWNODE
help
Choose this option if you have an NVIDIA Tegra SoC.

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index fb667df..c21dd09 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -9,10 +9,13 @@
#include <linux/host1x.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_graph.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>

+#include <media/v4l2-fwnode.h>
+
#include "csi.h"
#include "video.h"

@@ -285,26 +288,101 @@ static const struct v4l2_subdev_ops tegra_csi_ops = {
.pad = &tegra_csi_pad_ops,
};

+static int tegra_csi_channel_alloc(struct tegra_csi *csi,
+ struct device_node *node,
+ unsigned int port_num, unsigned int lanes,
+ unsigned int num_pads)
+{
+ struct tegra_csi_channel *chan;
+
+ chan = kzalloc(sizeof(*chan), GFP_KERNEL);
+ if (!chan)
+ return -ENOMEM;
+
+ list_add_tail(&chan->list, &csi->csi_chans);
+ chan->csi = csi;
+ chan->csi_port_num = port_num;
+ chan->numlanes = lanes;
+ chan->of_node = node;
+ chan->numpads = num_pads;
+ if (num_pads & 0x2) {
+ chan->pads[0].flags = MEDIA_PAD_FL_SINK;
+ chan->pads[1].flags = MEDIA_PAD_FL_SOURCE;
+ } else {
+ chan->pads[0].flags = MEDIA_PAD_FL_SOURCE;
+ }
+
+ return 0;
+}
+
static int tegra_csi_tpg_channels_alloc(struct tegra_csi *csi)
{
struct device_node *node = csi->dev->of_node;
unsigned int port_num;
- struct tegra_csi_channel *chan;
unsigned int tpg_channels = csi->soc->csi_max_channels;
+ int ret;

/* allocate CSI channel for each CSI x2 ports */
for (port_num = 0; port_num < tpg_channels; port_num++) {
- chan = kzalloc(sizeof(*chan), GFP_KERNEL);
- if (!chan)
- return -ENOMEM;
-
- list_add_tail(&chan->list, &csi->csi_chans);
- chan->csi = csi;
- chan->csi_port_num = port_num;
- chan->numlanes = 2;
- chan->of_node = node;
- chan->numpads = 1;
- chan->pads[0].flags = MEDIA_PAD_FL_SOURCE;
+ ret = tegra_csi_channel_alloc(csi, node, port_num, 2, 1);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int tegra_csi_channels_alloc(struct tegra_csi *csi)
+{
+ struct device_node *node = csi->dev->of_node;
+ struct v4l2_fwnode_endpoint v4l2_ep = {
+ .bus_type = V4L2_MBUS_CSI2_DPHY
+ };
+ struct fwnode_handle *fwh;
+ struct device_node *channel;
+ struct device_node *ep;
+ unsigned int lanes, portno, num_pads;
+ int ret;
+
+ for_each_child_of_node(node, channel) {
+ if (!of_node_name_eq(channel, "channel"))
+ continue;
+
+ ret = of_property_read_u32(channel, "reg", &portno);
+ if (ret < 0)
+ continue;
+
+ if (portno >= csi->soc->csi_max_channels) {
+ dev_err(csi->dev, "invalid port num %d\n", portno);
+ return -EINVAL;
+ }
+
+ ep = of_graph_get_endpoint_by_regs(channel, 0, 0);
+ if (!ep)
+ continue;
+
+ fwh = of_fwnode_handle(ep);
+ ret = v4l2_fwnode_endpoint_parse(fwh, &v4l2_ep);
+ of_node_put(ep);
+ if (ret) {
+ dev_err(csi->dev,
+ "failed to parse v4l2 endpoint: %d\n", ret);
+ return ret;
+ }
+
+ lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
+ if (!lanes || ((lanes & (lanes - 1)) != 0)) {
+ dev_err(csi->dev, "invalid data-lanes %d\n", lanes);
+ return -EINVAL;
+ }
+
+ num_pads = of_graph_get_endpoint_count(channel);
+ if (num_pads == TEGRA_CSI_PADS_NUM) {
+ ret = tegra_csi_channel_alloc(csi, channel, portno,
+ lanes, num_pads);
+ if (ret < 0)
+ return ret;
+ }
}

return 0;
@@ -350,6 +428,15 @@ static int tegra_csi_channel_init(struct tegra_csi_channel *chan)
return ret;
}

+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) {
+ ret = v4l2_async_register_subdev(subdev);
+ if (ret < 0) {
+ dev_err(csi->dev,
+ "failed to register subdev: %d\n", ret);
+ return ret;
+ }
+ }
+
return 0;
}

@@ -389,8 +476,12 @@ static void tegra_csi_channels_cleanup(struct tegra_csi *csi)

list_for_each_entry_safe(chan, tmp, &csi->csi_chans, list) {
subdev = &chan->subdev;
- if (subdev->dev)
+ if (subdev->dev) {
+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ v4l2_async_unregister_subdev(subdev);
media_entity_cleanup(&subdev->entity);
+ }
+
list_del(&chan->list);
kfree(chan);
}
@@ -427,13 +518,14 @@ static int tegra_csi_init(struct host1x_client *client)

INIT_LIST_HEAD(&csi->csi_chans);

- if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) {
+ if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
ret = tegra_csi_tpg_channels_alloc(csi);
- if (ret < 0) {
- dev_err(csi->dev,
- "failed to allocate tpg channels: %d\n", ret);
- goto cleanup;
- }
+ else
+ ret = tegra_csi_channels_alloc(csi);
+ if (ret < 0) {
+ dev_err(csi->dev,
+ "failed to allocate channels: %d\n", ret);
+ goto cleanup;
}

ret = tegra_csi_channels_init(csi);
diff --git a/drivers/staging/media/tegra-video/csi.h b/drivers/staging/media/tegra-video/csi.h
index 93bd2a0..78a5110 100644
--- a/drivers/staging/media/tegra-video/csi.h
+++ b/drivers/staging/media/tegra-video/csi.h
@@ -7,6 +7,7 @@
#define __TEGRA_CSI_H__

#include <media/media-entity.h>
+#include <media/v4l2-async.h>
#include <media/v4l2-subdev.h>

/*
diff --git a/drivers/staging/media/tegra-video/tegra210.c b/drivers/staging/media/tegra-video/tegra210.c
index 3492a8a..253bf33 100644
--- a/drivers/staging/media/tegra-video/tegra210.c
+++ b/drivers/staging/media/tegra-video/tegra210.c
@@ -230,7 +230,7 @@ static void tegra_channel_capture_error_recover(struct tegra_vi_channel *chan)
tegra_channel_capture_setup(chan);

/* recover CSI block */
- subdev = tegra_channel_get_remote_subdev(chan);
+ subdev = tegra_channel_get_remote_csi_subdev(chan);
tegra_csi_error_recover(subdev);
}

diff --git a/drivers/staging/media/tegra-video/vi.c b/drivers/staging/media/tegra-video/vi.c
index 93edade..5e19bab 100644
--- a/drivers/staging/media/tegra-video/vi.c
+++ b/drivers/staging/media/tegra-video/vi.c
@@ -12,6 +12,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/pm_runtime.h>
@@ -52,6 +53,12 @@ to_tegra_channel_buffer(struct vb2_v4l2_buffer *vb)
return container_of(vb, struct tegra_channel_buffer, buf);
}

+static inline struct tegra_vi_graph_entity *
+to_tegra_vi_graph_entity(struct v4l2_async_subdev *asd)
+{
+ return container_of(asd, struct tegra_vi_graph_entity, asd);
+}
+
static int tegra_get_format_idx_by_code(struct tegra_vi *vi,
unsigned int code,
unsigned int offset)
@@ -146,28 +153,64 @@ static void tegra_channel_buffer_queue(struct vb2_buffer *vb)
}

struct v4l2_subdev *
-tegra_channel_get_remote_subdev(struct tegra_vi_channel *chan)
+tegra_channel_get_remote_csi_subdev(struct tegra_vi_channel *chan)
+{
+ struct media_pad *pad;
+
+ pad = media_entity_remote_pad(&chan->pad);
+ if (!pad)
+ return NULL;
+
+ return media_entity_to_v4l2_subdev(pad->entity);
+}
+
+struct v4l2_subdev *
+tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan)
{
struct media_pad *pad;
struct v4l2_subdev *subdev;
struct media_entity *entity;

- pad = media_entity_remote_pad(&chan->pad);
- entity = pad->entity;
- subdev = media_entity_to_v4l2_subdev(entity);
+ subdev = tegra_channel_get_remote_csi_subdev(chan);
+ if (!subdev)
+ return NULL;
+
+ pad = &subdev->entity.pads[0];
+ while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) {
+ pad = media_entity_remote_pad(pad);
+ if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
+ break;
+ entity = pad->entity;
+ pad = &entity->pads[0];
+ subdev = media_entity_to_v4l2_subdev(entity);
+ }

return subdev;
}

int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on)
{
- struct v4l2_subdev *subdev;
+ struct v4l2_subdev *subdev, *csi_subdev, *src_subdev;
int ret;

- /* stream CSI */
- subdev = tegra_channel_get_remote_subdev(chan);
+ csi_subdev = tegra_channel_get_remote_csi_subdev(chan);
+ src_subdev = tegra_channel_get_remote_source_subdev(chan);
+ /*
+ * Tegra CSI receiver can detect the first LP to HS transition.
+ * So, start the CSI stream-on prior to sensor stream-on and
+ * vice-versa for stream-off.
+ */
+ subdev = on ? csi_subdev : src_subdev;
ret = v4l2_subdev_call(subdev, video, s_stream, on);
- if (on && ret < 0 && ret != -ENOIOCTLCMD)
+ if (ret < 0 && ret != -ENOIOCTLCMD)
+ return ret;
+
+ if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ return 0;
+
+ subdev = on ? src_subdev : csi_subdev;
+ ret = v4l2_subdev_call(subdev, video, s_stream, on);
+ if (ret < 0 && ret != -ENOIOCTLCMD)
return ret;

return 0;
@@ -252,7 +295,7 @@ static int tegra_channel_g_parm(struct file *file, void *fh,
struct tegra_vi_channel *chan = video_drvdata(file);
struct v4l2_subdev *subdev;

- subdev = tegra_channel_get_remote_subdev(chan);
+ subdev = tegra_channel_get_remote_source_subdev(chan);
return v4l2_g_parm_cap(&chan->video, subdev, a);
}

@@ -262,7 +305,7 @@ static int tegra_channel_s_parm(struct file *file, void *fh,
struct tegra_vi_channel *chan = video_drvdata(file);
struct v4l2_subdev *subdev;

- subdev = tegra_channel_get_remote_subdev(chan);
+ subdev = tegra_channel_get_remote_source_subdev(chan);
return v4l2_s_parm_cap(&chan->video, subdev, a);
}

@@ -284,7 +327,7 @@ static int tegra_channel_enum_framesizes(struct file *file, void *fh,

fse.code = fmtinfo->code;

- subdev = tegra_channel_get_remote_subdev(chan);
+ subdev = tegra_channel_get_remote_source_subdev(chan);
ret = v4l2_subdev_call(subdev, pad, enum_frame_size, NULL, &fse);
if (ret)
return ret;
@@ -316,7 +359,7 @@ static int tegra_channel_enum_frameintervals(struct file *file, void *fh,

fie.code = fmtinfo->code;

- subdev = tegra_channel_get_remote_subdev(chan);
+ subdev = tegra_channel_get_remote_source_subdev(chan);
ret = v4l2_subdev_call(subdev, pad, enum_frame_interval, NULL, &fie);
if (ret)
return ret;
@@ -335,6 +378,9 @@ static int tegra_channel_enum_format(struct file *file, void *fh,
unsigned int index = 0, i;
unsigned long *fmts_bitmap = chan->tpg_fmts_bitmap;

+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ fmts_bitmap = chan->fmts_bitmap;
+
if (f->index >= bitmap_weight(fmts_bitmap, MAX_FORMAT_NUM))
return -EINVAL;

@@ -391,8 +437,12 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
struct v4l2_subdev *subdev;
struct v4l2_subdev_format fmt;
struct v4l2_subdev_pad_config *pad_cfg;
+ int ret;
+
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ if (!subdev)
+ return -ENODEV;

- subdev = tegra_channel_get_remote_subdev(chan);
pad_cfg = v4l2_subdev_alloc_pad_config(subdev);
if (!pad_cfg)
return -ENOMEM;
@@ -412,7 +462,10 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
fmt.which = V4L2_SUBDEV_FORMAT_TRY;
fmt.pad = 0;
v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
- v4l2_subdev_call(subdev, pad, set_fmt, pad_cfg, &fmt);
+ ret = v4l2_subdev_call(subdev, pad, set_fmt, pad_cfg, &fmt);
+ if (ret < 0)
+ return ret;
+
v4l2_fill_pix_format(pix, &fmt.format);
tegra_channel_fmt_align(chan, pix, fmtinfo->bpp);

@@ -452,8 +505,11 @@ static int tegra_channel_set_format(struct file *file, void *fh,
fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
fmt.pad = 0;
v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
- subdev = tegra_channel_get_remote_subdev(chan);
- v4l2_subdev_call(subdev, pad, set_fmt, NULL, &fmt);
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ ret = v4l2_subdev_call(subdev, pad, set_fmt, NULL, &fmt);
+ if (ret < 0)
+ return ret;
+
v4l2_fill_pix_format(pix, &fmt.format);
tegra_channel_fmt_align(chan, pix, fmtinfo->bpp);

@@ -463,15 +519,50 @@ static int tegra_channel_set_format(struct file *file, void *fh,
return 0;
}

+static int tegra_channel_set_subdev_active_fmt(struct tegra_vi_channel *chan)
+{
+ int ret, index;
+ struct v4l2_subdev *subdev;
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+
+ /*
+ * Initialize channel format to the sub-device active format if there
+ * is corresponding match in the Tegra supported video formats.
+ */
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
+ if (ret)
+ return ret;
+
+ index = tegra_get_format_idx_by_code(chan->vi, fmt.format.code, 0);
+ if (index < 0)
+ return -EINVAL;
+
+ chan->fmtinfo = &chan->vi->soc->video_formats[index];
+ v4l2_fill_pix_format(&chan->format, &fmt.format);
+ chan->format.pixelformat = chan->fmtinfo->fourcc;
+ chan->format.bytesperline = chan->format.width * chan->fmtinfo->bpp;
+ chan->format.sizeimage = chan->format.bytesperline *
+ chan->format.height;
+ tegra_channel_fmt_align(chan, &chan->format, chan->fmtinfo->bpp);
+
+ return 0;
+}
+
static int tegra_channel_enum_input(struct file *file, void *fh,
struct v4l2_input *inp)
{
- /* currently driver supports internal TPG only */
+ struct tegra_vi_channel *chan = video_drvdata(file);
+ struct v4l2_subdev *subdev;
+
if (inp->index)
return -EINVAL;

inp->type = V4L2_INPUT_TYPE_CAMERA;
- strscpy(inp->name, "Tegra TPG", sizeof(inp->name));
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ strscpy(inp->name, subdev->name, sizeof(inp->name));

return 0;
}
@@ -578,6 +669,22 @@ static int tegra_channel_setup_ctrl_handler(struct tegra_vi_channel *chan)
v4l2_ctrl_handler_free(&chan->ctrl_handler);
return chan->ctrl_handler.error;
}
+#else
+ struct v4l2_subdev *subdev;
+
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ if (!subdev)
+ return -ENODEV;
+
+ ret = v4l2_ctrl_add_handler(&chan->ctrl_handler, subdev->ctrl_handler,
+ NULL, true);
+ if (ret < 0) {
+ dev_err(chan->vi->dev,
+ "failed to add subdev %s ctrl handler: %d\n",
+ subdev->name, ret);
+ v4l2_ctrl_handler_free(&chan->ctrl_handler);
+ return ret;
+ }
#endif

/* setup the controls */
@@ -608,6 +715,61 @@ static void vi_tpg_fmts_bitmap_init(struct tegra_vi_channel *chan)
bitmap_set(chan->tpg_fmts_bitmap, index, 1);
}

+static int vi_fmts_bitmap_init(struct tegra_vi_channel *chan)
+{
+ int index, ret, match_code = 0;
+ struct v4l2_subdev *subdev;
+ struct v4l2_subdev_mbus_code_enum code = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ };
+
+ bitmap_zero(chan->fmts_bitmap, MAX_FORMAT_NUM);
+
+ /*
+ * Set the bitmap bits based on all the matched formats between the
+ * available media bus formats of sub-device and the pre-defined Tegra
+ * supported video formats.
+ */
+ subdev = tegra_channel_get_remote_source_subdev(chan);
+ while (1) {
+ ret = v4l2_subdev_call(subdev, pad, enum_mbus_code,
+ NULL, &code);
+ if (ret < 0)
+ break;
+
+ index = tegra_get_format_idx_by_code(chan->vi, code.code, 0);
+ while (index >= 0) {
+ bitmap_set(chan->fmts_bitmap, index, 1);
+ if (!match_code)
+ match_code = code.code;
+ /* look for other formats with same mbus code */
+ index = tegra_get_format_idx_by_code(chan->vi,
+ code.code,
+ index + 1);
+ }
+
+ code.index++;
+ }
+
+ /*
+ * Set the bitmap bit corresponding to default tegra video format if
+ * there are no matched formats.
+ */
+ if (!match_code) {
+ match_code = tegra_default_format.code;
+ index = tegra_get_format_idx_by_code(chan->vi, match_code, 0);
+ if (WARN_ON(index < 0))
+ return -EINVAL;
+
+ bitmap_set(chan->fmts_bitmap, index, 1);
+ }
+
+ /* initialize channel format to the sub-device active format */
+ tegra_channel_set_subdev_active_fmt(chan);
+
+ return 0;
+}
+
static void tegra_channel_cleanup(struct tegra_vi_channel *chan)
{
v4l2_ctrl_handler_free(&chan->ctrl_handler);
@@ -720,6 +882,9 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
goto free_v4l2_ctrl_hdl;
}

+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ v4l2_async_notifier_init(&chan->notifier);
+
return 0;

free_v4l2_ctrl_hdl:
@@ -733,28 +898,84 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
return ret;
}

-static int tegra_vi_tpg_channels_alloc(struct tegra_vi *vi)
+static int tegra_vi_channel_alloc(struct tegra_vi *vi, unsigned int port_num,
+ struct device_node *node)
{
struct tegra_vi_channel *chan;
+
+ /*
+ * Do not use devm_kzalloc as memory is freed immediately
+ * when device instance is unbound but application might still
+ * be holding the device node open. Channel memory allocated
+ * with kzalloc is freed during video device release callback.
+ */
+ chan = kzalloc(sizeof(*chan), GFP_KERNEL);
+ if (!chan)
+ return -ENOMEM;
+
+ chan->vi = vi;
+ chan->portno = port_num;
+ chan->of_node = node;
+ list_add_tail(&chan->list, &vi->vi_chans);
+
+ return 0;
+}
+
+static int tegra_vi_tpg_channels_alloc(struct tegra_vi *vi)
+{
unsigned int port_num;
unsigned int nchannels = vi->soc->vi_max_channels;
+ int ret;

for (port_num = 0; port_num < nchannels; port_num++) {
- /*
- * Do not use devm_kzalloc as memory is freed immediately
- * when device instance is unbound but application might still
- * be holding the device node open. Channel memory allocated
- * with kzalloc is freed during video device release callback.
- */
- chan = kzalloc(sizeof(*chan), GFP_KERNEL);
- if (!chan)
- return -ENOMEM;
+ ret = tegra_vi_channel_alloc(vi, port_num, vi->dev->of_node);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int tegra_vi_channels_alloc(struct tegra_vi *vi)
+{
+ struct device_node *node = vi->dev->of_node;
+ struct device_node *ep = NULL;
+ struct device_node *ports;
+ struct device_node *port;
+ unsigned int port_num;
+ int ret;
+
+ ports = of_get_child_by_name(node, "ports");
+ if (!ports)
+ return -ENODEV;
+
+ for_each_child_of_node(ports, port) {
+ if (!of_node_name_eq(port, "port"))
+ continue;
+
+ ret = of_property_read_u32(port, "reg", &port_num);
+ if (ret < 0)
+ continue;
+
+ if (port_num > vi->soc->vi_max_channels) {
+ of_node_put(ports);
+ dev_err(vi->dev, "invalid port num %d\n", port_num);
+ return -EINVAL;
+ }

- chan->vi = vi;
- chan->portno = port_num;
- list_add_tail(&chan->list, &vi->vi_chans);
+ ep = of_get_child_by_name(port, "endpoint");
+ if (!ep)
+ continue;
+
+ of_node_put(ep);
+ ret = tegra_vi_channel_alloc(vi, port_num, port);
+ if (ret < 0) {
+ of_node_put(ports);
+ return ret;
+ }
}

+ of_node_put(ports);
return 0;
}

@@ -905,6 +1126,347 @@ static int __maybe_unused vi_runtime_suspend(struct device *dev)
return 0;
}

+/*
+ * Graph Management
+ */
+static struct tegra_vi_graph_entity *
+tegra_vi_graph_find_entity(struct tegra_vi_channel *chan,
+ const struct fwnode_handle *fwnode)
+{
+ struct tegra_vi_graph_entity *entity;
+ struct v4l2_async_subdev *asd;
+
+ list_for_each_entry(asd, &chan->notifier.asd_list, asd_list) {
+ entity = to_tegra_vi_graph_entity(asd);
+ if (entity->asd.match.fwnode == fwnode)
+ return entity;
+ }
+
+ return NULL;
+}
+
+static int tegra_vi_graph_build(struct tegra_vi_channel *chan,
+ struct tegra_vi_graph_entity *entity)
+{
+ struct tegra_vi *vi = chan->vi;
+ struct tegra_vi_graph_entity *ent;
+ struct fwnode_handle *ep = NULL;
+ struct v4l2_fwnode_link link;
+ struct media_entity *local = entity->entity;
+ struct media_entity *remote;
+ struct media_pad *local_pad;
+ struct media_pad *remote_pad;
+ u32 link_flags = MEDIA_LNK_FL_ENABLED;
+ int ret = 0;
+
+ dev_dbg(vi->dev, "creating links for entity %s\n", local->name);
+
+ while (1) {
+ ep = fwnode_graph_get_next_endpoint(entity->asd.match.fwnode,
+ ep);
+ if (!ep)
+ break;
+
+ ret = v4l2_fwnode_parse_link(ep, &link);
+ if (ret < 0) {
+ dev_err(vi->dev, "failed to parse link for %pOF: %d\n",
+ to_of_node(ep), ret);
+ continue;
+ }
+
+ if (link.local_port >= local->num_pads) {
+ dev_err(vi->dev, "invalid port number %u on %pOF\n",
+ link.local_port, to_of_node(link.local_node));
+ v4l2_fwnode_put_link(&link);
+ ret = -EINVAL;
+ break;
+ }
+
+ local_pad = &local->pads[link.local_port];
+ /* Remote node is vi node. So use channel video entity and pad
+ * as remote/sink.
+ */
+ if (link.remote_node == of_fwnode_handle(vi->dev->of_node)) {
+ remote = &chan->video.entity;
+ remote_pad = &chan->pad;
+ goto create_link;
+ }
+
+ /*
+ * Skip sink ports, they will be processed from the other end
+ * of the link.
+ */
+ if (local_pad->flags & MEDIA_PAD_FL_SINK) {
+ dev_dbg(vi->dev, "skipping sink port %pOF:%u\n",
+ to_of_node(link.local_node), link.local_port);
+ v4l2_fwnode_put_link(&link);
+ continue;
+ }
+
+ /* find the remote entity from notifier list */
+ ent = tegra_vi_graph_find_entity(chan, link.remote_node);
+ if (!ent) {
+ dev_err(vi->dev, "no entity found for %pOF\n",
+ to_of_node(link.remote_node));
+ v4l2_fwnode_put_link(&link);
+ ret = -ENODEV;
+ break;
+ }
+
+ remote = ent->entity;
+ if (link.remote_port >= remote->num_pads) {
+ dev_err(vi->dev, "invalid port number %u on %pOF\n",
+ link.remote_port,
+ to_of_node(link.remote_node));
+ v4l2_fwnode_put_link(&link);
+ ret = -EINVAL;
+ break;
+ }
+
+ remote_pad = &remote->pads[link.remote_port];
+
+create_link:
+ dev_dbg(vi->dev, "creating %s:%u -> %s:%u link\n",
+ local->name, local_pad->index,
+ remote->name, remote_pad->index);
+
+ ret = media_create_pad_link(local, local_pad->index,
+ remote, remote_pad->index,
+ link_flags);
+ v4l2_fwnode_put_link(&link);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to create %s:%u -> %s:%u link: %d\n",
+ local->name, local_pad->index,
+ remote->name, remote_pad->index, ret);
+ break;
+ }
+ }
+
+ fwnode_handle_put(ep);
+ return ret;
+}
+
+static int tegra_vi_graph_notify_complete(struct v4l2_async_notifier *notifier)
+{
+ struct tegra_vi_graph_entity *entity;
+ struct v4l2_async_subdev *asd;
+ struct v4l2_subdev *subdev;
+ struct tegra_vi_channel *chan;
+ struct tegra_vi *vi;
+ int ret;
+
+ chan = container_of(notifier, struct tegra_vi_channel, notifier);
+ vi = chan->vi;
+
+ dev_dbg(vi->dev, "notify complete, all subdevs registered\n");
+
+ /*
+ * Video device node should be created at the end of all the device
+ * related initialization/setup.
+ * Current video_register_device() does both initialize and register
+ * video device in same API.
+ *
+ * TODO: Update v4l2-dev driver to split initialize and register into
+ * separate APIs and then update Tegra video driver to do video device
+ * initialize followed by all video device related setup and then
+ * register the video device.
+ */
+ ret = video_register_device(&chan->video, VFL_TYPE_VIDEO, -1);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to register video device: %d\n", ret);
+ goto unregister_video;
+ }
+
+ /* create links between the entities */
+ list_for_each_entry(asd, &chan->notifier.asd_list, asd_list) {
+ entity = to_tegra_vi_graph_entity(asd);
+ ret = tegra_vi_graph_build(chan, entity);
+ if (ret < 0)
+ goto unregister_video;
+ }
+
+ ret = tegra_channel_setup_ctrl_handler(chan);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to setup channel controls: %d\n", ret);
+ goto unregister_video;
+ }
+
+ ret = vi_fmts_bitmap_init(chan);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to initialize formats bitmap: %d\n", ret);
+ goto unregister_video;
+ }
+
+ subdev = tegra_channel_get_remote_csi_subdev(chan);
+ if (!subdev) {
+ ret = -ENODEV;
+ dev_err(vi->dev,
+ "failed to get remote csi subdev: %d\n", ret);
+ goto unregister_video;
+ }
+
+ v4l2_set_subdev_hostdata(subdev, chan);
+
+ return 0;
+
+unregister_video:
+ video_unregister_device(&chan->video);
+ return ret;
+}
+
+static int tegra_vi_graph_notify_bound(struct v4l2_async_notifier *notifier,
+ struct v4l2_subdev *subdev,
+ struct v4l2_async_subdev *asd)
+{
+ struct tegra_vi_graph_entity *entity;
+ struct tegra_vi *vi;
+ struct tegra_vi_channel *chan;
+
+ chan = container_of(notifier, struct tegra_vi_channel, notifier);
+ vi = chan->vi;
+
+ /*
+ * Locate the entity corresponding to the bound subdev and store the
+ * subdev pointer.
+ */
+ entity = tegra_vi_graph_find_entity(chan, subdev->fwnode);
+ if (!entity) {
+ dev_err(vi->dev, "no entity for subdev %s\n", subdev->name);
+ return -EINVAL;
+ }
+
+ if (entity->subdev) {
+ dev_err(vi->dev, "duplicate subdev for node %pOF\n",
+ to_of_node(entity->asd.match.fwnode));
+ return -EINVAL;
+ }
+
+ dev_dbg(vi->dev, "subdev %s bound\n", subdev->name);
+ entity->entity = &subdev->entity;
+ entity->subdev = subdev;
+
+ return 0;
+}
+
+static const struct v4l2_async_notifier_operations tegra_vi_async_ops = {
+ .bound = tegra_vi_graph_notify_bound,
+ .complete = tegra_vi_graph_notify_complete,
+};
+
+static int tegra_vi_graph_parse_one(struct tegra_vi_channel *chan,
+ struct fwnode_handle *fwnode)
+{
+ struct tegra_vi *vi = chan->vi;
+ struct fwnode_handle *ep = NULL;
+ struct fwnode_handle *remote = NULL;
+ struct v4l2_async_subdev *asd;
+ struct device_node *node = NULL;
+ int ret;
+
+ dev_dbg(vi->dev, "parsing node %pOF\n", to_of_node(fwnode));
+
+ /* parse all the remote entities and put them into the list */
+ for_each_endpoint_of_node(to_of_node(fwnode), node) {
+ ep = of_fwnode_handle(node);
+ remote = fwnode_graph_get_remote_port_parent(ep);
+ if (!remote) {
+ dev_err(vi->dev,
+ "remote device at %pOF not found\n", node);
+ ret = -EINVAL;
+ goto cleanup;
+ }
+
+ /* skip entities that are already processed */
+ if (remote == dev_fwnode(vi->dev) ||
+ tegra_vi_graph_find_entity(chan, remote)) {
+ fwnode_handle_put(remote);
+ continue;
+ }
+
+ asd = v4l2_async_notifier_add_fwnode_subdev(&chan->notifier,
+ remote, sizeof(struct tegra_vi_graph_entity));
+ if (IS_ERR(asd)) {
+ ret = PTR_ERR(asd);
+ dev_err(vi->dev,
+ "failed to add subdev to notifier: %d\n", ret);
+ fwnode_handle_put(remote);
+ goto cleanup;
+ }
+
+ ret = tegra_vi_graph_parse_one(chan, remote);
+ if (ret < 0) {
+ fwnode_handle_put(remote);
+ goto cleanup;
+ }
+
+ fwnode_handle_put(remote);
+ }
+
+ return 0;
+
+cleanup:
+ dev_err(vi->dev, "failed parsing the graph: %d\n", ret);
+ v4l2_async_notifier_cleanup(&chan->notifier);
+ of_node_put(node);
+ return ret;
+}
+
+static int tegra_vi_graph_init(struct tegra_vi *vi)
+{
+ struct tegra_video_device *vid = dev_get_drvdata(vi->client.host);
+ struct tegra_vi_channel *chan;
+ struct fwnode_handle *fwnode = dev_fwnode(vi->dev);
+ int ret;
+ struct fwnode_handle *remote = NULL;
+
+ /*
+ * Walk the links to parse the full graph. Each channel will have
+ * one endpoint of the composite node. Start by parsing the
+ * composite node and parse the remote entities in turn.
+ * Each channel will register v4l2 async notifier to make the graph
+ * independent between the channels so we can the current channel
+ * in case of something wrong during graph parsing and continue with
+ * next channels.
+ */
+ list_for_each_entry(chan, &vi->vi_chans, list) {
+ remote = fwnode_graph_get_remote_node(fwnode, chan->portno, 0);
+ if (!remote)
+ continue;
+
+ ret = tegra_vi_graph_parse_one(chan, remote);
+ fwnode_handle_put(remote);
+ if (ret < 0 || list_empty(&chan->notifier.asd_list))
+ continue;
+
+ chan->notifier.ops = &tegra_vi_async_ops;
+ ret = v4l2_async_notifier_register(&vid->v4l2_dev,
+ &chan->notifier);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to register channel %d notifier: %d\n",
+ chan->portno, ret);
+ v4l2_async_notifier_cleanup(&chan->notifier);
+ }
+ }
+
+ return 0;
+}
+
+static void tegra_vi_graph_cleanup(struct tegra_vi *vi)
+{
+ struct tegra_vi_channel *chan;
+
+ list_for_each_entry(chan, &vi->vi_chans, list) {
+ vb2_video_unregister_device(&chan->video);
+ v4l2_async_notifier_unregister(&chan->notifier);
+ v4l2_async_notifier_cleanup(&chan->notifier);
+ }
+}
+
static int tegra_vi_init(struct host1x_client *client)
{
struct tegra_video_device *vid = dev_get_drvdata(client->host);
@@ -918,13 +1480,14 @@ static int tegra_vi_init(struct host1x_client *client)

INIT_LIST_HEAD(&vi->vi_chans);

- if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) {
+ if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
ret = tegra_vi_tpg_channels_alloc(vi);
- if (ret < 0) {
- dev_err(vi->dev,
- "failed to allocate tpg channels: %d\n", ret);
- goto free_chans;
- }
+ else
+ ret = tegra_vi_channels_alloc(vi);
+ if (ret < 0) {
+ dev_err(vi->dev,
+ "failed to allocate vi channels: %d\n", ret);
+ goto free_chans;
}

ret = tegra_vi_channels_init(vi);
@@ -933,6 +1496,12 @@ static int tegra_vi_init(struct host1x_client *client)

vid->vi = vi;

+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) {
+ ret = tegra_vi_graph_init(vi);
+ if (ret < 0)
+ goto free_chans;
+ }
+
return 0;

free_chans:
@@ -946,6 +1515,8 @@ static int tegra_vi_init(struct host1x_client *client)

static int tegra_vi_exit(struct host1x_client *client)
{
+ struct tegra_vi *vi = host1x_client_to_vi(client);
+
/*
* Do not cleanup the channels here as application might still be
* holding video device nodes. Channels cleanup will happen during
@@ -953,6 +1524,9 @@ static int tegra_vi_exit(struct host1x_client *client)
* device nodes are released.
*/

+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ tegra_vi_graph_cleanup(vi);
+
return 0;
}

diff --git a/drivers/staging/media/tegra-video/vi.h b/drivers/staging/media/tegra-video/vi.h
index 6272c9a..7d6b7a6 100644
--- a/drivers/staging/media/tegra-video/vi.h
+++ b/drivers/staging/media/tegra-video/vi.h
@@ -14,6 +14,7 @@
#include <linux/wait.h>

#include <media/media-entity.h>
+#include <media/v4l2-async.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-dev.h>
@@ -93,6 +94,19 @@ struct tegra_vi {
};

/**
+ * struct tegra_vi_graph_entity - Entity in the video graph
+ *
+ * @asd: subdev asynchronous registration information
+ * @entity: media entity from the corresponding V4L2 subdev
+ * @subdev: V4L2 subdev
+ */
+struct tegra_vi_graph_entity {
+ struct v4l2_async_subdev asd;
+ struct media_entity *entity;
+ struct v4l2_subdev *subdev;
+};
+
+/**
* struct tegra_vi_channel - Tegra video channel
*
* @list: list head for this entry
@@ -138,10 +152,13 @@ struct tegra_vi {
* @done_lock: protects the capture done queue list
*
* @portno: VI channel port number
+ * @of_node: device node of VI channel
*
* @ctrl_handler: V4L2 control handler of this video channel
+ * @fmts_bitmap: a bitmap for supported formats matching v4l2 subdev formats
* @tpg_fmts_bitmap: a bitmap for supported TPG formats
* @pg_mode: test pattern generator mode (disabled/direct/patch)
+ * @notifier: V4L2 asynchronous subdevs notifier
*/
struct tegra_vi_channel {
struct list_head list;
@@ -174,10 +191,14 @@ struct tegra_vi_channel {
spinlock_t done_lock;

unsigned char portno;
+ struct device_node *of_node;

struct v4l2_ctrl_handler ctrl_handler;
+ DECLARE_BITMAP(fmts_bitmap, MAX_FORMAT_NUM);
DECLARE_BITMAP(tpg_fmts_bitmap, MAX_FORMAT_NUM);
enum tegra_vi_pg_mode pg_mode;
+
+ struct v4l2_async_notifier notifier;
};

/**
@@ -249,7 +270,9 @@ extern const struct tegra_vi_soc tegra210_vi_soc;
#endif

struct v4l2_subdev *
-tegra_channel_get_remote_subdev(struct tegra_vi_channel *chan);
+tegra_channel_get_remote_csi_subdev(struct tegra_vi_channel *chan);
+struct v4l2_subdev *
+tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan);
int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on);
void tegra_channel_release_buffers(struct tegra_vi_channel *chan,
enum vb2_buffer_state state);
--
2.7.4

2020-07-16 13:25:46

by Thierry Reding

[permalink] [raw]
Subject: Re: [RFC PATCH v3 01/18] dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and power-domains

On Tue, Jul 14, 2020 at 09:20:38PM -0700, Sowjanya Komatineni wrote:
> This patch documents missing clocks and power-domains of Tegra210 VI I2C.
>
> Reviewed-by: Rob Herring <[email protected]>
> Signed-off-by: Sowjanya Komatineni <[email protected]>
> ---
> .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)

Applied, thanks.

Thierry


Attachments:
(No filename) (434.00 B)
signature.asc (849.00 B)
Download all attachments

2020-07-16 19:11:55

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [RFC PATCH v3 11/18] dt-bindings: tegra: Update VI and CSI bindings with port info

On Tue, 14 Jul 2020 21:20:48 -0700, Sowjanya Komatineni wrote:
> Update VI and CSI bindings to add port and endpoint nodes as per
> media video-interfaces DT binding document.
>
> Signed-off-by: Sowjanya Komatineni <[email protected]>
> ---
> .../display/tegra/nvidia,tegra20-host1x.txt | 92 +++++++++++++++++++++-
> 1 file changed, 90 insertions(+), 2 deletions(-)
>

Acked-by: Rob Herring <[email protected]>

2020-07-16 20:28:10

by Dmitry Osipenko

[permalink] [raw]
Subject: Re: [RFC PATCH v3 04/18] i2c: tegra: Remove NULL pointer check before clk_enable/disable/prepare/unprepare

15.07.2020 07:20, Sowjanya Komatineni пишет:
> clk_enable, clk_disable, clk_prepare, and clk_unprepare APIs have
> implementation for checking clk pointer not NULL and clock consumers
> can safely call these APIs without NULL pointer check.
>
> So, this patch cleans up Tegra i2c driver to remove explicit checks
> before these APIs.
>
> Signed-off-by: Sowjanya Komatineni <[email protected]>
> ---

Thanks!

Reviewed-by: Dmitry Osipenko <[email protected]>

2020-07-17 10:55:56

by Hans Verkuil

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor

Hi Sowjanya,

On 15/07/2020 06:20, Sowjanya Komatineni wrote:
> This series adds support for video capture from external camera sensor to
> Tegra video driver.
>
> Jetson TX1 has camera expansion connector and supports custom camera module
> designed as per TX1 design specification.
>
> This series also enables camera capture support for Jetson Nano which has
> Raspberry PI camera header.
>
> This series is tested with IMX219 camera sensor.
>
> This series include,
>
> VI I2C related fixes
> - Camera sensor programming happens through VI I2C which is on host1x bus.
> - These patches includes device tree and I2C driver fixes for VI I2C.
>
> Tegra video driver updates
> - TPG Vs Non-TPG based on Kconfig
> - Support for external sensor video capture based on device graph from DT.
> - Support for selection ioctl operations
> - Tegra MIPI CSI pads calibration
> - CSI T-CLK and T-HS settle time computation based on clock rates.
>
> Host1x driver updates
> - Adds API to allow creating mipi device for specific device node.
> - Splits MIPI pads calibrate start and waiting for calibration to be done.
>
> Device tree updates
> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson TX1 DT.
> - Enabled VI and CSI support in Jetson Nano DT.

I'm doing a bit of stress testing with:

while true; do v4l2-ctl --stream-mmap --stream-count=1; done

and I see that the imx274 has often streaming failures:

[ 172.025144] IMX274 8-001a: s_stream failed
[ 179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3132 = 870 (2 bytes)
[ 179.033575] IMX274 8-001a: s_stream failed
[ 226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3130 = 878 (2 bytes)
[ 226.533761] IMX274 8-001a: s_stream failed
[ 227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
[ 227.037758] IMX274 8-001a: s_stream failed
[ 247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
[ 247.033658] IMX274 8-001a: s_stream failed
[ 293.025517] IMX274 8-001a: s_stream failed
[ 309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30e0 = 0 (2 bytes)
[ 309.032969] IMX274 8-001a: s_stream failed
[ 309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f8 = 11d2 (3 bytes)
[ 309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
[ 309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
[ 309.550243] IMX274 8-001a: s_stream failed
[ 314.025561] IMX274 8-001a: s_stream failed
[ 329.025586] IMX274 8-001a: s_stream failed
[ 340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 303a = f0c (2 bytes)
[ 340.538009] IMX274 8-001a: s_stream failed
[ 347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
[ 347.534008] IMX274 8-001a: s_stream failed
[ 365.033640] IMX274 8-001a: s_stream failed
[ 437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3038 = c (2 bytes)
[ 437.533997] IMX274 8-001a: s_stream failed
[ 456.029780] IMX274 8-001a: s_stream failed
[ 472.025862] IMX274 8-001a: s_stream failed
[ 498.025861] IMX274 8-001a: s_stream failed
[ 500.025905] IMX274 8-001a: s_stream failed

where v4l2-ctl returns:

VIDIOC_STREAMON returned -1 (Remote I/O error)

I don't see this with the imx219.

I also see this occasionally:

[Fri Jul 17 12:51:42 2020] video4linux video1: failed to run capture start kthread: -4

Something is not stable here.

Regards,

Hans

>
>
> Delta between patch versions:
>
> [v3]: Includes v2 feedback
> - Uses separate helper function for retrieving remote csi subdevice
> and source subdevice.
> - Added check for presence of subdevice ops set/get_selection
> - dropped vb2_queue_release from driver and using
> vb2_video_unregister_device instead of video_unregister_device.
> - video device register should happen in the last after all video
> device related setup is done in the driver. This is being addressed
> in below RFC patch. Once proper implementation of this is available
> will update Tegra video driver to use split APIs and do all setup
> prior to device register. Added this as TODO in the driver.
> https://www.spinics.net/lists/linux-media/msg172761.html
>
> Note:
> Patch-0012 has compilation dependency on
> https://patchwork.kernel.org/patch/11659521/
>
>
> [v2]: Includes below changes based on v1 feedback
> - dt-binding document and the driver update for device graph to use
> separate ports for sink endpoint and source endpoint for csi.
> - Use data-lanes endpoint property for csi.
> - Update tegra_mipi_request() to take device node pointer argument
> rather than adding extra API.
> - Remove checking for clk pointer before clk_disable.
>
>
> Sowjanya Komatineni (18):
> dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
> power-domains
> arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C
> i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
> i2c: tegra: Remove NULL pointer check before
> clk_enable/disable/prepare/unprepare
> i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
> i2c: tegra: Fix runtime resume to re-init VI I2C
> i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
> media: tegra-video: Fix channel format alignment
> media: tegra-video: Enable TPG based on kernel config
> media: tegra-video: Update format lookup to offset based
> dt-bindings: tegra: Update VI and CSI bindings with port info
> media: tegra-video: Add support for external sensor capture
> media: tegra-video: Add support for selection ioctl ops
> gpu: host1x: mipi: Update tegra_mipi_request() to be node based
> gpu: host1x: mipi: Use readl_relaxed_poll_timeout in tegra_mipi_wait
> gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
> media: tegra-video: Add CSI MIPI pads calibration
> media: tegra-video: Compute settle times based on the clock rate
>
> .../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
> .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
> arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
> drivers/gpu/drm/tegra/dsi.c | 9 +-
> drivers/gpu/host1x/mipi.c | 37 +-
> drivers/i2c/busses/i2c-tegra.c | 101 +--
> drivers/staging/media/tegra-video/Kconfig | 7 +
> drivers/staging/media/tegra-video/csi.c | 247 ++++++-
> drivers/staging/media/tegra-video/csi.h | 8 +
> drivers/staging/media/tegra-video/tegra210.c | 25 +-
> drivers/staging/media/tegra-video/vi.c | 793 +++++++++++++++++++--
> drivers/staging/media/tegra-video/vi.h | 25 +-
> drivers/staging/media/tegra-video/video.c | 23 +-
> include/linux/host1x.h | 4 +-
> 14 files changed, 1242 insertions(+), 154 deletions(-)
>

2020-07-17 16:34:32

by Sowjanya Komatineni

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor


On 7/17/20 3:54 AM, Hans Verkuil wrote:
> Hi Sowjanya,
>
> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>> This series adds support for video capture from external camera sensor to
>> Tegra video driver.
>>
>> Jetson TX1 has camera expansion connector and supports custom camera module
>> designed as per TX1 design specification.
>>
>> This series also enables camera capture support for Jetson Nano which has
>> Raspberry PI camera header.
>>
>> This series is tested with IMX219 camera sensor.
>>
>> This series include,
>>
>> VI I2C related fixes
>> - Camera sensor programming happens through VI I2C which is on host1x bus.
>> - These patches includes device tree and I2C driver fixes for VI I2C.
>>
>> Tegra video driver updates
>> - TPG Vs Non-TPG based on Kconfig
>> - Support for external sensor video capture based on device graph from DT.
>> - Support for selection ioctl operations
>> - Tegra MIPI CSI pads calibration
>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>
>> Host1x driver updates
>> - Adds API to allow creating mipi device for specific device node.
>> - Splits MIPI pads calibrate start and waiting for calibration to be done.
>>
>> Device tree updates
>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson TX1 DT.
>> - Enabled VI and CSI support in Jetson Nano DT.
> I'm doing a bit of stress testing with:
>
> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>
> and I see that the imx274 has often streaming failures:
>
> [ 172.025144] IMX274 8-001a: s_stream failed
> [ 179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3132 = 870 (2 bytes)
> [ 179.033575] IMX274 8-001a: s_stream failed
> [ 226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3130 = 878 (2 bytes)
> [ 226.533761] IMX274 8-001a: s_stream failed
> [ 227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
> [ 227.037758] IMX274 8-001a: s_stream failed
> [ 247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
> [ 247.033658] IMX274 8-001a: s_stream failed
> [ 293.025517] IMX274 8-001a: s_stream failed
> [ 309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30e0 = 0 (2 bytes)
> [ 309.032969] IMX274 8-001a: s_stream failed
> [ 309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f8 = 11d2 (3 bytes)
> [ 309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
> [ 309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
> [ 309.550243] IMX274 8-001a: s_stream failed
> [ 314.025561] IMX274 8-001a: s_stream failed
> [ 329.025586] IMX274 8-001a: s_stream failed
> [ 340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 303a = f0c (2 bytes)
> [ 340.538009] IMX274 8-001a: s_stream failed
> [ 347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
> [ 347.534008] IMX274 8-001a: s_stream failed
> [ 365.033640] IMX274 8-001a: s_stream failed
> [ 437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3038 = c (2 bytes)
> [ 437.533997] IMX274 8-001a: s_stream failed
> [ 456.029780] IMX274 8-001a: s_stream failed
> [ 472.025862] IMX274 8-001a: s_stream failed
> [ 498.025861] IMX274 8-001a: s_stream failed
> [ 500.025905] IMX274 8-001a: s_stream failed
>
> where v4l2-ctl returns:
>
> VIDIOC_STREAMON returned -1 (Remote I/O error)
>
> I don't see this with the imx219.
>
> I also see this occasionally:
>
> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run capture start kthread: -4
>
> Something is not stable here.
>
> Regards,
>
> Hans

Hi Hans,

Running the same single frame continuous loop for more than 2 hours now
and I don't see any failure.

Above failure shows i2c bulk writes to IMX274 failure due to which
s_stream also failed.

Not sure if its due to i2c mux in the path to sensor on your module
causing some issue when there is more i2c write traffic as we are doing
single stream in continuous loop. Also IMX219 does not show on your side
so something specific to IMX274 setup probably.


Regarding kthread_run failure where kthread_run() returned -EINTR during
capture start thread, I always see this happen at the point of stopping
the continuous single stream while loop by pressing ctrl+c after few
loops of execution.

while true; do v4l2-ctl --stream-mmap --stream-count=1; done

when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
terminate immediately and probably SIGKILLed  is seen prior to complete.

Using below can help to terminate loop as well when we stop ctrl-c and
with this I don't see any repro of EINTR error from kthread_run when run
in infinite loop.

while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break; done



>>
>> Delta between patch versions:
>>
>> [v3]: Includes v2 feedback
>> - Uses separate helper function for retrieving remote csi subdevice
>> and source subdevice.
>> - Added check for presence of subdevice ops set/get_selection
>> - dropped vb2_queue_release from driver and using
>> vb2_video_unregister_device instead of video_unregister_device.
>> - video device register should happen in the last after all video
>> device related setup is done in the driver. This is being addressed
>> in below RFC patch. Once proper implementation of this is available
>> will update Tegra video driver to use split APIs and do all setup
>> prior to device register. Added this as TODO in the driver.
>> https://www.spinics.net/lists/linux-media/msg172761.html
>>
>> Note:
>> Patch-0012 has compilation dependency on
>> https://patchwork.kernel.org/patch/11659521/
>>
>>
>> [v2]: Includes below changes based on v1 feedback
>> - dt-binding document and the driver update for device graph to use
>> separate ports for sink endpoint and source endpoint for csi.
>> - Use data-lanes endpoint property for csi.
>> - Update tegra_mipi_request() to take device node pointer argument
>> rather than adding extra API.
>> - Remove checking for clk pointer before clk_disable.
>>
>>
>> Sowjanya Komatineni (18):
>> dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>> power-domains
>> arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C
>> i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>> i2c: tegra: Remove NULL pointer check before
>> clk_enable/disable/prepare/unprepare
>> i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>> i2c: tegra: Fix runtime resume to re-init VI I2C
>> i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>> media: tegra-video: Fix channel format alignment
>> media: tegra-video: Enable TPG based on kernel config
>> media: tegra-video: Update format lookup to offset based
>> dt-bindings: tegra: Update VI and CSI bindings with port info
>> media: tegra-video: Add support for external sensor capture
>> media: tegra-video: Add support for selection ioctl ops
>> gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>> gpu: host1x: mipi: Use readl_relaxed_poll_timeout in tegra_mipi_wait
>> gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
>> media: tegra-video: Add CSI MIPI pads calibration
>> media: tegra-video: Compute settle times based on the clock rate
>>
>> .../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
>> .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>> arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
>> drivers/gpu/drm/tegra/dsi.c | 9 +-
>> drivers/gpu/host1x/mipi.c | 37 +-
>> drivers/i2c/busses/i2c-tegra.c | 101 +--
>> drivers/staging/media/tegra-video/Kconfig | 7 +
>> drivers/staging/media/tegra-video/csi.c | 247 ++++++-
>> drivers/staging/media/tegra-video/csi.h | 8 +
>> drivers/staging/media/tegra-video/tegra210.c | 25 +-
>> drivers/staging/media/tegra-video/vi.c | 793 +++++++++++++++++++--
>> drivers/staging/media/tegra-video/vi.h | 25 +-
>> drivers/staging/media/tegra-video/video.c | 23 +-
>> include/linux/host1x.h | 4 +-
>> 14 files changed, 1242 insertions(+), 154 deletions(-)
>>

2020-07-17 17:09:23

by Hans Verkuil

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor

On 17/07/2020 18:34, Sowjanya Komatineni wrote:
>
> On 7/17/20 3:54 AM, Hans Verkuil wrote:
>> Hi Sowjanya,
>>
>> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>>> This series adds support for video capture from external camera sensor to
>>> Tegra video driver.
>>>
>>> Jetson TX1 has camera expansion connector and supports custom camera module
>>> designed as per TX1 design specification.
>>>
>>> This series also enables camera capture support for Jetson Nano which has
>>> Raspberry PI camera header.
>>>
>>> This series is tested with IMX219 camera sensor.
>>>
>>> This series include,
>>>
>>> VI I2C related fixes
>>> - Camera sensor programming happens through VI I2C which is on host1x bus.
>>> - These patches includes device tree and I2C driver fixes for VI I2C.
>>>
>>> Tegra video driver updates
>>> - TPG Vs Non-TPG based on Kconfig
>>> - Support for external sensor video capture based on device graph from DT.
>>> - Support for selection ioctl operations
>>> - Tegra MIPI CSI pads calibration
>>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>>
>>> Host1x driver updates
>>> - Adds API to allow creating mipi device for specific device node.
>>> - Splits MIPI pads calibrate start and waiting for calibration to be done.
>>>
>>> Device tree updates
>>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson TX1 DT.
>>> - Enabled VI and CSI support in Jetson Nano DT.
>> I'm doing a bit of stress testing with:
>>
>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>
>> and I see that the imx274 has often streaming failures:
>>
>> [ 172.025144] IMX274 8-001a: s_stream failed
>> [ 179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3132 = 870 (2 bytes)
>> [ 179.033575] IMX274 8-001a: s_stream failed
>> [ 226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3130 = 878 (2 bytes)
>> [ 226.533761] IMX274 8-001a: s_stream failed
>> [ 227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>> [ 227.037758] IMX274 8-001a: s_stream failed
>> [ 247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>> [ 247.033658] IMX274 8-001a: s_stream failed
>> [ 293.025517] IMX274 8-001a: s_stream failed
>> [ 309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30e0 = 0 (2 bytes)
>> [ 309.032969] IMX274 8-001a: s_stream failed
>> [ 309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f8 = 11d2 (3 bytes)
>> [ 309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
>> [ 309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
>> [ 309.550243] IMX274 8-001a: s_stream failed
>> [ 314.025561] IMX274 8-001a: s_stream failed
>> [ 329.025586] IMX274 8-001a: s_stream failed
>> [ 340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 303a = f0c (2 bytes)
>> [ 340.538009] IMX274 8-001a: s_stream failed
>> [ 347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>> [ 347.534008] IMX274 8-001a: s_stream failed
>> [ 365.033640] IMX274 8-001a: s_stream failed
>> [ 437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3038 = c (2 bytes)
>> [ 437.533997] IMX274 8-001a: s_stream failed
>> [ 456.029780] IMX274 8-001a: s_stream failed
>> [ 472.025862] IMX274 8-001a: s_stream failed
>> [ 498.025861] IMX274 8-001a: s_stream failed
>> [ 500.025905] IMX274 8-001a: s_stream failed
>>
>> where v4l2-ctl returns:
>>
>> VIDIOC_STREAMON returned -1 (Remote I/O error)
>>
>> I don't see this with the imx219.
>>
>> I also see this occasionally:
>>
>> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run capture start kthread: -4
>>
>> Something is not stable here.
>>
>> Regards,
>>
>> Hans
>
> Hi Hans,
>
> Running the same single frame continuous loop for more than 2 hours now
> and I don't see any failure.
>
> Above failure shows i2c bulk writes to IMX274 failure due to which
> s_stream also failed.
>
> Not sure if its due to i2c mux in the path to sensor on your module
> causing some issue when there is more i2c write traffic as we are doing
> single stream in continuous loop. Also IMX219 does not show on your side
> so something specific to IMX274 setup probably.

I'll take a closer look next week. Good to know that it works fine for you.

>
>
> Regarding kthread_run failure where kthread_run() returned -EINTR during
> capture start thread, I always see this happen at the point of stopping
> the continuous single stream while loop by pressing ctrl+c after few
> loops of execution.

Hmm, if this is normal behavior, then should this message be a debug message
only? Or perhaps only show the message if the error code != EINTR.

Regards,

Hans

>
> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>
> when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
> terminate immediately and probably SIGKILLed  is seen prior to complete.
>
> Using below can help to terminate loop as well when we stop ctrl-c and
> with this I don't see any repro of EINTR error from kthread_run when run
> in infinite loop.
>
> while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break; done
>
>
>
>>>
>>> Delta between patch versions:
>>>
>>> [v3]: Includes v2 feedback
>>> - Uses separate helper function for retrieving remote csi subdevice
>>> and source subdevice.
>>> - Added check for presence of subdevice ops set/get_selection
>>> - dropped vb2_queue_release from driver and using
>>> vb2_video_unregister_device instead of video_unregister_device.
>>> - video device register should happen in the last after all video
>>> device related setup is done in the driver. This is being addressed
>>> in below RFC patch. Once proper implementation of this is available
>>> will update Tegra video driver to use split APIs and do all setup
>>> prior to device register. Added this as TODO in the driver.
>>> https://www.spinics.net/lists/linux-media/msg172761.html
>>>
>>> Note:
>>> Patch-0012 has compilation dependency on
>>> https://patchwork.kernel.org/patch/11659521/
>>>
>>>
>>> [v2]: Includes below changes based on v1 feedback
>>> - dt-binding document and the driver update for device graph to use
>>> separate ports for sink endpoint and source endpoint for csi.
>>> - Use data-lanes endpoint property for csi.
>>> - Update tegra_mipi_request() to take device node pointer argument
>>> rather than adding extra API.
>>> - Remove checking for clk pointer before clk_disable.
>>>
>>>
>>> Sowjanya Komatineni (18):
>>> dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>>> power-domains
>>> arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C
>>> i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>>> i2c: tegra: Remove NULL pointer check before
>>> clk_enable/disable/prepare/unprepare
>>> i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>>> i2c: tegra: Fix runtime resume to re-init VI I2C
>>> i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>>> media: tegra-video: Fix channel format alignment
>>> media: tegra-video: Enable TPG based on kernel config
>>> media: tegra-video: Update format lookup to offset based
>>> dt-bindings: tegra: Update VI and CSI bindings with port info
>>> media: tegra-video: Add support for external sensor capture
>>> media: tegra-video: Add support for selection ioctl ops
>>> gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>>> gpu: host1x: mipi: Use readl_relaxed_poll_timeout in tegra_mipi_wait
>>> gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
>>> media: tegra-video: Add CSI MIPI pads calibration
>>> media: tegra-video: Compute settle times based on the clock rate
>>>
>>> .../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
>>> .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>>> arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
>>> drivers/gpu/drm/tegra/dsi.c | 9 +-
>>> drivers/gpu/host1x/mipi.c | 37 +-
>>> drivers/i2c/busses/i2c-tegra.c | 101 +--
>>> drivers/staging/media/tegra-video/Kconfig | 7 +
>>> drivers/staging/media/tegra-video/csi.c | 247 ++++++-
>>> drivers/staging/media/tegra-video/csi.h | 8 +
>>> drivers/staging/media/tegra-video/tegra210.c | 25 +-
>>> drivers/staging/media/tegra-video/vi.c | 793 +++++++++++++++++++--
>>> drivers/staging/media/tegra-video/vi.h | 25 +-
>>> drivers/staging/media/tegra-video/video.c | 23 +-
>>> include/linux/host1x.h | 4 +-
>>> 14 files changed, 1242 insertions(+), 154 deletions(-)
>>>

2020-07-17 17:20:33

by Sowjanya Komatineni

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor


On 7/17/20 10:08 AM, Hans Verkuil wrote:
> On 17/07/2020 18:34, Sowjanya Komatineni wrote:
>> On 7/17/20 3:54 AM, Hans Verkuil wrote:
>>> Hi Sowjanya,
>>>
>>> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>>>> This series adds support for video capture from external camera sensor to
>>>> Tegra video driver.
>>>>
>>>> Jetson TX1 has camera expansion connector and supports custom camera module
>>>> designed as per TX1 design specification.
>>>>
>>>> This series also enables camera capture support for Jetson Nano which has
>>>> Raspberry PI camera header.
>>>>
>>>> This series is tested with IMX219 camera sensor.
>>>>
>>>> This series include,
>>>>
>>>> VI I2C related fixes
>>>> - Camera sensor programming happens through VI I2C which is on host1x bus.
>>>> - These patches includes device tree and I2C driver fixes for VI I2C.
>>>>
>>>> Tegra video driver updates
>>>> - TPG Vs Non-TPG based on Kconfig
>>>> - Support for external sensor video capture based on device graph from DT.
>>>> - Support for selection ioctl operations
>>>> - Tegra MIPI CSI pads calibration
>>>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>>>
>>>> Host1x driver updates
>>>> - Adds API to allow creating mipi device for specific device node.
>>>> - Splits MIPI pads calibrate start and waiting for calibration to be done.
>>>>
>>>> Device tree updates
>>>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson TX1 DT.
>>>> - Enabled VI and CSI support in Jetson Nano DT.
>>> I'm doing a bit of stress testing with:
>>>
>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>
>>> and I see that the imx274 has often streaming failures:
>>>
>>> [ 172.025144] IMX274 8-001a: s_stream failed
>>> [ 179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3132 = 870 (2 bytes)
>>> [ 179.033575] IMX274 8-001a: s_stream failed
>>> [ 226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3130 = 878 (2 bytes)
>>> [ 226.533761] IMX274 8-001a: s_stream failed
>>> [ 227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>>> [ 227.037758] IMX274 8-001a: s_stream failed
>>> [ 247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>>> [ 247.033658] IMX274 8-001a: s_stream failed
>>> [ 293.025517] IMX274 8-001a: s_stream failed
>>> [ 309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30e0 = 0 (2 bytes)
>>> [ 309.032969] IMX274 8-001a: s_stream failed
>>> [ 309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f8 = 11d2 (3 bytes)
>>> [ 309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
>>> [ 309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
>>> [ 309.550243] IMX274 8-001a: s_stream failed
>>> [ 314.025561] IMX274 8-001a: s_stream failed
>>> [ 329.025586] IMX274 8-001a: s_stream failed
>>> [ 340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 303a = f0c (2 bytes)
>>> [ 340.538009] IMX274 8-001a: s_stream failed
>>> [ 347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 30f6 = 107 (2 bytes)
>>> [ 347.534008] IMX274 8-001a: s_stream failed
>>> [ 365.033640] IMX274 8-001a: s_stream failed
>>> [ 437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write failed, 3038 = c (2 bytes)
>>> [ 437.533997] IMX274 8-001a: s_stream failed
>>> [ 456.029780] IMX274 8-001a: s_stream failed
>>> [ 472.025862] IMX274 8-001a: s_stream failed
>>> [ 498.025861] IMX274 8-001a: s_stream failed
>>> [ 500.025905] IMX274 8-001a: s_stream failed
>>>
>>> where v4l2-ctl returns:
>>>
>>> VIDIOC_STREAMON returned -1 (Remote I/O error)
>>>
>>> I don't see this with the imx219.
>>>
>>> I also see this occasionally:
>>>
>>> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run capture start kthread: -4
>>>
>>> Something is not stable here.
>>>
>>> Regards,
>>>
>>> Hans
>> Hi Hans,
>>
>> Running the same single frame continuous loop for more than 2 hours now
>> and I don't see any failure.
>>
>> Above failure shows i2c bulk writes to IMX274 failure due to which
>> s_stream also failed.
>>
>> Not sure if its due to i2c mux in the path to sensor on your module
>> causing some issue when there is more i2c write traffic as we are doing
>> single stream in continuous loop. Also IMX219 does not show on your side
>> so something specific to IMX274 setup probably.
> I'll take a closer look next week. Good to know that it works fine for you.
>
>>
>> Regarding kthread_run failure where kthread_run() returned -EINTR during
>> capture start thread, I always see this happen at the point of stopping
>> the continuous single stream while loop by pressing ctrl+c after few
>> loops of execution.
> Hmm, if this is normal behavior, then should this message be a debug message
> only? Or perhaps only show the message if the error code != EINTR.

I believe its good to still show this as its reported by kthread_run ->
kthread_create_on_node.

But not sure in real usecase we will ever use while true like this and
we should use script to also break while loop along with v4l2-ctl
termination when ctrl-c terminate request happens.


>
> Regards,
>
> Hans
>
>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>
>> when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
>> terminate immediately and probably SIGKILLed  is seen prior to complete.
>>
>> Using below can help to terminate loop as well when we stop ctrl-c and
>> with this I don't see any repro of EINTR error from kthread_run when run
>> in infinite loop.
>>
>> while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break; done
>>
>>
>>
>>>> Delta between patch versions:
>>>>
>>>> [v3]: Includes v2 feedback
>>>> - Uses separate helper function for retrieving remote csi subdevice
>>>> and source subdevice.
>>>> - Added check for presence of subdevice ops set/get_selection
>>>> - dropped vb2_queue_release from driver and using
>>>> vb2_video_unregister_device instead of video_unregister_device.
>>>> - video device register should happen in the last after all video
>>>> device related setup is done in the driver. This is being addressed
>>>> in below RFC patch. Once proper implementation of this is available
>>>> will update Tegra video driver to use split APIs and do all setup
>>>> prior to device register. Added this as TODO in the driver.
>>>> https://www.spinics.net/lists/linux-media/msg172761.html
>>>>
>>>> Note:
>>>> Patch-0012 has compilation dependency on
>>>> https://patchwork.kernel.org/patch/11659521/
>>>>
>>>>
>>>> [v2]: Includes below changes based on v1 feedback
>>>> - dt-binding document and the driver update for device graph to use
>>>> separate ports for sink endpoint and source endpoint for csi.
>>>> - Use data-lanes endpoint property for csi.
>>>> - Update tegra_mipi_request() to take device node pointer argument
>>>> rather than adding extra API.
>>>> - Remove checking for clk pointer before clk_disable.
>>>>
>>>>
>>>> Sowjanya Komatineni (18):
>>>> dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>>>> power-domains
>>>> arm64: tegra: Add missing clocks and power-domains to Tegra210 VI I2C
>>>> i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>>>> i2c: tegra: Remove NULL pointer check before
>>>> clk_enable/disable/prepare/unprepare
>>>> i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>>>> i2c: tegra: Fix runtime resume to re-init VI I2C
>>>> i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>>>> media: tegra-video: Fix channel format alignment
>>>> media: tegra-video: Enable TPG based on kernel config
>>>> media: tegra-video: Update format lookup to offset based
>>>> dt-bindings: tegra: Update VI and CSI bindings with port info
>>>> media: tegra-video: Add support for external sensor capture
>>>> media: tegra-video: Add support for selection ioctl ops
>>>> gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>>>> gpu: host1x: mipi: Use readl_relaxed_poll_timeout in tegra_mipi_wait
>>>> gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
>>>> media: tegra-video: Add CSI MIPI pads calibration
>>>> media: tegra-video: Compute settle times based on the clock rate
>>>>
>>>> .../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
>>>> .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>>>> arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
>>>> drivers/gpu/drm/tegra/dsi.c | 9 +-
>>>> drivers/gpu/host1x/mipi.c | 37 +-
>>>> drivers/i2c/busses/i2c-tegra.c | 101 +--
>>>> drivers/staging/media/tegra-video/Kconfig | 7 +
>>>> drivers/staging/media/tegra-video/csi.c | 247 ++++++-
>>>> drivers/staging/media/tegra-video/csi.h | 8 +
>>>> drivers/staging/media/tegra-video/tegra210.c | 25 +-
>>>> drivers/staging/media/tegra-video/vi.c | 793 +++++++++++++++++++--
>>>> drivers/staging/media/tegra-video/vi.h | 25 +-
>>>> drivers/staging/media/tegra-video/video.c | 23 +-
>>>> include/linux/host1x.h | 4 +-
>>>> 14 files changed, 1242 insertions(+), 154 deletions(-)
>>>>

2020-07-17 17:38:22

by Sowjanya Komatineni

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor


On 7/17/20 10:23 AM, Sowjanya Komatineni wrote:
>
> On 7/17/20 10:08 AM, Hans Verkuil wrote:
>> On 17/07/2020 18:34, Sowjanya Komatineni wrote:
>>> On 7/17/20 3:54 AM, Hans Verkuil wrote:
>>>> Hi Sowjanya,
>>>>
>>>> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>>>>> This series adds support for video capture from external camera
>>>>> sensor to
>>>>> Tegra video driver.
>>>>>
>>>>> Jetson TX1 has camera expansion connector and supports custom
>>>>> camera module
>>>>> designed as per TX1 design specification.
>>>>>
>>>>> This series also enables camera capture support for Jetson Nano
>>>>> which has
>>>>> Raspberry PI camera header.
>>>>>
>>>>> This series is tested with IMX219 camera sensor.
>>>>>
>>>>> This series include,
>>>>>
>>>>> VI I2C related fixes
>>>>> - Camera sensor programming happens through VI I2C which is on
>>>>> host1x bus.
>>>>> - These patches includes device tree and I2C driver fixes for VI I2C.
>>>>>
>>>>> Tegra video driver updates
>>>>> - TPG Vs Non-TPG based on Kconfig
>>>>> - Support for external sensor video capture based on device graph
>>>>> from DT.
>>>>> - Support for selection ioctl operations
>>>>> - Tegra MIPI CSI pads calibration
>>>>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>>>>
>>>>> Host1x driver updates
>>>>> - Adds API to allow creating mipi device for specific device node.
>>>>> - Splits MIPI pads calibrate start and waiting for calibration to
>>>>> be done.
>>>>>
>>>>> Device tree updates
>>>>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to Jetson
>>>>> TX1 DT.
>>>>> - Enabled VI and CSI support in Jetson Nano DT.
>>>> I'm doing a bit of stress testing with:
>>>>
>>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>>
>>>> and I see that the imx274 has often streaming failures:
>>>>
>>>> [  172.025144] IMX274 8-001a: s_stream failed
>>>> [  179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 3132 = 870 (2 bytes)
>>>> [  179.033575] IMX274 8-001a: s_stream failed
>>>> [  226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 3130 = 878 (2 bytes)
>>>> [  226.533761] IMX274 8-001a: s_stream failed
>>>> [  227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 30f6 = 107 (2 bytes)
>>>> [  227.037758] IMX274 8-001a: s_stream failed
>>>> [  247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 30f6 = 107 (2 bytes)
>>>> [  247.033658] IMX274 8-001a: s_stream failed
>>>> [  293.025517] IMX274 8-001a: s_stream failed
>>>> [  309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 30e0 = 0 (2 bytes)
>>>> [  309.032969] IMX274 8-001a: s_stream failed
>>>> [  309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 30f8 = 11d2 (3 bytes)
>>>> [  309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
>>>> [  309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
>>>> [  309.550243] IMX274 8-001a: s_stream failed
>>>> [  314.025561] IMX274 8-001a: s_stream failed
>>>> [  329.025586] IMX274 8-001a: s_stream failed
>>>> [  340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 303a = f0c (2 bytes)
>>>> [  340.538009] IMX274 8-001a: s_stream failed
>>>> [  347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 30f6 = 107 (2 bytes)
>>>> [  347.534008] IMX274 8-001a: s_stream failed
>>>> [  365.033640] IMX274 8-001a: s_stream failed
>>>> [  437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>> failed, 3038 = c (2 bytes)
>>>> [  437.533997] IMX274 8-001a: s_stream failed
>>>> [  456.029780] IMX274 8-001a: s_stream failed
>>>> [  472.025862] IMX274 8-001a: s_stream failed
>>>> [  498.025861] IMX274 8-001a: s_stream failed
>>>> [  500.025905] IMX274 8-001a: s_stream failed
>>>>
>>>> where v4l2-ctl returns:
>>>>
>>>>                   VIDIOC_STREAMON returned -1 (Remote I/O error)
>>>>
>>>> I don't see this with the imx219.
>>>>
>>>> I also see this occasionally:
>>>>
>>>> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run
>>>> capture start kthread: -4
>>>>
>>>> Something is not stable here.
>>>>
>>>> Regards,
>>>>
>>>>     Hans
>>> Hi Hans,
>>>
>>> Running the same single frame continuous loop for more than 2 hours now
>>> and I don't see any failure.
>>>
>>> Above failure shows i2c bulk writes to IMX274 failure due to which
>>> s_stream also failed.
>>>
>>> Not sure if its due to i2c mux in the path to sensor on your module
>>> causing some issue when there is more i2c write traffic as we are doing
>>> single stream in continuous loop. Also IMX219 does not show on your
>>> side
>>> so something specific to IMX274 setup probably.
>> I'll take a closer look next week. Good to know that it works fine
>> for you.
>>
>>>
>>> Regarding kthread_run failure where kthread_run() returned -EINTR
>>> during
>>> capture start thread, I always see this happen at the point of stopping
>>> the continuous single stream while loop by pressing ctrl+c after few
>>> loops of execution.
>> Hmm, if this is normal behavior, then should this message be a debug
>> message
>> only? Or perhaps only show the message if the error code != EINTR.
>
> I believe its good to still show this as its reported by kthread_run
> -> kthread_create_on_node.
>
> But not sure in real usecase we will ever use while true like this and
> we should use script to also break while loop along with v4l2-ctl
> termination when ctrl-c terminate request happens.
>
Hi Hans, As this happens only during this type of case, I can update to
show message only when error code != EINTR.

Thanks

Sowjanya

>
>>
>> Regards,
>>
>>     Hans
>>
>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>
>>> when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
>>> terminate immediately and probably SIGKILLed  is seen prior to
>>> complete.
>>>
>>> Using below can help to terminate loop as well when we stop ctrl-c and
>>> with this I don't see any repro of EINTR error from kthread_run when
>>> run
>>> in infinite loop.
>>>
>>> while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break; done
>>>
>>>
>>>
>>>>> Delta between patch versions:
>>>>>
>>>>> [v3]:    Includes v2 feedback
>>>>>     - Uses separate helper function for retrieving remote csi
>>>>> subdevice
>>>>>       and source subdevice.
>>>>>     - Added check for presence of subdevice ops set/get_selection
>>>>>     - dropped vb2_queue_release from driver and using
>>>>>       vb2_video_unregister_device instead of video_unregister_device.
>>>>>     - video device register should happen in the last after all video
>>>>>       device related setup is done in the driver. This is being
>>>>> addressed
>>>>>       in below RFC patch. Once proper implementation of this is
>>>>> available
>>>>>       will update Tegra video driver to use split APIs and do all
>>>>> setup
>>>>>       prior to device register. Added this as TODO in the driver.
>>>>> https://www.spinics.net/lists/linux-media/msg172761.html
>>>>>
>>>>>     Note:
>>>>>     Patch-0012 has compilation dependency on
>>>>>     https://patchwork.kernel.org/patch/11659521/
>>>>>
>>>>>
>>>>> [v2]:    Includes below changes based on v1 feedback
>>>>>     - dt-binding document and the driver update for device graph
>>>>> to use
>>>>>       separate ports for sink endpoint and source endpoint for csi.
>>>>>     - Use data-lanes endpoint property for csi.
>>>>>     - Update tegra_mipi_request() to take device node pointer
>>>>> argument
>>>>>       rather than adding extra API.
>>>>>     - Remove checking for clk pointer before clk_disable.
>>>>>
>>>>>
>>>>> Sowjanya Komatineni (18):
>>>>>     dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>>>>>       power-domains
>>>>>     arm64: tegra: Add missing clocks and power-domains to Tegra210
>>>>> VI I2C
>>>>>     i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>>>>>     i2c: tegra: Remove NULL pointer check before
>>>>>       clk_enable/disable/prepare/unprepare
>>>>>     i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>>>>>     i2c: tegra: Fix runtime resume to re-init VI I2C
>>>>>     i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>>>>>     media: tegra-video: Fix channel format alignment
>>>>>     media: tegra-video: Enable TPG based on kernel config
>>>>>     media: tegra-video: Update format lookup to offset based
>>>>>     dt-bindings: tegra: Update VI and CSI bindings with port info
>>>>>     media: tegra-video: Add support for external sensor capture
>>>>>     media: tegra-video: Add support for selection ioctl ops
>>>>>     gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>>>>>     gpu: host1x: mipi: Use readl_relaxed_poll_timeout in
>>>>> tegra_mipi_wait
>>>>>     gpu: host1x: mipi: Split tegra_mipi_calibrate and tegra_mipi_wait
>>>>>     media: tegra-video: Add CSI MIPI pads calibration
>>>>>     media: tegra-video: Compute settle times based on the clock rate
>>>>>
>>>>>    .../display/tegra/nvidia,tegra20-host1x.txt        | 92 ++-
>>>>>    .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>>>>>    arch/arm64/boot/dts/nvidia/tegra210.dtsi           | 6 +
>>>>>    drivers/gpu/drm/tegra/dsi.c                        | 9 +-
>>>>>    drivers/gpu/host1x/mipi.c                          | 37 +-
>>>>>    drivers/i2c/busses/i2c-tegra.c                     | 101 +--
>>>>>    drivers/staging/media/tegra-video/Kconfig          | 7 +
>>>>>    drivers/staging/media/tegra-video/csi.c            | 247 ++++++-
>>>>>    drivers/staging/media/tegra-video/csi.h            | 8 +
>>>>>    drivers/staging/media/tegra-video/tegra210.c       | 25 +-
>>>>>    drivers/staging/media/tegra-video/vi.c             | 793
>>>>> +++++++++++++++++++--
>>>>>    drivers/staging/media/tegra-video/vi.h             | 25 +-
>>>>>    drivers/staging/media/tegra-video/video.c          | 23 +-
>>>>>    include/linux/host1x.h                             | 4 +-
>>>>>    14 files changed, 1242 insertions(+), 154 deletions(-)
>>>>>

2020-07-17 17:48:20

by Sowjanya Komatineni

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor


On 7/17/20 10:38 AM, Sowjanya Komatineni wrote:
>
> On 7/17/20 10:23 AM, Sowjanya Komatineni wrote:
>>
>> On 7/17/20 10:08 AM, Hans Verkuil wrote:
>>> On 17/07/2020 18:34, Sowjanya Komatineni wrote:
>>>> On 7/17/20 3:54 AM, Hans Verkuil wrote:
>>>>> Hi Sowjanya,
>>>>>
>>>>> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>>>>>> This series adds support for video capture from external camera
>>>>>> sensor to
>>>>>> Tegra video driver.
>>>>>>
>>>>>> Jetson TX1 has camera expansion connector and supports custom
>>>>>> camera module
>>>>>> designed as per TX1 design specification.
>>>>>>
>>>>>> This series also enables camera capture support for Jetson Nano
>>>>>> which has
>>>>>> Raspberry PI camera header.
>>>>>>
>>>>>> This series is tested with IMX219 camera sensor.
>>>>>>
>>>>>> This series include,
>>>>>>
>>>>>> VI I2C related fixes
>>>>>> - Camera sensor programming happens through VI I2C which is on
>>>>>> host1x bus.
>>>>>> - These patches includes device tree and I2C driver fixes for VI
>>>>>> I2C.
>>>>>>
>>>>>> Tegra video driver updates
>>>>>> - TPG Vs Non-TPG based on Kconfig
>>>>>> - Support for external sensor video capture based on device graph
>>>>>> from DT.
>>>>>> - Support for selection ioctl operations
>>>>>> - Tegra MIPI CSI pads calibration
>>>>>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>>>>>
>>>>>> Host1x driver updates
>>>>>> - Adds API to allow creating mipi device for specific device node.
>>>>>> - Splits MIPI pads calibrate start and waiting for calibration to
>>>>>> be done.
>>>>>>
>>>>>> Device tree updates
>>>>>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to
>>>>>> Jetson TX1 DT.
>>>>>> - Enabled VI and CSI support in Jetson Nano DT.
>>>>> I'm doing a bit of stress testing with:
>>>>>
>>>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>>>
>>>>> and I see that the imx274 has often streaming failures:
>>>>>
>>>>> [  172.025144] IMX274 8-001a: s_stream failed
>>>>> [  179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 3132 = 870 (2 bytes)
>>>>> [  179.033575] IMX274 8-001a: s_stream failed
>>>>> [  226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 3130 = 878 (2 bytes)
>>>>> [  226.533761] IMX274 8-001a: s_stream failed
>>>>> [  227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 30f6 = 107 (2 bytes)
>>>>> [  227.037758] IMX274 8-001a: s_stream failed
>>>>> [  247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 30f6 = 107 (2 bytes)
>>>>> [  247.033658] IMX274 8-001a: s_stream failed
>>>>> [  293.025517] IMX274 8-001a: s_stream failed
>>>>> [  309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 30e0 = 0 (2 bytes)
>>>>> [  309.032969] IMX274 8-001a: s_stream failed
>>>>> [  309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 30f8 = 11d2 (3 bytes)
>>>>> [  309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
>>>>> [  309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
>>>>> [  309.550243] IMX274 8-001a: s_stream failed
>>>>> [  314.025561] IMX274 8-001a: s_stream failed
>>>>> [  329.025586] IMX274 8-001a: s_stream failed
>>>>> [  340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 303a = f0c (2 bytes)
>>>>> [  340.538009] IMX274 8-001a: s_stream failed
>>>>> [  347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 30f6 = 107 (2 bytes)
>>>>> [  347.534008] IMX274 8-001a: s_stream failed
>>>>> [  365.033640] IMX274 8-001a: s_stream failed
>>>>> [  437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>> failed, 3038 = c (2 bytes)
>>>>> [  437.533997] IMX274 8-001a: s_stream failed
>>>>> [  456.029780] IMX274 8-001a: s_stream failed
>>>>> [  472.025862] IMX274 8-001a: s_stream failed
>>>>> [  498.025861] IMX274 8-001a: s_stream failed
>>>>> [  500.025905] IMX274 8-001a: s_stream failed
>>>>>
>>>>> where v4l2-ctl returns:
>>>>>
>>>>>                   VIDIOC_STREAMON returned -1 (Remote I/O error)
>>>>>
>>>>> I don't see this with the imx219.
>>>>>
>>>>> I also see this occasionally:
>>>>>
>>>>> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run
>>>>> capture start kthread: -4
>>>>>
>>>>> Something is not stable here.
>>>>>
>>>>> Regards,
>>>>>
>>>>>     Hans
>>>> Hi Hans,
>>>>
>>>> Running the same single frame continuous loop for more than 2 hours
>>>> now
>>>> and I don't see any failure.
>>>>
>>>> Above failure shows i2c bulk writes to IMX274 failure due to which
>>>> s_stream also failed.
>>>>
>>>> Not sure if its due to i2c mux in the path to sensor on your module
>>>> causing some issue when there is more i2c write traffic as we are
>>>> doing
>>>> single stream in continuous loop. Also IMX219 does not show on your
>>>> side
>>>> so something specific to IMX274 setup probably.
>>> I'll take a closer look next week. Good to know that it works fine
>>> for you.
>>>
>>>>
>>>> Regarding kthread_run failure where kthread_run() returned -EINTR
>>>> during
>>>> capture start thread, I always see this happen at the point of
>>>> stopping
>>>> the continuous single stream while loop by pressing ctrl+c after few
>>>> loops of execution.
>>> Hmm, if this is normal behavior, then should this message be a debug
>>> message
>>> only? Or perhaps only show the message if the error code != EINTR.
>>
>> I believe its good to still show this as its reported by kthread_run
>> -> kthread_create_on_node.
>>
>> But not sure in real usecase we will ever use while true like this
>> and we should use script to also break while loop along with v4l2-ctl
>> termination when ctrl-c terminate request happens.
>>
> Hi Hans, As this happens only during this type of case, I can update
> to show message only when error code != EINTR.
>
> Thanks
>
> Sowjanya


Sorry, Was thinking to not mask debug message for -EINTR in case if it
happens in any other valid scenarios. If you still want to mask, will
update in next version.

>
>>
>>>
>>> Regards,
>>>
>>>     Hans
>>>
>>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>>
>>>> when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
>>>> terminate immediately and probably SIGKILLed  is seen prior to
>>>> complete.
>>>>
>>>> Using below can help to terminate loop as well when we stop ctrl-c and
>>>> with this I don't see any repro of EINTR error from kthread_run
>>>> when run
>>>> in infinite loop.
>>>>
>>>> while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break;
>>>> done
>>>>
>>>>
>>>>
>>>>>> Delta between patch versions:
>>>>>>
>>>>>> [v3]:    Includes v2 feedback
>>>>>>     - Uses separate helper function for retrieving remote csi
>>>>>> subdevice
>>>>>>       and source subdevice.
>>>>>>     - Added check for presence of subdevice ops set/get_selection
>>>>>>     - dropped vb2_queue_release from driver and using
>>>>>>       vb2_video_unregister_device instead of
>>>>>> video_unregister_device.
>>>>>>     - video device register should happen in the last after all
>>>>>> video
>>>>>>       device related setup is done in the driver. This is being
>>>>>> addressed
>>>>>>       in below RFC patch. Once proper implementation of this is
>>>>>> available
>>>>>>       will update Tegra video driver to use split APIs and do all
>>>>>> setup
>>>>>>       prior to device register. Added this as TODO in the driver.
>>>>>> https://www.spinics.net/lists/linux-media/msg172761.html
>>>>>>
>>>>>>     Note:
>>>>>>     Patch-0012 has compilation dependency on
>>>>>>     https://patchwork.kernel.org/patch/11659521/
>>>>>>
>>>>>>
>>>>>> [v2]:    Includes below changes based on v1 feedback
>>>>>>     - dt-binding document and the driver update for device graph
>>>>>> to use
>>>>>>       separate ports for sink endpoint and source endpoint for csi.
>>>>>>     - Use data-lanes endpoint property for csi.
>>>>>>     - Update tegra_mipi_request() to take device node pointer
>>>>>> argument
>>>>>>       rather than adding extra API.
>>>>>>     - Remove checking for clk pointer before clk_disable.
>>>>>>
>>>>>>
>>>>>> Sowjanya Komatineni (18):
>>>>>>     dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>>>>>>       power-domains
>>>>>>     arm64: tegra: Add missing clocks and power-domains to
>>>>>> Tegra210 VI I2C
>>>>>>     i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>>>>>>     i2c: tegra: Remove NULL pointer check before
>>>>>>       clk_enable/disable/prepare/unprepare
>>>>>>     i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>>>>>>     i2c: tegra: Fix runtime resume to re-init VI I2C
>>>>>>     i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>>>>>>     media: tegra-video: Fix channel format alignment
>>>>>>     media: tegra-video: Enable TPG based on kernel config
>>>>>>     media: tegra-video: Update format lookup to offset based
>>>>>>     dt-bindings: tegra: Update VI and CSI bindings with port info
>>>>>>     media: tegra-video: Add support for external sensor capture
>>>>>>     media: tegra-video: Add support for selection ioctl ops
>>>>>>     gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>>>>>>     gpu: host1x: mipi: Use readl_relaxed_poll_timeout in
>>>>>> tegra_mipi_wait
>>>>>>     gpu: host1x: mipi: Split tegra_mipi_calibrate and
>>>>>> tegra_mipi_wait
>>>>>>     media: tegra-video: Add CSI MIPI pads calibration
>>>>>>     media: tegra-video: Compute settle times based on the clock rate
>>>>>>
>>>>>>    .../display/tegra/nvidia,tegra20-host1x.txt        | 92 ++-
>>>>>>    .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>>>>>>    arch/arm64/boot/dts/nvidia/tegra210.dtsi           | 6 +
>>>>>>    drivers/gpu/drm/tegra/dsi.c                        | 9 +-
>>>>>>    drivers/gpu/host1x/mipi.c                          | 37 +-
>>>>>>    drivers/i2c/busses/i2c-tegra.c                     | 101 +--
>>>>>>    drivers/staging/media/tegra-video/Kconfig          | 7 +
>>>>>>    drivers/staging/media/tegra-video/csi.c            | 247 ++++++-
>>>>>>    drivers/staging/media/tegra-video/csi.h            | 8 +
>>>>>>    drivers/staging/media/tegra-video/tegra210.c       | 25 +-
>>>>>>    drivers/staging/media/tegra-video/vi.c             | 793
>>>>>> +++++++++++++++++++--
>>>>>>    drivers/staging/media/tegra-video/vi.h             | 25 +-
>>>>>>    drivers/staging/media/tegra-video/video.c          | 23 +-
>>>>>>    include/linux/host1x.h                             | 4 +-
>>>>>>    14 files changed, 1242 insertions(+), 154 deletions(-)
>>>>>>

2020-07-20 04:42:27

by Sowjanya Komatineni

[permalink] [raw]
Subject: Re: [RFC PATCH v3 00/18] Support for Tegra video capture from external sensor


On 7/17/20 10:48 AM, Sowjanya Komatineni wrote:
>
> On 7/17/20 10:38 AM, Sowjanya Komatineni wrote:
>>
>> On 7/17/20 10:23 AM, Sowjanya Komatineni wrote:
>>>
>>> On 7/17/20 10:08 AM, Hans Verkuil wrote:
>>>> On 17/07/2020 18:34, Sowjanya Komatineni wrote:
>>>>> On 7/17/20 3:54 AM, Hans Verkuil wrote:
>>>>>> Hi Sowjanya,
>>>>>>
>>>>>> On 15/07/2020 06:20, Sowjanya Komatineni wrote:
>>>>>>> This series adds support for video capture from external camera
>>>>>>> sensor to
>>>>>>> Tegra video driver.
>>>>>>>
>>>>>>> Jetson TX1 has camera expansion connector and supports custom
>>>>>>> camera module
>>>>>>> designed as per TX1 design specification.
>>>>>>>
>>>>>>> This series also enables camera capture support for Jetson Nano
>>>>>>> which has
>>>>>>> Raspberry PI camera header.
>>>>>>>
>>>>>>> This series is tested with IMX219 camera sensor.
>>>>>>>
>>>>>>> This series include,
>>>>>>>
>>>>>>> VI I2C related fixes
>>>>>>> - Camera sensor programming happens through VI I2C which is on
>>>>>>> host1x bus.
>>>>>>> - These patches includes device tree and I2C driver fixes for VI
>>>>>>> I2C.
>>>>>>>
>>>>>>> Tegra video driver updates
>>>>>>> - TPG Vs Non-TPG based on Kconfig
>>>>>>> - Support for external sensor video capture based on device
>>>>>>> graph from DT.
>>>>>>> - Support for selection ioctl operations
>>>>>>> - Tegra MIPI CSI pads calibration
>>>>>>> - CSI T-CLK and T-HS settle time computation based on clock rates.
>>>>>>>
>>>>>>> Host1x driver updates
>>>>>>> - Adds API to allow creating mipi device for specific device node.
>>>>>>> - Splits MIPI pads calibrate start and waiting for calibration
>>>>>>> to be done.
>>>>>>>
>>>>>>> Device tree updates
>>>>>>> - Adds camera connector 2V8, 1V8, 1V2 regulator supplies to
>>>>>>> Jetson TX1 DT.
>>>>>>> - Enabled VI and CSI support in Jetson Nano DT.
>>>>>> I'm doing a bit of stress testing with:
>>>>>>
>>>>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>>>>
>>>>>> and I see that the imx274 has often streaming failures:
>>>>>>
>>>>>> [  172.025144] IMX274 8-001a: s_stream failed
>>>>>> [  179.025192] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 3132 = 870 (2 bytes)
>>>>>> [  179.033575] IMX274 8-001a: s_stream failed
>>>>>> [  226.525378] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 3130 = 878 (2 bytes)
>>>>>> [  226.533761] IMX274 8-001a: s_stream failed
>>>>>> [  227.029325] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 30f6 = 107 (2 bytes)
>>>>>> [  227.037758] IMX274 8-001a: s_stream failed
>>>>>> [  247.025218] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 30f6 = 107 (2 bytes)
>>>>>> [  247.033658] IMX274 8-001a: s_stream failed
>>>>>> [  293.025517] IMX274 8-001a: s_stream failed
>>>>>> [  309.024727] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 30e0 = 0 (2 bytes)
>>>>>> [  309.032969] IMX274 8-001a: s_stream failed
>>>>>> [  309.529506] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 30f8 = 11d2 (3 bytes)
>>>>>> [  309.538103] IMX274 8-001a: imx274_set_frame_length error = -121
>>>>>> [  309.544102] IMX274 8-001a: imx274_set_frame_interval error = -121
>>>>>> [  309.550243] IMX274 8-001a: s_stream failed
>>>>>> [  314.025561] IMX274 8-001a: s_stream failed
>>>>>> [  329.025586] IMX274 8-001a: s_stream failed
>>>>>> [  340.529567] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 303a = f0c (2 bytes)
>>>>>> [  340.538009] IMX274 8-001a: s_stream failed
>>>>>> [  347.525627] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 30f6 = 107 (2 bytes)
>>>>>> [  347.534008] IMX274 8-001a: s_stream failed
>>>>>> [  365.033640] IMX274 8-001a: s_stream failed
>>>>>> [  437.525788] IMX274 8-001a: imx274_write_mbreg : i2c bulk write
>>>>>> failed, 3038 = c (2 bytes)
>>>>>> [  437.533997] IMX274 8-001a: s_stream failed
>>>>>> [  456.029780] IMX274 8-001a: s_stream failed
>>>>>> [  472.025862] IMX274 8-001a: s_stream failed
>>>>>> [  498.025861] IMX274 8-001a: s_stream failed
>>>>>> [  500.025905] IMX274 8-001a: s_stream failed
>>>>>>
>>>>>> where v4l2-ctl returns:
>>>>>>
>>>>>>                   VIDIOC_STREAMON returned -1 (Remote I/O error)
>>>>>>
>>>>>> I don't see this with the imx219.
>>>>>>
>>>>>> I also see this occasionally:
>>>>>>
>>>>>> [Fri Jul 17 12:51:42 2020] video4linux video1: failed to run
>>>>>> capture start kthread: -4
>>>>>>
>>>>>> Something is not stable here.
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>>     Hans
>>>>> Hi Hans,
>>>>>
>>>>> Running the same single frame continuous loop for more than 2
>>>>> hours now
>>>>> and I don't see any failure.
>>>>>
>>>>> Above failure shows i2c bulk writes to IMX274 failure due to which
>>>>> s_stream also failed.
>>>>>
>>>>> Not sure if its due to i2c mux in the path to sensor on your module
>>>>> causing some issue when there is more i2c write traffic as we are
>>>>> doing
>>>>> single stream in continuous loop. Also IMX219 does not show on
>>>>> your side
>>>>> so something specific to IMX274 setup probably.
>>>> I'll take a closer look next week. Good to know that it works fine
>>>> for you.
>>>>
>>>>>
>>>>> Regarding kthread_run failure where kthread_run() returned -EINTR
>>>>> during
>>>>> capture start thread, I always see this happen at the point of
>>>>> stopping
>>>>> the continuous single stream while loop by pressing ctrl+c after few
>>>>> loops of execution.
>>>> Hmm, if this is normal behavior, then should this message be a
>>>> debug message
>>>> only? Or perhaps only show the message if the error code != EINTR.
>>>
>>> I believe its good to still show this as its reported by kthread_run
>>> -> kthread_create_on_node.
>>>
>>> But not sure in real usecase we will ever use while true like this
>>> and we should use script to also break while loop along with
>>> v4l2-ctl termination when ctrl-c terminate request happens.
>>>
>> Hi Hans, As this happens only during this type of case, I can update
>> to show message only when error code != EINTR.
>>
>> Thanks
>>
>> Sowjanya
>
>
> Sorry, Was thinking to not mask debug message for -EINTR in case if it
> happens in any other valid scenarios. If you still want to mask, will
> update in next version.
>
As we are running application that uses threads depending on when ctrl-c
gets hit I see sigkill happens during kthread run even with break
causing this.

Good way I see it working all the time is to use crtl-z and then kill
application as below

Command to run

while true; do ./v4l2-ctl --stream-mmap --stream-count=1; done

To stop ,

press ctrl-z and then execute kill %%


>>
>>>
>>>>
>>>> Regards,
>>>>
>>>>     Hans
>>>>
>>>>> while true; do v4l2-ctl --stream-mmap --stream-count=1; done
>>>>>
>>>>> when we stop loop with ctrl+c, v4l2-ctl terminates but loop does not
>>>>> terminate immediately and probably SIGKILLed  is seen prior to
>>>>> complete.
>>>>>
>>>>> Using below can help to terminate loop as well when we stop ctrl-c
>>>>> and
>>>>> with this I don't see any repro of EINTR error from kthread_run
>>>>> when run
>>>>> in infinite loop.
>>>>>
>>>>> while true; do ./v4l2-ctl --stream-mmap --stream-count=1 || break;
>>>>> done
>>>>>
>>>>>
>>>>>
>>>>>>> Delta between patch versions:
>>>>>>>
>>>>>>> [v3]:    Includes v2 feedback
>>>>>>>     - Uses separate helper function for retrieving remote csi
>>>>>>> subdevice
>>>>>>>       and source subdevice.
>>>>>>>     - Added check for presence of subdevice ops set/get_selection
>>>>>>>     - dropped vb2_queue_release from driver and using
>>>>>>>       vb2_video_unregister_device instead of
>>>>>>> video_unregister_device.
>>>>>>>     - video device register should happen in the last after all
>>>>>>> video
>>>>>>>       device related setup is done in the driver. This is being
>>>>>>> addressed
>>>>>>>       in below RFC patch. Once proper implementation of this is
>>>>>>> available
>>>>>>>       will update Tegra video driver to use split APIs and do
>>>>>>> all setup
>>>>>>>       prior to device register. Added this as TODO in the driver.
>>>>>>> https://www.spinics.net/lists/linux-media/msg172761.html
>>>>>>>
>>>>>>>     Note:
>>>>>>>     Patch-0012 has compilation dependency on
>>>>>>>     https://patchwork.kernel.org/patch/11659521/
>>>>>>>
>>>>>>>
>>>>>>> [v2]:    Includes below changes based on v1 feedback
>>>>>>>     - dt-binding document and the driver update for device graph
>>>>>>> to use
>>>>>>>       separate ports for sink endpoint and source endpoint for csi.
>>>>>>>     - Use data-lanes endpoint property for csi.
>>>>>>>     - Update tegra_mipi_request() to take device node pointer
>>>>>>> argument
>>>>>>>       rather than adding extra API.
>>>>>>>     - Remove checking for clk pointer before clk_disable.
>>>>>>>
>>>>>>>
>>>>>>> Sowjanya Komatineni (18):
>>>>>>>     dt-bindings: i2c: tegra: Document Tegra210 VI I2C clocks and
>>>>>>>       power-domains
>>>>>>>     arm64: tegra: Add missing clocks and power-domains to
>>>>>>> Tegra210 VI I2C
>>>>>>>     i2c: tegra: Don't mark VI I2C as IRQ safe runtime PM
>>>>>>>     i2c: tegra: Remove NULL pointer check before
>>>>>>>       clk_enable/disable/prepare/unprepare
>>>>>>>     i2c: tegra: Fix the error path in tegra_i2c_runtime_resume
>>>>>>>     i2c: tegra: Fix runtime resume to re-init VI I2C
>>>>>>>     i2c: tegra: Avoid tegra_i2c_init_dma() for Tegra210 vi i2c
>>>>>>>     media: tegra-video: Fix channel format alignment
>>>>>>>     media: tegra-video: Enable TPG based on kernel config
>>>>>>>     media: tegra-video: Update format lookup to offset based
>>>>>>>     dt-bindings: tegra: Update VI and CSI bindings with port info
>>>>>>>     media: tegra-video: Add support for external sensor capture
>>>>>>>     media: tegra-video: Add support for selection ioctl ops
>>>>>>>     gpu: host1x: mipi: Update tegra_mipi_request() to be node based
>>>>>>>     gpu: host1x: mipi: Use readl_relaxed_poll_timeout in
>>>>>>> tegra_mipi_wait
>>>>>>>     gpu: host1x: mipi: Split tegra_mipi_calibrate and
>>>>>>> tegra_mipi_wait
>>>>>>>     media: tegra-video: Add CSI MIPI pads calibration
>>>>>>>     media: tegra-video: Compute settle times based on the clock
>>>>>>> rate
>>>>>>>
>>>>>>>    .../display/tegra/nvidia,tegra20-host1x.txt | 92 ++-
>>>>>>>    .../devicetree/bindings/i2c/nvidia,tegra20-i2c.txt | 19 +-
>>>>>>>    arch/arm64/boot/dts/nvidia/tegra210.dtsi | 6 +
>>>>>>>    drivers/gpu/drm/tegra/dsi.c | 9 +-
>>>>>>>    drivers/gpu/host1x/mipi.c | 37 +-
>>>>>>>    drivers/i2c/busses/i2c-tegra.c | 101 +--
>>>>>>>    drivers/staging/media/tegra-video/Kconfig | 7 +
>>>>>>>    drivers/staging/media/tegra-video/csi.c | 247 ++++++-
>>>>>>>    drivers/staging/media/tegra-video/csi.h | 8 +
>>>>>>>    drivers/staging/media/tegra-video/tegra210.c | 25 +-
>>>>>>>    drivers/staging/media/tegra-video/vi.c | 793
>>>>>>> +++++++++++++++++++--
>>>>>>>    drivers/staging/media/tegra-video/vi.h | 25 +-
>>>>>>>    drivers/staging/media/tegra-video/video.c | 23 +-
>>>>>>>    include/linux/host1x.h | 4 +-
>>>>>>>    14 files changed, 1242 insertions(+), 154 deletions(-)
>>>>>>>