From patchwork Tue Nov 30 10:51:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14887 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 B22E5BDB13 for ; Tue, 30 Nov 2021 10:52:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6AEBF605B8; Tue, 30 Nov 2021 11:52:07 +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="Pjb0hPXx"; 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 50EA3605A4 for ; Tue, 30 Nov 2021 11:52:06 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id x7so15072049pjn.0 for ; Tue, 30 Nov 2021 02:52:06 -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=Co9Gj6E0SMOgGloogeFHf71M+RMWRlI5QsSOwt7cS/0=; b=Pjb0hPXxpRyf4hYZQEmW31fBMsBG55bEhq/RBDw+/pM9b/BZzqZJnw3/Rp3KMT0mI9 tn7o+8qTDroE1Jaq2faU8UZXo8QqKC8xvvWdhymkcGIaZGsnxvdBeHLBkfkou+N1h69Y bYIcpXI0EoY8x3lgT+k23gnQAI8VXU3IIJKT8= 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=Co9Gj6E0SMOgGloogeFHf71M+RMWRlI5QsSOwt7cS/0=; b=vNroVjiUuNguH7VaRS5zVhOrZyjU0820CqnGT4Qqg2oqqK11X7gFCo14zaATqf4nzu 2F36V7A8nnAj4nzSuJ2Q8iYYwRW/nvqR02G0CXqDotLNqC6/ERUtYoLf2TBsJ1+zv+z6 EJ/K2ivSScY1LPZfBjK1hd7oKm0fJakWplQT1Pb00H6/GYgX3UXUNupRQCrsGbthQ2o9 xpwSTPQsPRq/1SJE/nPZkTCC8mGgSqDb1ttvvelgt1kC9UNfp+zEaJHn5rwPDmtdfmtu YviWSK8MCiObcSFo3gunyZe3T9ASSksLW9yfBvE5NCE7z8VP6M8d/do4kJ771gXCWs/t 9Naw== X-Gm-Message-State: AOAM530dtxZdZ93SrmDD79sra+Eh/y1LNer/65mBd5nyPgbyMxe55CKp tb8xndoDuyJ8Pihd1CObq2djU9wyMK/gzA== X-Google-Smtp-Source: ABdhPJzEV9A7fwigqoR9EQnVmlx5n79dZqoYuZJtx71YK18UTXQsXXTIgAlT9xMlcCZK7wWQDCh3zQ== X-Received: by 2002:a17:90b:4b51:: with SMTP id mi17mr5161011pjb.48.1638269524216; Tue, 30 Nov 2021 02:52:04 -0800 (PST) Received: from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38]) by smtp.gmail.com with UTF8SMTPSA id v63sm14619120pgv.71.2021.11.30.02.52.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 02:52:03 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 18:51:54 +0800 Message-Id: <20211130105157.203856-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130105157.203856-1-hanlinchen@chromium.org> References: <20211130105157.203856-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 1/4] 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 --- 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 Tue Nov 30 10:51:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14888 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 584E8BDB13 for ; Tue, 30 Nov 2021 10:52:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14EF5605BA; Tue, 30 Nov 2021 11:52:11 +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="O6xCgaar"; dkim-atps=neutral Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D55F3605B4 for ; Tue, 30 Nov 2021 11:52:07 +0100 (CET) Received: by mail-pl1-x636.google.com with SMTP id b13so14624120plg.2 for ; Tue, 30 Nov 2021 02:52:07 -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=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=; b=O6xCgaarz5R0qcF9uAIb3U5E15RJHzT8nPbGdQQdeC8zpZZiTmsziu/BbwKbID/6pP DPmxh9F0rk5Yo0Ko6mHvzUf4/sk7WMEB8QaWQrN0rPCfutngwnBoqQ352OQ1fk6fYcJ0 k+HUxfOqzoWQMNt5A/VyX0jV27nf4iaDrA1i4= 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=msPJW3r55nb+G45KIz3gMpKkpg99ieTA6FL6j5NXWwI=; b=Alw+Y4qDLNa/U0aLjMh6BXsGFooRPKQFHMPrIz6MPylI6YUGUXLmoMd0OmsIIy/S3b sccan0Be8Y7SjH1TwKICQs6yXYWjKxbQV6VBp5ooPUbVjNS25/apBuaq3hVSkKEE5yFV idTo/EQuqNeyq5hDuKSUB9QiieLXEtrU0ucWcL58hjEKiz6xCzXCJkJ7cnm2YoH76J3v bDsndIzeynuVW57gaHkdp2YqaUAFc1VJbUK5W+ts5Gr/EiUJinwQivhvDeVXHnpFMFI1 gpvigESPjLhm51udhSqoB87TNJnJNo7mW+4HFyL2uCqbSEQBD0EUJJzIue/IptSXYmze dacA== X-Gm-Message-State: AOAM532vGoMPTmwA7jbkOzep+UJG8tu8kmVb+4joad4LxzlnZjeWhpm/ ivwHrMgCIiDzY9pAmqtje+AnPB9JkzS6BQ== X-Google-Smtp-Source: ABdhPJw9H20HYgshJ1g+ofP4Z86tKuV0EwOn8RddUY4Ort478hj7jb2tyQYcH3966sdT8thpCNdiSg== X-Received: by 2002:a17:90b:3a85:: with SMTP id om5mr5154759pjb.28.1638269526201; Tue, 30 Nov 2021 02:52:06 -0800 (PST) Received: from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38]) by smtp.gmail.com with UTF8SMTPSA id j16sm1651386pga.32.2021.11.30.02.52.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 02:52:05 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 18:51:55 +0800 Message-Id: <20211130105157.203856-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130105157.203856-1-hanlinchen@chromium.org> References: <20211130105157.203856-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 2/4] 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 --- 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 Tue Nov 30 10:51:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14889 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 F12CFBDB13 for ; Tue, 30 Nov 2021 10:52:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A03D960230; Tue, 30 Nov 2021 11:52:12 +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="LoxTAlax"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FA38605B7 for ; Tue, 30 Nov 2021 11:52:10 +0100 (CET) Received: by mail-pg1-x535.google.com with SMTP id 71so19346237pgb.4 for ; Tue, 30 Nov 2021 02:52:10 -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=F1vwhP5RgG8QaekroMGG0M2Z8gxjFljzKVlYD09fApc=; b=LoxTAlaxjHNhnm5nWaJ289i6vE8yQqleIvauts/ZE23Xl9C2gzpBJgOZW0Q0eBYuKH rB8m9K35zGu5RhhvHH0jZKlbaYTZjL+neJ57oUCfDMFskZQJ7xwuU5gI9KUyuaReITiO E0lcY1ZQD0d550m4dff3nP+7uG4DE5iYC0rJ0= 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=F1vwhP5RgG8QaekroMGG0M2Z8gxjFljzKVlYD09fApc=; b=uhQFREHwHT1x7Vvm0Lyku5B0VnmCQo/LEtWdvB1jwHlWJAaq3054Ge8d6gdgDFBk9R dk6Lh7Q56XpmPjubEVQE9s4N9mW1raG9Ijgj4iMbONTyXGb9frSoeh/XcgEK5BUri/ml eLov4ykTRPpGaI8Iv3/gG+p5XPNqqSLZRzJAbjSqOtJ/7jdCkXPu2urc8MoicIOPokXr GuaRY2goVgUpkR3IsPmwgbM0qwn50g5c8vFNQSH2Xb5STIQ5UIhkBBQJKFAj19kLkowq v0IdFPJGhfFbKq3WRtFAECj0F75jwASO1GK/NYqhT1EF5sjkgSgm0wOg4Tf6hoNQn/cj +LmA== X-Gm-Message-State: AOAM531k9e58JFSe886sG8m9qB/J2kKD29Mg/argrCSbglUTLEPS18Ge 5xuHxKnmhZH6RrkY90GSR+x+aS/f6rBU7A== X-Google-Smtp-Source: ABdhPJz4bwlBeTvQ677dLJk6EZD26TJDUXa4Qrcc/nNioridrLGlZrkKjE0yOul4HC5SOArJ1UDZxQ== X-Received: by 2002:a05:6a00:14d4:b0:49f:f2ca:e2fc with SMTP id w20-20020a056a0014d400b0049ff2cae2fcmr44990310pfu.54.1638269528435; Tue, 30 Nov 2021 02:52:08 -0800 (PST) Received: from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38]) by smtp.gmail.com with UTF8SMTPSA id c6sm22841609pfv.54.2021.11.30.02.52.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 02:52:08 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 18:51:56 +0800 Message-Id: <20211130105157.203856-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130105157.203856-1-hanlinchen@chromium.org> References: <20211130105157.203856-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 3/4] 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 --- 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 Tue Nov 30 10:51:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14890 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 2B819BDB13 for ; Tue, 30 Nov 2021 10:52:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DA022605B4; Tue, 30 Nov 2021 11:52:15 +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="Zn4uEUBq"; dkim-atps=neutral Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27F5F605B4 for ; Tue, 30 Nov 2021 11:52:12 +0100 (CET) Received: by mail-pl1-x630.google.com with SMTP id v19so14590812plo.7 for ; Tue, 30 Nov 2021 02:52:12 -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=mIKd6VTNdAEOYNVDMVnDc05R76+FTwUSTeL7x6XXBVw=; b=Zn4uEUBqWXQ+LrH1lnSo7+3wZTJzMsYIv1SiMplinHHPRDvVe8vyFHs2O7yeQWQOpX h2M/z6phvTmsFvV0Q1jW2BTpzonYz3OvqQ9bdj6I07y68jQCAwulCE16EhoG2l28Nt9Q 8TLnQKFkR5E/gWZe9DuRYlGHk4XZ9UwY0scjM= 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=mIKd6VTNdAEOYNVDMVnDc05R76+FTwUSTeL7x6XXBVw=; b=74w+RhgEcB0DRx8xHl42cRlxVDLeKtFTgzRnV0w5P69Tg9y4tEE/zlTWBW3J698z31 LAM82HGvsbQiyS0umUzSI0k8rQPrvbFlCd81fC3an/X0fxb0VPZrd7TjaC7f/75vJZRI K25vxvpaYGalPh9+g1e7F7V838jquZokHGlqZBd3o0SGlTUQEHNJE2QF+mJRD5Hmgj/X GN5Ls7lNUqFnX2tuaiHeWodKWQnvImt/aD46PIzn8SNZCmNL4TsykMyWBZe70aiqlHPQ RoIv3/HyzGl0iJ7t9gWIhk+aBRqFSL2QBAwrEbbKxR3UoCOqk48ePH4osUt5qoUozsAe HBEA== X-Gm-Message-State: AOAM533ozuVaorhKfUbnKx/RvEOfS3RFuvIWjYRWYP+cnKWWmoizlhIV tdB4ddPbHrlhbsL88GRMsdqF1FPoCFsc0g== X-Google-Smtp-Source: ABdhPJy1m6MS2MTAlKoDmfK/bsPdt1VfDcqCRtlFBuGN4CGktcoPYhC3DIyFITTh7xrQJYFPLDE/XA== X-Received: by 2002:a17:902:e741:b0:141:f9a7:4995 with SMTP id p1-20020a170902e74100b00141f9a74995mr66943009plf.49.1638269530583; Tue, 30 Nov 2021 02:52:10 -0800 (PST) Received: from localhost ([2401:fa00:1:10:1659:cd3d:a00c:fa38]) by smtp.gmail.com with UTF8SMTPSA id mn15sm2045591pjb.35.2021.11.30.02.52.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Nov 2021 02:52:10 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 18:51:57 +0800 Message-Id: <20211130105157.203856-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130105157.203856-1-hanlinchen@chromium.org> References: <20211130105157.203856-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 4/4] 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 --- src/libcamera/pipeline/ipu3/cio2.cpp | 1 + src/libcamera/pipeline/ipu3/cio2.h | 3 +++ src/libcamera/pipeline/ipu3/ipu3.cpp | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 59dda56b..ff795310 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -16,6 +16,7 @@ #include #include +#include "libcamera/internal/camera_lens.h" #include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/framebuffer.h" #include "libcamera/internal/media_device.h" diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index ba8f0052..635566c8 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -18,6 +18,7 @@ namespace libcamera { +class CameraLens; class CameraSensor; class FrameBuffer; class MediaDevice; @@ -52,6 +53,7 @@ public: int stop(); CameraSensor *sensor() { return sensor_.get(); } + CameraLens *lens() { return lens_.get(); } const CameraSensor *sensor() const { return sensor_.get(); } FrameBuffer *queueBuffer(Request *request, FrameBuffer *rawBuffer); @@ -67,6 +69,7 @@ private: void cio2BufferReady(FrameBuffer *buffer); std::unique_ptr sensor_; + std::unique_ptr lens_; std::unique_ptr csi2_; std::unique_ptr output_; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index c65afdb2..6e04ec8f 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,15 @@ 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); + if (!focusValue.isNone() && cio2_.lens()) + cio2_.lens()->setFocusPostion(focusValue.get()); + break; } case ipa::ipu3::ActionParamFilled: {