[v3,5/5] libipa: camera_sensor_helper: Add Mira016
diff mbox series

Message ID 20261124-b4-mira016-v3-5-b71d2cf61889@ideasonboard.com
State New
Headers show
Series
  • libcamera: Add Mira016 support
Related show

Commit Message

Jacopo Mondi Nov. 24, 2026, 4:58 p.m. UTC
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 <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/camera_sensor_helper.cpp | 43 +++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
index c5c8a447567f..7cb5e1c2004d 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 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.
+	 */
+	CameraSensorHelperMira016()
+	{
+		blackLevel_ = 2048;
+	}
+
+	uint32_t gainCode(double gain) const override
+	{
+		return std::max<long>(std::lround(gain * 1000), 1000);
+	}
+
+	double gain(uint32_t gainCode) const override
+	{
+		uint32_t code = std::clamp<uint32_t>(gainCode, 1000, 16000);
+		uint32_t n = std::floor(std::log2(84.0 * static_cast<double>(code) /
+						  kAdcRampStep));
+
+		uint32_t num = kAdcRampStep << n;
+		int adcGain = ((num + code / 2) / code) - 21;
+		adcGain = std::clamp(adcGain, 0, 63);
+
+		return static_cast<double>(num) / (adcGain + 21) / 1000.0;
+	}
+
+private:
+	static constexpr unsigned int kAdcRampStep = 5700;
+};
+REGISTER_CAMERA_SENSOR_HELPER(CameraSensorHelperMira016, "mira016")
+
 class CameraSensorHelperMira220 : public CameraSensorHelper
 {
 public: