[{"id":25884,"web_url":"https://patchwork.libcamera.org/comment/25884/","msgid":"<Y34w02xbLLDBzbCy@pendragon.ideasonboard.com>","date":"2022-11-23T14:40:19","subject":"Re: [libcamera-devel] [PATCH v2 1/4] libcamera: Move IPA sensor\n\tcontrols validation to CameraSensor","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, Nov 23, 2022 at 02:43:43PM +0100, Jacopo Mondi via libcamera-devel wrote:\n> The CameraSensor class validates that the sensor driver in use supports\n> the controls required for IPA modules to work correctly.\n> \n> For in-tree IPA modules, whose pipeline handlers already use\n> CameraSensor there's no need to validate such controls again.\n> \n> Remove controls validation from the IPU3 and RkISP1 IPA modules and rely\n> on CameraSensor doing that at initialization time.\n> \n> The list of mandatory controls is expanded to add V4L2_CID_ANALOGUE_GAIN\n> without which IPA modules cannot function.\n> \n> The new requirement only applies to RAW sensors, platforms like UVC and\n> Simple are not impacted by this change.\n> \n> While at it, expand the sensor driver requirements documentation to\n> include V4L2_ANALOGUE_GAIN in the list of mandatory controls a sensor\n> driver has to support.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  Documentation/sensor_driver_requirements.rst |  7 +++++\n>  src/ipa/ipu3/ipu3.cpp                        | 29 --------------------\n>  src/ipa/rkisp1/rkisp1.cpp                    | 12 +-------\n>  src/libcamera/camera_sensor.cpp              |  1 +\n>  4 files changed, 9 insertions(+), 40 deletions(-)\n> \n> diff --git a/Documentation/sensor_driver_requirements.rst b/Documentation/sensor_driver_requirements.rst\n> index b0854be3328a..3abc8f35924a 100644\n> --- a/Documentation/sensor_driver_requirements.rst\n> +++ b/Documentation/sensor_driver_requirements.rst\n> @@ -24,16 +24,23 @@ The sensor driver is assumed to be fully compliant with the V4L2 specification.\n>  \n>  For RAW sensors, the sensor driver shall support the following V4L2 controls:\n>  \n> +* `V4L2_CID_ANALOGUE_GAIN`_\n>  * `V4L2_CID_EXPOSURE`_\n>  * `V4L2_CID_HBLANK`_\n>  * `V4L2_CID_PIXEL_RATE`_\n>  * `V4L2_CID_VBLANK`_\n>  \n> +.. _V4L2_CID_ANALOGUE_GAIN: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-image-source.html\n>  .. _V4L2_CID_EXPOSURE: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/control.html\n>  .. _V4L2_CID_HBLANK: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-image-source.html\n>  .. _V4L2_CID_PIXEL_RATE: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-image-process.html\n>  .. _V4L2_CID_VBLANK: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-image-source.html\n>  \n> +The ``ANALOGUE_GAIN`` control units are sensor-specific. libcamera requires\n> +a sensor-specific CameraSensorHelper implementation to translate between the\n> +sensor specific ``gain code`` and the analogue ``gain value`` expressed as an\n> +absolute number as defined by ``controls::AnalogueGain``.\n> +\n>  While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera\n>  requires it to be expressed as a number of image lines. Camera sensor drivers\n>  that do not comply with this requirement will need to be adapted or will produce\n> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\n> index a9a2b49ca95b..08ee6eb30cc5 100644\n> --- a/src/ipa/ipu3/ipu3.cpp\n> +++ b/src/ipa/ipu3/ipu3.cpp\n> @@ -171,8 +171,6 @@ private:\n>  \t\t\t    ControlInfoMap *ipaControls);\n>  \tvoid updateSessionConfiguration(const ControlInfoMap &sensorControls);\n>  \n> -\tbool validateSensorControls();\n> -\n>  \tvoid setControls(unsigned int frame);\n>  \tvoid calculateBdsGrid(const Size &bdsOutputSize);\n>  \n> @@ -292,28 +290,6 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,\n>  \t*ipaControls = ControlInfoMap(std::move(controls), controls::controls);\n>  }\n>  \n> -/**\n> - * \\brief Validate that the sensor controls mandatory for the IPA exists\n> - */\n> -bool IPAIPU3::validateSensorControls()\n> -{\n> -\tstatic const uint32_t ctrls[] = {\n> -\t\tV4L2_CID_ANALOGUE_GAIN,\n> -\t\tV4L2_CID_EXPOSURE,\n> -\t\tV4L2_CID_VBLANK,\n> -\t};\n> -\n> -\tfor (auto c : ctrls) {\n> -\t\tif (sensorCtrls_.find(c) == sensorCtrls_.end()) {\n> -\t\t\tLOG(IPAIPU3, Error) << \"Unable to find sensor control \"\n> -\t\t\t\t\t    << utils::hex(c);\n> -\t\t\treturn false;\n> -\t\t}\n> -\t}\n> -\n> -\treturn true;\n> -}\n> -\n>  /**\n>   * \\brief Initialize the IPA module and its controls\n>   *\n> @@ -512,11 +488,6 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n>  \n>  \tcalculateBdsGrid(configInfo.bdsOutputSize);\n>  \n> -\tif (!validateSensorControls()) {\n> -\t\tLOG(IPAIPU3, Error) << \"Sensor control validation failed.\";\n> -\t\treturn -EINVAL;\n> -\t}\n> -\n>  \t/* Update the camera controls using the new sensor settings. */\n>  \tupdateControls(sensorInfo_, sensorCtrls_, ipaControls);\n>  \n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index fcb9dacccc3c..d237758f7bf0 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -216,20 +216,10 @@ int IPARkISP1::configure([[maybe_unused]] const IPACameraSensorInfo &info,\n>  \tctrls_ = entityControls.at(0);\n>  \n>  \tconst auto itExp = ctrls_.find(V4L2_CID_EXPOSURE);\n> -\tif (itExp == ctrls_.end()) {\n> -\t\tLOG(IPARkISP1, Error) << \"Can't find exposure control\";\n> -\t\treturn -EINVAL;\n> -\t}\n> -\n> -\tconst auto itGain = ctrls_.find(V4L2_CID_ANALOGUE_GAIN);\n> -\tif (itGain == ctrls_.end()) {\n> -\t\tLOG(IPARkISP1, Error) << \"Can't find gain control\";\n> -\t\treturn -EINVAL;\n> -\t}\n> -\n>  \tint32_t minExposure = itExp->second.min().get<int32_t>();\n>  \tint32_t maxExposure = itExp->second.max().get<int32_t>();\n>  \n> +\tconst auto itGain = ctrls_.find(V4L2_CID_ANALOGUE_GAIN);\n>  \tint32_t minGain = itGain->second.min().get<int32_t>();\n>  \tint32_t maxGain = itGain->second.max().get<int32_t>();\n>  \n> diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\n> index 572a313a8f99..ea373458a164 100644\n> --- a/src/libcamera/camera_sensor.cpp\n> +++ b/src/libcamera/camera_sensor.cpp\n> @@ -301,6 +301,7 @@ int CameraSensor::validateSensorDriver()\n>  \t * required by the CameraSensor class.\n>  \t */\n>  \tstatic constexpr uint32_t mandatoryControls[] = {\n> +\t\tV4L2_CID_ANALOGUE_GAIN,\n>  \t\tV4L2_CID_EXPOSURE,\n>  \t\tV4L2_CID_HBLANK,\n>  \t\tV4L2_CID_PIXEL_RATE,","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BEAF7BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 23 Nov 2022 14:40:36 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8022563313;\n\tWed, 23 Nov 2022 15:40:36 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6650063311\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Nov 2022 15:40:35 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E12F7890;\n\tWed, 23 Nov 2022 15:40:34 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1669214436;\n\tbh=X6470frZ5VNy2w8r2CYOQTdQX9VYJOdbrblzovJ6i7I=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=gZB0C+3mU/pm7ScZ1mre0HacA99Az7Yublay+Yp3cja8LA95/uFU9wK2EYvUWRpo1\n\tQsvBBnIvV2VeSjyRr0Og89eHU5WMO/EcK9n/QTWtxXhJmr9hPxVUliSps2mh6Ta1BK\n\ttyJRhL2IKaRACekBJoUA/JXu5JG6zm3Oyri5BfiK4oq7HE7e2tD6VuqgkNEFvH+SZ2\n\t6O6+/Ytcd0foXXlZB3wFawAlgxqbA1eqCxIzjKdbqUrYf+RQuFS0F7+0K6OHQ/Z9Td\n\toxOA5MThdgXfky/HRgcstNOlBrnZoZRMuIpqNRdEXQm/sRWcUjxqJdoJl57us/MxAv\n\tpvqHk8SyaUUZA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1669214435;\n\tbh=X6470frZ5VNy2w8r2CYOQTdQX9VYJOdbrblzovJ6i7I=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=EMCmK0MfC5MKxrCf6DlCHaXMDfD/eyNAG4gChI+VsyHUCkMvuPjA7BF8G6G/1x+QD\n\tcPxdncN+WlbXBIJPlrB+nWh5TcZUPWeaMaVPJ8EyuTNxNOvCuLpHsEqKxVk25mxfic\n\tYQZUWG2UHoFKD3QMHHJW7pt8g9CBZkIpedRQFKtg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"EMCmK0Mf\"; dkim-atps=neutral","Date":"Wed, 23 Nov 2022 16:40:19 +0200","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<Y34w02xbLLDBzbCy@pendragon.ideasonboard.com>","References":"<20221123134346.129807-1-jacopo@jmondi.org>\n\t<20221123134346.129807-2-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20221123134346.129807-2-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2 1/4] libcamera: Move IPA sensor\n\tcontrols validation to CameraSensor","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Nicholas Roth <nicholas@rothemail.net>,\n\tlibcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]