Skip to contentSkip to conversation

media: ti-vpe: Add CAL v4l2 camera capture driver

PATCH In review Benoit Parrot 2 participants 6 messages Jan 6, 2016 – Feb 19, 2016

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

v6 cover media: ti-vpe: Add CAL v4l2 camera capture driver

The Camera Adaptation Layer (CAL) is a block which consists of a dual port CSI2/MIPI camera capture engine.
This camera engine is currently found on DRA72xx family of devices.

Port #0 can handle CSI2 camera connected to up to 4 data lanes. Port #1 can handle CSI2 camera connected to up to 2 data lanes.

The driver implements the required API/ioctls to be V4L2 compliant. Driver supports the following:
- V4L2 API using DMABUF/MMAP buffer access based on videobuf2 api
- Asynchronous sensor sub device registration
- DT support

Currently each port is designed to connect to a single sub-device. In other words port aggregation is not currently supported.

Changes since v5:
- Added ti-vpe entry into the MAINTAINERS file.
- Per review comment corrected potential infinite loop.
- Fix checkpatch alignment and use safer strlcpy.
- Remove trace like debug statement.
- Modified register and bit field macro to use existing bitops support, cleaning up the header file and make the code a little easier to follow.

Changes since v4:
- Corrected dt bindings per review comment.
- Applied related dt bindings changes to driver code.
- Folded in coccinelle generated patches.
- Corrected checkpatch.pl --strict warnings.

Changes since v3:
- Nothing really I messed up the previous format-patch with the wrong commit-id. Sorry about the repeat.

Changes since v2:
- Rework Kconfig options and added COMPILE_TEST
- Merged in provided vb2 buffer rework
- Rebase on tip of lmm master and fixe vb2 split related changes

Changes since v1:
- Remove unnecessary format description
- Reworked how transient frame format is maintained
in order to make it easier to use the fill helper functions
- Added a per port list of active frame format
- Reworked an added missing vb2 cleanup code
- Fix a module load/unload kernel oops
- Switch to use proper int64 get function for pixel rate control

=====

Here is a sample output of the v4l2-compliance tool:

# ./v4l2-compliance -f -s -v -d /dev/video0 
Driver Info:
	Driver name   : cal
	Card type     : cal
	Bus info : platform:cal-000
	Capabilities  : 0x85200001
		Video Capture
		Read/Write
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps   : 0x05200001
		Video Capture
		Read/Write
		Streaming
		Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Test input 0:

Control ioctls:
info: checking v4l2_queryctrl of control 'User Controls' (0x00980001)
info: checking v4l2_queryctrl of control 'Horizontal Flip' (0x00980914)
info: checking v4l2_queryctrl of control 'Vertical Flip' (0x00980915)
info: checking v4l2_queryctrl of control 'Image Processing Controls' (0x009f0001)
info: checking v4l2_queryctrl of control 'Pixel Rate' (0x009f0902)
info: checking v4l2_queryctrl of control 'Horizontal Flip' (0x00980914)
info: checking v4l2_queryctrl of control 'Vertical Flip' (0x00980915) test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
info: checking control 'User Controls' (0x00980001)
info: checking control 'Horizontal Flip' (0x00980914)
info: checking control 'Vertical Flip' (0x00980915)
info: checking control 'Image Processing Controls' (0x009f0001)
info: checking control 'Pixel Rate' (0x009f0902)
test VIDIOC_G/S_CTRL: OK
info: checking extended control 'User Controls' (0x00980001)
info: checking extended control 'Horizontal Flip' (0x00980914)
info: checking extended control 'Vertical Flip' (0x00980915)
info: checking extended control 'Image Processing Controls' (0x009f0001)
info: checking extended control 'Pixel Rate' (0x009f0902)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
info: checking control event 'User Controls' (0x00980001)
info: checking control event 'Horizontal Flip' (0x00980914)
info: checking control event 'Vertical Flip' (0x00980915)
info: checking control event 'Image Processing Controls' (0x009f0001)
info: checking control event 'Pixel Rate' (0x009f0902)
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 5 Private Controls: 0

