Skip to contentSkip to conversation

i.MX Media Driver

PATCH Superseded Steve Longerbeam 14 participants 229 messages Feb 16, 2017 – Mar 26, 2017 Page 2 of 2

Subsystems (14)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
author maintainer
#148 lore raw

PATCH v4 22/36 media: imx: Add IC subdev drivers

In reply to Steve Longerbeam

This is a set of four media entity subdevice drivers for the i.MX Image Converter:

- Pre-process Router: Takes input frames from CSI0, CSI1, or VDIC. Two output pads enable either or both of the preprocess tasks below. If the input is from one of the CSIs, both proprocess task links can be enabled to process frames from that CSI simultaneously. If the input is the VDIC, only the Pre-processing Viewfinder task link can be enabled.

- Pre-processing Encode task: video frames are routed directly from the CSI and can be scaled, color-space converted, and rotated. Scaled output is limited to 1024x1024 resolution. Output frames are routed to the capture device.

- Pre-processing Viewfinder task: this task can perform the same conversions as the pre-process encode task, but in addition can be used for hardware motion compensated deinterlacing. Frames can come either directly from the CSI or from the VDIC. Scaled output is limited to 1024x1024 resolution. Output frames are routed to the capture device.

---
 drivers/staging/media/imx/Makefile          |    2 +
 drivers/staging/media/imx/imx-ic-common.c   |  113 +++
 drivers/staging/media/imx/imx-ic-prp.c      |  427 ++++++++++
 drivers/staging/media/imx/imx-ic-prpencvf.c | 1116 +++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-ic.h          |   38 +
 5 files changed, 1696 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-ic-common.c
 create mode 100644 drivers/staging/media/imx/imx-ic-prp.c
 create mode 100644 drivers/staging/media/imx/imx-ic-prpencvf.c
 create mode 100644 drivers/staging/media/imx/imx-ic.h
drivers/staging/media/imx/Makefile +2 -0
index 1f01520..878a126 100644
@@ -1,9 +1,11 @@
 imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o
 imx-media-common-objs := imx-media-utils.o imx-media-fim.o
+imx-media-ic-objs := imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o
 
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
drivers/staging/media/imx/imx-ic-common.c new file +113 -0

113 lines not on this page · raw message

drivers/staging/media/imx/imx-ic-prp.c new file +427 -0

427 lines not on this page · raw message

drivers/staging/media/imx/imx-ic-prpencvf.c new file +1116 -0

1,116 lines not on this page · raw message

