Skip to contentSkip to conversation

atmel-isc: add driver for Atmel ISC

PATCH Superseded Songjun Wu 2 participants 10 messages Aug 3, 2016 – Aug 10, 2016

Subsystems (3)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Songjun Wu

author
#0 lore raw

v8 cover atmel-isc: add driver for Atmel ISC

The Image Sensor Controller driver includes two parts.
1) Driver code to implement the ISC function.
2) Device tree binding documentation, it describes how to add the ISC in device tree.

Test result with v4l-utils.
v4l2-compliance SHA : not available

Driver Info:

        Driver name   : atmel_isc
        Card type     : Atmel Image Sensor Controller
        Bus info      : platform:atmel_isc f0008000.isc
        Driver version: 4.7.0
        Capabilities  : 0x84200001
                Video Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x04200001
                Video Capture
                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
test for unlimited opens: OK

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

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:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK (Not Supported) test VIDIOC_QUERYCTRL: OK (Not Supported)
test VIDIOC_G/S_CTRL: OK (Not Supported)
test VIDIOC_G/S/TRY_EXT_CTRLS: OK (Not Supported) test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK (Not Supported) test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 0 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
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:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test VIDIOC_EXPBUF: OK

Test input 0:

Stream using all formats:
test MMAP for Format BA81, Frame Size 640x480 at 60.00 Hz:
Stride 640, Field None: OK
test MMAP for Format YUYV, Frame Size 640x480 at 60.00 Hz:
Stride 1280, Field None: OK

Total: 45, Succeeded: 45, Failed: 0, Warnings: 0

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6:
- Add "iscck" and "gck" to clock-names.

Changes in v5:
- Modify the macro definition and the related code.
- Add clock-output-names.

Changes in v4:
- Modify the isc clock code since the dt is changed.
- Remove the isc clock nodes.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.
- Remove the 'atmel,sensor-preferred'.
- Modify the isc clock node according to the Rob's remarks.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().
- Remove the unit address of the endpoint.
- Add the unit address to the clock node.
- Avoid using underscores in node names.
- Drop the "0x" in the unit address of the i2c node.
- Modify the description of 'atmel,sensor-preferred'.
- Add the description for the ISC internal clock.

Songjun Wu (2):
[media] atmel-isc: add the Image Sensor Controller code [media] atmel-isc: DT binding for Image Sensor Controller driver

 .../devicetree/bindings/media/atmel-isc.txt        |   65 +
 drivers/media/platform/Kconfig                     |    1 +
 drivers/media/platform/Makefile                    |    2 +
 drivers/media/platform/atmel/Kconfig               |    9 +
 drivers/media/platform/atmel/Makefile              |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h      |  165 +++
 drivers/media/platform/atmel/atmel-isc.c           | 1503 ++++++++++++++++++++
 7 files changed, 1746 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isc.txt
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v8 1/2 atmel-isc: add the Image Sensor Controller code

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c
drivers/media/platform/Kconfig +1 -0
index f25344b..b23db17 100644
@@ -111,6 +111,7 @@ source "drivers/media/platform/s5p-tv/Kconfig"
 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"
 
 config VIDEO_TI_CAL
 	tristate "TI CAL (Camera Adaptation Layer) driver"
drivers/media/platform/Makefile +2 -0
index 21771c1..37b6c75 100644
@@ -58,6 +58,8 @@ obj-$(CONFIG_VIDEO_XILINX)		+= xilinx/
 
 obj-$(CONFIG_VIDEO_RCAR_VIN)		+= rcar-vin/
 
+obj-$(CONFIG_VIDEO_ATMEL_ISC)		+= atmel/
+
 ccflags-y += -I$(srctree)/drivers/media/i2c
 
 obj-$(CONFIG_VIDEO_MEDIATEK_VPU)	+= mtk-vpu/
drivers/media/platform/atmel/Kconfig new file +9 -0
new file mode 100644
index 0000000..867dca2
@@ -0,0 +1,9 @@
+config VIDEO_ATMEL_ISC
+	tristate "ATMEL Image Sensor Controller (ISC) support"
+	depends on VIDEO_V4L2 && COMMON_CLK && VIDEO_V4L2_SUBDEV_API && HAS_DMA
+	depends on ARCH_AT91 || COMPILE_TEST
+	select VIDEOBUF2_DMA_CONTIG
+	select REGMAP_MMIO
+	help
+	   This module makes the ATMEL Image Sensor Controller available
+	   as a v4l2 device.
\ No newline at end of file
drivers/media/platform/atmel/Makefile new file +1 -0
new file mode 100644
index 0000000..9d7c999
@@ -0,0 +1 @@
+obj-$(CONFIG_VIDEO_ATMEL_ISC) += atmel-isc.o
drivers/media/platform/atmel/atmel-isc-regs.h new file +165 -0

