Skip to content

Commit 339a6f7

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
UPSTREAM: device property: Move fwnode graph ops to firmware specific locations
Move firmware specific implementations of the fwnode graph operations to firmware specific locations. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> (cherry picked from commit 3b27d00e7b6d7c889d87fd00df600c495b968e30) Signed-off-by: Brian J Lovin <brian.j.lovin@intel.com> BUG=b:64133998 TEST=media device topology shows subdevs registered successfully TEST=no camera regression Change-Id: I4ced7427583a5438cfb5624d882ac8da96d03e70 Reviewed-on: https://chromium-review.googlesource.com/693677 Commit-Ready: Tomasz Figa <tfiga@chromium.org> Tested-by: Hyungwoo Yang <hyungwoo.yang@intel.com> Reviewed-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
1 parent 2bf7ce3 commit 339a6f7

4 files changed

Lines changed: 114 additions & 83 deletions

File tree

drivers/acpi/property.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,11 +1179,51 @@ acpi_fwnode_get_named_child_node(struct fwnode_handle *fwnode,
11791179
return NULL;
11801180
}
11811181

1182+
static struct fwnode_handle *
1183+
acpi_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
1184+
struct fwnode_handle *prev)
1185+
{
1186+
struct fwnode_handle *endpoint;
1187+
1188+
endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
1189+
if (IS_ERR(endpoint))
1190+
return NULL;
1191+
1192+
return endpoint;
1193+
}
1194+
1195+
static struct fwnode_handle *
1196+
acpi_fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
1197+
{
1198+
struct fwnode_handle *endpoint = NULL;
1199+
1200+
acpi_graph_get_remote_endpoint(fwnode, NULL, NULL, &endpoint);
1201+
1202+
return endpoint;
1203+
}
1204+
1205+
static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
1206+
struct fwnode_endpoint *endpoint)
1207+
{
1208+
struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
1209+
1210+
endpoint->local_fwnode = fwnode;
1211+
1212+
fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
1213+
fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
1214+
1215+
return 0;
1216+
}
1217+
11821218
const struct fwnode_operations acpi_fwnode_ops = {
11831219
.property_present = acpi_fwnode_property_present,
11841220
.property_read_int_array = acpi_fwnode_property_read_int_array,
11851221
.property_read_string_array = acpi_fwnode_property_read_string_array,
11861222
.get_parent = acpi_node_get_parent,
11871223
.get_next_child_node = acpi_get_next_subnode,
11881224
.get_named_child_node = acpi_fwnode_get_named_child_node,
1225+
.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
1226+
.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
1227+
.graph_get_port_parent = acpi_node_get_parent,
1228+
.graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint,
11891229
};

drivers/base/property.c

Lines changed: 8 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,24 +1083,7 @@ struct fwnode_handle *
10831083
fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
10841084
struct fwnode_handle *prev)
10851085
{
1086-
struct fwnode_handle *endpoint = NULL;
1087-
1088-
if (is_of_node(fwnode)) {
1089-
struct device_node *node;
1090-
1091-
node = of_graph_get_next_endpoint(to_of_node(fwnode),
1092-
to_of_node(prev));
1093-
1094-
if (node)
1095-
endpoint = &node->fwnode;
1096-
} else if (is_acpi_node(fwnode)) {
1097-
endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
1098-
if (IS_ERR(endpoint))
1099-
endpoint = NULL;
1100-
}
1101-
1102-
return endpoint;
1103-
1086+
return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
11041087
}
11051088
EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
11061089

@@ -1113,22 +1096,12 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
11131096
struct fwnode_handle *
11141097
fwnode_graph_get_remote_port_parent(struct fwnode_handle *fwnode)
11151098
{
1116-
struct fwnode_handle *parent = NULL;
1099+
struct fwnode_handle *port, *parent;
11171100

1118-
if (is_of_node(fwnode)) {
1119-
struct device_node *node;
1101+
port = fwnode_graph_get_remote_port(fwnode);
1102+
parent = fwnode_call_ptr_op(port, graph_get_port_parent);
11201103

1121-
node = of_graph_get_remote_port_parent(to_of_node(fwnode));
1122-
if (node)
1123-
parent = &node->fwnode;
1124-
} else if (is_acpi_node(fwnode)) {
1125-
int ret;
1126-
1127-
ret = acpi_graph_get_remote_endpoint(fwnode, &parent, NULL,
1128-
NULL);
1129-
if (ret)
1130-
return NULL;
1131-
}
1104+
fwnode_handle_put(port);
11321105

11331106
return parent;
11341107
}
@@ -1142,23 +1115,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
11421115
*/
11431116
struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode)
11441117
{
1145-
struct fwnode_handle *port = NULL;
1146-
1147-
if (is_of_node(fwnode)) {
1148-
struct device_node *node;
1149-
1150-
node = of_graph_get_remote_port(to_of_node(fwnode));
1151-
if (node)
1152-
port = &node->fwnode;
1153-
} else if (is_acpi_node(fwnode)) {
1154-
int ret;
1155-
1156-
ret = acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
1157-
if (ret)
1158-
return NULL;
1159-
}
1160-
1161-
return port;
1118+
return fwnode_get_next_parent(fwnode_graph_get_remote_endpoint(fwnode));
11621119
}
11631120
EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
11641121

