From patchwork Thu Dec 2 14:03:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14989 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4225FBF415 for ; Thu, 2 Dec 2021 14:03:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E74FF60866; Thu, 2 Dec 2021 15:03:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="nBSjjfOA"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C27646011A for ; Thu, 2 Dec 2021 15:03:26 +0100 (CET) Received: by mail-pj1-x1032.google.com with SMTP id iq11so20626947pjb.3 for ; Thu, 02 Dec 2021 06:03:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KkZXJPGYKAYgycnRX84OOEYhChCKyH0ZiBDNjsY7vhI=; b=nBSjjfOAhF5jMvPBNljOjTgZK+V+s3UEnJFPF6K+2SFAG3q2gH7Vu6ktVV7NyD1KCN Ac182ZVtCJw46eIkuP78iy9NfOZhb1JRoIhjKipoZP8OZIKX7LYevp7b8Du9J79qtCtU vI0e+8UBY1pWjoJWV7e885w1frnTzkLcFCcIM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KkZXJPGYKAYgycnRX84OOEYhChCKyH0ZiBDNjsY7vhI=; b=ErNmHg1iit5OZe35ORgWgUcOS5u1UeYfqQ3m60XvasM9U6IeDWTdVSqAsuJ+Zod4en RD2DnS0PP1cMvY7hLJ6UTCDRJIOn6kXRbAs1dCn6G5P11Zqq0pTjZUuqGL6Ol2JFh8yk TXYL8ucWn66YXJ+EdiKvEsGVfakGkMX21g2iB7CkvxqxTx3Xfz3UEKTpIwjpsrjBqkV2 drOQ+EmcSH1q8U+2IIRVlbCNENu/kc7ej6sGqevvAcjINTmW4MpWGoLrVXEjbWPa/H1W SDKM85XBTvxnf6vC0hq/4YXg3uFlgAfLktbHSMICMczqsmtjE/JmpQq02ceCWNtXi125 VoXw== X-Gm-Message-State: AOAM5337fEoTEFL4NnWlkpZxoiePDbTA+by4QtK014GH8xUgp0vMIiu5 e899N6lXXaxJMiRwEAJZlxwqkZqa+qNRCA== X-Google-Smtp-Source: ABdhPJycFT6SnlWOxpdue+kxcHnQKIsf/uWsULuxBTNYqlVOhp6qYgTnl49g/15KbcX94REgaUXA0A== X-Received: by 2002:a17:902:76c6:b0:142:644e:e9a with SMTP id j6-20020a17090276c600b00142644e0e9amr15422170plt.6.1638453804934; Thu, 02 Dec 2021 06:03:24 -0800 (PST) Received: from localhost ([2401:fa00:1:10:9029:d68:4045:e723]) by smtp.gmail.com with UTF8SMTPSA id p21sm3837189pfh.43.2021.12.02.06.03.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Dec 2021 06:03:24 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Dec 2021 22:03:13 +0800 Message-Id: <20211202140317.3118364-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211202140317.3118364-1-hanlinchen@chromium.org> References: <20211202140317.3118364-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 1/5] ipa: ipu3: Extend ipu3 ipa interface for lens controls X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" IPU3Event and IPU3Action use two fields for both libcamera controls and sensor V4L2 controls. The patch extend one more field for lens V4L2 controls for auto focus usage. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- include/libcamera/ipa/ipu3.mojom | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/libcamera/ipa/ipu3.mojom b/include/libcamera/ipa/ipu3.mojom index 16e3462e..cc0d822f 100644 --- a/include/libcamera/ipa/ipu3.mojom +++ b/include/libcamera/ipa/ipu3.mojom @@ -24,12 +24,14 @@ struct IPU3Event { uint32 bufferId; libcamera.ControlList controls; libcamera.ControlList sensorControls; + libcamera.ControlList lensControls; }; struct IPU3Action { IPU3Operations op; libcamera.ControlList controls; libcamera.ControlList sensorControls; + libcamera.ControlList lensControls; }; struct IPAConfigInfo { From patchwork Thu Dec 2 14:03:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14990 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 112F6BF415 for ; Thu, 2 Dec 2021 14:03:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C084F60836; Thu, 2 Dec 2021 15:03:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZSD6vSup"; dkim-atps=neutral Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 171FA605B8 for ; Thu, 2 Dec 2021 15:03:29 +0100 (CET) Received: by mail-pj1-x102f.google.com with SMTP id np3so20604635pjb.4 for ; Thu, 02 Dec 2021 06:03:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jFSmuXDyoaOm5MPWqGwLyyw6AuzVITNkacg+PDSy4ws=; b=ZSD6vSup3EUjaKJgf7wJNMtVpfs8JLkvOR7v3GRInjBnVob0+WLxnF+U5YJ10GTlhE JyX+IF90XK71dA47Y+ELJqKUIhTBGw9ARVMUM9+B3+/FLKcFINomlVxN+3eaMxlGbqCv MiCCzUfFc/B/u73rca+sd7oKgyqgPvXe5LMzE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jFSmuXDyoaOm5MPWqGwLyyw6AuzVITNkacg+PDSy4ws=; b=KC0J8vgb/QL7m4U+dw+2bpzD5m6io27tAEFflSb7ItxNqU0KajeKVrMa7HgvYdMlGl L+EQ+R2cZ2MzASzTFPOLjOhl+IER80mS8298y9c3Q6qTgBfmcXHECh16Rxsdw0j9uqho CStgcZ5OL8ksWhv00iiwwc1Y4VMeDlNY1ba+omBqnz9pGDPvNnAr22IoFKDClqgf48WM K94lxMxivpd1k80zt2FsmQFObYFPJgROFa0zuixz/cXFGDGqurac3G7syRAQdc13zJ2+ 4/EQES+yPhzBVle9pxSayUZPqO80GWcgaaFtxIEW/kaMxDsz1DUe6IDg7/AkZ4BErwfv g1JQ== X-Gm-Message-State: AOAM532V5Jy+PYiyr4I29EmEHh3uaGjn65itQgjxWKNXX1Ew9inWohod 5/uNWxQ2N64liNkgKZ/kbdHGqsGex2pfZA== X-Google-Smtp-Source: ABdhPJyuSl0cmQ8WaTofePTnGMYUQ5ETh0oxKQ9l9J9zIqlFOppXyWQ1iYynNacGbBdWuIlxKLCtyw== X-Received: by 2002:a17:90b:3807:: with SMTP id mq7mr6295255pjb.38.1638453807433; Thu, 02 Dec 2021 06:03:27 -0800 (PST) Received: from localhost ([2401:fa00:1:10:9029:d68:4045:e723]) by smtp.gmail.com with UTF8SMTPSA id s15sm2830397pjs.51.2021.12.02.06.03.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Dec 2021 06:03:26 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Dec 2021 22:03:14 +0800 Message-Id: <20211202140317.3118364-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211202140317.3118364-1-hanlinchen@chromium.org> References: <20211202140317.3118364-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 2/5] libcamera: add model() for retriving model name in V4L2Subdevice X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraSensor retrives model name from media entity. Move the heuristics method into V4L2Subdevice, so CameraLens can reuse the function. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_subdevice.h | 4 ++ src/libcamera/camera_sensor.cpp | 32 +--------------- src/libcamera/v4l2_subdevice.cpp | 42 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..763c4dec 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -61,6 +61,8 @@ public: int setFormat(unsigned int pad, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); + std::string model(); + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -75,6 +77,8 @@ private: unsigned int code); const MediaEntity *entity_; + + std::string model_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..6151b32e 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -347,34 +346,7 @@ void CameraSensor::initTestPatternModes( int CameraSensor::initProperties() { - /* - * Extract the camera sensor model name from the media entity name. - * - * There is no standardized naming scheme for sensor entities in the - * Linux kernel at the moment. - * - * - The most common rule, used by I2C sensors, associates the model - * name with the I2C bus number and address (e.g. 'imx219 0-0010'). - * - * - When the sensor exposes multiple subdevs, the model name is - * usually followed by a function name, as in the smiapp driver (e.g. - * 'jt8ew9 pixel_array 0-0010'). - * - * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'. - * - * Other schemes probably exist. As a best effort heuristic, use the - * part of the entity name before the first space if the name contains - * an I2C address, and use the full entity name otherwise. - */ - std::string entityName = entity_->name(); - std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" }; - std::smatch match; - - if (std::regex_search(entityName, match, i2cRegex)) - model_ = entityName.substr(0, entityName.find(' ')); - else - model_ = entityName; - + model_ = subdev_->model(); properties_.set(properties::Model, utils::toAscii(model_)); /* Generate a unique ID for the sensor. */ @@ -832,7 +804,7 @@ int CameraSensor::generateId() /* * Virtual sensors not described in firmware * - * Verify it's a platform device and construct ID from the deive path + * Verify it's a platform device and construct ID from the device path * and model of sensor. */ if (devPath.find("/sys/devices/platform/", 0) == 0) { diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..17ec9fdf 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -442,6 +443,47 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \brief Retrieve the model name + * \return The model name of the device + */ +std::string V4L2Subdevice::model() +{ + if (!model_.empty()) + return model_; + + /* + * Extract model name from the media entity name. + * + * There is no standardized naming scheme for sensor entities in the + * Linux kernel at the moment. + * + * - The most common rule, used by I2C sensors, associates the model + * name with the I2C bus number and address (e.g. 'imx219 0-0010'). + * + * - When the sensor exposes multiple subdevs, the model name is + * usually followed by a function name, as in the smiapp driver (e.g. + * 'jt8ew9 pixel_array 0-0010'). + * + * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'. + * + * Other schemes probably exist. As a best effort heuristic, use the + * part of the entity name before the first space if the name contains + * an I2C address, and use the full entity name otherwise. + */ + std::string entityName = entity_->name(); + std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" }; + std::smatch match; + + std::string model; + if (std::regex_search(entityName, match, i2cRegex)) + model_ = entityName.substr(0, entityName.find(' ')); + else + model_ = entityName; + + return model_; +} + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media From patchwork Thu Dec 2 14:03:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14991 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 75D6EBF415 for ; Thu, 2 Dec 2021 14:03:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B7C56011A; Thu, 2 Dec 2021 15:03:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PLOUNRaG"; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C69956011A for ; Thu, 2 Dec 2021 15:03:31 +0100 (CET) Received: by mail-pl1-x62b.google.com with SMTP id z6so20297244plk.6 for ; Thu, 02 Dec 2021 06:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJ63cKZP+EAGTa4hwAstFtBGEEx2PmjCe6CbWfZO8eI=; b=PLOUNRaGfcB4Xfyn1610TxhTJKrkAP1O6H1zFxfJgHLHFMe/t17e05ugKGeRrIoURl PtU0qmDnPW2bcrk+1WomBw+/+x8mkCnyL4j35tVTJedZ0lhAfzdPQa0KfyIWrd9HaaIC pDKBEahjt0EA4sQUISqf3wqwVH7wkHl5vPQIs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJ63cKZP+EAGTa4hwAstFtBGEEx2PmjCe6CbWfZO8eI=; b=7y3TUS1WHGAgDf40xUzKnvypPDEtaDH36FK6HuSbjfdi3211XtLg+tOD/RRe4qUfRJ Q3u4GpzbAoACcbL5KkHCCSmUZaLDj+z9IWtAoHNDvDFk7V/u6CG8BcRA9hw0NDmtzG42 v2MdJKxMr2EM8hxtpsr7MpMAzwlY3c3deLD7n1CaS5KTj/S8s81ikTAfwcWh9dSSqnMo YvgK6SKXuGnc6Iuty6TSCTZUbhl+jW5NpKda4K9I9JjfNGonvQS+MVzsOCtoHaatQFx6 1YzaoSe90ikhjPlLtlydUXWsOnCssM4W3Hs2enBB2fI9u0TiACc0RG9DItgzjrMU/LqB pbaA== X-Gm-Message-State: AOAM5303t7WRxc0nECdPIZ7/PKNUKAKZ2LxFHBoOCURR4Ry6Zw8A40Nj 0q8oeZbcoEZXsnvJKf/+pPGVe0Ibw4NhZQ== X-Google-Smtp-Source: ABdhPJz+cJxy1AXsKZ4awMrwWP0WkJP0SllQ7zhYLZatHflqiRDgtt5yd682Cl1cnoghE6SxLNypRw== X-Received: by 2002:a17:90a:df14:: with SMTP id gp20mr6235775pjb.186.1638453809944; Thu, 02 Dec 2021 06:03:29 -0800 (PST) Received: from localhost ([2401:fa00:1:10:9029:d68:4045:e723]) by smtp.gmail.com with UTF8SMTPSA id p6sm2799505pjb.48.2021.12.02.06.03.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Dec 2021 06:03:29 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Dec 2021 22:03:15 +0800 Message-Id: <20211202140317.3118364-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211202140317.3118364-1-hanlinchen@chromium.org> References: <20211202140317.3118364-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 3/5] libcamera: camera_lens: Add a new class to model a camera lens X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraLens class abstracts camera lens and provides helper functions to ease interactions with them. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- Documentation/index.rst | 1 + Documentation/lens_driver_requirements.rst | 27 ++++ Documentation/meson.build | 1 + include/libcamera/internal/camera_lens.h | 45 +++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_lens.cpp | 142 +++++++++++++++++++++ src/libcamera/meson.build | 1 + 7 files changed, 218 insertions(+) create mode 100644 Documentation/lens_driver_requirements.rst create mode 100644 include/libcamera/internal/camera_lens.h create mode 100644 src/libcamera/camera_lens.cpp diff --git a/Documentation/index.rst b/Documentation/index.rst index 1f4fc485..0ee10044 100644 --- a/Documentation/index.rst +++ b/Documentation/index.rst @@ -21,3 +21,4 @@ Tracing guide Environment variables Sensor driver requirements + Lens driver requirements diff --git a/Documentation/lens_driver_requirements.rst b/Documentation/lens_driver_requirements.rst new file mode 100644 index 00000000..b96e502d --- /dev/null +++ b/Documentation/lens_driver_requirements.rst @@ -0,0 +1,27 @@ +.. SPDX-License-Identifier: CC-BY-SA-4.0 + +.. _lens-driver-requirements: + +Lens Driver Requirements +======================== + +libcamera handles lens devices in the CameraLens class and defines +a consistent interface through its API towards other library components. + +The CameraLens class uses the V4L2 subdev kernel API to interface with the +camera lens through a sub-device exposed to userspace by the lens driver. + +In order for libcamera to be fully operational and provide all the required +information to interface with the camera lens to applications and pipeline +handlers, a set of mandatory features the driver has to support has been defined. + +Mandatory Requirements +---------------------- + +The lens driver is assumed to be fully compliant with the V4L2 specification. + +The lens driver shall support the following V4L2 controls: + +* `V4L2_CID_FOCUS_ABSOLUTE`_ + +.. _V4L2_CID_FOCUS_ABSOLUTE: https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-camera.html diff --git a/Documentation/meson.build b/Documentation/meson.build index 4c972675..33af82aa 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -66,6 +66,7 @@ if sphinx.found() 'guides/pipeline-handler.rst', 'guides/tracing.rst', 'index.rst', + 'lens_driver_requirements.rst', 'sensor_driver_requirements.rst', '../README.rst', ] diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h new file mode 100644 index 00000000..6f2ea1bc --- /dev/null +++ b/include/libcamera/internal/camera_lens.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_lens.h - A camera lens controller + */ +#pragma once + +#include +#include + +#include +#include + +namespace libcamera { + +class MediaEntity; +class V4L2Subdevice; + +class CameraLens : protected Loggable +{ +public: + explicit CameraLens(const MediaEntity *entity); + ~CameraLens(); + + int init(); + int setFocusPostion(int32_t position); + + const std::string &model() const { return model_; } + +protected: + std::string logPrefix() const override; + +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraLens) + + int validateLensDriver(); + + const MediaEntity *entity_; + std::unique_ptr subdev_; + + std::string model_; +}; + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 665fd6de..a96bbb95 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -14,6 +14,7 @@ libcamera_internal_headers = files([ 'byte_stream_buffer.h', 'camera.h', 'camera_controls.h', + 'camera_lens.h', 'camera_sensor.h', 'camera_sensor_properties.h', 'control_serializer.h', diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp new file mode 100644 index 00000000..189cb025 --- /dev/null +++ b/src/libcamera/camera_lens.cpp @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_lens.cpp - A camera lens + */ + +#include "libcamera/internal/camera_lens.h" + +#include + +#include "libcamera/internal/v4l2_subdevice.h" + +/** + * \file camera_lens.h + * \brief A camera lens controller + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(CameraLens) + +/** + * \class CameraLens + * \brief A camera lens based on V4L2 subdevices + * + * The CameraLens class eases handling of lens for pipeline handlers by + * hiding the details of the V4L2 subdevice kernel API and caching lens + * information. + */ + +/** + * \brief Construct a CameraLens + * \param[in] entity The media entity backing the camera lens controller + * + * Once constructed the instance must be initialized with init(). + */ +CameraLens::CameraLens(const MediaEntity *entity) + : entity_(entity) +{ +} + +/** + * \brief Destroy a CameraLens + */ +CameraLens::~CameraLens() = default; + +/** + * \brief Initialize the camera lens instance + * + * This function performs the initialisation steps of the CameraLens that may + * fail. It shall be called once and only once after constructing the instance. + * + * \return 0 on success or a negative error code otherwise + */ +int CameraLens::init() +{ + if (entity_->function() != MEDIA_ENT_F_LENS) { + LOG(CameraLens, Error) + << "Invalid lens function " + << utils::hex(entity_->function()); + return -EINVAL; + } + + /* Create and open the subdev. */ + subdev_ = std::make_unique(entity_); + int ret = subdev_->open(); + if (ret < 0) + return ret; + + ret = validateLensDriver(); + if (ret) + return ret; + + model_ = subdev_->model(); + return 0; +} + +/** + * \brief This function sets the focal point of the lens to a specific position. + * \param[in] position The focal point of the lens + * + * This function sets the value of focal point of the lens as in \a position. + * + * \return 0 on success or -EINVAL otherwise + */ +int CameraLens::setFocusPostion(int32_t position) +{ + ControlList lensCtrls(subdev_->controls()); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(position)); + + if (subdev_->setControls(&lensCtrls)) + return -EINVAL; + + return 0; +} + +int CameraLens::validateLensDriver() +{ + int ret = 0; + static constexpr uint32_t mandatoryControls[] = { + V4L2_CID_FOCUS_ABSOLUTE, + }; + + const ControlInfoMap &controls = subdev_->controls(); + for (uint32_t ctrl : mandatoryControls) { + if (!controls.count(ctrl)) { + LOG(CameraLens, Error) + << "Mandatory V4L2 control " << utils::hex(ctrl) + << " not available"; + ret = -EINVAL; + } + } + + if (ret) { + LOG(CameraLens, Error) + << "The lens kernel driver needs to be fixed"; + LOG(CameraLens, Error) + << "See Documentation/lens_driver_requirements.rst in" + << " the libcamera sources for more information"; + return ret; + } + + return ret; +} + +/** + * \fn CameraLens::model() + * \brief Retrieve the lens model name + * + * The lens model name is a free-formed string that uniquely identifies the + * lens model. + * + * \return The lens model name + */ + +std::string CameraLens::logPrefix() const +{ + return "'" + entity_->name() + "'"; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 6727a777..3bee8fee 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -5,6 +5,7 @@ libcamera_sources = files([ 'byte_stream_buffer.cpp', 'camera.cpp', 'camera_controls.cpp', + 'camera_lens.cpp', 'camera_manager.cpp', 'camera_sensor.cpp', 'camera_sensor_properties.cpp', From patchwork Thu Dec 2 14:03:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14992 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DB693BF415 for ; Thu, 2 Dec 2021 14:03:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8F62E60862; Thu, 2 Dec 2021 15:03:35 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="AXUwuHgD"; dkim-atps=neutral Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A0DD605B8 for ; Thu, 2 Dec 2021 15:03:34 +0100 (CET) Received: by mail-pf1-x433.google.com with SMTP id n85so27982700pfd.10 for ; Thu, 02 Dec 2021 06:03:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2McPthkXJ9/lLtflTowN3HeopjV9PW8uYtzgNugHnu8=; b=AXUwuHgD8Mfqs+jXkcBMD97qPt/N9BCQ0QSO7IqzTJgrRpJCvFWnEH/IsHYZqfvLG4 uqpT7cwYEg6o7GrETg8YN7o23HXTRDd3dbHiJI0EN44UYJsyjXQ3dcF/zuRI6rrVfb52 6zKq3s56lA5lJds+sbVJhP3gue39/KHNbPPbE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2McPthkXJ9/lLtflTowN3HeopjV9PW8uYtzgNugHnu8=; b=1olzYpaonjlWOI3vxtgLfFC8GSYaUAtDqxeFxJby8CgaTt3EMLFfdWIfiE4deQNMBk b427GhtL4YA7fAJ0SVklhTHQvamLcgq6izgNZC/IJ1oBqvJyBc7aPg6nFvKrsQHuROkZ oZnB8KcIp92/79c0u2jdiml7xO5BMaEuaAw+36FuhEpjzMOtyW1ek7R8lgB6xFFTOEIL RidyOmjUBCoyCQcFWDRcnRo0yaJkg9L+exl3GKoGd5CihX2usoEDzawFCsIUHhaBEKcy 28FBC/IrIQeFkMzqR3LFckLfHBYuZKL3OmJjKT6jMMbBvNlR1c8IWpi2tplNJK6DWI3X eI6A== X-Gm-Message-State: AOAM533a8r3U5A2C+CZYsiJIDL6uP7NHMfBS8aIXPoZUQuXJPugoFl6q lm6IyllgArEXy6WbFCZhyJQCgY2V4S5M+A== X-Google-Smtp-Source: ABdhPJwasaRNLRu9/L82wW5C6ikqUxfHmYyvBGtCsOW9rgCL1+yTNqQh3JKeTQzykMMqPVMoV3Gu0A== X-Received: by 2002:a65:4cc1:: with SMTP id n1mr9710857pgt.420.1638453812374; Thu, 02 Dec 2021 06:03:32 -0800 (PST) Received: from localhost ([2401:fa00:1:10:9029:d68:4045:e723]) by smtp.gmail.com with UTF8SMTPSA id f2sm3878134pfe.132.2021.12.02.06.03.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Dec 2021 06:03:32 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Dec 2021 22:03:16 +0800 Message-Id: <20211202140317.3118364-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211202140317.3118364-1-hanlinchen@chromium.org> References: <20211202140317.3118364-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 4/5] libcamera: camera_lens: add CameraLens as a member of CameraSensor X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add CameraLens as a member of CameraSenosr. The patch does not implement how to link the lens to the specific sensor yet. Only to provide an interface for pipeline handler's usage. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 5 +++++ src/libcamera/camera_sensor.cpp | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d25a1165..8e97a80e 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -24,6 +24,7 @@ namespace libcamera { class BayerFormat; +class CameraLens; class MediaEntity; class CameraSensor : protected Loggable @@ -60,6 +61,8 @@ public: void updateControlInfo(); + CameraLens *lens() { return lens_.get(); } + protected: std::string logPrefix() const override; @@ -91,6 +94,8 @@ private: const BayerFormat *bayerFormat_; ControlList properties_; + + std::unique_ptr lens_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 6151b32e..b386e7b0 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -20,6 +20,7 @@ #include #include "libcamera/internal/bayer_format.h" +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor_properties.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/sysfs.h" @@ -787,6 +788,13 @@ void CameraSensor::updateControlInfo() subdev_->updateControlInfo(); } +/** + * \fn CameraSensor::lens() + * \brief Retrieve the lens controller + * + * \return The lens controller. nullptr if no lens is connected to the sensor + */ + std::string CameraSensor::logPrefix() const { return "'" + entity_->name() + "'"; From patchwork Thu Dec 2 14:03:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14993 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 506CFBF415 for ; Thu, 2 Dec 2021 14:03:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0A66E60876; Thu, 2 Dec 2021 15:03:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Z+4vNwE1"; dkim-atps=neutral Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45FEC605B8 for ; Thu, 2 Dec 2021 15:03:36 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so2522021pju.3 for ; Thu, 02 Dec 2021 06:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aQHpsPdta6ziFqfTvCAUcpIaejkMZEdSho4mOQlpNqA=; b=Z+4vNwE1tpzPQUW1+Ww+3+i7DQd7DeKkovbG2GhuTrXOcUlzPE/azIb7/JFnnWPBMN DlzwnZ18zC36ZVSH7meZc4QFOp37EK98DOjkBGzIZ4tJbeUnWBQhBdPEOtS30zxuGooc k3cfDBkH5wOXtLVNzT+J0mxwEXQYeb5DEpvPo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aQHpsPdta6ziFqfTvCAUcpIaejkMZEdSho4mOQlpNqA=; b=dOTaZ4dLISGLMKrFqYQifBL73aXmFk3bBnFwn7gqcp/dv/SNjQxb5tracukaMT5XUm tl5+2ijzuJUtK2RvoQmo23mwm4Ee/hr2z9lnTDduR/A4Ucr9sNmMKIA+yrWjJrw8fZkU Ecy7kUUleBMnHNJNykzZ2W+BWzkqu4z8VRYrPjuAXCwf9i2SyTTld7xNrmhqk4+qnI3r 2/4R8pO1wBRda3V8DAUepx2GTspcZTZTRN8Vb7CP3ETalsewV8IW9xCIIpy3Jd78u5yZ z8/yy00Mj4KL1Cm4rvxHOLvQFKJNJiaw16oVxS0aCdXbZ+d7o0f+2kvXXKgyqyMOqqQl s7iA== X-Gm-Message-State: AOAM530NncpDmT0iYMhbxzYbFAkzmWg3/6/hjOwAcCa1nPdCR7NBgJ4b WLMbG+gz5Uww3N/Gfq632TOU4wU3LZFxuQ== X-Google-Smtp-Source: ABdhPJy8441E0e4AYx5EzaJgHai/3U4p+AZCXne2aNvRdBmJFMGyErCDDJJhqHIlbVw6WcE07XQHag== X-Received: by 2002:a17:90b:3908:: with SMTP id ob8mr6233468pjb.57.1638453814647; Thu, 02 Dec 2021 06:03:34 -0800 (PST) Received: from localhost ([2401:fa00:1:10:9029:d68:4045:e723]) by smtp.gmail.com with UTF8SMTPSA id b8sm3407187pfr.213.2021.12.02.06.03.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 Dec 2021 06:03:34 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Thu, 2 Dec 2021 22:03:17 +0800 Message-Id: <20211202140317.3118364-6-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.1.400.ga245620fadb-goog In-Reply-To: <20211202140317.3118364-1-hanlinchen@chromium.org> References: <20211202140317.3118364-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 5/5] ipu3: ipa: Allow IPA to apply controls to the lens device X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Allow IPA to apply controls to the lens device. Signed-off-by: Han-Lin Chen Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index c65afdb2..d26c8a2e 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -24,6 +24,7 @@ #include #include "libcamera/internal/camera.h" +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/delayed_controls.h" #include "libcamera/internal/device_enumerator.h" @@ -1238,8 +1239,16 @@ void IPU3CameraData::queueFrameAction(unsigned int id, { switch (action.op) { case ipa::ipu3::ActionSetSensorControls: { - const ControlList &controls = action.sensorControls; - delayedCtrls_->push(controls); + const ControlList &sensorControls = action.sensorControls; + delayedCtrls_->push(sensorControls); + + const ControlList lensControls = action.lensControls; + const ControlValue &focusValue = + lensControls.get(V4L2_CID_FOCUS_ABSOLUTE); + + CameraLens *lens = cio2_.sensor()->lens(); + if (lens && !focusValue.isNone()) + lens->setFocusPostion(focusValue.get()); break; } case ipa::ipu3::ActionParamFilled: {