Skip to contentSkip to conversation

Support for Synopsys DW CSI-2 Host

PATCH In review Ramiro Oliveira 5 participants 17 messages Mar 7, 2017 – May 17, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Support for Synopsys DW CSI-2 Host

This patchset adds support for the DW CSI-2 Host and also for a video device associated with it.

The first 2 patches are only for the DW CSI-2 Host and the last 2 are for the video device.

Although this patchset is named as v1 there were already two patchsets previous to this one, but with a different name: "Add support for the DW IP Prototyping Kits for MIPI CSI-2 Host".

v3:
- Correct description errors in Documentation
- Remove empty functions
- Change device caps and description setting
- Remove left-over code
- Add more VB2 io_modes
- Add support for dma_contig
- Correct spelling mistakes

v2:
- Add more detailed descriptions in the DT documentation
- Add binding examples to DT documentation
- Remove unnecessary debug structures
- Remove unused fields in structures
- Change variable types
- Remove unused functions
- Declare functions as static
- Remove some prints
- Add missing newlines.

Ramiro Oliveira (4):
Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host
media: platform: dwc: Support for DW CSI-2 Host
Documentation: dt: Add bindings documentation for CSI-2 Host Video
Platform
media: platform: dwc: Support for CSI-2 Host video platform

 .../devicetree/bindings/media/snps,dw-mipi-csi.txt |  37 +
 .../devicetree/bindings/media/snps,plat-csi2.txt   |  77 ++
 MAINTAINERS                                        |   7 +
 drivers/media/platform/Kconfig                     |   1 +
 drivers/media/platform/Makefile                    |   2 +
 drivers/media/platform/dwc/Kconfig                 |  45 ++
 drivers/media/platform/dwc/Makefile                |   3 +
 drivers/media/platform/dwc/csi_video_device.c      | 721 ++++++++++++++++++
 drivers/media/platform/dwc/csi_video_device.h      |  83 +++
 drivers/media/platform/dwc/csi_video_plat.c        | 818 +++++++++++++++++++++
 drivers/media/platform/dwc/csi_video_plat.h        | 101 +++
 drivers/media/platform/dwc/dw_mipi_csi.c           | 653 ++++++++++++++++
 drivers/media/platform/dwc/dw_mipi_csi.h           | 181 +++++
 include/media/dwc/csi_host_platform.h              |  97 +++
 14 files changed, 2826 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/csi_video_device.c
 create mode 100644 drivers/media/platform/dwc/csi_video_device.h
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.c
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.h
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h
Signature · 7 lines
2.11.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/4 Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host

Create device tree bindings documentation for the Synopsys DW MIPI CSI-2
Host.

---
 .../devicetree/bindings/media/snps,dw-mipi-csi.txt | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +37 -0
new file mode 100644
index 000000000000..5b24eb43d760
@@ -0,0 +1,37 @@
+Synopsys DesignWare CSI-2 Host controller
+
+Description
+-----------
+
+This HW block is used to receive image coming from an MIPI CSI-2 compatible
+camera.
+
+Required properties:
+- compatible: shall be "snps,dw-mipi-csi"
+- reg		: physical base address and size of the device memory mapped
+  registers;
+- interrupts	: CSI-2 Host interrupt
+- output-type   : Core output to be used (IPI-> 0 or IDI->1 or BOTH->2) These
+  values choose which of the Core outputs will be used, it can be Image Data
+  Interface or Image Pixel Interface.
+- phys: List of one PHY specifier (as defined in
+  Documentation/devicetree/bindings/phy/phy-bindings.txt). This PHY is a MIPI
+  DPHY working in RX mode.
+- resets: Reference to a reset controller (optional)
+
+Optional properties(if in IPI mode):
+- ipi-mode 	: Mode to be used when in IPI(Camera -> 0 or Controller -> 1)
+  This property defines if the controller will use the video timings available
+  in the video stream or if it will use pre-defined ones.
+- ipi-color-mode: Bus depth to be used in IPI (48 bits -> 0 or 16 bits -> 1)
+  This property defines the width of the IPI bus.
+- ipi-auto-flush: Data auto-flush (1 -> Yes or 0 -> No). This property defines
+  if the data is automatically flushed in each vsync or if this process is done
+  manually
+- virtual-channel: Virtual channel where data is present when in IPI mode. This
+  property chooses the virtual channel which IPI will use to retrieve the video
+  stream.
+
+The per-board settings:
+ - port sub-node describing a single endpoint connected to the camera as
+   described in video-interfaces.txt[1].
Signature · 7 lines
2.11.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 2/4 media: platform: dwc: Support for DW CSI-2 Host

In reply to Ramiro Oliveira

Add support for the Synopsys DesignWare CSI-2 Host

---
 MAINTAINERS                              |   7 +
 drivers/media/platform/Kconfig           |   1 +
 drivers/media/platform/Makefile          |   2 +
 drivers/media/platform/dwc/Kconfig       |   5 +
 drivers/media/platform/dwc/Makefile      |   1 +
 drivers/media/platform/dwc/dw_mipi_csi.c | 653 +++++++++++++++++++++++++++++++
 drivers/media/platform/dwc/dw_mipi_csi.h | 181 +++++++++
 include/media/dwc/csi_host_platform.h    |  97 +++++
 8 files changed, 947 insertions(+)
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h
MAINTAINERS +7 -0
index 5badfd33e51f..19673dad43b4 100644
@@ -11061,6 +11061,13 @@ S:	Maintained
 F:	drivers/staging/media/st-cec/
 F:	Documentation/devicetree/bindings/media/stih-cec.txt
 
+SYNOPSYS DESIGNWARE CSI-2 HOST VIDEO PLATFORM
+M:	Ramiro Oliveira <roliveir-HKixBCOQz3hWk0Htik3J/[email protected]>
+L:	[email protected]
+T:	git git://linuxtv.org/media_tree.git
+S:	Maintained
+F:	drivers/media/platform/dwc/
+
 SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS
 M:	Ursula Braun <[email protected]>
 L:	[email protected]
drivers/media/platform/Kconfig +1 -0
index 53f6f12bff0d..4b6e00da763f 100644
@@ -120,6 +120,7 @@ source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
 source "drivers/media/platform/atmel/Kconfig"
+source "drivers/media/platform/dwc/Kconfig"
 
 config VIDEO_TI_CAL
 	tristate "TI CAL (Camera Adaptation Layer) driver"
drivers/media/platform/Makefile +2 -0
index 8959f6e6692a..95eae2772c1f 100644
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)		+= rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)		+= atmel/
 
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)	+= dwc/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)	+= mtk-vpu/
drivers/media/platform/dwc/Kconfig new file +5 -0
new file mode 100644
index 000000000000..2cd13d23f897
@@ -0,0 +1,5 @@
+config DWC_MIPI_CSI2_HOST
+	tristate "SNPS DWC MIPI CSI2 Host"
+	select GENERIC_PHY
+	help
+	  This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
drivers/media/platform/dwc/Makefile new file +1 -0
new file mode 100644
index 000000000000..5eb076a55123
@@ -0,0 +1 @@
+obj-$(CONFIG_DWC_MIPI_CSI2_HOST)	+= dw_mipi_csi.o
drivers/media/platform/dwc/dw_mipi_csi.c new file +653 -0

653 lines not on this page · raw message

drivers/media/platform/dwc/dw_mipi_csi.h new file +181 -0

181 lines not on this page · raw message

include/media/dwc/csi_host_platform.h new file +97 -0

97 lines not on this page · raw message

Signature · 7 lines
2.11.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

PATCH 3/4 Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

In reply to Ramiro Oliveira

Create device tree bindings documentation for the CSI-2 Host Video
platform.

---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +77 -0
new file mode 100644
index 000000000000..f559257a0a44
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+--------------------
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+-------------------
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
+------------------
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.
+
+Example:
+
+
+	camera {
+		compatible = "snps,plat-csi2", "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+			video_device: video-device@0x10000 {
+				compatible = "snps,video-device";
+				dmas = <&axi_vdma_0 0>;
+				dma-names = "vdma0";
+			};
+
+			csi2:	csi2@0x03000 {
+				compatible = "snps,dw-mipi-csi";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = < 0x03000 0x7FF>;
+				interrupts = <2>;
+				phys = <&mipi_phy_ctrl1 0>;
+				resets = <&csi2_rst 1>;
+
+				output-type = <2>;
+				ipi-mode = <0>;
+				ipi-color-mode = <0>;
+				ipi-auto-flush = <1>;
+				virtual-channel = <0>;
+
+				port@1 {
+					reg = <1>;
+					csi1_ep1: endpoint {
+						remote-endpoint = <&camera>;
+						data-lanes = <1 2>;
+					};
+				};
+			};
+		};
+	};
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
Signature · 1 line
2.11.0
#14 lore raw

