Skip to contentSkip to conversation

i.MX Media Driver

PATCH Superseded Steve Longerbeam 14 participants 105 messages Mar 28, 2017 – May 9, 2017

Subsystems (10)

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Steve Longerbeam

author maintainer
#0 lore raw

v6 cover i.MX Media Driver

In version 6:

- moved FIM error event back to a i.MX private event. I would like to leave this as a (private) event rather than reporting a vb2 queue error, for now. If and when the i.MX6 timer input capture patch is accepted later, then this event can become a queue error.

- removed new-frame-before-end-of-frame (NFB4EOF) event. Instead when this IPU DMA channel error occurs, the next captured frame is marked with the vb2 error flag.

- updates to Documentation/media/v4l-drivers/imx.rst.

- ov5640: propagate return codes from the register read/write primitives in various places.

- ov5640: removed the [gs]_parm ops.

- ov5640: avoid possible divide-by-0's.

- only the CSI subdevice implements [gs]_frame_interval now (or needs to). Those ops have been removed from the subdevices that have no control over frame rate.

- removed the patch that adds v4l2_subdev_link_validate_frame_interval().

- properly propagate the TRY formats from sink to source pads within the subdevices (spotted by Philipp Zabel <[email protected]>).

- added enum_frame_size op to imx-ic-prpencvf and CSI subdevices.

- added enum_frame_intervals op to CSI subdevice (patch from Russell King <[email protected]>).

- added V4L2 interface ops enum_framesizes and enum_frameintervals, which calls the corresponding subdev op at the connected source subdev (patch from Russell King <[email protected]>).

- added missing Bayer support to CSI subdevice (patch from Russell King <[email protected]>).

- switched to v4l2_pipeline_pm_use() and v4l2_pipeline_link_notify() for the pipeline power management.

- the power-on order has changed due to above: the sensor now is powered on _before_ the MIPI CSI-2 receiver, which means MIPI CSI-2 receiver startup sequence steps 3, 4, and 5 can be moved up to csi2_s_power() from csi2_s_stream(). And that means step 7 (wait for clock lane) now has a place to be called in csi2_s_stream().

- changed the bus_info string for the capture device interfaces to "platform:[src_sd->name]" instead of using the capture device name, so that the bus_info strings are unique between the capture devices. I was hoping this would provide unique device node symlink names under /dev/v4l/by-path/, but they are still named "platform-capture-subsystem-video-indexNN".

- fixed cropping and /2 downsizing in the CSI subdevice. These should be specified using the crop and compose APIs at the sink pad, not the source pad (patch from Philipp Zabel <[email protected]>).

- added a check at CSI subdevice stream on. If the connected sensor reports faulty frames at power on via g_skip_frames op, the CSI should avoid capturing those frames before enabling the CSI.

- moved imx.h UAPI header to include/linux/imx-media.h while imx-media driver is still under staging.

Philipp Zabel (8):
[media] dt-bindings: Add bindings for video-multiplexer device
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
media: imx: csi: add sink selection rectangles

Russell King (5):
media: imx: add support for bayer formats
media: imx: csi: add support for bayer formats
media: imx: csi/fim: add support for frame intervals
media: imx-csi: add frame size/interval enumeration
media: imx-media-capture: add frame sizes/interval enumeration

Steve Longerbeam (26):
[media] dt-bindings: Add bindings for i.MX media driver [media] dt/bindings: Add bindings for OV5640
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-mc: add a function to inherit controls from a pipeline [media] add Omnivision OV5640 sensor driver
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
ARM: imx_v6_v7_defconfig: Enable staging video4linux drivers
media: imx: csi: add __csi_get_fmt
media: imx: redo pixel format enumeration and negotiation
media: imx: csi: Avoid faulty sensor frames at stream start
media: imx: propagate sink pad formats to source pads
media: imx-ic-prpencvf: add frame size enumeration

 .../devicetree/bindings/media/i2c/ov5640.txt       |   45 +
 Documentation/devicetree/bindings/media/imx.txt    |   74 +
 .../bindings/media/video-multiplexer.txt           |   59 +
 Documentation/media/uapi/mediactl/media-types.rst  |   22 +
 Documentation/media/v4l-drivers/imx.rst            |  590 ++++++
 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               |   11 +
 drivers/media/i2c/Kconfig                          |    7 +
 drivers/media/i2c/Makefile                         |    1 +
 drivers/media/i2c/ov5640.c                         | 2219 ++++++++++++++++++++
 drivers/media/platform/Kconfig                     |    8 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/video-multiplexer.c         |  451 ++++
 drivers/media/v4l2-core/v4l2-mc.c                  |   50 +
 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                     |   17 +
 drivers/staging/media/imx/imx-ic-common.c          |  113 +
 drivers/staging/media/imx/imx-ic-prp.c             |  452 ++++
 drivers/staging/media/imx/imx-ic-prpencvf.c        | 1232 +++++++++++
 drivers/staging/media/imx/imx-ic.h                 |   38 +
 drivers/staging/media/imx/imx-media-capture.c      |  776 +++++++
 drivers/staging/media/imx/imx-media-csi.c          | 1779 ++++++++++++++++
 drivers/staging/media/imx/imx-media-dev.c          |  503 +++++
 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        |  947 +++++++++
 drivers/staging/media/imx/imx-media-vdic.c         |  910 ++++++++
 drivers/staging/media/imx/imx-media.h              |  305 +++
 drivers/staging/media/imx/imx6-mipi-csi2.c         |  673 ++++++
 include/linux/imx-media.h                          |   27 +
 include/media/imx.h                                |   15 +
 include/media/v4l2-mc.h                            |   31 +
 include/uapi/linux/media.h                         |    6 +
 include/uapi/linux/v4l2-controls.h                 |    4 +
 47 files changed, 13207 insertions(+), 27 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/linux/imx-media.h
 create mode 100644 include/media/imx.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v6 1/39 dt-bindings: Add bindings for video-multiplexer device

From: Philipp Zabel <[email protected]>

Add bindings documentation for the video multiplexer device.

---
 .../bindings/media/video-multiplexer.txt           | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/video-multiplexer.txt
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>;
+			};
+		};
+	};
+};
Signature · 1 line
2.7.4
maintainer Acked-by on v6 1/39
#2 lore raw

Re: [PATCH v6 01/39] [media] dt-bindings: Add bindings for video-multiplexer device

Quoted 11 lines · Steve Longerbeam

From: Philipp Zabel <[email protected]>

Add bindings documentation for the video multiplexer device.

---
 .../bindings/media/video-multiplexer.txt           | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/video-multiplexer.txt
author maintainer
#3 lore raw

PATCH v6 2/39 dt-bindings: Add bindings for i.MX media driver

In reply to Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +74 -0
new file mode 100644
index 0000000..3059c06
@@ -0,0 +1,74 @@
+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,imx-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 D-PHY clock), video_27m (D-PHY PLL reference
+		  clock), and eim_podf;
+- clock-names	: must contain "dphy", "ref", "pix";
+- port@*        : five port nodes must exist, containing endpoints
+		  connecting to the source and sink devices according to
+		  of_graph bindings. The first port is an input port,
+		  connecting with a MIPI CSI-2 source, and ports 1
+		  through 4 are output ports connecting with parallel
+		  bus sink endpoint nodes and correspond to the four
+		  MIPI CSI-2 virtual channel outputs.
+
+Optional properties:
+- interrupts	: must contain two level-triggered interrupts,
+		  in order: 100 and 101;
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 62 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +48 -0
new file mode 100644
index 0000000..3059c06
@@ -0,0 +1,74 @@
+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,imx-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.

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

Quoted 10 lines
Documentation/devicetree/bindings/media/imx.txt new file +10 -0
+
+
+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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Rob

#5 lore raw

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 16 lines · Rob Herring

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

Quoted 12 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

<snip>

Documentation/devicetree/bindings/media/imx.txt new file +9 -0
+
+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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Hi Rob, I'm not sure what you are asking me to do.

I assume if there's another binding doc in progress, it means someone is working on another Synopsys DW CSI-2 subdevice driver.

Unfortunately I don't have the time to contribute and switch to this other subdevice, and do test/debug.

For now I would prefer if this patchset is merged as is, and then contribute/switch to another CSI-2 subdev later. It is also getting very difficult managing all these patches (39 as of this version), and I'd prefer not to spam the lists with such large patchsets for too much longer.

Steve

maintainer
#6 lore raw

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 20 lines · Steve Longerbeam
Quoted 16 lines · Rob Herring

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

Quoted 12 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

<snip>

Documentation/devicetree/bindings/media/imx.txt new file +9 -0
+
+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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Quoted 4 lines

Hi Rob, I'm not sure what you are asking me to do.

I assume if there's another binding doc in progress, it means someone is working on another Synopsys DW CSI-2 subdevice driver.

Yes. see http://patchwork.ozlabs.org/patch/736177/

Quoted 4 lines

Unfortunately I don't have the time to contribute and switch to this other subdevice, and do test/debug.

From a DT perspective, I'm not asking that you share the subdevice

driver, only the binding. Simply put, there's 1 h/w block here, so there should only be 1 binding. The binding is an ABI, so you can't just merge it and change it later.

The driver side is a decision for the V4L2 maintainers.

Quoted 5 lines

For now I would prefer if this patchset is merged as is, and then contribute/switch to another CSI-2 subdev later. It is also getting very difficult managing all these patches (39 as of this version), and I'd prefer not to spam the lists with such large patchsets for too much longer.

Then maybe you should figure out how to split up the series. I've not looked at it to provide suggestions.

Rob

#7 lore raw

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 6 lines · Rob Herring
Quoted 2 lines · Steve Longerbeam

I assume if there's another binding doc in progress, it means someone is working on another Synopsys DW CSI-2 subdevice driver.

Yes. see http://patchwork.ozlabs.org/patch/736177/

Quoted 7 lines
Quoted 4 lines

Unfortunately I don't have the time to contribute and switch to this other subdevice, and do test/debug.

From a DT perspective, I'm not asking that you share the subdevice

driver, only the binding. Simply put, there's 1 h/w block here, so there should only be 1 binding. The binding is an ABI, so you can't just merge it and change it later.

I think it would be nice to have some kind of standard base binding for CSI2 interfaces, but beyond the standard compatible/reg/interrupts and graph properties, I'm not sure what it would look like.

As far as those properties go, the iMX6 version does better than the DW version, because we specify the full graph, whereas the DW version only specifies the downstream link. Once that's done, there's some properties (like those specifying the output configuration) which probably ought to be moved to the graph links instead, once they exist.

So, if anything, I think it's the DW version needs to be augmented with fuller information, and some of the properties moved.

Also, as I've mentioned in my other reply, while they may both appear to be called "Synopsys DW CSI-2" devices, they appear to be quite different from the hardware perspective.

The rest

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

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

In reply to Rob Herring
Quoted 68 lines · Rob Herring
Quoted 67 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +53 -0
new file mode 100644
index 0000000..3059c06
@@ -0,0 +1,74 @@
+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,imx-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
+--------------
+
Quoted 8 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/media/imx.txt new file +5 -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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Maybe someone can provide some kind of reference to it, and it's associated driver?

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

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 78 lines · Russell King - ARM Linux
Quoted 68 lines · Rob Herring
Quoted 67 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +53 -0
new file mode 100644
index 0000000..3059c06
@@ -0,0 +1,74 @@
+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,imx-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
+--------------
+
Quoted 8 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/media/imx.txt new file +5 -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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Quoted 2 lines

Maybe someone can provide some kind of reference to it, and it's associated driver?

Let me Google that for you (TM). The reference is in my comments on v5. Here's a reference to it [1].

[1] https://lkml.org/lkml/2017/3/20/524

Quoted 5 lines
Signature · 4 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.
#10 lore raw

Re: [PATCH v6 02/39] [media] dt-bindings: Add bindings for i.MX media driver

Quoted 79 lines · Rob Herring
Quoted 78 lines · Russell King - ARM Linux
Quoted 76 lines · Rob Herring
Quoted 62 lines · Steve Longerbeam

Add bindings documentation for the i.MX media driver.

---
 Documentation/devicetree/bindings/media/imx.txt | 74 +++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/imx.txt
Documentation/devicetree/bindings/media/imx.txt new file +48 -0
new file mode 100644
index 0000000..3059c06
@@ -0,0 +1,74 @@
+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,imx-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.

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

Quoted 10 lines
Documentation/devicetree/bindings/media/imx.txt new file +10 -0
+
+
+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";

As I mentioned in v5, there's a DW CSI2 binding in progress. This needs to be based on that.

Quoted 5 lines
Quoted 2 lines

Maybe someone can provide some kind of reference to it, and it's associated driver?

Let me Google that for you (TM). The reference is in my comments on v5. Here's a reference to it [1].

Looking at the actual driver, it seems to at least have a different register layout:

register imx6 dw
version 0x000 0x000
n_lanes 0x004 0x004
phy_shutdownz 0x008 -
dphy_resetz 0x00c -
resetn 0x010 0x008
phy_state 0x014 -
data_ids_1 0x018 0x010
data_ids_2 0x01c 0x014
err1 0x020 -
err2 0x024 -
msk1 0x028 -
msk2 0x02c -
phy_tst_ctrl0 0x030 -
phy_tst_ctrl1 0x034 -
sft_reset 0xf00 - (not part of CSI2, but a IMX6 specific
CSI2 to IPU gasket layer, but lives in CSI2's register region)

The DW version has many more registers than are documented by the iMX6 version. Only the first two registers appear to be common between these two devices, and maybe five registers exist (I haven't checked whether their bit layouts are the same though.)

So, I would say that these are two different devices.

As for the bindings, the differences are:

compatible: dw uses "snps,dw-mipi-csi"

		imx6 uses "fsl,imx6-mipi-csi2", "snps,dw-mipi-csi2"

reg: dw and imx6 both use a single base address

interrupts: dw requires one interrupt, imx6 has up to two interrupts

output-type: relevant for DW, meaningless on imx6 (not documented)

phys: DW seems to specify a separate PHY, on imx6 the PHY
control/status is tightly integrated into the CSI2 register set, and the PHY itself is undocumented except for some specific programming documented in source code.

resets: DW lists this under "required", but suffixes it with
(optional), so is it optional or is it not? Meaningless on imx6.

port: imx6 requires this, and must specify all (5) connectivity -
one node to connect to the camera, and four nodes connecting to the rest of the capture system.

dw specifies only one port node to be connected to the camera.

dw document is unclear whether this is an optional or required property. imx6 requires all five nodes.

clocks, imx6 requires the clocks and clock names to be specified,
clock-names: dw requires no clocks. DW binding would need these to be
optional.

So, the only common properties are "reg" and maybe "interrupts".

The DW binding also looks specific to the SoC implementation - the lack of any specification in it as to how the module relates to other parts of the capture system _appears_ to mean that its relationship with those other parts can't be established from DT. That's a problem when it comes to iMX6, because the CSI2 relationship to the one or two IPU units depends on the SoC (whether it's a single/dual-lite or dual/quad version.)

Therefore, it does not make sense to (a) use the same compatible, or
(b) use the same binding.

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

PATCH v6 3/39 dt/bindings: Add bindings for OV5640

In reply to Steve Longerbeam

Add device tree binding documentation for the OV5640 camera sensor.

---
 .../devicetree/bindings/media/i2c/ov5640.txt       | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt
Documentation/devicetree/bindings/media/i2c/ov5640.txt new file +45 -0
new file mode 100644
index 0000000..540b36c
@@ -0,0 +1,45 @@
+* 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.
+	       This is an active low signal to the OV5640.
+- powerdown-gpios: reference to the GPIO connected to the powerdown pin,
+		   if any. This is an active high signal to the OV5640.
+
+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 */
+		powerdown-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>;
+			};
+		};
+	};
+};
Signature · 1 line
2.7.4
maintainer
#12 lore raw

Re: [PATCH v6 03/39] [media] dt/bindings: Add bindings for OV5640

Quoted 7 lines · Steve Longerbeam

Add device tree binding documentation for the OV5640 camera sensor.

---
 .../devicetree/bindings/media/i2c/ov5640.txt       | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov5640.txt

I already acked this. Please add acks when posting new versions.

Rob

author maintainer
#13 lore raw

PATCH v6 4/39 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 6d7bf64..d28a413 100644
@@ -1134,7 +1134,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", "ref", "pix";
+				status = "disabled";
 			};
 
 			mipi_dsi: mipi at 021e0000 {
Signature · 1 line
2.7.4
author maintainer
#14 lore raw

PATCH v6 5/39 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 7aa120f..8958c4a 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 d28a413..194badd 100644
@@ -807,8 +807,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 {
@@ -1136,6 +1138,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>,
@@ -1243,6 +1247,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
#15 lore raw

PATCH v6 6/39 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 8958c4a..a959c76 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
#16 lore raw

PATCH v6 7/39 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 8413179..89dce27 100644
@@ -270,9 +270,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";
 };
 
@@ -373,7 +370,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
#17 lore raw

PATCH v6 8/39 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 2f90452..3304076 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 02a7cdf..dc51262e 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
#18 lore raw

PATCH v6 9/39 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
#19 lore raw

PATCH v6 10/39 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 a2a714d..c8e35c4 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 {
@@ -290,27 +328,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 {
@@ -418,6 +435,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
#20 lore raw

PATCH v6 11/39 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 c8e35c4..21dea5f 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 {
@@ -441,6 +444,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
#21 lore raw

PATCH v6 12/39 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 21dea5f..1212f82 100644
@@ -456,6 +456,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
#22 lore raw

PATCH v6 13/39 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 1212f82..a712ff1 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>,
@@ -444,6 +478,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
#23 lore raw

PATCH v6 14/39 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 2a5164a..47ee003 100644
@@ -299,6 +299,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-VID-MUX:
+
+       -  ``MEDIA_ENT_F_VID_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
#24 lore raw

PATCH v6 15/39 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 | 50 +++++++++++++++++++++++++++++++++++++++
 include/media/v4l2-mc.h           | 31 ++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
drivers/media/v4l2-core/v4l2-mc.c +50 -0
index 303980b..fda580e 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,55 @@ 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;
+
+	lockdep_assert_held(&mdev->graph_mutex);
+
+	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 +31 -0
index 2634d9d..299d75d 100644
@@ -171,6 +171,23 @@ 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
+ *
+ * This function is intended to be called from the link_notify callback,
+ * which holds the media graph mutex lock. __v4l2_pipeline_inherit_controls
+ * is provided (which does not acquire the lock) for this purpose.
+ * v4l2_pipeline_inherit_controls is also provided for use in other
+ * locations where the graph mutex is not held.
+ */
+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 +248,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
#25 lore raw

PATCH v6 16/39 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.

---
 drivers/media/i2c/Kconfig  |    7 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/ov5640.c | 2219 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 2227 insertions(+)
 create mode 100644 drivers/media/i2c/ov5640.c
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 +2219 -0

2,219 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#26 lore raw

PATCH v6 17/39 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() 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)).

- removed [gs]_frame_interval ops. timeperframe is not used anywhwere in this subdev, and currently it has no control over frame rate.

- add link_validate to media_entity_operations.

- moved devicetree binding doc to a separate commit.

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

---
 drivers/media/platform/Kconfig             |   8 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/video-multiplexer.c | 451 +++++++++++++++++++++++++++++
 3 files changed, 461 insertions(+)
 create mode 100644 drivers/media/platform/video-multiplexer.c
drivers/media/platform/Kconfig +8 -0
index ab0bb48..c9b8d9c 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 8959f6e..d418add 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 +451 -0

451 lines not on this page · raw message

Signature · 1 line
2.7.4
#27 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Hi Steve,

Quoted 51 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() 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)).

- removed [gs]_frame_interval ops. timeperframe is not used anywhwere in this subdev, and currently it has no control over frame rate.

- add link_validate to media_entity_operations.

- moved devicetree binding doc to a separate commit.

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

---
 drivers/media/platform/Kconfig             |   8 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/video-multiplexer.c | 451 +++++++++++++++++++++++++++++
 3 files changed, 461 insertions(+)
 create mode 100644 drivers/media/platform/video-multiplexer.c
drivers/media/platform/Kconfig +0 -0
index ab0bb48..c9b8d9c 100644

drivers/media/platform/Kconfig config VIDEO_M32R_AR_M64278 · line 79

Quoted 6 lines
drivers/media/platform/Kconfig +3 -0
@@ -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

+ depends on OF

Quoted 5 lines
drivers/media/platform/Kconfig +5 -0
+	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.
+

[snip]

Quoted 10 lines
drivers/media/platform/Kconfig +10 -0
+static int vidsw_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct of_endpoint endpoint;
+	struct device_node *ep;
+	struct reg_field field;
+	struct vidsw *vidsw;
+	struct regmap *map;
+	unsigned int num_pads;
+	int ret;

drivers/media/platform/Kconfig

Quoted 10 lines
drivers/media/platform/Kconfig +10 -0
+
+	vidsw = devm_kzalloc(&pdev->dev, sizeof(*vidsw), GFP_KERNEL);
+	if (!vidsw)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, vidsw);
+
+	v4l2_subdev_init(&vidsw->subdev, &vidsw_subdev_ops);
+	snprintf(vidsw->subdev.name, sizeof(vidsw->subdev.name), "%s",
+			np->name);

.... or oops here ^^^^^^^^^.

Quoted 7 lines
drivers/media/platform/Kconfig +7 -0
+	vidsw->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	vidsw->subdev.dev = &pdev->dev;
+
+	/*
+	 * The largest numbered port is the output port. It determines
+	 * total number of pads
+	 */

drivers/media/platform/Kconfig

Quoted 10 lines
drivers/media/platform/Kconfig +10 -0
+	num_pads = 0;
+	for_each_endpoint_of_node(np, ep) {
+		of_graph_parse_endpoint(ep, &endpoint);
+		num_pads = max(num_pads, endpoint.port + 1);
+	}
+
+	if (num_pads < 2) {
+		dev_err(&pdev->dev, "Not enough ports %d\n", num_pads);
+		return -EINVAL;
+	}

This unveils another runtime dependency on OF.

Quoted 20 lines
drivers/media/platform/Kconfig +20 -0
+
+	ret = of_get_reg_field(np, &field);
+	if (ret == 0) {
+		map = syscon_node_to_regmap(np->parent);
+		if (!map) {
+			dev_err(&pdev->dev, "Failed to get syscon register map\n");
+			return PTR_ERR(map);
+		}
+
+		vidsw->field = devm_regmap_field_alloc(&pdev->dev, map, field);
+		if (IS_ERR(vidsw->field)) {
+			dev_err(&pdev->dev, "Failed to allocate regmap field\n");
+			return PTR_ERR(vidsw->field);
+		}
+
+		regmap_field_read(vidsw->field, &vidsw->active);
+	} else {
+		if (num_pads > 3) {
+			dev_err(&pdev->dev, "Too many ports %d\n", num_pads);
+			return -EINVAL;

drivers/media/platform/Kconfig

Quoted 10 lines
drivers/media/platform/Kconfig +10 -0
+		}
+
+		vidsw->gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
+		if (IS_ERR(vidsw->gpio)) {
+			dev_warn(&pdev->dev,
+				 "could not request control gpio: %d\n", ret);
+			vidsw->gpio = NULL;
+		}
+
+		vidsw->active = gpiod_get_value(vidsw->gpio) ? 1 : 0;

vidsw->active is always set to 0 ?

Quoted 7 lines
drivers/media/platform/Kconfig +7 -0
+	}
+
+	vidsw->num_pads = num_pads;
+	vidsw->pads = devm_kzalloc(&pdev->dev, sizeof(*vidsw->pads) * num_pads,
+			GFP_KERNEL);
+	vidsw->format_mbus = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->format_mbus) * num_pads, GFP_KERNEL);

drivers/media/platform/Kconfig

Quoted 10 lines
drivers/media/platform/Kconfig +10 -0
+	vidsw->endpoint = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->endpoint) * (num_pads - 1), GFP_KERNEL);
+
+	ret = vidsw_async_init(vidsw, np);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+

--
With best wishes,
Vladimir

#28 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

In reply to Steve Longerbeam

Hi Steve, Philipp and Pavel,

Quoted 6 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.

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

In general the driver looks pretty good, especially regarding the user space API implementation which is important for use with other drivers.

I have some more detailed comments below.

Quoted 100 lines

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

- added media_entity_cleanup() 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)).

- removed [gs]_frame_interval ops. timeperframe is not used anywhwere in this subdev, and currently it has no control over frame rate.

- add link_validate to media_entity_operations.

- moved devicetree binding doc to a separate commit.

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

---
 drivers/media/platform/Kconfig             |   8 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/video-multiplexer.c | 451 +++++++++++++++++++++++++++++
 3 files changed, 461 insertions(+)
 create mode 100644 drivers/media/platform/video-multiplexer.c
drivers/media/platform/Kconfig +8 -0
index ab0bb48..c9b8d9c 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 8959f6e..d418add 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 +22 -0
new file mode 100644
index 0000000..b18c317
@@ -0,0 +1,451 @@
+/*
+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer <[email protected]>
+ * Copyright (C) 2016 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <media/v4l2-async.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+#include <media/v4l2-of.h>
+
+struct vidsw {
+	struct v4l2_subdev subdev;
+	unsigned int num_pads;

You could use subdev.entity.num_pads instead of caching the value locally.

Quoted 54 lines
drivers/media/platform/video-multiplexer.c new file +54 -0
+	struct media_pad *pads;
+	struct v4l2_mbus_framefmt *format_mbus;
+	struct v4l2_of_endpoint *endpoint;
+	struct regmap_field *field;
+	struct gpio_desc *gpio;
+	int active;
+};
+
+static inline struct vidsw *v4l2_subdev_to_vidsw(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct vidsw, subdev);
+}
+
+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);
+}
+
+static int vidsw_link_setup(struct media_entity *entity,
+			    const struct media_pad *local,
+			    const struct media_pad *remote, u32 flags)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	/* We have no limitations on enabling or disabling our output link */
+	if (local->index == vidsw->num_pads - 1)
+		return 0;
+
+	dev_dbg(sd->dev, "link setup %s -> %s", remote->entity->name,
+		local->entity->name);
+
+	if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+		if (local->index == vidsw->active) {
+			dev_dbg(sd->dev, "going inactive\n");
+			vidsw->active = -1;
+		}
+		return 0;
+	}
+
+	if (vidsw->active >= 0) {
+		struct media_pad *pad;
+
+		if (vidsw->active == local->index)
+			return 0;

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+
+		pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+		if (pad) {
+			struct media_link *link;
+			int ret;
+
+			link = media_entity_find_link(pad,
+						&vidsw->pads[vidsw->active]);
+			if (link) {
+				ret = __media_entity_setup_link(link, 0);

I wouldn't implicitly disable a link, even if only one can be active at a given time. No other drivers do that either.

Perhaps returning an error might be a better thing to do: if you're reconfiguring the pipeline anyway, there are likely issues elsewhere in it.

We could also change the behaviour later to allow implicit changes but we can't later on go the other way without breaking the user space.

Quoted 11 lines
drivers/media/platform/video-multiplexer.c new file +11 -0
+				if (ret)
+					return ret;
+			}
+		}
+	}
+
+	vidsw_set_active(vidsw, local->index);
+
+	return 0;
+}
+

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+static struct media_entity_operations vidsw_ops = {
+	.link_setup = vidsw_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
+};
+
+static bool vidsw_endpoint_disabled(struct device_node *ep)
+{
+	struct device_node *rpp;
+
+	if (!of_device_is_available(ep))

ep here is the endpoint, whereas the argument to of_device_is_available() should correspond to the actual device.

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+		return true;
+
+	rpp = of_graph_get_remote_port_parent(ep);
+	if (!rpp)
+		return true;
+
+	return !of_device_is_available(rpp);
+}
+
+static int vidsw_async_init(struct vidsw *vidsw, struct device_node *node)

I think I'd arrange this closer to probe as it's related to probe directly. Up to you.

Quoted 48 lines
drivers/media/platform/video-multiplexer.c new file +48 -0
+{
+	struct device_node *ep;
+	u32 portno;
+	int numports;
+	int ret;
+	int i;
+	bool active_link = false;
+
+	numports = vidsw->num_pads;
+
+	for (i = 0; i < numports - 1; i++)
+		vidsw->pads[i].flags = MEDIA_PAD_FL_SINK;
+	vidsw->pads[numports - 1].flags = MEDIA_PAD_FL_SOURCE;
+
+	vidsw->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
+	ret = media_entity_pads_init(&vidsw->subdev.entity, numports,
+				     vidsw->pads);
+	if (ret < 0)
+		return ret;
+
+	vidsw->subdev.entity.ops = &vidsw_ops;
+
+	for_each_endpoint_of_node(node, ep) {
+		struct v4l2_of_endpoint endpoint;
+
+		v4l2_of_parse_endpoint(ep, &endpoint);
+
+		portno = endpoint.base.port;
+		if (portno >= numports - 1)
+			continue;
+
+		if (vidsw_endpoint_disabled(ep)) {
+			dev_dbg(vidsw->subdev.dev,
+				"port %d disabled\n", portno);
+			continue;
+		}
+
+		vidsw->endpoint[portno] = endpoint;
+
+		if (portno == vidsw->active)
+			active_link = true;
+	}
+
+	for (portno = 0; portno < numports - 1; portno++) {
+		if (!vidsw->endpoint[portno].base.local_node)
+			continue;
+
+		/* If the active input is not connected, use another */

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+		if (!active_link) {
+			vidsw_set_active(vidsw, portno);
+			active_link = true;
+		}
+	}
+
+	return v4l2_async_register_subdev(&vidsw->subdev);
+}
+
+int vidsw_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg)

We should get rid of g_mbus_config() in the long run, but as we don't have the alternative (frame descriptors) isn't up to the job yet I guess it's ok. I don't think we'll have too many users for the video switch right now.

Quoted 51 lines
drivers/media/platform/video-multiplexer.c new file +51 -0
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct media_pad *pad;
+	int ret;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "no configuration for inactive mux\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Retrieve media bus configuration from the entity connected to the
+	 * active input
+	 */
+	pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+	if (pad) {
+		sd = media_entity_to_v4l2_subdev(pad->entity);
+		ret = v4l2_subdev_call(sd, video, g_mbus_config, cfg);
+		if (ret == -ENOIOCTLCMD)
+			pad = NULL;
+		else if (ret < 0) {
+			dev_err(sd->dev, "failed to get source configuration\n");
+			return ret;
+		}
+	}
+	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;
+	}
+
+	return 0;
+}
+
+static int vidsw_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_subdev *upstream_sd;
+	struct media_pad *pad;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "Can not start streaming on inactive mux\n");
+		return -EINVAL;
+	}
+
+	pad = media_entity_remote_pad(&sd->entity.pads[vidsw->active]);
+	if (!pad) {
+		dev_err(sd->dev, "Failed to find remote source pad\n");
+		return -ENOLINK;

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	}
+
+	if (!is_media_entity_v4l2_subdev(pad->entity)) {
+		dev_err(sd->dev, "Upstream entity is not a v4l2 subdev\n");
+		return -ENODEV;
+	}
+
+	upstream_sd = media_entity_to_v4l2_subdev(pad->entity);
+
+	return v4l2_subdev_call(upstream_sd, video, s_stream, enable);

Now that we'll have more than two drivers involved in the same pipeline it becomes necessary to define the behaviour of s_stream() throughout the pipeline --- i.e. whose responsibility is it to call s_stream() on the sub-devices in the pipeline?

I can submit a patch for that. I think the way you do it here is good, as it enables the caller to choose the appropriate behaviour, i.e. start the local device before or after the upstream sub-device.

Quoted 32 lines
drivers/media/platform/video-multiplexer.c new file +32 -0
+}
+
+static const struct v4l2_subdev_video_ops vidsw_subdev_video_ops = {
+	.g_mbus_config = vidsw_g_mbus_config,
+	.s_stream = vidsw_s_stream,
+};
+
+static struct v4l2_mbus_framefmt *
+__vidsw_get_pad_format(struct v4l2_subdev *sd,
+		       struct v4l2_subdev_pad_config *cfg,
+		       unsigned int pad, u32 which)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	switch (which) {
+	case V4L2_SUBDEV_FORMAT_TRY:
+		return v4l2_subdev_get_try_format(sd, cfg, pad);
+	case V4L2_SUBDEV_FORMAT_ACTIVE:
+		return &vidsw->format_mbus[pad];
+	default:
+		return NULL;
+	}
+}
+
+static int vidsw_get_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
+{
+	sdformat->format = *__vidsw_get_pad_format(sd, cfg, sdformat->pad,
+						   sdformat->which);
+	return 0;
+}

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+
+static int vidsw_set_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_mbus_framefmt *mbusformat;
+
+	if (sdformat->pad >= vidsw->num_pads)
+		return -EINVAL;

This check is already performed in v4l2-subdev.c.

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

Quoted 7 lines
drivers/media/platform/video-multiplexer.c new file +7 -0
+
+	mbusformat = __vidsw_get_pad_format(sd, cfg, sdformat->pad,
+					    sdformat->which);
+	if (!mbusformat)
+		return -EINVAL;
+
+	/* Output pad mirrors active input pad, no limitations on input pads */

Source and sink pads.

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

Quoted 1 line
drivers/media/platform/video-multiplexer.c new file +1 -0
+	if (sdformat->pad == (vidsw->num_pads - 1) && vidsw->active >= 0)

I think it'd be cleaner to test for the pad flag instead of the number. Or, add a macro to obtain the source pad number.

Quoted 23 lines
drivers/media/platform/video-multiplexer.c new file +23 -0
+		sdformat->format = vidsw->format_mbus[vidsw->active];
+
+	*mbusformat = sdformat->format;
+
+	return 0;
+}
+
+static struct v4l2_subdev_pad_ops vidsw_pad_ops = {
+	.get_fmt = vidsw_get_format,
+	.set_fmt = vidsw_set_format,
+};
+
+static struct v4l2_subdev_ops vidsw_subdev_ops = {
+	.pad = &vidsw_pad_ops,
+	.video = &vidsw_subdev_video_ops,
+};
+
+static int of_get_reg_field(struct device_node *node, struct reg_field *field)
+{
+	u32 bit_mask;
+	int ret;
+
+	ret = of_property_read_u32(node, "reg", &field->reg);

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-mask", &bit_mask);
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-shift", &field->lsb);
+	if (ret < 0)
+		return ret;

I think the above would look nice in a MUX driver. :-)

Quoted 24 lines
drivers/media/platform/video-multiplexer.c new file +24 -0
+
+	field->msb = field->lsb + fls(bit_mask) - 1;
+
+	return 0;
+}
+
+static int vidsw_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct of_endpoint endpoint;
+	struct device_node *ep;
+	struct reg_field field;
+	struct vidsw *vidsw;
+	struct regmap *map;
+	unsigned int num_pads;
+	int ret;
+
+	vidsw = devm_kzalloc(&pdev->dev, sizeof(*vidsw), GFP_KERNEL);
+	if (!vidsw)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, vidsw);
+
+	v4l2_subdev_init(&vidsw->subdev, &vidsw_subdev_ops);

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	snprintf(vidsw->subdev.name, sizeof(vidsw->subdev.name), "%s",
+			np->name);
+	vidsw->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	vidsw->subdev.dev = &pdev->dev;
+
+	/*
+	 * The largest numbered port is the output port. It determines
+	 * total number of pads
+	 */
+	num_pads = 0;

You can initialise num_pads in variable declaration.

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

Quoted 3 lines
drivers/media/platform/video-multiplexer.c new file +3 -0
+	for_each_endpoint_of_node(np, ep) {
+		of_graph_parse_endpoint(ep, &endpoint);
+		num_pads = max(num_pads, endpoint.port + 1);

Port numbers come directly from DT.

Shouldn't num_pads be only the number of pads that have links with actual physical connections? I.e. if a device is disabled, it shouldn't be counted here.

Quoted 85 lines
drivers/media/platform/video-multiplexer.c new file +85 -0
+	}
+
+	if (num_pads < 2) {
+		dev_err(&pdev->dev, "Not enough ports %d\n", num_pads);
+		return -EINVAL;
+	}
+
+	ret = of_get_reg_field(np, &field);
+	if (ret == 0) {
+		map = syscon_node_to_regmap(np->parent);
+		if (!map) {
+			dev_err(&pdev->dev, "Failed to get syscon register map\n");
+			return PTR_ERR(map);
+		}
+
+		vidsw->field = devm_regmap_field_alloc(&pdev->dev, map, field);
+		if (IS_ERR(vidsw->field)) {
+			dev_err(&pdev->dev, "Failed to allocate regmap field\n");
+			return PTR_ERR(vidsw->field);
+		}
+
+		regmap_field_read(vidsw->field, &vidsw->active);
+	} else {
+		if (num_pads > 3) {
+			dev_err(&pdev->dev, "Too many ports %d\n", num_pads);
+			return -EINVAL;
+		}
+
+		vidsw->gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
+		if (IS_ERR(vidsw->gpio)) {
+			dev_warn(&pdev->dev,
+				 "could not request control gpio: %d\n", ret);
+			vidsw->gpio = NULL;
+		}
+
+		vidsw->active = gpiod_get_value(vidsw->gpio) ? 1 : 0;
+	}
+
+	vidsw->num_pads = num_pads;
+	vidsw->pads = devm_kzalloc(&pdev->dev, sizeof(*vidsw->pads) * num_pads,
+			GFP_KERNEL);
+	vidsw->format_mbus = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->format_mbus) * num_pads, GFP_KERNEL);
+	vidsw->endpoint = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->endpoint) * (num_pads - 1), GFP_KERNEL);
+
+	ret = vidsw_async_init(vidsw, np);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int vidsw_remove(struct platform_device *pdev)
+{
+	struct vidsw *vidsw = platform_get_drvdata(pdev);
+	struct v4l2_subdev *sd = &vidsw->subdev;
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+
+	return 0;
+}
+
+static const struct of_device_id vidsw_dt_ids[] = {
+	{ .compatible = "video-multiplexer", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, vidsw_dt_ids);
+
+static struct platform_driver vidsw_driver = {
+	.probe		= vidsw_probe,
+	.remove		= vidsw_remove,
+	.driver		= {
+		.of_match_table = vidsw_dt_ids,
+		.name = "video-multiplexer",
+	},
+};
+
+module_platform_driver(vidsw_driver);
+
+MODULE_DESCRIPTION("video stream multiplexer");
+MODULE_AUTHOR("Sascha Hauer, Pengutronix");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");
+MODULE_LICENSE("GPL");
Signature · 4 lines
Kind regards,

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

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Quoted 10 lines · Sakari Ailus

Hi Steve, Philipp and Pavel,

Quoted 6 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.

Quoted 4 lines

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

I would prefer to wait on this, and get what we have merged now so I can unload all these patches first.

Also this is Philipp's driver, so again I would prefer to get this merged as-is and then Philipp can address these issues in a future patch. But I will add my comments below...

Quoted 6 lines

In general the driver looks pretty good, especially regarding the user space API implementation which is important for use with other drivers.

I have some more detailed comments below.

<snip>

Quoted 6 lines

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

Quoted 4 lines
drivers/media/platform/video-multiplexer.c new file +4 -0
+
+struct vidsw {
+	struct v4l2_subdev subdev;
+	unsigned int num_pads;

You could use subdev.entity.num_pads instead of caching the value locally.

Agreed.

Quoted 69 lines
Quoted 55 lines
drivers/media/platform/video-multiplexer.c new file +54 -0
+	struct media_pad *pads;
+	struct v4l2_mbus_framefmt *format_mbus;
+	struct v4l2_of_endpoint *endpoint;
+	struct regmap_field *field;
+	struct gpio_desc *gpio;
+	int active;
+};
+
+static inline struct vidsw *v4l2_subdev_to_vidsw(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct vidsw, subdev);
+}
+
+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);
+}
+
+static int vidsw_link_setup(struct media_entity *entity,
+			    const struct media_pad *local,
+			    const struct media_pad *remote, u32 flags)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	/* We have no limitations on enabling or disabling our output link */
+	if (local->index == vidsw->num_pads - 1)
+		return 0;
+
+	dev_dbg(sd->dev, "link setup %s -> %s", remote->entity->name,
+		local->entity->name);
+
+	if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+		if (local->index == vidsw->active) {
+			dev_dbg(sd->dev, "going inactive\n");
+			vidsw->active = -1;
+		}
+		return 0;
+	}
+
+	if (vidsw->active >= 0) {
+		struct media_pad *pad;
+
+		if (vidsw->active == local->index)
+			return 0;

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+
+		pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+		if (pad) {
+			struct media_link *link;
+			int ret;
+
+			link = media_entity_find_link(pad,
+						&vidsw->pads[vidsw->active]);
+			if (link) {
+				ret = __media_entity_setup_link(link, 0);

I wouldn't implicitly disable a link, even if only one can be active at a given time. No other drivers do that either.

Quoted 5 lines

Perhaps returning an error might be a better thing to do: if you're reconfiguring the pipeline anyway, there are likely issues elsewhere in it.

We could also change the behaviour later to allow implicit changes but we can't later on go the other way without breaking the user space.

I think this whole if (vidsw->active >= 0) { ... } block should be removed. This is left-over from the first implementation that tried to propagate link setup upstream. This is not working yet, so for now I think this should be removed.

<snip>

Quoted 11 lines

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

Quoted 8 lines
drivers/media/platform/video-multiplexer.c new file +6 -0
+
+static bool vidsw_endpoint_disabled(struct device_node *ep)
+{
+	struct device_node *rpp;
+
+	if (!of_device_is_available(ep))

ep here is the endpoint, whereas the argument to of_device_is_available() should correspond to the actual device.

Agreed, I think this if statement should be removed, and...

Quoted 6 lines

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

Quoted 6 lines
drivers/media/platform/video-multiplexer.c new file +5 -0
+		return true;
+
+	rpp = of_graph_get_remote_port_parent(ep);
+	if (!rpp)
+		return true;

this if statement can also be removed, since that is handled automatically by of_device_is_available() below.

Quoted 130 lines

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

Quoted 5 lines
drivers/media/platform/video-multiplexer.c new file +5 -0
+
+	return !of_device_is_available(rpp);
+}
+
+static int vidsw_async_init(struct vidsw *vidsw, struct device_node *node)

I think I'd arrange this closer to probe as it's related to probe directly. Up to you.

Quoted 48 lines
drivers/media/platform/video-multiplexer.c new file +48 -0
+{
+	struct device_node *ep;
+	u32 portno;
+	int numports;
+	int ret;
+	int i;
+	bool active_link = false;
+
+	numports = vidsw->num_pads;
+
+	for (i = 0; i < numports - 1; i++)
+		vidsw->pads[i].flags = MEDIA_PAD_FL_SINK;
+	vidsw->pads[numports - 1].flags = MEDIA_PAD_FL_SOURCE;
+
+	vidsw->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
+	ret = media_entity_pads_init(&vidsw->subdev.entity, numports,
+				     vidsw->pads);
+	if (ret < 0)
+		return ret;
+
+	vidsw->subdev.entity.ops = &vidsw_ops;
+
+	for_each_endpoint_of_node(node, ep) {
+		struct v4l2_of_endpoint endpoint;
+
+		v4l2_of_parse_endpoint(ep, &endpoint);
+
+		portno = endpoint.base.port;
+		if (portno >= numports - 1)
+			continue;
+
+		if (vidsw_endpoint_disabled(ep)) {
+			dev_dbg(vidsw->subdev.dev,
+				"port %d disabled\n", portno);
+			continue;
+		}
+
+		vidsw->endpoint[portno] = endpoint;
+
+		if (portno == vidsw->active)
+			active_link = true;
+	}
+
+	for (portno = 0; portno < numports - 1; portno++) {
+		if (!vidsw->endpoint[portno].base.local_node)
+			continue;
+
+		/* If the active input is not connected, use another */

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+		if (!active_link) {
+			vidsw_set_active(vidsw, portno);
+			active_link = true;
+		}
+	}
+
+	return v4l2_async_register_subdev(&vidsw->subdev);
+}
+
+int vidsw_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg)

We should get rid of g_mbus_config() in the long run, but as we don't have the alternative (frame descriptors) isn't up to the job yet I guess it's ok. I don't think we'll have too many users for the video switch right now.

Quoted 58 lines
drivers/media/platform/video-multiplexer.c new file +58 -0
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct media_pad *pad;
+	int ret;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "no configuration for inactive mux\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Retrieve media bus configuration from the entity connected to the
+	 * active input
+	 */
+	pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+	if (pad) {
+		sd = media_entity_to_v4l2_subdev(pad->entity);
+		ret = v4l2_subdev_call(sd, video, g_mbus_config, cfg);
+		if (ret == -ENOIOCTLCMD)
+			pad = NULL;
+		else if (ret < 0) {
+			dev_err(sd->dev, "failed to get source configuration\n");
+			return ret;
+		}
+	}
+	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;
+	}
+
+	return 0;
+}
+
+static int vidsw_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_subdev *upstream_sd;
+	struct media_pad *pad;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "Can not start streaming on inactive mux\n");
+		return -EINVAL;
+	}
+
+	pad = media_entity_remote_pad(&sd->entity.pads[vidsw->active]);
+	if (!pad) {
+		dev_err(sd->dev, "Failed to find remote source pad\n");
+		return -ENOLINK;
+	}
+
+	if (!is_media_entity_v4l2_subdev(pad->entity)) {
+		dev_err(sd->dev, "Upstream entity is not a v4l2 subdev\n");
+		return -ENODEV;
+	}
+
Quoted 8 lines

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

Quoted 3 lines
drivers/media/platform/video-multiplexer.c new file +3 -0
+	upstream_sd = media_entity_to_v4l2_subdev(pad->entity);
+
+	return v4l2_subdev_call(upstream_sd, video, s_stream, enable);

Now that we'll have more than two drivers involved in the same pipeline it becomes necessary to define the behaviour of s_stream() throughout the pipeline --- i.e. whose responsibility is it to call s_stream() on the sub-devices in the pipeline?

In the case of imx-media, the capture device calls set stream on the whole pipeline in the start_streaming() callback. This subdev call is actually a NOOP for imx-media, because the upstream entity has already started streaming. Again I think this should be removed. It also enforces a stream order that some MC drivers may have a problem with.

For the remaining comments I'll let Philipp respond.

Steve

Quoted 234 lines

I can submit a patch for that. I think the way you do it here is good, as it enables the caller to choose the appropriate behaviour, i.e. start the local device before or after the upstream sub-device.

Quoted 32 lines
drivers/media/platform/video-multiplexer.c new file +32 -0
+}
+
+static const struct v4l2_subdev_video_ops vidsw_subdev_video_ops = {
+	.g_mbus_config = vidsw_g_mbus_config,
+	.s_stream = vidsw_s_stream,
+};
+
+static struct v4l2_mbus_framefmt *
+__vidsw_get_pad_format(struct v4l2_subdev *sd,
+		       struct v4l2_subdev_pad_config *cfg,
+		       unsigned int pad, u32 which)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	switch (which) {
+	case V4L2_SUBDEV_FORMAT_TRY:
+		return v4l2_subdev_get_try_format(sd, cfg, pad);
+	case V4L2_SUBDEV_FORMAT_ACTIVE:
+		return &vidsw->format_mbus[pad];
+	default:
+		return NULL;
+	}
+}
+
+static int vidsw_get_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
+{
+	sdformat->format = *__vidsw_get_pad_format(sd, cfg, sdformat->pad,
+						   sdformat->which);
+	return 0;
+}

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+
+static int vidsw_set_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_mbus_framefmt *mbusformat;
+
+	if (sdformat->pad >= vidsw->num_pads)
+		return -EINVAL;

This check is already performed in v4l2-subdev.c.

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

Quoted 7 lines
drivers/media/platform/video-multiplexer.c new file +7 -0
+
+	mbusformat = __vidsw_get_pad_format(sd, cfg, sdformat->pad,
+					    sdformat->which);
+	if (!mbusformat)
+		return -EINVAL;
+
+	/* Output pad mirrors active input pad, no limitations on input pads */

Source and sink pads.

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

Quoted 1 line
drivers/media/platform/video-multiplexer.c new file +1 -0
+	if (sdformat->pad == (vidsw->num_pads - 1) && vidsw->active >= 0)

I think it'd be cleaner to test for the pad flag instead of the number. Or, add a macro to obtain the source pad number.

Quoted 23 lines
drivers/media/platform/video-multiplexer.c new file +23 -0
+		sdformat->format = vidsw->format_mbus[vidsw->active];
+
+	*mbusformat = sdformat->format;
+
+	return 0;
+}
+
+static struct v4l2_subdev_pad_ops vidsw_pad_ops = {
+	.get_fmt = vidsw_get_format,
+	.set_fmt = vidsw_set_format,
+};
+
+static struct v4l2_subdev_ops vidsw_subdev_ops = {
+	.pad = &vidsw_pad_ops,
+	.video = &vidsw_subdev_video_ops,
+};
+
+static int of_get_reg_field(struct device_node *node, struct reg_field *field)
+{
+	u32 bit_mask;
+	int ret;
+
+	ret = of_property_read_u32(node, "reg", &field->reg);

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-mask", &bit_mask);
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-shift", &field->lsb);
+	if (ret < 0)
+		return ret;

I think the above would look nice in a MUX driver. :-)

Quoted 24 lines
drivers/media/platform/video-multiplexer.c new file +24 -0
+
+	field->msb = field->lsb + fls(bit_mask) - 1;
+
+	return 0;
+}
+
+static int vidsw_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct of_endpoint endpoint;
+	struct device_node *ep;
+	struct reg_field field;
+	struct vidsw *vidsw;
+	struct regmap *map;
+	unsigned int num_pads;
+	int ret;
+
+	vidsw = devm_kzalloc(&pdev->dev, sizeof(*vidsw), GFP_KERNEL);
+	if (!vidsw)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, vidsw);
+
+	v4l2_subdev_init(&vidsw->subdev, &vidsw_subdev_ops);

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	snprintf(vidsw->subdev.name, sizeof(vidsw->subdev.name), "%s",
+			np->name);
+	vidsw->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	vidsw->subdev.dev = &pdev->dev;
+
+	/*
+	 * The largest numbered port is the output port. It determines
+	 * total number of pads
+	 */
+	num_pads = 0;

You can initialise num_pads in variable declaration.

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

Quoted 3 lines
drivers/media/platform/video-multiplexer.c new file +3 -0
+	for_each_endpoint_of_node(np, ep) {
+		of_graph_parse_endpoint(ep, &endpoint);
+		num_pads = max(num_pads, endpoint.port + 1);

Port numbers come directly from DT.

Shouldn't num_pads be only the number of pads that have links with actual physical connections? I.e. if a device is disabled, it shouldn't be counted here.

Quoted 85 lines
drivers/media/platform/video-multiplexer.c new file +85 -0
+	}
+
+	if (num_pads < 2) {
+		dev_err(&pdev->dev, "Not enough ports %d\n", num_pads);
+		return -EINVAL;
+	}
+
+	ret = of_get_reg_field(np, &field);
+	if (ret == 0) {
+		map = syscon_node_to_regmap(np->parent);
+		if (!map) {
+			dev_err(&pdev->dev, "Failed to get syscon register map\n");
+			return PTR_ERR(map);
+		}
+
+		vidsw->field = devm_regmap_field_alloc(&pdev->dev, map, field);
+		if (IS_ERR(vidsw->field)) {
+			dev_err(&pdev->dev, "Failed to allocate regmap field\n");
+			return PTR_ERR(vidsw->field);
+		}
+
+		regmap_field_read(vidsw->field, &vidsw->active);
+	} else {
+		if (num_pads > 3) {
+			dev_err(&pdev->dev, "Too many ports %d\n", num_pads);
+			return -EINVAL;
+		}
+
+		vidsw->gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
+		if (IS_ERR(vidsw->gpio)) {
+			dev_warn(&pdev->dev,
+				 "could not request control gpio: %d\n", ret);
+			vidsw->gpio = NULL;
+		}
+
+		vidsw->active = gpiod_get_value(vidsw->gpio) ? 1 : 0;
+	}
+
+	vidsw->num_pads = num_pads;
+	vidsw->pads = devm_kzalloc(&pdev->dev, sizeof(*vidsw->pads) * num_pads,
+			GFP_KERNEL);
+	vidsw->format_mbus = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->format_mbus) * num_pads, GFP_KERNEL);
+	vidsw->endpoint = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->endpoint) * (num_pads - 1), GFP_KERNEL);
+
+	ret = vidsw_async_init(vidsw, np);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int vidsw_remove(struct platform_device *pdev)
+{
+	struct vidsw *vidsw = platform_get_drvdata(pdev);
+	struct v4l2_subdev *sd = &vidsw->subdev;
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+
+	return 0;
+}
+
+static const struct of_device_id vidsw_dt_ids[] = {
+	{ .compatible = "video-multiplexer", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, vidsw_dt_ids);
+
+static struct platform_driver vidsw_driver = {
+	.probe		= vidsw_probe,
+	.remove		= vidsw_remove,
+	.driver		= {
+		.of_match_table = vidsw_dt_ids,
+		.name = "video-multiplexer",
+	},
+};
+
+module_platform_driver(vidsw_driver);
+
+MODULE_DESCRIPTION("video stream multiplexer");
+MODULE_AUTHOR("Sascha Hauer, Pengutronix");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");
+MODULE_LICENSE("GPL");
#30 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Hi Steve,

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

Hi Steve, Philipp and Pavel,

Quoted 6 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.

Quoted 7 lines
Quoted 4 lines

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

I would prefer to wait on this, and get what we have merged now so I can unload all these patches first.

The DT bindings will be different for this one and if you were using a MUX, won't they? And you can't remove support for the existing bindings either, you have to continue to support them going forward.

Quoted 4 lines

Also this is Philipp's driver, so again I would prefer to get this merged as-is and then Philipp can address these issues in a future patch. But I will add my comments below...

I bet there will be more issues to handle if you were to do the changes later than now.

...

Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
drivers/media/platform/video-multiplexer.c new file +22 -0
+static int vidsw_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_subdev *upstream_sd;
+	struct media_pad *pad;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "Can not start streaming on inactive mux\n");
+		return -EINVAL;
+	}
+
+	pad = media_entity_remote_pad(&sd->entity.pads[vidsw->active]);
+	if (!pad) {
+		dev_err(sd->dev, "Failed to find remote source pad\n");
+		return -ENOLINK;
+	}
+
+	if (!is_media_entity_v4l2_subdev(pad->entity)) {
+		dev_err(sd->dev, "Upstream entity is not a v4l2 subdev\n");
+		return -ENODEV;
+	}
+
Quoted 8 lines

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

Quoted 3 lines
drivers/media/platform/video-multiplexer.c new file +3 -0
+	upstream_sd = media_entity_to_v4l2_subdev(pad->entity);
+
+	return v4l2_subdev_call(upstream_sd, video, s_stream, enable);

Now that we'll have more than two drivers involved in the same pipeline it becomes necessary to define the behaviour of s_stream() throughout the pipeline --- i.e. whose responsibility is it to call s_stream() on the sub-devices in the pipeline?

Quoted 5 lines

In the case of imx-media, the capture device calls set stream on the whole pipeline in the start_streaming() callback. This subdev call is actually a NOOP for imx-media, because the upstream entity has already started streaming. Again I think this should be removed. It also enforces a stream order that some MC drivers may have a problem with.

What I want to say here is that the order in which the different devices in the pipeline need to be started may not be known in a driver for a particular part of the pipeline.

In order to avoid trying to have a single point of decision making, the s_stream() op implemented in sub-device drivers should serve the purpose. I'll cc you for the documentation patch.

Signature · 4 lines
Kind regards,

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

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

In reply to Sakari Ailus

Hi Sakari,

thank you for the review.

Quoted 10 lines · Sakari Ailus

Hi Steve, Philipp and Pavel,

Quoted 6 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.

Quoted 4 lines

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

It is not quite clear to me how to design the DT bindings for this. Just splitting the video-multiplexer driver from the mux-mmio / mux-gpio would make it necessary to keep the video-multiplexer node to describe the of-graph bindings. But then we have two different nodes in the DT that describe the same hardware:

	mux: mux {
		compatible = "mux-gpio";
		mux-gpios = <&gpio 0>, <&gpio 1>;
		#mux-control-cells = <0>;
	}

	video-multiplexer {
		compatible = "video-multiplexer"
		mux-controls = <&mux>;

		ports {
			/* ... */
		}
	}

It would feel more natural to have the ports in the mux node, but then how would the video-multiplexer driver be instanciated, and how would it get to the of-graph nodes?

Quoted 109 lines

In general the driver looks pretty good, especially regarding the user space API implementation which is important for use with other drivers.

I have some more detailed comments below.

Quoted 104 lines

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

- added media_entity_cleanup() 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)).

- removed [gs]_frame_interval ops. timeperframe is not used anywhwere in this subdev, and currently it has no control over frame rate.

- add link_validate to media_entity_operations.

- moved devicetree binding doc to a separate commit.

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

---
 drivers/media/platform/Kconfig             |   8 +
 drivers/media/platform/Makefile            |   2 +
 drivers/media/platform/video-multiplexer.c | 451 +++++++++++++++++++++++++++++
 3 files changed, 461 insertions(+)
 create mode 100644 drivers/media/platform/video-multiplexer.c
drivers/media/platform/Kconfig +8 -0
index ab0bb48..c9b8d9c 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 8959f6e..d418add 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 +26 -0
new file mode 100644
index 0000000..b18c317
@@ -0,0 +1,451 @@
+/*
+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer <[email protected]>
+ * Copyright (C) 2016 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 the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/err.h>
+#include <linux/gpio/consumer.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_graph.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <media/v4l2-async.h>
+#include <media/v4l2-device.h>
Quoted 8 lines

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

Quoted 6 lines
drivers/media/platform/video-multiplexer.c new file +6 -0
+#include <media/v4l2-subdev.h>
+#include <media/v4l2-of.h>
+
+struct vidsw {
+	struct v4l2_subdev subdev;
+	unsigned int num_pads;

You could use subdev.entity.num_pads instead of caching the value locally.

Ok, I'll change this.

Quoted 68 lines
Quoted 54 lines
drivers/media/platform/video-multiplexer.c new file +54 -0
+	struct media_pad *pads;
+	struct v4l2_mbus_framefmt *format_mbus;
+	struct v4l2_of_endpoint *endpoint;
+	struct regmap_field *field;
+	struct gpio_desc *gpio;
+	int active;
+};
+
+static inline struct vidsw *v4l2_subdev_to_vidsw(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct vidsw, subdev);
+}
+
+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);
+}
+
+static int vidsw_link_setup(struct media_entity *entity,
+			    const struct media_pad *local,
+			    const struct media_pad *remote, u32 flags)
+{
+	struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	/* We have no limitations on enabling or disabling our output link */
+	if (local->index == vidsw->num_pads - 1)
+		return 0;
+
+	dev_dbg(sd->dev, "link setup %s -> %s", remote->entity->name,
+		local->entity->name);
+
+	if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+		if (local->index == vidsw->active) {
+			dev_dbg(sd->dev, "going inactive\n");
+			vidsw->active = -1;
+		}
+		return 0;
+	}
+
+	if (vidsw->active >= 0) {
+		struct media_pad *pad;
+
+		if (vidsw->active == local->index)
+			return 0;

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+
+		pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+		if (pad) {
+			struct media_link *link;
+			int ret;
+
+			link = media_entity_find_link(pad,
+						&vidsw->pads[vidsw->active]);
+			if (link) {
+				ret = __media_entity_setup_link(link, 0);

I wouldn't implicitly disable a link, even if only one can be active at a given time. No other drivers do that either.

Quoted 5 lines

Perhaps returning an error might be a better thing to do: if you're reconfiguring the pipeline anyway, there are likely issues elsewhere in it.

We could also change the behaviour later to allow implicit changes but we can't later on go the other way without breaking the user space.

Fair enough, I'll drop this.

Quoted 16 lines
Quoted 16 lines
drivers/media/platform/video-multiplexer.c new file +16 -0
+				if (ret)
+					return ret;
+			}
+		}
+	}
+
+	vidsw_set_active(vidsw, local->index);
+
+	return 0;
+}
+
+static struct media_entity_operations vidsw_ops = {
+	.link_setup = vidsw_link_setup,
+	.link_validate = v4l2_subdev_link_validate,
+};
+
Quoted 8 lines

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

Quoted 5 lines
drivers/media/platform/video-multiplexer.c new file +5 -0
+static bool vidsw_endpoint_disabled(struct device_node *ep)
+{
+	struct device_node *rpp;
+
+	if (!of_device_is_available(ep))

ep here is the endpoint, whereas the argument to of_device_is_available() should correspond to the actual device.

Well, this was a convenience to allow adding status = "disabled" to endpoints to turn them off (see the function name). I

Quoted 5 lines
Quoted 5 lines
drivers/media/platform/video-multiplexer.c new file +5 -0
+		return true;
+
+	rpp = of_graph_get_remote_port_parent(ep);
+	if (!rpp)
+		return true;
Quoted 8 lines

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

Quoted 5 lines
drivers/media/platform/video-multiplexer.c new file +5 -0
+
+	return !of_device_is_available(rpp);
+}
+
+static int vidsw_async_init(struct vidsw *vidsw, struct device_node *node)

I think I'd arrange this closer to probe as it's related to probe directly. Up to you.

I'll change this to

	rpp = of_graph_get_remote_port_parent(ep);
	return !of_device_is_available(rpp);

as Steve suggested.

Quoted 54 lines
Quoted 54 lines
drivers/media/platform/video-multiplexer.c new file +54 -0
+{
+	struct device_node *ep;
+	u32 portno;
+	int numports;
+	int ret;
+	int i;
+	bool active_link = false;
+
+	numports = vidsw->num_pads;
+
+	for (i = 0; i < numports - 1; i++)
+		vidsw->pads[i].flags = MEDIA_PAD_FL_SINK;
+	vidsw->pads[numports - 1].flags = MEDIA_PAD_FL_SOURCE;
+
+	vidsw->subdev.entity.function = MEDIA_ENT_F_VID_MUX;
+	ret = media_entity_pads_init(&vidsw->subdev.entity, numports,
+				     vidsw->pads);
+	if (ret < 0)
+		return ret;
+
+	vidsw->subdev.entity.ops = &vidsw_ops;
+
+	for_each_endpoint_of_node(node, ep) {
+		struct v4l2_of_endpoint endpoint;
+
+		v4l2_of_parse_endpoint(ep, &endpoint);
+
+		portno = endpoint.base.port;
+		if (portno >= numports - 1)
+			continue;
+
+		if (vidsw_endpoint_disabled(ep)) {
+			dev_dbg(vidsw->subdev.dev,
+				"port %d disabled\n", portno);
+			continue;
+		}
+
+		vidsw->endpoint[portno] = endpoint;
+
+		if (portno == vidsw->active)
+			active_link = true;
+	}
+
+	for (portno = 0; portno < numports - 1; portno++) {
+		if (!vidsw->endpoint[portno].base.local_node)
+			continue;
+
+		/* If the active input is not connected, use another */
+		if (!active_link) {
+			vidsw_set_active(vidsw, portno);
+			active_link = true;
+		}
+	}
+
Quoted 8 lines

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

Quoted 4 lines
drivers/media/platform/video-multiplexer.c new file +4 -0
+	return v4l2_async_register_subdev(&vidsw->subdev);
+}
+
+int vidsw_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg)

We should get rid of g_mbus_config() in the long run, but as we don't have the alternative (frame descriptors) isn't up to the job yet I guess it's ok. I don't think we'll have too many users for the video switch right now.

Ok, we can add a comment to mark this as undesirable.

Quoted 67 lines
Quoted 51 lines
drivers/media/platform/video-multiplexer.c new file +51 -0
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct media_pad *pad;
+	int ret;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "no configuration for inactive mux\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Retrieve media bus configuration from the entity connected to the
+	 * active input
+	 */
+	pad = media_entity_remote_pad(&vidsw->pads[vidsw->active]);
+	if (pad) {
+		sd = media_entity_to_v4l2_subdev(pad->entity);
+		ret = v4l2_subdev_call(sd, video, g_mbus_config, cfg);
+		if (ret == -ENOIOCTLCMD)
+			pad = NULL;
+		else if (ret < 0) {
+			dev_err(sd->dev, "failed to get source configuration\n");
+			return ret;
+		}
+	}
+	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;
+	}
+
+	return 0;
+}
+
+static int vidsw_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_subdev *upstream_sd;
+	struct media_pad *pad;
+
+	if (vidsw->active == -1) {
+		dev_err(sd->dev, "Can not start streaming on inactive mux\n");
+		return -EINVAL;
+	}
+
+	pad = media_entity_remote_pad(&sd->entity.pads[vidsw->active]);
+	if (!pad) {
+		dev_err(sd->dev, "Failed to find remote source pad\n");
+		return -ENOLINK;

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	}
+
+	if (!is_media_entity_v4l2_subdev(pad->entity)) {
+		dev_err(sd->dev, "Upstream entity is not a v4l2 subdev\n");
+		return -ENODEV;
+	}
+
+	upstream_sd = media_entity_to_v4l2_subdev(pad->entity);
+
+	return v4l2_subdev_call(upstream_sd, video, s_stream, enable);

Now that we'll have more than two drivers involved in the same pipeline it becomes necessary to define the behaviour of s_stream() throughout the pipeline --- i.e. whose responsibility is it to call s_stream() on the sub-devices in the pipeline?

Quoted 3 lines

I can submit a patch for that. I think the way you do it here is good, as it enables the caller to choose the appropriate behaviour, i.e. start the local device before or after the upstream sub-device.

Please do, this should be decided before any more complex inter-driver pipelines show up.

Quoted 36 lines
Quoted 36 lines
drivers/media/platform/video-multiplexer.c new file +36 -0
+}
+
+static const struct v4l2_subdev_video_ops vidsw_subdev_video_ops = {
+	.g_mbus_config = vidsw_g_mbus_config,
+	.s_stream = vidsw_s_stream,
+};
+
+static struct v4l2_mbus_framefmt *
+__vidsw_get_pad_format(struct v4l2_subdev *sd,
+		       struct v4l2_subdev_pad_config *cfg,
+		       unsigned int pad, u32 which)
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+
+	switch (which) {
+	case V4L2_SUBDEV_FORMAT_TRY:
+		return v4l2_subdev_get_try_format(sd, cfg, pad);
+	case V4L2_SUBDEV_FORMAT_ACTIVE:
+		return &vidsw->format_mbus[pad];
+	default:
+		return NULL;
+	}
+}
+
+static int vidsw_get_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
+{
+	sdformat->format = *__vidsw_get_pad_format(sd, cfg, sdformat->pad,
+						   sdformat->which);
+	return 0;
+}
+
+static int vidsw_set_format(struct v4l2_subdev *sd,
+			    struct v4l2_subdev_pad_config *cfg,
+			    struct v4l2_subdev_format *sdformat)
Quoted 8 lines

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

Quoted 6 lines
drivers/media/platform/video-multiplexer.c new file +6 -0
+{
+	struct vidsw *vidsw = v4l2_subdev_to_vidsw(sd);
+	struct v4l2_mbus_framefmt *mbusformat;
+
+	if (sdformat->pad >= vidsw->num_pads)
+		return -EINVAL;

This check is already performed in v4l2-subdev.c.

Excellent.

Quoted 9 lines

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

Quoted 7 lines
drivers/media/platform/video-multiplexer.c new file +7 -0
+
+	mbusformat = __vidsw_get_pad_format(sd, cfg, sdformat->pad,
+					    sdformat->which);
+	if (!mbusformat)
+		return -EINVAL;
+
+	/* Output pad mirrors active input pad, no limitations on input pads */

Source and sink pads.

Ok.

Quoted 32 lines

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

Quoted 1 line
drivers/media/platform/video-multiplexer.c new file +1 -0
+	if (sdformat->pad == (vidsw->num_pads - 1) && vidsw->active >= 0)

I think it'd be cleaner to test for the pad flag instead of the number. Or, add a macro to obtain the source pad number.

Quoted 27 lines
drivers/media/platform/video-multiplexer.c new file +27 -0
+		sdformat->format = vidsw->format_mbus[vidsw->active];
+
+	*mbusformat = sdformat->format;
+
+	return 0;
+}
+
+static struct v4l2_subdev_pad_ops vidsw_pad_ops = {
+	.get_fmt = vidsw_get_format,
+	.set_fmt = vidsw_set_format,
+};
+
+static struct v4l2_subdev_ops vidsw_subdev_ops = {
+	.pad = &vidsw_pad_ops,
+	.video = &vidsw_subdev_video_ops,
+};
+
+static int of_get_reg_field(struct device_node *node, struct reg_field *field)
+{
+	u32 bit_mask;
+	int ret;
+
+	ret = of_property_read_u32(node, "reg", &field->reg);
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-mask", &bit_mask);
Quoted 8 lines

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

Quoted 6 lines
drivers/media/platform/video-multiplexer.c new file +6 -0
+	if (ret < 0)
+		return ret;
+
+	ret = of_property_read_u32(node, "bit-shift", &field->lsb);
+	if (ret < 0)
+		return ret;

I think the above would look nice in a MUX driver. :-)

I'll submit an MMIO / syscon / regmap bitfield mux driver.

Quoted 43 lines
Quoted 24 lines
drivers/media/platform/video-multiplexer.c new file +24 -0
+
+	field->msb = field->lsb + fls(bit_mask) - 1;
+
+	return 0;
+}
+
+static int vidsw_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct of_endpoint endpoint;
+	struct device_node *ep;
+	struct reg_field field;
+	struct vidsw *vidsw;
+	struct regmap *map;
+	unsigned int num_pads;
+	int ret;
+
+	vidsw = devm_kzalloc(&pdev->dev, sizeof(*vidsw), GFP_KERNEL);
+	if (!vidsw)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, vidsw);
+
+	v4l2_subdev_init(&vidsw->subdev, &vidsw_subdev_ops);

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

Quoted 10 lines
drivers/media/platform/video-multiplexer.c new file +10 -0
+	snprintf(vidsw->subdev.name, sizeof(vidsw->subdev.name), "%s",
+			np->name);
+	vidsw->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	vidsw->subdev.dev = &pdev->dev;
+
+	/*
+	 * The largest numbered port is the output port. It determines
+	 * total number of pads
+	 */
+	num_pads = 0;

You can initialise num_pads in variable declaration.

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

Quoted 3 lines
drivers/media/platform/video-multiplexer.c new file +3 -0
+	for_each_endpoint_of_node(np, ep) {
+		of_graph_parse_endpoint(ep, &endpoint);
+		num_pads = max(num_pads, endpoint.port + 1);

Port numbers come directly from DT.

Quoted 3 lines

Shouldn't num_pads be only the number of pads that have links with actual physical connections? I.e. if a device is disabled, it shouldn't be counted here.

If we only create media pads for the connected DT ports with available remote device, there is no 1:1 correspondence between pad number and the physical mux setting anymore, complicating the driver.

Quoted 77 lines
Quoted 77 lines
drivers/media/platform/video-multiplexer.c new file +77 -0
+	}
+
+	if (num_pads < 2) {
+		dev_err(&pdev->dev, "Not enough ports %d\n", num_pads);
+		return -EINVAL;
+	}
+
+	ret = of_get_reg_field(np, &field);
+	if (ret == 0) {
+		map = syscon_node_to_regmap(np->parent);
+		if (!map) {
+			dev_err(&pdev->dev, "Failed to get syscon register map\n");
+			return PTR_ERR(map);
+		}
+
+		vidsw->field = devm_regmap_field_alloc(&pdev->dev, map, field);
+		if (IS_ERR(vidsw->field)) {
+			dev_err(&pdev->dev, "Failed to allocate regmap field\n");
+			return PTR_ERR(vidsw->field);
+		}
+
+		regmap_field_read(vidsw->field, &vidsw->active);
+	} else {
+		if (num_pads > 3) {
+			dev_err(&pdev->dev, "Too many ports %d\n", num_pads);
+			return -EINVAL;
+		}
+
+		vidsw->gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW);
+		if (IS_ERR(vidsw->gpio)) {
+			dev_warn(&pdev->dev,
+				 "could not request control gpio: %d\n", ret);
+			vidsw->gpio = NULL;
+		}
+
+		vidsw->active = gpiod_get_value(vidsw->gpio) ? 1 : 0;
+	}
+
+	vidsw->num_pads = num_pads;
+	vidsw->pads = devm_kzalloc(&pdev->dev, sizeof(*vidsw->pads) * num_pads,
+			GFP_KERNEL);
+	vidsw->format_mbus = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->format_mbus) * num_pads, GFP_KERNEL);
+	vidsw->endpoint = devm_kzalloc(&pdev->dev,
+			sizeof(*vidsw->endpoint) * (num_pads - 1), GFP_KERNEL);
+
+	ret = vidsw_async_init(vidsw, np);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int vidsw_remove(struct platform_device *pdev)
+{
+	struct vidsw *vidsw = platform_get_drvdata(pdev);
+	struct v4l2_subdev *sd = &vidsw->subdev;
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+
+	return 0;
+}
+
+static const struct of_device_id vidsw_dt_ids[] = {
+	{ .compatible = "video-multiplexer", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, vidsw_dt_ids);
+
+static struct platform_driver vidsw_driver = {
+	.probe		= vidsw_probe,
+	.remove		= vidsw_remove,
+	.driver		= {
+		.of_match_table = vidsw_dt_ids,
+		.name = "video-multiplexer",
+	},
Quoted 8 lines

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

Quoted 8 lines
drivers/media/platform/video-multiplexer.c new file +8 -0
+};
+
+module_platform_driver(vidsw_driver);
+
+MODULE_DESCRIPTION("video stream multiplexer");
+MODULE_AUTHOR("Sascha Hauer, Pengutronix");
+MODULE_AUTHOR("Philipp Zabel, Pengutronix");
+MODULE_LICENSE("GPL");

regards
Philipp

#32 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Hi!

Quoted 26 lines
Quoted 4 lines

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

It is not quite clear to me how to design the DT bindings for this. Just splitting the video-multiplexer driver from the mux-mmio / mux-gpio would make it necessary to keep the video-multiplexer node to describe the of-graph bindings. But then we have two different nodes in the DT that describe the same hardware:

	mux: mux {
		compatible = "mux-gpio";
		mux-gpios = <&gpio 0>, <&gpio 1>;
		#mux-control-cells = <0>;
	}

	video-multiplexer {
		compatible = "video-multiplexer"
		mux-controls = <&mux>;

		ports {
			/* ... */
		}
	}
Quoted 3 lines

It would feel more natural to have the ports in the mux node, but then how would the video-multiplexer driver be instanciated, and how would it get to the of-graph nodes?

Device tree representation and code used to implement the muxing driver should be pretty independend, no? Yes, one piece of hardware should have one entry in the device tree, so it should be something like:

video-multiplexer {
compatible = "video-multiplexer-gpio" mux-gpios = <&gpio 0>, <&gpio 1>; #mux-control-cells = <0>;

mux-controls = <&mux>;

ports {
/* ... */
}
}

You should be able to use code in drivers/mux as a library...

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/20170414/381bc993/attachment.sig>
maintainer
#33 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Hi Pavel,

Quoted 28 lines · Pavel Machek

Hi!

Quoted 26 lines
Quoted 4 lines

The MUX framework is already in linux-next. Could you use that instead of adding new driver + bindings that are not compliant with the MUX framework? I don't think it'd be much of a change in terms of code, using the MUX framework appears quite simple.

It is not quite clear to me how to design the DT bindings for this. Just splitting the video-multiplexer driver from the mux-mmio / mux-gpio would make it necessary to keep the video-multiplexer node to describe the of-graph bindings. But then we have two different nodes in the DT that describe the same hardware:

	mux: mux {
		compatible = "mux-gpio";
		mux-gpios = <&gpio 0>, <&gpio 1>;
		#mux-control-cells = <0>;
	}

	video-multiplexer {
		compatible = "video-multiplexer"
		mux-controls = <&mux>;

		ports {
			/* ... */
		}
	}
Quoted 7 lines
Quoted 3 lines

It would feel more natural to have the ports in the mux node, but then how would the video-multiplexer driver be instanciated, and how would it get to the of-graph nodes?

Device tree representation and code used to implement the muxing driver should be pretty independend, no? Yes, one piece of hardware should have one entry in the device tree,

I agree.

Review

Quoted 13 lines

so it should be something like:

(quoted diff) +0 -0
 	video-multiplexer {
 		compatible = "video-multiplexer-gpio"	
 		mux-gpios = <&gpio 0>, <&gpio 1>;
 		#mux-control-cells = <0>;
 
 		mux-controls = <&mux>;
 
 		ports {
 			/* ... */
 		}
 	}

That self-referencing mux-controls property looks a bit superfluous:

	mux: video-multiplexer {
		mux-controls = <&mux>;
	};

Other than that, I'm completely fine with splitting the compatible into something like video-mux-gpio and video-mux-mmio and reusing the mux-gpios property for video-mux-gpio.

Quoted 1 line

You should be able to use code in drivers/mux as a library...

This is a good idea in principle, but this requires some rework of the mux subsystem, and that subsystem hasn't even landed yet. For now I'd like to focus on getting the DT bindings right.

I'd honestly prefer to not add this rework as a requirement for the i.MX media drivers to get into staging.

regards
Philipp

#34 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Hi!

Quoted 9 lines

That self-referencing mux-controls property looks a bit superfluous:

	mux: video-multiplexer {
		mux-controls = <&mux>;
	};

Other than that, I'm completely fine with splitting the compatible into something like video-mux-gpio and video-mux-mmio and reusing the mux-gpios property for video-mux-gpio.

Agreed, I overseen that.

Quoted 8 lines
Quoted 1 line

You should be able to use code in drivers/mux as a library...

This is a good idea in principle, but this requires some rework of the mux subsystem, and that subsystem hasn't even landed yet. For now I'd like to focus on getting the DT bindings right.

I'd honestly prefer to not add this rework as a requirement for the i.MX media drivers to get into staging.

Hmm. staging/ normally accepts code with bigger design problems than that.

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/20170418/1c115102/attachment.sig>
#35 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

In reply to Steve Longerbeam

Hi!

Quoted 4 lines

+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer <[email protected]>
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel <[email protected]>

This is actually quite interesting. Same email address for two people...

Plus, I believe this wants to say that copyright is with Pengutronix, not Sascha and Philipp. In that case you probably want to list copyright and authors separately?

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/20170405/09cc8ef6/attachment.sig>
#36 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Am Mittwoch, den 05.04.2017, 13:18 +0200 schrieb Pavel Machek:

Quoted 7 lines

Hi!

Quoted 4 lines

+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer <[email protected]>
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel <[email protected]>

Quoted 7 lines

This is actually quite interesting. Same email address for two people...

Plus, I believe this wants to say that copyright is with Pengutronix, not Sascha and Philipp. In that case you probably want to list copyright and authors separately?

Nope, copyright doesn't get transferred to the employer within the rules of the German "Urheberrecht", but stays at the original author of the code.
Same email is just to ensure that any requests regarding this code get routed to the right people, even if someone leaves the company or is temporarily unavailable. kernel@ is a list for the Pengutronix kernel team.

Regards,
Lucas

#37 lore raw

Re: [PATCH v6 17/39] platform: add video-multiplexer subdevice driver

Quoted 11 lines · Lucas Stach

Am Mittwoch, den 05.04.2017, 13:18 +0200 schrieb Pavel Machek:

Quoted 10 lines

Hi!

Quoted 4 lines

+ * video stream multiplexer controlled via gpio or syscon
+ *
+ * Copyright (C) 2013 Pengutronix, Sascha Hauer <[email protected]>
+ * Copyright (C) 2016 Pengutronix, Philipp Zabel <[email protected]>

This is actually quite interesting. Same email address for two people...

Quoted 7 lines
Quoted 4 lines

Plus, I believe this wants to say that copyright is with Pengutronix, not Sascha and Philipp. In that case you probably want to list copyright and authors separately?

Nope, copyright doesn't get transferred to the employer within the rules of the German "Urheberrecht", but stays at the original author of the code.

Ok, then I guess it should be

Copyright (C) 2013 Sascha Hauer
Work sponsored by Pengutronix, use <[email protected]> as contact address

or something? I know license change is not on the table, but I guess it is good to get legal stuff right.
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/20170405/ebfb44c4/attachment.sig>
author maintainer
#38 lore raw

PATCH v6 18/39 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 events and v4l2 controls for the i.MX v4l2 subdevices.

---
 include/linux/imx-media.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 include/linux/imx-media.h
include/linux/imx-media.h new file +27 -0
new file mode 100644
index 0000000..267777f
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2014-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
+ */
+
+#ifndef __LINUX_IMX_MEDIA_H__
+#define __LINUX_IMX_MEDIA_H__
+
+/*
+ * events from the subdevs
+ */
+#define V4L2_EVENT_IMX_CLASS                V4L2_EVENT_PRIVATE_START
+#define V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR (V4L2_EVENT_IMX_CLASS + 1)
+
+enum imx_ctrl_id {
+	V4L2_CID_IMX_FIM_ENABLE = (V4L2_CID_USER_IMX_BASE + 0),
+	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
#39 lore raw

PATCH v6 19/39 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           | 590 ++++++++++++++++++
 drivers/staging/media/Kconfig                     |   2 +
 drivers/staging/media/Makefile                    |   1 +
 drivers/staging/media/imx/Kconfig                 |   6 +
 drivers/staging/media/imx/Makefile                |   5 +
 drivers/staging/media/imx/TODO                    |  17 +
 drivers/staging/media/imx/imx-media-dev.c         | 503 ++++++++++++++++
 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       | 704 ++++++++++++++++++++++
 drivers/staging/media/imx/imx-media.h             | 297 +++++++++
 include/media/imx.h                               |  15 +
 include/uapi/linux/v4l2-controls.h                |   4 +
 14 files changed, 3231 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 +590 -0
new file mode 100644
index 0000000..c508d5b
@@ -0,0 +1,590 @@
+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. 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.
+
+
+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, with a node name of the format "ipuX_csiY capture".
+
+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.
+
+This subdev can generate the following event:
+
+- V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR
+
+The user application can subscribe to this event from the ipuX_csiY
+subdev node. This event is generated by the Frame Interval Monitor
+(see below for more on the FIM).
+
+Cropping in ipuX_csiY
+---------------------
+
+The CSI supports cropping the incoming raw sensor frames. This is
+implemented in the ipuX_csiY entities at the sink pad, using the
+crop selection subdev API.
+
+The CSI also supports fixed divide-by-two downscaling indepently in
+width and height. This is implemented in the ipuX_csiY entities at
+the sink pad, using the compose selection subdev API.
+
+The output rectangle at the ipuX_csiY source pad is the same as
+the compose rectangle at the sink pad. So the source pad rectangle
+cannot be negotiated, it must be set using the compose selection
+API at sink pad (if /w downscale is desired, otherwise source pad
+rectangle is equal to incoming rectangle).
+
+To give an example of crop and /2 downscale, this will crop a
+1280x960 input frame to 640x480, and then /2 downscale in both
+dimensions to 320x240 (assumes ipu1_csi0 is linked to ipu1_csi0_mux):
+
+media-ctl -V "'ipu1_csi0_mux':2[fmt:UYVY2X8/1280x960]"
+media-ctl -V "'ipu1_csi0':0[crop:(0,0)/640x480]"
+media-ctl -V "'ipu1_csi0':0[compose:(0,0)/320x240]"
+
+Frame Skipping in ipuX_csiY
+---------------------------
+
+The CSI supports frame rate decimation, via frame skipping. Frame
+rate decimation is specified by setting the frame intervals at
+sink and source pads. The ipuX_csiY entity then applies the best
+frame skip setting to the CSI to achieve the desired frame rate
+at the source pad.
+
+The following example reduces an assumed incoming 60 Hz frame
+rate by half at the IDMAC output source pad:
+
+media-ctl -V "'ipu1_csi0':0[fmt:UYVY2X8/640x480 at 1/60]"
+media-ctl -V "'ipu1_csi0':2[fmt:UYVY2X8/640x480 at 1/30]"
+
+Frame Interval Monitor in ipuX_csiY
+-----------------------------------
+
+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, the ipuX_csiY subdev will send the event
+V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR. Userland can register with
+the FIM event notification on the ipuX_csiY subdev device node.
+Userland can issue a streaming restart when this event is received
+to correct the rolling/split image.
+
+The ipuX_csiY subdev 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 measurements to average before comparing against
+the nominal frame interval reported by the sensor. This can reduce noise
+caused by interrupt latency.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MIN
+
+If the averaged intervals fall outside nominal by this amount, in
+microseconds, the V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR event is sent.
+
+- V4L2_CID_IMX_FIM_TOLERANCE_MAX
+
+If any intervals are higher than this value, those 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 interrupt
+latency from high system load.
+
+- V4L2_CID_IMX_FIM_NUM_SKIP
+
+How many frames to skip after a FIM reset or stream restart before
+FIM begins to average intervals.
+
+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 the menu control V4L2_CID_DEINTERLACING_MODE. 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, with a node name of the format
+"ipuX_ic_prpenc capture".
+
+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. Flip
+and rotation are provided via standard V4L2 controls.
+
+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, with a node name of the format
+"ipuX_ic_prpvf capture".
+
+It is identical in operation to ipuX_ic_prpenc, with the same resizing
+and CSC operations and flip/rotation controls. 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 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, via ipuX_csiY IDMAC source pad:
+
+-> ipuX_csiY:2 -> ipuX_csiY capture
+
+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:1 -> 0:ipuX_ic_prp:1 -> 0:ipuX_ic_prpenc:1 ->
+   ipuX_ic_prpenc capture
+
+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:1 -> 0:ipuX_vdic:2 -> 0:ipuX_ic_prp:2 ->
+   0:ipuX_ic_prpvf:1 -> ipuX_ic_prpvf capture
+
+
+Usage Notes
+-----------
+
+To aid in configuration and for backward compatibility with V4L2
+applications that access controls only from video device nodes, the
+capture device interfaces inherit controls from the active entities
+in the current pipeline, so controls can be accessed either directly
+from the subdev or from the active capture device interface. For
+example, the FIM controls are available either from the ipuX_csiY
+subdevs or from the active capture device.
+
+The following are specific usage notes for the 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 (which is
+imx6-mipi-csi2 pad 2), is routed to ipu1_csi1. Both sensors are
+configured to output 640x480, and 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 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:AYUV32/640x480 field:none]"
+   # Configure pads for OV5640 pipeline
+   media-ctl -V "'ov5640 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:AYUV32/640x480 field:none]"
+
+Streaming can then begin independently on the capture device nodes
+"ipu1_csi0 capture" and "ipu1_csi1 capture". The v4l2-ctl tool can
+be used to select any supported YUV pixelformat on the capture device
+nodes, including planar.
+
+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':1 -> '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". The v4l2-ctl tool can be used to select any
+supported YUV or RGB pixelformat on the capture device node.
+
+This platform accepts Composite Video analog inputs to the ADV7180 on
+Ain1 (connector J42).
+
+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, transmitting on MIPI CSI-2 virtual channel 1. $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 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 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. The v4l2-ctl
+tool can be used to select any supported YUV or RGB pixelformat on the
+capture device 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/linux/imx-media.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 <[email protected]>
+
+Copyright (C) 2012-2017 Mentor Graphics Inc.
drivers/staging/media/Kconfig +2 -0
index abd0e2d..31af2a0 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/platform/bcm2835/Kconfig"
drivers/staging/media/Makefile +1 -0
index dc89325..0bfb65d 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_BCM2835)	+= platform/bcm2835/
 obj-$(CONFIG_VIDEO_DM365_VPFE)	+= davinci_vpfe/
drivers/staging/media/imx/Kconfig new file +6 -0
new file mode 100644
index 0000000..62a3c34
@@ -0,0 +1,6 @@
+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 +5 -0
new file mode 100644
index 0000000..ddd7d94
@@ -0,0 +1,5 @@
+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 +17 -0
new file mode 100644
index 0000000..78f78fa
@@ -0,0 +1,17 @@
+
+- Finish v4l2-compliance
+
+- 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.
+
+- 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 imx-media-csi.c to setup the CSI.
+  Laurent Pinchart argues that instead the CSI 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 +503 -0

503 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 +704 -0

704 lines not on this page · raw message

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

73 lines not on this page · raw message

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

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.

maintainer
#40 lore raw

RFC 1/1 imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).
---

 drivers/staging/media/imx/imx-media-dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/staging/media/imx/imx-media-dev.c +9 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct imx_media_dev *imxmd,
 	source_pad = link->local_pad;
 	sink_pad = link->remote_pad;
 
+	/*
+	 * If the source subdev is an analog video decoder with a single source
+	 * port, assume that this port 0 corresponds to the DEMOD_PAD_VID_OUT
+	 * entity pad.
+	 */
+	if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+	    local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+		source_pad = DEMOD_PAD_VID_OUT;
+
 	v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
 		  source->name, source_pad, sink->name, sink_pad);
 
Signature · 1 line
2.11.0
author maintainer
#41 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 10 lines · Philipp Zabel

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Shouldn't the DT bindings define ports for these other pads? I haven't seen this documented anywhere, but shouldn't there be a 1:1 correspondence between DT ports and media pads?

Steve

Quoted 26 lines

---

 drivers/staging/media/imx/imx-media-dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/staging/media/imx/imx-media-dev.c +9 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct imx_media_dev *imxmd,
 	source_pad = link->local_pad;
 	sink_pad = link->remote_pad;
 
+	/*
+	 * If the source subdev is an analog video decoder with a single source
+	 * port, assume that this port 0 corresponds to the DEMOD_PAD_VID_OUT
+	 * entity pad.
+	 */
+	if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+	    local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+		source_pad = DEMOD_PAD_VID_OUT;
+
 	v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
 		  source->name, source_pad, sink->name, sink_pad);
 
maintainer
#42 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 13 lines · Steve Longerbeam
Quoted 10 lines · Philipp Zabel

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Quoted 1 line

Shouldn't the DT bindings define ports for these other pads?

In this case, probably yes for the input pad, certainly no for the VBI/audio pads. See the other mail.

Quoted 2 lines

I haven't seen this documented anywhere, but shouldn't there be a 1:1 correspondence between DT ports and media pads?

Not in general. But imagine a dual HDMI->CSI2 converter, for example. We don't support this yet, but that might reasonably be described in the device tree as a single device with two output ports. But the internal representation would be two completely separate v4l2 subdevices.

regards
Philipp

#43 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

In reply to Philipp Zabel
Quoted 10 lines · Philipp Zabel

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Looking at the patch, it's highlighted another review point with Steve's driver.

Quoted 9 lines
drivers/staging/media/imx/imx-media-dev.c +1 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct imx_media_dev *imxmd,
 	source_pad = link->local_pad;
 	sink_pad = link->remote_pad;
 
+	/*

drivers/staging/media/imx/imx-media-dev.c static int imx_media_create_link(struct imx_media_dev *imxmd, · line 280

Quoted 10 lines
drivers/staging/media/imx/imx-media-dev.c +8 -0
+	 * If the source subdev is an analog video decoder with a single source
+	 * port, assume that this port 0 corresponds to the DEMOD_PAD_VID_OUT
+	 * entity pad.
+	 */
+	if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+	    local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+		source_pad = DEMOD_PAD_VID_OUT;
+
 	v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
 		  source->name, source_pad, sink->name, sink_pad);

What is "local" and what is "remote" here? It seems that, in the case of a link being created with the sensor(etc), it's all back to front.

Eg, I see locally:

imx-media: imx_media_create_link: imx219 0-0010:0 -> imx6-mipi-csi2:0

So here, "source" is the imx219 (the sensor), and sink is "imx6-mipi-csi2" (part of the iMX6 capture.) However, this makes "local_sd" the subdev of the sensor, and "remote_sd" the subdev of the CSI2 interface - which is totally back to front - this code is part of the iMX6 capture system, so "local" implies that it should be part of that, and the "remote" thing would be the sensor.

Hence, this seems completely confused. I'd suggest that:

(a) the "pad->pad.flags & MEDIA_PAD_FL_SINK" test in imx_media_create_link()

    is moved into imx_media_create_links(), and placed here instead:

		for (j = 0; j < num_pads; j++) {
			pad = &local_sd->pad[j];

			if (pad->pad.flags & MEDIA_PAD_FL_SINK)
				continue;

			...
		}

    as the pad isn't going to spontaneously change this flag while we
    consider each individual link.  However, maybe the test should be:

			if (!(pad->pad.flags & MEDIA_PAD_FL_SOURCE))

    ?

(b) the terms "local" and "remote" in imx_media_create_link() are replaced with "source" and "sink" respectively, since this will now be called with a guaranteed source pad.

As for Philipp's solution, I'm not sure what the correct solution for something like this is. It depends how you view "hardware interface" as defined by video-interfaces.txt, and whether the pads on the TVP5150 represent the hardware interfaces. If we take the view that the pads do represent hardware interfaces, then using the reg= property on the port node will solve this problem.

If not, it would mean that we would have to have the iMX capture code scan the pads on the source device, looking for outputs - but that runs into a problem - if the source device has multiple outputs, does the reg= property specify the output pad index or the pad number, and what if one binding for a device specifies it one way and another device's binding specifies it a different way.

There's lots of scope for making things really painful here, and ending up with needing sensor-specific code in capture drivers to work around different decisions on this.

I think someone needs to nail this down, if it's not already too late.

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

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

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

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Looking at the patch, it's highlighted another review point with Steve's driver.

Quoted 9 lines
drivers/staging/media/imx/imx-media-dev.c +1 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct imx_media_dev *imxmd,
 	source_pad = link->local_pad;
 	sink_pad = link->remote_pad;
 
+	/*

drivers/staging/media/imx/imx-media-dev.c static int imx_media_create_link(struct imx_media_dev *imxmd, · line 280

Quoted 10 lines
drivers/staging/media/imx/imx-media-dev.c +8 -0
+	 * If the source subdev is an analog video decoder with a single source
+	 * port, assume that this port 0 corresponds to the DEMOD_PAD_VID_OUT
+	 * entity pad.
+	 */
+	if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+	    local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+		source_pad = DEMOD_PAD_VID_OUT;
+
 	v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
 		  source->name, source_pad, sink->name, sink_pad);

What is "local" and what is "remote" here? It seems that, in the case of a link being created with the sensor(etc), it's all back to front.

Eg, I see locally:

imx-media: imx_media_create_link: imx219 0-0010:0 -> imx6-mipi-csi2:0

So here, "source" is the imx219 (the sensor), and sink is "imx6-mipi-csi2" (part of the iMX6 capture.) However, this makes "local_sd" the subdev of the sensor, and "remote_sd" the subdev of the CSI2 interface - which is totally back to front - this code is part of the iMX6 capture system, so "local" implies that it should be part of that, and the "remote" thing would be the sensor.

Hence, this seems completely confused. I'd suggest that:

(a) the "pad->pad.flags & MEDIA_PAD_FL_SINK" test in imx_media_create_link()

Quoted 13 lines
    is moved into imx_media_create_links(), and placed here instead:

		for (j = 0; j < num_pads; j++) {
			pad = &local_sd->pad[j];

			if (pad->pad.flags & MEDIA_PAD_FL_SINK)
				continue;

			...
		}

    as the pad isn't going to spontaneously change this flag while we
    consider each individual link.

Sure, I can do that. It would avoid iterating unnecessarily through the pad's links if the pad is a sink.

Quoted 6 lines

However, maybe the test should be:

			if (!(pad->pad.flags & MEDIA_PAD_FL_SOURCE))

    ?

maybe that is more intuitive.

Quoted 3 lines

(b) the terms "local" and "remote" in imx_media_create_link() are replaced with "source" and "sink" respectively, since this will now be called with a guaranteed source pad.

Agreed. I'll change the arg and local var names.

Quoted 7 lines

As for Philipp's solution, I'm not sure what the correct solution for something like this is. It depends how you view "hardware interface" as defined by video-interfaces.txt, and whether the pads on the TVP5150 represent the hardware interfaces. If we take the view that the pads do represent hardware interfaces, then using the reg= property on the port node will solve this problem.

And the missing port nodes would have to actually be defined first. According to Philipp they aren't, only a single output port 0.

Quoted 5 lines

If not, it would mean that we would have to have the iMX capture code scan the pads on the source device, looking for outputs - but that runs into a problem - if the source device has multiple outputs, does the reg= property specify the output pad index or the pad number,

And how do we even know the data direction of a DT port. Is it an input, an output, bidirectional? The OF graph parsing in imx-media-of.c can't determine a port's direction if it encounters a device it doesn't recognize that has multiple ports. For now that is not really a problem because upstream from the video mux and csi-2 receiver it's expected there will only be original sources of video with only one source port. But it can become a limitation later. For example a device that has multiple output bus interfaces, which would require multiple output ports.

Steve

Quoted 9 lines

and what if one binding for a device specifies it one way and another device's binding specifies it a different way.

There's lots of scope for making things really painful here, and ending up with needing sensor-specific code in capture drivers to work around different decisions on this.

I think someone needs to nail this down, if it's not already too late.

author maintainer
#45 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 114 lines · Steve Longerbeam
Quoted 58 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Looking at the patch, it's highlighted another review point with Steve's driver.

Quoted 15 lines
drivers/staging/media/imx/imx-media-dev.c +2 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct
 imx_media_dev *imxmd,
     source_pad = link->local_pad;
     sink_pad = link->remote_pad;
 
+    /*
+     * If the source subdev is an analog video decoder with a single

source
+ * port, assume that this port 0 corresponds to the
DEMOD_PAD_VID_OUT

drivers/staging/media/imx/imx-media-dev.c static int imx_media_create_link(struct imx_media_dev *imxmd, · line 280

Quoted 8 lines
drivers/staging/media/imx/imx-media-dev.c +6 -0
+     * entity pad.
+     */
+    if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+        local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+        source_pad = DEMOD_PAD_VID_OUT;
+
     v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
           source->name, source_pad, sink->name, sink_pad);

What is "local" and what is "remote" here? It seems that, in the case of a link being created with the sensor(etc), it's all back to front.

Eg, I see locally:

imx-media: imx_media_create_link: imx219 0-0010:0 -> imx6-mipi-csi2:0

So here, "source" is the imx219 (the sensor), and sink is "imx6-mipi-csi2"
(part of the iMX6 capture.) However, this makes "local_sd" the subdev of the sensor, and "remote_sd" the subdev of the CSI2 interface - which is totally back to front - this code is part of the iMX6 capture system, so "local" implies that it should be part of that, and the "remote" thing would be the sensor.

Hence, this seems completely confused. I'd suggest that:

(a) the "pad->pad.flags & MEDIA_PAD_FL_SINK" test in imx_media_create_link()

Quoted 13 lines
    is moved into imx_media_create_links(), and placed here instead:

        for (j = 0; j < num_pads; j++) {
            pad = &local_sd->pad[j];

            if (pad->pad.flags & MEDIA_PAD_FL_SINK)
                continue;

            ...
        }

    as the pad isn't going to spontaneously change this flag while we
    consider each individual link.

Sure, I can do that. It would avoid iterating unnecessarily through the pad's links if the pad is a sink.

Quoted 6 lines

However, maybe the test should be:

            if (!(pad->pad.flags & MEDIA_PAD_FL_SOURCE))

    ?

maybe that is more intuitive.

Quoted 3 lines

(b) the terms "local" and "remote" in imx_media_create_link() are replaced with "source" and "sink" respectively, since this will now be called with a guaranteed source pad.

Agreed. I'll change the arg and local var names.

Quoted 7 lines

As for Philipp's solution, I'm not sure what the correct solution for something like this is. It depends how you view "hardware interface" as defined by video-interfaces.txt, and whether the pads on the TVP5150 represent the hardware interfaces. If we take the view that the pads do represent hardware interfaces, then using the reg= property on the port node will solve this problem.

And the missing port nodes would have to actually be defined first. According to Philipp they aren't, only a single output port 0.

Quoted 5 lines

If not, it would mean that we would have to have the iMX capture code scan the pads on the source device, looking for outputs - but that runs into a problem - if the source device has multiple outputs, does the reg= property specify the output pad index or the pad number,

Quoted 10 lines

And how do we even know the data direction of a DT port. Is it an input, an output, bidirectional? The OF graph parsing in imx-media-of.c can't determine a port's direction if it encounters a device it doesn't recognize that has multiple ports. For now that is not really a problem because upstream from the video mux and csi-2 receiver it's expected there will only be original sources of video with only one source port. But it can become a limitation later. For example a device that has multiple output bus interfaces, which would require multiple output ports.

Actually what was I thinking, the TVP5150 is already an example of such a device.

All of this could be solved if there was some direction information in port nodes.

Steve

#46 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 128 lines · Steve Longerbeam
Quoted 114 lines · Steve Longerbeam
Quoted 69 lines · Russell King - ARM Linux
Quoted 10 lines · Philipp Zabel

The TVP5150 DT bindings specify a single output port (port 0) that corresponds to the video output pad (pad 1, DEMOD_PAD_VID_OUT).

---
I'm trying to get this to work with a TVP5150 analog TV decoder, and the first problem is that this device doesn't have pad 0 as its single output pad. Instead, as a MEDIA_ENT_F_ATV_DECODER entity, it has for pads (input, video out, vbi out, audio out), and video out is pad 1, whereas the device tree only defines a single port (0).

Looking at the patch, it's highlighted another review point with Steve's driver.

Quoted 15 lines
drivers/staging/media/imx/imx-media-dev.c +2 -0
index 17e2386a3ca3a..c52d6ca797965 100644
@@ -267,6 +267,15 @@ static int imx_media_create_link(struct
 imx_media_dev *imxmd,
    source_pad = link->local_pad;
    sink_pad = link->remote_pad;
 
+    /*
+     * If the source subdev is an analog video decoder with a single

source
+ * port, assume that this port 0 corresponds to the
DEMOD_PAD_VID_OUT

drivers/staging/media/imx/imx-media-dev.c static int imx_media_create_link(struct imx_media_dev *imxmd, · line 280

Quoted 8 lines
drivers/staging/media/imx/imx-media-dev.c +6 -0
+     * entity pad.
+     */
+    if (source->entity.function == MEDIA_ENT_F_ATV_DECODER &&
+        local_sd->num_sink_pads == 0 && local_sd->num_src_pads == 1)
+        source_pad = DEMOD_PAD_VID_OUT;
+
    v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
          source->name, source_pad, sink->name, sink_pad);

What is "local" and what is "remote" here? It seems that, in the case of a link being created with the sensor(etc), it's all back to front.

Eg, I see locally:

imx-media: imx_media_create_link: imx219 0-0010:0 -> imx6-mipi-csi2:0

So here, "source" is the imx219 (the sensor), and sink is "imx6-mipi-csi2"
(part of the iMX6 capture.) However, this makes "local_sd" the subdev of the sensor, and "remote_sd" the subdev of the CSI2 interface - which is totally back to front - this code is part of the iMX6 capture system, so "local" implies that it should be part of that, and the "remote" thing would be the sensor.

Hence, this seems completely confused. I'd suggest that:

(a) the "pad->pad.flags & MEDIA_PAD_FL_SINK" test in imx_media_create_link()
is moved into imx_media_create_links(), and placed here instead:

       for (j = 0; j < num_pads; j++) {
           pad = &local_sd->pad[j];

           if (pad->pad.flags & MEDIA_PAD_FL_SINK)
               continue;

           ...
       }
Quoted 2 lines

as the pad isn't going to spontaneously change this flag while we consider each individual link.

Sure, I can do that. It would avoid iterating unnecessarily through the pad's links if the pad is a sink.

Quoted 6 lines

However, maybe the test should be:

           if (!(pad->pad.flags & MEDIA_PAD_FL_SOURCE))
   ?

maybe that is more intuitive.

Quoted 3 lines

(b) the terms "local" and "remote" in imx_media_create_link() are replaced with "source" and "sink" respectively, since this will now be called with a guaranteed source pad.

Agreed. I'll change the arg and local var names.

Quoted 7 lines

As for Philipp's solution, I'm not sure what the correct solution for something like this is. It depends how you view "hardware interface" as defined by video-interfaces.txt, and whether the pads on the TVP5150 represent the hardware interfaces. If we take the view that the pads do represent hardware interfaces, then using the reg= property on the port node will solve this problem.

And the missing port nodes would have to actually be defined first. According to Philipp they aren't, only a single output port 0.

Quoted 5 lines

If not, it would mean that we would have to have the iMX capture code scan the pads on the source device, looking for outputs - but that runs into a problem - if the source device has multiple outputs, does the reg= property specify the output pad index or the pad number,

Quoted 10 lines

And how do we even know the data direction of a DT port. Is it an input, an output, bidirectional? The OF graph parsing in imx-media-of.c can't determine a port's direction if it encounters a device it doesn't recognize that has multiple ports. For now that is not really a problem because upstream from the video mux and csi-2 receiver it's expected there will only be original sources of video with only one source port. But it can become a limitation later. For example a device that has multiple output bus interfaces, which would require multiple output ports.

Quoted 5 lines

Actually what was I thinking, the TVP5150 is already an example of such a device.

All of this could be solved if there was some direction information in port nodes.

I disagree.

Philipp identified that the TVP5150 has four pads:

* Input pad
* Video output pad
* VBI output pad
* Audio output pad

So, it has one input and three outputs. How does marking the direction in the port node (which would indicate that there was a data flow out of TVP5150 into the iMX6 capture) help identify which of those pads should be used?

It would eliminate the input pad, but you still have three output pads to choose from.

So no, your idea can't work.

As I already stated, I believe that this case is already covered by video-interfaces.txt:

If more than
one port is present in a device node or there is more than one endpoint at a port, or port node needs to be associated with a selected hardware interface,

        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

a common scheme using '#address-cells', '#size-cells' and 'reg' properties is used.

So, according to that, you do not need to have more than one port node to use the reg property - it's _either_ more than one port _or_ to select the hardware interface.

It all hinges on whether you consider the video output, VBI output or audio output to be separate hardware interfaces that the singular specified "port" node needs to select between.

There's another reason why the TVP5150 binding looks wrong and broken, however. How does the audio output get routed to other parts of the system if you're using the video output, and how is that relationship defined? It's a v4l2 subdev pad, so it would need to be part of the v4l2 subdev graph. It sounds to me like the binding was created with a narrow focused "this is the board in front of me, it only has video wired up, I'm not going to consider other use cases" blinkered view.

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

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

On Wed, 2017-04-05 at 09:21 +0100, Russell King - ARM Linux wrote:
[...]

Quoted 6 lines
Quoted 5 lines

Actually what was I thinking, the TVP5150 is already an example of such a device.

All of this could be solved if there was some direction information in port nodes.

Quoted 8 lines

I disagree.

Philipp identified that the TVP5150 has four pads:

* Input pad
* Video output pad
* VBI output pad
* Audio output pad

I didn't think hard enough about this earlier, but there are really only two hardware interfaces on TVP5150. The ADC input, which can be connected to either of two composite input pins (AIP1A, AIP1B), or use both for s-video, and the digital output connected to pins (YOUT[7:0]).

VBI data can be transferred via the output pins during horizontal or vertical blanking, if I understand correctly, or read from a FIFO via I2C.

There is no apparent support for audio data whatsoever, and the only mention of audio in the data manual is a vague reference about an "audio interface available on the TVP5150" providing a clock to an audio interface between an external audio decoder and the backend processor.

Further, commit 55606310e77f ("[media] tvp5150: create the expected number of pads") creates DEMOD_NUM_PADS pads, but doesn't mention or initialize the audio pad. It clearly expects the value of DEMOD_NUM_PADS to be 3. And indeed the fourth pad was added later in commit bddc418787cc ("[media] au0828: use standard demod pads struct").

So to me it looks like the VBI and audio pads should be removed from TVP5150.

Quoted 9 lines

So, it has one input and three outputs. How does marking the direction in the port node (which would indicate that there was a data flow out of TVP5150 into the iMX6 capture) help identify which of those pads should be used?

It would eliminate the input pad, but you still have three output pads to choose from.

So no, your idea can't work.

In this case, removal of the VBI and audio pads might make this work, but in general this is true. In my opinion, to make this truly generic, we need an interface to ask the driver which media entity pad a given device tree port corresponds to, as there might not even be a single media entity corresponding to all ports for more complex devices.

Quoted 6 lines

As I already stated, I believe that this case is already covered by video-interfaces.txt:

If more than
one port is present in a device node or there is more than one endpoint at a port, or port node needs to be associated with a selected hardware interface,

Quoted 7 lines
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

a common scheme using '#address-cells', '#size-cells' and 'reg' properties is used.

So, according to that, you do not need to have more than one port node to use the reg property - it's _either_ more than one port _or_ to select the hardware interface.

I don't think enforcing a 1:1 correspondence between device tree node and media entity and enforcing port reg property == entity pad index is a good idea in the long run. Binding errors are going to be made that will have to be worked around at the driver level, and more complex devices might have to create multiple media entities / v4l2 subdevices with external ports that interface with the of graph.

Quoted 11 lines

It all hinges on whether you consider the video output, VBI output or audio output to be separate hardware interfaces that the singular specified "port" node needs to select between.

There's another reason why the TVP5150 binding looks wrong and broken, however. How does the audio output get routed to other parts of the system if you're using the video output, and how is that relationship defined? It's a v4l2 subdev pad, so it would need to be part of the v4l2 subdev graph. It sounds to me like the binding was created with a narrow focused "this is the board in front of me, it only has video wired up, I'm not going to consider other use cases" blinkered view.

I think the output part is accurate, as the audio pad is an artifact of an unrelated change. I'm not so sure about the VBI pad, but I think that shouldn't exist either. The input pad, on the other hand, not having any of graph representation in the device tree seems a bit strange. There was a custom binding for the inputs, that got quickly reverted:
https://patchwork.kernel.org/patch/8395521/

regards
Philipp

#48 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Hello Philipp,

Quoted 1 line · Philipp Zabel

On Wed, 2017-04-05 at 09:21 +0100, Russell King - ARM Linux wrote:

[snip]

Quoted 4 lines

I think the output part is accurate, as the audio pad is an artifact of an unrelated change. I'm not so sure about the VBI pad, but I think that shouldn't exist either. The input pad, on the other hand, not having any of graph representation in the device tree seems a bit strange. There

Agreed, there should be a OF graph representation (and also a MC representation) of the input PADs.

The tvp5150 driver currently has hardcoded as input TVP5150_COMPOSITE1 (AIP1B), so it won't work for a board that has the composite connector wired to TVP5150_COMPOSITE0 (AIP1A) neither will work for S-Video (AIP1A + AIP1B).

Quoted 3 lines

was a custom binding for the inputs, that got quickly reverted:
https://patchwork.kernel.org/patch/8395521/

Yes, that was my first attempt to have input connector support for tvp5150. The patches were merged without a detailed review of the DT bindings and latter were found to be wrong. Instead of having a driver specific DT binding, a generic binding that could be used by any device should be defined.

The latest proposal was [0] but that was also found to be inadequate. After a lot of discussion on #v4l, the best approach we could come with was something like like [1]. But I was busy with other stuff and never found time to do the driver changes.

By the way, only the DT bindings portion from the first approach got reverted but the patch reverting the driver changes never made to mainline. Could you please test if [2] doesn't cause any issues to you so the left over can be finally removed?

Quoted 3 lines

regards
Philipp

[0]: https://lkml.org/lkml/2016/4/12/983
[1]: https://hastebin.com/kadagidino.diff
[2]: https://patchwork.kernel.org/patch/9472623/

Best regards,
Javier

#49 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

In reply to Philipp Zabel

Em Wed, 05 Apr 2017 11:34:19 +0200
Philipp Zabel <[email protected]> escreveu:

Quoted 31 lines · Russell King - ARM Linux

[...]

Quoted 6 lines
Quoted 5 lines

Actually what was I thinking, the TVP5150 is already an example of such a device.

All of this could be solved if there was some direction information in port nodes.

Quoted 8 lines

I disagree.

Philipp identified that the TVP5150 has four pads:

* Input pad
* Video output pad
* VBI output pad
* Audio output pad

I didn't think hard enough about this earlier, but there are really only two hardware interfaces on TVP5150. The ADC input, which can be connected to either of two composite input pins (AIP1A, AIP1B), or use both for s-video, and the digital output connected to pins (YOUT[7:0]).

VBI data can be transferred via the output pins during horizontal or vertical blanking, if I understand correctly, or read from a FIFO via I2C.

There is no apparent support for audio data whatsoever, and the only mention of audio in the data manual is a vague reference about an "audio interface available on the TVP5150" providing a clock to an audio interface between an external audio decoder and the backend processor.

Quoted 8 lines

Further, commit 55606310e77f ("[media] tvp5150: create the expected number of pads") creates DEMOD_NUM_PADS pads, but doesn't mention or initialize the audio pad. It clearly expects the value of DEMOD_NUM_PADS to be 3. And indeed the fourth pad was added later in commit bddc418787cc ("[media] au0828: use standard demod pads struct").

So to me it looks like the VBI and audio pads should be removed from TVP5150.

There are a number of drivers that can work with different types of TV demodulators. Typical examples of such hardware can be found at em28xx, saa7134, cx88 drivers (among lots of other drivers). Those drivers don't use the subdev API. Instead, they use a generic helper function with sets the pipelines, based on the pad number.

The problem here is that, currently, both MC API and MC core lacks a way to identify PAD ports per type, as the only information that a bridge driver has is a pad number. So, in order for a generic helper function to work, we had to hardcode pad numbers, in a way that it would work for all possible types of demods.

It shouldn't be hard to add a "pad_type" information at media_pad struct, but passing such info to userspace requires a new API (we're calling it as "properties API"). Sakari was meant to send us an updated RFC for it[1] with a patchset, back in 2015, but this never happened.

[1] https://linuxtv.org/news.php?entry=2015-08-17.mchehab

Each vendor chooses the demod using some random criteria (usually, they use whatever costs less by the time they create a hardware model). Newer versions of the same hardware frequently has a different model.

For example, in the case of em28xx driver, there are currently several types of demods supported there, like (among other options):

- demods with tda9887, with is actually part of a tuner that has an outputs for IF luminance, IF chrominance and IF audio;

- demods with xc3028, with is an integrated tuner + audio demod, with outputs both video as a baseband signal and audio data via IF, (or outputs a single IF signal, for Digital TV);

- demods with both xc3028 and msp3400. The last one transforms audio IF into I2S;

- demods with saa711x (supported by saa7115 driver), with may or may not have raw VBI and/or sliced VBI, depending on the specific model, with is detected during driver's probe.

The generic function should be robust enough to handle all above cases.

Without a way to report the PAD type to userspace, applications that need to setup or recognize such pipelines need to hardcode the pad numbers on userspace. That's, by the way, one of the issues why it is currently impossible to write a full generic MC plugin at libv4l:
there's currently no way for userspace to recognize what type of signals each PAD input or output carries.

So, in short, the tvp5150 demod doesn't decode audio, but there are other demods that do it.

In the case of VBI, tvp5150 has actually two ways of reporting it:

1) via YOUT[7:0] pins. VBI information is transmitted as a set of raw samples, via an ancillary data block, during vertical/horizontal blanking intervals. So, yes, it shares the same hardware output, although the VBI contents are actually multiplexed there. Please notice that not all video out PADS encapsulate raw VBI the same way as tvp5150 (and some devices even don't support raw VBI, like saa7110 and some models supported by saa7115 driver).

2) via an interrupt that indicates that it decoded VBI data. The VBI information itself is there on FIFO, accessible via a set of registers (see "VBI Data processor" chapter at the datasheet).

Currently, the driver doesn't support (2), because, at the time I wrote the driver, I didn't find a way to read the interrupts generated by tvp5150 at em28xx[1], due to the lack of em28xx documentation, but adding support for it shoudn't be hard. I may eventually do it when I have some time to play with my ISEE hardware.

So, in the case of tvp5150 hardware, have those PADS:

- Input baseband;
- Video + raw VBI output;
- sliced VBI output.

Yet, we need an always unconnected audio output, in order to support different demods out there.

[1] tvp5150 was written to support some em28xx-based devices

Quoted 9 lines
Quoted 9 lines

So, it has one input and three outputs. How does marking the direction in the port node (which would indicate that there was a data flow out of TVP5150 into the iMX6 capture) help identify which of those pads should be used?

It would eliminate the input pad, but you still have three output pads to choose from.

Quoted 7 lines
Quoted 1 line

So no, your idea can't work.

In this case, removal of the VBI and audio pads might make this work, but in general this is true. In my opinion, to make this truly generic, we need an interface to ask the driver which media entity pad a given device tree port corresponds to, as there might not even be a single media entity corresponding to all ports for more complex devices.