Format ioctls:
info: found 1 frameintervals for pixel format 47425247 and size 1920x1080
info: found 1 framesizes for pixel format 47425247
info: found 1 formats for buftype 1
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
info: test buftype Video Capture test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK (Not Supported)

Test input 0:

Streaming ioctls:

	test read/write: OK
	    Video Capture:
		Buffer: 0 Sequence: 0 Field: None Timestamp: 353.276293s
		Buffer: 1 Sequence: 1 Field: None Timestamp: 353.298270s
		Buffer: 2 Sequence: 2 Field: None Timestamp: 353.320238s
		Buffer: 0 Sequence: 3 Field: None Timestamp: 353.342223s
		Buffer: 1 Sequence: 4 Field: None Timestamp: 353.364199s
		Buffer: 2 Sequence: 5 Field: None Timestamp: 353.386175s
		Buffer: 0 Sequence: 6 Field: None Timestamp: 353.408152s
		Buffer: 1 Sequence: 7 Field: None Timestamp: 353.430128s
		Buffer: 2 Sequence: 8 Field: None Timestamp: 353.452105s
		Buffer: 0 Sequence: 9 Field: None Timestamp: 353.474074s
		Buffer: 1 Sequence: 10 Field: None Timestamp: 353.496058s
		Buffer: 2 Sequence: 11 Field: None Timestamp: 353.518034s
		Buffer: 0 Sequence: 12 Field: None Timestamp: 353.540010s
		Buffer: 1 Sequence: 13 Field: None Timestamp: 353.561978s
		Buffer: 2 Sequence: 14 Field: None Timestamp: 353.583963s
		Buffer: 0 Sequence: 15 Field: None Timestamp: 353.605940s
		Buffer: 1 Sequence: 16 Field: None Timestamp: 353.627916s
		Buffer: 2 Sequence: 17 Field: None Timestamp: 353.649893s
		Buffer: 0 Sequence: 18 Field: None Timestamp: 353.671869s
		Buffer: 1 Sequence: 19 Field: None Timestamp: 353.693846s
		Buffer: 2 Sequence: 20 Field: None Timestamp: 353.715815s
		Buffer: 0 Sequence: 21 Field: None Timestamp: 353.737799s
		Buffer: 1 Sequence: 22 Field: None Timestamp: 353.759775s
		Buffer: 2 Sequence: 23 Field: None Timestamp: 353.781751s
		Buffer: 0 Sequence: 24 Field: None Timestamp: 353.803728s
		Buffer: 1 Sequence: 25 Field: None Timestamp: 353.825698s
		Buffer: 2 Sequence: 26 Field: None Timestamp: 353.847681s
		Buffer: 0 Sequence: 27 Field: None Timestamp: 353.869658s
		Buffer: 1 Sequence: 28 Field: None Timestamp: 353.891634s
		Buffer: 2 Sequence: 29 Field: None Timestamp: 353.913610s
		Buffer: 0 Sequence: 30 Field: None Timestamp: 353.935587s
		Buffer: 1 Sequence: 31 Field: None Timestamp: 353.957564s
		Buffer: 2 Sequence: 32 Field: None Timestamp: 353.979533s
		Buffer: 0 Sequence: 33 Field: None Timestamp: 354.001510s
		Buffer: 1 Sequence: 34 Field: None Timestamp: 354.023493s
		Buffer: 2 Sequence: 35 Field: None Timestamp: 354.045469s
		Buffer: 0 Sequence: 36 Field: None Timestamp: 354.067446s
		Buffer: 1 Sequence: 37 Field: None Timestamp: 354.089422s
		Buffer: 2 Sequence: 38 Field: None Timestamp: 354.111399s
		Buffer: 0 Sequence: 39 Field: None Timestamp: 354.133375s
		Buffer: 1 Sequence: 40 Field: None Timestamp: 354.155351s
		Buffer: 2 Sequence: 41 Field: None Timestamp: 354.177328s
		Buffer: 0 Sequence: 42 Field: None Timestamp: 354.199304s
		Buffer: 1 Sequence: 43 Field: None Timestamp: 354.221274s
		Buffer: 2 Sequence: 44 Field: None Timestamp: 354.243257s
		Buffer: 0 Sequence: 45 Field: None Timestamp: 354.265234s
		Buffer: 1 Sequence: 46 Field: None Timestamp: 354.287210s
		Buffer: 2 Sequence: 47 Field: None Timestamp: 354.309187s
		Buffer: 0 Sequence: 48 Field: None Timestamp: 354.331163s
		Buffer: 1 Sequence: 49 Field: None Timestamp: 354.353140s
		Buffer: 2 Sequence: 50 Field: None Timestamp: 354.375116s
		Buffer: 0 Sequence: 51 Field: None Timestamp: 354.397093s
		Buffer: 1 Sequence: 52 Field: None Timestamp: 354.419069s
		Buffer: 2 Sequence: 53 Field: None Timestamp: 354.441038s
		Buffer: 0 Sequence: 54 Field: None Timestamp: 354.463022s
		Buffer: 1 Sequence: 55 Field: None Timestamp: 354.484998s
		Buffer: 2 Sequence: 56 Field: None Timestamp: 354.506975s
		Buffer: 0 Sequence: 57 Field: None Timestamp: 354.528952s
		Buffer: 1 Sequence: 58 Field: None Timestamp: 354.550928s
		Buffer: 2 Sequence: 59 Field: None Timestamp: 354.572904s
	    Video Capture (polling):
		Buffer: 0 Sequence: 60 Field: None Timestamp: 354.594881s
		Buffer: 1 Sequence: 61 Field: None Timestamp: 354.616857s
		Buffer: 2 Sequence: 62 Field: None Timestamp: 354.638834s
		Buffer: 0 Sequence: 63 Field: None Timestamp: 354.660810s
		Buffer: 1 Sequence: 64 Field: None Timestamp: 354.682787s
		Buffer: 2 Sequence: 65 Field: None Timestamp: 354.704764s
		Buffer: 0 Sequence: 66 Field: None Timestamp: 354.726733s
		Buffer: 1 Sequence: 67 Field: None Timestamp: 354.748716s
		Buffer: 2 Sequence: 68 Field: None Timestamp: 354.770693s
		Buffer: 0 Sequence: 69 Field: None Timestamp: 354.792669s
		Buffer: 1 Sequence: 70 Field: None Timestamp: 354.814645s
		Buffer: 2 Sequence: 71 Field: None Timestamp: 354.836615s
		Buffer: 0 Sequence: 72 Field: None Timestamp: 354.858591s
		Buffer: 1 Sequence: 73 Field: None Timestamp: 354.880575s
		Buffer: 2 Sequence: 74 Field: None Timestamp: 354.902552s
		Buffer: 0 Sequence: 75 Field: None Timestamp: 354.924528s
		Buffer: 1 Sequence: 76 Field: None Timestamp: 354.946505s
		Buffer: 2 Sequence: 77 Field: None Timestamp: 354.968481s
		Buffer: 0 Sequence: 78 Field: None Timestamp: 354.990457s
		Buffer: 1 Sequence: 79 Field: None Timestamp: 355.012434s
		Buffer: 2 Sequence: 80 Field: None Timestamp: 355.034411s
		Buffer: 0 Sequence: 81 Field: None Timestamp: 355.056387s
		Buffer: 1 Sequence: 82 Field: None Timestamp: 355.078364s
		Buffer: 2 Sequence: 83 Field: None Timestamp: 355.100340s
		Buffer: 0 Sequence: 84 Field: None Timestamp: 355.122316s
		Buffer: 1 Sequence: 85 Field: None Timestamp: 355.144293s
		Buffer: 2 Sequence: 86 Field: None Timestamp: 355.166269s
		Buffer: 0 Sequence: 87 Field: None Timestamp: 355.188246s
		Buffer: 1 Sequence: 88 Field: None Timestamp: 355.210223s
		Buffer: 2 Sequence: 89 Field: None Timestamp: 355.232199s
		Buffer: 0 Sequence: 90 Field: None Timestamp: 355.254176s
		Buffer: 1 Sequence: 91 Field: None Timestamp: 355.276152s
		Buffer: 2 Sequence: 92 Field: None Timestamp: 355.298128s
		Buffer: 0 Sequence: 93 Field: None Timestamp: 355.320096s
		Buffer: 1 Sequence: 94 Field: None Timestamp: 355.342081s
		Buffer: 2 Sequence: 95 Field: None Timestamp: 355.364058s
		Buffer: 0 Sequence: 96 Field: None Timestamp: 355.386035s
		Buffer: 1 Sequence: 97 Field: None Timestamp: 355.408011s
		Buffer: 2 Sequence: 98 Field: None Timestamp: 355.429987s
		Buffer: 0 Sequence: 99 Field: None Timestamp: 355.451964s
		Buffer: 1 Sequence: 100 Field: None Timestamp: 355.473933s
		Buffer: 2 Sequence: 101 Field: None Timestamp: 355.495917s
		Buffer: 0 Sequence: 102 Field: None Timestamp: 355.517893s
		Buffer: 1 Sequence: 103 Field: None Timestamp: 355.539870s
		Buffer: 2 Sequence: 104 Field: None Timestamp: 355.561837s
		Buffer: 0 Sequence: 105 Field: None Timestamp: 355.583823s
		Buffer: 1 Sequence: 106 Field: None Timestamp: 355.605799s
		Buffer: 2 Sequence: 107 Field: None Timestamp: 355.627775s
		Buffer: 0 Sequence: 108 Field: None Timestamp: 355.649752s
		Buffer: 1 Sequence: 109 Field: None Timestamp: 355.671729s
		Buffer: 2 Sequence: 110 Field: None Timestamp: 355.693705s
		Buffer: 0 Sequence: 111 Field: None Timestamp: 355.715681s
		Buffer: 1 Sequence: 112 Field: None Timestamp: 355.737657s
		Buffer: 2 Sequence: 113 Field: None Timestamp: 355.759634s
		Buffer: 0 Sequence: 114 Field: None Timestamp: 355.781610s
		Buffer: 1 Sequence: 115 Field: None Timestamp: 355.803580s
		Buffer: 2 Sequence: 116 Field: None Timestamp: 355.825556s
		Buffer: 0 Sequence: 117 Field: None Timestamp: 355.847541s
		Buffer: 1 Sequence: 118 Field: None Timestamp: 355.869517s
		Buffer: 2 Sequence: 119 Field: None Timestamp: 355.891493s
	test MMAP: OK
	test USERPTR: OK (Not Supported)
	test DMABUF: Cannot test, specify --expbuf-device

