Skip to content

Commit 9d52054

Browse files
Bartosz GolaszewskipH5
authored andcommitted
reset: convert of_reset_control_get_count() to using firmware nodes
Start the conversion of reset core to using firmware nodes by reworking of_reset_control_get_count(). Unfortunately there is no fwnode-based alternative to of_count_phandle_with_args() so we have to hand-code it. Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
1 parent 8c91302 commit 9d52054

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

drivers/reset/core.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/device.h>
1313
#include <linux/err.h>
1414
#include <linux/export.h>
15+
#include <linux/fwnode.h>
1516
#include <linux/gpio/driver.h>
1617
#include <linux/gpio/machine.h>
1718
#include <linux/gpio/property.h>
@@ -20,6 +21,7 @@
2021
#include <linux/kref.h>
2122
#include <linux/module.h>
2223
#include <linux/of.h>
24+
#include <linux/property.h>
2325
#include <linux/reset.h>
2426
#include <linux/reset-controller.h>
2527
#include <linux/slab.h>
@@ -1430,21 +1432,35 @@ EXPORT_SYMBOL_GPL(__device_reset);
14301432
*/
14311433

14321434
/**
1433-
* of_reset_control_get_count - Count number of resets available with a device
1435+
* fwnode_reset_control_get_count - Count number of resets available with a device
14341436
*
1435-
* @node: device node that contains 'resets'.
1437+
* @fwnode: firmware node that contains 'resets'.
14361438
*
14371439
* Returns positive reset count on success, or error number on failure and
14381440
* on count being zero.
14391441
*/
1440-
static int of_reset_control_get_count(struct device_node *node)
1442+
static int fwnode_reset_control_get_count(struct fwnode_handle *fwnode)
14411443
{
1442-
int count;
1444+
struct fwnode_reference_args args;
1445+
int count = 0, ret;
14431446

1444-
if (!node)
1447+
if (!fwnode)
14451448
return -EINVAL;
14461449

1447-
count = of_count_phandle_with_args(node, "resets", "#reset-cells");
1450+
for (;;) {
1451+
ret = fwnode_property_get_reference_args(fwnode, "resets", "#reset-cells",
1452+
0, count, &args);
1453+
if (ret) {
1454+
if (ret == -ENOENT)
1455+
break;
1456+
1457+
return ret;
1458+
}
1459+
1460+
fwnode_handle_put(args.fwnode);
1461+
count++;
1462+
}
1463+
14481464
if (count == 0)
14491465
count = -ENOENT;
14501466

@@ -1468,7 +1484,7 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag
14681484
struct reset_control *rstc;
14691485
int num, i;
14701486

1471-
num = of_reset_control_get_count(np);
1487+
num = fwnode_reset_control_get_count(of_fwnode_handle(np));
14721488
if (num < 0)
14731489
return optional ? NULL : ERR_PTR(num);
14741490

@@ -1542,8 +1558,10 @@ EXPORT_SYMBOL_GPL(devm_reset_control_array_get);
15421558
*/
15431559
int reset_control_get_count(struct device *dev)
15441560
{
1545-
if (dev->of_node)
1546-
return of_reset_control_get_count(dev->of_node);
1561+
struct fwnode_handle *fwnode = dev_fwnode(dev);
1562+
1563+
if (fwnode)
1564+
return fwnode_reset_control_get_count(fwnode);
15471565

15481566
return -ENOENT;
15491567
}

0 commit comments

Comments
 (0)