From patchwork Mon Jul 17 10:33:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todor Tomov X-Patchwork-Id: 107889 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4341985qge; Mon, 17 Jul 2017 03:36:55 -0700 (PDT) X-Received: by 10.101.91.203 with SMTP id o11mr28289671pgr.206.1500287814901; Mon, 17 Jul 2017 03:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500287814; cv=none; d=google.com; s=arc-20160816; b=ICQZm2bnwNXjARxG/O/CPcSTwVE0aK1muYtclqkmCkk/VoOaRcRdgh0jCh7T6yCn3E rC5MsTRp/DM0sJeqghqJzpLCmyL/p3/gnw2ppVrzV+l5/qI0ULqFHOjomf/3n6T8l326 dZbzUgk+FoAnDDnfAC2JUoWA5SAa3fdgkDJ600B9EYhdbQZ0WEU2nakJ8iG/71VlsqbQ F4ZWLqjHQYBMkxVwM5R87Om6ht0ZxeeVmlMD+7m7yKgkPX+URnSkm/mbTTw2gTZmQSbB ZWWXcbyxF8MBJrlp8mGMo3NyGz/lkRvvuOkProYumko6cqexpYVIlAzscDnwTZStC8W5 eEEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=wxkMfUvuMemsOLwl6xu86jDAIkJloTmFef3/UGbjth4=; b=uJ/QVCmIiZVrUoNrRxeO8AHJ3ZyyNr4tB6kKsHpkGjYeoUj5pLCmHeB61hkYj6GejR HoB1hJoJKO0vnifigkrJnhKD9orOBztX5ZRA9G1T+ltg7tDJRicGznq4nwy6Ad26LsCA hOX8o8oWd4kxdkQFhO8uXPON4MEZi5SqwrkhJT2QuIYVuSaVwLQf2R5bdUjBZ0kwkc/z 4raQ8sHZo+2s22r9izz27AJlHdon+ednk3oXYhBCSlShYsO7o2acLAZ62GA9R9gC7xtp jWFdrfRJe/v69Pp7KLuFfystwsckdVaFBoJDzQ4R4wjHRX4W9GwMR/bfHYG2QWl/XfUS KfRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si1070572pln.417.2017.07.17.03.36.54; Mon, 17 Jul 2017 03:36:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751541AbdGQKgx (ORCPT + 10 others); Mon, 17 Jul 2017 06:36:53 -0400 Received: from ns.mm-sol.com ([37.157.136.199]:36083 "EHLO extserv.mm-sol.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbdGQKfH (ORCPT ); Mon, 17 Jul 2017 06:35:07 -0400 Received: from mms-0439.qualcomm.mm-sol.com (unknown [37.157.136.206]) by extserv.mm-sol.com (Postfix) with ESMTPSA id 4FD08CBF3; Mon, 17 Jul 2017 13:34:59 +0300 (EEST) From: Todor Tomov To: mchehab@kernel.org, hans.verkuil@cisco.com, javier@osg.samsung.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 Subject: [PATCH v3 19/23] camss: vfe: Add interface for cropping Date: Mon, 17 Jul 2017 13:33:45 +0300 Message-Id: <1500287629-23703-20-git-send-email-todor.tomov@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500287629-23703-1-git-send-email-todor.tomov@linaro.org> References: <1500287629-23703-1-git-send-email-todor.tomov@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Extend selection ioctls to handle cropping configuration. Signed-off-by: Todor Tomov --- 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(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c index f994b35..17617c0 100644 --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c @@ -1961,6 +1961,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 @@ -2008,7 +2028,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; @@ -2093,6 +2113,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 @@ -2256,34 +2319,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; } @@ -2301,33 +2388,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; };