Yes. We also need something like that at the userspace API.

Thanks,
Mauro

#50 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 5 lines

Currently, the driver doesn't support (2), because, at the time I wrote the driver, I didn't find a way to read the interrupts generated by tvp5150 at em28xx[1], due to the lack of em28xx documentation, but adding support for it shoudn't be hard. I may eventually do it when I have some time to play with my ISEE hardware.

For what it's worth, I doubt most of the em28xx designs have the tvp5150 interrupt request line connected in any way. You would likely have to poll the FIFO status register via I2C, or use the feature to embed the sliced data into as VANC data in the 656 output (as described in sec 3.9 of the tvp5150am1 spec).

Devin

Signature · 2 lines
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
#51 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Em Wed, 5 Apr 2017 11:39:06 -0400
Devin Heitmueller <[email protected]> escreveu:

Quoted 8 lines
Quoted 5 lines

Currently, the driver doesn't support (2), because, at the time I wrote the driver, I didn't find a way to read the interrupts generated by tvp5150 at em28xx[1], due to the lack of em28xx documentation, but adding support for it shoudn't be hard. I may eventually do it when I have some time to play with my ISEE hardware.

For what it's worth, I doubt most of the em28xx designs have the tvp5150 interrupt request line connected in any way.

True. But, on embedded hardware, such line may be connected into the SoC. Actually, from the IGEPv3 expansion diagram:

https://www.isee.biz/support/downloads/item/igepv2-expansion-rc-schematics

The INT line is connected to CAM_IRQ. That's connected to GPIO_154 pin at OMAP3.

So, on a first glance, it seems possible to use it, instead of polling.

Quoted 2 lines

You would likely
have to poll the FIFO status register via I2C,

Yes, I considered this option when I wrote the driver. It could work, although it would likely have some performance drawback, as the driver would need to poll it at least 60 times per second.

Quoted 3 lines

or use the feature to
embed the sliced data into as VANC data in the 656 output (as described in sec 3.9 of the tvp5150am1 spec).

True, but the bridge driver would need to handle such data.

I remember I looked on this when I wrote the driver, but I was unable to find a way for em28xx to parse (or forward) such data packets.

Thanks,
Mauro

#52 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Quoted 6 lines
Quoted 2 lines

For what it's worth, I doubt most of the em28xx designs have the tvp5150 interrupt request line connected in any way.

True. But, on embedded hardware, such line may be connected into the SoC. Actually, from the IGEPv3 expansion diagram:

Quoted 6 lines

https://www.isee.biz/support/downloads/item/igepv2-expansion-rc-schematics

The INT line is connected to CAM_IRQ. That's connected to GPIO_154 pin at OMAP3.

So, on a first glance, it seems possible to use it, instead of polling.

To be clear, I wasn't suggesting that the IRQ request line on the tvp5150 couldn't be supported in general (for example, for those embedded targets which have it wired up to a host processor). I'm just saying you shouldn't expect it to work on most (perhaps all) em28xx designs which have the tvp5150. In fact on some em28xx designs the pin is used as a GPIO output tied to a mux to control input selection. Hence blindly enabling the interrupt request line by default would do all sorts of bad things.

Quoted 7 lines
Quoted 2 lines

You would likely
have to poll the FIFO status register via I2C,

Yes, I considered this option when I wrote the driver. It could work, although it would likely have some performance drawback, as the driver would need to poll it at least 60 times per second.

Quoted 5 lines
Quoted 3 lines

or use the feature to
embed the sliced data into as VANC data in the 656 output (as described in sec 3.9 of the tvp5150am1 spec).

True, but the bridge driver would need to handle such data.

Correct.

Quoted 3 lines

I remember I looked on this when I wrote the driver, but I was unable to find a way for em28xx to parse (or forward) such data packets.

I'm pretty sure it's possible, but I haven't looked at the datasheets in a number of years and don't recall the details.

Hardware VBI splicing is supported by a number of decoders but it's rarely used on commodity PCs (the Conexant and NXP decoders support it as well). That said, I won't argue there might be some value on really low end platforms. All I would ask is that if you do introduce any such functionality into the tvp5150 driver for some embedded application that you please not break support for devices such as the em28xx.

Thanks,

Devin

Signature · 2 lines
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
#53 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

Em Wed, 5 Apr 2017 13:02:52 -0400
Devin Heitmueller <[email protected]> escreveu:

Quoted 7 lines
Quoted 3 lines

I remember I looked on this when I wrote the driver, but I was unable to find a way for em28xx to parse (or forward) such data packets.

I'm pretty sure it's possible, but I haven't looked at the datasheets in a number of years and don't recall the details.

Quoted 7 lines

Hardware VBI splicing is supported by a number of decoders but it's rarely used on commodity PCs (the Conexant and NXP decoders support it as well). That said, I won't argue there might be some value on really low end platforms. All I would ask is that if you do introduce any such functionality into the tvp5150 driver for some embedded application that you please not break support for devices such as the em28xx.

Yeah, sure. If I write such patchset[1], it will be optional, and will depend on a DT variable (or platform_data) setup that would tell what GPIO pin should be used for interrupt.

Not providing it should either disable such feature or enable it via polling.

[1] Please notice that I don't have any demand of doing it. Yet, I may do it for fun on my spare time:-)

I added in the past an initial support for sliced VBI API on em28xx, with got reverted on changeset 1d179eeedc8cb48712bc236ec82ec6c63af42008, mainly due to the lack of such feature on tvp5150. So, such code was never tested (and likely need fixes/updates), but if I end by adding sliced VBI support on tvp5150 and on OMAP3, I may add support for it on em28xx too, using I2C poll. On such case, I'll likely add a modprobe parameter to enable such feature.

Thanks,
Mauro

maintainer
#54 lore raw

Re: [RFC] [media] imx: assume MEDIA_ENT_F_ATV_DECODER entities output video on pad 1

In reply to Mauro Carvalho Chehab

On Wed, 2017-04-05 at 11:53 -0300, Mauro Carvalho Chehab wrote:
[...]

Quoted 12 lines

There are a number of drivers that can work with different types of TV demodulators. Typical examples of such hardware can be found at em28xx, saa7134, cx88 drivers (among lots of other drivers). Those drivers don't use the subdev API. Instead, they use a generic helper function with sets the pipelines, based on the pad number.

The problem here is that, currently, both MC API and MC core lacks a way to identify PAD ports per type, as the only information that a bridge driver has is a pad number. So, in order for a generic helper function to work, we had to hardcode pad numbers, in a way that it would work for all possible types of demods.

Quoted 7 lines

It shouldn't be hard to add a "pad_type" information at media_pad struct, but passing such info to userspace requires a new API (we're calling it as "properties API"). Sakari was meant to send us an updated RFC for it[1] with a patchset, back in 2015, but this never happened.

[1] https://linuxtv.org/news.php?entry=2015-08-17.mchehab

[...]

That would be most useful.

Quoted 6 lines

So, in short, the tvp5150 demod doesn't decode audio, but there are other demods that do it.

In the case of VBI, tvp5150 has actually two ways of reporting it:

Quoted 8 lines

1) via YOUT[7:0] pins. VBI information is transmitted as a set of raw samples, via an ancillary data block, during vertical/horizontal blanking intervals. So, yes, it shares the same hardware output, although the VBI contents are actually multiplexed there. Please notice that not all video out PADS encapsulate raw VBI the same way as tvp5150 (and some devices even don't support raw VBI, like saa7110 and some models supported by saa7115 driver).

This is the physical interface that corresponds to the output port (should be port at 1) in the device tree. It should correspond to the video output media entity pad.
What is unclear to is me whether the VBI media entity pad also should correspond to the same physical interface / DT port.

Quoted 10 lines

2) via an interrupt that indicates that it decoded VBI data. The VBI information itself is there on FIFO, accessible via a set of registers (see "VBI Data processor" chapter at the datasheet).

Currently, the driver doesn't support (2), because, at the time I wrote the driver, I didn't find a way to read the interrupts generated by tvp5150 at em28xx[1], due to the lack of em28xx documentation, but adding support for it shoudn't be hard. I may eventually do it when I have some time to play with my ISEE hardware.

Quoted 5 lines

So, in the case of tvp5150 hardware, have those PADS:

- Input baseband;
- Video + raw VBI output;
- sliced VBI output.

This DEMOD_PAD_VBI_OUT, does it correspond to 1) or 2) above?

Quoted 2 lines

Yet, we need an always unconnected audio output, in order to support different demods out there.

Are you saying we have to keep pad[DEMOD_PAD_AUDIO_OUT] in tvp5150 even though it doesn't exist because the framework can't cope with an audio-less ATV_DECODER that only has three pads?

Quoted 13 lines

[1] tvp5150 was written to support some em28xx-based devices

Quoted 11 lines
Quoted 10 lines

So, it has one input and three outputs. How does marking the direction in the port node (which would indicate that there was a data flow out of TVP5150 into the iMX6 capture) help identify which of those pads should be used?

It would eliminate the input pad, but you still have three output pads to choose from.

So no, your idea can't work.

Quoted 7 lines
Quoted 5 lines

In this case, removal of the VBI and audio pads might make this work, but in general this is true. In my opinion, to make this truly generic, we need an interface to ask the driver which media entity pad a given device tree port corresponds to, as there might not even be a single media entity corresponding to all ports for more complex devices.

Yes. We also need something like that at the userspace API.

thanks
Philipp

#55 lore raw

Re: [PATCH v6 19/39] media: Add i.MX media core driver

In reply to Steve Longerbeam

Hi!

Quoted 1 line

+https://boundarydevices.com/products/nit6x_5mp

I'd use /product/ in url, as it redirects there.

Quoted 1 line

+https://boundarydevices.com/product/nit6x_5mp_mipi

..and for consistency.

Quoted 14 lines
Documentation/media/v4l-drivers/imx.rst new file +14 -0
+The following example configures a direct conversion pipeline to capture
+from the OV5640, transmitting on MIPI CSI-2 virtual channel 1. $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 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]"

Documentation/media/v4l-drivers/imx.rst line 556

Quoted 10 lines
Documentation/media/v4l-drivers/imx.rst new file +10 -0
+   # Configure pads
+   media-ctl -V "'ov5640 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. The v4l2-ctl
+tool can be used to select any supported YUV or RGB pixelformat on the
+capture device node.

Nothing for you to fix here, but we should really create some library-like interface for media-ctl.
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/20170405/028b8853/attachment-0001.sig>
#56 lore raw

Re: [PATCH v6 19/39] media: Add i.MX media core driver

In reply to Steve Longerbeam

Hi!

Documentation/media/v4l-drivers/imx.rst line 581

Quoted 5 lines
Documentation/media/v4l-drivers/imx.rst new file +5 -0
+References
+----------
+
+[1] "i.MX 6Dual/6Quad Applications Processor Reference Manual"
+[2] "i.MX 6Solo/6DualLite Applications Processor Reference Manual"

[2] is not present in the text above. [1] is there many times. What is purpose of this section?
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/20170405/0d7064c6/attachment.sig>
maintainer
#57 lore raw

Re: [PATCH v6 19/39] 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.

[...]

Quoted 6 lines
drivers/staging/media/imx/imx-media-of.c new file +0 -0
new file mode 100644
index 0000000..b383be4
@@ -0,0 +1,267 @@

[...]

Quoted 12 lines
drivers/staging/media/imx/imx-media-of.c new file +12 -0
+/*
+ * find the remote device node and remote port id (remote pad #)
+ * given local endpoint node
+ */
+static void of_get_remote_pad(struct device_node *epnode,
+			      struct device_node **remote_node,
+			      int *remote_pad)
+{
+	struct device_node *rp, *rpp;
+	struct device_node *remote;
+
+	rp = of_graph_get_remote_port(epnode);

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-of.c new file +10 -0
+	rpp = of_graph_get_remote_port_parent(epnode);
+
+	if (of_device_is_compatible(rpp, "fsl,imx6q-ipu")) {
+		/* the remote is one of the CSI ports */
+		remote = rp;
+		*remote_pad = 0;
+		of_node_put(rpp);
+	} else {
+		remote = rpp;
+		of_property_read_u32(rp, "reg", remote_pad);

If this fails because there is no reg property, *remote_pad will keep the previous value. It should be set to 0 in this case.

----------8<----------

drivers/staging/media/imx/imx-media-of.c +3 -1
@@ -85,7 +85,9 @@ static void of_get_remote_pad(struct device_node *epnode,
                of_node_put(rpp);
        } else {
                remote = rpp;
-               of_property_read_u32(rp, "reg", remote_pad);
+               /* FIXME port number and pad index are not the same */
+               if (of_property_read_u32(rp, "reg", remote_pad))
+                       *remote_pad = 0;
                of_node_put(rp);
        }
 

---------->8----------

regards
Philipp

author maintainer
#58 lore raw

Re: [PATCH v6 19/39] media: Add i.MX media core driver

Quoted 29 lines · Philipp Zabel
Quoted 3 lines · Steve Longerbeam

Add the core media driver for i.MX SOC.

[...]

Quoted 6 lines
drivers/staging/media/imx/imx-media-of.c new file +0 -0
new file mode 100644
index 0000000..b383be4
@@ -0,0 +1,267 @@

[...]

Quoted 17 lines
drivers/staging/media/imx/imx-media-of.c new file +17 -0
+/*
+ * find the remote device node and remote port id (remote pad #)
+ * given local endpoint node
+ */
+static void of_get_remote_pad(struct device_node *epnode,
+			      struct device_node **remote_node,
+			      int *remote_pad)
+{
+	struct device_node *rp, *rpp;
+	struct device_node *remote;
+
+	rp = of_graph_get_remote_port(epnode);
+	rpp = of_graph_get_remote_port_parent(epnode);
+
+	if (of_device_is_compatible(rpp, "fsl,imx6q-ipu")) {
+		/* the remote is one of the CSI ports */
+		remote = rp;
Quoted 8 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-of.c new file +5 -0
+		*remote_pad = 0;
+		of_node_put(rpp);
+	} else {
+		remote = rpp;
+		of_property_read_u32(rp, "reg", remote_pad);

If this fails because there is no reg property, *remote_pad will keep the previous value. It should be set to 0 in this case.

Ok, I will apply this change.

Steve

Quoted 20 lines

----------8<----------

drivers/staging/media/imx/imx-media-of.c +3 -2
@@ -85,7 +85,9 @@ static void of_get_remote_pad(struct device_node *epnode,
                of_node_put(rpp);
        } else {
                remote = rpp;
-               of_property_read_u32(rp, "reg", remote_pad);
+               /* FIXME port number and pad index are not the same */
+               if (of_property_read_u32(rp, "reg", remote_pad))
+                       *remote_pad = 0;
                of_node_put(rp);
        }
 
---------->8----------

regards
Philipp

author maintainer
#59 lore raw

PATCH v6 20/39 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            |   1 +
 drivers/staging/media/imx/imx-media-capture.c | 663 ++++++++++++++++++++++++++
 2 files changed, 664 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-capture.c
drivers/staging/media/imx/Makefile +1 -0
index ddd7d94..4606a3a 100644
@@ -3,3 +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 +663 -0

663 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#60 lore raw

PATCH v6 21/39 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         |   14 +
 drivers/staging/media/imx/Makefile        |    2 +
 drivers/staging/media/imx/imx-media-csi.c | 1318 +++++++++++++++++++++++++++++
 3 files changed, 1334 insertions(+)
 create mode 100644 drivers/staging/media/imx/imx-media-csi.c
drivers/staging/media/imx/Kconfig +14 -0
index 62a3c34..e27ad6d 100644
@@ -4,3 +4,17 @@ config VIDEO_IMX_MEDIA
 	---help---
 	  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 +1318 -0

1,318 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#61 lore raw

PATCH 1/1 imx: csi: retain current field order and colorimetry setting as default

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +34 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}
+
 	*fmt = sdformat->format;
 
 	if (sdformat->pad == CSI_SINK_PAD) {
Signature · 1 line
2.11.0
#62 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 23 lines · Philipp Zabel
drivers/staging/media/imx/imx-media-csi.c +23 -0
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}

Would it make sense for this to be a helper function?

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

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 28 lines · Russell King - ARM Linux
Quoted 27 lines · Philipp Zabel
drivers/staging/media/imx/imx-media-csi.c +27 -0
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
Quoted 8 lines

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}

Would it make sense for this to be a helper function?

Quite possible, the next subdev that has to set frame_interval on both pads manually because its upstream source pad doesn't suport frame_interval might want to do the same.

regards
Philipp

#64 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 38 lines · Philipp Zabel
Quoted 28 lines · Russell King - ARM Linux
Quoted 27 lines · Philipp Zabel
drivers/staging/media/imx/imx-media-csi.c +27 -0
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
Quoted 8 lines

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}

Would it make sense for this to be a helper function?

Quoted 3 lines

Quite possible, the next subdev that has to set frame_interval on both pads manually because its upstream source pad doesn't suport frame_interval might want to do the same.

Hmm. I'm not sure I agree with this approach. If a subdev hardware does not support any modification of the colourspace or field, then it should not be modifyable at the source pad - it should retain the propagated settings from the sink pad.

I thought I had already sent a patch doing exactly that.

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

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 39 lines · Russell King - ARM Linux
Quoted 38 lines · Philipp Zabel
Quoted 36 lines · Russell King - ARM Linux
Quoted 23 lines · Philipp Zabel
drivers/staging/media/imx/imx-media-csi.c +23 -0
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}

Would it make sense for this to be a helper function?

Quoted 8 lines
Quoted 3 lines

Quite possible, the next subdev that has to set frame_interval on both pads manually because its upstream source pad doesn't suport frame_interval might want to do the same.

Hmm. I'm not sure I agree with this approach. If a subdev hardware does not support any modification of the colourspace or field, then it should not be modifyable at the source pad - it should retain the propagated settings from the sink pad.

This new code is only relevant for the CSI_SINK_PAD.

Quoted 1 line

I thought I had already sent a patch doing exactly that.

Yes. Right above the modification there is a call to csi_try_fmt which will already fix up sdformat->format for the source pads. So for the CSI_SRC_PAD_DIRECT and CSI_SRC_PAD_IDMAC this should amount to a no-op.

If might be better to move this into a separate function and only call it if sdformat->pad == CSI_SINK_PAD.

regards
Philipp

author maintainer
#66 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 51 lines · Philipp Zabel
Quoted 39 lines · Russell King - ARM Linux
Quoted 38 lines · Philipp Zabel
Quoted 36 lines · Russell King - ARM Linux
Quoted 23 lines · Philipp Zabel
drivers/staging/media/imx/imx-media-csi.c +23 -0
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}
+	}

Would it make sense for this to be a helper function?

Quoted 8 lines
Quoted 3 lines

Quite possible, the next subdev that has to set frame_interval on both pads manually because its upstream source pad doesn't suport frame_interval might want to do the same.

Hmm. I'm not sure I agree with this approach. If a subdev hardware does not support any modification of the colourspace or field, then it should not be modifyable at the source pad - it should retain the propagated settings from the sink pad.

This new code is only relevant for the CSI_SINK_PAD.

Quoted 8 lines
Quoted 1 line

I thought I had already sent a patch doing exactly that.

Yes. Right above the modification there is a call to csi_try_fmt which will already fix up sdformat->format for the source pads. So for the CSI_SRC_PAD_DIRECT and CSI_SRC_PAD_IDMAC this should amount to a no-op.

If might be better to move this into a separate function and only call it if sdformat->pad == CSI_SINK_PAD.

I've done this, I will follow with the new patch. Philipp, let me know if this looks ok to you and I will add your sign-off.

Steve

author maintainer
#67 lore raw

PATCH 40/40 media: imx: set and propagate empty field, colorimetry params

This patch adds a call to imx_media_fill_empty_mbus_fields() in the *_try_fmt() functions at the sink pads, to set empty field order and colorimetry parameters.

If the field order is set to ANY, choose the currently set field order at the sink pad. If the colorspace is set to DEFAULT, choose the current colorspace at the sink pad. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current sink pad setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

Colorimetry is also propagated from sink to source pads anywhere this has not already been done. The exception is ic-prpencvf at the source pad, since the Image Converter outputs fixed quantization and Y`CbCr encoding.

---
 drivers/staging/media/imx/imx-ic-prp.c      |  5 ++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 25 +++++++++++---
 drivers/staging/media/imx/imx-media-csi.c   | 12 +++++--
 drivers/staging/media/imx/imx-media-utils.c | 53 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media-vdic.c  |  7 ++--
 drivers/staging/media/imx/imx-media.h       |  3 +-
 6 files changed, 95 insertions(+), 10 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +4 -1
index b4d4e48..8baa0d5 100644
@@ -180,6 +180,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		goto out;
 	}
 
+	fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
+
 	switch (sdformat->pad) {
 	case PRP_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -193,11 +195,12 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 			cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
 			sdformat->format.code = cc->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, fmt);
 		break;
 	case PRP_SRC_PAD_PRPENC:
 	case PRP_SRC_PAD_PRPVF:
 		/* Output pads mirror input pad */
-		fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
 		sdformat->format = *fmt;
 		break;
 	}
drivers/staging/media/imx/imx-ic-prpencvf.c +21 -4
index 860b406..cdfb51a 100644
@@ -772,6 +772,8 @@ static void prp_try_fmt(struct prp_priv *priv,
 			struct v4l2_subdev_format *sdformat,
 			const struct imx_media_pixfmt **cc)
 {
+	struct v4l2_mbus_framefmt *infmt;
+
 	*cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY);
 	if (!*cc) {
 		u32 code;
@@ -781,11 +783,9 @@ static void prp_try_fmt(struct prp_priv *priv,
 		sdformat->format.code = (*cc)->codes[0];
 	}
 
-	if (sdformat->pad == PRPENCVF_SRC_PAD) {
-		struct v4l2_mbus_framefmt *infmt =
-			__prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD,
-				      sdformat->which);
+	infmt = __prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD, sdformat->which);
 
+	if (sdformat->pad == PRPENCVF_SRC_PAD) {
 		if (sdformat->format.field != V4L2_FIELD_NONE)
 			sdformat->format.field = infmt->field;
 
@@ -804,12 +804,29 @@ static void prp_try_fmt(struct prp_priv *priv,
 					      &sdformat->format.height,
 					      infmt->height / 4, MAX_H_SRC,
 					      H_ALIGN_SRC, S_ALIGN);
+
+		/*
+		 * The Image Converter produces fixed quantization
+		 * (full range for RGB, limited range for YUV), and
+		 * uses a fixed Y`CbCr encoding (V4L2_YCBCR_ENC_601).
+		 * For colorspace and transfer func, just propagate
+		 * from the sink.
+		 */
+		sdformat->format.quantization =
+			((*cc)->cs != IPUV3_COLORSPACE_YUV) ?
+			V4L2_QUANTIZATION_FULL_RANGE :
+			V4L2_QUANTIZATION_LIM_RANGE;
+		sdformat->format.ycbcr_enc = V4L2_YCBCR_ENC_601;
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
 	} else {
 		v4l_bound_align_image(&sdformat->format.width,
 				      MIN_W_SINK, MAX_W_SINK, W_ALIGN_SINK,
 				      &sdformat->format.height,
 				      MIN_H_SINK, MAX_H_SINK, H_ALIGN_SINK,
 				      S_ALIGN);
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);
 	}
 }
 
drivers/staging/media/imx/imx-media-csi.c +10 -2
index b11e80f..730d1aa 100644
@@ -1220,11 +1220,11 @@ static void csi_try_fmt(struct csi_priv *priv,
 	struct v4l2_mbus_framefmt *infmt;
 	u32 code;
 
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which);
+
 	switch (sdformat->pad) {
 	case CSI_SRC_PAD_DIRECT:
 	case CSI_SRC_PAD_IDMAC:
-		infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD,
-				      sdformat->which);
 		incc = imx_media_find_mbus_format(infmt->code,
 						  CS_SEL_ANY, true);
 
@@ -1260,6 +1260,12 @@ static void csi_try_fmt(struct csi_priv *priv,
 			sdformat->format.field =  (infmt->height == 480) ?
 				V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
 		}
+
+		/* propagate colorimetry from sink */
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
+		sdformat->format.quantization = infmt->quantization;
+		sdformat->format.ycbcr_enc = infmt->ycbcr_enc;
 		break;
 	case CSI_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -1286,6 +1292,8 @@ static void csi_try_fmt(struct csi_priv *priv,
 							CS_SEL_ANY, false);
 			sdformat->format.code = (*cc)->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);
 		break;
 	}
 }
drivers/staging/media/imx/imx-media-utils.c +53 -0

59 lines not on this page · raw message

drivers/staging/media/imx/imx-media-vdic.c +5 -2
index 0da45cf..b71d522 100644
@@ -577,10 +577,11 @@ static void vdic_try_fmt(struct vdic_priv *priv,
 		sdformat->format.code = (*cc)->codes[0];
 	}
 
+	infmt = __vdic_get_fmt(priv, cfg, priv->active_input_pad,
+			       sdformat->which);
+
 	switch (sdformat->pad) {
 	case VDIC_SRC_PAD_DIRECT:
-		infmt = __vdic_get_fmt(priv, cfg, priv->active_input_pad,
-				       sdformat->which);
 		sdformat->format = *infmt;
 		/* output is always progressive! */
 		sdformat->format.field = V4L2_FIELD_NONE;
@@ -592,6 +593,8 @@ static void vdic_try_fmt(struct vdic_priv *priv,
 				      &sdformat->format.height,
 				      MIN_H, MAX_H_VDIC, H_ALIGN, S_ALIGN);
 
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);
+
 		/* input must be interlaced! Choose SEQ_TB if not */
 		if (!V4L2_FIELD_HAS_BOTH(sdformat->format.field))
 			sdformat->format.field = V4L2_FIELD_SEQ_TB;
drivers/staging/media/imx/imx-media.h +2 -1
index 9985aa0..3bc685c 100644
@@ -189,7 +189,8 @@ 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,
 			    const struct imx_media_pixfmt **cc);
-
+void imx_media_fill_empty_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
+				      struct v4l2_mbus_framefmt *fmt);
 int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,
 				  struct v4l2_mbus_framefmt *mbus,
 				  const struct imx_media_pixfmt *cc);
Signature · 1 line
2.7.4
maintainer
#68 lore raw

Re: [PATCH 40/40] media: imx: set and propagate empty field, colorimetry params

Hi Steve,

thanks for cleaning this up. Apart from the comments below, this looks good to me.

Quoted 31 lines · Steve Longerbeam

This patch adds a call to imx_media_fill_empty_mbus_fields() in the *_try_fmt() functions at the sink pads, to set empty field order and colorimetry parameters.

If the field order is set to ANY, choose the currently set field order at the sink pad. If the colorspace is set to DEFAULT, choose the current colorspace at the sink pad. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current sink pad setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

Colorimetry is also propagated from sink to source pads anywhere this has not already been done. The exception is ic-prpencvf at the source pad, since the Image Converter outputs fixed quantization and Y`CbCr encoding.

---
 drivers/staging/media/imx/imx-ic-prp.c      |  5 ++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 25 +++++++++++---
 drivers/staging/media/imx/imx-media-csi.c   | 12 +++++--
 drivers/staging/media/imx/imx-media-utils.c | 53 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media-vdic.c  |  7 ++--
 drivers/staging/media/imx/imx-media.h       |  3 +-
 6 files changed, 95 insertions(+), 10 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +0 -0
index b4d4e48..8baa0d5 100644

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

Quoted 5 lines
drivers/staging/media/imx/imx-ic-prp.c +2 -0
@@ -180,6 +180,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		goto out;
 	}
 
+	fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
+

Should this be changed to infmt for consistency?

Quoted 51 lines
drivers/staging/media/imx/imx-ic-prp.c +2 -1
 	switch (sdformat->pad) {
 	case PRP_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -193,11 +195,12 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 			cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
 			sdformat->format.code = cc->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, fmt);
 		break;
 	case PRP_SRC_PAD_PRPENC:
 	case PRP_SRC_PAD_PRPVF:
 		/* Output pads mirror input pad */
-		fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
 		sdformat->format = *fmt;
 		break;
 	}
drivers/staging/media/imx/imx-ic-prpencvf.c +7 -4
index 860b406..cdfb51a 100644
@@ -772,6 +772,8 @@ static void prp_try_fmt(struct prp_priv *priv,
 			struct v4l2_subdev_format *sdformat,
 			const struct imx_media_pixfmt **cc)
 {
+	struct v4l2_mbus_framefmt *infmt;
+
 	*cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY);
 	if (!*cc) {
 		u32 code;
@@ -781,11 +783,9 @@ static void prp_try_fmt(struct prp_priv *priv,
 		sdformat->format.code = (*cc)->codes[0];
 	}
 
-	if (sdformat->pad == PRPENCVF_SRC_PAD) {
-		struct v4l2_mbus_framefmt *infmt =
-			__prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD,
-				      sdformat->which);
+	infmt = __prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD, sdformat->which);
 
+	if (sdformat->pad == PRPENCVF_SRC_PAD) {
 		if (sdformat->format.field != V4L2_FIELD_NONE)
 			sdformat->format.field = infmt->field;
 
@@ -804,12 +804,29 @@ static void prp_try_fmt(struct prp_priv *priv,
 					      &sdformat->format.height,
 					      infmt->height / 4, MAX_H_SRC,
 					      H_ALIGN_SRC, S_ALIGN);
+
+		/*
+		 * The Image Converter produces fixed quantization

drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 819

Quoted 10 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +10 -0
+		 * (full range for RGB, limited range for YUV), and
+		 * uses a fixed Y`CbCr encoding (V4L2_YCBCR_ENC_601).
+		 * For colorspace and transfer func, just propagate
+		 * from the sink.
+		 */
+		sdformat->format.quantization =
+			((*cc)->cs != IPUV3_COLORSPACE_YUV) ?
+			V4L2_QUANTIZATION_FULL_RANGE :
+			V4L2_QUANTIZATION_LIM_RANGE;
+		sdformat->format.ycbcr_enc = V4L2_YCBCR_ENC_601;

