Skip to contentSkip to conversation

rcar-vin: Enable Gen3 support

PATCH In review Niklas Söderlund 3 participants 18 messages May 25, 2016 – Jun 16, 2016

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

cover rcar-vin: Enable Gen3 support

From: Niklas Söderlund <[email protected]>

Hi,

This series enable Gen3 support for the rcar-vin driver. It is based on top of the media_tree:

git://linuxtv.org/media_tree.git master

And it depends on the first rcar-vin patch at which I hope soon will enter the media tree:

https://patchwork.linuxtv.org/patch/34129/

This is a rather large patch since unfortunately the subdevice and input selection on Gen3 are much more complex than on Gen2, see individual patches for a more detailed explanation.

- Patch 1-3 picks up work done by Ulrich so that effort is not wasted before the driver is updated for Gen3.
- Patch 4-6 are the big patches where the driver learns how to work with Gen3.
- Patch 7-8 add compatible strings for Gen3 and fallback strings that are present in the old soc-camera driver but not in this new driver.

The series is tested on Koelsch for Gen2 and it works as expected. If one wants to test the HDMI input the patch 'r8a7791-koelsch.dts: add HDMI input' from Hans Verkuil are needed to add it to DT . The driver passes a v4l2-compliance on Gen2 without errors or warnings. And there are no problems grabbing frames using the CVBS or HDMI input sources using qv4l2.

For Gen3 there are more drivers needed to get working video input running. To be able to grab frames drivers are needed for the R-Car CSI-2 interface and the ADV7482 devices which are not yet present in the kernel. Prototypes for thees two drivers exist and a wiki page at
http://elinux.org/R-Car/Tests:rcar-vin talks about how to test it all together.

Whit thees prototype drivers for CSI-2 and ADV7482 the rcar-vin driver pass the v4l2-compliance tool without errors or warnings on CVBS inputs. On HDMI inputs it complains about missing DV features, this is because the prototype ADV7482 do not yet implement thees operations and are not a fault in the rcar-vin driver.

Disregarding the v4l2-compliance result there is no issue grabbing frames from both CVBS and HDMI input sources on Salvator-X. But more work is needed on the prototype drivers before they are ready to be submitted for upstream.

Niklas Söderlund (5):
[media] rcar-vin: allow subdevices to be bound late [media] rcar-vin: add Gen3 HW registers
[media] rcar-vin: add shared subdevice groups
[media] rcar-vin: enable Gen3
[media] rcar-vin: add Gen2 and Gen3 fallback compatibility strings

Ulrich Hecht (3):
media: rcar-vin: pad-aware driver initialisation
media: rcar_vin: Use correct pad number in try_fmt
media: rcar-vin: add DV timings support

 .../devicetree/bindings/media/rcar_vin.txt         |  218 +++-
 drivers/media/platform/rcar-vin/Kconfig            |    2 +-
 drivers/media/platform/rcar-vin/Makefile           |    2 +-
 drivers/media/platform/rcar-vin/rcar-core.c        |  474 ++++++---
 drivers/media/platform/rcar-vin/rcar-dma.c         |  202 +++-
 drivers/media/platform/rcar-vin/rcar-group.c       | 1122 ++++++++++++++++++++
 drivers/media/platform/rcar-vin/rcar-group.h       |  139 +++
 drivers/media/platform/rcar-vin/rcar-v4l2.c        |  449 ++++----
 drivers/media/platform/rcar-vin/rcar-vin.h         |   83 +-
 9 files changed, 2253 insertions(+), 438 deletions(-)
 create mode 100644 drivers/media/platform/rcar-vin/rcar-group.c
 create mode 100644 drivers/media/platform/rcar-vin/rcar-group.h
Signature · 1 line
2.8.2
#1 lore raw

PATCH 1/8 media: rcar-vin: pad-aware driver initialisation

From: Ulrich Hecht <[email protected]>

Add detection of source pad number for drivers aware of the media controller API, so that rcar-vin can create device nodes to support modern drivers such as adv7604.c (for HDMI on Lager) and the converted adv7180.c (for composite) underneath.

Building rcar_vin gains a dependency on CONFIG_MEDIA_CONTROLLER, in line with requirements for building the drivers associated with it.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 16 ++++++++++++++++
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 ++
 2 files changed, 18 insertions(+)
drivers/media/platform/rcar-vin/rcar-v4l2.c +16 -0
index 0bc4487..929816b 100644
@@ -683,6 +683,9 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
 	struct v4l2_mbus_framefmt *mf = &fmt.format;
 	struct video_device *vdev = &vin->vdev;
 	struct v4l2_subdev *sd = vin_to_source(vin);
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	int pad_idx;
+#endif
 	int ret;
 
 	v4l2_set_subdev_hostdata(sd, vin);
@@ -729,6 +732,19 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
 		V4L2_CAP_READWRITE;
 
+	vin->src_pad_idx = 0;
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
+		if (sd->entity.pads[pad_idx].flags
+				== MEDIA_PAD_FL_SOURCE)
+			break;
+	if (pad_idx >= sd->entity.num_pads)
+		return -EINVAL;
+
+	vin->src_pad_idx = pad_idx;
+#endif
+	fmt.pad = vin->src_pad_idx;
+
 	/* Try to improve our guess of a reasonable window format */
 	ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
 	if (ret) {
drivers/media/platform/rcar-vin/rcar-vin.h +2 -0
index 544a3b3..a6dd6db 100644
@@ -87,6 +87,7 @@ struct rvin_graph_entity {
  *
  * @vdev:		V4L2 video device associated with VIN
  * @v4l2_dev:		V4L2 device
+ * @src_pad_idx:	source pad index for media controller drivers
  * @ctrl_handler:	V4L2 control handler
  * @notifier:		V4L2 asynchronous subdevs notifier
  * @entity:		entity in the DT for subdevice
@@ -117,6 +118,7 @@ struct rvin_dev {
 
 	struct video_device vdev;
 	struct v4l2_device v4l2_dev;
+	int src_pad_idx;
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_async_notifier notifier;
 	struct rvin_graph_entity entity;
Signature · 1 line
2.8.2
#3 lore raw

PATCH 2/8 media: rcar_vin: Use correct pad number in try_fmt

In reply to Niklas Söderlund

From: Ulrich Hecht <[email protected]>

Fix rcar_vin_try_fmt's use of an inappropriate pad number when calling the subdev set_fmt function - for the ADV7612, IDs should be non-zero.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/media/platform/rcar-vin/rcar-v4l2.c +11 -3
index 929816b..3788f8a 100644
@@ -98,7 +98,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 					struct rvin_source_fmt *source)
 {
 	struct v4l2_subdev *sd;
-	struct v4l2_subdev_pad_config pad_cfg;
+	struct v4l2_subdev_pad_config *pad_cfg;
 	struct v4l2_subdev_format format = {
 		.which = which,
 	};
@@ -108,10 +108,16 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 
 	v4l2_fill_mbus_format(&format.format, pix, vin->source.code);
 
+	pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+	if (pad_cfg == NULL)
+		return -ENOMEM;
+
+	format.pad = vin->src_pad_idx;
+
 	ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, pad, set_fmt,
-					 &pad_cfg, &format);
+					 pad_cfg, &format);
 	if (ret < 0)
-		return ret;
+		goto cleanup;
 
 	v4l2_fill_pix_format(pix, &format.format);
 
@@ -121,6 +127,8 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 	vin_dbg(vin, "Source resolution: %ux%u\n", source->width,
 		source->height);
 
+cleanup:
+	v4l2_subdev_free_pad_config(pad_cfg);
 	return 0;
 }
 
Signature · 1 line
2.8.2
#5 lore raw

PATCH 3/8 media: rcar-vin: add DV timings support

In reply to Niklas Söderlund

From: Ulrich Hecht <[email protected]>

Adds ioctls DV_TIMINGS_CAP, ENUM_DV_TIMINGS, G_DV_TIMINGS, S_DV_TIMINGS, and QUERY_DV_TIMINGS.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 82 +++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)
drivers/media/platform/rcar-vin/rcar-v4l2.c +82 -0
index 3788f8a..10a5c10 100644
@@ -400,6 +400,10 @@ static int rvin_enum_input(struct file *file, void *priv,
 
 	i->type = V4L2_INPUT_TYPE_CAMERA;
 	i->std = vin->vdev.tvnorms;
+
+	if (v4l2_subdev_has_op(sd, pad, dv_timings_cap))
+		i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
+
 	strlcpy(i->name, "Camera", sizeof(i->name));
 
 	return 0;
@@ -478,6 +482,78 @@ static int rvin_subscribe_event(struct v4l2_fh *fh,
 	return v4l2_ctrl_subscribe_event(fh, sub);
 }
 
+static int rvin_enum_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_enum_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int pad, ret;
+
+	pad = timings->pad;
+	timings->pad = vin->src_pad_idx;
+
+	ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
+
+	timings->pad = pad;
+
+	return ret;
+}
+
+static int rvin_s_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int err;
+
+	err = v4l2_subdev_call(sd,
+			video, s_dv_timings, timings);
+	if (!err) {
+		vin->source.width = timings->bt.width;
+		vin->source.height = timings->bt.height;
+		vin->format.width = timings->bt.width;
+		vin->format.height = timings->bt.height;
+	}
+	return err;
+}
+
+static int rvin_g_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+
+	return v4l2_subdev_call(sd,
+			video, g_dv_timings, timings);
+}
+
+static int rvin_query_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+
+	return v4l2_subdev_call(sd,
+			video, query_dv_timings, timings);
+}
+
+static int rvin_dv_timings_cap(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings_cap *cap)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int pad, ret;
+
+	pad = cap->pad;
+	cap->pad = vin->src_pad_idx;
+
+	ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
+
+	cap->pad = pad;
+
+	return ret;
+}
+
 static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
 	.vidioc_querycap		= rvin_querycap,
 	.vidioc_try_fmt_vid_cap		= rvin_try_fmt_vid_cap,
@@ -494,6 +570,12 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
 	.vidioc_g_input			= rvin_g_input,
 	.vidioc_s_input			= rvin_s_input,
 
+	.vidioc_dv_timings_cap		= rvin_dv_timings_cap,
+	.vidioc_enum_dv_timings		= rvin_enum_dv_timings,
+	.vidioc_g_dv_timings		= rvin_g_dv_timings,
+	.vidioc_s_dv_timings		= rvin_s_dv_timings,
+	.vidioc_query_dv_timings	= rvin_query_dv_timings,
+
 	.vidioc_querystd		= rvin_querystd,
 	.vidioc_g_std			= rvin_g_std,
 	.vidioc_s_std			= rvin_s_std,
Signature · 1 line
2.8.2
#8 lore raw

PATCH 5/8 rcar-vin: add Gen3 HW registers

In reply to Niklas Söderlund

From: Niklas Söderlund <[email protected]>

Add the register needed to work with Gen3 hardware. This patch just adds the logic for how to work with the Gen3 hardware. More work is required to enable the subdevice structure needed to support capturing.

---
 drivers/media/platform/rcar-vin/rcar-dma.c  | 99 +++++++++++++++++++----------
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 15 ++++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  1 +
 3 files changed, 80 insertions(+), 35 deletions(-)
drivers/media/platform/rcar-vin/rcar-dma.c +67 -32
index b3d3c5e..5196395 100644
@@ -33,21 +33,23 @@
 #define VNELPRC_REG	0x10	/* Video n End Line Pre-Clip Register */
 #define VNSPPRC_REG	0x14	/* Video n Start Pixel Pre-Clip Register */
 #define VNEPPRC_REG	0x18	/* Video n End Pixel Pre-Clip Register */
-#define VNSLPOC_REG	0x1C	/* Video n Start Line Post-Clip Register */
-#define VNELPOC_REG	0x20	/* Video n End Line Post-Clip Register */
-#define VNSPPOC_REG	0x24	/* Video n Start Pixel Post-Clip Register */
-#define VNEPPOC_REG	0x28	/* Video n End Pixel Post-Clip Register */
 #define VNIS_REG	0x2C	/* Video n Image Stride Register */
 #define VNMB_REG(m)	(0x30 + ((m) << 2)) /* Video n Memory Base m Register */
 #define VNIE_REG	0x40	/* Video n Interrupt Enable Register */
 #define VNINTS_REG	0x44	/* Video n Interrupt Status Register */
 #define VNSI_REG	0x48	/* Video n Scanline Interrupt Register */
 #define VNMTC_REG	0x4C	/* Video n Memory Transfer Control Register */
-#define VNYS_REG	0x50	/* Video n Y Scale Register */
-#define VNXS_REG	0x54	/* Video n X Scale Register */
 #define VNDMR_REG	0x58	/* Video n Data Mode Register */
 #define VNDMR2_REG	0x5C	/* Video n Data Mode Register 2 */
 #define VNUVAOF_REG	0x60	/* Video n UV Address Offset Register */
+
+/* Register offsets specific for Gen2 */
+#define VNSLPOC_REG	0x1C	/* Video n Start Line Post-Clip Register */
+#define VNELPOC_REG	0x20	/* Video n End Line Post-Clip Register */
+#define VNSPPOC_REG	0x24	/* Video n Start Pixel Post-Clip Register */
+#define VNEPPOC_REG	0x28	/* Video n End Pixel Post-Clip Register */
+#define VNYS_REG	0x50	/* Video n Y Scale Register */
+#define VNXS_REG	0x54	/* Video n X Scale Register */
 #define VNC1A_REG	0x80	/* Video n Coefficient Set C1A Register */
 #define VNC1B_REG	0x84	/* Video n Coefficient Set C1B Register */
 #define VNC1C_REG	0x88	/* Video n Coefficient Set C1C Register */
@@ -73,9 +75,13 @@
 #define VNC8B_REG	0xF4	/* Video n Coefficient Set C8B Register */
 #define VNC8C_REG	0xF8	/* Video n Coefficient Set C8C Register */
 
+/* Register offsets specific for Gen3 */
+#define VNCSI_IFMD_REG		0x20 /* Video n CSI2 Interface Mode Register */
 
 /* Register bit fields for R-Car VIN */
 /* Video n Main Control Register bits */
+#define VNMC_DPINE		(1 << 27) /* Gen3 specific */
+#define VNMC_SCLE		(1 << 26) /* Gen3 specific */
 #define VNMC_FOC		(1 << 21)
 #define VNMC_YCAL		(1 << 19)
 #define VNMC_INF_YUV8_BT656	(0 << 16)
@@ -118,6 +124,12 @@
 #define VNDMR2_FTEV		(1 << 17)
 #define VNDMR2_VLV(n)		((n & 0xf) << 12)
 
+/* Video n CSI2 Interface Mode Register (Gen3) */
+#define VNCSI_IFMD_DES2		(1 << 27)
+#define VNCSI_IFMD_DES1		(1 << 26)
+#define VNCSI_IFMD_DES0		(1 << 25)
+#define VNCSI_IFMD_CSI_CHSEL(n) ((n & 0xf) << 0)
+
 static void rvin_write(struct rvin_dev *vin, u32 value, u32 offset)
 {
 	iowrite32(value, vin->base + offset);
@@ -196,7 +208,10 @@ static int rvin_setup(struct rvin_dev *vin)
 	}
 
 	/* Enable VSYNC Field Toogle mode after one VSYNC input */
-	dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
+	if (vin->chip == RCAR_GEN3)
+		dmr2 = VNDMR2_FTEV;
+	else
+		dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
 	/* Hsync Signal Polarity Select */
 	if (!(mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
@@ -232,7 +247,8 @@ static int rvin_setup(struct rvin_dev *vin)
 		dmr = 0;
 		break;
 	case V4L2_PIX_FMT_XBGR32:
-		if (vin->chip == RCAR_GEN2 || vin->chip == RCAR_H1) {
+		if (vin->chip == RCAR_GEN2 || vin->chip == RCAR_H1 ||
+		    vin->chip == RCAR_GEN3) {
 			dmr = VNDMR_EXRGB;
 			break;
 		}
@@ -250,6 +266,14 @@ static int rvin_setup(struct rvin_dev *vin)
 	if (input_is_yuv == output_is_yuv)
 		vnmc |= VNMC_BPS;
 
+	if (vin->chip == RCAR_GEN3) {
+		/* Select between CSI-2 and Digital input */
+		if (mbus_cfg.type == V4L2_MBUS_CSI2)
+			vnmc &= ~VNMC_DPINE;
+		else
+			vnmc |= VNMC_DPINE;
+	}
+
 	/* Progressive or interlaced mode */
 	interrupts = progressive ? VNIE_FIE : VNIE_EFE;
 
@@ -740,28 +764,10 @@ static void rvin_set_coeff(struct rvin_dev *vin, unsigned short xs)
 	rvin_write(vin, p_set->coeff_set[23], VNC8C_REG);
 }
 
-void rvin_crop_scale_comp(struct rvin_dev *vin)
+static void rvin_crop_scale_comp_gen2(struct rvin_dev *vin)
 {
 	u32 xs, ys;
 
-	/* Set Start/End Pixel/Line Pre-Clip */
-	rvin_write(vin, vin->crop.left, VNSPPRC_REG);
-	rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG);
-	switch (vin->format.field) {
-	case V4L2_FIELD_INTERLACED:
-	case V4L2_FIELD_INTERLACED_TB:
-	case V4L2_FIELD_INTERLACED_BT:
-		rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG);
-		rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1,
-			   VNELPRC_REG);
-		break;
-	default:
-		rvin_write(vin, vin->crop.top, VNSLPRC_REG);
-		rvin_write(vin, vin->crop.top + vin->crop.height - 1,
-			   VNELPRC_REG);
-		break;
-	}
-
 	/* Set scaling coefficient */
 	ys = 0;
 	if (vin->crop.height != vin->compose.height)
@@ -799,11 +805,6 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
 		break;
 	}
 
-	if (vin->format.pixelformat == V4L2_PIX_FMT_NV16)
-		rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG);
-	else
-		rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG);
-
 	vin_dbg(vin,
 		"Pre-Clip: %ux%u@%u:%u YS: %d XS: %d Post-Clip: %ux%u@%u:%u\n",
 		vin->crop.width, vin->crop.height, vin->crop.left,
@@ -811,9 +812,43 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
 		0, 0);
 }
 
