Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2576265rwb; Mon, 19 Sep 2022 07:06:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7rVrBAuF1i5IrGKGeizOveWvL1/gQiIBVIR/FdNatdcgjEydVJQvLnZLFPjG4MRo8Yjt8+ X-Received: by 2002:a05:6402:2756:b0:443:4a6d:f05a with SMTP id z22-20020a056402275600b004434a6df05amr15695241edd.396.1663596363807; Mon, 19 Sep 2022 07:06:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663596363; cv=none; d=google.com; s=arc-20160816; b=SC8ojZDG9rXu8NU+HFY9LHi8IzDPeAJK2IeZPSI7kADdZJ9UUsE20nMLObkFOXHRHj T3vyvBg6juDABdfHw0b96Mk1lkwKFPqS8xgIQI6y3BmxRjeh3IyphoPv+jPz183xUBsZ Pqi2ciEwLo6lRfl50x+9ZRgWPum/sLI+yjVyAEO3gNbX++ie0gzJLBG7O4jjKzknC7g6 fi+SQvJUbt701qJmTrGls6DcMwNcIrH1bUuYU18SgYGg57kvkIm9E27Im9UH6ZhCluGh V2bN4tfR7AlSa3gn36mTvjDJSEAi6YK+WZ9eVSKKI/k8ARkFxxHuA8BjsW8RjJVEkYy+ besQ== 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:dkim-signature; bh=OMujRWyv0Pv+i/7po1rQ7SZsgGGEGwWDRAQ9mIadCeA=; b=C6yDsmeo15nmHyN+ctgmBwXc553/GTue+Fb3lVLsFSh/kQOZtFJpXjWpU4AvtMiR7c YsQTPXWWmpwU3Keir5XqWjd4NO3zN6xZeITEWAhJtHV4k8+UHsEmHxNfyDJhgeXpKDqL V7tjt1eLFFXWnCBMHIZeqBTANBfN5xjHY80S5ubMdWuLXS37u1SvOzN/i1rVg9h3dIh6 L6BC/jiWz+C5HvERo7S5wXV4d+mLP1VGZKS2dsBXYxqowXMqHo8TPD+3imHfoqdOy8CY B3YXNsBc5A21lGg/5V9LI1Hy328Zn5VcN5jG40Xm/CeGcX/JWAT4n3KlBswVfEG1sryf 8BZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZrZP6r3x; 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 d10-20020aa7d5ca000000b0043999754363si7559293eds.516.2022.09.19.07.05.37; Mon, 19 Sep 2022 07:06:03 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZrZP6r3x; 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 S231152AbiISNtr (ORCPT + 99 others); Mon, 19 Sep 2022 09:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230154AbiISNtc (ORCPT ); Mon, 19 Sep 2022 09:49:32 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B3CF2DAA3; Mon, 19 Sep 2022 06:49:23 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E06D9BA; Mon, 19 Sep 2022 15:49:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1663595360; bh=N1LVG0MXObEOzn3wAb8ucps7CX6MhaStUY9Gll/LMYI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZrZP6r3x5Ai0F1Y3DZPRAorq0kuyTi7Kphb86o1+MgIxakQCZFkLY35TYczLuZbcX JnTDMYDaja2NkwTvQsJfcqLsa7wdr39DLxlbkXjG+trokP2E+JZxQBt41t3wJ21zin 5WcZ4H3K9RFp1OXDokRGtuVubRBWxyZibbHd77JI= Date: Mon, 19 Sep 2022 16:49:06 +0300 From: Laurent Pinchart To: Sakari Ailus Cc: Mikhail Rudenko , Dave Stevenson , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Hans Verkuil , Jacopo Mondi , Shawn Tu , Jimmy Su , Arnd Bergmann , Arec Kao , Marek Vasut , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 0/2] Add Omnivision OV4689 image sensor driver Message-ID: References: <20220911200147.375198-1-mike.rudenko@gmail.com> <87czbwp9xx.fsf@gmail.com> <87wn9zreic.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham 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 Hello, On Mon, Sep 19, 2022 at 10:31:02AM +0000, Sakari Ailus wrote: > On Mon, Sep 19, 2022 at 10:01:06AM +0300, Mikhail Rudenko wrote: > > On 2022-09-19 at 06:40 GMT, Sakari Ailus wrote: > > > On Fri, Sep 16, 2022 at 12:27:42AM +0300, Mikhail Rudenko wrote: > > >> On 2022-09-14 at 10:58 +01, Dave Stevenson wrote: > > >> > On Sun, 11 Sept 2022 at 21:02, Mikhail Rudenko wrote: > > >> >> > > >> >> Hello, > > >> >> > > >> >> this series implements support for Omnivision OV4689 image > > >> >> sensor. The Omnivision OV4689 is a high performance, 1/3-inch, 4 > > >> >> megapixel image sensor. Ihis chip supports high frame rate speeds up > > >> >> to 90 fps at 2688x1520 resolution. It is programmable through an I2C > > >> >> interface, and sensor output is sent via 1/2/4 lane MIPI CSI-2 > > >> >> connection. > > >> >> > > >> >> The driver is based on Rockchip BSP kernel [1]. It implements 4-lane CSI-2 > > >> >> and single 2688x1520 @ 30 fps mode. The driver was tested on Rockchip > > >> >> 3399-based FriendlyElec NanoPi M4 board with MCAM400 camera > > >> >> module. > > >> >> While porting the driver, I stumbled upon two issues: > > > > [snip] > > > > >> >> (2) The original driver exposes analog gain range 0x0 - 0x7ff, but the > > >> >> gain is not linear across that range. Instead, it is piecewise linear > > >> >> (and discontinuous). 0x0-0xff register values result in 0x-2x gain, > > >> >> 0x100-0x1ff to 0x-4x, 0x300-0x3ff to 0x-8x, and 0x700-0x7ff to 0x-16x, > > >> >> with more linear segments in between. Rockchip's camera engine code > > >> >> chooses one of the above segments depenging on the desired gain > > >> >> value. The question is, how should we proceed keeping in mind > > >> >> libcamera use case? Should the whole 0x0-0x7ff be exposed as-is and > > >> >> libcamera will do the mapping, or the driver will do the mapping > > >> >> itself and expose some logical gain units not tied to the actual gain > > >> >> register value? Meanwhile, this driver conservatively exposes only > > >> >> 0x0-0xf8 gain register range. > > >> > > > >> > The datasheet linked above says "for the gain formula, please contact > > >> > your local OmniVision FAE" :-( > > >> > I would assume that the range is from 1x rather than 0x - people > > >> > rarely want a totally black image that 0x would give. Or is it ranges > > >> > of 1x - 2x, 2x - 4x, 4x - 8x, and 8x - 16x? > > >> > > >> A picture is worth a thousand words, so I've attached the results of my > > >> experimentation with the gain register. They were obtained with Rockchip > > >> 3399, with AEC, AGC and black level subtraction disabled. The image was > > >> converted from 10-bit RGGB to 8-bit YUV 4:2:0 by the Rockchip ISP. Is that full or limited range YUV ? > > > Based on that it looks like their medication may have been a little too > > > strong. > > > > > > Could this be implemented so that the control value would be linear linear > > > but its range would correspond 1x--16x values? > > > > > > libcamera will be able to cope with that. > > > > According to the following fragment of the Rockchip camera engine sensor > > configuration file for ov4689 [1] > > > > > > [1 2 128 0 1 128 255 > > 2 4 64 -248 1 376 504 > > 4 8 32 -756 1 884 1012 > > 8 16 16 -1784 1 1912 2040] > > , > > > > it uses gain register value range 128-255 for gain 1x-2x, 376-504 for > > gain 2x-4x, 884-1024 for 4x-8x, and 1912-2040 for 8x-16x. Do you suggest That looks *really* weird. I would have understood [384, 511], [896, 1023] and [1920, 2047], but not those intervals. The driver hardcodes bit 0x3503[2] to 1, which means "sensor gain format". Maybe setting it to 0 ("real gain format") would produce saner results ? > > to implement this calculation in the sensor driver and expose some > > linear "logical" gain to userspace (ranging, e.g., 128-2048 for gains > > 1x-16x)? > > Yes. This way the user space can somehow work without knowing this special > implementation, even though the granularity changes over the range. I guess > the granularity would need to be known in libcamera but that's a separate > issue. I can live with that. -- Regards, Laurent Pinchart