Skip to contentSkip to conversation

i.MX Media Driver

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

Subsystems (14)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Steve Longerbeam

author maintainer
#0 lore raw

v4 cover i.MX Media Driver

In version 4:

Changes suggested by Philipp Zabel <[email protected]> and Jean-Michel Hautbois <[email protected]>:

- split out VDIC from imx-ic-prpvf into a distinct VDIC subdev.

Changes suggested by Philipp Zabel <[email protected]>:

- Re-org of pre-process entities. Created an ipuX_ic_prp entity that receives on a single sink pad from the CSIs and the VDIC. Two source pads route to ipuX_ic_prpenc and ipuX_ic_prpvf. The code for ipuX_ic_prpenc and ipuX_ic_prpvf is now identical, which adds rotation to ipuX_ic_prpvf.

- renamed media node in DT to capture-subsystem, compatible string to "fsl,imx-capture-subsystem".

- the ov564x subdevs get the xclk rate from clk_get_rate() instead of attempting to change the rate. "xclk" property in ov564x DT nodes is removed.

- changed "pix" clock to IMX6QDL_CLK_EIM_PODF in mipi_csi node.

- added comptible string "snps,dw-mipi-csi2" to mipi_csi node in DT.

- silenced many of the v4l2_info()'s.

- move conversion of ALTERNATE field type to SEQ_BT/TB to output pad of ipuX_csiY entity.

- added bounds checks to set_fmt in ipuX_csiY and ipuX_vdic entities.

- Get rid of SMFC entity. CSI frame output via SMFC and IDMAC channel is now built into the CSI entities via a new source pad. So CSI entities now have two source pads : direct and IDMAC.

- the IPU internal pads (direct between subunuits, not via IDMAC channels), should only accept the pixel formats used internally by the IPU:
MEDIA_BUS_FMT_AYUV8_1X32 and MEDIA_BUS_FMT_ARGB8888_1X32.

- export V4L2_EVENT_IMX_EOF_TIMEOUT as V4L2_EVENT_FRAME_TIMEOUT for general use.

- export imx_media_inherit_controls() as v4l2_pipeline_inherit_controls() for general use.

- completely removed dma_buf ring support. There is no capture interface or ic-pp subdevs any longer. The CSI and ic-prp enc/vf subdevs now attach directly to a capture device node from their IDMAC (non-direct) source pads.

Changes suggested by Javier Martinez Canillas <[email protected]>:

- add missing MODULE_DEVICE_TABLE() to video mux subdev.

Changes suggested by Hans Verkuil <[email protected]>:

- entity function type MEDIA_ENT_F_MUX renamed to MEDIA_ENT_F_VID_MUX.

- removed use of g_mbus_config subdev op. Sensor bus config is instead gotten from the sensor DT node via v4l2_of_parse_endpoint().

- use v4l2_ctrl_handler_setup() for restoring current control values in the ov564x subdevs, rather than a custom control cache.

Changes suggested by Russell King <[email protected]>:

- re-ordered clock lane and data lane # assignments in device tree.

- fixed module unload.

- propagate the return code from ipu_ic_task_idma_init(), don't start streaming if it returned error!

Changes suggested by Laurent Pinchart <[email protected]>:

- ov5640 subdev is improved and moved to drivers/media/i2c, along with binding docs. The ov5642 subdev has been dropped for now.

- regulator DT properties are now required in ov5640 subdev, and resewt/power GPIOs are optional. Created dummy regulator nodes in imx6qdl-sabrelite.dtsi for the ov5640 node (the ov5640 regulators are fixed regulators on the OV5640 module for sabrelite).

- removed use of endpoint ID in device tree as a way to specify a MIPI CSI-2 virtual channel for the OV5640. The ov5640 subdev now hard-codes the virtual channel to 1 until a new subdev API becomes available to allow run-time virtual channel selection.

Other changes:

- v4l2-compliance fixes.

- since dma_buf ring support is gone, the VDIC subdev is modified to potentially receive frames from a future output device node on its IDMAC sink pad.

- fixed mbus pixel format enumeration and selection. The source pads and capture device select the correct formats based on the sink formats. For example the capture device can only report and allow selecting an RGB format if the attached source pad's format is RGB. Likewise for YUV space, with the added benefit that the capture device can select a YUV planar format in this case, and the attached subdev will comply and output planar.

- stripped out sensor input OF properties and parsing for now. It is problematic since there is currently no subdev op so that the bridge can retrieve this information and use for VIDIOC_{ENUM|S|G}_INPUT.

- modified imx6-mipi-csi2 subdev to comply strictly with the MIPI CSI-2 startup sequence described in the i.MX6 reference manual.

Philipp Zabel (6):
ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their
connections
add mux and video interface bridge entity functions
platform: add video-multiplexer subdevice driver
media: imx: csi: fix crop rectangle changes in set_fmt
media: imx: csi: add frame skipping support
media: imx: csi: fix crop rectangle reset in sink set_fmt

Russell King (3):
media: imx: add support for bayer formats
media: imx: csi: add support for bayer formats
media: imx: mipi-csi2: enable setting and getting of frame rates

Steve Longerbeam (27):
[media] dt-bindings: Add bindings for i.MX media driver
ARM: dts: imx6qdl: Add compatible, clocks, irqs to MIPI CSI-2 node
ARM: dts: imx6qdl: add capture-subsystem device
ARM: dts: imx6qdl-sabrelite: remove erratum ERR006687 workaround
ARM: dts: imx6-sabrelite: add OV5642 and OV5640 camera sensors
ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors
ARM: dts: imx6-sabreauto: create i2cmux for i2c3
ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b
ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture
ARM: dts: imx6-sabreauto: add the ADV7180 video decoder [media] v4l2: add a frame timeout event
[media] v4l2-mc: add a function to inherit controls from a pipeline
UAPI: Add media UAPI Kbuild file
media: Add userspace header file for i.MX
media: Add i.MX media core driver
media: imx: Add Capture Device Interface
media: imx: Add CSI subdev driver
media: imx: Add VDIC subdev driver
media: imx: Add IC subdev drivers
media: imx: Add MIPI CSI-2 Receiver subdev driver [media] add Omnivision OV5640 sensor driver
ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers
media: imx: update capture dev format on IDMAC output pad set_fmt
media: imx: csi: add __csi_get_fmt
media: imx: csi/fim: add support for frame intervals
media: imx: redo pixel format enumeration and negotiation
media: imx: propagate sink pad formats to source pads

 .../devicetree/bindings/media/i2c/ov5640.txt       |   43 +
 Documentation/devicetree/bindings/media/imx.txt    |   66 +
 .../bindings/media/video-multiplexer.txt           |   59 +
 Documentation/media/uapi/mediactl/media-types.rst  |   22 +
 Documentation/media/uapi/v4l/vidioc-dqevent.rst    |    5 +
 Documentation/media/v4l-drivers/imx.rst            |  542 +++++
 Documentation/media/videodev2.h.rst.exceptions     |    1 +
 arch/arm/boot/dts/imx6dl-sabrelite.dts             |    5 +
 arch/arm/boot/dts/imx6dl-sabresd.dts               |    5 +
 arch/arm/boot/dts/imx6dl.dtsi                      |  185 ++
 arch/arm/boot/dts/imx6q-sabrelite.dts              |    5 +
 arch/arm/boot/dts/imx6q-sabresd.dts                |    5 +
 arch/arm/boot/dts/imx6q.dtsi                       |  121 ++
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi           |  144 +-
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi           |  152 +-
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi             |  114 +-
 arch/arm/boot/dts/imx6qdl.dtsi                     |   17 +-
 arch/arm/configs/imx_v6_v7_defconfig               |   14 +-
 drivers/media/i2c/Kconfig                          |    7 +
 drivers/media/i2c/Makefile                         |    1 +
 drivers/media/i2c/ov5640.c                         | 2109 ++++++++++++++++++++
 drivers/media/platform/Kconfig                     |    8 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/video-multiplexer.c         |  474 +++++
 drivers/media/v4l2-core/v4l2-mc.c                  |   48 +
 drivers/staging/media/Kconfig                      |    2 +
 drivers/staging/media/Makefile                     |    1 +
 drivers/staging/media/imx/Kconfig                  |   20 +
 drivers/staging/media/imx/Makefile                 |   12 +
 drivers/staging/media/imx/TODO                     |   36 +
 drivers/staging/media/imx/imx-ic-common.c          |  113 ++
 drivers/staging/media/imx/imx-ic-prp.c             |  458 +++++
 drivers/staging/media/imx/imx-ic-prpencvf.c        | 1138 +++++++++++
 drivers/staging/media/imx/imx-ic.h                 |   38 +
 drivers/staging/media/imx/imx-media-capture.c      |  671 +++++++
 drivers/staging/media/imx/imx-media-csi.c          | 1483 ++++++++++++++
 drivers/staging/media/imx/imx-media-dev.c          |  487 +++++
 drivers/staging/media/imx/imx-media-fim.c          |  463 +++++
 drivers/staging/media/imx/imx-media-internal-sd.c  |  349 ++++
 drivers/staging/media/imx/imx-media-of.c           |  267 +++
 drivers/staging/media/imx/imx-media-utils.c        |  930 +++++++++
 drivers/staging/media/imx/imx-media-vdic.c         |  915 +++++++++
 drivers/staging/media/imx/imx-media.h              |  305 +++
 drivers/staging/media/imx/imx6-mipi-csi2.c         |  600 ++++++
 include/media/imx.h                                |   15 +
 include/media/v4l2-mc.h                            |   25 +
 include/uapi/Kbuild                                |    1 +
 include/uapi/linux/media.h                         |    6 +
 include/uapi/linux/v4l2-controls.h                 |    4 +
 include/uapi/linux/videodev2.h                     |    1 +
 include/uapi/media/Kbuild                          |    2 +
 include/uapi/media/imx.h                           |   29 +
 52 files changed, 12496 insertions(+), 29 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
 create mode 100644 Documentation/devicetree/bindings/media/video-multiplexer.txt
 create mode 100644 Documentation/media/v4l-drivers/imx.rst
 create mode 100644 drivers/media/i2c/ov5640.c
 create mode 100644 drivers/media/platform/video-multiplexer.c
 create mode 100644 drivers/staging/media/imx/Kconfig
 create mode 100644 drivers/staging/media/imx/Makefile
 create mode 100644 drivers/staging/media/imx/TODO
 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
 create mode 100644 drivers/staging/media/imx/imx-media-capture.c
 create mode 100644 drivers/staging/media/imx/imx-media-csi.c
 create mode 100644 drivers/staging/media/imx/imx-media-dev.c
 create mode 100644 drivers/staging/media/imx/imx-media-fim.c
 create mode 100644 drivers/staging/media/imx/imx-media-internal-sd.c
 create mode 100644 drivers/staging/media/imx/imx-media-of.c
 create mode 100644 drivers/staging/media/imx/imx-media-utils.c
 create mode 100644 drivers/staging/media/imx/imx-media-vdic.c
 create mode 100644 drivers/staging/media/imx/imx-media.h
 create mode 100644 drivers/staging/media/imx/imx6-mipi-csi2.c
 create mode 100644 include/media/imx.h
 create mode 100644 include/uapi/media/Kbuild
 create mode 100644 include/uapi/media/imx.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v4 1/36 dt-bindings: Add bindings for i.MX media driver

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +66 -0
new file mode 100644
index 0000000..fd5af50
@@ -0,0 +1,66 @@
+Freescale i.MX Media Video Device
+=================================
+
+Video Media Controller node
+---------------------------
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports      : Should contain a list of phandles pointing to camera
+		sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+	compatible = "fsl,capture-subsystem";
+	ports = <&ipu1_csi0>, <&ipu1_csi1>;
+};
+
+fim child node
+--------------
+
+This is an optional child node of the ipu_csi port nodes. If present and
+available, it enables the Frame Interval Monitor. Its properties can be
+used to modify the method in which the FIM measures frame intervals.
+Refer to Documentation/media/v4l-drivers/imx.rst for more info on the
+Frame Interval Monitor.
+
+Optional properties:
+- fsl,input-capture-channel: an input capture channel and channel flags,
+			     specified as <chan flags>. The channel number
+			     must be 0 or 1. The flags can be
+			     IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, or
+			     IRQ_TYPE_EDGE_BOTH, and specify which input
+			     capture signal edge will trigger the input
+			     capture event. If an input capture channel is
+			     specified, the FIM will use this method to
+			     measure frame intervals instead of via the EOF
+			     interrupt. The input capture method is much
+			     preferred over EOF as it is not subject to
+			     interrupt latency errors. However it requires
+			     routing the VSYNC or FIELD output signals of
+			     the camera sensor to one of the i.MX input
+			     capture pads (SD1_DAT0, SD1_DAT1), which also
+			     gives up support for SD1.
+
+
+mipi_csi2 node
+--------------
+
+This is the device node for the MIPI CSI-2 Receiver, required for MIPI
+CSI-2 sensors.
+
+Required properties:
+- compatible	: "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
+- reg           : physical base address and length of the register set;
+- clocks	: the MIPI CSI-2 receiver requires three clocks: hsi_tx
+                  (the DPHY clock), video_27m, and eim_podf;
+- clock-names	: must contain "dphy", "cfg", "pix";
+
+Optional properties:
+- interrupts	: must contain two level-triggered interrupts,
+                  in order: 100 and 101;
Signature · 1 line
2.7.4
author maintainer
#6 lore raw

PATCH v4 2/36 ARM: dts: imx6qdl: Add compatible, clocks, irqs to MIPI CSI-2 node

In reply to Steve Longerbeam

Add to the MIPI CSI2 receiver node: compatible strings, interrupt sources, and clocks.

---
 arch/arm/boot/dts/imx6qdl.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/dts/imx6qdl.dtsi +7 -0
index 61569c8..aac70b9 100644
@@ -1125,7 +1125,14 @@
 			};
 
 			mipi_csi: mipi at 021dc000 {
+				compatible = "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
 				reg = <0x021dc000 0x4000>;
+				interrupts = <0 100 0x04>, <0 101 0x04>;
+				clocks = <&clks IMX6QDL_CLK_HSI_TX>,
+					 <&clks IMX6QDL_CLK_VIDEO_27M>,
+					 <&clks IMX6QDL_CLK_EIM_PODF>;
+				clock-names = "dphy", "cfg", "pix";
+				status = "disabled";
 			};
 
 			mipi_dsi: mipi at 021e0000 {
Signature · 1 line
2.7.4
author maintainer
#7 lore raw

PATCH v4 3/36 ARM: dts: imx6qdl: Add mipi_ipu1/2 multiplexers, mipi_csi, and their connections

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

This patch adds the device tree graph connecting the input multiplexers to the IPU CSIs and the MIPI-CSI2 gasket on i.MX6. The MIPI_IPU multiplexers are added as children of the iomuxc-gpr syscon device node. On i.MX6Q/D two two-input multiplexers in front of IPU1 CSI0 and IPU2 CSI1 allow to select between CSI0/1 parallel input pads and the MIPI CSI-2 virtual channels 0/3.
On i.MX6DL/S two five-input multiplexers in front of IPU1 CSI0 and IPU1 CSI1 allow to select between CSI0/1 parallel input pads and any of the four MIPI CSI-2 virtual channels.

--

- Removed some dangling/unused endpoints (ipu2_csi0_from_csi2ipu)
- Renamed the mipi virtual channel endpoint labels, from "mipi_csiX_..." to "mipi_vcX...".
- Added input endpoint anchors to the video muxes for the connections from parallel sensors.

---
 arch/arm/boot/dts/imx6dl.dtsi  | 180 +++++++++++++++++++++++++++++++++++++++++
 arch/arm/boot/dts/imx6q.dtsi   | 116 ++++++++++++++++++++++++++
 arch/arm/boot/dts/imx6qdl.dtsi |  10 ++-
 3 files changed, 305 insertions(+), 1 deletion(-)
arch/arm/boot/dts/imx6dl.dtsi +180 -0
index 1ade195..371288a 100644
@@ -181,6 +181,186 @@
 		      "di0", "di1";
 };
 
+&gpr {
+	ipu1_csi0_mux: ipu1_csi0_mux at 34 {
+		compatible = "video-multiplexer";
+		reg = <0x34>;
+		bit-mask = <0x7>;
+		bit-shift = <0>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "okay";
+
+		port at 0 {
+			reg = <0>;
+
+			ipu1_csi0_mux_from_mipi_vc0: endpoint {
+				remote-endpoint = <&mipi_vc0_to_ipu1_csi0_mux>;
+			};
+		};
+
+		port at 1 {
+			reg = <1>;
+
+			ipu1_csi0_mux_from_mipi_vc1: endpoint {
+				remote-endpoint = <&mipi_vc1_to_ipu1_csi0_mux>;
+			};
+		};
+
+		port at 2 {
+			reg = <2>;
+
+			ipu1_csi0_mux_from_mipi_vc2: endpoint {
+				remote-endpoint = <&mipi_vc2_to_ipu1_csi0_mux>;
+			};
+		};
+
+		port at 3 {
+			reg = <3>;
+
+			ipu1_csi0_mux_from_mipi_vc3: endpoint {
+				remote-endpoint = <&mipi_vc3_to_ipu1_csi0_mux>;
+			};
+		};
+
+		port at 4 {
+			reg = <4>;
+
+			ipu1_csi0_mux_from_parallel_sensor: endpoint {
+			};
+		};
+
+		port at 5 {
+			reg = <5>;
+
+			ipu1_csi0_mux_to_ipu1_csi0: endpoint {
+				remote-endpoint = <&ipu1_csi0_from_ipu1_csi0_mux>;
+			};
+		};
+	};
+
+	ipu1_csi1_mux: ipu1_csi1_mux at 34 {
+		compatible = "video-multiplexer";
+		reg = <0x34>;
+		bit-mask = <0x7>;
+		bit-shift = <3>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "okay";
+
+		port at 0 {
+			reg = <0>;
+
+			ipu1_csi1_mux_from_mipi_vc0: endpoint {
+				remote-endpoint = <&mipi_vc0_to_ipu1_csi1_mux>;
+			};
+		};
+
+		port at 1 {
+			reg = <1>;
+
+			ipu1_csi1_mux_from_mipi_vc1: endpoint {
+				remote-endpoint = <&mipi_vc1_to_ipu1_csi1_mux>;
+			};
+		};
+
+		port at 2 {
+			reg = <2>;
+
+			ipu1_csi1_mux_from_mipi_vc2: endpoint {
+				remote-endpoint = <&mipi_vc2_to_ipu1_csi1_mux>;
+			};
+		};
+
+		port at 3 {
+			reg = <3>;
+
+			ipu1_csi1_mux_from_mipi_vc3: endpoint {
+				remote-endpoint = <&mipi_vc3_to_ipu1_csi1_mux>;
+			};
+		};
+
+		port at 4 {
+			reg = <4>;
+
+			ipu1_csi1_mux_from_parallel_sensor: endpoint {
+			};
+		};
+
+		port at 5 {
+			reg = <5>;
+
+			ipu1_csi1_mux_to_ipu1_csi1: endpoint {
+				remote-endpoint = <&ipu1_csi1_from_ipu1_csi1_mux>;
+			};
+		};
+	};
+};
+
+&ipu1_csi1 {
+	ipu1_csi1_from_ipu1_csi1_mux: endpoint {
+		remote-endpoint = <&ipu1_csi1_mux_to_ipu1_csi1>;
+	};
+};
+
+&mipi_csi {
+	port at 1 {
+		reg = <1>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mipi_vc0_to_ipu1_csi0_mux: endpoint at 0 {
+			remote-endpoint = <&ipu1_csi0_mux_from_mipi_vc0>;
+		};
+
+		mipi_vc0_to_ipu1_csi1_mux: endpoint at 1 {
+			remote-endpoint = <&ipu1_csi1_mux_from_mipi_vc0>;
+		};
+	};
+
+	port at 2 {
+		reg = <2>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mipi_vc1_to_ipu1_csi0_mux: endpoint at 0 {
+			remote-endpoint = <&ipu1_csi0_mux_from_mipi_vc1>;
+		};
+
+		mipi_vc1_to_ipu1_csi1_mux: endpoint at 1 {
+			remote-endpoint = <&ipu1_csi1_mux_from_mipi_vc1>;
+		};
+	};
+
+	port at 3 {
+		reg = <3>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mipi_vc2_to_ipu1_csi0_mux: endpoint at 0 {
+			remote-endpoint = <&ipu1_csi0_mux_from_mipi_vc2>;
+		};
+
+		mipi_vc2_to_ipu1_csi1_mux: endpoint at 1 {
+			remote-endpoint = <&ipu1_csi1_mux_from_mipi_vc2>;
+		};
+	};
+
+	port at 4 {
+		reg = <4>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mipi_vc3_to_ipu1_csi0_mux: endpoint at 0 {
+			remote-endpoint = <&ipu1_csi0_mux_from_mipi_vc3>;
+		};
+
+		mipi_vc3_to_ipu1_csi1_mux: endpoint at 1 {
+			remote-endpoint = <&ipu1_csi1_mux_from_mipi_vc3>;
+		};
+	};
+};
+
 &vpu {
 	compatible = "fsl,imx6dl-vpu", "cnm,coda960";
 };
arch/arm/boot/dts/imx6q.dtsi +116 -0

138 lines not on this page · raw message

arch/arm/boot/dts/imx6qdl.dtsi +9 -1
index aac70b9..c4130d5 100644
@@ -799,8 +799,10 @@
 			};
 
 			gpr: iomuxc-gpr at 020e0000 {
-				compatible = "fsl,imx6q-iomuxc-gpr", "syscon";
+				compatible = "fsl,imx6q-iomuxc-gpr", "syscon", "simple-mfd";
 				reg = <0x020e0000 0x38>;
+				#address-cells = <1>;
+				#size-cells = <0>;
 			};
 
 			iomuxc: iomuxc at 020e0000 {
@@ -1127,6 +1129,8 @@
 			mipi_csi: mipi at 021dc000 {
 				compatible = "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
 				reg = <0x021dc000 0x4000>;
+				#address-cells = <1>;
+				#size-cells = <0>;
 				interrupts = <0 100 0x04>, <0 101 0x04>;
 				clocks = <&clks IMX6QDL_CLK_HSI_TX>,
 					 <&clks IMX6QDL_CLK_VIDEO_27M>,
@@ -1234,6 +1238,10 @@
 
 			ipu1_csi0: port at 0 {
 				reg = <0>;
+
+				ipu1_csi0_from_ipu1_csi0_mux: endpoint {
+					remote-endpoint = <&ipu1_csi0_mux_to_ipu1_csi0>;
+				};
 			};
 
 			ipu1_csi1: port at 1 {
Signature · 1 line
2.7.4
author maintainer
#8 lore raw

PATCH v4 4/36 ARM: dts: imx6qdl: add capture-subsystem device

In reply to Steve Longerbeam
---
 arch/arm/boot/dts/imx6dl.dtsi | 5 +++++
 arch/arm/boot/dts/imx6q.dtsi  | 5 +++++
 2 files changed, 10 insertions(+)
arch/arm/boot/dts/imx6dl.dtsi +5 -0
index 371288a..f1743fc 100644
@@ -100,6 +100,11 @@
 		};
 	};
 
+	capture-subsystem {
+		compatible = "fsl,imx-capture-subsystem";
+		ports = <&ipu1_csi0>, <&ipu1_csi1>;
+	};
+
 	display-subsystem {
 		compatible = "fsl,imx-display-subsystem";
 		ports = <&ipu1_di0>, <&ipu1_di1>;
arch/arm/boot/dts/imx6q.dtsi +5 -0
index b833b0d..4cc6579 100644
@@ -206,6 +206,11 @@
 		};
 	};
 
+	capture-subsystem {
+		compatible = "fsl,imx-capture-subsystem";
+		ports = <&ipu1_csi0>, <&ipu1_csi1>, <&ipu2_csi0>, <&ipu2_csi1>;
+	};
+
 	display-subsystem {
 		compatible = "fsl,imx-display-subsystem";
 		ports = <&ipu1_di0>, <&ipu1_di1>, <&ipu2_di0>, <&ipu2_di1>;
Signature · 1 line
2.7.4
author maintainer
#9 lore raw

PATCH v4 5/36 ARM: dts: imx6qdl-sabrelite: remove erratum ERR006687 workaround

In reply to Steve Longerbeam

There is a pin conflict with GPIO_6. This pin functions as a power input pin to the OV5642 camera sensor, but ENET uses it as the h/w workaround for erratum ERR006687, to wake-up the ARM cores on normal RX and TX packet done events. So we need to remove the h/w workaround to support the OV5642. The result is that the CPUidle driver will no longer allow entering the deep idle states on the sabrelite.

This is a partial revert of

commit 6261c4c8f13e ("ARM: dts: imx6qdl-sabrelite: use GPIO_6 for FEC
interrupt.")
commit a28eeb43ee57 ("ARM: dts: imx6: tag boards that have the HW workaround

			for ERR006687")
---
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 4 ----
 1 file changed, 4 deletions(-)
arch/arm/boot/dts/imx6qdl-sabrelite.dtsi +0 -4
index 1f9076e..795b5a5 100644
@@ -271,9 +271,6 @@
 	txd1-skew-ps = <0>;
 	txd2-skew-ps = <0>;
 	txd3-skew-ps = <0>;
-	interrupts-extended = <&gpio1 6 IRQ_TYPE_LEVEL_HIGH>,
-			      <&intc 0 119 IRQ_TYPE_LEVEL_HIGH>;
-	fsl,err006687-workaround-present;
 	status = "okay";
 };
 
@@ -374,7 +371,6 @@
 				MX6QDL_PAD_RGMII_RX_CTL__RGMII_RX_CTL	0x1b030
 				/* Phy reset */
 				MX6QDL_PAD_EIM_D23__GPIO3_IO23		0x000b0
-				MX6QDL_PAD_GPIO_6__ENET_IRQ		0x000b1
 			>;
 		};
 
Signature · 1 line
2.7.4
author maintainer
#10 lore raw

PATCH v4 6/36 ARM: dts: imx6-sabrelite: add OV5642 and OV5640 camera sensors

In reply to Steve Longerbeam

Adds the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor. Both hang off the same i2c2 bus, so they require different (and non- default) i2c slave addresses.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

The OV5640 connects to the input port on the MIPI CSI-2 receiver on mipi_csi.

The OV5642 node is disabled temporarily while the subdev driver is cleaned up and submitted later.

---
 arch/arm/boot/dts/imx6dl-sabrelite.dts   |   5 ++
 arch/arm/boot/dts/imx6q-sabrelite.dts    |   5 ++
 arch/arm/boot/dts/imx6qdl-sabrelite.dtsi | 148 +++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+)
arch/arm/boot/dts/imx6dl-sabrelite.dts +5 -0
index 0f06ca5..cfd5110 100644
@@ -48,3 +48,8 @@
 	model = "Freescale i.MX6 DualLite SABRE Lite Board";
 	compatible = "fsl,imx6dl-sabrelite", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+	clock-lanes = <0>;
+	data-lanes = <1 2>;
+};
arch/arm/boot/dts/imx6q-sabrelite.dts +5 -0
index 66d10d8..e00fc06 100644
@@ -52,3 +52,8 @@
 &sata {
 	status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+	clock-lanes = <0>;
+	data-lanes = <1 2>;
+};
arch/arm/boot/dts/imx6qdl-sabrelite.dtsi +148 -0

187 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#11 lore raw

PATCH v4 7/36 ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors

In reply to Steve Longerbeam

Enables the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

The OV5640 connects to the input port on the MIPI CSI-2 receiver on mipi_csi.

Until the OV5652 sensor module compatible with the SabreSD becomes available for testing, the ov5642 node is currently disabled.

---
 arch/arm/boot/dts/imx6dl-sabresd.dts   |   5 ++
 arch/arm/boot/dts/imx6q-sabresd.dts    |   5 ++
 arch/arm/boot/dts/imx6qdl-sabresd.dtsi | 114 ++++++++++++++++++++++++++++++++-
 3 files changed, 123 insertions(+), 1 deletion(-)
arch/arm/boot/dts/imx6dl-sabresd.dts +5 -0
index 1e45f2f..9607afe 100644
@@ -15,3 +15,8 @@
 	model = "Freescale i.MX6 DualLite SABRE Smart Device Board";
 	compatible = "fsl,imx6dl-sabresd", "fsl,imx6dl";
 };
+
+&ipu1_csi1_from_ipu1_csi1_mux {
+	clock-lanes = <0>;
+	data-lanes = <1 2>;
+};
arch/arm/boot/dts/imx6q-sabresd.dts +5 -0
index 9cbdfe7..527772b 100644
@@ -23,3 +23,8 @@
 &sata {
 	status = "okay";
 };
+
+&ipu1_csi1_from_mipi_vc1 {
+	clock-lanes = <0>;
+	data-lanes = <1 2>;
+};
arch/arm/boot/dts/imx6qdl-sabresd.dtsi +113 -1

144 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#14 lore raw

PATCH v4 8/36 ARM: dts: imx6-sabreauto: create i2cmux for i2c3

In reply to Steve Longerbeam

The sabreauto uses a steering pin to select between the SDA signal on i2c3 bus, and a data-in pin for an SPI NOR chip. Use i2cmux to control this steering pin. Idle state of the i2cmux selects SPI NOR. This is not a classic way to use i2cmux, since one side of the mux selects something other than an i2c bus, but it works and is probably the cleanest solution. Note that if one thread is attempting to access SPI NOR while another thread is accessing i2c3, the SPI NOR access will fail since the i2cmux has selected the SDA pin rather than SPI NOR data-in. This couldn't be avoided in any case, the board is not designed to allow concurrent i2c3 and SPI NOR functions (and the default device-tree does not enable SPI NOR anyway).

Devices hanging off i2c3 should now be defined under i2cmux, so that the steering pin can be properly controlled to access those devices. The port expanders (MAX7310) are thus moved into i2cmux.

---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 65 +++++++++++++++++++++-----------
 1 file changed, 44 insertions(+), 21 deletions(-)
arch/arm/boot/dts/imx6qdl-sabreauto.dtsi +44 -21
index 52390ba..cace88c 100644
@@ -108,6 +108,44 @@
 		default-brightness-level = <7>;
 		status = "okay";
 	};
+
+	i2cmux {
+		compatible = "i2c-mux-gpio";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_i2c3mux>;
+		mux-gpios = <&gpio5 4 0>;
+		i2c-parent = <&i2c3>;
+		idle-state = <0>;
+
+		i2c at 1 {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <1>;
+
+			max7310_a: gpio at 30 {
+				compatible = "maxim,max7310";
+				reg = <0x30>;
+				gpio-controller;
+				#gpio-cells = <2>;
+			};
+
+			max7310_b: gpio at 32 {
+				compatible = "maxim,max7310";
+				reg = <0x32>;
+				gpio-controller;
+				#gpio-cells = <2>;
+			};
+
+			max7310_c: gpio at 34 {
+				compatible = "maxim,max7310";
+				reg = <0x34>;
+				gpio-controller;
+				#gpio-cells = <2>;
+			};
+		};
+	};
 };
 
 &clks {
@@ -291,27 +329,6 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&pinctrl_i2c3>;
 	status = "okay";
-
-	max7310_a: gpio at 30 {
-		compatible = "maxim,max7310";
-		reg = <0x30>;
-		gpio-controller;
-		#gpio-cells = <2>;
-	};
-
-	max7310_b: gpio at 32 {
-		compatible = "maxim,max7310";
-		reg = <0x32>;
-		gpio-controller;
-		#gpio-cells = <2>;
-	};
-
-	max7310_c: gpio at 34 {
-		compatible = "maxim,max7310";
-		reg = <0x34>;
-		gpio-controller;
-		#gpio-cells = <2>;
-	};
 };
 
 &iomuxc {
@@ -419,6 +436,12 @@
 			>;
 		};
 
