Show a patch.

GET /api/1.1/patches/15005/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 15005,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/15005/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15005/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20211203094426.101454-4-hanlinchen@chromium.org>",
    "date": "2021-12-03T09:44:24",
    "name": "[libcamera-devel,v8,3/5] libcamera: camera_lens: Add a new class to model a camera lens",
    "commit_ref": "6e80c1bcf410cca4b0c028dd337a749a50f9bb7a",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "6ad8be749843da833c683473d7c1d5435f54cbea",
    "submitter": {
        "id": 98,
        "url": "https://patchwork.libcamera.org/api/1.1/people/98/?format=api",
        "name": "Hanlin Chen",
        "email": "hanlinchen@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/15005/mbox/",
    "series": [
        {
            "id": 2807,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2807/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2807",
            "date": "2021-12-03T09:44:21",
            "name": "Introduce Lens class and apply auto focus on ipu3",
            "version": 8,
            "mbox": "https://patchwork.libcamera.org/series/2807/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15005/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15005/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 73D5FBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  3 Dec 2021 09:44:40 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B82460862;\n\tFri,  3 Dec 2021 10:44:40 +0100 (CET)",
            "from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com\n\t[IPv6:2607:f8b0:4864:20::62f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1874C60710\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  3 Dec 2021 10:44:39 +0100 (CET)",
            "by mail-pl1-x62f.google.com with SMTP id b11so1692053pld.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 03 Dec 2021 01:44:39 -0800 (PST)",
            "from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647])\n\tby smtp.gmail.com with UTF8SMTPSA id\n\tcv1sm4698908pjb.48.2021.12.03.01.44.35\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 03 Dec 2021 01:44:36 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"CF+ABvzv\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=HiGSGWbAJ4xqd7rUssmXQArMeNPZOnVUtiN/sIjJRK4=;\n\tb=CF+ABvzvZiVrpfvbzf0NjWaCDopCCt0jQ0A3kVrVaVh/8NQTEesv2455mvR0P6BGiw\n\tpvAmt2i9TksW/RSOv4dPV59rmHywQEPva+r7jNujFTtyZB11/qUZ/edqvCofD2lJMwrR\n\tOlIIRZ3zxiCXonMgSSzvgnfojAvs8YrSUj+Zg=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=HiGSGWbAJ4xqd7rUssmXQArMeNPZOnVUtiN/sIjJRK4=;\n\tb=VOSPpwgFN1C+OvlSczBQGabm/eZnYE6oH2lFaw3NiWa8OCBTmqBOLf5ijJfKeoIhLN\n\tq4dAJ25ypT/wM2RTkoqnRS4hRslZEkUHoofx1pLGejd6s/5GRxCsS/fh1PtP4NDNvgMt\n\twlXQn2r3WqXQag2wm1P7c7CG8XgMFvORnde4TbigW25Mzy4XK7k/ac6i5OfooDHj0SWe\n\tuZ2DgUBQE+yqaKO9gF8UEM2/Tpr3hNX0mdKgsi3jlMFUWr75CztoB00FaTlZJzt0KOJy\n\tVpcz9FCmnpE4OeVY61ypY7zKuPseWHT0IJnXYnz754JPVVTtQQbah4pOLc+IXetnxQXC\n\t0wFQ==",
        "X-Gm-Message-State": "AOAM532w20scXugoioFJ6Tf8KN7QQG8Zhp+8f+T+RerLetlNRKEi/r0d\n\tAc2ZLoaCeneResXsPD0w8qaFxIZ/fu0DIA==",
        "X-Google-Smtp-Source": "ABdhPJy4KS/CsdKrFdIsCPqYvMGE5Db+8IHFZui9PpqWBgt74WFo89LHR4begxctIy62sCH/ucSxKQ==",
        "X-Received": "by 2002:a17:902:6b07:b0:142:852a:9e1f with SMTP id\n\to7-20020a1709026b0700b00142852a9e1fmr21435661plk.29.1638524677207; \n\tFri, 03 Dec 2021 01:44:37 -0800 (PST)",
        "From": "Han-Lin Chen <hanlinchen@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  3 Dec 2021 17:44:24 +0800",
        "Message-Id": "<20211203094426.101454-4-hanlinchen@chromium.org>",
        "X-Mailer": "git-send-email 2.34.0.384.gca35af8252-goog",
        "In-Reply-To": "<20211203094426.101454-1-hanlinchen@chromium.org>",
        "References": "<20211203094426.101454-1-hanlinchen@chromium.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v8 3/5] libcamera: camera_lens: Add a new\n\tclass to model a camera lens",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "The CameraLens class abstracts camera lens and provides helper\nfunctions to ease interactions with them.\n\nSigned-off-by: Han-Lin Chen <hanlinchen@chromium.org>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n---\n Documentation/index.rst                    |   1 +\n Documentation/lens_driver_requirements.rst |  27 ++++\n Documentation/meson.build                  |   1 +\n include/libcamera/internal/camera_lens.h   |  45 +++++++\n include/libcamera/internal/meson.build     |   1 +\n src/libcamera/camera_lens.cpp              | 142 +++++++++++++++++++++\n src/libcamera/meson.build                  |   1 +\n 7 files changed, 218 insertions(+)\n create mode 100644 Documentation/lens_driver_requirements.rst\n create mode 100644 include/libcamera/internal/camera_lens.h\n create mode 100644 src/libcamera/camera_lens.cpp",
    "diff": "diff --git a/Documentation/index.rst b/Documentation/index.rst\nindex 1f4fc485..0ee10044 100644\n--- a/Documentation/index.rst\n+++ b/Documentation/index.rst\n@@ -21,3 +21,4 @@\n    Tracing guide <guides/tracing>\n    Environment variables <environment_variables>\n    Sensor driver requirements <sensor_driver_requirements>\n+   Lens driver requirements <lens_driver_requirements>\ndiff --git a/Documentation/lens_driver_requirements.rst b/Documentation/lens_driver_requirements.rst\nnew file mode 100644\nindex 00000000..b96e502d\n--- /dev/null\n+++ b/Documentation/lens_driver_requirements.rst\n@@ -0,0 +1,27 @@\n+.. SPDX-License-Identifier: CC-BY-SA-4.0\n+\n+.. _lens-driver-requirements:\n+\n+Lens Driver Requirements\n+========================\n+\n+libcamera handles lens devices in the CameraLens class and defines\n+a consistent interface through its API towards other library components.\n+\n+The CameraLens class uses the V4L2 subdev kernel API to interface with the\n+camera lens through a sub-device exposed to userspace by the lens driver.\n+\n+In order for libcamera to be fully operational and provide all the required\n+information to interface with the camera lens to applications and pipeline\n+handlers, a set of mandatory features the driver has to support has been defined.\n+\n+Mandatory Requirements\n+----------------------\n+\n+The lens driver is assumed to be fully compliant with the V4L2 specification.\n+\n+The lens driver shall support the following V4L2 controls:\n+\n+* `V4L2_CID_FOCUS_ABSOLUTE`_\n+\n+.. _V4L2_CID_FOCUS_ABSOLUTE: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-camera.html\ndiff --git a/Documentation/meson.build b/Documentation/meson.build\nindex 4c972675..33af82aa 100644\n--- a/Documentation/meson.build\n+++ b/Documentation/meson.build\n@@ -66,6 +66,7 @@ if sphinx.found()\n         'guides/pipeline-handler.rst',\n         'guides/tracing.rst',\n         'index.rst',\n+        'lens_driver_requirements.rst',\n         'sensor_driver_requirements.rst',\n        '../README.rst',\n     ]\ndiff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h\nnew file mode 100644\nindex 00000000..6f2ea1bc\n--- /dev/null\n+++ b/include/libcamera/internal/camera_lens.h\n@@ -0,0 +1,45 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * camera_lens.h - A camera lens controller\n+ */\n+#pragma once\n+\n+#include <memory>\n+#include <string>\n+\n+#include <libcamera/base/class.h>\n+#include <libcamera/base/log.h>\n+\n+namespace libcamera {\n+\n+class MediaEntity;\n+class V4L2Subdevice;\n+\n+class CameraLens : protected Loggable\n+{\n+public:\n+\texplicit CameraLens(const MediaEntity *entity);\n+\t~CameraLens();\n+\n+\tint init();\n+\tint setFocusPostion(int32_t position);\n+\n+\tconst std::string &model() const { return model_; }\n+\n+protected:\n+\tstd::string logPrefix() const override;\n+\n+private:\n+\tLIBCAMERA_DISABLE_COPY_AND_MOVE(CameraLens)\n+\n+\tint validateLensDriver();\n+\n+\tconst MediaEntity *entity_;\n+\tstd::unique_ptr<V4L2Subdevice> subdev_;\n+\n+\tstd::string model_;\n+};\n+\n+} /* namespace libcamera */\ndiff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build\nindex 665fd6de..a96bbb95 100644\n--- a/include/libcamera/internal/meson.build\n+++ b/include/libcamera/internal/meson.build\n@@ -14,6 +14,7 @@ libcamera_internal_headers = files([\n     'byte_stream_buffer.h',\n     'camera.h',\n     'camera_controls.h',\n+    'camera_lens.h',\n     'camera_sensor.h',\n     'camera_sensor_properties.h',\n     'control_serializer.h',\ndiff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp\nnew file mode 100644\nindex 00000000..189cb025\n--- /dev/null\n+++ b/src/libcamera/camera_lens.cpp\n@@ -0,0 +1,142 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * camera_lens.cpp - A camera lens\n+ */\n+\n+#include \"libcamera/internal/camera_lens.h\"\n+\n+#include <libcamera/base/utils.h>\n+\n+#include \"libcamera/internal/v4l2_subdevice.h\"\n+\n+/**\n+ * \\file camera_lens.h\n+ * \\brief A camera lens controller\n+ */\n+\n+namespace libcamera {\n+\n+LOG_DEFINE_CATEGORY(CameraLens)\n+\n+/**\n+ * \\class CameraLens\n+ * \\brief A camera lens based on V4L2 subdevices\n+ *\n+ * The CameraLens class eases handling of lens for pipeline handlers by\n+ * hiding the details of the V4L2 subdevice kernel API and caching lens\n+ * information.\n+ */\n+\n+/**\n+ * \\brief Construct a CameraLens\n+ * \\param[in] entity The media entity backing the camera lens controller\n+ *\n+ * Once constructed the instance must be initialized with init().\n+ */\n+CameraLens::CameraLens(const MediaEntity *entity)\n+\t: entity_(entity)\n+{\n+}\n+\n+/**\n+ * \\brief Destroy a CameraLens\n+ */\n+CameraLens::~CameraLens() = default;\n+\n+/**\n+ * \\brief Initialize the camera lens instance\n+ *\n+ * This function performs the initialisation steps of the CameraLens that may\n+ * fail. It shall be called once and only once after constructing the instance.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ */\n+int CameraLens::init()\n+{\n+\tif (entity_->function() != MEDIA_ENT_F_LENS) {\n+\t\tLOG(CameraLens, Error)\n+\t\t\t<< \"Invalid lens function \"\n+\t\t\t<< utils::hex(entity_->function());\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/* Create and open the subdev. */\n+\tsubdev_ = std::make_unique<V4L2Subdevice>(entity_);\n+\tint ret = subdev_->open();\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tret = validateLensDriver();\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmodel_ = subdev_->model();\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief This function sets the focal point of the lens to a specific position.\n+ * \\param[in] position The focal point of the lens\n+ *\n+ * This function sets the value of focal point of the lens as in \\a position.\n+ *\n+ * \\return 0 on success or -EINVAL otherwise\n+ */\n+int CameraLens::setFocusPostion(int32_t position)\n+{\n+\tControlList lensCtrls(subdev_->controls());\n+\tlensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(position));\n+\n+\tif (subdev_->setControls(&lensCtrls))\n+\t\treturn -EINVAL;\n+\n+\treturn 0;\n+}\n+\n+int CameraLens::validateLensDriver()\n+{\n+\tint ret = 0;\n+\tstatic constexpr uint32_t mandatoryControls[] = {\n+\t\tV4L2_CID_FOCUS_ABSOLUTE,\n+\t};\n+\n+\tconst ControlInfoMap &controls = subdev_->controls();\n+\tfor (uint32_t ctrl : mandatoryControls) {\n+\t\tif (!controls.count(ctrl)) {\n+\t\t\tLOG(CameraLens, Error)\n+\t\t\t\t<< \"Mandatory V4L2 control \" << utils::hex(ctrl)\n+\t\t\t\t<< \" not available\";\n+\t\t\tret = -EINVAL;\n+\t\t}\n+\t}\n+\n+\tif (ret) {\n+\t\tLOG(CameraLens, Error)\n+\t\t\t<< \"The lens kernel driver needs to be fixed\";\n+\t\tLOG(CameraLens, Error)\n+\t\t\t<< \"See Documentation/lens_driver_requirements.rst in\"\n+\t\t\t<< \" the libcamera sources for more information\";\n+\t\treturn ret;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * \\fn CameraLens::model()\n+ * \\brief Retrieve the lens model name\n+ *\n+ * The lens model name is a free-formed string that uniquely identifies the\n+ * lens model.\n+ *\n+ * \\return The lens model name\n+ */\n+\n+std::string CameraLens::logPrefix() const\n+{\n+\treturn \"'\" + entity_->name() + \"'\";\n+}\n+\n+} /* namespace libcamera */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex ddedc78c..a0e3c689 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -5,6 +5,7 @@ libcamera_sources = files([\n     'byte_stream_buffer.cpp',\n     'camera.cpp',\n     'camera_controls.cpp',\n+    'camera_lens.cpp',\n     'camera_manager.cpp',\n     'camera_sensor.cpp',\n     'camera_sensor_properties.cpp',\n",
    "prefixes": [
        "libcamera-devel",
        "v8",
        "3/5"
    ]
}