From patchwork Tue Nov 24 16:58:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 29080 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 DE0BABDE17 for ; Tue, 24 Nov 2026 16:59:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14E996A9D2; Tue, 24 Nov 2026 17:59:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZtX/diL7"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 578176A979 for ; Tue, 24 Nov 2026 17:58:57 +0100 (CET) Received: from [192.168.95.178] (mob-5-90-67-29.net.vodafone.it [5.90.67.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E095EBE; Tue, 24 Nov 2026 17:56:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1795539384; bh=JkuflD7rL2N5pCqZCAd1L4oUgr2T1pe/DoxMzw8/FLY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZtX/diL7OWblF1VJcjgrk/M0CnSN2RMz/NKm+GOFGWCeHvJGKHRiZ0D60DI5c6dvP 4WeL07eugl0vdS7ImnNag8wR2dw41pXpj8FdVL/75sXa0JxIFrbha3IvUGXt0S6ubm DMPuPmsv7fmLCMHi8X8jcZaS7siJUpwge3ZUypGk= From: Jacopo Mondi Date: Tue, 24 Nov 2026 17:58:02 +0100 Subject: [PATCH v3 1/5] ipa: rpi: cam_helper: Add Mira016 cam helper MIME-Version: 1.0 Message-Id: <20261124-b4-mira016-v3-1-b71d2cf61889@ideasonboard.com> References: <20261124-b4-mira016-v3-0-b71d2cf61889@ideasonboard.com> In-Reply-To: <20261124-b4-mira016-v3-0-b71d2cf61889@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=wtwZwxLRh1WmrfelVw51mLjMibF8InnH4ddW11Riinc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBrBcJE1Lo7DQ+MLvWImXmKPbrDknCS8Oi+sTLgV ap5yP14dBmJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCawXCRAAKCRByNAaPFqFW PPMyD/0XXNR60Yya8zsfFuemSMG+rbQqaOlKJrt+fQSvdVMnyvMhlVbGVoRw3/vXJnG3mFKt2YK RLg1XmSqhr5bQcgaPZ5VJ3KinsCS+NHpBIyGDPTxysa+MpiWxMxTmZLekdDJZ3LCaEIZy90MXkJ ssbJD+IHrp36669CE5uP1ImHrynMJrDAD2xNfZHJYUT+p43EBvN0aOTTtNdVrHbP1uL8ykb1Q5a lLs1HpARUJiHhP4EULywEYMJdp+R1ODnxIuDEm2VmE4bM1EgwB/lJTPXOqX9JqNRumaXkDIeUyl 4hF2PMe6r3taJs+ikl2z1msSP+L59O0kboY/BRe1rkwmu2vG4IzuFMf70vgav9NvgkZtNOHM8cx WgXhQk8MIvN7tP5+yEY4l0KzONvebsA21rYuFEzGdsOPMU+1B0K9fqcyknJAKrUyLgdi+LyTaKS E71GpTcjYcvju+VDNI21pluxhV2/FPErhHYBm7OLcxdKmEOPrVsGMT745ZUTyQed9axVQkLfA8Z LLgoGkfgH7MD/JtxU9jvMKpE1amm63uA+np4lInGmWOzDdBTcEnlDnnFt9sGdrq2gL1WrVErCy2 GGkKRvciE/UeEI8eSCps7JteiqmNvyhWOZ8txQosWQxAxs+x45e05S5omJhQ3mb9Ox6Z0JRS0V5 z1MerabChPOW7Ig== 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 Sender: "libcamera-devel" 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..754948a60c7a --- /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 = 5700; +}; + +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 21 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',