From patchwork Wed Dec 2 15:23:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 29142 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A0307C3300 for ; Wed, 2 Dec 2026 15:23:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ACCC06AAFF; Wed, 2 Dec 2026 16:23:29 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="efgxVMDr"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 481336AAEC for ; Wed, 2 Dec 2026 16:23:27 +0100 (CET) Received: from [192.168.1.182] (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F1D13A4; Wed, 2 Dec 2026 16:20:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796224848; bh=1X6v2jEE1Tnp+vnnYCPJSzBfUbV0nmDEfC5a3oKBbEo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=efgxVMDrF80PUoI+JUiOTPzNw15hG3MrER/xkV6+uxcnSDXx3NufyVecvwPQ30HRc sjtrgSdW/3CALTUr5sLvHa6Sk28RZ1NngXjIVCSemlLXs8RXeS7OQL/5iMMvwBqo1n NZA0xsasXgFepChf64pOWqExGEnCDw1aITAUPEIQ= From: Jacopo Mondi Date: Wed, 02 Dec 2026 16:23:16 +0100 Subject: [PATCH v4 1/5] ipa: rpi: cam_helper: Add Mira016 cam helper MIME-Version: 1.0 Message-Id: <20261202-b4-mira016-v4-1-6cb5648ead85@ideasonboard.com> References: <20261202-b4-mira016-v4-0-6cb5648ead85@ideasonboard.com> In-Reply-To: <20261202-b4-mira016-v4-0-6cb5648ead85@ideasonboard.com> To: Philippe Baetens , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3740; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=U8vgtrCDY/WP/aXS1Fqua0hD+b0phBISvgQvMZjcM7Y=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBrEDftEshvZU88SCAj8zizcJer04zicjgsAnB4g tqDKevHfMWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaxA37QAKCRByNAaPFqFW PE8MEACNauBtDbsldmo1iF+oxdBvE90s1tAj7aJr7NxU3b3xCqPx146l4nDuSaBzheGB5AUuY3y MXckjS9Scw59qOy1uAOBbkzNAsH9RfxM1/J5ce7XMsrnYZCSwbuN8IsKesj4Fahc9w2q6Dp5wAO kVQz1zpVyIGIP8tYZVah31hCpcFvnU7QXD2Ja70JiSX/06hWwZtVh/0xNx0EqHAbLcNlXQxfKpo SnVRXANOoz0JK5jZlOSHhrKIiU2JsGC2FkGA/X3QwsyJfsuDvrjjQRx9mSwTznUt64FkbI2y9oz VzBrL16mtGJkc7i/aiHHDaPQtIc3jsI2P2leWO5IYtMB1nFMUgoukHer9l8vynQfGVYpZp5btyM 1XIBb4UHCWH3utynoZeAMkcEo0LIXyg85hPUoxwvzHZeHQup4fzLSc5n8hnTFMO0IPBSGdcn/+f 33HmgPP7DHHX6RqrDVR8g+ZANACfGaB1KijDI6XXUd2e6aYgEtrLi8njRLdV9XRUndl4M33zcK7 KZ3+57Tva3YWFjpSd29GG7OGVVuDOGJZXjQumKyzYQj0ULVhAWmP1ccAHGSdMyXCu5BPUcv+B/D Yo3h7Wpn6Ni5U6TGE6dYPrb3ntmnKf+fuBuEsQj9m9NdBoz1PTaoXH0Xm46PJMKbjb64vMbFs5M p5vUnm5XsK5vz4g== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org From: Philippe Baetens AMS-OSRAM Mira016 is a global shutter 0.5Mpixel mono sensor. Add a cam_helper to the RaspberryPi IPA to support it. The analogue gain code is the gain in thousandths (1000 is 1x), and the driver computes the fine gain registers from it, rounding to: gain = 57 * 2^n / (ADC_GAIN + 21). The gainCode() function returns the gain times 1000, and the gain() function computes the gain as the driver does, so the IPA knows the real applied gain. Signed-off-by: Philippe Baetens Signed-off-by: Jacopo Mondi --- src/ipa/rpi/cam_helper/cam_helper_mira016.cpp | 78 +++++++++++++++++++++++++++ src/ipa/rpi/cam_helper/meson.build | 1 + 2 files changed, 79 insertions(+) diff --git a/src/ipa/rpi/cam_helper/cam_helper_mira016.cpp b/src/ipa/rpi/cam_helper/cam_helper_mira016.cpp new file mode 100644 index 000000000000..e5642fe165a9 --- /dev/null +++ b/src/ipa/rpi/cam_helper/cam_helper_mira016.cpp @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (C) 2026, ams-OSRAM + * Copyright (C) 2026, Ideas on Board Oy + * + * Camera helper for Mira016 sensor + */ + +#include +#include + +#include "cam_helper.h" + +namespace { + +using namespace RPiController; + +class CamHelperMira016 : public CamHelper +{ +public: + CamHelperMira016(); + uint32_t gainCode(double gain) const override; + double gain(uint32_t code) const override; + +private: + /* + * The sensor manual doesn't really specify a minimum difference between + * the exposure time and the frame duration, so pick a safe value of + * 4 frames. The mira016 driver uses the same value as the exposure + * margin. + */ + static constexpr int frameIntegrationDiff = 4; + static constexpr unsigned int kAdcRampStep = 57000; +}; + +CamHelperMira016::CamHelperMira016() + : CamHelper({}, frameIntegrationDiff) +{ +} + +/* + * The driver's analogue gain code is the gain in thousandths (1000 is 1x), up + * to 16000 in 8-bit modes, 4000 in 10-bit modes and only 1000 in 12-bit modes. + * The driver rounds it to the nearest gain the fine gain registers give: + * + * gain = 57 * 2^n / (ADC_GAIN + 21) + * + * n is the octave of the gain (0 to 4) and ADC_GAIN is 0 to 63. Up to 4x the + * 8 and 10-bit modes give the same gains, so the conversion does not depend on + * the mode, which matters because the IPA converts the gain limits of a new + * mode before it passes that mode to the helper. + */ +uint32_t CamHelperMira016::gainCode(double gain) const +{ + return std::max(std::lround(gain * 1000), 1000); +} + +double CamHelperMira016::gain(uint32_t gainCode) const +{ + uint32_t code = std::clamp(gainCode, 1000, 16000); + uint32_t n = std::floor(std::log2(84.0 * static_cast(code) / + kAdcRampStep)); + + uint32_t num = kAdcRampStep << n; + int adcGain = ((num + code / 2) / code) - 21; + adcGain = std::clamp(adcGain, 0, 63); + + return static_cast(num) / (adcGain + 21) / 1000.0; +} + +CamHelper *create() +{ + return new CamHelperMira016(); +} + +RegisterCamHelper reg("mira016", &create); + +} /* namespace */ diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build index 6935cecf885f..6fc5f5c12f37 100644 --- a/src/ipa/rpi/cam_helper/meson.build +++ b/src/ipa/rpi/cam_helper/meson.build @@ -12,6 +12,7 @@ rpi_ipa_cam_helper_sources = files([ 'cam_helper_imx477.cpp', 'cam_helper_imx519.cpp', 'cam_helper_imx708.cpp', + 'cam_helper_mira016.cpp', 'cam_helper_mira220.cpp', 'cam_helper_ov64a40.cpp', 'cam_helper_ov7251.cpp',