Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5489086ioo; Wed, 1 Jun 2022 06:39:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr1DH6W5prpoiLcdlAUCsRV4XEZ3QdO+o2ywAlBNaeLtEj5XJsPJske1kisCDhvYhaCV9u X-Received: by 2002:a05:6402:e0c:b0:42d:7f16:ac2c with SMTP id h12-20020a0564020e0c00b0042d7f16ac2cmr25410727edh.328.1654090782441; Wed, 01 Jun 2022 06:39:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654090782; cv=none; d=google.com; s=arc-20160816; b=Acivn0CiaQIPokwRxWiGWbBlDLvBK0kLABnsHWLL10tfeDj9ariNPkgEfvYRaBkONL F1F+WdF/YT6L/N9vnEsDG/r7yj0Rd8izxHw9q8JR1KGsn/SWgTwbOBz8zTMpOZzKnw8q g3iWEKLEJmFhzfW1SJk/xAmrnXbWFDWj5gAoNmtJN09XEBAlV2m31SfQ82Qn1Gvb9ATE L4z50cY1m1Cq9thR4QJ5esWxiksD6v8UqY4zFt+QBTOAdmpAUeCk/8t4n1PCkU93DXkc 10LGNHfYaG23vGy7FKClwRGNbwas8RCOFZAV/8Mz4EDJZ3S/SQOYmXechGtKtSIGEALk 4ZQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=QJDdfhA0NzR5jw3IlIe483LSvhqRybcPEd5rgzmzwn4=; b=ehCQVwclaMb9Rlo30d98raA+RtEYUXRQtopseZm2mNNoF3SUBsHUiaVcr7OXqZbHLD b2fP2qNEkye7oERZiqP51z9oh7UHjkgViqepdO9bdbZF6PXtC3SyCfr5Nswfe2JRO842 PeMvajWq6e1jrhOa54XcaXJHpRY9ZVGCFsukIZtsYjEG6VUQaDCLhP8ugx+tOCAjFHtL KI/zQRV93UdkBjmy8lDcXZ1/SixPchpUJdgE9x8q19IucKQKdHcu175fqnn+RCfd7yVa BJ9Wuup4lH89Jv8/RYj9OF98dFieEsJ+46dK2YKDEPZ/TGO0iCcf/YU2N/TXzfgYncy3 nSAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr6-20020a170907720600b006ff151d090fsi1926551ejc.937.2022.06.01.06.39.15; Wed, 01 Jun 2022 06:39:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343561AbiEaKuZ (ORCPT + 99 others); Tue, 31 May 2022 06:50:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233804AbiEaKuU (ORCPT ); Tue, 31 May 2022 06:50:20 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58BC190CC8; Tue, 31 May 2022 03:50:18 -0700 (PDT) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 2186B1C0006; Tue, 31 May 2022 10:50:13 +0000 (UTC) Date: Tue, 31 May 2022 12:50:11 +0200 From: Jacopo Mondi To: Quentin Schulz Cc: shawnx.tu@intel.com, mchehab@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Quentin Schulz Subject: Re: [PATCH v5 4/4] media: i2c: ov5675: add .get_selection support Message-ID: <20220531105011.yxrosmwtw3mpaomb@uno.localdomain> References: <20220525145833.1165437-1-foss+kernel@0leil.net> <20220525145833.1165437-4-foss+kernel@0leil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220525145833.1165437-4-foss+kernel@0leil.net> X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_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 Hi Quentin On Wed, May 25, 2022 at 04:58:33PM +0200, Quentin Schulz wrote: > From: Quentin Schulz > > The sensor has 2592*1944 active pixels, surrounded by 16 active dummy > pixels and there are an additional 24 black rows "at the bottom". > > [2624] > +-----+------------------+-----+ > | | 16 dummy | | > +-----+------------------+-----+ > | | | | > | | [2592] | | > | | | | > |16 | valid | 16 |[2000] > |dummy| |dummy| > | | [1944]| | > | | | | > +-----+------------------+-----+ > | | 16 dummy | | > +-----+------------------+-----+ > | | 24 black lines | | > +-----+------------------+-----+ > > The top-left coordinate is gotten from the registers specified in the > modes which are identical for both currently supported modes. > > Signed-off-by: Quentin Schulz > --- > > v4: > - explicit a bit more the commit log, > - added drawing in the commit log, > - fixed reporting for V4L2_SEL_TGT_CROP_* thanks to Jacopo's help, > > added in v3 > > drivers/media/i2c/ov5675.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c > index c1f3c387afde0..384a9ea2372c3 100644 > --- a/drivers/media/i2c/ov5675.c > +++ b/drivers/media/i2c/ov5675.c > @@ -1121,6 +1121,38 @@ static int ov5675_get_format(struct v4l2_subdev *sd, > return 0; > } > > +static int ov5675_get_selection(struct v4l2_subdev *sd, > + struct v4l2_subdev_state *state, > + struct v4l2_subdev_selection *sel) > +{ > + struct ov5675 *ov5675 = to_ov5675(sd); > + > + if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) > + return -EINVAL; > + > + switch (sel->target) { > + case V4L2_SEL_TGT_CROP_BOUNDS: > + sel->r.top = 0; > + sel->r.left = 0; > + sel->r.width = 2624; > + sel->r.height = 2000; > + return 0; > + case V4L2_SEL_TGT_CROP: > + sel->r.top = 16; > + sel->r.left = 16; > + sel->r.width = ov5675->cur_mode->width; > + sel->r.height = ov5675->cur_mode->height; > + return 0; I'm afraid this doesn't match exactly my understanding of the discussion we had. The driver defines the following modes /* * OV5670 sensor supports following resolutions with full FOV: * 4:3 ==> {2592x1944, 1296x972, 648x486} * 16:9 ==> {2560x1440, 1280x720, 640x360} */ static const struct ov5670_mode supported_modes[] = { { .width = 2592, .height = 1944, }, { .width = 1296, .height = 972, }, { .width = 648, .height = 486, }, { .width = 2560, .height = 1440, }, { .width = 1280, .height = 720, }, { .width = 640, .height = 360, } }; The comment says all modes retain the "full FOV", which I assume it implies they are obtained by sub-sampling and not cropping. The first three modes (4:3) are indeed obtained by subsampling the full active pixel array: (2592,1944) / 2 = (1296,972) / 2 = (648,486) The last three are obtained by subsampling a slightly cropped portion of the pixel array (2560,1440) / 2 = (1280,720) / 2 = (640,360) If you set CROP = cur_mode->[width/height] you will instead report the visible width/height, which as said it's obtained by subsampling (of a slightly cropped portion of the pixel array for the last three ones) The CROP rectangle is then (2592, 1944) for the first three and (2560, 1440) for the last three. I would add a v4l2_rect to struct ov5670_mode where to record that and report it here. > + case V4L2_SEL_TGT_CROP_DEFAULT: > + sel->r.top = 16; > + sel->r.left = 16; > + sel->r.width = supported_modes[0].width; > + sel->r.height = supported_modes[0].height; > + return 0; You could also define these values instead of fishing in the supported_modes array, to protect against future changes to the array itself. Up to you. > + } > + return -EINVAL; > +} > + > static int ov5675_enum_mbus_code(struct v4l2_subdev *sd, > struct v4l2_subdev_state *sd_state, > struct v4l2_subdev_mbus_code_enum *code) > @@ -1170,6 +1202,7 @@ static const struct v4l2_subdev_video_ops ov5675_video_ops = { > static const struct v4l2_subdev_pad_ops ov5675_pad_ops = { > .set_fmt = ov5675_set_format, > .get_fmt = ov5675_get_format, > + .get_selection = ov5675_get_selection, > .enum_mbus_code = ov5675_enum_mbus_code, > .enum_frame_size = ov5675_enum_frame_size, > }; > -- > 2.36.1 >