Stream using all formats:

	test MMAP for Format GRBG, Frame Size [email protected] Hz:
		Stride 1920, Field None: OK                                 

Total: 46, Succeeded: 46, Failed: 0, Warnings: 0

*** BLURB HERE ***

Benoit Parrot (3):
media: ti-vpe: Document CAL driver
MAINTAINERS: Add ti-vpe maintainer entry
media: ti-vpe: Add CAL v4l2 camera capture driver

 Documentation/devicetree/bindings/media/ti-cal.txt |   72 +
 MAINTAINERS                                        |    8 +
 drivers/media/platform/Kconfig                     |   12 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/ti-vpe/Makefile             |    4 +
 drivers/media/platform/ti-vpe/cal.c                | 1970 ++++++++++++++++++++
 drivers/media/platform/ti-vpe/cal_regs.h           |  479 +++++
 7 files changed, 2547 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt
 create mode 100644 drivers/media/platform/ti-vpe/cal.c
 create mode 100644 drivers/media/platform/ti-vpe/cal_regs.h
Signature · 1 line
1.8.5.1
#1 lore raw

PATCH v6 1/3 media: ti-vpe: Document CAL driver

Device Tree bindings for the Camera Adaptation Layer (CAL) driver

---
 Documentation/devicetree/bindings/media/ti-cal.txt | 72 ++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/ti-cal.txt