PATCH 4/4 media: platform: dwc: Support for CSI-2 Host video platform

In reply to Ramiro Oliveira

Add support for the CSI-2 Host video platform. This platform exists only
to support the Synopsys DW CSI-2 Host bring-up and debug efforts.

---
 drivers/media/platform/dwc/Kconfig            |  40 ++
 drivers/media/platform/dwc/Makefile           |   2 +
 drivers/media/platform/dwc/csi_video_device.c | 721 +++++++++++++++++++++++
 drivers/media/platform/dwc/csi_video_device.h |  83 +++
 drivers/media/platform/dwc/csi_video_plat.c   | 818 ++++++++++++++++++++++++++
 drivers/media/platform/dwc/csi_video_plat.h   | 101 ++++
 6 files changed, 1765 insertions(+)
 create mode 100644 drivers/media/platform/dwc/csi_video_device.c
 create mode 100644 drivers/media/platform/dwc/csi_video_device.h
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.c
 create mode 100644 drivers/media/platform/dwc/csi_video_plat.h
drivers/media/platform/dwc/Kconfig +40 -0
index 2cd13d23f897..057208ec3e7b 100644
@@ -1,5 +1,45 @@
+config CSI_VIDEO_PLATFORM
+	tristate "Designware Cores CSI-2 VIDEO PLATFORM"
+	select DWC_MIPI_CSI2_HOST
+	select CSI_VIDEO_DEVICE
+	depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && OF && HAS_DMA
+	help
+	  This a V4L2 driver to support the DesignWare Cores CSI-2 Host Video
+	  Platform.
+
+	  To compile this driver as a module, choose M here
+
+if CSI_VIDEO_PLATFORM
+
 config DWC_MIPI_CSI2_HOST
 	tristate "SNPS DWC MIPI CSI2 Host"
 	select GENERIC_PHY
 	help
 	  This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
+
+config CSI_VIDEO_DEVICE
+	tristate "DWC VIDEO DEVICE"
+	depends on CSI_VIDEO_PLATFORM
+	help
+	  This is a V4L2 driver for the CSI-2 Video platform video device
+
+choice
+	prompt "Video Device Videobuf2 mode"
+	depends on CSI_VIDEO_DEVICE
+	default VIDEO_DWC_DMA_CONTIG
+
+config VIDEO_DWC_DMA_CONTIG
+	bool "Support Videobuf2 DMA CONTIG"
+	select VIDEOBUF2_DMA_CONTIG
+	help
+	  Use DMA CONTIG in CSI Video Device
+
+config VIDEO_DWC_VMALLOC
+	bool "Support Videobuf2 VMALLOC"
+	select VIDEOBUF2_VMALLOC
+	help
+	  Use VMALLOC in CSI Video Device
+
+endchoice
+
+endif # CSI2_VIDEO_PLATFORM
drivers/media/platform/dwc/Makefile +2 -0
index 5eb076a55123..ab6f76296b34 100644
@@ -1 +1,3 @@
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)	+= csi_video_plat.o
 obj-$(CONFIG_DWC_MIPI_CSI2_HOST)	+= dw_mipi_csi.o
+obj-$(CONFIG_CSI_VIDEO_DEVICE)		+= csi_video_device.o
drivers/media/platform/dwc/csi_video_device.c new file +721 -0

721 lines not on this page · raw message

drivers/media/platform/dwc/csi_video_device.h new file +83 -0

83 lines not on this page · raw message

drivers/media/platform/dwc/csi_video_plat.c new file +818 -0

818 lines not on this page · raw message

drivers/media/platform/dwc/csi_video_plat.h new file +101 -0

101 lines not on this page · raw message

Signature · 7 lines
2.11.0


--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

Re: [PATCH 3/4] Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

In reply to Ramiro Oliveira

Hi Ramiro,

Quoted 2 lines · Ramiro Oliveira

Create device tree bindings documentation for the CSI-2 Host Video
platform.

Extra space here.

Quoted 38 lines
---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +25 -0
new file mode 100644
index 000000000000..f559257a0a44
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+--------------------
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+-------------------
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 35

Quoted 10 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +10 -0
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
+------------------
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.

You should defined which properties you explicitly support on endpoints and elsewhere. There are some optional ones for CSI-2, for instance.

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 44

Quoted 9 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +9 -0
+
+Example:
+
+
+	camera {
+		compatible = "snps,plat-csi2", "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;

Is there something missing here?

Quoted 12 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +12 -0
+			video_device: video-device@0x10000 {
+				compatible = "snps,video-device";
+				dmas = <&axi_vdma_0 0>;
+				dma-names = "vdma0";
+			};
+
+			csi2:	csi2@0x03000 {
+				compatible = "snps,dw-mipi-csi";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = < 0x03000 0x7FF>;
+				interrupts = <2>;

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 66

Quoted 10 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +10 -0
+				phys = <&mipi_phy_ctrl1 0>;
+				resets = <&csi2_rst 1>;
+
+				output-type = <2>;
+				ipi-mode = <0>;
+				ipi-color-mode = <0>;
+				ipi-auto-flush = <1>;
+				virtual-channel = <0>;
+
+				port@1 {

What are the valid ports for this device?

Quoted 11 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +11 -0
+					reg = <1>;
+					csi1_ep1: endpoint {
+						remote-endpoint = <&camera>;
+						data-lanes = <1 2>;
+					};
+				};
+			};
+		};
+	};
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
maintainer
#2 lore raw

Re: [PATCH 1/4] Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host

In reply to Ramiro Oliveira
Quoted 15 lines · Ramiro Oliveira

Create device tree bindings documentation for the Synopsys DW MIPI CSI-2
Host.

---
 .../devicetree/bindings/media/snps,dw-mipi-csi.txt | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +0 -0
new file mode 100644
index 000000000000..5b24eb43d760

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +10 -0
@@ -0,0 +1,37 @@
+Synopsys DesignWare CSI-2 Host controller
+
+Description
+-----------
+
+This HW block is used to receive image coming from an MIPI CSI-2 compatible
+camera.
+
+Required properties:
+- compatible: shall be "snps,dw-mipi-csi"

... "and an SoC specific compatible string"

Quoted 5 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +5 -0
+- reg		: physical base address and size of the device memory mapped
+  registers;
+- interrupts	: CSI-2 Host interrupt
+- output-type   : Core output to be used (IPI-> 0 or IDI->1 or BOTH->2) These
+  values choose which of the Core outputs will be used, it can be Image Data

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +10 -0
+  Interface or Image Pixel Interface.
+- phys: List of one PHY specifier (as defined in
+  Documentation/devicetree/bindings/phy/phy-bindings.txt). This PHY is a MIPI
+  DPHY working in RX mode.
+- resets: Reference to a reset controller (optional)
+
+Optional properties(if in IPI mode):
+- ipi-mode 	: Mode to be used when in IPI(Camera -> 0 or Controller -> 1)
+  This property defines if the controller will use the video timings available
+  in the video stream or if it will use pre-defined ones.

This could be boolean instead. I'd expect the former to be the typical mode, so name the property for the latter.

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 27

Quoted 2 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +2 -0
+- ipi-color-mode: Bus depth to be used in IPI (48 bits -> 0 or 16 bits -> 1)
+  This property defines the width of the IPI bus.

Are these the only 2 modes that any h/w would ever have (not just your controller)? Perhaps using the actual bits for the value would be better. Also, if this is the bus width, then the property should be named that as bus widths and pixel formats or color modes are not necessarily the same.

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 30

Quoted 3 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +3 -0
+- ipi-auto-flush: Data auto-flush (1 -> Yes or 0 -> No). This property defines
+  if the data is automatically flushed in each vsync or if this process is done
+  manually

This could be boolean.

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 33

