From patchwork Tue Nov 23 12:37:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14705 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 62435BF415 for ; Tue, 23 Nov 2021 12:38:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 14A6F60230; Tue, 23 Nov 2021 13:38: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="HL498L9C"; 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 EE80E60230 for ; Tue, 23 Nov 2021 13:38:03 +0100 (CET) Received: by mail-pl1-x62f.google.com with SMTP id z6so15773025plk.6 for ; Tue, 23 Nov 2021 04:38:03 -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=HL498L9C9hmvst0fhNwFpFiK/SEMPWAOCg2InfShUZ0dnZUatGlGcKHceSsU46DwZ7 sj9gwYtZH7kAa/AUVsX+qNaMNHp/z5s3xEtjpeWp4sX3heQrwYFDhTqlP0uGJ85T95wQ t+QaHDdCTAV4rWpDmAm1GnQllAbsSJn+0/zKc= 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=LnV4A2DAI0GC8t1f0K8GTX+DDUDJnuHk0WTd7gpK+AqgFZ+aS/VNxX2tJDM1Kpt9Rr qbPLDs6QPvfnAnXslwvuXhtsaQHpJJRfNR7pr1Kq45c3JKsdvjkDb4y1FuYpkQJbK2RS fIoemNO/x1rM+x8Lo/ZjvKkrRDoOgfxfKTHjjVGbw+0eGKogzsmHhdlueVoiCGPznmzQ 5axT96hdvL4M0n/2NYD9RSxn2KNm9t6zGD/N8R1N9KhQ7t70UkauWGLXNHngGEeuD5Dk WV3zuFnEC2oz5yQPBKOYI/HBtNSlRDiklDsXnGswUsSOl7dIfFEXq19TbLZkhCrXvKgL CM5Q== X-Gm-Message-State: AOAM530Y9UtBpCzH/qaMc33NkHluiXOomhbaTaXiZmO9k7RlrNm4I3We XFTyE4+ufNnf6UWnoilrlBWj8z3BgnuIow== X-Google-Smtp-Source: ABdhPJyN1oJB592YGYV3NsGE2x4IR3RTZLAeXubTmrfJdmYCedL+xVELj/20u0IncTIVQEss12QQlA== X-Received: by 2002:a17:90a:1b67:: with SMTP id q94mr2482524pjq.119.1637671081880; Tue, 23 Nov 2021 04:38:01 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id b11sm12685172pfm.7.2021.11.23.04.38.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:38:01 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:37:48 +0800 Message-Id: <20211123123751.3194696-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123123751.3194696-1-hanlinchen@chromium.org> References: <20211123123751.3194696-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 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 Tue Nov 23 12:37:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14706 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 4CB93C324F for ; Tue, 23 Nov 2021 12:38:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 71DE46039C; Tue, 23 Nov 2021 13:38: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="CQGlQQnz"; dkim-atps=neutral Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC38660121 for ; Tue, 23 Nov 2021 13:38:05 +0100 (CET) Received: by mail-pj1-x1033.google.com with SMTP id o6-20020a17090a0a0600b001a64b9a11aeso2784160pjo.3 for ; Tue, 23 Nov 2021 04:38:05 -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=79Xcfs2Cn5N780DQdk4iOZc3jJXYLSX2EDgtrl8AS6c=; b=CQGlQQnz5fvN5tKt/oeoybb3fxkw5duwK2nLxJRhpTRrwgKJv49bI6mX3EGv/JJNT8 jJ/pfPeUFxvmcIIvSH728KdhaJiZoCQWDvVadj/V5N7VVtV2tR1ROySGhdCAwYFZ7yd7 35S14lrZRfVu3anTCaYgEci9ov+1RJaG0RNRc= 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=79Xcfs2Cn5N780DQdk4iOZc3jJXYLSX2EDgtrl8AS6c=; b=J+u+JaS5lrnMWgWormI+QNQft70kPUmCKrBvy84V9WLeMA/RnO+1NfNsD7eCHSkryl NvLB4MeJPRvVREnYodQd+WV4Z5ZZC4ApCW3KEzXO854C8i9s3x7ouqwCYOhkDAzHYIRQ mD5+Ou8XULKLqXCWWHzlLfqBdVvEap7GWE/grUE4SkXercVSbGAF/5KNp/8WCsKrnwAW oiAPfKPf2l0vwoCDlscje2jzVOiwOoFNLhFG8LsGfk97h7TPBhsDyhO05s0vrhn03jTm NKkPnPqxXWarwsrPafbNY6Sw2jibCfv4BWozmy0z7l2eiirhWj+NgyiWRfSJVfIplkfZ zVaQ== X-Gm-Message-State: AOAM5310XtUkrl0B7IVtIMrY0L17rr1FRQ92vG1C5O0VdkPtGr56ZjXU 6kF56xT97Zma2kdkQeR38UJcPeLymaXdnQ== X-Google-Smtp-Source: ABdhPJy8BbPg53UUzo2lwoc/kFtNshuksRo6pgYh6W7dTHM9Fh5tsHJa9kIisfaYg1AiYVcIXyigSQ== X-Received: by 2002:a17:90b:4a05:: with SMTP id kk5mr2471413pjb.142.1637671084038; Tue, 23 Nov 2021 04:38:04 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id y130sm11960803pfg.202.2021.11.23.04.38.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:38:03 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:37:49 +0800 Message-Id: <20211123123751.3194696-3-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123123751.3194696-1-hanlinchen@chromium.org> References: <20211123123751.3194696-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/4] libcamera: camera_utils: Add a file for utils common to sensor and 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" Add a file to locate utils common to camera sensor and the following lens class. The patch also moves two functions from camera_sensor.cpp used to generate id and model name for the sensor into the file. Signed-off-by: Han-Lin Chen --- include/libcamera/internal/camera_sensor.h | 1 - include/libcamera/internal/camera_utils.h | 22 +++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_sensor.cpp | 45 ++--------- src/libcamera/camera_utils.cpp | 94 ++++++++++++++++++++++ src/libcamera/meson.build | 1 + 6 files changed, 124 insertions(+), 40 deletions(-) create mode 100644 include/libcamera/internal/camera_utils.h create mode 100644 src/libcamera/camera_utils.cpp diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index d25a1165..134108ff 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -66,7 +66,6 @@ protected: private: LIBCAMERA_DISABLE_COPY(CameraSensor) - int generateId(); int validateSensorDriver(); void initVimcDefaultProperties(); void initStaticProperties(); diff --git a/include/libcamera/internal/camera_utils.h b/include/libcamera/internal/camera_utils.h new file mode 100644 index 00000000..04c5e76f --- /dev/null +++ b/include/libcamera/internal/camera_utils.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_utils.h - Camera related utilities + */ +#ifndef __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__ +#define __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__ + +#include + +#include "libcamera/internal/v4l2_device.h" + +namespace libcamera { + +std::string extractModelFromEntityName(const std::string &entityName); +std::string generateIdForV4L2Device(const V4L2Device *dev, + const std::string &model); + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_INTERNAL_CAMERA_UTILS_H__ */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 665fd6de..de8630fe 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -16,6 +16,7 @@ libcamera_internal_headers = files([ 'camera_controls.h', 'camera_sensor.h', 'camera_sensor_properties.h', + 'camera_utils.h', 'control_serializer.h', 'control_validator.h', 'delayed_controls.h', diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 9fdb8c09..e91c2b0a 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -6,14 +6,12 @@ */ #include "libcamera/internal/camera_sensor.h" -#include "libcamera/internal/media_device.h" #include #include #include #include #include -#include #include #include @@ -22,8 +20,9 @@ #include "libcamera/internal/bayer_format.h" #include "libcamera/internal/camera_sensor_properties.h" +#include "libcamera/internal/camera_utils.h" #include "libcamera/internal/formats.h" -#include "libcamera/internal/sysfs.h" +#include "libcamera/internal/media_device.h" /** * \file camera_sensor.h @@ -366,21 +365,13 @@ 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_ = extractModelFromEntityName(entity_->name()); properties_.set(properties::Model, utils::toAscii(model_)); /* Generate a unique ID for the sensor. */ - int ret = generateId(); - if (ret) - return ret; + id_ = generateIdForV4L2Device(subdev_.get(), model_); + if (id_.empty()) + return -EINVAL; /* Initialize the static properties from the sensor database. */ initStaticProperties(); @@ -820,28 +811,4 @@ std::string CameraSensor::logPrefix() const return "'" + entity_->name() + "'"; } -int CameraSensor::generateId() -{ - const std::string devPath = subdev_->devicePath(); - - /* Try to get ID from firmware description. */ - id_ = sysfs::firmwareNodePath(devPath); - if (!id_.empty()) - return 0; - - /* - * Virtual sensors not described in firmware - * - * Verify it's a platform device and construct ID from the deive path - * and model of sensor. - */ - if (devPath.find("/sys/devices/platform/", 0) == 0) { - id_ = devPath.substr(strlen("/sys/devices/")) + " " + model(); - return 0; - } - - LOG(CameraSensor, Error) << "Can't generate sensor ID"; - return -EINVAL; -} - } /* namespace libcamera */ diff --git a/src/libcamera/camera_utils.cpp b/src/libcamera/camera_utils.cpp new file mode 100644 index 00000000..b42911b4 --- /dev/null +++ b/src/libcamera/camera_utils.cpp @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_utils.cpp - Camera related utilities + */ + +#include "libcamera/internal/camera_utils.h" + +#include + +#include "libcamera/internal/sysfs.h" + +/** + * \file camera_utils.h + * \brief Utilities for Camera instances + */ + +namespace libcamera { + +/** + * \brief Extract the sensor or lens model name from the media entity name + * \param[in] entityName The entity name of a lens or sensor + * + * \return Model name as string + */ +std::string extractModelFromEntityName(const std::string &entityName) +{ + /* + * Extract the sensor or lens 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::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 Generate ID for V4L2 device + * \param[in] dev The V4L2Device + * \param[in] model The ModelName + * + * Contruct ID from the firmware description. If it doesn't exist, contruct it + * from the device path and the provided model name. + * If both fails, return an empty string. + * + * \return ID as string + */ +std::string generateIdForV4L2Device(const V4L2Device *dev, + const std::string &model) +{ + const std::string devPath = dev->devicePath(); + + /* Try to get ID from firmware description. */ + std::string id = sysfs::firmwareNodePath(devPath); + if (!id.empty()) + return id; + + /* + * Virtual device not described in firmware + * + * Verify it's a platform device and construct ID from the deive path + * and model of a sensor or lens. + */ + if (devPath.find("/sys/devices/platform/", 0) == 0) { + return devPath.substr(strlen("/sys/devices/")) + " " + model; + } + + return ""; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 6727a777..563ed861 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -8,6 +8,7 @@ libcamera_sources = files([ 'camera_manager.cpp', 'camera_sensor.cpp', 'camera_sensor_properties.cpp', + 'camera_utils.cpp', 'controls.cpp', 'control_serializer.cpp', 'control_validator.cpp', From patchwork Tue Nov 23 12:37:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14707 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 56D8BBF415 for ; Tue, 23 Nov 2021 12:38:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB75960398; Tue, 23 Nov 2021 13:38:10 +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="oD+AmyG6"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 035BE60398 for ; Tue, 23 Nov 2021 13:38:08 +0100 (CET) Received: by mail-pf1-x42f.google.com with SMTP id n26so19322886pff.3 for ; Tue, 23 Nov 2021 04:38: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=CD0u+dZO4p2XssMpLn5qa6N9zSQYWtS1JAmrhwOI/kU=; b=oD+AmyG639vMrJ65dyBlbasf2EXV2IMMmwFSCCqDpLrV4BBDiUd0VPWGM+838qnZTX 95mkixYila7tnFZh7xJZ11xhv8saJK07Wa9qSV74uHNoufJ1hXkJL9KnG83QdicgUxlA f0tWD17dHj0vpp3xFiMIa/XbDAAGBDI4Ao/KE= 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=CD0u+dZO4p2XssMpLn5qa6N9zSQYWtS1JAmrhwOI/kU=; b=kWVSzAC6pm6K/EVf9RDu0bIg2y0riTFPoXkSQ/0vLbQ325Rx4qU6poHejKujfIx26H SFHm1NpYMRCWpaiAADJiYHPR1qFOfymwmDeTcC1YOCwQJpbYdUdSnFx4FInlLh0D9TSr ufABWUsHmCACTfqDFfECR9npZs7rq/tGf0dfgSz7qm+gTZOlb8+mj3t0tPc9R05btOhp rLaPuUdfcxd/bFaU/BL6LWnuat1Avs4HBGb/Ao924my8sDGVg1YZ9VFJ7ePuTUOB1VzF XNv7/bHLWE9HU8osRHgL2i5ATatob3u9vAZlHHtzmxpRgyLRj0WB0fd5YLryoNWp0NbK Gxkw== X-Gm-Message-State: AOAM533B1wW82d1+7G6IXCJzAq47Sxkbdw4XV6hpkB4L7KIZDBkxRTxB MsdaQXhNHKCK0L/zBU++OAgh81jrhpQ5KA== X-Google-Smtp-Source: ABdhPJzYiD+guD5Jb6PGZhtDZ+twcG1KMSdUSDx471tx4mFb5KDwHJGSyjWvfTInN9suNESS/gViBQ== X-Received: by 2002:a65:5ccb:: with SMTP id b11mr3616462pgt.408.1637671086228; Tue, 23 Nov 2021 04:38:06 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id j6sm12860904pfu.205.2021.11.23.04.38.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:38:05 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:37:50 +0800 Message-Id: <20211123123751.3194696-4-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123123751.3194696-1-hanlinchen@chromium.org> References: <20211123123751.3194696-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- Documentation/index.rst | 1 + Documentation/lens_driver_requirements.rst | 28 ++++ Documentation/meson.build | 1 + include/libcamera/internal/camera_lens.h | 48 +++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/camera_lens.cpp | 150 +++++++++++++++++++++ src/libcamera/meson.build | 1 + 7 files changed, 230 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..afc300cf --- /dev/null +++ b/Documentation/lens_driver_requirements.rst @@ -0,0 +1,28 @@ +.. 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 one or multiple 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..fe83d4ad --- /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 "libcamera/internal/v4l2_subdevice.h" + +namespace libcamera { + +class MediaEntity; + +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 de8630fe..7e9b9998 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', 'camera_utils.h', diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp new file mode 100644 index 00000000..cb7159fe --- /dev/null +++ b/src/libcamera/camera_lens.cpp @@ -0,0 +1,150 @@ +/* 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 + +#include "libcamera/internal/camera_utils.h" +#include "libcamera/internal/media_device.h" +#include "libcamera/internal/sysfs.h" + +/** + * \file camera_lens.h + * \brief A camera lens + */ + +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. + * + * The implementation is currently limited to lens that expose a single V4L2 + * subdevice. It will be extended to support more complex devices as the needs + * arise. + */ + +/** + * \brief Construct a CameraLens + * \param[in] entity The media entity backing the camera lens + * + * 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; + } + + model_ = extractModelFromEntityName(entity_->name()); + + /* 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; + + 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 err = 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"; + err = -EINVAL; + } + } + + if (err) { + 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 err; + } + + return 0; +} + +/** + * \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 563ed861..2100805d 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 23 12:37:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 14708 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 824BEBF415 for ; Tue, 23 Nov 2021 12:38:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3422B60394; Tue, 23 Nov 2021 13:38:13 +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="Jpc+N5kE"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B0C86022F for ; Tue, 23 Nov 2021 13:38:10 +0100 (CET) Received: by mail-pl1-x62d.google.com with SMTP id o14so16957256plg.5 for ; Tue, 23 Nov 2021 04:38: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=Wts5FaHlWgEzLQTSI6cOeLZs+nV4J2NqWI0WqjNYSw0=; b=Jpc+N5kEEAjvEjqBdv6M8m8udGp0Yh1GtoVksxOz/hjsVKYTfcYUbm34H41YQ7e/ok TPvnRQDwAa6xlbfFpkrwG0nVDNxIbiLQKciOpfzFBQYErPfn8JE3ktsMKz15hGCbtxYS yxF8RIltZarHtC1yd5kPGQ2u91Sruar4z4cec= 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=Vgl5VrAvZnUFw9Yil+DULrrsKkPmbt5okIOo2HPw502xQNfGYf79rfU3wxl8cP21n7 3JUqgXsxwgzpNiGsTAiQPgvJny/H2ZUdnDxWW05GjRpCCMD4uEdD2tKhZSSPtkwARicf Uzqx/T7jubJsfKSC1b73CSqu8UIISSRpqbrWGDt9REVWtBaGeCBwfl9RFzacCpjUZxM1 kMuI9SJB/gI+YL5bJjtxxTJBXbXBq/3/EQ4MYdPhBo0yWHnHqDy1Xs+loJrOc4qldpg9 VE09dO4MbT7g/8jV86dnQCXSk8vdnCe8t2C/RlcCSShEM9x6d+8XTWhCim3CgyNGyizl YJrA== X-Gm-Message-State: AOAM5339tZ7Yydzp06yaQEL72oX2I07ohwrLo59Cp0z93eajeobkE6o0 NXHE1xrP82DtPh5i6NgLWAY+PQ2pl7d+lg== X-Google-Smtp-Source: ABdhPJwSd7bDO0VT8HpIVGKDTP47XCLN4FTTe/oknQvbGhl2ucYdUzu+pjEIzeFOBAPmVCkh2wAyLg== X-Received: by 2002:a17:90a:e60b:: with SMTP id j11mr2542259pjy.52.1637671088458; Tue, 23 Nov 2021 04:38:08 -0800 (PST) Received: from localhost ([2401:fa00:1:10:8aa3:febd:fadf:4199]) by smtp.gmail.com with UTF8SMTPSA id u22sm12985033pfi.187.2021.11.23.04.38.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Nov 2021 04:38:08 -0800 (PST) From: Han-Lin Chen To: libcamera-devel@lists.libcamera.org Date: Tue, 23 Nov 2021 20:37:51 +0800 Message-Id: <20211123123751.3194696-5-hanlinchen@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211123123751.3194696-1-hanlinchen@chromium.org> References: <20211123123751.3194696-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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: {