Skip to content

Commit c87b8fc

Browse files
Sakari Ailusrafaeljw
authored andcommitted
device property: Implement fwnode_graph_get_endpoint_count()
Add fwnode_graph_get_endpoint_count() function to provide generic implementation of of_graph_get_endpoint_count(). The former by default only counts endpoints to available devices which is consistent with the rest of the fwnode graph API. By providing FWNODE_GRAPH_DEVICE_DISABLED flag, also unconnected endpoints and endpoints to disabled devices are counted. Signed-off-by: Sakari Ailus <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 59f3f98 commit c87b8fc

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

drivers/base/property.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,18 @@ fwnode_graph_get_remote_node(const struct fwnode_handle *fwnode, u32 port_id,
10491049
}
10501050
EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_node);
10511051

1052+
static bool fwnode_graph_remote_available(struct fwnode_handle *ep)
1053+
{
1054+
struct fwnode_handle *dev_node;
1055+
bool available;
1056+
1057+
dev_node = fwnode_graph_get_remote_port_parent(ep);
1058+
available = fwnode_device_is_available(dev_node);
1059+
fwnode_handle_put(dev_node);
1060+
1061+
return available;
1062+
}
1063+
10521064
/**
10531065
* fwnode_graph_get_endpoint_by_id - get endpoint by port and endpoint numbers
10541066
* @fwnode: parent fwnode_handle containing the graph
@@ -1082,16 +1094,8 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
10821094
struct fwnode_endpoint fwnode_ep = { 0 };
10831095
int ret;
10841096

1085-
if (enabled_only) {
1086-
struct fwnode_handle *dev_node;
1087-
bool available;
1088-
1089-
dev_node = fwnode_graph_get_remote_port_parent(ep);
1090-
available = fwnode_device_is_available(dev_node);
1091-
fwnode_handle_put(dev_node);
1092-
if (!available)
1093-
continue;
1094-
}
1097+
if (enabled_only && !fwnode_graph_remote_available(ep))
1098+
continue;
10951099

10961100
ret = fwnode_graph_parse_endpoint(ep, &fwnode_ep);
10971101
if (ret < 0)
@@ -1124,6 +1128,31 @@ fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
11241128
}
11251129
EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_by_id);
11261130

1131+
/**
1132+
* fwnode_graph_get_endpoint_count - Count endpoints on a device node
1133+
* @fwnode: The node related to a device
1134+
* @flags: fwnode lookup flags
1135+
* Count endpoints in a device node.
1136+
*
1137+
* If FWNODE_GRAPH_DEVICE_DISABLED flag is specified, also unconnected endpoints
1138+
* and endpoints connected to disabled devices are counted.
1139+
*/
1140+
unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode,
1141+
unsigned long flags)
1142+
{
1143+
struct fwnode_handle *ep;
1144+
unsigned int count = 0;
1145+
1146+
fwnode_graph_for_each_endpoint(fwnode, ep) {
1147+
if (flags & FWNODE_GRAPH_DEVICE_DISABLED ||
1148+
fwnode_graph_remote_available(ep))
1149+
count++;
1150+
}
1151+
1152+
return count;
1153+
}
1154+
EXPORT_SYMBOL_GPL(fwnode_graph_get_endpoint_count);
1155+
11271156
/**
11281157
* fwnode_graph_parse_endpoint - parse common endpoint node properties
11291158
* @fwnode: pointer to endpoint fwnode_handle

include/linux/property.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ static inline bool fwnode_graph_is_endpoint(struct fwnode_handle *fwnode)
423423
struct fwnode_handle *
424424
fwnode_graph_get_endpoint_by_id(const struct fwnode_handle *fwnode,
425425
u32 port, u32 endpoint, unsigned long flags);
426+
unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode,
427+
unsigned long flags);
426428

427429
#define fwnode_graph_for_each_endpoint(fwnode, child) \
428430
for (child = NULL; \

0 commit comments

Comments
 (0)