Quoted 3 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +3 -0
+- virtual-channel: Virtual channel where data is present when in IPI mode. This
+  property chooses the virtual channel which IPI will use to retrieve the video
+  stream.

Again, some of these should probably be common properties (and therefore documented in a common location). I'm looking for some feedback from video/camera maintainers on this. I know I've seen some other similar bindings for camera interfaces recently.

Rob

maintainer
#12 lore raw

Re: [PATCH 3/4] Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

In reply to Ramiro Oliveira
Quoted 50 lines · Ramiro Oliveira

Create device tree bindings documentation for the CSI-2 Host Video
platform.

---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +35 -0
new file mode 100644
index 000000000000..f559257a0a44
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+--------------------
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+-------------------
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
+------------------
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 45

Quoted 10 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +10 -0
+
+Example:
+
+
+	camera {
+		compatible = "snps,plat-csi2", "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+			video_device: video-device@0x10000 {

Drop the '0x' and any leading 0s on unit addresses.

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 49

Quoted 4 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +4 -0
+				compatible = "snps,video-device";
+				dmas = <&axi_vdma_0 0>;
+				dma-names = "vdma0";
+			};

If video-device is not a real device, then you shouldn't need a DT node. I need a better explanation or diagram of what the h/w blocks and connections look like here.

Quoted 1 line

From the looks of this, you can just move dmas to the csi2 node. But I

don't think that is right, because you can't generally just use an external DMA controller with camera data (maybe for validation, but it's not something you see in SoCs).

Quoted 32 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +28 -0
+
+			csi2:	csi2@0x03000 {
+				compatible = "snps,dw-mipi-csi";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = < 0x03000 0x7FF>;
+				interrupts = <2>;
+				phys = <&mipi_phy_ctrl1 0>;
+				resets = <&csi2_rst 1>;
+
+				output-type = <2>;
+				ipi-mode = <0>;
+				ipi-color-mode = <0>;
+				ipi-auto-flush = <1>;
+				virtual-channel = <0>;
+
+				port@1 {
+					reg = <1>;
+					csi1_ep1: endpoint {
+						remote-endpoint = <&camera>;
+						data-lanes = <1 2>;
+					};
+				};
+			};
+		};
+	};
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
Signature · 1 line
2.11.0
#5 lore raw

Re: [PATCH 2/4] media: platform: dwc: Support for DW CSI-2 Host

In reply to Ramiro Oliveira

Hi Ramiro,

My sincere apologies for the long delay in reviewing this. The good news is that I should have more time for reviews going forward, so I hope I'll be a lot quicker in the future.

Quoted 188 lines · Ramiro Oliveira

Add support for the Synopsys DesignWare CSI-2 Host

---
 MAINTAINERS                              |   7 +
 drivers/media/platform/Kconfig           |   1 +
 drivers/media/platform/Makefile          |   2 +
 drivers/media/platform/dwc/Kconfig       |   5 +
 drivers/media/platform/dwc/Makefile      |   1 +
 drivers/media/platform/dwc/dw_mipi_csi.c | 653 +++++++++++++++++++++++++++++++
 drivers/media/platform/dwc/dw_mipi_csi.h | 181 +++++++++
 include/media/dwc/csi_host_platform.h    |  97 +++++
 8 files changed, 947 insertions(+)
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h
MAINTAINERS +7 -0
index 5badfd33e51f..19673dad43b4 100644
@@ -11061,6 +11061,13 @@ S:	Maintained
 F:	drivers/staging/media/st-cec/
 F:	Documentation/devicetree/bindings/media/stih-cec.txt
 
+SYNOPSYS DESIGNWARE CSI-2 HOST VIDEO PLATFORM
+M:	Ramiro Oliveira <roliveir-HKixBCOQz3hWk0Htik3J/[email protected]>
+L:	[email protected]
+T:	git git://linuxtv.org/media_tree.git
+S:	Maintained
+F:	drivers/media/platform/dwc/
+
 SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS
 M:	Ursula Braun <[email protected]>
 L:	[email protected]
drivers/media/platform/Kconfig +1 -0
index 53f6f12bff0d..4b6e00da763f 100644
@@ -120,6 +120,7 @@ source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
 source "drivers/media/platform/atmel/Kconfig"
+source "drivers/media/platform/dwc/Kconfig"
 
 config VIDEO_TI_CAL
 	tristate "TI CAL (Camera Adaptation Layer) driver"
drivers/media/platform/Makefile +2 -0
index 8959f6e6692a..95eae2772c1f 100644
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)		+= rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)		+= atmel/
 
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)	+= dwc/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)	+= mtk-vpu/
drivers/media/platform/dwc/Kconfig new file +5 -0
new file mode 100644
index 000000000000..2cd13d23f897
@@ -0,0 +1,5 @@
+config DWC_MIPI_CSI2_HOST
+	tristate "SNPS DWC MIPI CSI2 Host"
+	select GENERIC_PHY
+	help
+	  This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
drivers/media/platform/dwc/Makefile new file +1 -0
new file mode 100644
index 000000000000..5eb076a55123
@@ -0,0 +1 @@
+obj-$(CONFIG_DWC_MIPI_CSI2_HOST)	+= dw_mipi_csi.o
drivers/media/platform/dwc/dw_mipi_csi.c new file +102 -0
new file mode 100644
index 000000000000..6905def40a07
@@ -0,0 +1,653 @@
+/*
+ * DWC MIPI CSI-2 Host device driver
+ *
+ * Copyright (C) 2016 Synopsys, Inc. All rights reserved.
+ * Author: Ramiro Oliveira <ramiro.oliveira-HKixBCOQz3hWk0Htik3J/[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 "dw_mipi_csi.h"
+
+/**
+ * @short Video formats supported by the MIPI CSI-2
+ */
+static const struct mipi_fmt dw_mipi_csi_formats[] = {
+	{
+		/* RAW 8 */
+		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.depth = 8,
+	},
+	{
+		/* RAW 10 */
+		.code = MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE,
+		.depth = 10,
+	},
+	{
+		/* RGB 565 */
+		.code = MEDIA_BUS_FMT_RGB565_2X8_BE,
+		.depth = 16,
+	},
+	{
+		/* BGR 565 */
+		.code = MEDIA_BUS_FMT_RGB565_2X8_LE,
+		.depth = 16,
+	},
+	{
+		/* RGB 888 */
+		.code = MEDIA_BUS_FMT_RGB888_2X12_LE,
+		.depth = 24,
+	},
+	{
+		/* BGR 888 */
+		.code = MEDIA_BUS_FMT_RGB888_2X12_BE,
+		.depth = 24,
+	},
+};
+
+static struct mipi_csi_dev *sd_to_mipi_csi_dev(struct v4l2_subdev *sdev)
+{
+	return container_of(sdev, struct mipi_csi_dev, sd);
+}
+
+static void dw_mipi_csi_write(struct mipi_csi_dev *dev,
+		  unsigned int address, unsigned int data)
+{
+	iowrite32(data, dev->base_address + address);
+}
+
+static u32 dw_mipi_csi_read(struct mipi_csi_dev *dev, unsigned long address)
+{
+	return ioread32(dev->base_address + address);
+}
+
+static void dw_mipi_csi_write_part(struct mipi_csi_dev *dev,
+		       unsigned long address, unsigned long data,
+		       unsigned char shift, unsigned char width)
+{
+	u32 mask = (1 << width) - 1;
+	u32 temp = dw_mipi_csi_read(dev, address);
+
+	temp &= ~(mask << shift);
+	temp |= (data & mask) << shift;
+	dw_mipi_csi_write(dev, address, temp);
+}
+
+static const struct mipi_fmt *
+find_dw_mipi_csi_format(struct v4l2_mbus_framefmt *mf)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(dw_mipi_csi_formats); i++)
+		if (mf->code == dw_mipi_csi_formats[i].code)
+			return &dw_mipi_csi_formats[i];
+	return NULL;
+}
+
+static void dw_mipi_csi_reset(struct mipi_csi_dev *dev)
+{
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 0);
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 1);
+}
+
+static int dw_mipi_csi_mask_irq_power_off(struct mipi_csi_dev *dev)
+{
+	/* set only one lane (lane 0) as active (ON) */
+	dw_mipi_csi_write(dev, R_CSI2_N_LANES, 0);
+
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY_FATAL, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT_FATAL, 0);

