[libcamera-devel,5/6] libcamera: ipu3: Set pipe_mode based on stream configuration

Message ID 20190602130435.18780-6-jacopo@jmondi.org
State Accepted
Headers show
Series
  • libcamera: v4l2_controls: Add support for V4L2 controls
Related show

Commit Message

Jacopo Mondi June 2, 2019, 1:04 p.m. UTC
Set the ImgU pipe_mode control based on the active stream configuration.
Use 'Video' pipe mode unless the viewfinder stream is not active.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 30 ++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Patch

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 05005c42106b..0a50b6159782 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -22,6 +22,7 @@ 
 #include "media_device.h"
 #include "pipeline_handler.h"
 #include "utils.h"
+#include "v4l2_controls.h"
 #include "v4l2_device.h"
 #include "v4l2_subdevice.h"
 
@@ -29,6 +30,10 @@  namespace libcamera {
 
 LOG_DEFINE_CATEGORY(IPU3)
 
+#define IPU3_PIPE_MODE_CTRL	0x009819c1
+static V4L2IntControl IPU3PipeModeStillCapture(IPU3_PIPE_MODE_CTRL, 1);
+static V4L2IntControl IPU3PipeModeVideo(IPU3_PIPE_MODE_CTRL, 0);
+
 class ImgUDevice
 {
 public:
@@ -485,6 +490,7 @@  int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)
 	IPU3Stream *vfStream = &data->vfStream_;
 	CIO2Device *cio2 = &data->cio2_;
 	ImgUDevice *imgu = data->imgu_;
+	V4L2IntControl *pipeMode;
 	int ret;
 
 	/*
@@ -536,6 +542,7 @@  int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)
 	 * the configuration of the active one for that purpose (there should
 	 * be at least one active stream in the configuration request).
 	 */
+	pipeMode = &IPU3PipeModeVideo;
 	if (!outStream->active_) {
 		ret = imgu->configureOutput(outStream->device_, config->at(0));
 		if (ret)
@@ -546,6 +553,12 @@  int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)
 		ret = imgu->configureOutput(vfStream->device_, config->at(0));
 		if (ret)
 			return ret;
+
+		/*
+		 * \todo: This works as long as only two concurrent streams
+		 * per pipe are supported.
+		 */
+		pipeMode = &IPU3PipeModeStillCapture;
 	}
 
 	/*
@@ -559,6 +572,23 @@  int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)
 	if (ret)
 		return ret;
 
+	/* Apply the "pipe_mode" control to the ImgU subdevice. */
+	ret = imgu->imgu_->setControl(pipeMode);
+	if (ret) {
+		LOG(IPU3, Error) << "Unable to set pipe_mode control";
+		return ret;
+	}
+
+	V4L2Control *pipeModeCtrl = imgu->imgu_->getControl(IPU3_PIPE_MODE_CTRL);
+	if (!pipeModeCtrl) {
+		LOG(IPU3, Error) << "Unable to get pipe_mode control value";
+		return ret;
+	}
+
+	pipeMode = static_cast<V4L2IntControl *>(pipeModeCtrl);
+	LOG(IPU3, Debug) << "ImgU pipe mode set to: "
+			 << (pipeMode->value() ? "'Still Capture'"
+					       : "'Video'");
 	return 0;
 }