From patchwork Sun May 26 20:47:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10961883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F8DD1390 for ; Sun, 26 May 2019 20:48:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 407AF28A74 for ; Sun, 26 May 2019 20:48:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3504628A92; Sun, 26 May 2019 20:48:40 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFD8528A74 for ; Sun, 26 May 2019 20:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726012AbfEZUsO (ORCPT ); Sun, 26 May 2019 16:48:14 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:46240 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfEZUsN (ORCPT ); Sun, 26 May 2019 16:48:13 -0400 Received: by mail-lf1-f65.google.com with SMTP id l26so10568672lfh.13; Sun, 26 May 2019 13:48:12 -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 :mime-version:content-transfer-encoding; bh=W8mYYWBQJosjwipD1CvvNNNq1i8OAaYumTI2biJWE/E=; b=nh1ZY8pWQpTkUyzgKnlrGGDBCKLuN2UZEmKWdH+TBkUzy9RMLxK7Ef2ajgLs0AzDN7 VDu/CyUWtMaSzb2VKOghUbz/b/0JtBvFoUwwrQcgUOFdzITVxMs1fpHjeoSz5odkRglS Vd6LrTtlASAeA71u2a9AnZLlXH3por9e/YLMckKdojbmDZNNH7omtzdrO9Qn6gsE6ben RI+yLcAMFesSbhS7qcXOp0PrdzgjQgFoiY6K2VG+N4Mt6kTmI2DOSUhgKlbpAQXUwva8 UeZkg7RXY3hVVxV5QSMiGoBB1q8LA9QIX2Hr8VXdelrN4IPrUV8yyTJ3WUW1AaG7i4GL zMhQ== 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:mime-version:content-transfer-encoding; bh=W8mYYWBQJosjwipD1CvvNNNq1i8OAaYumTI2biJWE/E=; b=ZdFiefVjUfkXtR6Z0hFQ7xJeQDwAGQgnBWwQEKlU1OS1IHpX3TZ2dum+4QtbbXyJt+ J/0NU5tN8+A1bnHhTL1lRQjS2WYw3F7cQP6rYb/gpO/NXHGNxYrSIzo3o5KyQ9J9aki1 SqfASh33cbY9uMpR7Nm/mq1YbFd6r+pd0z0hyc+OMXcDOXWnRFq/ADcRq+HzrFRNezqs g2aMo0uXOHWrovaihyPgRj25cUdu0FE9zventm7GjSbYEXP/qbzT4M102xbtGt2wHpCk o2slepi5mThSeUsPIn9t6XeCJsYunU+jOn5p/Wtxc5qn7iqDs/J7ZvzmOkQfTVCpuKFC bSJQ== X-Gm-Message-State: APjAAAWs4JciKiNYVuO85tsFeq1odDm9RevHGK/UveZJ8hMdIPqhhVg9 wPyi0S+VhPptfemOrpg/dAw= X-Google-Smtp-Source: APXvYqyjA8lxM+r8BZSmmRljaWrEPojIgBmalQfNSBrTkh2E9Mmhrlz6CBQFNG9G8OLYZUhB0Qz3Nw== X-Received: by 2002:ac2:4430:: with SMTP id w16mr14972736lfl.35.1558903691999; Sun, 26 May 2019 13:48:11 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id i187sm1859475lfe.64.2019.05.26.13.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 13:48:11 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH 1/5] media: ov6650: Fix V4L2_SEL_FLAG_KEEP_CONFIG handling Date: Sun, 26 May 2019 22:47:54 +0200 Message-Id: <20190526204758.1904-2-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526204758.1904-1-jmkrzyszt@gmail.com> References: <20190526204758.1904-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This flag is now ignored - output frame size is affected by new crop settings regardless of the flag value. Fix it. Since keeping output frame size untouched while applying new crop settings is not supported, simply return results of .get_selection() if V4L2_SEL_FLAG_KEEP_CONFIG is passed to .set_selection(). Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index c728f718716b..1b02479b616f 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -484,6 +484,10 @@ static int ov6650_set_selection(struct v4l2_subdev *sd, sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; + /* No support for changing crop rectangle with frame size preserved */ + if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) + return ov6650_get_selection(sd, cfg, sel); + v4l_bound_align_image(&sel->r.width, 2, W_CIF, 1, &sel->r.height, 2, H_CIF, 1, 0); v4l_bound_align_image(&sel->r.left, DEF_HSTRT << 1, From patchwork Sun May 26 20:47:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10961881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EA7D13AD for ; Sun, 26 May 2019 20:48:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E3EE28A74 for ; Sun, 26 May 2019 20:48:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 328EB28A92; Sun, 26 May 2019 20:48:37 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8D4428A74 for ; Sun, 26 May 2019 20:48:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbfEZUsP (ORCPT ); Sun, 26 May 2019 16:48:15 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45381 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbfEZUsP (ORCPT ); Sun, 26 May 2019 16:48:15 -0400 Received: by mail-lj1-f193.google.com with SMTP id r76so2120651lja.12; Sun, 26 May 2019 13:48:14 -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 :mime-version:content-transfer-encoding; bh=Yx1xMRaM6E8Nc7cDm7I5aJSojnIVrzlfHniVdC7mgZM=; b=NaSCG09kgCfM525wIDxNzdNP3ZIh9qVU2HoElxhryrOQR7JhlzBSF3mhGMRinPGEYo pUk/bGXnkU0R66MZx9ygsUje+oeCntM78jvBDHsz0C0ylujt8utOk0aDFetJDZHmTIqs fvaQQRIEZfixaH34rsX24HXFxHzG8q8Nv7MOrszyN7DNgoMDNNmq+LxgO9xhmOes82Yh 13lEZjE/hEq87YWyyWR/W+Nb4fNWbTMWMnvJu9N0PwDZyMKbNa0NgZYkIAsWETA+cWEu /9KdITGQ0DJJ+6cheBvuaT/YOxdA9BpD+FdzhFrVf2Ul4NF8qoytNKRcpaS9U9K5WBiQ 9Yuw== 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:mime-version:content-transfer-encoding; bh=Yx1xMRaM6E8Nc7cDm7I5aJSojnIVrzlfHniVdC7mgZM=; b=pC6BABpnrpQCcaVNpDESY3CEnqI5JgQ5WNcW5GI5KJcSe2oGVXWDqFJLdRUU0jN8Zu yymKOFWXkBzR0NRDhMLrCFPQDwX1NGDGDqwYukAkXlEsPsEN9HMB/12aVJa8KF6oDgZ7 x+7kPYYQJoYoizEoZjXasHCgOQm1uZl2jx5lohuPTivVDORyB0L0uCFDkFWCqbWRpYQc z8QH4F9ZqpGvwYTX/DBLzITzIVw7kBQRkfkAsf6JqTxuBRTKMeZQqwUwlJmuxhSA2dbg fcpnXgMBO+O/oCs8G71j/z7bPTJTiFCH6owyMnK8AHhZd/lUCKfOKtkB6U9WFEMXo5fg k6Ug== X-Gm-Message-State: APjAAAWmXFUQpt/8ag2jwlfiL44gHWseNJI6NwvTl24Jx+WC9e+h/EiL M57UyIMLmHd3I8YLJ3MP6Ac= X-Google-Smtp-Source: APXvYqy4K3OXlf0fm1AbMZwyV7Raqtcu50PZoucXv9BRVqbBfKcd7S1k1c+cjzyNhauyNYUmrHOzTQ== X-Received: by 2002:a2e:960e:: with SMTP id v14mr7851486ljh.31.1558903693154; Sun, 26 May 2019 13:48:13 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id i187sm1859475lfe.64.2019.05.26.13.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 13:48:12 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH 2/5] media: ov6650: Refactor ov6650_s_fmt() helper Date: Sun, 26 May 2019 22:47:55 +0200 Message-Id: <20190526204758.1904-3-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526204758.1904-1-jmkrzyszt@gmail.com> References: <20190526204758.1904-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver suffers from a few compliance and implementation issues: - crop rectangle is affected by .set_fmt() pad operation callback, - frame scaling is not reset on modification of crop rectangle, - V4L2_SUBDEV_FORMAT_TRY support in .set_fmt() uses active crop rectangle, not the one from a pad config, as a reference. For easy resolution of those issues, ov6650_s_fmt() will first be refactored. The ov6650_s_fmt() helper function, mostly called form .set_fmt() pad operation callback, now takes a decision if half scaling is applicable for current crop rectangle and requested frame size, then possibly adjusts hardware crop settings, frame scaling and media bus frame format. It accepts a struct v4l2_mbus_framefmt argument passed by a user to .set_fmt(). Move the decision on applicability of half scaling up to .set_fmt(), then modify the ov6650_s_fmt() API so it accepts a half scaling flag. In order to avoid passing full struct v4l2_mbus_framefmt argument to it when called from functions other than .set_fmt(), also accept a target pixel code as an argument and make the struct v4l2_mbus_framefmt used for crop rectangle modification optional. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index 1b02479b616f..8cb30f3e4851 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -570,25 +570,18 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe, } /* set the format we will capture in */ -static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) +static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf, + u32 code, bool half_scale) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); - bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); struct v4l2_subdev_selection sel = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, .target = V4L2_SEL_TGT_CROP, - .r.left = priv->rect.left + (priv->rect.width >> 1) - - (mf->width >> (1 - half_scale)), - .r.top = priv->rect.top + (priv->rect.height >> 1) - - (mf->height >> (1 - half_scale)), - .r.width = mf->width << half_scale, - .r.height = mf->height << half_scale, }; - u32 code = mf->code; unsigned long mclk, pclk; u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask, clkrc; - int ret; + int ret = 0; /* select color matrix configuration for given color encoding */ switch (code) { @@ -668,7 +661,16 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", mclk / pclk, 10 * mclk % pclk / pclk); - ret = ov6650_set_selection(sd, NULL, &sel); + if (mf) { + sel.r.left = priv->rect.left + (priv->rect.width >> 1) - + (mf->width >> (1 - half_scale)), + sel.r.top = priv->rect.top + (priv->rect.height >> 1) - + (mf->height >> (1 - half_scale)), + sel.r.width = mf->width << half_scale, + sel.r.height = mf->height << half_scale, + + ret = ov6650_set_selection(sd, NULL, &sel); + } if (!ret) ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask); if (!ret) @@ -691,11 +693,14 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf = &format->format; struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); + bool half_scale; if (format->pad) return -EINVAL; - if (is_unscaled_ok(mf->width, mf->height, &priv->rect)) + half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); + + if (!half_scale) v4l_bound_align_image(&mf->width, 2, W_CIF, 1, &mf->height, 2, H_CIF, 1, 0); @@ -730,7 +735,7 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd, } else { /* apply new media bus format code and frame size */ - int ret = ov6650_s_fmt(sd, mf); + int ret = ov6650_s_fmt(sd, mf, mf->code, half_scale); if (ret) return ret; @@ -885,11 +890,8 @@ static int ov6650_video_probe(struct v4l2_subdev *sd) ret = ov6650_reset(client); if (!ret) ret = ov6650_prog_dflt(client); - if (!ret) { - struct v4l2_mbus_framefmt mf = ov6650_def_fmt; - - ret = ov6650_s_fmt(sd, &mf); - } + if (!ret) + ret = ov6650_s_fmt(sd, NULL, ov6650_def_fmt.code, false); if (!ret) ret = v4l2_ctrl_handler_setup(&priv->hdl); From patchwork Sun May 26 20:47:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10961877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 504B11390 for ; Sun, 26 May 2019 20:48:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FB9D28A74 for ; Sun, 26 May 2019 20:48:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 341D328A92; Sun, 26 May 2019 20:48:30 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACC5428A74 for ; Sun, 26 May 2019 20:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726126AbfEZUsS (ORCPT ); Sun, 26 May 2019 16:48:18 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42922 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725813AbfEZUsR (ORCPT ); Sun, 26 May 2019 16:48:17 -0400 Received: by mail-lf1-f65.google.com with SMTP id y13so10562112lfh.9; Sun, 26 May 2019 13:48:15 -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 :mime-version:content-transfer-encoding; bh=U0IfYdmtpVovrAyM/FdLov7do6Ak4PuwSIViICDb5F4=; b=p22jOLCuVZ+qXsuY7U1ysdkCSJg+JRnmU5odVwYC1M1ce7Xx8fCa3VXBzJX2MqFQdR 699Y3L8F1feuK1SNnCzSLqCH/sovq4a2OmwRM5CCp/JTn6DxlNQEhJXYRVq22r8Dvmxl rSQDCeIbyTUniqerCO1Zd4XiDWWPPQ1YCld9TgpyTdflQHwW1nYL1N5fQu3kKqH18P9y IUfLIkSZkPZ0Cc23NqfAtWxuXL0w4z/KPU4/RWLqA+WLKKUL9OIgdgmEjOYq9OaL6O3c DSU3tzI4HRuCSwoKgAMnBqztZFGPNMmRWVxrPqK2RTUrFtUedW/WtH8HSSe883dRGiDe TLPA== 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:mime-version:content-transfer-encoding; bh=U0IfYdmtpVovrAyM/FdLov7do6Ak4PuwSIViICDb5F4=; b=qLB5Jqx7FxkVnjnWo4kXl7k8tfL7ex8lnpSgCBBQ9uBLIofFEZULCQX/PD7ru3FX0G q9HqQ+5IPUSXPitNjpUwq3sLg3nclyLgGr6dzZEj8OW8TwlxurT7YJrmW9vElly+RhEp 5mceQ/fWwRFzhhm8evaICXCgWaCzXTEpZ8k+NPuihHxehQszJPnxy65FA6vo/ds5AEPj 9nq5bR4ZKwjahtqS2jt6kTPHimP15QwMA1myLC0KRZas2K/FcVwkF0GLgcZtJP78HwGt 5iFQ3yEBLnZHCS7SadbQ2VvGNN/HuJz7uSgVbxnUEnsKyGsArECqcIhW4MaYLNqZPPmO nGKg== X-Gm-Message-State: APjAAAXpQRZf/cG07dwzZmWPEKMZWhbafjfA/YgtyPcI6hDgNvdRJ128 9j/lWttgqWfmRfJH1fExiw8= X-Google-Smtp-Source: APXvYqz/yzgw1Vxskxu3LN3jWegAz0RuH7Ph8emqaSgldOaz7ANsn5hKN9GEIs5hbERzBQ9Z2YPcvA== X-Received: by 2002:a05:6512:6c:: with SMTP id i12mr39405009lfo.130.1558903694657; Sun, 26 May 2019 13:48:14 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id i187sm1859475lfe.64.2019.05.26.13.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 13:48:14 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH 3/5] media: ov6650: Fix active crop rectangle affected by .set_fmt() Date: Sun, 26 May 2019 22:47:56 +0200 Message-Id: <20190526204758.1904-4-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526204758.1904-1-jmkrzyszt@gmail.com> References: <20190526204758.1904-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to subdevice interface specification found in V4L2 API documentation, .set_fmt() pad operation callback should not affect image geometry set in preceding image processing steps. Unfortunately, ov6650_s_fmt() helper, when called from .set_fmt() with new user requested frame size passed to it, does not respect that requirement as that was not the case before, when the helper was still called from .mbus_set_fmt() video operation callback. Remmove a call to .set_selection() from ov6650_s_fmt() helper so it no longer modifies the active crop rectangle and simplify its API by removing no longer needed struct v4l2_mbus_framefmt argument. For consistency of its results with active format processing, also update try format path inside .set_fmt() (still using active crop rectangle as a reference instead of the try one from pad config which is not yet maintained by the driver). Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index 8cb30f3e4851..47590cd51190 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -570,15 +570,10 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe, } /* set the format we will capture in */ -static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf, - u32 code, bool half_scale) +static int ov6650_s_fmt(struct v4l2_subdev *sd, u32 code, bool half_scale) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); - struct v4l2_subdev_selection sel = { - .which = V4L2_SUBDEV_FORMAT_ACTIVE, - .target = V4L2_SEL_TGT_CROP, - }; unsigned long mclk, pclk; u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask, clkrc; int ret = 0; @@ -661,18 +656,7 @@ static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf, dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", mclk / pclk, 10 * mclk % pclk / pclk); - if (mf) { - sel.r.left = priv->rect.left + (priv->rect.width >> 1) - - (mf->width >> (1 - half_scale)), - sel.r.top = priv->rect.top + (priv->rect.height >> 1) - - (mf->height >> (1 - half_scale)), - sel.r.width = mf->width << half_scale, - sel.r.height = mf->height << half_scale, - - ret = ov6650_set_selection(sd, NULL, &sel); - } - if (!ret) - ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask); + ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask); if (!ret) ret = ov6650_reg_write(client, REG_CLKRC, clkrc); if (!ret) { @@ -700,10 +684,6 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd, half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); - if (!half_scale) - v4l_bound_align_image(&mf->width, 2, W_CIF, 1, - &mf->height, 2, H_CIF, 1, 0); - switch (mf->code) { case MEDIA_BUS_FMT_Y10_1X10: mf->code = MEDIA_BUS_FMT_Y8_1X8; @@ -723,8 +703,8 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd, if (format->which == V4L2_SUBDEV_FORMAT_TRY) { /* store media bus format code and frame size in pad config */ - cfg->try_fmt.width = mf->width; - cfg->try_fmt.height = mf->height; + cfg->try_fmt.width = priv->rect.width >> half_scale; + cfg->try_fmt.height = priv->rect.height >> half_scale; cfg->try_fmt.code = mf->code; /* return default mbus frame format updated with pad config */ @@ -735,7 +715,7 @@ static int ov6650_set_fmt(struct v4l2_subdev *sd, } else { /* apply new media bus format code and frame size */ - int ret = ov6650_s_fmt(sd, mf, mf->code, half_scale); + int ret = ov6650_s_fmt(sd, mf->code, half_scale); if (ret) return ret; @@ -891,7 +871,7 @@ static int ov6650_video_probe(struct v4l2_subdev *sd) if (!ret) ret = ov6650_prog_dflt(client); if (!ret) - ret = ov6650_s_fmt(sd, NULL, ov6650_def_fmt.code, false); + ret = ov6650_s_fmt(sd, ov6650_def_fmt.code, false); if (!ret) ret = v4l2_ctrl_handler_setup(&priv->hdl); From patchwork Sun May 26 20:47:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10961879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27E2D13AD for ; Sun, 26 May 2019 20:48:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18A5928A74 for ; Sun, 26 May 2019 20:48:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CF3628A92; Sun, 26 May 2019 20:48: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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3F9128A74 for ; Sun, 26 May 2019 20:48:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726202AbfEZUsa (ORCPT ); Sun, 26 May 2019 16:48:30 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41151 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbfEZUsS (ORCPT ); Sun, 26 May 2019 16:48:18 -0400 Received: by mail-lj1-f196.google.com with SMTP id q16so4530021ljj.8; Sun, 26 May 2019 13:48:16 -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 :mime-version:content-transfer-encoding; bh=yxy8jhb7vj4f583mX+9bjwUeoCyJQOsv4k9GjkXUQ2g=; b=h6tdj+sL53sdFiNAj75lH6fUo0CsOzTPQ7xv1AERtT/h1WVe35E4pq/nB90f9V/C+v WHORIAj3z4FRPd24Z2dwdelOP5Yf05LMyqDj5HGxWqNXp50gGmyFnAXVZFCg7uhOEM8J 7dJRsJ4htsB3CDvLc6j+GbjBe88DML8fUMdpFzYpFTYNg5icFqxfRJEi8aimcrUc7QiY MQZbDjfUfvC60XnIwlMoqYInsEZn9P+iDMKfGQIDMFRNo6j4GPfKD17sSprcD/Oxa491 lCvEVEhZKZGNePdbgFhtpolAfYzL0IrfCzqCsc55FUUXf2yk4D5sNMD4Ym6JHg/jpQNn p5qg== 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:mime-version:content-transfer-encoding; bh=yxy8jhb7vj4f583mX+9bjwUeoCyJQOsv4k9GjkXUQ2g=; b=Yc9F4mB1xhp8voF8CxhXMe6AJU2HWZMh/DxFdNV+sCyhtSg1X8MSLJ9Irq88h3inX0 yU3DgiuvfqSGuXh5iLmniKa187Xrd2CaTJzcK1aq4Vd/FtegDEhJSv+dAt++k8eFijV7 Ty7w38st/ciwOMytF0wWaantMaCpe62P/a61HT2siZYS2CRc+lDkF+yn72SDTxPTG609 TuuMsIwyH5rY3TmwOSa+36Edqm5GQHz40K/n7tbQ7ReEP8mnypbd59zCdvin/0Vh56V5 z8YbSozILYalMrXnnM7awCfQSdk22+UU21EC+x+8cSJR0ajrRhCOcAyl+sQAi14WnAm2 e8Og== X-Gm-Message-State: APjAAAWlQ7NPrRRh9h1/vjz555DzD0+u1a5l62Wd3BR3AotqgVLSgcJ5 zLLwGN1xA7DUdbx/PVUvesM= X-Google-Smtp-Source: APXvYqxdqLj3Qk75k2XIFwOaySBHWie+VHdFb+eGV2zH1WXrGaxvKJfUF+5xAiND0OBA1r98FCNhEQ== X-Received: by 2002:a2e:900e:: with SMTP id h14mr39180739ljg.77.1558903696049; Sun, 26 May 2019 13:48:16 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id i187sm1859475lfe.64.2019.05.26.13.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 13:48:15 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH 4/5] media: ov6650: Fix frame scaling not reset on crop Date: Sun, 26 May 2019 22:47:57 +0200 Message-Id: <20190526204758.1904-5-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526204758.1904-1-jmkrzyszt@gmail.com> References: <20190526204758.1904-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to V4L2 subdevice interface specification, frame scaling factors should be reset to default values on modification of input frame format. Assuming that requirement also applies in case of crop rectangle modification unless V4L2_SEL_FLAG_KEEP_CONFIG is requested, the driver now does not respect it. The KEEP_CONFIG case is already implemented, fix the other path. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index 47590cd51190..cc70d8952999 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -472,6 +472,8 @@ static int ov6650_get_selection(struct v4l2_subdev *sd, } } +static int ov6650_s_fmt(struct v4l2_subdev *sd, u32 code, bool half_scale); + static int ov6650_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) @@ -515,7 +517,13 @@ static int ov6650_set_selection(struct v4l2_subdev *sd, } if (!ret) priv->rect.height = sel->r.height; + else + return ret; + if (priv->half_scale) { + /* turn off half scaling, preserve media bus format */ + ret = ov6650_s_fmt(sd, priv->code, false); + } return ret; } From patchwork Sun May 26 20:47:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10961875 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BFA0013AD for ; Sun, 26 May 2019 20:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 956E828A7D for ; Sun, 26 May 2019 20:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 848A328A74; Sun, 26 May 2019 20:48:29 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HK_RANDOM_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1713628A74 for ; Sun, 26 May 2019 20:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726165AbfEZUsX (ORCPT ); Sun, 26 May 2019 16:48:23 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:38187 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbfEZUsT (ORCPT ); Sun, 26 May 2019 16:48:19 -0400 Received: by mail-lf1-f68.google.com with SMTP id b11so4172950lfa.5; Sun, 26 May 2019 13:48:18 -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 :mime-version:content-transfer-encoding; bh=+x6WG6WqbSoE6WUEpqF/4MvaYXvmZDdI8YQeSR6pdD8=; b=FJZ3qf3EdxoSTq8Zw6mow2R8CM8rKNPwCia7dpfuJr79mWc3Y+l7Yd3oBMtj9rZYJY EGSE8r5UI81ttNQpJaIUxQtFAh+mI1onGNQKJv93No1Tdv8I9NwJQOOVnpbCVcq84fcw tbkEDyYx0xRfMs7EUkVSYcoR8Co+J6CxYIGlyUOw4pQLT6/BlWA8gMd73HYkxzwNCDiF ryy4Tp77LPg1LrdUdteoodZ9kmogF/Ttp2Iodgp9ifY635nu0dxg4kdQKCEjZeTQxNVp 8ZnB/J1DBuIuR0zGAlHs9yZJ1gAVwwLpY9+PmXtwHGTSRx5UiDhd6OgfZUPFQbYSyIsR PjpA== 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:mime-version:content-transfer-encoding; bh=+x6WG6WqbSoE6WUEpqF/4MvaYXvmZDdI8YQeSR6pdD8=; b=o7m3nWoF1iDR6unuRMj71Rdxf4brEOp7QqjYwvJs4jJsjrnDdOBttacTBnJQotr2tl 6Q1D93B1ocWVWtQ7yhaXW01s7YPItr+Wdvp+NeINv5Vvua8nqIx+p59rcTFJGbrFv3+U W28eFSg7FhJCw8QFl7z6BvICtNEZBRKOGnoT2zQA7sPYSfhrbvaMcdkkiIW1saCPu4hn IllwGAsMIxGxUX+ylhIOVfYmgD3Z2gzydrw0i6FUwByPI3PQrF+QTgD7hBPesQtRWbHV JkDOBz4YwpKBPtlK0230RXMyIF9+J3XzjNwbE9ylml62uO+JEQK1zSotjF59mgcsy6mq a+rQ== X-Gm-Message-State: APjAAAV1lFN1POVvVaFplSH7Uq6u8H0dJoa7dsnFw5cJO+bMErW9qbwi DQWgEw9zPDu8wPTveZ+0cxE= X-Google-Smtp-Source: APXvYqxEZxbj0cvy32Qo1Uc8bigNO+ua0rKsDLgeke2jkdcJeBuoF1/4drlztU40NHIxnsyUaLRU3g== X-Received: by 2002:a19:2247:: with SMTP id i68mr719938lfi.174.1558903697319; Sun, 26 May 2019 13:48:17 -0700 (PDT) Received: from z50.gdansk-morena.vectranet.pl (109241207190.gdansk.vectranet.pl. [109.241.207.190]) by smtp.gmail.com with ESMTPSA id i187sm1859475lfe.64.2019.05.26.13.48.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 13:48:16 -0700 (PDT) From: Janusz Krzysztofik To: Mauro Carvalho Chehab Cc: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Janusz Krzysztofik Subject: [RFC PATCH 5/5] media: ov6650: Add .init_cfg() pad operation callback Date: Sun, 26 May 2019 22:47:58 +0200 Message-Id: <20190526204758.1904-6-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190526204758.1904-1-jmkrzyszt@gmail.com> References: <20190526204758.1904-1-jmkrzyszt@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver now supports V4L2_SUBDEV_FORMAT_TRY operation mode only in .get/set_fmt() pad operation callbacks. That means only .try_format member of pad config is maintained. As a consequence, active crop rectangle is used as a referece while V4L2_SUBDEV_FORMAT_TRY requests are processed. In order to fix that, a method for initialization of .try_crop pad config member is needed. Implement .init_cfg() pad operation callback which initializes the pad config from current active format and selection settings. From now on, and before the driver V4L2_SUBDEV_FORMAT_TRY support is further modified, host interface drivers should call .init_cfg() on a pad config before passing it to V4L2_SUBDEV_FORMAT_TRY operations. Signed-off-by: Janusz Krzysztofik --- drivers/media/i2c/ov6650.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/media/i2c/ov6650.c b/drivers/media/i2c/ov6650.c index cc70d8952999..c3d4c1f598b2 100644 --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -447,6 +447,26 @@ static int ov6650_s_power(struct v4l2_subdev *sd, int on) return ret; } +static int ov6650_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + struct v4l2_mbus_framefmt *mf; + struct v4l2_rect *rect; + + mf = &cfg->try_fmt; + *mf = ov6650_def_fmt; + mf->width = priv->rect.width >> priv->half_scale; + mf->height = priv->rect.height >> priv->half_scale; + mf->code = priv->code; + + rect = &cfg->try_crop; + *rect = priv->rect; + + return 0; +} + static int ov6650_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_selection *sel) @@ -959,6 +979,7 @@ static const struct v4l2_subdev_video_ops ov6650_video_ops = { }; static const struct v4l2_subdev_pad_ops ov6650_pad_ops = { + .init_cfg = ov6650_init_cfg, .enum_mbus_code = ov6650_enum_mbus_code, .get_selection = ov6650_get_selection, .set_selection = ov6650_set_selection,