drivers/media/platform/dwc/dw_mipi_csi.c line 112

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_FRAME_FATAL, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_LINE, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_IPI, 0);
+
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 0);
+
+	return 0;
+

Spurious empty line.

Quoted 11 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +11 -0
+}
+
+static int dw_mipi_csi_hw_stdby(struct mipi_csi_dev *dev)
+{
+	/* set only one lane (lane 0) as active (ON) */
+	dw_mipi_csi_reset(dev);
+
+	dw_mipi_csi_write(dev, R_CSI2_N_LANES, 0);
+
+	phy_init(dev->phy);
+

drivers/media/platform/dwc/dw_mipi_csi.c line 133

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_FRAME_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_LINE, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_IPI, 0xFFFFFFFF);
+
+	return 0;
+

Ditto.

Quoted 35 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +35 -0
+}
+
+static void dw_mipi_csi_set_ipi_fmt(struct mipi_csi_dev *csi_dev)
+{
+	struct device *dev = &csi_dev->pdev->dev;
+
+	switch (csi_dev->fmt->code) {
+	case MEDIA_BUS_FMT_RGB565_2X8_BE:
+	case MEDIA_BUS_FMT_RGB565_2X8_LE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB565);
+		dev_dbg(dev, "DT: RGB 565");
+		break;
+
+	case MEDIA_BUS_FMT_RGB888_2X12_LE:
+	case MEDIA_BUS_FMT_RGB888_2X12_BE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB888);
+		dev_dbg(dev, "DT: RGB 888");
+		break;
+	case MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RAW10);
+		dev_dbg(dev, "DT: RAW 10");
+		break;
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RAW8);
+		dev_dbg(dev, "DT: RAW 8");
+		break;
+	default:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB565);
+		dev_dbg(dev, "Error");
+		break;
+	}
+}
+
+static void __dw_mipi_csi_fill_timings(struct mipi_csi_dev *dev,
+			   const struct v4l2_bt_timings *bt)

drivers/media/platform/dwc/dw_mipi_csi.c line 178

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+{
+
+	if (bt == NULL)
+		return;
+
+	dev->hw.hsa = bt->hsync;
+	dev->hw.hbp = bt->hbackporch;
+	dev->hw.hsd = bt->hsync;
+	dev->hw.htotal = bt->height + bt->vfrontporch +
+	    bt->vsync + bt->vbackporch;

Use V4L2_DV_BT_FRAME_HEIGHT define.

Quoted 122 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +122 -0
+	dev->hw.vsa = bt->vsync;
+	dev->hw.vbp = bt->vbackporch;
+	dev->hw.vfp = bt->vfrontporch;
+	dev->hw.vactive = bt->height;
+}
+
+static void dw_mipi_csi_start(struct mipi_csi_dev *csi_dev)
+{
+	const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[0].bt;
+	struct device *dev = &csi_dev->pdev->dev;
+
+	__dw_mipi_csi_fill_timings(csi_dev, bt);
+
+	dw_mipi_csi_write(csi_dev, R_CSI2_N_LANES, (csi_dev->hw.num_lanes - 1));
+	dev_dbg(dev, "N Lanes: %d\n", csi_dev->hw.num_lanes);
+
+	/*IPI Related Configuration */
+	if ((csi_dev->hw.output_type == IPI_OUT)
+	    || (csi_dev->hw.output_type == BOTH_OUT)) {
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MODE,
+					csi_dev->hw.ipi_mode, 0, 1);
+		dev_dbg(dev, "IPI MODE: %d\n", csi_dev->hw.ipi_mode);
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MODE,
+				       csi_dev->hw.ipi_color_mode, 8, 1);
+		dev_dbg(dev, "Color Mode: %d\n", csi_dev->hw.ipi_color_mode);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VCID,
+					csi_dev->hw.virtual_ch);
+		dev_dbg(dev, "Virtual Channel: %d\n", csi_dev->hw.virtual_ch);
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MEM_FLUSH,
+				       csi_dev->hw.ipi_auto_flush, 8, 1);
+		dev_dbg(dev, "Auto-flush: %d\n", csi_dev->hw.ipi_auto_flush);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HSA_TIME,
+					csi_dev->hw.hsa);
+		dev_dbg(dev, "HSA: %d\n", csi_dev->hw.hsa);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HBP_TIME,
+					csi_dev->hw.hbp);
+		dev_dbg(dev, "HBP: %d\n", csi_dev->hw.hbp);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HSD_TIME,
+					csi_dev->hw.hsd);
+		dev_dbg(dev, "HSD: %d\n", csi_dev->hw.hsd);
+
+		if (csi_dev->hw.ipi_mode == AUTO_TIMING) {
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HLINE_TIME,
+					  csi_dev->hw.htotal);
+			dev_dbg(dev, "H total: %d\n", csi_dev->hw.htotal);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VSA_LINES,
+					  csi_dev->hw.vsa);
+			dev_dbg(dev, "VSA: %d\n", csi_dev->hw.vsa);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VBP_LINES,
+					  csi_dev->hw.vbp);
+			dev_dbg(dev, "VBP: %d\n", csi_dev->hw.vbp);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VFP_LINES,
+					  csi_dev->hw.vfp);
+			dev_dbg(dev, "VFP: %d\n", csi_dev->hw.vfp);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VACTIVE_LINES,
+					  csi_dev->hw.vactive);
+			dev_dbg(dev, "V Active: %d\n", csi_dev->hw.vactive);
+		}
+	}
+
+	phy_power_on(csi_dev->phy);
+}
+
+static int dw_mipi_csi_enum_mbus_code(struct v4l2_subdev *sd,
+					struct v4l2_subdev_pad_config *cfg,
+					struct v4l2_subdev_mbus_code_enum *code)
+{
+	if (code->index >= ARRAY_SIZE(dw_mipi_csi_formats))
+		return -EINVAL;
+
+	code->code = dw_mipi_csi_formats[code->index].code;
+	return 0;
+}
+
+static struct mipi_fmt const *
+dw_mipi_csi_try_format(struct v4l2_mbus_framefmt *mf)
+{
+	struct mipi_fmt const *fmt;
+
+	fmt = find_dw_mipi_csi_format(mf);
+	if (fmt == NULL)
+		fmt = &dw_mipi_csi_formats[0];
+
+	mf->code = fmt->code;
+	return fmt;
+}
+
+static struct v4l2_mbus_framefmt *
+__dw_mipi_csi_get_format(struct mipi_csi_dev *dev,
+			 struct v4l2_subdev_pad_config *cfg,
+			 enum v4l2_subdev_format_whence which)
+{
+	if (which == V4L2_SUBDEV_FORMAT_TRY)
+		return cfg ? v4l2_subdev_get_try_format(&dev->sd, cfg,
+							0) : NULL;
+
+	return &dev->format;
+}
+
+static int
+dw_mipi_csi_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
+		    struct v4l2_subdev_format *fmt)
+{
+	struct mipi_csi_dev *dev = sd_to_mipi_csi_dev(sd);
+	struct mipi_fmt const *dev_fmt;
+	struct v4l2_mbus_framefmt *mf;
+	unsigned int i = 0;
+	const struct v4l2_bt_timings *bt_r = &v4l2_dv_timings_presets[0].bt;
+
+	mf = __dw_mipi_csi_get_format(dev, cfg, fmt->which);
+

drivers/media/platform/dwc/dw_mipi_csi.c line 310

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+	dev_fmt = dw_mipi_csi_try_format(&fmt->format);
+	if (dev_fmt) {
+		*mf = fmt->format;
+		if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
+			dev->fmt = dev_fmt;
+		dw_mipi_csi_set_ipi_fmt(dev);
+	}
+	while (v4l2_dv_timings_presets[i].bt.width) {
+		const struct v4l2_bt_timings *bt =
+		    &v4l2_dv_timings_presets[i].bt;

Add empty line here.

drivers/media/platform/dwc/dw_mipi_csi.c line 311

Quoted 1 line
drivers/media/platform/dwc/dw_mipi_csi.c new file +1 -0
+		if (mf->width == bt->width && mf->height == bt->width) {

This is way too generic. There are many preset timings that have the same width and height but different blanking periods.

I am really not sure how this is supposed to work. If you want to support HDMI here, then I would expect to see support for the s_dv_timings op and friends in this driver. And I don't see support for that in the host driver either.

Is this a generic csi driver, or specific for hdmi? Or supposed to handle both?

Can you give some background and clarification of this?

Before I do any more code review I need to have a clearer understanding of this.

Regards,

Hans

drivers/media/platform/dwc/dw_mipi_csi.c line 321

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+			__dw_mipi_csi_fill_timings(dev, bt);
+			return 0;
+		}
+		i++;
+	}
+
+	__dw_mipi_csi_fill_timings(dev, bt_r);
+	return 0;
+
+}

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH 1/4] Documentation: dt: Add bindings documentation for DW MIPI CSI-2 Host