+		pinctrl_i2c3mux: i2c3muxgrp {
+			fsl,pins = <
+				MX6QDL_PAD_EIM_A24__GPIO5_IO04 0x0b0b1
+			>;
+		};
+
 		pinctrl_pwm3: pwm1grp {
 			fsl,pins = <
 				MX6QDL_PAD_SD4_DAT1__PWM3_OUT		0x1b0b1
Signature · 1 line
2.7.4
author maintainer
#15 lore raw

PATCH v4 9/36 ARM: dts: imx6-sabreauto: add reset-gpios property for max7310_b

In reply to Steve Longerbeam

The reset pin to the port expander chip (MAX7310) is controlled by a gpio, so define a reset-gpios property to control it. There are three MAX7310's on the SabreAuto CPU card (max7310_[abc]), but all use the same pin for their reset. Since all can't acquire the same pin, assign it to max7310_b, that chip is needed by more functions (usb and adv7180).

---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/boot/dts/imx6qdl-sabreauto.dtsi +9 -0
index cace88c..967c3b8 100644
@@ -136,6 +136,9 @@
 				reg = <0x32>;
 				gpio-controller;
 				#gpio-cells = <2>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&pinctrl_max7310>;
+				reset-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
 			};
 
 			max7310_c: gpio at 34 {
@@ -442,6 +445,12 @@
 			>;
 		};
 
+		pinctrl_max7310: max7310grp {
+			fsl,pins = <
+				MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x1b0b0
+			>;
+		};
+
 		pinctrl_pwm3: pwm1grp {
 			fsl,pins = <
 				MX6QDL_PAD_SD4_DAT1__PWM3_OUT		0x1b0b1
Signature · 1 line
2.7.4
author maintainer
#16 lore raw

PATCH v4 10/36 ARM: dts: imx6-sabreauto: add pinctrl for gpt input capture

In reply to Steve Longerbeam

Add pinctrl groups for both GPT input capture channels.

---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/boot/dts/imx6qdl-sabreauto.dtsi +12 -0
index 967c3b8..495709f 100644
@@ -457,6 +457,18 @@
 			>;
 		};
 
+		pinctrl_gpt_input_capture0: gptinputcapture0grp {
+			fsl,pins = <
+				MX6QDL_PAD_SD1_DAT0__GPT_CAPTURE1	0x1b0b0
+			>;
+		};
+
+		pinctrl_gpt_input_capture1: gptinputcapture1grp {
+			fsl,pins = <
+				MX6QDL_PAD_SD1_DAT1__GPT_CAPTURE2	0x1b0b0
+			>;
+		};
+
 		pinctrl_spdif: spdifgrp {
 			fsl,pins = <
 				MX6QDL_PAD_KEY_COL3__SPDIF_IN 0x1b0b0
Signature · 1 line
2.7.4
author maintainer
#17 lore raw

PATCH v4 11/36 ARM: dts: imx6-sabreauto: add the ADV7180 video decoder

In reply to Steve Longerbeam

Enables the ADV7180 decoder sensor. The ADV7180 connects to the parallel-bus mux input on ipu1_csi0_mux.

The ADV7180 power pin is via max7310_b port expander.

---
 arch/arm/boot/dts/imx6qdl-sabreauto.dtsi | 58 ++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
arch/arm/boot/dts/imx6qdl-sabreauto.dtsi +58 -0
index 495709f..f03057b 100644
@@ -124,6 +124,21 @@
 			#size-cells = <0>;
 			reg = <1>;
 
+			adv7180: camera at 21 {
+				compatible = "adi,adv7180";
+				reg = <0x21>;
+				powerdown-gpios = <&max7310_b 2 GPIO_ACTIVE_LOW>;
+				interrupt-parent = <&gpio1>;
+				interrupts = <27 0x8>;
+
+				port {
+					adv7180_to_ipu1_csi0_mux: endpoint {
+						remote-endpoint = <&ipu1_csi0_mux_from_parallel_sensor>;
+						bus-width = <8>;
+					};
+				};
+			};
+
 			max7310_a: gpio at 30 {
 				compatible = "maxim,max7310";
 				reg = <0x30>;
@@ -151,6 +166,25 @@
 	};
 };
 
+&ipu1_csi0_from_ipu1_csi0_mux {
+	bus-width = <8>;
+};
+
+&ipu1_csi0_mux_from_parallel_sensor {
+	remote-endpoint = <&adv7180_to_ipu1_csi0_mux>;
+	bus-width = <8>;
+};
+
+&ipu1_csi0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_ipu1_csi0>;
+
+	/* enable frame interval monitor on this port */
+	fim {
+		status = "okay";
+	};
+};
+
 &clks {
 	assigned-clocks = <&clks IMX6QDL_PLL4_BYPASS_SRC>,
 			  <&clks IMX6QDL_PLL4_BYPASS>,
@@ -445,6 +479,30 @@
 			>;
 		};
 
+		pinctrl_ipu1_csi0: ipu1csi0grp {
+			fsl,pins = <
+				MX6QDL_PAD_CSI0_DAT4__IPU1_CSI0_DATA04   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT5__IPU1_CSI0_DATA05   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT6__IPU1_CSI0_DATA06   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT7__IPU1_CSI0_DATA07   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT8__IPU1_CSI0_DATA08   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT9__IPU1_CSI0_DATA09   0x1b0b0
+				MX6QDL_PAD_CSI0_DAT10__IPU1_CSI0_DATA10  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT11__IPU1_CSI0_DATA11  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT12__IPU1_CSI0_DATA12  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT13__IPU1_CSI0_DATA13  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT14__IPU1_CSI0_DATA14  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT15__IPU1_CSI0_DATA15  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT16__IPU1_CSI0_DATA16  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT17__IPU1_CSI0_DATA17  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT18__IPU1_CSI0_DATA18  0x1b0b0
+				MX6QDL_PAD_CSI0_DAT19__IPU1_CSI0_DATA19  0x1b0b0
+				MX6QDL_PAD_CSI0_PIXCLK__IPU1_CSI0_PIXCLK 0x1b0b0
+				MX6QDL_PAD_CSI0_MCLK__IPU1_CSI0_HSYNC    0x1b0b0
+				MX6QDL_PAD_CSI0_VSYNC__IPU1_CSI0_VSYNC   0x1b0b0
+			>;
+		};
+
 		pinctrl_max7310: max7310grp {
 			fsl,pins = <
 				MX6QDL_PAD_SD2_DAT0__GPIO1_IO15 0x1b0b0
Signature · 1 line
2.7.4
author maintainer
#18 lore raw

PATCH v4 12/36 add mux and video interface bridge entity functions

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

- renamed MEDIA_ENT_F_MUX to MEDIA_ENT_F_VID_MUX

---
 Documentation/media/uapi/mediactl/media-types.rst | 22 ++++++++++++++++++++++
 include/uapi/linux/media.h                        |  6 ++++++
 2 files changed, 28 insertions(+)
Documentation/media/uapi/mediactl/media-types.rst +22 -0
index 3e03dc2..023be29 100644
@@ -298,6 +298,28 @@ Types and flags used to represent the media graph elements
 	  received on its sink pad and outputs the statistics data on
 	  its source pad.
 
+    -  ..  row 29
+
+       ..  _MEDIA-ENT-F-MUX:
+
+       -  ``MEDIA_ENT_F_MUX``
+
+       - Video multiplexer. An entity capable of multiplexing must have at
+         least two sink pads and one source pad, and must pass the video
+         frame(s) received from the active sink pad to the source pad. Video
+         frame(s) from the inactive sink pads are discarded.
+
+    -  ..  row 30
+
+       ..  _MEDIA-ENT-F-VID-IF-BRIDGE:
+
+       -  ``MEDIA_ENT_F_VID_IF_BRIDGE``
+
+       - Video interface bridge. A video interface bridge entity must have at
+         least one sink pad and one source pad. It receives video frame(s) on
+         its sink pad in one bus format (HDMI, eDP, MIPI CSI-2, ...) and
+         converts them and outputs them on its source pad in another bus format
+         (eDP, MIPI CSI-2, parallel, ...).
 
 ..  tabularcolumns:: |p{5.5cm}|p{12.0cm}|
 
include/uapi/linux/media.h +6 -0
index 4890787..fac96c6 100644
@@ -105,6 +105,12 @@ struct media_device_info {
 #define MEDIA_ENT_F_PROC_VIDEO_STATISTICS	(MEDIA_ENT_F_BASE + 0x4006)
 
 /*
+ * Switch and bridge entitites
+ */
+#define MEDIA_ENT_F_VID_MUX			(MEDIA_ENT_F_BASE + 0x5001)
+#define MEDIA_ENT_F_VID_IF_BRIDGE		(MEDIA_ENT_F_BASE + 0x5002)
+
+/*
  * Connectors
  */
 /* It is a responsibility of the entity drivers to add connectors and links */
Signature · 1 line
2.7.4
author maintainer
#21 lore raw

PATCH v4 13/36 v4l2: add a frame timeout event

In reply to Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---
 Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
 Documentation/media/videodev2.h.rst.exceptions  | 1 +
 include/uapi/linux/videodev2.h                  | 1 +
 3 files changed, 7 insertions(+)
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.
     * - ``V4L2_EVENT_PRIVATE_START``
       - 0x08000000
       - Base event number for driver-private events.
Documentation/media/videodev2.h.rst.exceptions +1 -0
index e11a0d0..5b0f767 100644
@@ -459,6 +459,7 @@ replace define V4L2_EVENT_CTRL event-type
 replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_FRAME_TIMEOUT event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
include/uapi/linux/videodev2.h +1 -0
index 46e8a2e3..e174c45 100644
@@ -2132,6 +2132,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_FRAME_SYNC			4
 #define V4L2_EVENT_SOURCE_CHANGE		5
 #define V4L2_EVENT_MOTION_DET			6
+#define V4L2_EVENT_FRAME_TIMEOUT		7
 #define V4L2_EVENT_PRIVATE_START		0x08000000
 
 /* Payload for V4L2_EVENT_VSYNC */
Signature · 1 line
2.7.4
author maintainer
#32 lore raw

PATCH v4 14/36 v4l2-mc: add a function to inherit controls from a pipeline

In reply to Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +48 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)
+{
+	struct media_device *mdev = start_entity->graph_obj.mdev;
+	struct media_entity *entity;
+	struct media_graph graph;
+	struct v4l2_subdev *sd;
+	int ret;
+
+	ret = media_graph_walk_init(&graph, mdev);
+	if (ret)
+		return ret;
+
+	media_graph_walk_start(&graph, start_entity);
+
+	while ((entity = media_graph_walk_next(&graph))) {
+		if (!is_media_entity_v4l2_subdev(entity))
+			continue;
+
+		sd = media_entity_to_v4l2_subdev(entity);
+
+		ret = v4l2_ctrl_add_handler(vfd->ctrl_handler,
+					    sd->ctrl_handler,
+					    NULL);
+		if (ret)
+			break;
+	}
+
+	media_graph_walk_cleanup(&graph);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(__v4l2_pipeline_inherit_controls);
+
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				   struct media_entity *start_entity)
+{
+	struct media_device *mdev = start_entity->graph_obj.mdev;
+	int ret;
+
+	mutex_lock(&mdev->graph_mutex);
+	ret = __v4l2_pipeline_inherit_controls(vfd, start_entity);
+	mutex_unlock(&mdev->graph_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_pipeline_inherit_controls);
+
 /* -----------------------------------------------------------------------------
  * Pipeline power management
  *
include/media/v4l2-mc.h +25 -0
index 2634d9d..9848e77 100644
@@ -171,6 +171,17 @@ void v4l_disable_media_source(struct video_device *vdev);
  */
 int v4l_vb2q_enable_media_source(struct vb2_queue *q);
 
+/**
+ * v4l2_pipeline_inherit_controls - Add the v4l2 controls from all
+ *				    subdev entities in a pipeline to
+ *				    the given video device.
+ * @vfd: the video device
+ * @start_entity: Starting entity
+ */
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity);
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				   struct media_entity *start_entity);
 
 /**
  * v4l2_pipeline_pm_use - Update the use count of an entity
@@ -231,6 +242,20 @@ static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 	return 0;
 }
 
+static inline int __v4l2_pipeline_inherit_controls(
+	struct video_device *vfd,
+	struct media_entity *start_entity)
+{
+	return 0;
+}
+
+static inline int v4l2_pipeline_inherit_controls(
+	struct video_device *vfd,
+	struct media_entity *start_entity)
+{
+	return 0;
+}
+
 static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
 {
 	return 0;
Signature · 1 line
2.7.4
author maintainer
#121 lore raw

PATCH v4 15/36 platform: add video-multiplexer subdevice driver

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

This driver can handle SoC internal and external video bus multiplexers, controlled either by register bit fields or by a GPIO. The subdevice passes through frame interval and mbus configuration of the active input to the output side.

--

- fixed a cut&paste error in vidsw_remove(): v4l2_async_register_subdev() should be unregister.

- added media_entity_cleanup() and v4l2_device_unregister_subdev() to vidsw_remove().

- added missing MODULE_DEVICE_TABLE().

- there was a line left over from a previous iteration that negated the new way of determining the pad count just before it which has been removed (num_pads = of_get_child_count(np)).

- Philipp Zabel has developed a set of patches that allow adding to the subdev async notifier waiting list using a chaining method from the async registered callbacks (v4l2_of_subdev_registered() and the prep patches for that). For now, I've removed the use of v4l2_of_subdev_registered() for the vidmux driver's registered callback. This doesn't affect the functionality of this driver, but allows for it to be merged now, before adding the chaining support.

---
 .../bindings/media/video-multiplexer.txt           |  59 +++
 drivers/media/platform/Kconfig                     |   8 +
 drivers/media/platform/Makefile                    |   2 +
 drivers/media/platform/video-multiplexer.c         | 474 +++++++++++++++++++++
 4 files changed, 543 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/video-multiplexer.txt
 create mode 100644 drivers/media/platform/video-multiplexer.c
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +59 -0
new file mode 100644
index 0000000..9d133d9
@@ -0,0 +1,59 @@
+Video Multiplexer
+=================
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.
+
+Example:
+
+syscon {
+	compatible = "syscon", "simple-mfd";
+
+	mux {
+		compatible = "video-multiplexer";
+		/* Single bit (1 << 19) in syscon register 0x04: */
+		reg = <0x04>;
+		bit-mask = <1>;
+		bit-shift = <19>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		port at 0 {
+			reg = <0>;
+
+			mux_in0: endpoint {
+				remote-endpoint = <&video_source0_out>;
+			};
+		};
+
+		port at 1 {
+			reg = <1>;
+
+			mux_in1: endpoint {
+				remote-endpoint = <&video_source1_out>;
+			};
+		};
+
+		port at 2 {
+			reg = <2>;
+
+			mux_out: endpoint {
+				remote-endpoint = <&capture_interface_in>;
+			};
+		};
+	};
+};
drivers/media/platform/Kconfig +8 -0
index c9106e1..3d60d4c 100644
@@ -74,6 +74,14 @@ config VIDEO_M32R_AR_M64278
 	  To compile this driver as a module, choose M here: the
 	  module will be called arv.
 
+config VIDEO_MULTIPLEXER
+	tristate "Video Multiplexer"
+	depends on VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
+	help
+	  This driver provides support for SoC internal N:1 video bus
+	  multiplexers controlled by register bitfields as well as external
+	  2:1 video multiplexers controlled by a single GPIO.
+
 config VIDEO_OMAP3
 	tristate "OMAP 3 Camera support"
 	depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && ARCH_OMAP3
drivers/media/platform/Makefile +2 -0
index 349ddf6..31bfa99 100644
@@ -27,6 +27,8 @@ obj-$(CONFIG_VIDEO_SH_VEU)		+= sh_veu.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)	+= m2m-deinterlace.o
 
+obj-$(CONFIG_VIDEO_MULTIPLEXER)		+= video-multiplexer.o
+
 obj-$(CONFIG_VIDEO_S3C_CAMIF) 		+= s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) 	+= exynos4-is/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)	+= s5p-jpeg/
drivers/media/platform/video-multiplexer.c new file +474 -0

474 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#127 lore raw

PATCH v4 16/36 UAPI: Add media UAPI Kbuild file

In reply to Steve Longerbeam

Add an empty UAPI Kbuild file for media UAPI headers.

---
 include/uapi/Kbuild       | 1 +
 include/uapi/media/Kbuild | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 include/uapi/media/Kbuild
include/uapi/Kbuild +1 -0
index 245aa6e..9a51957 100644
@@ -6,6 +6,7 @@
 header-y += asm-generic/
 header-y += linux/
 header-y += sound/
+header-y += media/
 header-y += mtd/
 header-y += rdma/
 header-y += video/
include/uapi/media/Kbuild new file +1 -0
new file mode 100644
index 0000000..aafaa5a
@@ -0,0 +1 @@
+# UAPI Header export list
Signature · 1 line
2.7.4
author maintainer
#128 lore raw

PATCH v4 17/36 media: Add userspace header file for i.MX

In reply to Steve Longerbeam

This adds a header file for use by userspace programs wanting to interact with the i.MX media driver. It defines custom v4l2 controls and events generated by the i.MX v4l2 subdevices.

---
 include/uapi/media/Kbuild |  1 +
 include/uapi/media/imx.h  | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 include/uapi/media/imx.h
include/uapi/media/Kbuild +1 -0
index aafaa5a..fa78958 100644
@@ -1 +1,2 @@
 # UAPI Header export list
+header-y += imx.h
include/uapi/media/imx.h new file +29 -0
new file mode 100644
index 0000000..1fdd1c1
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014-2015 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 __UAPI_MEDIA_IMX_H__
+#define __UAPI_MEDIA_IMX_H__
+
+/*
+ * events from the subdevs
+ */
+#define V4L2_EVENT_IMX_CLASS          V4L2_EVENT_PRIVATE_START
+#define V4L2_EVENT_IMX_NFB4EOF        (V4L2_EVENT_IMX_CLASS + 1)
+#define V4L2_EVENT_IMX_FRAME_INTERVAL (V4L2_EVENT_IMX_CLASS + 2)
+
+enum imx_ctrl_id {
+	V4L2_CID_IMX_MOTION = (V4L2_CID_USER_IMX_BASE + 0),
+	V4L2_CID_IMX_FIM_ENABLE,
+	V4L2_CID_IMX_FIM_NUM,
+	V4L2_CID_IMX_FIM_TOLERANCE_MIN,
+	V4L2_CID_IMX_FIM_TOLERANCE_MAX,
+	V4L2_CID_IMX_FIM_NUM_SKIP,
+};
+
+#endif
Signature · 1 line
2.7.4
author maintainer
#131 lore raw

PATCH v4 18/36 media: Add i.MX media core driver

In reply to Steve Longerbeam

Add the core media driver for i.MX SOC.

---
 Documentation/media/v4l-drivers/imx.rst           | 542 +++++++++++++++++
 drivers/staging/media/Kconfig                     |   2 +
 drivers/staging/media/Makefile                    |   1 +
 drivers/staging/media/imx/Kconfig                 |   7 +
 drivers/staging/media/imx/Makefile                |   6 +
 drivers/staging/media/imx/TODO                    |  36 ++
 drivers/staging/media/imx/imx-media-dev.c         | 487 +++++++++++++++
 drivers/staging/media/imx/imx-media-fim.c         | 471 +++++++++++++++
 drivers/staging/media/imx/imx-media-internal-sd.c | 349 +++++++++++
 drivers/staging/media/imx/imx-media-of.c          | 267 ++++++++
 drivers/staging/media/imx/imx-media-utils.c       | 701 ++++++++++++++++++++++
 drivers/staging/media/imx/imx-media.h             | 297 +++++++++
 include/media/imx.h                               |  15 +
 include/uapi/linux/v4l2-controls.h                |   4 +
 14 files changed, 3185 insertions(+)
 create mode 100644 Documentation/media/v4l-drivers/imx.rst
 create mode 100644 drivers/staging/media/imx/Kconfig
 create mode 100644 drivers/staging/media/imx/Makefile
 create mode 100644 drivers/staging/media/imx/TODO
 create mode 100644 drivers/staging/media/imx/imx-media-dev.c
 create mode 100644 drivers/staging/media/imx/imx-media-fim.c
 create mode 100644 drivers/staging/media/imx/imx-media-internal-sd.c
 create mode 100644 drivers/staging/media/imx/imx-media-of.c
 create mode 100644 drivers/staging/media/imx/imx-media-utils.c
 create mode 100644 drivers/staging/media/imx/imx-media.h
 create mode 100644 include/media/imx.h