165 lines not on this page · raw message

drivers/media/platform/atmel/atmel-isc.c new file +1503 -0

1,503 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#9 lore raw

PATCH v8 2/2 atmel-isc: DT binding for Image Sensor Controller driver

In reply to Songjun Wu

DT binding documentation for ISC driver.

---

Changes in v8: None
Changes in v7: None
Changes in v6:
- Add "iscck" and "gck" to clock-names.

Changes in v5:
- Add clock-output-names.

Changes in v4:
- Remove the isc clock nodes.

Changes in v3:
- Remove the 'atmel,sensor-preferred'.
- Modify the isc clock node according to the Rob's remarks.

Changes in v2:
- Remove the unit address of the endpoint.
- Add the unit address to the clock node.
- Avoid using underscores in node names.
- Drop the "0x" in the unit address of the i2c node.
- Modify the description of 'atmel,sensor-preferred'.
- Add the description for the ISC internal clock.

 .../devicetree/bindings/media/atmel-isc.txt        | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/atmel-isc.txt
Documentation/devicetree/bindings/media/atmel-isc.txt new file +65 -0
new file mode 100644
index 0000000..bbe0e87c
@@ -0,0 +1,65 @@
+Atmel Image Sensor Controller (ISC)
+----------------------------------------------
+
+Required properties for ISC:
+- compatible
+	Must be "atmel,sama5d2-isc".
+- reg
+	Physical base address and length of the registers set for the device.
+- interrupts
+	Should contain IRQ line for the ISC.
+- clocks
+	List of clock specifiers, corresponding to entries in
+	the clock-names property;
+	Please refer to clock-bindings.txt.
+- clock-names
+	Required elements: "hclock", "iscck", "gck".
+- #clock-cells
+	Should be 0.
+- clock-output-names
+	Should be "isc-mck".
+- pinctrl-names, pinctrl-0
+	Please refer to pinctrl-bindings.txt.
+
+ISC supports a single port node with parallel bus. It should contain one
+'port' child node with child 'endpoint' node. Please refer to the bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.
+
+Example:
+isc: isc at f0008000 {
+	compatible = "atmel,sama5d2-isc";
+	reg = <0xf0008000 0x4000>;
+	interrupts = <46 IRQ_TYPE_LEVEL_HIGH 5>;
+	clocks = <&isc_clk>, <&iscck>, <&isc_gclk>;
+	clock-names = "hclock", "iscck", "gck";
+	#clock-cells = <0>;
+	clock-output-names = "isc-mck";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_isc_base &pinctrl_isc_data_8bit &pinctrl_isc_data_9_10 &pinctrl_isc_data_11_12>;
+
+	port {
+		isc_0: endpoint {
+			remote-endpoint = <&ov7740_0>;
+			hsync-active = <1>;
+			vsync-active = <0>;
+			pclk-sample = <1>;
+		};
+	};
+};
+
+i2c1: i2c at fc028000 {
+	ov7740: camera at 21 {
+		compatible = "ovti,ov7740";
+		reg = <0x21>;
+		clocks = <&isc>;
+		clock-names = "xvclk";
+		assigned-clocks = <&isc>;
+		assigned-clock-rates = <24000000>;
+
+		port {
+			ov7740_0: endpoint {
+				remote-endpoint = <&isc_0>;
+			};
+		};
+	};
+};
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

In reply to Songjun Wu
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Quoted 8 lines
drivers/media/platform/atmel/atmel-isc.c new file +8 -0
+	if (ret)
+		goto unlock;
+
+unlock:
+	mutex_unlock(&isc->lock);
+	return ret;
+}
+

<snip>