Support for V4L2_YCBCR_ENC_709 and quantization options could be added to the IPUv3 core code, so this limitation could be relaxed later.

drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 829

Quoted 10 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +4 -0
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
 	} else {
 		v4l_bound_align_image(&sdformat->format.width,
 				      MIN_W_SINK, MAX_W_SINK, W_ALIGN_SINK,
 				      &sdformat->format.height,
 				      MIN_H_SINK, MAX_H_SINK, H_ALIGN_SINK,
 				      S_ALIGN);
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);

So we should limit quantization and ycbcr_enc here as well. Right now there is no way to convert from limited range RGB to full range RGB, for example.

Quoted 94 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0 -0
 	}
 }
 
drivers/staging/media/imx/imx-media-csi.c +10 -2
index b11e80f..730d1aa 100644
@@ -1220,11 +1220,11 @@ static void csi_try_fmt(struct csi_priv *priv,
 	struct v4l2_mbus_framefmt *infmt;
 	u32 code;
 
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which);
+
 	switch (sdformat->pad) {
 	case CSI_SRC_PAD_DIRECT:
 	case CSI_SRC_PAD_IDMAC:
-		infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD,
-				      sdformat->which);
 		incc = imx_media_find_mbus_format(infmt->code,
 						  CS_SEL_ANY, true);
 
@@ -1260,6 +1260,12 @@ static void csi_try_fmt(struct csi_priv *priv,
 			sdformat->format.field =  (infmt->height == 480) ?
 				V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
 		}
+
+		/* propagate colorimetry from sink */
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
+		sdformat->format.quantization = infmt->quantization;
+		sdformat->format.ycbcr_enc = infmt->ycbcr_enc;
 		break;
 	case CSI_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -1286,6 +1292,8 @@ static void csi_try_fmt(struct csi_priv *priv,
 							CS_SEL_ANY, false);
 			sdformat->format.code = (*cc)->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);
 		break;
 	}
 }
drivers/staging/media/imx/imx-media-utils.c +43 -0
index 7b2f92d..b07d0ae 100644
@@ -464,6 +464,59 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 }
 EXPORT_SYMBOL_GPL(imx_media_init_mbus_fmt);
 
+/*
+ * Check whether the field or colorimetry params in tryfmt are
+ * uninitialized, and if so fill them with the values from fmt.
+ * The exception is when tryfmt->colorspace has been initialized,
+ * if so all the further default colorimetry params can be derived
+ * from tryfmt->colorspace.
+ */
+void imx_media_fill_empty_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
+				      struct v4l2_mbus_framefmt *fmt)
+{
+	/* fill field if necessary */
+	if (tryfmt->field == V4L2_FIELD_ANY)
+		tryfmt->field = fmt->field;
+
+	/* fill colorimetry if necessary */
+	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
+		tryfmt->colorspace = fmt->colorspace;
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			tryfmt->xfer_func = fmt->xfer_func;
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
+			tryfmt->quantization = fmt->quantization;
+	} else {
+		const struct imx_media_pixfmt *cc;
+		bool is_rgb = false;
+
+		cc = imx_media_find_mbus_format(tryfmt->code,
+						CS_SEL_ANY, false);
+		if (!cc)
+			cc = imx_media_find_ipu_format(tryfmt->code,
+						       CS_SEL_ANY);
+		if (cc && cc->cs != IPUV3_COLORSPACE_YUV)
+			is_rgb = true;
+
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			tryfmt->xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace);
+		}
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			tryfmt->ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
+		}

drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 519

Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10 -0
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) {
+			tryfmt->quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+					is_rgb, tryfmt->colorspace,
+					tryfmt->ycbcr_enc);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(imx_media_fill_empty_mbus_fields);
+

I'd s/empty/default/ in the function name.

After we agree on and write down some guidelines on expected behaviour in the spec, this could be lifted into v4l2-core.

regards
Philipp

author maintainer
#69 lore raw

Re: [PATCH 40/40] media: imx: set and propagate empty field, colorimetry params

Quoted 40 lines · Philipp Zabel

Hi Steve,

thanks for cleaning this up. Apart from the comments below, this looks good to me.

Quoted 34 lines · Steve Longerbeam

This patch adds a call to imx_media_fill_empty_mbus_fields() in the *_try_fmt() functions at the sink pads, to set empty field order and colorimetry parameters.

If the field order is set to ANY, choose the currently set field order at the sink pad. If the colorspace is set to DEFAULT, choose the current colorspace at the sink pad. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current sink pad setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

Colorimetry is also propagated from sink to source pads anywhere this has not already been done. The exception is ic-prpencvf at the source pad, since the Image Converter outputs fixed quantization and Y`CbCr encoding.

---
 drivers/staging/media/imx/imx-ic-prp.c      |  5 ++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 25 +++++++++++---
 drivers/staging/media/imx/imx-media-csi.c   | 12 +++++--
 drivers/staging/media/imx/imx-media-utils.c | 53 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media-vdic.c  |  7 ++--
 drivers/staging/media/imx/imx-media.h       |  3 +-
 6 files changed, 95 insertions(+), 10 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +0 -0
index b4d4e48..8baa0d5 100644
@@ -180,6 +180,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		goto out;
 	}
 
Quoted 4 lines

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

Quoted 2 lines
drivers/staging/media/imx/imx-ic-prp.c +2 -0
+	fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
+

Should this be changed to infmt for consistency?

sure, will do.

Quoted 57 lines
Quoted 57 lines
drivers/staging/media/imx/imx-ic-prp.c +2 -1
 	switch (sdformat->pad) {
 	case PRP_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -193,11 +195,12 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 			cc = imx_media_find_ipu_format(code, CS_SEL_ANY);
 			sdformat->format.code = cc->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, fmt);
 		break;
 	case PRP_SRC_PAD_PRPENC:
 	case PRP_SRC_PAD_PRPVF:
 		/* Output pads mirror input pad */
-		fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
 		sdformat->format = *fmt;
 		break;
 	}
drivers/staging/media/imx/imx-ic-prpencvf.c +12 -4
index 860b406..cdfb51a 100644
@@ -772,6 +772,8 @@ static void prp_try_fmt(struct prp_priv *priv,
 			struct v4l2_subdev_format *sdformat,
 			const struct imx_media_pixfmt **cc)
 {
+	struct v4l2_mbus_framefmt *infmt;
+
 	*cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY);
 	if (!*cc) {
 		u32 code;
@@ -781,11 +783,9 @@ static void prp_try_fmt(struct prp_priv *priv,
 		sdformat->format.code = (*cc)->codes[0];
 	}
 
-	if (sdformat->pad == PRPENCVF_SRC_PAD) {
-		struct v4l2_mbus_framefmt *infmt =
-			__prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD,
-				      sdformat->which);
+	infmt = __prp_get_fmt(priv, cfg, PRPENCVF_SINK_PAD, sdformat->which);
 
+	if (sdformat->pad == PRPENCVF_SRC_PAD) {
 		if (sdformat->format.field != V4L2_FIELD_NONE)
 			sdformat->format.field = infmt->field;
 
@@ -804,12 +804,29 @@ static void prp_try_fmt(struct prp_priv *priv,
 					      &sdformat->format.height,
 					      infmt->height / 4, MAX_H_SRC,
 					      H_ALIGN_SRC, S_ALIGN);
+
+		/*
+		 * The Image Converter produces fixed quantization
+		 * (full range for RGB, limited range for YUV), and
+		 * uses a fixed Y`CbCr encoding (V4L2_YCBCR_ENC_601).
+		 * For colorspace and transfer func, just propagate
+		 * from the sink.
+		 */
Quoted 8 lines

drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 819

Quoted 5 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -0
+		sdformat->format.quantization =
+			((*cc)->cs != IPUV3_COLORSPACE_YUV) ?
+			V4L2_QUANTIZATION_FULL_RANGE :
+			V4L2_QUANTIZATION_LIM_RANGE;
+		sdformat->format.ycbcr_enc = V4L2_YCBCR_ENC_601;

Support for V4L2_YCBCR_ENC_709 and quantization options could be added to the IPUv3 core code, so this limitation could be relaxed later.

Yes, I was going to mention that too. We can add coefficient tables to ipu-ic for all the encodings enumerated in enum v4l2_ycbcr_encoding.

I know that quantization is programmable in the DP, but is it in the IC? AFAICT there is none.

Quoted 15 lines

drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 829

Quoted 11 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +4 -0
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
 	} else {
 		v4l_bound_align_image(&sdformat->format.width,
 				      MIN_W_SINK, MAX_W_SINK, W_ALIGN_SINK,
 				      &sdformat->format.height,
 				      MIN_H_SINK, MAX_H_SINK, H_ALIGN_SINK,
 				      S_ALIGN);
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);

So we should limit quantization and ycbcr_enc here as well. Right now there is no way to convert from limited range RGB to full range RGB, for example.

True, yes, I was scratching my head about that. I'll move the above to apply to all pads.

Quoted 99 lines
Quoted 99 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0 -0
 	}
 }
 
drivers/staging/media/imx/imx-media-csi.c +10 -2
index b11e80f..730d1aa 100644
@@ -1220,11 +1220,11 @@ static void csi_try_fmt(struct csi_priv *priv,
 	struct v4l2_mbus_framefmt *infmt;
 	u32 code;
 
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sdformat->which);
+
 	switch (sdformat->pad) {
 	case CSI_SRC_PAD_DIRECT:
 	case CSI_SRC_PAD_IDMAC:
-		infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD,
-				      sdformat->which);
 		incc = imx_media_find_mbus_format(infmt->code,
 						  CS_SEL_ANY, true);
 
@@ -1260,6 +1260,12 @@ static void csi_try_fmt(struct csi_priv *priv,
 			sdformat->format.field =  (infmt->height == 480) ?
 				V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
 		}
+
+		/* propagate colorimetry from sink */
+		sdformat->format.colorspace = infmt->colorspace;
+		sdformat->format.xfer_func = infmt->xfer_func;
+		sdformat->format.quantization = infmt->quantization;
+		sdformat->format.ycbcr_enc = infmt->ycbcr_enc;
 		break;
 	case CSI_SINK_PAD:
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
@@ -1286,6 +1292,8 @@ static void csi_try_fmt(struct csi_priv *priv,
 							CS_SEL_ANY, false);
 			sdformat->format.code = (*cc)->codes[0];
 		}
+
+		imx_media_fill_empty_mbus_fields(&sdformat->format, infmt);
 		break;
 	}
 }
drivers/staging/media/imx/imx-media-utils.c +47 -0
index 7b2f92d..b07d0ae 100644
@@ -464,6 +464,59 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 }
 EXPORT_SYMBOL_GPL(imx_media_init_mbus_fmt);
 
+/*
+ * Check whether the field or colorimetry params in tryfmt are
+ * uninitialized, and if so fill them with the values from fmt.
+ * The exception is when tryfmt->colorspace has been initialized,
+ * if so all the further default colorimetry params can be derived
+ * from tryfmt->colorspace.
+ */
+void imx_media_fill_empty_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
+				      struct v4l2_mbus_framefmt *fmt)
+{
+	/* fill field if necessary */
+	if (tryfmt->field == V4L2_FIELD_ANY)
+		tryfmt->field = fmt->field;
+
+	/* fill colorimetry if necessary */
+	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
+		tryfmt->colorspace = fmt->colorspace;
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			tryfmt->xfer_func = fmt->xfer_func;
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
+			tryfmt->quantization = fmt->quantization;
+	} else {
+		const struct imx_media_pixfmt *cc;
+		bool is_rgb = false;
+
+		cc = imx_media_find_mbus_format(tryfmt->code,
+						CS_SEL_ANY, false);
+		if (!cc)
+			cc = imx_media_find_ipu_format(tryfmt->code,
+						       CS_SEL_ANY);
+		if (cc && cc->cs != IPUV3_COLORSPACE_YUV)
+			is_rgb = true;
+
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			tryfmt->xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace);
+		}
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			tryfmt->ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
+		}
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) {
+			tryfmt->quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+					is_rgb, tryfmt->colorspace,
Quoted 8 lines

drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 519

Quoted 6 lines
drivers/staging/media/imx/imx-media-utils.c +6 -0
+					tryfmt->ycbcr_enc);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(imx_media_fill_empty_mbus_fields);
+

I'd s/empty/default/ in the function name.

sounds good.

Quoted 3 lines

After we agree on and write down some guidelines on expected behaviour in the spec, this could be lifted into v4l2-core.

Agreed.

Steve

maintainer
#70 lore raw

Re: [PATCH 40/40] media: imx: set and propagate empty field, colorimetry params

On Thu, 2017-04-13 at 09:40 -0700, Steve Longerbeam wrote:
[...]

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +8 -0
@@ -804,12 +804,29 @@ static void prp_try_fmt(struct prp_priv *priv,
 					      &sdformat->format.height,
 					      infmt->height / 4, MAX_H_SRC,
 					      H_ALIGN_SRC, S_ALIGN);
+
+		/*
+		 * The Image Converter produces fixed quantization
+		 * (full range for RGB, limited range for YUV), and
+		 * uses a fixed Y`CbCr encoding (V4L2_YCBCR_ENC_601).
+		 * For colorspace and transfer func, just propagate
+		 * from the sink.
+		 */
Quoted 8 lines

drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 819

Quoted 5 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -0
+		sdformat->format.quantization =
+			((*cc)->cs != IPUV3_COLORSPACE_YUV) ?
+			V4L2_QUANTIZATION_FULL_RANGE :
+			V4L2_QUANTIZATION_LIM_RANGE;
+		sdformat->format.ycbcr_enc = V4L2_YCBCR_ENC_601;

Support for V4L2_YCBCR_ENC_709 and quantization options could be added to the IPUv3 core code, so this limitation could be relaxed later.

Quoted 2 lines

Yes, I was going to mention that too. We can add coefficient tables to ipu-ic for all the encodings enumerated in enum v4l2_ycbcr_encoding.

Exactly.

Quoted 2 lines

I know that quantization is programmable in the DP, but is it in the IC? AFAICT there is none.

We have a freely programmable 4x3 matrix multiplication both before and after processing in each task, and there is a saturation mode switch that can limit the first component to (16...235) and the other two to (16...240). That should be enough for at least full/limited range YCbCr quantizations. So we apparently can't saturate to limited range RGB, but for example full-range -> limited-range RGB conversions should be perfectly possible.

regards
Philipp

maintainer
#71 lore raw

Re: [PATCH 40/40] media: imx: set and propagate empty field, colorimetry params

In reply to Steve Longerbeam

Hi Steve,

Quoted 26 lines · Steve Longerbeam

This patch adds a call to imx_media_fill_empty_mbus_fields() in the *_try_fmt() functions at the sink pads, to set empty field order and colorimetry parameters.

If the field order is set to ANY, choose the currently set field order at the sink pad. If the colorspace is set to DEFAULT, choose the current colorspace at the sink pad. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current sink pad setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

Colorimetry is also propagated from sink to source pads anywhere this has not already been done. The exception is ic-prpencvf at the source pad, since the Image Converter outputs fixed quantization and Y`CbCr encoding.

---
 drivers/staging/media/imx/imx-ic-prp.c      |  5 ++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 25 +++++++++++---
 drivers/staging/media/imx/imx-media-csi.c   | 12 +++++--
 drivers/staging/media/imx/imx-media-utils.c | 53 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media-vdic.c  |  7 ++--
 drivers/staging/media/imx/imx-media.h       |  3 +-
 6 files changed, 95 insertions(+), 10 deletions(-)

[...]

Quoted 21 lines
drivers/staging/media/imx/imx-media-utils.c +13 -0
index 7b2f92d..b07d0ae 100644
@@ -464,6 +464,59 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 }
 EXPORT_SYMBOL_GPL(imx_media_init_mbus_fmt);
 
+/*
+ * Check whether the field or colorimetry params in tryfmt are
+ * uninitialized, and if so fill them with the values from fmt.
+ * The exception is when tryfmt->colorspace has been initialized,
+ * if so all the further default colorimetry params can be derived
+ * from tryfmt->colorspace.
+ */
+void imx_media_fill_empty_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
+				      struct v4l2_mbus_framefmt *fmt)
+{
+	/* fill field if necessary */
+	if (tryfmt->field == V4L2_FIELD_ANY)
+		tryfmt->field = fmt->field;

drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 489

Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10 -0
+
+	/* fill colorimetry if necessary */
+	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
+		tryfmt->colorspace = fmt->colorspace;
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			tryfmt->xfer_func = fmt->xfer_func;
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
+			tryfmt->quantization = fmt->quantization;

According to Hans' latest comments, this could be changed to:

----------8<----------

Quoted 1 line

From cca3cda9effcaca0891eb8044a79137023fed1c2 Mon Sep 17 00:00:00 2001

From: Philipp Zabel <[email protected]>
Date: Mon, 8 May 2017 11:38:05 +0200
Subject: [PATCH] fixup! media: imx: set and propagate default field,
colorimetry

---
 drivers/staging/media/imx/imx-media-utils.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +3 -6
index a8766489e8a18..ec2abd618cc44 100644
@@ -497,12 +497,9 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
 	/* fill colorimetry if necessary */
 	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
 		tryfmt->colorspace = fmt->colorspace;
-		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
-			tryfmt->xfer_func = fmt->xfer_func;
-		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
-			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
-		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
-			tryfmt->quantization = fmt->quantization;
+		tryfmt->xfer_func = fmt->xfer_func;
+		tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		tryfmt->quantization = fmt->quantization;
 	} else {
 		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) {
 			tryfmt->xfer_func =
Signature · 2 lines
2.11.0
---------->8----------
Quoted 17 lines
drivers/staging/media/imx/imx-media-utils.c +17 -0
+	} else {
+		const struct imx_media_pixfmt *cc;
+		bool is_rgb = false;
+
+		cc = imx_media_find_mbus_format(tryfmt->code,
+						CS_SEL_ANY, false);
+		if (!cc)
+			cc = imx_media_find_ipu_format(tryfmt->code,
+						       CS_SEL_ANY);
+		if (cc && cc->cs != IPUV3_COLORSPACE_YUV)
+			is_rgb = true;
+
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			tryfmt->xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(tryfmt->colorspace);
+		}
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10 -0
+			tryfmt->ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(tryfmt->colorspace);
+		}
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT) {
+			tryfmt->quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+					is_rgb, tryfmt->colorspace,
+					tryfmt->ycbcr_enc);
+		}
+	}

I'm not sure about removing this part yet.

regards
Philipp

author maintainer
#72 lore raw

Re: [PATCH 40/40] media: imx: set and propagate empty field, colorimetry params

Quoted 87 lines · Philipp Zabel

Hi Steve,

Quoted 26 lines · Steve Longerbeam

This patch adds a call to imx_media_fill_empty_mbus_fields() in the *_try_fmt() functions at the sink pads, to set empty field order and colorimetry parameters.

If the field order is set to ANY, choose the currently set field order at the sink pad. If the colorspace is set to DEFAULT, choose the current colorspace at the sink pad. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current sink pad setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

Colorimetry is also propagated from sink to source pads anywhere this has not already been done. The exception is ic-prpencvf at the source pad, since the Image Converter outputs fixed quantization and Y`CbCr encoding.

---
 drivers/staging/media/imx/imx-ic-prp.c      |  5 ++-
 drivers/staging/media/imx/imx-ic-prpencvf.c | 25 +++++++++++---
 drivers/staging/media/imx/imx-media-csi.c   | 12 +++++--
 drivers/staging/media/imx/imx-media-utils.c | 53 +++++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-media-vdic.c  |  7 ++--
 drivers/staging/media/imx/imx-media.h       |  3 +-
 6 files changed, 95 insertions(+), 10 deletions(-)

[...]

Quoted 21 lines
drivers/staging/media/imx/imx-media-utils.c +13 -0
index 7b2f92d..b07d0ae 100644
@@ -464,6 +464,59 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
 }
 EXPORT_SYMBOL_GPL(imx_media_init_mbus_fmt);
 
+/*
+ * Check whether the field or colorimetry params in tryfmt are
+ * uninitialized, and if so fill them with the values from fmt.
+ * The exception is when tryfmt->colorspace has been initialized,
+ * if so all the further default colorimetry params can be derived
+ * from tryfmt->colorspace.
+ */
+void imx_media_fill_empty_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
+				      struct v4l2_mbus_framefmt *fmt)
+{
+	/* fill field if necessary */
+	if (tryfmt->field == V4L2_FIELD_ANY)
+		tryfmt->field = fmt->field;

drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 489

Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10 -0
+
+	/* fill colorimetry if necessary */
+	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
+		tryfmt->colorspace = fmt->colorspace;
+		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			tryfmt->xfer_func = fmt->xfer_func;
+		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
+			tryfmt->quantization = fmt->quantization;

According to Hans' latest comments, this could be changed to:

----------8<----------
From cca3cda9effcaca0891eb8044a79137023fed1c2 Mon Sep 17 00:00:00 2001
From: Philipp Zabel <[email protected]>
Date: Mon, 8 May 2017 11:38:05 +0200
Subject: [PATCH] fixup! media: imx: set and propagate default field,
colorimetry

---
 drivers/staging/media/imx/imx-media-utils.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +0 -2
index a8766489e8a18..ec2abd618cc44 100644
@@ -497,12 +497,9 @@ void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt,
 	/* fill colorimetry if necessary */
 	if (tryfmt->colorspace == V4L2_COLORSPACE_DEFAULT) {
 		tryfmt->colorspace = fmt->colorspace;
-		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT)
-			tryfmt->xfer_func = fmt->xfer_func;

drivers/staging/media/imx/imx-media-utils.c void imx_media_fill_default_mbus_fields(struct v4l2_mbus_framefmt *tryfmt, · line 505

Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +3 -4
-		if (tryfmt->ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
-			tryfmt->ycbcr_enc = fmt->ycbcr_enc;
-		if (tryfmt->quantization == V4L2_QUANTIZATION_DEFAULT)
-			tryfmt->quantization = fmt->quantization;
+		tryfmt->xfer_func = fmt->xfer_func;
+		tryfmt->ycbcr_enc = fmt->ycbcr_enc;
+		tryfmt->quantization = fmt->quantization;
 	} else {
 		if (tryfmt->xfer_func == V4L2_XFER_FUNC_DEFAULT) {
 			tryfmt->xfer_func =

Hi Philipp, makes sense to me, I'll make the change in next revision.

Steve

#73 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

In reply to Philipp Zabel
Quoted 34 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644

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

Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;

No! Subdevs should never return COLORSPACE_DEFAULT. If they do, then fix them. If this happens a lot (I'm not sure how reliably subdevs fill this in) you could set it to COLORSPACE_RAW. Perhaps with a WARN_ON_ONCE.

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

Nack. This is meaningless.

Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c +8 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

This isn't wrong, but it is perfectly fine to keep the DEFAULT here and let the application call V4L2_MAP_.

I get the feeling this patch is a workaround for subdev errors. Either that, or the commit log doesn't give me enough information to really understand the problem that's being addressed here.

Regards,

Hans

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +2 -0
+	}
+
 	*fmt = sdformat->format;
 
 	if (sdformat->pad == CSI_SINK_PAD) {
#74 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 37 lines · Hans Verkuil
Quoted 36 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
Quoted 8 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

Please explain further - sdformat->format.field is the field passed _in_ from userspace, and from what I can see, userspace is free to pass in any value through the ioctl as check_format() does nothing to validate that the various format.* fields are sane.

This patch is detecting that the user is requesting FIELD_ANY, and fixing it up. Surely that's the right thing to do, and is way more preferable than just accepting the FIELD_ANY from userspace and storing that value?

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

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

In reply to Hans Verkuil
Quoted 37 lines · Hans Verkuil
Quoted 36 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
Quoted 8 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

This is the subdev. sdformat is passed in from userspace, so we have to deal with it being set to ANY. I'm trying hard right now not to return ANY though. The values in sdformat->format are applied to fmt down below.

Quoted 8 lines

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;

No! Subdevs should never return COLORSPACE_DEFAULT. If they do, then fix them. If this happens a lot (I'm not sure how reliably subdevs fill this in) you could set it to COLORSPACE_RAW. Perhaps with a WARN_ON_ONCE.

Same here, if userspace calls VIDIOC_SUBDEV_S_FMT with DEFAULT colorspace, I don't want to return that unchanged, but overwrite it with the currently set value.

Quoted 8 lines

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

Nack. This is meaningless.

It isn't. It may be wrong, but it is not without effect. If the colorimetry info (in fmt) is currently set to something that is non-standard, calling VIDIOC_SUBDEV_S_FMT with DEFAULT in xfer_func, ycbcr_enc or quantization will cause those old values to be retained, instead of overwriting them to DEFAULT.

Quoted 22 lines
Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c +8 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

This isn't wrong, but it is perfectly fine to keep the DEFAULT here and let the application call V4L2_MAP_.

Quoted 3 lines

I get the feeling this patch is a workaround for subdev errors. Either that, or the commit log doesn't give me enough information to really understand the problem that's being addressed here.

It's the latter. I should have written VIDIOC_SUBDEV_S_FMT instead of just set_fmt in the comment.

Quoted 7 lines

Regards,

Hans

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

Quoted 3 lines
drivers/staging/media/imx/imx-media-csi.c +2 -0
+	}
+
 	*fmt = sdformat->format;

Here sdformat is applied to the subdev pad.

regards
Philipp

#76 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 47 lines · Philipp Zabel
Quoted 37 lines · Hans Verkuil
Quoted 36 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
Quoted 8 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

Quoted 4 lines

This is the subdev. sdformat is passed in from userspace, so we have to deal with it being set to ANY. I'm trying hard right now not to return ANY though. The values in sdformat->format are applied to fmt down below.

Do you have a git tree with this patch? It is really hard to review without having the full imx-media-csi.c source.

I think one problem is that it is not clearly defined how subdevs and colorspace information should work.

Regards,

Hans

Quoted 71 lines
Quoted 9 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;

No! Subdevs should never return COLORSPACE_DEFAULT. If they do, then fix them. If this happens a lot (I'm not sure how reliably subdevs fill this in) you could set it to COLORSPACE_RAW. Perhaps with a WARN_ON_ONCE.

Same here, if userspace calls VIDIOC_SUBDEV_S_FMT with DEFAULT colorspace, I don't want to return that unchanged, but overwrite it with the currently set value.

Quoted 8 lines

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

Nack. This is meaningless.

It isn't. It may be wrong, but it is not without effect. If the colorimetry info (in fmt) is currently set to something that is non-standard, calling VIDIOC_SUBDEV_S_FMT with DEFAULT in xfer_func, ycbcr_enc or quantization will cause those old values to be retained, instead of overwriting them to DEFAULT.

Quoted 22 lines
Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c +8 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

This isn't wrong, but it is perfectly fine to keep the DEFAULT here and let the application call V4L2_MAP_.

Quoted 3 lines

I get the feeling this patch is a workaround for subdev errors. Either that, or the commit log doesn't give me enough information to really understand the problem that's being addressed here.

It's the latter. I should have written VIDIOC_SUBDEV_S_FMT instead of just set_fmt in the comment.

Quoted 7 lines

Regards,

Hans

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

Quoted 3 lines
drivers/staging/media/imx/imx-media-csi.c +2 -0
+	}
+
 	*fmt = sdformat->format;

Here sdformat is applied to the subdev pad.

regards
Philipp

maintainer
#77 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 48 lines · Hans Verkuil
Quoted 47 lines · Philipp Zabel
Quoted 45 lines · Hans Verkuil
Quoted 34 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644

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

Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

Quoted 7 lines
Quoted 4 lines

This is the subdev. sdformat is passed in from userspace, so we have to deal with it being set to ANY. I'm trying hard right now not to return ANY though. The values in sdformat->format are applied to fmt down below.

Do you have a git tree with this patch? It is really hard to review without having the full imx-media-csi.c source.

The patch applies on top of

https://github.com/slongerbeam/mediatree.git imx-media-staging-md-v14

I have uploaded a branch

git://git.pengutronix.de/git/pza/linux imx-media-staging-md-v14+color

with the patch applied on top.

Quoted 2 lines

I think one problem is that it is not clearly defined how subdevs and colorspace information should work.

regards
Philipp

#78 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 59 lines · Philipp Zabel
Quoted 48 lines · Hans Verkuil
Quoted 47 lines · Philipp Zabel
Quoted 45 lines · Hans Verkuil
Quoted 34 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644

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

Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

Quoted 7 lines
Quoted 4 lines

This is the subdev. sdformat is passed in from userspace, so we have to deal with it being set to ANY. I'm trying hard right now not to return ANY though. The values in sdformat->format are applied to fmt down below.

Do you have a git tree with this patch? It is really hard to review without having the full imx-media-csi.c source.

The patch applies on top of

Quoted 10 lines

https://github.com/slongerbeam/mediatree.git imx-media-staging-md-v14

I have uploaded a branch

git://git.pengutronix.de/git/pza/linux imx-media-staging-md-v14+color

with the patch applied on top.

Quoted 2 lines

I think one problem is that it is not clearly defined how subdevs and colorspace information should work.

Ah, having the full source helped.

Ignore my previous review, it was incorrect.

I'll have to think about this some more. I'll get back to this, but it may take some time since my vacation starts tomorrow. The spec is simply unclear about how to handle this so we have to come up with some guidelines.

Regards,

Hans

maintainer
#79 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

On Wed, 2017-04-12 at 09:03 +0200, Hans Verkuil wrote:
[...]

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

Do you have a git tree with this patch? It is really hard to review without having the full imx-media-csi.c source.

The patch applies on top of

https://github.com/slongerbeam/mediatree.git imx-media-staging-md-v14

I have uploaded a branch

git://git.pengutronix.de/git/pza/linux imx-media-staging-md-v14+color

Quoted 8 lines
Quoted 4 lines

with the patch applied on top.

Quoted 2 lines

I think one problem is that it is not clearly defined how subdevs and colorspace information should work.

Ah, having the full source helped.

Ignore my previous review, it was incorrect.

Ok.

Quoted 3 lines

I'll have to think about this some more. I'll get back to this, but it may take some time since my vacation starts tomorrow. The spec is simply unclear about how to handle this so we have to come up with some guidelines.

Yes, please. Until then, have a nice vacation.

regards
Philipp

maintainer
#80 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

In reply to Hans Verkuil
Quoted 13 lines · Hans Verkuil
Quoted 12 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

Quoted 8 lines
Quoted 8 lines

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"

To be more clear, this media-ctl command will call VIDIOC_SUBDEV_S_FMT on the 'ipu1_csi0':0 sink pad during the propagation phase, with field and colorspace set to whatever was propagated from the 'tc358743 1-000f':0 pad in the previous steps (as returned by VIDIOC_SUBDEV_G_FMT on the 'ipu1_csi0_mux':2 source pad).

Quoted 1 line
Quoted 1 line

4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"

And this media-ctl command will call VIDIOC_SUBDEV_S_FMT on the 'ipu1_csi0':0 sink pad with V4L2_FIELD_ANY (since there is no "field:" set), and with V4L2_COLORSPACE_DEFAULT (since there is no colorspace:" set) and so on. I don't want the correct values from step 3) to be replaced with DEFAULT here.

Quoted 8 lines
Quoted 8 lines

5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Quoted 5 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,

So the VIDIOC_SUBDEV_S_FMT callback has to check for DEFAULT values and do something about them.

Quoted 57 lines

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

Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

sdformat->format.field should never be FIELD_ANY. If it is, then that's a subdev bug and I'm pretty sure FIELD_NONE was intended.

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;

No! Subdevs should never return COLORSPACE_DEFAULT. If they do, then fix them. If this happens a lot (I'm not sure how reliably subdevs fill this in) you could set it to COLORSPACE_RAW. Perhaps with a WARN_ON_ONCE.

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +6 -0
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

Nack. This is meaningless.

Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c +8 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

This isn't wrong, but it is perfectly fine to keep the DEFAULT here and let the application call V4L2_MAP_.

I get the feeling this patch is a workaround for subdev errors. Either that, or the commit log doesn't give me enough information to really understand the problem that's being addressed here.

Regards,

Quoted 8 lines

Hans

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

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +2 -0
+	}
+
 	*fmt = sdformat->format;
 
 	if (sdformat->pad == CSI_SINK_PAD) {

regards
Philipp

#81 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

In reply to Philipp Zabel

Hi Philipp,

Sorry for the very long delay, but I finally had some time to think about this.

Quoted 34 lines · Philipp Zabel

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644

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

Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

This is OK.

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

If sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT, then you can just copy all four fields from fmt to sdformat->format. The other three fields are meaningless when colorspace == V4L2_COLORSPACE_DEFAULT.

Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c +8 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +10 -0
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

Is this needed for validation? Currently these fields play no role in the default link validation. Which I think is actually the right thing to do, unless the subdev can do actual colorspace conversion.

I would just drop the whole 'else' here.

Actually, wouldn't it be better to always just copy this information from fmt? This subdev doesn't do any colorspace conversion, it just passes on this information. I.e., you can't set it in any meaningful way.

Regards,

Hans

Quoted 6 lines
drivers/staging/media/imx/imx-media-csi.c +2 -0
+	}
+
 	*fmt = sdformat->format;
 
 	if (sdformat->pad == CSI_SINK_PAD) {
maintainer
#82 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Hi Hans,

Quoted 3 lines · Hans Verkuil

Hi Philipp,

Sorry for the very long delay, but I finally had some time to think about this.

Thank you for your thoughts.

Quoted 37 lines · Philipp Zabel
Quoted 36 lines

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
Quoted 7 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

This is OK.

Would this be a "may" or a "should"? As in,
"If SUBDEV_S_FMT is called with field == ANY, the driver may/should set field to the previously configured interlacing field order".

What would be the correct place to document this behaviour? Documentation/media/uapi/v4l/vidioc-subdev-g-fmt.rst?

Quoted 5 lines
Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +5 -0
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
Quoted 8 lines

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

If sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT, then you can just copy all four fields from fmt to sdformat->format. The other three fields are meaningless when colorspace == V4L2_COLORSPACE_DEFAULT.

Ok, good. Ignoring the transfer function / YCbCr encoding / quantization range fields when colorspace is DEFAULT would simplify this part to:

	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
		sdformat->format.colorspace = fmt->colorspace;
		sdformat->format.xfer_func = fmt->xfer_func;
		sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
		sdformat->format.quantization = fmt->quantization;
	}

Is that expectation already written down somewhere? If not, should we add it to Documentation/media/uapi/v4l/pixfmt-006.rst?

Quoted 14 lines
Quoted 14 lines
drivers/staging/media/imx/imx-media-csi.c +14 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
Quoted 8 lines

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

Is this needed for validation? Currently these fields play no role in the default link validation. Which I think is actually the right thing to do, unless the subdev can do actual colorspace conversion.

The CSI subdevice can't do colorspace conversion, but exactly the same applies to the IC subdevices, which can. Also I'd like this information to be correct, as the /dev/videoX capture device takes its colorspace information from the CSI source pad.

The problem I wanted to solve here initially was that if the colorspace information was previously set correctly:

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60 colorspace:rec709 xfer:709 ycbcr:709 quantization:lim-range]"

    ->
	V4L2_COLORSPACE_REC709
	V4L2_XFER_FUNC_709
	V4L2_YCBCR_ENC_709
	V4L2_QUANTIZATION_LIMITED_RANGE

A later media-ctl call to just change the frame interval would overwrite the colorspace information:

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/30]"

    ->
	V4L2_COLORSPACE_DEFAULT
	V4L2_XFER_FUNC_DEFAULT
	V4L2_YCBCR_ENC_DEFAULT
	V4L2_QUANTIZATION_DEFAULT
Quoted 1 line

I would just drop the whole 'else' here.

That would allow to set the actual colorspace information reported by SUBDEV_G_FMT on both sink and source pads (and by extension, the colorspace information reported by G_FMT on /dev/videoX) to V4L2_{XFER_FUNC,YCBCR_ENC,QUANTIZATION}_DEFAULT.

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 colorspace:rec709]"

    ->
	V4L2_COLORSPACE_REC709
	V4L2_XFER_FUNC_DEFAULT
	V4L2_YCBCR_ENC_DEFAULT
	V4L2_QUANTIZATION_DEFAULT

I suppose that is acceptable as given the colorspace, the other DEFAULT values have a unique meaning, but wouldn't it be nicer to show userspace what these default inputs actually map to?

Quoted 3 lines

Actually, wouldn't it be better to always just copy this information from fmt? This subdev doesn't do any colorspace conversion, it just passes on this information. I.e., you can't set it in any meaningful way.

csi_set_fmt on the sink pad is the function that actually sets fmt in the first place. If we always copy colorspace information from fmt, it can't be set to the correct value at all.

regards
Philipp

#83 lore raw

Re: [PATCH] [media] imx: csi: retain current field order and colorimetry setting as default

Quoted 54 lines · Philipp Zabel

Hi Hans,

Quoted 3 lines · Hans Verkuil

Hi Philipp,

Sorry for the very long delay, but I finally had some time to think about this.

Thank you for your thoughts.

Quoted 37 lines · Philipp Zabel
Quoted 36 lines

If the the field order is set to ANY in set_fmt, choose the currently set field order. If the colorspace is set to DEFAULT, choose the current colorspace. If any of xfer_func, ycbcr_enc or quantization are set to DEFAULT, either choose the current setting, or the default setting for the new colorspace, if non-DEFAULT colorspace was given.

This allows to let field order and colorimetry settings be propagated from upstream by calling media-ctl on the upstream entity source pad, and then call media-ctl on the sink pad to manually set the input frame interval, without changing the already set field order and colorimetry information.

---
This is based on imx-media-staging-md-v14, and it is supposed to allow configuring the pipeline with media-ctl like this:

1) media-ctl --set-v4l2 "'tc358743 1-000f':0[fmt:UYVY8_1X16/1920x1080]"
2) media-ctl --set-v4l2 "'imx6-mipi-csi2':1[fmt:UYVY8_1X16/1920x108]"
3) media-ctl --set-v4l2 "'ipu1_csi0_mux':2[fmt:UYVY8_1X16/1920x1080]"
4) media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60]"
5) media-ctl --set-v4l2 "'ipu1_csi0':2[fmt:AYUV32/1920x1080 at 1/30]"

Without having step 4) overwrite the colorspace and field order set on 'ipu1_csi0':0 by the propagation in step 3).

---
 drivers/staging/media/imx/imx-media-csi.c | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +0 -0
index 64dc454f6b371..d94ce1de2bf05 100644
@@ -1325,6 +1325,40 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
Quoted 7 lines

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

Quoted 5 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+
+	/* Retain current field setting as default */
+	if (sdformat->format.field == V4L2_FIELD_ANY)
+		sdformat->format.field = fmt->field;

This is OK.

Quoted 3 lines

Would this be a "may" or a "should"? As in,
"If SUBDEV_S_FMT is called with field == ANY, the driver may/should set field to the previously configured interlacing field order".

To quote the FIELD_ANY documentation:

file:///home/hans/work/src/v4l/media-git/Documentation/output/html/uapi/v4l/field-order.html#field-order

"Drivers must never return V4L2_FIELD_ANY."

How a driver replaces FIELD_ANY is something that I am not sure should be explicitly stated in the documentation. In many cases there is only one choice (usually FIELD_NONE).

In cases like this I think your proposed rule is a good recommendation. I would probably phrase it like that.

Quoted 2 lines

What would be the correct place to document this behaviour? Documentation/media/uapi/v4l/vidioc-subdev-g-fmt.rst?

Yes.

Quoted 25 lines
Quoted 14 lines

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

Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +9 -0
+	/* Retain current colorspace setting as default */
+	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
+		sdformat->format.colorspace = fmt->colorspace;
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT)
+			sdformat->format.xfer_func = fmt->xfer_func;
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT)
+			sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT)
+			sdformat->format.quantization = fmt->quantization;

If sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT, then you can just copy all four fields from fmt to sdformat->format. The other three fields are meaningless when colorspace == V4L2_COLORSPACE_DEFAULT.

Ok, good. Ignoring the transfer function / YCbCr encoding / quantization range fields when colorspace is DEFAULT would simplify this part to:

	if (sdformat->format.colorspace == V4L2_COLORSPACE_DEFAULT) {
		sdformat->format.colorspace = fmt->colorspace;
		sdformat->format.xfer_func = fmt->xfer_func;
		sdformat->format.ycbcr_enc = fmt->ycbcr_enc;
		sdformat->format.quantization = fmt->quantization;
	}
Quoted 2 lines

Is that expectation already written down somewhere? If not, should we add it to Documentation/media/uapi/v4l/pixfmt-006.rst?

I don't think it is written down. It would be a good idea to make this explicit.

Quoted 39 lines
Quoted 15 lines
Quoted 15 lines
drivers/staging/media/imx/imx-media-csi.c +14 -0
+	} else {
+		if (sdformat->format.xfer_func == V4L2_XFER_FUNC_DEFAULT) {
+			sdformat->format.xfer_func =
+				V4L2_MAP_XFER_FUNC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.ycbcr_enc == V4L2_YCBCR_ENC_DEFAULT) {
+			sdformat->format.ycbcr_enc =
+				V4L2_MAP_YCBCR_ENC_DEFAULT(
+						sdformat->format.colorspace);
+		}
+		if (sdformat->format.quantization == V4L2_QUANTIZATION_DEFAULT) {
+			sdformat->format.quantization =
+				V4L2_MAP_QUANTIZATION_DEFAULT(
Quoted 8 lines

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

Quoted 4 lines
drivers/staging/media/imx/imx-media-csi.c +4 -0
+						cc->cs != IPUV3_COLORSPACE_YUV,
+						sdformat->format.colorspace,
+						sdformat->format.ycbcr_enc);
+		}

Is this needed for validation? Currently these fields play no role in the default link validation. Which I think is actually the right thing to do, unless the subdev can do actual colorspace conversion.

The CSI subdevice can't do colorspace conversion, but exactly the same applies to the IC subdevices, which can. Also I'd like this information to be correct, as the /dev/videoX capture device takes its colorspace information from the CSI source pad.

The problem I wanted to solve here initially was that if the colorspace information was previously set correctly:

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/60 colorspace:rec709 xfer:709 ycbcr:709 quantization:lim-range]"

    ->
	V4L2_COLORSPACE_REC709
	V4L2_XFER_FUNC_709
	V4L2_YCBCR_ENC_709
	V4L2_QUANTIZATION_LIMITED_RANGE
Quoted 8 lines

A later media-ctl call to just change the frame interval would overwrite the colorspace information:

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 at 1/30]"

    ->
	V4L2_COLORSPACE_DEFAULT
	V4L2_XFER_FUNC_DEFAULT
	V4L2_YCBCR_ENC_DEFAULT
	V4L2_QUANTIZATION_DEFAULT

Not anymore since if media-ctl sets colorspace to DEFAULT, then it will just copy the last configuration.

If media-ctl sets colorspace to a non-DEFAULT value, then I assume that it is a new explicitly defined colorspace.

Quoted 15 lines
Quoted 2 lines

I would just drop the whole 'else' here.

That would allow to set the actual colorspace information reported by SUBDEV_G_FMT on both sink and source pads (and by extension, the colorspace information reported by G_FMT on /dev/videoX) to V4L2_{XFER_FUNC,YCBCR_ENC,QUANTIZATION}_DEFAULT.

media-ctl --set-v4l2 "'ipu1_csi0':0[fmt:UYVY8_1X16/1920x1080 colorspace:rec709]"

    ->
	V4L2_COLORSPACE_REC709
	V4L2_XFER_FUNC_DEFAULT
	V4L2_YCBCR_ENC_DEFAULT
	V4L2_QUANTIZATION_DEFAULT
Quoted 3 lines

I suppose that is acceptable as given the colorspace, the other DEFAULT values have a unique meaning, but wouldn't it be nicer to show userspace what these default inputs actually map to?

Good question. Right now this isn't done in other drivers.

I have been struggling with this question myself. My problem is that I don't like to have to copy this code in every driver. Ideally this should be handled in the v4l2 core, but I am not sure if all the required information is available there.

I would postpone this, and look at this in a separate patch.

Quoted 7 lines
Quoted 3 lines

Actually, wouldn't it be better to always just copy this information from fmt? This subdev doesn't do any colorspace conversion, it just passes on this information. I.e., you can't set it in any meaningful way.

csi_set_fmt on the sink pad is the function that actually sets fmt in the first place. If we always copy colorspace information from fmt, it can't be set to the correct value at all.

Yes, sorry about that. Ignore that comment.

Regards,

Hans

author maintainer
#84 lore raw

PATCH v6 22/39 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 | 911 +++++++++++++++++++++++++++++
 2 files changed, 912 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 +911 -0

911 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#85 lore raw

PATCH v6 23/39 media: imx: Add IC subdev drivers

In reply to Steve Longerbeam

This is a set of three 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      |  434 ++++++++++
 drivers/staging/media/imx/imx-ic-prpencvf.c | 1170 +++++++++++++++++++++++++++
 drivers/staging/media/imx/imx-ic.h          |   38 +
 5 files changed, 1757 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 +434 -0

434 lines not on this page · raw message

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

1,170 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
#86 lore raw

PATCH v6 24/39 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 | 673 +++++++++++++++++++++++++++++
 2 files changed, 674 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 +673 -0

673 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#87 lore raw

PATCH v6 25/39 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 | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/configs/imx_v6_v7_defconfig +11 -0
index eaba3b1..5d8c94a 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
@@ -181,6 +182,7 @@ 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
@@ -221,14 +223,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 +346,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
#88 lore raw

PATCH v6 26/39 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 3e94179..83d227d 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 96a6931..b991081 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
#89 lore raw

PATCH v6 27/39 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 | 75 +++++++++++++++++++++++--------
 1 file changed, 57 insertions(+), 18 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +57 -18
index 9e2a73c..37c68d8 100644
@@ -285,10 +285,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];
@@ -306,24 +307,52 @@ static int csi_idmac_setup_channel(struct csi_priv *priv)
 	image.phys0 = phys[0];
 	image.phys1 = phys[1];
 
-	ret = ipu_cpmem_set_image(priv->idmac_ch, &image);
-	if (ret)
-		goto unsetup_vb2;
-
-	burst_size = (image.pix.width & 0xf) ? 8 : 16;
-
-	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:
+		burst_size = (image.pix.width & 0xf) ? 8 : 16;
+		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);
+	if (passthrough) {
+		ipu_cpmem_set_resolution(priv->idmac_ch, image.rect.width,
+					 image.rect.height);
+		ipu_cpmem_set_stride(priv->idmac_ch, image.pix.bytesperline);
+		ipu_cpmem_set_buffer(priv->idmac_ch, 0, image.phys0);
+		ipu_cpmem_set_buffer(priv->idmac_ch, 1, image.phys1);
+		ipu_cpmem_set_format_passthrough(priv->idmac_ch,
+						 passthrough_bits);
+	} else {
+		ret = ipu_cpmem_set_image(priv->idmac_ch, &image);
+		if (ret)
+			goto unsetup_vb2;
+	}
+
+	ipu_cpmem_set_burstsize(priv->idmac_ch, burst_size);
 
 	/*
 	 * Set the channel for the direct CSI-->memory via SMFC
@@ -737,6 +766,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;
 	struct imx_media_subdev *sensor;
 	bool is_csi2;
@@ -757,8 +787,17 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 
 	priv->sensor = sensor;
 	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");
+		ret = -EINVAL;
+		goto out;
+	}
 
 	if (is_csi2) {
 		int vc_num = 0;
@@ -783,7 +822,7 @@ static int csi_link_validate(struct v4l2_subdev *sd,
 
 	/* select either parallel or MIPI-CSI2 as input to CSI */
 	ipu_set_csi_src_mux(priv->ipu, priv->csi_id, is_csi2);
-
+out:
 	mutex_unlock(&priv->lock);
 	return ret;
 }
Signature · 1 line
2.7.4
author maintainer
#90 lore raw

PATCH v6 28/39 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 37c68d8..730966b 100644
@@ -555,6 +555,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);
@@ -945,15 +949,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)
-			goto out;
-		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,
@@ -999,6 +1003,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)
+			goto out;
+
 		cc = imx_media_find_format(0, sdformat->format.code,
 					   true, false);
 		if (!cc) {
@@ -1017,9 +1029,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
#91 lore raw

PATCH v6 29/39 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 | 61 ++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 14 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +47 -14
index 730966b..f4c6a33 100644
@@ -843,13 +843,26 @@ 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;
 	struct v4l2_mbus_framefmt *infmt;
 
-	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);
@@ -899,17 +912,24 @@ 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;
+	int ret = 0;
 
 	if (sdformat->pad >= CSI_NUM_PADS)
 		return -EINVAL;
 
 	mutex_lock(&priv->lock);
 
-	sdformat->format = priv->format_mbus[sdformat->pad];
+	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+	if (!fmt) {
+		ret = -EINVAL;
+		goto out;
+	}
 
+	sdformat->format = *fmt;
+out:
 	mutex_unlock(&priv->lock);
-
-	return 0;
+	return ret;
 }
 
 static int csi_set_fmt(struct v4l2_subdev *sd,
@@ -940,8 +960,6 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 		goto out;
 	}
 
-	infmt = &priv->format_mbus[CSI_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);
@@ -949,6 +967,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
@@ -1007,7 +1027,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)
 			goto out;
 
@@ -1052,7 +1073,11 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 
 	mutex_lock(&priv->lock);
 
-	infmt = &priv->format_mbus[CSI_SINK_PAD];
+	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
+	if (!infmt) {
+		ret = -EINVAL;
+		goto out;
+	}
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_CROP_BOUNDS:
@@ -1062,12 +1087,20 @@ 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:
 		ret = -EINVAL;
 	}
 
+out:
 	mutex_unlock(&priv->lock);
 	return ret;
 }
@@ -1077,7 +1110,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 = 0;
 
@@ -1111,15 +1143,16 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 		goto out;
 	}
 
-	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)
 		goto out;
 
 	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
#92 lore raw

PATCH v6 30/39 media: imx: csi/fim: add support for frame intervals

In reply to Steve Longerbeam

From: Russell King <[email protected]>

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 | 46 +++++++++++++++++++++++++++++--
 drivers/staging/media/imx/imx-media-fim.c | 28 +++++++------------
 drivers/staging/media/imx/imx-media.h     |  2 +-
 3 files changed, 54 insertions(+), 22 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +43 -3
index f4c6a33..59d80ba 100644
@@ -63,6 +63,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;
 
 	/* active vb2 buffers to send to video dev sink */
@@ -589,7 +590,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;
 	}
@@ -604,7 +606,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);
@@ -618,7 +621,8 @@ 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);
 }
@@ -627,6 +631,36 @@ static void csi_stop(struct csi_priv *priv)
  * V4L2 subdev operations.
  */
 
+static int csi_g_frame_interval(struct v4l2_subdev *sd,
+				struct v4l2_subdev_frame_interval *fi)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+
+	mutex_lock(&priv->lock);
+	fi->interval = priv->frame_interval;
+	mutex_unlock(&priv->lock);
+
+	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);
+
+	mutex_lock(&priv->lock);
+
+	/* 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;
+
+	mutex_unlock(&priv->lock);
+
+	return 0;
+}
+
 static int csi_s_stream(struct v4l2_subdev *sd, int enable)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
@@ -1216,6 +1250,10 @@ static int csi_registered(struct v4l2_subdev *sd)
 			goto put_csi;
 	}
 
+	/* init default frame interval */
+	priv->frame_interval.numerator = 1;
+	priv->frame_interval.denominator = 30;
+
 	priv->fim = imx_media_fim_init(&priv->sd);
 	if (IS_ERR(priv->fim)) {
 		ret = PTR_ERR(priv->fim);
@@ -1266,6 +1304,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 0623bc5..e9525cd 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 b991081..b6a0e41 100644
@@ -256,7 +256,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
#93 lore raw

PATCH v6 31/39 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           IPU RGB
YUV (any)        IPU YUV           IPU YUV
Bayer              N/A             must be same bayer code as sink

VDIC:

direct sink pad    IDMAC sink pad    direct src pad
---------------    --------------    --------------
IPU YUV only       IPU YUV only       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)          IPU RGB or IPU 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, bool allow_bayer); 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        |  77 ++++--
 drivers/staging/media/imx/imx-ic-prpencvf.c   |  57 ++--
 drivers/staging/media/imx/imx-media-capture.c |  85 ++++--
 drivers/staging/media/imx/imx-media-csi.c     | 108 +++++---
 drivers/staging/media/imx/imx-media-utils.c   | 371 +++++++++++++++++++-------
 drivers/staging/media/imx/imx-media-vdic.c    |  69 ++---
 drivers/staging/media/imx/imx-media.h         |  27 +-
 7 files changed, 504 insertions(+), 290 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +52 -25
index d0f4e82..505f456 100644
@@ -88,16 +88,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)
@@ -114,6 +104,38 @@ __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_pad_config *cfg,
  * V4L2 subdev operations.
  */
 
+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;
+
+	mutex_lock(&priv->lock);
+
+	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) {
+			ret = -EINVAL;
+			goto out;
+		}
+		infmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, code->which);
+		code->code = infmt->code;
+		break;
+	default:
+		ret = -EINVAL;
+	}
+out:
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+
 static int prp_get_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_pad_config *cfg,
 		       struct v4l2_subdev_format *sdformat)
@@ -159,23 +181,28 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		goto out;
 	}
 
-	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) {
@@ -367,7 +394,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 +20 -37

93 lines not on this page · raw message

drivers/staging/media/imx/imx-media-capture.c +56 -29

124 lines not on this page · raw message

drivers/staging/media/imx/imx-media-csi.c +64 -44

156 lines not on this page · raw message

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

477 lines not on this page · raw message

drivers/staging/media/imx/imx-media-vdic.c +22 -47

104 lines not on this page · raw message

drivers/staging/media/imx/imx-media.h +17 -10
index b6a0e41..9985aa0 100644
@@ -168,16 +168,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, bool allow_bayer);
+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
#94 lore raw

PATCH v6 32/39 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 | 127 ++++++++++++++++++++++++++++--
 1 file changed, 122 insertions(+), 5 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +122 -5
index 5a09fa8..d9c3a3b 100644
@@ -1,13 +1,15 @@
 /*
  * V4L2 Capture CSI Subdev for Freescale i.MX5/6 SOC
  *
- * Copyright (c) 2014-2016 Mentor Graphics Inc.
+ * Copyright (c) 2014-2017 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
  * 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 +42,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;
@@ -65,6 +79,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];
 
 	/* active vb2 buffers to send to video dev sink */
 	struct imx_media_buffer *active_vb2_buf[2];
@@ -536,10 +551,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;
@@ -564,6 +581,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;
@@ -627,6 +647,79 @@ 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;
+	}
+}
+
+/*
+ * 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) {
+		*out = *in;
+		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;
+}
+
 /*
  * V4L2 subdev operations.
  */
@@ -636,8 +729,16 @@ static int csi_g_frame_interval(struct v4l2_subdev *sd,
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 
+	if (fi->pad >= CSI_NUM_PADS)
+		return -EINVAL;
+
 	mutex_lock(&priv->lock);
+
 	fi->interval = priv->frame_interval;
+
+	if (fi->pad != CSI_SINK_PAD)
+		csi_apply_skip_interval(priv->skip[fi->pad - 1], &fi->interval);
+
 	mutex_unlock(&priv->lock);
 
 	return 0;
@@ -648,14 +749,27 @@ static int csi_s_frame_interval(struct v4l2_subdev *sd,
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 
+	if (fi->pad >= CSI_NUM_PADS)
+		return -EINVAL;
+
 	mutex_lock(&priv->lock);
 
-	/* 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;
+	/* 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];
 
-	priv->frame_interval = fi->interval;
+		goto out;
+	}
+
+	/* Output pads depend on input interval, modified by frame skipping */
+	priv->skip[fi->pad - 1] = csi_find_best_skip(&priv->frame_interval,
+						     &fi->interval);
 
+out:
 	mutex_unlock(&priv->lock);
 
 	return 0;
@@ -1268,6 +1382,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];
 	}
 
 	/* init default frame interval */
Signature · 1 line
2.7.4
author maintainer
#95 lore raw

PATCH v6 33/39 media: imx: csi: Avoid faulty sensor frames at stream start

In reply to Steve Longerbeam

If the attached sensor reports faulty frames at stream start via g_skip_frames callback, add a delay to avoid them before enabling the CSI hardware. Especially for sensors with a bt.656 interface, any shifts in the SAV/EAV sync codes will cause the CSI to lose vert/horiz sync.

---
 drivers/staging/media/imx/imx-media-csi.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +21 -0
index d9c3a3b..8597d7e 100644
@@ -9,6 +9,7 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  */
+#include <linux/delay.h>
 #include <linux/gcd.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
@@ -591,6 +592,7 @@ static int csi_setup(struct csi_priv *priv)
 
 static int csi_start(struct csi_priv *priv)
 {
+	u32 bad_frames = 0;
 	int ret;
 
 	if (!priv->sensor) {
@@ -598,6 +600,25 @@ static int csi_start(struct csi_priv *priv)
 		return -EINVAL;
 	}
 
+	ret = v4l2_subdev_call(priv->sensor->sd, sensor,
+			       g_skip_frames, &bad_frames);
+	if (!ret && bad_frames) {
+		struct v4l2_fract *fi = &priv->frame_interval;
+		u32 delay_usec;
+
+		/*
+		 * This sensor has bad frames when it is turned on,
+		 * add a delay to avoid them before enabling the CSI
+		 * hardware. Especially for sensors with a bt.656 interface,
+		 * any shifts in the SAV/EAV sync codes will cause the CSI
+		 * to lose vert/horiz sync.
+		 */
+		delay_usec = DIV_ROUND_UP_ULL(
+			(u64)USEC_PER_SEC * fi->numerator * bad_frames,
+			fi->denominator);
+		usleep_range(delay_usec, delay_usec + 1000);
+	}
+
 	if (priv->dest == IPU_CSI_DEST_IDMAC) {
 		ret = csi_idmac_start(priv);
 		if (ret)
Signature · 1 line
2.7.4
author maintainer
#96 lore raw

PATCH v6 34/39 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 8597d7e..dee5733 100644
@@ -1025,13 +1025,11 @@ __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;
 
-	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, which);
 	sensor_ep = &sensor->sensor_ep;
 
 	crop->width = min_t(__u32, infmt->width, crop->width);
@@ -1214,8 +1212,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)
 			goto out;
 
@@ -1299,6 +1296,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 = 0;
 
@@ -1332,7 +1330,8 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 		goto out;
 	}
 
-	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)
 		goto out;
 
Signature · 1 line
2.7.4
author maintainer
#97 lore raw

PATCH v6 35/39 media: imx: propagate sink pad formats to source pads

In reply to Steve Longerbeam

As part of this, separate format try code from *_set_fmt() into *_try_fmt(), so that the latter function can be used to propagate a legal format from sink to source. This also reduces subsequent bloat in *_set_fmt().

imx-ic-prp never needed separate formats for sink and source pads, so propagation in this case was easy, just have only a single format shared by both pads.

---
 drivers/staging/media/imx/imx-ic-prp.c        |  39 ++---
 drivers/staging/media/imx/imx-ic-prpencvf.c   |  95 +++++++----
 drivers/staging/media/imx/imx-media-capture.c |  13 ++
 drivers/staging/media/imx/imx-media-csi.c     | 224 +++++++++++++++-----------
 drivers/staging/media/imx/imx-media-vdic.c    |  82 ++++++----
 5 files changed, 279 insertions(+), 174 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +15 -24
index 505f456..b4d4e48 100644
@@ -56,8 +56,7 @@ struct prp_priv {
 	/* the CSI id at link validate */
 	int csi_id;
 
-	struct v4l2_mbus_framefmt format_mbus[PRP_NUM_PADS];
-	const struct imx_media_pixfmt *cc[PRP_NUM_PADS];
+	struct v4l2_mbus_framefmt format_mbus;
 
 	bool stream_on; /* streaming is on */
 };
@@ -97,7 +96,7 @@ __prp_get_fmt(struct prp_priv *priv, struct v4l2_subdev_pad_config *cfg,
 	if (which == V4L2_SUBDEV_FORMAT_TRY)
 		return v4l2_subdev_get_try_format(&ic_priv->sd, cfg, pad);
 	else
-		return &priv->format_mbus[pad];
+		return &priv->format_mbus;
 }
 
 /*
@@ -166,8 +165,8 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_format *sdformat)
 {
 	struct prp_priv *priv = sd_to_priv(sd);
-	const struct imx_media_pixfmt *cc = NULL;
-	struct v4l2_mbus_framefmt *infmt;
+	const struct imx_media_pixfmt *cc;
+	struct v4l2_mbus_framefmt *fmt;
 	int ret = 0;
 	u32 code;
 
@@ -198,20 +197,13 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	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;
+		fmt = __prp_get_fmt(priv, cfg, PRP_SINK_PAD, sdformat->which);
+		sdformat->format = *fmt;
 		break;
 	}
 
-	if (sdformat->which == V4L2_SUBDEV_FORMAT_TRY) {
-		cfg->try_fmt = sdformat->format;
-	} else {
-		priv->format_mbus[sdformat->pad] = sdformat->format;
-		priv->cc[sdformat->pad] = cc;
-	}
-
+	fmt = __prp_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
+	*fmt = sdformat->format;
 out:
 	mutex_unlock(&priv->lock);
 	return ret;
@@ -392,16 +384,15 @@ static int prp_registered(struct v4l2_subdev *sd)
 	for (i = 0; i < PRP_NUM_PADS; i++) {
 		priv->pad[i].flags = (i == PRP_SINK_PAD) ?
 			MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
-
-		/* set a default mbus format  */
-		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]);
-		if (ret)
-			return ret;
 	}
 
+	/* set a default mbus format  */
+	imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV);
+	ret = imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code,
+				      V4L2_FIELD_NONE, NULL);
+	if (ret)
+		return ret;
+
 	return media_entity_pads_init(&sd->entity, PRP_NUM_PADS, priv->pad);
 }
 
drivers/staging/media/imx/imx-ic-prpencvf.c +67 -28

116 lines not on this page · raw message

drivers/staging/media/imx/imx-media-capture.c +13 -0
index ff0a6ed..7521ca9 100644
@@ -506,6 +506,19 @@ static struct video_device capture_videodev = {
 	.device_caps	= V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING,
 };
 
+void imx_media_capture_device_set_format(struct imx_media_video_dev *vdev,
+					 struct v4l2_pix_format *pix)
+{
+	struct capture_priv *priv = to_capture_priv(vdev);
+
+	mutex_lock(&priv->mutex);
+	priv->vdev.fmt.fmt.pix = *pix;
+	priv->vdev.cc = imx_media_find_format(pix->pixelformat, CS_SEL_ANY,
+					      false);
+	mutex_unlock(&priv->mutex);
+}
+EXPORT_SYMBOL_GPL(imx_media_capture_device_set_format);
+
 struct imx_media_buffer *
 imx_media_capture_device_next_buf(struct imx_media_video_dev *vdev)
 {
drivers/staging/media/imx/imx-media-csi.c +131 -93

326 lines not on this page · raw message

drivers/staging/media/imx/imx-media-vdic.c +53 -29

110 lines not on this page · raw message

Signature · 1 line
2.7.4
author maintainer
#98 lore raw

PATCH v6 36/39 media: imx: csi: add sink selection rectangles

In reply to Steve Longerbeam

From: Philipp Zabel <[email protected]>

Move the crop rectangle to the sink pad and add a sink compose rectangle to configure scaling. Also propagate rectangles from sink pad to crop rectangle, to compose rectangle, and to the source pads both in ACTIVE and TRY variants of set_fmt/selection, and initialize the default crop and compose rectangles.

---
 drivers/staging/media/imx/imx-media-csi.c | 153 +++++++++++++++++++++++-------
 1 file changed, 117 insertions(+), 36 deletions(-)
drivers/staging/media/imx/imx-media-csi.c +117 -36
index 6b8f875..19609a7 100644
@@ -80,6 +80,7 @@ struct csi_priv {
 	const struct imx_media_pixfmt *cc[CSI_NUM_PADS];
 	struct v4l2_fract frame_interval;
 	struct v4l2_rect crop;
+	struct v4l2_rect compose;
 	const struct csi_skip_desc *skip[CSI_NUM_PADS - 1];
 
 	/* active vb2 buffers to send to video dev sink */
@@ -575,8 +576,8 @@ 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);
+			     priv->crop.width == 2 * priv->compose.width,
+			     priv->crop.height == 2 * priv->compose.height);
 
 	ipu_csi_init_interface(priv->csi, &sensor_mbus_cfg, &if_fmt);
 
@@ -1032,6 +1033,17 @@ __csi_get_crop(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg,
 		return &priv->crop;
 }
 
+static struct v4l2_rect *
+__csi_get_compose(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg,
+		  enum v4l2_subdev_format_whence which)
+{
+	if (which == V4L2_SUBDEV_FORMAT_TRY)
+		return v4l2_subdev_get_try_compose(&priv->sd, cfg,
+						   CSI_SINK_PAD);
+	else
+		return &priv->compose;
+}
+
 static void csi_try_crop(struct csi_priv *priv,
 			 struct v4l2_rect *crop,
 			 struct v4l2_subdev_pad_config *cfg,
@@ -1141,6 +1153,7 @@ static void csi_try_fmt(struct csi_priv *priv,
 			struct v4l2_subdev_pad_config *cfg,
 			struct v4l2_subdev_format *sdformat,
 			struct v4l2_rect *crop,
+			struct v4l2_rect *compose,
 			const struct imx_media_pixfmt **cc)
 {
 	const struct imx_media_pixfmt *incc;
@@ -1155,15 +1168,8 @@ static void csi_try_fmt(struct csi_priv *priv,
 		incc = imx_media_find_mbus_format(infmt->code,
 						  CS_SEL_ANY, true);
 
-		if (sdformat->format.width < crop->width * 3 / 4)
-			sdformat->format.width = crop->width / 2;
-		else
-			sdformat->format.width = crop->width;
-
-		if (sdformat->format.height < crop->height * 3 / 4)
-			sdformat->format.height = crop->height / 2;
-		else
-			sdformat->format.height = crop->height;
+		sdformat->format.width = compose->width;
+		sdformat->format.height = compose->height;
 
 		if (incc->bayer) {
 			sdformat->format.code = infmt->code;
@@ -1199,11 +1205,17 @@ static void csi_try_fmt(struct csi_priv *priv,
 		v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W,
 				      W_ALIGN, &sdformat->format.height,
 				      MIN_H, MAX_H, H_ALIGN, S_ALIGN);
+
+		/* Reset crop and compose rectangles */
 		crop->left = 0;
 		crop->top = 0;
 		crop->width = sdformat->format.width;
 		crop->height = sdformat->format.height;
 		csi_try_crop(priv, crop, cfg, &sdformat->format, sensor);
+		compose->left = 0;
+		compose->top = 0;
+		compose->width = crop->width;
+		compose->height = crop->height;
 
 		*cc = imx_media_find_mbus_format(sdformat->format.code,
 						 CS_SEL_ANY, true);
@@ -1228,7 +1240,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	struct imx_media_subdev *sensor;
 	struct v4l2_pix_format vdev_fmt;
 	struct v4l2_mbus_framefmt *fmt;
-	struct v4l2_rect *crop;
+	struct v4l2_rect *crop, *compose;
 	int ret = 0;
 
 	if (sdformat->pad >= CSI_NUM_PADS)
@@ -1248,8 +1260,9 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 	}
 
 	crop = __csi_get_crop(priv, cfg, sdformat->which);
+	compose = __csi_get_compose(priv, cfg, sdformat->which);
 
-	csi_try_fmt(priv, sensor, cfg, sdformat, crop, &cc);
+	csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc);
 
 	fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which);
 	*fmt = sdformat->format;
@@ -1266,7 +1279,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd,
 			format.pad = pad;
 			format.which = sdformat->which;
 			format.format = sdformat->format;
-			csi_try_fmt(priv, sensor, cfg, &format, crop, &outcc);
+			csi_try_fmt(priv, sensor, cfg, &format, NULL, compose,
+				    &outcc);
 
 			outfmt = __csi_get_fmt(priv, cfg, pad, sdformat->which);
 			*outfmt = format.format;
@@ -1300,16 +1314,17 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 	struct v4l2_mbus_framefmt *infmt;
-	struct v4l2_rect *crop;
+	struct v4l2_rect *crop, *compose;
 	int ret = 0;
 
-	if (sel->pad >= CSI_NUM_PADS || sel->pad == CSI_SINK_PAD)
+	if (sel->pad != CSI_SINK_PAD)
 		return -EINVAL;
 
 	mutex_lock(&priv->lock);
 
 	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
 	crop = __csi_get_crop(priv, cfg, sel->which);
+	compose = __csi_get_compose(priv, cfg, sel->which);
 
 	switch (sel->target) {
 	case V4L2_SEL_TGT_CROP_BOUNDS:
@@ -1321,6 +1336,15 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 	case V4L2_SEL_TGT_CROP:
 		sel->r = *crop;
 		break;
+	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+		sel->r.left = 0;
+		sel->r.top = 0;
+		sel->r.width = crop->width;
+		sel->r.height = crop->height;
+		break;
+	case V4L2_SEL_TGT_COMPOSE:
+		sel->r = *compose;
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -1329,19 +1353,34 @@ static int csi_get_selection(struct v4l2_subdev *sd,
 	return ret;
 }
 
+static int csi_set_scale(u32 *compose, u32 crop, u32 flags)
+{
+	if ((flags & (V4L2_SEL_FLAG_LE | V4L2_SEL_FLAG_GE)) ==
+		     (V4L2_SEL_FLAG_LE | V4L2_SEL_FLAG_GE) &&
+	    *compose != crop && *compose != crop / 2)
+		return -ERANGE;
+
+	if (*compose <= crop / 2 ||
+	    (*compose < crop * 3 / 4 && !(flags & V4L2_SEL_FLAG_GE)) ||
+	    (*compose < crop && (flags & V4L2_SEL_FLAG_LE)))
+		*compose = crop / 2;
+	else
+		*compose = crop;
+
+	return 0;
+}
+
 static int csi_set_selection(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_pad_config *cfg,
 			     struct v4l2_subdev_selection *sel)
 {
 	struct csi_priv *priv = v4l2_get_subdevdata(sd);
 	struct v4l2_mbus_framefmt *infmt;
+	struct v4l2_rect *crop, *compose;
 	struct imx_media_subdev *sensor;
-	struct v4l2_rect *crop;
 	int pad, ret = 0;
 
-	if (sel->pad >= CSI_NUM_PADS ||
-	    sel->pad == CSI_SINK_PAD ||
-	    sel->target != V4L2_SEL_TGT_CROP)
+	if (sel->pad != CSI_SINK_PAD)
 		return -EINVAL;
 
 	sensor = imx_media_find_sensor(priv->md, &priv->sd.entity);
@@ -1359,30 +1398,66 @@ static int csi_set_selection(struct v4l2_subdev *sd,
 
 	infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which);
 	crop = __csi_get_crop(priv, cfg, sel->which);
+	compose = __csi_get_compose(priv, cfg, sel->which);
 
-	/*
-	 * Modifying the crop rectangle always changes the format on the source
-	 * pad. If the KEEP_CONFIG flag is set, just return the current crop
-	 * rectangle.
-	 */
-	if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
-		sel->r = priv->crop;
-		if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
-			*crop = sel->r;
-		goto out;
-	}
+	switch (sel->target) {
+	case V4L2_SEL_TGT_CROP:
+		/*
+		 * Modifying the crop rectangle always changes the format on
+		 * the source pads. If the KEEP_CONFIG flag is set, just return
+		 * the current crop rectangle.
+		 */
+		if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
+			sel->r = priv->crop;
+			if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+				*crop = sel->r;
+			goto out;
+		}
+
+		csi_try_crop(priv, &sel->r, cfg, infmt, sensor);
+
+		*crop = sel->r;
+
+		/* Reset scaling to 1:1 */
+		compose->width = crop->width;
+		compose->height = crop->height;
+		break;
+	case V4L2_SEL_TGT_COMPOSE:
+		/*
+		 * Modifying the compose rectangle always changes the format on
+		 * the source pads. If the KEEP_CONFIG flag is set, just return
+		 * the current compose rectangle.
+		 */
+		if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
+			sel->r = priv->compose;
+			if (sel->which == V4L2_SUBDEV_FORMAT_TRY)
+				*compose = sel->r;
+			goto out;
+		}
 
-	csi_try_crop(priv, &sel->r, cfg, infmt, sensor);
+		sel->r.left = 0;
+		sel->r.top = 0;
+		ret = csi_set_scale(&sel->r.width, crop->width, sel->flags);
+		if (ret)
+			goto out;
+		ret = csi_set_scale(&sel->r.height, crop->height, sel->flags);
+		if (ret)
+			goto out;
 
-	*crop = sel->r;
+		*compose = sel->r;
+		break;
+	default:
+		ret = -EINVAL;
+		goto out;
+	}
 
-	/* Update the source pad formats */
+	/* Reset source pads to sink compose rectangle */
 	for (pad = CSI_SINK_PAD + 1; pad < CSI_NUM_PADS; pad++) {
 		struct v4l2_mbus_framefmt *outfmt;
 
 		outfmt = __csi_get_fmt(priv, cfg, pad, sel->which);
-		outfmt->width = crop->width;
-		outfmt->height = crop->height;
+		outfmt->width = compose->width;
+		outfmt->height = compose->height;
 	}
 
 out:
@@ -1445,6 +1520,12 @@ static int csi_registered(struct v4l2_subdev *sd)
 			priv->skip[i - 1] = &csi_skip[0];
 	}
 
+	/* init default crop and compose rectangle sizes */
+	priv->crop.width = 640;
+	priv->crop.height = 480;
+	priv->compose.width = 640;
+	priv->compose.height = 480;
+
 	/* init default frame interval */
 	priv->frame_interval.numerator = 1;
 	priv->frame_interval.denominator = 30;
Signature · 1 line
2.7.4
author maintainer
#99 lore raw

PATCH v6 37/39 media: imx-csi: add frame size/interval enumeration

In reply to Steve Longerbeam

From: Russell King <[email protected]>

Add frame size and frame interval enumeration to CSI.

CSI can downscale the image independently horizontally and vertically by a factor of two, which enumerates to four different frame sizes at the output pads. The input pad supports a range of frame sizes.

CSI can also drop frames, resulting in frame rate reduction, so enumerate the resulting possible output frame rates.

---
 drivers/staging/media/imx/imx-media-csi.c | 62 +++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
drivers/staging/media/imx/imx-media-csi.c +62 -0
index 19609a7..b11e80f 100644
@@ -1123,6 +1123,66 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,
 	return ret;
 }
 
+static int csi_enum_frame_size(struct v4l2_subdev *sd,
+			       struct v4l2_subdev_pad_config *cfg,
+			       struct v4l2_subdev_frame_size_enum *fse)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	struct v4l2_rect *crop;
+	int ret = 0;
+
+	if (fse->pad >= CSI_NUM_PADS ||
+	    fse->index > (fse->pad == CSI_SINK_PAD ? 0 : 3))
+		return -EINVAL;
+
+	mutex_lock(&priv->lock);
+
+	if (fse->pad == CSI_SINK_PAD) {
+		fse->min_width = MIN_W;
+		fse->max_width = MAX_W;
+		fse->min_height = MIN_H;
+		fse->max_height = MAX_H;
+	} else {
+		crop = __csi_get_crop(priv, cfg, fse->which);
+
+		fse->min_width = fse->max_width = fse->index & 1 ?
+			crop->width / 2 : crop->width;
+		fse->min_height = fse->max_height = fse->index & 2 ?
+			crop->height / 2 : crop->height;
+	}
+
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+
+static int csi_enum_frame_interval(struct v4l2_subdev *sd,
+				   struct v4l2_subdev_pad_config *cfg,
+				   struct v4l2_subdev_frame_interval_enum *fie)
+{
+	struct csi_priv *priv = v4l2_get_subdevdata(sd);
+	struct v4l2_rect *crop;
+	int ret = 0;
+
+	if (fie->pad >= CSI_NUM_PADS ||
+	    fie->index >= (fie->pad == CSI_SINK_PAD ? 1 : ARRAY_SIZE(csi_skip)))
+		return -EINVAL;
+
+	mutex_lock(&priv->lock);
+
+	crop = __csi_get_crop(priv, cfg, fie->which);
+
+	if ((fie->width == crop->width || fie->width == crop->width / 2) &&
+	    (fie->height == crop->height || fie->height == crop->height / 2)) {
+		fie->interval = priv->frame_interval;
+		csi_apply_skip_interval(&csi_skip[fie->index], &fie->interval);
+	} else {
+		ret = -EINVAL;
+	}
+	mutex_unlock(&priv->lock);
+
+	return ret;
+}
+
 static int csi_get_fmt(struct v4l2_subdev *sd,
 		       struct v4l2_subdev_pad_config *cfg,
 		       struct v4l2_subdev_format *sdformat)
@@ -1587,6 +1647,8 @@ static struct v4l2_subdev_video_ops csi_video_ops = {
 
 static struct v4l2_subdev_pad_ops csi_pad_ops = {
 	.enum_mbus_code = csi_enum_mbus_code,
+	.enum_frame_size = csi_enum_frame_size,
+	.enum_frame_interval = csi_enum_frame_interval,
 	.get_fmt = csi_get_fmt,
 	.set_fmt = csi_set_fmt,
 	.get_selection = csi_get_selection,
Signature · 1 line
2.7.4
author maintainer
#100 lore raw

PATCH v6 38/39 media: imx-ic-prpencvf: add frame size enumeration

In reply to Steve Longerbeam

Add frame size enumeration operation. The PRP ENC/VF subdevices are scalers, so they can output a continuous range of widths/ heights on their source pads.

---
 drivers/staging/media/imx/imx-ic-prpencvf.c | 40 +++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/staging/media/imx/imx-ic-prpencvf.c +40 -0
index 4123b03..860b406 100644
@@ -875,6 +875,45 @@ static int prp_set_fmt(struct v4l2_subdev *sd,
 	return ret;
 }
 
+static int prp_enum_frame_size(struct v4l2_subdev *sd,
+			       struct v4l2_subdev_pad_config *cfg,
+			       struct v4l2_subdev_frame_size_enum *fse)
+{
+	struct prp_priv *priv = sd_to_priv(sd);
+	struct v4l2_subdev_format format = {0};
+	const struct imx_media_pixfmt *cc;
+	int ret = 0;
+
+	if (fse->pad >= PRPENCVF_NUM_PADS || fse->index != 0)
+		return -EINVAL;
+
+	mutex_lock(&priv->lock);
+
+	format.pad = fse->pad;
+	format.which = fse->which;
+	format.format.code = fse->code;
+	format.format.width = 1;
+	format.format.height = 1;
+	prp_try_fmt(priv, cfg, &format, &cc);
+	fse->min_width = format.format.width;
+	fse->min_height = format.format.height;
+
+	if (format.format.code != fse->code) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	format.format.code = fse->code;
+	format.format.width = -1;
+	format.format.height = -1;
+	prp_try_fmt(priv, cfg, &format, &cc);
+	fse->max_width = format.format.width;
+	fse->max_height = format.format.height;
+out:
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+
 static int prp_link_setup(struct media_entity *entity,
 			  const struct media_pad *local,
 			  const struct media_pad *remote, u32 flags)
@@ -1125,6 +1164,7 @@ static void prp_unregistered(struct v4l2_subdev *sd)
 
 static struct v4l2_subdev_pad_ops prp_pad_ops = {
 	.enum_mbus_code = prp_enum_mbus_code,
+	.enum_frame_size = prp_enum_frame_size,
 	.get_fmt = prp_get_fmt,
 	.set_fmt = prp_set_fmt,
 	.link_validate = prp_link_validate,
Signature · 1 line
2.7.4
author maintainer
#101 lore raw

PATCH v6 39/39 media: imx-media-capture: add frame sizes/interval enumeration

In reply to Steve Longerbeam

From: Russell King <[email protected]>

Add support for enumerating frame sizes and frame intervals from the first subdev via the V4L2 interfaces.

---
 drivers/staging/media/imx/imx-media-capture.c | 73 +++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
drivers/staging/media/imx/imx-media-capture.c +73 -0
index 7521ca9..11a8689 100644
@@ -82,6 +82,76 @@ static int vidioc_querycap(struct file *file, void *fh,
 	return 0;
 }
 
+static int capture_enum_framesizes(struct file *file, void *fh,
+				   struct v4l2_frmsizeenum *fsize)
+{
+	struct capture_priv *priv = video_drvdata(file);
+	const struct imx_media_pixfmt *cc;
+	struct v4l2_subdev_frame_size_enum fse = {
+		.index = fsize->index,
+		.pad = priv->src_sd_pad,
+		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+	};
+	int ret;
+
+	cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY, true);
+	if (!cc)
+		return -EINVAL;
+
+	fse.code = cc->codes[0];
+
+	ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_size, NULL, &fse);
+	if (ret)
+		return ret;
+
+	if (fse.min_width == fse.max_width &&
+	    fse.min_height == fse.max_height) {
+		fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+		fsize->discrete.width = fse.min_width;
+		fsize->discrete.height = fse.min_height;
+	} else {
+		fsize->type = V4L2_FRMSIZE_TYPE_CONTINUOUS;
+		fsize->stepwise.min_width = fse.min_width;
+		fsize->stepwise.max_width = fse.max_width;
+		fsize->stepwise.min_height = fse.min_height;
+		fsize->stepwise.max_height = fse.max_height;
+		fsize->stepwise.step_width = 1;
+		fsize->stepwise.step_height = 1;
+	}
+
+	return 0;
+}
+
+static int capture_enum_frameintervals(struct file *file, void *fh,
+				       struct v4l2_frmivalenum *fival)
+{
+	struct capture_priv *priv = video_drvdata(file);
+	const struct imx_media_pixfmt *cc;
+	struct v4l2_subdev_frame_interval_enum fie = {
+		.index = fival->index,
+		.pad = priv->src_sd_pad,
+		.width = fival->width,
+		.height = fival->height,
+		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+	};
+	int ret;
+
+	cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY, true);
+	if (!cc)
+		return -EINVAL;
+
+	fie.code = cc->codes[0];
+
+	ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_interval, NULL, &fie);
+	if (ret)
+		return ret;
+
+	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+	fival->discrete = fie.interval;
+
+	return 0;
+}
+
 static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
 				    struct v4l2_fmtdesc *f)
 {
@@ -270,6 +340,9 @@ static int capture_s_parm(struct file *file, void *fh,
 static const struct v4l2_ioctl_ops capture_ioctl_ops = {
 	.vidioc_querycap	= vidioc_querycap,
 
+	.vidioc_enum_framesizes = capture_enum_framesizes,
+	.vidioc_enum_frameintervals = capture_enum_frameintervals,
+
 	.vidioc_enum_fmt_vid_cap        = capture_enum_fmt_vid_cap,
 	.vidioc_g_fmt_vid_cap           = capture_g_fmt_vid_cap,
 	.vidioc_try_fmt_vid_cap         = capture_try_fmt_vid_cap,
Signature · 1 line
2.7.4
#102 lore raw
In reply to Steve Longerbeam

This fails at step 1. The removal of the frame interval support now means my setup script fails when trying to set the frame interval on the camera:

Enumerating pads and links
Setting up format SRGGB8_1X8 816x616 on pad imx219 0-0010/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx219 0-0010/0
Frame interval set: 1/25
Setting up format SRGGB8_1X8 816x616 on pad imx6-mipi-csi2/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx6-mipi-csi2/0
Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

This is because media-ctl tries to propagate it from the imx219 source pad to the csi2 sink pad, and the csi2 now fails that ioctl.

This makes media-ctl return a failure code, which means that it's not possible for a script to determine whether the failure was due to the camera setup or something else. So, we have to assume that the whole command failed.

This is completely broken, and I'm even more convinced that those arguing for this behaviour really have not thought it through well enough before demanding that this code was removed.

As far as I'm concerned, the end result is completely broken and unusable. I'm going to be merging the frame interval support back into my test tree, because that's the only sane thing to do.

If v4l2 people want to object to having frame interval support present for all subdevs, then _they_ need to make sure that the rest of their software conforms to what they're telling people to do.

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
#103 lore raw
Quoted 14 lines · Russell King - ARM Linux

This fails at step 1. The removal of the frame interval support now means my setup script fails when trying to set the frame interval on the camera:

Enumerating pads and links
Setting up format SRGGB8_1X8 816x616 on pad imx219 0-0010/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx219 0-0010/0
Frame interval set: 1/25
Setting up format SRGGB8_1X8 816x616 on pad imx6-mipi-csi2/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx6-mipi-csi2/0
Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

Quoted 2 lines

This is because media-ctl tries to propagate it from the imx219 source pad to the csi2 sink pad, and the csi2 now fails that ioctl.

I assume you're using Philipp's frame interval patches to media-ctl. Can you make the frame interval propagation optional in those patches? I.e. don't error-out with a failure code if the ioctl returns ENOTTY.

Steve

Quoted 18 lines

This makes media-ctl return a failure code, which means that it's not possible for a script to determine whether the failure was due to the camera setup or something else. So, we have to assume that the whole command failed.

This is completely broken, and I'm even more convinced that those arguing for this behaviour really have not thought it through well enough before demanding that this code was removed.

As far as I'm concerned, the end result is completely broken and unusable. I'm going to be merging the frame interval support back into my test tree, because that's the only sane thing to do.

If v4l2 people want to object to having frame interval support present for all subdevs, then _they_ need to make sure that the rest of their software conforms to what they're telling people to do.

#104 lore raw
Quoted 17 lines · Steve Longerbeam
Quoted 14 lines · Russell King - ARM Linux

This fails at step 1. The removal of the frame interval support now means my setup script fails when trying to set the frame interval on the camera:

Enumerating pads and links
Setting up format SRGGB8_1X8 816x616 on pad imx219 0-0010/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx219 0-0010/0
Frame interval set: 1/25
Setting up format SRGGB8_1X8 816x616 on pad imx6-mipi-csi2/0
Format set: SRGGB8_1X8 816x616
Setting up frame interval 1/25 on pad imx6-mipi-csi2/0
Unable to set frame interval: Inappropriate ioctl for device (-25)Unable to setup formats: Inappropriate ioctl for device (25)

Quoted 6 lines
Quoted 2 lines

This is because media-ctl tries to propagate it from the imx219 source pad to the csi2 sink pad, and the csi2 now fails that ioctl.

I assume you're using Philipp's frame interval patches to media-ctl. Can you make the frame interval propagation optional in those patches? I.e. don't error-out with a failure code if the ioctl returns ENOTTY.

Damn, you're right. There's way too much stuff to try and keep track of with this stuff.

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.