drivers/staging/media/imx/imx-ic.h new file +38 -0
new file mode 100644
index 0000000..5535111
@@ -0,0 +1,38 @@
+/*
+ * V4L2 Image Converter Subdev for Freescale i.MX5/6 SOC
+ *
+ * Copyright (c) 2016 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#ifndef _IMX_IC_H
+#define _IMX_IC_H
+
+#include <media/v4l2-subdev.h>
+
+struct imx_ic_priv {
+	struct device *dev;
+	struct v4l2_subdev sd;
+	int    ipu_id;
+	int    task_id;
+	void   *prp_priv;
+	void   *task_priv;
+};
+
+struct imx_ic_ops {
+	struct v4l2_subdev_ops *subdev_ops;
+	struct v4l2_subdev_internal_ops *internal_ops;
+	struct media_entity_operations *entity_ops;
+
+	int (*init)(struct imx_ic_priv *ic_priv);
+	void (*remove)(struct imx_ic_priv *ic_priv);
+};
+
+extern struct imx_ic_ops imx_ic_prp_ops;
+extern struct imx_ic_ops imx_ic_prpencvf_ops;
+extern struct imx_ic_ops imx_ic_pp_ops;
+
+#endif
Signature · 1 line
2.7.4
author maintainer
#149 lore raw

PATCH v4 23/36 media: imx: Add MIPI CSI-2 Receiver subdev driver

In reply to Steve Longerbeam

Adds MIPI CSI-2 Receiver subdev driver. This subdev is required for sensors with a MIPI CSI2 interface.

---
 drivers/staging/media/imx/Makefile         |   1 +
 drivers/staging/media/imx/imx6-mipi-csi2.c | 573 +++++++++++++++++++++++++++++
 2 files changed, 574 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx6-mipi-csi2.c
drivers/staging/media/imx/Makefile +1 -0
index 878a126..3569625 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
drivers/staging/media/imx/imx6-mipi-csi2.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
2.7.4
#150 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 4 lines · Steve Longerbeam

Adds MIPI CSI-2 Receiver subdev driver. This subdev is required for sensors with a MIPI CSI2 interface.

Just like I reported on the 30th January:

.git/rebase-apply/patch:236: trailing whitespace.
*
warning: 1 line adds whitespace errors.

This needs fixing.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#151 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 6 lines · Russell King - ARM Linux
Quoted 4 lines · Steve Longerbeam

Adds MIPI CSI-2 Receiver subdev driver. This subdev is required for sensors with a MIPI CSI2 interface.

Quoted 8 lines

Just like I reported on the 30th January:

.git/rebase-apply/patch:236: trailing whitespace.
*
warning: 1 line adds whitespace errors.

This needs fixing.

Fixed.

maintainer
#152 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

In reply to Steve Longerbeam
Quoted 143 lines · Steve Longerbeam

Adds MIPI CSI-2 Receiver subdev driver. This subdev is required for sensors with a MIPI CSI2 interface.

---
 drivers/staging/media/imx/Makefile         |   1 +
 drivers/staging/media/imx/imx6-mipi-csi2.c | 573 +++++++++++++++++++++++++++++
 2 files changed, 574 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx6-mipi-csi2.c
drivers/staging/media/imx/Makefile +1 -0
index 878a126..3569625 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
drivers/staging/media/imx/imx6-mipi-csi2.c new file +118 -0
new file mode 100644
index 0000000..23dca80
@@ -0,0 +1,573 @@
+/*
+ * MIPI CSI-2 Receiver Subdev for Freescale i.MX6 SOC.
+ *
+ * Copyright (c) 2012-2017 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-of.h>
+#include <media/v4l2-subdev.h>
+#include "imx-media.h"
+
+/*
+ * there must be 5 pads: 1 input pad from sensor, and
+ * the 4 virtual channel output pads
+ */
+#define CSI2_SINK_PAD       0
+#define CSI2_NUM_SINK_PADS  1
+#define CSI2_NUM_SRC_PADS   4
+#define CSI2_NUM_PADS       5
+
+struct csi2_dev {
+	struct device          *dev;
+	struct v4l2_subdev      sd;
+	struct media_pad       pad[CSI2_NUM_PADS];
+	struct v4l2_mbus_framefmt format_mbus;
+	struct clk             *dphy_clk;
+	struct clk             *cfg_clk;
+	struct clk             *pix_clk; /* what is this? */
+	void __iomem           *base;
+	struct v4l2_of_bus_mipi_csi2 bus;
+	bool                    on;
+	bool                    stream_on;
+	bool                    src_linked;
+	bool                    sink_linked[CSI2_NUM_SRC_PADS];
+};
+
+#define DEVICE_NAME "imx6-mipi-csi2"
+
+/* Register offsets */
+#define CSI2_VERSION            0x000
+#define CSI2_N_LANES            0x004
+#define CSI2_PHY_SHUTDOWNZ      0x008
+#define CSI2_DPHY_RSTZ          0x00c
+#define CSI2_RESETN             0x010
+#define CSI2_PHY_STATE          0x014
+#define PHY_STOPSTATEDATA_BIT   4
+#define PHY_STOPSTATEDATA(n)    BIT(PHY_STOPSTATEDATA_BIT + (n))
+#define PHY_RXCLKACTIVEHS       BIT(8)
+#define PHY_RXULPSCLKNOT        BIT(9)
+#define PHY_STOPSTATECLK        BIT(10)
+#define CSI2_DATA_IDS_1         0x018
+#define CSI2_DATA_IDS_2         0x01c
+#define CSI2_ERR1               0x020
+#define CSI2_ERR2               0x024
+#define CSI2_MSK1               0x028
+#define CSI2_MSK2               0x02c
+#define CSI2_PHY_TST_CTRL0      0x030
+#define PHY_TESTCLR		BIT(0)
+#define PHY_TESTCLK		BIT(1)
+#define CSI2_PHY_TST_CTRL1      0x034
+#define PHY_TESTEN		BIT(16)
+#define CSI2_SFT_RESET          0xf00
+
+static inline struct csi2_dev *sd_to_dev(struct v4l2_subdev *sdev)
+{
+	return container_of(sdev, struct csi2_dev, sd);
+}
+
+static void csi2_enable(struct csi2_dev *csi2, bool enable)
+{
+	if (enable) {
+		writel(0x1, csi2->base + CSI2_PHY_SHUTDOWNZ);
+		writel(0x1, csi2->base + CSI2_DPHY_RSTZ);
+		writel(0x1, csi2->base + CSI2_RESETN);
+	} else {
+		writel(0x0, csi2->base + CSI2_PHY_SHUTDOWNZ);
+		writel(0x0, csi2->base + CSI2_DPHY_RSTZ);
+		writel(0x0, csi2->base + CSI2_RESETN);
+	}
+}
+
+static void csi2_set_lanes(struct csi2_dev *csi2)
+{
+	int lanes = csi2->bus.num_data_lanes;
+
+	writel(lanes - 1, csi2->base + CSI2_N_LANES);
+}
+
+static void dw_mipi_csi2_phy_write(struct csi2_dev *csi2,
+				   u32 test_code, u32 test_data)
+{
+	/* Clear PHY test interface */
+	writel(PHY_TESTCLR, csi2->base + CSI2_PHY_TST_CTRL0);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Raise test interface strobe signal */
+	writel(PHY_TESTCLK, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Configure address write on falling edge and lower strobe signal */
+	writel(PHY_TESTEN | test_code, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Configure data write on rising edge and raise strobe signal */
+	writel(test_data, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(PHY_TESTCLK, csi2->base + CSI2_PHY_TST_CTRL0);
+

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 10 lines
drivers/staging/media/imx/imx6-mipi-csi2.c new file +10 -0
+	/* Clear strobe signal */
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+}
+
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

regards
Philipp

#153 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#154 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 12 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

Quoted 3 lines

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

I had code to calculate the number of needed lanes from the bit rate and link frequency. I did not actually change the D-PHY register value. And as you pointed out, calculating the number of lanes is not useful without input from the sensor driver, as some lane configurations might not be supported.

Quoted 5 lines

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

The tc358743 also currently only implements a fixed rate (of 594 Mbps).

regards
Philipp

author maintainer
#155 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 23 lines · Philipp Zabel
Quoted 12 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

Quoted 3 lines

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

I had code to calculate the number of needed lanes from the bit rate and link frequency. I did not actually change the D-PHY register value. And as you pointed out, calculating the number of lanes is not useful without input from the sensor driver, as some lane configurations might not be supported.

Quoted 7 lines
Quoted 5 lines

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

The tc358743 also currently only implements a fixed rate (of 594 Mbps).

I've analyzed the OV5640 video modes, and they generate the following "sysclk"'s in Mhz:

210
280
420
560
840

But I don't know whether this is equivalent to bit rate. Is it the same as Mbps-per-lane? If so, this could be indicated to the sink by implementing V4L2_CID_LINK_FREQ in the ov5640.c sensor driver.

The Mbps-per-lane value would then be link_freq * 2, and then Mbps-per-lane could be used to lookup the correct "hsfreqsel" value to program the D-PHY.

I've added this to imx6-mipi-csi2.c. If the source didn't implement V4L2_CID_LINK_FREQ then it uses a default 849 Mbps-per-lane.

Steve

author maintainer
#156 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 43 lines · Steve Longerbeam
Quoted 23 lines · Philipp Zabel
Quoted 12 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+    /*
+     * FIXME: 0x14 is derived from a fixed D-PHY reference
+     * clock from the HSI_TX PLL, and a fixed target lane max
+     * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

Quoted 3 lines

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

I had code to calculate the number of needed lanes from the bit rate and link frequency. I did not actually change the D-PHY register value. And as you pointed out, calculating the number of lanes is not useful without input from the sensor driver, as some lane configurations might not be supported.

Quoted 7 lines
Quoted 5 lines

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

The tc358743 also currently only implements a fixed rate (of 594 Mbps).

I've analyzed the OV5640 video modes, and they generate the following "sysclk"'s in Mhz:

210
280
420
560
840

Quoted 4 lines

But I don't know whether this is equivalent to bit rate. Is it the same as Mbps-per-lane? If so, this could be indicated to the sink by implementing V4L2_CID_LINK_FREQ in the ov5640.c sensor driver.

er, rather, if I knew what this "sysclk" value was, I could use it to convert to a link frequency and return it in V4L2_CID_LINK_FREQ.

Steve

Quoted 10 lines

The Mbps-per-lane value would then be link_freq * 2, and then Mbps-per-lane could be used to lookup the correct "hsfreqsel" value to program the D-PHY.

I've added this to imx6-mipi-csi2.c. If the source didn't implement V4L2_CID_LINK_FREQ then it uses a default 849 Mbps-per-lane.

Steve

author maintainer
#157 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

In reply to Russell King - ARM Linux
Quoted 16 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

Quoted 5 lines

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

Hi Russell,

As I mentioned, I've added code to imx6-mipi-csi2 to determine the sources link frequency via V4L2_CID_LINK_FREQ. If you were to implement this control and return 912 Mbps-per-lane, the D-PHY will be programmed correctly for the IMX219 (at least, that is the theory anyway).

Alternatively, I could up the default in imx6-mipi-csi2 to 950 Mbps. I will have to test that to make sure it still works with OV5640 and tc358743.

Steve

author maintainer
#158 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 25 lines · Steve Longerbeam
Quoted 16 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+    /*
+     * FIXME: 0x14 is derived from a fixed D-PHY reference
+     * clock from the HSI_TX PLL, and a fixed target lane max
+     * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

I thought you had some code to compute the correct value, although I guess we've lost the ability to know how fast the sensor is going to drive the link.

Quoted 5 lines

Note that the IMX219 currently drives the data lanes at 912Mbps almost exclusively, as I've yet to finish working out how to derive the PLL parameters. (I have something that works, but it currently takes on the order of 100k iterations to derive the parameters. gcd() doesn't help you in this instance.)

Quoted 5 lines

Hi Russell,

As I mentioned, I've added code to imx6-mipi-csi2 to determine the sources link frequency via V4L2_CID_LINK_FREQ. If you were to implement this control and return 912 Mbps-per-lane,

argh, I mean return 912 / 2.

Steve

the D-PHY will be programmed

Quoted 7 lines

correctly for the IMX219 (at least, that is the theory anyway).

Alternatively, I could up the default in imx6-mipi-csi2 to 950 Mbps. I will have to test that to make sure it still works with OV5640 and tc358743.

Steve

maintainer
#159 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

In reply to Philipp Zabel
Quoted 149 lines · Philipp Zabel
Quoted 148 lines · Steve Longerbeam

Adds MIPI CSI-2 Receiver subdev driver. This subdev is required for sensors with a MIPI CSI2 interface.

---
 drivers/staging/media/imx/Makefile         |   1 +
 drivers/staging/media/imx/imx6-mipi-csi2.c | 573 +++++++++++++++++++++++++++++
 2 files changed, 574 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx6-mipi-csi2.c
drivers/staging/media/imx/Makefile +1 -0
index 878a126..3569625 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
 obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
 
 obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
+obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
drivers/staging/media/imx/imx6-mipi-csi2.c new file +123 -0
new file mode 100644
index 0000000..23dca80
@@ -0,0 +1,573 @@
+/*
+ * MIPI CSI-2 Receiver Subdev for Freescale i.MX6 SOC.
+ *
+ * Copyright (c) 2012-2017 Mentor Graphics Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-of.h>
+#include <media/v4l2-subdev.h>
+#include "imx-media.h"
+
+/*
+ * there must be 5 pads: 1 input pad from sensor, and
+ * the 4 virtual channel output pads
+ */
+#define CSI2_SINK_PAD       0
+#define CSI2_NUM_SINK_PADS  1
+#define CSI2_NUM_SRC_PADS   4
+#define CSI2_NUM_PADS       5
+
+struct csi2_dev {
+	struct device          *dev;
+	struct v4l2_subdev      sd;
+	struct media_pad       pad[CSI2_NUM_PADS];
+	struct v4l2_mbus_framefmt format_mbus;
+	struct clk             *dphy_clk;
+	struct clk             *cfg_clk;
+	struct clk             *pix_clk; /* what is this? */
+	void __iomem           *base;
+	struct v4l2_of_bus_mipi_csi2 bus;
+	bool                    on;
+	bool                    stream_on;
+	bool                    src_linked;
+	bool                    sink_linked[CSI2_NUM_SRC_PADS];
+};
+
+#define DEVICE_NAME "imx6-mipi-csi2"
+
+/* Register offsets */
+#define CSI2_VERSION            0x000
+#define CSI2_N_LANES            0x004
+#define CSI2_PHY_SHUTDOWNZ      0x008
+#define CSI2_DPHY_RSTZ          0x00c
+#define CSI2_RESETN             0x010
+#define CSI2_PHY_STATE          0x014
+#define PHY_STOPSTATEDATA_BIT   4
+#define PHY_STOPSTATEDATA(n)    BIT(PHY_STOPSTATEDATA_BIT + (n))
+#define PHY_RXCLKACTIVEHS       BIT(8)
+#define PHY_RXULPSCLKNOT        BIT(9)
+#define PHY_STOPSTATECLK        BIT(10)
+#define CSI2_DATA_IDS_1         0x018
+#define CSI2_DATA_IDS_2         0x01c
+#define CSI2_ERR1               0x020
+#define CSI2_ERR2               0x024
+#define CSI2_MSK1               0x028
+#define CSI2_MSK2               0x02c
+#define CSI2_PHY_TST_CTRL0      0x030
+#define PHY_TESTCLR		BIT(0)
+#define PHY_TESTCLK		BIT(1)
+#define CSI2_PHY_TST_CTRL1      0x034
+#define PHY_TESTEN		BIT(16)
+#define CSI2_SFT_RESET          0xf00
+
+static inline struct csi2_dev *sd_to_dev(struct v4l2_subdev *sdev)
+{
+	return container_of(sdev, struct csi2_dev, sd);
+}
+
+static void csi2_enable(struct csi2_dev *csi2, bool enable)
+{
+	if (enable) {
+		writel(0x1, csi2->base + CSI2_PHY_SHUTDOWNZ);
+		writel(0x1, csi2->base + CSI2_DPHY_RSTZ);
+		writel(0x1, csi2->base + CSI2_RESETN);
+	} else {
+		writel(0x0, csi2->base + CSI2_PHY_SHUTDOWNZ);
+		writel(0x0, csi2->base + CSI2_DPHY_RSTZ);
+		writel(0x0, csi2->base + CSI2_RESETN);
+	}
+}
+
+static void csi2_set_lanes(struct csi2_dev *csi2)
+{
+	int lanes = csi2->bus.num_data_lanes;
+
+	writel(lanes - 1, csi2->base + CSI2_N_LANES);
+}
+
+static void dw_mipi_csi2_phy_write(struct csi2_dev *csi2,
+				   u32 test_code, u32 test_data)
+{
+	/* Clear PHY test interface */
+	writel(PHY_TESTCLR, csi2->base + CSI2_PHY_TST_CTRL0);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Raise test interface strobe signal */
+	writel(PHY_TESTCLK, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Configure address write on falling edge and lower strobe signal */
+	writel(PHY_TESTEN | test_code, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Configure data write on rising edge and raise strobe signal */
+	writel(test_data, csi2->base + CSI2_PHY_TST_CTRL1);
+	writel(PHY_TESTCLK, csi2->base + CSI2_PHY_TST_CTRL0);
+
+	/* Clear strobe signal */
+	writel(0x0, csi2->base + CSI2_PHY_TST_CTRL0);
+}
+
+static void csi2_dphy_init(struct csi2_dev *csi2)
Quoted 8 lines

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 5 lines
drivers/staging/media/imx/imx6-mipi-csi2.c new file +5 -0
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

I got it, the dptdin_map value for 300 Mbps is 0x14 in the Rockchip DSI driver. But that value is written to the register as HSFREQRANGE_SEL(x):

#define HSFREQRANGE_SEL(val) (((val) & 0x3f) << 1)

which is 0x28. Further, the Rockchip D-PHY probably is another version, as its max_mbps goes up to 1500.

regards
Philipp

author maintainer
#160 lore raw

Re: [PATCH v4 23/36] media: imx: Add MIPI CSI-2 Receiver subdev driver

Quoted 12 lines · Philipp Zabel
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/imx6-mipi-csi2.c line 128

Quoted 6 lines · Steve Longerbeam
drivers/staging/media/imx/imx6-mipi-csi2.c new file +6 -0
+static void csi2_dphy_init(struct csi2_dev *csi2)
+{
+	/*
+	 * FIXME: 0x14 is derived from a fixed D-PHY reference
+	 * clock from the HSI_TX PLL, and a fixed target lane max
+	 * bandwidth of 300 Mbps. This value should be derived

If the table in https://community.nxp.com/docs/DOC-94312 is correct, this should be 850 Mbps. Where does this 300 Mbps value come from?

Quoted 4 lines

I got it, the dptdin_map value for 300 Mbps is 0x14 in the Rockchip DSI driver. But that value is written to the register as HSFREQRANGE_SEL(x):

#define HSFREQRANGE_SEL(val) (((val) & 0x3f) << 1)

Ah you are right, 0x14 would be a "testdin" value of 0x0a, which from the Rockchip table would be 950 MHz per lane.

But thanks for pointing the table at
https://community.nxp.com/docs/DOC-94312. That table is what should be referenced in the above comment (850 MHz per lane for a 27MHz reference clock). I will update the comment based on that table.

Steve

Quoted 5 lines

which is 0x28. Further, the Rockchip D-PHY probably is another version, as its max_mbps goes up to 1500.

author maintainer
#161 lore raw

PATCH v4 24/36 add Omnivision OV5640 sensor driver

In reply to Steve Longerbeam

This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta branch, modified heavily to bring forward to latest interfaces and code cleanup.

---
 .../devicetree/bindings/media/i2c/ov5640.txt       |   43 +
 drivers/media/i2c/Kconfig                          |    7 +
 drivers/media/i2c/Makefile                         |    1 +
 drivers/media/i2c/ov5640.c                         | 2109 ++++++++++++++++++++
 4 files changed, 2160 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt
 create mode 100644 drivers/media/i2c/ov5640.c
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +43 -0
new file mode 100644
index 0000000..4607bbe
@@ -0,0 +1,43 @@
+* Omnivision OV5640 MIPI CSI-2 sensor
+
+Required Properties:
+- compatible: should be "ovti,ov5640"
+- clocks: reference to the xclk input clock.
+- clock-names: should be "xclk".
+- DOVDD-supply: Digital I/O voltage supply, 1.8 volts
+- AVDD-supply: Analog voltage supply, 2.8 volts
+- DVDD-supply: Digital core voltage supply, 1.5 volts
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset pin, if any.
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+&i2c1 {
+	ov5640: camera at 3c {
+		compatible = "ovti,ov5640";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_ov5640>;
+		reg = <0x3c>;
+		clocks = <&clks IMX6QDL_CLK_CKO>;
+		clock-names = "xclk";
+		DOVDD-supply = <&vgen4_reg>; /* 1.8v */
+		AVDD-supply = <&vgen3_reg>;  /* 2.8v */
+		DVDD-supply = <&vgen2_reg>;  /* 1.5v */
+		pwdn-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+		reset-gpios = <&gpio1 20 GPIO_ACTIVE_LOW>;
+
+		port {
+			ov5640_to_mipi_csi2: endpoint {
+				remote-endpoint = <&mipi_csi2_from_ov5640>;
+				clock-lanes = <0>;
+				data-lanes = <1 2>;
+			};
+		};
+	};
+};
drivers/media/i2c/Kconfig +7 -0
index cee1dae..bf67661 100644
@@ -531,6 +531,13 @@ config VIDEO_OV2659
 	  To compile this driver as a module, choose M here: the
 	  module will be called ov2659.
 
+config VIDEO_OV5640
+	tristate "OmniVision OV5640 sensor support"
+	depends on GPIOLIB && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
+	---help---
+	  This is a V4L2 sensor-level driver for the Omnivision
+	  OV5640 camera sensor with a MIPI CSI-2 interface.
+
 config VIDEO_OV7640
 	tristate "OmniVision OV7640 sensor support"
 	depends on I2C && VIDEO_V4L2
drivers/media/i2c/Makefile +1 -0
index 5bc7bbe..3a9d73a 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
 obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o
 obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
 obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
+obj-$(CONFIG_VIDEO_OV5640) += ov5640.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
drivers/media/i2c/ov5640.c new file +2109 -0

2,109 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#162 lore raw

Re: [PATCH v4 24/36] [media] add Omnivision OV5640 sensor driver

Quoted 7 lines · Steve Longerbeam

This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta branch, modified heavily to bring forward to latest interfaces and code cleanup.

---
 .../devicetree/bindings/media/i2c/ov5640.txt       |   43 +

Please split to separate commit.

Quoted 16 lines
 drivers/media/i2c/Kconfig                          |    7 +
 drivers/media/i2c/Makefile                         |    1 +
 drivers/media/i2c/ov5640.c                         | 2109 ++++++++++++++++++++
 4 files changed, 2160 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt
 create mode 100644 drivers/media/i2c/ov5640.c
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +3 -0
new file mode 100644
index 0000000..4607bbe
@@ -0,0 +1,43 @@
+* Omnivision OV5640 MIPI CSI-2 sensor
+
+Required Properties:

Documentation/devicetree/bindings/media/i2c/ov5640.txt line 13

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +10 -0
+- compatible: should be "ovti,ov5640"
+- clocks: reference to the xclk input clock.
+- clock-names: should be "xclk".
+- DOVDD-supply: Digital I/O voltage supply, 1.8 volts
+- AVDD-supply: Analog voltage supply, 2.8 volts
+- DVDD-supply: Digital core voltage supply, 1.5 volts
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset pin, if any.
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.

Use powerdown-gpios here as that is a somewhat standard name.

Both need to state what is the active state.

Quoted 30 lines
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +30 -0
+
+The device node must contain one 'port' child node for its digital output
+video port, in accordance with the video interface bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+
+&i2c1 {
+	ov5640: camera at 3c {
+		compatible = "ovti,ov5640";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_ov5640>;
+		reg = <0x3c>;
+		clocks = <&clks IMX6QDL_CLK_CKO>;
+		clock-names = "xclk";
+		DOVDD-supply = <&vgen4_reg>; /* 1.8v */
+		AVDD-supply = <&vgen3_reg>;  /* 2.8v */
+		DVDD-supply = <&vgen2_reg>;  /* 1.5v */
+		pwdn-gpios = <&gpio1 19 GPIO_ACTIVE_HIGH>;
+		reset-gpios = <&gpio1 20 GPIO_ACTIVE_LOW>;
+
+		port {
+			ov5640_to_mipi_csi2: endpoint {
+				remote-endpoint = <&mipi_csi2_from_ov5640>;
+				clock-lanes = <0>;
+				data-lanes = <1 2>;
+			};
+		};
+	};
+};
author maintainer
#163 lore raw

Re: [PATCH v4 24/36] [media] add Omnivision OV5640 sensor driver

Quoted 9 lines · Rob Herring
Quoted 7 lines · Steve Longerbeam

This driver is based on ov5640_mipi.c from Freescale imx_3.10.17_1.0.0_beta branch, modified heavily to bring forward to latest interfaces and code cleanup.

---
  .../devicetree/bindings/media/i2c/ov5640.txt       |   43 +

Please split to separate commit.

Done.

Quoted 20 lines
Quoted 20 lines
  drivers/media/i2c/Kconfig                          |    7 +
  drivers/media/i2c/Makefile                         |    1 +
  drivers/media/i2c/ov5640.c                         | 2109 ++++++++++++++++++++
  4 files changed, 2160 insertions(+)

create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt create mode 100644 drivers/media/i2c/ov5640.c

Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +6 -0
new file mode 100644
index 0000000..4607bbe
@@ -0,0 +1,43 @@
+* Omnivision OV5640 MIPI CSI-2 sensor
+
+Required Properties:
+- compatible: should be "ovti,ov5640"
+- clocks: reference to the xclk input clock.
+- clock-names: should be "xclk".
Quoted 8 lines

Documentation/devicetree/bindings/media/i2c/ov5640.txt line 13

Quoted 7 lines
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +7 -0
+- DOVDD-supply: Digital I/O voltage supply, 1.8 volts
+- AVDD-supply: Analog voltage supply, 2.8 volts
+- DVDD-supply: Digital core voltage supply, 1.5 volts
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset pin, if any.
+- pwdn-gpios: reference to the GPIO connected to the pwdn pin, if any.

Use powerdown-gpios here as that is a somewhat standard name.

Done.

Quoted 2 lines

Both need to state what is the active state.

Done.

Steve

author maintainer
#164 lore raw

PATCH v4 25/36 ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers

In reply to Steve Longerbeam

Enable i.MX v4l2 media staging driver. For video capture on i.MX, the video multiplexer subdev is required. On the SabreAuto, the ADV7180 video decoder is required along with i2c-mux-gpio. The Sabrelite and SabreSD require the OV5640 and the SabreLite requires PWM clocks for the OV5640.

Increase max zoneorder to allow larger video buffer allocations.

---
 arch/arm/configs/imx_v6_v7_defconfig | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
arch/arm/configs/imx_v6_v7_defconfig +12 -2
index cbe7faf..daeb164 100644
@@ -51,6 +51,7 @@ CONFIG_PREEMPT_VOLUNTARY=y
 CONFIG_AEABI=y
 CONFIG_HIGHMEM=y
 CONFIG_CMA=y
+CONFIG_FORCE_MAX_ZONEORDER=14
 CONFIG_CMDLINE="noinitrd console=ttymxc0,115200"
 CONFIG_KEXEC=y
 CONFIG_CPU_FREQ=y
@@ -174,13 +175,13 @@ CONFIG_INPUT_MISC=y
 CONFIG_INPUT_MMA8450=y
 CONFIG_SERIO_SERPORT=m
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_IMX=y
 CONFIG_SERIAL_IMX_CONSOLE=y
 CONFIG_SERIAL_FSL_LPUART=y
 CONFIG_SERIAL_FSL_LPUART_CONSOLE=y
 # CONFIG_I2C_COMPAT is not set
 CONFIG_I2C_CHARDEV=y
+CONFIG_I2C_MUX=y
 CONFIG_I2C_MUX_GPIO=y
 # CONFIG_I2C_HELPER_AUTO is not set
 CONFIG_I2C_ALGOPCF=m
@@ -194,11 +195,11 @@ CONFIG_GPIO_SYSFS=y
 CONFIG_GPIO_MC9S08DZ60=y
 CONFIG_GPIO_PCA953X=y
 CONFIG_GPIO_STMPE=y
-CONFIG_POWER_SUPPLY=y
 CONFIG_POWER_RESET=y
 CONFIG_POWER_RESET_IMX=y
 CONFIG_POWER_RESET_SYSCON=y
 CONFIG_POWER_RESET_SYSCON_POWEROFF=y
+CONFIG_POWER_SUPPLY=y
 CONFIG_SENSORS_GPIO_FAN=y
 CONFIG_SENSORS_IIO_HWMON=y
 CONFIG_THERMAL=y
@@ -221,14 +222,20 @@ CONFIG_REGULATOR_PFUZE100=y
 CONFIG_MEDIA_SUPPORT=y
 CONFIG_MEDIA_CAMERA_SUPPORT=y
 CONFIG_MEDIA_RC_SUPPORT=y
+CONFIG_MEDIA_CONTROLLER=y
+CONFIG_VIDEO_V4L2_SUBDEV_API=y
 CONFIG_RC_DEVICES=y
 CONFIG_IR_GPIO_CIR=y
 CONFIG_MEDIA_USB_SUPPORT=y
 CONFIG_USB_VIDEO_CLASS=m
 CONFIG_V4L_PLATFORM_DRIVERS=y
+CONFIG_VIDEO_MULTIPLEXER=y
 CONFIG_SOC_CAMERA=y
 CONFIG_V4L_MEM2MEM_DRIVERS=y
 CONFIG_VIDEO_CODA=y
+# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
+CONFIG_VIDEO_ADV7180=m
+CONFIG_VIDEO_OV5640=m
 CONFIG_SOC_CAMERA_OV2640=y
 CONFIG_IMX_IPUV3_CORE=y
 CONFIG_DRM=y
@@ -338,6 +345,9 @@ CONFIG_FSL_EDMA=y
 CONFIG_IMX_SDMA=y
 CONFIG_MXS_DMA=y
 CONFIG_STAGING=y
+CONFIG_STAGING_MEDIA=y
+CONFIG_VIDEO_IMX_MEDIA=y
+CONFIG_COMMON_CLK_PWM=y
 CONFIG_IIO=y
 CONFIG_VF610_ADC=y
 CONFIG_MPL3115=y
Signature · 1 line
2.7.4
author maintainer
#165 lore raw

PATCH v4 26/36 media: imx: add support for bayer formats

In reply to Steve Longerbeam

From: Russell King <[email protected]>

Add the bayer formats to imx-media's list of supported pixel and bus formats.

- added a bayer boolean to struct imx_media_pixfmt.

---
 drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media.h       |  1 +
 2 files changed, 69 insertions(+)
drivers/staging/media/imx/imx-media-utils.c +68 -0
index 55603d9..6855560 100644
@@ -61,6 +61,74 @@ static const struct imx_media_pixfmt imx_media_formats[] = {
 		.cs     = IPUV3_COLORSPACE_RGB,
 		.bpp    = 32,
 		.ipufmt = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SBGGR8,
+		.codes  = {MEDIA_BUS_FMT_SBGGR8_1X8},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG8,
+		.codes  = {MEDIA_BUS_FMT_SGBRG8_1X8},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG8,
+		.codes  = {MEDIA_BUS_FMT_SGRBG8_1X8},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB8,
+		.codes  = {MEDIA_BUS_FMT_SRGGB8_1X8},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 8,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SBGGR16,
+		.codes  = {
+			MEDIA_BUS_FMT_SBGGR10_1X10,
+			MEDIA_BUS_FMT_SBGGR12_1X12,
+			MEDIA_BUS_FMT_SBGGR14_1X14,
+			MEDIA_BUS_FMT_SBGGR16_1X16
+		},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGBRG16,
+		.codes  = {
+			MEDIA_BUS_FMT_SGBRG10_1X10,
+			MEDIA_BUS_FMT_SGBRG12_1X12,
+			MEDIA_BUS_FMT_SGBRG14_1X14,
+			MEDIA_BUS_FMT_SGBRG16_1X16,
+		},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SGRBG16,
+		.codes  = {
+			MEDIA_BUS_FMT_SGRBG10_1X10,
+			MEDIA_BUS_FMT_SGRBG12_1X12,
+			MEDIA_BUS_FMT_SGRBG14_1X14,
+			MEDIA_BUS_FMT_SGRBG16_1X16,
+		},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
+	}, {
+		.fourcc = V4L2_PIX_FMT_SRGGB16,
+		.codes  = {
+			MEDIA_BUS_FMT_SRGGB10_1X10,
+			MEDIA_BUS_FMT_SRGGB12_1X12,
+			MEDIA_BUS_FMT_SRGGB14_1X14,
+			MEDIA_BUS_FMT_SRGGB16_1X16,
+		},
+		.cs     = IPUV3_COLORSPACE_RGB,
+		.bpp    = 16,
+		.bayer  = true,
 	},
 	/*** non-mbus formats start here ***/
 	{
drivers/staging/media/imx/imx-media.h +1 -0
index 3d4f3c7..ae3af0d 100644
@@ -91,6 +91,7 @@ struct imx_media_pixfmt {
 	int     bpp;     /* total bpp */
 	enum ipu_color_space cs;
 	bool    planar;  /* is a planar format */
+	bool    bayer;   /* is a raw bayer format */
 	bool    ipufmt;  /* is one of the IPU internal formats */
 };
 
Signature · 1 line
2.7.4
author maintainer
#166 lore raw

PATCH v4 27/36 media: imx: csi: add support for bayer formats

In reply to Steve Longerbeam

From: Russell King <[email protected]>

Bayer formats must be treated as generic data and passthrough mode must be used. Add the correct setup for these formats.

- added check to csi_link_validate() to verify that destination is IDMAC output pad when passthrough conditions exist: bayer formats and 16-bit parallel buses.

---
 drivers/staging/media/imx/imx-media-csi.c | 50 ++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 8 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +42 -8
index 0343fc3..ae24b42 100644
@@ -2,6 +2,7 @@
  * V4L2 Capture CSI Subdev for Freescale i.MX5/6 SOC
  *
  * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ * Copyright (C) 2017 Pengutronix, Philipp Zabel <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -271,10 +272,11 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
 	struct imx_media_video_dev *vdev = priv->vdev;
 	struct v4l2_of_endpoint *sensor_ep;
 	struct v4l2_mbus_framefmt *infmt;
-	unsigned int burst_size;
 	struct ipu_image image;
+	u32 passthrough_bits;
 	dma_addr_t phys[2];
 	bool passthrough;
+	u32 burst_size;
 	int ret;
 
 	infmt = &priv->format_mbus[CSI_SINK_PAD];
@@ -301,15 +303,38 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
 	ipu_cpmem_set_burstsize(priv->idmac_ch, burst_size);
 
 	/*
-	 * If the sensor uses 16-bit parallel CSI bus, we must handle
-	 * the data internally in the IPU as 16-bit generic, aka
-	 * passthrough mode.
+	 * Check for conditions that require the IPU to handle the
+	 * data internally as generic data, aka passthrough mode:
+	 * - raw bayer formats
+	 * - the sensor bus is 16-bit parallel
 	 */
-	passthrough = (sensor_ep->bus_type != V4L2_MBUS_CSI2 &&
-		       sensor_ep->bus.parallel.bus_width >= 16);
+	switch (image.pix.pixelformat) {
+	case V4L2_PIX_FMT_SBGGR8:
+	case V4L2_PIX_FMT_SGBRG8:
+	case V4L2_PIX_FMT_SGRBG8:
+	case V4L2_PIX_FMT_SRGGB8:
+		burst_size = 8;
+		passthrough = true;
+		passthrough_bits = 8;
+		break;
+	case V4L2_PIX_FMT_SBGGR16:
+	case V4L2_PIX_FMT_SGBRG16:
+	case V4L2_PIX_FMT_SGRBG16:
+	case V4L2_PIX_FMT_SRGGB16:
+		burst_size = 4;
+		passthrough = true;
+		passthrough_bits = 16;
+		break;
+	default:
+		passthrough = (sensor_ep->bus_type != V4L2_MBUS_CSI2 &&
+			       sensor_ep->bus.parallel.bus_width >= 16);
+		passthrough_bits = 16;
+		break;
+	}
 
 	if (passthrough)
-		ipu_cpmem_set_format_passthrough(priv->idmac_ch, 16);
+		ipu_cpmem_set_format_passthrough(priv->idmac_ch,
+						 passthrough_bits);
 
 	/*
 	 * Set the channel for the direct CSI-->memory via SMFC
@@ -695,6 +720,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_format *sink_fmt)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	const struct imx_media_pixfmt *incc;
 	struct v4l2_of_endpoint *sensor_ep;
 	bool is_csi2;
 	int ret;
@@ -713,8 +739,16 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 	}
 
 	sensor_ep = &priv->sensor->sensor_ep;
-
 	is_csi2 = (sensor_ep->bus_type == V4L2_MBUS_CSI2);
+	incc = priv->cc[CSI_SINK_PAD];
+
+	if (priv->dest != IPU_CSI_DEST_IDMAC &&
+	    (incc->bayer || (!is_csi2 &&
+			     sensor_ep->bus.parallel.bus_width >= 16))) {
+		v4l2_err(&priv->sd,
+			 "bayer/16-bit parallel buses must go to IDMAC pad\n");
+		return -EINVAL;
+	}
 
 	if (is_csi2) {
 		int vc_num = 0;
Signature · 1 line
2.7.4
author maintainer
#167 lore raw

PATCH v4 28/36 media: imx: csi: fix crop rectangle changes in set_fmt

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

The cropping rectangle was being modified by the output pad's set_fmt, which is the wrong pad to do this. The crop rectangle should not be modified by the output pad set_fmt. It instead should be reset to the full input frame when the input pad format is set.

The output pad set_fmt should set width/height to the current crop dimensions, or 1/2 the crop width/height to enable downscaling.

So the other part of this patch is to enable downscaling if the output pad dimension(s) are 1/2 the crop dimension(s) at csi_setup() time.

---
 drivers/staging/media/imx/imx-media-csi.c | 35 ++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 12 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +23 -12
index ae24b42..3cb97e2 100644
@@ -531,6 +531,10 @@ static int csi_setup(struct csi_priv *priv)
 
 	ipu_csi_set_window(priv->csi, &priv->crop);
 
+	ipu_csi_set_downsize(priv->csi,
+			     priv->crop.width == 2 * outfmt->width,
+			     priv->crop.height == 2 * outfmt->height);
+
 	ipu_csi_init_interface(priv->csi, &sensor_mbus_cfg, &if_fmt);
 
 	ipu_csi_set_dest(priv->csi, priv->dest);
@@ -890,15 +894,15 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	switch (sdformat->pad) {
 	case CSI_SRC_PAD_DIRECT:
 	case CSI_SRC_PAD_IDMAC:
-		crop.left = priv->crop.left;
-		crop.top = priv->crop.top;
-		crop.width = sdformat->format.width;
-		crop.height = sdformat->format.height;
-		ret = csi_try_crop(priv, &crop, sensor);
-		if (ret)
-			return ret;
-		sdformat->format.width = crop.width;
-		sdformat->format.height = crop.height;
+		if (sdformat->format.width < priv->crop.width * 3 / 4)
+			sdformat->format.width = priv->crop.width / 2;
+		else
+			sdformat->format.width = priv->crop.width;
+
+		if (sdformat->format.height < priv->crop.height * 3 / 4)
+			sdformat->format.height = priv->crop.height / 2;
+		else
+			sdformat->format.height = priv->crop.height;
 
 		if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
 			cc = imx_media_find_format(0, sdformat->format.code,
@@ -948,6 +952,14 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		}
 		break;
 	case CSI_SINK_PAD:
+		crop.left = 0;
+		crop.top = 0;
+		crop.width = sdformat->format.width;
+		crop.height = sdformat->format.height;
+		ret = csi_try_crop(priv, &crop, sensor);
+		if (ret)
+			return ret;
+
 		cc = imx_media_find_format(0, sdformat->format.code,
 					   true, false);
 		if (!cc) {
@@ -965,9 +977,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	} else {
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		/* Update the crop window if this is an output pad  */
-		if (sdformat->pad == CSI_SRC_PAD_DIRECT ||
-		    sdformat->pad == CSI_SRC_PAD_IDMAC)
+		/* Reset the crop window if this is the input pad */
+		if (sdformat->pad == CSI_SINK_PAD)
 			priv->crop = crop;
 	}
 
Signature · 1 line
2.7.4
#168 lore raw

Re: [PATCH v4 28/36] media: imx: csi: fix crop rectangle changes in set_fmt

drivers/staging/media/imx/imx-media-csi.c static int csi_setup(struct csi_priv *priv) · line 537

Quoted 12 lines · Steve Longerbeam
drivers/staging/media/imx/imx-media-csi.c +4 -0
index ae24b42..3cb97e2 100644
@@ -531,6 +531,10 @@ static int csi_setup(struct csi_priv *priv)
 
 	ipu_csi_set_window(priv->csi, &priv->crop);
 
+	ipu_csi_set_downsize(priv->csi,
+			     priv->crop.width == 2 * outfmt->width,
+			     priv->crop.height == 2 * outfmt->height);
+

This fails to build:

ERROR: "ipu_csi_set_downsize" [drivers/staging/media/imx/imx-media-csi.ko] undefined!

ipu_csi_set_downsize needs to be exported if we're going to use it in a module:

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#169 lore raw

Re: [PATCH v4 28/36] media: imx: csi: fix crop rectangle changes in set_fmt

Quoted 16 lines · Russell King - ARM Linux

drivers/staging/media/imx/imx-media-csi.c static int csi_setup(struct csi_priv *priv) · line 537

Quoted 12 lines · Steve Longerbeam
drivers/staging/media/imx/imx-media-csi.c +4 -0
index ae24b42..3cb97e2 100644
@@ -531,6 +531,10 @@ static int csi_setup(struct csi_priv *priv)
 
 	ipu_csi_set_window(priv->csi, &priv->crop);
 
+	ipu_csi_set_downsize(priv->csi,
+			     priv->crop.width == 2 * outfmt->width,
+			     priv->crop.height == 2 * outfmt->height);
+

This fails to build:

Quoted 5 lines

ERROR: "ipu_csi_set_downsize" [drivers/staging/media/imx/imx-media-csi.ko] undefined!

ipu_csi_set_downsize needs to be exported if we're going to use it in a module:

Yes I encountered the missing export too, forgot to mention it. Philipp submitted a patch to dri-devel separately.

Steve

author maintainer
#170 lore raw

PATCH v4 29/36 media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Add support at MIPI CSI2 level for handling this part of the negotiation.

---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/staging/media/imx/imx6-mipi-csi2.c +27 -0
index 23dca80..c62f14e 100644
@@ -34,6 +34,7 @@ struct csi2_dev {
 	struct v4l2_subdev      sd;
 	struct media_pad       pad[CSI2_NUM_PADS];
 	struct v4l2_mbus_framefmt format_mbus;
+	struct v4l2_fract      frame_interval;
 	struct clk             *dphy_clk;
 	struct clk             *cfg_clk;
 	struct clk             *pix_clk; /* what is this? */
@@ -397,6 +398,30 @@ static int csi2_set_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int csi2_g_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	fi->interval = csi2->frame_interval;
+
+	return 0;
+}
+
+static int csi2_s_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	/* Output pads mirror active input pad, no limits on input pads */
+	if (fi->pad != CSI2_SINK_PAD)
+		fi->interval = csi2->frame_interval;
+
+	csi2->frame_interval = fi->interval;
+
+	return 0;
+}
+
 /*
  * retrieve our pads parsed from the OF graph by the media device
  */
@@ -430,6 +455,8 @@ static struct v4l2_subdev_core_ops csi2_core_ops = {
 
 static struct v4l2_subdev_video_ops csi2_video_ops = {
 	.s_stream = csi2_s_stream,
+	.g_frame_interval = csi2_g_frame_interval,
+	.s_frame_interval = csi2_s_frame_interval,
 };
 
 static struct v4l2_subdev_pad_ops csi2_pad_ops = {
Signature · 1 line
2.7.4
#171 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 11 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Add support at MIPI CSI2 level for handling this part of the negotiation.

Hi Russell,

I signed-off on this but after more review I'm not sure this is right.

The CSI-2 receiver really has no control over frame rate. It's output frame rate is the same as the rate that is delivered to it.

So this subdev should either not implement these ops, or it should refer them to the attached source subdev.

Steve

Quoted 57 lines
---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/staging/media/imx/imx6-mipi-csi2.c +27 -0
index 23dca80..c62f14e 100644
@@ -34,6 +34,7 @@ struct csi2_dev {
 	struct v4l2_subdev      sd;
 	struct media_pad       pad[CSI2_NUM_PADS];
 	struct v4l2_mbus_framefmt format_mbus;
+	struct v4l2_fract      frame_interval;
 	struct clk             *dphy_clk;
 	struct clk             *cfg_clk;
 	struct clk             *pix_clk; /* what is this? */
@@ -397,6 +398,30 @@ static int csi2_set_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int csi2_g_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	fi->interval = csi2->frame_interval;
+
+	return 0;
+}
+
+static int csi2_s_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	/* Output pads mirror active input pad, no limits on input pads */
+	if (fi->pad != CSI2_SINK_PAD)
+		fi->interval = csi2->frame_interval;
+
+	csi2->frame_interval = fi->interval;
+
+	return 0;
+}
+
 /*
  * retrieve our pads parsed from the OF graph by the media device
  */
@@ -430,6 +455,8 @@ static struct v4l2_subdev_core_ops csi2_core_ops = {
 
 static struct v4l2_subdev_video_ops csi2_video_ops = {
 	.s_stream = csi2_s_stream,
+	.g_frame_interval = csi2_g_frame_interval,
+	.s_frame_interval = csi2_s_frame_interval,
 };
 
 static struct v4l2_subdev_pad_ops csi2_pad_ops = {
Signature · 3 lines
Steve Longerbeam | Senior Embedded Engineer, ESD Services
Mentor Embedded(tm) | 46871 Bayside Parkway, Fremont, CA 94538
P 510.354.5838 | M 408.410.2735
author maintainer
#172 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Steve Longerbeam
Quoted 11 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Add support at MIPI CSI2 level for handling this part of the negotiation.

Hi Russell,

I signed-off on this but after more review I'm not sure this is right.

The CSI-2 receiver really has no control over frame rate. It's output frame rate is the same as the rate that is delivered to it.

So this subdev should either not implement these ops, or it should refer them to the attached source subdev.

Steve

Quoted 57 lines
---
 drivers/staging/media/imx/imx6-mipi-csi2.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/staging/media/imx/imx6-mipi-csi2.c +27 -0
index 23dca80..c62f14e 100644
@@ -34,6 +34,7 @@ struct csi2_dev {
 	struct v4l2_subdev      sd;
 	struct media_pad       pad[CSI2_NUM_PADS];
 	struct v4l2_mbus_framefmt format_mbus;
+	struct v4l2_fract      frame_interval;
 	struct clk             *dphy_clk;
 	struct clk             *cfg_clk;
 	struct clk             *pix_clk; /* what is this? */
@@ -397,6 +398,30 @@ static int csi2_set_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int csi2_g_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	fi->interval = csi2->frame_interval;
+
+	return 0;
+}
+
+static int csi2_s_frame_interval(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi2_dev *csi2 = sd_to_dev(sd);
+
+	/* Output pads mirror active input pad, no limits on input pads */
+	if (fi->pad != CSI2_SINK_PAD)
+		fi->interval = csi2->frame_interval;
+
+	csi2->frame_interval = fi->interval;
+
+	return 0;
+}
+
 /*
  * retrieve our pads parsed from the OF graph by the media device
  */
@@ -430,6 +455,8 @@ static struct v4l2_subdev_core_ops csi2_core_ops = {
 
 static struct v4l2_subdev_video_ops csi2_video_ops = {
 	.s_stream = csi2_s_stream,
+	.g_frame_interval = csi2_g_frame_interval,
+	.s_frame_interval = csi2_s_frame_interval,
 };
 
 static struct v4l2_subdev_pad_ops csi2_pad_ops = {
Signature · 3 lines
Steve Longerbeam | Senior Embedded Engineer, ESD Services
Mentor Embedded(tm) | 46871 Bayside Parkway, Fremont, CA 94538
P 510.354.5838 | M 408.410.2735
#173 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 9 lines · Steve Longerbeam

Hi Russell,

I signed-off on this but after more review I'm not sure this is right.

The CSI-2 receiver really has no control over frame rate. It's output frame rate is the same as the rate that is delivered to it.

So this subdev should either not implement these ops, or it should refer them to the attached source subdev.

Where in the V4L2 documentation does it say that is permissible?

If you don't implement these, media-ctl fails to propagate _anything_ to the next sink pad if you specify a frame rate, because media-ctl throws an error and exits immediately.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#174 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 5 lines · Russell King - ARM Linux
Quoted 4 lines · Steve Longerbeam

Hi Russell,

I signed-off on this but after more review I'm not sure this is right.

Quoted 8 lines
Quoted 5 lines

The CSI-2 receiver really has no control over frame rate. It's output frame rate is the same as the rate that is delivered to it.

So this subdev should either not implement these ops, or it should refer them to the attached source subdev.

Where in the V4L2 documentation does it say that is permissible?

https://www.linuxtv.org/downloads/v4l-dvb-apis-old/vidioc-subdev-g-frame-interval.html

"The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls."

Quoted 4 lines

If you don't implement these, media-ctl fails to propagate _anything_ to the next sink pad if you specify a frame rate, because media-ctl throws an error and exits immediately.

But I agree with you here. I think our only option is to ignore that quoted requirement above and propagate [gs]_frame_interval all the way to the CSI (which can control the frame rate via frame skipping).

Steve

#175 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 15 lines · Steve Longerbeam
Quoted 5 lines · Russell King - ARM Linux
Quoted 4 lines · Steve Longerbeam

Hi Russell,

I signed-off on this but after more review I'm not sure this is right.

Quoted 8 lines
Quoted 5 lines

The CSI-2 receiver really has no control over frame rate. It's output frame rate is the same as the rate that is delivered to it.

So this subdev should either not implement these ops, or it should refer them to the attached source subdev.

Where in the V4L2 documentation does it say that is permissible?

Quoted 6 lines

https://www.linuxtv.org/downloads/v4l-dvb-apis-old/vidioc-subdev-g-frame-interval.html

"The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls."

That sounds clear - but the TV tuner example seems odd - the frame rate is determined at transmission time, not reception time. Yes, it's possible to skip frames (which would be scaling) but you can't _control_ the frame rate per se.

Quoted 8 lines
Quoted 4 lines

If you don't implement these, media-ctl fails to propagate _anything_ to the next sink pad if you specify a frame rate, because media-ctl throws an error and exits immediately.

But I agree with you here. I think our only option is to ignore that quoted requirement above and propagate [gs]_frame_interval all the way to the CSI (which can control the frame rate via frame skipping).

Sounds like something to tackle the media maintainers over - the documentation vs media-ctl seem to have different ideas on this point.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#176 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Steve Longerbeam

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Signature · 2 lines
Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
author maintainer
#177 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 10 lines · Sakari Ailus

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Hi Sakari,

i.MX does need the ability to negotiate the frame rates in the pipelines. The CSI has the ability to skip frames at the output, which is something Philipp added to the CSI subdev. That affects frame interval at the CSI output.

But as Russell pointed out, the lack of [gs]_frame_interval op causes media-ctl to fail:

media-ctl -v -d /dev/media1 --set-v4l2
'"imx6-mipi-csi2":1[fmt:SGBRG8/512x512 at 1/30]'

Opening media device /dev/media1
Enumerating entities
Found 29 entities
Enumerating pads and links
Setting up format SGBRG8 512x512 on pad imx6-mipi-csi2/1 Format set: SGBRG8 512x512
Setting up frame interval 1/30 on entity imx6-mipi-csi2 Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

So i.MX needs to implement this op in every subdev in the pipeline, otherwise it's not possible to configure the pipeline with media-ctl.

Steve

author maintainer
#178 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 39 lines · Steve Longerbeam
Quoted 10 lines · Sakari Ailus

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Hi Sakari,

i.MX does need the ability to negotiate the frame rates in the pipelines. The CSI has the ability to skip frames at the output, which is something Philipp added to the CSI subdev. That affects frame interval at the CSI output.

But as Russell pointed out, the lack of [gs]_frame_interval op causes media-ctl to fail:

media-ctl -v -d /dev/media1 --set-v4l2
'"imx6-mipi-csi2":1[fmt:SGBRG8/512x512 at 1/30]'

Opening media device /dev/media1
Enumerating entities
Found 29 entities
Enumerating pads and links
Setting up format SGBRG8 512x512 on pad imx6-mipi-csi2/1 Format set: SGBRG8 512x512
Setting up frame interval 1/30 on entity imx6-mipi-csi2 Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

Quoted 4 lines

So i.MX needs to implement this op in every subdev in the pipeline, otherwise it's not possible to configure the pipeline with media-ctl.

Hi Russell,

But Sakari brings up a good point. The mipi csi-2 receiver doesn't have any control over frame rate, so why do you even need to give it this information via media-ctl?

Steve

#179 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Steve Longerbeam

Hi Steve,

Quoted 39 lines · Steve Longerbeam
Quoted 10 lines · Sakari Ailus

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Hi Sakari,

i.MX does need the ability to negotiate the frame rates in the pipelines. The CSI has the ability to skip frames at the output, which is something Philipp added to the CSI subdev. That affects frame interval at the CSI output.

But as Russell pointed out, the lack of [gs]_frame_interval op causes media-ctl to fail:

media-ctl -v -d /dev/media1 --set-v4l2
'"imx6-mipi-csi2":1[fmt:SGBRG8/512x512 at 1/30]'

Opening media device /dev/media1
Enumerating entities
Found 29 entities
Enumerating pads and links
Setting up format SGBRG8 512x512 on pad imx6-mipi-csi2/1
Format set: SGBRG8 512x512
Setting up frame interval 1/30 on entity imx6-mipi-csi2
Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

Quoted 3 lines

So i.MX needs to implement this op in every subdev in the pipeline, otherwise it's not possible to configure the pipeline with media-ctl.

The frame rate is only set on the sub-device which you explicitly set it. I.e. setting the frame rate fails if it's not supported on a pad.

Philipp recently posted patches that add frame rate propagation to media-ctl.

Frame rate is typically settable (and gettable) only on sensor sub-device's source pad, which means it normally would not be propagated by the kernel but with Philipp's patches, on the sink pad of the bus receiver. Receivers don't have a way to control it nor they implement the IOCTLs, so that would indeed result in an error.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
author maintainer
#180 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 49 lines · Sakari Ailus

Hi Steve,

Quoted 39 lines · Steve Longerbeam
Quoted 10 lines · Sakari Ailus

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Hi Sakari,

i.MX does need the ability to negotiate the frame rates in the pipelines. The CSI has the ability to skip frames at the output, which is something Philipp added to the CSI subdev. That affects frame interval at the CSI output.

But as Russell pointed out, the lack of [gs]_frame_interval op causes media-ctl to fail:

media-ctl -v -d /dev/media1 --set-v4l2
'"imx6-mipi-csi2":1[fmt:SGBRG8/512x512 at 1/30]'

Opening media device /dev/media1
Enumerating entities
Found 29 entities
Enumerating pads and links
Setting up format SGBRG8 512x512 on pad imx6-mipi-csi2/1
Format set: SGBRG8 512x512
Setting up frame interval 1/30 on entity imx6-mipi-csi2
Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

Quoted 3 lines

So i.MX needs to implement this op in every subdev in the pipeline, otherwise it's not possible to configure the pipeline with media-ctl.

The frame rate is only set on the sub-device which you explicitly set it. I.e. setting the frame rate fails if it's not supported on a pad.

Quoted 9 lines

Philipp recently posted patches that add frame rate propagation to media-ctl.

Frame rate is typically settable (and gettable) only on sensor sub-device's source pad, which means it normally would not be propagated by the kernel but with Philipp's patches, on the sink pad of the bus receiver. Receivers don't have a way to control it nor they implement the IOCTLs, so that would indeed result in an error.

Frame rate is really an essential piece of information. The spatial dimensions and data type provided by set_fmt are really only half the equation, the other is temporal, i.e. the data rate.

It's true that subdevices have no control over the frame rate at their sink pads, but the same argument applies to set_fmt. Even if it has no control over the data format it receives, it still needs that information in order to determine the correct format at the source. The same argument applies to frame rate.

So in my opinion, the behavior of [gs]_frame_interval should be, if a subdevice is capable of modifying the frame rate, then it should implement [gs]_frame_interval at _all_ of its pads, similar to set_fmt. And frame rate should really be part of link validation the same as set_fmt is.

Steve

author maintainer
#181 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 77 lines · Steve Longerbeam
Quoted 53 lines · Sakari Ailus

Hi Steve,

Quoted 40 lines · Steve Longerbeam
Quoted 10 lines · Sakari Ailus

Hi Steve,

Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

Hi Sakari,

i.MX does need the ability to negotiate the frame rates in the pipelines. The CSI has the ability to skip frames at the output, which is something Philipp added to the CSI subdev. That affects frame interval at the CSI output.

But as Russell pointed out, the lack of [gs]_frame_interval op causes media-ctl to fail:

media-ctl -v -d /dev/media1 --set-v4l2
'"imx6-mipi-csi2":1[fmt:SGBRG8/512x512 at 1/30]'

Opening media device /dev/media1
Enumerating entities
Found 29 entities
Enumerating pads and links
Setting up format SGBRG8 512x512 on pad imx6-mipi-csi2/1 Format set: SGBRG8 512x512
Setting up frame interval 1/30 on entity imx6-mipi-csi2 Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to
setup formats: Inappropriate ioctl for device (25)

Quoted 3 lines

So i.MX needs to implement this op in every subdev in the pipeline, otherwise it's not possible to configure the pipeline with media-ctl.

The frame rate is only set on the sub-device which you explicitly set it. I.e. setting the frame rate fails if it's not supported on a pad.

Philipp recently posted patches that add frame rate propagation to media-ctl.

Quoted 10 lines

Frame rate is typically settable (and gettable) only on sensor sub-device's
source pad, which means it normally would not be propagated by the kernel
but with Philipp's patches, on the sink pad of the bus receiver. Receivers
don't have a way to control it nor they implement the IOCTLs, so that would
indeed result in an error.

Frame rate is really an essential piece of information. The spatial dimensions and data type provided by set_fmt are really only half the equation, the other is temporal, i.e. the data rate.

It's true that subdevices have no control over the frame rate at their sink pads, but the same argument applies to set_fmt. Even if it has no control over the data format it receives, it still needs that information in order to determine the correct format at the source. The same argument applies to frame rate.

Quoted 6 lines

So in my opinion, the behavior of [gs]_frame_interval should be, if a subdevice is capable of modifying the frame rate, then it should implement [gs]_frame_interval at _all_ of its pads, similar to set_fmt. And frame rate should really be part of link validation the same as set_fmt is.

Actually, if frame rate were added to link validation then [gs]_frame_interval would have to be mandatory, even if the subdev has no control over frame rate, again this is like set_fmt. Otherwise, if a subdev has not implemented [gs]_frame_interval, then frame rate validation across the whole pipeline is broken. Because, if we have

A -> B -> C

and B has not implemented [gs]_frame_interval, and C is expecting 30 fps, then pipeline validation would succeed even though A is outputting 60 fps.

Steve

#182 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Sakari Ailus
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

The problem there is that the format setting for the csi2 does not get propagated forward:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

In any case, the documentation vs media-ctl create something of a very obscure situation, one that probably needs solving one way or another.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#183 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 103 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

The problem there is that the format setting for the csi2 does not get propagated forward:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

Quoted 4 lines

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

I agree, frame rate, if indicated/specified by both sides of a link, should match. So maybe this should be part of v4l2 link validation.

This might be a good time to propose the following patch.

Steve

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0015-media-v4l-subdev-Add-function-to-validate-frame-inte.patch
Type: text/x-patch
Size: 4620 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170220/6026ed58/attachment-0001.bin>

maintainer
#184 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 87 lines · Steve Longerbeam
Quoted 85 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

The problem there is that the format setting for the csi2 does not get propagated forward:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Quoted 3 lines
Quoted 3 lines

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

I'd interpret this as meaning pixel skipping, not frame skipping.

Quoted 19 lines
Quoted 14 lines

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

Quoted 4 lines

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

Quoted 4 lines

I agree, frame rate, if indicated/specified by both sides of a link, should match. So maybe this should be part of v4l2 link validation.

This might be a good time to propose the following patch.

I agree with Steve and Russell. I don't see why the (nominal) frame interval should be handled differently than resolution, data format, and colorspace information. I think it should just be propagated in the same way, and there is no reason to have two connected pads set to a different interval. That would make implementing the g/s_frame_interval subdev calls mandatory.

regards
Philipp

#185 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Hi Philipp,

On Tue, Feb 21, 2017 at 09:50:23AM +0100, Philipp Zabel wrote:
...

Quoted 22 lines
Quoted 22 lines
Quoted 14 lines

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

Quoted 4 lines

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

I agree, frame rate, if indicated/specified by both sides of a link, should match. So maybe this should be part of v4l2 link validation.

Quoted 8 lines
Quoted 1 line

This might be a good time to propose the following patch.

I agree with Steve and Russell. I don't see why the (nominal) frame interval should be handled differently than resolution, data format, and colorspace information. I think it should just be propagated in the same way, and there is no reason to have two connected pads set to a different interval. That would make implementing the g/s_frame_interval subdev calls mandatory.

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#186 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#187 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Which would include the frame interval returned by VIDIOC_G_PARM on the connected video device, as that gets its information from the CSI output pad's frame interval.

regards
Philipp

author maintainer
#188 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 30 lines · Philipp Zabel
Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Quoted 4 lines

Which would include the frame interval returned by VIDIOC_G_PARM on the connected video device, as that gets its information from the CSI output pad's frame interval.

I'm kinda in the middle on this topic. I agree with Sakari that frame rate can fluctuate, but that should only be temporary. If the frame rate permanently shifts from what a subdev reports via g_frame_interval, then that is a system problem. So I agree with Phillip and Russell that a link validation of frame interval still makes sense.

But I also have to agree with Sakari that a subdev that has no control over frame rate has no business implementing those ops.

And then I agree with Russell that for subdevs that do have control over frame rate, they would have to walk the graph to find the frame rate source.

So we're stuck in a broken situation: either the subdevs have to walk the graph to find the source of frame rate, or s_frame_interval would have to be mandatory and validated between pads, same as set_fmt.

Steve

#189 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Hi Steve,

Quoted 48 lines · Steve Longerbeam
Quoted 30 lines · Philipp Zabel
Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Quoted 4 lines

Which would include the frame interval returned by VIDIOC_G_PARM on the connected video device, as that gets its information from the CSI output pad's frame interval.

I'm kinda in the middle on this topic. I agree with Sakari that frame rate can fluctuate, but that should only be temporary. If the frame rate permanently shifts from what a subdev reports via g_frame_interval, then that is a system problem. So I agree with Phillip and Russell that a link validation of frame interval still makes sense.

But I also have to agree with Sakari that a subdev that has no control over frame rate has no business implementing those ops.

Quoted 7 lines

And then I agree with Russell that for subdevs that do have control over frame rate, they would have to walk the graph to find the frame rate source.

So we're stuck in a broken situation: either the subdevs have to walk the graph to find the source of frame rate, or s_frame_interval would have to be mandatory and validated between pads, same as set_fmt.

It's not broken; what we are missing though is documentation on how to control devices that can change the frame rate i.e. presumably drop frames occasionally.

If you're doing something that hasn't been done before, it may be that new documentation needs to be written to accomodate that use case. As we have an existing interface (VIDIOC_SUBDEV_[GS]_FRAME_INTERVAL) it does make sense to use that. What is not possible, though, is to mandate its use in link validation everywhere.

If you had a hardware limitation that would require that the frame rate is constant, then we'd need to handle that in link validation for that particular piece of hardware. But there really is no case for doing that for everything else.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#190 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 17 lines · Sakari Ailus

Hi Steve,

Quoted 14 lines · Steve Longerbeam

I'm kinda in the middle on this topic. I agree with Sakari that frame rate can fluctuate, but that should only be temporary. If the frame rate permanently shifts from what a subdev reports via g_frame_interval, then that is a system problem. So I agree with Phillip and Russell that a link validation of frame interval still makes sense.

But I also have to agree with Sakari that a subdev that has no control over frame rate has no business implementing those ops.

And then I agree with Russell that for subdevs that do have control over frame rate, they would have to walk the graph to find the frame rate source.

Quoted 7 lines
Quoted 3 lines

So we're stuck in a broken situation: either the subdevs have to walk the graph to find the source of frame rate, or s_frame_interval would have to be mandatory and validated between pads, same as set_fmt.

It's not broken; what we are missing though is documentation on how to control devices that can change the frame rate i.e. presumably drop frames occasionally.

It's not about "presumably drop frames occasionally." The definition of "occasional" is "occurring or appearing at irregular or infrequent intervals". Another word which describes what you're saying would be "randomly drop frames" which would be a quite absurd "feature" to include in hardware.

It's about _deterministically_ omitting frames from the capture.

The hardware provides two controls:
1. the size of a group of frames - between 1 and 5 frames
2. select which frames within the group are dropped using a bitmask

This gives a _regular_ pattern of dropped frames.

The rate scaling is given by: hweight(bitmask) / group size.

So, for example, if you're receiving a 50fps TV broadcast, and want to capture at 25fps, you can set the group size to 2, and set the frame drop to binary "01" or "10" - if it's interlaced, this would have the effect of selecting one field, or skipping every other frame if progressive.

That's not "we'll occasionally drop some frames", that's frame rate scaling. Just like you can scale the size of an image by omitting every other pixel and every other line, this hardware allows omitting every other frame or more.

So, to configure this feature, CSI needs to know two bits of information:

1. The _source_ frame rate.
2. The desired _sink_ frame rate.

Quoted 1 line

From that, it can compute how many frames to drop, and size of the group.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#191 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Sakari Ailus
Quoted 69 lines · Sakari Ailus

Hi Steve,

Quoted 48 lines · Steve Longerbeam
Quoted 30 lines · Philipp Zabel
Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Quoted 4 lines

Which would include the frame interval returned by VIDIOC_G_PARM on the connected video device, as that gets its information from the CSI output pad's frame interval.

I'm kinda in the middle on this topic. I agree with Sakari that frame rate can fluctuate, but that should only be temporary. If the frame rate permanently shifts from what a subdev reports via g_frame_interval, then that is a system problem. So I agree with Phillip and Russell that a link validation of frame interval still makes sense.

But I also have to agree with Sakari that a subdev that has no control over frame rate has no business implementing those ops.

Quoted 7 lines

And then I agree with Russell that for subdevs that do have control over frame rate, they would have to walk the graph to find the frame rate source.

So we're stuck in a broken situation: either the subdevs have to walk the graph to find the source of frame rate, or s_frame_interval would have to be mandatory and validated between pads, same as set_fmt.

It's not broken; what we are missing though is documentation on how to control devices that can change the frame rate i.e. presumably drop frames occasionally.

If you're doing something that hasn't been done before, it may be that new documentation needs to be written to accomodate that use case. As we have an existing interface (VIDIOC_SUBDEV_[GS]_FRAME_INTERVAL) it does make sense to use that. What is not possible, though, is to mandate its use in link validation everywhere.

Quoted 5 lines

If you had a hardware limitation that would require that the frame rate is constant, then we'd need to handle that in link validation for that particular piece of hardware. But there really is no case for doing that for everything else.

General note: I would strongly recommend that g/s_parm support is removed in v4l2_subdev in favor of g/s_frame_interval.

g/s_parm is an abomination...

There seem to be only a few i2c drivers that use g/s_parm, so this shouldn't be a lot of work.

Having two APIs for the same thing is always very bad.

Regards,

Hans

maintainer
#192 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 76 lines · Hans Verkuil
Quoted 69 lines · Sakari Ailus

Hi Steve,

Quoted 48 lines · Steve Longerbeam
Quoted 30 lines · Philipp Zabel
Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Quoted 4 lines

Which would include the frame interval returned by VIDIOC_G_PARM on the connected video device, as that gets its information from the CSI output pad's frame interval.

I'm kinda in the middle on this topic. I agree with Sakari that frame rate can fluctuate, but that should only be temporary. If the frame rate permanently shifts from what a subdev reports via g_frame_interval, then that is a system problem. So I agree with Phillip and Russell that a link validation of frame interval still makes sense.

But I also have to agree with Sakari that a subdev that has no control over frame rate has no business implementing those ops.

Quoted 7 lines

And then I agree with Russell that for subdevs that do have control over frame rate, they would have to walk the graph to find the frame rate source.

So we're stuck in a broken situation: either the subdevs have to walk the graph to find the source of frame rate, or s_frame_interval would have to be mandatory and validated between pads, same as set_fmt.

It's not broken; what we are missing though is documentation on how to control devices that can change the frame rate i.e. presumably drop frames occasionally.

If you're doing something that hasn't been done before, it may be that new documentation needs to be written to accomodate that use case. As we have an existing interface (VIDIOC_SUBDEV_[GS]_FRAME_INTERVAL) it does make sense to use that. What is not possible, though, is to mandate its use in link validation everywhere.

Quoted 5 lines

If you had a hardware limitation that would require that the frame rate is constant, then we'd need to handle that in link validation for that particular piece of hardware. But there really is no case for doing that for everything else.

Quoted 4 lines

General note: I would strongly recommend that g/s_parm support is removed in v4l2_subdev in favor of g/s_frame_interval.

g/s_parm is an abomination...

Agreed. Just in this specific case I was talking about G_PARM on the /dev/video node, not the v4l2_subdev nodes. This is currently used by non-subdev-aware userspace to obtain the framerate from the video capture device.

Quoted 9 lines

There seem to be only a few i2c drivers that use g/s_parm, so this shouldn't be a lot of work.

Having two APIs for the same thing is always very bad.

Regards,

Hans

regards
Philipp

#193 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Russell King - ARM Linux

Hi Russell,

Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

The user is responsible for configuring the pipeline. It is thus not unreasonable to as the user to configure the frame rate as well if there are device in the pipeline that can affect the frame rate. The way I proposed to implement it is compliant with the existing API and entirely deterministic, contrary to what you're saying.

It's not the job of the CSI sub-device to figure it out.

S_PARM and G_PARM function as interface on the V4L2 API to access the frame rate on plain V4L2 devices. The i.MX6 IPU is not a plain V4L2 device. Essentially the V4L2 device node you have there is an interface to a rather plain DMA engine, no more.

There have been plans to add device profiles to the documentation but that work has not yet been done.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#194 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 32 lines · Sakari Ailus

Hi Russell,

Quoted 22 lines · Russell King - ARM Linux
Quoted 10 lines · Sakari Ailus

The vast majority of existing drivers do not implement them nor the user space expects having to set them. Making that mandatory would break existing user space.

In addition, that does not belong to link validation either: link validation should only include static properties of the link that are required for correct hardware operation. Frame rate is not such property: hardware that supports the MC interface generally does not recognise such concept (with the exception of some sensors). Additionally, it is dynamic: the frame rate can change during streaming, making its validation at streamon time useless.

So how do we configure the CSI, which can do frame skipping?

With what you're proposing, it means it's possible to configure the camera sensor source pad to do 50fps. Configure the CSI sink pad to an arbitary value, such as 30fps, and configure the CSI source pad to 15fps.

What you actually get out of the CSI is 25fps, which bears very little with the actual values used on the CSI source pad.

Quoted 6 lines

You could say "CSI should ask the camera sensor" - well, that's fine if it's immediately downstream, but otherwise we'd need to go walking down the graph to find something that resembles its source - there may be mux and CSI2 interface subdev blocks in that path. Or we just accept that frame rates are completely arbitary and bear no useful meaning what so ever.

Quoted 5 lines

The user is responsible for configuring the pipeline. It is thus not unreasonable to as the user to configure the frame rate as well if there are device in the pipeline that can affect the frame rate. The way I proposed to implement it is compliant with the existing API and entirely deterministic, contrary to what you're saying.

You haven't really addressed my point at all.

What you seem to be saying is that you're quite happy for the situation (which is a total misconfiguration) to exist. Given the vapourware of userspace (which I don't see changing in any kind of reasonable timeline) I think this is completely absurd.

I'll state clearly now: everything that we've discussed so far, I'm finding very hard to take anything you've said seriously. I think we have very different and incompatible point of views about what is acceptable from a user point of view, so much so that we're never going to agree on any point.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#195 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

In reply to Russell King - ARM Linux

Hi Russell,

Quoted 30 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

Quoted 2 lines

The problem there is that the format setting for the csi2 does not get propagated forward:

The CSI-2 receivers typically do not implement frame interval IOCTLs as they do not control the frame interval. Some sensors or TV tuners typically do, so they implement these IOCTLs.

There are alternative ways to specify the frame rate.

Quoted 14 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++
Quoted 7 lines

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

You should remove the frame interval setting from sub-devices that do not support it.

Quoted 12 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
Quoted 8 lines

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

The origins of the S_FRAME_INTERVAL IOCTL for sub-devices are the S_PARM IOCTL for video nodes. It is used to control the frame rate for more simple devices that do not expose the Media controller interface. The similar S_FRAME_INTERVAL was added for sub-devices as well, and it has been so far used to control the frame interval for sensors (and G_FRAME_INTERVAL to obtain the frame interval for TV tuners, for instance).

The pad argument was added there but media-ctl only supported setting the frame interval on pad 0, which, coincidentally, worked well for sensor devices.

The link validation is primarily done in order to ensure the validity of the hardware configuration: streaming may not be started if the hardware configuration is not valid.

Also, frame interval is not a static property during streaming: it may be changed without the knowledge of the other sub-device drivers downstream. It neither is a property of hardware receiving or processing images: if there are limitations in processing pixels, then they in practice are related to pixel rates or image sizes (i.e. not frame rates).

Quoted 12 lines

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Quoted 3 lines

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

Skipping in the context is used to refer to sub-sampling. The term is often used in conjunction of sensors. The documentation could certainly be clarified here.

Quoted 15 lines

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

Quoted 6 lines

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

In any case, the documentation vs media-ctl create something of a very obscure situation, one that probably needs solving one way or another.

Before going to solutions I need to ask: what do you want to achieve?

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#196 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 33 lines · Sakari Ailus

Hi Russell,

Quoted 30 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

Quoted 6 lines
Quoted 2 lines

The problem there is that the format setting for the csi2 does not get propagated forward:

The CSI-2 receivers typically do not implement frame interval IOCTLs as they do not control the frame interval. Some sensors or TV tuners typically do, so they implement these IOCTLs.

No, TV tuners do not. The frame rate for a TV tuner is set by the broadcaster, not by the tuner. The tuner can't change that frame rate. The tuner may opt to "skip" fields or frames. That's no different from what the CSI block in my example below is capable of doing.

Treating a tuner differently from the CSI block is inconsistent and completely wrong.

Quoted 1 line

There are alternative ways to specify the frame rate.

Empty statements (or hand-waving type statements) I'm afraid don't contribute to the discussion, because they mean nothing to me. Please give an example, or flesh out what you mean.

Quoted 16 lines
Quoted 16 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

Quoted 7 lines
Quoted 4 lines

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

You should remove the frame interval setting from sub-devices that do not support it.

That means we end up with horribly complex scripts. This "solution" does not scale. Therefore, it is not a "solution".

It's fine if you want to write a script to setup the media pipeline using media-ctl, listing _each_ media-ctl command individually, with arguments specific to each step, but as I've already said, that does not scale.

I don't want to end up writing separate scripts to configure the pipeline for different parameters or setups. I don't want to teach users how to do that either.

How are users supposed to cope with this craziness? Are they expected to write their own scripts and understand this stuff?

As far as I can see, there are no applications out there at the moment that come close to understanding how to configure a media pipeline, so users have to understand how to use media-ctl to configure the pipeline manually. Are we really expecting users to write scripts to do this, and understand all these nuances?

IMHO, this is completely crazy, and hasn't been fully thought out.

Quoted 35 lines
Quoted 11 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
Quoted 8 lines

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

The origins of the S_FRAME_INTERVAL IOCTL for sub-devices are the S_PARM IOCTL for video nodes. It is used to control the frame rate for more simple devices that do not expose the Media controller interface. The similar S_FRAME_INTERVAL was added for sub-devices as well, and it has been so far used to control the frame interval for sensors (and G_FRAME_INTERVAL to obtain the frame interval for TV tuners, for instance).

The pad argument was added there but media-ctl only supported setting the frame interval on pad 0, which, coincidentally, worked well for sensor devices.

The link validation is primarily done in order to ensure the validity of the hardware configuration: streaming may not be started if the hardware configuration is not valid.

Quoted 5 lines

Also, frame interval is not a static property during streaming: it may be changed without the knowledge of the other sub-device drivers downstream. It neither is a property of hardware receiving or processing images: if there are limitations in processing pixels, then they in practice are related to pixel rates or image sizes (i.e. not frame rates).

So what about the case where we have a subdev (CSI) that is capable of frame rate reduction, that needs to know the input frame rate and the desired output frame rate? It seems to me that this has not been thought through...

Quoted 11 lines
Quoted 11 lines

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Quoted 7 lines
Quoted 3 lines

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

Skipping in the context is used to refer to sub-sampling. The term is often used in conjunction of sensors. The documentation could certainly be clarified here.

It definitely needs to be, it's currently mis-leading.

Quoted 14 lines
Quoted 14 lines

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

Quoted 8 lines
Quoted 6 lines

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

In any case, the documentation vs media-ctl create something of a very obscure situation, one that probably needs solving one way or another.

Before going to solutions I need to ask: what do you want to achieve?

Full and consistent support for the hardware, and a sane and consistent way to setup a media pipeline that is easy for everyone to understand.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#197 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Hi Russell,

Quoted 41 lines · Russell King - ARM Linux
Quoted 33 lines · Sakari Ailus

Hi Russell,

Quoted 30 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

Quoted 6 lines
Quoted 2 lines

The problem there is that the format setting for the csi2 does not get propagated forward:

The CSI-2 receivers typically do not implement frame interval IOCTLs as they do not control the frame interval. Some sensors or TV tuners typically do, so they implement these IOCTLs.

Quoted 7 lines

No, TV tuners do not. The frame rate for a TV tuner is set by the broadcaster, not by the tuner. The tuner can't change that frame rate. The tuner may opt to "skip" fields or frames. That's no different from what the CSI block in my example below is capable of doing.

Treating a tuner differently from the CSI block is inconsistent and completely wrong.

I agree tuners in that sense are somewhat similar, and they are not treated differently because they are tuners (and not CSI-2 receivers). Neither can control the frame rate of the incoming video stream.

Conceivably a tuner could implement G_FRAME_INTERVAL IOCTL, but based on a quick glance none appears to. Neither do CSI-2 receivers. Only sensor drivers do currently.

Quoted 6 lines
Quoted 2 lines

There are alternative ways to specify the frame rate.

Empty statements (or hand-waving type statements) I'm afraid don't contribute to the discussion, because they mean nothing to me. Please give an example, or flesh out what you mean.

Images are transmitted as series of lines, with each line ending in a horizontal blanking period, and each frame ending with a similar period of vertical blanking. The blanking configuration in the units of pixels and lines at their pixel clock is a native unit which sensors typically use, and some drivers expose the blanking controls directly to the user.

<URL:http://hverkuil.home.xs4all.nl/spec/uapi/v4l/extended-controls.html#image-source-control-ids>

Quoted 25 lines
Quoted 17 lines
Quoted 17 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbec16244) = 0
ioctl(3, VIDIOC_SUBDEV_S_FRAME_INTERVAL, 0xbec162a4) = -1 ENOTTY (Inappropriate
ioctl for device)
fstat64(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 2), ...}) = 0
write(1, "Unable to setup formats: Inappro"..., 61) = 61
Unable to setup formats: Inappropriate ioctl for device (25)
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

because media-ctl exits as soon as it encouters the error while trying to set the frame rate.

Quoted 7 lines
Quoted 4 lines

This makes implementing setup of the media pipeline in shell scripts unnecessarily difficult - as you need to then know whether an entity is likely not to support the VIDIOC_SUBDEV_S_FRAME_INTERVAL call, and either avoid specifying a frame rate:

You should remove the frame interval setting from sub-devices that do not support it.

Quoted 2 lines

That means we end up with horribly complex scripts. This "solution" does not scale. Therefore, it is not a "solution".

I have to disagree with that: if a piece of hardware does not offer to control or, if a concept is not even relevant for a piece of hardware, then a driver for that piece of hardware should not expose an interface to control such a feature. Doing so would provide no value and at the same time would be simply confusing for the user space.

Quoted 4 lines

It's fine if you want to write a script to setup the media pipeline using media-ctl, listing _each_ media-ctl command individually, with arguments specific to each step, but as I've already said, that does not scale.

Pipeline configuration as such is highly hardware specific. There are rules, but there are details in hardware that have to be taken into account, such as mandated cropping in certain situations. You have to simply accept that:
when it comes to camera Image Signal Processors, there are no standard pipelines. Each ISP is different from the rest, more or less, and often more so.

As the interface is generic, you can write generic programs that use that interface, but you need to be able to adapt to the differences in the functionality of the hardware.

Frankly, I think this is just needless noise stemming from a problem that's not really difficult to solve --- if that technical problem really even exists. But let's not debate that; I accept that dropping frames is what you're willing to do.

Quoted 57 lines

I don't want to end up writing separate scripts to configure the pipeline for different parameters or setups. I don't want to teach users how to do that either.

How are users supposed to cope with this craziness? Are they expected to write their own scripts and understand this stuff?

As far as I can see, there are no applications out there at the moment that come close to understanding how to configure a media pipeline, so users have to understand how to use media-ctl to configure the pipeline manually. Are we really expecting users to write scripts to do this, and understand all these nuances?

IMHO, this is completely crazy, and hasn't been fully thought out.

Quoted 35 lines
Quoted 11 lines
$ strace media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616]'
...
open("/dev/v4l-subdev16", O_RDWR)       = 3
ioctl(3, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
open("/dev/v4l-subdev0", O_RDWR)        = 4
ioctl(4, VIDIOC_SUBDEV_S_FMT, 0xbeb1a254) = 0
close(4)                                = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++
Quoted 8 lines

or manually setting the format on the sink.

Allowing the S_FRAME_INTERVAL call seems to me to be more in keeping with the negotiation mechanism that is implemented in subdevs, and IMHO should be implemented inside the kernel as a pad operation along with the format negotiation, especially so as frame skipping is defined as scaling, in just the same way as the frame size is also scaling:

The origins of the S_FRAME_INTERVAL IOCTL for sub-devices are the S_PARM IOCTL for video nodes. It is used to control the frame rate for more simple devices that do not expose the Media controller interface. The similar S_FRAME_INTERVAL was added for sub-devices as well, and it has been so far used to control the frame interval for sensors (and G_FRAME_INTERVAL to obtain the frame interval for TV tuners, for instance).

The pad argument was added there but media-ctl only supported setting the frame interval on pad 0, which, coincidentally, worked well for sensor devices.

The link validation is primarily done in order to ensure the validity of the hardware configuration: streaming may not be started if the hardware configuration is not valid.

Quoted 5 lines

Also, frame interval is not a static property during streaming: it may be changed without the knowledge of the other sub-device drivers downstream. It neither is a property of hardware receiving or processing images: if there are limitations in processing pixels, then they in practice are related to pixel rates or image sizes (i.e. not frame rates).

Quoted 4 lines

So what about the case where we have a subdev (CSI) that is capable of frame rate reduction, that needs to know the input frame rate and the desired output frame rate? It seems to me that this has not been thought through...

That's because I believe you're the first one wanting to willfully throw away perfectly good frames. :-)

If you want to do that, a simple option could be to just support [GS]_FRAME_INTERVAL on all pads of a sub-device that can drop frames. But it should not be include in pipeline validation, it simply does not belong there for the reasons stated previously.

The user would be responsible for configuring the frame rates right. That information would simply be used to configure frame dropping frequency.

I'd like to have a comment from Laurent and Hans on this.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

- ``MEDIA_ENT_F_PROC_VIDEO_SCALER``

- Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and skipping are considered as scaling.

Although, this is vague, as it doesn't define what it means by "skipping", whether that's skipping pixels (iow, sub-sampling) or whether that's frame skipping.

Quoted 5 lines
Quoted 3 lines

Skipping in the context is used to refer to sub-sampling. The term is often used in conjunction of sensors. The documentation could certainly be clarified here.

It definitely needs to be, it's currently mis-leading.

If you're not familiar with terminology typically used with many camera sensor, perhaps so. The documentation should indeed not assume that; I'll submit a patch to fix that.

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines

Then there's the issue where, if you have this setup:

camera --> csi2 receiver --> csi --> capture

and the "csi" subdev can skip frames, you need to know (a) at the CSI sink pad what the frame rate is of the source (b) what the desired source pad frame rate is, so you can configure the frame skipping. So, does the csi subdev have to walk back through the media graph looking for the frame rate? Does the capture device have to walk back through the media graph looking for some subdev to tell it what the frame rate is - the capture device certainly can't go straight to the sensor to get an answer to that question, because that bypasses the effect of the CSI frame skipping (which will lower the frame rate.)

IMHO, frame rate is just another format property, just like the resolution and data format itself, and v4l2 should be treating it no differently.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In any case, the documentation vs media-ctl create something of a very obscure situation, one that probably needs solving one way or another.

Before going to solutions I need to ask: what do you want to achieve?

Full and consistent support for the hardware, and a sane and consistent way to setup a media pipeline that is easy for everyone to understand.

That's essentially what we do have: the same interface is supported on a large variety of different hardware devices. However, not all IOCTLs are supported by all device drivers.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#198 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 52 lines · Sakari Ailus

Hi Russell,

Quoted 41 lines · Russell King - ARM Linux
Quoted 33 lines · Sakari Ailus

Hi Russell,

Quoted 30 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

Quoted 6 lines
Quoted 2 lines

The problem there is that the format setting for the csi2 does not get propagated forward:

The CSI-2 receivers typically do not implement frame interval IOCTLs as they do not control the frame interval. Some sensors or TV tuners typically do, so they implement these IOCTLs.

Quoted 7 lines

No, TV tuners do not. The frame rate for a TV tuner is set by the broadcaster, not by the tuner. The tuner can't change that frame rate. The tuner may opt to "skip" fields or frames. That's no different from what the CSI block in my example below is capable of doing.

Treating a tuner differently from the CSI block is inconsistent and completely wrong.

Quoted 7 lines

I agree tuners in that sense are somewhat similar, and they are not treated differently because they are tuners (and not CSI-2 receivers). Neither can control the frame rate of the incoming video stream.

Conceivably a tuner could implement G_FRAME_INTERVAL IOCTL, but based on a quick glance none appears to. Neither do CSI-2 receivers. Only sensor drivers do currently.

Please look again. I am being very careful with "CSI" vs "CSI-2" in my emails, you are conflating the two.

In all my emails so far, "CSI" refers to a block of hardware that is responsible for receiving an image stream from some kind of source. It contains hardware that supports frame skipping.

"CSI-2" refers to a different block of hardware that is responsible for receiving a serially encoded stream from a MIPI-CSI-2 compliant source and providing it to the "CSI" block.

I would have thought my diagram that I drew would have made it clear that they were different blocks of hardware, but I guess in this case, the old saying "a picture is worth 1000 words" is simply not true.

Quoted 2 lines

Images are transmitted as series of lines, with each line ending in a horizontal blanking period, and each frame ending with a similar period of

I'm sorry, are you seriously teaching me to suck rocks? I am insulted.

I've been involved in TV and video for many years, I don't need you to tell me how video is transmitted.

Sorry, you've just lost my interest in further discussion.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
#199 lore raw

Re: [PATCH v4 29/36] media: imx: mipi-csi2: enable setting and getting of frame rates

Quoted 61 lines · Russell King - ARM Linux
Quoted 52 lines · Sakari Ailus

Hi Russell,

Quoted 41 lines · Russell King - ARM Linux
Quoted 33 lines · Sakari Ailus

Hi Russell,

Quoted 30 lines · Russell King - ARM Linux
Quoted 8 lines · Sakari Ailus
Quoted 5 lines · Steve Longerbeam

From: Russell King <[email protected]>

Setting and getting frame rates is part of the negotiation mechanism between subdevs. The lack of support means that a frame rate at the sensor can't be negotiated through the subdev path.

Just wondering --- what do you need this for?

The v4l2 documentation contradicts the media-ctl implementation.

While v4l2 documentation says:

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

However, when trying to configure the pipeline using media-ctl, eg:

media-ctl -d /dev/media1 --set-v4l2 '"imx219 pixel 0-0010":0[crop:(0,0)/3264x2464]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":1[fmt:SRGGB10/3264x2464 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx219 0-0010":0[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"imx6-mipi-csi2":1[fmt:SRGGB8/816x616 at 1/30]' Unable to setup formats: Inappropriate ioctl for device (25)
media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0_mux":2[fmt:SRGGB8/816x616 at 1/30]' media-ctl -d /dev/media1 --set-v4l2 '"ipu1_csi0":2[fmt:SRGGB8/816x616 at 1/30]'

Quoted 6 lines
Quoted 2 lines

The problem there is that the format setting for the csi2 does not get propagated forward:

The CSI-2 receivers typically do not implement frame interval IOCTLs as they do not control the frame interval. Some sensors or TV tuners typically do, so they implement these IOCTLs.

Quoted 7 lines

No, TV tuners do not. The frame rate for a TV tuner is set by the broadcaster, not by the tuner. The tuner can't change that frame rate. The tuner may opt to "skip" fields or frames. That's no different from what the CSI block in my example below is capable of doing.

Treating a tuner differently from the CSI block is inconsistent and completely wrong.

Quoted 7 lines

I agree tuners in that sense are somewhat similar, and they are not treated differently because they are tuners (and not CSI-2 receivers). Neither can control the frame rate of the incoming video stream.

Conceivably a tuner could implement G_FRAME_INTERVAL IOCTL, but based on a quick glance none appears to. Neither do CSI-2 receivers. Only sensor drivers do currently.

Quoted 6 lines

Please look again. I am being very careful with "CSI" vs "CSI-2" in my emails, you are conflating the two.

In all my emails so far, "CSI" refers to a block of hardware that is responsible for receiving an image stream from some kind of source. It contains hardware that supports frame skipping.

Ah, I missed the difference. Thanks for pointing it out.

Still, that does not change how the skipping would work nor how I proposed it would be configured from the user space.

Quoted 12 lines

"CSI-2" refers to a different block of hardware that is responsible for receiving a serially encoded stream from a MIPI-CSI-2 compliant source and providing it to the "CSI" block.

I would have thought my diagram that I drew would have made it clear that they were different blocks of hardware, but I guess in this case, the old saying "a picture is worth 1000 words" is simply not true.

Quoted 2 lines

Images are transmitted as series of lines, with each line ending in a horizontal blanking period, and each frame ending with a similar period of

Quoted 6 lines

I'm sorry, are you seriously teaching me to suck rocks? I am insulted.

I've been involved in TV and video for many years, I don't need you to tell me how video is transmitted.

Sorry, you've just lost my interest in further discussion.

There's no need to feel insulted; that certainly was not the intention.

I've proposed you a solution, please comment on that.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
author maintainer
#200 lore raw

PATCH v4 30/36 media: imx: update capture dev format on IDMAC output pad set_fmt

In reply to Steve Longerbeam

When configuring the IDMAC output pad formats (in ipu_csi, ipu_ic_prpenc, and ipu_ic_prpvf subdevs), the attached capture device format must also be updated.

---
 drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +++++++++
 drivers/staging/media/imx/imx-media-csi.c   | 9 +++++++++
 2 files changed, 18 insertions(+)
drivers/staging/media/imx/imx-ic-prpencvf.c +9 -0
index 2be8845..6e45975 100644
@@ -739,6 +739,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_format *sdformat)
 {
 	struct prp_priv *priv = sd_to_priv(sd);
+	struct imx_media_video_dev *vdev = priv->vdev;
 	const struct imx_media_pixfmt *cc;
 	struct v4l2_mbus_framefmt *infmt;
 	u32 code;
@@ -800,6 +801,14 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	} else {
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+		if (sdformat->pad == PRPENCVF_SRC_PAD) {
+			/*
+			 * update the capture device format if this is
+			 * the IDMAC output pad
+			 */
+			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
+						      &sdformat->format, cc);
+		}
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-csi.c +9 -0
index 3cb97e2..63555dc 100644
@@ -866,6 +866,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_format *sdformat)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	struct imx_media_video_dev *vdev = priv->vdev;
 	const struct imx_media_pixfmt *cc, *incc;
 	struct v4l2_mbus_framefmt *infmt;
 	struct imx_media_subdev *sensor;
@@ -980,6 +981,14 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		/* Reset the crop window if this is the input pad */
 		if (sdformat->pad == CSI_SINK_PAD)
 			priv->crop = crop;
+		else if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
+			/*
+			 * update the capture device format if this is
+			 * the IDMAC output pad
+			 */
+			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
+						      &sdformat->format, cc);
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
maintainer
#201 lore raw

Re: [PATCH v4 30/36] media: imx: update capture dev format on IDMAC output pad set_fmt

Quoted 25 lines · Steve Longerbeam

When configuring the IDMAC output pad formats (in ipu_csi, ipu_ic_prpenc, and ipu_ic_prpvf subdevs), the attached capture device format must also be updated.

---
 drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +++++++++
 drivers/staging/media/imx/imx-media-csi.c   | 9 +++++++++
 2 files changed, 18 insertions(+)
drivers/staging/media/imx/imx-ic-prpencvf.c +1 -0
index 2be8845..6e45975 100644
@@ -739,6 +739,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_format *sdformat)
 {
 	struct prp_priv *priv = sd_to_priv(sd);
+	struct imx_media_video_dev *vdev = priv->vdev;
 	const struct imx_media_pixfmt *cc;
 	struct v4l2_mbus_framefmt *infmt;
 	u32 code;
@@ -800,6 +801,14 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	} else {

drivers/staging/media/imx/imx-ic-prpencvf.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 811

Quoted 10 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +8 -0
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+		if (sdformat->pad == PRPENCVF_SRC_PAD) {
+			/*
+			 * update the capture device format if this is
+			 * the IDMAC output pad
+			 */
+			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
+						      &sdformat->format, cc);
+		}

This is replaced again by patch 36. These should probably be squashed together.

regards
Philipp

author maintainer
#202 lore raw

PATCH v4 31/36 media: imx: csi: add __csi_get_fmt

In reply to Steve Longerbeam

Add __csi_get_fmt() and use it to return the correct mbus format (active or try) in get_fmt. Use it in other places as well.

---
 drivers/staging/media/imx/imx-media-csi.c | 52 ++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 12 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +40 -12
index 63555dc..b0aac82 100644
@@ -788,7 +788,20 @@ static int csi_eof_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
 	return 0;
 }
 
-static int csi_try_crop(struct csi_priv *priv, struct v4l2_rect *crop,
+static struct v4l2_mbus_framefmt *
+__csi_get_fmt(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg,
+	      unsigned int pad, enum v4l2_subdev_format_whence which)
+{
+	if (which == V4L2_SUBDEV_FORMAT_TRY)
+		return v4l2_subdev_get_try_format(&priv->sd, cfg, pad);
+	else
+		return &priv->format_mbus[pad];
+}
+
+static int csi_try_crop(struct csi_priv *priv,
+			struct v4l2_rect *crop,
+			struct v4l2_subdev_pad_config *cfg,
+			enum v4l2_subdev_format_whence which,
 			struct imx_media_subdev *sensor)
 {
 	struct v4l2_of_endpoint *sensor_ep;
@@ -796,7 +809,7 @@ static int csi_try_crop(struct csi_priv *priv, struct v4l2_rect *crop,
 	v4l2_std_id std;
 	int ret;
 
-	infmt = &priv->format_mbus[CSI_SINK_PAD];
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, which);
 	sensor_ep = &sensor->sensor_ep;
 
 	crop->width = min_t(__u32, infmt->width, crop->width);
@@ -852,11 +865,16 @@ static int csi_get_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_format *sdformat)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	struct v4l2_mbus_framefmt *fmt;
 
 	if (sdformat->pad >= CSI_NUM_PADS)
 		return -EINVAL;
 
-	sdformat->format = priv->format_mbus[sdformat->pad];
+	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+	if (!fmt)
+		return -EINVAL;
+
+	sdformat->format = *fmt;
 
 	return 0;
 }