Quoted 48 lines
drivers/media/platform/atmel/atmel-isc.c new file +48 -0
+static int isc_async_complete(struct v4l2_async_notifier *notifier)
+{
+	struct isc_device *isc = container_of(notifier->v4l2_dev,
+					      struct isc_device, v4l2_dev);
+	struct isc_subdev_entity *sd_entity;
+	struct video_device *vdev = &isc->video_dev;
+	struct vb2_queue *q = &isc->vb2_vidq;
+	int ret;
+
+	isc->current_subdev = container_of(notifier,
+					   struct isc_subdev_entity, notifier);
+	sd_entity = isc->current_subdev;
+
+	mutex_init(&isc->lock);
+	init_completion(&isc->comp);
+
+	/* Initialize videobuf2 queue */
+	q->type			= V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	q->io_modes		= VB2_MMAP | VB2_DMABUF | VB2_READ;
+	q->drv_priv		= isc;
+	q->buf_struct_size	= sizeof(struct isc_buffer);
+	q->ops			= &isc_vb2_ops;
+	q->mem_ops		= &vb2_dma_contig_memops;
+	q->timestamp_flags	= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+	q->lock			= &isc->lock;
+	q->min_buffers_needed	= 1;
+	q->dev			= isc->dev;
+
+	ret = vb2_queue_init(q);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "vb2_queue_init() failed: %d\n", ret);
+		return ret;
+	}
+
+	/* Init video dma queues */
+	INIT_LIST_HEAD(&isc->dma_queue);
+	spin_lock_init(&isc->dma_queue_lock);
+
+	/* Register video device */
+	strlcpy(vdev->name, ATMEL_ISC_NAME, sizeof(vdev->name));
+	vdev->release		= video_device_release_empty;
+	vdev->fops		= &isc_fops;
+	vdev->ioctl_ops		= &isc_ioctl_ops;
+	vdev->v4l2_dev		= &isc->v4l2_dev;
+	vdev->vfl_dir		= VFL_DIR_RX;
+	vdev->queue		= q;
+	vdev->lock		= &isc->lock;

drivers/media/platform/atmel/atmel-isc.c line 1185

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+	vdev->ctrl_handler	= isc->current_subdev->sd->ctrl_handler;
+	vdev->device_caps	= V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE;
+	video_set_drvdata(vdev, isc);
+
+	ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "video_register_device failed: %d\n", ret);
+		return ret;
+	}

This should be done last. Once the device is registered apps can use it, so everything should be configured.

Quoted 4 lines
drivers/media/platform/atmel/atmel-isc.c new file +4 -0
+
+	sd_entity->config = v4l2_subdev_alloc_pad_config(sd_entity->sd);
+	if (sd_entity->config == NULL)
+		return -ENOMEM;

drivers/media/platform/atmel/atmel-isc.c line 1199

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+
+	ret = isc_formats_init(isc);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "Init format failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}

Regards,

Hans

#3 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

Quoted 130 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 2 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Actually, you do need to set the format here since here is where you turn on the sensor power, but it should be the current format, not the default format.

And in isc_set_default_fmt I recommend that you call the try fmt of the subdev in order to let the subdev adjust the proposed default format. The 'try' doesn't need to power on the sensor.

Quoted 2 lines

drivers/media/platform/atmel/atmel-isc.c

Quoted 2 lines
drivers/media/platform/atmel/atmel-isc.c new file +1 -0
+	if (ret)

You also need to power off the sd on error!

Quoted 8 lines

drivers/media/platform/atmel/atmel-isc.c line 954

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc.c new file +7 -0
+		goto unlock;
+
+unlock:
+	mutex_unlock(&isc->lock);
+	return ret;
+}
+

Regards,

Hans

#8 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

In reply to Hans Verkuil
Quoted 86 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

Quoted 7 lines

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Accept, thank you.
The raw format is listed on the beginning, in order to select non-raw format, the last format is picked. But it's not very important, it's better to use the beginning of the format list.

Quoted 37 lines
Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 3 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Only on the first open, the default format will be set. If it's done in isc_async_complete(), there is a problem, the sensor is powered off, the default format maybe not be set successfully, because in some sensor drivers, calling set_fmt will set the register directly.

Quoted 64 lines
Quoted 8 lines
drivers/media/platform/atmel/atmel-isc.c new file +8 -0
+	if (ret)
+		goto unlock;
+
+unlock:
+	mutex_unlock(&isc->lock);
+	return ret;
+}
+

<snip>

Quoted 53 lines
drivers/media/platform/atmel/atmel-isc.c new file +53 -0
+static int isc_async_complete(struct v4l2_async_notifier *notifier)
+{
+	struct isc_device *isc = container_of(notifier->v4l2_dev,
+					      struct isc_device, v4l2_dev);
+	struct isc_subdev_entity *sd_entity;
+	struct video_device *vdev = &isc->video_dev;
+	struct vb2_queue *q = &isc->vb2_vidq;
+	int ret;
+
+	isc->current_subdev = container_of(notifier,
+					   struct isc_subdev_entity, notifier);
+	sd_entity = isc->current_subdev;
+
+	mutex_init(&isc->lock);
+	init_completion(&isc->comp);
+
+	/* Initialize videobuf2 queue */
+	q->type			= V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	q->io_modes		= VB2_MMAP | VB2_DMABUF | VB2_READ;
+	q->drv_priv		= isc;
+	q->buf_struct_size	= sizeof(struct isc_buffer);
+	q->ops			= &isc_vb2_ops;
+	q->mem_ops		= &vb2_dma_contig_memops;
+	q->timestamp_flags	= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+	q->lock			= &isc->lock;
+	q->min_buffers_needed	= 1;
+	q->dev			= isc->dev;
+
+	ret = vb2_queue_init(q);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "vb2_queue_init() failed: %d\n", ret);
+		return ret;
+	}
+
+	/* Init video dma queues */
+	INIT_LIST_HEAD(&isc->dma_queue);
+	spin_lock_init(&isc->dma_queue_lock);
+
+	/* Register video device */
+	strlcpy(vdev->name, ATMEL_ISC_NAME, sizeof(vdev->name));
+	vdev->release		= video_device_release_empty;
+	vdev->fops		= &isc_fops;
+	vdev->ioctl_ops		= &isc_ioctl_ops;
+	vdev->v4l2_dev		= &isc->v4l2_dev;
+	vdev->vfl_dir		= VFL_DIR_RX;
+	vdev->queue		= q;
+	vdev->lock		= &isc->lock;
+	vdev->ctrl_handler	= isc->current_subdev->sd->ctrl_handler;
+	vdev->device_caps	= V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE;
+	video_set_drvdata(vdev, isc);
+
+	ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
Quoted 9 lines

drivers/media/platform/atmel/atmel-isc.c line 1185

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +5 -0
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "video_register_device failed: %d\n", ret);
+		return ret;
+	}

This should be done last. Once the device is registered apps can use it, so everything should be configured.

Accept, thank you.

Quoted 19 lines
Quoted 4 lines
drivers/media/platform/atmel/atmel-isc.c new file +4 -0
+
+	sd_entity->config = v4l2_subdev_alloc_pad_config(sd_entity->sd);
+	if (sd_entity->config == NULL)
+		return -ENOMEM;

drivers/media/platform/atmel/atmel-isc.c line 1199

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+
+	ret = isc_formats_init(isc);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev,
+			 "Init format failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}

Regards,

Hans

#4 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

In reply to Hans Verkuil
Quoted 134 lines · Hans Verkuil
Quoted 130 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 2 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Quoted 7 lines

Actually, you do need to set the format here since here is where you turn on the sensor power, but it should be the current format, not the default format.

And in isc_set_default_fmt I recommend that you call the try fmt of the subdev in order to let the subdev adjust the proposed default format. The 'try' doesn't need to power on the sensor.

Accept, thank you.

My purpose is to set a default format, if the default format is not set, there will be a fail case when tested by v4l2-tool. I will try to modify the code and test again.

Quoted 5 lines
Quoted 2 lines

drivers/media/platform/atmel/atmel-isc.c

Quoted 2 lines
drivers/media/platform/atmel/atmel-isc.c new file +1 -0
+	if (ret)

You also need to power off the sd on error!

Accept, thank you.

Quoted 13 lines
Quoted 8 lines

drivers/media/platform/atmel/atmel-isc.c line 954

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc.c new file +7 -0
+		goto unlock;
+
+unlock:
+	mutex_unlock(&isc->lock);
+	return ret;
+}
+

Regards,

Hans

#5 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

In reply to Hans Verkuil
Quoted 134 lines · Hans Verkuil
Quoted 130 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 2 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Quoted 7 lines

Actually, you do need to set the format here since here is where you turn on the sensor power, but it should be the current format, not the default format.

And in isc_set_default_fmt I recommend that you call the try fmt of the subdev in order to let the subdev adjust the proposed default format. The 'try' doesn't need to power on the sensor.

I replace the 'set fmt' with 'try fmt', then test with v4l2-compliance, but there are tree fail cases. I think it's reasonable that setting a default fmt on the first open. When app open the device on the first open, it should set a fmt, or the default fmt will be set.

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported)
fail: v4l2-test-formats.cpp(423): fmt.type != type test VIDIOC_G_FMT: FAIL
test VIDIOC_TRY_FMT: OK (Not Supported) test VIDIOC_S_FMT: OK (Not Supported) test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
fail: v4l2-test-formats.cpp(1530): doioctl(node,
VIDIOC_S_FMT, &fmt)

                 fail: v4l2-test-formats.cpp(1627): doioctl(node, 

VIDIOC_S_FMT, &fmt)
test Scaling: FAIL

Quoted 18 lines
Quoted 2 lines

drivers/media/platform/atmel/atmel-isc.c

Quoted 2 lines
drivers/media/platform/atmel/atmel-isc.c new file +1 -0
+	if (ret)

You also need to power off the sd on error!

Quoted 8 lines

drivers/media/platform/atmel/atmel-isc.c line 954

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc.c new file +7 -0
+		goto unlock;
+
+unlock:
+	mutex_unlock(&isc->lock);
+	return ret;
+}
+

Regards,

Hans

#6 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

Quoted 140 lines · Songjun
Quoted 137 lines · Hans Verkuil
Quoted 130 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 2 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Actually, you do need to set the format here since here is where you turn on the sensor power, but it should be the current format, not the default format.

Quoted 8 lines
Quoted 4 lines

And in isc_set_default_fmt I recommend that you call the try fmt of the subdev in order to let the subdev adjust the proposed default format. The 'try' doesn't need to power on the sensor.

I replace the 'set fmt' with 'try fmt', then test with v4l2-compliance, but there are tree fail cases. I think it's reasonable that setting a default fmt on the first open. When app open the device on the first open, it should set a fmt, or the default fmt will be set.

It's not reasonable :-). In V4L2 all format (or any other for that matter) settings are persistent.

Anyway, take a look at my atmel-isi driver:

https://git.linuxtv.org/hverkuil/media_tree.git/tree/drivers/media/platform/atmel-isi.c?h=sama5d3

There I use try_fmt as well, and that passes the compliance test just fine.

Regards,

Hans

#7 lore raw

Re: [PATCH v8 1/2] [media] atmel-isc: add the Image Sensor Controller code

Quoted 150 lines · Hans Verkuil
Quoted 140 lines · Songjun
Quoted 137 lines · Hans Verkuil
Quoted 130 lines · Hans Verkuil
Quoted 74 lines · Songjun Wu

Add driver for the Image Sensor Controller. It manages incoming data from a parallel based CMOS/CCD sensor. It has an internal image processor, also integrates a triple channel direct memory access controller master interface.

---

Changes in v8:
- Power on the sensor on the first open in function 'isc_open'.
- Power off the sensor on the last release in function 'isc_release'.
- Remove the switch of the pipeline.

Changes in v7:
- Add enum_framesizes and enum_frameintervals.
- Call s_stream(0) when stream start fail.
- Fill the device_caps field of struct video_device with V4L2_CAP_STREAMING and V4L2_CAP_VIDEO_CAPTURE.
- Initialize the dev of struct vb2_queue.
- Set field to FIELD_NONE if the pix field is not supported.
- Return the result directly when call g/s_parm of subdev.

Changes in v6: None
Changes in v5:
- Modify the macro definition and the related code.

Changes in v4:
- Modify the isc clock code since the dt is changed.

Changes in v3:
- Add pm runtime feature.
- Modify the isc clock code since the dt is changed.

