[v2,3/3] media: rkisp1: Implement ENUM_FRAMESIZES

Message ID 20221117084217.3892680-4-paul.elder@ideasonboard.com
State New
Headers
Series media: rkisp1: Miscellaneous improvements |

Commit Message

Paul Elder Nov. 17, 2022, 8:42 a.m. UTC
  Implement VIDIOC_ENUM_FRAMESIZES for the rkisp1 capture devices.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 .../platform/rockchip/rkisp1/rkisp1-capture.c | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
  

Comments

Dafna Hirschfeld Nov. 19, 2022, 10:57 a.m. UTC | #1
On 17.11.2022 17:42, Paul Elder wrote:
>Implement VIDIOC_ENUM_FRAMESIZES for the rkisp1 capture devices.
>
>Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
>Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Dafna Hirschfeld <dafna@fastmail.com>

>---
> .../platform/rockchip/rkisp1/rkisp1-capture.c | 30 +++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
>diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
>index 91e685fdbbe9..03c2922bfbed 100644
>--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
>+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
>@@ -1236,6 +1236,35 @@ static int rkisp1_enum_fmt_vid_cap_mplane(struct file *file, void *priv,
> 	return -EINVAL;
> }
>
>+static int rkisp1_enum_framesizes(struct file *file, void *fh,
>+				  struct v4l2_frmsizeenum *fsize)
>+{
>+	static const unsigned int max_widths[] = {
>+		RKISP1_RSZ_MP_SRC_MAX_WIDTH,
>+		RKISP1_RSZ_SP_SRC_MAX_WIDTH,
>+	};
>+	static const unsigned int max_heights[] = {
>+		RKISP1_RSZ_MP_SRC_MAX_HEIGHT,
>+		RKISP1_RSZ_SP_SRC_MAX_HEIGHT,
>+	};
>+	struct rkisp1_capture *cap = video_drvdata(file);
>+
>+	if (fsize->index != 0)
>+		return -EINVAL;
>+
>+	fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
>+
>+	fsize->stepwise.min_width = RKISP1_RSZ_SRC_MIN_WIDTH;
>+	fsize->stepwise.max_width = max_widths[cap->id];
>+	fsize->stepwise.step_width = 2;
>+
>+	fsize->stepwise.min_height = RKISP1_RSZ_SRC_MIN_HEIGHT;
>+	fsize->stepwise.max_height = max_heights[cap->id];
>+	fsize->stepwise.step_height = 2;
>+
>+	return 0;
>+}
>+
> static int rkisp1_s_fmt_vid_cap_mplane(struct file *file,
> 				       void *priv, struct v4l2_format *f)
> {
>@@ -1285,6 +1314,7 @@ static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = {
> 	.vidioc_s_fmt_vid_cap_mplane = rkisp1_s_fmt_vid_cap_mplane,
> 	.vidioc_g_fmt_vid_cap_mplane = rkisp1_g_fmt_vid_cap_mplane,
> 	.vidioc_enum_fmt_vid_cap = rkisp1_enum_fmt_vid_cap_mplane,
>+	.vidioc_enum_framesizes = rkisp1_enum_framesizes,
> 	.vidioc_querycap = rkisp1_querycap,
> 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
> 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
>-- 
>2.35.1
>
  

Patch

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
index 91e685fdbbe9..03c2922bfbed 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
@@ -1236,6 +1236,35 @@  static int rkisp1_enum_fmt_vid_cap_mplane(struct file *file, void *priv,
 	return -EINVAL;
 }
 
+static int rkisp1_enum_framesizes(struct file *file, void *fh,
+				  struct v4l2_frmsizeenum *fsize)
+{
+	static const unsigned int max_widths[] = {
+		RKISP1_RSZ_MP_SRC_MAX_WIDTH,
+		RKISP1_RSZ_SP_SRC_MAX_WIDTH,
+	};
+	static const unsigned int max_heights[] = {
+		RKISP1_RSZ_MP_SRC_MAX_HEIGHT,
+		RKISP1_RSZ_SP_SRC_MAX_HEIGHT,
+	};
+	struct rkisp1_capture *cap = video_drvdata(file);
+
+	if (fsize->index != 0)
+		return -EINVAL;
+
+	fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+
+	fsize->stepwise.min_width = RKISP1_RSZ_SRC_MIN_WIDTH;
+	fsize->stepwise.max_width = max_widths[cap->id];
+	fsize->stepwise.step_width = 2;
+
+	fsize->stepwise.min_height = RKISP1_RSZ_SRC_MIN_HEIGHT;
+	fsize->stepwise.max_height = max_heights[cap->id];
+	fsize->stepwise.step_height = 2;
+
+	return 0;
+}
+
 static int rkisp1_s_fmt_vid_cap_mplane(struct file *file,
 				       void *priv, struct v4l2_format *f)
 {
@@ -1285,6 +1314,7 @@  static const struct v4l2_ioctl_ops rkisp1_v4l2_ioctl_ops = {
 	.vidioc_s_fmt_vid_cap_mplane = rkisp1_s_fmt_vid_cap_mplane,
 	.vidioc_g_fmt_vid_cap_mplane = rkisp1_g_fmt_vid_cap_mplane,
 	.vidioc_enum_fmt_vid_cap = rkisp1_enum_fmt_vid_cap_mplane,
+	.vidioc_enum_framesizes = rkisp1_enum_framesizes,
 	.vidioc_querycap = rkisp1_querycap,
 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,