From patchwork Wed Jun 7 18:34:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 9772415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5933360364 for ; Wed, 7 Jun 2017 18:51:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39A072847A for ; Wed, 7 Jun 2017 18:51:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D0A92852C; Wed, 7 Jun 2017 18:51:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5ED6828521 for ; Wed, 7 Jun 2017 18:51:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=t0AH/PB1TjBZSXuYOAdamr5HbjPCWLUy+32VvPRo9k4=; b=MERDfAQETcvql75R6AzE/BJJuE jsXbkN0p05NiFoW0dIeYEE7otdRbJxavbIevXgQOSRonYJ2dJ1CjH5AXYM0OjLu2Bab4LS1G6pyAE Hu3kJWkHgpsIMh/tvn6ywSo9i9pKWjKSjaxTpxMVh3hNfSOEBCt4XOnmzcoibDuBW8jtcIAuCUUm9 FLvJWaOAWltllLHO11fQsFvngCgMATtPvle6WOK/uYdz5abnOk6viRKhd0B2zg9JAludm7M5l6zvd IdYmRWRwHqxcV22VJ7YlGeVKgn1w66IsdBdLI+vCe+VZyBfk6Kmc7K2sJmW61zqroktrz4cx3R3rB M63GF8ZA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dIg3F-0007px-UZ; Wed, 07 Jun 2017 18:51:29 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIg37-0007V2-EK for linux-arm-kernel@bombadil.infradead.org; Wed, 07 Jun 2017 18:51:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=r2aTEmRA7swdPMvLDnH4+kXVE8DiVKP0ZYjDfpVa6qA=; b=ShHenI4q5d+fIjoMtvX5w6FEy onBT3GXL8ByY/tzaSzc77SYcnuOHGCBbZqiWOtmzRP8RUxmbsNAA+1h2YE7GKo6okgY9lILVqzJ8S bFqtordbcPMc0bpnNVysnPpE7e/CNilq0eNP2nWQgNFQF1lR6xkI6XpYxSALmiYksWPAAo0jOGAbC v0gYYQUx5u3lvDB3FF2IZvel3jF8wfTKTtvlZzbO+z8he1m7uOiyKsNgTPT7yvdnQWq90nlyB3eta Q/xPbdicDmHolIm33dFtwA7PvP1XGCo01r6rPQW/9Xe627HpNGcB4+T1u6M1nU7ydji1Wq8D8MLeX sya1LnyIw==; Received: from mail-pf0-f195.google.com ([209.85.192.195]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dIfrC-0008TZ-S2 for linux-arm-kernel@lists.infradead.org; Wed, 07 Jun 2017 18:39:05 +0000 Received: by mail-pf0-f195.google.com with SMTP id u26so2404950pfd.2 for ; Wed, 07 Jun 2017 11:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r2aTEmRA7swdPMvLDnH4+kXVE8DiVKP0ZYjDfpVa6qA=; b=i+MEsktEB7wvcIuHlC803m0yXycSmi+LbcgrIrHd8ZojleuetM757C29AS36/ufE1Y qgjuKUajAW+VA/60zN9o7H6X2ko9q3ESw7jXngd8pRopYW/xYbJNcyJg61YCvl16jsWm sVmopyyTYCiimc6IHSVInOgL0w8O/I4RJpWSQO4P5hcRLt2G97Mo7UrmxSgSL39ZLlSy 7kcoJd8NDJ5LICSqYh+tTiXZHuLXpe1QRSqbt+PhrJyOfFl7ajlqt8wyh8edWCcEKAgz qXcWCsIRnDBtYhjTxzGp1f42SbE7NBNQnigxSrig9ecK3Tw5dncCbg+rHVgx7yexy1mz 8JKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r2aTEmRA7swdPMvLDnH4+kXVE8DiVKP0ZYjDfpVa6qA=; b=BlIPrxSfNBmuB9seZ++N2UH6OJA62ImCsY4odI23J8c0I8mX3gyREUhGAxt/Nen0A+ NYr0rvTdunnnkQfMPQm8UDkFxl6HeyE1N8l2+QuCvjXBim6DXeokzRoZ1NJ9IuzfnxS2 SuwrCxFBdjhLhMAtJhlZ0HzJIgXk8Wo3v43w5cWazOWMzIwkLJ4baP2vbzoHASb+AIS8 oFpzpBZeclmhOmFYPuTI3YLBw9836OYAlKXVFbRr6FSYv8WjO8lSs/ygr+kd4rvF4X// gYRlR7ECdysphDhNF3kUDUxPRn5+dbTfW4WrmGAvmdOtHGwNee1JNHbISM19g3IVA+wC /qVA== X-Gm-Message-State: AODbwcCCv1wNpwrW3mtjcwuEpKTSplt0ktSIi8mJOSw9e0P3t4iob9AV kLbdhecnP5U50w== X-Received: by 10.84.210.166 with SMTP id a35mr30052236pli.160.1496860537671; Wed, 07 Jun 2017 11:35:37 -0700 (PDT) Received: from majic.sklembedded.com (c-98-210-181-167.hsd1.ca.comcast.net. [98.210.181.167]) by smtp.googlemail.com with ESMTPSA id d2sm5141565pfb.110.2017.06.07.11.35.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jun 2017 11:35:36 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: robh+dt@kernel.org, mark.rutland@arm.com, shawnguo@kernel.org, kernel@pengutronix.de, fabio.estevam@nxp.com, linux@armlinux.org.uk, mchehab@kernel.org, hverkuil@xs4all.nl, nick@shmanahar.org, markus.heiser@darmarIT.de, p.zabel@pengutronix.de, laurent.pinchart+renesas@ideasonboard.com, bparrot@ti.com, geert@linux-m68k.org, arnd@arndb.de, sudipm.mukherjee@gmail.com, minghsiu.tsai@mediatek.com, tiffany.lin@mediatek.com, jean-christophe.trotin@st.com, horms+renesas@verge.net.au, niklas.soderlund+renesas@ragnatech.se, robert.jarzmik@free.fr, songjun.wu@microchip.com, andrew-ct.chen@mediatek.com, gregkh@linuxfoundation.org, shuah@kernel.org, sakari.ailus@linux.intel.com, pavel@ucw.cz Subject: [PATCH v8 29/34] media: imx: csi: add sink selection rectangles Date: Wed, 7 Jun 2017 11:34:08 -0700 Message-Id: <1496860453-6282-30-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496860453-6282-1-git-send-email-steve_longerbeam@mentor.com> References: <1496860453-6282-1-git-send-email-steve_longerbeam@mentor.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170607_193903_201169_1CBE73DE X-CRM114-Status: GOOD ( 23.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Philipp Zabel Move the crop rectangle to the sink pad and add a sink compose rectangle to configure scaling. Also propagate rectangles from sink pad to crop rectangle, to compose rectangle, and to the source pads both in ACTIVE and TRY variants of set_fmt/selection, and initialize the default crop and compose rectangles. Signed-off-by: Philipp Zabel --- drivers/staging/media/imx/imx-media-csi.c | 153 +++++++++++++++++++++++------- 1 file changed, 117 insertions(+), 36 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index fb66695..655a095 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -80,6 +80,7 @@ struct csi_priv { const struct imx_media_pixfmt *cc[CSI_NUM_PADS]; struct v4l2_fract frame_interval[CSI_NUM_PADS]; struct v4l2_rect crop; + struct v4l2_rect compose; const struct csi_skip_desc *skip; /* active vb2 buffers to send to video dev sink */ @@ -588,8 +589,8 @@ static int csi_setup(struct csi_priv *priv) ipu_csi_set_window(priv->csi, &priv->crop); ipu_csi_set_downsize(priv->csi, - priv->crop.width == 2 * outfmt->width, - priv->crop.height == 2 * outfmt->height); + priv->crop.width == 2 * priv->compose.width, + priv->crop.height == 2 * priv->compose.height); ipu_csi_init_interface(priv->csi, &sensor_mbus_cfg, &if_fmt); @@ -1047,6 +1048,17 @@ __csi_get_crop(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg, return &priv->crop; } +static struct v4l2_rect * +__csi_get_compose(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg, + enum v4l2_subdev_format_whence which) +{ + if (which == V4L2_SUBDEV_FORMAT_TRY) + return v4l2_subdev_get_try_compose(&priv->sd, cfg, + CSI_SINK_PAD); + else + return &priv->compose; +} + static void csi_try_crop(struct csi_priv *priv, struct v4l2_rect *crop, struct v4l2_subdev_pad_config *cfg, @@ -1156,6 +1168,7 @@ static void csi_try_fmt(struct csi_priv *priv, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *sdformat, struct v4l2_rect *crop, + struct v4l2_rect *compose, const struct imx_media_pixfmt **cc) { const struct imx_media_pixfmt *incc; @@ -1170,15 +1183,8 @@ static void csi_try_fmt(struct csi_priv *priv, incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY, true); - if (sdformat->format.width < crop->width * 3 / 4) - sdformat->format.width = crop->width / 2; - else - sdformat->format.width = crop->width; - - if (sdformat->format.height < crop->height * 3 / 4) - sdformat->format.height = crop->height / 2; - else - sdformat->format.height = crop->height; + sdformat->format.width = compose->width; + sdformat->format.height = compose->height; if (incc->bayer) { sdformat->format.code = infmt->code; @@ -1214,11 +1220,17 @@ static void csi_try_fmt(struct csi_priv *priv, v4l_bound_align_image(&sdformat->format.width, MIN_W, MAX_W, W_ALIGN, &sdformat->format.height, MIN_H, MAX_H, H_ALIGN, S_ALIGN); + + /* Reset crop and compose rectangles */ crop->left = 0; crop->top = 0; crop->width = sdformat->format.width; crop->height = sdformat->format.height; csi_try_crop(priv, crop, cfg, &sdformat->format, sensor); + compose->left = 0; + compose->top = 0; + compose->width = crop->width; + compose->height = crop->height; *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY, true); @@ -1243,7 +1255,7 @@ static int csi_set_fmt(struct v4l2_subdev *sd, struct imx_media_subdev *sensor; struct v4l2_pix_format vdev_fmt; struct v4l2_mbus_framefmt *fmt; - struct v4l2_rect *crop; + struct v4l2_rect *crop, *compose; int ret = 0; if (sdformat->pad >= CSI_NUM_PADS) @@ -1263,8 +1275,9 @@ static int csi_set_fmt(struct v4l2_subdev *sd, } crop = __csi_get_crop(priv, cfg, sdformat->which); + compose = __csi_get_compose(priv, cfg, sdformat->which); - csi_try_fmt(priv, sensor, cfg, sdformat, crop, &cc); + csi_try_fmt(priv, sensor, cfg, sdformat, crop, compose, &cc); fmt = __csi_get_fmt(priv, cfg, sdformat->pad, sdformat->which); *fmt = sdformat->format; @@ -1281,7 +1294,8 @@ static int csi_set_fmt(struct v4l2_subdev *sd, format.pad = pad; format.which = sdformat->which; format.format = sdformat->format; - csi_try_fmt(priv, sensor, cfg, &format, crop, &outcc); + csi_try_fmt(priv, sensor, cfg, &format, NULL, compose, + &outcc); outfmt = __csi_get_fmt(priv, cfg, pad, sdformat->which); *outfmt = format.format; @@ -1315,16 +1329,17 @@ static int csi_get_selection(struct v4l2_subdev *sd, { struct csi_priv *priv = v4l2_get_subdevdata(sd); struct v4l2_mbus_framefmt *infmt; - struct v4l2_rect *crop; + struct v4l2_rect *crop, *compose; int ret = 0; - if (sel->pad >= CSI_NUM_PADS || sel->pad == CSI_SINK_PAD) + if (sel->pad != CSI_SINK_PAD) return -EINVAL; mutex_lock(&priv->lock); infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which); crop = __csi_get_crop(priv, cfg, sel->which); + compose = __csi_get_compose(priv, cfg, sel->which); switch (sel->target) { case V4L2_SEL_TGT_CROP_BOUNDS: @@ -1336,6 +1351,15 @@ static int csi_get_selection(struct v4l2_subdev *sd, case V4L2_SEL_TGT_CROP: sel->r = *crop; break; + case V4L2_SEL_TGT_COMPOSE_BOUNDS: + sel->r.left = 0; + sel->r.top = 0; + sel->r.width = crop->width; + sel->r.height = crop->height; + break; + case V4L2_SEL_TGT_COMPOSE: + sel->r = *compose; + break; default: ret = -EINVAL; } @@ -1344,19 +1368,34 @@ static int csi_get_selection(struct v4l2_subdev *sd, return ret; } +static int csi_set_scale(u32 *compose, u32 crop, u32 flags) +{ + if ((flags & (V4L2_SEL_FLAG_LE | V4L2_SEL_FLAG_GE)) == + (V4L2_SEL_FLAG_LE | V4L2_SEL_FLAG_GE) && + *compose != crop && *compose != crop / 2) + return -ERANGE; + + if (*compose <= crop / 2 || + (*compose < crop * 3 / 4 && !(flags & V4L2_SEL_FLAG_GE)) || + (*compose < crop && (flags & V4L2_SEL_FLAG_LE))) + *compose = crop / 2; + else + *compose = crop; + + return 0; +} + static int csi_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) { struct csi_priv *priv = v4l2_get_subdevdata(sd); struct v4l2_mbus_framefmt *infmt; + struct v4l2_rect *crop, *compose; struct imx_media_subdev *sensor; - struct v4l2_rect *crop; int pad, ret = 0; - if (sel->pad >= CSI_NUM_PADS || - sel->pad == CSI_SINK_PAD || - sel->target != V4L2_SEL_TGT_CROP) + if (sel->pad != CSI_SINK_PAD) return -EINVAL; sensor = imx_media_find_sensor(priv->md, &priv->sd.entity); @@ -1374,30 +1413,66 @@ static int csi_set_selection(struct v4l2_subdev *sd, infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, sel->which); crop = __csi_get_crop(priv, cfg, sel->which); + compose = __csi_get_compose(priv, cfg, sel->which); - /* - * Modifying the crop rectangle always changes the format on the source - * pad. If the KEEP_CONFIG flag is set, just return the current crop - * rectangle. - */ - if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) { - sel->r = priv->crop; - if (sel->which == V4L2_SUBDEV_FORMAT_TRY) - *crop = sel->r; - goto out; - } + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + /* + * Modifying the crop rectangle always changes the format on + * the source pads. If the KEEP_CONFIG flag is set, just return + * the current crop rectangle. + */ + if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) { + sel->r = priv->crop; + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) + *crop = sel->r; + goto out; + } + + csi_try_crop(priv, &sel->r, cfg, infmt, sensor); + + *crop = sel->r; + + /* Reset scaling to 1:1 */ + compose->width = crop->width; + compose->height = crop->height; + break; + case V4L2_SEL_TGT_COMPOSE: + /* + * Modifying the compose rectangle always changes the format on + * the source pads. If the KEEP_CONFIG flag is set, just return + * the current compose rectangle. + */ + if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) { + sel->r = priv->compose; + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) + *compose = sel->r; + goto out; + } - csi_try_crop(priv, &sel->r, cfg, infmt, sensor); + sel->r.left = 0; + sel->r.top = 0; + ret = csi_set_scale(&sel->r.width, crop->width, sel->flags); + if (ret) + goto out; + ret = csi_set_scale(&sel->r.height, crop->height, sel->flags); + if (ret) + goto out; - *crop = sel->r; + *compose = sel->r; + break; + default: + ret = -EINVAL; + goto out; + } - /* Update the source pad formats */ + /* Reset source pads to sink compose rectangle */ for (pad = CSI_SINK_PAD + 1; pad < CSI_NUM_PADS; pad++) { struct v4l2_mbus_framefmt *outfmt; outfmt = __csi_get_fmt(priv, cfg, pad, sel->which); - outfmt->width = crop->width; - outfmt->height = crop->height; + outfmt->width = compose->width; + outfmt->height = compose->height; } out: @@ -1464,6 +1539,12 @@ static int csi_registered(struct v4l2_subdev *sd) /* disable frame skipping */ priv->skip = &csi_skip[0]; + /* init default crop and compose rectangle sizes */ + priv->crop.width = 640; + priv->crop.height = 480; + priv->compose.width = 640; + priv->compose.height = 480; + priv->fim = imx_media_fim_init(&priv->sd); if (IS_ERR(priv->fim)) { ret = PTR_ERR(priv->fim);