From db6a3bfa6e92081c33463ce58c51ac8fae7f854c Mon Sep 17 00:00:00 2001
From: Jacopo Mondi <jacopo@jmondi.org>
Date: Tue, 5 Jan 2021 13:12:38 +0100
Subject: libcamera: camera_sensor: Initialize VIMC properties
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The VIMC driver does not yet support all the features required
for all sensor drivers. As it is the main testing platforms and the
driver changes might take a long time to land in the developments
and testing platforms, temporary close the gap by skipping driver
validation and initializing properties with static information such
as the sensor resolution.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 include/libcamera/internal/camera_sensor.h |  1 +
 src/libcamera/camera_sensor.cpp            | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 86902b85..fed36bf2 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -70,6 +70,7 @@ protected:
 private:
 	int generateId();
 	int validateSensorDriver();
+	void initVimcDefaultProperties();
 	int initProperties();
 
 	const MediaEntity *entity_;
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index e9c80c30..251691ae 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "libcamera/internal/camera_sensor.h"
+#include "libcamera/internal/media_device.h"
 
 #include <algorithm>
 #include <float.h>
@@ -207,6 +208,21 @@ int CameraSensor::init()
 	 */
 	resolution_ = sizes_.back();
 
+	/*
+	 * VIMC is a bit special, as it does not yet support all the mandatory
+	 * requirements regular sensors have to respect.
+	 *
+	 * Do not validate the driver if it's VIMC and initialize the sensor
+	 * properties with static information.
+	 *
+	 * \todo Remove the special case once the VIMC driver has been
+	 * updated in all test platforms.
+	 */
+	if (entity_->device()->driver() == "vimc") {
+		initVimcDefaultProperties();
+		return initProperties();
+	}
+
 	ret = validateSensorDriver();
 	if (ret)
 		return ret;
@@ -304,6 +320,16 @@ int CameraSensor::validateSensorDriver()
 	return 0;
 }
 
+/*
+ * \brief Initialize properties that cannot be intialized by the
+ * regular initProperties() function for VIMC
+ */
+void CameraSensor::initVimcDefaultProperties()
+{
+	pixelArraySize_ = resolution();
+	activeArea_ = Rectangle(pixelArraySize_);
+}
+
 int CameraSensor::initProperties()
 {
 	/*
-- 
cgit v1.2.1