In reply to Rob Herring

Hi Rob,

Thank you for your feedback and sorry for the late reply.

Quoted 20 lines · Rob Herring
Quoted 19 lines · Ramiro Oliveira

Create device tree bindings documentation for the Synopsys DW MIPI CSI-2
Host.

---
 .../devicetree/bindings/media/snps,dw-mipi-csi.txt | 37 ++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +4 -0
new file mode 100644
index 000000000000..5b24eb43d760
@@ -0,0 +1,37 @@
+Synopsys DesignWare CSI-2 Host controller
+
+Description
+-----------
Quoted 9 lines

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 10

Quoted 6 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +6 -0
+
+This HW block is used to receive image coming from an MIPI CSI-2 compatible
+camera.
+
+Required properties:
+- compatible: shall be "snps,dw-mipi-csi"

... "and an SoC specific compatible string"

I'm not sure what you mean by this.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +10 -0
+- reg		: physical base address and size of the device memory mapped
+  registers;
+- interrupts	: CSI-2 Host interrupt
+- output-type   : Core output to be used (IPI-> 0 or IDI->1 or BOTH->2) These
+  values choose which of the Core outputs will be used, it can be Image Data
+  Interface or Image Pixel Interface.
+- phys: List of one PHY specifier (as defined in
+  Documentation/devicetree/bindings/phy/phy-bindings.txt). This PHY is a MIPI
+  DPHY working in RX mode.
+- resets: Reference to a reset controller (optional)
Quoted 9 lines

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 25

Quoted 5 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +5 -0
+
+Optional properties(if in IPI mode):
+- ipi-mode 	: Mode to be used when in IPI(Camera -> 0 or Controller -> 1)
+  This property defines if the controller will use the video timings available
+  in the video stream or if it will use pre-defined ones.

This could be boolean instead. I'd expect the former to be the typical mode, so name the property for the latter.

Sure. I can do this.

Quoted 9 lines

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 27

Quoted 2 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +2 -0
+- ipi-color-mode: Bus depth to be used in IPI (48 bits -> 0 or 16 bits -> 1)
+  This property defines the width of the IPI bus.

Are these the only 2 modes that any h/w would ever have (not just your controller)? Perhaps using the actual bits for the value would be better. Also, if this is the bus width, then the property should be named that as bus widths and pixel formats or color modes are not necessarily the same.

I'm not sure I understand what you mean, but I'll try to explain what this does.

Our controller, when in IPI mode, has a data bus that can be either 16 or 48 bits wide. However when in 48 bits mode some data types will not use the entire bus width.

Quoted 6 lines

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 30

Quoted 3 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +3 -0
+- ipi-auto-flush: Data auto-flush (1 -> Yes or 0 -> No). This property defines
+  if the data is automatically flushed in each vsync or if this process is done
+  manually

This could be boolean.

I'll change it.

Quoted 9 lines

Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt line 33

Quoted 3 lines
Documentation/devicetree/bindings/media/snps,dw-mipi-csi.txt new file +3 -0
+- virtual-channel: Virtual channel where data is present when in IPI mode. This
+  property chooses the virtual channel which IPI will use to retrieve the video
+  stream.

Again, some of these should probably be common properties (and therefore documented in a common location). I'm looking for some feedback from video/camera maintainers on this. I know I've seen some other similar bindings for camera interfaces recently.

You're right, Virtual channel is MIPI CSI-2 property, not a Synopsys one, so this could be a common property, although I haven't found it anywhere.

Quoted 2 lines

Rob

Signature · 8 lines
Best Regards

Ramiro Oliveira
Ramiro.Oliveira-HKixBCOQz3hWk0Htik3J/[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw

Re: [PATCH 3/4] Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

In reply to Sakari Ailus

Hi Sakari,

Thank you for your feedback and sorry for the late response.

Quoted 51 lines · Sakari Ailus

Hi Ramiro,

Quoted 2 lines · Ramiro Oliveira

Create device tree bindings documentation for the CSI-2 Host Video
platform.

Extra space here.

Quoted 43 lines
---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +30 -0
new file mode 100644
index 000000000000..f559257a0a44
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+--------------------
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+-------------------
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
Quoted 9 lines

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 35

Quoted 5 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +5 -0
+------------------
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.

You should defined which properties you explicitly support on endpoints and elsewhere. There are some optional ones for CSI-2, for instance.

I'll take a look and see if it makes sense to add support for some properties

Quoted 12 lines

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 44

Quoted 9 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +9 -0
+
+Example:
+
+
+	camera {
+		compatible = "snps,plat-csi2", "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;

Is there something missing here?

I don't think so, but should I add something?

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +16 -0
+			video_device: video-device@0x10000 {
+				compatible = "snps,video-device";
+				dmas = <&axi_vdma_0 0>;
+				dma-names = "vdma0";
+			};
+
+			csi2:	csi2@0x03000 {
+				compatible = "snps,dw-mipi-csi";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = < 0x03000 0x7FF>;
+				interrupts = <2>;
+				phys = <&mipi_phy_ctrl1 0>;
+				resets = <&csi2_rst 1>;
+
+				output-type = <2>;
Quoted 9 lines

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 66

Quoted 6 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +6 -0
+				ipi-mode = <0>;
+				ipi-color-mode = <0>;
+				ipi-auto-flush = <1>;
+				virtual-channel = <0>;
+
+				port@1 {

What are the valid ports for this device?

I don't think I understand what you mean by valid.

Quoted 12 lines
Quoted 11 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +11 -0
+					reg = <1>;
+					csi1_ep1: endpoint {
+						remote-endpoint = <&camera>;
+						data-lanes = <1 2>;
+					};
+				};
+			};
+		};
+	};
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
Signature · 4 lines
Best Regards

Ramiro Oliveira
[email protected]
#13 lore raw

Re: [PATCH 3/4] Documentation: dt: Add bindings documentation for CSI-2 Host Video Platform

In reply to Rob Herring

Hi Rob,

Once again sorry for the late response and thank you for your feedback.

Quoted 55 lines · Rob Herring
Quoted 54 lines · Ramiro Oliveira

Create device tree bindings documentation for the CSI-2 Host Video
platform.

---
 .../devicetree/bindings/media/snps,plat-csi2.txt   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/snps,plat-csi2.txt
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +39 -0
new file mode 100644
index 000000000000..f559257a0a44
@@ -0,0 +1,77 @@
+Synopsys DesignWare CSI-2 Host Video Platform
+
+The Synopsys DesignWare CSI-2 Host Video Device subsystem comprises of multiple
+sub-devices represented by separate device tree nodes. Currently this includes:
+plat-csi2, video-device, and dw-mipi-csi.
+
+The sub-subdevices are defined as child nodes of the common 'camera'.
+
+Common 'camera' node
+--------------------
+
+Required properties:
+
+- compatible: must be "snps,plat-csi2", "simple-bus"
+
+The 'camera' node must include at least one 'video-device' and one 'dw-mipi-csi'
+child node.
+
+'video-device' device nodes
+-------------------
+
+Required properties:
+
+- compatible: "snps,video-device"
+- dmas, dma-names: List of one DMA specifier and identifier string (as defined
+  in Documentation/devicetree/bindings/dma/dma.txt) per port. Each port
+  requires a DMA channel with the identifier string set to "vdma" followed by
+  the port index.
+
+Image sensor nodes
+------------------
+
+The sensor device nodes should be added to their control bus controller (e.g.
+I2C0) nodes and linked to a port node in the dw-mipi-csi,using the common video
+interfaces bindings, defined in video-interfaces.txt.
+
+Example:
+
+
Quoted 9 lines

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 45