Documentation/media/v4l-drivers/imx.rst new file +542 -0
new file mode 100644
index 0000000..f085e43
@@ -0,0 +1,542 @@
+i.MX Video Capture Driver
+=========================
+
+Introduction
+------------
+
+The Freescale i.MX5/6 contains an Image Processing Unit (IPU), which
+handles the flow of image frames to and from capture devices and
+display devices.
+
+For image capture, the IPU contains the following internal subunits:
+
+- Image DMA Controller (IDMAC)
+- Camera Serial Interface (CSI)
+- Image Converter (IC)
+- Sensor Multi-FIFO Controller (SMFC)
+- Image Rotator (IRT)
+- Video De-Interlacing or Combining Block (VDIC)
+
+The IDMAC is the DMA controller for transfer of image frames to and from
+memory. Various dedicated DMA channels exist for both video capture and
+display paths. During transfer, the IDMAC is also capable of vertical
+image flip, 8x8 block transfer (see IRT description), pixel component
+re-ordering (for example UYVY to YUYV) within the same colorspace, and
+even packed <--> planar conversion. It can also perform a simple
+de-interlacing by interleaving even and odd lines during transfer
+(without motion compensation which requires the VDIC).
+
+The CSI is the backend capture unit that interfaces directly with
+camera sensors over Parallel, BT.656/1120, and MIPI CSI-2 busses.
+
+The IC handles color-space conversion, resizing (downscaling and
+upscaling), horizontal flip, and 90/270 degree rotation operations.
+
+There are three independent "tasks" within the IC that can carry out
+conversions concurrently: pre-process encoding, pre-process viewfinder,
+and post-processing. Within each task, conversions are split into three
+sections: downsizing section, main section (upsizing, flip, colorspace
+conversion, and graphics plane combining), and rotation section.
+
+The IPU time-shares the IC task operations. The time-slice granularity
+is one burst of eight pixels in the downsizing section, one image line
+in the main processing section, one image frame in the rotation section.
+
+The SMFC is composed of four independent FIFOs that each can transfer
+captured frames from sensors directly to memory concurrently via four
+IDMAC channels.
+
+The IRT carries out 90 and 270 degree image rotation operations. The
+rotation operation is carried out on 8x8 pixel blocks at a time. This
+operation is supported by the IDMAC which handles the 8x8 block transfer
+along with block reordering, in coordination with vertical flip.
+
+The VDIC handles the conversion of interlaced video to progressive, with
+support for different motion compensation modes (low, medium, and high
+motion). The deinterlaced output frames from the VDIC can be sent to the
+IC pre-process viewfinder task for further conversions. The VDIC also
+contains a Combiner that combines two image planes, with alpha blending
+and color keying.
+
+In addition to the IPU internal subunits, there are also two units
+outside the IPU that are also involved in video capture on i.MX:
+
+- MIPI CSI-2 Receiver for camera sensors with the MIPI CSI-2 bus
+  interface. This is a Synopsys DesignWare core.
+- Two video multiplexers for selecting among multiple sensor inputs
+  to send to a CSI.
+
+For more info, refer to the latest versions of the i.MX5/6 reference
+manuals listed under References.
+
+
+Features
+--------
+
+Some of the features of this driver include:
+
+- Many different pipelines can be configured via media controller API,
+  that correspond to the hardware video capture pipelines supported in
+  the i.MX.
+
+- Supports parallel, BT.565, and MIPI CSI-2 interfaces.
+
+- Up to four concurrent sensor acquisitions, by configuring each
+  sensor's pipeline using independent entities. This is currently
+  demonstrated with the SabreSD and SabreLite reference boards with
+  independent OV5642 and MIPI CSI-2 OV5640 sensor modules.
+
+- Scaling, color-space conversion, horizontal and vertical flip, and
+  image rotation via IC task subdevs.
+
+- Many pixel formats supported (RGB, packed and planar YUV, partial
+  planar YUV).
+
+- The VDIC subdev supports motion compensated de-interlacing, with three
+  motion compensation modes: low, medium, and high motion. The mode is
+  specified with a custom control. Pipelines are defined that allow
+  sending frames to the VDIC subdev directly from the CSI or from
+  memory buffers via an output/mem2mem device node. For low and medium
+  motion modes, the VDIC must receive from memory buffers via a device
+  node.
+
+- Includes a Frame Interval Monitor (FIM) that can correct vertical sync
+  problems with the ADV718x video decoders. See below for a description
+  of the FIM.
+
+
+Entities
+--------
+
+imx6-mipi-csi2
+--------------
+
+This is the MIPI CSI-2 receiver entity. It has one sink pad to receive
+the MIPI CSI-2 stream (usually from a MIPI CSI-2 camera sensor). It has
+four source pads, corresponding to the four MIPI CSI-2 demuxed virtual
+channel outputs.
+
+This entity actually consists of two sub-blocks. One is the MIPI CSI-2
+core. This is a Synopsys Designware MIPI CSI-2 core. The other sub-block
+is a "CSI-2 to IPU gasket". The gasket acts as a demultiplexer of the
+four virtual channels streams, providing four separate parallel buses
+containing each virtual channel that are routed to CSIs or video
+multiplexers as described below.
+
+On i.MX6 solo/dual-lite, all four virtual channel buses are routed to
+two video multiplexers. Both CSI0 and CSI1 can receive any virtual
+channel, as selected by the video multiplexers.
+
+On i.MX6 Quad, virtual channel 0 is routed to IPU1-CSI0 (after selected
+by a video mux), virtual channels 1 and 2 are hard-wired to IPU1-CSI1
+and IPU2-CSI0, respectively, and virtual channel 3 is routed to
+IPU2-CSI1 (again selected by a video mux).
+
+ipuX_csiY_mux
+-------------
+
+These are the video multiplexers. They have two or more sink pads to
+select from either camera sensors with a parallel interface, or from
+MIPI CSI-2 virtual channels from imx6-mipi-csi2 entity. They have a
+single source pad that routes to a CSI (ipuX_csiY entities).
+
+On i.MX6 solo/dual-lite, there are two video mux entities. One sits
+in front of IPU1-CSI0 to select between a parallel sensor and any of
+the four MIPI CSI-2 virtual channels (a total of five sink pads). The
+other mux sits in front of IPU1-CSI1, and again has five sink pads to
+select between a parallel sensor and any of the four MIPI CSI-2 virtual
+channels.
+
+On i.MX6 Quad, there are two video mux entities. One sits in front of
+IPU1-CSI0 to select between a parallel sensor and MIPI CSI-2 virtual
+channel 0 (two sink pads). The other mux sits in front of IPU2-CSI1 to
+select between a parallel sensor and MIPI CSI-2 virtual channel 3 (two
+sink pads).
+
+ipuX_csiY
+---------
+
+These are the CSI entities. They have a single sink pad receiving from
+either a video mux or from a MIPI CSI-2 virtual channel as described
+above.
+
+This entity has two source pads. The first source pad can link directly
+to the ipuX_vdic entity or the ipuX_ic_prp entity, using hardware links
+that require no IDMAC memory buffer transfer.
+
+When the direct source pad is routed to the ipuX_ic_prp entity, frames
+from the CSI will be processed by one of the IC pre-processing tasks.
+
+When the direct source pad is routed to the ipuX_vdic entity, the VDIC
+will carry out motion-compensated de-interlace using "high motion" mode
+(see description of ipuX_vdic entity).
+
+The second source pad sends video frames to memory buffers via the SMFC
+and an IDMAC channel. This source pad is routed to a capture device
+node.
+
+Note that since the IDMAC source pad makes use of an IDMAC channel, it
+can do pixel reordering within the same colorspace. For example, the
+sink pad can take UYVY2X8, but the IDMAC source pad can output YUYV2X8.
+If the sink pad is receiving YUV, the output at the capture device can
+also be converted to a planar YUV format such as YUV420.
+
+It will also perform simple de-interlace without motion compensation,
+which is activated if the sink pad's field type is an interlaced type,
+and the IDMAC source pad field type is set to none.
+
+ipuX_vdic
+---------
+
+The VDIC carries out motion compensated de-interlacing, with three
+motion compensation modes: low, medium, and high motion. The mode is
+specified with a custom v4l2 control. It has two sink pads and a
+single source pad.
+
+The direct sink pad receives from an ipuX_csiY direct pad. With this
+link the VDIC can only operate in high motion mode.
+
+When the IDMAC sink pad is activated, it receives from an output
+or mem2mem device node. With this pipeline, it can also operate
+in low and medium modes, because these modes require receiving
+frames from memory buffers. Note that an output or mem2mem device
+is not implemented yet, so this sink pad currently has no links.
+
+The source pad routes to the IC pre-processing entity ipuX_ic_prp.
+
+ipuX_ic_prp
+-----------
+
+This is the IC pre-processing entity. It acts as a router, routing
+data from its sink pad to one or both of its source pads.
+
+It has a single sink pad. The sink pad can receive from the ipuX_csiY
+direct pad, or from ipuX_vdic.
+
+This entity has two source pads. One source pad routes to the
+pre-process encode task entity (ipuX_ic_prpenc), the other to the
+pre-process viewfinder task entity (ipuX_ic_prpvf). Both source pads
+can be activated at the same time if the sink pad is receiving from
+ipuX_csiY. Only the source pad to the pre-process viewfinder task entity
+can be activated if the sink pad is receiving from ipuX_vdic (frames
+from the VDIC can only be processed by the pre-process viewfinder task).
+
+ipuX_ic_prpenc
+--------------
+
+This is the IC pre-processing encode entity. It has a single sink pad
+from ipuX_ic_prp, and a single source pad. The source pad is routed
+to a capture device node.
+
+This entity performs the IC pre-process encode task operations:
+color-space conversion, resizing (downscaling and upscaling), horizontal
+and vertical flip, and 90/270 degree rotation.
+
+Like the ipuX_csiY IDMAC source, it can also perform simple de-interlace
+without motion compensation, and pixel reordering.
+
+ipuX_ic_prpvf
+-------------
+
+This is the IC pre-processing viewfinder entity. It has a single sink pad
+from ipuX_ic_prp, and a single source pad. The source pad is routed to
+a capture device node.
+
+It is identical in operation to ipuX_ic_prpenc. It will receive and
+process de-interlaced frames from the ipuX_vdic if ipuX_ic_prp is
+receiving from ipuX_vdic.
+
+Like the ipuX_csiY IDMAC source, it can perform simple de-interlace
+without motion compensation. However, note that if the ipuX_vdic is
+included in the pipeline (ipuX_ic_prp is receiving from ipuX_vdic),
+it's not possible to use simple de-interlace in ipuX_ic_prpvf, since
+the ipuX_vdic has already carried out de-interlacing (with motion
+compensation) and therefore the field type output from ipuX_ic_prp can
+only be none.
+
+Capture Pipelines
+-----------------
+
+The following describe the various use-cases supported by the pipelines.
+
+The links shown do not include the backend sensor, video mux, or mipi
+csi-2 receiver links. This depends on the type of sensor interface
+(parallel or mipi csi-2). So in all cases, these pipelines begin with:
+
+sensor -> ipuX_csiY_mux -> ...
+
+for parallel sensors, or:
+
+sensor -> imx6-mipi-csi2 -> (ipuX_csiY_mux) -> ...
+
+for mipi csi-2 sensors. The imx6-mipi-csi2 receiver may need to route
+to the video mux (ipuX_csiY_mux) before sending to the CSI, depending
+on the mipi csi-2 virtual channel, hence ipuX_csiY_mux is shown in
+parenthesis.
+
+Unprocessed Video Capture:
+--------------------------
+
+Send frames directly from sensor to camera device interface node, with
+no conversions:
+
+-> ipuX_csiY IDMAC pad -> capture node
+
+IC Direct Conversions:
+----------------------
+
+This pipeline uses the preprocess encode entity to route frames directly
+from the CSI to the IC, to carry out scaling up to 1024x1024 resolution,
+CSC, flipping, and image rotation:
+
+-> ipuX_csiY direct pad -> ipuX_ic_prp -> ipuX_ic_prpenc -> capture node
+
+Motion Compensated De-interlace:
+--------------------------------
+
+This pipeline routes frames from the CSI direct pad to the VDIC entity to
+support motion-compensated de-interlacing (high motion mode only),
+scaling up to 1024x1024, CSC, flip, and rotation:
+
+-> ipuX_csiY direct pad -> ipuX_vdic direct pad -> ipuX_ic_prp ->
+   ipuX_ic_prpvf -> capture node
+
+
+Usage Notes
+-----------
+
+Many of the subdevs require information from the active sensor in the
+current pipeline when configuring pad formats. Therefore the media links
+should be established before configuring the media pad formats.
+
+Similarly, the capture device interfaces inherit controls from the
+active entities in the current pipeline at link-setup time. Therefore
+the capture device node links should be the last links established in
+order for the capture interfaces to "see" and inherit all possible
+controls.
+
+The following are usage notes for Sabre- reference platforms:
+
+
+SabreLite with OV5642 and OV5640
+--------------------------------
+
+This platform requires the OmniVision OV5642 module with a parallel
+camera interface, and the OV5640 module with a MIPI CSI-2
+interface. Both modules are available from Boundary Devices:
+
+https://boundarydevices.com/products/nit6x_5mp
+https://boundarydevices.com/product/nit6x_5mp_mipi
+
+Note that if only one camera module is available, the other sensor
+node can be disabled in the device tree.
+
+The OV5642 module is connected to the parallel bus input on the i.MX
+internal video mux to IPU1 CSI0. It's i2c bus connects to i2c bus 2.
+
+The MIPI CSI-2 OV5640 module is connected to the i.MX internal MIPI CSI-2
+receiver, and the four virtual channel outputs from the receiver are
+routed as follows: vc0 to the IPU1 CSI0 mux, vc1 directly to IPU1 CSI1,
+vc2 directly to IPU2 CSI0, and vc3 to the IPU2 CSI1 mux. The OV5640 is
+also connected to i2c bus 2 on the SabreLite, therefore the OV5642 and
+OV5640 must not share the same i2c slave address.
+
+The following basic example configures unprocessed video capture
+pipelines for both sensors. The OV5642 is routed to ipu1_csi0, and
+the OV5640 (transmitting on mipi csi-2 virtual channel 1) is routed
+to ipu1_csi1. Both sensors are configured to output 640x480, the
+OV5642 outputs YUYV2X8, the OV5640 UYVY2X8:
+
+.. code-block:: none
+
+   # Setup links for OV5642
+   media-ctl -l '"ov5642 1-0042":0 -> "ipu1_csi0_mux":1[1]'
+   media-ctl -l '"ipu1_csi0_mux":2 -> "ipu1_csi0":0[1]'
+   media-ctl -l '"ipu1_csi0":2 -> "ipu1_csi0 capture":0[1]'
+   # Setup links for OV5640
+   media-ctl -l '"ov5640_mipi 1-0040":0 -> "imx6-mipi-csi2":0[1]'
+   media-ctl -l '"imx6-mipi-csi2":2 -> "ipu1_csi1":0[1]'
+   media-ctl -l '"ipu1_csi1":2 -> "ipu1_csi1 capture":0[1]'
+   # Configure pads for OV5642 pipeline
+   media-ctl -V "\"ov5642 1-0042\":0 [fmt:YUYV2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi0_mux\":2 [fmt:YUYV2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi0\":2 [fmt:YUYV2X8/640x480 field:none]"
+   # Configure pads for OV5640 pipeline
+   media-ctl -V "\"ov5640_mipi 1-0040\":0 [fmt:UYVY2X8/640x480 field:none]"
+   media-ctl -V "\"imx6-mipi-csi2\":2 [fmt:UYVY2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi1\":2 [fmt:UYVY2X8/640x480 field:none]"
+
+Streaming can then begin independently on the capture device nodes
+"ipu1_csi0 capture" and "ipu1_csi1 capture".
+
+SabreAuto with ADV7180 decoder
+------------------------------
+
+On the SabreAuto, an on-board ADV7180 SD decoder is connected to the
+parallel bus input on the internal video mux to IPU1 CSI0.
+
+The following example configures a pipeline to capture from the ADV7180
+video decoder, assuming NTSC 720x480 input signals, with Motion
+Compensated de-interlacing. Pad field types assume the adv7180 outputs
+"alternate", which the ipu1_csi0 entity converts to "seq-tb" at its
+source pad. $outputfmt can be any format supported by the ipu1_ic_prpvf
+entity at its output pad:
+
+.. code-block:: none
+
+   # Setup links
+   media-ctl -l '"adv7180 4-0021":0 -> "ipu1_csi0_mux":1[1]'
+   media-ctl -l '"ipu1_csi0_mux":2 -> "ipu1_csi0":0[1]'
+   media-ctl -l '"ipu1_csi0":2 -> "ipu1_vdic":0[1]'
+   media-ctl -l '"ipu1_vdic":2 -> "ipu1_ic_prp":0[1]'
+   media-ctl -l '"ipu1_ic_prp":2 -> "ipu1_ic_prpvf":0[1]'
+   media-ctl -l '"ipu1_ic_prpvf":1 -> "ipu1_ic_prpvf capture":0[1]'
+   # Configure pads
+   media-ctl -V "\"adv7180 4-0021\":0 [fmt:UYVY2X8/720x480]"
+   media-ctl -V "\"ipu1_csi0_mux\":2 [fmt:UYVY2X8/720x480 field:alternate]"
+   media-ctl -V "\"ipu1_csi0\":1 [fmt:AYUV32/720x480 field:seq-tb]"
+   media-ctl -V "\"ipu1_vdic\":2 [fmt:AYUV32/720x480 field:none]"
+   media-ctl -V "\"ipu1_ic_prp\":2 [fmt:AYUV32/720x480 field:none]"
+   media-ctl -V "\"ipu1_ic_prpvf\":1 [fmt:$outputfmt field:none]"
+
+Streaming can then begin on the capture device node at
+"ipu1_ic_prpvf capture".
+
+This platform accepts Composite Video analog inputs to the ADV7180 on
+Ain1 (connector J42).
+
+Frame Interval Monitor
+----------------------
+
+The adv718x decoders can occasionally send corrupt fields during
+NTSC/PAL signal re-sync (too little or too many video lines). When
+this happens, the IPU triggers a mechanism to re-establish vertical
+sync by adding 1 dummy line every frame, which causes a rolling effect
+from image to image, and can last a long time before a stable image is
+recovered. Or sometimes the mechanism doesn't work at all, causing a
+permanent split image (one frame contains lines from two consecutive
+captured images).
+
+From experiment it was found that during image rolling, the frame
+intervals (elapsed time between two EOF's) drop below the nominal
+value for the current standard, by about one frame time (60 usec),
+and remain at that value until rolling stops.
+
+While the reason for this observation isn't known (the IPU dummy
+line mechanism should show an increase in the intervals by 1 line
+time every frame, not a fixed value), we can use it to detect the
+corrupt fields using a frame interval monitor. If the FIM detects a
+bad frame interval, a subdev event is sent. In response, userland can
+issue a streaming restart to correct the rolling/split image.
+
+The FIM is implemented in the ipuX_csiY entity, and the entities that
+generate End-Of-Frame interrupts call into the FIM to monitor the frame
+intervals: ipuX_ic_prpenc, and ipuX_ic_prpvf. Userland can register with
+the FIM event notifications on the ipuX_csiY subdev device node
+(V4L2_EVENT_IMX_FRAME_INTERVAL).
+
+The ipuX_csiY entity includes custom controls to tweak some dials for
+FIM. If one of these controls is changed during streaming, the FIM will
+be reset and will continue at the new settings.
+
+- V4L2_CID_IMX_FIM_ENABLE
+
+Enable/disable the FIM.
+
+- V4L2_CID_IMX_FIM_NUM
+
+How many frame interval errors to average before comparing against the
+nominal frame interval reported by the sensor. This can reduce noise
+from interrupt latency.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MIN
+
+If the averaged intervals fall outside nominal by this amount, in
+microseconds, streaming will be restarted.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MAX
+
+If any interval errors are higher than this value, those error samples
+are discarded and do not enter into the average. This can be used to
+discard really high interval errors that might be due to very high
+system load, causing excessive interrupt latencies.
+
+- V4L2_CID_IMX_FIM_NUM_SKIP
+
+How many frames to skip after a FIM reset or stream restart before
+FIM begins to average intervals. It has been found that there can
+be a few bad frame intervals after stream restart which are not
+attributed to adv718x sending a corrupt field, so this is used to
+skip those frames to prevent unnecessary restarts.
+
+
+SabreSD with MIPI CSI-2 OV5640
+------------------------------
+
+Similarly to SabreLite, the SabreSD supports a parallel interface
+OV5642 module on IPU1 CSI0, and a MIPI CSI-2 OV5640 module. The OV5642
+connects to i2c bus 1 and the OV5640 to i2c bus 2.
+
+The device tree for SabreSD includes OF graphs for both the parallel
+OV5642 and the MIPI CSI-2 OV5640, but as of this writing only the MIPI
+CSI-2 OV5640 has been tested, so the OV5642 node is currently disabled.
+The OV5640 module connects to MIPI connector J5 (sorry I don't have the
+compatible module part number or URL).
+
+The following example configures a direct conversion pipeline to capture
+from the OV5640. $sensorfmt can be any format supported by the OV5640.
+$sensordim is the frame dimension part of $sensorfmt (minus the mbus
+pixel code). $outputfmt can be any format supported by the
+ipu1_ic_prpenc entity at its output pad:
+
+.. code-block:: none
+
+   # Setup links
+   media-ctl -l '"ov5640_mipi 1-003c":0 -> "imx6-mipi-csi2":0[1]'
+   media-ctl -l '"imx6-mipi-csi2":2 -> "ipu1_csi1":0[1]'
+   media-ctl -l '"ipu1_csi1":1 -> "ipu1_ic_prp":0[1]'
+   media-ctl -l '"ipu1_ic_prp":1 -> "ipu1_ic_prpenc":0[1]'
+   media-ctl -l '"ipu1_ic_prpenc":1 -> "ipu1_ic_prpenc capture":0[1]'
+   # Configure pads
+   media-ctl -V "\"ov5640_mipi 1-003c\":0 [fmt:$sensorfmt field:none]"
+   media-ctl -V "\"imx6-mipi-csi2\":2 [fmt:$sensorfmt field:none]"
+   media-ctl -V "\"ipu1_csi1\":1 [fmt:AYUV32/$sensordim field:none]"
+   media-ctl -V "\"ipu1_ic_prp\":1 [fmt:AYUV32/$sensordim field:none]"
+   media-ctl -V "\"ipu1_ic_prpenc\":1 [fmt:$outputfmt field:none]"
+
+Streaming can then begin on "ipu1_ic_prpenc capture" node.
+
+
+
+Known Issues
+------------
+
+1. When using 90 or 270 degree rotation control at capture resolutions
+   near the IC resizer limit of 1024x1024, and combined with planar
+   pixel formats (YUV420, YUV422p), frame capture will often fail with
+   no end-of-frame interrupts from the IDMAC channel. To work around
+   this, use lower resolution and/or packed formats (YUYV, RGB3, etc.)
+   when 90 or 270 rotations are needed.
+
+
+File list
+---------
+
+drivers/staging/media/imx/
+include/media/imx.h
+include/uapi/media/imx.h
+
+References
+----------
+
+[1] "i.MX 6Dual/6Quad Applications Processor Reference Manual"
+[2] "i.MX 6Solo/6DualLite Applications Processor Reference Manual"
+
+
+Authors
+-------
+Steve Longerbeam <[email protected]>
+Philipp Zabel <[email protected]>
+Russell King - ARM Linux <[email protected]>
+
+Copyright (C) 2012-2017 Mentor Graphics Inc.
drivers/staging/media/Kconfig +2 -0
index ffb8fa7..05b55a8 100644
@@ -25,6 +25,8 @@ source "drivers/staging/media/cxd2099/Kconfig"
 
 source "drivers/staging/media/davinci_vpfe/Kconfig"
 
+source "drivers/staging/media/imx/Kconfig"
+
 source "drivers/staging/media/omap4iss/Kconfig"
 
 source "drivers/staging/media/s5p-cec/Kconfig"
drivers/staging/media/Makefile +1 -0
index a28e82c..6f50ddd 100644
@@ -1,6 +1,7 @@
 obj-$(CONFIG_I2C_BCM2048)	+= bcm2048/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC) += s5p-cec/
 obj-$(CONFIG_DVB_CXD2099)	+= cxd2099/
+obj-$(CONFIG_VIDEO_IMX_MEDIA)	+= imx/
 obj-$(CONFIG_LIRC_STAGING)	+= lirc/
 obj-$(CONFIG_VIDEO_DM365_VPFE)	+= davinci_vpfe/
 obj-$(CONFIG_VIDEO_OMAP4)	+= omap4iss/
drivers/staging/media/imx/Kconfig new file +7 -0
new file mode 100644
index 0000000..722ed55
@@ -0,0 +1,7 @@
+config VIDEO_IMX_MEDIA
+	tristate "i.MX5/6 V4L2 media core driver"
+	depends on MEDIA_CONTROLLER && VIDEO_V4L2 && ARCH_MXC && IMX_IPUV3_CORE
+	---help---
+	  Say yes here to enable support for video4linux media controller
+	  driver for the i.MX5/6 SOC.
+
drivers/staging/media/imx/Makefile new file +6 -0
new file mode 100644
index 0000000..ba8e4fb
@@ -0,0 +1,6 @@
+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
+
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
+
drivers/staging/media/imx/TODO new file +36 -0
new file mode 100644
index 0000000..f6d2bac
@@ -0,0 +1,36 @@
+
+- Finish v4l2-compliance
+
+- imx-csi subdev is not being autoloaded as a kernel module, probably
+  because ipu_add_client_devices() does not register the IPU client
+  platform devices, but only allocates those devices.
+
+- Currently registering with notifications from subdevs are only
+  available through the subdev device nodes and not through the main
+  capture device node. Need to come up with a way to find the capture
+  device in the current pipeline that owns the subdev that sent the
+  notify.
+
+- Clean up and move the ov5642 subdev driver to drivers/media/i2c, and
+  create the binding docs for it.
+
+- The Frame Interval Monitor could be exported to v4l2-core for
+  general use.
+
+- The subdev that is the original source of video data (referred to as
+  the "sensor" in the code), is called from various subdevs in the
+  pipeline in order to set/query the video standard ({g|s|enum}_std)
+  and to get/set the original frame interval from the capture interface
+  ([gs]_parm). Instead, the entities that need this info should call its
+  direct neighbor, and the neighbor should propagate the call to its
+  neighbor in turn if necessary.
+
+- At driver load time, the device-tree node that is the original source
+  (the "sensor"), is parsed to record its media bus configuration, and
+  this info is required in various subdevs to setup the pipeline.
+  Laurent Pinchart argues that instead the subdev should call its
+  neighbor's g_mbus_config op (which should be propagated if necessary)
+  to get this info. However Hans Verkuil is planning to remove the
+  g_mbus_config op. For now this driver uses the parsed DT mbus config
+  method until this issue is resolved.
+
drivers/staging/media/imx/imx-media-dev.c new file +487 -0

487 lines not on this page · raw message

drivers/staging/media/imx/imx-media-fim.c new file +471 -0

471 lines not on this page · raw message

drivers/staging/media/imx/imx-media-internal-sd.c new file +349 -0

349 lines not on this page · raw message

drivers/staging/media/imx/imx-media-of.c new file +267 -0

267 lines not on this page · raw message

drivers/staging/media/imx/imx-media-utils.c new file +701 -0

701 lines not on this page · raw message

drivers/staging/media/imx/imx-media.h new file +297 -0

119 lines not on this page · raw message

include/media/imx.h new file +15 -0
new file mode 100644
index 0000000..5025a72

Lines of this file are not shown. View the raw message.

include/uapi/linux/v4l2-controls.h +4 -0
index 0d2e1e0..6c29f42 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.7.4

Part of the diff is not shown here. View the raw message.

author maintainer
#138 lore raw

PATCH v4 19/36 media: imx: Add Capture Device Interface

In reply to Steve Longerbeam

This is the capture device interface driver that provides the v4l2 user interface. Frames can be received from various sources:

- directly from CSI for capturing unconverted images directly from camera sensors.

- from the IC pre-process encode task.

- from the IC pre-process viewfinder task.

---
 drivers/staging/media/imx/Makefile            |   2 +-
 drivers/staging/media/imx/imx-media-capture.c | 654 ++++++++++++++++++++++++++
 2 files changed, 655 insertions(+), 1 deletion(-)
 create mode 100644 drivers/staging/media/imx/imx-media-capture.c
drivers/staging/media/imx/Makefile +1 -1
index ba8e4fb..4606a3a 100644
@@ -3,4 +3,4 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.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
drivers/staging/media/imx/imx-media-capture.c new file +654 -0

654 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#139 lore raw

PATCH v4 20/36 media: imx: Add CSI subdev driver

In reply to Steve Longerbeam

This is a media entity subdevice for the i.MX Camera Sensor Interface module.

---
 drivers/staging/media/imx/Kconfig         |   13 +
 drivers/staging/media/imx/Makefile        |    2 +
 drivers/staging/media/imx/imx-media-csi.c | 1220 +++++++++++++++++++++++++++++
 3 files changed, 1235 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-csi.c
drivers/staging/media/imx/Kconfig +13 -0
index 722ed55..e27ad6d 100644
@@ -5,3 +5,16 @@ config VIDEO_IMX_MEDIA
 	  Say yes here to enable support for video4linux media controller
 	  driver for the i.MX5/6 SOC.
 
+if VIDEO_IMX_MEDIA
+menu "i.MX5/6 Media Sub devices"
+
+config VIDEO_IMX_CSI
+	tristate "i.MX5/6 Camera Sensor Interface driver"
+	depends on VIDEO_IMX_MEDIA && VIDEO_DEV && I2C
+	select VIDEOBUF2_DMA_CONTIG
+	default y
+	---help---
+	  A video4linux camera sensor interface driver for i.MX5/6.
+
+endmenu
+endif
drivers/staging/media/imx/Makefile +2 -0
index 4606a3a..c054490 100644
@@ -4,3 +4,5 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.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_CSI) += imx-media-csi.o
drivers/staging/media/imx/imx-media-csi.c new file +1220 -0

1,220 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#147 lore raw

PATCH v4 21/36 media: imx: Add VDIC subdev driver

In reply to Steve Longerbeam

This is a media entity subdevice driver for the i.MX Video De-Interlacing or Combining Block. So far this entity does not implement the Combining function but only motion compensated deinterlacing. Video frames are received from the CSI and are routed to the IC PRPVF entity.

---
 drivers/staging/media/imx/Makefile         |   1 +
 drivers/staging/media/imx/imx-media-vdic.c | 886 +++++++++++++++++++++++++++++
 2 files changed, 887 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-vdic.c
drivers/staging/media/imx/Makefile +1 -0
index c054490..1f01520 100644
@@ -4,5 +4,6 @@ imx-media-common-objs := imx-media-utils.o imx-media-fim.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_CSI) += imx-media-csi.o
drivers/staging/media/imx/imx-media-vdic.c new file +886 -0

886 lines not on this page · raw message

Signature · 1 line
2.7.4
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
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
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
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
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
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
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
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
#204 lore raw

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

In reply to Steve Longerbeam

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
#132 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

In reply to Steve Longerbeam
Quoted 3 lines · Steve Longerbeam

Add the core media driver for i.MX SOC.

Just as I reported on the 30th January:

Applying: media: Add i.MX media core driver .git/rebase-apply/patch:614: new blank line at EOF. +
.git/rebase-apply/patch:626: new blank line at EOF. +
.git/rebase-apply/patch:668: new blank line at EOF. +

These need 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.
#150 lore raw

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

In reply to Steve Longerbeam
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.
#168 lore raw

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

In reply to Steve Longerbeam

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.
maintainer
#201 lore raw

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

In reply to Steve Longerbeam
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

maintainer
#213 lore raw

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

In reply to Steve Longerbeam

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

maintainer
#206 lore raw

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

In reply to Steve Longerbeam
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

maintainer
#129 lore raw

Re: [PATCH v4 17/36] media: Add userspace header file for i.MX

In reply to Steve Longerbeam
Quoted 32 lines · Steve Longerbeam

This adds a header file for use by userspace programs wanting to interact with the i.MX media driver. It defines custom v4l2 controls and events generated by the i.MX v4l2 subdevices.

---
 include/uapi/media/Kbuild |  1 +
 include/uapi/media/imx.h  | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 include/uapi/media/imx.h
include/uapi/media/Kbuild +1 -0
index aafaa5a..fa78958 100644
@@ -1 +1,2 @@
 # UAPI Header export list
+header-y += imx.h
include/uapi/media/imx.h new file +8 -0
new file mode 100644
index 0000000..1fdd1c1
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2014-2015 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/uapi/media/imx.h line 18

Quoted 10 lines
include/uapi/media/imx.h new file +10 -0
+
+#ifndef __UAPI_MEDIA_IMX_H__
+#define __UAPI_MEDIA_IMX_H__
+
+/*
+ * events from the subdevs
+ */
+#define V4L2_EVENT_IMX_CLASS          V4L2_EVENT_PRIVATE_START
+#define V4L2_EVENT_IMX_NFB4EOF        (V4L2_EVENT_IMX_CLASS + 1)
+#define V4L2_EVENT_IMX_FRAME_INTERVAL (V4L2_EVENT_IMX_CLASS + 2)

These events are still i.MX specific. I think they shouldn't be.

include/uapi/media/imx.h line 29

Quoted 10 lines
include/uapi/media/imx.h new file +10 -0
+enum imx_ctrl_id {
+	V4L2_CID_IMX_MOTION = (V4L2_CID_USER_IMX_BASE + 0),
+	V4L2_CID_IMX_FIM_ENABLE,
+	V4L2_CID_IMX_FIM_NUM,
+	V4L2_CID_IMX_FIM_TOLERANCE_MIN,
+	V4L2_CID_IMX_FIM_TOLERANCE_MAX,
+	V4L2_CID_IMX_FIM_NUM_SKIP,
+};
+
+#endif

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.
#140 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Steve Longerbeam
Quoted 10 lines · Steve Longerbeam
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+static const struct platform_device_id imx_csi_ids[] = {
+	{ .name = "imx-ipuv3-csi" },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, imx_csi_ids);
+
+static struct platform_driver imx_csi_driver = {
+	.probe = imx_csi_probe,
+	.remove = imx_csi_remove,
+	.id_table = imx_csi_ids,

drivers/staging/media/imx/imx-media-csi.c line 1220

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+	.driver = {
+		.name = "imx-ipuv3-csi",
+	},
+};
+module_platform_driver(imx_csi_driver);
+
+MODULE_DESCRIPTION("i.MX CSI subdev driver");
+MODULE_AUTHOR("Steve Longerbeam <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:imx-ipuv3-csi");

Just a reminder that automatic module loading of this is completely broken right now (not your problem) due to this stupid idea in the IPUv3 code:

		if (!ret)
			ret = platform_device_add(pdev);
		if (ret) {
			platform_device_put(pdev);
			goto err_register;
		}

		/*
		 * Set of_node only after calling platform_device_add. Otherwise
		 * the platform:imx-ipuv3-crtc modalias won't be used.
		 */
		pdev->dev.of_node = of_node;

setting pdev->dev.of_node changes the modalias exported to userspace, so udev sees a DT based modalias, which causes it to totally miss any driver using a non-DT based modalias.

The IPUv3 code needs fixing, not only for imx-media-csi, but also for imx-ipuv3-crtc too, because that module will also suffer the same issue.

The only solution is... don't fsck with dev->of_node assignment. In this case, it's probably much better to pass it in via platform data. If you then absolutely must have dev->of_node, doing it in the driver means that you avoid the modalias mess before the appropriate driver is loaded. However, that's still not a nice solution because the modalias file still ends up randomly changing its contents.

As I say, not _your_ problem, but it's still a problem that needs solving, and I don't want it forgotten about.

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
#2 lore raw

Re: [PATCH v4 01/36] [media] dt-bindings: Add bindings for i.MX media driver

In reply to Steve Longerbeam
Quoted 23 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +9 -0
new file mode 100644
index 0000000..fd5af50
@@ -0,0 +1,66 @@
+Freescale i.MX Media Video Device
+=================================
+
+Video Media Controller node
+---------------------------
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.

Documentation/devicetree/bindings/media/imx.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/media/imx.txt new file +10 -0
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports      : Should contain a list of phandles pointing to camera
+		sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+	compatible = "fsl,capture-subsystem";

"fsl,imx-capture-subsystem"

regards
Philipp

#141 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Russell King - ARM Linux
Quoted 54 lines · Russell King - ARM Linux
Quoted 10 lines · Steve Longerbeam
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+static const struct platform_device_id imx_csi_ids[] = {
+	{ .name = "imx-ipuv3-csi" },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, imx_csi_ids);
+
+static struct platform_driver imx_csi_driver = {
+	.probe = imx_csi_probe,
+	.remove = imx_csi_remove,
+	.id_table = imx_csi_ids,

drivers/staging/media/imx/imx-media-csi.c line 1220

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+	.driver = {
+		.name = "imx-ipuv3-csi",
+	},
+};
+module_platform_driver(imx_csi_driver);
+
+MODULE_DESCRIPTION("i.MX CSI subdev driver");
+MODULE_AUTHOR("Steve Longerbeam <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:imx-ipuv3-csi");

Just a reminder that automatic module loading of this is completely broken right now (not your problem) due to this stupid idea in the IPUv3 code:

		if (!ret)
			ret = platform_device_add(pdev);
		if (ret) {
			platform_device_put(pdev);
			goto err_register;
		}

		/*
		 * Set of_node only after calling platform_device_add. Otherwise
		 * the platform:imx-ipuv3-crtc modalias won't be used.
		 */
		pdev->dev.of_node = of_node;

setting pdev->dev.of_node changes the modalias exported to userspace, so udev sees a DT based modalias, which causes it to totally miss any driver using a non-DT based modalias.

The IPUv3 code needs fixing, not only for imx-media-csi, but also for imx-ipuv3-crtc too, because that module will also suffer the same issue.

The only solution is... don't fsck with dev->of_node assignment. In this case, it's probably much better to pass it in via platform data. If you then absolutely must have dev->of_node, doing it in the driver means that you avoid the modalias mess before the appropriate driver is loaded. However, that's still not a nice solution because the modalias file still ends up randomly changing its contents.

Quoted 2 lines

As I say, not _your_ problem, but it's still a problem that needs solving, and I don't want it forgotten about.

I've just hacked up a solution to this, and unfortunately it reveals a problem with Steve's code. Picking out the imx & media-related messages:

