Skip to content

Commit 8a06d1e

Browse files
Saravana Kannangregkh
authored andcommitted
of: property: Update implementation of add_links() to create fwnode links
The semantics of add_links() has changed from creating device link between devices to creating fwnode links between fwnodes. So, update the implementation of add_links() to match the new semantics. Acked-by: Rob Herring <[email protected]> Signed-off-by: Saravana Kannan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 25ac86c commit 8a06d1e

File tree

1 file changed

+41
-109
lines changed

1 file changed

+41
-109
lines changed

drivers/of/property.c

Lines changed: 41 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,33 +1038,9 @@ static bool of_is_ancestor_of(struct device_node *test_ancestor,
10381038
}
10391039

10401040
/**
1041-
* of_get_next_parent_dev - Add device link to supplier from supplier phandle
1042-
* @np: device tree node
1043-
*
1044-
* Given a device tree node (@np), this function finds its closest ancestor
1045-
* device tree node that has a corresponding struct device.
1046-
*
1047-
* The caller of this function is expected to call put_device() on the returned
1048-
* device when they are done.
1049-
*/
1050-
static struct device *of_get_next_parent_dev(struct device_node *np)
1051-
{
1052-
struct device *dev = NULL;
1053-
1054-
of_node_get(np);
1055-
do {
1056-
np = of_get_next_parent(np);
1057-
if (np)
1058-
dev = get_dev_from_fwnode(&np->fwnode);
1059-
} while (np && !dev);
1060-
of_node_put(np);
1061-
return dev;
1062-
}
1063-
1064-
/**
1065-
* of_link_to_phandle - Add device link to supplier from supplier phandle
1066-
* @dev: consumer device
1067-
* @sup_np: phandle to supplier device tree node
1041+
* of_link_to_phandle - Add fwnode link to supplier from supplier phandle
1042+
* @con_np: consumer device tree node
1043+
* @sup_np: supplier device tree node
10681044
*
10691045
* Given a phandle to a supplier device tree node (@sup_np), this function
10701046
* finds the device that owns the supplier device tree node and creates a
@@ -1074,16 +1050,14 @@ static struct device *of_get_next_parent_dev(struct device_node *np)
10741050
* cases, it returns an error.
10751051
*
10761052
* Returns:
1077-
* - 0 if link successfully created to supplier
1078-
* - -EAGAIN if linking to the supplier should be reattempted
1053+
* - 0 if fwnode link successfully created to supplier
10791054
* - -EINVAL if the supplier link is invalid and should not be created
1080-
* - -ENODEV if there is no device that corresponds to the supplier phandle
1055+
* - -ENODEV if struct device will never be create for supplier
10811056
*/
1082-
static int of_link_to_phandle(struct device *dev, struct device_node *sup_np,
1083-
u32 dl_flags)
1057+
static int of_link_to_phandle(struct device_node *con_np,
1058+
struct device_node *sup_np)
10841059
{
1085-
struct device *sup_dev, *sup_par_dev;
1086-
int ret = 0;
1060+
struct device *sup_dev;
10871061
struct device_node *tmp_np = sup_np;
10881062

10891063
of_node_get(sup_np);
@@ -1106,7 +1080,8 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np,
11061080
}
11071081

11081082
if (!sup_np) {
1109-
dev_dbg(dev, "Not linking to %pOFP - No device\n", tmp_np);
1083+
pr_debug("Not linking %pOFP to %pOFP - No device\n",
1084+
con_np, tmp_np);
11101085
return -ENODEV;
11111086
}
11121087