@@ -1171,25 +1128,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
11711128
struct fwnode_handle *
11721129
fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
11731130
{
1174-
struct fwnode_handle *endpoint = NULL;
1175-
1176-
if (is_of_node(fwnode)) {
1177-
struct device_node *node;
1178-
1179-
node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint",
1180-
0);
1181-
if (node)
1182-
endpoint = &node->fwnode;
1183-
} else if (is_acpi_node(fwnode)) {
1184-
int ret;
1185-
1186-
ret = acpi_graph_get_remote_endpoint(fwnode, NULL, NULL,
1187-
&endpoint);
1188-
if (ret)
1189-
return NULL;
1190-
}
1191-
1192-
return endpoint;
1131+
return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
11931132
}
11941133
EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
11951134

@@ -1205,22 +1144,8 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
12051144
int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
12061145
struct fwnode_endpoint *endpoint)
12071146
{
1208-
struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
1209-
12101147
memset(endpoint, 0, sizeof(*endpoint));
12111148

1212-
endpoint->local_fwnode = fwnode;
1213-
1214-
if (is_acpi_node(port_fwnode)) {
1215-
fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
1216-
fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
1217-
} else {
1218-
fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port);
1219-
fwnode_property_read_u32(fwnode, "reg", &endpoint->id);
1220-
}
1221-
1222-
fwnode_handle_put(port_fwnode);
1223-
1224-
return 0;
1149+
return fwnode_call_int_op(fwnode, graph_parse_endpoint, endpoint);
12251150
}
12261151
EXPORT_SYMBOL(fwnode_graph_parse_endpoint);

drivers/of/property.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,54 @@ of_fwnode_get_named_child_node(struct fwnode_handle *fwnode,
844844
return NULL;
845845
}
846846

847+
static struct fwnode_handle *
848+
of_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
849+
struct fwnode_handle *prev)
850+
{
851+
return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode),
852+
to_of_node(prev)));
853+
}
854+
855+
static struct fwnode_handle *
856+
of_fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
857+
{
858+
return of_fwnode_handle(of_parse_phandle(to_of_node(fwnode),
859+
"remote-endpoint", 0));
860+
}
861+
862+
static struct fwnode_handle *
863+
of_fwnode_graph_get_port_parent(struct fwnode_handle *fwnode)
864+
{
865+
struct device_node *np;
866+
867+
/* Get the parent of the port */
868+
np = of_get_next_parent(to_of_node(fwnode));
869+
if (!np)
870+
return NULL;
871+
872+
/* Is this the "ports" node? If not, it's the port parent. */
873+
if (of_node_cmp(np->name, "ports"))
874+
return of_fwnode_handle(np);
875+
876+
return of_fwnode_handle(of_get_next_parent(np));
877+
}
878+
879+
static int of_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
880+
struct fwnode_endpoint *endpoint)
881+
{
882+
struct device_node *node = to_of_node(fwnode);
883+
struct device_node *port_node = of_get_parent(node);
884+
885+
endpoint->local_fwnode = fwnode;
886+
887+
of_property_read_u32(port_node, "reg", &endpoint->port);
888+
of_property_read_u32(node, "reg", &endpoint->id);
889+
890+
of_node_put(port_node);
891+
892+
return 0;
893+
}
894+
847895
const struct fwnode_operations of_fwnode_ops = {
848896
.get = of_fwnode_get,
849897
.put = of_fwnode_put,
@@ -853,4 +901,8 @@ const struct fwnode_operations of_fwnode_ops = {
853901
.get_parent = of_fwnode_get_parent,
854902
.get_next_child_node = of_fwnode_get_next_child_node,
855903
.get_named_child_node = of_fwnode_get_named_child_node,
904+
.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
905+
.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
906+
.graph_get_port_parent = of_fwnode_graph_get_port_parent,
907+
.graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
856908
};

include/linux/fwnode.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ struct fwnode_endpoint {
5656
* @get_parent: Return the parent of an fwnode.
5757
* @get_next_child_node: Return the next child node in an iteration.
5858
* @get_named_child_node: Return a child node with a given name.
59+
* @graph_get_next_endpoint: Return an endpoint node in an iteration.
60+
* @graph_get_remote_endpoint: Return the remote endpoint node of a local
61+
* endpoint node.
62+
* @graph_get_port_parent: Return the parent node of a port node.
63+
* @graph_parse_endpoint: Parse endpoint for port and endpoint id.
5964
*/
6065
struct fwnode_operations {
6166
void (*get)(struct fwnode_handle *fwnode);
@@ -75,6 +80,15 @@ struct fwnode_operations {
7580
struct fwnode_handle *child);
7681
struct fwnode_handle *
7782
(*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
83+
struct fwnode_handle *
84+
(*graph_get_next_endpoint)(struct fwnode_handle *fwnode,
85+
struct fwnode_handle *prev);
86+
struct fwnode_handle *
87+
(*graph_get_remote_endpoint)(struct fwnode_handle *fwnode);
88+
struct fwnode_handle *
89+
(*graph_get_port_parent)(struct fwnode_handle *fwnode);
90+
int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
91+
struct fwnode_endpoint *endpoint);
7892
};
7993

8094
#define fwnode_has_op(fwnode, op) \

0 commit comments

Comments
 (0)