blob: 9db632d16cbcb0199019e3ae88ed309d62122b3c [file] [log] [blame]
Philipp Zabelfd9fdb72014-02-10 22:01:48 +01001/*
2 * OF graph binding parsing helpers
3 *
4 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 *
7 * Copyright (C) 2012 Renesas Electronics Corp.
8 * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 */
14#ifndef __LINUX_OF_GRAPH_H
15#define __LINUX_OF_GRAPH_H
16
Mark Brown01218bf12015-03-26 09:47:55 -070017#include <linux/types.h>
Arnd Bergmann011d6f52016-05-02 12:59:19 +020018#include <linux/errno.h>
Mark Brown01218bf12015-03-26 09:47:55 -070019
Philipp Zabelf2a575f2014-02-14 11:53:56 +010020/**
21 * struct of_endpoint - the OF graph endpoint data structure
22 * @port: identifier (value of reg property) of a port this endpoint belongs to
23 * @id: identifier (value of reg property) of this endpoint
24 * @local_node: pointer to device_node of this endpoint
25 */
26struct of_endpoint {
27 unsigned int port;
28 unsigned int id;
29 const struct device_node *local_node;
30};
31
Philipp Zabelee890592014-04-14 17:53:25 +020032/**
33 * for_each_endpoint_of_node - iterate over every endpoint in a device node
34 * @parent: parent device node containing ports and endpoints
35 * @child: loop variable pointing to the current endpoint node
36 *
37 * When breaking out of the loop, of_node_put(child) has to be called manually.
38 */
39#define for_each_endpoint_of_node(parent, child) \
40 for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
41 child = of_graph_get_next_endpoint(parent, child))
42
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010043#ifdef CONFIG_OF
Philipp Zabelf2a575f2014-02-14 11:53:56 +010044int of_graph_parse_endpoint(const struct device_node *node,
45 struct of_endpoint *endpoint);
Philipp Zabelbfe446e2014-03-11 11:21:11 +010046struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010047struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
48 struct device_node *previous);
Hyungwon Hwang8ccd0d02015-06-12 21:59:01 +090049struct device_node *of_graph_get_endpoint_by_regs(
50 const struct device_node *parent, int port_reg, int reg);
Kuninori Morimoto4c9c3d52017-04-20 01:31:42 +000051struct device_node *of_graph_get_remote_endpoint(
52 const struct device_node *node);
Kuninori Morimoto0ef472a2017-04-20 01:32:17 +000053struct device_node *of_graph_get_port_parent(struct device_node *node);
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010054struct device_node *of_graph_get_remote_port_parent(
55 const struct device_node *node);
56struct device_node *of_graph_get_remote_port(const struct device_node *node);
Rob Herringb85ad492017-02-03 12:39:03 -060057struct device_node *of_graph_get_remote_node(const struct device_node *node,
58 u32 port, u32 endpoint);
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010059#else
60
Philipp Zabelf2a575f2014-02-14 11:53:56 +010061static inline int of_graph_parse_endpoint(const struct device_node *node,
Philipp Zabel00fd9612014-03-07 15:49:54 +010062 struct of_endpoint *endpoint)
Philipp Zabelf2a575f2014-02-14 11:53:56 +010063{
64 return -ENOSYS;
65}
66
Philipp Zabelbfe446e2014-03-11 11:21:11 +010067static inline struct device_node *of_graph_get_port_by_id(
68 struct device_node *node, u32 id)
69{
70 return NULL;
71}
72
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010073static inline struct device_node *of_graph_get_next_endpoint(
74 const struct device_node *parent,
75 struct device_node *previous)
76{
77 return NULL;
78}
79
Inki Daece0bdb82015-06-23 16:06:44 +090080static inline struct device_node *of_graph_get_endpoint_by_regs(
Hyungwon Hwang8ccd0d02015-06-12 21:59:01 +090081 const struct device_node *parent, int port_reg, int reg)
82{
83 return NULL;
84}
85
Kuninori Morimoto4c9c3d52017-04-20 01:31:42 +000086static inline struct device_node *of_graph_get_remote_endpoint(
87 const struct device_node *node)
88{
89 return NULL;
90}
91
Kuninori Morimoto0ef472a2017-04-20 01:32:17 +000092static inline struct device_node *of_graph_get_port_parent(
93 struct device_node *node)
94{
95 return NULL;
96}
97
Philipp Zabelfd9fdb72014-02-10 22:01:48 +010098static inline struct device_node *of_graph_get_remote_port_parent(
99 const struct device_node *node)
100{
101 return NULL;
102}
103
104static inline struct device_node *of_graph_get_remote_port(
105 const struct device_node *node)
106{
107 return NULL;
108}
Rob Herringb85ad492017-02-03 12:39:03 -0600109static inline struct device_node *of_graph_get_remote_node(
110 const struct device_node *node,
111 u32 port, u32 endpoint)
112{
113 return NULL;
114}
Philipp Zabelfd9fdb72014-02-10 22:01:48 +0100115
116#endif /* CONFIG_OF */
117
118#endif /* __LINUX_OF_GRAPH_H */