@@ -1115,53 +1090,30 @@ static int of_link_to_phandle(struct device *dev, struct device_node *sup_np,
11151090
* descendant nodes. By definition, a child node can't be a functional
11161091
* dependency for the parent node.
11171092
*/
1118-
if (of_is_ancestor_of(dev->of_node, sup_np)) {
1119-
dev_dbg(dev, "Not linking to %pOFP - is descendant\n", sup_np);
1093+
if (of_is_ancestor_of(con_np, sup_np)) {
1094+
pr_debug("Not linking %pOFP to %pOFP - is descendant\n",
1095+
con_np, sup_np);
11201096
of_node_put(sup_np);
11211097
return -EINVAL;
11221098
}
1099+
1100+
/*
1101+
* Don't create links to "early devices" that won't have struct devices
1102+
* created for them.
1103+
*/
11231104
sup_dev = get_dev_from_fwnode(&sup_np->fwnode);
11241105
if (!sup_dev && of_node_check_flag(sup_np, OF_POPULATED)) {
1125-
/* Early device without struct device. */
1126-
dev_dbg(dev, "Not linking to %pOFP - No struct device\n",
1127-
sup_np);
1106+
pr_debug("Not linking %pOFP to %pOFP - No struct device\n",
1107+
con_np, sup_np);
11281108
of_node_put(sup_np);
11291109
return -ENODEV;
1130-
} else if (!sup_dev) {
1131-
/*
1132-
* DL_FLAG_SYNC_STATE_ONLY doesn't block probing and supports
1133-
* cycles. So cycle detection isn't necessary and shouldn't be
1134-
* done.
1135-
*/
1136-
if (dl_flags & DL_FLAG_SYNC_STATE_ONLY) {
1137-
of_node_put(sup_np);
1138-
return -EAGAIN;
1139-
}
1140-
1141-
sup_par_dev = of_get_next_parent_dev(sup_np);
1142-
1143-
if (sup_par_dev && device_is_dependent(dev, sup_par_dev)) {
1144-
/* Cyclic dependency detected, don't try to link */
1145-
dev_dbg(dev, "Not linking to %pOFP - cycle detected\n",
1146-
sup_np);
1147-
ret = -EINVAL;
1148-
} else {
1149-
/*
1150-
* Can't check for cycles or no cycles. So let's try
1151-
* again later.
1152-
*/
1153-
ret = -EAGAIN;
1154-
}
1155-
1156-
of_node_put(sup_np);
1157-
put_device(sup_par_dev);
1158-
return ret;
11591110
}
1160-
of_node_put(sup_np);
1161-
if (!device_link_add(dev, sup_dev, dl_flags))
1162-
ret = -EINVAL;
11631111
put_device(sup_dev);
1164-
return ret;
1112+
1113+
fwnode_link_add(of_fwnode_handle(con_np), of_fwnode_handle(sup_np));
1114+
of_node_put(sup_np);
1115+
1116+
return 0;
11651117
}
11661118

11671119
/**
@@ -1361,69 +1313,49 @@ static const struct supplier_bindings of_supplier_bindings[] = {
13611313
* that list phandles to suppliers. If @prop_name isn't one, this function
13621314
* doesn't do anything.
13631315
*
1364-
* If @prop_name is one, this function attempts to create device links from the
1365-
* consumer device @dev to all the devices of the suppliers listed in
1366-
* @prop_name.
1316+
* If @prop_name is one, this function attempts to create fwnode links from the
1317+
* consumer device tree node @con_np to all the suppliers device tree nodes
1318+
* listed in @prop_name.
13671319
*
1368-
* Any failed attempt to create a device link will NOT result in an immediate
1320+
* Any failed attempt to create a fwnode link will NOT result in an immediate
13691321
* return. of_link_property() must create links to all the available supplier
1370-
* devices even when attempts to create a link to one or more suppliers fail.
1322+
* device tree nodes even when attempts to create a link to one or more
1323+
* suppliers fail.
13711324
*/
1372-
static int of_link_property(struct device *dev, struct device_node *con_np,
1373-
const char *prop_name)
1325+
static int of_link_property(struct device_node *con_np, const char *prop_name)
13741326
{
13751327
struct device_node *phandle;
13761328
const struct supplier_bindings *s = of_supplier_bindings;
13771329
unsigned int i = 0;
13781330
bool matched = false;
13791331
int ret = 0;
1380-
u32 dl_flags;
1381-
1382-
if (dev->of_node == con_np)
1383-
dl_flags = fw_devlink_get_flags();
1384-
else
1385-
dl_flags = DL_FLAG_SYNC_STATE_ONLY;
13861332

13871333
/* Do not stop at first failed link, link all available suppliers. */
13881334
while (!matched && s->parse_prop) {
13891335
while ((phandle = s->parse_prop(con_np, prop_name, i))) {
13901336
matched = true;
13911337
i++;
1392-
if (of_link_to_phandle(dev, phandle, dl_flags)
1393-
== -EAGAIN)
1394-
ret = -EAGAIN;
1338+
of_link_to_phandle(con_np, phandle);
13951339
of_node_put(phandle);
13961340
}
13971341
s++;
13981342
}
13991343
return ret;
14001344
}
14011345

1402-
static int of_link_to_suppliers(struct device *dev,
1403-
struct device_node *con_np)
1346+
static int of_fwnode_add_links(struct fwnode_handle *fwnode,
1347+
struct device *dev)
14041348
{
1405-
struct device_node *child;
14061349
struct property *p;
1407-
int ret = 0;
1350+
struct device_node *con_np = to_of_node(fwnode);
14081351

1409-
for_each_property_of_node(con_np, p)
1410-
if (of_link_property(dev, con_np, p->name))
1411-
ret = -ENODEV;
1412-
1413-
for_each_available_child_of_node(con_np, child)
1414-
if (of_link_to_suppliers(dev, child) && !ret)
1415-
ret = -EAGAIN;
1416-
1417-
return ret;
1418-
}
1352+
if (!con_np)
1353+
return -EINVAL;
14191354

1420-
static int of_fwnode_add_links(const struct fwnode_handle *fwnode,
1421-
struct device *dev)
1422-
{
1423-
if (unlikely(!is_of_node(fwnode)))
1424-
return 0;
1355+
for_each_property_of_node(con_np, p)
1356+
of_link_property(con_np, p->name);
14251357

1426-
return of_link_to_suppliers(dev, to_of_node(fwnode));
1358+
return 0;
14271359
}
14281360

14291361
const struct fwnode_operations of_fwnode_ops = {

0 commit comments

Comments
 (0)