Skip to content

Commit 3b27d00

Browse files
Sakari Ailusrafaeljw
authored andcommitted
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>
1 parent 3708184 commit 3b27d00

File tree

4 files changed

+114
-83
lines changed

4 files changed

+114
-83
lines changed

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
@@ -1156,24 +1156,7 @@ struct fwnode_handle *
11561156
fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
11571157
struct fwnode_handle *prev)
11581158
{
1159-
struct fwnode_handle *endpoint = NULL;
1160-
1161-
if (is_of_node(fwnode)) {
1162-
struct device_node *node;
1163-
1164-
node = of_graph_get_next_endpoint(to_of_node(fwnode),
1165-
to_of_node(prev));
1166-
1167-
if (node)
1168-
endpoint = &node->fwnode;
1169-
} else if (is_acpi_node(fwnode)) {
1170-
endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
1171-
if (IS_ERR(endpoint))
1172-
endpoint = NULL;
1173-
}
1174-
1175-
return endpoint;
1176-
1159+
return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
11771160
}
11781161
EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
11791162

@@ -1186,22 +1169,12 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
11861169
struct fwnode_handle *
11871170
fwnode_graph_get_remote_port_parent(struct fwnode_handle *fwnode)
11881171
{
1189-
struct fwnode_handle *parent = NULL;
1172+
struct fwnode_handle *port, *parent;
11901173

1191-
if (is_of_node(fwnode)) {
1192-
struct device_node *node;
1174+
port = fwnode_graph_get_remote_port(fwnode);
1175+
parent = fwnode_call_ptr_op(port, graph_get_port_parent);
11931176

1194-
node = of_graph_get_remote_port_parent(to_of_node(fwnode));
1195-
if (node)
1196-
parent = &node->fwnode;
1197-
} else if (is_acpi_node(fwnode)) {
1198-
int ret;
1199-
1200-
ret = acpi_graph_get_remote_endpoint(fwnode, &parent, NULL,
1201-
NULL);
1202-
if (ret)
1203-
return NULL;
1204-
}
1177+
fwnode_handle_put(port);
12051178

12061179
return parent;
12071180
}
@@ -1215,23 +1188,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
12151188
*/
12161189
struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode)
12171190
{
1218-
struct fwnode_handle *port = NULL;
1219-
1220-
if (is_of_node(fwnode)) {
1221-
struct device_node *node;
1222-
1223-
node = of_graph_get_remote_port(to_of_node(fwnode));
1224-
if (node)
1225-
port = &node->fwnode;
1226-
} else if (is_acpi_node(fwnode)) {
1227-
int ret;
1228-
1229-
ret = acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
1230-
if (ret)
1231-
return NULL;
1232-
}
1233-
1234-
return port;
1191+
return fwnode_get_next_parent(fwnode_graph_get_remote_endpoint(fwnode));
12351192
}
12361193
EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
12371194

@@ -1244,25 +1201,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
12441201
struct fwnode_handle *
12451202
fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
12461203
{
1247-
struct fwnode_handle *endpoint = NULL;
1248-
1249-
if (is_of_node(fwnode)) {
1250-
struct device_node *node;
1251-
1252-
node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint",
1253-
0);
1254-
if (node)
1255-
endpoint = &node->fwnode;
1256-
} else if (is_acpi_node(fwnode)) {
1257-
int ret;
1258-
1259-
ret = acpi_graph_get_remote_endpoint(fwnode, NULL, NULL,
1260-
&endpoint);
1261-
if (ret)
1262-
return NULL;
1263-
}
1264-
1265-
return endpoint;
1204+
return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
12661205
}
12671206
EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
12681207

@@ -1278,22 +1217,8 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
12781217
int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
12791218
struct fwnode_endpoint *endpoint)
12801219
{
1281-
struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
1282-
12831220
memset(endpoint, 0, sizeof(*endpoint));
12841221

1285-
endpoint->local_fwnode = fwnode;
1286-
1287-
if (is_acpi_node(port_fwnode)) {
1288-
fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
1289-
fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id);
1290-
} else {
1291-
fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port);
1292-
fwnode_property_read_u32(fwnode, "reg", &endpoint->id);
1293-
}
1294-
1295-
fwnode_handle_put(port_fwnode);
1296-
1297-
return 0;
1222+
return fwnode_call_int_op(fwnode, graph_parse_endpoint, endpoint);
12981223
}
12991224
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
@@ -57,6 +57,11 @@ struct fwnode_endpoint {
5757
* @get_parent: Return the parent of an fwnode.
5858
* @get_next_child_node: Return the next child node in an iteration.
5959
* @get_named_child_node: Return a child node with a given name.
60+
* @graph_get_next_endpoint: Return an endpoint node in an iteration.
61+
* @graph_get_remote_endpoint: Return the remote endpoint node of a local
62+
* endpoint node.
63+
* @graph_get_port_parent: Return the parent node of a port node.
64+
* @graph_parse_endpoint: Parse endpoint for port and endpoint id.
6065
*/
6166
struct fwnode_operations {
6267
void (*get)(struct fwnode_handle *fwnode);
@@ -76,6 +81,15 @@ struct fwnode_operations {
7681
struct fwnode_handle *child);
7782
struct fwnode_handle *
7883
(*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
84+
struct fwnode_handle *
85+
(*graph_get_next_endpoint)(struct fwnode_handle *fwnode,
86+
struct fwnode_handle *prev);
87+
struct fwnode_handle *
88+
(*graph_get_remote_endpoint)(struct fwnode_handle *fwnode);
89+
struct fwnode_handle *
90+
(*graph_get_port_parent)(struct fwnode_handle *fwnode);
91+
int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
92+
struct fwnode_endpoint *endpoint);
7993
};
8094

8195
#define fwnode_has_op(fwnode, op) \

0 commit comments

Comments
 (0)