+void rvin_crop_scale_comp(struct rvin_dev *vin)
+{
+	/* Set Start/End Pixel/Line Pre-Clip */
+	rvin_write(vin, vin->crop.left, VNSPPRC_REG);
+	rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG);
+	switch (vin->format.field) {
+	case V4L2_FIELD_INTERLACED:
+	case V4L2_FIELD_INTERLACED_TB:
+	case V4L2_FIELD_INTERLACED_BT:
+		rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG);
+		rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1,
+			   VNELPRC_REG);
+		break;
+	default:
+		rvin_write(vin, vin->crop.top, VNSLPRC_REG);
+		rvin_write(vin, vin->crop.top + vin->crop.height - 1,
+			   VNELPRC_REG);
+		break;
+	}
+
+	/* Driver do not support UDS */
+	if (vin->chip != RCAR_GEN3)
+		rvin_crop_scale_comp_gen2(vin);
+
+	if (vin->format.pixelformat == V4L2_PIX_FMT_NV16)
+		rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG);
+	else
+		rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG);
+}
+
 void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
 		    u32 width, u32 height)
 {
+	/* Driver do not support UDS */
+	if (vin->chip == RCAR_GEN3)
+		return;
+
 	/* All VIN channels on Gen2 have scalers */
 	pix->width = width;
 	pix->height = height;
drivers/media/platform/rcar-vin/rcar-v4l2.c +12 -3
index 2307f5b..f4eaef0 100644
@@ -25,6 +25,8 @@
 #define RVIN_DEFAULT_FORMAT	V4L2_PIX_FMT_YUYV
 #define RVIN_MAX_WIDTH		2048
 #define RVIN_MAX_HEIGHT		2048
+#define RVIN_MAX_WIDTH_GEN3	4096
+#define RVIN_MAX_HEIGHT_GEN3	4096
 
 /* -----------------------------------------------------------------------------
  * Format Conversions
@@ -139,7 +141,7 @@ static int __rvin_try_format(struct rvin_dev *vin,
 			     struct rvin_source_fmt *source)
 {
 	const struct rvin_video_format *info;
-	u32 rwidth, rheight, walign;
+	u32 rwidth, rheight, walign, max_width, max_height;
 
 	/* Requested */
 	rwidth = pix->width;
@@ -173,8 +175,15 @@ static int __rvin_try_format(struct rvin_dev *vin,
 	walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
 
 	/* Limit to VIN capabilities */
-	v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign,
-			      &pix->height, 4, RVIN_MAX_HEIGHT, 2, 0);
+	if (vin->chip == RCAR_GEN3) {
+		max_width = RVIN_MAX_WIDTH_GEN3;
+		max_height = RVIN_MAX_HEIGHT_GEN3;
+	} else {
+		max_width = RVIN_MAX_WIDTH;
+		max_height = RVIN_MAX_HEIGHT;
+	}
+	v4l_bound_align_image(&pix->width, 2, max_width, walign,
+			      &pix->height, 4, max_height, 2, 0);
 
 	switch (pix->field) {
 	case V4L2_FIELD_NONE:
drivers/media/platform/rcar-vin/rcar-vin.h +1 -0
index 81780f1..b97fa43 100644
@@ -32,6 +32,7 @@
 #define HW_BUFFER_MASK 0x7f
 
 enum chip_id {
+	RCAR_GEN3,
 	RCAR_GEN2,
 	RCAR_H1,
 	RCAR_M1,
Signature · 1 line
2.8.2
#11 lore raw

PATCH 7/8 rcar-vin: enable Gen3

In reply to Niklas Söderlund

From: Niklas Söderlund <[email protected]>

---
 drivers/media/platform/rcar-vin/Kconfig     | 2 +-
 drivers/media/platform/rcar-vin/rcar-core.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/rcar-vin/Kconfig +1 -1
index b2ff2d4..ca3ea91 100644
@@ -5,7 +5,7 @@ config VIDEO_RCAR_VIN
 	select VIDEOBUF2_DMA_CONTIG
 	---help---
 	  Support for Renesas R-Car Video Input (VIN) driver.
-	  Supports R-Car Gen2 SoCs.
+	  Supports R-Car Gen2 and Gen3 SoCs.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called rcar-vin.
drivers/media/platform/rcar-vin/rcar-core.c +1 -0
index d901ad0..520690c 100644
@@ -26,6 +26,7 @@
 #include "rcar-vin.h"
 
 static const struct of_device_id rvin_of_id_table[] = {
+	{ .compatible = "renesas,vin-r8a7795", .data = (void *)RCAR_GEN3 },
 	{ .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
Signature · 1 line
2.8.2
#7 lore raw

PATCH 4/8 rcar-vin: allow subdevices to be bound late

In reply to Niklas Söderlund

From: Niklas Söderlund <[email protected]>

This is done to prepare for Gen3 support where there are more than one subdevice and the usage of them are complex. There is a need to be able to change which subdevices are involved in capturing during runtime (but not while streaming). Furtherer more the subdevices can be shared by more then one rcar-vin instance. To be able to facilitate this for Gen3 this patch adds support to select an input (set of subdevices) after the struct video_device have been registered.

It makes the selection when the first open occurs on the video device, concurrent opens of the device are stuck with the input which was set by the first open. A exception to this is if there is only one user of the video device it is possible to change the input selection using s_input. If s_input is attempted while there are more then one user of the video device it will be disallowed with a -EBUSY. If a user tries to open the video device before it has found a valid input (bound its subdevices) it will be denied to open the video device with a -EBUSY.

At this point this change is purely academic since the driver in its current form only supports one subdevice so not much point in trying to change it. It do however solve the issue of bind/unbind of subdevices and still remaining operational.

---
 drivers/media/platform/rcar-vin/rcar-core.c  | 425 ++++++++++++++++-----------
 drivers/media/platform/rcar-vin/rcar-dma.c   |  36 +--
 drivers/media/platform/rcar-vin/rcar-group.h | 102 +++++++
 drivers/media/platform/rcar-vin/rcar-v4l2.c  | 416 ++++++++++++--------------
 drivers/media/platform/rcar-vin/rcar-vin.h   |  49 ++-
 5 files changed, 587 insertions(+), 441 deletions(-)
 create mode 100644 drivers/media/platform/rcar-vin/rcar-group.h
drivers/media/platform/rcar-vin/rcar-core.c +249 -176
index 341c081..b8dff90 100644
@@ -25,48 +25,127 @@
 
 #include "rcar-vin.h"
 
+static const struct of_device_id rvin_of_id_table[] = {
+	{ .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
+	{ .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
+	{ .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
+	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
+	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
+	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, rvin_of_id_table);
+
 /* -----------------------------------------------------------------------------
- * Async notifier
+ * Subdevice group helpers
  */
 
-#define notifier_to_vin(n) container_of(n, struct rvin_dev, notifier)
-
-static int rvin_mbus_supported(struct rvin_dev *vin)
+int rvin_subdev_get(struct rvin_dev *vin)
 {
-	struct v4l2_subdev *sd;
-	struct v4l2_subdev_mbus_code_enum code = {
-		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
-	};
-
-	sd = vin_to_source(vin);
-
-	code.index = 0;
-	while (!v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &code)) {
-		code.index++;
-		switch (code.code) {
-		case MEDIA_BUS_FMT_YUYV8_1X16:
-		case MEDIA_BUS_FMT_YUYV8_2X8:
-		case MEDIA_BUS_FMT_YUYV10_2X10:
-		case MEDIA_BUS_FMT_RGB888_1X24:
-			vin->source.code = code.code;
-			vin_dbg(vin, "Found supported media bus format: %d\n",
-				vin->source.code);
-			return true;
-		default:
-			break;
-		}
+	int i, num = 0;
+
+	for (i = 0; i < RVIN_INPUT_MAX; i++) {
+		vin->inputs[i].type = RVIN_INPUT_NONE;
+		vin->inputs[i].hint = false;
+	}
+
+	/* Add local digital input */
+	if (num < RVIN_INPUT_MAX && vin->digital.subdev) {
+		vin->inputs[num].type = RVIN_INPUT_DIGITAL;
+		strncpy(vin->inputs[num].name, "Digital", RVIN_INPUT_NAME_SIZE);
+		vin->inputs[num].sink_idx =
+			sd_to_pad_idx(vin->digital.subdev, MEDIA_PAD_FL_SINK);
+		vin->inputs[num].source_idx =
+			sd_to_pad_idx(vin->digital.subdev, MEDIA_PAD_FL_SOURCE);
+		/* If last input was digital we want it again */
+		if (vin->current_input == RVIN_INPUT_DIGITAL)
+			vin->inputs[num].hint = true;
+	}
+
+	/* Make sure we have at least one input */
+	if (vin->inputs[0].type == RVIN_INPUT_NONE) {
+		vin_err(vin, "No inputs for channel with current selection\n");
+		return -EBUSY;
 	}
+	vin->current_input = 0;
+
+	/* Search for hint and prefer digital over CSI2 run over all elements */
+	for (i = 0; i < RVIN_INPUT_MAX; i++)
+		if (vin->inputs[i].hint)
+			vin->current_input = i;
+
+	return 0;
+}
+
+int rvin_subdev_put(struct rvin_dev *vin)
+{
+	/* Store what type of input we used */
+	vin->current_input = vin->inputs[vin->current_input].type;
+
+	return 0;
+}
+
+int rvin_subdev_set_input(struct rvin_dev *vin, struct rvin_input_item *item)
+{
+	if (vin->digital.subdev)
+		return 0;
+
+	return -EBUSY;
+}
+
+int rvin_subdev_get_code(struct rvin_dev *vin, u32 *code)
+{
+	*code = vin->digital.code;
+	return 0;
+}
+
+int rvin_subdev_get_mbus_cfg(struct rvin_dev *vin,
+			     struct v4l2_mbus_config *mbus_cfg)
+{
+	*mbus_cfg = vin->digital.mbus_cfg;
+	return 0;
+}
+
+struct v4l2_subdev_pad_config*
+rvin_subdev_alloc_pad_config(struct rvin_dev *vin)
+{
+	return v4l2_subdev_alloc_pad_config(vin->digital.subdev);
+}
+
+int rvin_subdev_ctrl_add_handler(struct rvin_dev *vin)
+{
+	int ret;
+
+	v4l2_ctrl_handler_free(&vin->ctrl_handler);
+
+	ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
+	if (ret < 0)
+		return ret;
 
-	return false;
+	return v4l2_ctrl_add_handler(&vin->ctrl_handler,
+				     vin->digital.subdev->ctrl_handler, NULL);
 }
 
-static int rvin_graph_notify_complete(struct v4l2_async_notifier *notifier)
+/* -----------------------------------------------------------------------------
+ * Async notifier for local Digital
+ */
+
+#define notifier_to_vin(n) container_of(n, struct rvin_dev, notifier)
+
+static int rvin_digital_notify_complete(struct v4l2_async_notifier *notifier)
 {
-	struct v4l2_subdev *sd;
 	struct rvin_dev *vin = notifier_to_vin(notifier);
 	int ret;
 
-	sd = vin_to_source(vin);
+	/* Verify subdevices mbus format */
+	if (!rvin_mbus_supported(&vin->digital)) {
+		vin_err(vin, "Unsupported media bus format for %s\n",
+			vin->digital.subdev->name);
+		return -EINVAL;
+	}
+
+	vin_dbg(vin, "Found media bus format for %s: %d\n",
+		vin->digital.subdev->name, vin->digital.code);
 
 	ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev);
 	if (ret < 0) {
@@ -74,236 +153,226 @@ static int rvin_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		return ret;
 	}
 
-	if (!rvin_mbus_supported(vin)) {
-		vin_err(vin, "No supported mediabus format found\n");
-		return -EINVAL;
+	return 0;
+}
+
+static void rvin_digital_notify_unbind(struct v4l2_async_notifier *notifier,
+				       struct v4l2_subdev *subdev,
+				       struct v4l2_async_subdev *asd)
+{
+	struct rvin_dev *vin = notifier_to_vin(notifier);
+
+	if (vin->digital.subdev == subdev) {
+		vin_dbg(vin, "unbind digital subdev %s\n", subdev->name);
+		vin->digital.subdev = NULL;
+		return;
 	}
 
-	return rvin_v4l2_probe(vin);
+	vin_err(vin, "no entity for subdev %s to unbind\n", subdev->name);
 }
 
-static void rvin_graph_notify_unbind(struct v4l2_async_notifier *notifier,
-				     struct v4l2_subdev *sd,
+static int rvin_digital_notify_bound(struct v4l2_async_notifier *notifier,
+				     struct v4l2_subdev *subdev,
 				     struct v4l2_async_subdev *asd)
 {
 	struct rvin_dev *vin = notifier_to_vin(notifier);
 
-	rvin_v4l2_remove(vin);
+	v4l2_set_subdev_hostdata(subdev, vin);
+
+	if (vin->digital.asd.match.of.node == subdev->dev->of_node) {
+		vin_dbg(vin, "bound digital subdev %s\n", subdev->name);
+		vin->digital.subdev = subdev;
+		return 0;
+	}
+
+	vin_err(vin, "no entity for subdev %s to bind\n", subdev->name);
+	return -EINVAL;
 }
 
-static int rvin_graph_notify_bound(struct v4l2_async_notifier *notifier,
-				   struct v4l2_subdev *subdev,
-				   struct v4l2_async_subdev *asd)
+static int rvin_digitial_parse_v4l2(struct rvin_dev *vin,
+				    struct device_node *ep,
+				    struct v4l2_mbus_config *mbus_cfg)
 {
-	struct rvin_dev *vin = notifier_to_vin(notifier);
+	struct v4l2_of_endpoint v4l2_ep;
+	int ret;
 
-	vin_dbg(vin, "subdev %s bound\n", subdev->name);
+	ret = v4l2_of_parse_endpoint(ep, &v4l2_ep);
+	if (ret) {
+		vin_err(vin, "Could not parse v4l2 endpoint\n");
+		return -EINVAL;
+	}
+
+	mbus_cfg->type = v4l2_ep.bus_type;
 
-	vin->entity.entity = &subdev->entity;
-	vin->entity.subdev = subdev;
+	switch (mbus_cfg->type) {
+	case V4L2_MBUS_PARALLEL:
+		vin_dbg(vin, "Found PARALLEL media bus\n");
+		mbus_cfg->flags = v4l2_ep.bus.parallel.flags;
+		break;
+	case V4L2_MBUS_BT656:
+		vin_dbg(vin, "Found BT656 media bus\n");
+		mbus_cfg->flags = 0;
+		break;
+	default:
+		vin_err(vin, "Unknown media bus type\n");
+		return -EINVAL;
+	}
 
 	return 0;
 }
 
-static int rvin_graph_parse(struct rvin_dev *vin,
-			    struct device_node *node)
+static int rvin_digital_get(struct rvin_dev *vin)
 {
-	struct device_node *remote;
-	struct device_node *ep = NULL;
-	struct device_node *next;
-	int ret = 0;
+	struct device_node *ep, *np;
+	int ret;
 
-	while (1) {
-		next = of_graph_get_next_endpoint(node, ep);
-		if (!next)
-			break;
+	vin->digital.asd.match.of.node = NULL;
+	vin->digital.subdev = NULL;
 
+	/*
+	 * Port 0 id 0 is local digital input, try to get it.
+	 * Not all instances can or will have this, that is OK
+	 */
+	ep = of_graph_get_endpoint_by_regs(vin->dev->of_node, RVIN_PORT_LOCAL,
+					   0);
+	if (!ep)
+		return 0;
+
+	np = of_graph_get_remote_port_parent(ep);
+	if (!np) {
+		vin_err(vin, "No remote parent for digital input\n");
 		of_node_put(ep);
-		ep = next;
-
-		remote = of_graph_get_remote_port_parent(ep);
-		if (!remote) {
-			ret = -EINVAL;
-			break;
-		}
-
-		/* Skip entities that we have already processed. */
-		if (remote == vin->dev->of_node) {
-			of_node_put(remote);
-			continue;
-		}
-
-		/* Remote node to connect */
-		if (!vin->entity.node) {
-			vin->entity.node = remote;
-			vin->entity.asd.match_type = V4L2_ASYNC_MATCH_OF;
-			vin->entity.asd.match.of.node = remote;
-			ret++;
-		}
+		return -EINVAL;
 	}
+	of_node_put(np);
 
+	ret = rvin_digitial_parse_v4l2(vin, ep, &vin->digital.mbus_cfg);
 	of_node_put(ep);
+	if (ret)
+		return ret;
 
-	return ret;
+	vin->digital.asd.match.of.node = np;
+	vin->digital.asd.match_type = V4L2_ASYNC_MATCH_OF;
+
+	return 0;
 }
 
-static int rvin_graph_init(struct rvin_dev *vin)
+static int rvin_digital_graph_init(struct rvin_dev *vin)
 {
 	struct v4l2_async_subdev **subdevs = NULL;
 	int ret;
 
-	/* Parse the graph to extract a list of subdevice DT nodes. */
-	ret = rvin_graph_parse(vin, vin->dev->of_node);
-	if (ret < 0) {
-		vin_err(vin, "Graph parsing failed\n");
-		goto done;
-	}
-
-	if (!ret) {
-		vin_err(vin, "No subdev found in graph\n");
-		goto done;
-	}
+	ret = rvin_digital_get(vin);
+	if (ret)
+		return ret;
 
-	if (ret != 1) {
-		vin_err(vin, "More then one subdev found in graph\n");
-		goto done;
+	if (!vin->digital.asd.match.of.node) {
+		vin_dbg(vin, "No digital subdevice found\n");
+		return -EINVAL;
 	}
 
 	/* Register the subdevices notifier. */
 	subdevs = devm_kzalloc(vin->dev, sizeof(*subdevs), GFP_KERNEL);
-	if (subdevs == NULL) {
-		ret = -ENOMEM;
-		goto done;
-	}
+	if (subdevs == NULL)
+		return -ENOMEM;
 
-	subdevs[0] = &vin->entity.asd;
+	subdevs[0] =  &vin->digital.asd;
+
+	vin_dbg(vin, "Found digital subdevice %s\n",
+		of_node_full_name(subdevs[0]->match.of.node));
 
-	vin->notifier.subdevs = subdevs;
 	vin->notifier.num_subdevs = 1;
-	vin->notifier.bound = rvin_graph_notify_bound;
-	vin->notifier.unbind = rvin_graph_notify_unbind;
-	vin->notifier.complete = rvin_graph_notify_complete;
+	vin->notifier.subdevs = subdevs;
+	vin->notifier.bound = rvin_digital_notify_bound;
+	vin->notifier.unbind = rvin_digital_notify_unbind;
+	vin->notifier.complete = rvin_digital_notify_complete;
 
 	ret = v4l2_async_notifier_register(&vin->v4l2_dev, &vin->notifier);
 	if (ret < 0) {
 		vin_err(vin, "Notifier registration failed\n");
-		goto done;
-	}
-
-	ret = 0;
-
-done:
-	if (ret < 0) {
-		v4l2_async_notifier_unregister(&vin->notifier);
-		of_node_put(vin->entity.node);
+		return ret;
 	}
 
-	return ret;
+	return 0;
 }
 
 /* -----------------------------------------------------------------------------
  * Platform Device Driver
  */
 
-static const struct of_device_id rvin_of_id_table[] = {
-	{ .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
-	{ .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
-	{ .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
-	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
-	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
-	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
-	{ },
-};
-MODULE_DEVICE_TABLE(of, rvin_of_id_table);
-
-static int rvin_parse_dt(struct rvin_dev *vin)
+static int rvin_probe_channel(struct platform_device *pdev,
+			      struct rvin_dev *vin)
 {
-	const struct of_device_id *match;
-	struct v4l2_of_endpoint ep;
-	struct device_node *np;
-	int ret;
-
-	match = of_match_device(of_match_ptr(rvin_of_id_table), vin->dev);
-	if (!match)
-		return -ENODEV;
-
-	vin->chip = (enum chip_id)match->data;
+	struct resource *mem;
+	int irq, ret;
 
-	np = of_graph_get_next_endpoint(vin->dev->of_node, NULL);
-	if (!np) {
-		vin_err(vin, "Could not find endpoint\n");
+	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (mem == NULL)
 		return -EINVAL;
-	}
 
-	ret = v4l2_of_parse_endpoint(np, &ep);
-	if (ret) {
-		vin_err(vin, "Could not parse endpoint\n");
-		return ret;
-	}
-
-	of_node_put(np);
+	vin->base = devm_ioremap_resource(vin->dev, mem);
+	if (IS_ERR(vin->base))
+		return PTR_ERR(vin->base);
 
-	vin->mbus_cfg.type = ep.bus_type;
+	irq = platform_get_irq(pdev, 0);
+	if (irq <= 0)
+		return irq;
 
-	switch (vin->mbus_cfg.type) {
-	case V4L2_MBUS_PARALLEL:
-		vin->mbus_cfg.flags = ep.bus.parallel.flags;
-		break;
-	case V4L2_MBUS_BT656:
-		vin->mbus_cfg.flags = 0;
-		break;
-	default:
-		vin_err(vin, "Unknown media bus type\n");
-		return -EINVAL;
-	}
+	ret = rvin_dma_probe(vin, irq);
+	if (ret)
+		return ret;
 
 	return 0;
 }
 
 static int rcar_vin_probe(struct platform_device *pdev)
 {
+	const struct of_device_id *match;
 	struct rvin_dev *vin;
-	struct resource *mem;
-	int irq, ret;
+	int ret;
 
 	vin = devm_kzalloc(&pdev->dev, sizeof(*vin), GFP_KERNEL);
 	if (!vin)
 		return -ENOMEM;
 
+	match = of_match_device(of_match_ptr(rvin_of_id_table), &pdev->dev);
+	if (!match)
+		return -ENODEV;
+
 	vin->dev = &pdev->dev;
+	vin->chip = (enum chip_id)match->data;
 
-	ret = rvin_parse_dt(vin);
+	/* Prefer digital input */
+	vin->current_input = RVIN_INPUT_DIGITAL;
+
+	/* Initialize the top-level structure */
+	ret = v4l2_device_register(vin->dev, &vin->v4l2_dev);
 	if (ret)
 		return ret;
 
-	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (mem == NULL)
-		return -EINVAL;
-
-	vin->base = devm_ioremap_resource(vin->dev, mem);
-	if (IS_ERR(vin->base))
-		return PTR_ERR(vin->base);
+	ret = rvin_probe_channel(pdev, vin);
+	if (ret)
+		goto err_register;
 
-	irq = platform_get_irq(pdev, 0);
-	if (irq <= 0)
-		return ret;
+	ret = rvin_digital_graph_init(vin);
+	if (ret < 0)
+		goto err_dma;
 
-	ret = rvin_dma_probe(vin, irq);
+	ret = rvin_v4l2_probe(vin);
 	if (ret)
-		return ret;
+		goto err_dma;
 
-	ret = rvin_graph_init(vin);
-	if (ret < 0)
-		goto error;
+	platform_set_drvdata(pdev, vin);
 
 	pm_suspend_ignore_children(&pdev->dev, true);
 	pm_runtime_enable(&pdev->dev);
 
-	platform_set_drvdata(pdev, vin);
-
 	return 0;
-error:
+
+err_dma:
 	rvin_dma_remove(vin);
+err_register:
+	v4l2_device_unregister(&vin->v4l2_dev);
 
 	return ret;
 }
@@ -314,10 +383,14 @@ static int rcar_vin_remove(struct platform_device *pdev)
 
 	pm_runtime_disable(&pdev->dev);
 
+	rvin_v4l2_remove(vin);
+
 	v4l2_async_notifier_unregister(&vin->notifier);
 
 	rvin_dma_remove(vin);
 
+	v4l2_device_unregister(&vin->v4l2_dev);
+
 	return 0;
 }
 
drivers/media/platform/rcar-vin/rcar-dma.c +16 -20
index dad3b03..b3d3c5e 100644
@@ -130,9 +130,16 @@ static u32 rvin_read(struct rvin_dev *vin, u32 offset)
 
 static int rvin_setup(struct rvin_dev *vin)
 {
-	u32 vnmc, dmr, dmr2, interrupts;
+	u32 code, vnmc, dmr, dmr2, interrupts;
+	struct v4l2_mbus_config mbus_cfg;
 	bool progressive = false, output_is_yuv = false, input_is_yuv = false;
 
+	if (rvin_subdev_get_mbus_cfg(vin, &mbus_cfg))
+		return -EINVAL;
+
+	if (rvin_subdev_get_code(vin, &code))
+		return -EINVAL;
+
 	switch (vin->format.field) {
 	case V4L2_FIELD_TOP:
 		vnmc = VNMC_IM_ODD;
@@ -163,7 +170,7 @@ static int rvin_setup(struct rvin_dev *vin)
 	/*
 	 * Input interface
 	 */
-	switch (vin->source.code) {
+	switch (code) {
 	case MEDIA_BUS_FMT_YUYV8_1X16:
 		/* BT.601/BT.1358 16bit YCbCr422 */
 		vnmc |= VNMC_INF_YUV16;
@@ -171,7 +178,7 @@ static int rvin_setup(struct rvin_dev *vin)
 		break;
 	case MEDIA_BUS_FMT_YUYV8_2X8:
 		/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
-		vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ?
+		vnmc |= mbus_cfg.type == V4L2_MBUS_BT656 ?
 			VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
 		input_is_yuv = true;
 		break;
@@ -180,7 +187,7 @@ static int rvin_setup(struct rvin_dev *vin)
 		break;
 	case MEDIA_BUS_FMT_YUYV10_2X10:
 		/* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
-		vnmc |= vin->mbus_cfg.type == V4L2_MBUS_BT656 ?
+		vnmc |= mbus_cfg.type == V4L2_MBUS_BT656 ?
 			VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
 		input_is_yuv = true;
 		break;
@@ -192,11 +199,11 @@ static int rvin_setup(struct rvin_dev *vin)
 	dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
 	/* Hsync Signal Polarity Select */
-	if (!(vin->mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
+	if (!(mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
 		dmr2 |= VNDMR2_HPS;
 
 	/* Vsync Signal Polarity Select */
-	if (!(vin->mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
+	if (!(mbus_cfg.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
 		dmr2 |= VNDMR2_VPS;
 
 	/*
@@ -1030,12 +1037,10 @@ static void rvin_buffer_queue(struct vb2_buffer *vb)
 static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
 	struct rvin_dev *vin = vb2_get_drv_priv(vq);
-	struct v4l2_subdev *sd;
 	unsigned long flags;
 	int ret;
 
-	sd = vin_to_source(vin);
-	v4l2_subdev_call(sd, video, s_stream, 1);
+	rvin_subdev_call(vin, video, s_stream, 1);
 
 	spin_lock_irqsave(&vin->qlock, flags);
 
@@ -1060,7 +1065,7 @@ out:
 	/* Return all buffers if something went wrong */
 	if (ret) {
 		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
-		v4l2_subdev_call(sd, video, s_stream, 0);
+		rvin_subdev_call(vin, video, s_stream, 0);
 	}
 
 	spin_unlock_irqrestore(&vin->qlock, flags);
@@ -1071,7 +1076,6 @@ out:
 static void rvin_stop_streaming(struct vb2_queue *vq)
 {
 	struct rvin_dev *vin = vb2_get_drv_priv(vq);
-	struct v4l2_subdev *sd;
 	unsigned long flags;
 	int retries = 0;
 
@@ -1110,8 +1114,7 @@ static void rvin_stop_streaming(struct vb2_queue *vq)
 
 	spin_unlock_irqrestore(&vin->qlock, flags);
 
-	sd = vin_to_source(vin);
-	v4l2_subdev_call(sd, video, s_stream, 0);
+	rvin_subdev_call(vin, video, s_stream, 0);
 
 	/* disable interrupts */
 	rvin_disable_interrupts(vin);
@@ -1133,8 +1136,6 @@ void rvin_dma_remove(struct rvin_dev *vin)
 		vb2_dma_contig_cleanup_ctx(vin->alloc_ctx);
 
 	mutex_destroy(&vin->lock);
-
-	v4l2_device_unregister(&vin->v4l2_dev);
 }
 
 int rvin_dma_probe(struct rvin_dev *vin, int irq)
@@ -1142,11 +1143,6 @@ int rvin_dma_probe(struct rvin_dev *vin, int irq)
 	struct vb2_queue *q = &vin->queue;
 	int i, ret;
 
-	/* Initialize the top-level structure */
-	ret = v4l2_device_register(vin->dev, &vin->v4l2_dev);
-	if (ret)
-		return ret;
-
 	mutex_init(&vin->lock);
 	INIT_LIST_HEAD(&vin->buf_list);
 
drivers/media/platform/rcar-vin/rcar-group.h new file +102 -0

102 lines not on this page · raw message

drivers/media/platform/rcar-vin/rcar-v4l2.c +187 -229

625 lines not on this page · raw message

drivers/media/platform/rcar-vin/rcar-vin.h +33 -16

110 lines not on this page · raw message

Signature · 1 line
2.8.2
#10 lore raw

PATCH 6/8 rcar-vin: add shared subdevice groups

In reply to Niklas Söderlund

From: Niklas Söderlund <[email protected]>

This is done to prepare for Gen3 support where there are more than one subdevice and the usage of them are complex and can be shared between multiple rcar-vin instances. There are a few trouble areas with Gen3 that needs to be solved in order to be able to capture video.

1. There can be up to 4 CSI-2 sources, CSI20, CSI21, CSI40 and CSI41. Each CSI-2 source can be used simultaneously by more then one VIN instance, as shown below. This requires that more then one rcar-vin instance be able to to use the same set of subdevices at the same time.

2. There can be up to 8 VIN instances, VIN0-VIN7. Each instance can capture video simultaneous as any other instance, but they are not fully independent of each other. There is one register which controls what input source is used that is only present in VIN0 and VIN4. The register in VIN0 controls input source for VIN0-VIN3 and the register in VIN4 input source for VIN4-7.

To further complicate input selection it is not possible to independently select an input for a specific VIN instance, the whole group of VIN0-3 or VIN4-7 are needs to be set according to these predetermined selections.

- VIN0-3 controlled by chsel bits in VnCSI_IFMD register in VIN0

   chsel    VIN0        VIN1        VIN2        VIN3
   0        CSI40/VC0   CSI20/VC0   CSI21/VC0   CSI40/VC1
   1        CSI20/VC0   CSI21/VC0   CSI40/VC0   CSI20/VC1
   2        CSI21/VC0   CSI40/VC0   CSI20/VC0   CSI21/VC1
   3        CSI40/VC0   CSI40/VC1   CSI40/VC2   CSI40/VC3
   4        CSI20/VC0   CSI20/VC1   CSI20/VC2   CSI20/VC3
   5        CSI21/VC0   CSI21/VC1   CSI21/VC2   CSI21/VC3

- VIN4-7 controlled by chsel bits in VnCSI_IFMD register in VIN4

   chsel    VIN4        VIN5        VIN6        VIN7
   0        CSI41/VC0   CSI20/VC0   CSI21/VC0   CSI41/VC1
   1        CSI20/VC0   CSI21/VC0   CSI41/VC0   CSI20/VC1
   2        CSI21/VC0   CSI41/VC0   CSI20/VC0   CSI21/VC1
   3        CSI41/VC0   CSI41/VC1   CSI41/VC2   CSI41/VC3
   4        CSI20/VC0   CSI20/VC1   CSI20/VC2   CSI20/VC3
   5        CSI21/VC0   CSI21/VC1   CSI21/VC2   CSI21/VC3

3. Some VIN instances (VIN4 and VIN5) can in addition the shared CSI-2 sources described above have access to a private digital input channel.

This patch tries to solve this problem by adding a group concept to the rcar-vin driver. One VIN instance is in DT described to be the group master. It can be any VIN node but preferably it should be VIN0 or VIN4 since at lest one of those nodes are required to control the chsel bits. To allow CSI-2 input for VIN0-3 the VIN0 node must be present and the same is true for VIN4-7 and VIN4. One can even have two separate groups one for VIN0-3 and one for VIN4-7 provided the two groups don't want to share a CSI-2 input source.

Each rcar-vin instance will register itself as a v4l2 subdevice in addition to a video device. This subdevice serves a few purposes:

1. Allow for the group master to find all rcar-vin members of its group and bind them.

2. Allow for the group master to control the chsel bits using the only operation implemented on the subdevice, s_gpio. This operation is only valid for VIN0 and VIN4 instances of rcar-vin.

3. Allow for the slave rcar-vin members to access the group API exposed by the master by use of the subdevice v4l2_dev pointer.

The master rcar-vin instance will bind to all subdevices needed by the group. That is all the rcar-vin slave nodes, CSI-2 nodes and the video source subdevices which is connected to the other end of the CSI-2 nodes. It will expose an API to the slave nodes by setting the subdevice v4l2_dev pointer.

The group API exposed by the master allows each slave rcar-vin instance to operate on the correct set of subdevices for the current chsel value simply by using the operation rvin_subdev_call() instead of v4l2_subdev_call(). There is one special case for the operations involved in input enumeration (g_input_status, g_tvnorms, dv_timings_cap and *enum_dv_timings), where an extension is made v4l2_subdev_call_input() which allows for the slave to specify which of its inputs it wish to operate on.

Inside the group API there is refcounting keeping track of s_power and s_stream calls so they are not called multiple times for the same set of subdevices. This is needed since more then one rcar-vin slave can view the same input. The second instance will simply join an ongoing stream.

Each rcar-vin slave can request for the input to be changed (chsel value) for its subgroup (VIN0-3 or VIN4-7). But there are a few restrictions on if the input changed is allowed. These restrictions exist to prevent one rcar-vin instance from pulling the rug from another.

1. It is only allowed to change input if the request is coming from a sole user of the subgroup. That is to say if there is exactly one open video device in the subgroup (the one requesting the input change). Multiple opens of the same video device are treated as there are more then one user of the subgroup.

2. A rcar-vin slave can only switch to an input source that is valid for itself. That is to say if the group only have access to CSI20 and CSI40 it is invalid for a slave instance to request a chsel value that would put CSI21 as its input.

A final restriction on the driver as a whole are that it's not allowed to open a video device if the current chsel value puts its input on a CSI-2 node that is not available. An attempt to do so will result in a -EBUSY error.

---
 .../devicetree/bindings/media/rcar_vin.txt         |  218 +++-
 drivers/media/platform/rcar-vin/Makefile           |    2 +-
 drivers/media/platform/rcar-vin/rcar-core.c        |   52 +
 drivers/media/platform/rcar-vin/rcar-dma.c         |   67 ++
 drivers/media/platform/rcar-vin/rcar-group.c       | 1122 ++++++++++++++++++++
 drivers/media/platform/rcar-vin/rcar-group.h       |   39 +-
 drivers/media/platform/rcar-vin/rcar-vin.h         |   41 +-
 7 files changed, 1527 insertions(+), 14 deletions(-)
 create mode 100644 drivers/media/platform/rcar-vin/rcar-group.c
Documentation/devicetree/bindings/media/rcar_vin.txt +211 -7
index 6a4e61c..9aa81dd 100644
@@ -2,8 +2,13 @@ Renesas RCar Video Input driver (rcar_vin)
 ------------------------------------------
 
 The rcar_vin device provides video input capabilities for the Renesas R-Car
-family of devices. The current blocks are always slaves and suppot one input
-channel which can be either RGB, YUYV or BT656.
+family of devices.
+
+On Gen2 the current blocks are always slaves and support one input
+channel which can be either RGB, YUYV or BT656
+
+On Gen3 the current blocks are always slaves and support multiple inputs
+channels which can be ether RGB, YUVU, BT656 or CSI-2.
 
  - compatible: Must be one or more of the following
    - "renesas,vin-r8a7795" for the R8A7795 device
@@ -28,7 +33,30 @@ channel which can be either RGB, YUYV or BT656.
 Additionally, an alias named vinX will need to be created to specify
 which video input device this is.
 
-The per-board settings:
+On Gen3 additional ports can be specified to describe the CSI-2 group
+hierarchy. Port 0 are used to describe inputs (in per-board settings)
+and VIN group membership. Port 1 are used to describe CSI-2 endpoints.
+Port 2 are used to describe VIN endpoints which are part of the group.
+    - ports:
+        - port@0:
+            - reg 1: sub-node describing a endpoint connected to the VIN
+              group master.
+        - port@1: remote CSI-2 endpoints part of VIN group
+            - reg 0: sub-node describing a endpoint to CSI20
+            - reg 1: sub-node describing a endpoint to CSI21
+            - reg 3: sub-node describing a endpoint to CSI40
+            - reg 4: sub-node describing a endpoint to CSI41
+        - port@2: remote VIN endpoints part of VIN group
+            - reg 0: sub-node describing a endpoint to VIN0
+            - reg 1: sub-node describing a endpoint to VIN1
+            - reg 2: sub-node describing a endpoint to VIN2
+            - reg 3: sub-node describing a endpoint to VIN3
+            - reg 4: sub-node describing a endpoint to VIN4
+            - reg 5: sub-node describing a endpoint to VIN5
+            - reg 6: sub-node describing a endpoint to VIN6
+            - reg 7: sub-node describing a endpoint to VIN7
+
+The per-board settings Gen2:
  - port sub-node describing a single endpoint connected to the vin
    as described in video-interfaces.txt[1]. Only the first one will
    be considered as each vin interface has one input port.
@@ -36,9 +64,17 @@ The per-board settings:
    These settings are used to work out video input format and widths
    into the system.
 
+The per-board settings Gen3:
+-ports:
+    - port@0:
+        - reg 0: sub-node describing a endpoint connected to the VIN
+          private digital input as described in video-interfaces.txt[1].
+
+   These settings are used to work out video input format and widths
+   into the system.
 
-Device node example
--------------------
+Device node example Gen2
+------------------------
 
 	aliases {
 	       vin0 = &vin0;
@@ -52,8 +88,8 @@ Device node example
                 status = "disabled";
         };
 
-Board setup example (vin1 composite video input)
-------------------------------------------------
+Board setup example Gen2 (vin1 composite video input)
+-----------------------------------------------------
 
 &i2c2   {
         status = "ok";
@@ -92,6 +128,174 @@ Board setup example (vin1 composite video input)
         };
 };
 
+Device node example Gen3
+------------------------
+
+aliases {
+       vin0 = &vin0;
+       vin4 = &vin4;
+};
+
+csi21: csi2@fea90000 {
+        ...
+
+        ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@1 {
+                        reg = <1>;
+
+                        csi21_out: endpoint@1 {
+                                remote-endpoint =  <&vin0csi21>;
+                        };
+                };
+        };
+};
+
+vin0: video@e6ef0000 {
+        compatible = "renesas,vin-r8a7795";
+        reg = <0 0xe6ef0000 0 0x1000>;
+        interrupts = <0 188 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&cpg CPG_MOD 811>;
+        power-domains = <&cpg>;
+        status = "disabled";
+
+        ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                        reg = <0>;
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+
+                        vin0csi: endpoint@1 {
+                                reg = <1>;
+                                remote-endpoint= <&vin0out0>;
+                        };
+
+                };
+                port@1 {
+                        reg = <1>;
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+
+                        vin0csi21: endpoint@1 {
+                                reg = <1>;
+                                remote-endpoint= <&csi21_out>;
+                        };
+                };
+                port@2 {
+                        reg = <2>;
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+
+                        vin0out0: endpoint@0 {
+                                reg = <0>;
+                                remote-endpoint = <&vin0csi>;
+                        };
+                        vin0out4: endpoint@4 {
+                                reg = <4>;
+                                remote-endpoint = <&vin4csi>;
+                        };
+                };
+        };
+};
+
+vin4: video@e6ef4000 {
+        compatible = "renesas,vin-r8a7795";
+        reg = <0 0xe6ef4000 0 0x1000>;
+        interrupts = <0 174 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&cpg CPG_MOD 807>;
+        power-domains = <&cpg>;
+        status = "disabled";
+
+        ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                        reg = <0>;
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+
+                        vin4csi: endpoint@1 {
+                                reg = <1>;
+                                remote-endpoint = <&vin0out4>;
+                        };
+                };
+        };
+};
+
+Board setup example Gen3
+- VIN0 and VIN4 part of CSI-2 group
+- VIN4 with local digital input
+-----------------------------------------------------
+
+&i2c2   {
+        ...
+
+        adv7482: composite-in@70 {
+                ...
+                port {
+                        adv7482_out: endpoint@1 {
+                                clock-lanes = <0>;
+                                data-lanes = <1>;
+                                remote-endpoint = <&csi21_in>;
+                        };
+                };
+        };
 
+        adv7612: composite-in@20 {
+                ...
+                port {
+                        adv7612_out: endpoint {
+                                bus-width = <8>;
+                                remote-endpoint = <&vin4ep0>;
+                        };
+                };
+        };
+};
+
+&csi21 {
+        status = "okay";
+
+        ...
+
+        ports {
+                port@0 {
+                        reg = <0>;
+
+                        csi21_in: endpoint@0 {
+                                clock-lanes = <0>;
+                                data-lanes = <1>;
+                                remote-endpoint = <&adv7482_out>;
+                        };
+                };
+        };
+};
+
+&vin0 {
+        status = "okay";
+};
+
+&vin4 {
+        status = "okay";
+
+        ports {
+                port@0 {
+                        reg = <0>;
+                        #address-cells = <1>;
+                        #size-cells = <0>;
+
+                        vin4ep0: endpoint@0 {
+                                reg = <0>;
+                                remote-endpoint= <&adv7612_out>;
+                        };
+
+                };
+        };
+};
 
 [1] video-interfaces.txt common video media interface
drivers/media/platform/rcar-vin/Makefile +1 -1
index 48c5632..7af1b36 100644
@@ -1,3 +1,3 @@
-rcar-vin-objs = rcar-core.o rcar-dma.o rcar-v4l2.o
+rcar-vin-objs = rcar-core.o rcar-dma.o rcar-v4l2.o rcar-group.o
 
 obj-$(CONFIG_VIDEO_RCAR_VIN) += rcar-vin.o
drivers/media/platform/rcar-vin/rcar-core.c +52 -0

132 lines not on this page · raw message

drivers/media/platform/rcar-vin/rcar-dma.c +67 -0

76 lines not on this page · raw message

drivers/media/platform/rcar-vin/rcar-group.c new file +1122 -0

1,122 lines not on this page · raw message

drivers/media/platform/rcar-vin/rcar-group.h +38 -1
index 59eae46..8295ae4 100644
@@ -16,14 +16,17 @@
 #include <media/v4l2-device.h>
 
 #define RVIN_PORT_LOCAL 0
+#define RVIN_PORT_CSI 1
+#define RVIN_PORT_REMOTE 2
 
 enum rvin_input_type {
 	RVIN_INPUT_NONE,
 	RVIN_INPUT_DIGITAL,
+	RVIN_INPUT_CSI2,
 };
 
 /* Max number of inputs supported */
-#define RVIN_INPUT_MAX 1
+#define RVIN_INPUT_MAX 7
 #define RVIN_INPUT_NAME_SIZE 32
 
 /**
@@ -99,4 +102,38 @@ static inline int sd_to_pad_idx(struct v4l2_subdev *sd, int flag)
 	return pad_idx;
 }
 
+struct rvin_group_input_ops {
+	int (*g_input_status)(struct v4l2_subdev *sd,
+			      struct rvin_input_item *item, u32 *status);
+	int (*g_tvnorms)(struct v4l2_subdev *sd,
+			 struct rvin_input_item *item, v4l2_std_id *std);
+	int (*dv_timings_cap)(struct v4l2_subdev *sd,
+			      struct rvin_input_item *item,
+			      struct v4l2_dv_timings_cap *cap);
+	int (*enum_dv_timings)(struct v4l2_subdev *sd,
+			       struct rvin_input_item *item,
+			       struct v4l2_enum_dv_timings *timings);
+};
+
+struct rvin_group_api {
+	int (*get)(struct v4l2_subdev *sd, struct rvin_input_item *inputs);
+	int (*put)(struct v4l2_subdev *sd);
+	int (*set_input)(struct v4l2_subdev *sd, struct rvin_input_item *item);
+	int (*get_code)(struct v4l2_subdev *sd, u32 *code);
+	int (*get_mbus_cfg)(struct v4l2_subdev *sd,
+			    struct v4l2_mbus_config *mbus_cfg);
+
+	int (*ctrl_add_handler)(struct v4l2_subdev *sd,
+				struct v4l2_ctrl_handler *hdl);
+	int (*alloc_pad_config)(struct v4l2_subdev *sd,
+				struct v4l2_subdev_pad_config **cfg);
+
+	const struct v4l2_subdev_ops *ops;
+	const struct rvin_group_input_ops *input_ops;
+};
+
+struct rvin_group_api *rvin_group_probe(struct device *dev,
+					struct v4l2_device *v4l2_dev);
+int rvin_group_remove(struct rvin_group_api *grp);
+
 #endif
drivers/media/platform/rcar-vin/rcar-vin.h +36 -5

70 lines not on this page · raw message

Signature · 1 line
2.8.2
#13 lore raw

PATCH 8/8 rcar-vin: add Gen2 and Gen3 fallback compatibility strings

In reply to Niklas Söderlund

From: Niklas Söderlund <[email protected]>

These are present in the soc-camera version of this driver and it's time to add them to this driver as well.

---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/rcar-vin/rcar-core.c +2 -0
index 520690c..87041db 100644
@@ -33,6 +33,8 @@ static const struct of_device_id rvin_of_id_table[] = {
 	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
 	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
Signature · 1 line
2.8.2
#14 lore raw

Re: [PATCH 8/8] [media] rcar-vin: add Gen2 and Gen3 fallback compatibility strings

Quoted 15 lines · Niklas Söderlund

From: Niklas Söderlund <[email protected]>

These are present in the soc-camera version of this driver and it's time to add them to this driver as well.

---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/rcar-vin/rcar-core.c +0 -0
index 520690c..87041db 100644

drivers/media/platform/rcar-vin/rcar-core.c static const struct of_device_id rvin_of_id_table[] = { · line 37

Quoted 5 lines
drivers/media/platform/rcar-vin/rcar-core.c +2 -0
@@ -33,6 +33,8 @@ static const struct of_device_id rvin_of_id_table[] = {
 	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
 	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },

What's the point of adding the H3 specific compatibility string in the
previous patch then? The fallback stings were added not have to updated the driver for every new SoC exactly.

MBR, Sergei

#15 lore raw

Re: [PATCH 8/8] [media] rcar-vin: add Gen2 and Gen3 fallback compatibility strings

Hi Sergei,

Quoted 12 lines · Sergei Shtylyov
Quoted 10 lines · Niklas Söderlund

From: Niklas Söderlund <[email protected]>

These are present in the soc-camera version of this driver and it's time to add them to this driver as well.

---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

drivers/media/platform/rcar-vin/rcar-core.c static const struct of_device_id rvin_of_id_table[] = { · line 37

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-core.c +2 -0
index 520690c..87041db 100644
@@ -33,6 +33,8 @@ static const struct of_device_id rvin_of_id_table[] = {
 	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
 	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },

What's the point of adding the H3 specific compatibility string in the
previous patch then? The fallback stings were added not have to updated the driver for every new SoC exactly.

Since this driver aims to replace the previous R-Car VIN driver which uses soc-camera I think it also should contain all the compatibility strings that the soc-camera driver do.

Other then that I have no strong opining and are happy to drop the previous patch if the intended use of the fallback strings are to use them over a SoC specific one.

Signature · 2 lines
Regards,
Niklas Söderlund
#16 lore raw

Re: [PATCH 8/8] [media] rcar-vin: add Gen2 and Gen3 fallback compatibility strings

Hello.

Quoted 25 lines · Niklas Söderlund
Quoted 10 lines
Quoted 10 lines

From: Niklas Söderlund <[email protected]>

These are present in the soc-camera version of this driver and it's time to add them to this driver as well.

---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

drivers/media/platform/rcar-vin/rcar-core.c static const struct of_device_id rvin_of_id_table[] = { · line 37

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-core.c +2 -0
index 520690c..87041db 100644
@@ -33,6 +33,8 @@ static const struct of_device_id rvin_of_id_table[] = {
 	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
 	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },

What's the point of adding the H3 specific compatibility string in the
previous patch then? The fallback stings were added not have to updated the driver for every new SoC exactly.

Quoted 3 lines

Since this driver aims to replace the previous R-Car VIN driver which uses soc-camera I think it also should contain all the compatibility strings that the soc-camera driver do.

Indeed. And I'm not seeing the gen2/3 strings there yet (I thought Simon
had already pushed them there). Nevermind then.

MBR, Sergei

#2 lore raw

Re: [PATCH 1/8] media: rcar-vin: pad-aware driver initialisation

In reply to Niklas Söderlund

Hello Niklas,

Thank you for the patch.

Quoted 25 lines · On Wednesday 25 May 2016 21:10:02 Niklas Söderlund wrote:

From: Ulrich Hecht <[email protected]>

Add detection of source pad number for drivers aware of the media controller API, so that rcar-vin can create device nodes to support modern drivers such as adv7604.c (for HDMI on Lager) and the converted adv7180.c (for composite) underneath.

Building rcar_vin gains a dependency on CONFIG_MEDIA_CONTROLLER, in line with requirements for building the drivers associated with it.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 16 ++++++++++++++++
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 ++
 2 files changed, 18 insertions(+)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 0bc4487..929816b 100644

drivers/media/platform/rcar-vin/rcar-v4l2.c int rvin_v4l2_probe(struct rvin_dev *vin) · line 686

Quoted 4 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +1 -0
@@ -683,6 +683,9 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
 	struct v4l2_mbus_framefmt *mf = &fmt.format;
 	struct video_device *vdev = &vin->vdev;
 	struct v4l2_subdev *sd = vin_to_source(vin);
+#if defined(CONFIG_MEDIA_CONTROLLER)

I think you can get rid of conditional compilation here and below. Patch 2/8 calls v4l2_subdev_alloc_pad_config() unconditionally, which depends on CONFIG_MEDIA_CONTROLLER.

Quoted 6 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +2 -0
+	int pad_idx;
+#endif
 	int ret;
 
 	v4l2_set_subdev_hostdata(sd, vin);

drivers/media/platform/rcar-vin/rcar-v4l2.c int rvin_v4l2_probe(struct rvin_dev *vin) · line 739

Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +5 -0
@@ -729,6 +732,19 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
 		V4L2_CAP_READWRITE;
 
+	vin->src_pad_idx = 0;
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	for (pad_idx = 0; pad_idx < sd->entity.num_pads; pad_idx++)
+		if (sd->entity.pads[pad_idx].flags
+				== MEDIA_PAD_FL_SOURCE)

No need for a line break.

Quoted 31 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +8 -0
+			break;
+	if (pad_idx >= sd->entity.num_pads)
+		return -EINVAL;
+
+	vin->src_pad_idx = pad_idx;
+#endif
+	fmt.pad = vin->src_pad_idx;
+
 	/* Try to improve our guess of a reasonable window format */
 	ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &fmt);
 	if (ret) {
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-vin.h index 544a3b3..a6dd6db 100644

drivers/media/platform/rcar-vin/rcar-vin.h +2 -0
@@ -87,6 +87,7 @@ struct rvin_graph_entity {
  *
  * @vdev:		V4L2 video device associated with VIN
  * @v4l2_dev:		V4L2 device
+ * @src_pad_idx:	source pad index for media controller drivers
  * @ctrl_handler:	V4L2 control handler
  * @notifier:		V4L2 asynchronous subdevs notifier
  * @entity:		entity in the DT for subdevice
@@ -117,6 +118,7 @@ struct rvin_dev {
 
 	struct video_device vdev;
 	struct v4l2_device v4l2_dev;
+	int src_pad_idx;
 	struct v4l2_ctrl_handler ctrl_handler;
 	struct v4l2_async_notifier notifier;
 	struct rvin_graph_entity entity;
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Re: [PATCH 2/8] media: rcar_vin: Use correct pad number in try_fmt

In reply to Niklas Söderlund

Hello Niklas,

Thank you for the patch.

Quoted 32 lines · On Wednesday 25 May 2016 21:10:03 Niklas Söderlund wrote:

From: Ulrich Hecht <[email protected]>

Fix rcar_vin_try_fmt's use of an inappropriate pad number when calling the subdev set_fmt function - for the ADV7612, IDs should be non-zero.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 929816b..3788f8a 100644

drivers/media/platform/rcar-vin/rcar-v4l2.c +1 -1
@@ -98,7 +98,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 					struct rvin_source_fmt *source)
 {
 	struct v4l2_subdev *sd;
-	struct v4l2_subdev_pad_config pad_cfg;
+	struct v4l2_subdev_pad_config *pad_cfg;
 	struct v4l2_subdev_format format = {
 		.which = which,
 	};
@@ -108,10 +108,16 @@ static int __rvin_try_format_source(struct rvin_dev
 *vin,
 
 	v4l2_fill_mbus_format(&format.format, pix, vin->source.code);

drivers/media/platform/rcar-vin/rcar-v4l2.c static int __rvin_try_format_source(struct rvin_dev · line 119

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +7 -1
 
+	pad_cfg = v4l2_subdev_alloc_pad_config(sd);
+	if (pad_cfg == NULL)
+		return -ENOMEM;
+
+	format.pad = vin->src_pad_idx;
+
 	ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, pad, set_fmt,
-					 &pad_cfg, &format);
+					 pad_cfg, &format);

pad_cfg is subdev-specific, you can't use v4l2_device_call_until_err(). You should use v4l2_subdev_call() instead. This will obviously not be enough if we have more than one subdev in the pipeline, but the code is broken in that case anyway.

drivers/media/platform/rcar-vin/rcar-v4l2.c static int __rvin_try_format_source(struct rvin_dev · line 130

Quoted 11 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +2 -1
 	if (ret < 0)
-		return ret;
+		goto cleanup;
 
 	v4l2_fill_pix_format(pix, &format.format);
@@ -121,6 +127,8 @@ static int __rvin_try_format_source(struct rvin_dev
 *vin, vin_dbg(vin, "Source resolution: %ux%u\n", source->width,
 		source->height);
 
+cleanup:

Nitpicking, I'd name the label "done".

Quoted 3 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +1 -0
+	v4l2_subdev_free_pad_config(pad_cfg);
 	return 0;
 }
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Re: [PATCH 3/8] media: rcar-vin: add DV timings support

In reply to Niklas Söderlund

Hello Niklas,

Thank you for the patch.

Quoted 28 lines · On Wednesday 25 May 2016 21:10:04 Niklas Söderlund wrote:

From: Ulrich Hecht <[email protected]>

Adds ioctls DV_TIMINGS_CAP, ENUM_DV_TIMINGS, G_DV_TIMINGS, S_DV_TIMINGS, and QUERY_DV_TIMINGS.

---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 82 ++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 3788f8a..10a5c10 100644

drivers/media/platform/rcar-vin/rcar-v4l2.c +4 -0
@@ -400,6 +400,10 @@ static int rvin_enum_input(struct file *file, void
 *priv,
 
 	i->type = V4L2_INPUT_TYPE_CAMERA;
 	i->std = vin->vdev.tvnorms;
+
+	if (v4l2_subdev_has_op(sd, pad, dv_timings_cap))
+		i->capabilities = V4L2_IN_CAP_DV_TIMINGS;
+
 	strlcpy(i->name, "Camera", sizeof(i->name));
 
drivers/media/platform/rcar-vin/rcar-v4l2.c +0 -0
 	return 0;

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 490

Quoted 9 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +6 -0
@@ -478,6 +482,78 @@ static int rvin_subscribe_event(struct v4l2_fh *fh,
 	return v4l2_ctrl_subscribe_event(fh, sub);
 }
 
+static int rvin_enum_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_enum_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int pad, ret;

pad can't be negative, you can make it an unsigned int.

	unsigned int pad = timings->pad;
	int ret;

	timings->pad = vin->src_pad_idx;
Quoted 7 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +7 -0
+
+	pad = timings->pad;
+	timings->pad = vin->src_pad_idx;
+
+	ret = v4l2_subdev_call(sd, pad, enum_dv_timings, timings);
+
+	timings->pad = pad;

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 507

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +10 -0
+
+	return ret;
+}
+
+static int rvin_s_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int err;

The driver uses ret instead of err, let's keep it that way.

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 510

Quoted 3 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +3 -0
+
+	err = v4l2_subdev_call(sd,
+			video, s_dv_timings, timings);

No need for a line break.

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 511

Quoted 1 line
drivers/media/platform/rcar-vin/rcar-v4l2.c +1 -0
+	if (!err) {

I'd write this

	if (ret)
		return ret;

(with a return 0; at the end of the function) to lower the indentation level of the code below.

Quoted 6 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +6 -0
+		vin->source.width = timings->bt.width;
+		vin->source.height = timings->bt.height;
+		vin->format.width = timings->bt.width;
+		vin->format.height = timings->bt.height;
+	}
+	return err;

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 527

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +10 -0
+}
+
+static int rvin_g_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+
+	return v4l2_subdev_call(sd,
+			video, g_dv_timings, timings);

No need for a line break.

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 537

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +10 -0
+}
+
+static int rvin_query_dv_timings(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings *timings)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+
+	return v4l2_subdev_call(sd,
+			video, query_dv_timings, timings);

No need for a line break.

drivers/media/platform/rcar-vin/rcar-v4l2.c static int rvin_subscribe_event(struct v4l2_fh *fh, · line 545

Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +8 -0
+}
+
+static int rvin_dv_timings_cap(struct file *file, void *priv_fh,
+				    struct v4l2_dv_timings_cap *cap)
+{
+	struct rvin_dev *vin = video_drvdata(file);
+	struct v4l2_subdev *sd = vin_to_source(vin);
+	int pad, ret;

Same comment as above about pad not being negative.

Quoted 27 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +17 -0
+
+	pad = cap->pad;
+	cap->pad = vin->src_pad_idx;
+
+	ret = v4l2_subdev_call(sd, pad, dv_timings_cap, cap);
+
+	cap->pad = pad;
+
+	return ret;
+}
+
 static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
 	.vidioc_querycap		= rvin_querycap,
 	.vidioc_try_fmt_vid_cap		= rvin_try_fmt_vid_cap,
@@ -494,6 +570,12 @@ static const struct v4l2_ioctl_ops rvin_ioctl_ops = {
 	.vidioc_g_input			= rvin_g_input,
 	.vidioc_s_input			= rvin_s_input,
 
+	.vidioc_dv_timings_cap		= rvin_dv_timings_cap,
+	.vidioc_enum_dv_timings		= rvin_enum_dv_timings,
+	.vidioc_g_dv_timings		= rvin_g_dv_timings,
+	.vidioc_s_dv_timings		= rvin_s_dv_timings,
+	.vidioc_query_dv_timings	= rvin_query_dv_timings,
+
 	.vidioc_querystd		= rvin_querystd,
 	.vidioc_g_std			= rvin_g_std,
 	.vidioc_s_std			= rvin_s_std,
Signature · 3 lines
Regards,

Laurent Pinchart
#9 lore raw

Re: [PATCH 5/8] [media] rcar-vin: add Gen3 HW registers

In reply to Niklas Söderlund

Hi Niklas,

Thank you for the patch.

Quoted 18 lines · On Wednesday 25 May 2016 21:10:06 Niklas Söderlund wrote:

From: Niklas Söderlund <[email protected]>

Add the register needed to work with Gen3 hardware. This patch just adds the logic for how to work with the Gen3 hardware. More work is required to enable the subdevice structure needed to support capturing.

---
 drivers/media/platform/rcar-vin/rcar-dma.c  | 99 ++++++++++++++++----------
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 15 ++++-
 drivers/media/platform/rcar-vin/rcar-vin.h  |  1 +
 3 files changed, 80 insertions(+), 35 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-dma.c index b3d3c5e..5196395 100644

drivers/media/platform/rcar-vin/rcar-dma.c line 35

Quoted 3 lines
drivers/media/platform/rcar-vin/rcar-dma.c +0 -0
@@ -33,21 +33,23 @@
 #define VNELPRC_REG	0x10	/* Video n End Line Pre-Clip Register */
 #define VNSPPRC_REG	0x14	/* Video n Start Pixel Pre-Clip Register */
 #define VNEPPRC_REG	0x18	/* Video n End Pixel Pre-Clip Register */

By the way, that's not directly related to this patch, but hex constants in the kernel tend to use lowercase letters.

Also, feel free to give a bit more air to the register definitions even if it makes them cross the 80 characters per line limit, if it helps improving readability. If it was up to me I'd add one tab before the register address for instance to align them with the register fields values a bit further below.

Still from a readability point of view, I would extend the register address to 4 (or just 3 if you prefer) hex digits as we have registers above the first 0x100 bytes.

Quoted 55 lines
drivers/media/platform/rcar-vin/rcar-dma.c +8 -6
-#define VNSLPOC_REG	0x1C	/* Video n Start Line Post-Clip Register */
-#define VNELPOC_REG	0x20	/* Video n End Line Post-Clip Register */
-#define VNSPPOC_REG	0x24	/* Video n Start Pixel Post-Clip Register */
-#define VNEPPOC_REG	0x28	/* Video n End Pixel Post-Clip Register */
 #define VNIS_REG	0x2C	/* Video n Image Stride Register */
 #define VNMB_REG(m)	(0x30 + ((m) << 2)) /* Video n Memory Base m Register
 */
 #define VNIE_REG	0x40	/* Video n Interrupt Enable Register */
 #define VNINTS_REG	0x44	/* Video n Interrupt Status Register */
 #define VNSI_REG	0x48	/* Video n Scanline Interrupt Register */
 #define VNMTC_REG	0x4C	/* Video n Memory Transfer Control Register */
-#define VNYS_REG	0x50	/* Video n Y Scale Register */
-#define VNXS_REG	0x54	/* Video n X Scale Register */
 #define VNDMR_REG	0x58	/* Video n Data Mode Register */
 #define VNDMR2_REG	0x5C	/* Video n Data Mode Register 2 */
 #define VNUVAOF_REG	0x60	/* Video n UV Address Offset Register */
+
+/* Register offsets specific for Gen2 */
+#define VNSLPOC_REG	0x1C	/* Video n Start Line Post-Clip Register */
+#define VNELPOC_REG	0x20	/* Video n End Line Post-Clip Register */
+#define VNSPPOC_REG	0x24	/* Video n Start Pixel Post-Clip Register */
+#define VNEPPOC_REG	0x28	/* Video n End Pixel Post-Clip Register */
+#define VNYS_REG	0x50	/* Video n Y Scale Register */
+#define VNXS_REG	0x54	/* Video n X Scale Register */
 #define VNC1A_REG	0x80	/* Video n Coefficient Set C1A Register */
 #define VNC1B_REG	0x84	/* Video n Coefficient Set C1B Register */

#define VNC1C_REG 0x88 /* Video n Coefficient Set C1C Register */

drivers/media/platform/rcar-vin/rcar-dma.c +10 -0
@@ -73,9 +75,13 @@
 #define VNC8B_REG	0xF4	/* Video n Coefficient Set C8B Register */
 #define VNC8C_REG	0xF8	/* Video n Coefficient Set C8C Register */
 
+/* Register offsets specific for Gen3 */
+#define VNCSI_IFMD_REG		0x20 /* Video n CSI2 Interface Mode Register */
 
 /* Register bit fields for R-Car VIN */
 /* Video n Main Control Register bits */
+#define VNMC_DPINE		(1 << 27) /* Gen3 specific */
+#define VNMC_SCLE		(1 << 26) /* Gen3 specific */
 #define VNMC_FOC		(1 << 21)
 #define VNMC_YCAL		(1 << 19)
 #define VNMC_INF_YUV8_BT656	(0 << 16)
@@ -118,6 +124,12 @@
 #define VNDMR2_FTEV		(1 << 17)
 #define VNDMR2_VLV(n)		((n & 0xf) << 12)
 
+/* Video n CSI2 Interface Mode Register (Gen3) */
+#define VNCSI_IFMD_DES2		(1 << 27)
+#define VNCSI_IFMD_DES1		(1 << 26)
+#define VNCSI_IFMD_DES0		(1 << 25)
+#define VNCSI_IFMD_CSI_CHSEL(n) ((n & 0xf) << 0)
+
 static void rvin_write(struct rvin_dev *vin, u32 value, u32 offset)
 {
 	iowrite32(value, vin->base + offset);

drivers/media/platform/rcar-vin/rcar-dma.c static int rvin_setup(struct rvin_dev *vin) · line 211

Quoted 5 lines
drivers/media/platform/rcar-vin/rcar-dma.c +1 -1
@@ -196,7 +208,10 @@ static int rvin_setup(struct rvin_dev *vin)
 	}
 
 	/* Enable VSYNC Field Toogle mode after one VSYNC input */
-	dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
+	if (vin->chip == RCAR_GEN3)

I'm not too fond of scattering this kind of check across the code. My preferred approach is to add a device info structure that stores information about specific device models, and use it as appropriate. You can check the vsp1 or rcar-du driver for examples.

This being said, given that you have a limited number of such checks, there's no need to change this now, but please keep that in mind for the future when more code will be conditioned to the device model.

On a side note, I would rename the field from chip to model, and the values from RCAR_* to RCAR_VIN_*, as what matters is the VIN model, not the SoC.

drivers/media/platform/rcar-vin/rcar-dma.c static int rvin_setup(struct rvin_dev *vin) · line 251

Quoted 13 lines
drivers/media/platform/rcar-vin/rcar-dma.c +5 -1
+		dmr2 = VNDMR2_FTEV;
+	else
+		dmr2 = VNDMR2_FTEV | VNDMR2_VLV(1);
 
 	/* Hsync Signal Polarity Select */
 	if (!(mbus_cfg.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
@@ -232,7 +247,8 @@ static int rvin_setup(struct rvin_dev *vin)
 		dmr = 0;
 		break;
 	case V4L2_PIX_FMT_XBGR32:
-		if (vin->chip == RCAR_GEN2 || vin->chip == RCAR_H1) {
+		if (vin->chip == RCAR_GEN2 || vin->chip == RCAR_H1 ||
+		    vin->chip == RCAR_GEN3) {

If V4L2_PIX_FMT_XBGR32 isn't allowed on M1, VIDIOC_S_FMT and VIDIOC_TRY_FMT should disallow it. This isn't the right place for error checking.

I know the problem isn't introduced by this patch, so you can fix it in a separate patch. Ideally I would fix the problem first, which would get rid of this check, and then apply this patch with this hunk removed.

Quoted 61 lines
drivers/media/platform/rcar-vin/rcar-dma.c +9 -24
 			dmr = VNDMR_EXRGB;
 			break;
 		}
@@ -250,6 +266,14 @@ static int rvin_setup(struct rvin_dev *vin)
 	if (input_is_yuv == output_is_yuv)
 		vnmc |= VNMC_BPS;
 
+	if (vin->chip == RCAR_GEN3) {
+		/* Select between CSI-2 and Digital input */
+		if (mbus_cfg.type == V4L2_MBUS_CSI2)
+			vnmc &= ~VNMC_DPINE;
+		else
+			vnmc |= VNMC_DPINE;
+	}
+
 	/* Progressive or interlaced mode */
 	interrupts = progressive ? VNIE_FIE : VNIE_EFE;
 
@@ -740,28 +764,10 @@ static void rvin_set_coeff(struct rvin_dev *vin,
 unsigned short xs) rvin_write(vin, p_set->coeff_set[23], VNC8C_REG);
 }
 
-void rvin_crop_scale_comp(struct rvin_dev *vin)
+static void rvin_crop_scale_comp_gen2(struct rvin_dev *vin)
 {
 	u32 xs, ys;
 
-	/* Set Start/End Pixel/Line Pre-Clip */
-	rvin_write(vin, vin->crop.left, VNSPPRC_REG);
-	rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG);
-	switch (vin->format.field) {
-	case V4L2_FIELD_INTERLACED:
-	case V4L2_FIELD_INTERLACED_TB:
-	case V4L2_FIELD_INTERLACED_BT:
-		rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG);
-		rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1,
-			   VNELPRC_REG);
-		break;
-	default:
-		rvin_write(vin, vin->crop.top, VNSLPRC_REG);
-		rvin_write(vin, vin->crop.top + vin->crop.height - 1,
-			   VNELPRC_REG);
-		break;
-	}
-
 	/* Set scaling coefficient */
 	ys = 0;
 	if (vin->crop.height != vin->compose.height)
@@ -799,11 +805,6 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
 		break;
 	}
 
-	if (vin->format.pixelformat == V4L2_PIX_FMT_NV16)
-		rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG);
-	else
-		rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG);
-
 	vin_dbg(vin,
 		"Pre-Clip: %ux%u@%u:%u YS: %d XS: %d Post-Clip: %ux%u@%u:%u\n",
 		vin->crop.width, vin->crop.height, vin->crop.left,

drivers/media/platform/rcar-vin/rcar-dma.c void rvin_crop_scale_comp(struct rvin_dev *vin) · line 819

Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-dma.c +5 -0
@@ -811,9 +812,43 @@ void rvin_crop_scale_comp(struct rvin_dev *vin)
 		0, 0);
 }
 
+void rvin_crop_scale_comp(struct rvin_dev *vin)
+{
+	/* Set Start/End Pixel/Line Pre-Clip */
+	rvin_write(vin, vin->crop.left, VNSPPRC_REG);
+	rvin_write(vin, vin->crop.left + vin->crop.width - 1, VNEPPRC_REG);

Please add a blank line here.

Quoted 8 lines
drivers/media/platform/rcar-vin/rcar-dma.c +8 -0
+	switch (vin->format.field) {
+	case V4L2_FIELD_INTERLACED:
+	case V4L2_FIELD_INTERLACED_TB:
+	case V4L2_FIELD_INTERLACED_BT:
+		rvin_write(vin, vin->crop.top / 2, VNSLPRC_REG);
+		rvin_write(vin, (vin->crop.top + vin->crop.height) / 2 - 1,
+			   VNELPRC_REG);
+		break;

drivers/media/platform/rcar-vin/rcar-dma.c void rvin_crop_scale_comp(struct rvin_dev *vin) · line 837

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-dma.c +10 -0
+	default:
+		rvin_write(vin, vin->crop.top, VNSLPRC_REG);
+		rvin_write(vin, vin->crop.top + vin->crop.height - 1,
+			   VNELPRC_REG);
+		break;
+	}
+
+	/* Driver do not support UDS */
+	if (vin->chip != RCAR_GEN3)
+		rvin_crop_scale_comp_gen2(vin);

If you reorder the chip IDs as proposed below, I think

	if (vin->chip <= RCAR_GEN2)
		rvin_crop_scale_comp_gen2(vin);

would be clearer.

drivers/media/platform/rcar-vin/rcar-dma.c void rvin_crop_scale_comp(struct rvin_dev *vin) · line 848

Quoted 11 lines
drivers/media/platform/rcar-vin/rcar-dma.c +8 -0
+
+	if (vin->format.pixelformat == V4L2_PIX_FMT_NV16)
+		rvin_write(vin, ALIGN(vin->format.width, 0x20), VNIS_REG);
+	else
+		rvin_write(vin, ALIGN(vin->format.width, 0x10), VNIS_REG);
+}
+
 void rvin_scale_try(struct rvin_dev *vin, struct v4l2_pix_format *pix,
 		    u32 width, u32 height)
 {
+	/* Driver do not support UDS */

s/do not/does not/

And I'd write it as

/* TODO: Add support for the UDS scaler. */

Quoted 31 lines
drivers/media/platform/rcar-vin/rcar-dma.c +3 -0
+	if (vin->chip == RCAR_GEN3)
+		return;
+
 	/* All VIN channels on Gen2 have scalers */
 	pix->width = width;
 	pix->height = height;
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-v4l2.c index 2307f5b..f4eaef0 100644

drivers/media/platform/rcar-vin/rcar-v4l2.c +3 -1
@@ -25,6 +25,8 @@
 #define RVIN_DEFAULT_FORMAT	V4L2_PIX_FMT_YUYV
 #define RVIN_MAX_WIDTH		2048
 #define RVIN_MAX_HEIGHT		2048
+#define RVIN_MAX_WIDTH_GEN3	4096
+#define RVIN_MAX_HEIGHT_GEN3	4096
 
 /* ------------------------------------------------------------------------
  * Format Conversions
@@ -139,7 +141,7 @@ static int __rvin_try_format(struct rvin_dev *vin,
 			     struct rvin_source_fmt *source)
 {
 	const struct rvin_video_format *info;
-	u32 rwidth, rheight, walign;
+	u32 rwidth, rheight, walign, max_width, max_height;
 
 	/* Requested */
 	rwidth = pix->width;
@@ -173,8 +175,15 @@ static int __rvin_try_format(struct rvin_dev *vin,
 	walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
 

drivers/media/platform/rcar-vin/rcar-v4l2.c static int __rvin_try_format(struct rvin_dev *vin, · line 184

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +7 -2
 	/* Limit to VIN capabilities */
-	v4l_bound_align_image(&pix->width, 2, RVIN_MAX_WIDTH, walign,
-			      &pix->height, 4, RVIN_MAX_HEIGHT, 2, 0);
+	if (vin->chip == RCAR_GEN3) {
+		max_width = RVIN_MAX_WIDTH_GEN3;
+		max_height = RVIN_MAX_HEIGHT_GEN3;
+	} else {
+		max_width = RVIN_MAX_WIDTH;
+		max_height = RVIN_MAX_HEIGHT;
+	}

This is one example where I think a device info structure would help. You could store there the maximum width and height, and remove the condition here.

Again, no need to change this now as long as we don't have too many such checks.

Quoted 10 lines
drivers/media/platform/rcar-vin/rcar-v4l2.c +2 -0
+	v4l_bound_align_image(&pix->width, 2, max_width, walign,
+			      &pix->height, 4, max_height, 2, 0);
 
 	switch (pix->field) {
 	case V4L2_FIELD_NONE:
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-vin.h index 81780f1..b97fa43 100644

drivers/media/platform/rcar-vin/rcar-vin.h line 38

Quoted 7 lines
drivers/media/platform/rcar-vin/rcar-vin.h +1 -0
@@ -32,6 +32,7 @@
 #define HW_BUFFER_MASK 0x7f
 
 enum chip_id {
+	RCAR_GEN3,
 	RCAR_GEN2,
 	RCAR_H1,
 	RCAR_M1,

Nitpicking, it looks weird to me to list them in reverse chronological order, I'd order them as

	RCAR_H1
	RCAR_M1
	RCAR_GEN2
	RCAR_GEN3

Another node

Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

Re: [PATCH 7/8] [media] rcar-vin: enable Gen3

In reply to Niklas Söderlund

Hi Niklas,

Thank you for the patch.

Quoted 26 lines · On Wednesday 25 May 2016 21:10:08 Niklas Söderlund wrote:

From: Niklas Söderlund <[email protected]>

---
 drivers/media/platform/rcar-vin/Kconfig     | 2 +-
 drivers/media/platform/rcar-vin/rcar-core.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/Kconfig index b2ff2d4..ca3ea91 100644

drivers/media/platform/rcar-vin/Kconfig +1 -1
@@ -5,7 +5,7 @@ config VIDEO_RCAR_VIN
 	select VIDEOBUF2_DMA_CONTIG
 	---help---
 	  Support for Renesas R-Car Video Input (VIN) driver.
-	  Supports R-Car Gen2 SoCs.
+	  Supports R-Car Gen2 and Gen3 SoCs.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called rcar-vin.
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-core.c index d901ad0..520690c 100644

drivers/media/platform/rcar-vin/rcar-core.c line 29

Quoted 4 lines
drivers/media/platform/rcar-vin/rcar-core.c +1 -0
@@ -26,6 +26,7 @@
 #include "rcar-vin.h"
 
 static const struct of_device_id rvin_of_id_table[] = {
+	{ .compatible = "renesas,vin-r8a7795", .data = (void *)RCAR_GEN3 },

This isn't needed with patch 8/8. I'd drop this hunk, and merge the previous one into 8/8.

Quoted 3 lines
drivers/media/platform/rcar-vin/rcar-core.c +0 -0
 	{ .compatible = "renesas,vin-r8a7794", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7793", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
Signature · 3 lines
Regards,

Laurent Pinchart
Acked-by on v1 8/8
#17 lore raw

Re: [PATCH 8/8] [media] rcar-vin: add Gen2 and Gen3 fallback compatibility strings

In reply to Niklas Söderlund

Hi Niklas,

Thank you for the patch.

Quoted 6 lines · On Wednesday 25 May 2016 21:10:09 Niklas Söderlund wrote:

From: Niklas Söderlund <[email protected]>

These are present in the soc-camera version of this driver and it's time to add them to this driver as well.

Quoted 17 lines
---
 drivers/media/platform/rcar-vin/rcar-core.c | 2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/media/platform/rcar-vin/rcar-core.c index 520690c..87041db 100644

drivers/media/platform/rcar-vin/rcar-core.c +2 -0
@@ -33,6 +33,8 @@ static const struct of_device_id rvin_of_id_table[] = {
 	{ .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
 	{ .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
 	{ .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
+	{ .compatible = "renesas,rcar-gen3-vin", .data = (void *)RCAR_GEN3 },
+	{ .compatible = "renesas,rcar-gen2-vin", .data = (void *)RCAR_GEN2 },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
Signature · 3 lines
Regards,

Laurent Pinchart