Documentation/devicetree/bindings/media/ti-cal.txt new file +72 -0
new file mode 100644
index 000000000000..ae9b52f37576
@@ -0,0 +1,72 @@
+Texas Instruments DRA72x CAMERA ADAPTATION LAYER (CAL)
+------------------------------------------------------
+
+The Camera Adaptation Layer (CAL) is a key component for image capture
+applications. The capture module provides the system interface and the
+processing capability to connect CSI2 image-sensor modules to the
+DRA72x device.
+
+Required properties:
+- compatible: must be "ti,dra72-cal"
+- reg:	CAL Top level, Receiver Core #0, Receiver Core #1 and Camera RX
+	control address space
+- reg-names: cal_top, cal_rx_core0, cal_rx_core1, and camerrx_control
+	     registers
+- interrupts: should contain IRQ line for the CAL;
+
+CAL supports 2 camera port nodes on MIPI bus. Each CSI2 camera port nodes
+should contain a 'port' child node with child 'endpoint' node. Please
+refer to the bindings defined in
+Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+	cal: cal@4845b000 {
+		compatible = "ti,dra72-cal";
+		ti,hwmods = "cal";
+		reg = <0x4845B000 0x400>,
+		      <0x4845B800 0x40>,
+		      <0x4845B900 0x40>,
+		      <0x4A002e94 0x4>;
+		reg-names = "cal_top",
+			    "cal_rx_core0",
+			    "cal_rx_core1",
+			    "camerrx_control";
+		interrupts = <GIC_SPI 119 IRQ_TYPE_LEVEL_HIGH>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			csi2_0: port@0 {
+				reg = <0>;
+				endpoint {
+					slave-mode;
+					remote-endpoint = <&ar0330_1>;
+				};
+			};
+			csi2_1: port@1 {
+				reg = <1>;
+			};
+		};
+	};
+
+	i2c5: i2c@4807c000 {
+		ar0330@10 {
+			compatible = "ti,ar0330";
+			reg = <0x10>;
+
+			port {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				ar0330_1: endpoint {
+					reg = <0>;
+					clock-lanes = <1>;
+					data-lanes = <0 2 3 4>;
+					remote-endpoint = <&csi2_0>;
+				};
+			};
+		};
+	};
Signature · 1 line
1.8.5.1
#2 lore raw

