From patchwork Fri Dec 3 09:44:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15003 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 A58A5BDB13 for ; Fri, 3 Dec 2021 09:44:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5DDCC6084A; Fri, 3 Dec 2021 10:44: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="ETDJ/CJM"; dkim-atps=neutral Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3CC6260710 for ; Fri, 3 Dec 2021 10:44:34 +0100 (CET) Received: by mail-pg1-x52d.google.com with SMTP id 133so2456100pgc.12 for ; Fri, 03 Dec 2021 01:44: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=mjrurec9ea45rKuUYvsbyyUWooqtEO7znSiEL6ewWEc=; b=ETDJ/CJMGG1Scg6B0VvAGbjwXU+A48++DOnMAeQv5AVn672rN5DGTSMrk6dIAXCNdP baKg8uSYEYvNFx1HSnVJ40xp53ia32y1IWYUcAANTP2Pvutabd8/bBRekoMJX/d388wl idqmI/bXBY/tMrAvhV733O4r5jkpp08aODOTA= 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=mjrurec9ea45rKuUYvsbyyUWooqtEO7znSiEL6ewWEc=; b=FvMeqLtqI5YC6DoIQpzSDDIrjjpecMy4MWCe/Wx4Zm2tZagFa5iFNZn1kYL+RpFPuQ exSlIWgQCyeOqeH46mN8IWlL4VACECHE04qgbSJonYoRJ16IL9jNRsgSURvMdFd2CwHA hXxE+MTtCd/tTg82yRrm6DsO/yIc0rDZUXuikilk1IT2zs6D1mV3AS5WKLQD65zN4Tq6 PRecSTLXqTlKUKAtsBmw9hDEMUDraW81tdmoFgDArIzXPYskCdS6tg4SxlLG2JwkUJ9A esvDo5cK87fLWrulAd9EUYusOc+lUBLHS3ndodDF8MyXsI3sLEN/PzXOkKaCuu/LKt4E WTaQ== X-Gm-Message-State: AOAM533S35r/CkXaK5KCX4JeSNdLTpI+Uvge6tIWxQIfyM8m7h6UBv/7 GvBNZ2nC/BG6lO35dgdGjD45eiSbhjvyrA== X-Google-Smtp-Source: ABdhPJx0ie11DHu/1l9BV/0sleNKDZnBZaIa0TTyQB87liDDuqp6vGYCDenN8O7JQcIqjeiUP0GYKg== X-Received: by 2002:aa7:88d6:0:b0:49f:dd4b:ddbc with SMTP id k22-20020aa788d6000000b0049fdd4bddbcmr18058429pff.31.1638524672354; Fri, 03 Dec 2021 01:44:32 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id b14sm2887364pfv.65.2021.12.03.01.44.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:31 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:22 +0800 Message-Id: <20211203094426.101454-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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 Fri Dec 3 09:44:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15004 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 0E474BDB13 for ; Fri, 3 Dec 2021 09:44:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5FCB607DE; Fri, 3 Dec 2021 10:44:38 +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="mf1RH6W5"; dkim-atps=neutral Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C69D560710 for ; Fri, 3 Dec 2021 10:44:36 +0100 (CET) Received: by mail-pl1-x634.google.com with SMTP id k4so1710060plx.8 for ; Fri, 03 Dec 2021 01:44: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=Z4QqmdJUB/xMXj6lpUpiLyim0Gmrw/FIaSyOxP2tj9A=; b=mf1RH6W5fIYIwtmVmNp82txbSVDqJJpA5JioVjt75EHMsTKEqSHu9D9cI5E+dhfMl/ LJW9yn/rV8z/OuARNzZTFJcMziU5qwn+Cu+UiSAmsQV73+XBQBRUkS12cdV2x8z8RHGa +TGzxXAeZtKgHY764eZCrKTrTP0un1aX+8tPc= 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=Z4QqmdJUB/xMXj6lpUpiLyim0Gmrw/FIaSyOxP2tj9A=; b=y6UhhCN8WWQ2gfq6AHjuq++7IGKshw8wXZQmn7JGYPXL0dTPRYzhtSOx2THL1n8Kna nNoDYvReJ6H5Qob/puMTxFnLIReSm0q0XrKG3gFoVHtg/ZKXFjek43EguvXs5DpH6qEb CDQbm7JK6JL47hentJW78oU33yTAWb2+KCTh+FUTSYeoB46EWP5IHaAhCJYe1mWFj1Np bRdBlRYd/8zXAa1nUAUJeTMk9G2syH5sJU0Mk2olZiRylzWCSeWMzHNUpaNrbOnLW3sc VQSF3yaZvfGzn+viWWSBDjW7IlnhmrQVr51S1AHSEUi0vxb8Bs97cLTsORMjscKx/2wr SFgg== X-Gm-Message-State: AOAM5303kRiqHAVIgTtrcdtqfmpqHSmaemWXwAaiPiTXwfDNLE3+YPFe gX+97VHL4tpQapW01nUotP40QLRVSNKVow== X-Google-Smtp-Source: ABdhPJw1eXKrFHaDYGsgWR4mnCHTjY6MKhZueE/OhziRm2+SnwF70SSs/xYGwb5UP0opAJM2aDLL8Q== X-Received: by 2002:a17:90a:c286:: with SMTP id f6mr12913665pjt.45.1638524674770; Fri, 03 Dec 2021 01:44:34 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id y6sm2817203pfi.154.2021.12.03.01.44.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:34 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:23 +0800 Message-Id: <20211203094426.101454-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 2/5] libcamera: add model() for retrieving 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 retrieves 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 | 53 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 484fcfdd..a6873b67 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); + const 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..61e15b69 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,58 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, return 0; } +/** + * \brief Retrieve the model name of the device + * + * The model name allows identification of the specific device model. This can + * be used to infer device characteristics, for instance to determine the + * analogue gain model of a camera sensor based on the sensor model name. + * + * Neither the V4L2 API nor the Media Controller API expose an explicit model + * name. This function implements a heuristics to extract the model name from + * the subdevice's entity name. This should produce accurate results for + * I2C-based devices. If the heuristics can't match a known naming pattern, + * the function returns the full entity name. + * + * \return The model name of the device + */ +const 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 or other 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 Fri Dec 3 09:44:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15005 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 73D5FBDB13 for ; Fri, 3 Dec 2021 09:44:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B82460862; Fri, 3 Dec 2021 10:44:40 +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="CF+ABvzv"; dkim-atps=neutral Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1874C60710 for ; Fri, 3 Dec 2021 10:44:39 +0100 (CET) Received: by mail-pl1-x62f.google.com with SMTP id b11so1692053pld.12 for ; Fri, 03 Dec 2021 01:44:39 -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=HiGSGWbAJ4xqd7rUssmXQArMeNPZOnVUtiN/sIjJRK4=; b=CF+ABvzvZiVrpfvbzf0NjWaCDopCCt0jQ0A3kVrVaVh/8NQTEesv2455mvR0P6BGiw pvAmt2i9TksW/RSOv4dPV59rmHywQEPva+r7jNujFTtyZB11/qUZ/edqvCofD2lJMwrR OlIIRZ3zxiCXonMgSSzvgnfojAvs8YrSUj+Zg= 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=HiGSGWbAJ4xqd7rUssmXQArMeNPZOnVUtiN/sIjJRK4=; b=VOSPpwgFN1C+OvlSczBQGabm/eZnYE6oH2lFaw3NiWa8OCBTmqBOLf5ijJfKeoIhLN q4dAJ25ypT/wM2RTkoqnRS4hRslZEkUHoofx1pLGejd6s/5GRxCsS/fh1PtP4NDNvgMt wlXQn2r3WqXQag2wm1P7c7CG8XgMFvORnde4TbigW25Mzy4XK7k/ac6i5OfooDHj0SWe uZ2DgUBQE+yqaKO9gF8UEM2/Tpr3hNX0mdKgsi3jlMFUWr75CztoB00FaTlZJzt0KOJy Vpcz9FCmnpE4OeVY61ypY7zKuPseWHT0IJnXYnz754JPVVTtQQbah4pOLc+IXetnxQXC 0wFQ== X-Gm-Message-State: AOAM532w20scXugoioFJ6Tf8KN7QQG8Zhp+8f+T+RerLetlNRKEi/r0d Ac2ZLoaCeneResXsPD0w8qaFxIZ/fu0DIA== X-Google-Smtp-Source: ABdhPJy4KS/CsdKrFdIsCPqYvMGE5Db+8IHFZui9PpqWBgt74WFo89LHR4begxctIy62sCH/ucSxKQ== X-Received: by 2002:a17:902:6b07:b0:142:852a:9e1f with SMTP id o7-20020a1709026b0700b00142852a9e1fmr21435661plk.29.1638524677207; Fri, 03 Dec 2021 01:44:37 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id cv1sm4698908pjb.48.2021.12.03.01.44.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:36 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:24 +0800 Message-Id: <20211203094426.101454-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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 ddedc78c..a0e3c689 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 Dec 3 09:44:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15006 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 D7B29BDB13 for ; Fri, 3 Dec 2021 09:44:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 93C8760832; Fri, 3 Dec 2021 10:44:42 +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="Qza/PZoc"; 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 25204607DE for ; Fri, 3 Dec 2021 10:44:41 +0100 (CET) Received: by mail-pl1-x636.google.com with SMTP id b13so1732809plg.2 for ; Fri, 03 Dec 2021 01:44:41 -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=91+Ee9OsrtZPeC0t7KdR7vuUzPXFmVUxQdvdEkxOXGk=; b=Qza/PZocqcKFTpyh1xrbaCq25g8q9oT65ClGhdUCSJuSssgconsSHU+nt9CHknB09X WJbLWnSKiH0NaoqkJtVkt10L5ACfF4bFJdWpPHTXRNUGOna0SyRIDy4GIB2bjvBktM07 F4yMTXkWJrih6PAb0BHaH/J0Nip4AaC3rlu+I= 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=91+Ee9OsrtZPeC0t7KdR7vuUzPXFmVUxQdvdEkxOXGk=; b=whYNb1QRydQL1FSN1kYlDm6yCdSJJf5tFOLN2KZ+NSO9TXUiOoOpocuXe13TDz41XY N9EOSR86GuC+Eg980HJvYsYV7E7EJSEGcokqj9BkL06NCN4FgBIo8OZxkN+sfhzduwI6 ze+xkZLpuyJZW5M76GL/zO1+mSQuN6I5mMWePIptLrx2b/v8HQkINOzRwxMmE4SBEHUr Xt5REqmEJYjXQguJrodssnDHW/EYQ/Z8kDTbvv1o4DVLe/034YajufmxkYE80xX8emiY coyEZZISpYdwnBouOWDUk4mfG01Iqgk/X3VMzXkDd9k/9XFA4o+kAUHjQoU+6/p4S2+/ xiLw== X-Gm-Message-State: AOAM532Rv2Jqz4cRvTgN4xxhxq7LANWVg7Yy4iSRQOy/Udk89FISeNT2 YuZ4+nzJ72ikFCJEev5djyW7VNvXG9Bezg== X-Google-Smtp-Source: ABdhPJxC9699c1ZArpgV9JsOsxrxF7I5D81BPXdUofNiFU0++FYCNlbVzlQRf+Rm8klWVIRpF06YhA== X-Received: by 2002:a17:90a:df14:: with SMTP id gp20mr12803284pjb.186.1638524679606; Fri, 03 Dec 2021 01:44:39 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id s8sm2474535pfe.196.2021.12.03.01.44.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:39 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:25 +0800 Message-Id: <20211203094426.101454-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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 CameraSensor. 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 | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2facbf3c..788c2fa3 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 *focusLens() { return focusLens_.get(); } + protected: std::string logPrefix() const override; @@ -91,6 +94,8 @@ private: const BayerFormat *bayerFormat_; ControlList properties_; + + std::unique_ptr focusLens_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 6151b32e..c89d39e1 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,14 @@ void CameraSensor::updateControlInfo() subdev_->updateControlInfo(); } +/** + * \fn CameraSensor::focusLens_() + * \brief Retrieve the focus lens controller + * + * \return The focus lens controller. nullptr if no focus lens controller is + * connected to the sensor + */ + std::string CameraSensor::logPrefix() const { return "'" + entity_->name() + "'"; From patchwork Fri Dec 3 09:44:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 15007 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 8344ABDB13 for ; Fri, 3 Dec 2021 09:44:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3C6EA6086C; Fri, 3 Dec 2021 10:44:45 +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="mSmkGJUF"; 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 48FD060822 for ; Fri, 3 Dec 2021 10:44:44 +0100 (CET) Received: by mail-pj1-x1036.google.com with SMTP id p18-20020a17090ad31200b001a78bb52876so4708076pju.3 for ; Fri, 03 Dec 2021 01:44:44 -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=MQRk4fRbBtHKsH9Fd/COcASc6Fveou2FbQmOKlzyNYs=; b=mSmkGJUFAovzhVsnB8dzWPoBnhnSxCgrMzEpaXfYjyBDNRVjGEWywy4um0HdUw4lKj zTkjI1SLfarfYJdEQMgWag0RfNZheVUkXsphlHarsI2C95Bg0ukDseJ2ktIbJlhjvkAe a4fMvJUMIMXhXDpKZe64O76kDcV3H2JtHUMyM= 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=MQRk4fRbBtHKsH9Fd/COcASc6Fveou2FbQmOKlzyNYs=; b=hjkXs6SzPXhn25jZNSuvZlJCDmOeQu1XecDL4sI+kE8BhTQHaMK6GI1+Glh7ZSD/st m4Wz2ZxvnSifx37eZILLQOzP7pjas99TLqDpQi+h9k7y9RTAOb6X71wuYbUiUhkTIZNw H3nTLSctQSQ3bl5Ygg2046g4iXUxB0Rn39czOVCn16efEPpnHZyEd4W76yispmffNr3B CDMFLppOAZxlLE0iG4tZjS/8UtGLwWpxXDZhj/pCvrBf1VFtAlnSShSKyQtrjjX8/HL/ AS2ePPZdykJ0BTCzFZ7gVZQrzO21vvaYPf47Q0rfnnahAlrn+WTC2tiUKAStrpKn6YZ1 WqfA== X-Gm-Message-State: AOAM533lC/qDjKTk8ykZ+6uzq9usjx6HBA2xMGcGp2KfK5P6wsV+NGsc dE0IjV4CvymcxG8+JX/bMBb4cM8/46EQDQ== X-Google-Smtp-Source: ABdhPJxe13PBDr0AwGmQ5DhT+FL2ZUPrL1HNlVbmOJubgffuhS3+g6WpyGZa84jU6CCwvvJiTeP6Zg== X-Received: by 2002:a17:90b:17cd:: with SMTP id me13mr12864138pjb.79.1638524682307; Fri, 03 Dec 2021 01:44:42 -0800 (PST) Received: from localhost ([2401:fa00:1:10:110e:45d1:2f92:6647]) by smtp.gmail.com with UTF8SMTPSA id h26sm1859204pgm.68.2021.12.03.01.44.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Dec 2021 01:44:41 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 17:44:26 +0800 Message-Id: <20211203094426.101454-6-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.384.gca35af8252-goog In-Reply-To: <20211203094426.101454-1-hanlinchen@chromium.org> References: <20211203094426.101454-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 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..1215bdb8 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 *focusLens = cio2_.sensor()->focusLens(); + if (focusLens && !focusValue.isNone()) + focusLens->setFocusPostion(focusValue.get()); break; } case ipa::ipu3::ActionParamFilled: {