Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 1 | /* |
| 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 Brown | 01218bf | 2015-03-26 09:47:55 -0700 | [diff] [blame] | 17 | #include <linux/types.h> |
Arnd Bergmann | 011d6f5 | 2016-05-02 12:59:19 +0200 | [diff] [blame] | 18 | #include <linux/errno.h> |
Mark Brown | 01218bf | 2015-03-26 09:47:55 -0700 | [diff] [blame] | 19 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 20 | /** |
| 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 | */ |
| 26 | struct of_endpoint { |
| 27 | unsigned int port; |
| 28 | unsigned int id; |
| 29 | const struct device_node *local_node; |
| 30 | }; |
| 31 | |
Philipp Zabel | ee89059 | 2014-04-14 17:53:25 +0200 | [diff] [blame] | 32 | /** |
| 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 Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 43 | #ifdef CONFIG_OF |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 44 | int of_graph_parse_endpoint(const struct device_node *node, |
| 45 | struct of_endpoint *endpoint); |
Kuninori Morimoto | ac1e695 | 2017-04-20 01:32:47 +0000 | [diff] [blame] | 46 | int of_graph_get_endpoint_count(const struct device_node *np); |
Philipp Zabel | bfe446e | 2014-03-11 11:21:11 +0100 | [diff] [blame] | 47 | 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] | 48 | struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, |
| 49 | struct device_node *previous); |
Hyungwon Hwang | 8ccd0d0 | 2015-06-12 21:59:01 +0900 | [diff] [blame] | 50 | struct device_node *of_graph_get_endpoint_by_regs( |
| 51 | const struct device_node *parent, int port_reg, int reg); |
Kuninori Morimoto | 4c9c3d5 | 2017-04-20 01:31:42 +0000 | [diff] [blame] | 52 | struct device_node *of_graph_get_remote_endpoint( |
| 53 | const struct device_node *node); |
Kuninori Morimoto | 0ef472a | 2017-04-20 01:32:17 +0000 | [diff] [blame] | 54 | struct device_node *of_graph_get_port_parent(struct device_node *node); |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 55 | struct device_node *of_graph_get_remote_port_parent( |
| 56 | const struct device_node *node); |
| 57 | 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] | 58 | struct device_node *of_graph_get_remote_node(const struct device_node *node, |
| 59 | u32 port, u32 endpoint); |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 60 | #else |
| 61 | |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 62 | static inline int of_graph_parse_endpoint(const struct device_node *node, |
Philipp Zabel | 00fd961 | 2014-03-07 15:49:54 +0100 | [diff] [blame] | 63 | struct of_endpoint *endpoint) |
Philipp Zabel | f2a575f | 2014-02-14 11:53:56 +0100 | [diff] [blame] | 64 | { |
| 65 | return -ENOSYS; |
| 66 | } |
| 67 | |
Kuninori Morimoto | ac1e695 | 2017-04-20 01:32:47 +0000 | [diff] [blame] | 68 | static inline int of_graph_get_endpoint_count(const struct device_node *np) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | |
Philipp Zabel | bfe446e | 2014-03-11 11:21:11 +0100 | [diff] [blame] | 73 | static inline struct device_node *of_graph_get_port_by_id( |
| 74 | struct device_node *node, u32 id) |
| 75 | { |
| 76 | return NULL; |
| 77 | } |
| 78 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 79 | static inline struct device_node *of_graph_get_next_endpoint( |
| 80 | const struct device_node *parent, |
| 81 | struct device_node *previous) |
| 82 | { |
| 83 | return NULL; |
| 84 | } |
| 85 | |
Inki Dae | ce0bdb8 | 2015-06-23 16:06:44 +0900 | [diff] [blame] | 86 | static inline struct device_node *of_graph_get_endpoint_by_regs( |
Hyungwon Hwang | 8ccd0d0 | 2015-06-12 21:59:01 +0900 | [diff] [blame] | 87 | const struct device_node *parent, int port_reg, int reg) |
| 88 | { |
| 89 | return NULL; |
| 90 | } |
| 91 | |
Kuninori Morimoto | 4c9c3d5 | 2017-04-20 01:31:42 +0000 | [diff] [blame] | 92 | static inline struct device_node *of_graph_get_remote_endpoint( |
| 93 | const struct device_node *node) |
| 94 | { |
| 95 | return NULL; |
| 96 | } |
| 97 | |
Kuninori Morimoto | 0ef472a | 2017-04-20 01:32:17 +0000 | [diff] [blame] | 98 | static inline struct device_node *of_graph_get_port_parent( |
| 99 | struct device_node *node) |
| 100 | { |
| 101 | return NULL; |
| 102 | } |
| 103 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 104 | static inline struct device_node *of_graph_get_remote_port_parent( |
| 105 | const struct device_node *node) |
| 106 | { |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | static inline struct device_node *of_graph_get_remote_port( |
| 111 | const struct device_node *node) |
| 112 | { |
| 113 | return NULL; |
| 114 | } |
Rob Herring | b85ad49 | 2017-02-03 12:39:03 -0600 | [diff] [blame] | 115 | static inline struct device_node *of_graph_get_remote_node( |
| 116 | const struct device_node *node, |
| 117 | u32 port, u32 endpoint) |
| 118 | { |
| 119 | return NULL; |
| 120 | } |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 121 | |
| 122 | #endif /* CONFIG_OF */ |
| 123 | |
| 124 | #endif /* __LINUX_OF_GRAPH_H */ |