From patchwork Wed Aug 2 17:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 709453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58AF9C04A94 for ; Wed, 2 Aug 2023 17:36:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232435AbjHBRgN (ORCPT ); Wed, 2 Aug 2023 13:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232429AbjHBRfw (ORCPT ); Wed, 2 Aug 2023 13:35:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93E03598 for ; Wed, 2 Aug 2023 10:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690997515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k/nFqXA0wtAvy1b9IydNoKSYHTK903b7QUEoHi0uMCE=; b=UyY3DrzsavZXRkm1evG8sZdleYnNKjsou9p/wlyE27vqiL0qHNc+34WsppT7vW1+C0+/Nl PQ9L+gu0Czf7duDA9pFmMsf3b+3Je0O6tr2RCxjJFRsXi/xiIgYbk97lJkkqPr7VWVZN8c 8CBxSV9Hb4Wul0hlVoczWrGzTLpjOM0= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-690-fBSraxxIMduMaswfLSW8ig-1; Wed, 02 Aug 2023 13:31:50 -0400 X-MC-Unique: fBSraxxIMduMaswfLSW8ig-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D5A728EA6E4; Wed, 2 Aug 2023 17:31:49 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1116B140E949; Wed, 2 Aug 2023 17:31:47 +0000 (UTC) From: Hans de Goede To: Sakari Ailus , Laurent Pinchart , Rui Miguel Silva , Daniel Scally Cc: Hans de Goede , Mauro Carvalho Chehab , Andy Shevchenko , Kate Hsuan , Dave Stevenson , Tommaso Merciai , linux-media@vger.kernel.org Subject: [PATCH v4 24/32] media: ov2680: Fix exposure and gain ctrls range and default value Date: Wed, 2 Aug 2023 19:30:38 +0200 Message-ID: <20230802173046.368434-25-hdegoede@redhat.com> In-Reply-To: <20230802173046.368434-1-hdegoede@redhat.com> References: <20230802173046.368434-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The exposure control's max effective value is VTS - 8, set the control range to match this. Thas means that if/when a future commit makes VTS configurable as a control itself the exposure range needs to be updated dynamically to match the VTS value. The gain control goes from 0 - 1023, higher values wrap around to the lowest gain setting. The gain control, controls an analog gain so use V4L2_CID_ANALOGUE_GAIN for it instead of V4L2_CID_GAIN. Also stop setting 0 as default for both controls this leads to a totally black picture which is no good. This is esp. important for tests of the sensor driver without (userspace driven) auto exposure / gain. Acked-by: Rui Miguel Silva Reviewed-by: Daniel Scally Signed-off-by: Hans de Goede --- Changes in v4: - Use V4L2_CID_ANALOGUE_GAIN --- drivers/media/i2c/ov2680.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c index ecd99e6669bd..b251265594b0 100644 --- a/drivers/media/i2c/ov2680.c +++ b/drivers/media/i2c/ov2680.c @@ -81,6 +81,9 @@ /* If possible send 16 extra rows / lines to the ISP as padding */ #define OV2680_END_MARGIN 16 +/* Max exposure time is VTS - 8 */ +#define OV2680_INTEGRATION_TIME_MARGIN 8 + #define OV2680_DEFAULT_WIDTH 800 #define OV2680_DEFAULT_HEIGHT 600 @@ -779,7 +782,7 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl) } switch (ctrl->id) { - case V4L2_CID_GAIN: + case V4L2_CID_ANALOGUE_GAIN: ret = ov2680_gain_set(sensor, ctrl->val); break; case V4L2_CID_EXPOSURE: @@ -849,6 +852,7 @@ static int ov2680_v4l2_register(struct ov2680_dev *sensor) const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops; struct ov2680_ctrls *ctrls = &sensor->ctrls; struct v4l2_ctrl_handler *hdl = &ctrls->handler; + int exp_max = OV2680_LINES_PER_FRAME - OV2680_INTEGRATION_TIME_MARGIN; int ret = 0; v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_subdev_ops); @@ -874,9 +878,10 @@ static int ov2680_v4l2_register(struct ov2680_dev *sensor) 0, 0, test_pattern_menu); ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, - 0, 32767, 1, 0); + 0, exp_max, 1, exp_max); - ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN, 0, 2047, 1, 0); + ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, + 0, 1023, 1, 250); if (hdl->error) { ret = hdl->error;