@@ -880,8 +898,6 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	if (priv->stream_on)
 		return -EBUSY;
 
-	infmt = &priv->format_mbus[CSI_SINK_PAD];
-
 	sensor = imx_media_find_sensor(priv->md, &priv->sd.entity);
 	if (IS_ERR(sensor)) {
 		v4l2_err(&priv->sd, "no sensor attached\n");
@@ -895,6 +911,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	switch (sdformat->pad) {
 	case CSI_SRC_PAD_DIRECT:
 	case CSI_SRC_PAD_IDMAC:
+		infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which);
+
 		if (sdformat->format.width < priv->crop.width * 3 / 4)
 			sdformat->format.width = priv->crop.width / 2;
 		else
@@ -957,7 +975,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		crop.top = 0;
 		crop.width = sdformat->format.width;
 		crop.height = sdformat->format.height;
-		ret = csi_try_crop(priv, &crop, sensor);
+		ret = csi_try_crop(priv, &crop, cfg,
+				   sdformat->which, sensor);
 		if (ret)
 			return ret;
 
@@ -1004,7 +1023,9 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 	if (sel->pad >= CSI_NUM_PADS || sel->pad == CSI_SINK_PAD)
 		return -EINVAL;
 
-	infmt = &priv->format_mbus[CSI_SINK_PAD];
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
+	if (!infmt)
+		return -EINVAL;
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_CROP_BOUNDS:
@@ -1014,7 +1035,14 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 		sel->r.height = infmt->height;
 		break;
 	case V4L2_SEL_TGT_CROP:
-		sel->r = priv->crop;
+		if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
+			struct v4l2_rect *try_crop =
+				v4l2_subdev_get_try_crop(&priv->sd,
+							 cfg, sel->pad);
+			sel->r = *try_crop;
+		} else {
+			sel->r = priv->crop;
+		}
 		break;
 	default:
 		return -EINVAL;
@@ -1028,7 +1056,6 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_selection *sel)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
-	struct v4l2_mbus_framefmt *outfmt;
 	struct imx_media_subdev *sensor;
 	int ret;
 
@@ -1058,15 +1085,16 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 		return 0;
 	}
 
