From patchwork Mon Jan 31 22:33:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 15309 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 4A93DBF415 for ; Mon, 31 Jan 2022 22:33:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E28B609D6; Mon, 31 Jan 2022 23:33:48 +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="UWFLZmzS"; dkim-atps=neutral Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 684D3609C9 for ; Mon, 31 Jan 2022 23:33:45 +0100 (CET) Received: by mail-wr1-x431.google.com with SMTP id u15so28289166wrt.3 for ; Mon, 31 Jan 2022 14:33:45 -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=NlysUB6FBhVB8yavInpASF7jF/JylVh3ZMvCc4z37Yc=; b=UWFLZmzScSLwcK0xM1JgyBU5raDsjFAa433mDHU6b7vIUnwkcwrDKizz/m+aqIRdtf 3cZN3qUKlE0XvrFW3c7DcAG/CydC90clBq4A5wywpn/iba2HoTOYkFaheUta4IeR5uNS zfLymiPWofW4rI/79yTGjjXkoARjQuPCsEnjb6wMLm8ezG8O/InEgGptMy9tS8ivzYq3 iUgy24FgdM8oApRimZhA3opKdoovLC34QGtWm5M+ox5MzbTE03XQwO8v581Z+D4O94oe DbHji206E538tI6nH7Jecl2UsnJrQoz58wPqOLkHSe+m9dXp1iy4ld9I4AD0WZZN1EvG 8qEQ== 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=NlysUB6FBhVB8yavInpASF7jF/JylVh3ZMvCc4z37Yc=; b=h3RO7f6/dY5pEujnji2zAT7UjnhNeY62WIRDrd/UGnBeF9GrTi+9Wi4ZbujqNzTlKi Qxr1/NEochF2T99UBSvZPUtGBd0KeJxtcnun+p/yl9+yoo9oenpXIF0GwFXuz6GwJiCB OlHjY0Gamptu9eaaJtdc/raGonB8QCvst/S1UsPkZVQjUcvd/NdX7e1Zu1U/Y7s7Z1U1 RTkPPtvrg4Hb0vbyeYypIjC5yy+L6NXle+yXgul2yAotNkkdiQodWdf4lN4aOrO2nKdi nqaCLQGy5HTPb0SW8OdL8Wlu+KvMCpwb70IDdwOWI2LQU0DapOIiaW3KWX+8VkmKXi2v ePKg== X-Gm-Message-State: AOAM5311Pek2hNWIryyGrb4U33/HbKvPy01gq2epOI672t6C/I1Vf5B9 VwKGnwrb14lcc6uWkMwW/uM8jFzwJl0= X-Google-Smtp-Source: ABdhPJwvNHMo+lzyhw7f2P6N/fZhsxR6yfIJNJ/q/Y3rzIsJzXzb0vtMOJf1G/Kq9Nh6/X4Sn9VLgg== X-Received: by 2002:a05:6000:c2:: with SMTP id q2mr19255937wrx.85.1643668425221; Mon, 31 Jan 2022 14:33:45 -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 q2sm6986740wrw.14.2022.01.31.14.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jan 2022 14:33:44 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Mon, 31 Jan 2022 22:33:25 +0000 Message-Id: <20220131223330.61563-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220131223330.61563-1-djrscally@gmail.com> References: <20220131223330.61563-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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(). Reviewed-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes in v4: - Fixed typo (Laurent) 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 64f7f12c..f00c0aca 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -172,6 +172,10 @@ int CameraSensor::init() if (ret) return ret; + ret = discoverAncillaryDevices(); + if (ret) + return ret; + return applyTestPatternMode(controls::draft::TestPatternModeEnum::TestPatternModeOff); } @@ -443,6 +447,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