[v4,9/9] ipa: rkisp1: blc: Add support for BLS in compand
diff mbox series

Message ID 20240827014044.24673-10-laurent.pinchart@ideasonboard.com
State Accepted
Commit 9020c2eec9de5d9b5bc1016b26e714b1c0206441
Headers show
Series
  • rkisp1: Support BLS on i.MX8MP
Related show

Commit Message

Laurent Pinchart Aug. 27, 2024, 1:40 a.m. UTC
From: Paul Elder <paul.elder@ideasonboard.com>

Extend the RkISP1 BLC algorithm to use the ISP 'companding' block for
versions of the ISP (such as the one on the i.MX8MP) that lack the
dedicated BLS block but implement BLS as part of the companding block.

As access to the companding block requires the extensible parameters
format, disable BLC when using the legacy parameters format on i.MX8MP
to avoid crashes at runtime with older kernels.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
Changes since v3:

- Disable BLC on i.MX8MP if using the legacy parameters format
---
 src/ipa/rkisp1/algorithms/blc.cpp | 57 ++++++++++++++++++++++++-------
 src/ipa/rkisp1/algorithms/blc.h   |  5 ++-
 2 files changed, 48 insertions(+), 14 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/blc.cpp b/src/ipa/rkisp1/algorithms/blc.cpp
index c93f7ead62cf..98cb7145e164 100644
--- a/src/ipa/rkisp1/algorithms/blc.cpp
+++ b/src/ipa/rkisp1/algorithms/blc.cpp
@@ -7,6 +7,8 @@ 
 
 #include "blc.h"
 
+#include <linux/videodev2.h>
+
 #include <libcamera/base/log.h>
 
 #include <libcamera/control_ids.h>
@@ -38,7 +40,6 @@  namespace ipa::rkisp1::algorithms {
 LOG_DEFINE_CATEGORY(RkISP1Blc)
 
 BlackLevelCorrection::BlackLevelCorrection()
-	: tuningParameters_(false)
 {
 	/*
 	 * This is a bit of a hack. In raw mode no black level correction
@@ -96,8 +97,6 @@  int BlackLevelCorrection::init(IPAContext &context, const YamlObject &tuningData
 		blackLevelBlue_ = *blackLevel;
 	}
 
-	tuningParameters_ = true;
-
 	LOG(RkISP1Blc, Debug)
 		<< "Black levels: red " << blackLevelRed_
 		<< ", green (red) " << blackLevelGreenR_
@@ -107,10 +106,27 @@  int BlackLevelCorrection::init(IPAContext &context, const YamlObject &tuningData
 	return 0;
 }
 
+int BlackLevelCorrection::configure(IPAContext &context,
+				    [[maybe_unused]] const IPACameraSensorInfo &configInfo)
+{
+	/*
+	 * BLC on ISP versions that include the companding block requires usage
+	 * of the extensible parameters format.
+	 */
+	supported_ = context.configuration.paramFormat == V4L2_META_FMT_RK_ISP1_EXT_PARAMS ||
+		     !context.hw->compand;
+
+	if (!supported_)
+		LOG(RkISP1Blc, Warning)
+			<< "BLC in companding block requires extensible parameters";
+
+	return 0;
+}
+
 /**
  * \copydoc libcamera::ipa::Algorithm::prepare
  */
-void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,
+void BlackLevelCorrection::prepare(IPAContext &context,
 				   const uint32_t frame,
 				   [[maybe_unused]] IPAFrameContext &frameContext,
 				   RkISP1Params *params)
@@ -121,18 +137,33 @@  void BlackLevelCorrection::prepare([[maybe_unused]] IPAContext &context,
 	if (frame > 0)
 		return;
 
-	if (!tuningParameters_)
+	if (!supported_)
 		return;
 
-	auto config = params->block<BlockType::Bls>();
-	config.setEnabled(true);
+	if (context.hw->compand) {
+		auto config = params->block<BlockType::CompandBls>();
+		config.setEnabled(true);
 
-	config->enable_auto = 0;
-	/* The rkisp1 uses 12bit based black levels. Scale down accordingly. */
-	config->fixed_val.r = blackLevelRed_ >> 4;
-	config->fixed_val.gr = blackLevelGreenR_ >> 4;
-	config->fixed_val.gb = blackLevelGreenB_ >> 4;
-	config->fixed_val.b = blackLevelBlue_ >> 4;
+		/*
+		 * Scale up to the 20-bit black levels used by the companding
+		 * block.
+		 */
+		config->r = blackLevelRed_ << 4;
+		config->gr = blackLevelGreenR_ << 4;
+		config->gb = blackLevelGreenB_ << 4;
+		config->b = blackLevelBlue_ << 4;
+	} else {
+		auto config = params->block<BlockType::Bls>();
+		config.setEnabled(true);
+
+		config->enable_auto = 0;
+
+		/* Scale down to the 12-bit black levels used by the BLS block. */
+		config->fixed_val.r = blackLevelRed_ >> 4;
+		config->fixed_val.gr = blackLevelGreenR_ >> 4;
+		config->fixed_val.gb = blackLevelGreenB_ >> 4;
+		config->fixed_val.b = blackLevelBlue_ >> 4;
+	}
 }
 
 /**
diff --git a/src/ipa/rkisp1/algorithms/blc.h b/src/ipa/rkisp1/algorithms/blc.h
index 372f6f7d00cc..f797ae44d639 100644
--- a/src/ipa/rkisp1/algorithms/blc.h
+++ b/src/ipa/rkisp1/algorithms/blc.h
@@ -20,6 +20,8 @@  public:
 	~BlackLevelCorrection() = default;
 
 	int init(IPAContext &context, const YamlObject &tuningData) override;
+	int configure(IPAContext &context,
+		      const IPACameraSensorInfo &configInfo) override;
 	void prepare(IPAContext &context, const uint32_t frame,
 		     IPAFrameContext &frameContext,
 		     RkISP1Params *params) override;
@@ -29,7 +31,8 @@  public:
 		     ControlList &metadata) override;
 
 private:
-	bool tuningParameters_;
+	bool supported_;
+
 	int16_t blackLevelRed_;
 	int16_t blackLevelGreenR_;
 	int16_t blackLevelGreenB_;