linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Todor Tomov <todor.tomov@linaro.org>
To: mchehab@kernel.org, hans.verkuil@cisco.com,
	s.nawrocki@samsung.com, sakari.ailus@iki.fi,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org
Cc: Todor Tomov <todor.tomov@linaro.org>
Subject: [PATCH v4 17/21] camss: vfe: Add interface for cropping
Date: Tue,  8 Aug 2017 16:30:14 +0300	[thread overview]
Message-ID: <1502199018-28250-18-git-send-email-todor.tomov@linaro.org> (raw)
In-Reply-To: <1502199018-28250-1-git-send-email-todor.tomov@linaro.org>

Extend selection ioctls to handle cropping configuration.

Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
---
 drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 191 ++++++++++++++++-----
 drivers/media/platform/qcom/camss-8x16/camss-vfe.h |   1 +
 2 files changed, 150 insertions(+), 42 deletions(-)

diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
index cc1fc68..680e059 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c
@@ -1994,6 +1994,26 @@ __vfe_get_compose(struct vfe_line *line,
 }
 
 /*
+ * __vfe_get_crop - Get pointer to crop selection structure
+ * @line: VFE line
+ * @cfg: V4L2 subdev pad configuration
+ * @which: TRY or ACTIVE format
+ *
+ * Return pointer to TRY or ACTIVE crop rectangle structure
+ */
+static struct v4l2_rect *
+__vfe_get_crop(struct vfe_line *line,
+	       struct v4l2_subdev_pad_config *cfg,
+	       enum v4l2_subdev_format_whence which)
+{
+	if (which == V4L2_SUBDEV_FORMAT_TRY)
+		return v4l2_subdev_get_try_crop(&line->subdev, cfg,
+						MSM_VFE_PAD_SRC);
+
+	return &line->crop;
+}
+
+/*
  * vfe_try_format - Handle try format by pad subdev method
  * @line: VFE line
  * @cfg: V4L2 subdev pad configuration
@@ -2041,7 +2061,7 @@ static void vfe_try_format(struct vfe_line *line,
 		if (line->id == VFE_LINE_PIX) {
 			struct v4l2_rect *rect;
 
-			rect = __vfe_get_compose(line, cfg, which);
+			rect = __vfe_get_crop(line, cfg, which);
 
 			fmt->width = rect->width;
 			fmt->height = rect->height;
@@ -2121,6 +2141,49 @@ static void vfe_try_compose(struct vfe_line *line,
 }
 
 /*
+ * vfe_try_crop - Handle try crop selection by pad subdev method
+ * @line: VFE line
+ * @cfg: V4L2 subdev pad configuration
+ * @rect: pointer to v4l2 rect structure
+ * @which: wanted subdev format
+ */
+static void vfe_try_crop(struct vfe_line *line,
+			 struct v4l2_subdev_pad_config *cfg,
+			 struct v4l2_rect *rect,
+			 enum v4l2_subdev_format_whence which)
+{
+	struct v4l2_rect *compose;
+
+	compose = __vfe_get_compose(line, cfg, which);
+
+	if (rect->width > compose->width)
+		rect->width = compose->width;
+
+	if (rect->width + rect->left > compose->width)
+		rect->left = compose->width - rect->width;
+
+	if (rect->height > compose->height)
+		rect->height = compose->height;
+
+	if (rect->height + rect->top > compose->height)
+		rect->top = compose->height - rect->height;
+
+	/* wm in line based mode writes multiple of 16 horizontally */
+	rect->left += (rect->width & 0xf) >> 1;
+	rect->width &= ~0xf;
+
+	if (rect->width < 16) {
+		rect->left = 0;
+		rect->width = 16;
+	}
+
+	if (rect->height < 4) {
+		rect->top = 0;
+		rect->height = 4;
+	}
+}
+
+/*
  * vfe_enum_mbus_code - Handle pixel format enumeration
  * @sd: VFE V4L2 subdevice
  * @cfg: V4L2 subdev pad configuration
@@ -2284,34 +2347,58 @@ static int vfe_get_selection(struct v4l2_subdev *sd,
 {
 	struct vfe_line *line = v4l2_get_subdevdata(sd);
 	struct v4l2_subdev_format fmt = { 0 };
-	struct v4l2_rect *compose;
+	struct v4l2_rect *rect;
 	int ret;
 
-	if (line->id != VFE_LINE_PIX || sel->pad != MSM_VFE_PAD_SINK)
+	if (line->id != VFE_LINE_PIX)
 		return -EINVAL;
 
-	switch (sel->target) {
-	case V4L2_SEL_TGT_COMPOSE_BOUNDS:
-		fmt.pad = sel->pad;
-		fmt.which = sel->which;
-		ret = vfe_get_format(sd, cfg, &fmt);
-		if (ret < 0)
-			return ret;
-		sel->r.left = 0;
-		sel->r.top = 0;
-		sel->r.width = fmt.format.width;
-		sel->r.height = fmt.format.height;
-		break;
-	case V4L2_SEL_TGT_COMPOSE:
-		compose = __vfe_get_compose(line, cfg, sel->which);
-		if (compose == NULL)
+	if (sel->pad == MSM_VFE_PAD_SINK)
+		switch (sel->target) {
+		case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+			fmt.pad = sel->pad;
+			fmt.which = sel->which;
+			ret = vfe_get_format(sd, cfg, &fmt);
+			if (ret < 0)
+				return ret;
+
+			sel->r.left = 0;
+			sel->r.top = 0;
+			sel->r.width = fmt.format.width;
+			sel->r.height = fmt.format.height;
+			break;
+		case V4L2_SEL_TGT_COMPOSE:
+			rect = __vfe_get_compose(line, cfg, sel->which);
+			if (rect == NULL)
+				return -EINVAL;
+
+			sel->r = *rect;
+			break;
+		default:
 			return -EINVAL;
+		}
+	else if (sel->pad == MSM_VFE_PAD_SRC)
+		switch (sel->target) {
+		case V4L2_SEL_TGT_CROP_BOUNDS:
+			rect = __vfe_get_compose(line, cfg, sel->which);
+			if (rect == NULL)
+				return -EINVAL;
 
-		sel->r = *compose;
-		break;
-	default:
-		return -EINVAL;
-	}
+			sel->r.left = rect->left;
+			sel->r.top = rect->top;
+			sel->r.width = rect->width;
+			sel->r.height = rect->height;
+			break;
+		case V4L2_SEL_TGT_CROP:
+			rect = __vfe_get_crop(line, cfg, sel->which);
+			if (rect == NULL)
+				return -EINVAL;
+
+			sel->r = *rect;
+			break;
+		default:
+			return -EINVAL;
+		}
 
 	return 0;
 }
@@ -2329,33 +2416,53 @@ int vfe_set_selection(struct v4l2_subdev *sd,
 			     struct v4l2_subdev_selection *sel)
 {
 	struct vfe_line *line = v4l2_get_subdevdata(sd);
-	struct v4l2_rect *compose;
-	struct v4l2_subdev_format fmt = { 0 };
+	struct v4l2_rect *rect;
 	int ret;
 
-	if (line->id != VFE_LINE_PIX || sel->pad != MSM_VFE_PAD_SINK)
+	if (line->id != VFE_LINE_PIX)
 		return -EINVAL;
 
-	if (sel->target != V4L2_SEL_TGT_COMPOSE)
-		return -EINVAL;
+	if (sel->target == V4L2_SEL_TGT_COMPOSE &&
+		sel->pad == MSM_VFE_PAD_SINK) {
+		struct v4l2_subdev_selection crop = { 0 };
 
-	compose = __vfe_get_compose(line, cfg, sel->which);
-	if (compose == NULL)
-		return -EINVAL;
+		rect = __vfe_get_compose(line, cfg, sel->which);
+		if (rect == NULL)
+			return -EINVAL;
+
+		vfe_try_compose(line, cfg, &sel->r, sel->which);
+		*rect = sel->r;
+
+		/* Reset source crop selection */
+		crop.which = sel->which;
+		crop.pad = MSM_VFE_PAD_SRC;
+		crop.target = V4L2_SEL_TGT_CROP;
+		crop.r = *rect;
+		ret = vfe_set_selection(sd, cfg, &crop);
+	} else if (sel->target == V4L2_SEL_TGT_CROP &&
+		sel->pad == MSM_VFE_PAD_SRC) {
+		struct v4l2_subdev_format fmt = { 0 };
+
+		rect = __vfe_get_crop(line, cfg, sel->which);
+		if (rect == NULL)
+			return -EINVAL;
 
-	vfe_try_compose(line, cfg, &sel->r, sel->which);
-	*compose = sel->r;
+		vfe_try_crop(line, cfg, &sel->r, sel->which);
+		*rect = sel->r;
 
-	/* Reset source pad format width and height */
-	fmt.which = sel->which;
-	fmt.pad = MSM_VFE_PAD_SRC;
-	ret = vfe_get_format(sd, cfg, &fmt);
-	if (ret < 0)
-		return ret;
+		/* Reset source pad format width and height */
+		fmt.which = sel->which;
+		fmt.pad = MSM_VFE_PAD_SRC;
+		ret = vfe_get_format(sd, cfg, &fmt);
+		if (ret < 0)
+			return ret;
 
-	fmt.format.width = compose->width;
-	fmt.format.height = compose->height;
-	ret = vfe_set_format(sd, cfg, &fmt);
+		fmt.format.width = rect->width;
+		fmt.format.height = rect->height;
+		ret = vfe_set_format(sd, cfg, &fmt);
+	} else {
+		ret = -EINVAL;
+	}
 
 	return ret;
 }
diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
index 6518c7a..3651ece 100644
--- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
+++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h
@@ -81,6 +81,7 @@ struct vfe_line {
 	struct media_pad pads[MSM_VFE_PADS_NUM];
 	struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM];
 	struct v4l2_rect compose;
+	struct v4l2_rect crop;
 	struct camss_video video_out;
 	struct vfe_output output;
 };
-- 
2.7.4

  parent reply	other threads:[~2017-08-08 13:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 13:29 [PATCH v4 00/21] Qualcomm 8x16 Camera Subsystem driver Todor Tomov
2017-08-08 13:29 ` [PATCH v4 01/21] v4l: Add packed Bayer raw12 pixel formats Todor Tomov
2017-08-08 13:29 ` [PATCH v4 02/21] dt-bindings: media: Binding document for Qualcomm Camera subsystem driver Todor Tomov
2017-08-08 13:30 ` [PATCH v4 03/21] MAINTAINERS: Add " Todor Tomov
2017-08-08 13:30 ` [PATCH v4 04/21] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document Todor Tomov
2017-08-18  7:45   ` Hans Verkuil
2017-08-18  7:53     ` Todor Tomov
2017-08-25 14:10   ` Daniel Mack
2017-08-28  7:10     ` Todor Tomov
2017-08-29 17:02       ` Daniel Mack
2017-10-16 15:01       ` Daniel Mack
2017-10-25 12:07         ` Todor Tomov
2017-10-25 12:18           ` Daniel Mack
2017-08-08 13:30 ` [PATCH v4 05/21] media: camss: Add CSIPHY files Todor Tomov
2017-08-08 13:30 ` [PATCH v4 06/21] media: camss: Add CSID files Todor Tomov
2017-08-08 13:30 ` [PATCH v4 07/21] media: camss: Add ISPIF files Todor Tomov
2017-08-08 13:30 ` [PATCH v4 08/21] media: camss: Add VFE files Todor Tomov
2017-08-08 13:30 ` [PATCH v4 09/21] media: camss: Add files which handle the video device nodes Todor Tomov
2017-08-08 14:44   ` Sakari Ailus
2017-08-08 13:30 ` [PATCH v4 10/21] media: camms: Add core files Todor Tomov
2017-08-08 13:30 ` [PATCH v4 11/21] media: camss: Enable building Todor Tomov
2017-08-08 13:30 ` [PATCH v4 12/21] camss: vfe: Format conversion support using PIX interface Todor Tomov
2017-09-10  9:58   ` Geert Uytterhoeven
2017-09-11  6:56     ` Todor Tomov
2017-09-11  7:45       ` Geert Uytterhoeven
2017-08-08 13:30 ` [PATCH v4 13/21] doc: media/v4l-drivers: Qualcomm Camera Subsystem - PIX Interface Todor Tomov
2017-08-08 13:30 ` [PATCH v4 14/21] camss: vfe: Support for frame padding Todor Tomov
2017-08-08 13:30 ` [PATCH v4 15/21] camss: vfe: Add interface for scaling Todor Tomov
2017-08-08 13:30 ` [PATCH v4 16/21] camss: vfe: Configure scaler module in VFE Todor Tomov
2017-08-08 13:30 ` Todor Tomov [this message]
2017-08-08 13:30 ` [PATCH v4 18/21] camss: vfe: Configure crop " Todor Tomov
2017-08-08 13:30 ` [PATCH v4 19/21] doc: media/v4l-drivers: Qualcomm Camera Subsystem - Scale and crop Todor Tomov
2017-08-08 13:30 ` [PATCH v4 20/21] camss: Use optimal clock frequency rates Todor Tomov
2017-08-08 13:30 ` [PATCH v4 21/21] doc: media/v4l-drivers: Qualcomm Camera Subsystem - Media graph Todor Tomov
2017-08-08 14:53 ` [PATCH v4 00/21] Qualcomm 8x16 Camera Subsystem driver Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502199018-28250-18-git-send-email-todor.tomov@linaro.org \
    --to=todor.tomov@linaro.org \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=sakari.ailus@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).