From patchwork Fri Nov 26 00:31:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 14784 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 E62DEBDB13 for ; Fri, 26 Nov 2021 00:31:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ECCCE604FB; Fri, 26 Nov 2021 01:31:31 +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="eAkvW3gV"; dkim-atps=neutral Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 504CF6011D for ; Fri, 26 Nov 2021 01:31:28 +0100 (CET) Received: by mail-wm1-x329.google.com with SMTP id m25-20020a7bcb99000000b0033aa12cdd33so1684933wmi.1 for ; Thu, 25 Nov 2021 16:31:28 -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=fSBgCp0X8JPVM+FaRxWoz/LqsQf7vjdyPzNhZaKS5rY=; b=eAkvW3gVxIM9PeX6CamuIVZCW1mlaQlIvg717set+7u7MaTLRExJ64MCw6AyAOIolK gHgE3YzvuYktX3QkDj+tKgl877wq9hxJ21zSXysOpfdXjhfWmNrwWf7Xvo/Kc91R1h2U 671mZcu3of0e2jsKaQECYehfSnbn+aeTb5hXNLRFayrvEwrpeBI55wNc4WjPdGMvGZOa uzLHTJqBC5cw70EaLRPc98WoU31Dqje1nCH2COoBI7+EtugPirKJcatHEuWx7/gFMxJw pnOpJeqlYZwO0Q8q9ZFOuWxrsre0U0u/YjqFK9a8bzgSdTFvwmCrQp+f9+yVQqFlLu5o 0rGQ== 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=fSBgCp0X8JPVM+FaRxWoz/LqsQf7vjdyPzNhZaKS5rY=; b=5rvgnLMkoNurXcUWZBB7VavpP9USjtk3Nv5pGXOHmY8x3tbhszLe4TvT8TJqXG45hp 48OsGt/xF5FfpRcLFY2JiZuPljvXNJH56lg6ll399J9zKS5pkBfE2O9cPIQsUbPQ1Mwq eOLy9TNPNjs5Fb9M0gefzL+GAwpZhCV+7nY27nE6NQf6FLdoO1pBeDgBQxy/zuSjpLY0 3MuXuPPYyKI9P3i2YVE0681XfTbAPkY9ItYDmw3T7vyz1p1SQQRSo0f7Ufixi6ktwmrA IuZ8+iyM4aMtOptkB82d022efzQUJ11rdo1ITXY3L4cRRCpYo6iQgXvF09Kl+IMbSqGJ 67Nw== X-Gm-Message-State: AOAM530m2tSI1SFECCe99EjOWIteVidSOivXSLo/nyvc3ZtOjHAGPkMv 8RXB00lQrNdFVQPgrn2JE/P6i417aj4= X-Google-Smtp-Source: ABdhPJwbQN7PeTtXpTZrG498qwAdGN2ZyzokyRaMC7lWbpnVtzzpJkcgYbJOIeeS2X6GPkJy+AxjeA== X-Received: by 2002:a05:600c:1993:: with SMTP id t19mr12354806wmq.21.1637886688102; Thu, 25 Nov 2021 16:31:28 -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 b188sm4381455wmd.45.2021.11.25.16.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 16:31:27 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 00:31:14 +0000 Message-Id: <20211126003118.42356-2-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126003118.42356-1-djrscally@gmail.com> References: <20211126003118.42356-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/5] libcamera: Add support for ancillary links to MediaLink 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" Update the MediaLink class to include members suitable for the new type of media_v2_link, connecting two instances of MediaEntity rather than MediaPads Signed-off-by: Daniel Scally --- Adding new members and a new constructor here seemed in the end like the least impactful and probably cleanest method of doing this, as otherwise the source and sink would need to become MediaObjects and be cast everywhere. include/libcamera/internal/media_object.h | 10 ++++++++++ src/libcamera/media_object.cpp | 24 ++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h index 6ae22c67..79c71325 100644 --- a/include/libcamera/internal/media_object.h +++ b/include/libcamera/internal/media_object.h @@ -45,6 +45,8 @@ class MediaLink : public MediaObject public: MediaPad *source() const { return source_; } MediaPad *sink() const { return sink_; } + MediaEntity *primary() const { return primary_; }; + MediaEntity *ancillary() const { return ancillary_; }; unsigned int flags() const { return flags_; } int setEnabled(bool enable); @@ -55,9 +57,13 @@ private: MediaLink(const struct media_v2_link *link, MediaPad *source, MediaPad *sink); + MediaLink(const struct media_v2_link *link, + MediaEntity *primary, MediaEntity *ancillary); MediaPad *source_; MediaPad *sink_; + MediaEntity *primary_; + MediaEntity *ancillary_; unsigned int flags_; }; @@ -104,12 +110,15 @@ public: unsigned int deviceMinor() const { return minor_; } const std::vector &pads() const { return pads_; } + const std::vector &ancillary_links() const { return ancillary_links_; } const MediaPad *getPadByIndex(unsigned int index) const; const MediaPad *getPadById(unsigned int id) const; int setDeviceNode(const std::string &deviceNode); + void addLink(MediaLink *link); + private: LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity) @@ -129,6 +138,7 @@ private: unsigned int minor_; std::vector pads_; + std::vector ancillary_links_; }; } /* namespace libcamera */ diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index f425d044..e903d5ef 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -134,7 +134,7 @@ int MediaLink::setEnabled(bool enable) } /** - * \brief Construct a MediaLink + * \brief Construct a MediaLink between two pads * \param[in] link The media link kernel data * \param[in] source The source pad at the origin of the link * \param[in] sink The sink pad at the destination of the link @@ -146,6 +146,19 @@ MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source, { } +/** + * \brief Construct a MediaLink between two entities + * \param[in] link The media link kernel data + * \param[in] primary The primary entity at the origin of the link + * \param[in] ancillary The ancillary entity at the destination of the link + */ +MediaLink::MediaLink(const struct media_v2_link *link, MediaEntity *primary, + MediaEntity *ancillary) + : MediaObject(primary->device(), link->id), primary_(primary), + ancillary_(ancillary), flags_(link->flags) +{ +} + /** * \fn MediaLink::source() * \brief Retrieve the link's source pad @@ -378,6 +391,15 @@ int MediaEntity::setDeviceNode(const std::string &deviceNode) return 0; } +/** + * \brief Add an ancillary link to the MediaEntity + * \param[in] link Pointer to the MediaLink class + */ +void MediaEntity::addLink(MediaLink *link) +{ + ancillary_links_.push_back(link); +} + /** * \brief Construct a MediaEntity * \param[in] dev The media device this entity belongs to From patchwork Fri Nov 26 00:31:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 14785 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 48A61C324F for ; Fri, 26 Nov 2021 00:31:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F39D460490; Fri, 26 Nov 2021 01:31:32 +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="DkrA1GMp"; dkim-atps=neutral Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0893C6011D for ; Fri, 26 Nov 2021 01:31:29 +0100 (CET) Received: by mail-wm1-x32e.google.com with SMTP id 137so6826287wma.1 for ; Thu, 25 Nov 2021 16:31:29 -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=aemq21Ri5fdhqriXaF8QcTIZVoJtSLB/xFzBO4uxDmg=; b=DkrA1GMpPAsPY8fqANUNBP0sLDXrxNVoAOKBubxBokPKd/lytFc6w7E1sy38McXf25 erRvKmh9WDjzX6L7NIeNnAsmw+T1NsXGzb8I8sFNf3zjQu+Il5dAs0c4U6H2fJnTdHXI E+dQ2w42Md8vZ/SNxTmkQdIh4wvYPDD2COcedFodHThEpUYnLEbsxYeFzUhou6ZrVjq/ SHOKK3xZSSn9KYCeBAYMRBmeBIolecoWt/VuLRfhMI6xpNCChPAZq6imYr7J7XgjFdOZ oWtjlnlt/Rxe5IYlFA/96Hl+KovwhdIql8usY+3dEfeIYVP2WASg5+6AVPAO5jZ2ai3x 5v7w== 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=aemq21Ri5fdhqriXaF8QcTIZVoJtSLB/xFzBO4uxDmg=; b=gqNQ8DUhM/DD90V/SjO7lBxd6C/rcnyfNwTQZIf3D/0dQkbGuXrzoEUtkskFmU3ewA LH9bPUd0oN9VuekNCa4cXcNQTdKb/jB8Ut/AWVU/FpGUp9mW3rrNkGkT3l3feCQSCQ2g Tmykp1Frk+41bIF3jGBdbezIguTgdT+nTaxPu1QO3+/lflbiQlViTFTm1vZxwFNLwrcU 2bq/dC+UwV8E5Hi+NKuzxfsWImA3MqN+OSwVkdQ/Cgc+m1SZV/CljRMPu8kc9oo2PAyq UEvndaIvRMG/v4OFPIZuliRMefLlLGgOc8CbHMoZLg5Gni5A6DBl56jrSQOpSpQ7OC0+ FzIw== X-Gm-Message-State: AOAM532m9zfWCgQdOc4jxvPYFc37dqp+E/dfmByAh/PboAxceqRpiqSr c0Cur0h8qNDMM18FhZUqcAIdbAc6mIY= X-Google-Smtp-Source: ABdhPJwO4ZEO0HcV/cvWw9t5QPJ6AI7x0UGlk84rhKoIJBxss4Rxyx/aQp0wBLpLdFP8fi3KHFBtbA== X-Received: by 2002:a7b:cf18:: with SMTP id l24mr12085405wmg.145.1637886688820; Thu, 25 Nov 2021 16:31:28 -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 b188sm4381455wmd.45.2021.11.25.16.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 16:31:28 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 00:31:15 +0000 Message-Id: <20211126003118.42356-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126003118.42356-1-djrscally@gmail.com> References: <20211126003118.42356-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/5] libcamera: media_device: Handle ancillary links in populateLinks() 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 populateLinks() function can't currently handle ancillary links which causes an error to be thrown in process() when the MediaObject cannot be cast to a MediaPad. Add explicit handling for the different link types, creating either pad-2-pad or entity-2-entity versions of a MediaLink based on the link type in the link's flags. Signed-off-by: Daniel Scally --- include/linux/media.h | 1 + src/libcamera/media_device.cpp | 52 ++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/include/linux/media.h b/include/linux/media.h index 17432318..e3123d1a 100644 --- a/include/linux/media.h +++ b/include/linux/media.h @@ -222,6 +222,7 @@ struct media_pad_desc { #define MEDIA_LNK_FL_LINK_TYPE (0xf << 28) # define MEDIA_LNK_FL_DATA_LINK (0 << 28) # define MEDIA_LNK_FL_INTERFACE_LINK (1 << 28) +# define MEDIA_LNK_FL_ANCILLARY_LINK (2 << 28) struct media_link_desc { struct media_pad_desc source; diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index aa93da75..8133c534 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -699,45 +699,67 @@ bool MediaDevice::populateLinks(const struct media_v2_topology &topology) { struct media_v2_link *mediaLinks = reinterpret_cast (topology.ptr_links); + unsigned int link_type; + MediaLink *link; for (unsigned int i = 0; i < topology.num_links; ++i) { /* * Skip links between entities and interfaces: we only care - * about pad-2-pad links here. + * about pad-2-pad and entity-2-entity links here. */ if ((mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE) == MEDIA_LNK_FL_INTERFACE_LINK) continue; - /* Store references to source and sink pads in the link. */ + /* Store references to source and sink objects in the link. */ unsigned int source_id = mediaLinks[i].source_id; - MediaPad *source = dynamic_cast - (object(source_id)); + MediaObject *source = object(source_id); if (!source) { LOG(MediaDevice, Error) - << "Failed to find pad with id: " + << "Failed to find MediaObject with id: " << source_id; return false; } unsigned int sink_id = mediaLinks[i].sink_id; - MediaPad *sink = dynamic_cast - (object(sink_id)); + MediaObject *sink = object(sink_id); if (!sink) { LOG(MediaDevice, Error) - << "Failed to find pad with id: " + << "Failed to find MediaObject with id: " << sink_id; return false; } - MediaLink *link = new MediaLink(&mediaLinks[i], source, sink); - if (!addObject(link)) { - delete link; - return false; - } + link_type = mediaLinks[i].flags & MEDIA_LNK_FL_LINK_TYPE; + + switch (link_type) { + case MEDIA_LNK_FL_DATA_LINK: + link = new MediaLink(&mediaLinks[i], + dynamic_cast(source), + dynamic_cast(sink)); + if (!addObject(link)) { + delete link; + return false; + } + + link->source()->addLink(link); + link->sink()->addLink(link); - source->addLink(link); - sink->addLink(link); + break; + case MEDIA_LNK_FL_ANCILLARY_LINK: + link = new MediaLink(&mediaLinks[i], + dynamic_cast(source), + dynamic_cast(sink)); + if (!addObject(link)) { + delete link; + return false; + } + + link->primary()->addLink(link); + link->ancillary()->addLink(link); + + break; + } } return true; From patchwork Fri Nov 26 00:31:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 14786 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 34DDABDB13 for ; Fri, 26 Nov 2021 00:31:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DCF0D604FB; Fri, 26 Nov 2021 01:31:35 +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="DLaFPl9/"; dkim-atps=neutral Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30EE760499 for ; Fri, 26 Nov 2021 01:31:30 +0100 (CET) Received: by mail-wr1-x435.google.com with SMTP id i5so14976528wrb.2 for ; Thu, 25 Nov 2021 16:31:30 -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=WiOK10IpVso/amOg/JULzN+ZlDMbZCiXCePGnabe+Y8=; b=DLaFPl9/zVgKMzN/9UmawBuMXIgK/LxxgrMU1Fp1WRAqCmZNOI8C/5flCw3ohnm+jx kf2oylfWGtbmei0pTBgwpl90Fa7F0yLvk5aBDZv3L4YOiyn0v+vDgUiKJramhwtMwjOs ip0LvSb75EX9WtVs9mH1Sz4AgTuQiKdevj1QXZjvUIELv4TbcFSXZ2m7Yf9hXDnRpDKk /tGH+TnFssFC2Suu6oI0SYPYbWP5axq8ldzfK4FEhUSFNXGfMWc4Mnnb35ew1468uioq jxi2WeV6TaFRWvkROHD48QtpkW1SuOIJwGTwGKcyQfPx5oBaYSEeqgcqvXopBMODH4sA RrOA== 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=WiOK10IpVso/amOg/JULzN+ZlDMbZCiXCePGnabe+Y8=; b=r45aut4QRVC23hfJG2Nadl3SAfQG2F8fIiUDdN+Lj+lDnknhNjAeZEAFD1ig6Y8s/N q0tZAxtQSEtPlfv0AC8JatoonXaxtCmVl7MCg3hfLBAjKUf3wYrrcZEG7tZABGyBoRmo LxfPNVkVoMJRKtQw486Jq220KrDfYp3VN+EF9aKLO1Lkd/Kp2hQvPBCeiVlCLOF+z9F9 uZM2hTyUkgMA86H6tr1B2gqhGF0orbZ1oE7dSF5CXSEI1EOn4BdeAI6gd7Xwj3wvPlad bBg5A5p8NqhK0vYkcTCR93jFl6D8C/v+eoObF+mRB2ORh0P6Cigk48EFgJzU8RwgmYyD vuCA== X-Gm-Message-State: AOAM533KHmAlfuCiwgjNLyqvb6Tj+D94IBZGG5zX1K7gzJXv9hnYKT+b KX6ABi3uFX7KgkRf/UEoIeTQFZQwkw4= X-Google-Smtp-Source: ABdhPJxiBIq9TMyRoaTqLNPPUOGGqq/RvyOG3bjYxYEeTxx4/6qP5QV0zOi0MOc5yfvNQSrkaHnt1A== X-Received: by 2002:adf:d1c2:: with SMTP id b2mr11031705wrd.114.1637886689713; Thu, 25 Nov 2021 16:31:29 -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 b188sm4381455wmd.45.2021.11.25.16.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 16:31:29 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 00:31:16 +0000 Message-Id: <20211126003118.42356-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126003118.42356-1-djrscally@gmail.com> References: <20211126003118.42356-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] libcamera: ipu3-cio2: 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" Rather than attempting to discover VCMs via model name matching we should follow the ancillary links that define the relationship between the two devices to locate any entities linked to the sensor. Where we have linked entities with the function MEDIA_ENT_F_LENS we can then create an instance of CameraLens to represent it. Signed-off-by: Daniel Scally --- Alternatively rather than replace the matching on model names we could try the ancillary links first and then simply guard the existing model matching with an if (!lens_) ... src/libcamera/pipeline/ipu3/cio2.cpp | 45 +++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index 59b2f586..169e7b54 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -161,30 +161,35 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index) } /* - * \todo Read the lens model from the sensor itself or from a device - * database. For now use default values taken from ChromeOS database. + * Sensors sometimes have ancillary devices such as a Lens or Flash + * that could be linked to the MediaEntity - search for and handle + * any such device (for now, we can only handle MEDIA_ENT_F_LENS) + * + * \todo Handle MEDIA_ENT_F_FLASH too. */ - 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); + const std::vector &ancillary_links = sensorEntity->ancillary_links(); + if (!ancillary_links.empty()) { + for (auto it : ancillary_links) { + MediaEntity *ancillaryEntity = it->ancillary(); + + switch (ancillaryEntity->function()) { + case MEDIA_ENT_F_LENS: + lens_ = std::make_unique(ancillaryEntity); ret = lens_->init(); - if (!ret && lens_->model() == it->second) { - break; + if (ret) { + LOG(IPU3, Error) + << "Error during CameraLens init"; + return ret; } - lens_.reset(); + break; + case MEDIA_ENT_F_FLASH: + LOG(IPU3, Warning) + << "Flash not yet supported"; + break; + default: + LOG(IPU3, Warning) + << "Unsupported entity function"; } - if (!lens_) - LOG(IPU3, Warning) << "Lens device " - << it->second << " not found"; } } From patchwork Fri Nov 26 00:31:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 14787 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 BFF45C324F for ; Fri, 26 Nov 2021 00:31:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7694C60490; Fri, 26 Nov 2021 01:31: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="oeYwmFF/"; dkim-atps=neutral Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D6A260491 for ; Fri, 26 Nov 2021 01:31:30 +0100 (CET) Received: by mail-wr1-x434.google.com with SMTP id d24so15035815wra.0 for ; Thu, 25 Nov 2021 16:31:30 -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=PtZtuMpNPvR4zJxo934IO/r140cDWkr6TO5+zilQ0qU=; b=oeYwmFF/1W4anK5mIK7EOGLnE1QOswf9CX+qWt7+yFHhWgyL+NkG2RP3BTCDRBSorB MiH55fubfzrmu/NFl0/s+z4ZNz3Uc6T3xgnLi0kkSvIjYo1sDiv5qqCwCoFhaRH8Fqxx dgGniQdmfat34GLKngfAz5HrHfGImb0jJ2QsKq9SlwbyTxrbKrnE3H/NKyit3cnBDayU J9rWEg1SflfrPuDBQPdIHgaxIvKeeR9mxyatGtmMDHPrlI1FI/0pKslXYgHL9SoNxUwA Af6lgJ02LtzR8TUZF6dL4RF6rA5PT6KlE2Sf/FWGL55mIbLMZASW95ePXmn1oljFtjz7 WLTA== 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=PtZtuMpNPvR4zJxo934IO/r140cDWkr6TO5+zilQ0qU=; b=nZsr4CNVj/1KirFCzeKa71WAHvgeIYfHg3xsk0BGXSPt+COdxEhm7KAyL9jKblMwRo tbnbfxufWa/PX1K+J2XVuDHc3netuDNmdfc8CRErU7e3vTvGzfUNRKfLxYIhXzOuEK7f Sb407lzOvS6T3tLBnD6PFvYlo71PK/Hu+rDJ4aIbb0gIXz4r+bnrj+sZVDeUGhTFsIlS BsqlacaelUS5LKD8QUUWrXznmh6U1oiJMXJebjyA5AYYgYx4Mhm97hgqsfQj0+FYVdsw nbCtJH1WzF3B/4Y0nltl4/iR5jT9TthIqEQQnybRTGeaSiem/c0RLJbJHorQ5ONPWRZO 3mfw== X-Gm-Message-State: AOAM531xXVLuuBTGKXh+d1JtHqD7oE32/qMNoIuFgPbnd4TqEn2d9grJ T6ZDZ8WSx+jxZWQc1MF1GsoiAJodADk= X-Google-Smtp-Source: ABdhPJykaSBCktMhps4b4TPBDk32AcY47Zt5Io6iHb4MPBzbt0UtwGvxCYOwTP1EmWHTXv7A9NrF7w== X-Received: by 2002:a5d:584c:: with SMTP id i12mr10803741wrf.95.1637886690460; Thu, 25 Nov 2021 16:31:30 -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 b188sm4381455wmd.45.2021.11.25.16.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 16:31:30 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 00:31:17 +0000 Message-Id: <20211126003118.42356-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126003118.42356-1-djrscally@gmail.com> References: <20211126003118.42356-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/5] ipa: ipu3: Send lens controls to pipeline handler 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" Pick up the focus value from the AF algorithm and send lens controls along in the frame context. Signed-off-by: Daniel Scally --- src/ipa/ipu3/ipu3.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 6c76193a..abdcd69d 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -173,6 +173,7 @@ private: uint32_t gain_; uint32_t minGain_; uint32_t maxGain_; + uint32_t focus_; utils::Duration lineDuration_; @@ -671,6 +672,9 @@ void IPAIPU3::setControls(unsigned int frame) ctrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain_)); op.sensorControls = ctrls; + focus_ = context_.frameContext.af.focus; + op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(focus_)); + queueFrameAction.emit(frame, op); } From patchwork Fri Nov 26 00:31:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 14788 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 94B37C3250 for ; Fri, 26 Nov 2021 00:31:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2485560128; Fri, 26 Nov 2021 01:31:37 +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="PLGekzFb"; dkim-atps=neutral Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FDFA60442 for ; Fri, 26 Nov 2021 01:31:31 +0100 (CET) Received: by mail-wm1-x32d.google.com with SMTP id az34-20020a05600c602200b0033bf8662572so5740110wmb.0 for ; Thu, 25 Nov 2021 16:31: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=bZVKkt1twe0fHtrI7EWid1fVCYFD2Bw6ZSsYAt/eJoI=; b=PLGekzFbOzSnWsGUE30E0SKMTw2cOc62QI1NBLKjKU9mkeICWrSQwmBlSjcUkwDjt9 5CXNcFZRezttu51A4CanzaGCrPQarInlVfFQVIC++Uhs4l5iRk7dNLZL0vFRPZ9f+bxP M84jtmfK7Q/AFSjFFX8Wn36Oac/75t2KbHx384YkMrFYove4VA1uuCkzjCKGV6LR5IDu VIrElDEVQRkK6kczssAjhRYd7NhXTAYGM6YtHJTZGliaaKHeyBlaA0IuDUexrm03Tanf uDCBRXsYiifHAibxDoWcF7Wa/efXRk7XKyS5lkBD71ClQcKycmYFrgRp5DzR0Y+AA0EJ jPDA== 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=bZVKkt1twe0fHtrI7EWid1fVCYFD2Bw6ZSsYAt/eJoI=; b=eidFLN/PCmj0Jxsz9Oh+f9ci1u/WK1JwgycEJIioJzb5Enst4tLU/unCj5B2OL4J2Z ip2pzzyjb6uCaA1RHH7PIVbGq5CRkUl6uoSFg3W2pJhyArsdfwgCpCdBnQQk7UXUSUHb LzQLo2+ZQFfeGOuDM8BImdce/QWAs3Eea0iFKxox3kGFZ5nHSEUd5/gwmsIJNIg7EYHT nRNb9SumjIu2SEtMR7NHciI1XoTNiZJwGuXR4Cgy4F6t/9RhZVQ/xXR5s8BVmHodxH10 SuWTjlYI/30vCyJoJdsJDhb6cM4FMwJICOGf4II6vZdIBq6fp7LJh1P7sTzgm4ApnaKO zIYw== X-Gm-Message-State: AOAM531KAPLbH9OKEcTEB5yuqLHEUyeqHiI8jSJLx/GEi3Bv6We7tSsa 5fXF12zkBuawMiwtUXsiO4yZcYHEf7o= X-Google-Smtp-Source: ABdhPJxYe3DiW79GymGq1R7ghGkljJwRbQzmkX9+oIgOjTsem/fjVFP1U+hkuTjOPF2mAXvLYO8bCQ== X-Received: by 2002:a05:600c:224a:: with SMTP id a10mr11882982wmm.154.1637886691161; Thu, 25 Nov 2021 16:31: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 b188sm4381455wmd.45.2021.11.25.16.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 16:31:30 -0800 (PST) From: Daniel Scally To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Nov 2021 00:31:18 +0000 Message-Id: <20211126003118.42356-6-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211126003118.42356-1-djrscally@gmail.com> References: <20211126003118.42356-1-djrscally@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 5/5] ipa: ipu3: af: Remove v4l2 interaction from AF algorithm 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" Now that the actual interaction with the VCM's V4L2 subdev can be done through the CameraLens class, remove it from the auto focus algorithm code. Signed-off-by: Daniel Scally Reviewed-by: Kate Hsuan --- src/ipa/ipu3/algorithms/af.cpp | 29 +---------------------------- src/ipa/ipu3/algorithms/af.h | 3 --- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 2859a6a8..1bbf64aa 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -66,17 +66,10 @@ static constexpr double MaxChange_ = 0.8; Af::Af() : focus_(0), currentVariance_(0.0) { - /** - * For surface Go 2 back camera VCM (dw9719) - * \todo move to control class - */ - vcmFd_ = open("/dev/v4l-subdev8", O_RDWR); } Af::~Af() { - if (vcmFd_ != -1) - close(vcmFd_); } void Af::prepare(IPAContext &context, ipu3_uapi_params *params) @@ -169,25 +162,6 @@ int Af::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &con return 0; } -/** - * \brief Send focus step to the VCM. - * \param[in] value Set lens position. - * \todo It is hardcoded here for the dw9717 VCM and will be moved to the - * subdev control in the future. - */ -int Af::vcmSet(int value) -{ - int ret; - struct v4l2_control ctrl; - if (vcmFd_ == -1) - return -EINVAL; - memset(&ctrl, 0, sizeof(struct v4l2_control)); - ctrl.id = V4L2_CID_FOCUS_ABSOLUTE; - ctrl.value = value; - ret = ioctl(vcmFd_, VIDIOC_S_CTRL, &ctrl); - return ret; -} - /** * \brief Determine the max contrast image and lens position. y_table is the * statictic data from IPU3 and is composed of low pass and high pass filtered @@ -263,10 +237,9 @@ void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) if (focus_ > MaxFocusSteps_) { /* If reach the max step, move lens to the position and set "focus stable". */ context.frameContext.af.stable = true; - vcmSet(context.frameContext.af.focus); } else { focus_ += MinSearchStep_; - vcmSet(focus_); + context.frameContext.af.focus = focus_; } LOG(IPU3Af, Debug) << "Focus searching max variance is: " << context.frameContext.af.maxVariance diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index d32d5184..b21084e9 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -36,9 +36,6 @@ public: void process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override; private: - int vcmSet(int value); - - int vcmFd_; /* Used for focus scan. */ uint32_t focus_; /* Recent AF statistic variance. */