Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] v4l: of: Add v4l2_of_parse_link() function

The function fills a link data structure with the device node and port
number at both the local and remote ends of a link defined by one of its
endpoint nodes.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
c9bca8b3 2dca0551

+88
+61
drivers/media/v4l2-core/v4l2-of.c
··· 165 165 return 0; 166 166 } 167 167 EXPORT_SYMBOL(v4l2_of_parse_endpoint); 168 + 169 + /** 170 + * v4l2_of_parse_link() - parse a link between two endpoints 171 + * @node: pointer to the endpoint at the local end of the link 172 + * @link: pointer to the V4L2 OF link data structure 173 + * 174 + * Fill the link structure with the local and remote nodes and port numbers. 175 + * The local_node and remote_node fields are set to point to the local and 176 + * remote port's parent nodes respectively (the port parent node being the 177 + * parent node of the port node if that node isn't a 'ports' node, or the 178 + * grand-parent node of the port node otherwise). 179 + * 180 + * A reference is taken to both the local and remote nodes, the caller must use 181 + * v4l2_of_put_link() to drop the references when done with the link. 182 + * 183 + * Return: 0 on success, or -ENOLINK if the remote endpoint can't be found. 184 + */ 185 + int v4l2_of_parse_link(const struct device_node *node, 186 + struct v4l2_of_link *link) 187 + { 188 + struct device_node *np; 189 + 190 + memset(link, 0, sizeof(*link)); 191 + 192 + np = of_get_parent(node); 193 + of_property_read_u32(np, "reg", &link->local_port); 194 + np = of_get_next_parent(np); 195 + if (of_node_cmp(np->name, "ports") == 0) 196 + np = of_get_next_parent(np); 197 + link->local_node = np; 198 + 199 + np = of_parse_phandle(node, "remote-endpoint", 0); 200 + if (!np) { 201 + of_node_put(link->local_node); 202 + return -ENOLINK; 203 + } 204 + 205 + np = of_get_parent(np); 206 + of_property_read_u32(np, "reg", &link->remote_port); 207 + np = of_get_next_parent(np); 208 + if (of_node_cmp(np->name, "ports") == 0) 209 + np = of_get_next_parent(np); 210 + link->remote_node = np; 211 + 212 + return 0; 213 + } 214 + EXPORT_SYMBOL(v4l2_of_parse_link); 215 + 216 + /** 217 + * v4l2_of_put_link() - drop references to nodes in a link 218 + * @link: pointer to the V4L2 OF link data structure 219 + * 220 + * Drop references to the local and remote nodes in the link. This function must 221 + * be called on every link parsed with v4l2_of_parse_link(). 222 + */ 223 + void v4l2_of_put_link(struct v4l2_of_link *link) 224 + { 225 + of_node_put(link->local_node); 226 + of_node_put(link->remote_node); 227 + } 228 + EXPORT_SYMBOL(v4l2_of_put_link);
+27
include/media/v4l2-of.h
··· 69 69 struct list_head head; 70 70 }; 71 71 72 + /** 73 + * struct v4l2_of_link - a link between two endpoints 74 + * @local_node: pointer to device_node of this endpoint 75 + * @local_port: identifier of the port this endpoint belongs to 76 + * @remote_node: pointer to device_node of the remote endpoint 77 + * @remote_port: identifier of the port the remote endpoint belongs to 78 + */ 79 + struct v4l2_of_link { 80 + struct device_node *local_node; 81 + unsigned int local_port; 82 + struct device_node *remote_node; 83 + unsigned int remote_port; 84 + }; 85 + 72 86 #ifdef CONFIG_OF 73 87 int v4l2_of_parse_endpoint(const struct device_node *node, 74 88 struct v4l2_of_endpoint *endpoint); 89 + int v4l2_of_parse_link(const struct device_node *node, 90 + struct v4l2_of_link *link); 91 + void v4l2_of_put_link(struct v4l2_of_link *link); 75 92 #else /* CONFIG_OF */ 76 93 77 94 static inline int v4l2_of_parse_endpoint(const struct device_node *node, 78 95 struct v4l2_of_endpoint *link) 79 96 { 80 97 return -ENOSYS; 98 + } 99 + 100 + static inline int v4l2_of_parse_link(const struct device_node *node, 101 + struct v4l2_of_link *link) 102 + { 103 + return -ENOSYS; 104 + } 105 + 106 + static inline void v4l2_of_put_link(struct v4l2_of_link *link) 107 + { 81 108 } 82 109 83 110 #endif /* CONFIG_OF */