From patchwork Fri Nov 26 11:29:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14805 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 11E72BF415 for ; Fri, 26 Nov 2021 11:29:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B54E160555; Fri, 26 Nov 2021 12:29:18 +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="Wa+dF1x8"; dkim-atps=neutral Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 395B660546 for ; Fri, 26 Nov 2021 12:29:16 +0100 (CET) Received: by mail-pf1-x42e.google.com with SMTP id g19so8647438pfb.8 for ; Fri, 26 Nov 2021 03:29:16 -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=Zj3ETCdTBLu7RAS5BC4KuZZFoO4fy7wXGac8BmsLB78=; b=Wa+dF1x8TbGh4O0PWq12KuG0ZV7aeecrIJu2JGOYUpYCrszvSXZ3b6rmt+ZRaGlOJ8 eInzoTOG4q2PYe6h8/tAnA/nkcbZvWMSrT5au3/X2jR2ldbKG3e8F3v4VJDa6kuxAg0J /AAtn44hDPorsWrYn9//9wcJ6mwINSY9PZN5w= 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=Zj3ETCdTBLu7RAS5BC4KuZZFoO4fy7wXGac8BmsLB78=; b=DdjRRdhxm6nfZRYXR1q+2vkxVHSGvmwHbetXOkGJ2p3tUk8GhJxq93kh/9uH79dUc4 LD6PGu9jweY5L/0ZhR2SdJM1L2hNGYfPwWnyjnssaPDxD71C3dhzvlWRl/4uHU+Di2o3 3BM+2vrH2Y0zvSFYpODMV3GABAI1/VgxsZt/AFD8C1yXtjKnzJDc4mRVBVxbOnhvMCDq tMuBngzoDRIHjA/tpo5y8WCeTKwnl4xXi0dOxZirOdZamwIQ30mPoGyDOqZWqhcnruJu Wz8eUz/Mu8Mc/efbbLPkKjDV57bqf6uwMJYO1UzI+bfQwQlxbXDUyG3XIsZdDxQ1/uKp jEwQ== X-Gm-Message-State: AOAM531bPzQwg6aI+JgWd5w9NZtNQkTMMkNELl4wj7fZ6GH7/UEGjV1l nO7wuMo0KqvU7RTvz/Qu//9MfwSE1L/lxQ== X-Google-Smtp-Source: ABdhPJyozB8AqrBEcZInusrrnGiqR95i+JkNARz4mDb7sUFW4PLk0kbuwaMOa7Qh6xMytgCgeSyX/g== X-Received: by 2002:a05:6a00:7cc:b0:49f:9cf1:2969 with SMTP id n12-20020a056a0007cc00b0049f9cf12969mr20582502pfu.12.1637926154506; Fri, 26 Nov 2021 03:29:14 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a0de:e637:c058:6824]) by smtp.gmail.com with UTF8SMTPSA id d7sm7365954pfj.91.2021.11.26.03.29.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 03:29:14 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 19:29:00 +0800 Message-Id: <20211126112903.3276056-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211126112903.3276056-1-hanlinchen@chromium.org> References: <20211126112903.3276056-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 Fri Nov 26 11:29:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14806 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 62EBEBF415 for ; Fri, 26 Nov 2021 11:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 197E660555; Fri, 26 Nov 2021 12:29:22 +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="I4Uphpqa"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 698096011E for ; Fri, 26 Nov 2021 12:29:18 +0100 (CET) Received: by mail-pl1-x629.google.com with SMTP id b11so6485532pld.12 for ; Fri, 26 Nov 2021 03:29:18 -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=Eo24BCzFTNfwI9ZVqRhR4vaLcTMu7CGBWJcis3efd/E=; b=I4UphpqaDnCcuQVHDP4g+e8I7aygtyL/mXrKz1MH73zEXaDcI8fGB5wKaprNgrwVAd ONreeBAeIyu0eXpWyDgC7AGcbtCIe85mgvIbNjg5IAIloSteq3U8dVkFJjOLru/9N6cA 6zaPRaPZqfyeaO/K2JvR3ImFdX7NpKOC8dYFI= 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=Eo24BCzFTNfwI9ZVqRhR4vaLcTMu7CGBWJcis3efd/E=; b=aVlDli0QrQFytO5Mtabo75Ax7ArvroHFfTvCA8LgOw6YGHEYZjdMCPAAcvu1TXlQLL /AFX+EFcqx01kK61mIQyJWeYsMEBMugUcSPdKhmYHUnW1YHLSNrD/pOFDzKEZ2NBVQGX 4R8LJtF9FawhwmvDVIVY0SigM+ShcI1ZPJz/lfGpUilrU3p/39ZuNPuRYBXLWGso7Lgy wsr9wxBdxpxlpo1loE1Is2ZIp8YkIal+lJa5ADSlZm9PF5nJav+auUuJMcu/kDFwLrxJ 9UHfOcZgbr3HJNiWmrwN3mujIcejqUbQuz0fg7yZa0tBpYKjO6fvCnnkzTOk/3PR2abh j6/Q== X-Gm-Message-State: AOAM532+X/tevS5P78RfCQZex0cYgBya/YWuSYZ2aY7rBhiUC3+VQ9cx 6oLKooCpCFmKv+Hz78Wh7joG4w0frlMH0A== X-Google-Smtp-Source: ABdhPJzhsbqKpYs7LEtMJhp9pNDT15yjK/wmGHCI5GwnUYaDrF1iE4xWkGj6Oj4S4LGl31O6ZfG9xw== X-Received: by 2002:a17:90a:909:: with SMTP id n9mr15067185pjn.1.1637926156454; Fri, 26 Nov 2021 03:29:16 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a0de:e637:c058:6824]) by smtp.gmail.com with UTF8SMTPSA id c18sm7133362pfl.201.2021.11.26.03.29.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 03:29:16 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 19:29:01 +0800 Message-Id: <20211126112903.3276056-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211126112903.3276056-1-hanlinchen@chromium.org> References: <20211126112903.3276056-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- include/libcamera/internal/v4l2_subdevice.h | 5 +++ src/libcamera/camera_sensor.cpp | 13 ++----- src/libcamera/v4l2_subdevice.cpp | 40 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 97b89fb9..794c80c6 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() { return model_; } + static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); @@ -73,8 +75,11 @@ private: std::vector enumPadCodes(unsigned int pad); std::vector enumPadSizes(unsigned int pad, unsigned int code); + void generateModel(); const MediaEntity *entity_; + + std::string model_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..3659ff2d 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -366,15 +365,7 @@ int CameraSensor::initProperties() * 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 +823,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..0e194081 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -239,6 +240,7 @@ uint8_t V4L2SubdeviceFormat::bitsPerPixel() const V4L2Subdevice::V4L2Subdevice(const MediaEntity *entity) : V4L2Device(entity->deviceNode()), entity_(entity) { + generateModel(); } V4L2Subdevice::~V4L2Subdevice() @@ -442,6 +444,12 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \fn V4L2Subdevice::model() + * \brief Retrieve the model name + * \return The model name of the device + */ + /** * \brief Create a new video subdevice instance from \a entity in media device * \a media @@ -525,4 +533,36 @@ std::vector V4L2Subdevice::enumPadSizes(unsigned int pad, return sizes; } +void V4L2Subdevice::generateModel() +{ + /* + * 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; +} + } /* namespace libcamera */ From patchwork Fri Nov 26 11:29:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14807 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 4B818C324F for ; Fri, 26 Nov 2021 11:29:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B9BAF6055F; Fri, 26 Nov 2021 12:29:22 +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="SE8lgssC"; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49E7D60230 for ; Fri, 26 Nov 2021 12:29:20 +0100 (CET) Received: by mail-pf1-x434.google.com with SMTP id o4so8630442pfp.13 for ; Fri, 26 Nov 2021 03:29:20 -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=Ebu2k7YiEpI8mIiynRyzp9HXCENuqe/DRckWU+FF+Xc=; b=SE8lgssCm7urRSRyxqtd0hoeg7dcLchW433nLSiJ+TjBJKZvlZWsMxDobqxOxE8S56 NIf3qeZ7s70wtudhoUZFNax/syp5RL75VDHzqKdkuJ/QXWFpVCN8oD4L8p8mdLJm96j7 ygVPt3JZ2TiMdlPoiZj6jzBFGTB+SrWJzxbt8= 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=Ebu2k7YiEpI8mIiynRyzp9HXCENuqe/DRckWU+FF+Xc=; b=P86b7VREG4EEgBFYNobN8n1b28pBkdzsJRvJs93+IcTfRn52O/bJWat1wYFSeyMTr5 z92EfaSjTeiYYlVgEWB2Hv3GkK00M7It7sCdxT2N6xXsRPE4d5EOHUQoMcKH5Oa3D9ab BHGn1RSGq+gXGXC0YRDQ5yFi5HmtEMQLmV+JGoo2x3LTxpTlo3tHIphneMX3a3g/fGbZ OzO5CjL3K741CCJX8E1OWlX4FeD6o5iVeOXZTXh8bBvd8CjXzUvXXc9WzHaQq7iNz/Uu tFfuXR6zTgishBsV7G+3PzqpM0vXQRuYT5wluhbhKEo5cpBq6pob6CRlDDWS97Xq2Z/J pomw== X-Gm-Message-State: AOAM532+3eZfl4BzSyneh0MdL4mJwMTv8063SWI6kP/dEeXrOS8KxTuq tYrSCYlmN1xXvCbLWKOCvOSFg2norcou4Q== X-Google-Smtp-Source: ABdhPJzFk53OG0VAAf/Baa5QARzsLZTjvCRRC5ddnfU5O5Pdl6U679kBoQq6kvCDhqALJyvxpHmNsQ== X-Received: by 2002:a62:ce4c:0:b0:4a4:d175:306f with SMTP id y73-20020a62ce4c000000b004a4d175306fmr20333134pfg.75.1637926158583; Fri, 26 Nov 2021 03:29:18 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a0de:e637:c058:6824]) by smtp.gmail.com with UTF8SMTPSA id q6sm7147278pfk.144.2021.11.26.03.29.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 03:29:18 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 19:29:02 +0800 Message-Id: <20211126112903.3276056-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211126112903.3276056-1-hanlinchen@chromium.org> References: <20211126112903.3276056-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 | 48 +++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_lens.cpp | 142 +++++++++++++++++++++ src/libcamera/meson.build | 1 + 7 files changed, 221 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..21e778fd --- /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-devices exposed in 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..3597e929 --- /dev/null +++ b/include/libcamera/internal/camera_lens.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_lens.h - A camera lens + */ +#ifndef __LIBCAMERA_INTERNAL_CAMERA_LENS_H__ +#define __LIBCAMERA_INTERNAL_CAMERA_LENS_H__ + +#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 */ + +#endif /* __LIBCAMERA_INTERNAL_CAMERA_LENS_H__ */ 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 Fri Nov 26 11:29:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14808 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 A476DBF415 for ; Fri, 26 Nov 2021 11:29:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6194860543; Fri, 26 Nov 2021 12:29:25 +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="MWqFQJbL"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9AC42604FB for ; Fri, 26 Nov 2021 12:29:22 +0100 (CET) Received: by mail-pf1-x42d.google.com with SMTP id p13so1001283pfw.2 for ; Fri, 26 Nov 2021 03:29:22 -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=Wts5FaHlWgEzLQTSI6cOeLZs+nV4J2NqWI0WqjNYSw0=; b=MWqFQJbLwsoOP+KdWh6bYysOLa6F5ePqTT4XOLoaAkNznVZKbGSGt+gZPNL+tNWr48 xUCMbJ1XmaV3AbYtmxzPFQ7iMtPgN0LVNhDJpJx+DJobn4a3JcIaKKmNDFfUbpEiJVyp IQajH9SR41q35Gk9a9xyvvLbqnoAORR0qigYo= 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=Wts5FaHlWgEzLQTSI6cOeLZs+nV4J2NqWI0WqjNYSw0=; b=KHKYZpJMU7PNj6s9FnJnrDz5AK8tWoxKEYkmkwdGFPUx1ZDYyVerQbfm3JNqahB0BU ADa64knAkwaaTftje6tO03N45M4mfL83tYkjtIEHP0eiRLKpSwwqxscGElvOUSqurfmh AYFrUoKMymZq0ZSe95++S99raWqWKRiQrMjsE+3Gr8pBDsgevh6GW5FvYG0nBJ9YaMKt oi1DiDacNC0vvzMyLtBqLApeyCwG7J+78lEdtJQFR9FRCEMDJB6xAfunfr1zNzP4PHzi UAQF+o6qckOmQBz90NE8Hahige2ueOnsK5Aq9EHauUhbFONcmn1fbiJkcjlc5nfHETCI UzIA== X-Gm-Message-State: AOAM530x/kPydQL8U/Em5menEdeFmPQhWf3jbjUrYBXsqDyFoOncQkWV r/kgdxZKIwymhoKMAYKgwdQGC4qBg9DPhw== X-Google-Smtp-Source: ABdhPJz8NOas1neJLo5fLxU7Q644qjr8KwsnjnVBDjeiqP1qN2iZ1bDORAgGW0FRjgWt8nHG08AyXA== X-Received: by 2002:a63:3e88:: with SMTP id l130mr18513607pga.266.1637926160998; Fri, 26 Nov 2021 03:29:20 -0800 (PST) Received: from localhost ([2401:fa00:1:10:a0de:e637:c058:6824]) by smtp.gmail.com with UTF8SMTPSA id d10sm6817669pfl.139.2021.11.26.03.29.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Nov 2021 03:29:20 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 19:29:03 +0800 Message-Id: <20211126112903.3276056-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211126112903.3276056-1-hanlinchen@chromium.org> References: <20211126112903.3276056-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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 --- src/libcamera/pipeline/ipu3/cio2.cpp | 29 ++++++++++++++++++++++++++++ src/libcamera/pipeline/ipu3/cio2.h | 3 +++ src/libcamera/pipeline/ipu3/ipu3.cpp | 12 ++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 59dda56b..59b2f586 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" @@ -159,6 +160,34 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) return -EINVAL; } + /* + * \todo Read the lens model from the sensor itself or from a device + * database. For now use default values taken from ChromeOS database. + */ + static std::unordered_map sensorLens = { + { "ov13858", "dw9714" }, + { "imx258", "dw9807" }, + { "imx355", "ak7375" } + }; + + auto it = sensorLens.find(sensor_->model()); + if (it != sensorLens.end()) { + const std::vector &entities = media->entities(); + for (auto ent : entities) { + if (ent->function() == MEDIA_ENT_F_LENS) { + lens_ = std::make_unique(ent); + ret = lens_->init(); + if (!ret && lens_->model() == it->second) { + break; + } + lens_.reset(); + } + if (!lens_) + LOG(IPU3, Warning) << "Lens device " + << it->second << " not found"; + } + } + /* * \todo Define when to open and close video device nodes, as they * might impact on power consumption. 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: {