From patchwork Wed Dec 2 15:23:20 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 29146 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 18A10C3355 for ; Wed, 2 Dec 2026 15:23:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DC5A6AB02; Wed, 2 Dec 2026 16:23:32 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="W12D7kBf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 551586AAED for ; Wed, 2 Dec 2026 16:23:28 +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 756B53A4; Wed, 2 Dec 2026 16:20:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1796224849; bh=vJmWB5Gzslf3oyQ6XeaMVogp8gxos6BPdrUxw0eyRi4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W12D7kBf4hLR5hzlT7JWusOupzo92Ol9f0fVSm/zrWd4EU7rf+aAfuuqr8O6Mqah+ hNUjNOAsZA0E/icnMMPUtGjZdEMRSN33X1wgvWPV2jmht1U8Pt9jXW3xtM3XA6/JGp VgplppWl5zZJEmg33v7lUJAZojkhoaFMiNg3Neh4= From: Jacopo Mondi Date: Wed, 02 Dec 2026 16:23:20 +0100 Subject: [PATCH v4 5/5] libipa: camera_sensor_helper: Add Mira016 MIME-Version: 1.0 Message-Id: <20261202-b4-mira016-v4-5-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=2509; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=vJmWB5Gzslf3oyQ6XeaMVogp8gxos6BPdrUxw0eyRi4=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBrEDfu96f1cUWSyLUX89+f8B+DQaYX+FnwKuKDP bANakuadHqJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaxA37gAKCRByNAaPFqFW PJgOEACmDZqRONSHVkDSgkQ9FUSJOQXdFjLm6YGFSBz8RV+8QFcXhkP0eCK1/nq5iWo2MZfabxv sdTjaTujLrm3IaCMOxcLPoXn+YmhLJ0NmGJhc07F1Vj1S2Odhd+CllfexWDFs97ORQ6Ygt0+ZFO fijj9zoQlk5cxFWxG1T+hE1RloYAf3hMJL1RYTKTravXa7uKfHzgKZX5HoPvTXqwmJTQncBcc1N tWRQaaO+ZYgKPd3l5Pkkek0A/+Hr6G+jbq+LbEEN6URPWAYY1zUYE4K2B2RAXwztbg7JRBfywRn 9nvdbDrszWtBjRLUDaDizMbF3sCdRHk73OEY2eLzZXYsq0cJnHXdEhkw9fKJiInDZJwyG7Zvvw6 ZblIV+Thz8qbWCyNx0EuI65v0MSNlZV1XhhnXWCLloJ0nOaf+jCXTB1Kgt43X7mV8UHU9CoFk9U enN5LLJtV78Hem/Pu10kkJpI7jPPNfiVTH1p5Ra9rGWlzP3f3JarkeeB9GfEYVnOq4GjmwtUF5F 40VIYA+4hVCleV8cHCYPozsxtqT7J9c8GEqmAUfLM7Ek1CsxoWic5F0yQWT7MED8W35+sT/fzPC I7PiEOW/G1PSTW2YSuqLZeB3zo9Dwd0+52xOghHeKW6iw91znMJHB9pagH4cu2LeQwbb0rud0T9 PRdBwTCnGKg3E2w== 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 Add a camera sensor helper for the AMS-OSRAM Mira016 sensor. The sensor black level has been measured by averaging the pixel values while covering the lens. 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 driver programs for a code, so the IPA knows the real gain. 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: Jacopo Mondi --- src/ipa/libipa/camera_sensor_helper.cpp | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index c5c8a447567f..c6377ff2160a 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -787,6 +787,49 @@ public: }; REGISTER_CAMERA_SENSOR_HELPER(CameraSensorHelperOv08x40, "ov08x40") +class CameraSensorHelperMira016 : public CameraSensorHelper +{ +public: + /* + * 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. + */ + CameraSensorHelperMira016() + { + blackLevel_ = 1536; + } + + uint32_t gainCode(double gain) const override + { + return std::max(std::lround(gain * 1000), 1000); + } + + double gain(uint32_t gainCode) const override + { + 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; + } + +private: + static constexpr unsigned int kAdcRampStep = 57000; +}; +REGISTER_CAMERA_SENSOR_HELPER(CameraSensorHelperMira016, "mira016") + class CameraSensorHelperMira220 : public CameraSensorHelper { public: