Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp760140pxb; Tue, 5 Apr 2022 22:07:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXhkF5Gp7Y+/xkZ1GX6iY2Iu8tLws08ml93K3urHBJUjfLoQWL0cTTn04XEx0YrklBxeEL X-Received: by 2002:a17:90a:af8f:b0:1ca:7bce:ce3b with SMTP id w15-20020a17090aaf8f00b001ca7bcece3bmr8045220pjq.224.1649221655484; Tue, 05 Apr 2022 22:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649221655; cv=none; d=google.com; s=arc-20160816; b=WNlTZmyyBeFvE0WZWqB+F081MG/Xwn0zyWAiHW6yHOtTm+FnaSt+SRnUl55kLO6DsF 8/URAaPUg//uPuoB9Bzbe6h8Y2KLdI2ZifFbBrgrwSRxO+WrPKCQe0wDneJDcxdgjPBg XOLSovUSxM72riKyRQUhk2IHu4bLOrNu4nFiCLbB9L4j8G503Hs1Km3YOmu8hXfVjs6z pS02Qgzkaio2lAmnlvCnq61NlP0MGT6RznUoQZ6XGl9ABa+Gtu6WG3kShtdPBBalCyPU Wfs7tS+3LXD+9blC85xmLCHA85plehsRA3RLgQ3EEABbz8SQOvWZLg7gPpbSabzWbFg4 hpYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BOWcUY5Rwk5IUT4VhsSdvGQCu1iUZVi2A5Qd1qBMcz4=; b=VIDDpY1Cy57fGYAlxGEe7w17okq9lDUzUpqFaFLluY3D3AQdlR/jEjqfZsLr8HDor2 wMAHNufupBnXFtx5+y+SxEA3NQBDWXUOQgdUSjh3ZK8R5u59QGQOPPZ8LBXZfQYtO1qX HgCDelvp9RKi1uQ3rtGFW3+3hBTZtPfv/g21h/++TLRk+rd0Ya4ZpaHXL9FzCkwEyMGp 5tp2SAbkvNODBkqGoAHf5CL01UOd0Mr955Ue1LnKKjRo0LqyGloLBgEckslis/CJXc/n AIC2gGIQtIEIQBhSqsD3CR6DoJbOfYWqQNMCeVR/d10W9rLBpQApgTa02805X9Gp8GXp Tdgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I0A2X0Wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y5-20020a63ad45000000b003989e2bf080si14734492pgo.734.2022.04.05.22.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 22:07:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I0A2X0Wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 58F47190B70; Tue, 5 Apr 2022 20:31:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244803AbiDEN75 (ORCPT + 99 others); Tue, 5 Apr 2022 09:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238452AbiDEJ3Q (ORCPT ); Tue, 5 Apr 2022 05:29:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A09A13E10; Tue, 5 Apr 2022 02:16:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E4F5BB818F3; Tue, 5 Apr 2022 09:16:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A606C385A2; Tue, 5 Apr 2022 09:16:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150215; bh=JVi6iNnNgKNf/3WG5A4crMAJ/xLn832x/mT8K/pZK30=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0A2X0Wthm4P73W+IjsmhvdR0G1QZP4zABfhm2kI1xyUrbjG7aIdwqxUWXbuUq61M rYEEvhIs+UwquqkT7MDxGxgORrEjJRo1aaJoVx3JMqnN+zwt1pUeg/J0yt5AZ9LRUW EdBXZZVhA+oZ8VkhFYc8D5syIWcFyJVd7eJrn8H4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Janusz Krzysztofik , Sakari Ailus , Mauro Carvalho Chehab Subject: [PATCH 5.16 0994/1017] media: ov6650: Add try support to selection API operations Date: Tue, 5 Apr 2022 09:31:47 +0200 Message-Id: <20220405070423.709048356@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Janusz Krzysztofik commit c74052646496ffe0bc606152e6b9653137020cbf upstream. Try requests are now only supported by format processing pad operations implemented by the driver. The driver selection API operations currently respond to them with -EINVAL. While that is correct, it constraints video device drivers to not use subdevice cropping at all while processing user requested active frame size, otherwise their set try format results might differ from active. As a consequence, we can't fix set format pad operation as not to touch crop rectangle since that would affect users not being able to set arbitrary frame sizes. Moreover, without a working set try selection support we are not able to use pad config crop rectangle as a reference while processing set try format requests. Implement missing try selection support. Moreover, as it will be now possible to maintain the pad config crop rectangle via selection API, start using it instead of the active one as a reference while processing set try format requests. is_unscaled_ok() helper, now also called from set selection operation, has been just moved up in the source file to avoid a prototype, with no functional changes. [Sakari Ailus: Rebase on subdev state patches] Fixes: 717fd5b4907a ("[media] v4l2: replace try_mbus_fmt by set_fmt") Signed-off-by: Janusz Krzysztofik Signed-off-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/i2c/ov6650.c | 54 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-) --- a/drivers/media/i2c/ov6650.c +++ b/drivers/media/i2c/ov6650.c @@ -472,9 +472,16 @@ static int ov6650_get_selection(struct v { struct i2c_client *client = v4l2_get_subdevdata(sd); struct ov6650 *priv = to_ov6650(client); + struct v4l2_rect *rect; - if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { + /* pre-select try crop rectangle */ + rect = &sd_state->pads->try_crop; + + } else { + /* pre-select active crop rectangle */ + rect = &priv->rect; + } switch (sel->target) { case V4L2_SEL_TGT_CROP_BOUNDS: @@ -483,14 +490,22 @@ static int ov6650_get_selection(struct v sel->r.width = W_CIF; sel->r.height = H_CIF; return 0; + case V4L2_SEL_TGT_CROP: - sel->r = priv->rect; + /* use selected crop rectangle */ + sel->r = *rect; return 0; + default: return -EINVAL; } } +static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) +{ + return width > rect->width >> 1 || height > rect->height >> 1; +} + static void ov6650_bind_align_crop_rectangle(struct v4l2_rect *rect) { v4l_bound_align_image(&rect->width, 2, W_CIF, 1, @@ -510,12 +525,30 @@ static int ov6650_set_selection(struct v struct ov6650 *priv = to_ov6650(client); int ret; - if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE || - sel->target != V4L2_SEL_TGT_CROP) + if (sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; ov6650_bind_align_crop_rectangle(&sel->r); + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { + struct v4l2_rect *crop = &sd_state->pads->try_crop; + struct v4l2_mbus_framefmt *mf = &sd_state->pads->try_fmt; + /* detect current pad config scaling factor */ + bool half_scale = !is_unscaled_ok(mf->width, mf->height, crop); + + /* store new crop rectangle */ + *crop = sel->r; + + /* adjust frame size */ + mf->width = crop->width >> half_scale; + mf->height = crop->height >> half_scale; + + return 0; + } + + /* V4L2_SUBDEV_FORMAT_ACTIVE */ + + /* apply new crop rectangle */ ret = ov6650_reg_write(client, REG_HSTRT, sel->r.left >> 1); if (!ret) { priv->rect.width += priv->rect.left - sel->r.left; @@ -567,11 +600,6 @@ static int ov6650_get_fmt(struct v4l2_su return 0; } -static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) -{ - return width > rect->width >> 1 || height > rect->height >> 1; -} - #define to_clkrc(div) ((div) - 1) /* set the format we will capture in */ @@ -692,7 +720,11 @@ static int ov6650_set_fmt(struct v4l2_su break; } - *crop = priv->rect; + if (format->which == V4L2_SUBDEV_FORMAT_TRY) + *crop = sd_state->pads->try_crop; + else + *crop = priv->rect; + half_scale = !is_unscaled_ok(mf->width, mf->height, crop); /* adjust new crop rectangle position against its current center */