Quoted 6 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +6 -0
+	camera {
+		compatible = "snps,plat-csi2", "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+			video_device: video-device@0x10000 {

Drop the '0x' and any leading 0s on unit addresses.

Sure.

Quoted 9 lines

Documentation/devicetree/bindings/media/snps,plat-csi2.txt line 49

Quoted 4 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +4 -0
+				compatible = "snps,video-device";
+				dmas = <&axi_vdma_0 0>;
+				dma-names = "vdma0";
+			};

If video-device is not a real device, then you shouldn't need a DT node. I need a better explanation or diagram of what the h/w blocks and connections look like here.

Quoted 5 lines

From the looks of this, you can just move dmas to the csi2 node. But I don't think that is right, because you can't generally just use an external DMA controller with camera data (maybe for validation, but it's not something you see in SoCs).

Actually we do use an external DMA controller directly connected to the CSI-2 Host controller, although, like you said, we use it for HW validation.

I "created" the video-device in order to remove the DMA engine control from the CSI-2 Host driver, in order to make it more useful to other people.

Quoted 32 lines
Quoted 32 lines
Documentation/devicetree/bindings/media/snps,plat-csi2.txt new file +28 -0
+
+			csi2:	csi2@0x03000 {
+				compatible = "snps,dw-mipi-csi";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = < 0x03000 0x7FF>;
+				interrupts = <2>;
+				phys = <&mipi_phy_ctrl1 0>;
+				resets = <&csi2_rst 1>;
+
+				output-type = <2>;
+				ipi-mode = <0>;
+				ipi-color-mode = <0>;
+				ipi-auto-flush = <1>;
+				virtual-channel = <0>;
+
+				port@1 {
+					reg = <1>;
+					csi1_ep1: endpoint {
+						remote-endpoint = <&camera>;
+						data-lanes = <1 2>;
+					};
+				};
+			};
+		};
+	};
+
+The dw-mipi-csi device binding is defined in snps,dw-mipi-csi.txt.
Signature · 1 line
2.11.0
Signature · 4 lines
Best Regards

Ramiro Oliveira
[email protected]
#6 lore raw

Re: [PATCH 2/4] media: platform: dwc: Support for DW CSI-2 Host

In reply to Hans Verkuil

Hi Hans,

Thank you very much for your feedback.

Quoted 199 lines · Hans Verkuil

Hi Ramiro,

My sincere apologies for the long delay in reviewing this. The good news is that I should have more time for reviews going forward, so I hope I'll be a lot quicker in the future.

Quoted 192 lines · Ramiro Oliveira

Add support for the Synopsys DesignWare CSI-2 Host

---
 MAINTAINERS                              |   7 +
 drivers/media/platform/Kconfig           |   1 +
 drivers/media/platform/Makefile          |   2 +
 drivers/media/platform/dwc/Kconfig       |   5 +
 drivers/media/platform/dwc/Makefile      |   1 +
 drivers/media/platform/dwc/dw_mipi_csi.c | 653 +++++++++++++++++++++++++++++++
 drivers/media/platform/dwc/dw_mipi_csi.h | 181 +++++++++
 include/media/dwc/csi_host_platform.h    |  97 +++++
 8 files changed, 947 insertions(+)
 create mode 100644 drivers/media/platform/dwc/Kconfig
 create mode 100644 drivers/media/platform/dwc/Makefile
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.c
 create mode 100644 drivers/media/platform/dwc/dw_mipi_csi.h
 create mode 100644 include/media/dwc/csi_host_platform.h
MAINTAINERS +7 -0
index 5badfd33e51f..19673dad43b4 100644
@@ -11061,6 +11061,13 @@ S:	Maintained
 F:	drivers/staging/media/st-cec/
 F:	Documentation/devicetree/bindings/media/stih-cec.txt
 
+SYNOPSYS DESIGNWARE CSI-2 HOST VIDEO PLATFORM
+M:	Ramiro Oliveira <roliveir-HKixBCOQz3hWk0Htik3J/[email protected]>
+L:	[email protected]
+T:	git git://linuxtv.org/media_tree.git
+S:	Maintained
+F:	drivers/media/platform/dwc/
+
 SHARED MEMORY COMMUNICATIONS (SMC) SOCKETS
 M:	Ursula Braun <[email protected]>
 L:	[email protected]
drivers/media/platform/Kconfig +1 -0
index 53f6f12bff0d..4b6e00da763f 100644
@@ -120,6 +120,7 @@ source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 source "drivers/media/platform/rcar-vin/Kconfig"
 source "drivers/media/platform/atmel/Kconfig"
+source "drivers/media/platform/dwc/Kconfig"
 
 config VIDEO_TI_CAL
 	tristate "TI CAL (Camera Adaptation Layer) driver"
drivers/media/platform/Makefile +2 -0
index 8959f6e6692a..95eae2772c1f 100644
@@ -64,6 +64,8 @@ obj-$(CONFIG_VIDEO_RCAR_VIN)		+= rcar-vin/
 
 obj-$(CONFIG_VIDEO_ATMEL_ISC)		+= atmel/
 
+obj-$(CONFIG_CSI_VIDEO_PLATFORM)	+= dwc/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)	+= mtk-vpu/
drivers/media/platform/dwc/Kconfig new file +5 -0
new file mode 100644
index 000000000000..2cd13d23f897
@@ -0,0 +1,5 @@
+config DWC_MIPI_CSI2_HOST
+	tristate "SNPS DWC MIPI CSI2 Host"
+	select GENERIC_PHY
+	help
+	  This is a V4L2 driver for Synopsys Designware MIPI CSI-2 Host.
drivers/media/platform/dwc/Makefile new file +1 -0
new file mode 100644
index 000000000000..5eb076a55123
@@ -0,0 +1 @@
+obj-$(CONFIG_DWC_MIPI_CSI2_HOST)	+= dw_mipi_csi.o
drivers/media/platform/dwc/dw_mipi_csi.c new file +106 -0
new file mode 100644
index 000000000000..6905def40a07
@@ -0,0 +1,653 @@
+/*
+ * DWC MIPI CSI-2 Host device driver
+ *
+ * Copyright (C) 2016 Synopsys, Inc. All rights reserved.
+ * Author: Ramiro Oliveira <ramiro.oliveira-HKixBCOQz3hWk0Htik3J/[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 "dw_mipi_csi.h"
+
+/**
+ * @short Video formats supported by the MIPI CSI-2
+ */
+static const struct mipi_fmt dw_mipi_csi_formats[] = {
+	{
+		/* RAW 8 */
+		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.depth = 8,
+	},
+	{
+		/* RAW 10 */
+		.code = MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE,
+		.depth = 10,
+	},
+	{
+		/* RGB 565 */
+		.code = MEDIA_BUS_FMT_RGB565_2X8_BE,
+		.depth = 16,
+	},
+	{
+		/* BGR 565 */
+		.code = MEDIA_BUS_FMT_RGB565_2X8_LE,
+		.depth = 16,
+	},
+	{
+		/* RGB 888 */
+		.code = MEDIA_BUS_FMT_RGB888_2X12_LE,
+		.depth = 24,
+	},
+	{
+		/* BGR 888 */
+		.code = MEDIA_BUS_FMT_RGB888_2X12_BE,
+		.depth = 24,
+	},
+};
+
+static struct mipi_csi_dev *sd_to_mipi_csi_dev(struct v4l2_subdev *sdev)
+{
+	return container_of(sdev, struct mipi_csi_dev, sd);
+}
+
+static void dw_mipi_csi_write(struct mipi_csi_dev *dev,
+		  unsigned int address, unsigned int data)
+{
+	iowrite32(data, dev->base_address + address);
+}
+
+static u32 dw_mipi_csi_read(struct mipi_csi_dev *dev, unsigned long address)
+{
+	return ioread32(dev->base_address + address);
+}
+
+static void dw_mipi_csi_write_part(struct mipi_csi_dev *dev,
+		       unsigned long address, unsigned long data,
+		       unsigned char shift, unsigned char width)
+{
+	u32 mask = (1 << width) - 1;
+	u32 temp = dw_mipi_csi_read(dev, address);
+
+	temp &= ~(mask << shift);
+	temp |= (data & mask) << shift;
+	dw_mipi_csi_write(dev, address, temp);
+}
+
+static const struct mipi_fmt *
+find_dw_mipi_csi_format(struct v4l2_mbus_framefmt *mf)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(dw_mipi_csi_formats); i++)
+		if (mf->code == dw_mipi_csi_formats[i].code)
+			return &dw_mipi_csi_formats[i];
+	return NULL;
+}
+
+static void dw_mipi_csi_reset(struct mipi_csi_dev *dev)
+{
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 0);
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 1);
+}
+
+static int dw_mipi_csi_mask_irq_power_off(struct mipi_csi_dev *dev)
+{
+	/* set only one lane (lane 0) as active (ON) */
+	dw_mipi_csi_write(dev, R_CSI2_N_LANES, 0);
+
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY_FATAL, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT_FATAL, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_FRAME_FATAL, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT, 0);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_LINE, 0);
Quoted 9 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 112

