From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2CC2373C17 for ; Fri, 4 Sep 2026 08:42:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788511340; cv=none; b=GD9qzpnAL/IiBUCWj9Jh18XAv4sYZkQC6yipLb26LhULPExqPHTmMNJkGaTVTp0YVggO1r5qdoLKgLvzzLb2ChywnPJAI0LmUJfeBxGRE7wOHKESpvTHEm/WwYIaEKea4ZGv3NR2A9c4JJQs4iph9SrmROR/vR1SKI1sKm2opNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788511340; c=relaxed/simple; bh=RGLL0tPfDP6uNlWVczfepdqpvZGR4BjUGaRZ583Zkzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I1vONGtY+O+L24qEVIz5FwDCTWAmiaYVnk8ICt6m8d2Ho/fFwII4RbTDPrjxw9iYlbxTDWeRiV7ET406Rq43CrxVskrPEo+A5Zpf7I/ha8mSFM1LaubQFqkqZqSNEx3+GGuSsSfPzPFgo4KQ1TPZszSLllUB+NzjiLlHxM4BnZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SdoxKF/l; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SdoxKF/l" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-cc1c8d4a959so659073a12.3 for ; Fri, 04 Sep 2026 01:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1788511337; x=1789116137; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=WRetEA2OXFI4SKJH2CBFzorRJvZCDQyI99zumpuCSb8=; b=SdoxKF/l8oxoFHgKxIo2orVm21tVNJeFZDYAAxz/og1s6K6/DLU1+vy+GxEnQ+d0O0 fH3coiOH9Oliz/lEqLyhSc1d8a8rS/4hCT7ewMQ+3J5qSbEMzkxbHxURGEcATdhgisYI P4/Zw0UjWnATRqqNQXFB8t1U7BgppgBSCHS9Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788511337; x=1789116137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WRetEA2OXFI4SKJH2CBFzorRJvZCDQyI99zumpuCSb8=; b=gQcj11YvI4tvtldk3oWKukqU5RdBfqPlR+Tzu2nyVxw4Jc69FeVAFZ1j904HLCmxxu Zizm2xqP6V093syYf36JbtiHnJM9H8HjIpBQ6eHEBu7PABQ1bMmbZjDh/wbAop+NMS3k e7snlQOVz3W7MwnRSED534jW9C1Qv4gCEyuquumOHPJpIANFYb0lY5XTJKj+q43bEPeq oixfm8STkjHVYPICqOeDE5DigGQzkA5YKVmVR6xzRhbQYdOJMhuTNKXVzZvNiurjkPHa fSAIb3KFkK2h7jHStuSXE5SSH4YRqSQPJZPj7x+K0WZd4GmPCFze+fMpixMDgoD5aDFb EvcQ== X-Forwarded-Encrypted: i=1; AKwUvByknKtc7pLdS7OSFJA3PzxIihPP1nCf6yjAopjjdHRIWHs+tvfvAHFf/CB9XsodM4s9zmAXkvcj1/ur9TE=@vger.kernel.org X-Gm-Message-State: AFuF++lBqbiocHzRzYtrGgBC9vlCE50AwWYcC1/Kw6Q8DXaS2jmv+OlQ gR5ioYuWnIWeIU2N0/4KIHvtN+8NKs4ceiG8grMZRdD2CnYzNW0mufzr3ZFmtybCxA== X-Gm-Gg: AYBFou3v1Utzm5V/AJJ3KasfWQrpPEX/x3AqTAW7AApX5950NMTVMoUjitPTbeh5tD4 y0QR159YQiOWSzknEeuvwcYE/B+7QeVlVNFC9Zk74Jbua930tcV8HQhR+1GWzeBW5nYkkQEgIpS LTc0FMR2N3PyhMlHJYubraNp6OPEWdvB2SxoEmwYRh5j2gfw3HBvt+Tl0aISvZkpToO7OdYKR5x 80iKxktnAoIGKttiw4Rbh7UmanzdtHaFYils5cF3xWp0zi1Ed2XgjQUADoySzn9102qoahhoAhW pPU02LwUFgejzLqPDDxSK28IM4+qaUV6GTGs/rFWRze2q6S5y7KUW8vObKuiN4gq4rN6MHrI4oc dwCDEB19m7cxBBeyEwmMKwySAI0Z55FKYr6lZIz6rGmtkn3Jc2hRRE9EUmOrvRsLs++aekVT/Q8 lwkGgJO+mEZJajjLJ7032j9equXeBfqXbGuUjRXHoQduQsOeld5+6L0M67aCoX3mx+lHGCTyknG akH7g4eytsJchmmn/FPLWwJ/xesDZDb3f9HI/Ort9zF X-Received: by 2002:a17:90b:314e:b0:38f:efed:5445 with SMTP id 98e67ed59e1d1-39b261500fdmr6024537a91.4.1788511335746; Fri, 04 Sep 2026 01:42:15 -0700 (PDT) Received: from wenst-7875.tpe.corp.google.com ([2a00:79e0:201d:8:343:bf21:3095:9c5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39b260fdf9asm3343538a91.9.2026.09.04.01.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 01:42:15 -0700 (PDT) From: Chen-Yu Tsai To: Bartosz Golaszewski , Greg Kroah-Hartman , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , "Rafael J. Wysocki" , Danilo Krummrich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno Cc: Wei Deng , Konrad Dybcio , Chen-Yu Tsai , linux-acpi@vger.kernel.org, driver-core@lists.linux.dev, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam , Alan Stern , Bartosz Golaszewski Subject: [PATCH v8 01/16] device property: Add fwnode_graph_get_port_by_id() Date: Fri, 4 Sep 2026 16:41:40 +0800 Message-ID: <20260904084158.1341550-2-wenst@chromium.org> X-Mailer: git-send-email 2.55.0.979.g7e5102b832-goog In-Reply-To: <20260904084158.1341550-1-wenst@chromium.org> References: <20260904084158.1341550-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In some cases the driver needs a reference to the port firmware node. Once such case is the upcoming USB power sequencing integration. The USB hub port is tied to the corresponding port firmware node if it exists. Provide a helper for this. Reviewed-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko Signed-off-by: Chen-Yu Tsai --- Changes since v7: - Mention in kernel-doc that the function does not return ports that have no endpoints (Sakari) Changes since v5: - Dropped left-over declaration in header (Sashiko) Changes since v4: - Added flags parameter so users can specify whether incomplete ports are returned or not (Sashiko) Changes since v2: - Moved "Return:" kernel-doc section to the end. (Andy) Changes since v1: - New patch --- drivers/base/property.c | 31 +++++++++++++++++++++++++++++++ include/linux/property.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index b136c339ddae..68108805482d 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1353,6 +1353,37 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, } EXPORT_SYMBOL(fwnode_graph_parse_endpoint); +/** + * fwnode_graph_get_port_by_id - get the port matching a given id + * @fwnode: parent fwnode_handle containing the graph + * @id: id of the port + * @flags: fwnode lookup flags + * + * The caller is responsible for calling fwnode_handle_put() on the returned + * fwnode pointer. + * + * Does not return ports that belong to disabled devices or endpoints that + * are unconnected, unless FWNODE_GRAPH_DEVICE_DISABLED is passed in @flags. + * + * Does not return ports that have no endpoints. + * + * Return: A 'port' firmware node pointer with refcount incremented. + */ +struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode, + u32 id, + unsigned long flags) +{ + struct fwnode_handle *ep; + + ep = fwnode_graph_get_endpoint_by_id(fwnode, id, 0, + flags | FWNODE_GRAPH_ENDPOINT_NEXT); + if (!ep) + return NULL; + + return fwnode_get_next_parent(ep); +} +EXPORT_SYMBOL_GPL(fwnode_graph_get_port_by_id); + const void *device_get_match_data(const struct device *dev) { return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev); diff --git a/include/linux/property.h b/include/linux/property.h index 907c790a3f01..3dbbd01a52d0 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -507,6 +507,8 @@ int fwnode_get_phy_mode(const struct fwnode_handle *fwnode); void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index); +struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode, u32 id, + unsigned long flags); struct fwnode_handle *fwnode_graph_get_next_endpoint( const struct fwnode_handle *fwnode, struct fwnode_handle *prev); struct fwnode_handle * -- 2.55.0.979.g7e5102b832-goog