-	outfmt = &priv->format_mbus[sel->pad];
-
-	ret = csi_try_crop(priv, &sel->r, sensor);
+	ret = csi_try_crop(priv, &sel->r, cfg, sel->which, sensor);
 	if (ret)
 		return ret;
 
 	if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_crop = sel->r;
 	} else {
+		struct v4l2_mbus_framefmt *outfmt =
+			&priv->format_mbus[sel->pad];
+
 		priv->crop = sel->r;
 		/* Update the source format */
 		outfmt->width = sel->r.width;
Signature · 1 line
2.7.4
author maintainer
#203 lore raw

PATCH v4 32/36 media: imx: csi/fim: add support for frame intervals

In reply to Steve Longerbeam

Add support to CSI for negotiation of frame intervals, and use this information to configure the frame interval monitor.

---
 drivers/staging/media/imx/imx-media-csi.c | 36 ++++++++++++++++++++++++++++---
 drivers/staging/media/imx/imx-media-fim.c | 28 +++++++++---------------
 drivers/staging/media/imx/imx-media.h     |  2 +-
 3 files changed, 44 insertions(+), 22 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +33 -3
index b0aac82..040cca6 100644
@@ -56,6 +56,7 @@ struct csi_priv {
 
 	struct v4l2_mbus_framefmt format_mbus[CSI_NUM_PADS];
 	const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
+	struct v4l2_fract frame_interval;
 	struct v4l2_rect crop;
 
 	/* the video device at IDMAC output pad */
@@ -565,7 +566,8 @@ static int csi_start(struct csi_priv *priv)
 
 	/* start the frame interval monitor */
 	if (priv->fim) {
-		ret = imx_media_fim_set_stream(priv->fim, priv->sensor, true);
+		ret = imx_media_fim_set_stream(priv->fim,
+					       &priv->frame_interval, true);
 		if (ret)
 			goto idmac_stop;
 	}
@@ -580,7 +582,8 @@ static int csi_start(struct csi_priv *priv)
 
 fim_off:
 	if (priv->fim)
-		imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+		imx_media_fim_set_stream(priv->fim,
+					 &priv->frame_interval, false);
 idmac_stop:
 	if (priv->dest == IPU_CSI_DEST_IDMAC)
 		csi_idmac_stop(priv);
@@ -594,11 +597,36 @@ static void csi_stop(struct csi_priv *priv)
 
 	/* stop the frame interval monitor */
 	if (priv->fim)
-		imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+		imx_media_fim_set_stream(priv->fim,
+					 &priv->frame_interval, false);
 
 	ipu_csi_disable(priv->csi);
 }
 
+static int csi_g_frame_interval(struct v4l2_subdev *sd,
+				struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+	fi->interval = priv->frame_interval;
+
+	return 0;
+}
+
+static int csi_s_frame_interval(struct v4l2_subdev *sd,
+				struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+	/* Output pads mirror active input pad, no limits on input pads */
+	if (fi->pad == CSI_SRC_PAD_IDMAC || fi->pad == CSI_SRC_PAD_DIRECT)
+		fi->interval = priv->frame_interval;
+
+	priv->frame_interval = fi->interval;
+
+	return 0;
+}
+
 static int csi_s_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
@@ -1187,6 +1215,8 @@ static struct v4l2_subdev_core_ops csi_core_ops = {
 };
 
 static struct v4l2_subdev_video_ops csi_video_ops = {
+	.g_frame_interval = csi_g_frame_interval,
+	.s_frame_interval = csi_s_frame_interval,
 	.s_stream = csi_s_stream,
 };
 
drivers/staging/media/imx/imx-media-fim.c +10 -18
index acc7e39..a6ed57e 100644
@@ -67,26 +67,18 @@ struct imx_media_fim {
 };
 
 static void update_fim_nominal(struct imx_media_fim *fim,
-			       struct imx_media_subdev *sensor)
+			       const struct v4l2_fract *fi)
 {
-	struct v4l2_streamparm parm;
-	struct v4l2_fract tpf;
-	int ret;
-
-	parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-	ret = v4l2_subdev_call(sensor->sd, video, g_parm, &parm);
-	tpf = parm.parm.capture.timeperframe;
-
-	if (ret || tpf.denominator == 0) {
-		dev_dbg(fim->sd->dev, "no tpf from sensor, FIM disabled\n");
+	if (fi->denominator == 0) {
+		dev_dbg(fim->sd->dev, "no frame interval, FIM disabled\n");
 		fim->enabled = false;
 		return;
 	}
 
-	fim->nominal = DIV_ROUND_CLOSEST(1000 * 1000 * tpf.numerator,
-					 tpf.denominator);
+	fim->nominal = DIV_ROUND_CLOSEST_ULL(1000000ULL * (u64)fi->numerator,
+					     fi->denominator);
 
-	dev_dbg(fim->sd->dev, "sensor FI=%lu usec\n", fim->nominal);
+	dev_dbg(fim->sd->dev, "FI=%lu usec\n", fim->nominal);
 }
 
 static void reset_fim(struct imx_media_fim *fim, bool curval)
@@ -130,8 +122,8 @@ static void send_fim_event(struct imx_media_fim *fim, unsigned long error)
 
 /*
  * Monitor an averaged frame interval. If the average deviates too much
- * from the sensor's nominal frame rate, send the frame interval error
- * event. The frame intervals are averaged in order to quiet noise from
+ * from the nominal frame rate, send the frame interval error event. The
+ * frame intervals are averaged in order to quiet noise from
  * (presumably random) interrupt latency.
  */
 static void frame_interval_monitor(struct imx_media_fim *fim,
@@ -422,12 +414,12 @@ EXPORT_SYMBOL_GPL(imx_media_fim_set_power);
 
 /* Called by the subdev in its s_stream callback */
 int imx_media_fim_set_stream(struct imx_media_fim *fim,
-			     struct imx_media_subdev *sensor,
+			     const struct v4l2_fract *fi,
 			     bool on)
 {
 	if (on) {
 		reset_fim(fim, true);
-		update_fim_nominal(fim, sensor);
+		update_fim_nominal(fim, fi);
 
 		if (fim->icap_channel >= 0)
 			fim_acquire_first_ts(fim);
drivers/staging/media/imx/imx-media.h +1 -1
index ae3af0d..7f19739 100644
@@ -259,7 +259,7 @@ struct imx_media_fim;
 void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts);
 int imx_media_fim_set_power(struct imx_media_fim *fim, bool on);
 int imx_media_fim_set_stream(struct imx_media_fim *fim,
-			     struct imx_media_subdev *sensor,
+			     const struct v4l2_fract *frame_interval,
 			     bool on);
 struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd);
 void imx_media_fim_free(struct imx_media_fim *fim);
Signature · 1 line
2.7.4
#204 lore raw

Re: [PATCH v4 32/36] media: imx: csi/fim: add support for frame intervals

Sorry, I forgot to change authorship on this patch. It should be authored by Russell King <[email protected]>.

Steve

Quoted 166 lines · Steve Longerbeam

Add support to CSI for negotiation of frame intervals, and use this information to configure the frame interval monitor.

---
  drivers/staging/media/imx/imx-media-csi.c | 36 ++++++++++++++++++++++++++++---
  drivers/staging/media/imx/imx-media-fim.c | 28 +++++++++---------------
  drivers/staging/media/imx/imx-media.h     |  2 +-
  3 files changed, 44 insertions(+), 22 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +33 -3
index b0aac82..040cca6 100644
@@ -56,6 +56,7 @@ struct csi_priv {
 
  	struct v4l2_mbus_framefmt format_mbus[CSI_NUM_PADS];
  	const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
+	struct v4l2_fract frame_interval;
  	struct v4l2_rect crop;
 
  	/* the video device at IDMAC output pad */
@@ -565,7 +566,8 @@ static int csi_start(struct csi_priv *priv)
 
  	/* start the frame interval monitor */
  	if (priv->fim) {
-		ret = imx_media_fim_set_stream(priv->fim, priv->sensor, true);
+		ret = imx_media_fim_set_stream(priv->fim,
+					       &priv->frame_interval, true);
  		if (ret)
  			goto idmac_stop;
  	}
@@ -580,7 +582,8 @@ static int csi_start(struct csi_priv *priv)
 
  fim_off:
  	if (priv->fim)
-		imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+		imx_media_fim_set_stream(priv->fim,
+					 &priv->frame_interval, false);
  idmac_stop:
  	if (priv->dest == IPU_CSI_DEST_IDMAC)
  		csi_idmac_stop(priv);
@@ -594,11 +597,36 @@ static void csi_stop(struct csi_priv *priv)
 
  	/* stop the frame interval monitor */
  	if (priv->fim)
-		imx_media_fim_set_stream(priv->fim, priv->sensor, false);
+		imx_media_fim_set_stream(priv->fim,
+					 &priv->frame_interval, false);
 
  	ipu_csi_disable(priv->csi);
  }
 
+static int csi_g_frame_interval(struct v4l2_subdev *sd,
+				struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+	fi->interval = priv->frame_interval;
+
+	return 0;
+}
+
+static int csi_s_frame_interval(struct v4l2_subdev *sd,
+				struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+	/* Output pads mirror active input pad, no limits on input pads */
+	if (fi->pad == CSI_SRC_PAD_IDMAC || fi->pad == CSI_SRC_PAD_DIRECT)
+		fi->interval = priv->frame_interval;
+
+	priv->frame_interval = fi->interval;
+
+	return 0;
+}
+
  static int csi_s_stream(struct v4l2_subdev *sd, int enable)
  {
  	struct csi_priv *priv = v4l2_get_subdevdata(sd);
@@ -1187,6 +1215,8 @@ static struct v4l2_subdev_core_ops csi_core_ops = {
  };
 
  static struct v4l2_subdev_video_ops csi_video_ops = {
+	.g_frame_interval = csi_g_frame_interval,
+	.s_frame_interval = csi_s_frame_interval,
  	.s_stream = csi_s_stream,
  };
 
drivers/staging/media/imx/imx-media-fim.c +10 -18
index acc7e39..a6ed57e 100644
@@ -67,26 +67,18 @@ struct imx_media_fim {
  };
 
  static void update_fim_nominal(struct imx_media_fim *fim,
-			       struct imx_media_subdev *sensor)
+			       const struct v4l2_fract *fi)
  {
-	struct v4l2_streamparm parm;
-	struct v4l2_fract tpf;
-	int ret;
-
-	parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-	ret = v4l2_subdev_call(sensor->sd, video, g_parm, &parm);
-	tpf = parm.parm.capture.timeperframe;
-
-	if (ret || tpf.denominator == 0) {
-		dev_dbg(fim->sd->dev, "no tpf from sensor, FIM disabled\n");
+	if (fi->denominator == 0) {
+		dev_dbg(fim->sd->dev, "no frame interval, FIM disabled\n");
  		fim->enabled = false;
  		return;
  	}
 
-	fim->nominal = DIV_ROUND_CLOSEST(1000 * 1000 * tpf.numerator,
-					 tpf.denominator);
+	fim->nominal = DIV_ROUND_CLOSEST_ULL(1000000ULL * (u64)fi->numerator,
+					     fi->denominator);
 
-	dev_dbg(fim->sd->dev, "sensor FI=%lu usec\n", fim->nominal);
+	dev_dbg(fim->sd->dev, "FI=%lu usec\n", fim->nominal);
  }
 
  static void reset_fim(struct imx_media_fim *fim, bool curval)
@@ -130,8 +122,8 @@ static void send_fim_event(struct imx_media_fim *fim, unsigned long error)
 
  /*
   * Monitor an averaged frame interval. If the average deviates too much
- * from the sensor's nominal frame rate, send the frame interval error
- * event. The frame intervals are averaged in order to quiet noise from
+ * from the nominal frame rate, send the frame interval error event. The
+ * frame intervals are averaged in order to quiet noise from
   * (presumably random) interrupt latency.
   */
  static void frame_interval_monitor(struct imx_media_fim *fim,
@@ -422,12 +414,12 @@ EXPORT_SYMBOL_GPL(imx_media_fim_set_power);
 
  /* Called by the subdev in its s_stream callback */
  int imx_media_fim_set_stream(struct imx_media_fim *fim,
-			     struct imx_media_subdev *sensor,
+			     const struct v4l2_fract *fi,
  			     bool on)
  {
  	if (on) {
  		reset_fim(fim, true);
-		update_fim_nominal(fim, sensor);
+		update_fim_nominal(fim, fi);
 
  		if (fim->icap_channel >= 0)
  			fim_acquire_first_ts(fim);
drivers/staging/media/imx/imx-media.h +1 -1
index ae3af0d..7f19739 100644
@@ -259,7 +259,7 @@ struct imx_media_fim;
  void imx_media_fim_eof_monitor(struct imx_media_fim *fim, struct timespec *ts);
  int imx_media_fim_set_power(struct imx_media_fim *fim, bool on);
  int imx_media_fim_set_stream(struct imx_media_fim *fim,
-			     struct imx_media_subdev *sensor,
+			     const struct v4l2_fract *frame_interval,
  			     bool on);
  struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd);
  void imx_media_fim_free(struct imx_media_fim *fim);
Signature · 3 lines
Steve Longerbeam | Senior Embedded Engineer, ESD Services
Mentor Embedded(tm) | 46871 Bayside Parkway, Fremont, CA 94538
P 510.354.5838 | M 408.410.2735
author maintainer
#205 lore raw

PATCH v4 33/36 media: imx: redo pixel format enumeration and negotiation

In reply to Steve Longerbeam

The previous API and negotiation of mbus codes and pixel formats was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

CSI:

sink pad     direct src pad      IDMAC src pad
--------     ----------------    -------------
RGB (any)        IPU RGB           RGB (any)
YUV (any)        IPU YUV           YUV (any)
Bayer              N/A             must be same bayer code as sink

VDIC:

direct sink pad    IDMAC sink pad    direct src pad
---------------    --------------    --------------
IPU YUV only       YUV (any)         IPU YUV only

PRP:

direct sink pad    direct src pads
---------------    ---------------
IPU (any)          same as sink code

PRP ENC/VF:

direct sink pad    IDMAC src pads
---------------    --------------
IPU (any)          any RGB or YUV

Given the above, a new internal API is created:

enum codespace_sel {
CS_SEL_YUV = 0, /* find or enumerate only YUV codes */
CS_SEL_RGB, /* find or enumerate only RGB codes */
CS_SEL_ANY, /* find or enumerate both YUV and RGB codes */
};

/* Find and enumerate fourcc pixel formats */
const struct imx_media_pixfmt *
imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel);
int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel);

/* Find and enumerate media bus codes */
const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel,

                          bool allow_bayer);
int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel,
                              bool allow_bayer);

/* Find and enumerate IPU internal media bus codes */
const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel); int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);

The tables have been split into separate tables for YUV and RGB formats to support the implementation of the above.

The subdev's .enum_mbus_code() and .set_fmt() operations have been rewritten using the above APIs.

---
 drivers/staging/media/imx/imx-ic-prp.c        |  72 ++++--
 drivers/staging/media/imx/imx-ic-prpencvf.c   |  53 ++--
 drivers/staging/media/imx/imx-media-capture.c |  77 +++---
 drivers/staging/media/imx/imx-media-csi.c     | 107 +++++---
 drivers/staging/media/imx/imx-media-utils.c   | 357 +++++++++++++++++++-------
 drivers/staging/media/imx/imx-media-vdic.c    | 100 +++++---
 drivers/staging/media/imx/imx-media.h         |  27 +-
 7 files changed, 528 insertions(+), 265 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +47 -25
index 3683f7c..b9ee8fb 100644
@@ -96,16 +96,6 @@ static void prp_stop(struct prp_priv *priv)
 {
 }
 
-static int prp_enum_mbus_code(struct v4l2_subdev *sd,
-			      struct v4l2_subdev_pad_config *cfg,
-			      struct v4l2_subdev_mbus_code_enum *code)
-{
-	if (code->pad >= PRP_NUM_PADS)
-		return -EINVAL;
-
-	return imx_media_enum_ipu_format(NULL, &code->code, code->index, true);
-}
-
 static struct v4l2_mbus_framefmt *
 __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_pad_config *cfg,
 	      unsigned int pad, enum v4l2_subdev_format_whence which)
@@ -118,6 +108,33 @@ __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_pad_config *cfg,
 		return &priv->format_mbus[pad];
 }
 
+static int prp_enum_mbus_code(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_pad_config *cfg,
+			      struct v4l2_subdev_mbus_code_enum *code)
+{
+	struct prp_priv *priv = sd_to_priv(sd);
+	struct v4l2_mbus_framefmt *infmt;
+	int ret = 0;
+
+	switch (code->pad) {
+	case PRP_SINK_PAD:
+		ret = imx_media_enum_ipu_format(&code->code, code->index,
+						CS_SEL_ANY);
+		break;
+	case PRP_SRC_PAD_PRPENC:
+	case PRP_SRC_PAD_PRPVF:
+		if (code->index != 0)
+			return -EINVAL;
+		infmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, code->which);
+		code->code = infmt->code;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return ret;
+}
+
 static int prp_get_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_pad_config *cfg,
 		       struct v4l2_subdev_format *sdformat)
@@ -152,23 +169,28 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	if (priv->stream_on)
 		return -EBUSY;
 
-	cc = imx_media_find_ipu_format(0, sdformat->format.code, true);
-	if (!cc) {
-		imx_media_enum_ipu_format(NULL, &code, 0, true);
-		cc = imx_media_find_ipu_format(0, code, true);
-		sdformat->format.code = cc->codes[0];
-	}
-
-	v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
-			      W_ALIGN, &sdformat->format.height,
-			      MIN_H, MAX_H, H_ALIGN, S_ALIGN);
-
-	/* Output pads mirror input pad */
-	if (sdformat->pad == PRP_SRC_PAD_PRPENC ||
-	    sdformat->pad == PRP_SRC_PAD_PRPVF) {
+	switch (sdformat->pad) {
+	case PRP_SINK_PAD:
+		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
+				      W_ALIGN, &sdformat->format.height,
+				      MIN_H, MAX_H, H_ALIGN, S_ALIGN);
+
+		cc = imx_media_find_ipu_format(sdformat->format.code,
+					       CS_SEL_ANY);
+		if (!cc) {
+			imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY);
+			cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
+			sdformat->format.code = cc->codes[0];
+		}
+		break;
+	case PRP_SRC_PAD_PRPENC:
+	case PRP_SRC_PAD_PRPVF:
+		/* Output pads mirror input pad */
 		infmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD,
 				      sdformat->which);
+		cc = imx_media_find_ipu_format(infmt->code, CS_SEL_ANY);
 		sdformat->format = *infmt;
+		break;
 	}
 
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
@@ -364,7 +386,7 @@ static int prp_registered(struct v4l2_subdev *sd)
 			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
 
 		/* set a default mbus format  */
-		imx_media_enum_ipu_format(NULL, &code, 0, true);
+		imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV);
 		ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
 					      640, 480, code, V4L2_FIELD_NONE,
 					      &priv->cc[i]);
drivers/staging/media/imx/imx-ic-prpencvf.c +30 -23

85 lines not on this page · raw message

drivers/staging/media/imx/imx-media-capture.c +47 -30

115 lines not on this page · raw message

drivers/staging/media/imx/imx-media-csi.c +70 -37

162 lines not on this page · raw message

drivers/staging/media/imx/imx-media-utils.c +259 -98

459 lines not on this page · raw message

drivers/staging/media/imx/imx-media-vdic.c +58 -42

139 lines not on this page · raw message

drivers/staging/media/imx/imx-media.h +17 -10
index 7f19739..4ac2bb6 100644
@@ -171,16 +171,23 @@ struct imx_media_dev {
 	struct v4l2_async_notifier subdev_notifier;
 };
 
-const struct imx_media_pixfmt *imx_media_find_format(u32 fourcc, u32 code,
-						     bool allow_rgb,
-						     bool allow_planar);
-const struct imx_media_pixfmt *imx_media_find_ipu_format(u32 fourcc, u32 code,
-							 bool allow_rgb);
-
-int imx_media_enum_format(u32 *fourcc, u32 *code, u32 index,
-			  bool allow_rgb, bool allow_planar);
-int imx_media_enum_ipu_format(u32 *fourcc, u32 *code, u32 index,
-			      bool allow_rgb);
+enum codespace_sel {
+	CS_SEL_YUV = 0,
+	CS_SEL_RGB,
+	CS_SEL_ANY,
+};
+
+const struct imx_media_pixfmt *
+imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel);
+int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel);
+const struct imx_media_pixfmt *
+imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel,
+			   bool allow_bayer);
+int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel,
+			       bool allow_bayer);
+const struct imx_media_pixfmt *
+imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel);
+int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);
 
 int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 			    u32 width, u32 height, u32 code, u32 field,
Signature · 1 line
2.7.4
maintainer
#206 lore raw

Re: [PATCH v4 33/36] media: imx: redo pixel format enumeration and negotiation

Quoted 5 lines · Steve Longerbeam

The previous API and negotiation of mbus codes and pixel formats was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

Quoted 7 lines

CSI:

sink pad     direct src pad      IDMAC src pad
--------     ----------------    -------------
RGB (any)        IPU RGB           RGB (any)
YUV (any)        IPU YUV           YUV (any)
Bayer              N/A             must be same bayer code as sink

The IDMAC src pad should also use the internal 32-bit RGB / YUV format, except if bayer/raw mode is selected, in which case the attached capture video device should only allow a single mode corresponding to the output pad media bus format.

regards
Philipp

author maintainer
#207 lore raw

Re: [PATCH v4 33/36] media: imx: redo pixel format enumeration and negotiation

Hi Philipp,

Quoted 14 lines · Philipp Zabel
Quoted 5 lines · Steve Longerbeam

The previous API and negotiation of mbus codes and pixel formats was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

Quoted 7 lines

CSI:

sink pad     direct src pad      IDMAC src pad
--------     ----------------    -------------
RGB (any)        IPU RGB           RGB (any)
YUV (any)        IPU YUV           YUV (any)
Bayer              N/A             must be same bayer code as sink
Quoted 4 lines

The IDMAC src pad should also use the internal 32-bit RGB / YUV format, except if bayer/raw mode is selected, in which case the attached capture video device should only allow a single mode corresponding to the output pad media bus format.

The IDMAC source pad is going to memory, so it has left the IPU. Are you sure it should be an internal IPU format? I realize it is linked to a capture device node, and the IPU format could then be translated to a v4l2 fourcc by the capture device, but IMHO this pad is external to the IPU.

Steve

maintainer
#208 lore raw

Re: [PATCH v4 33/36] media: imx: redo pixel format enumeration and negotiation

Hi Steve,

Quoted 23 lines · Steve Longerbeam

Hi Philipp,

Quoted 14 lines · Philipp Zabel
Quoted 5 lines · Steve Longerbeam

The previous API and negotiation of mbus codes and pixel formats was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

Quoted 7 lines

CSI:

sink pad     direct src pad      IDMAC src pad
--------     ----------------    -------------
RGB (any)        IPU RGB           RGB (any)
YUV (any)        IPU YUV           YUV (any)
Bayer              N/A             must be same bayer code as sink
Quoted 4 lines

The IDMAC src pad should also use the internal 32-bit RGB / YUV format, except if bayer/raw mode is selected, in which case the attached capture video device should only allow a single mode corresponding to the output pad media bus format.

Quoted 5 lines

The IDMAC source pad is going to memory, so it has left the IPU. Are you sure it should be an internal IPU format? I realize it is linked to a capture device node, and the IPU format could then be translated to a v4l2 fourcc by the capture device, but IMHO this pad is external to the IPU.

The CSI IDMAC source pad should describe the format at the connection between the CSI and the IDMAC, just as the icprpvf and icprpenc source pads.
The format outside of the IPU is the memory format written by the IDMAC, but that is a memory pixel format and not a media bus format at all.

That would also make it more straightforward to enumerate the memory pixel formats in the capture device: If the source pad media bus format is 32-bit YUV, enumerate all YUV formats, if it is 32-bit RGB or RGB565, enumerate all rgb formats, otherwise (bayer/raw mode) only allow the specific memory format matching the bus format.

regards
Philipp

author maintainer
#209 lore raw

Re: [PATCH v4 33/36] media: imx: redo pixel format enumeration and negotiation

Quoted 32 lines · Philipp Zabel

Hi Steve,

Quoted 23 lines · Steve Longerbeam

Hi Philipp,

Quoted 14 lines · Philipp Zabel
Quoted 5 lines · Steve Longerbeam

The previous API and negotiation of mbus codes and pixel formats was broken, and has been completely redone.

The negotiation of media bus codes should be as follows:

Quoted 7 lines

CSI:

sink pad     direct src pad      IDMAC src pad
--------     ----------------    -------------
RGB (any)        IPU RGB           RGB (any)
YUV (any)        IPU YUV           YUV (any)
Bayer              N/A             must be same bayer code as sink
Quoted 4 lines

The IDMAC src pad should also use the internal 32-bit RGB / YUV format, except if bayer/raw mode is selected, in which case the attached capture video device should only allow a single mode corresponding to the output pad media bus format.

Quoted 5 lines