Quoted 6 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +6 -0
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_IPI, 0);
+
+	dw_mipi_csi_write(dev, R_CSI2_CTRL_RESETN, 0);
+
+	return 0;
+

Spurious empty line.

I'll remove it.

Quoted 15 lines
Quoted 15 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +15 -0
+}
+
+static int dw_mipi_csi_hw_stdby(struct mipi_csi_dev *dev)
+{
+	/* set only one lane (lane 0) as active (ON) */
+	dw_mipi_csi_reset(dev);
+
+	dw_mipi_csi_write(dev, R_CSI2_N_LANES, 0);
+
+	phy_init(dev->phy);
+
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_FRAME_FATAL, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PHY, 0xFFFFFFFF);
Quoted 9 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 133

Quoted 6 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +6 -0
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_PKT, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_LINE, 0xFFFFFFFF);
+	dw_mipi_csi_write(dev, R_CSI2_MASK_INT_IPI, 0xFFFFFFFF);
+
+	return 0;
+

Ditto.

I'll remove it also.

Quoted 39 lines
Quoted 39 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +39 -0
+}
+
+static void dw_mipi_csi_set_ipi_fmt(struct mipi_csi_dev *csi_dev)
+{
+	struct device *dev = &csi_dev->pdev->dev;
+
+	switch (csi_dev->fmt->code) {
+	case MEDIA_BUS_FMT_RGB565_2X8_BE:
+	case MEDIA_BUS_FMT_RGB565_2X8_LE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB565);
+		dev_dbg(dev, "DT: RGB 565");
+		break;
+
+	case MEDIA_BUS_FMT_RGB888_2X12_LE:
+	case MEDIA_BUS_FMT_RGB888_2X12_BE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB888);
+		dev_dbg(dev, "DT: RGB 888");
+		break;
+	case MEDIA_BUS_FMT_SBGGR10_2X8_PADHI_BE:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RAW10);
+		dev_dbg(dev, "DT: RAW 10");
+		break;
+	case MEDIA_BUS_FMT_SBGGR8_1X8:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RAW8);
+		dev_dbg(dev, "DT: RAW 8");
+		break;
+	default:
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_DATA_TYPE, CSI_2_RGB565);
+		dev_dbg(dev, "Error");
+		break;
+	}
+}
+
+static void __dw_mipi_csi_fill_timings(struct mipi_csi_dev *dev,
+			   const struct v4l2_bt_timings *bt)
+{
+
+	if (bt == NULL)
+		return;
Quoted 9 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 178

Quoted 6 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +6 -0
+
+	dev->hw.hsa = bt->hsync;
+	dev->hw.hbp = bt->hbackporch;
+	dev->hw.hsd = bt->hsync;
+	dev->hw.htotal = bt->height + bt->vfrontporch +
+	    bt->vsync + bt->vbackporch;

Use V4L2_DV_BT_FRAME_HEIGHT define.

I'll use it now.

Quoted 126 lines
Quoted 126 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +126 -0
+	dev->hw.vsa = bt->vsync;
+	dev->hw.vbp = bt->vbackporch;
+	dev->hw.vfp = bt->vfrontporch;
+	dev->hw.vactive = bt->height;
+}
+
+static void dw_mipi_csi_start(struct mipi_csi_dev *csi_dev)
+{
+	const struct v4l2_bt_timings *bt = &v4l2_dv_timings_presets[0].bt;
+	struct device *dev = &csi_dev->pdev->dev;
+
+	__dw_mipi_csi_fill_timings(csi_dev, bt);
+
+	dw_mipi_csi_write(csi_dev, R_CSI2_N_LANES, (csi_dev->hw.num_lanes - 1));
+	dev_dbg(dev, "N Lanes: %d\n", csi_dev->hw.num_lanes);
+
+	/*IPI Related Configuration */
+	if ((csi_dev->hw.output_type == IPI_OUT)
+	    || (csi_dev->hw.output_type == BOTH_OUT)) {
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MODE,
+					csi_dev->hw.ipi_mode, 0, 1);
+		dev_dbg(dev, "IPI MODE: %d\n", csi_dev->hw.ipi_mode);
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MODE,
+				       csi_dev->hw.ipi_color_mode, 8, 1);
+		dev_dbg(dev, "Color Mode: %d\n", csi_dev->hw.ipi_color_mode);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VCID,
+					csi_dev->hw.virtual_ch);
+		dev_dbg(dev, "Virtual Channel: %d\n", csi_dev->hw.virtual_ch);
+
+		dw_mipi_csi_write_part(csi_dev, R_CSI2_IPI_MEM_FLUSH,
+				       csi_dev->hw.ipi_auto_flush, 8, 1);
+		dev_dbg(dev, "Auto-flush: %d\n", csi_dev->hw.ipi_auto_flush);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HSA_TIME,
+					csi_dev->hw.hsa);
+		dev_dbg(dev, "HSA: %d\n", csi_dev->hw.hsa);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HBP_TIME,
+					csi_dev->hw.hbp);
+		dev_dbg(dev, "HBP: %d\n", csi_dev->hw.hbp);
+
+		dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HSD_TIME,
+					csi_dev->hw.hsd);
+		dev_dbg(dev, "HSD: %d\n", csi_dev->hw.hsd);
+
+		if (csi_dev->hw.ipi_mode == AUTO_TIMING) {
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_HLINE_TIME,
+					  csi_dev->hw.htotal);
+			dev_dbg(dev, "H total: %d\n", csi_dev->hw.htotal);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VSA_LINES,
+					  csi_dev->hw.vsa);
+			dev_dbg(dev, "VSA: %d\n", csi_dev->hw.vsa);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VBP_LINES,
+					  csi_dev->hw.vbp);
+			dev_dbg(dev, "VBP: %d\n", csi_dev->hw.vbp);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VFP_LINES,
+					  csi_dev->hw.vfp);
+			dev_dbg(dev, "VFP: %d\n", csi_dev->hw.vfp);
+
+			dw_mipi_csi_write(csi_dev, R_CSI2_IPI_VACTIVE_LINES,
+					  csi_dev->hw.vactive);
+			dev_dbg(dev, "V Active: %d\n", csi_dev->hw.vactive);
+		}
+	}
+
+	phy_power_on(csi_dev->phy);
+}
+
+static int dw_mipi_csi_enum_mbus_code(struct v4l2_subdev *sd,
+					struct v4l2_subdev_pad_config *cfg,
+					struct v4l2_subdev_mbus_code_enum *code)
+{
+	if (code->index >= ARRAY_SIZE(dw_mipi_csi_formats))
+		return -EINVAL;
+
+	code->code = dw_mipi_csi_formats[code->index].code;
+	return 0;
+}
+
+static struct mipi_fmt const *
+dw_mipi_csi_try_format(struct v4l2_mbus_framefmt *mf)
+{
+	struct mipi_fmt const *fmt;
+
+	fmt = find_dw_mipi_csi_format(mf);
+	if (fmt == NULL)
+		fmt = &dw_mipi_csi_formats[0];
+
+	mf->code = fmt->code;
+	return fmt;
+}
+
+static struct v4l2_mbus_framefmt *
+__dw_mipi_csi_get_format(struct mipi_csi_dev *dev,
+			 struct v4l2_subdev_pad_config *cfg,
+			 enum v4l2_subdev_format_whence which)
+{
+	if (which == V4L2_SUBDEV_FORMAT_TRY)
+		return cfg ? v4l2_subdev_get_try_format(&dev->sd, cfg,
+							0) : NULL;
+
+	return &dev->format;
+}
+
+static int
+dw_mipi_csi_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
+		    struct v4l2_subdev_format *fmt)
+{
+	struct mipi_csi_dev *dev = sd_to_mipi_csi_dev(sd);
+	struct mipi_fmt const *dev_fmt;
+	struct v4l2_mbus_framefmt *mf;
+	unsigned int i = 0;
+	const struct v4l2_bt_timings *bt_r = &v4l2_dv_timings_presets[0].bt;
+
+	mf = __dw_mipi_csi_get_format(dev, cfg, fmt->which);
+
+	dev_fmt = dw_mipi_csi_try_format(&fmt->format);
+	if (dev_fmt) {
+		*mf = fmt->format;
+		if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
Quoted 9 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 310

Quoted 6 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +6 -0
+			dev->fmt = dev_fmt;
+		dw_mipi_csi_set_ipi_fmt(dev);
+	}
+	while (v4l2_dv_timings_presets[i].bt.width) {
+		const struct v4l2_bt_timings *bt =
+		    &v4l2_dv_timings_presets[i].bt;

Add empty line here.

Sure.

Quoted 10 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 311

Quoted 1 line
drivers/media/platform/dwc/dw_mipi_csi.c new file +1 -0
+		if (mf->width == bt->width && mf->height == bt->width) {

This is way too generic. There are many preset timings that have the same width and height but different blanking periods.

I am really not sure how this is supposed to work. If you want to support HDMI here, then I would expect to see support for the s_dv_timings op and friends in this driver. And I don't see support for that in the host driver either.

Is this a generic csi driver, or specific for hdmi? Or supposed to handle both?

This is a generic CSI driver.

Quoted 2 lines

Can you give some background and clarification of this?

This piece of code might seem strange but I'm just using it fill our controller timing configuration.

I don't have any specific requirements, but they should match, more or less, the sensor configurations, so I decided to re-use the HDMI blanking values, since, usually, they match with the sensor configurations

So, my intention is to check if there is any HDMI preset that matches the required width and height, and then use the blanking values to configure our controller. I know this might not be very common, and I'm open to use different approaches, but from my perspective it seems to work fine.

Quoted 17 lines

Before I do any more code review I need to have a clearer understanding of this.

Regards,

Hans

Quoted 10 lines
drivers/media/platform/dwc/dw_mipi_csi.c new file +10 -0
+			__dw_mipi_csi_fill_timings(dev, bt);
+			return 0;
+		}
+		i++;
+	}
+
+	__dw_mipi_csi_fill_timings(dev, bt_r);
+	return 0;
+
+}
Signature · 8 lines
Best Regards

