@@ -683,6 +683,41 @@ struct device_node *of_graph_get_endpoint_by_regs(
683683}
684684EXPORT_SYMBOL (of_graph_get_endpoint_by_regs );
685685
686+ /**
687+ * of_graph_get_remote_endpoint() - get remote endpoint node
688+ * @node: pointer to a local endpoint device_node
689+ *
690+ * Return: Remote endpoint node associated with remote endpoint node linked
691+ * to @node. Use of_node_put() on it when done.
692+ */
693+ struct device_node * of_graph_get_remote_endpoint (const struct device_node * node )
694+ {
695+ /* Get remote endpoint node. */
696+ return of_parse_phandle (node , "remote-endpoint" , 0 );
697+ }
698+ EXPORT_SYMBOL (of_graph_get_remote_endpoint );
699+
700+ /**
701+ * of_graph_get_port_parent() - get port's parent node
702+ * @node: pointer to a local endpoint device_node
703+ *
704+ * Return: device node associated with endpoint node linked
705+ * to @node. Use of_node_put() on it when done.
706+ */
707+ struct device_node * of_graph_get_port_parent (struct device_node * node )
708+ {
709+ unsigned int depth ;
710+
711+ /* Walk 3 levels up only if there is 'ports' node. */
712+ for (depth = 3 ; depth && node ; depth -- ) {
713+ node = of_get_next_parent (node );
714+ if (depth == 2 && of_node_cmp (node -> name , "ports" ))
715+ break ;
716+ }
717+ return node ;
718+ }
719+ EXPORT_SYMBOL (of_graph_get_port_parent );
720+
686721/**
687722 * of_graph_get_remote_port_parent() - get remote port's parent node
688723 * @node: pointer to a local endpoint device_node
@@ -694,18 +729,11 @@ struct device_node *of_graph_get_remote_port_parent(
694729 const struct device_node * node )
695730{
696731 struct device_node * np ;
697- unsigned int depth ;
698732
699733 /* Get remote endpoint node. */
700- np = of_parse_phandle (node , "remote-endpoint" , 0 );
734+ np = of_graph_get_remote_endpoint (node );
701735
702- /* Walk 3 levels up only if there is 'ports' node. */
703- for (depth = 3 ; depth && np ; depth -- ) {
704- np = of_get_next_parent (np );
705- if (depth == 2 && of_node_cmp (np -> name , "ports" ))
706- break ;
707- }
708- return np ;
736+ return of_graph_get_port_parent (np );
709737}
710738EXPORT_SYMBOL (of_graph_get_remote_port_parent );
711739
@@ -721,13 +749,25 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
721749 struct device_node * np ;
722750
723751 /* Get remote endpoint node. */
724- np = of_parse_phandle (node , "remote-endpoint" , 0 );
752+ np = of_graph_get_remote_endpoint (node );
725753 if (!np )
726754 return NULL ;
727755 return of_get_next_parent (np );
728756}
729757EXPORT_SYMBOL (of_graph_get_remote_port );
730758
759+ int of_graph_get_endpoint_count (const struct device_node * np )
760+ {
761+ struct device_node * endpoint ;
762+ int num = 0 ;
763+
764+ for_each_endpoint_of_node (np , endpoint )
765+ num ++ ;
766+
767+ return num ;
768+ }
769+ EXPORT_SYMBOL (of_graph_get_endpoint_count );
770+
731771/**
732772 * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint
733773 * @node: pointer to parent device_node containing graph port/endpoint
0 commit comments