diff mbox series

[7/7] media: rkisp1: Implement s_fmt/try_fmt

Message ID 20240621145406.119088-8-jacopo.mondi@ideasonboard.com
State Superseded
Headers show
Series media: rkisp1: Implement support for extensible parameters | expand

Commit Message

Jacopo Mondi June 21, 2024, 2:54 p.m. UTC
Implement in the rkisp1 driver support for the s_fmt and try_fmt
operation to allow userspace to select between the extensible
and the fixed parameters formats.

Implement enum_mbus_code to enumerate the fixed and the extensible
formats and disallow changing the data format while the queue is busy.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 .../platform/rockchip/rkisp1/rkisp1-params.c  | 58 ++++++++++++++++---
 1 file changed, 50 insertions(+), 8 deletions(-)

Comments

Laurent Pinchart June 29, 2024, 2:39 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Fri, Jun 21, 2024 at 04:54:05PM +0200, Jacopo Mondi wrote:
> Implement in the rkisp1 driver support for the s_fmt and try_fmt
> operation to allow userspace to select between the extensible
> and the fixed parameters formats.
> 
> Implement enum_mbus_code to enumerate the fixed and the extensible
> formats and disallow changing the data format while the queue is busy.
> 
> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

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

> ---
>  .../platform/rockchip/rkisp1/rkisp1-params.c  | 58 ++++++++++++++++---
>  1 file changed, 50 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> index f3ea70c7e0c1..904164bd201a 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
> @@ -54,6 +54,17 @@ static const struct v4l2_meta_format rkisp1_params_formats[] = {
>  	},
>  };
>  
> +static const struct v4l2_meta_format *
> +rkisp1_params_get_format_info(u32 dataformat)
> +{
> +	for (unsigned int i = 0; i < ARRAY_SIZE(rkisp1_params_formats); i++) {
> +		if (rkisp1_params_formats[i].dataformat == dataformat)
> +			return &rkisp1_params_formats[i];
> +	}
> +
> +	return &rkisp1_params_formats[RKISP1_PARAMS_FIXED];
> +}
> +
>  static inline void
>  rkisp1_param_set_bits(struct rkisp1_params *params, u32 reg, u32 bit_mask)
>  {
> @@ -2222,12 +2233,12 @@ static int rkisp1_params_enum_fmt_meta_out(struct file *file, void *priv,
>  					   struct v4l2_fmtdesc *f)
>  {
>  	struct video_device *video = video_devdata(file);
> -	struct rkisp1_params *params = video_get_drvdata(video);
>  
> -	if (f->index > 0 || f->type != video->queue->type)
> +	if (f->index >= ARRAY_SIZE(rkisp1_params_formats) ||
> +	    f->type != video->queue->type)
>  		return -EINVAL;
>  
> -	f->pixelformat = params->metafmt->dataformat;
> +	f->pixelformat = rkisp1_params_formats[f->index].dataformat;
>  
>  	return 0;
>  }
> @@ -2242,9 +2253,40 @@ static int rkisp1_params_g_fmt_meta_out(struct file *file, void *fh,
>  	if (f->type != video->queue->type)
>  		return -EINVAL;
>  
> -	memset(meta, 0, sizeof(*meta));
> -	meta->dataformat = params->metafmt->dataformat;
> -	meta->buffersize = params->metafmt->buffersize;
> +	*meta = *params->metafmt;
> +
> +	return 0;
> +}
> +
> +static int rkisp1_params_try_fmt_meta_out(struct file *file, void *fh,
> +					  struct v4l2_format *f)
> +{
> +	struct video_device *video = video_devdata(file);
> +	struct v4l2_meta_format *meta = &f->fmt.meta;
> +
> +	if (f->type != video->queue->type)
> +		return -EINVAL;
> +
> +	*meta = *rkisp1_params_get_format_info(meta->dataformat);
> +
> +	return 0;
> +}
> +
> +static int rkisp1_params_s_fmt_meta_out(struct file *file, void *fh,
> +					struct v4l2_format *f)
> +{
> +	struct video_device *video = video_devdata(file);
> +	struct rkisp1_params *params = video_get_drvdata(video);
> +	struct v4l2_meta_format *meta = &f->fmt.meta;
> +
> +	if (f->type != video->queue->type)
> +		return -EINVAL;
> +
> +	if (vb2_is_busy(video->queue))
> +		return -EBUSY;
> +
> +	params->metafmt = rkisp1_params_get_format_info(meta->dataformat);
> +	*meta = *params->metafmt;
>  
>  	return 0;
>  }
> @@ -2274,8 +2316,8 @@ static const struct v4l2_ioctl_ops rkisp1_params_ioctl = {
>  	.vidioc_streamoff = vb2_ioctl_streamoff,
>  	.vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
>  	.vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> -	.vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> -	.vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
> +	.vidioc_s_fmt_meta_out = rkisp1_params_s_fmt_meta_out,
> +	.vidioc_try_fmt_meta_out = rkisp1_params_try_fmt_meta_out,
>  	.vidioc_querycap = rkisp1_params_querycap,
>  	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
>  	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
diff mbox series

Patch

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
index f3ea70c7e0c1..904164bd201a 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c
@@ -54,6 +54,17 @@  static const struct v4l2_meta_format rkisp1_params_formats[] = {
 	},
 };
 
+static const struct v4l2_meta_format *
+rkisp1_params_get_format_info(u32 dataformat)
+{
+	for (unsigned int i = 0; i < ARRAY_SIZE(rkisp1_params_formats); i++) {
+		if (rkisp1_params_formats[i].dataformat == dataformat)
+			return &rkisp1_params_formats[i];
+	}
+
+	return &rkisp1_params_formats[RKISP1_PARAMS_FIXED];
+}
+
 static inline void
 rkisp1_param_set_bits(struct rkisp1_params *params, u32 reg, u32 bit_mask)
 {
@@ -2222,12 +2233,12 @@  static int rkisp1_params_enum_fmt_meta_out(struct file *file, void *priv,
 					   struct v4l2_fmtdesc *f)
 {
 	struct video_device *video = video_devdata(file);
-	struct rkisp1_params *params = video_get_drvdata(video);
 
-	if (f->index > 0 || f->type != video->queue->type)
+	if (f->index >= ARRAY_SIZE(rkisp1_params_formats) ||
+	    f->type != video->queue->type)
 		return -EINVAL;
 
-	f->pixelformat = params->metafmt->dataformat;
+	f->pixelformat = rkisp1_params_formats[f->index].dataformat;
 
 	return 0;
 }
@@ -2242,9 +2253,40 @@  static int rkisp1_params_g_fmt_meta_out(struct file *file, void *fh,
 	if (f->type != video->queue->type)
 		return -EINVAL;
 
-	memset(meta, 0, sizeof(*meta));
-	meta->dataformat = params->metafmt->dataformat;
-	meta->buffersize = params->metafmt->buffersize;
+	*meta = *params->metafmt;
+
+	return 0;
+}
+
+static int rkisp1_params_try_fmt_meta_out(struct file *file, void *fh,
+					  struct v4l2_format *f)
+{
+	struct video_device *video = video_devdata(file);
+	struct v4l2_meta_format *meta = &f->fmt.meta;
+
+	if (f->type != video->queue->type)
+		return -EINVAL;
+
+	*meta = *rkisp1_params_get_format_info(meta->dataformat);
+
+	return 0;
+}
+
+static int rkisp1_params_s_fmt_meta_out(struct file *file, void *fh,
+					struct v4l2_format *f)
+{
+	struct video_device *video = video_devdata(file);
+	struct rkisp1_params *params = video_get_drvdata(video);
+	struct v4l2_meta_format *meta = &f->fmt.meta;
+
+	if (f->type != video->queue->type)
+		return -EINVAL;
+
+	if (vb2_is_busy(video->queue))
+		return -EBUSY;
+
+	params->metafmt = rkisp1_params_get_format_info(meta->dataformat);
+	*meta = *params->metafmt;
 
 	return 0;
 }
@@ -2274,8 +2316,8 @@  static const struct v4l2_ioctl_ops rkisp1_params_ioctl = {
 	.vidioc_streamoff = vb2_ioctl_streamoff,
 	.vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out,
 	.vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
-	.vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
-	.vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out,
+	.vidioc_s_fmt_meta_out = rkisp1_params_s_fmt_meta_out,
+	.vidioc_try_fmt_meta_out = rkisp1_params_try_fmt_meta_out,
 	.vidioc_querycap = rkisp1_params_querycap,
 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,