From patchwork Fri Dec 3 22:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15033 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 902CABF415 for ; Fri, 3 Dec 2021 22:42:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5AF0760868; Fri, 3 Dec 2021 23:42:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="hs147ox7"; dkim-atps=neutral Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1FD4460832 for ; Fri, 3 Dec 2021 23:42:39 +0100 (CET) Received: by mail-wr1-x433.google.com with SMTP id c4so8639695wrd.9 for ; Fri, 03 Dec 2021 14:42:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b67B6PydBk9/XDflw+3N/GXguKDJd77sJVZ13CnMHl0=; b=hs147ox7cTI8S9DJKLAWxPUDqrAZ60rlp8gM4Ny1Hw9IxSSvgbxMxD/uB20qbGiJlV 0ByW5B8VVe102EtGsAst1OtB8/e+kuXG2ezTyDsVtCCKUurrljW3/YVmJMxnIPMdzHu9 CPJC8+Ig0RpaxCGyOf5IzODlrXxuLYNqdESG3LIOLp0VcWaiK2ZjqQUaMyVrWAetB8j8 mm0SB0db6nLMLNanipOcHzKgIOgpNFgx2qkwE5tnOVw9xpMko5YZW3/k0oVHoLFz/MxN nxwXlA0q2ElWcwox9Tc0+Ct+pLy73ujOX3J8zavW7Y4SbTuyPFp494GtHzbrj6ZMC3XL 18QA== 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=b67B6PydBk9/XDflw+3N/GXguKDJd77sJVZ13CnMHl0=; b=iDu6EtB5K594l1Fk5QY3FP2AKxXwpmj5jdueUL/cgNrXZjHHWCYXfhyUMPCH0BOmpI PRjem2yQakluiG8xbTBEs0gkzirZt1yVUbXEuvj5Fkte2iqrbWyvYLNNXTwFbKcYVFkq PcT20TlQbus9KG1m7P4fCMzNfggpIjdU0gGkJTAc5QYo9ML9aJWGBSG2wlvB/apn5+yM DHqgmm0a4PCBsb+j47edygVB1kqnYaGOfFfS3KnB+37OvcYQ+1sYfynRA1doRW8R4eB5 0sKXf2hBbUK+AzjEhAHMHX89eX64TnYQfessyEKQj6kf9axEqDc17SaoYhFLTDXOpE8d tFcA== X-Gm-Message-State: AOAM533V5TksIuPYtuGOPbYiOfng0FRdIFy7Dqzt1eHylNWTG3B7sGi/ zqJkakpBOMq4BwrAgs/P/ctgL4twjGk= X-Google-Smtp-Source: ABdhPJwmI/CfF5hPEW9xOZmf7yRIZItsw3/1dxOEX1Dk4UpVDbCtcvRXmnVfnOyzSb3s+nMee50VJA== X-Received: by 2002:adf:fd90:: with SMTP id d16mr24124093wrr.385.1638571358903; Fri, 03 Dec 2021 14:42:38 -0800 (PST) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id o25sm3939919wms.17.2021.12.03.14.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 14:42:38 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Dec 2021 22:42:26 +0000 Message-Id: <20211203224230.38700-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211203224230.38700-1-djrscally@gmail.com> References: <20211203224230.38700-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/7] libcamera: camera_sensor: Discover VCMs through ancillary links 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 function to check for and initialise any VCMs linked to the CameraSensor's entity by ancillary links. This should initialise the lens_ member with the linked entity. Call the new function during CameraSensor::init(). Signed-off-by: Daniel Scally --- Changes in v2: - Moved this functionality to CameraSensor::init() instead of the pipeline's ::configure() (Laurent) include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 788c2fa3..d329c512 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -76,6 +76,7 @@ private: void initTestPatternModes( const std::map &testPatternModeMap); int initProperties(); + int discoverAncillaryDevices(); const MediaEntity *entity_; std::unique_ptr subdev_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 4c142a58..e1d4d424 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -161,6 +161,10 @@ int CameraSensor::init() if (ret) return ret; + ret = discoverAncillaryDevices(); + if (ret) + return ret; + return 0; } @@ -423,6 +427,44 @@ int CameraSensor::initProperties() return 0; } +/** + * \brief Check for and initialise any ancillary devices + * + * Sensors sometimes have ancillary devices such as a Lens or Flash that could + * be linked to their MediaEntity by the kernel. Search for and handle any + * such device. + * + * \todo Handle MEDIA_ENT_F_FLASH too. + */ +int CameraSensor::discoverAncillaryDevices() +{ + int ret; + + for (MediaEntity *ancillary : entity_->ancillaryEntities()) { + + switch (ancillary->function()) { + case MEDIA_ENT_F_LENS: + focusLens_ = std::make_unique(ancillary); + ret = focusLens_->init(); + if (ret) { + LOG(CameraSensor, Error) + << "Error during CameraLens init"; + return ret; + } + break; + case MEDIA_ENT_F_FLASH: + LOG(CameraSensor, Warning) + << "Flash devices not yet supported"; + break; + default: + LOG(CameraSensor, Warning) + << "Unsupported ancillary entity function"; + } + } + + return 0; +} + /** * \fn CameraSensor::model() * \brief Retrieve the sensor model name