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: 9565811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 407FB601E9 for ; Fri, 10 Feb 2017 01:41:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3330D2823D for ; Fri, 10 Feb 2017 01:41:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27A2F28542; Fri, 10 Feb 2017 01:41:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 656BE2823D for ; Fri, 10 Feb 2017 01:41:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 19CF46EB81; Fri, 10 Feb 2017 01:41:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-oi0-f65.google.com (mail-oi0-f65.google.com [209.85.218.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id B8C226EB8C for ; Thu, 9 Feb 2017 19:06:03 +0000 (UTC) Received: by mail-oi0-f65.google.com with SMTP id u143so945375oif.3 for ; 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=dMvFbewtuGT73VdPusL0HDVTo9ixbMHcHQSyMsZ/vo2L90aP/to43Wc8aEwUl4D6JA faQeIpQaCDt5MCxbEtAyox4Yp7LlE88JiVm6DszJI/7GJyQRDoYaQ8sprh76AMB6NQrK 8pzDfoja9BS5t9qpY4p3LGYWPqHFtb7PIq0VsQdk+ddoNBWK+wmGfSujVcoZqHguQEuk vo+gLPeVWtFf8sMV96638hSQHbkT0Y2cBaB+Jl8DURupVXJk9erHkZvZpqdGcYmJGMhH 74w2cUH3hi0SLc6BJ5Y+jO4CKFcQT7fA8KOl5O1yuO+L9gY54jW1oN5snA160oMklBy6 RlGA== X-Gm-Message-State: AMke39meWj4gB5n3LtXsBaGhOjd/0qurK27a4f8egmQYY0PYhQy4og1Qhhd879a49+lQHw== 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 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> X-Mailman-Approved-At: Fri, 10 Feb 2017 01:41:18 +0000 Cc: Neil Armstrong , Liviu Dudau , dri-devel@lists.freedesktop.org, Tomi Valkeinen , Frank Rowand , Marek Vasut , Kevin Hilman , Chen-Yu Tsai , Krzysztof Kozlowski , Xinliang Liu , Javier Martinez Canillas , Xinwei Kong , Kukjin Kim , Mali DP Maintainers , devicetree@vger.kernel.org, Chen Feng , Jyri Sarha , Carlo Caione , Russell King , Matthias Brugger , Alison Wang , Jingoo Han , Seung-Woo Kim , linux-kernel@vger.kernel.org, Kyungmin Park , Rongrong Zou , Maxime Ripard X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 */