The IDMAC source pad is going to memory, so it has left the IPU. Are you sure it should be an internal IPU format? I realize it is linked to a capture device node, and the IPU format could then be translated to a v4l2 fourcc by the capture device, but IMHO this pad is external to the IPU.

Quoted 6 lines

The CSI IDMAC source pad should describe the format at the connection between the CSI and the IDMAC, just as the icprpvf and icprpenc source pads.
The format outside of the IPU is the memory format written by the IDMAC, but that is a memory pixel format and not a media bus format at all.

True, it is a memory format. I don't really mind if the CSI and PRP ENC/VF source pads are characterized as IPU internal formats, since they are only used to indicate the colorspace to the capture device.

And yes it did simplify the enumeration and try_fmt code a bit. So I went ahead and made the change.

Steve

Quoted 7 lines

That would also make it more straightforward to enumerate the memory pixel formats in the capture device: If the source pad media bus format is 32-bit YUV, enumerate all YUV formats, if it is 32-bit RGB or RGB565, enumerate all rgb formats, otherwise (bayer/raw mode) only allow the specific memory format matching the bus format.

author maintainer
#210 lore raw

PATCH v4 34/36 media: imx: csi: add frame skipping support

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

The CSI can skip any out of up to 6 input frames, allowing to reduce the frame rate at the output pads by small fractions.

---
 drivers/staging/media/imx/imx-media-csi.c | 119 +++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +115 -4
index 1d4e746..6284f99 100644
@@ -9,6 +9,7 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
+#include <linux/gcd.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -40,6 +41,18 @@
 #define H_ALIGN    1 /* multiple of 2 lines */
 #define S_ALIGN    1 /* multiple of 2 */
 
+/*
+ * struct csi_skip_desc - CSI frame skipping descriptor
+ * @keep - number of frames kept per max_ratio frames
+ * @max_ratio - width of skip_smfc, written to MAX_RATIO bitfield
+ * @skip_smfc - skip pattern written to the SKIP_SMFC bitfield
+ */
+struct csi_skip_desc {
+	u8 keep;
+	u8 max_ratio;
+	u8 skip_smfc;
+};
+
 struct csi_priv {
 	struct device *dev;
 	struct ipu_soc *ipu;
@@ -58,6 +71,7 @@ struct csi_priv {
 	const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
 	struct v4l2_fract frame_interval;
 	struct v4l2_rect crop;
+	const struct csi_skip_desc *skip[CSI_NUM_PADS - 1];
 
 	/* the video device at IDMAC output pad */
 	struct imx_media_video_dev *vdev;
@@ -512,10 +526,12 @@ static int csi_setup(struct csi_priv *priv)
 	struct v4l2_mbus_config sensor_mbus_cfg;
 	struct v4l2_of_endpoint *sensor_ep;
 	struct v4l2_mbus_framefmt if_fmt;
+	const struct csi_skip_desc *skip;
 
 	infmt = &priv->format_mbus[CSI_SINK_PAD];
 	outfmt = &priv->format_mbus[priv->active_output_pad];
 	sensor_ep = &priv->sensor->sensor_ep;
+	skip = priv->skip[priv->active_output_pad - 1];
 
 	/* compose mbus_config from sensor endpoint */
 	sensor_mbus_cfg.type = sensor_ep->bus_type;
@@ -540,6 +556,9 @@ static int csi_setup(struct csi_priv *priv)
 
 	ipu_csi_set_dest(priv->csi, priv->dest);
 
+	ipu_csi_set_skip_smfc(priv->csi, skip->skip_smfc, skip->max_ratio - 1,
+			      0);
+
 	ipu_csi_dump(priv->csi);
 
 	return 0;
@@ -603,26 +622,115 @@ static void csi_stop(struct csi_priv *priv)
 	ipu_csi_disable(priv->csi);
 }
 
+static const struct csi_skip_desc csi_skip[12] = {
+	{ 1, 1, 0x00 }, /* Keep all frames */
+	{ 5, 6, 0x10 }, /* Skip every sixth frame */
+	{ 4, 5, 0x08 }, /* Skip every fifth frame */
+	{ 3, 4, 0x04 }, /* Skip every fourth frame */
+	{ 2, 3, 0x02 }, /* Skip every third frame */
+	{ 3, 5, 0x0a }, /* Skip frames 1 and 3 of every 5 */
+	{ 1, 2, 0x01 }, /* Skip every second frame */
+	{ 2, 5, 0x0b }, /* Keep frames 1 and 4 of every 5 */
+	{ 1, 3, 0x03 }, /* Keep one in three frames */
+	{ 1, 4, 0x07 }, /* Keep one in four frames */
+	{ 1, 5, 0x0f }, /* Keep one in five frames */
+	{ 1, 6, 0x1f }, /* Keep one in six frames */
+};
+
+static void csi_apply_skip_interval(const struct csi_skip_desc *skip,
+				    struct v4l2_fract *interval)
+{
+	unsigned int div;
+
+	interval->numerator *= skip->max_ratio;
+	interval->denominator *= skip->keep;
+
+	/* Reduce fraction to lowest terms */
+	div = gcd(interval->numerator, interval->denominator);
+	if (div > 1) {
+		interval->numerator /= div;
+		interval->denominator /= div;
+	}
+}
+
 static int csi_g_frame_interval(struct v4l2_subdev *sd,
 				struct v4l2_subdev_frame_interval *fi)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 
+	if (fi->pad >= CSI_NUM_PADS)
+		return -EINVAL;
+
 	fi->interval = priv->frame_interval;
 
+	if (fi->pad != CSI_SINK_PAD)
+		csi_apply_skip_interval(priv->skip[fi->pad - 1], &fi->interval);
+
 	return 0;
 }
 
+/*
+ * Find the skip pattern to produce the output frame interval closest to the
+ * requested one, for the given input frame interval. Updates the output frame
+ * interval to the exact value.
+ */
+static const struct csi_skip_desc *csi_find_best_skip(struct v4l2_fract *in,
+						      struct v4l2_fract *out)
+{
+	const struct csi_skip_desc *skip = &csi_skip[0], *best_skip = skip;
+	u32 min_err = UINT_MAX;
+	u64 want_us;
+	int i;
+
+	/* Default to 1:1 ratio */
+	if (out->numerator == 0 || out->denominator == 0 ||
+	    in->numerator == 0 || in->denominator == 0)
+		return best_skip;
+
+	want_us = div_u64((u64)USEC_PER_SEC * out->numerator, out->denominator);
+
+	/* Find the reduction closest to the requested time per frame */
+	for (i = 0; i < ARRAY_SIZE(csi_skip); i++, skip++) {
+		u64 tmp, err;
+
+		tmp = div_u64((u64)USEC_PER_SEC * in->numerator *
+			      skip->max_ratio, in->denominator * skip->keep);
+
+		err = abs((s64)tmp - want_us);
+		if (err < min_err) {
+			min_err = err;
+			best_skip = skip;
+		}
+	}
+
+	*out = *in;
+	csi_apply_skip_interval(best_skip, out);
+
+	return best_skip;
+}
+
 static int csi_s_frame_interval(struct v4l2_subdev *sd,
 				struct v4l2_subdev_frame_interval *fi)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 
-	/* Output pads mirror active input pad, no limits on input pads */
-	if (fi->pad == CSI_SRC_PAD_IDMAC || fi->pad == CSI_SRC_PAD_DIRECT)
-		fi->interval = priv->frame_interval;
+	if (fi->pad >= CSI_NUM_PADS)
+		return -EINVAL;
+
+	/* No limits on input pad */
+	if (fi->pad == CSI_SINK_PAD) {
+		priv->frame_interval = fi->interval;
+
+		/* Reset frame skipping ratio to 1:1 */
+		priv->skip[0] = &csi_skip[0];
+		priv->skip[1] = &csi_skip[0];
+
+		return 0;
+	}
 
-	priv->frame_interval = fi->interval;
+	/* Output pads depend on input interval, modified by frame skipping */
+	priv->skip[fi->pad - 1] = csi_find_best_skip(&priv->frame_interval,
+						     &fi->interval);
 
 	return 0;
 }
@@ -1198,6 +1306,9 @@ static int csi_registered(struct v4l2_subdev *sd)
 					      &priv->cc[i]);
 		if (ret)
 			goto put_csi;
+		/* disable frame skipping */
+		if (i != CSI_SINK_PAD)
+			priv->skip[i - 1] = &csi_skip[0];
 	}
 
 	priv->fim = imx_media_fim_init(&priv->sd);
Signature · 1 line
2.7.4
author maintainer
#211 lore raw

PATCH v4 35/36 media: imx: csi: fix crop rectangle reset in sink set_fmt

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

The csi_try_crop call in set_fmt should compare the cropping rectangle to the currently set input format, not to the previous input format.

---
 drivers/staging/media/imx/imx-media-csi.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +5 -6
index 6284f99..3e6b607 100644
@@ -937,15 +937,13 @@ __csi_get_fmt(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg,
 static int csi_try_crop(struct csi_priv *priv,
 			struct v4l2_rect *crop,
 			struct v4l2_subdev_pad_config *cfg,
-			enum v4l2_subdev_format_whence which,
+			struct v4l2_mbus_framefmt *infmt,
 			struct imx_media_subdev *sensor)
 {
 	struct v4l2_of_endpoint *sensor_ep;
-	struct v4l2_mbus_framefmt *infmt;
 	v4l2_std_id std;
 	int ret;
 
-	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, which);
 	sensor_ep = &sensor->sensor_ep;
 
 	crop->width = min_t(__u32, infmt->width, crop->width);
@@ -1142,8 +1140,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		crop.top = 0;
 		crop.width = sdformat->format.width;
 		crop.height = sdformat->format.height;
-		ret = csi_try_crop(priv, &crop, cfg,
-				   sdformat->which, sensor);
+		ret = csi_try_crop(priv, &crop, cfg, &sdformat->format, sensor);
 		if (ret)
 			return ret;
 
@@ -1225,6 +1222,7 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_selection *sel)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	struct v4l2_mbus_framefmt *infmt;
 	struct imx_media_subdev *sensor;
 	int ret;
 
@@ -1254,7 +1252,8 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 		return 0;
 	}
 
-	ret = csi_try_crop(priv, &sel->r, cfg, sel->which, sensor);
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
+	ret = csi_try_crop(priv, &sel->r, cfg, infmt, sensor);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.7.4
author maintainer
#212 lore raw

PATCH v4 36/36 media: imx: propagate sink pad formats to source pads

In reply to Steve Longerbeam
---
 drivers/staging/media/imx/imx-ic-prp.c      | 11 ++++++++++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 22 ++++++++++++++--------
 drivers/staging/media/imx/imx-media-csi.c   | 26 +++++++++++++++++---------
 drivers/staging/media/imx/imx-media-vdic.c  | 15 ++++++++++++++-
 4 files changed, 55 insertions(+), 19 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +10 -1
index b9ee8fb..5c57d2b 100644
@@ -196,8 +196,17 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+
+		/* propagate format to source pads */
+		if (sdformat->pad == PRP_SINK_PAD) {
+			priv->format_mbus[PRP_SRC_PAD_PRPENC] = *f;
+			priv->format_mbus[PRP_SRC_PAD_PRPVF] = *f;
+		}
 	}
 
 	return 0;
