Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2465602rdb; Wed, 15 Nov 2023 01:13:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHHnmsjGUz7EHSkf24Jn6Qz2JwpIeC/PeZghVu3K3sHawunJOxp0bRmscH0IwKWYyg3JNSM X-Received: by 2002:a05:6a00:6c94:b0:6be:2dce:cf5a with SMTP id jc20-20020a056a006c9400b006be2dcecf5amr12297339pfb.26.1700039601862; Wed, 15 Nov 2023 01:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700039601; cv=none; d=google.com; s=arc-20160816; b=WLDwdwgmSyUbgO0m04kmc1pfqtUMEW41MsNQj+np96mSbVkvR+cjFW7vA1s6hD8rmL vnXzp/Joake0qVspwwKHvge1PcNB80tPCllRHokXQLkVERk6TQNf/N8cI1o07cHZY4Fb qiI2IyrzMtffxRkQ70cEY6nbKSVvSY+kPosoMsa/Pp68y/KZ3sBhOrs8QhW3aVsUf2MZ YJNDdT0JXYZkJN32hwzYhHpSnb4z+P1zV2+QZR9X38Subu3PUok9ht9yrwvgGIAJh/LW xBIcVZTSfUvU9OO0CNkre/IjTpAnJgHFz9nfuRWqFEjj33X3/TIoEUQ9lsLZY8/wHUgM RMmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id; bh=e1FzU0JwL9Ylru1q9p+SWEQ4SqNHlKG/DKSaWThYujc=; fh=Hrrh6JiMpOcnR5qrPHf3AYfYXV3jTL8Vxqz7znUHfao=; b=Aot/2+XgtfsrfXBydVUKusok14Z38qme8SYzr2RwgsrR82lJf5ud8UO+6itGtK+etN EIkde/ZqnBihP0UEAM/dPoKdHpyBJV5jk45RGxexivjFd+SMa6zqe4UFV60VG6ZGyjpu 1+E2B5aruhs9aMjMVg2xOJemcVBKarT1bU8LSV2TvjTZEBCqaHRMhlBaJAaRXq1ovRoO dWp1r2lmanuMye/nsc0C8DINcZN85yL4FC+8HaBWjYOrpuqnPqqY913lY2t06wM36nEf ctlop7sZABn3BfdLIOCMhpAKEI3dK8ESrdKx/WCw0AZEHzRM0iM7YH/hvayxkpwuKlH2 J5+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f5-20020a056a0022c500b00690f9ca0f99si10330214pfj.12.2023.11.15.01.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:13:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 47B7F81373D3; Wed, 15 Nov 2023 01:13:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234684AbjKOJNR (ORCPT + 99 others); Wed, 15 Nov 2023 04:13:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234651AbjKOJNQ (ORCPT ); Wed, 15 Nov 2023 04:13:16 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE30EFC for ; Wed, 15 Nov 2023 01:13:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D517DC433C8; Wed, 15 Nov 2023 09:13:07 +0000 (UTC) Message-ID: <22df79da-eece-4b9a-b452-b36cba2b4711@xs4all.nl> Date: Wed, 15 Nov 2023 10:13:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 10/15] media: uapi: Add V4L2_CTRL_TYPE_FIXED_POINT Content-Language: en-US, nl To: Tomasz Figa Cc: Laurent Pinchart , Sakari Ailus , Shengjiu Wang , m.szyprowski@samsung.com, mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, shengjiu.wang@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, nicoleotsuka@gmail.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linuxppc-dev@lists.ozlabs.org References: <1699595289-25773-1-git-send-email-shengjiu.wang@nxp.com> <1699595289-25773-11-git-send-email-shengjiu.wang@nxp.com> <4cd6b593-2376-4cbc-a7c8-d3eb36a2f7a0@xs4all.nl> <20231113104238.GA13981@pendragon.ideasonboard.com> <6a3e7eb9-505c-4cfb-8a86-a8947a2e44d5@xs4all.nl> <20231113110754.GB24338@pendragon.ideasonboard.com> <3e898664-cbfc-4892-9765-37b66891643b@xs4all.nl> <20231113114357.GD24338@pendragon.ideasonboard.com> <20231113124412.GA18974@pendragon.ideasonboard.com> From: Hans Verkuil Autocrypt: addr=hverkuil@xs4all.nl; keydata= xsFNBFQ84W0BEAC7EF1iL4s3tY8cRTVkJT/297h0Hz0ypA+ByVM4CdU9sN6ua/YoFlr9k0K4 BFUlg7JzJoUuRbKxkYb8mmqOe722j7N3HO8+ofnio5cAP5W0WwDpM0kM84BeHU0aPSTsWiGR yw55SOK2JBSq7hueotWLfJLobMWhQii0Zd83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ifG8q9LWFIZhQ7TA1WD/9yxJvQrpf6LcNrr8uMlQWCg2iz2q1LGt1Itkuu KaavEF9nqHmoqhSfZeAIKAPn6xuYbGxXDrpN7dXCOH92fscLodZqZtK5FtbLvO572EPfxneY UT7JzDc/5LT9cFFugTMOhq1BG62vUm/F6V91+unyp4dRlyryAeqEuISykhvjZCVHk/woaMZv c1Dm4Uvkv0Ilelt3Pb9J7zhcx6sm5T7v16VceF96jG61bnJ2GFS+QZerZp3PY27XgtPxRxYj AmFUeF486PHx/2Yi4u1rQpIpC5inPxIgR1+ZFvQrAV36SvLFfuMhyCAxV6WBlQc85ArOiQZB Wm7L0repwr7zEJFEkdy8C81WRhMdPvHkAIh3RoY1SGcdB7rB3wCzfYkAuCBqaF7Zgfw8xkad KEiQTexRbM1sc/I8ACpla3N26SfQwrfg6V7TIoweP0RwDrcf5PVvwSWsRQp2LxFCkwnCXOra gYmkrmv0duG1FStpY+IIQn1TOkuXrciTVfZY1cZD0aVxwlxXBnUNZZNslldvXFtndxR0SFat sflovhDxKyhFwXOP0Rv8H378/+14TaykknRBIKEc0+lcr+EMOSUR5eg4aURb8Gc3Uc7fgQ6q UssTXzHPyj1hAyDpfu8DzAwlh4kKFTodxSsKAjI45SLjadSc94/5Gy8645Y1KgBzBPTH7Q== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:13:20 -0800 (PST) On 15/11/2023 09:45, Tomasz Figa wrote: > On Wed, Nov 15, 2023 at 5:09 PM Hans Verkuil wrote: >> >> Hi Laurent, >> >> On 13/11/2023 13:44, Laurent Pinchart wrote: >>> Hi Hans, >>> >>> On Mon, Nov 13, 2023 at 01:05:12PM +0100, Hans Verkuil wrote: >>>> On 13/11/2023 12:43, Laurent Pinchart wrote: >>>>> On Mon, Nov 13, 2023 at 11:28:51AM +0000, Sakari Ailus wrote: >>>>>> On Mon, Nov 13, 2023 at 12:24:14PM +0100, Hans Verkuil wrote: >>>>>>> On 13/11/2023 12:07, Laurent Pinchart wrote: >>>>>>>> On Mon, Nov 13, 2023 at 11:56:49AM +0100, Hans Verkuil wrote: >>>>>>>>> On 13/11/2023 11:42, Laurent Pinchart wrote: >>>>>>>>>> On Mon, Nov 13, 2023 at 11:29:09AM +0100, Hans Verkuil wrote: >>>>>>>>>>> On 10/11/2023 06:48, Shengjiu Wang wrote: >>>>>>>>>>>> Fixed point controls are used by the user to configure >>>>>>>>>>>> a fixed point value in 64bits, which Q31.32 format. >>>>>>>>>>>> >>>>>>>>>>>> Signed-off-by: Shengjiu Wang >>>>>>>>>>> >>>>>>>>>>> This patch adds a new control type. This is something that also needs to be >>>>>>>>>>> tested by v4l2-compliance, and for that we need to add support for this to >>>>>>>>>>> one of the media test-drivers. The best place for that is the vivid driver, >>>>>>>>>>> since that has already a bunch of test controls for other control types. >>>>>>>>>>> >>>>>>>>>>> See e.g. VIVID_CID_INTEGER64 in vivid-ctrls.c. >>>>>>>>>>> >>>>>>>>>>> Can you add a patch adding a fixed point test control to vivid? >>>>>>>>>> >>>>>>>>>> I don't think V4L2_CTRL_TYPE_FIXED_POINT is a good idea. This seems to >>>>>>>>>> relate more to units than control types. We have lots of fixed-point >>>>>>>>>> values in controls already, using the 32-bit and 64-bit integer control >>>>>>>>>> types. They use various locations for the decimal point, depending on >>>>>>>>>> the control. If we want to make this more explicit to users, we should >>>>>>>>>> work on adding unit support to the V4L2 controls. >>>>>>>>> >>>>>>>>> "Fixed Point" is not a unit, it's a type. 'Db', 'Hz' etc. are units. >>>>>>>> >>>>>>>> It's not a unit, but I think it's related to units. My point is that, >>>>>>>> without units support, I don't see why we need a formal definition of >>>>>>>> fixed-point types, and why this series couldn't just use >>>>>>>> VIVID_CID_INTEGER64. Drivers already interpret VIVID_CID_INTEGER64 >>>>>>>> values as they see fit. >>>>>>> >>>>>>> They do? That's new to me. A quick grep for V4L2_CTRL_TYPE_INTEGER64 >>>>>>> (I assume you meant that rather than VIVID_CID_INTEGER64) shows that it >>>>> >>>>> Yes, I meant V4L2_CTRL_TYPE_INTEGER64. Too hasty copy & paste :-) >>>>> >>>>>>> is always interpreted as a 64 bit integer and nothing else. As it should. >>>>> >>>>> The most common case for control handling in drivers is taking the >>>>> integer value and converting it to a register value, using >>>>> device-specific encoding of the register value. It can be a fixed-point >>>>> format or something else, depending on the device. My point is that >>>>> drivers routinely convert a "plain" integer to something else, and that >>>>> has never been considered as a cause of concern. I don't see why it >>>>> would be different in this series. >>>>> >>>>>>> And while we do not have support for units (other than the documentation), >>>>>>> we do have type support in the form of V4L2_CTRL_TYPE_*. >>>>>>> >>>>>>>>> A quick "git grep -i "fixed point" Documentation/userspace-api/media/' >>>>>>>>> only shows a single driver specific control (dw100.rst). >>>>>>>>> >>>>>>>>> I'm not aware of other controls in mainline that use fixed point. >>>>>>>> >>>>>>>> The analog gain control for sensors for instance. >>>>>>> >>>>>>> Not really. The documentation is super vague: >>>>>>> >>>>>>> V4L2_CID_ANALOGUE_GAIN (integer) >>>>>>> >>>>>>> Analogue gain is gain affecting all colour components in the pixel matrix. The >>>>>>> gain operation is performed in the analogue domain before A/D conversion. >>>>>>> >>>>>>> And the integer is just a range. Internally it might map to some fixed >>>>>>> point value, but userspace won't see that, it's hidden in the driver AFAICT. >>>>> >>>>> It's hidden so well that libcamera has a database of the sensor it >>>>> supports, with formulas to map a real gain value to the >>>>> V4L2_CID_ANALOGUE_GAIN control. The encoding of the integer value does >>>>> matter, and the kernel doesn't expose it. We may or may not consider >>>>> that as a shortcoming of the V4L2 control API, but in any case it's the >>>>> situation we have today. >>>>> >>>>>> I wonder if Laurent meant digital gain. >>>>> >>>>> No, I meant analog. It applies to digital gain too though. >>>>> >>>>>> Those are often Q numbers. The practice there has been that the default >>>>>> value yields gain of 1. >>>>>> >>>>>> There are probably many other examples in controls where something being >>>>>> controlled isn't actually an integer while integer controls are still being >>>>>> used for the purpose. >>>>> >>>>> A good summary of my opinion :-) >>>> >>>> And that works fine as long as userspace doesn't need to know what the value >>>> actually means. >>>> >>>> That's not the case here. The control is really a fractional Hz value: >>>> >>>> +``V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET (fixed point)`` >>>> + Sets the offset from the audio source sample rate, unit is Hz. >>>> + The offset compensates for any clock drift. The actual source audio sample >>>> + rate is the ideal source audio sample rate from >>>> + ``V4L2_CID_M2M_AUDIO_SOURCE_RATE`` plus this fixed point offset. >>> >>> I don't see why this would require a new type, you can use >>> V4L2_CTRL_TYPE_INTEGER64, and document the control as containing >>> fixed-point values in Q31.32 format. >> >> Why would you want to do this? I can store a double in a long long int, >> and just document that the variable is really a double, but why would you? >> >> The cost of adding a FIXED_POINT type is minimal, and having this type >> makes it easy to work with fixed point controls (think about proper reporting >> and setting of the value in v4l2-ctl and user applications in general that >> deal with controls). > > I can see one potential drawback of adding a new type - userspace > would have to be made aware of it, although arguably with brand new > controls, userspace would have to be aware of them anyway. Not sure if > we have some kind of userspace that can handle any controls purely > based on their type - if yes, they would not be able to handle the new > controls. The generic userspace apps are all in v4l-utils (v4l2-ctl/compliance, qv4l2), so that is not a problem. We add new types all the time, this is nothing new. Regards, Hans > >> >> If this would add a thousand lines of complex code, then this would be a >> consideration, but this is just a few lines. >> >> Just to give an example, if you use 'v4l2-ctl -l' to list a int64 control >> and it reports the value 13958643712, would you be able to see that that is >> really 3.25 in fixed point format? With the right type it would be printed >> like that. Much easier to work work. >> >> Regards, >> >> Hans >> >>> >>>>>> Instead of this patch, I'd prefer to have a way to express the meaning of >>>>>> the control value, be it a Q number or something else, and do that >>>>>> independently of the type of the control. >>>> >>>> Huh? How is that different from the type of the control? You have integers >>>> (one type) and fixed point (another type). >>>> >>>> Or do you want a more general V4L2_CTRL_TYPE_ that specifies the N.M values >>>> explicitly? >>>> >>>> I think the main reason why we use integer controls for gain is that we >>>> never had a fixed point control type and you could get away with that in >>>> user space for that particular use-case. >>>> >>>> Based on the V4L2_CID_NOTIFY_GAINS documentation the gain value can typically >>>> be calculated as (value / default_value), >>> >>> Typically, but not always. Some sensor have an exponential gain model, >>> and some have weird gain representation, such as 1/x. That's getting out >>> of scope though. >>> >>>> but that won't work for a rate offset >>>> control as above, or for e.g. CSC matrices for color converters. >>>> >>>>> Agreed. >>>>> >>>>>>> In the case of this particular series the control type is really a fixed point >>>>>>> value with a documented unit (Hz). It really is not something you want to >>>>>>> use type INTEGER64 for. >>>>>>> >>>>>>>>> Note that V4L2_CTRL_TYPE_FIXED_POINT is a Q31.32 format. By setting >>>>>>>>> min/max/step you can easily map that to just about any QN.M format where >>>>>>>>> N <= 31 and M <= 32. >>>>>>>>> >>>>>>>>> In the case of dw100 it is a bit different in that it is quite specialized >>>>>>>>> and it had to fit in 16 bits. >>> >>