Changes in v2:
- Add "depends on COMMON_CLK" and "VIDEO_V4L2_SUBDEV_API" in Kconfig file.
- Correct typos and coding style according to Laurent's remarks
- Delete the loop while in 'isc_clk_enable' function.
- Replace 'hsync_active', 'vsync_active' and 'pclk_sample' with 'pfe_cfg0' in struct isc_subdev_entity.
- Add the code to support VIDIOC_CREATE_BUFS in 'isc_queue_setup' function.
- Invoke isc_config to configure register in 'isc_start_streaming' function.
- Add the struct completion 'comp' to synchronize with the frame end interrupt in 'isc_stop_streaming' function.
- Check the return value of the clk_prepare_enable
in 'isc_open' function.
- Set the default format in 'isc_open' function.
- Add an exit condition in the loop while in 'isc_config'.
- Delete the hardware setup operation in 'isc_set_format'.
- Refuse format modification during streaming
in 'isc_s_fmt_vid_cap' function.
- Invoke v4l2_subdev_alloc_pad_config to allocate and initialize the pad config in 'isc_async_complete' function.
- Remove the '.owner = THIS_MODULE,' in atmel_isc_driver.
- Replace the module_platform_driver_probe() with module_platform_driver().

 drivers/media/platform/Kconfig                |    1 +
 drivers/media/platform/Makefile               |    2 +
 drivers/media/platform/atmel/Kconfig          |    9 +
 drivers/media/platform/atmel/Makefile         |    1 +
 drivers/media/platform/atmel/atmel-isc-regs.h |  165 +++
 drivers/media/platform/atmel/atmel-isc.c      | 1503 +++++++++++++++++++++++++
 6 files changed, 1681 insertions(+)
 create mode 100644 drivers/media/platform/atmel/Kconfig
 create mode 100644 drivers/media/platform/atmel/Makefile
 create mode 100644 drivers/media/platform/atmel/atmel-isc-regs.h
 create mode 100644 drivers/media/platform/atmel/atmel-isc.c

<snip>

Quoted 5 lines
drivers/media/platform/atmel/atmel-isc.c new file +0 -0
new file mode 100644
index 0000000..d99d4a5

<snip>

drivers/media/platform/atmel/atmel-isc.c line 912

Quoted 3 lines
drivers/media/platform/atmel/atmel-isc.c new file +3 -0
+static int isc_set_default_fmt(struct isc_device *isc)
+{
+	u32 index = isc->num_user_formats - 1;

Why pick the last format? Strictly speaking it doesn't matter, but in practice the most common formats tend to be at the beginning of the format list.

Quoted 24 lines
drivers/media/platform/atmel/atmel-isc.c new file +24 -0
+	struct v4l2_format f = {
+		.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
+		.fmt.pix = {
+			.width		= VGA_WIDTH,
+			.height		= VGA_HEIGHT,
+			.field		= V4L2_FIELD_NONE,
+			.pixelformat	= isc->user_formats[index]->fourcc,
+		},
+	};
+
+	return isc_set_fmt(isc, &f);
+}
+
+static int isc_open(struct file *file)
+{
+	struct isc_device *isc = video_drvdata(file);
+	struct v4l2_subdev *sd = isc->current_subdev->sd;
+	int ret;
+
+	if (mutex_lock_interruptible(&isc->lock))
+		return -ERESTARTSYS;
+
+	ret = v4l2_fh_open(file);
+	if (ret < 0)

drivers/media/platform/atmel/atmel-isc.c line 946

Quoted 10 lines
drivers/media/platform/atmel/atmel-isc.c new file +10 -0
+		goto unlock;
+
+	if (!v4l2_fh_is_singular_file(file))
+		goto unlock;
+
+	ret = v4l2_subdev_call(sd, core, s_power, 1);
+	if (ret < 0 && ret != -ENOIOCTLCMD)
+		goto unlock;
+
+	ret = isc_set_default_fmt(isc);

This doesn't belong here, this needs to be done in isc_async_complete().

Quoted 2 lines

Having the code here means that every time you open the device, the format changes back to the default. That's not what you want.

Actually, you do need to set the format here since here is where you turn on the sensor power, but it should be the current format, not the default format.

Quoted 8 lines
Quoted 4 lines

And in isc_set_default_fmt I recommend that you call the try fmt of the subdev in order to let the subdev adjust the proposed default format. The 'try' doesn't need to power on the sensor.

I replace the 'set fmt' with 'try fmt', then test with v4l2-compliance, but there are tree fail cases. I think it's reasonable that setting a default fmt on the first open. When app open the device on the first open, it should set a fmt, or the default fmt will be set.

Quoted 9 lines

It's not reasonable :-). In V4L2 all format (or any other for that matter) settings are persistent.

Anyway, take a look at my atmel-isi driver:

https://git.linuxtv.org/hverkuil/media_tree.git/tree/drivers/media/platform/atmel-isi.c?h=sama5d3

There I use try_fmt as well, and that passes the compliance test just fine.

Thank you, I will try again.

Quoted 4 lines

Regards,

Hans