[    8.012191] imx_media_common: module is from the staging directory, the quality is unknown, you have been warned.
[    8.018175] imx_media: module is from the staging directory, the quality is unknown, you have been warned.
[    8.748345] imx-media: Registered subdev ipu1_csi0_mux
[    8.753451] imx-media: Registered subdev ipu2_csi1_mux
[    9.055196] imx219 0-0010: detected IMX219 sensor
[    9.090733] imx6_mipi_csi2: module is from the staging directory, the quality is unknown, you have been warned.
[    9.092247] imx-media: Registered subdev imx219 0-0010
[    9.334338] imx-media: Registered subdev imx6-mipi-csi2
[    9.372452] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.378163] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.390033] imx_media_csi: module is from the staging directory, the quality is unknown, you have been warned.
[    9.394362] imx-media: Received unknown subdev ipu1_csi0
[    9.394699] imx-ipuv3-csi: probe of imx-ipuv3-csi.0 failed with error -22
[    9.394840] imx-media: Received unknown subdev ipu1_csi1
[    9.394887] imx-ipuv3-csi: probe of imx-ipuv3-csi.1 failed with error -22
[    9.394992] imx-media: Received unknown subdev ipu2_csi0
[    9.395026] imx-ipuv3-csi: probe of imx-ipuv3-csi.4 failed with error -22
[    9.395119] imx-media: Received unknown subdev ipu2_csi1
[    9.395159] imx-ipuv3-csi: probe of imx-ipuv3-csi.5 failed with error -22
[    9.411722] imx_media_vdic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.412820] imx-media: Registered subdev ipu1_vdic
[    9.424687] imx-media: Registered subdev ipu2_vdic
[    9.436074] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.437455] imx-media: Registered subdev ipu1_ic_prp
[    9.437788] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.447542] imx-media: Registered subdev ipu1_ic_prpenc
[    9.455225] ipu1_ic_prpenc: Registered ipu1_ic_prpenc capture as /dev/video3
[    9.459203] imx-media: Registered subdev ipu1_ic_prpvf
[    9.460484] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.460726] ipu1_ic_prpvf: Registered ipu1_ic_prpvf capture as /dev/video4
[    9.460983] imx-media: Registered subdev ipu2_ic_prp
[    9.461161] imx-media: Registered subdev ipu2_ic_prpenc
[    9.461737] ipu2_ic_prpenc: Registered ipu2_ic_prpenc capture as /dev/video5
[    9.463767] imx-media: Registered subdev ipu2_ic_prpvf
[    9.464294] ipu2_ic_prpvf: Registered ipu2_ic_prpvf capture as /dev/video6
[    9.464345] imx-media: imx_media_create_link: (null):1 -> ipu1_ic_prp:0
[    9.464413] ------------[ cut here ]------------
[    9.469134] kernel BUG at /home/rmk/git/linux-rmk/drivers/media/media-entity.c:628!
[    9.476924] Internal error: Oops - BUG: 0 [#1] SMP ARM
[    9.482246] Modules linked in: imx_media_ic(C+) imx_media_vdic(C) imx_media_csi(C) imx_media_capture(C) uvcvideo imx6_mipi_csi2(C) snd_soc_imx_audmux imx219 snd_soc_sgtl5000 video_multiplexer caam imx_sdma imx2_wdt snd_soc_fsl_ssi snd_soc_fsl_spdif imx_pcm_dma coda imx_thermal v4l2_mem2mem videobuf2_v4l2 videobuf2_dma_contig videobuf2_core videobuf2_vmalloc videobuf2_memops imx_media(C) imx_media_common(C) rc_pinnacle_pctv_hd nfsd dw_hdmi_cec dw_hdmi_ahb_audio etnaviv
[    9.524500] CPU: 1 PID: 263 Comm: systemd-udevd Tainted: G         C      4.10.0-rc7+ #2112
[    9.532995] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[    9.539619] task: edef1880 task.stack: d03ca000
[    9.544313] PC is at media_create_pad_link+0x134/0x140
[    9.549541] LR is at imx_media_probe_complete+0x164/0x24c [imx_media]
[    9.556080] pc : [<c04f0eb0>]    lr : [<bf052524>]    psr: 60070013
               sp : d03cbbc8  ip : d03cbbf8  fp : d03cbbf4
[    9.567712] r10: 00000001  r9 : 00000000  r8 : d0170d14
[    9.573007] r7 : 00000000  r6 : 00000001  r5 : 00000000  r4 : d0170d14
[    9.579612] r3 : 00000000  r2 : d0170d14  r1 : 00000001  r0 : 00000000
[    9.586256] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none[    9.593486] Control: 10c5387d  Table: 3e77c04a  DAC: 00000051
[    9.599317] Process systemd-udevd (pid: 263, stack limit = 0xd03ca210)
[    9.605950] Stack: (0xd03cbbc8 to 0xd03cc000)
[    9.610368] bbc0:                   00000000 00000000 ee980410 00000000 00000000 d0170d14
[    9.618658] bbe0: 00000000 00000001 d03cbc54 d03cbbf8 bf052524 c04f0d88 00000000 d0170d88
[    9.626961] bc00: 00000000 c0a57dc4 0004a364 ee98011c 00000000 00000003 00000001 ee980230
[    9.635267] bc20: ee980274 ee980010 d03cbc54 d0170f14 ee9ca4cc ee9974c4 bf0523c0 c0a57dc4
[    9.643539] bc40: f184bb30 00000026 d03cbc74 d03cbc58 c0502f50 bf0523cc ee9ca4cc d0170f14
[    9.651824] bc60: c0a57e08 d0170fc0 d03cbc9c d03cbc78 c0502fdc c0502e70 00000000 d0170f10
[    9.660132] bc80: 00000000 d02c0c10 bf122cd0 d0170f14 d03cbcc4 d03cbca0 bf121154 c0502f68
[    9.668423] bca0: bf12104c ffffffed d02c0c10 fffffdfb bf123248 00000000 d03cbce4 d03cbcc8
[    9.676713] bcc0: c041aeb4 bf121058 d02c0c10 c1419d70 00000000 bf123248 d03cbd0c d03cbce8
[    9.684992] bce0: c0418ec4 c041ae68 d02c0c10 bf123248 d02c0c44 00000000 00000001 00000124
[    9.693282] bd00: d03cbd2c d03cbd10 c0419044 c0418ccc 00000000 00000000 bf123248 c0418f88
[    9.701618] bd20: d03cbd54 d03cbd30 c04172e4 c0418f94 ef0f64a4 d01b8cd0 d03d9858 bf123248
[    9.709900] bd40: d03d9c00 c0a45e10 d03cbd64 d03cbd58 c0418728 c0417294 d03cbd8c d03cbd68
[    9.718203] bd60: c0418428 c0418710 bf122e48 d03cbd78 bf123248 c0a704a8 bf126000 00000000
[    9.729180] bd80: d03cbda4 d03cbd90 c0419ec4 c0418340 bf123480 c0a704a8 d03cbdb4 d03cbda8
[    9.739950] bda0: c041ad88 c0419e50 d03cbdc4 d03cbdb8 bf126018 c041ad4c d03cbe34 d03cbdc8
[    9.751089] bdc0: c00098ac bf12600c d03cbdec d03cbdd8 c00a8888 c0087240 00000000 ed4a9440
[    9.761941] bde0: d03cbe34 d03cbdf0 c016c690 c00a8814 c016b554 c016aa60 00000001 c015f3f8
[    9.772940] be00: 00000005 0000000c edef1880 bf123480 c0a704a8 bf123480 c0a704a8 ed4a9440
[    9.784008] be20: bf123480 00000001 d03cbe5c d03cbe38 c011b1e4 c0009874 d03cbe5c d03cbe48
[    9.795017] be40: c09f5ea7 c0a704a8 c09e04ec bf123480 d03cbf14 d03cbe60 c00d2dd0 c011b188
[    9.806069] be60: bf12348c 00007fff bf123480 c00d09f0 f1847000 bf12792c f18495c0 bf123680
[    9.817194] be80: bf12348c bf1236f0 00000000 bf1234c8 c017c1d0 c017bfac f1847000 00004f68
[    9.828347] bea0: c017c2e8 00000000 edef1880 00000000 00000000 00000000 00000000 00000000
[    9.839542] bec0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    9.850754] bee0: 00000000 00000000 00000003 7fffffff 00000000 00000000 00000007 b6c9e63c
[    9.861991] bf00: d03ca000 00000000 d03cbfa4 d03cbf18 c00d36cc c00d1480 7fffffff 00000000
[    9.873266] bf20: 00000003 ee0384d4 d03cbf74 f1847000 00004f68 00000000 00000002 f1847000
[    9.884593] bf40: 00004f68 f184bb30 f184989b f184a7d8 000026f0 00002dd0 00000000 00000000
[    9.895998] bf60: 00000000 0000192c 00000019 0000001a 00000011 00000000 0000000a 00000000
[    9.907408] bf80: c008b848 80c36630 00000000 2529fc00 0000017b c000ff04 00000000 d03cbfa8
[    9.918858] bfa0: c000fd60 c00d3644 80c36630 00000000 00000007 b6c9e63c 00000000 80c38178
[    9.930354] bfc0: 80c36630 00000000 2529fc00 0000017b 00020000 7f96eb0c 80c37848 00000000
[    9.941900] bfe0: bed55928 bed55918 b6c988ff b6bea572 600f0030 00000007 3fffd861 3fffdc61
[    9.953532] Backtrace:
[    9.959442] [<c04f0d7c>] (media_create_pad_link) from [<bf052524>] (imx_media_probe_complete+0x164/0x24c [imx_media])
[    9.973644]  r10:00000001 r9:00000000 r8:d0170d14 r7:00000000 r6:00000000 r5:ee980410
[    9.985112]  r4:00000000 r3:00000000
[    9.992696] [<bf0523c0>] (imx_media_probe_complete [imx_media]) from [<c0502f50>] (v4l2_async_test_notify+0xec/0xf8)
[   10.007413]  r10:00000026 r9:f184bb30 r8:c0a57dc4 r7:bf0523c0 r6:ee9974c4 r5:ee9ca4cc
[   10.019212]  r4:d0170f14
[   10.025650] [<c0502e64>] (v4l2_async_test_notify) from [<c0502fdc>] (v4l2_async_register_subdev+0x80/0xdc)
[   10.039736]  r7:d0170fc0 r6:c0a57e08 r5:d0170f14 r4:ee9ca4cc
[   10.049613] [<c0502f5c>] (v4l2_async_register_subdev) from [<bf121154>] (imx_ic_probe+0x108/0x144 [imx_media_ic])
[   10.063953]  r8:d0170f14 r7:bf122cd0 r6:d02c0c10 r5:00000000 r4:d0170f10 r3:00000000
[   10.075786] [<bf12104c>] (imx_ic_probe [imx_media_ic]) from [<c041aeb4>] (platform_drv_probe+0x58/0xb8)
[   10.089118]  r8:00000000 r7:bf123248 r6:fffffdfb r5:d02c0c10 r4:ffffffed r3:bf12104c
[   10.100683] [<c041ae5c>] (platform_drv_probe) from [<c0418ec4>] (driver_probe_device+0x204/0x2c8)
[   10.113279]  r7:bf123248 r6:00000000 r5:c1419d70 r4:d02c0c10
[   10.122765] [<c0418cc0>] (driver_probe_device) from [<c0419044>] (__driver_attach+0xbc/0xc0)
[   10.135098]  r10:00000124 r8:00000001 r7:00000000 r6:d02c0c44 r5:bf123248 r4:d02c0c10
[   10.146785] [<c0418f88>] (__driver_attach) from [<c04172e4>] (bus_for_each_dev+0x5c/0x90)
[   10.158811]  r6:c0418f88 r5:bf123248 r4:00000000 r3:00000000
[   10.168375] [<c0417288>] (bus_for_each_dev) from [<c0418728>] (driver_attach+0x24/0x28)
[   10.180413]  r6:c0a45e10 r5:d03d9c00 r4:bf123248
[   10.188959] [<c0418704>] (driver_attach) from [<c0418428>] (bus_add_driver+0xf4/0x200)
[   10.200775] [<c0418334>] (bus_add_driver) from [<c0419ec4>] (driver_register+0x80/0xfc)
[   10.212707]  r7:00000000 r6:bf126000 r5:c0a704a8 r4:bf123248
[   10.222254] [<c0419e44>] (driver_register) from [<c041ad88>] (__platform_driver_register+0x48/0x4c)
[   10.235212]  r5:c0a704a8 r4:bf123480
[   10.242694] [<c041ad40>] (__platform_driver_register) from [<bf126018>] (imx_ic_driver_init+0x18/0x24 [imx_media_ic])
[   10.257308] [<bf126000>] (imx_ic_driver_init [imx_media_ic]) from [<c00098ac>] (do_one_initcall+0x44/0x170)
[   10.271043] [<c0009868>] (do_one_initcall) from [<c011b1e4>] (do_init_module+0x68/0x1d8)
[   10.283139]  r8:00000001 r7:bf123480 r6:ed4a9440 r5:c0a704a8 r4:bf123480
[   10.293849] [<c011b17c>] (do_init_module) from [<c00d2dd0>] (load_module+0x195c/0x2080)
[   10.305867]  r7:bf123480 r6:c09e04ec r5:c0a704a8 r4:c09f5ea7
[   10.315523] [<c00d1474>] (load_module) from [<c00d36cc>] (SyS_finit_module+0x94/0xa0)
[   10.327382]  r10:00000000 r9:d03ca000 r8:b6c9e63c r7:00000007 r6:00000000 r5:00000000
[   10.339238]  r4:7fffffff
[   10.345766] [<c00d3638>] (SyS_finit_module) from [<c000fd60>] (ret_fast_syscall+0x0/0x1c)
[   10.357994]  r8:c000ff04 r7:0000017b r6:2529fc00 r5:00000000 r4:80c36630
[   10.368747] Code: e1a01007 ebfffce1 e3e0000b e89daff8 (e7f001f2)
[   10.378883] ---[ end trace 2051fac455b36c5a ]---
[   11.228961] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[   11.247536] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[   11.301366] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.

So there's probably some sort of race going on.

However, the following is primerily directed at Laurent as the one who introduced the BUG_ON() in question...

NEVER EVER USE BUG_ON() IN A PATH THAT CAN RETURN AN ERROR.

It's possible to find Linus rants about this, eg,
https://www.spinics.net/lists/stable/msg146439.html

I should have reacted to the damn added BUG_ON() lines. I suspect I will have to finally just remove the idiotic BUG_ON() concept once and for all, because there is NO F*CKING EXCUSE to knowingly kill the kernel.

Also: http://yarchive.net/comp/linux/BUG.html

Rule of thumb: BUG() is only good for something that never happens and that we really have no other option for (ie state is so corrupt that continuing is deadly).

So, _unless_ people want to see BUG_ON() removed from the kernel, I strongly suggest to _STOP_ using it as "we didn't like the function arguments, let's use it as an assert() statement instead of returning an error."

There's no excuse what so ever to be killing the machine in media_create_pad_link(). If it doesn't like a NULL pointer, it's damn well got an error path to report that fact. Use that mechanism and stop needlessly killing the kernel.

BUG_ON() IS NOT ASSERT(). DO NOT USE IT AS SUCH.

Linus is absolutely right about BUG_ON() - it hurts debuggability, because now the only way to do further tests is to reboot the damned machine after removing those fscking BUG_ON()s that should *never* have been there in the first place.

As Linus went on to say:

And dammit, if anybody else feels that they had done "debugging messages with BUG_ON()", I would suggest you

(a) rethink your approach to programming

(b) send me patches to remove the crap entirely, or make them real
*DEBUGGING* messages, not "kill the whole machine" messages.

I've ranted against people using BUG_ON() for debugging in the past. Why the f*ck does this still happen? And Andrew - please stop taking those kinds of patches! Lookie here:

     https://lwn.net/Articles/13183/

so excuse me for being upset that people still do this shit almost 15 years later.

So I suggest people heed that advice and start fixing these stupid BUG_ON()s that they've created.

Thanks.

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
#134 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

In reply to Steve Longerbeam
Quoted 635 lines · Steve Longerbeam

Add the core media driver for i.MX SOC.

---
 Documentation/media/v4l-drivers/imx.rst           | 542 +++++++++++++++++
 drivers/staging/media/Kconfig                     |   2 +
 drivers/staging/media/Makefile                    |   1 +
 drivers/staging/media/imx/Kconfig                 |   7 +
 drivers/staging/media/imx/Makefile                |   6 +
 drivers/staging/media/imx/TODO                    |  36 ++
 drivers/staging/media/imx/imx-media-dev.c         | 487 +++++++++++++++
 drivers/staging/media/imx/imx-media-fim.c         | 471 +++++++++++++++
 drivers/staging/media/imx/imx-media-internal-sd.c | 349 +++++++++++
 drivers/staging/media/imx/imx-media-of.c          | 267 ++++++++
 drivers/staging/media/imx/imx-media-utils.c       | 701 ++++++++++++++++++++++
 drivers/staging/media/imx/imx-media.h             | 297 +++++++++
 include/media/imx.h                               |  15 +
 include/uapi/linux/v4l2-controls.h                |   4 +
 14 files changed, 3185 insertions(+)
 create mode 100644 Documentation/media/v4l-drivers/imx.rst
 create mode 100644 drivers/staging/media/imx/Kconfig
 create mode 100644 drivers/staging/media/imx/Makefile
 create mode 100644 drivers/staging/media/imx/TODO
 create mode 100644 drivers/staging/media/imx/imx-media-dev.c
 create mode 100644 drivers/staging/media/imx/imx-media-fim.c
 create mode 100644 drivers/staging/media/imx/imx-media-internal-sd.c
 create mode 100644 drivers/staging/media/imx/imx-media-of.c
 create mode 100644 drivers/staging/media/imx/imx-media-utils.c
 create mode 100644 drivers/staging/media/imx/imx-media.h
 create mode 100644 include/media/imx.h
Documentation/media/v4l-drivers/imx.rst new file +542 -0
new file mode 100644
index 0000000..f085e43
@@ -0,0 +1,542 @@
+i.MX Video Capture Driver
+=========================
+
+Introduction
+------------
+
+The Freescale i.MX5/6 contains an Image Processing Unit (IPU), which
+handles the flow of image frames to and from capture devices and
+display devices.
+
+For image capture, the IPU contains the following internal subunits:
+
+- Image DMA Controller (IDMAC)
+- Camera Serial Interface (CSI)
+- Image Converter (IC)
+- Sensor Multi-FIFO Controller (SMFC)
+- Image Rotator (IRT)
+- Video De-Interlacing or Combining Block (VDIC)
+
+The IDMAC is the DMA controller for transfer of image frames to and from
+memory. Various dedicated DMA channels exist for both video capture and
+display paths. During transfer, the IDMAC is also capable of vertical
+image flip, 8x8 block transfer (see IRT description), pixel component
+re-ordering (for example UYVY to YUYV) within the same colorspace, and
+even packed <--> planar conversion. It can also perform a simple
+de-interlacing by interleaving even and odd lines during transfer
+(without motion compensation which requires the VDIC).
+
+The CSI is the backend capture unit that interfaces directly with
+camera sensors over Parallel, BT.656/1120, and MIPI CSI-2 busses.
+
+The IC handles color-space conversion, resizing (downscaling and
+upscaling), horizontal flip, and 90/270 degree rotation operations.
+
+There are three independent "tasks" within the IC that can carry out
+conversions concurrently: pre-process encoding, pre-process viewfinder,
+and post-processing. Within each task, conversions are split into three
+sections: downsizing section, main section (upsizing, flip, colorspace
+conversion, and graphics plane combining), and rotation section.
+
+The IPU time-shares the IC task operations. The time-slice granularity
+is one burst of eight pixels in the downsizing section, one image line
+in the main processing section, one image frame in the rotation section.
+
+The SMFC is composed of four independent FIFOs that each can transfer
+captured frames from sensors directly to memory concurrently via four
+IDMAC channels.
+
+The IRT carries out 90 and 270 degree image rotation operations. The
+rotation operation is carried out on 8x8 pixel blocks at a time. This
+operation is supported by the IDMAC which handles the 8x8 block transfer
+along with block reordering, in coordination with vertical flip.
+
+The VDIC handles the conversion of interlaced video to progressive, with
+support for different motion compensation modes (low, medium, and high
+motion). The deinterlaced output frames from the VDIC can be sent to the
+IC pre-process viewfinder task for further conversions. The VDIC also
+contains a Combiner that combines two image planes, with alpha blending
+and color keying.
+
+In addition to the IPU internal subunits, there are also two units
+outside the IPU that are also involved in video capture on i.MX:
+
+- MIPI CSI-2 Receiver for camera sensors with the MIPI CSI-2 bus
+  interface. This is a Synopsys DesignWare core.
+- Two video multiplexers for selecting among multiple sensor inputs
+  to send to a CSI.
+
+For more info, refer to the latest versions of the i.MX5/6 reference
+manuals listed under References.
+
+
+Features
+--------
+
+Some of the features of this driver include:
+
+- Many different pipelines can be configured via media controller API,
+  that correspond to the hardware video capture pipelines supported in
+  the i.MX.
+
+- Supports parallel, BT.565, and MIPI CSI-2 interfaces.
+
+- Up to four concurrent sensor acquisitions, by configuring each
+  sensor's pipeline using independent entities. This is currently
+  demonstrated with the SabreSD and SabreLite reference boards with
+  independent OV5642 and MIPI CSI-2 OV5640 sensor modules.
+
+- Scaling, color-space conversion, horizontal and vertical flip, and
+  image rotation via IC task subdevs.
+
+- Many pixel formats supported (RGB, packed and planar YUV, partial
+  planar YUV).
+
+- The VDIC subdev supports motion compensated de-interlacing, with three
+  motion compensation modes: low, medium, and high motion. The mode is
+  specified with a custom control. Pipelines are defined that allow
+  sending frames to the VDIC subdev directly from the CSI or from
+  memory buffers via an output/mem2mem device node. For low and medium
+  motion modes, the VDIC must receive from memory buffers via a device
+  node.
+
+- Includes a Frame Interval Monitor (FIM) that can correct vertical sync
+  problems with the ADV718x video decoders. See below for a description
+  of the FIM.
+
+
+Entities
+--------
+
+imx6-mipi-csi2
+--------------
+
+This is the MIPI CSI-2 receiver entity. It has one sink pad to receive
+the MIPI CSI-2 stream (usually from a MIPI CSI-2 camera sensor). It has
+four source pads, corresponding to the four MIPI CSI-2 demuxed virtual
+channel outputs.
+
+This entity actually consists of two sub-blocks. One is the MIPI CSI-2
+core. This is a Synopsys Designware MIPI CSI-2 core. The other sub-block
+is a "CSI-2 to IPU gasket". The gasket acts as a demultiplexer of the
+four virtual channels streams, providing four separate parallel buses
+containing each virtual channel that are routed to CSIs or video
+multiplexers as described below.
+
+On i.MX6 solo/dual-lite, all four virtual channel buses are routed to
+two video multiplexers. Both CSI0 and CSI1 can receive any virtual
+channel, as selected by the video multiplexers.
+
+On i.MX6 Quad, virtual channel 0 is routed to IPU1-CSI0 (after selected
+by a video mux), virtual channels 1 and 2 are hard-wired to IPU1-CSI1
+and IPU2-CSI0, respectively, and virtual channel 3 is routed to
+IPU2-CSI1 (again selected by a video mux).
+
+ipuX_csiY_mux
+-------------
+
+These are the video multiplexers. They have two or more sink pads to
+select from either camera sensors with a parallel interface, or from
+MIPI CSI-2 virtual channels from imx6-mipi-csi2 entity. They have a
+single source pad that routes to a CSI (ipuX_csiY entities).
+
+On i.MX6 solo/dual-lite, there are two video mux entities. One sits
+in front of IPU1-CSI0 to select between a parallel sensor and any of
+the four MIPI CSI-2 virtual channels (a total of five sink pads). The
+other mux sits in front of IPU1-CSI1, and again has five sink pads to
+select between a parallel sensor and any of the four MIPI CSI-2 virtual
+channels.
+
+On i.MX6 Quad, there are two video mux entities. One sits in front of
+IPU1-CSI0 to select between a parallel sensor and MIPI CSI-2 virtual
+channel 0 (two sink pads). The other mux sits in front of IPU2-CSI1 to
+select between a parallel sensor and MIPI CSI-2 virtual channel 3 (two
+sink pads).
+
+ipuX_csiY
+---------
+
+These are the CSI entities. They have a single sink pad receiving from
+either a video mux or from a MIPI CSI-2 virtual channel as described
+above.
+
+This entity has two source pads. The first source pad can link directly
+to the ipuX_vdic entity or the ipuX_ic_prp entity, using hardware links
+that require no IDMAC memory buffer transfer.
+
+When the direct source pad is routed to the ipuX_ic_prp entity, frames
+from the CSI will be processed by one of the IC pre-processing tasks.
+
+When the direct source pad is routed to the ipuX_vdic entity, the VDIC
+will carry out motion-compensated de-interlace using "high motion" mode
+(see description of ipuX_vdic entity).
+
+The second source pad sends video frames to memory buffers via the SMFC
+and an IDMAC channel. This source pad is routed to a capture device
+node.
+
+Note that since the IDMAC source pad makes use of an IDMAC channel, it
+can do pixel reordering within the same colorspace. For example, the
+sink pad can take UYVY2X8, but the IDMAC source pad can output YUYV2X8.
+If the sink pad is receiving YUV, the output at the capture device can
+also be converted to a planar YUV format such as YUV420.
+
+It will also perform simple de-interlace without motion compensation,
+which is activated if the sink pad's field type is an interlaced type,
+and the IDMAC source pad field type is set to none.
+
+ipuX_vdic
+---------
+
+The VDIC carries out motion compensated de-interlacing, with three
+motion compensation modes: low, medium, and high motion. The mode is
+specified with a custom v4l2 control. It has two sink pads and a
+single source pad.
+
+The direct sink pad receives from an ipuX_csiY direct pad. With this
+link the VDIC can only operate in high motion mode.
+
+When the IDMAC sink pad is activated, it receives from an output
+or mem2mem device node. With this pipeline, it can also operate
+in low and medium modes, because these modes require receiving
+frames from memory buffers. Note that an output or mem2mem device
+is not implemented yet, so this sink pad currently has no links.
+
+The source pad routes to the IC pre-processing entity ipuX_ic_prp.
+
+ipuX_ic_prp
+-----------
+
+This is the IC pre-processing entity. It acts as a router, routing
+data from its sink pad to one or both of its source pads.
+
+It has a single sink pad. The sink pad can receive from the ipuX_csiY
+direct pad, or from ipuX_vdic.
+
+This entity has two source pads. One source pad routes to the
+pre-process encode task entity (ipuX_ic_prpenc), the other to the
+pre-process viewfinder task entity (ipuX_ic_prpvf). Both source pads
+can be activated at the same time if the sink pad is receiving from
+ipuX_csiY. Only the source pad to the pre-process viewfinder task entity
+can be activated if the sink pad is receiving from ipuX_vdic (frames
+from the VDIC can only be processed by the pre-process viewfinder task).
+
+ipuX_ic_prpenc
+--------------
+
+This is the IC pre-processing encode entity. It has a single sink pad
+from ipuX_ic_prp, and a single source pad. The source pad is routed
+to a capture device node.
+
+This entity performs the IC pre-process encode task operations:
+color-space conversion, resizing (downscaling and upscaling), horizontal
+and vertical flip, and 90/270 degree rotation.
+
+Like the ipuX_csiY IDMAC source, it can also perform simple de-interlace
+without motion compensation, and pixel reordering.
+
+ipuX_ic_prpvf
+-------------
+
+This is the IC pre-processing viewfinder entity. It has a single sink pad
+from ipuX_ic_prp, and a single source pad. The source pad is routed to
+a capture device node.
+
+It is identical in operation to ipuX_ic_prpenc. It will receive and
+process de-interlaced frames from the ipuX_vdic if ipuX_ic_prp is
+receiving from ipuX_vdic.
+
+Like the ipuX_csiY IDMAC source, it can perform simple de-interlace
+without motion compensation. However, note that if the ipuX_vdic is
+included in the pipeline (ipuX_ic_prp is receiving from ipuX_vdic),
+it's not possible to use simple de-interlace in ipuX_ic_prpvf, since
+the ipuX_vdic has already carried out de-interlacing (with motion
+compensation) and therefore the field type output from ipuX_ic_prp can
+only be none.
+
+Capture Pipelines
+-----------------
+
+The following describe the various use-cases supported by the pipelines.
+
+The links shown do not include the backend sensor, video mux, or mipi
+csi-2 receiver links. This depends on the type of sensor interface
+(parallel or mipi csi-2). So in all cases, these pipelines begin with:
+
+sensor -> ipuX_csiY_mux -> ...
+
+for parallel sensors, or:
+
+sensor -> imx6-mipi-csi2 -> (ipuX_csiY_mux) -> ...
+
+for mipi csi-2 sensors. The imx6-mipi-csi2 receiver may need to route
+to the video mux (ipuX_csiY_mux) before sending to the CSI, depending
+on the mipi csi-2 virtual channel, hence ipuX_csiY_mux is shown in
+parenthesis.
+
+Unprocessed Video Capture:
+--------------------------
+
+Send frames directly from sensor to camera device interface node, with
+no conversions:
+
+-> ipuX_csiY IDMAC pad -> capture node
+
+IC Direct Conversions:
+----------------------
+
+This pipeline uses the preprocess encode entity to route frames directly
+from the CSI to the IC, to carry out scaling up to 1024x1024 resolution,
+CSC, flipping, and image rotation:
+
+-> ipuX_csiY direct pad -> ipuX_ic_prp -> ipuX_ic_prpenc -> capture node
+
+Motion Compensated De-interlace:
+--------------------------------
+
+This pipeline routes frames from the CSI direct pad to the VDIC entity to
+support motion-compensated de-interlacing (high motion mode only),
+scaling up to 1024x1024, CSC, flip, and rotation:
+
+-> ipuX_csiY direct pad -> ipuX_vdic direct pad -> ipuX_ic_prp ->
+   ipuX_ic_prpvf -> capture node
+
+
+Usage Notes
+-----------
+
+Many of the subdevs require information from the active sensor in the
+current pipeline when configuring pad formats. Therefore the media links
+should be established before configuring the media pad formats.
+
+Similarly, the capture device interfaces inherit controls from the
+active entities in the current pipeline at link-setup time. Therefore
+the capture device node links should be the last links established in
+order for the capture interfaces to "see" and inherit all possible
+controls.
+
+The following are usage notes for Sabre- reference platforms:
+
+
+SabreLite with OV5642 and OV5640
+--------------------------------
+
+This platform requires the OmniVision OV5642 module with a parallel
+camera interface, and the OV5640 module with a MIPI CSI-2
+interface. Both modules are available from Boundary Devices:
+
+https://boundarydevices.com/products/nit6x_5mp
+https://boundarydevices.com/product/nit6x_5mp_mipi
+
+Note that if only one camera module is available, the other sensor
+node can be disabled in the device tree.
+
+The OV5642 module is connected to the parallel bus input on the i.MX
+internal video mux to IPU1 CSI0. It's i2c bus connects to i2c bus 2.
+
+The MIPI CSI-2 OV5640 module is connected to the i.MX internal MIPI CSI-2
+receiver, and the four virtual channel outputs from the receiver are
+routed as follows: vc0 to the IPU1 CSI0 mux, vc1 directly to IPU1 CSI1,
+vc2 directly to IPU2 CSI0, and vc3 to the IPU2 CSI1 mux. The OV5640 is
+also connected to i2c bus 2 on the SabreLite, therefore the OV5642 and
+OV5640 must not share the same i2c slave address.
+
+The following basic example configures unprocessed video capture
+pipelines for both sensors. The OV5642 is routed to ipu1_csi0, and
+the OV5640 (transmitting on mipi csi-2 virtual channel 1) is routed
+to ipu1_csi1. Both sensors are configured to output 640x480, the
+OV5642 outputs YUYV2X8, the OV5640 UYVY2X8:
+
+.. code-block:: none
+
+   # Setup links for OV5642
+   media-ctl -l '"ov5642 1-0042":0 -> "ipu1_csi0_mux":1[1]'
+   media-ctl -l '"ipu1_csi0_mux":2 -> "ipu1_csi0":0[1]'
+   media-ctl -l '"ipu1_csi0":2 -> "ipu1_csi0 capture":0[1]'
+   # Setup links for OV5640
+   media-ctl -l '"ov5640_mipi 1-0040":0 -> "imx6-mipi-csi2":0[1]'
+   media-ctl -l '"imx6-mipi-csi2":2 -> "ipu1_csi1":0[1]'
+   media-ctl -l '"ipu1_csi1":2 -> "ipu1_csi1 capture":0[1]'
+   # Configure pads for OV5642 pipeline
+   media-ctl -V "\"ov5642 1-0042\":0 [fmt:YUYV2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi0_mux\":2 [fmt:YUYV2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi0\":2 [fmt:YUYV2X8/640x480 field:none]"
+   # Configure pads for OV5640 pipeline
+   media-ctl -V "\"ov5640_mipi 1-0040\":0 [fmt:UYVY2X8/640x480 field:none]"
+   media-ctl -V "\"imx6-mipi-csi2\":2 [fmt:UYVY2X8/640x480 field:none]"
+   media-ctl -V "\"ipu1_csi1\":2 [fmt:UYVY2X8/640x480 field:none]"
+
+Streaming can then begin independently on the capture device nodes
+"ipu1_csi0 capture" and "ipu1_csi1 capture".
+
+SabreAuto with ADV7180 decoder
+------------------------------
+
+On the SabreAuto, an on-board ADV7180 SD decoder is connected to the
+parallel bus input on the internal video mux to IPU1 CSI0.
+
+The following example configures a pipeline to capture from the ADV7180
+video decoder, assuming NTSC 720x480 input signals, with Motion
+Compensated de-interlacing. Pad field types assume the adv7180 outputs
+"alternate", which the ipu1_csi0 entity converts to "seq-tb" at its
+source pad. $outputfmt can be any format supported by the ipu1_ic_prpvf
+entity at its output pad:
+
+.. code-block:: none
+
+   # Setup links
+   media-ctl -l '"adv7180 4-0021":0 -> "ipu1_csi0_mux":1[1]'
+   media-ctl -l '"ipu1_csi0_mux":2 -> "ipu1_csi0":0[1]'
+   media-ctl -l '"ipu1_csi0":2 -> "ipu1_vdic":0[1]'
+   media-ctl -l '"ipu1_vdic":2 -> "ipu1_ic_prp":0[1]'
+   media-ctl -l '"ipu1_ic_prp":2 -> "ipu1_ic_prpvf":0[1]'
+   media-ctl -l '"ipu1_ic_prpvf":1 -> "ipu1_ic_prpvf capture":0[1]'
+   # Configure pads
+   media-ctl -V "\"adv7180 4-0021\":0 [fmt:UYVY2X8/720x480]"
+   media-ctl -V "\"ipu1_csi0_mux\":2 [fmt:UYVY2X8/720x480 field:alternate]"
+   media-ctl -V "\"ipu1_csi0\":1 [fmt:AYUV32/720x480 field:seq-tb]"
+   media-ctl -V "\"ipu1_vdic\":2 [fmt:AYUV32/720x480 field:none]"
+   media-ctl -V "\"ipu1_ic_prp\":2 [fmt:AYUV32/720x480 field:none]"
+   media-ctl -V "\"ipu1_ic_prpvf\":1 [fmt:$outputfmt field:none]"
+
+Streaming can then begin on the capture device node at
+"ipu1_ic_prpvf capture".
+
+This platform accepts Composite Video analog inputs to the ADV7180 on
+Ain1 (connector J42).
+
+Frame Interval Monitor
+----------------------
+
+The adv718x decoders can occasionally send corrupt fields during
+NTSC/PAL signal re-sync (too little or too many video lines). When
+this happens, the IPU triggers a mechanism to re-establish vertical
+sync by adding 1 dummy line every frame, which causes a rolling effect
+from image to image, and can last a long time before a stable image is
+recovered. Or sometimes the mechanism doesn't work at all, causing a
+permanent split image (one frame contains lines from two consecutive
+captured images).
+
+From experiment it was found that during image rolling, the frame
+intervals (elapsed time between two EOF's) drop below the nominal
+value for the current standard, by about one frame time (60 usec),
+and remain at that value until rolling stops.
+
+While the reason for this observation isn't known (the IPU dummy
+line mechanism should show an increase in the intervals by 1 line
+time every frame, not a fixed value), we can use it to detect the
+corrupt fields using a frame interval monitor. If the FIM detects a
+bad frame interval, a subdev event is sent. In response, userland can
+issue a streaming restart to correct the rolling/split image.
+
+The FIM is implemented in the ipuX_csiY entity, and the entities that
+generate End-Of-Frame interrupts call into the FIM to monitor the frame
+intervals: ipuX_ic_prpenc, and ipuX_ic_prpvf. Userland can register with
+the FIM event notifications on the ipuX_csiY subdev device node
+(V4L2_EVENT_IMX_FRAME_INTERVAL).
+
+The ipuX_csiY entity includes custom controls to tweak some dials for
+FIM. If one of these controls is changed during streaming, the FIM will
+be reset and will continue at the new settings.
+
+- V4L2_CID_IMX_FIM_ENABLE
+
+Enable/disable the FIM.
+
+- V4L2_CID_IMX_FIM_NUM
+
+How many frame interval errors to average before comparing against the
+nominal frame interval reported by the sensor. This can reduce noise
+from interrupt latency.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MIN
+
+If the averaged intervals fall outside nominal by this amount, in
+microseconds, streaming will be restarted.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MAX
+
+If any interval errors are higher than this value, those error samples
+are discarded and do not enter into the average. This can be used to
+discard really high interval errors that might be due to very high
+system load, causing excessive interrupt latencies.
+
+- V4L2_CID_IMX_FIM_NUM_SKIP
+
+How many frames to skip after a FIM reset or stream restart before
+FIM begins to average intervals. It has been found that there can
+be a few bad frame intervals after stream restart which are not
+attributed to adv718x sending a corrupt field, so this is used to
+skip those frames to prevent unnecessary restarts.
+
+
+SabreSD with MIPI CSI-2 OV5640
+------------------------------
+
+Similarly to SabreLite, the SabreSD supports a parallel interface
+OV5642 module on IPU1 CSI0, and a MIPI CSI-2 OV5640 module. The OV5642
+connects to i2c bus 1 and the OV5640 to i2c bus 2.
+
+The device tree for SabreSD includes OF graphs for both the parallel
+OV5642 and the MIPI CSI-2 OV5640, but as of this writing only the MIPI
+CSI-2 OV5640 has been tested, so the OV5642 node is currently disabled.
+The OV5640 module connects to MIPI connector J5 (sorry I don't have the
+compatible module part number or URL).
+
+The following example configures a direct conversion pipeline to capture
+from the OV5640. $sensorfmt can be any format supported by the OV5640.
+$sensordim is the frame dimension part of $sensorfmt (minus the mbus
+pixel code). $outputfmt can be any format supported by the
+ipu1_ic_prpenc entity at its output pad:
+
+.. code-block:: none
+
+   # Setup links
+   media-ctl -l '"ov5640_mipi 1-003c":0 -> "imx6-mipi-csi2":0[1]'
+   media-ctl -l '"imx6-mipi-csi2":2 -> "ipu1_csi1":0[1]'
+   media-ctl -l '"ipu1_csi1":1 -> "ipu1_ic_prp":0[1]'
+   media-ctl -l '"ipu1_ic_prp":1 -> "ipu1_ic_prpenc":0[1]'
+   media-ctl -l '"ipu1_ic_prpenc":1 -> "ipu1_ic_prpenc capture":0[1]'
+   # Configure pads
+   media-ctl -V "\"ov5640_mipi 1-003c\":0 [fmt:$sensorfmt field:none]"
+   media-ctl -V "\"imx6-mipi-csi2\":2 [fmt:$sensorfmt field:none]"
+   media-ctl -V "\"ipu1_csi1\":1 [fmt:AYUV32/$sensordim field:none]"
+   media-ctl -V "\"ipu1_ic_prp\":1 [fmt:AYUV32/$sensordim field:none]"
+   media-ctl -V "\"ipu1_ic_prpenc\":1 [fmt:$outputfmt field:none]"
+
+Streaming can then begin on "ipu1_ic_prpenc capture" node.
+
+
+
+Known Issues
+------------
+
+1. When using 90 or 270 degree rotation control at capture resolutions
+   near the IC resizer limit of 1024x1024, and combined with planar
+   pixel formats (YUV420, YUV422p), frame capture will often fail with
+   no end-of-frame interrupts from the IDMAC channel. To work around
+   this, use lower resolution and/or packed formats (YUYV, RGB3, etc.)
+   when 90 or 270 rotations are needed.
+
+
+File list
+---------
+
+drivers/staging/media/imx/
+include/media/imx.h
+include/uapi/media/imx.h
+
+References
+----------
+
+[1] "i.MX 6Dual/6Quad Applications Processor Reference Manual"
+[2] "i.MX 6Solo/6DualLite Applications Processor Reference Manual"
+
+
+Authors
+-------
+Steve Longerbeam <[email protected]>
+Philipp Zabel <[email protected]>
+Russell King - ARM Linux <[email protected]>
+
+Copyright (C) 2012-2017 Mentor Graphics Inc.
drivers/staging/media/Kconfig +2 -0
index ffb8fa7..05b55a8 100644
@@ -25,6 +25,8 @@ source "drivers/staging/media/cxd2099/Kconfig"
 
 source "drivers/staging/media/davinci_vpfe/Kconfig"
 
+source "drivers/staging/media/imx/Kconfig"
+
 source "drivers/staging/media/omap4iss/Kconfig"
 
 source "drivers/staging/media/s5p-cec/Kconfig"
drivers/staging/media/Makefile +1 -0
index a28e82c..6f50ddd 100644
@@ -1,6 +1,7 @@
 obj-$(CONFIG_I2C_BCM2048)	+= bcm2048/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC) += s5p-cec/
 obj-$(CONFIG_DVB_CXD2099)	+= cxd2099/
+obj-$(CONFIG_VIDEO_IMX_MEDIA)	+= imx/
 obj-$(CONFIG_LIRC_STAGING)	+= lirc/
 obj-$(CONFIG_VIDEO_DM365_VPFE)	+= davinci_vpfe/
 obj-$(CONFIG_VIDEO_OMAP4)	+= omap4iss/
drivers/staging/media/imx/Kconfig new file +7 -0
new file mode 100644
index 0000000..722ed55
@@ -0,0 +1,7 @@
+config VIDEO_IMX_MEDIA
+	tristate "i.MX5/6 V4L2 media core driver"
+	depends on MEDIA_CONTROLLER && VIDEO_V4L2 && ARCH_MXC && IMX_IPUV3_CORE
+	---help---
+	  Say yes here to enable support for video4linux media controller
+	  driver for the i.MX5/6 SOC.
+
drivers/staging/media/imx/Makefile new file +6 -0
new file mode 100644
index 0000000..ba8e4fb
@@ -0,0 +1,6 @@
+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
+
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
+obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
+
drivers/staging/media/imx/TODO new file +0 -0
new file mode 100644
index 0000000..f6d2bac

drivers/staging/media/imx/TODO line 6

Quoted 6 lines
drivers/staging/media/imx/TODO new file +6 -0
@@ -0,0 +1,36 @@
+
+- Finish v4l2-compliance
+
+- imx-csi subdev is not being autoloaded as a kernel module, probably
+  because ipu_add_client_devices() does not register the IPU client
+  platform devices, but only allocates those devices.

As Russell points out, this is an issue with the ipu-v3 driver, which needs to be fixed to stop setting the ipu client devices' dev->of_node field.

drivers/staging/media/imx/TODO line 15

Quoted 8 lines
drivers/staging/media/imx/TODO new file +8 -0
+- Currently registering with notifications from subdevs are only
+  available through the subdev device nodes and not through the main
+  capture device node. Need to come up with a way to find the capture
+  device in the current pipeline that owns the subdev that sent the
+  notify.
+
+- Clean up and move the ov5642 subdev driver to drivers/media/i2c, and
+  create the binding docs for it.

This is done already, right?

drivers/staging/media/imx/TODO line 26

Quoted 10 lines
drivers/staging/media/imx/TODO new file +10 -0
+- The Frame Interval Monitor could be exported to v4l2-core for
+  general use.
+
+- The subdev that is the original source of video data (referred to as
+  the "sensor" in the code), is called from various subdevs in the
+  pipeline in order to set/query the video standard ({g|s|enum}_std)
+  and to get/set the original frame interval from the capture interface
+  ([gs]_parm). Instead, the entities that need this info should call its
+  direct neighbor, and the neighbor should propagate the call to its
+  neighbor in turn if necessary.

Especially the [gs]_parm fix is necessary to present userspace with the correct frame interval in case of frame skipping in the CSI.

Quoted 14 lines
drivers/staging/media/imx/TODO new file +9 -0
+- At driver load time, the device-tree node that is the original source
+  (the "sensor"), is parsed to record its media bus configuration, and
+  this info is required in various subdevs to setup the pipeline.
+  Laurent Pinchart argues that instead the subdev should call its
+  neighbor's g_mbus_config op (which should be propagated if necessary)
+  to get this info. However Hans Verkuil is planning to remove the
+  g_mbus_config op. For now this driver uses the parsed DT mbus config
+  method until this issue is resolved.
+
drivers/staging/media/imx/imx-media-dev.c new file +0 -0
new file mode 100644
index 0000000..e2041ad

[...]

drivers/staging/media/imx/imx-media-dev.c

Quoted 5 lines
drivers/staging/media/imx/imx-media-dev.c new file +5 -0
+static inline u32 pixfmt_to_colorspace(const struct imx_media_pixfmt *fmt)
+{
+	return (fmt->cs == IPUV3_COLORSPACE_RGB) ?
+		V4L2_COLORSPACE_SRGB : V4L2_COLORSPACE_SMPTE170M;
+}

This ...

[...]

Quoted 8 lines
drivers/staging/media/imx/imx-media-dev.c new file +8 -0
+int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
+				  struct v4l2_mbus_framefmt *mbus,
+				  const struct imx_media_pixfmt *cc)
+{
+	u32 stride;
+
+	if (!cc) {
+		cc = imx_media_find_format(0, mbus->code, true, false);

drivers/staging/media/imx/imx-media-dev.c

Quoted 10 lines
drivers/staging/media/imx/imx-media-dev.c new file +10 -0
+		if (!cc)
+			return -EINVAL;
+	}
+
+	stride = cc->planar ? mbus->width : (mbus->width * cc->bpp) >> 3;
+
+	pix->width = mbus->width;
+	pix->height = mbus->height;
+	pix->pixelformat = cc->fourcc;
+	pix->colorspace = pixfmt_to_colorspace(cc);

... is not right. The colorspace should be taken from the input pad colorspace everywhere (except for the IC output pad in the future, once that supports changing YCbCr encoding and quantization), not guessed based on the media bus format.

regards
Philipp

#142 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Russell King - ARM Linux
Quoted 50 lines · Russell King - ARM Linux

However, the following is primerily directed at Laurent as the one who introduced the BUG_ON() in question...

NEVER EVER USE BUG_ON() IN A PATH THAT CAN RETURN AN ERROR.

It's possible to find Linus rants about this, eg,
https://www.spinics.net/lists/stable/msg146439.html

I should have reacted to the damn added BUG_ON() lines. I suspect I will have to finally just remove the idiotic BUG_ON() concept once and for all, because there is NO F*CKING EXCUSE to knowingly kill the kernel.

Also: http://yarchive.net/comp/linux/BUG.html

Rule of thumb: BUG() is only good for something that never happens and that we really have no other option for (ie state is so corrupt that continuing is deadly).

So, _unless_ people want to see BUG_ON() removed from the kernel, I strongly suggest to _STOP_ using it as "we didn't like the function arguments, let's use it as an assert() statement instead of returning an error."

There's no excuse what so ever to be killing the machine in media_create_pad_link(). If it doesn't like a NULL pointer, it's damn well got an error path to report that fact. Use that mechanism and stop needlessly killing the kernel.

BUG_ON() IS NOT ASSERT(). DO NOT USE IT AS SUCH.

Linus is absolutely right about BUG_ON() - it hurts debuggability, because now the only way to do further tests is to reboot the damned machine after removing those fscking BUG_ON()s that should *never* have been there in the first place.

As Linus went on to say:

And dammit, if anybody else feels that they had done "debugging messages with BUG_ON()", I would suggest you

(a) rethink your approach to programming

(b) send me patches to remove the crap entirely, or make them real
*DEBUGGING* messages, not "kill the whole machine" messages.

I've ranted against people using BUG_ON() for debugging in the past. Why the f*ck does this still happen? And Andrew - please stop taking those kinds of patches! Lookie here:

Quoted 7 lines
     https://lwn.net/Articles/13183/

so excuse me for being upset that people still do this shit almost 15 years later.

So I suggest people heed that advice and start fixing these stupid BUG_ON()s that they've created.

More crap.

If the "complete" method fails (or, in fact, anything in v4l2_async_test_notify() fails) then all hell breaks loose, because of the total lack of clean up (and no, this isn't anything to do with some stupid justification of those BUG_ON()s above.)

v4l2_async_notifier_register() gets called, it adds the notifier to the global notifier list. v4l2_async_test_notify() gets called. It returns an error, which is propagated out of v4l2_async_notifier_register().

So the caller thinks that v4l2_async_notifier_register() failed, which will cause imx_media_probe() to fail, causing imxmd->subdev_notifier to be kfree()'d. We now have a use-after free bug.

Second case. v4l2_async_register_subdev(). Almost exactly the same, except in this case adding sd->async_list to the notifier->done list may have succeeded, and failure after that, again, results in an in-use list_head being kfree()'d.

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.
#135 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

In reply to Philipp Zabel
Quoted 10 lines · Philipp Zabel

drivers/staging/media/imx/TODO line 6

Quoted 3 lines · Steve Longerbeam

+- imx-csi subdev is not being autoloaded as a kernel module, probably

drivers/staging/media/imx/TODO new file +2 -0
+  because ipu_add_client_devices() does not register the IPU client
+  platform devices, but only allocates those devices.

As Russell points out, this is an issue with the ipu-v3 driver, which needs to be fixed to stop setting the ipu client devices' dev->of_node field.

From my local testing (albiet the shambles that is bits of v4l2) setting

dev->of_node is not necessary for imx-drm - imx-drm comes up fine without.

Fixing _this_ code for that is not too difficult - it's a matter of:

	priv->sd.of_node = pdata->of_node;

in imx_csi_probe(). However, the difficult bit is the poor state of code in v4l2, particularly the v4l2-async crap. Right now, fixing the module autoloading will oops the kernel, so it's best that module autoloading remains broken for the time being.

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.
#143 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Russell King - ARM Linux
Quoted 71 lines · Russell King - ARM Linux
Quoted 50 lines · Russell King - ARM Linux

However, the following is primerily directed at Laurent as the one who introduced the BUG_ON() in question...

NEVER EVER USE BUG_ON() IN A PATH THAT CAN RETURN AN ERROR.

It's possible to find Linus rants about this, eg,
https://www.spinics.net/lists/stable/msg146439.html

I should have reacted to the damn added BUG_ON() lines. I suspect I will have to finally just remove the idiotic BUG_ON() concept once and for all, because there is NO F*CKING EXCUSE to knowingly kill the kernel.

Also: http://yarchive.net/comp/linux/BUG.html

Rule of thumb: BUG() is only good for something that never happens and that we really have no other option for (ie state is so corrupt that continuing is deadly).

So, _unless_ people want to see BUG_ON() removed from the kernel, I strongly suggest to _STOP_ using it as "we didn't like the function arguments, let's use it as an assert() statement instead of returning an error."

There's no excuse what so ever to be killing the machine in media_create_pad_link(). If it doesn't like a NULL pointer, it's damn well got an error path to report that fact. Use that mechanism and stop needlessly killing the kernel.

BUG_ON() IS NOT ASSERT(). DO NOT USE IT AS SUCH.

Linus is absolutely right about BUG_ON() - it hurts debuggability, because now the only way to do further tests is to reboot the damned machine after removing those fscking BUG_ON()s that should *never* have been there in the first place.

As Linus went on to say:

And dammit, if anybody else feels that they had done "debugging messages with BUG_ON()", I would suggest you

(a) rethink your approach to programming

(b) send me patches to remove the crap entirely, or make them real
*DEBUGGING* messages, not "kill the whole machine" messages.

I've ranted against people using BUG_ON() for debugging in the past. Why the f*ck does this still happen? And Andrew - please stop taking those kinds of patches! Lookie here:

Quoted 7 lines
     https://lwn.net/Articles/13183/

so excuse me for being upset that people still do this shit almost 15 years later.

So I suggest people heed that advice and start fixing these stupid BUG_ON()s that they've created.

More crap.

If the "complete" method fails (or, in fact, anything in v4l2_async_test_notify() fails) then all hell breaks loose, because of the total lack of clean up (and no, this isn't anything to do with some stupid justification of those BUG_ON()s above.)

v4l2_async_notifier_register() gets called, it adds the notifier to the global notifier list. v4l2_async_test_notify() gets called. It returns an error, which is propagated out of v4l2_async_notifier_register().

Quoted 8 lines

So the caller thinks that v4l2_async_notifier_register() failed, which will cause imx_media_probe() to fail, causing imxmd->subdev_notifier to be kfree()'d. We now have a use-after free bug.

Second case. v4l2_async_register_subdev(). Almost exactly the same, except in this case adding sd->async_list to the notifier->done list may have succeeded, and failure after that, again, results in an in-use list_head being kfree()'d.

And here's a patch which, combined with the fixes for ipuv3, results in everything appearing to work properly. Feel free to tear out the bits for your area and turn them into proper patches.

 drivers/gpu/ipu-v3/ipu-common.c           |  6 ---
 drivers/media/media-entity.c              |  7 +--
 drivers/media/v4l2-core/v4l2-async.c      | 71 +++++++++++++++++++++++--------
 drivers/staging/media/imx/imx-media-csi.c |  1 +
 drivers/staging/media/imx/imx-media-dev.c |  2 +-
 5 files changed, 59 insertions(+), 28 deletions(-)
drivers/gpu/ipu-v3/ipu-common.c +0 -6
index 97218af4fe75..8368e6f766ee 100644
@@ -1238,12 +1238,6 @@ static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
 			platform_device_put(pdev);
 			goto err_register;
 		}
-
-		/*
-		 * Set of_node only after calling platform_device_add. Otherwise
-		 * the platform:imx-ipuv3-crtc modalias won't be used.
-		 */
-		pdev->dev.of_node = of_node;
 	}
 
 	return 0;
drivers/media/media-entity.c +4 -3
index f9f723f5e4f0..154593a168df 100644
@@ -625,9 +625,10 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	struct media_link *link;
 	struct media_link *backlink;
 
-	BUG_ON(source == NULL || sink == NULL);
-	BUG_ON(source_pad >= source->num_pads);
-	BUG_ON(sink_pad >= sink->num_pads);
+	if (WARN_ON(source == NULL || sink == NULL) ||
+	    WARN_ON(source_pad >= source->num_pads) ||
+	    WARN_ON(sink_pad >= sink->num_pads))
+		return -EINVAL;
 
 	link = media_add_link(&source->links);
 	if (link == NULL)
drivers/media/v4l2-core/v4l2-async.c +53 -18

131 lines not on this page · raw message

drivers/staging/media/imx/imx-media-csi.c +1 -0
index 9d9ec03436e4..507026feee91 100644
@@ -1427,6 +1427,7 @@ static int imx_csi_probe(struct platform_device *pdev)
 	priv->sd.entity.ops = &csi_entity_ops;
 	priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
 	priv->sd.dev = &pdev->dev;
+	priv->sd.of_node = pdata->of_node;
 	priv->sd.owner = THIS_MODULE;
 	priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
 	priv->sd.grp_id = priv->csi_id ?
drivers/staging/media/imx/imx-media-dev.c +1 -1
index 60f45fe4b506..5b4dfc1fb6ab 100644
@@ -197,7 +197,7 @@ static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
 	struct imx_media_subdev *imxsd;
 	int ret = -EINVAL;
 
-	imxsd = imx_media_find_async_subdev(imxmd, sd->dev->of_node,
+	imxsd = imx_media_find_async_subdev(imxmd, sd->of_node,
 					    dev_name(sd->dev));
 	if (!imxsd)
 		goto out;
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
#133 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

In reply to Russell King - ARM Linux
Quoted 14 lines · Russell King - ARM Linux
Quoted 3 lines · Steve Longerbeam

Add the core media driver for i.MX SOC.

Just as I reported on the 30th January:

Applying: media: Add i.MX media core driver .git/rebase-apply/patch:614: new blank line at EOF. +
.git/rebase-apply/patch:626: new blank line at EOF. +
.git/rebase-apply/patch:668: new blank line at EOF. +

Quoted 1 line

These need fixing.

Missed these obviously, fixed.

Steve

author maintainer
#151 lore raw

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

In reply to Russell King - ARM Linux
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.

author maintainer
#169 lore raw

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

In reply to Russell King - ARM Linux
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
#214 lore raw

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

In reply to Philipp Zabel
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

author maintainer
#216 lore raw
In reply to Russell King - ARM Linux
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

author maintainer
#145 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Russell King - ARM Linux
Quoted 61 lines · Russell King - ARM Linux
Quoted 54 lines · Russell King - ARM Linux
Quoted 10 lines · Steve Longerbeam
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+static const struct platform_device_id imx_csi_ids[] = {
+	{ .name = "imx-ipuv3-csi" },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, imx_csi_ids);
+
+static struct platform_driver imx_csi_driver = {
+	.probe = imx_csi_probe,
+	.remove = imx_csi_remove,
+	.id_table = imx_csi_ids,

drivers/staging/media/imx/imx-media-csi.c line 1220

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c new file +10 -0
+	.driver = {
+		.name = "imx-ipuv3-csi",
+	},
+};
+module_platform_driver(imx_csi_driver);
+
+MODULE_DESCRIPTION("i.MX CSI subdev driver");
+MODULE_AUTHOR("Steve Longerbeam <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:imx-ipuv3-csi");

Just a reminder that automatic module loading of this is completely broken right now (not your problem) due to this stupid idea in the IPUv3 code:

		if (!ret)
			ret = platform_device_add(pdev);
		if (ret) {
			platform_device_put(pdev);
			goto err_register;
		}

		/*
		 * Set of_node only after calling platform_device_add. Otherwise
		 * the platform:imx-ipuv3-crtc modalias won't be used.
		 */
		pdev->dev.of_node = of_node;

setting pdev->dev.of_node changes the modalias exported to userspace, so udev sees a DT based modalias, which causes it to totally miss any driver using a non-DT based modalias.

The IPUv3 code needs fixing, not only for imx-media-csi, but also for imx-ipuv3-crtc too, because that module will also suffer the same issue.

The only solution is... don't fsck with dev->of_node assignment. In this case, it's probably much better to pass it in via platform data. If you then absolutely must have dev->of_node, doing it in the driver means that you avoid the modalias mess before the appropriate driver is loaded. However, that's still not a nice solution because the modalias file still ends up randomly changing its contents.

Quoted 2 lines

As I say, not _your_ problem, but it's still a problem that needs solving, and I don't want it forgotten about.

I've just hacked up a solution to this, and unfortunately it reveals a problem with Steve's code. Picking out the imx & media-related messages:

Quoted 12 lines
[    8.012191] imx_media_common: module is from the staging directory, the quality is unknown, you have been warned.
[    8.018175] imx_media: module is from the staging directory, the quality is unknown, you have been warned.
[    8.748345] imx-media: Registered subdev ipu1_csi0_mux
[    8.753451] imx-media: Registered subdev ipu2_csi1_mux
[    9.055196] imx219 0-0010: detected IMX219 sensor
[    9.090733] imx6_mipi_csi2: module is from the staging directory, the quality is unknown, you have been warned.
[    9.092247] imx-media: Registered subdev imx219 0-0010
[    9.334338] imx-media: Registered subdev imx6-mipi-csi2
[    9.372452] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.378163] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.390033] imx_media_csi: module is from the staging directory, the quality is unknown, you have been warned.
[    9.394362] imx-media: Received unknown subdev ipu1_csi0

The root problem is here. I don't know why the CSI entities are not being recognized. Can you share the changes you made?

So imx_media_subdev_bound() returns error because it didn't recognize the subdev that was bound.

And for some reason, even though some of the subdev bound ops return error, v4l2-core still calls the async completion notifier (imx_media_probe_complete()).

I'll add some checks to imx_media_probe_complete() to try and detect when not all subdevs were bound correctly to get around this issue. That should prevent the kernel BUG() below.

Steve

