From patchwork Mon Jul 17 10:33:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todor Tomov X-Patchwork-Id: 107895 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp4343546qge; Mon, 17 Jul 2017 03:38:39 -0700 (PDT) X-Received: by 10.99.140.7 with SMTP id m7mr28615337pgd.49.1500287919252; Mon, 17 Jul 2017 03:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500287919; cv=none; d=google.com; s=arc-20160816; b=M9TGtyvm0oUyiiEqLl/7/SI/oqnSOvnMEPOR6v8hwjMp/F7yK2c63ZHFHkzOTuekao XrlMYpYFFRAYy3DQopa+350EhduvJdYubCt9XKRIUboVkKQAifuO4FTgkIHr6XgVqBex 18HbppCTLGdNB6EcOi/W2UgOJntpp9d9nKHKH70pTXaZqeFgmszS6jkz8dV9uE4XuI2R x64iuzuhtJ6uoGI2CU13/gYn52+5D3jruHAuH6692XgALVVMQ3ajS1B0w40mMUCX5xw5 NFvqx9KKbmVNOk5CJd/S0BWbSR9gmZ+g3CIk9UYJyYWcu06S8SRxoCC+GnJRzZrmUGfh JA4A== 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=K1wBPXh4b6tFfOZxKoQWYCct79x4YziuSWJWEMX271I=; b=xaQiNXh9E2V5dMadxu+ORLh2H7hI1BZgN3CKIDBq/ikoO0DVT7RwOzLhhU9P4YFYjW Ol2KIMiKuMAgBgGk3PFpqfIi7QO6Kfvv+zproaxGuekIYer9b//xJ+xE0mL/xaI44ZTU Zm6C5RN4UdNvFuGbkQRSqTm3+z2cFUWHecbnF2noNvKKzWMqyrs2wlmJO4yyECwLVTHO d8S6Qrlm6bVHnsU+szAiN/u1TVWAJ1C0nWbC+SOaPCxYkjYVK28V/LxqSD0QXqlXVSFG KT4oZwG2uFhyM/6u4t3Shy+TMU8mqgozIAMBsHRpZFCcpeex4+oSco+TNUPtB7c5g7UT P9sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 j26si12316405pfj.308.2017.07.17.03.38.38; Mon, 17 Jul 2017 03:38:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1751969AbdGQKif (ORCPT + 25 others); Mon, 17 Jul 2017 06:38:35 -0400 Received: from ns.mm-sol.com ([37.157.136.199]:36070 "EHLO extserv.mm-sol.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751397AbdGQKfG (ORCPT ); Mon, 17 Jul 2017 06:35:06 -0400 Received: from mms-0439.qualcomm.mm-sol.com (unknown [37.157.136.206]) by extserv.mm-sol.com (Postfix) with ESMTPSA id 2AD32CBF1; 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 17/23] camss: vfe: Add interface for scaling Date: Mon, 17 Jul 2017 13:33:43 +0300 Message-Id: <1500287629-23703-18-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add compose selection ioctls to handle scaling configuration. Signed-off-by: Todor Tomov --- drivers/media/platform/qcom/camss-8x16/camss-vfe.c | 189 ++++++++++++++++++++- drivers/media/platform/qcom/camss-8x16/camss-vfe.h | 1 + 2 files changed, 188 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c index 327f158..8ec6ce7 100644 --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.c +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.c @@ -211,6 +211,8 @@ #define CAMIF_TIMEOUT_SLEEP_US 1000 #define CAMIF_TIMEOUT_ALL_US 1000000 +#define SCALER_RATIO_MAX 16 + static const u32 vfe_formats[] = { MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_VYUY8_2X8, @@ -1905,6 +1907,25 @@ __vfe_get_format(struct vfe_line *line, return &line->fmt[pad]; } +/* + * __vfe_get_compose - Get pointer to compose selection structure + * @line: VFE line + * @cfg: V4L2 subdev pad configuration + * @which: TRY or ACTIVE format + * + * Return pointer to TRY or ACTIVE compose rectangle structure + */ +static struct v4l2_rect * +__vfe_get_compose(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_compose(&line->subdev, cfg, + MSM_VFE_PAD_SINK); + + return &line->compose; +} /* * vfe_try_format - Handle try format by pad subdev method @@ -1951,7 +1972,14 @@ static void vfe_try_format(struct vfe_line *line, *fmt = *__vfe_get_format(line, cfg, MSM_VFE_PAD_SINK, which); - if (line->id == VFE_LINE_PIX) + if (line->id == VFE_LINE_PIX) { + struct v4l2_rect *rect; + + rect = __vfe_get_compose(line, cfg, which); + + fmt->width = rect->width; + fmt->height = rect->height; + switch (fmt->code) { case MEDIA_BUS_FMT_YUYV8_2X8: if (code == MEDIA_BUS_FMT_YUYV8_1_5X8) @@ -1979,6 +2007,7 @@ static void vfe_try_format(struct vfe_line *line, fmt->code = MEDIA_BUS_FMT_VYUY8_2X8; break; } + } break; } @@ -1987,6 +2016,50 @@ static void vfe_try_format(struct vfe_line *line, } /* + * vfe_try_compose - Handle try compose 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_compose(struct vfe_line *line, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_rect *rect, + enum v4l2_subdev_format_whence which) +{ + struct v4l2_mbus_framefmt *fmt; + + rect->width = rect->width - rect->left; + rect->left = 0; + rect->height = rect->height - rect->top; + rect->top = 0; + + fmt = __vfe_get_format(line, cfg, MSM_VFE_PAD_SINK, which); + + if (rect->width > fmt->width) + rect->width = fmt->width; + + if (rect->height > fmt->height) + rect->height = fmt->height; + + if (fmt->width > rect->width * SCALER_RATIO_MAX) + rect->width = (fmt->width + SCALER_RATIO_MAX - 1) / + SCALER_RATIO_MAX; + + rect->width &= ~0x1; + + if (fmt->height > rect->height * SCALER_RATIO_MAX) + rect->height = (fmt->height + SCALER_RATIO_MAX - 1) / + SCALER_RATIO_MAX; + + if (rect->width < 16) + rect->width = 16; + + if (rect->height < 4) + rect->height = 4; +} + +/* * vfe_enum_mbus_code - Handle pixel format enumeration * @sd: VFE V4L2 subdevice * @cfg: V4L2 subdev pad configuration @@ -2081,6 +2154,10 @@ static int vfe_get_format(struct v4l2_subdev *sd, return 0; } +static int vfe_set_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel); + /* * vfe_set_format - Handle set format by pads subdev method * @sd: VFE V4L2 subdevice @@ -2103,20 +2180,126 @@ static int vfe_set_format(struct v4l2_subdev *sd, vfe_try_format(line, cfg, fmt->pad, &fmt->format, fmt->which); *format = fmt->format; - /* Propagate the format from sink to source */ if (fmt->pad == MSM_VFE_PAD_SINK) { + struct v4l2_subdev_selection sel = { 0 }; + int ret; + + /* Propagate the format from sink to source */ format = __vfe_get_format(line, cfg, MSM_VFE_PAD_SRC, fmt->which); *format = fmt->format; vfe_try_format(line, cfg, MSM_VFE_PAD_SRC, format, fmt->which); + + if (line->id != VFE_LINE_PIX) + return 0; + + /* Reset sink pad compose selection */ + sel.which = fmt->which; + sel.pad = MSM_VFE_PAD_SINK; + sel.target = V4L2_SEL_TGT_COMPOSE; + sel.r.width = fmt->format.width; + sel.r.height = fmt->format.height; + ret = vfe_set_selection(sd, cfg, &sel); + if (ret < 0) + return ret; } return 0; } /* + * vfe_get_selection - Handle get selection by pads subdev method + * @sd: VFE V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @sel: pointer to v4l2 subdev selection structure + * + * Return -EINVAL or zero on success + */ +static int vfe_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + struct vfe_line *line = v4l2_get_subdevdata(sd); + struct v4l2_subdev_format fmt = { 0 }; + struct v4l2_rect *compose; + int ret; + + if (line->id != VFE_LINE_PIX || sel->pad != MSM_VFE_PAD_SINK) + 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) + return -EINVAL; + + sel->r = *compose; + break; + default: + return -EINVAL; + } + + return 0; +} + +/* + * vfe_set_selection - Handle set selection by pads subdev method + * @sd: VFE V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @sel: pointer to v4l2 subdev selection structure + * + * Return -EINVAL or zero on success + */ +int vfe_set_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) +{ + struct vfe_line *line = v4l2_get_subdevdata(sd); + struct v4l2_rect *compose; + struct v4l2_subdev_format fmt = { 0 }; + int ret; + + if (line->id != VFE_LINE_PIX || sel->pad != MSM_VFE_PAD_SINK) + return -EINVAL; + + if (sel->target != V4L2_SEL_TGT_COMPOSE) + return -EINVAL; + + compose = __vfe_get_compose(line, cfg, sel->which); + if (compose == NULL) + return -EINVAL; + + vfe_try_compose(line, cfg, &sel->r, sel->which); + *compose = 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; + + fmt.format.width = compose->width; + fmt.format.height = compose->height; + ret = vfe_set_format(sd, cfg, &fmt); + + return ret; +} + +/* * vfe_init_formats - Initialize formats on all pads * @sd: VFE V4L2 subdevice * @fh: V4L2 subdev file handle @@ -2310,6 +2493,8 @@ static const struct v4l2_subdev_pad_ops vfe_pad_ops = { .enum_frame_size = vfe_enum_frame_size, .get_fmt = vfe_get_format, .set_fmt = vfe_set_format, + .get_selection = vfe_get_selection, + .set_selection = vfe_set_selection, }; static const struct v4l2_subdev_ops vfe_v4l2_ops = { diff --git a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h index b0598e4..6518c7a 100644 --- a/drivers/media/platform/qcom/camss-8x16/camss-vfe.h +++ b/drivers/media/platform/qcom/camss-8x16/camss-vfe.h @@ -80,6 +80,7 @@ struct vfe_line { struct v4l2_subdev subdev; struct media_pad pads[MSM_VFE_PADS_NUM]; struct v4l2_mbus_framefmt fmt[MSM_VFE_PADS_NUM]; + struct v4l2_rect compose; struct camss_video video_out; struct vfe_output output; };