From patchwork Wed May 25 19:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 12861641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8083CC433F5 for ; Wed, 25 May 2022 19:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8ONI6qyjxZV09Q0SCjVrYN/wjRebiZWh0SNu7U94Sq0=; b=Qg3myUVCxZxA2G +cEJZ0W//c+SD4UmUw7qJOcwOltE7Qa20Ng9F9CiNn67ejjJWIh5rKq/hmv2/2E9zwn5fc0zrukRd 33aU8PeLgtQsv3UIIA9G+Ueuc4dHWL+xeeMdvmW4OIb3Xv0alk8WhOQpTDbCnENrz5/0IzKLJwoMR Ku8vNuB8kTPiX2GfGg0KLvBR32n5UrP7DvdbW52wnZPACexfWW8MFDpIi8jfIjXiTZ7JN4IoKAL7J uUL5oVwNlr8fjaz5+oawXcvES7EFdqoYY1OV2fDSa+nI2STkrj2+7pnE7xP+f4bbg7Ie2RtlR7dKV e12trYG7KrPp+vuafdwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntwZN-00CK1m-Gt; Wed, 25 May 2022 19:21:21 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntwLR-00CEJV-4w for linux-arm-kernel@bombadil.infradead.org; Wed, 25 May 2022 19:06:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ShnSBA6h1ZBG7xxW8nZ//1YX0cs8S1JRXO0VG9uh+xg=; b=D+LXJzp5HEiSN47/xcmSnVMB3p Kp4stLmf0a6IKcmckevets2upyTSufQbxfrRvq3ckBVC+0avO5Ysw5jf3GJpaUaG9ox+r30ipu5Ih bguP90UwbDntC+6JgcOVklT/HcslYVwADSIPlQCY+9c/yfhTlko9hiAbmDMpQrri7nD7YBqNRzYaw p8Ae5dJ0rY7yBBzH5P7FpyVcWde/PIdcmg74n+Wf8xx6V74nkatv8EmMrtBClPLbrYa5asXR+2RBK Js/uZyQrGpZBGqSzh2WhL1NSOnrbNp1OhCRofYVPgRQ3uZZLTMSICEnGMdpmfs7BKVGRlcgF3YSNl bC0wGqJg==; Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntwLJ-001hEo-BI for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2022 19:06:54 +0000 Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 139EA1C000A; Wed, 25 May 2022 19:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1653505605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ShnSBA6h1ZBG7xxW8nZ//1YX0cs8S1JRXO0VG9uh+xg=; b=kk7s4W/ruFrG7csXC5kJYlaPv6OlQIo9avRpAJ4vEhHmVtCwoR0vIIK9Bw7Z0+VxAD9blu ifX0C9UQ699/HUuJUu2IZFZBr/Hm9GV+h1rrZE/U4xpbLGZ7HiuCdcfQEKNWtdj1CV4sUU AaNOLWNm2yaepE1vjnBPPo8RIlfIGroRGuCZE1ComIcep8u00PUC+B6aH2gLDAY8VR0EZw DpUg+7dNNCFshBdK6u34STg6Yy0ApZse1ZrbIm9K0dsCUAzVM1cbHsAEBiionDvzuIQx8i cP3J68rIcWG5Bpvw9K3yXbHa7M7EcAQhr5Zp+2W+rQbf97XXoCOhYIXsc+c7uQ== From: Paul Kocialkowski To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Cc: Yong Deng , Paul Kocialkowski , Mauro Carvalho Chehab , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Laurent Pinchart , Maxime Ripard , Thomas Petazzoni Subject: [PATCH v5 16/44] media: media-entity: Add helper to get a single enabled link Date: Wed, 25 May 2022 21:05:49 +0200 Message-Id: <20220525190617.696344-17-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220525190617.696344-1-paul.kocialkowski@bootlin.com> References: <20220525190617.696344-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220525_200650_092075_00CC23B5 X-CRM114-Status: GOOD ( 15.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In a situation where multiple links can be connected to the same pad of an entity, drivers might need to ensure that only a single link is enabled to apply appropriate routing (when the hardware can only use one at a time). Add a helper to return the single enabled link of an entity given a specific pad index, which errors out when zero or more than one link candidates are found. Signed-off-by: Paul Kocialkowski --- drivers/media/mc/mc-entity.c | 26 ++++++++++++++++++++++++++ include/media/media-entity.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index 11f5207f73aa..5387bd5f4cd7 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -900,6 +900,32 @@ media_entity_find_link(struct media_pad *source, struct media_pad *sink) } EXPORT_SYMBOL_GPL(media_entity_find_link); +struct media_link * +media_entity_get_single_enabled_link(struct media_entity *entity, + u16 pad_index) +{ + struct media_link *candidate = ERR_PTR(-ENODEV); + struct media_link *link; + + list_for_each_entry(link, &entity->links, list) { + struct media_pad *pad = link->sink->entity == entity ? + link->sink : link->source; + + if (pad->index != pad_index || + !(link->flags & MEDIA_LNK_FL_ENABLED)) + continue; + + /* Error out with more than a single candidate. */ + if (candidate != ERR_PTR(-ENODEV)) + return ERR_PTR(-ENXIO); + + candidate = link; + } + + return candidate; +} +EXPORT_SYMBOL_GPL(media_entity_get_single_enabled_link); + struct media_pad *media_entity_remote_pad(const struct media_pad *pad) { struct media_link *link; diff --git a/include/media/media-entity.h b/include/media/media-entity.h index a9a1c0ec5d1c..63c1436ffacf 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -847,6 +847,19 @@ int media_entity_setup_link(struct media_link *link, u32 flags); struct media_link *media_entity_find_link(struct media_pad *source, struct media_pad *sink); +/** + * media_entity_get_single_enabled_link - Get a single link for an entity pad + * @entity: The entity + * @pad_index: The index of the entity's pad expected to take part in link + * + * Return: returns a pointer to the single enabled link with the entity's pad. + * If no such link exists, returns a pointer error with %-ENODEV. + * If more than a single link exist, returns a pointer error with %-ENXIO. + */ +struct media_link * +media_entity_get_single_enabled_link(struct media_entity *entity, + u16 pad_index); + /** * media_entity_remote_pad - Find the pad at the remote end of a link * @pad: Pad at the local end of the link