PATCH v6 2/3 MAINTAINERS: Add ti-vpe maintainer entry

In reply to Benoit Parrot
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 4635e1d14612..ebbdb410c0f0 100644
@@ -10631,6 +10631,14 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/thermal/ti-soc-thermal/
 
+TI VPE/CAL DRIVERS
+M:	Benoit Parrot <[email protected]>
+L:	[email protected]
+W:	http://linuxtv.org/
+Q:	http://patchwork.linuxtv.org/project/linux-media/list/
+S:	Maintained
+F:	drivers/media/platform/ti-vpe/
+
 TI CDCE706 CLOCK DRIVER
 M:	Max Filippov <[email protected]>
 S:	Maintained
Signature · 1 line
1.8.5.1
#3 lore raw

PATCH v6 3/3 media: ti-vpe: Add CAL v4l2 camera capture driver

In reply to Benoit Parrot

The Camera Adaptation Layer (CAL) is a block which consists of a dual port CSI2/MIPI camera capture engine.
Port #0 can handle CSI2 camera connected to up to 4 data lanes. Port #1 can handle CSI2 camera connected to up to 2 data lanes. The driver implements the required API/ioctls to be V4L2 compliant. Driver supports the following:
- V4L2 API using DMABUF/MMAP buffer access based on videobuf2 api
- Asynchronous sensor sub device registration
- DT support

---
 drivers/media/platform/Kconfig           |   12 +
 drivers/media/platform/Makefile          |    2 +
 drivers/media/platform/ti-vpe/Makefile   |    4 +
 drivers/media/platform/ti-vpe/cal.c      | 1970 ++++++++++++++++++++++++++++++
 drivers/media/platform/ti-vpe/cal_regs.h |  479 ++++++++
 5 files changed, 2467 insertions(+)
 create mode 100644 drivers/media/platform/ti-vpe/cal.c
 create mode 100644 drivers/media/platform/ti-vpe/cal_regs.h
drivers/media/platform/Kconfig +12 -0
index 0c53805dff0e..db052f5a627a 100644
@@ -120,6 +120,18 @@ source "drivers/media/platform/s5p-tv/Kconfig"
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 
+config VIDEO_TI_CAL
+	tristate "TI CAL (Camera Adaptation Layer) driver"
+	depends on VIDEO_DEV && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+	depends on SOC_DRA7XX || COMPILE_TEST
+	select VIDEOBUF2_DMA_CONTIG
+	default n
+	---help---
+	  Support for the TI CAL (Camera Adaptation Layer) block
+	  found on DRA72X SoC.
+	  In TI Technical Reference Manual this module is referred as
+	  Camera Interface Subsystem (CAMSS).
+
 endif # V4L_PLATFORM_DRIVERS
 
 menuconfig V4L_MEM2MEM_DRIVERS
drivers/media/platform/Makefile +2 -0
index efa0295af87b..028a7233096b 100644
@@ -18,6 +18,8 @@ obj-$(CONFIG_VIDEO_VIM2M)		+= vim2m.o
 
 obj-$(CONFIG_VIDEO_TI_VPE)		+= ti-vpe/
 
+obj-$(CONFIG_VIDEO_TI_CAL)		+= ti-vpe/
+
 obj-$(CONFIG_VIDEO_MX2_EMMAPRP)		+= mx2_emmaprp.o
 obj-$(CONFIG_VIDEO_CODA) 		+= coda/
 
drivers/media/platform/ti-vpe/Makefile +4 -0
index be680f839e77..e236059a60ad 100644
@@ -3,3 +3,7 @@ obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
 ti-vpe-y := vpe.o sc.o csc.o vpdma.o
 
 ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
+
+obj-$(CONFIG_VIDEO_TI_CAL) += ti-cal.o
+
+ti-cal-y := cal.o
drivers/media/platform/ti-vpe/cal.c new file +1970 -0

1,970 lines not on this page · raw message

drivers/media/platform/ti-vpe/cal_regs.h new file +479 -0

479 lines not on this page · raw message

Signature · 1 line
1.8.5.1
#4 lore raw

Em Wed, 6 Jan 2016 17:37:26 -0600
Benoit Parrot <[email protected]> escreveu:

Quoted 13 lines

The Camera Adaptation Layer (CAL) is a block which consists of a dual port CSI2/MIPI camera capture engine.
Port #0 can handle CSI2 camera connected to up to 4 data lanes. Port #1 can handle CSI2 camera connected to up to 2 data lanes. The driver implements the required API/ioctls to be V4L2 compliant. Driver supports the following:
- V4L2 API using DMABUF/MMAP buffer access based on videobuf2 api
- Asynchronous sensor sub device registration
- DT support

---

...

