From patchwork Thu Feb 9 19:05:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 93768 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp151045qgi; Thu, 9 Feb 2017 11:06:14 -0800 (PST) X-Received: by 10.98.10.69 with SMTP id s66mr5377292pfi.146.1486667174526; Thu, 09 Feb 2017 11:06:14 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si10857164plj.103.2017.02.09.11.06.13; Thu, 09 Feb 2017 11:06:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753879AbdBITGH (ORCPT + 25 others); Thu, 9 Feb 2017 14:06:07 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:34664 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752301AbdBITGD (ORCPT ); Thu, 9 Feb 2017 14:06:03 -0500 Received: by mail-oi0-f66.google.com with SMTP id w144so959665oiw.1; Thu, 09 Feb 2017 11:06:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LL7AQp6rwDqvKVUp8qmi1QDLOLtg5hgfmqCw0hEbLS8=; b=c+TNE23qIm/f8Oygf4+xpae49sqrq38VnyQy0njZQO6198zHzCBM3ha0TJD2bThzsc xPh+xWmABPKLlxCd2EwYLr7sVDNnHt1eECCdTkrbPp0s8V/yos7re+APsAgehsWF2RZL Qr2xEtdkBHbyg2SF7NWAC0w8aRV8sr+o3lk3EmUs5ZvYoHeuHl7pcpbQ/GKjFpymQxMQ EIYEX7tbVOm8jKpFy8WtXA7hGSkYeJ3CAhaL22p9a1QzPp85LiK+cfYftTeSC/ll+MDh ANyZqxrOiIr+wTgJYQ5WjKg0MhZh5SzS44GlBXF8P2wuQkY5PDpx0nalzV2uqgfLOMHY g1xg== X-Gm-Message-State: AMke39lBKCXwgtoKIBewVJjTLwm6OyxGu6aM/LheZDrwdRBYYYK1UuWyUMagqZ2aP0KfMg== X-Received: by 10.202.244.131 with SMTP id s125mr2216452oih.136.1486667163045; Thu, 09 Feb 2017 11:06:03 -0800 (PST) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id s11sm6316209oia.15.2017.02.09.11.06.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2017 11:06:02 -0800 (PST) From: Rob Herring To: David Airlie , Daniel Vetter , Sean Paul Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Frank Rowand , Boris Brezillon , Archit Taneja , Jingoo Han , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Kyungmin Park , Kukjin Kim , Krzysztof Kozlowski , Javier Martinez Canillas , Stefan Agner , Alison Wang , Xinliang Liu , Rongrong Zou , Xinwei Kong , Chen Feng , Philipp Zabel , CK Hu , Matthias Brugger , Marek Vasut , Mark Yao , Heiko Stuebner , Maxime Ripard , Chen-Yu Tsai , Liviu Dudau , Mali DP Maintainers , Neil Armstrong , Carlo Caione , Kevin Hilman , Rob Clark , Jyri Sarha , Tomi Valkeinen , Eric Anholt , Russell King Subject: [PATCH v2 1/6] of: introduce of_graph_get_remote_node Date: Thu, 9 Feb 2017 13:05:53 -0600 Message-Id: <20170209190558.4784-2-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170209190558.4784-1-robh@kernel.org> References: <20170209190558.4784-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The OF graph API leaves too much of the graph walking to clients when in many cases the driver doesn't care about accessing the port or endpoint nodes. The drivers typically just want the device connected via a particular graph connection. of_graph_get_remote_node provides this functionality. Signed-off-by: Rob Herring Acked-by: Philipp Zabel --- v2: - Fix of_node_put on endpoint node - Added DocBook comments for function - Made port/endpoint unsigned to disallow -1 drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/of_graph.h | 8 ++++++++ 2 files changed, 45 insertions(+) -- 2.10.1 diff --git a/drivers/of/base.c b/drivers/of/base.c index d4bea3c797d6..525eb804f6ea 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2469,3 +2469,40 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node) return of_get_next_parent(np); } EXPORT_SYMBOL(of_graph_get_remote_port); + +/** + * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint + * @node: pointer to parent device_node containing graph port/endpoint + * @port: identifier (value of reg property) of the parent port node + * @endpoint: identifier (value of reg property) of the endpoint node + * + * Return: Remote device node associated with remote endpoint node linked + * to @node. Use of_node_put() on it when done. + */ +struct device_node *of_graph_get_remote_node(const struct device_node *node, + u32 port, u32 endpoint) +{ + struct device_node *endpoint_node, *remote; + + endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint); + if (!endpoint_node) { + pr_debug("no valid endpoint (%d, %d) for node %s\n", + port, endpoint, node->full_name); + return NULL; + } + + remote = of_graph_get_remote_port_parent(endpoint_node); + of_node_put(endpoint_node); + if (!remote) { + pr_debug("no valid remote node\n"); + return NULL; + } + + if (!of_device_is_available(remote)) { + pr_debug("not available for remote node\n"); + return NULL; + } + + return remote; +} +EXPORT_SYMBOL(of_graph_get_remote_node); diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index bb3a5a2cd570..abdb02eaef06 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -51,6 +51,8 @@ struct device_node *of_graph_get_endpoint_by_regs( struct device_node *of_graph_get_remote_port_parent( const struct device_node *node); struct device_node *of_graph_get_remote_port(const struct device_node *node); +struct device_node *of_graph_get_remote_node(const struct device_node *node, + u32 port, u32 endpoint); #else static inline int of_graph_parse_endpoint(const struct device_node *node, @@ -89,6 +91,12 @@ static inline struct device_node *of_graph_get_remote_port( { return NULL; } +static inline struct device_node *of_graph_get_remote_node( + const struct device_node *node, + u32 port, u32 endpoint) +{ + return NULL; +} #endif /* CONFIG_OF */