Rob Herring | af6074f | 2017-12-27 12:55:14 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 2 | /* |
| 3 | * OF graph binding parsing helpers |
| 4 | * |
| 5 | * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd. |
| 6 | * Author: Sylwester Nawrocki <s.nawrocki@samsung.com> |
| 7 | * |
| 8 | * Copyright (C) 2012 Renesas Electronics Corp. |
| 9 | * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 10 | */ |
| 11 | #ifndef __LINUX_OF_GRAPH_H |
| 12 | #define __LINUX_OF_GRAPH_H |
| 13 | |
Mark Brown | 01218bf1 | 2015-03-26 09:47:55 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
Arnd Bergmann | 011d6f5 | 2016-05-02 12:59:19 +0200 | [diff] [blame] | 15 | #include <linux/errno.h> |
Mark Brown | 01218bf1 | 2015-03-26 09:47:55 -0700 | [diff] [blame] | 16 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 17 | /** |
| 18 | * struct of_endpoint - the OF graph endpoint data structure |
| 19 | * @port: identifier (value of reg property) of a port this endpoint belongs to |
| 20 | * @id: identifier (value of reg property) of this endpoint |
| 21 | * @local_node: pointer to device_node of this endpoint |
| 22 | */ |
| 23 | struct of_endpoint { |
| 24 | unsigned int port; |
| 25 | unsigned int id; |
| 26 | const struct device_node *local_node; |
| 27 | }; |
| 28 | |
Philipp Zabel | ee89059 | 2014-04-14 17:53:25 +0200 | [diff] [blame] | 29 | /** |
| 30 | * for_each_endpoint_of_node - iterate over every endpoint in a device node |
| 31 | * @parent: parent device node containing ports and endpoints |
| 32 | * @child: loop variable pointing to the current endpoint node |
| 33 | * |
| 34 | * When breaking out of the loop, of_node_put(child) has to be called manually. |
| 35 | */ |
| 36 | #define for_each_endpoint_of_node(parent, child) \ |
| 37 | for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \ |
| 38 | child = of_graph_get_next_endpoint(parent, child)) |
| 39 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 40 | #ifdef CONFIG_OF |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 41 | int of_graph_parse_endpoint(const struct device_node *node, |
| 42 | struct of_endpoint *endpoint); |
Kuninori Morimoto | ac1e695 | 2017-04-20 01:32:47 +0000 | [diff] [blame] | 43 | int of_graph_get_endpoint_count(const struct device_node *np); |
Philipp Zabel | bfe446e | 2014-03-11 11:21:11 +0100 | [diff] [blame] | 44 | struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id); |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 45 | struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, |
| 46 | struct device_node *previous); |
Hyungwon Hwang | 8ccd0d0 | 2015-06-12 21:59:01 +0900 | [diff] [blame] | 47 | struct device_node *of_graph_get_endpoint_by_regs( |
| 48 | const struct device_node *parent, int port_reg, int reg); |
Kuninori Morimoto | 4c9c3d5 | 2017-04-20 01:31:42 +0000 | [diff] [blame] | 49 | struct device_node *of_graph_get_remote_endpoint( |
| 50 | const struct device_node *node); |
Kuninori Morimoto | 0ef472a | 2017-04-20 01:32:17 +0000 | [diff] [blame] | 51 | struct device_node *of_graph_get_port_parent(struct device_node *node); |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 52 | struct device_node *of_graph_get_remote_port_parent( |
| 53 | const struct device_node *node); |
| 54 | struct device_node *of_graph_get_remote_port(const struct device_node *node); |
Rob Herring | b85ad49 | 2017-02-03 12:39:03 -0600 | [diff] [blame] | 55 | struct device_node *of_graph_get_remote_node(const struct device_node *node, |
| 56 | u32 port, u32 endpoint); |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 57 | #else |
| 58 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 59 | static inline int of_graph_parse_endpoint(const struct device_node *node, |
Philipp Zabel | 00fd961 | 2014-03-07 15:49:54 +0100 | [diff] [blame] | 60 | struct of_endpoint *endpoint) |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 61 | { |
| 62 | return -ENOSYS; |
| 63 | } |
| 64 | |
Kuninori Morimoto | ac1e695 | 2017-04-20 01:32:47 +0000 | [diff] [blame] | 65 | static inline int of_graph_get_endpoint_count(const struct device_node *np) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
Philipp Zabel | bfe446e | 2014-03-11 11:21:11 +0100 | [diff] [blame] | 70 | static inline struct device_node *of_graph_get_port_by_id( |
| 71 | struct device_node *node, u32 id) |
| 72 | { |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 76 | static inline struct device_node *of_graph_get_next_endpoint( |
| 77 | const struct device_node *parent, |
| 78 | struct device_node *previous) |
| 79 | { |
| 80 | return NULL; |
| 81 | } |
| 82 | |
Inki Dae | ce0bdb8 | 2015-06-23 16:06:44 +0900 | [diff] [blame] | 83 | static inline struct device_node *of_graph_get_endpoint_by_regs( |
Hyungwon Hwang | 8ccd0d0 | 2015-06-12 21:59:01 +0900 | [diff] [blame] | 84 | const struct device_node *parent, int port_reg, int reg) |
| 85 | { |
| 86 | return NULL; |
| 87 | } |
| 88 | |
Kuninori Morimoto | 4c9c3d5 | 2017-04-20 01:31:42 +0000 | [diff] [blame] | 89 | static inline struct device_node *of_graph_get_remote_endpoint( |
| 90 | const struct device_node *node) |
| 91 | { |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Kuninori Morimoto | 0ef472a | 2017-04-20 01:32:17 +0000 | [diff] [blame] | 95 | static inline struct device_node *of_graph_get_port_parent( |
| 96 | struct device_node *node) |
| 97 | { |
| 98 | return NULL; |
| 99 | } |
| 100 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 101 | static inline struct device_node *of_graph_get_remote_port_parent( |
| 102 | const struct device_node *node) |
| 103 | { |
| 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | static inline struct device_node *of_graph_get_remote_port( |
| 108 | const struct device_node *node) |
| 109 | { |
| 110 | return NULL; |
| 111 | } |
Rob Herring | b85ad49 | 2017-02-03 12:39:03 -0600 | [diff] [blame] | 112 | static inline struct device_node *of_graph_get_remote_node( |
| 113 | const struct device_node *node, |
| 114 | u32 port, u32 endpoint) |
| 115 | { |
| 116 | return NULL; |
| 117 | } |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 118 | |
| 119 | #endif /* CONFIG_OF */ |
| 120 | |
| 121 | #endif /* __LINUX_OF_GRAPH_H */ |