Quoted 180 lines
[    9.394699] imx-ipuv3-csi: probe of imx-ipuv3-csi.0 failed with error -22
[    9.394840] imx-media: Received unknown subdev ipu1_csi1
[    9.394887] imx-ipuv3-csi: probe of imx-ipuv3-csi.1 failed with error -22
[    9.394992] imx-media: Received unknown subdev ipu2_csi0
[    9.395026] imx-ipuv3-csi: probe of imx-ipuv3-csi.4 failed with error -22
[    9.395119] imx-media: Received unknown subdev ipu2_csi1
[    9.395159] imx-ipuv3-csi: probe of imx-ipuv3-csi.5 failed with error -22
[    9.411722] imx_media_vdic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.412820] imx-media: Registered subdev ipu1_vdic
[    9.424687] imx-media: Registered subdev ipu2_vdic
[    9.436074] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.437455] imx-media: Registered subdev ipu1_ic_prp
[    9.437788] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.447542] imx-media: Registered subdev ipu1_ic_prpenc
[    9.455225] ipu1_ic_prpenc: Registered ipu1_ic_prpenc capture as /dev/video3
[    9.459203] imx-media: Registered subdev ipu1_ic_prpvf
[    9.460484] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[    9.460726] ipu1_ic_prpvf: Registered ipu1_ic_prpvf capture as /dev/video4
[    9.460983] imx-media: Registered subdev ipu2_ic_prp
[    9.461161] imx-media: Registered subdev ipu2_ic_prpenc
[    9.461737] ipu2_ic_prpenc: Registered ipu2_ic_prpenc capture as /dev/video5
[    9.463767] imx-media: Registered subdev ipu2_ic_prpvf
[    9.464294] ipu2_ic_prpvf: Registered ipu2_ic_prpvf capture as /dev/video6
[    9.464345] imx-media: imx_media_create_link: (null):1 -> ipu1_ic_prp:0
[    9.464413] ------------[ cut here ]------------
[    9.469134] kernel BUG at /home/rmk/git/linux-rmk/drivers/media/media-entity.c:628!
[    9.476924] Internal error: Oops - BUG: 0 [#1] SMP ARM
[    9.482246] Modules linked in: imx_media_ic(C+) imx_media_vdic(C) imx_media_csi(C) imx_media_capture(C) uvcvideo imx6_mipi_csi2(C) snd_soc_imx_audmux imx219 snd_soc_sgtl5000 video_multiplexer caam imx_sdma imx2_wdt snd_soc_fsl_ssi snd_soc_fsl_spdif imx_pcm_dma coda imx_thermal v4l2_mem2mem videobuf2_v4l2 videobuf2_dma_contig videobuf2_core videobuf2_vmalloc videobuf2_memops imx_media(C) imx_media_common(C) rc_pinnacle_pctv_hd nfsd dw_hdmi_cec dw_hdmi_ahb_audio etnaviv
[    9.524500] CPU: 1 PID: 263 Comm: systemd-udevd Tainted: G         C      4.10.0-rc7+ #2112
[    9.532995] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[    9.539619] task: edef1880 task.stack: d03ca000
[    9.544313] PC is at media_create_pad_link+0x134/0x140
[    9.549541] LR is at imx_media_probe_complete+0x164/0x24c [imx_media]
[    9.556080] pc : [<c04f0eb0>]    lr : [<bf052524>]    psr: 60070013
               sp : d03cbbc8  ip : d03cbbf8  fp : d03cbbf4
[    9.567712] r10: 00000001  r9 : 00000000  r8 : d0170d14
[    9.573007] r7 : 00000000  r6 : 00000001  r5 : 00000000  r4 : d0170d14
[    9.579612] r3 : 00000000  r2 : d0170d14  r1 : 00000001  r0 : 00000000
[    9.586256] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none[    9.593486] Control: 10c5387d  Table: 3e77c04a  DAC: 00000051
[    9.599317] Process systemd-udevd (pid: 263, stack limit = 0xd03ca210)
[    9.605950] Stack: (0xd03cbbc8 to 0xd03cc000)
[    9.610368] bbc0:                   00000000 00000000 ee980410 00000000 00000000 d0170d14
[    9.618658] bbe0: 00000000 00000001 d03cbc54 d03cbbf8 bf052524 c04f0d88 00000000 d0170d88
[    9.626961] bc00: 00000000 c0a57dc4 0004a364 ee98011c 00000000 00000003 00000001 ee980230
[    9.635267] bc20: ee980274 ee980010 d03cbc54 d0170f14 ee9ca4cc ee9974c4 bf0523c0 c0a57dc4
[    9.643539] bc40: f184bb30 00000026 d03cbc74 d03cbc58 c0502f50 bf0523cc ee9ca4cc d0170f14
[    9.651824] bc60: c0a57e08 d0170fc0 d03cbc9c d03cbc78 c0502fdc c0502e70 00000000 d0170f10
[    9.660132] bc80: 00000000 d02c0c10 bf122cd0 d0170f14 d03cbcc4 d03cbca0 bf121154 c0502f68
[    9.668423] bca0: bf12104c ffffffed d02c0c10 fffffdfb bf123248 00000000 d03cbce4 d03cbcc8
[    9.676713] bcc0: c041aeb4 bf121058 d02c0c10 c1419d70 00000000 bf123248 d03cbd0c d03cbce8
[    9.684992] bce0: c0418ec4 c041ae68 d02c0c10 bf123248 d02c0c44 00000000 00000001 00000124
[    9.693282] bd00: d03cbd2c d03cbd10 c0419044 c0418ccc 00000000 00000000 bf123248 c0418f88
[    9.701618] bd20: d03cbd54 d03cbd30 c04172e4 c0418f94 ef0f64a4 d01b8cd0 d03d9858 bf123248
[    9.709900] bd40: d03d9c00 c0a45e10 d03cbd64 d03cbd58 c0418728 c0417294 d03cbd8c d03cbd68
[    9.718203] bd60: c0418428 c0418710 bf122e48 d03cbd78 bf123248 c0a704a8 bf126000 00000000
[    9.729180] bd80: d03cbda4 d03cbd90 c0419ec4 c0418340 bf123480 c0a704a8 d03cbdb4 d03cbda8
[    9.739950] bda0: c041ad88 c0419e50 d03cbdc4 d03cbdb8 bf126018 c041ad4c d03cbe34 d03cbdc8
[    9.751089] bdc0: c00098ac bf12600c d03cbdec d03cbdd8 c00a8888 c0087240 00000000 ed4a9440
[    9.761941] bde0: d03cbe34 d03cbdf0 c016c690 c00a8814 c016b554 c016aa60 00000001 c015f3f8
[    9.772940] be00: 00000005 0000000c edef1880 bf123480 c0a704a8 bf123480 c0a704a8 ed4a9440
[    9.784008] be20: bf123480 00000001 d03cbe5c d03cbe38 c011b1e4 c0009874 d03cbe5c d03cbe48
[    9.795017] be40: c09f5ea7 c0a704a8 c09e04ec bf123480 d03cbf14 d03cbe60 c00d2dd0 c011b188
[    9.806069] be60: bf12348c 00007fff bf123480 c00d09f0 f1847000 bf12792c f18495c0 bf123680
[    9.817194] be80: bf12348c bf1236f0 00000000 bf1234c8 c017c1d0 c017bfac f1847000 00004f68
[    9.828347] bea0: c017c2e8 00000000 edef1880 00000000 00000000 00000000 00000000 00000000
[    9.839542] bec0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    9.850754] bee0: 00000000 00000000 00000003 7fffffff 00000000 00000000 00000007 b6c9e63c
[    9.861991] bf00: d03ca000 00000000 d03cbfa4 d03cbf18 c00d36cc c00d1480 7fffffff 00000000
[    9.873266] bf20: 00000003 ee0384d4 d03cbf74 f1847000 00004f68 00000000 00000002 f1847000
[    9.884593] bf40: 00004f68 f184bb30 f184989b f184a7d8 000026f0 00002dd0 00000000 00000000
[    9.895998] bf60: 00000000 0000192c 00000019 0000001a 00000011 00000000 0000000a 00000000
[    9.907408] bf80: c008b848 80c36630 00000000 2529fc00 0000017b c000ff04 00000000 d03cbfa8
[    9.918858] bfa0: c000fd60 c00d3644 80c36630 00000000 00000007 b6c9e63c 00000000 80c38178
[    9.930354] bfc0: 80c36630 00000000 2529fc00 0000017b 00020000 7f96eb0c 80c37848 00000000
[    9.941900] bfe0: bed55928 bed55918 b6c988ff b6bea572 600f0030 00000007 3fffd861 3fffdc61
[    9.953532] Backtrace:
[    9.959442] [<c04f0d7c>] (media_create_pad_link) from [<bf052524>] (imx_media_probe_complete+0x164/0x24c [imx_media])
[    9.973644]  r10:00000001 r9:00000000 r8:d0170d14 r7:00000000 r6:00000000 r5:ee980410
[    9.985112]  r4:00000000 r3:00000000
[    9.992696] [<bf0523c0>] (imx_media_probe_complete [imx_media]) from [<c0502f50>] (v4l2_async_test_notify+0xec/0xf8)
[   10.007413]  r10:00000026 r9:f184bb30 r8:c0a57dc4 r7:bf0523c0 r6:ee9974c4 r5:ee9ca4cc
[   10.019212]  r4:d0170f14
[   10.025650] [<c0502e64>] (v4l2_async_test_notify) from [<c0502fdc>] (v4l2_async_register_subdev+0x80/0xdc)
[   10.039736]  r7:d0170fc0 r6:c0a57e08 r5:d0170f14 r4:ee9ca4cc
[   10.049613] [<c0502f5c>] (v4l2_async_register_subdev) from [<bf121154>] (imx_ic_probe+0x108/0x144 [imx_media_ic])
[   10.063953]  r8:d0170f14 r7:bf122cd0 r6:d02c0c10 r5:00000000 r4:d0170f10 r3:00000000
[   10.075786] [<bf12104c>] (imx_ic_probe [imx_media_ic]) from [<c041aeb4>] (platform_drv_probe+0x58/0xb8)
[   10.089118]  r8:00000000 r7:bf123248 r6:fffffdfb r5:d02c0c10 r4:ffffffed r3:bf12104c
[   10.100683] [<c041ae5c>] (platform_drv_probe) from [<c0418ec4>] (driver_probe_device+0x204/0x2c8)
[   10.113279]  r7:bf123248 r6:00000000 r5:c1419d70 r4:d02c0c10
[   10.122765] [<c0418cc0>] (driver_probe_device) from [<c0419044>] (__driver_attach+0xbc/0xc0)
[   10.135098]  r10:00000124 r8:00000001 r7:00000000 r6:d02c0c44 r5:bf123248 r4:d02c0c10
[   10.146785] [<c0418f88>] (__driver_attach) from [<c04172e4>] (bus_for_each_dev+0x5c/0x90)
[   10.158811]  r6:c0418f88 r5:bf123248 r4:00000000 r3:00000000
[   10.168375] [<c0417288>] (bus_for_each_dev) from [<c0418728>] (driver_attach+0x24/0x28)
[   10.180413]  r6:c0a45e10 r5:d03d9c00 r4:bf123248
[   10.188959] [<c0418704>] (driver_attach) from [<c0418428>] (bus_add_driver+0xf4/0x200)
[   10.200775] [<c0418334>] (bus_add_driver) from [<c0419ec4>] (driver_register+0x80/0xfc)
[   10.212707]  r7:00000000 r6:bf126000 r5:c0a704a8 r4:bf123248
[   10.222254] [<c0419e44>] (driver_register) from [<c041ad88>] (__platform_driver_register+0x48/0x4c)
[   10.235212]  r5:c0a704a8 r4:bf123480
[   10.242694] [<c041ad40>] (__platform_driver_register) from [<bf126018>] (imx_ic_driver_init+0x18/0x24 [imx_media_ic])
[   10.257308] [<bf126000>] (imx_ic_driver_init [imx_media_ic]) from [<c00098ac>] (do_one_initcall+0x44/0x170)
[   10.271043] [<c0009868>] (do_one_initcall) from [<c011b1e4>] (do_init_module+0x68/0x1d8)
[   10.283139]  r8:00000001 r7:bf123480 r6:ed4a9440 r5:c0a704a8 r4:bf123480
[   10.293849] [<c011b17c>] (do_init_module) from [<c00d2dd0>] (load_module+0x195c/0x2080)
[   10.305867]  r7:bf123480 r6:c09e04ec r5:c0a704a8 r4:c09f5ea7
[   10.315523] [<c00d1474>] (load_module) from [<c00d36cc>] (SyS_finit_module+0x94/0xa0)
[   10.327382]  r10:00000000 r9:d03ca000 r8:b6c9e63c r7:00000007 r6:00000000 r5:00000000
[   10.339238]  r4:7fffffff
[   10.345766] [<c00d3638>] (SyS_finit_module) from [<c000fd60>] (ret_fast_syscall+0x0/0x1c)
[   10.357994]  r8:c000ff04 r7:0000017b r6:2529fc00 r5:00000000 r4:80c36630
[   10.368747] Code: e1a01007 ebfffce1 e3e0000b e89daff8 (e7f001f2)
[   10.378883] ---[ end trace 2051fac455b36c5a ]---
[   11.228961] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[   11.247536] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.
[   11.301366] imx_media_ic: module is from the staging directory, the quality is unknown, you have been warned.

So there's probably some sort of race going on.

However, the following is primerily directed at Laurent as the one who introduced the BUG_ON() in question...

NEVER EVER USE BUG_ON() IN A PATH THAT CAN RETURN AN ERROR.

It's possible to find Linus rants about this, eg,
https://www.spinics.net/lists/stable/msg146439.html

I should have reacted to the damn added BUG_ON() lines. I suspect I will have to finally just remove the idiotic BUG_ON() concept once and for all, because there is NO F*CKING EXCUSE to knowingly kill the kernel.

Also: http://yarchive.net/comp/linux/BUG.html

Rule of thumb: BUG() is only good for something that never happens and that we really have no other option for (ie state is so corrupt that continuing is deadly).

So, _unless_ people want to see BUG_ON() removed from the kernel, I strongly suggest to _STOP_ using it as "we didn't like the function arguments, let's use it as an assert() statement instead of returning an error."

There's no excuse what so ever to be killing the machine in media_create_pad_link(). If it doesn't like a NULL pointer, it's damn well got an error path to report that fact. Use that mechanism and stop needlessly killing the kernel.

BUG_ON() IS NOT ASSERT(). DO NOT USE IT AS SUCH.

Linus is absolutely right about BUG_ON() - it hurts debuggability, because now the only way to do further tests is to reboot the damned machine after removing those fscking BUG_ON()s that should *never* have been there in the first place.

As Linus went on to say:

And dammit, if anybody else feels that they had done "debugging messages with BUG_ON()", I would suggest you

(a) rethink your approach to programming

(b) send me patches to remove the crap entirely, or make them real
*DEBUGGING* messages, not "kill the whole machine" messages.

I've ranted against people using BUG_ON() for debugging in the past. Why the f*ck does this still happen? And Andrew - please stop taking those kinds of patches! Lookie here:

     https://lwn.net/Articles/13183/

so excuse me for being upset that people still do this shit almost 15 years later.

So I suggest people heed that advice and start fixing these stupid BUG_ON()s that they've created.

Thanks.

author maintainer
#144 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Russell King - ARM Linux
Quoted 40 lines · Russell King - ARM Linux
Quoted 14 lines · Russell King - ARM Linux

<snip>
More crap.

If the "complete" method fails (or, in fact, anything in v4l2_async_test_notify() fails) then all hell breaks loose, because of the total lack of clean up (and no, this isn't anything to do with some stupid justification of those BUG_ON()s above.)

v4l2_async_notifier_register() gets called, it adds the notifier to the global notifier list. v4l2_async_test_notify() gets called. It returns an error, which is propagated out of v4l2_async_notifier_register().

Quoted 8 lines

So the caller thinks that v4l2_async_notifier_register() failed, which will cause imx_media_probe() to fail, causing imxmd->subdev_notifier to be kfree()'d. We now have a use-after free bug.

Second case. v4l2_async_register_subdev(). Almost exactly the same, except in this case adding sd->async_list to the notifier->done list may have succeeded, and failure after that, again, results in an in-use list_head being kfree()'d.

And here's a patch which, combined with the fixes for ipuv3, results in everything appearing to work properly. Feel free to tear out the bits for your area and turn them into proper patches.

 drivers/gpu/ipu-v3/ipu-common.c           |  6 ---
 drivers/media/media-entity.c              |  7 +--
 drivers/media/v4l2-core/v4l2-async.c      | 71 +++++++++++++++++++++++--------
 drivers/staging/media/imx/imx-media-csi.c |  1 +
 drivers/staging/media/imx/imx-media-dev.c |  2 +-
 5 files changed, 59 insertions(+), 28 deletions(-)
drivers/gpu/ipu-v3/ipu-common.c +0 -0
index 97218af4fe75..8368e6f766ee 100644

drivers/gpu/ipu-v3/ipu-common.c static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base) · line 1241

Quoted 10 lines
drivers/gpu/ipu-v3/ipu-common.c +0 -6
@@ -1238,12 +1238,6 @@ static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
 			platform_device_put(pdev);
 			goto err_register;
 		}
-
-		/*
-		 * Set of_node only after calling platform_device_add. Otherwise
-		 * the platform:imx-ipuv3-crtc modalias won't be used.
-		 */
-		pdev->dev.of_node = of_node;
 	}

Ah, never mind my question earlier, I see now why the CSI's were likely not recognized, probably because of this. Anyway I agree with this change and I made the accompanying requisite change to imx-media-csi.c and imx-media-dev.c below.

Steve

Quoted 189 lines
drivers/gpu/ipu-v3/ipu-common.c +0 -0
 	return 0;
drivers/media/media-entity.c +4 -3
index f9f723f5e4f0..154593a168df 100644
@@ -625,9 +625,10 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	struct media_link *link;
 	struct media_link *backlink;
 
-	BUG_ON(source == NULL || sink == NULL);
-	BUG_ON(source_pad >= source->num_pads);
-	BUG_ON(sink_pad >= sink->num_pads);
+	if (WARN_ON(source == NULL || sink == NULL) ||
+	    WARN_ON(source_pad >= source->num_pads) ||
+	    WARN_ON(sink_pad >= sink->num_pads))
+		return -EINVAL;
 
 	link = media_add_link(&source->links);
 	if (link == NULL)
drivers/media/v4l2-core/v4l2-async.c +53 -18
index 5bada202b2d3..09934fb96a8d 100644
@@ -94,7 +94,7 @@ static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *
 }
 
 static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
-				  struct v4l2_subdev *sd,
+				  struct list_head *new, struct v4l2_subdev *sd,
 				  struct v4l2_async_subdev *asd)
 {
 	int ret;
@@ -107,22 +107,36 @@ static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
 	if (notifier->bound) {
 		ret = notifier->bound(notifier, sd, asd);
 		if (ret < 0)
-			return ret;
+			goto err_bind;
 	}
+
 	/* Move from the global subdevice list to notifier's done */
-	list_move(&sd->async_list, &notifier->done);
+	list_move(&sd->async_list, new);
 
 	ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
-	if (ret < 0) {
-		if (notifier->unbind)
-			notifier->unbind(notifier, sd, asd);
-		return ret;
-	}
+	if (ret < 0)
+		goto err_register;
 
-	if (list_empty(&notifier->waiting) && notifier->complete)
-		return notifier->complete(notifier);
+	if (list_empty(&notifier->waiting) && notifier->complete) {
+		ret = notifier->complete(notifier);
+		if (ret < 0)
+			goto err_complete;
+	}
 
 	return 0;
+
+err_complete:
+	v4l2_device_unregister_subdev(sd);
+err_register:
+	if (notifier->unbind)
+		notifier->unbind(notifier, sd, asd);
+err_bind:
+	sd->notifier = NULL;
+	sd->asd = NULL;
+	list_add(&asd->list, &notifier->waiting);
+	/* always take this off the list on error */
+	list_del(&sd->async_list);
+	return ret;
 }
 
 static void v4l2_async_cleanup(struct v4l2_subdev *sd)
@@ -139,7 +153,8 @@ int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
 {
 	struct v4l2_subdev *sd, *tmp;
 	struct v4l2_async_subdev *asd;
-	int i;
+	LIST_HEAD(new);
+	int ret, i;
 
 	if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
 		return -EINVAL;
@@ -172,22 +187,39 @@ int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
 	list_add(&notifier->list, &notifier_list);
 
 	list_for_each_entry_safe(sd, tmp, &subdev_list, async_list) {
-		int ret;
-
 		asd = v4l2_async_belongs(notifier, sd);
 		if (!asd)
 			continue;
 
-		ret = v4l2_async_test_notify(notifier, sd, asd);
+		ret = v4l2_async_test_notify(notifier, &new, sd, asd);
 		if (ret < 0) {
-			mutex_unlock(&list_lock);
-			return ret;
+			/*
+			 * On failure, v4l2_async_test_notify() takes the
+			 * sd off the subdev list.  Add it back.
+			 */
+			list_add(&sd->async_list, &subdev_list);
+			goto err_notify;
 		}
 	}
 
+	list_splice(&new, &notifier->done);
+
 	mutex_unlock(&list_lock);
 
 	return 0;
+
+err_notify:
+	list_del(&notifier->list);
+	list_for_each_entry_safe(sd, tmp, &new, async_list) {
+		v4l2_device_unregister_subdev(sd);
+		list_move(&sd->async_list, &subdev_list);
+		if (notifier->unbind)
+			notifier->unbind(notifier, sd, sd->asd);
+		sd->notifier = NULL;
+		sd->asd = NULL;
+	}
+	mutex_unlock(&list_lock);
+	return ret;
 }
 EXPORT_SYMBOL(v4l2_async_notifier_register);
 
@@ -213,6 +245,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
 	list_del(&notifier->list);
 
 	list_for_each_entry_safe(sd, tmp, &notifier->done, async_list) {
+		struct v4l2_async_subdev *asd = sd->asd;
 		struct device *d;
 
 		d = get_device(sd->dev);
@@ -223,7 +256,7 @@ void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
 		device_release_driver(d);
 
 		if (notifier->unbind)
-			notifier->unbind(notifier, sd, sd->asd);
+			notifier->unbind(notifier, sd, asd);
 
 		/*
 		 * Store device at the device cache, in order to call
@@ -288,7 +321,9 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
 	list_for_each_entry(notifier, &notifier_list, list) {
 		struct v4l2_async_subdev *asd = v4l2_async_belongs(notifier, sd);
 		if (asd) {
-			int ret = v4l2_async_test_notify(notifier, sd, asd);
+			int ret = v4l2_async_test_notify(notifier,
+							 &notifier->done,
+							 sd, asd);
 			mutex_unlock(&list_lock);
 			return ret;
 		}
drivers/staging/media/imx/imx-media-csi.c +1 -0
index 9d9ec03436e4..507026feee91 100644
@@ -1427,6 +1427,7 @@ static int imx_csi_probe(struct platform_device *pdev)
 	priv->sd.entity.ops = &csi_entity_ops;
 	priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
 	priv->sd.dev = &pdev->dev;
+	priv->sd.of_node = pdata->of_node;
 	priv->sd.owner = THIS_MODULE;
 	priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
 	priv->sd.grp_id = priv->csi_id ?
drivers/staging/media/imx/imx-media-dev.c +1 -1
index 60f45fe4b506..5b4dfc1fb6ab 100644
@@ -197,7 +197,7 @@ static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
 	struct imx_media_subdev *imxsd;
 	int ret = -EINVAL;
 
-	imxsd = imx_media_find_async_subdev(imxmd, sd->dev->of_node,
+	imxsd = imx_media_find_async_subdev(imxmd, sd->of_node,
 					    dev_name(sd->dev));
 	if (!imxsd)
 		goto out;
#146 lore raw

Re: [PATCH v4 20/36] media: imx: Add CSI subdev driver

In reply to Steve Longerbeam
Quoted 14 lines · Steve Longerbeam
Quoted 4 lines · Russell King - ARM Linux
[    8.012191] imx_media_common: module is from the staging directory, the quality is unknown, you have been warned.
[    8.018175] imx_media: module is from the staging directory, the quality is unknown, you have been warned.
[    8.748345] imx-media: Registered subdev ipu1_csi0_mux
[    8.753451] imx-media: Registered subdev ipu2_csi1_mux
Quoted 8 lines
[    9.055196] imx219 0-0010: detected IMX219 sensor
[    9.090733] imx6_mipi_csi2: module is from the staging directory, the quality is unknown, you have been warned.
[    9.092247] imx-media: Registered subdev imx219 0-0010
[    9.334338] imx-media: Registered subdev imx6-mipi-csi2
[    9.372452] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.378163] imx_media_capture: module is from the staging directory, the quality is unknown, you have been warned.
[    9.390033] imx_media_csi: module is from the staging directory, the quality is unknown, you have been warned.
[    9.394362] imx-media: Received unknown subdev ipu1_csi0
Quoted 2 lines

The root problem is here. I don't know why the CSI entities are not being recognized. Can you share the changes you made?

No, it's not the root problem that's causing the BUG/etc, but it is _a_ problem. Nevertheless, it's something I fixed - disconnecting the of_node from the struct device needed one other change in the imx-media code that was missing at this time.

However, that's no excuse what so ever for the BUG_ON() and lack of error cleanup (causing use-after-free, which is just another way of saying "data corruption waiting to happen") that I identified.

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
#3 lore raw

Re: [PATCH v4 01/36] [media] dt-bindings: Add bindings for i.MX media driver

In reply to Philipp Zabel
Quoted 28 lines · Philipp Zabel
Quoted 27 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +13 -0
new file mode 100644
index 0000000..fd5af50
@@ -0,0 +1,66 @@
+Freescale i.MX Media Video Device
+=================================
+
+Video Media Controller node
+---------------------------
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports      : Should contain a list of phandles pointing to camera
Quoted 8 lines

Documentation/devicetree/bindings/media/imx.txt line 19

Quoted 6 lines
Documentation/devicetree/bindings/media/imx.txt new file +6 -0
+		sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+	compatible = "fsl,capture-subsystem";

"fsl,imx-capture-subsystem"

Fixed.

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.
reviewer
#12 lore raw

Re: [PATCH v4 07/36] ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors

In reply to Steve Longerbeam

Hi Steve,

Quoted 9 lines · Steve Longerbeam

Enables the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

The OV5640 connects to the input port on the MIPI CSI-2 receiver on mipi_csi.

Until the OV5652 sensor module compatible with the SabreSD becomes available for testing, the ov5642 node is currently disabled.

You missed your Signed-off-by.

author maintainer
#13 lore raw

Re: [PATCH v4 07/36] ARM: dts: imx6-sabresd: add OV5642 and OV5640 camera sensors

Quoted 8 lines · Fabio Estevam

Hi Steve,

Quoted 4 lines · Steve Longerbeam

Enables the OV5642 parallel-bus sensor, and the OV5640 MIPI CSI-2 sensor.

The OV5642 connects to the parallel-bus mux input port on ipu1_csi0_mux.

Quoted 7 lines
Quoted 5 lines

The OV5640 connects to the input port on the MIPI CSI-2 receiver on mipi_csi.

Until the OV5652 sensor module compatible with the SabreSD becomes available for testing, the ov5642 node is currently disabled.

You missed your Signed-off-by.

Thanks, fixed.

Steve

author maintainer
#136 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

In reply to Philipp Zabel
Quoted 1 line · Philipp Zabel

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

<snip>

Quoted 5 lines

drivers/staging/media/imx/TODO line 15

Quoted 3 lines
drivers/staging/media/imx/TODO new file +3 -0
+
+- Clean up and move the ov5642 subdev driver to drivers/media/i2c, and
+  create the binding docs for it.

This is done already, right?

I cleaned up ov5640 and moved it to drivers/media/i2c with binding docs, but not the ov5642 yet.

Quoted 12 lines

drivers/staging/media/imx/TODO line 26

Quoted 11 lines

+- The Frame Interval Monitor could be exported to v4l2-core for

drivers/staging/media/imx/TODO new file +9 -0
+  general use.
+
+- The subdev that is the original source of video data (referred to as
+  the "sensor" in the code), is called from various subdevs in the
+  pipeline in order to set/query the video standard ({g|s|enum}_std)
+  and to get/set the original frame interval from the capture interface
+  ([gs]_parm). Instead, the entities that need this info should call its
+  direct neighbor, and the neighbor should propagate the call to its
+  neighbor in turn if necessary.
Quoted 2 lines

Especially the [gs]_parm fix is necessary to present userspace with the correct frame interval in case of frame skipping in the CSI.

Right, understood. I've added this to list of fixes for version 5.

What a pain though! It means propagating every call to g_frame_interval upstream until a subdev "that cares" returns ret == 0 or
ret != -ENOIOCTLCMD. And that goes for any other chained subdev call as well.

I've thought of writing something like a v4l2_chained_subdev_call() macro to do this, but it would be a big macro.

Quoted 40 lines
Quoted 15 lines

+- At driver load time, the device-tree node that is the original source

drivers/staging/media/imx/TODO new file +8 -0
+  (the "sensor"), is parsed to record its media bus configuration, and
+  this info is required in various subdevs to setup the pipeline.
+  Laurent Pinchart argues that instead the subdev should call its
+  neighbor's g_mbus_config op (which should be propagated if necessary)
+  to get this info. However Hans Verkuil is planning to remove the
+  g_mbus_config op. For now this driver uses the parsed DT mbus config
+  method until this issue is resolved.
+
drivers/staging/media/imx/imx-media-dev.c new file +0 -0
new file mode 100644
index 0000000..e2041ad

[...]

drivers/staging/media/imx/imx-media-dev.c

Quoted 5 lines
drivers/staging/media/imx/imx-media-dev.c new file +5 -0
+static inline u32 pixfmt_to_colorspace(const struct imx_media_pixfmt *fmt)
+{
+	return (fmt->cs == IPUV3_COLORSPACE_RGB) ?
+		V4L2_COLORSPACE_SRGB : V4L2_COLORSPACE_SMPTE170M;
+}

This ...

[...]

Quoted 15 lines
drivers/staging/media/imx/imx-media-dev.c new file +15 -0
+int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
+				  struct v4l2_mbus_framefmt *mbus,
+				  const struct imx_media_pixfmt *cc)
+{
+	u32 stride;
+
+	if (!cc) {
+		cc = imx_media_find_format(0, mbus->code, true, false);
+		if (!cc)
+			return -EINVAL;
+	}
+
+	stride = cc->planar ? mbus->width : (mbus->width * cc->bpp) >> 3;
+
+	pix->width = mbus->width;
Quoted 8 lines

drivers/staging/media/imx/imx-media-dev.c

Quoted 3 lines
drivers/staging/media/imx/imx-media-dev.c new file +3 -0
+	pix->height = mbus->height;
+	pix->pixelformat = cc->fourcc;
+	pix->colorspace = pixfmt_to_colorspace(cc);

... is not right. The colorspace should be taken from the input pad colorspace everywhere (except for the IC output pad in the future, once that supports changing YCbCr encoding and quantization), not guessed based on the media bus format.

Ok, will fix this to assign pix->colorspace to mbus->colorspace, after all the subdevs assign colorspace values to their pads.

Steve

maintainer
#137 lore raw

Re: [PATCH v4 18/36] media: Add i.MX media core driver

Quoted 8 lines · Steve Longerbeam
Quoted 1 line · Philipp Zabel

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

<snip>

Quoted 4 lines
Quoted 3 lines
drivers/staging/media/imx/TODO new file +3 -0
+
+- Clean up and move the ov5642 subdev driver to drivers/media/i2c, and
+  create the binding docs for it.
Quoted 5 lines
Quoted 1 line

This is done already, right?

I cleaned up ov5640 and moved it to drivers/media/i2c with binding docs, but not the ov5642 yet.

Ok, thanks.

Quoted 15 lines
Quoted 11 lines

drivers/staging/media/imx/TODO line 26

Quoted 10 lines

+- The Frame Interval Monitor could be exported to v4l2-core for

drivers/staging/media/imx/TODO new file +9 -0
+  general use.
+
+- The subdev that is the original source of video data (referred to as
+  the "sensor" in the code), is called from various subdevs in the
+  pipeline in order to set/query the video standard ({g|s|enum}_std)
+  and to get/set the original frame interval from the capture interface
+  ([gs]_parm). Instead, the entities that need this info should call its
+  direct neighbor, and the neighbor should propagate the call to its
+  neighbor in turn if necessary.
Quoted 2 lines

Especially the [gs]_parm fix is necessary to present userspace with the correct frame interval in case of frame skipping in the CSI.

Quoted 6 lines

Right, understood. I've added this to list of fixes for version 5.

What a pain though! It means propagating every call to g_frame_interval upstream until a subdev "that cares" returns ret == 0 or
ret != -ENOIOCTLCMD. And that goes for any other chained subdev call as well.

Not at all. Since the frame interval is a property of the pad, that had to be propagated downstream by media-ctl along with media bus format, frame size, and colorimetry earlier.

regards
Philipp

maintainer
#220 lore raw
In reply to Russell King - ARM Linux
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

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

#221 lore raw
In reply to Philipp Zabel
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.
#153 lore raw

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

In reply to 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?

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
#222 lore raw
In reply to Russell King - ARM Linux
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

maintainer
#154 lore raw

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

In reply to Russell King - ARM Linux
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

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
#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

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

author maintainer
#160 lore raw

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

In reply to Philipp Zabel
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.

#171 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
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.
#228 lore raw
In reply to Philipp Zabel

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
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

author maintainer
#174 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
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.
Reviewed-by on v4 12/36
#19 lore raw

Re: [PATCH v4 12/36] add mux and video interface bridge entity functions

In reply to Steve Longerbeam
Quoted 7 lines · Steve Longerbeam

From: Philipp Zabel <[email protected]>

- renamed MEDIA_ENT_F_MUX to MEDIA_ENT_F_VID_MUX

This is slightly "interesting" format of changelog. Normally signoffs go below.

Documentation/media/uapi/mediactl/media-types.rst Types and flags used to represent the media graph elements · line 305

Quoted 13 lines
Documentation/media/uapi/mediactl/media-types.rst +5 -0
index 3e03dc2..023be29 100644
@@ -298,6 +298,28 @@ Types and flags used to represent the media graph elements
 	  received on its sink pad and outputs the statistics data on
 	  its source pad.
 
+    -  ..  row 29
+
+       ..  _MEDIA-ENT-F-MUX:
+
+       -  ``MEDIA_ENT_F_MUX``

And you probably want to rename it here, too.

With that fixed:

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170219/b1c5bf01/attachment.sig>
Reviewed-by on v4 14/36
#33 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Steve Longerbeam
Quoted 4 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170219/db57b10d/attachment.sig>
#122 lore raw

Re: [PATCH v4 15/36] platform: add video-multiplexer subdevice driver

In reply to Steve Longerbeam

Hi!

Quoted 11 lines

From: Philipp Zabel <[email protected]>

This driver can handle SoC internal and external video bus multiplexers, controlled either by register bit fields or by a GPIO. The subdevice passes through frame interval and mbus configuration of the active input to the output side.

--

Again, this is slightly non-standard format. Normally changes from v1 go below ---, but in your case it would cut off the signoff...

Quoted 15 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +9 -0
new file mode 100644
index 0000000..9d133d9
@@ -0,0 +1,59 @@
+Video Multiplexer
+=================
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"

Documentation/devicetree/bindings/media/video-multiplexer.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +10 -0
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.

At least three? I guess it is exactly three with the gpio?

Plus you might want to describe which port correspond to which gpio state/bitfield values...

Documentation/devicetree/bindings/media/video-multiplexer.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +1 -0
+struct vidsw {

I knew it: it is secretely a switch! :-).

Documentation/devicetree/bindings/media/video-multiplexer.txt line 32

Quoted 12 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +12 -0
+static void vidsw_set_active(struct vidsw *vidsw, int active)
+{
+	vidsw->active = active;
+	if (active < 0)
+		return;
+
+	dev_dbg(vidsw->subdev.dev, "setting %d active\n", active);
+
+	if (vidsw->field)
+		regmap_field_write(vidsw->field, active);
+	else if (vidsw->gpio)
+		gpiod_set_value(vidsw->gpio, active);
         else dev_err()...?

Documentation/devicetree/bindings/media/video-multiplexer.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +5 -0
+static int vidsw_async_init(struct vidsw *vidsw, struct device_node *node)
+{
+	struct device_node *ep;
+	u32 portno;
+	int numports;

numbports is int, so I guess portno should be, too?

Documentation/devicetree/bindings/media/video-multiplexer.txt

Quoted 12 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +10 -0
+		portno = endpoint.base.port;
+		if (portno >= numports - 1)
+			continue;
 
 
+	if (!pad) {
+		/* Mirror the input side on the output side */
+		cfg->type = vidsw->endpoint[vidsw->active].bus_type;
+		if (cfg->type == V4L2_MBUS_PARALLEL ||
+		    cfg->type == V4L2_MBUS_BT656)
+			cfg->flags = vidsw->endpoint[vidsw->active].bus.parallel.flags;
+	}