Quoted 35 lines
(quoted diff) +35 -0
+/* timeperframe is arbitrary and continuous */
+static int cal_enum_frameintervals(struct file *file, void *priv,
+				   struct v4l2_frmivalenum *fival)
+{
+	struct cal_ctx *ctx = video_drvdata(file);
+	const struct cal_fmt *fmt;
+	struct v4l2_subdev_frame_size_enum fse;
+	int ret;
+
+	if (fival->index)
+		return -EINVAL;
+
+	fmt = find_format_by_pix(ctx, fival->pixel_format);
+	if (!fmt)
+		return -EINVAL;
+
+	/* check for valid width/height */
+	ret = 0;
+	fse.pad = 0;
+	fse.code = fmt->code;
+	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	for (fse.index = 0; ; fse.index++) {
+		ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
+				       NULL, &fse);
+		if (ret)
+			return -EINVAL;
+
+		if ((fival->width == fse.max_width) &&
+		    (fival->height == fse.max_height))
+			break;
+		else if ((fival->width >= fse.min_width) &&
+			 (fival->width <= fse.max_width) &&
+			 (fival->height >= fse.min_height) &&
+			 (fival->height <= fse.max_height))
+			break;

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+		return -EINVAL;
+	}
+
+	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+	fival->discrete.numerator = 1;
+	fival->discrete.denominator = 30;
+
+	return 0;
+}

The above routine is too complex and sounds wrong. Why do you need a loop there, if the loop will either return -EINVAL or be aborted the first time it runs?

The way it is, it is just confusing and produces a smatch error:

drivers/media/platform/ti-vpe/cal.c:1219 cal_enum_frameintervals() info: ignoring unreachable code.

If all you want here is to run the loop once, this patch would do the same, with a clearer logic.

ti-vpe/cal: Simplify the logic to avoid confusing smatch

drivers/media/platform/ti-vpe/cal.c:1219 cal_enum_frameintervals() info: ignoring unreachable code.

This is caused by a very confusing logic that looks like a loop, but it runs only once.

drivers/media/platform/ti-vpe/cal.c +15 -16
index 35fa1071c5b2..62721ee7b9bc 100644
@@ -1216,29 +1216,28 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
 	fse.pad = 0;
 	fse.code = fmt->code;
 	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-	for (fse.index = 0; ; fse.index++) {
-		ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
-				       NULL, &fse);
-		if (ret)
-			return -EINVAL;
-
-		if ((fival->width == fse.max_width) &&
-		    (fival->height == fse.max_height))
-			break;
-		else if ((fival->width >= fse.min_width) &&
-			 (fival->width <= fse.max_width) &&
-			 (fival->height >= fse.min_height) &&
-			 (fival->height <= fse.max_height))
-			break;
+	fse.index = 0;
 
+	ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
+			       NULL, &fse);
+	if (ret)
 		return -EINVAL;
-	}
 
 	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
 	fival->discrete.numerator = 1;
 	fival->discrete.denominator = 30;
 
