From patchwork Tue Dec 7 22:45:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15070 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 DF461C324B for ; Tue, 7 Dec 2021 22:45:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8A1E36089D; Tue, 7 Dec 2021 23:45:36 +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="FSqsqDfY"; dkim-atps=neutral Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F57360592 for ; Tue, 7 Dec 2021 23:45:31 +0100 (CET) Received: by mail-wr1-x432.google.com with SMTP id o13so687623wrs.12 for ; Tue, 07 Dec 2021 14:45:31 -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=moWXhDYYHDTxZgKoZg+f4F5npDP4+tmfBJEX072EnMU=; b=FSqsqDfY9G9DAXBhNPIUhGytmWe+NmMaoE+PRW3yO9c8CfR8hp+A7AjsD9NvLe1o0v qxwFIZcOWESxicTYGqtPM929vwBZBNWoSwnM74nOA0CKMdqlJnGguSVxsrimmN6IWD5o AQAdTvVBcmGgWP7g6p2DVrxo//5t/ncBIDvA06m7eV9Nng0mArNmcXPdWE2tllDa57pJ VSSHmN6XzDYhdu2Rhup7qkQccAmZeKnHk+dymSZut/uZpAI+SBq1QA4kDa5dFEL3xhOa I/rPbPIUpCuiabqYfNDoUIjBWJbfENGx6Q/9CRRh03ubCURotmIs5nL0jnpLSdS6xSpB rFvA== 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=moWXhDYYHDTxZgKoZg+f4F5npDP4+tmfBJEX072EnMU=; b=DIrBRqb9l01aiM3RL4moLcE5CPOfVFdNqc4BSWBq1jfaSv/w0VThV7F4sz5qk2N4fu +g30I4aPD4WokiRQFBLtiSoPHusDe+zqEmif6KTM/+x3nVGjKvn+st1icxwugawir+ke toQfgX3te1xvuMcpWcUVy0uYzzRlSqc1oDX5KUslCb8L4kmoAgJQw3PpkUKAOh3HtHgG yLE09EHUNykRo9/WwSNitUaSjarMGOk8kB2iDCf4pd+mOHtianwT3J2ksKkMhxMGgFIK tqqnj06aE0YGJJv4bBcloqwc/hsEq4mSkt2Ne7XWAcLpmH6gcmF5xS2yyxClpJdtP6sm 7C2A== X-Gm-Message-State: AOAM530cCfslyr5kNiFDVbbIpa/3DCN06Icym+za1XyAKK+j1wL+1OlE aD1LUN8fnvFKMObctz52PNtndlcgbaQ= X-Google-Smtp-Source: ABdhPJx6lzMT2DbMnF703JtARko0XVa45U6zKPfxd7/nM4AdeVQyrZPZXIK53s6Mi4w/oiQnERE62g== X-Received: by 2002:a5d:6da5:: with SMTP id u5mr56498929wrs.374.1638917131191; Tue, 07 Dec 2021 14:45:31 -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 y12sm980332wrn.73.2021.12.07.14.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 14:45:30 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Tue, 7 Dec 2021 22:45:07 +0000 Message-Id: <20211207224512.753979-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211207224512.753979-1-djrscally@gmail.com> References: <20211207224512.753979-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/9] 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 Reviewed-by: Laurent Pinchart --- Changes in v3: - Fixed some style errors - Replaced the flash case by printing the entity function in the default case. include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 39 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 2fa11567..7fb4eded 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -81,6 +81,7 @@ private: void initTestPatternModes(); int initProperties(); int applyTestPatternMode(controls::draft::TestPatternModeEnum mode); + int discoverAncillaryDevices(); const MediaEntity *entity_; std::unique_ptr subdev_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 7bb39b1e..1cfb1781 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 applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } @@ -432,6 +436,41 @@ 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) + << "CameraLens initialisation failed"; + return ret; + } + break; + + default: + LOG(CameraSensor, Warning) + << "Unsupported ancillary entity function: " + << ancillary->function(); + } + } + + return 0; +} + /** * \fn CameraSensor::model() * \brief Retrieve the sensor model name