Ramiro Oliveira
Ramiro.Oliveira-HKixBCOQz3hWk0Htik3J/[email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw
In reply to Ramiro Oliveira

Hi Ramiro,

Quoted 9 lines · Ramiro Oliveira

This patchset adds support for the DW CSI-2 Host and also for a video device associated with it.

The first 2 patches are only for the DW CSI-2 Host and the last 2 are for the video device.

Although this patchset is named as v1 there were already two patchsets previous to this one, but with a different name: "Add support for the DW IP Prototyping Kits for MIPI CSI-2 Host".

Could you briefly describe the hardware and which IP blocks you have there? Three devices to capture images from CSI-2 bus seems a lot.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#7 lore raw

Re: [PATCH 2/4] media: platform: dwc: Support for DW CSI-2 Host

In reply to Ramiro Oliveira

Hi Sakari,

Can you comment on this? You are much more a CSI sensor expert than I am.

Quoted 12 lines · Ramiro Oliveira

Hi Hans,

Thank you very much for your feedback.

Quoted 7 lines · Hans Verkuil

Hi Ramiro,

My sincere apologies for the long delay in reviewing this. The good news is that I should have more time for reviews going forward, so I hope I'll be a lot quicker in the future.

On 03/07/2017 03:37 PM, Ramiro Oliveira wrote:

<snip>

Quoted 19 lines
Quoted 10 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 311

Quoted 1 line
drivers/media/platform/dwc/dw_mipi_csi.c new file +1 -0
+		if (mf->width == bt->width && mf->height == bt->width) {

This is way too generic. There are many preset timings that have the same width and height but different blanking periods.

I am really not sure how this is supposed to work. If you want to support HDMI here, then I would expect to see support for the s_dv_timings op and friends in this driver. And I don't see support for that in the host driver either.

Is this a generic csi driver, or specific for hdmi? Or supposed to handle both?

This is a generic CSI driver.

Quoted 2 lines

Can you give some background and clarification of this?

This piece of code might seem strange but I'm just using it fill our controller timing configuration.

Quoted 8 lines

I don't have any specific requirements, but they should match, more or less, the sensor configurations, so I decided to re-use the HDMI blanking values, since, usually, they match with the sensor configurations

So, my intention is to check if there is any HDMI preset that matches the required width and height, and then use the blanking values to configure our controller. I know this might not be very common, and I'm open to use different approaches, but from my perspective it seems to work fine.

Regards,

Hans

#8 lore raw

Re: [PATCH 2/4] media: platform: dwc: Support for DW CSI-2 Host

Hi Hans,

Quoted 3 lines · Hans Verkuil

Hi Sakari,

Can you comment on this? You are much more a CSI sensor expert than I am.

Sure. Thanks for the ping.

Quoted 36 lines · Ramiro Oliveira
Quoted 12 lines

Hi Hans,

Thank you very much for your feedback.

Quoted 7 lines · Hans Verkuil

Hi Ramiro,

My sincere apologies for the long delay in reviewing this. The good news is that I should have more time for reviews going forward, so I hope I'll be a lot quicker in the future.

On 03/07/2017 03:37 PM, Ramiro Oliveira wrote:

<snip>

Quoted 19 lines
Quoted 10 lines

drivers/media/platform/dwc/dw_mipi_csi.c line 311

Quoted 1 line
drivers/media/platform/dwc/dw_mipi_csi.c new file +1 -0
+		if (mf->width == bt->width && mf->height == bt->width) {

This is way too generic. There are many preset timings that have the same width and height but different blanking periods.

I am really not sure how this is supposed to work. If you want to support HDMI here, then I would expect to see support for the s_dv_timings op and friends in this driver. And I don't see support for that in the host driver either.

Is this a generic csi driver, or specific for hdmi? Or supposed to handle both?

This is a generic CSI driver.

Quoted 2 lines

Can you give some background and clarification of this?

This piece of code might seem strange but I'm just using it fill our controller timing configuration.

Quoted 8 lines
Quoted 8 lines

I don't have any specific requirements, but they should match, more or less, the sensor configurations, so I decided to re-use the HDMI blanking values, since, usually, they match with the sensor configurations

So, my intention is to check if there is any HDMI preset that matches the required width and height, and then use the blanking values to configure our controller. I know this might not be very common, and I'm open to use different approaches, but from my perspective it seems to work fine.

What kind of timing information do you need to configure the receiver?

If you pick a random HDMI configuration it can't be expected to match an unrelated configuration of a sensor. Generally CSI-2 bus frequency, number of lanes and horizontal and vertical blanking are enough to calculate what the hardware needs regarding timing. The received image size is necessary for other purposes.

Do you see that you'd need something else in addition to that?

Signature · 6 lines
Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw
In reply to Sakari Ailus

Em Wed, 17 May 2017 00:48:17 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 9 lines

Hi Ramiro,

Quoted 6 lines · Ramiro Oliveira

This patchset adds support for the DW CSI-2 Host and also for a video device associated with it.

The first 2 patches are only for the DW CSI-2 Host and the last 2 are for the video device.

Quoted 6 lines
Quoted 3 lines

Although this patchset is named as v1 there were already two patchsets previous to this one, but with a different name: "Add support for the DW IP Prototyping Kits for MIPI CSI-2 Host".

Could you briefly describe the hardware and which IP blocks you have there? Three devices to capture images from CSI-2 bus seems a lot.

Just a quick notice here... calling the driver as "dwc" sounds confusing, we have already a "dwc2" and a "dwc3" driver (and an OOT "otg-dwc" driver at RPi tree).

Ok, those are USB drivers, but, as we had some patches for it (or due to it) at linux-media, I would prefer if you could use some other name here, to avoid confusion :-)

Thanks,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html