drivers/staging/media/imx/imx-ic-prpencvf.c +14 -8
index dd9d499..c43f85f 100644
@@ -806,16 +806,22 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[PRPENCVF_SRC_PAD];
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		if (sdformat->pad == PRPENCVF_SRC_PAD) {
-			/*
-			 * update the capture device format if this is
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-						      &sdformat->format, cc);
+
+		/* propagate format to source pad */
+		if (sdformat->pad == PRPENCVF_SINK_PAD) {
+			outf->width = f->width;
+			outf->height = f->height;
 		}
+
+		/* update the capture device format from output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, outf, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-csi.c +17 -9
index 3e6b607..9d9ec03 100644
@@ -1161,19 +1161,27 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
+		struct v4l2_mbus_framefmt *f_direct, *f_idmac;
+
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		/* Reset the crop window if this is the input pad */
-		if (sdformat->pad == CSI_SINK_PAD)
+
+		f_direct = &priv->format_mbus[CSI_SRC_PAD_DIRECT];
+		f_idmac = &priv->format_mbus[CSI_SRC_PAD_IDMAC];
+
+		if (sdformat->pad == CSI_SINK_PAD) {
+			/* reset the crop window */
 			priv->crop = crop;
-		else if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
-			/*
-			 * update the capture device format if this is
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-						      &sdformat->format, cc);
+
+			/* propagate format to source pads */
+			f_direct->width = crop.width;
+			f_direct->height = crop.height;
+			f_idmac->width = crop.width;
+			f_idmac->height = crop.height;
 		}
+
+		/* update the capture device format from IDMAC output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, f_idmac, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-vdic.c +14 -1
index 61e6017..55fb522 100644
@@ -649,8 +649,21 @@ static int vdic_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[VDIC_SRC_PAD_DIRECT];
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+
+		/* propagate format to source pad */
+		if (sdformat->pad == VDIC_SINK_PAD_DIRECT ||
+		    sdformat->pad == VDIC_SINK_PAD_IDMAC) {
+			outf->width = f->width;
+			outf->height = f->height;
+			outf->field = V4L2_FIELD_NONE;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.7.4
maintainer
#213 lore raw

Re: [PATCH v4 36/36] media: imx: propagate sink pad formats to source pads

On Wed, 2017-02-15 at 18:19 -0800, Steve Longerbeam wrote:
[...]

Quoted 18 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +6 -3
index dd9d499..c43f85f 100644
@@ -806,16 +806,22 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[PRPENCVF_SRC_PAD];
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		if (sdformat->pad == PRPENCVF_SRC_PAD) {
-			/*

drivers/staging/media/imx/imx-ic-prpencvf.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 820

Quoted 10 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -5
-			 * update the capture device format if this is
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-						      &sdformat->format, cc);
+
+		/* propagate format to source pad */
+		if (sdformat->pad == PRPENCVF_SINK_PAD) {
+			outf->width = f->width;
+			outf->height = f->height;

What about media bus format, field, and colorimetry?

Quoted 31 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +3 -0
 		}
+
+		/* update the capture device format from output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, outf, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-csi.c +8 -5
index 3e6b607..9d9ec03 100644
@@ -1161,19 +1161,27 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
+		struct v4l2_mbus_framefmt *f_direct, *f_idmac;
+
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		/* Reset the crop window if this is the input pad */
-		if (sdformat->pad == CSI_SINK_PAD)
+
+		f_direct = &priv->format_mbus[CSI_SRC_PAD_DIRECT];
+		f_idmac = &priv->format_mbus[CSI_SRC_PAD_IDMAC];
+
+		if (sdformat->pad == CSI_SINK_PAD) {
+			/* reset the crop window */
 			priv->crop = crop;
-		else if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
-			/*
-			 * update the capture device format if this is

drivers/staging/media/imx/imx-media-csi.c static int csi_set_fmt(struct v4l2_subdev *sd, · line 1180

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +6 -4
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-						      &sdformat->format, cc);
+
+			/* propagate format to source pads */
+			f_direct->width = crop.width;
+			f_direct->height = crop.height;
+			f_idmac->width = crop.width;
+			f_idmac->height = crop.height;

This is missing also media bus format, field and colorimetry propagation.

Quoted 20 lines
drivers/staging/media/imx/imx-media-csi.c +3 -0
 		}
+
+		/* update the capture device format from IDMAC output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, f_idmac, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-vdic.c +4 -1
index 61e6017..55fb522 100644
@@ -649,8 +649,21 @@ static int vdic_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[VDIC_SRC_PAD_DIRECT];

drivers/staging/media/imx/imx-media-vdic.c static int vdic_set_fmt(struct v4l2_subdev *sd, · line 665

Quoted 10 lines
drivers/staging/media/imx/imx-media-vdic.c +9 -0
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+
+		/* propagate format to source pad */
+		if (sdformat->pad == VDIC_SINK_PAD_DIRECT ||
+		    sdformat->pad == VDIC_SINK_PAD_IDMAC) {
+			outf->width = f->width;
+			outf->height = f->height;
+			outf->field = V4L2_FIELD_NONE;

This is missing colorimetry, too.

regards
Philipp

author maintainer
#214 lore raw

Re: [PATCH v4 36/36] media: imx: propagate sink pad formats to source pads

Quoted 24 lines · Philipp Zabel

On Wed, 2017-02-15 at 18:19 -0800, Steve Longerbeam wrote:
[...]

Quoted 22 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +6 -7
index dd9d499..c43f85f 100644
@@ -806,16 +806,22 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[PRPENCVF_SRC_PAD];
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		if (sdformat->pad == PRPENCVF_SRC_PAD) {
-			/*
-			 * update the capture device format if this is
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
Quoted 8 lines

drivers/staging/media/imx/imx-ic-prpencvf.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 820

Quoted 6 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -1
-						      &sdformat->format, cc);
+
+		/* propagate format to source pad */
+		if (sdformat->pad == PRPENCVF_SINK_PAD) {
+			outf->width = f->width;
+			outf->height = f->height;

What about media bus format, field, and colorimetry?

Right, I need to propagate a default media bus format and field that works.

As for colorimtery, I did see the work you are doing in your branch, but was not sure if you were finished with that support. Can you send me a patch?

Quoted 37 lines
Quoted 37 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +3 -0
 		}
+
+		/* update the capture device format from output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, outf, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-csi.c +9 -9
index 3e6b607..9d9ec03 100644
@@ -1161,19 +1161,27 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
+		struct v4l2_mbus_framefmt *f_direct, *f_idmac;
+
 		priv->format_mbus[sdformat->pad] = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
-		/* Reset the crop window if this is the input pad */
-		if (sdformat->pad == CSI_SINK_PAD)
+
+		f_direct = &priv->format_mbus[CSI_SRC_PAD_DIRECT];
+		f_idmac = &priv->format_mbus[CSI_SRC_PAD_IDMAC];
+
+		if (sdformat->pad == CSI_SINK_PAD) {
+			/* reset the crop window */
 			priv->crop = crop;
-		else if (sdformat->pad == CSI_SRC_PAD_IDMAC) {
-			/*
-			 * update the capture device format if this is
-			 * the IDMAC output pad
-			 */
-			imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix,
-						      &sdformat->format, cc);
+
Quoted 8 lines

drivers/staging/media/imx/imx-media-csi.c static int csi_set_fmt(struct v4l2_subdev *sd, · line 1180

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +5 -0
+			/* propagate format to source pads */
+			f_direct->width = crop.width;
+			f_direct->height = crop.height;
+			f_idmac->width = crop.width;
+			f_idmac->height = crop.height;

This is missing also media bus format, field and colorimetry propagation.

Yep, will add that.

Steve

Quoted 37 lines
Quoted 21 lines
drivers/staging/media/imx/imx-media-csi.c +3 -0
 		}
+
+		/* update the capture device format from IDMAC output pad */
+		imx_media_mbus_fmt_to_pix_fmt(&vdev->fmt.fmt.pix, f_idmac, cc);
 	}
 
 	return 0;
drivers/staging/media/imx/imx-media-vdic.c +4 -1
index 61e6017..55fb522 100644
@@ -649,8 +649,21 @@ static int vdic_set_fmt(struct v4l2_subdev *sd,
 	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
 		cfg->try_fmt = sdformat->format;
 	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
+		struct v4l2_mbus_framefmt *f =
+			&priv->format_mbus[sdformat->pad];
+		struct v4l2_mbus_framefmt *outf =
+			&priv->format_mbus[VDIC_SRC_PAD_DIRECT];

drivers/staging/media/imx/imx-media-vdic.c static int vdic_set_fmt(struct v4l2_subdev *sd, · line 665

Quoted 10 lines
drivers/staging/media/imx/imx-media-vdic.c +9 -0
+
+		*f = sdformat->format;
 		priv->cc[sdformat->pad] = cc;
+
+		/* propagate format to source pad */
+		if (sdformat->pad == VDIC_SINK_PAD_DIRECT ||
+		    sdformat->pad == VDIC_SINK_PAD_IDMAC) {
+			outf->width = f->width;
+			outf->height = f->height;
+			outf->field = V4L2_FIELD_NONE;

This is missing colorimetry, too.

regards
Philipp

#215 lore raw
In reply to Steve Longerbeam

Two problems.

Quoted 1 line · Steve Longerbeam

media: imx: propagate sink pad formats to source pads

1) It looks like all cases aren't being caught:

- entity 74: ipu1_csi0 (3 pads, 4 links)

             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev13
        pad0: Sink
                [fmt:SRGGB8/816x616 field:none]
                <- "ipu1_csi0_mux":2 [ENABLED]
        pad1: Source
                [fmt:AYUV32/816x616 field:none
                 crop.bounds:(0,0)/816x616
                 crop:(0,0)/816x616]
                -> "ipu1_ic_prp":0 []
                -> "ipu1_vdic":0 []
        pad2: Source
                [fmt:SRGGB8/816x616 field:none
                 crop.bounds:(0,0)/816x616
                 crop:(0,0)/816x616]
                -> "ipu1_csi0 capture":0 [ENABLED]

While the size has been propagated to pad1, the format has not.

2) /dev/video* device node assignment

I've no idea at the moment how the correct /dev/video* node should be chosen - initially with Philipp and your previous code, it was /dev/video3 after initial boot. Philipp's was consistently /dev/video3. Yours changed to /dev/video7 when removing and re-inserting the modules (having fixed that locally.) This version makes CSI0 be /dev/video7, but after a remove+reinsert, it becomes (eg) /dev/video8.

/dev/v4l/by-path/platform-capture-subsystem-video-index4 also is not a stable path - the digit changes (it's supposed to be a stable path.) After a remove+reinsert, it becomes (eg) /dev/v4l/by-path/platform-capture-subsystem-video-index5. /dev/v4l/by-id doesn't contain a symlink for this either.

What this means is that it's very hard to script the setup, because there's no easy way to know what device is the capture device. While it may be possible to do:

	media-ctl -d /dev/media1 -p | \
		grep -A2 ': ipu1_csi0 capture' | \
			sed -n 's|.*\(/dev/video[0-9]*\).*|\1|p'

that's hardly a nice solution - while it fixes the setup script, it doesn't stop the pain of having to delve around to find the correct device to use for gstreamer to test with.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#216 lore raw
Quoted 25 lines · Russell King - ARM Linux

Two problems.

Quoted 1 line · Steve Longerbeam

media: imx: propagate sink pad formats to source pads

1) It looks like all cases aren't being caught:

- entity 74: ipu1_csi0 (3 pads, 4 links)

             type V4L2 subdev subtype Unknown flags 0
             device node name /dev/v4l-subdev13
        pad0: Sink
                [fmt:SRGGB8/816x616 field:none]
                <- "ipu1_csi0_mux":2 [ENABLED]
        pad1: Source
                [fmt:AYUV32/816x616 field:none
                 crop.bounds:(0,0)/816x616
                 crop:(0,0)/816x616]
                -> "ipu1_ic_prp":0 []
                -> "ipu1_vdic":0 []
        pad2: Source
                [fmt:SRGGB8/816x616 field:none
                 crop.bounds:(0,0)/816x616
                 crop:(0,0)/816x616]
                -> "ipu1_csi0 capture":0 [ENABLED]
Quoted 1 line

While the size has been propagated to pad1, the format has not.

Right, Philipp also caught this. I need to finish propagating all params from sink to source pads (mbus code and field, and colorimetry eventually).

Quoted 20 lines

2) /dev/video* device node assignment

I've no idea at the moment how the correct /dev/video* node should be chosen - initially with Philipp and your previous code, it was /dev/video3 after initial boot. Philipp's was consistently /dev/video3. Yours changed to /dev/video7 when removing and re-inserting the modules (having fixed that locally.) This version makes CSI0 be /dev/video7, but after a remove+reinsert, it becomes (eg) /dev/video8.

/dev/v4l/by-path/platform-capture-subsystem-video-index4 also is not a stable path - the digit changes (it's supposed to be a stable path.) After a remove+reinsert, it becomes (eg) /dev/v4l/by-path/platform-capture-subsystem-video-index5. /dev/v4l/by-id doesn't contain a symlink for this either.

What this means is that it's very hard to script the setup, because there's no easy way to know what device is the capture device. While it may be possible to do:

Quoted 8 lines
	media-ctl -d /dev/media1 -p | \
		grep -A2 ': ipu1_csi0 capture' | \
			sed -n 's|.*\(/dev/video[0-9]*\).*|\1|p'

that's hardly a nice solution - while it fixes the setup script, it doesn't stop the pain of having to delve around to find the correct device to use for gstreamer to test with.

I'll try to nail down the main capture node numbers, even after module reload.

Steve

#217 lore raw
In reply to Steve Longerbeam
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
author maintainer
#218 lore raw
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

If we want to bring in the patch that adds a .prepare_stream() op, the csi-2 bus would need to be placed in LP-11 in that op instead.

Philipp, should I go ahead and add your .prepare_stream() patch?

Steve

#219 lore raw
Quoted 8 lines · Steve Longerbeam
Quoted 5 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

Quoted 7 lines
Quoted 3 lines
[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

The only way to do that is to enable streaming from the sensor, wait an initialisation time, and then disable streaming, and wait for the current line to finish. There is _no_ other way to get the sensor to place its clock and data lines into LP-11 state.

For that to happen, we need to program the sensor a bit more than we currently do at power on (to a minimal resolution, and setting up the PLLs), and introduce another 4ms on top of the 8ms or so that the runtime resume function already takes.

Looking at the SMIA driver, things are worse, and I suspect that it also will not work with the current setup - the SMIA spec shows that the CSI clock and data lines are tristated while the sensor is not streaming, which means they aren't held at a guaranteed LP-11 state, even if that driver momentarily enabled streaming. Hence, Freescale's (or is it Synopsis') requirement may actually be difficult to satisfy.

However, I regard runtime PM broken with the current imx-capture setup. At the moment, power is controlled at the sensor by whether the media links are enabled. So, if you have an enabled link coming off the sensor, the sensor will be powered up, whether you're using it or not.

Given that the number of applications out there that know about the media subdevs is really quite small, this combination makes having runtime PM in sensor devices completely pointless - they can't sleep as long as they have an enabled link, which could be persistent over many days or weeks.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#220 lore raw
Quoted 13 lines · Russell King - ARM Linux
Quoted 12 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110
Quoted 8 lines
Quoted 3 lines

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

The only way to do that is to enable streaming from the sensor, wait an initialisation time, and then disable streaming, and wait for the current line to finish. There is _no_ other way to get the sensor to place its clock and data lines into LP-11 state.

I thought going through LP-11 is part of the D-PHY transmitter initialization, during the LP->HS wakeup sequence. But then I have no access to MIPI specs.
It is unfortunate that the i.MX6 MIPI CSI-2 core needs software assistance here, but could it be possible to trigger that sequence in the sensor and then without waiting switching to polling for LP-11 state in the i.MX6 MIPI CSI-2 receiver?

Quoted 17 lines

For that to happen, we need to program the sensor a bit more than we currently do at power on (to a minimal resolution, and setting up the PLLs), and introduce another 4ms on top of the 8ms or so that the runtime resume function already takes.

Looking at the SMIA driver, things are worse, and I suspect that it also will not work with the current setup - the SMIA spec shows that the CSI clock and data lines are tristated while the sensor is not streaming, which means they aren't held at a guaranteed LP-11 state, even if that driver momentarily enabled streaming. Hence, Freescale's (or is it Synopsis') requirement may actually be difficult to satisfy.

However, I regard runtime PM broken with the current imx-capture setup. At the moment, power is controlled at the sensor by whether the media links are enabled. So, if you have an enabled link coming off the sensor, the sensor will be powered up, whether you're using it or not.

Quoted 5 lines

Given that the number of applications out there that know about the media subdevs is really quite small, this combination makes having runtime PM in sensor devices completely pointless - they can't sleep as long as they have an enabled link, which could be persistent over many days or weeks.

regards
Philipp

#221 lore raw
Quoted 18 lines · Philipp Zabel
Quoted 17 lines · Russell King - ARM Linux
Quoted 15 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

Quoted 8 lines
Quoted 4 lines

The only way to do that is to enable streaming from the sensor, wait an initialisation time, and then disable streaming, and wait for the current line to finish. There is _no_ other way to get the sensor to place its clock and data lines into LP-11 state.

I thought going through LP-11 is part of the D-PHY transmitter initialization, during the LP->HS wakeup sequence. But then I have no access to MIPI specs.

The D-PHY transmitter initialisation *only* happens as part of the wake-up from standby to streaming mode. That is because Sony expect that you program the sensor, and then when you switch it to streaming mode, it computes the D-PHY parameters from the PLL, input clock rate (you have to tell it the clock rate in 1/256 MHz units), number of lanes, and other parameters.

It is possible to program the D-PHY parameters manually, but that doesn't change the above sequence in any way (it just avoids the chip computing the values, it doesn't result in any change of behaviour on the bus.)

The IMX219 specifications are clear: the clock and data lines are held low (LP-00 state) after releasing the hardware enable signal. There's a period of chip initialisation, and then you can access the I2C bus and configure it. There's a further period of initialisation where charge pumps are getting to their operating state. Then, you set the streaming bit, and a load more initialisation happens before the CSI bus enters LP-11 state and the first frame pops out. When entering standby, the last frame is completed, and then the CSI bus enters LP-11 state.

SMIA are slightly different - mostly following what I've said above, but the clock and data lines are tristated after releasing the xshutdown signal, and they remain tristated until the clock line starts toggling before the first frame appears. There appears to be no point that the clock line enters LP-11 state before it starts toggling. When entering standby, the last frame is completed, and the CSI bus enters tristate mode (so floating.) There is no way to get these sensors into LP-11 state.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#222 lore raw
Quoted 40 lines · Russell King - ARM Linux
Quoted 18 lines · Philipp Zabel
Quoted 17 lines · Russell King - ARM Linux
Quoted 15 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

Quoted 8 lines
Quoted 4 lines

The only way to do that is to enable streaming from the sensor, wait an initialisation time, and then disable streaming, and wait for the current line to finish. There is _no_ other way to get the sensor to place its clock and data lines into LP-11 state.

I thought going through LP-11 is part of the D-PHY transmitter initialization, during the LP->HS wakeup sequence. But then I have no access to MIPI specs.

The D-PHY transmitter initialisation *only* happens as part of the wake-up from standby to streaming mode. That is because Sony expect that you program the sensor, and then when you switch it to streaming mode, it computes the D-PHY parameters from the PLL, input clock rate (you have to tell it the clock rate in 1/256 MHz units), number of lanes, and other parameters.

It is possible to program the D-PHY parameters manually, but that doesn't change the above sequence in any way (it just avoids the chip computing the values, it doesn't result in any change of behaviour on the bus.)

Quoted 9 lines

The IMX219 specifications are clear: the clock and data lines are held low (LP-00 state) after releasing the hardware enable signal. There's a period of chip initialisation, and then you can access the I2C bus and configure it. There's a further period of initialisation where charge pumps are getting to their operating state. Then, you set the streaming bit, and a load more initialisation happens before the CSI bus enters LP-11 state and the first frame pops out. When entering standby, the last frame is completed, and then the CSI bus enters LP-11 state.

How about firing off a thread in imx6-mipi-csi2 prepare_stream that spins on the LP-11 check and then continues with the receiver D-PHY initialization once the condition is met? I think we should have at least 100 us to do this, but maybe the IMX219 can be programmed to stay in LP-11 for a longer time.

Quoted 8 lines

SMIA are slightly different - mostly following what I've said above, but the clock and data lines are tristated after releasing the xshutdown signal, and they remain tristated until the clock line starts toggling before the first frame appears. There appears to be no point that the clock line enters LP-11 state before it starts toggling. When entering standby, the last frame is completed, and the CSI bus enters tristate mode (so floating.) There is no way to get these sensors into LP-11 state.

I have no idea what to do about those.

regards
Philipp

author maintainer
#223 lore raw
In reply to Russell King - ARM Linux
Quoted 22 lines · Russell King - ARM Linux
Quoted 8 lines · Steve Longerbeam
Quoted 5 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

Quoted 7 lines
Quoted 3 lines
[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

The only way to do that is to enable streaming from the sensor, wait an initialisation time, and then disable streaming, and wait for the current line to finish. There is _no_ other way to get the sensor to place its clock and data lines into LP-11 state.

Quoted 4 lines

For that to happen, we need to program the sensor a bit more than we currently do at power on (to a minimal resolution, and setting up the PLLs), and introduce another 4ms on top of the 8ms or so that the runtime resume function already takes.

This is basically the same procedure that was necessary to get the OV5640 to enter LP-11 on all its lanes. Power-on procedure writes an initial register set that gets the sensor to a default resolution, turn on streaming briefly (I wait 1msec which is probably too long, but it's not clear to me how to determine that wait time), and then disable streaming. All lanes are then in LP-11 state.

Steve

maintainer
#224 lore raw
In reply to Steve Longerbeam
Quoted 11 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110
Quoted 8 lines

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

If we want to bring in the patch that adds a .prepare_stream() op, the csi-2 bus would need to be placed in LP-11 in that op instead.

Philipp, should I go ahead and add your .prepare_stream() patch?

I think with Russell's explanation of how the imx219 sensor operates, we'll have to do something before calling the sensor s_stream, but right now I'm still unsure what exactly.

regards
Philipp

#225 lore raw

Hi Philipp, Steve and Russell,

Quoted 16 lines · Philipp Zabel
Quoted 15 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

Quoted 8 lines
Quoted 4 lines

If we want to bring in the patch that adds a .prepare_stream() op, the csi-2 bus would need to be placed in LP-11 in that op instead.

Philipp, should I go ahead and add your .prepare_stream() patch?

I think with Russell's explanation of how the imx219 sensor operates, we'll have to do something before calling the sensor s_stream, but right now I'm still unsure what exactly.

Indeed there appears to be no other way to achieve the LP-11 state than going through the streaming state for this particular sensor, apart from starting streaming.

Is there a particular reason why you're waiting for the transmitter to transfer to LP-11 state? That appears to be the last step which is done in the csi2_s_stream() callback.

What the sensor does next is to start streaming, and the first thing it does in that process is to switch to LP-11 state.

Have you tried what happens if you simply drop the LP-11 check? To me that would seem the right thing to do.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk
#226 lore raw
Quoted 15 lines · Sakari Ailus

Hi Philipp, Steve and Russell,

Quoted 3 lines · Philipp Zabel

I think with Russell's explanation of how the imx219 sensor operates, we'll have to do something before calling the sensor s_stream, but right now I'm still unsure what exactly.

Indeed there appears to be no other way to achieve the LP-11 state than going through the streaming state for this particular sensor, apart from starting streaming.

Is there a particular reason why you're waiting for the transmitter to transfer to LP-11 state? That appears to be the last step which is done in the csi2_s_stream() callback.

Quoted 5 lines

What the sensor does next is to start streaming, and the first thing it does in that process is to switch to LP-11 state.

Have you tried what happens if you simply drop the LP-11 check? To me that would seem the right thing to do.

The Freescale documentation for iMX6's CSI2 receiver (chapter 40.3.1) specifies a very specific sequence to be followed to safely bring up the CSI2 receiver. Bold text gets used, which implies emphasis on certain points, which suggests that it's important to follow it.

Presumably, the reason for this is to ensure that a state machine within the CSI2 receiver is properly synchronised to the incoming data stream, and while avoiding the sequence may work, it may not be guaranteed to work every time.

I guess we need someone from NXP to comment.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
maintainer
#227 lore raw
In reply to Sakari Ailus
Quoted 36 lines · Sakari Ailus

Hi Philipp, Steve and Russell,

Quoted 16 lines · Philipp Zabel
Quoted 15 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

Quoted 8 lines
Quoted 4 lines

If we want to bring in the patch that adds a .prepare_stream() op, the csi-2 bus would need to be placed in LP-11 in that op instead.

Philipp, should I go ahead and add your .prepare_stream() patch?

I think with Russell's explanation of how the imx219 sensor operates, we'll have to do something before calling the sensor s_stream, but right now I'm still unsure what exactly.

Indeed there appears to be no other way to achieve the LP-11 state than going through the streaming state for this particular sensor, apart from starting streaming.

Is there a particular reason why you're waiting for the transmitter to transfer to LP-11 state? That appears to be the last step which is done in the csi2_s_stream() callback.

Quoted 5 lines

What the sensor does next is to start streaming, and the first thing it does in that process is to switch to LP-11 state.

Have you tried what happens if you simply drop the LP-11 check? To me that would seem the right thing to do.

Removing the wait for LP-11 alone might not be an issue in my case, as the TC358743 is known to be in stop state all along. So I just have to make sure that the time between s_stream(csi2) starting the receiver and s_stream(tc358743) causing LP-11 to be changed to the next state is long enough for the receiver to detect LP-11 (which I really can't, I just have to pray I2C transmissions are slow enough).

The problems start if we have to enable the D-PHY and deassert resets either before the sensor enters LP-11 state or after it already started streaming, because we don't know when the sensor drives that state on the bus.

The latter case I is simulated easily by again changing the order so that the "sensor" (tc358743) is enabled before the CSI-2 receiver D-PHY initialization. The result is that captures time out, presumably because the receiver never entered HS mode because it didn't see LP-11. The PHY_STATE register contains 0x200, meaning RXCLKACTIVEHS (which we should wait for in step 7.) is never set.

I tried to test the former by instead modifying the tc358743 driver a bit:

----------8<----------

drivers/media/i2c/tc358743.c +5 -5
index 39d4cdd328c0f..43df80903215b 100644
@@ -1378,8 +1378,6 @@ static int tc358743_s_dv_timings(struct v4l2_subdev *sd,
        state->timings = *timings;
 
        enable_stream(sd, false);
-       tc358743_set_pll(sd);
-       tc358743_set_csi(sd);
 
        return 0;
 }
@@ -1469,6 +1467,11 @@ static int tc358743_g_mbus_config(struct v4l2_subdev *sd,
 
 static int tc358743_s_stream(struct v4l2_subdev *sd, int enable)
 {
+       if (enable) {
+               tc358743_set_pll(sd);
+               tc358743_set_csi(sd);
+               tc358743_set_csi_color_space(sd);
+       }
        enable_stream(sd, enable);
        if (!enable) {
                /* Put all lanes in PL-11 state (STOPSTATE) */
@@ -1657,9 +1660,6 @@ static int tc358743_set_fmt(struct v4l2_subdev *sd,
        state->vout_color_sel = vout_color_sel;
 
        enable_stream(sd, false);
-       tc358743_set_pll(sd);
-       tc358743_set_csi(sd);
-       tc358743_set_csi_color_space(sd);
 
        return 0;
 }

---------->8----------

That should enable the CSI-2 Tx and put it in LP-11 only after the CSI-2 receiver is enabled, right before starting streaming.

That did seem to work the few times I tested, but I have no idea how this will behave with other chips that do something else to the bus while not streaming, and whether it is ok to enable the CSI right after the sensor without waiting for the CSI-2 bus to settle.

regards
Philipp

#228 lore raw

Hi Philipp and Russell,

Quoted 43 lines · Philipp Zabel
Quoted 36 lines · Sakari Ailus

Hi Philipp, Steve and Russell,

Quoted 16 lines · Philipp Zabel
Quoted 15 lines · Steve Longerbeam
Quoted 8 lines · Russell King - ARM Linux
Quoted 1 line · Steve Longerbeam

In version 4:

With this version, I get:

[28762.892053] imx6-mipi-csi2: LP-11 timeout, phy_state = 0x00000000
[28762.899409] ipu1_csi0: pipeline_set_stream failed with -110

Right, in the imx219, on exit from s_power(), the clock and data lanes must be placed in the LP-11 state. This has been done in the ov5640 and tc358743 subdevs.

Quoted 8 lines
Quoted 4 lines

If we want to bring in the patch that adds a .prepare_stream() op, the csi-2 bus would need to be placed in LP-11 in that op instead.

Philipp, should I go ahead and add your .prepare_stream() patch?

I think with Russell's explanation of how the imx219 sensor operates, we'll have to do something before calling the sensor s_stream, but right now I'm still unsure what exactly.

Indeed there appears to be no other way to achieve the LP-11 state than going through the streaming state for this particular sensor, apart from starting streaming.

Is there a particular reason why you're waiting for the transmitter to transfer to LP-11 state? That appears to be the last step which is done in the csi2_s_stream() callback.

Quoted 5 lines

What the sensor does next is to start streaming, and the first thing it does in that process is to switch to LP-11 state.

Have you tried what happens if you simply drop the LP-11 check? To me that would seem the right thing to do.

Quoted 6 lines

Removing the wait for LP-11 alone might not be an issue in my case, as the TC358743 is known to be in stop state all along. So I just have to make sure that the time between s_stream(csi2) starting the receiver and s_stream(tc358743) causing LP-11 to be changed to the next state is long enough for the receiver to detect LP-11 (which I really can't, I just have to pray I2C transmissions are slow enough).

Fair enough; it appears that the timing of the bus setup is indeed ill defined between the transmitter and the receiver. So there can be hardware specific matters in stream starting that have to be taken into account. :-(

This is quite annoying, as there does not appear to be a good way to tell the sensor to set the receiver to LP-11 state without going through the streaming state. If there was, just doing that in s_power(, 1) callback would be quite practical.

I guess then there's no really a way to avoid having an extra callback that would explicitly tell the sensor to go to LP-11 state. It should be no issue if the transmitter is already in that state from power-on, but the new callback should guarantee that.

Another question is that how far do you need to proceed with streaming in a case where you want to go to LP-11 through streaming? Is simply starting streaming and stopping it right after enough? On some devices it might be but not on others. As the receiver is not started yet, you can't wait for the first frame to start either. And how long it would take for the first frame to start is not defined either in general case: or a driver such as SMIA that's not exactly aware of the underlying hardware but is relying on a standard device interface and behaviour, such approach could be best effort only. Of course it's possible to make changes to the driver if you encounter a combination of a sensor and a receiver that doesn't seem to work, but still it's hardly an ideal solution.

How about calling the new callback phy_prepare(), for instance? We could document that it must explicitly set up the transmitter PHY in LP-11 state for CSI-2. The current documentation states that the device should be already in LP-11 after power-on but that apparently is not the case in general.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: sakari.ailus at iki.fi	XMPP: sailus at retiisi.org.uk