-	return 0;
+	if ((fival->width == fse.max_width) &&
+	    (fival->height == fse.max_height))
+		return 0;
+
+	if ((fival->width >= fse.min_width) &&
+	    (fival->width <= fse.max_width) &&
+	    (fival->height >= fse.min_height) &&
+	    (fival->height <= fse.max_height))
+		return 0;
+
+	return -EINVAL;
 }
 
 /*
#5 lore raw

Mauro,

Thanks for the proposed fix.
But I decided to fix it in a different way.
I'll send a patch shortly.

Regards,
Benoit

Mauro Carvalho Chehab <[email protected]> wrote on Fri [2016-Feb-19 14:54:23 -0200]:

Quoted 125 lines

Em Wed, 6 Jan 2016 17:37:26 -0600
Benoit Parrot <[email protected]> escreveu:

Quoted 13 lines

The Camera Adaptation Layer (CAL) is a block which consists of a dual port CSI2/MIPI camera capture engine.
Port #0 can handle CSI2 camera connected to up to 4 data lanes. Port #1 can handle CSI2 camera connected to up to 2 data lanes. The driver implements the required API/ioctls to be V4L2 compliant. Driver supports the following:
- V4L2 API using DMABUF/MMAP buffer access based on videobuf2 api
- Asynchronous sensor sub device registration
- DT support

---

...

Quoted 35 lines
(quoted diff) +35 -0
+/* timeperframe is arbitrary and continuous */
+static int cal_enum_frameintervals(struct file *file, void *priv,
+				   struct v4l2_frmivalenum *fival)
+{
+	struct cal_ctx *ctx = video_drvdata(file);
+	const struct cal_fmt *fmt;
+	struct v4l2_subdev_frame_size_enum fse;
+	int ret;
+
+	if (fival->index)
+		return -EINVAL;
+
+	fmt = find_format_by_pix(ctx, fival->pixel_format);
+	if (!fmt)
+		return -EINVAL;
+
+	/* check for valid width/height */
+	ret = 0;
+	fse.pad = 0;
+	fse.code = fmt->code;
+	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
+	for (fse.index = 0; ; fse.index++) {
+		ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
+				       NULL, &fse);
+		if (ret)
+			return -EINVAL;
+
+		if ((fival->width == fse.max_width) &&
+		    (fival->height == fse.max_height))
+			break;
+		else if ((fival->width >= fse.min_width) &&
+			 (fival->width <= fse.max_width) &&
+			 (fival->height >= fse.min_height) &&
+			 (fival->height <= fse.max_height))
+			break;

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+		return -EINVAL;
+	}
+
+	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+	fival->discrete.numerator = 1;
+	fival->discrete.denominator = 30;
+
+	return 0;
+}

The above routine is too complex and sounds wrong. Why do you need a loop there, if the loop will either return -EINVAL or be aborted the first time it runs?

The way it is, it is just confusing and produces a smatch error:

drivers/media/platform/ti-vpe/cal.c:1219 cal_enum_frameintervals() info: ignoring unreachable code.

If all you want here is to run the loop once, this patch would do the same, with a clearer logic.

ti-vpe/cal: Simplify the logic to avoid confusing smatch

drivers/media/platform/ti-vpe/cal.c:1219 cal_enum_frameintervals() info: ignoring unreachable code.

This is caused by a very confusing logic that looks like a loop, but it runs only once.

drivers/media/platform/ti-vpe/cal.c +8 -16
index 35fa1071c5b2..62721ee7b9bc 100644
@@ -1216,29 +1216,28 @@ static int cal_enum_frameintervals(struct file *file, void *priv,
 	fse.pad = 0;
 	fse.code = fmt->code;
 	fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
-	for (fse.index = 0; ; fse.index++) {
-		ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
-				       NULL, &fse);
-		if (ret)
-			return -EINVAL;
-
-		if ((fival->width == fse.max_width) &&
-		    (fival->height == fse.max_height))
-			break;
-		else if ((fival->width >= fse.min_width) &&
-			 (fival->width <= fse.max_width) &&
-			 (fival->height >= fse.min_height) &&
-			 (fival->height <= fse.max_height))
-			break;
+	fse.index = 0;
 
+	ret = v4l2_subdev_call(ctx->sensor, pad, enum_frame_size,
+			       NULL, &fse);
+	if (ret)
 		return -EINVAL;
-	}
 
 	fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
 	fival->discrete.numerator = 1;
 	fival->discrete.denominator = 30;
 
-	return 0;
+	if ((fival->width == fse.max_width) &&
+	    (fival->height == fse.max_height))
+		return 0;
+

drivers/media/platform/ti-vpe/cal.c static int cal_enum_frameintervals(struct file *file, void *priv, · line 1243

Quoted 10 lines
drivers/media/platform/ti-vpe/cal.c +7 -0
+	if ((fival->width >= fse.min_width) &&
+	    (fival->width <= fse.max_width) &&
+	    (fival->height >= fse.min_height) &&
+	    (fival->height <= fse.max_height))
+		return 0;
+
+	return -EINVAL;
 }
 
 /*

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