linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] rcar-vin: Add support for outputting NV12
@ 2019-10-14  0:16 Niklas Söderlund
  2019-10-14  0:16 ` [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12 Niklas Söderlund
  2019-10-14  0:16 ` [PATCH v2 2/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
  0 siblings, 2 replies; 6+ messages in thread
From: Niklas Söderlund @ 2019-10-14  0:16 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Hi,

This series adds support for storing captures in NV12 pixel format on
most Gen3 SoCs. It is based on top of latest media-tree and tested on
Gen2 and Gen3 with out any regressions.

Patch 1/2 prepares for the admonition of NV12 support by defining which
Gen3 SoCs supports the output format. While patch 2/2 is the real change
adding the format and register writes to deliver NV12.

Niklas Söderlund (2):
  rcar-vin: Define which hardware supports NV12
  rcar-vin: Add support for outputting NV12

 drivers/media/platform/rcar-vin/rcar-core.c |  6 ++++
 drivers/media/platform/rcar-vin/rcar-dma.c  |  5 ++-
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 39 +++++++++++++++++----
 drivers/media/platform/rcar-vin/rcar-vin.h  |  2 ++
 4 files changed, 45 insertions(+), 7 deletions(-)

-- 
2.23.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12
  2019-10-14  0:16 [PATCH v2 0/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
@ 2019-10-14  0:16 ` Niklas Söderlund
  2019-10-14 22:11   ` Laurent Pinchart
  2019-10-14  0:16 ` [PATCH v2 2/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
  1 sibling, 1 reply; 6+ messages in thread
From: Niklas Söderlund @ 2019-10-14  0:16 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Most but not all Gen3 hardware support outputting NV12, add a flag to
indicate which SoCs do support it.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-core.c | 6 ++++++
 drivers/media/platform/rcar-vin/rcar-vin.h  | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
index 334c62805959cc8a..dcb539711151a3b5 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -983,6 +983,7 @@ static const struct rvin_group_route rcar_info_r8a7795_routes[] = {
 static const struct rvin_info rcar_info_r8a7795 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a7795_routes,
@@ -1077,6 +1078,7 @@ static const struct rvin_group_route rcar_info_r8a7796_routes[] = {
 static const struct rvin_info rcar_info_r8a7796 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a7796_routes,
@@ -1121,6 +1123,7 @@ static const struct rvin_group_route rcar_info_r8a77965_routes[] = {
 static const struct rvin_info rcar_info_r8a77965 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a77965_routes,
@@ -1168,6 +1171,7 @@ static const struct rvin_group_route rcar_info_r8a77980_routes[] = {
 static const struct rvin_info rcar_info_r8a77980 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a77980_routes,
@@ -1184,6 +1188,7 @@ static const struct rvin_group_route rcar_info_r8a77990_routes[] = {
 static const struct rvin_info rcar_info_r8a77990 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a77990_routes,
@@ -1196,6 +1201,7 @@ static const struct rvin_group_route rcar_info_r8a77995_routes[] = {
 static const struct rvin_info rcar_info_r8a77995 = {
 	.model = RCAR_GEN3,
 	.use_mc = true,
+	.nv12 = true,
 	.max_width = 4096,
 	.max_height = 4096,
 	.routes = rcar_info_r8a77995_routes,
diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h
index 86e9bad44484092c..a36b0824f81d171d 100644
--- a/drivers/media/platform/rcar-vin/rcar-vin.h
+++ b/drivers/media/platform/rcar-vin/rcar-vin.h
@@ -126,6 +126,7 @@ struct rvin_group_route {
  * struct rvin_info - Information about the particular VIN implementation
  * @model:		VIN model
  * @use_mc:		use media controller instead of controlling subdevice
+ * @nv12:		support outputing NV12 pixel format
  * @max_width:		max input width the VIN supports
  * @max_height:		max input height the VIN supports
  * @routes:		list of possible routes from the CSI-2 recivers to
@@ -134,6 +135,7 @@ struct rvin_group_route {
 struct rvin_info {
 	enum model_id model;
 	bool use_mc;
+	bool nv12;
 
 	unsigned int max_width;
 	unsigned int max_height;
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] rcar-vin: Add support for outputting NV12
  2019-10-14  0:16 [PATCH v2 0/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
  2019-10-14  0:16 ` [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12 Niklas Söderlund
@ 2019-10-14  0:16 ` Niklas Söderlund
  2019-10-14 22:11   ` Laurent Pinchart
  1 sibling, 1 reply; 6+ messages in thread
From: Niklas Söderlund @ 2019-10-14  0:16 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: linux-renesas-soc, Niklas Söderlund, Simon Horman

Most Gen3 boards can output frames in NV12 format, add support for this
with a runtime check that the running hardware supports it.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
---
 drivers/media/platform/rcar-vin/rcar-dma.c  |  5 ++-
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 39 +++++++++++++++++----
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
index af4f774149f08597..cf9029efeb0450cb 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -118,6 +118,7 @@
 #define VNDMR_ABIT		(1 << 2)
 #define VNDMR_DTMD_YCSEP	(1 << 1)
 #define VNDMR_DTMD_ARGB		(1 << 0)
+#define VNDMR_DTMD_YCSEP_420	(3 << 0)
 
 /* Video n Data Mode Register 2 bits */
 #define VNDMR2_VPS		(1 << 30)
@@ -701,11 +702,13 @@ static int rvin_setup(struct rvin_dev *vin)
 	 * Output format
 	 */
 	switch (vin->format.pixelformat) {
+	case V4L2_PIX_FMT_NV12:
 	case V4L2_PIX_FMT_NV16:
 		rvin_write(vin,
 			   ALIGN(vin->format.bytesperline * vin->format.height,
 				 0x80), VNUVAOF_REG);
-		dmr = VNDMR_DTMD_YCSEP;
+		dmr = vin->format.pixelformat == V4L2_PIX_FMT_NV12 ?
+			VNDMR_DTMD_YCSEP_420 : VNDMR_DTMD_YCSEP;
 		output_is_yuv = true;
 		break;
 	case V4L2_PIX_FMT_YUYV:
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 13b7cd5d2e40415a..9e2e63ffcc47acad 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -30,6 +30,10 @@
  */
 
 static const struct rvin_video_format rvin_formats[] = {
+	{
+		.fourcc			= V4L2_PIX_FMT_NV12,
+		.bpp			= 1,
+	},
 	{
 		.fourcc			= V4L2_PIX_FMT_NV16,
 		.bpp			= 1,
@@ -72,6 +76,9 @@ const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin,
 	if (vin->info->model == RCAR_M1 && pixelformat == V4L2_PIX_FMT_XBGR32)
 		return NULL;
 
+	if (pixelformat == V4L2_PIX_FMT_NV12 && !vin->info->nv12)
+		return NULL;
+
 	for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
 		if (rvin_formats[i].fourcc == pixelformat)
 			return rvin_formats + i;
@@ -90,17 +97,29 @@ static u32 rvin_format_bytesperline(struct rvin_dev *vin,
 	if (WARN_ON(!fmt))
 		return -EINVAL;
 
-	align = pix->pixelformat == V4L2_PIX_FMT_NV16 ? 0x20 : 0x10;
+	switch (pix->pixelformat) {
+	case V4L2_PIX_FMT_NV12:
+	case V4L2_PIX_FMT_NV16:
+		align = 0x20;
+		break;
+	default:
+		align = 0x10;
+		break;
+	}
 
 	return ALIGN(pix->width, align) * fmt->bpp;
 }
 
 static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
 {
-	if (pix->pixelformat == V4L2_PIX_FMT_NV16)
+	switch (pix->pixelformat) {
+	case V4L2_PIX_FMT_NV12:
+		return pix->bytesperline * pix->height * 3 / 2;
+	case V4L2_PIX_FMT_NV16:
 		return pix->bytesperline * pix->height * 2;
-
-	return pix->bytesperline * pix->height;
+	default:
+		return pix->bytesperline * pix->height;
+	}
 }
 
 static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
@@ -124,8 +143,16 @@ static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
 		break;
 	}
 
-	/* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
-	walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
+	/* HW limit width to a multiple of 32 (2^5) for NV12/16 else 2 (2^1) */
+	switch (vin->format.pixelformat) {
+	case V4L2_PIX_FMT_NV12:
+	case V4L2_PIX_FMT_NV16:
+		walign = 5;
+		break;
+	default:
+		walign = 1;
+		break;
+	}
 
 	/* Limit to VIN capabilities */
 	v4l_bound_align_image(&pix->width, 2, vin->info->max_width, walign,
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] rcar-vin: Add support for outputting NV12
  2019-10-14  0:16 ` [PATCH v2 2/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
@ 2019-10-14 22:11   ` Laurent Pinchart
  2019-10-17  8:48     ` Jacopo Mondi
  0 siblings, 1 reply; 6+ messages in thread
From: Laurent Pinchart @ 2019-10-14 22:11 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc, Simon Horman

Hi Niklas,

Thank you for the patch.

On Mon, Oct 14, 2019 at 02:16:15AM +0200, Niklas Söderlund wrote:
> Most Gen3 boards can output frames in NV12 format, add support for this
> with a runtime check that the running hardware supports it.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
> ---
>  drivers/media/platform/rcar-vin/rcar-dma.c  |  5 ++-
>  drivers/media/platform/rcar-vin/rcar-v4l2.c | 39 +++++++++++++++++----
>  2 files changed, 37 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> index af4f774149f08597..cf9029efeb0450cb 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -118,6 +118,7 @@
>  #define VNDMR_ABIT		(1 << 2)
>  #define VNDMR_DTMD_YCSEP	(1 << 1)

While at it, I would define this as (2 << 0).

>  #define VNDMR_DTMD_ARGB		(1 << 0)
> +#define VNDMR_DTMD_YCSEP_420	(3 << 0)
>  
>  /* Video n Data Mode Register 2 bits */
>  #define VNDMR2_VPS		(1 << 30)
> @@ -701,11 +702,13 @@ static int rvin_setup(struct rvin_dev *vin)
>  	 * Output format
>  	 */
>  	switch (vin->format.pixelformat) {
> +	case V4L2_PIX_FMT_NV12:
>  	case V4L2_PIX_FMT_NV16:
>  		rvin_write(vin,
>  			   ALIGN(vin->format.bytesperline * vin->format.height,
>  				 0x80), VNUVAOF_REG);
> -		dmr = VNDMR_DTMD_YCSEP;
> +		dmr = vin->format.pixelformat == V4L2_PIX_FMT_NV12 ?
> +			VNDMR_DTMD_YCSEP_420 : VNDMR_DTMD_YCSEP;

According to the datasheet, VNDMR_DTMD_YCSEP_420 is only valid for some
of the channels (see footnote of the VnDMR register documentation).

>  		output_is_yuv = true;
>  		break;
>  	case V4L2_PIX_FMT_YUYV:
> diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> index 13b7cd5d2e40415a..9e2e63ffcc47acad 100644
> --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> @@ -30,6 +30,10 @@
>   */
>  
>  static const struct rvin_video_format rvin_formats[] = {
> +	{
> +		.fourcc			= V4L2_PIX_FMT_NV12,
> +		.bpp			= 1,
> +	},
>  	{
>  		.fourcc			= V4L2_PIX_FMT_NV16,
>  		.bpp			= 1,
> @@ -72,6 +76,9 @@ const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin,
>  	if (vin->info->model == RCAR_M1 && pixelformat == V4L2_PIX_FMT_XBGR32)
>  		return NULL;
>  
> +	if (pixelformat == V4L2_PIX_FMT_NV12 && !vin->info->nv12)
> +		return NULL;
> +
>  	for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
>  		if (rvin_formats[i].fourcc == pixelformat)
>  			return rvin_formats + i;
> @@ -90,17 +97,29 @@ static u32 rvin_format_bytesperline(struct rvin_dev *vin,
>  	if (WARN_ON(!fmt))
>  		return -EINVAL;
>  
> -	align = pix->pixelformat == V4L2_PIX_FMT_NV16 ? 0x20 : 0x10;
> +	switch (pix->pixelformat) {
> +	case V4L2_PIX_FMT_NV12:
> +	case V4L2_PIX_FMT_NV16:
> +		align = 0x20;
> +		break;
> +	default:
> +		align = 0x10;
> +		break;
> +	}
>  
>  	return ALIGN(pix->width, align) * fmt->bpp;
>  }
>  
>  static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
>  {
> -	if (pix->pixelformat == V4L2_PIX_FMT_NV16)
> +	switch (pix->pixelformat) {
> +	case V4L2_PIX_FMT_NV12:
> +		return pix->bytesperline * pix->height * 3 / 2;
> +	case V4L2_PIX_FMT_NV16:
>  		return pix->bytesperline * pix->height * 2;
> -
> -	return pix->bytesperline * pix->height;
> +	default:
> +		return pix->bytesperline * pix->height;
> +	}
>  }
>  
>  static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
> @@ -124,8 +143,16 @@ static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
>  		break;
>  	}
>  
> -	/* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
> -	walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
> +	/* HW limit width to a multiple of 32 (2^5) for NV12/16 else 2 (2^1) */
> +	switch (vin->format.pixelformat) {
> +	case V4L2_PIX_FMT_NV12:
> +	case V4L2_PIX_FMT_NV16:
> +		walign = 5;
> +		break;
> +	default:
> +		walign = 1;
> +		break;
> +	}
>  
>  	/* Limit to VIN capabilities */
>  	v4l_bound_align_image(&pix->width, 2, vin->info->max_width, walign,

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12
  2019-10-14  0:16 ` [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12 Niklas Söderlund
@ 2019-10-14 22:11   ` Laurent Pinchart
  0 siblings, 0 replies; 6+ messages in thread
From: Laurent Pinchart @ 2019-10-14 22:11 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

Thank you for the patch.

On Mon, Oct 14, 2019 at 02:16:14AM +0200, Niklas Söderlund wrote:
> Most but not all Gen3 hardware support outputting NV12, add a flag to
> indicate which SoCs do support it.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/platform/rcar-vin/rcar-core.c | 6 ++++++
>  drivers/media/platform/rcar-vin/rcar-vin.h  | 2 ++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
> index 334c62805959cc8a..dcb539711151a3b5 100644
> --- a/drivers/media/platform/rcar-vin/rcar-core.c
> +++ b/drivers/media/platform/rcar-vin/rcar-core.c
> @@ -983,6 +983,7 @@ static const struct rvin_group_route rcar_info_r8a7795_routes[] = {
>  static const struct rvin_info rcar_info_r8a7795 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a7795_routes,
> @@ -1077,6 +1078,7 @@ static const struct rvin_group_route rcar_info_r8a7796_routes[] = {
>  static const struct rvin_info rcar_info_r8a7796 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a7796_routes,
> @@ -1121,6 +1123,7 @@ static const struct rvin_group_route rcar_info_r8a77965_routes[] = {
>  static const struct rvin_info rcar_info_r8a77965 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a77965_routes,
> @@ -1168,6 +1171,7 @@ static const struct rvin_group_route rcar_info_r8a77980_routes[] = {
>  static const struct rvin_info rcar_info_r8a77980 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a77980_routes,
> @@ -1184,6 +1188,7 @@ static const struct rvin_group_route rcar_info_r8a77990_routes[] = {
>  static const struct rvin_info rcar_info_r8a77990 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a77990_routes,
> @@ -1196,6 +1201,7 @@ static const struct rvin_group_route rcar_info_r8a77995_routes[] = {
>  static const struct rvin_info rcar_info_r8a77995 = {
>  	.model = RCAR_GEN3,
>  	.use_mc = true,
> +	.nv12 = true,
>  	.max_width = 4096,
>  	.max_height = 4096,
>  	.routes = rcar_info_r8a77995_routes,
> diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h
> index 86e9bad44484092c..a36b0824f81d171d 100644
> --- a/drivers/media/platform/rcar-vin/rcar-vin.h
> +++ b/drivers/media/platform/rcar-vin/rcar-vin.h
> @@ -126,6 +126,7 @@ struct rvin_group_route {
>   * struct rvin_info - Information about the particular VIN implementation
>   * @model:		VIN model
>   * @use_mc:		use media controller instead of controlling subdevice
> + * @nv12:		support outputing NV12 pixel format
>   * @max_width:		max input width the VIN supports
>   * @max_height:		max input height the VIN supports
>   * @routes:		list of possible routes from the CSI-2 recivers to
> @@ -134,6 +135,7 @@ struct rvin_group_route {
>  struct rvin_info {
>  	enum model_id model;
>  	bool use_mc;
> +	bool nv12;
>  
>  	unsigned int max_width;
>  	unsigned int max_height;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] rcar-vin: Add support for outputting NV12
  2019-10-14 22:11   ` Laurent Pinchart
@ 2019-10-17  8:48     ` Jacopo Mondi
  0 siblings, 0 replies; 6+ messages in thread
From: Jacopo Mondi @ 2019-10-17  8:48 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Niklas Söderlund, linux-media, linux-renesas-soc, Simon Horman

[-- Attachment #1: Type: text/plain, Size: 5206 bytes --]

Hi Niklas, Laurent,

On Tue, Oct 15, 2019 at 01:11:07AM +0300, Laurent Pinchart wrote:
> Hi Niklas,
>
> Thank you for the patch.
>
> On Mon, Oct 14, 2019 at 02:16:15AM +0200, Niklas Söderlund wrote:
> > Most Gen3 boards can output frames in NV12 format, add support for this
> > with a runtime check that the running hardware supports it.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> > Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
> > ---
> >  drivers/media/platform/rcar-vin/rcar-dma.c  |  5 ++-
> >  drivers/media/platform/rcar-vin/rcar-v4l2.c | 39 +++++++++++++++++----
> >  2 files changed, 37 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> > index af4f774149f08597..cf9029efeb0450cb 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> > @@ -118,6 +118,7 @@
> >  #define VNDMR_ABIT		(1 << 2)
> >  #define VNDMR_DTMD_YCSEP	(1 << 1)
>
> While at it, I would define this as (2 << 0).
>
> >  #define VNDMR_DTMD_ARGB		(1 << 0)
> > +#define VNDMR_DTMD_YCSEP_420	(3 << 0)
> >
> >  /* Video n Data Mode Register 2 bits */
> >  #define VNDMR2_VPS		(1 << 30)
> > @@ -701,11 +702,13 @@ static int rvin_setup(struct rvin_dev *vin)
> >  	 * Output format
> >  	 */
> >  	switch (vin->format.pixelformat) {
> > +	case V4L2_PIX_FMT_NV12:
> >  	case V4L2_PIX_FMT_NV16:
> >  		rvin_write(vin,
> >  			   ALIGN(vin->format.bytesperline * vin->format.height,
> >  				 0x80), VNUVAOF_REG);
> > -		dmr = VNDMR_DTMD_YCSEP;
> > +		dmr = vin->format.pixelformat == V4L2_PIX_FMT_NV12 ?
> > +			VNDMR_DTMD_YCSEP_420 : VNDMR_DTMD_YCSEP;
>
> According to the datasheet, VNDMR_DTMD_YCSEP_420 is only valid for some
> of the channels (see footnote of the VnDMR register documentation).
>

It took me a while to interpret this footnote:
3. Do not make this setting for video channels 2, 3, 6, 7, 10(V3H), 11(V3H), 14(V3H) and 15(V3H).

But if the note in table 26.15 is considered too:
Setting the DTMD[1:0] bits to B'11 is only allowed for video channels 0, 1, 4, and 5.

Can we refuse to set the fromat here or is it too late and should be
catched at rvin_format_from_pixel() time (where, if I'm not mistaken,
we have not channel id information available though).

Thanks
   j

> >  		output_is_yuv = true;
> >  		break;
> >  	case V4L2_PIX_FMT_YUYV:
> > diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > index 13b7cd5d2e40415a..9e2e63ffcc47acad 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
> > @@ -30,6 +30,10 @@
> >   */
> >
> >  static const struct rvin_video_format rvin_formats[] = {
> > +	{
> > +		.fourcc			= V4L2_PIX_FMT_NV12,
> > +		.bpp			= 1,
> > +	},
> >  	{
> >  		.fourcc			= V4L2_PIX_FMT_NV16,
> >  		.bpp			= 1,
> > @@ -72,6 +76,9 @@ const struct rvin_video_format *rvin_format_from_pixel(struct rvin_dev *vin,
> >  	if (vin->info->model == RCAR_M1 && pixelformat == V4L2_PIX_FMT_XBGR32)
> >  		return NULL;
> >
> > +	if (pixelformat == V4L2_PIX_FMT_NV12 && !vin->info->nv12)
> > +		return NULL;
> > +
> >  	for (i = 0; i < ARRAY_SIZE(rvin_formats); i++)
> >  		if (rvin_formats[i].fourcc == pixelformat)
> >  			return rvin_formats + i;
> > @@ -90,17 +97,29 @@ static u32 rvin_format_bytesperline(struct rvin_dev *vin,
> >  	if (WARN_ON(!fmt))
> >  		return -EINVAL;
> >
> > -	align = pix->pixelformat == V4L2_PIX_FMT_NV16 ? 0x20 : 0x10;
> > +	switch (pix->pixelformat) {
> > +	case V4L2_PIX_FMT_NV12:
> > +	case V4L2_PIX_FMT_NV16:
> > +		align = 0x20;
> > +		break;
> > +	default:
> > +		align = 0x10;
> > +		break;
> > +	}
> >
> >  	return ALIGN(pix->width, align) * fmt->bpp;
> >  }
> >
> >  static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
> >  {
> > -	if (pix->pixelformat == V4L2_PIX_FMT_NV16)
> > +	switch (pix->pixelformat) {
> > +	case V4L2_PIX_FMT_NV12:
> > +		return pix->bytesperline * pix->height * 3 / 2;
> > +	case V4L2_PIX_FMT_NV16:
> >  		return pix->bytesperline * pix->height * 2;
> > -
> > -	return pix->bytesperline * pix->height;
> > +	default:
> > +		return pix->bytesperline * pix->height;
> > +	}
> >  }
> >
> >  static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
> > @@ -124,8 +143,16 @@ static void rvin_format_align(struct rvin_dev *vin, struct v4l2_pix_format *pix)
> >  		break;
> >  	}
> >
> > -	/* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
> > -	walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
> > +	/* HW limit width to a multiple of 32 (2^5) for NV12/16 else 2 (2^1) */
> > +	switch (vin->format.pixelformat) {
> > +	case V4L2_PIX_FMT_NV12:
> > +	case V4L2_PIX_FMT_NV16:
> > +		walign = 5;
> > +		break;
> > +	default:
> > +		walign = 1;
> > +		break;
> > +	}
> >
> >  	/* Limit to VIN capabilities */
> >  	v4l_bound_align_image(&pix->width, 2, vin->info->max_width, walign,
>
> --
> Regards,
>
> Laurent Pinchart

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-17  8:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14  0:16 [PATCH v2 0/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
2019-10-14  0:16 ` [PATCH v2 1/2] rcar-vin: Define which hardware supports NV12 Niklas Söderlund
2019-10-14 22:11   ` Laurent Pinchart
2019-10-14  0:16 ` [PATCH v2 2/2] rcar-vin: Add support for outputting NV12 Niklas Söderlund
2019-10-14 22:11   ` Laurent Pinchart
2019-10-17  8:48     ` Jacopo Mondi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).