From patchwork Sat Aug 17 10:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1815 Return-Path: Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DFACD61919 for ; Sat, 17 Aug 2019 12:58:17 +0200 (CEST) X-Originating-IP: 87.5.130.64 Received: from uno.homenet.telecomitalia.it (host64-130-dynamic.5-87-r.retail.telecomitalia.it [87.5.130.64]) (Authenticated sender: jacopo@jmondi.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 648CD1C0002; Sat, 17 Aug 2019 10:58:17 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sat, 17 Aug 2019 12:59:35 +0200 Message-Id: <20190817105937.29353-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190817105937.29353-1-jacopo@jmondi.org> References: <20190817105937.29353-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] libcamera: camera_sensor: Store the camera location X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Aug 2019 10:58:18 -0000 Store the camera sensor location by parsing the V4L2_CID_CAMERA_SENSOR_LOCATION V4L2 control. Signed-off-by: Jacopo Mondi --- src/libcamera/camera_sensor.cpp | 25 +++++++++++++++++++++++++ src/libcamera/include/camera_sensor.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index a7670b449b31..2703d10c719e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -89,6 +89,31 @@ int CameraSensor::init() if (ret < 0) return ret; + /* Retrieve and store the camera sensor location. */ + V4L2ControlList controls; + controls.add(V4L2_CID_CAMERA_SENSOR_LOCATION); + + ret = subdev_->getControls(&controls); + if (ret) { + LOG(CameraSensor, Error) + << "Failed to get camera sensor controls: " << ret; + return ret; + } + + V4L2Control *locationControl = controls[V4L2_CID_CAMERA_SENSOR_LOCATION]; + int64_t v4l2Location = locationControl->value(); + switch (v4l2Location) { + case V4L2_LOCATION_FRONT: + location_ = CAMERA_LOCATION_FRONT; + break; + case V4L2_LOCATION_BACK: + location_ = CAMERA_LOCATION_BACK; + break; + default: + LOG(CameraSensor, Error) << "Unsupported camera location"; + return -EINVAL; + } + /* Enumerate and cache media bus codes and sizes. */ const ImageFormats formats = subdev_->formats(0); if (formats.isEmpty()) { diff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h index fe033fb374c1..a237a1684605 100644 --- a/src/libcamera/include/camera_sensor.h +++ b/src/libcamera/include/camera_sensor.h @@ -10,6 +10,7 @@ #include #include +#include #include #include "log.h" @@ -55,6 +56,8 @@ private: std::vector mbusCodes_; std::vector sizes_; + + CameraLocation location_; }; } /* namespace libcamera */