Will this need support for other V4L2_MBUS_ values?

Documentation/devicetree/bindings/media/video-multiplexer.txt

Quoted 2 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +2 -0
+MODULE_AUTHOR("Sascha Hauer, Pengutronix");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");

Normally, MODULE_AUTHOR contains comma separated names of authors, perhaps with <email@addresses>. Not sure two MODULE_AUTHORs per file will work.

Thanks,
Pavel

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170219/3eb79876/attachment.sig>
#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

#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

maintainer
#123 lore raw

Re: [PATCH v4 15/36] platform: add video-multiplexer subdevice driver

In reply to Pavel Machek
Quoted 36 lines · Pavel Machek

Hi!

Quoted 11 lines

From: Philipp Zabel <[email protected]>

This driver can handle SoC internal and external video bus multiplexers, controlled either by register bit fields or by a GPIO. The subdevice passes through frame interval and mbus configuration of the active input to the output side.

--

Again, this is slightly non-standard format. Normally changes from v1 go below ---, but in your case it would cut off the signoff...

Quoted 19 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +13 -0
new file mode 100644
index 0000000..9d133d9
@@ -0,0 +1,59 @@
+Video Multiplexer
+=================
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
Quoted 8 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 19

Quoted 6 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +6 -0
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.

At least three? I guess it is exactly three with the gpio?

Yes. With the mmio bitfield muxes there can be more.

Quoted 6 lines

Plus you might want to describe which port correspond to which gpio state/bitfield values...

Documentation/devicetree/bindings/media/video-multiplexer.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +1 -0
+struct vidsw {

I knew it: it is secretely a switch! :-).

This driver started as a two-input gpio controlled bus switch. I changed the name when adding support for bitfield controlled multiplexers with more than two inputs.

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +6 -0
+static void vidsw_set_active(struct vidsw *vidsw, int active)
+{
+	vidsw->active = active;
+	if (active < 0)
+		return;
+
Quoted 8 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 32

Quoted 6 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +6 -0
+	dev_dbg(vidsw->subdev.dev, "setting %d active\n", active);
+
+	if (vidsw->field)
+		regmap_field_write(vidsw->field, active);
+	else if (vidsw->gpio)
+		gpiod_set_value(vidsw->gpio, active);
         else dev_err()...?

If neither field nor gpio are set, probe will have failed and this will never be called.

Quoted 7 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 37

Quoted 5 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +5 -0
+static int vidsw_async_init(struct vidsw *vidsw, struct device_node *node)
+{
+	struct device_node *ep;
+	u32 portno;
+	int numports;

numbports is int, so I guess portno should be, too?

We could change both to unsigned int, as both vidsw->num_pads and endpoint.base.port are unsigned int, and they are only compared/assigned to those and each other.

Quoted 4 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 40

Quoted 3 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +3 -0
+		portno = endpoint.base.port;
+		if (portno >= numports - 1)
+			continue;
     I. 
Quoted 9 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 47

Quoted 7 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +7 -0
+	if (!pad) {
+		/* Mirror the input side on the output side */
+		cfg->type = vidsw->endpoint[vidsw->active].bus_type;
+		if (cfg->type == V4L2_MBUS_PARALLEL ||
+		    cfg->type == V4L2_MBUS_BT656)
+			cfg->flags = vidsw->endpoint[vidsw->active].bus.parallel.flags;
+	}

Will this need support for other V4L2_MBUS_ values?

To support CSI-2 multiplexers, yes.

Quoted 9 lines

Documentation/devicetree/bindings/media/video-multiplexer.txt line 49

Quoted 2 lines
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +2 -0
+MODULE_AUTHOR("Sascha Hauer, Pengutronix");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");

Normally, MODULE_AUTHOR contains comma separated names of authors, perhaps with <email@addresses>. Not sure two MODULE_AUTHORs per file will work.

Thanks,
Pavel

regards
Philipp

#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
#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
#180 lore raw

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

In reply to Sakari Ailus
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

author maintainer
#20 lore raw

Re: [PATCH v4 12/36] add mux and video interface bridge entity functions

In reply to Pavel Machek
Quoted 20 lines · Pavel Machek
Quoted 7 lines · Steve Longerbeam

From: Philipp Zabel <[email protected]>

- renamed MEDIA_ENT_F_MUX to MEDIA_ENT_F_VID_MUX

This is slightly "interesting" format of changelog. Normally signoffs go below.

Quoted 8 lines
Documentation/media/uapi/mediactl/media-types.rst +0 -0
index 3e03dc2..023be29 100644
@@ -298,6 +298,28 @@ Types and flags used to represent the media graph elements
 	  received on its sink pad and outputs the statistics data on
 	  its source pad.
 
Quoted 7 lines

Documentation/media/uapi/mediactl/media-types.rst Types and flags used to represent the media graph elements · line 305

Quoted 5 lines
Documentation/media/uapi/mediactl/media-types.rst +5 -0
+    -  ..  row 29
+
+       ..  _MEDIA-ENT-F-MUX:
+
+       -  ``MEDIA_ENT_F_MUX``

And you probably want to rename it here, too.

Done, thanks.
Steve

Quoted 5 lines

With that fixed:

author maintainer
#155 lore raw

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

In reply to Philipp Zabel
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
#207 lore raw

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

In reply to Philipp Zabel

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

author maintainer
#130 lore raw

Re: [PATCH v4 17/36] media: Add userspace header file for i.MX

In reply to Philipp Zabel
Quoted 10 lines · Philipp Zabel

include/uapi/media/imx.h line 18

Quoted 7 lines · Steve Longerbeam
include/uapi/media/imx.h new file +6 -0
+/*
+ * events from the subdevs
+ */
+#define V4L2_EVENT_IMX_CLASS          V4L2_EVENT_PRIVATE_START
+#define V4L2_EVENT_IMX_NFB4EOF        (V4L2_EVENT_IMX_CLASS + 1)
+#define V4L2_EVENT_IMX_FRAME_INTERVAL (V4L2_EVENT_IMX_CLASS + 2)

These events are still i.MX specific. I think they shouldn't be.

Done, I've exported them to

V4L2_EVENT_FRAME_INTERVAL_ERROR
V4L2_EVENT_NEW_FRAME_BEFORE_EOF

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
#208 lore raw

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

In reply to Steve Longerbeam

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.

#124 lore raw

Re: [PATCH v4 15/36] platform: add video-multiplexer subdevice driver

In reply to Philipp Zabel

Hi!

Quoted 10 lines
Quoted 6 lines

Plus you might want to describe which port correspond to which gpio state/bitfield values...

Quoted 1 line

+struct vidsw {

I knew it: it is secretely a switch! :-).

This driver started as a two-input gpio controlled bus switch. I changed the name when adding support for bitfield controlled multiplexers with more than two inputs.

We had discussion with Sakari / Rob whether gpio controlled thing is a switch or a multiplexer :-).

Quoted 11 lines
Quoted 9 lines

drivers/media/platform/video-multiplexer.c line 217

Quoted 7 lines
drivers/media/platform/video-multiplexer.c new file +7 -0
+	if (!pad) {
+		/* Mirror the input side on the output side */
+		cfg->type = vidsw->endpoint[vidsw->active].bus_type;
+		if (cfg->type == V4L2_MBUS_PARALLEL ||
+		    cfg->type == V4L2_MBUS_BT656)
+			cfg->flags = vidsw->endpoint[vidsw->active].bus.parallel.flags;
+	}

Will this need support for other V4L2_MBUS_ values?

To support CSI-2 multiplexers, yes.

Can you stick switch () { .... default: dev_err() } there, to help future hackers?

Thank,
Pavel

Signature · 9 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170224/521fe700/attachment.sig>
maintainer
#4 lore raw

Re: [PATCH v4 01/36] [media] dt-bindings: Add bindings for i.MX media driver

In reply to Steve Longerbeam
Quoted 34 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 66 +++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +20 -0
new file mode 100644
index 0000000..fd5af50
@@ -0,0 +1,66 @@
+Freescale i.MX Media Video Device
+=================================
+
+Video Media Controller node
+---------------------------
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports      : Should contain a list of phandles pointing to camera
+		sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+	compatible = "fsl,capture-subsystem";
+	ports = <&ipu1_csi0>, <&ipu1_csi1>;

Documentation/devicetree/bindings/media/imx.txt line 30

Quoted 10 lines
Documentation/devicetree/bindings/media/imx.txt new file +10 -0
+};
+
+fim child node
+--------------
+
+This is an optional child node of the ipu_csi port nodes. If present and
+available, it enables the Frame Interval Monitor. Its properties can be
+used to modify the method in which the FIM measures frame intervals.
+Refer to Documentation/media/v4l-drivers/imx.rst for more info on the
+Frame Interval Monitor.

This should have a compatible string.

Quoted 22 lines
Documentation/devicetree/bindings/media/imx.txt new file +22 -0
+
+Optional properties:
+- fsl,input-capture-channel: an input capture channel and channel flags,
+			     specified as <chan flags>. The channel number
+			     must be 0 or 1. The flags can be
+			     IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, or
+			     IRQ_TYPE_EDGE_BOTH, and specify which input
+			     capture signal edge will trigger the input
+			     capture event. If an input capture channel is
+			     specified, the FIM will use this method to
+			     measure frame intervals instead of via the EOF
+			     interrupt. The input capture method is much
+			     preferred over EOF as it is not subject to
+			     interrupt latency errors. However it requires
+			     routing the VSYNC or FIELD output signals of
+			     the camera sensor to one of the i.MX input
+			     capture pads (SD1_DAT0, SD1_DAT1), which also
+			     gives up support for SD1.
+
+
+mipi_csi2 node
+--------------

Documentation/devicetree/bindings/media/imx.txt line 62

Quoted 10 lines
Documentation/devicetree/bindings/media/imx.txt new file +10 -0
+
+This is the device node for the MIPI CSI-2 Receiver, required for MIPI
+CSI-2 sensors.
+
+Required properties:
+- compatible	: "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
+- reg           : physical base address and length of the register set;
+- clocks	: the MIPI CSI-2 receiver requires three clocks: hsi_tx
+                  (the DPHY clock), video_27m, and eim_podf;
+- clock-names	: must contain "dphy", "cfg", "pix";

Don't you need ports to describe the sensor and IPU connections?

Quoted 7 lines
Documentation/devicetree/bindings/media/imx.txt new file +4 -0
+
+Optional properties:
+- interrupts	: must contain two level-triggered interrupts,
+                  in order: 100 and 101;
Signature · 1 line
2.7.4
maintainer
#125 lore raw

Re: [PATCH v4 15/36] platform: add video-multiplexer subdevice driver

In reply to Steve Longerbeam
Quoted 34 lines · Steve Longerbeam

From: Philipp Zabel <[email protected]>

This driver can handle SoC internal and external video bus multiplexers, controlled either by register bit fields or by a GPIO. The subdevice passes through frame interval and mbus configuration of the active input to the output side.

--

- fixed a cut&paste error in vidsw_remove(): v4l2_async_register_subdev() should be unregister.

- added media_entity_cleanup() and v4l2_device_unregister_subdev() to vidsw_remove().

- added missing MODULE_DEVICE_TABLE().

- there was a line left over from a previous iteration that negated the new way of determining the pad count just before it which has been removed (num_pads = of_get_child_count(np)).

- Philipp Zabel has developed a set of patches that allow adding to the subdev async notifier waiting list using a chaining method from the async registered callbacks (v4l2_of_subdev_registered() and the prep patches for that). For now, I've removed the use of v4l2_of_subdev_registered() for the vidmux driver's registered callback. This doesn't affect the functionality of this driver, but allows for it to be merged now, before adding the chaining support.

Quoted 3 lines
---
 .../bindings/media/video-multiplexer.txt           |  59 +++

Please make this a separate commit.

Quoted 72 lines
 drivers/media/platform/Kconfig                     |   8 +
 drivers/media/platform/Makefile                    |   2 +
 drivers/media/platform/video-multiplexer.c         | 474 +++++++++++++++++++++
 4 files changed, 543 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/video-multiplexer.txt
 create mode 100644 drivers/media/platform/video-multiplexer.c
Documentation/devicetree/bindings/media/video-multiplexer.txt new file +59 -0
new file mode 100644
index 0000000..9d133d9
@@ -0,0 +1,59 @@
+Video Multiplexer
+=================
+
+Video multiplexers allow to select between multiple input ports. Video received
+on the active input port is passed through to the output port. Muxes described
+by this binding may be controlled by a syscon register bitfield or by a GPIO.
+
+Required properties:
+- compatible : should be "video-multiplexer"
+- reg: should be register base of the register containing the control bitfield
+- bit-mask: bitmask of the control bitfield in the control register
+- bit-shift: bit offset of the control bitfield in the control register
+- gpios: alternatively to reg, bit-mask, and bit-shift, a single GPIO phandle
+  may be given to switch between two inputs
+- #address-cells: should be <1>
+- #size-cells: should be <0>
+- port@*: at least three port nodes containing endpoints connecting to the
+  source and sink devices according to of_graph bindings. The last port is
+  the output port, all others are inputs.
+
+Example:
+
+syscon {
+	compatible = "syscon", "simple-mfd";
+
+	mux {
+		compatible = "video-multiplexer";
+		/* Single bit (1 << 19) in syscon register 0x04: */
+		reg = <0x04>;
+		bit-mask = <1>;
+		bit-shift = <19>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		port at 0 {
+			reg = <0>;
+
+			mux_in0: endpoint {
+				remote-endpoint = <&video_source0_out>;
+			};
+		};
+
+		port at 1 {
+			reg = <1>;
+
+			mux_in1: endpoint {
+				remote-endpoint = <&video_source1_out>;
+			};
+		};
+
+		port at 2 {
+			reg = <2>;
+
+			mux_out: endpoint {
+				remote-endpoint = <&capture_interface_in>;
+			};
+		};
+	};
+};
maintainer
#162 lore raw

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

In reply to Steve Longerbeam
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
#5 lore raw

Re: [PATCH v4 01/36] [media] dt-bindings: Add bindings for i.MX media driver

In reply to Rob Herring

Hi Rob,

Quoted 38 lines · Rob Herring
Quoted 37 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
  Documentation/devicetree/bindings/media/imx.txt | 66 +++++++++++++++++++++++++
  1 file changed, 66 insertions(+)

create mode 100644 Documentation/devicetree/bindings/media/imx.txt

Documentation/devicetree/bindings/media/imx.txt new file +23 -0
new file mode 100644
index 0000000..fd5af50
@@ -0,0 +1,66 @@
+Freescale i.MX Media Video Device
+=================================
+
+Video Media Controller node
+---------------------------
+
+This is the media controller node for video capture support. It is a
+virtual device that lists the camera serial interface nodes that the
+media device will control.
+
+Required properties:
+- compatible : "fsl,imx-capture-subsystem";
+- ports      : Should contain a list of phandles pointing to camera
+		sensor interface ports of IPU devices
+
+example:
+
+capture-subsystem {
+	compatible = "fsl,capture-subsystem";
+	ports = <&ipu1_csi0>, <&ipu1_csi1>;
+};
+
+fim child node
Quoted 8 lines

Documentation/devicetree/bindings/media/imx.txt line 30

Quoted 7 lines
Documentation/devicetree/bindings/media/imx.txt new file +7 -0
+--------------
+
+This is an optional child node of the ipu_csi port nodes. If present and
+available, it enables the Frame Interval Monitor. Its properties can be
+used to modify the method in which the FIM measures frame intervals.
+Refer to Documentation/media/v4l-drivers/imx.rst for more info on the
+Frame Interval Monitor.

This should have a compatible string.

I don't think so. The fim child node does not represent a device. The CSI supports monitoring frame intervals (reporting via a v4l2 event when a measured frame interval falls outside the nominal interval by some tolerance value). The fim child node is only to group properties for the FIM under a common child node.

Quoted 25 lines
Quoted 25 lines
Documentation/devicetree/bindings/media/imx.txt new file +25 -0
+
+Optional properties:
+- fsl,input-capture-channel: an input capture channel and channel flags,
+			     specified as <chan flags>. The channel number
+			     must be 0 or 1. The flags can be
+			     IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, or
+			     IRQ_TYPE_EDGE_BOTH, and specify which input
+			     capture signal edge will trigger the input
+			     capture event. If an input capture channel is
+			     specified, the FIM will use this method to
+			     measure frame intervals instead of via the EOF
+			     interrupt. The input capture method is much
+			     preferred over EOF as it is not subject to
+			     interrupt latency errors. However it requires
+			     routing the VSYNC or FIELD output signals of
+			     the camera sensor to one of the i.MX input
+			     capture pads (SD1_DAT0, SD1_DAT1), which also
+			     gives up support for SD1.
+
+
+mipi_csi2 node
+--------------
+
+This is the device node for the MIPI CSI-2 Receiver, required for MIPI
+CSI-2 sensors.
Quoted 8 lines

Documentation/devicetree/bindings/media/imx.txt line 62

Quoted 7 lines
Documentation/devicetree/bindings/media/imx.txt new file +7 -0
+
+Required properties:
+- compatible	: "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2";
+- reg           : physical base address and length of the register set;
+- clocks	: the MIPI CSI-2 receiver requires three clocks: hsi_tx
+                  (the DPHY clock), video_27m, and eim_podf;
+- clock-names	: must contain "dphy", "cfg", "pix";

Don't you need ports to describe the sensor and IPU connections?

Done.

Steve

author maintainer
#126 lore raw

Re: [PATCH v4 15/36] platform: add video-multiplexer subdevice driver

In reply to Rob Herring
Quoted 35 lines · Rob Herring
Quoted 34 lines · Steve Longerbeam

From: Philipp Zabel <[email protected]>

This driver can handle SoC internal and external video bus multiplexers, controlled either by register bit fields or by a GPIO. The subdevice passes through frame interval and mbus configuration of the active input to the output side.

--

- fixed a cut&paste error in vidsw_remove(): v4l2_async_register_subdev() should be unregister.

- added media_entity_cleanup() and v4l2_device_unregister_subdev() to vidsw_remove().

- added missing MODULE_DEVICE_TABLE().

- there was a line left over from a previous iteration that negated the new way of determining the pad count just before it which has been removed (num_pads = of_get_child_count(np)).

- Philipp Zabel has developed a set of patches that allow adding to the subdev async notifier waiting list using a chaining method from the async registered callbacks (v4l2_of_subdev_registered() and the prep patches for that). For now, I've removed the use of v4l2_of_subdev_registered() for the vidmux driver's registered callback. This doesn't affect the functionality of this driver, but allows for it to be merged now, before adding the chaining support.

Quoted 4 lines
Quoted 3 lines
---
  .../bindings/media/video-multiplexer.txt           |  59 +++

Please make this a separate commit.

Done.

Steve

author maintainer
#163 lore raw

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

In reply to Rob Herring
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

#22 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Steve Longerbeam

Hi Steve,

Quoted 16 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---
 Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
 Documentation/media/videodev2.h.rst.exceptions  | 1 +
 include/uapi/linux/videodev2.h                  | 1 +
 3 files changed, 7 insertions(+)
Documentation/media/uapi/v4l/vidioc-dqevent.rst +0 -0
index 8d663a7..dd77d9b 100644

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 8 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

Quoted 27 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +0 -0
     * - ``V4L2_EVENT_PRIVATE_START``
       - 0x08000000
       - Base event number for driver-private events.
Documentation/media/videodev2.h.rst.exceptions +1 -0
index e11a0d0..5b0f767 100644
@@ -459,6 +459,7 @@ replace define V4L2_EVENT_CTRL event-type
 replace define V4L2_EVENT_FRAME_SYNC event-type
 replace define V4L2_EVENT_SOURCE_CHANGE event-type
 replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_FRAME_TIMEOUT event-type
 replace define V4L2_EVENT_PRIVATE_START event-type
 
 replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
include/uapi/linux/videodev2.h +1 -0
index 46e8a2e3..e174c45 100644
@@ -2132,6 +2132,7 @@ struct v4l2_streamparm {
 #define V4L2_EVENT_FRAME_SYNC			4
 #define V4L2_EVENT_SOURCE_CHANGE		5
 #define V4L2_EVENT_MOTION_DET			6
+#define V4L2_EVENT_FRAME_TIMEOUT		7
 #define V4L2_EVENT_PRIVATE_START		0x08000000
 
 /* Payload for V4L2_EVENT_VSYNC */
Signature · 4 lines
Regards,

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

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Steve Longerbeam

Hi Steve,

Quoted 22 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 5 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

- This implementation is only workable as long as you do not modify the pipeline. Once you disable a link along the pipeline, a device where the control was inherited from may no longer be a part of the pipeline. Depending on the hardware, it could be a part of another pipeline, in which case it certainly must not be accessible through an unrelated video node. As the function is added to the framework, I would expect it to handle such a case correctly.

- I assume it is the responsibility of the caller of this function to ensure the device in question will not be powered off whilst the video node is used as another user space interface to such a sub-device. If the driver uses the generic PM functions in the same file, this works, but it still has to be documented.

Quoted 91 lines
drivers/media/v4l2-core/v4l2-mc.c +45 -0
+{
+	struct media_device *mdev = start_entity->graph_obj.mdev;
+	struct media_entity *entity;
+	struct media_graph graph;
+	struct v4l2_subdev *sd;
+	int ret;
+
+	ret = media_graph_walk_init(&graph, mdev);
+	if (ret)
+		return ret;
+
+	media_graph_walk_start(&graph, start_entity);
+
+	while ((entity = media_graph_walk_next(&graph))) {
+		if (!is_media_entity_v4l2_subdev(entity))
+			continue;
+
+		sd = media_entity_to_v4l2_subdev(entity);
+
+		ret = v4l2_ctrl_add_handler(vfd->ctrl_handler,
+					    sd->ctrl_handler,
+					    NULL);
+		if (ret)
+			break;
+	}
+
+	media_graph_walk_cleanup(&graph);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(__v4l2_pipeline_inherit_controls);
+
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				   struct media_entity *start_entity)
+{
+	struct media_device *mdev = start_entity->graph_obj.mdev;
+	int ret;
+
+	mutex_lock(&mdev->graph_mutex);
+	ret = __v4l2_pipeline_inherit_controls(vfd, start_entity);
+	mutex_unlock(&mdev->graph_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_pipeline_inherit_controls);
+
 /* -----------------------------------------------------------------------------
  * Pipeline power management
  *
include/media/v4l2-mc.h +25 -0
index 2634d9d..9848e77 100644
@@ -171,6 +171,17 @@ void v4l_disable_media_source(struct video_device *vdev);
  */
 int v4l_vb2q_enable_media_source(struct vb2_queue *q);
 
+/**
+ * v4l2_pipeline_inherit_controls - Add the v4l2 controls from all
+ *				    subdev entities in a pipeline to
+ *				    the given video device.
+ * @vfd: the video device
+ * @start_entity: Starting entity
+ */
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity);
+int v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				   struct media_entity *start_entity);
 
 /**
  * v4l2_pipeline_pm_use - Update the use count of an entity
@@ -231,6 +242,20 @@ static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 	return 0;
 }
 
+static inline int __v4l2_pipeline_inherit_controls(
+	struct video_device *vfd,
+	struct media_entity *start_entity)
+{
+	return 0;
+}
+
+static inline int v4l2_pipeline_inherit_controls(
+	struct video_device *vfd,
+	struct media_entity *start_entity)
+{
+	return 0;
+}
+
 static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
 {
 	return 0;
Signature · 4 lines
Kind regards,

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

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Sakari Ailus
Quoted 14 lines · Sakari Ailus

Hi Steve,

Quoted 11 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---
 Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
 Documentation/media/videodev2.h.rst.exceptions  | 1 +
 include/uapi/linux/videodev2.h                  | 1 +
 3 files changed, 7 insertions(+)
Quoted 16 lines

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 13 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

Steve

author maintainer
#35 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Sakari Ailus
Quoted 28 lines · Sakari Ailus

Hi Steve,

Quoted 25 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
Quoted 7 lines

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 2 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

I don't really understand what you are trying to say. That's exactly what this function is doing, accessing every subdevice in a pipeline directly, in one convenient function call.

Quoted 4 lines

- This implementation is only workable as long as you do not modify the pipeline. Once you disable a link along the pipeline, a device where the control was inherited from may no longer be a part of the pipeline.

That's correct. It's up to the media driver to clear the video device's inherited controls whenever the pipeline is modified, and then call this function again if need be.

In imx-media driver, the function is called in link_setup when the link from a source pad that is attached to a capture video node is enabled. This is the last link that must be made to define the pipeline, so it is at this time that a complete list of subdevice controls can be gathered by walking the pipeline.

Quoted 4 lines

Depending on the hardware, it could be a part of another pipeline, in which case it certainly must not be accessible through an unrelated video node. As the function is added to the framework, I would expect it to handle such a case correctly.

The function will not inherit controls from a device that is not reachable from the given starting subdevice, so I don't understand you're point here.

Quoted 6 lines

- I assume it is the responsibility of the caller of this function to ensure the device in question will not be powered off whilst the video node is used as another user space interface to such a sub-device. If the driver uses the generic PM functions in the same file, this works, but it still has to be documented.

I guess I'm missing something. Why are you bringing up the subject of power? What does this function have to do with whether a subdevice is powered or not? The function makes use of v4l2_ctrl_add_handler(), and the latter has no requirements about whether the device's owning the control handlers are powered or not.

Steve

author maintainer
#36 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

Quoted 49 lines · Steve Longerbeam
Quoted 31 lines · Sakari Ailus

Hi Steve,

Quoted 28 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48
+++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct
 vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
Quoted 7 lines

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct · line 244

Quoted 2 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+                     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

I don't really understand what you are trying to say. That's exactly what this function is doing, accessing every subdevice in a pipeline directly, in one convenient function call.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

- This implementation is only workable as long as you do not modify the pipeline. Once you disable a link along the pipeline, a device where
the
control was inherited from may no longer be a part of the pipeline.

That's correct. It's up to the media driver to clear the video device's inherited controls whenever the pipeline is modified, and then call this function again if need be.

And here is where I need to eat my words :). I'm not actually clearing the inherited controls if an upstream link from the device node link is modified after the whole pipeline has been configured. If the user does that the controls can become invalid. Need to fix that by clearing device node controls in the link_notify callback.

Steve

Quoted 7 lines

In imx-media driver, the function is called in link_setup when the link from a source pad that is attached to a capture video node is enabled. This is the last link that must be made to define the pipeline, so it is at this time that a complete list of subdevice controls can be gathered by walking the pipeline.

author maintainer
#37 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Steve Longerbeam
Quoted 39 lines · Steve Longerbeam
Quoted 36 lines · Sakari Ailus

Hi Steve,

Quoted 24 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48
+++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct · line 244

Quoted 6 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct
 vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+                     struct media_entity *start_entity)

I have a few concerns / questions:

Quoted 6 lines
Quoted 2 lines

- What's the purpose of this patch? Why not to access the sub-device node directly?

I don't really understand what you are trying to say.<snip>

Actually I think I understand what you mean now. Yes, the user can always access a subdev's control directly from its /dev/v4l-subdevXX. I'm only providing this feature as a convenience to the user, so that all controls in a pipeline can be accessed from one place, i.e. the main capture device node.

Steve

#24 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Steve Longerbeam
Quoted 34 lines · Steve Longerbeam
Quoted 14 lines · Sakari Ailus

Hi Steve,

Quoted 11 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---

Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
Documentation/media/videodev2.h.rst.exceptions  | 1 +
include/uapi/linux/videodev2.h                  | 1 +
3 files changed, 7 insertions(+)
Quoted 16 lines

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 13 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

Quoted 2 lines

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

The frame rate is not necessarily constant during streaming. It may well change as a result of lighting conditions. I wouldn't add an event for this:
this is unreliable and 30 times the frame period is an arbitrary value anyway. No other drivers do this either.

The user space is generally in control of the frame period (or on some devices it could be the sensor, too, but *not* the CSI-2 receiver driver), so detecting the condition of not receiving any frames is more reliably done in the user space --- if needed.

Signature · 4 lines
Regards,

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

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Steve Longerbeam

Hi Steve,

Quoted 46 lines · Steve Longerbeam
Quoted 43 lines · Steve Longerbeam
Quoted 38 lines · Sakari Ailus

Hi Steve,

Quoted 24 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
drivers/media/v4l2-core/v4l2-mc.c | 48
+++++++++++++++++++++++++++++++++++++++
include/media/v4l2-mc.h | 25 ++++++++++++++++++++

2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct · line 244

Quoted 6 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct
 vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+                     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

Quoted 8 lines
Quoted 2 lines

I don't really understand what you are trying to say.<snip>

Actually I think I understand what you mean now. Yes, the user can always access a subdev's control directly from its /dev/v4l-subdevXX. I'm only providing this feature as a convenience to the user, so that all controls in a pipeline can be accessed from one place, i.e. the main capture device node.

No other MC based V4L2 driver does this. You'd be creating device specific behaviour that differs from what the rest of the drivers do. The purpose of MC is to provide the user with knowledge of what devices are there, and the V4L2 sub-devices interface is used to access them in this case.

It does matter where a control is implemented, too. If the pipeline contains multiple sub-devices that implement the same control, only one of them may be accessed. The driver calling the function (or even less the function) would not know which one of them should be ignored.

If you need such functionality, it should be implemented in the user space instead.

Signature · 4 lines
Regards,

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

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Sakari Ailus
Quoted 35 lines · Sakari Ailus
Quoted 34 lines · Steve Longerbeam
Quoted 30 lines · Sakari Ailus

Hi Steve,

Quoted 16 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---

Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
Documentation/media/videodev2.h.rst.exceptions  | 1 +
include/uapi/linux/videodev2.h                  | 1 +
3 files changed, 7 insertions(+)
Documentation/media/uapi/v4l/vidioc-dqevent.rst +0 -0
index 8d663a7..dd77d9b 100644

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 8 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

Quoted 5 lines
Quoted 2 lines

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

The frame rate is not necessarily constant during streaming. It may well change as a result of lighting conditions.

I think you mean that would be a _temporary_ change in frame rate, but yes I agree the data rate can temporarily fluctuate. Although I doubt lighting conditions would cause a sensor to pause data transmission for a full 1 second.

Quoted 3 lines

I wouldn't add an event for this:
this is unreliable and 30 times the frame period is an arbitrary value anyway. No other drivers do this either.

If no other drivers do this I don't mind removing it. It is really meant to deal with the ADV718x CVBS decoder, which often simply stops sending data on the BT.656 bus if there is an interruption in the input analog signal. But I agree that user space could detect this timeout instead. Unless I hear from someone else that they would like to keep this feature I'll remove it in version 5.

Steve

Quoted 6 lines

The user space is generally in control of the frame period (or on some devices it could be the sensor, too, but *not* the CSI-2 receiver driver), so detecting the condition of not receiving any frames is more reliably done in the user space --- if needed.

author maintainer
#39 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Sakari Ailus
Quoted 58 lines · Sakari Ailus

Hi Steve,

Quoted 46 lines · Steve Longerbeam
Quoted 43 lines · Steve Longerbeam
Quoted 38 lines · Sakari Ailus

Hi Steve,

Quoted 24 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
drivers/media/v4l2-core/v4l2-mc.c | 48
+++++++++++++++++++++++++++++++++++++++
include/media/v4l2-mc.h | 25 ++++++++++++++++++++

2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct · line 244

Quoted 6 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct
 vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+                     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

Quoted 8 lines
Quoted 2 lines

I don't really understand what you are trying to say.<snip>

Actually I think I understand what you mean now. Yes, the user can always access a subdev's control directly from its /dev/v4l-subdevXX. I'm only providing this feature as a convenience to the user, so that all controls in a pipeline can be accessed from one place, i.e. the main capture device node.

Quoted 4 lines

No other MC based V4L2 driver does this. You'd be creating device specific behaviour that differs from what the rest of the drivers do. The purpose of MC is to provide the user with knowledge of what devices are there, and the V4L2 sub-devices interface is used to access them in this case.

Well, again, I don't mind removing this. As I said it is only a convenience (although quite a nice one in my opinion). I'd like to hear from others whether this is worth keeping though.

Quoted 5 lines

It does matter where a control is implemented, too. If the pipeline contains multiple sub-devices that implement the same control, only one of them may be accessed. The driver calling the function (or even less the function) would not know which one of them should be ignored.

Yes the pipeline should not have any duplicate controls. On imx-media no pipelines that can be configured have duplicate controls.

Steve

Quoted 4 lines

If you need such functionality, it should be implemented in the user space instead.

#40 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Sakari Ailus
Quoted 28 lines · Sakari Ailus

Hi Steve,

Quoted 25 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
Quoted 7 lines

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 2 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

What tools are in existance _today_ to provide access to these controls via the sub-device nodes?

v4l-tools doesn't last time I looked - in fact, the only tool in v4l-tools which is capable of accessing the subdevices is media-ctl, and that only provides functionality for configuring the pipeline.

So, pointing people at vapourware userspace is really quite rediculous.

The established way to control video capture is through the main video capture device, not through the sub-devices. Yes, the controls are exposed through sub-devices too, but that does not mean that is the correct way to access them.

The v4l2 documentation (Documentation/media/kapi/v4l2-controls.rst) even disagrees with your statements. That talks about control inheritence from sub-devices to the main video device, and the core v4l2 code provides _automatic_ support for this - see v4l2_device_register_subdev():

        /* This just returns 0 if either of the two args is NULL */
        err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);

which merges the subdev's controls into the main device's control handler.

So, (a) I don't think Steve needs to add this code, and (b) I think your statements about not inheriting controls goes against the documentation and API compatibility with _existing_ applications, and ultimately hurts the user experience, since there's nothing existing today to support what you're suggesting in userspace.

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
#41 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

Quoted 37 lines · Russell King - ARM Linux
Quoted 28 lines · Sakari Ailus

Hi Steve,

Quoted 25 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
Quoted 7 lines

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 2 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

- What's the purpose of this patch? Why not to access the sub-device node directly?

Quoted 8 lines

What tools are in existance _today_ to provide access to these controls via the sub-device nodes?

v4l-tools doesn't last time I looked - in fact, the only tool in v4l-tools which is capable of accessing the subdevices is media-ctl, and that only provides functionality for configuring the pipeline.

So, pointing people at vapourware userspace is really quite rediculous.

Hi Russell,

Yes, that's a big reason why I added this capability. The v4l2-ctl tool won't accept subdev nodes, although Philipp Zabel has a quick hack to get around this (ignore return code from VIDIOC_QUERYCAP).

Quoted 12 lines

The established way to control video capture is through the main video capture device, not through the sub-devices. Yes, the controls are exposed through sub-devices too, but that does not mean that is the correct way to access them.

The v4l2 documentation (Documentation/media/kapi/v4l2-controls.rst) even disagrees with your statements. That talks about control inheritence from sub-devices to the main video device, and the core v4l2 code provides _automatic_ support for this - see v4l2_device_register_subdev():

Quoted 5 lines
        /* This just returns 0 if either of the two args is NULL */
        err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);

which merges the subdev's controls into the main device's control handler.

Actually v4l2_dev->ctrl_handler is not of much use to me. This will compose a list of controls from all registered subdevs, i.e. _all possible controls_.

What v4l2_pipeline_inherit_controls() does is compose a list of controls that are reachable and available in the currently configured pipeline.

Steve

Quoted 7 lines

So, (a) I don't think Steve needs to add this code, and (b) I think your statements about not inheriting controls goes against the documentation and API compatibility with _existing_ applications, and ultimately hurts the user experience, since there's nothing existing today to support what you're suggesting in userspace.

#26 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Steve Longerbeam

Hi Steve,

Quoted 41 lines · Steve Longerbeam
Quoted 38 lines · Sakari Ailus
Quoted 36 lines · Steve Longerbeam
Quoted 14 lines · Sakari Ailus

Hi Steve,

Quoted 11 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---

Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
Documentation/media/videodev2.h.rst.exceptions  | 1 +
include/uapi/linux/videodev2.h                  | 1 +
3 files changed, 7 insertions(+)
Quoted 16 lines

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 13 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

Quoted 7 lines
Quoted 2 lines

The frame rate is not necessarily constant during streaming. It may well change as a result of lighting conditions.

I think you mean that would be a _temporary_ change in frame rate, but yes I agree the data rate can temporarily fluctuate. Although I doubt lighting conditions would cause a sensor to pause data transmission for a full 1 second.

Likely not, at least not in typical conditions. The exposure time is still quite specific to applications: it could be minutes if you take photos e.g. of the night sky.

What I'm saying here is that any static value is likely not both reasonable and workable in all potential situations all the time. Still there are cases (as yours below) that may happen in relatively common cases on some hardware (more common than taking long exposure photos of the night sky with the said hardware :)).

Quoted 6 lines
Quoted 5 lines

I wouldn't add an event for this:
this is unreliable and 30 times the frame period is an arbitrary value anyway. No other drivers do this either.

Quoted 6 lines

If no other drivers do this I don't mind removing it. It is really meant to deal with the ADV718x CVBS decoder, which often simply stops sending data on the BT.656 bus if there is an interruption in the input analog signal. But I agree that user space could detect this timeout instead. Unless I hear from someone else that they would like to keep this feature I'll remove it in version 5.

That's a bit of a special situation --- still there are alike conditions on existing hardware. You should return the buffers to the user with the ERROR flag set --- or return -EIO from VIDIOC_DQBUF, if the condition will persist:

<URL:https://www.linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-qbuf.html>

Do you already obtain the frame rate from the image source (e.g. tuner, sensor, decoder) and multiply the frame time by some number in the current implementation? Not all sub-device drivers may implement g_frame_interval() so I'd disable the timeout in that case.

Signature · 4 lines
Kind regards,

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

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Russell King - ARM Linux

Hi Russell,

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

Hi Steve,

Quoted 22 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 5 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

Quoted 5 lines
Quoted 2 lines

- What's the purpose of this patch? Why not to access the sub-device node directly?

What tools are in existance _today_ to provide access to these controls via the sub-device nodes?

yavta, for instance:

<URL:http://git.ideasonboard.org/yavta.git>

VIDIOC_QUERYCAP isn't supported on sub-devices and v4l2-ctl appears to be checking for that. That check should be removed (with possible other implications taken into account).

Quoted 6 lines

v4l-tools doesn't last time I looked - in fact, the only tool in v4l-tools which is capable of accessing the subdevices is media-ctl, and that only provides functionality for configuring the pipeline.

So, pointing people at vapourware userspace is really quite rediculous.

Do bear in mind that there are other programs that can make use of these interfaces. It's not just the test programs, or a test program you attempted to use.

Quoted 5 lines

The established way to control video capture is through the main video capture device, not through the sub-devices. Yes, the controls are exposed through sub-devices too, but that does not mean that is the correct way to access them.

It is. That's the very purpose of the sub-devices: to provide access to the hardware independently of how the links are configured.

Quoted 7 lines

The v4l2 documentation (Documentation/media/kapi/v4l2-controls.rst) even disagrees with your statements. That talks about control inheritence from sub-devices to the main video device, and the core v4l2 code provides _automatic_ support for this - see v4l2_device_register_subdev():

Quoted 5 lines
        /* This just returns 0 if either of the two args is NULL */
        err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);

which merges the subdev's controls into the main device's control handler.

That's done on different kind of devices: those that provide plain V4L2 API to control the entire device. V4L2 sub-device interface is used *in kernel* as an interface to control sub-devices that do not need to be exposed to the user space.

Devices that have complex pipeline that do essentially require using the Media controller interface to configure them are out of that scope.

Signature · 4 lines
Regards,

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

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

In reply to Sakari Ailus
Quoted 56 lines · Sakari Ailus

Hi Steve,

Quoted 41 lines · Steve Longerbeam
Quoted 38 lines · Sakari Ailus
Quoted 36 lines · Steve Longerbeam
Quoted 14 lines · Sakari Ailus

Hi Steve,

Quoted 11 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---

Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
Documentation/media/videodev2.h.rst.exceptions  | 1 +
include/uapi/linux/videodev2.h                  | 1 +
3 files changed, 7 insertions(+)
Quoted 16 lines

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 13 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

Quoted 7 lines
Quoted 2 lines

The frame rate is not necessarily constant during streaming. It may well change as a result of lighting conditions.

I think you mean that would be a _temporary_ change in frame rate, but yes I agree the data rate can temporarily fluctuate. Although I doubt lighting conditions would cause a sensor to pause data transmission for a full 1 second.

Likely not, at least not in typical conditions. The exposure time is still quite specific to applications: it could be minutes if you take photos e.g. of the night sky.

Quoted 5 lines

What I'm saying here is that any static value is likely not both reasonable and workable in all potential situations all the time. Still there are cases (as yours below) that may happen in relatively common cases on some hardware (more common than taking long exposure photos of the night sky with the said hardware :)).

I doubt night photography will ever be a use-case for i.MX. The most common use-case for this driver will be used in automotive applications such as rear-view or 360 degree view cameras.

Quoted 14 lines
Quoted 7 lines
Quoted 6 lines

I wouldn't add an event for this:
this is unreliable and 30 times the frame period is an arbitrary value anyway. No other drivers do this either.

Quoted 6 lines

If no other drivers do this I don't mind removing it. It is really meant to deal with the ADV718x CVBS decoder, which often simply stops sending data on the BT.656 bus if there is an interruption in the input analog signal. But I agree that user space could detect this timeout instead. Unless I hear from someone else that they would like to keep this feature I'll remove it in version 5.

Quoted 4 lines

That's a bit of a special situation --- still there are alike conditions on existing hardware. You should return the buffers to the user with the ERROR flag set --- or return -EIO from VIDIOC_DQBUF, if the condition will persist:

On i.MX an EOF timeout is not recoverable without a stream restart, so I decided to call vb2_queue_error() when the timeout occurs (instead of sending an event). The user will then get -EIO when it attempts to queue or dequeue further buffers.

Quoted 6 lines

<URL:https://www.linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-qbuf.html>

Do you already obtain the frame rate from the image source (e.g. tuner, sensor, decoder) and multiply the frame time by some number in the current implementation?

No the timeout is a constant value, regardless of the source frame rate. Should the timeout be based on a constant time, or based on a constant # of frames? I really don't think it matters much, what matters is that it be long enough to be reasonably sure no data is forthcoming, for most use-cases.

Steve

Quoted 3 lines

Not all sub-device drivers may implement g_frame_interval() so I'd disable the timeout in that case.

#28 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

Quoted 65 lines · Steve Longerbeam
Quoted 56 lines · Sakari Ailus

Hi Steve,

Quoted 41 lines · Steve Longerbeam
Quoted 38 lines · Sakari Ailus
Quoted 36 lines · Steve Longerbeam
Quoted 14 lines · Sakari Ailus

Hi Steve,

Quoted 11 lines · Steve Longerbeam

Add a new FRAME_TIMEOUT event to signal that a video capture or output device has timed out waiting for reception or transmit completion of a video frame.

---

Documentation/media/uapi/v4l/vidioc-dqevent.rst | 5 +++++
Documentation/media/videodev2.h.rst.exceptions  | 1 +
include/uapi/linux/videodev2.h                  | 1 +
3 files changed, 7 insertions(+)
Quoted 16 lines

Documentation/media/uapi/v4l/vidioc-dqevent.rst call. · line 204

Quoted 13 lines
Documentation/media/uapi/v4l/vidioc-dqevent.rst +5 -0
index 8d663a7..dd77d9b 100644
@@ -197,6 +197,11 @@ call.
 	the regions changes. This event has a struct
 	:c:type:`v4l2_event_motion_det`
 	associated with it.
+    * - ``V4L2_EVENT_FRAME_TIMEOUT``
+      - 7
+      - This event is triggered when the video capture or output device
+	has timed out waiting for the reception or transmit completion of
+	a frame of video.

As you're adding a new interface, I suppose you have an implementation around. How do you determine what that timeout should be?

The imx-media driver sets the timeout to 1 second, or 30 frame periods at 30 fps.

Quoted 7 lines
Quoted 2 lines

The frame rate is not necessarily constant during streaming. It may well change as a result of lighting conditions.

I think you mean that would be a _temporary_ change in frame rate, but yes I agree the data rate can temporarily fluctuate. Although I doubt lighting conditions would cause a sensor to pause data transmission for a full 1 second.

Likely not, at least not in typical conditions. The exposure time is still quite specific to applications: it could be minutes if you take photos e.g. of the night sky.

Quoted 5 lines

What I'm saying here is that any static value is likely not both reasonable and workable in all potential situations all the time. Still there are cases (as yours below) that may happen in relatively common cases on some hardware (more common than taking long exposure photos of the night sky with the said hardware :)).

Quoted 3 lines

I doubt night photography will ever be a use-case for i.MX. The most common use-case for this driver will be used in automotive applications such as rear-view or 360 degree view cameras.

Ack.

Quoted 21 lines
Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

I wouldn't add an event for this:
this is unreliable and 30 times the frame period is an arbitrary value anyway. No other drivers do this either.

Quoted 6 lines

If no other drivers do this I don't mind removing it. It is really meant to deal with the ADV718x CVBS decoder, which often simply stops sending data on the BT.656 bus if there is an interruption in the input analog signal. But I agree that user space could detect this timeout instead. Unless I hear from someone else that they would like to keep this feature I'll remove it in version 5.

Quoted 4 lines

That's a bit of a special situation --- still there are alike conditions on existing hardware. You should return the buffers to the user with the ERROR flag set --- or return -EIO from VIDIOC_DQBUF, if the condition will persist:

Quoted 4 lines

On i.MX an EOF timeout is not recoverable without a stream restart, so I decided to call vb2_queue_error() when the timeout occurs (instead of sending an event). The user will then get -EIO when it attempts to queue or dequeue further buffers.

It believe that's the correct thing to do.

Quoted 9 lines
Quoted 8 lines

<URL:https://www.linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/vidioc-qbuf.html>

Do you already obtain the frame rate from the image source (e.g. tuner, sensor, decoder) and multiply the frame time by some number in the current implementation?

Quoted 5 lines

No the timeout is a constant value, regardless of the source frame rate. Should the timeout be based on a constant time, or based on a constant # of frames? I really don't think it matters much, what matters is that it be long enough to be reasonably sure no data is forthcoming, for most use-cases.

That should be fine. If there is a use case that requires something else, then the implementation can be changed: it's not visible to the user space anyway.

Signature · 4 lines
Kind regards,

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

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

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

That's a bit of a special situation --- still there are alike conditions on existing hardware. You should return the buffers to the user with the ERROR flag set --- or return -EIO from VIDIOC_DQBUF, if the condition will persist:

Quoted 4 lines

On i.MX an EOF timeout is not recoverable without a stream restart, so I decided to call vb2_queue_error() when the timeout occurs (instead of sending an event). The user will then get -EIO when it attempts to queue or dequeue further buffers.

I'm not sure that statement is entirely accurate. With the IMX219 camera, I _could_ (with previous iterations of the iMX capture code) stop it streaming, wait a while, and restart it, and everything continues to work.

Are you sure that the problem you have here is caused by the iMX6 rather than the ADV718x CVBS decoder (your initial description said it was the decoder.)

If it _is_ the decoder that's going wrong, that doesn't justify cripping the rest of the driver for one instance of broken hardware that _might_ be attached to it.

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
#30 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

Quoted 14 lines · Russell King - ARM Linux
Quoted 8 lines · Steve Longerbeam
Quoted 4 lines · Sakari Ailus

That's a bit of a special situation --- still there are alike conditions on existing hardware. You should return the buffers to the user with the ERROR flag set --- or return -EIO from VIDIOC_DQBUF, if the condition will persist:

Quoted 4 lines

On i.MX an EOF timeout is not recoverable without a stream restart, so I decided to call vb2_queue_error() when the timeout occurs (instead of sending an event). The user will then get -EIO when it attempts to queue or dequeue further buffers.

Quoted 4 lines

I'm not sure that statement is entirely accurate. With the IMX219 camera, I _could_ (with previous iterations of the iMX capture code) stop it streaming, wait a while, and restart it, and everything continues to work.

Hi Russell, did you see the "EOF timeout" kernel error message when you stopped the IMX219 from streaming? Only a "EOF timeout" message indicates the unrecoverable case.

Quoted 4 lines

Are you sure that the problem you have here is caused by the iMX6 rather than the ADV718x CVBS decoder (your initial description said it was the decoder.)

Actually yes I did say it was the adv718x, but in fact I doubt the adv718x has abruptly stopped data transmission on the bt.656 bus. I actually suspect the IPU, specifically the CSI. In our experience the CSI is rather sensitive to glitches and/or truncated frames on the bt.656 bus and can easily loose vertical sync, and/or lock-up.

Steve

Quoted 5 lines

If it _is_ the decoder that's going wrong, that doesn't justify cripping the rest of the driver for one instance of broken hardware that _might_ be attached to it.

#31 lore raw

Re: [PATCH v4 13/36] [media] v4l2: add a frame timeout event

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

I'm not sure that statement is entirely accurate. With the IMX219 camera, I _could_ (with previous iterations of the iMX capture code) stop it streaming, wait a while, and restart it, and everything continues to work.

Hi Russell, did you see the "EOF timeout" kernel error message when you stopped the IMX219 from streaming? Only a "EOF timeout" message indicates the unrecoverable case.

I really couldn't tell you anymore - I can't go back and test at all, because:

(a) your v4 patch set never worked for me
(b) I've now moved forward to v4.11-rc1, which conflicts with your v4 and older patch sets.

In any case, I'm in complete disagreement with many of the points that Sakari has been bringing up, and I'm finding the direction that things are progressing to be abhorrent.

I've discussed with Mauro about (eg) the application interface, and unsurprisingly to me, Mauro immediately said about control inheritence to the main v4l2 device, contradicting what Sakari has been saying. The subdev API is supposed to be there to allow for finer control, it's not a "one or the other" thing. The controls are still supposed to be exposed through the main v4l2 subdev device.

Since the v4l2 stuff is becoming abhorrent, and I've also come to realise that I'm going to have to write an entirely new userspace application to capture, debayer and encode efficiently, I'm finding that I've little motivation to take much of a further interest in iMX6 capture, or indeed continue my reverse engineering efforts of the IMX219 sensor.

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.
#43 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

In reply to Sakari Ailus
Quoted 43 lines · Sakari Ailus

Hi Russell,

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

Hi Steve,

Quoted 22 lines · Steve Longerbeam

v4l2_pipeline_inherit_controls() will add the v4l2 controls from all subdev entities in a pipeline to a given video device.

---
 drivers/media/v4l2-core/v4l2-mc.c | 48 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 25 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +1 -0
index 303980b..09d4d97 100644
@@ -22,6 +22,7 @@
 #include <linux/usb.h>
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <media/v4l2-ctrls.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-mc.h>
 #include <media/v4l2-subdev.h>

drivers/media/v4l2-core/v4l2-mc.c int v4l_vb2q_enable_media_source(struct vb2_queue *q) · line 243

Quoted 5 lines
drivers/media/v4l2-core/v4l2-mc.c +2 -0
@@ -238,6 +239,53 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 }
 EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
 
+int __v4l2_pipeline_inherit_controls(struct video_device *vfd,
+				     struct media_entity *start_entity)

I have a few concerns / questions:

Quoted 5 lines
Quoted 2 lines

- What's the purpose of this patch? Why not to access the sub-device node directly?

What tools are in existance _today_ to provide access to these controls via the sub-device nodes?

Quoted 7 lines

yavta, for instance:

<URL:http://git.ideasonboard.org/yavta.git>

VIDIOC_QUERYCAP isn't supported on sub-devices and v4l2-ctl appears to be checking for that. That check should be removed (with possible other implications taken into account).

No, the subdev API should get a similar QUERYCAP ioctl. There isn't a single ioctl that is guaranteed to be available for all subdev devices. I've made proposals for this in the past, and those have all been shot down.

Add that, and I'll add support for subdevs in v4l2-ctl.

Quoted 34 lines
Quoted 7 lines

v4l-tools doesn't last time I looked - in fact, the only tool in v4l-tools which is capable of accessing the subdevices is media-ctl, and that only provides functionality for configuring the pipeline.

So, pointing people at vapourware userspace is really quite rediculous.

Do bear in mind that there are other programs that can make use of these interfaces. It's not just the test programs, or a test program you attempted to use.

Quoted 5 lines

The established way to control video capture is through the main video capture device, not through the sub-devices. Yes, the controls are exposed through sub-devices too, but that does not mean that is the correct way to access them.

It is. That's the very purpose of the sub-devices: to provide access to the hardware independently of how the links are configured.

Quoted 7 lines

The v4l2 documentation (Documentation/media/kapi/v4l2-controls.rst) even disagrees with your statements. That talks about control inheritence from sub-devices to the main video device, and the core v4l2 code provides _automatic_ support for this - see v4l2_device_register_subdev():

Quoted 5 lines
        /* This just returns 0 if either of the two args is NULL */
        err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);

which merges the subdev's controls into the main device's control handler.

Quoted 8 lines

That's done on different kind of devices: those that provide plain V4L2 API to control the entire device. V4L2 sub-device interface is used *in kernel* as an interface to control sub-devices that do not need to be exposed to the user space.

Devices that have complex pipeline that do essentially require using the Media controller interface to configure them are out of that scope.

Way too much of how the MC devices should be used is in the minds of developers. There is a major lack for good detailed documentation, utilities, compliance test (really needed!) and libv4l plugins.

Russell's comments are spot on and it is a thorn in my side that this still hasn't been addressed.

I want to see if I can get time from my boss to work on this this summer, but there is no guarantee.

The main reason this hasn't been a much bigger problem is that most end-users make custom applications for this hardware. It makes sense, if you need full control over everything you make the application yourself, that's the whole point.

But there was always meant to be a layer (libv4l plugin) that could be used to setup a 'default scenario' that existing applications could use, but that was never enforced, sadly.

Anyway, regarding this specific patch and for this MC-aware driver: no, you shouldn't inherit controls from subdevs. It defeats the purpose.

Regards,

Hans

#44 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

Quoted 3 lines · Hans Verkuil

But there was always meant to be a layer (libv4l plugin) that could be used to setup a 'default scenario' that existing applications could use, but that was never enforced, sadly.

However, there's other painful issues lurking in userspace, particularly to do with the v4l libraries.

The idea that the v4l libraries should intercept the format negotiation between the application and kernel is a particularly painful one - the default gstreamer build detects the v4l libraries, and links against it. That much is fine.

However, the problem comes when you're trying to use bayer formats. The v4l libraries "helpfully" (or rather unhelpfully) intercept the format negotiation, and decide that they'll invoke v4lconvert to convert the bayer to RGB for you, whether you want them to do that or not.

v4lconvert may not be the most efficient way to convert, or even what is desired (eg, you may want to receive the raw bayer image.) However, since the v4l libraries/v4lconvert gives you no option but to have its conversion forced into the pipeline, other options (such as using the gstreamer neon accelerated de-bayer plugin) isn't an option without rebuilding gstreamer _without_ linking against the v4l libraries.

At that point, saying "this should be done in a libv4l plugin" becomes a total nonsense, because if you need to avoid libv4l due to its stupidities, you don't get the benefit of subdevs, and it yet again _forces_ people down the route of custom applications.

So, I really don't agree with pushing this into a userspace library plugin - at least not with the current state there.

_At least_ the debayering in the v4l libraries needs to become optional.

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.
#45 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

Quoted 30 lines · Russell King - ARM Linux
Quoted 3 lines · Hans Verkuil

But there was always meant to be a layer (libv4l plugin) that could be used to setup a 'default scenario' that existing applications could use, but that was never enforced, sadly.

However, there's other painful issues lurking in userspace, particularly to do with the v4l libraries.

The idea that the v4l libraries should intercept the format negotiation between the application and kernel is a particularly painful one - the default gstreamer build detects the v4l libraries, and links against it. That much is fine.

However, the problem comes when you're trying to use bayer formats. The v4l libraries "helpfully" (or rather unhelpfully) intercept the format negotiation, and decide that they'll invoke v4lconvert to convert the bayer to RGB for you, whether you want them to do that or not.

v4lconvert may not be the most efficient way to convert, or even what is desired (eg, you may want to receive the raw bayer image.) However, since the v4l libraries/v4lconvert gives you no option but to have its conversion forced into the pipeline, other options (such as using the gstreamer neon accelerated de-bayer plugin) isn't an option without rebuilding gstreamer _without_ linking against the v4l libraries.

At that point, saying "this should be done in a libv4l plugin" becomes a total nonsense, because if you need to avoid libv4l due to its stupidities, you don't get the benefit of subdevs, and it yet again _forces_ people down the route of custom applications.

Quoted 5 lines

So, I really don't agree with pushing this into a userspace library plugin - at least not with the current state there.

_At least_ the debayering in the v4l libraries needs to become optional.

I *thought* that when a plugin is used the format conversion code was disabled. But I'm not sure.

The whole problem is that we still don't have a decent plugin for an MC driver. There is one for the exynos4 floating around, but it's still not accepted.

Companies write the driver, but the plugin isn't really needed since their customers won't use it anyway since they make their own embedded driver.

And nobody of the media core developers has the time to work on the docs, utilities and libraries you need to make this all work cleanly and reliably.

As mentioned, I will attempt to try and get some time to work on this later this year. Fingers crossed.

We also have a virtual MC driver floating around. I've pinged the author if she can fix the last round of review comments and post a new version. Having a virtual driver makes life much easier when writing docs, utilities, etc. since you don't need real hardware which can be hard to obtain and run.

Again, I agree completely with you. But we don't have many core developers who can do something like this, and it's even harder for them to find the time.

Solutions on a postcard...

BTW, Steve: this has nothing to do with your work, it's a problem in our subsystem.

Regards,

Hans

#46 lore raw

Re: [PATCH v4 14/36] [media] v4l2-mc: add a function to inherit controls from a pipeline

Quoted 2 lines · Hans Verkuil

And nobody of the media core developers has the time to work on the docs, utilities and libraries you need to make this all work cleanly and reliably.

Well, talking about docs, and in connection to control inheritence, this is already documented in at least three separate places:

Documentation/media/uapi/v4l/dev-subdev.rst:

Controls
========
...
Depending on the driver, those controls might also be exposed through one (or several) V4L2 device nodes.

Documentation/media/kapi/v4l2-subdev.rst:

``VIDIOC_QUERYCTRL``,
``VIDIOC_QUERYMENU``,
``VIDIOC_G_CTRL``,
``VIDIOC_S_CTRL``,
``VIDIOC_G_EXT_CTRLS``,
``VIDIOC_S_EXT_CTRLS`` and
``VIDIOC_TRY_EXT_CTRLS``:

The controls ioctls are identical to the ones defined in V4L2. They behave identically, with the only exception that they deal only with controls implemented in the sub-device. Depending on the driver, those controls can be also be accessed through one (or several) V4L2 device nodes.

Then there's Documentation/media/kapi/v4l2-controls.rst, which gives a step by step approach to the main video device inheriting controls from its subdevices, and it says:

Inheriting Controls
-------------------

When a sub-device is registered with a V4L2 driver by calling v4l2_device_register_subdev() and the ctrl_handler fields of both v4l2_subdev and v4l2_device are set, then the controls of the subdev will become automatically available in the V4L2 driver as well. If the subdev driver contains controls that already exist in the V4L2 driver, then those will be skipped (so a V4L2 driver can always override a subdev control).

What happens here is that v4l2_device_register_subdev() calls v4l2_ctrl_add_handler() adding the controls of the subdev to the controls of v4l2_device.

So, either the docs are wrong, or the advice being mentioned in emails about subdev control inheritence is misleading. Whatever, the two are currently inconsistent.

As I've already mentioned, from talking about this with Mauro, it seems Mauro is in agreement with permitting the control inheritence... I wish Mauro would comment for himself, as I can't quote our private discussion on the subject.

Right now, my view is that v4l2 is currently being screwed up by people with different opinions - there is no unified concensus on how any of this stuff is supposed to work, everyone is pulling in different directions. That needs solving _really_ quickly, so I suggest that v4l2 people urgently talk to each other and thrash out some of the issues that Steve's patch set has brought up, and settle on a way forward, rather than what is seemingly happening today - which is everyone working in isolation of everyone else with their own bias on how things should be done.

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.