Skip to content

Commit ba8dbbb

Browse files
Bartosz GolaszewskipH5
authored andcommitted
reset: convert the core API to using firmware nodes
In order to simplify the commit converting the internals of reset core to using firmware nodes, first convert the user-facing API. Modify the signature of the core consumer functions but leave the specialized wrappers as is to avoid modifying users for now. No functional change intended. 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 9d52054 commit ba8dbbb

3 files changed

Lines changed: 46 additions & 31 deletions

File tree

Documentation/driver-api/reset.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ query the reset line status using reset_control_status().
198198
reset_control_rearm
199199
reset_control_put
200200
of_reset_control_get_count
201-
of_reset_control_array_get
202201
devm_reset_control_array_get
203202
reset_control_get_count
204203

drivers/reset/core.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
10611061
rgpio_dev->of_args = *args;
10621062
/*
10631063
* We keep the device_node reference, but of_args.np is put at the end
1064-
* of __of_reset_control_get(), so get it one more time.
1064+
* of __fwnode_reset_control_get(), so get it one more time.
10651065
* Hold reference as long as rgpio_dev memory is valid.
10661066
*/
10671067
of_node_get(rgpio_dev->of_args.np);
@@ -1115,18 +1115,19 @@ static struct reset_controller_dev *__reset_find_rcdev(const struct of_phandle_a
11151115
}
11161116

11171117
struct reset_control *
1118-
__of_reset_control_get(struct device_node *node, const char *id, int index,
1119-
enum reset_control_flags flags)
1118+
__fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int index,
1119+
enum reset_control_flags flags)
11201120
{
11211121
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
11221122
bool gpio_fallback = false;
1123+
struct device_node *node = to_of_node(fwnode);
11231124
struct reset_control *rstc = ERR_PTR(-EINVAL);
11241125
struct reset_controller_dev *rcdev;
11251126
struct of_phandle_args args;
11261127
int rstc_id;
11271128
int ret;
11281129

1129-
if (!node)
1130+
if (!fwnode)
11301131
return ERR_PTR(-EINVAL);
11311132

11321133
if (id) {
@@ -1193,20 +1194,21 @@ __of_reset_control_get(struct device_node *node, const char *id, int index,
11931194

11941195
return rstc;
11951196
}
1196-
EXPORT_SYMBOL_GPL(__of_reset_control_get);
1197+
EXPORT_SYMBOL_GPL(__fwnode_reset_control_get);
11971198

11981199
struct reset_control *__reset_control_get(struct device *dev, const char *id,
11991200
int index, enum reset_control_flags flags)
12001201
{
12011202
bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED;
12021203
bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED;
12031204
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
1205+
struct fwnode_handle *fwnode = dev_fwnode(dev);
12041206

12051207
if (WARN_ON(shared && acquired))
12061208
return ERR_PTR(-EINVAL);
12071209

1208-
if (dev->of_node)
1209-
return __of_reset_control_get(dev->of_node, id, index, flags);
1210+
if (fwnode)
1211+
return __fwnode_reset_control_get(fwnode, id, index, flags);
12101212

12111213
return optional ? NULL : ERR_PTR(-ENOENT);
12121214
}
@@ -1468,23 +1470,24 @@ static int fwnode_reset_control_get_count(struct fwnode_handle *fwnode)
14681470
}
14691471

14701472
/**
1471-
* of_reset_control_array_get - Get a list of reset controls using
1472-
* device node.
1473+
* fwnode_reset_control_array_get - Get a list of reset controls using
1474+
* a firmware node.
14731475
*
1474-
* @np: device node for the device that requests the reset controls array
1476+
* @fwnode: firmware node for the device that requests the reset controls array
14751477
* @flags: whether reset controls are shared, optional, acquired
14761478
*
14771479
* Returns pointer to allocated reset_control on success or error on failure
14781480
*/
14791481
struct reset_control *
1480-
of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
1482+
fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
1483+
enum reset_control_flags flags)
14811484
{
14821485
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
14831486
struct reset_control_array *resets;
14841487
struct reset_control *rstc;
14851488
int num, i;
14861489

1487-
num = fwnode_reset_control_get_count(of_fwnode_handle(np));
1490+
num = fwnode_reset_control_get_count(fwnode);
14881491
if (num < 0)
14891492
return optional ? NULL : ERR_PTR(num);
14901493

@@ -1494,7 +1497,7 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag
14941497
resets->num_rstcs = num;
14951498

14961499
for (i = 0; i < num; i++) {
1497-
rstc = __of_reset_control_get(np, NULL, i, flags);
1500+
rstc = __fwnode_reset_control_get(fwnode, NULL, i, flags);
14981501
if (IS_ERR(rstc))
14991502
goto err_rst;
15001503
resets->rstc[i] = rstc;
@@ -1511,7 +1514,7 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag
15111514

15121515
return rstc;
15131516
}
1514-
EXPORT_SYMBOL_GPL(of_reset_control_array_get);
1517+
EXPORT_SYMBOL_GPL(fwnode_reset_control_array_get);
15151518

15161519
/**
15171520
* devm_reset_control_array_get - Resource managed reset control array get
@@ -1535,7 +1538,7 @@ devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags)
15351538
if (!ptr)
15361539
return ERR_PTR(-ENOMEM);
15371540

1538-
rstc = of_reset_control_array_get(dev->of_node, flags);
1541+
rstc = fwnode_reset_control_array_get(dev_fwnode(dev), flags);
15391542
if (IS_ERR_OR_NULL(rstc)) {
15401543
devres_free(ptr);
15411544
return rstc;

include/linux/reset.h

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include <linux/bits.h>
66
#include <linux/err.h>
77
#include <linux/errno.h>
8+
#include <linux/of.h>
89
#include <linux/types.h>
910

1011
struct device;
1112
struct device_node;
13+
struct fwnode_handle;
1214
struct reset_control;
1315

1416
/**
@@ -84,7 +86,7 @@ int reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *r
8486
int reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs);
8587
void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs);
8688

87-
struct reset_control *__of_reset_control_get(struct device_node *node,
89+
struct reset_control *__fwnode_reset_control_get(struct fwnode_handle *fwnode,
8890
const char *id, int index, enum reset_control_flags flags);
8991
struct reset_control *__reset_control_get(struct device *dev, const char *id,
9092
int index, enum reset_control_flags flags);
@@ -103,7 +105,8 @@ int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
103105

104106
struct reset_control *devm_reset_control_array_get(struct device *dev,
105107
enum reset_control_flags flags);
106-
struct reset_control *of_reset_control_array_get(struct device_node *np, enum reset_control_flags);
108+
struct reset_control *fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
109+
enum reset_control_flags);
107110

108111
int reset_control_get_count(struct device *dev);
109112

@@ -152,8 +155,8 @@ static inline int __device_reset(struct device *dev, bool optional)
152155
return optional ? 0 : -ENOTSUPP;
153156
}
154157

155-
static inline struct reset_control *__of_reset_control_get(
156-
struct device_node *node,
158+
static inline struct reset_control *__fwnode_reset_control_get(
159+
struct fwnode_handle *fwnode,
157160
const char *id, int index, enum reset_control_flags flags)
158161
{
159162
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
@@ -242,7 +245,7 @@ devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags)
242245
}
243246

244247
static inline struct reset_control *
245-
of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
248+
fwnode_reset_control_array_get(struct fwnode_handle *fwnode, enum reset_control_flags flags)
246249
{
247250
bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
248251

@@ -500,7 +503,8 @@ reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
500503
static inline struct reset_control *of_reset_control_get_exclusive(
501504
struct device_node *node, const char *id)
502505
{
503-
return __of_reset_control_get(node, id, 0, RESET_CONTROL_EXCLUSIVE);
506+
return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
507+
RESET_CONTROL_EXCLUSIVE);
504508
}
505509

506510
/**
@@ -520,7 +524,8 @@ static inline struct reset_control *of_reset_control_get_exclusive(
520524
static inline struct reset_control *of_reset_control_get_optional_exclusive(
521525
struct device_node *node, const char *id)
522526
{
523-
return __of_reset_control_get(node, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
527+
return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
528+
RESET_CONTROL_OPTIONAL_EXCLUSIVE);
524529
}
525530

526531
/**
@@ -545,7 +550,8 @@ static inline struct reset_control *of_reset_control_get_optional_exclusive(
545550
static inline struct reset_control *of_reset_control_get_shared(
546551
struct device_node *node, const char *id)
547552
{
548-
return __of_reset_control_get(node, id, 0, RESET_CONTROL_SHARED);
553+
return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
554+
RESET_CONTROL_SHARED);
549555
}
550556

551557
/**
@@ -562,7 +568,8 @@ static inline struct reset_control *of_reset_control_get_shared(
562568
static inline struct reset_control *of_reset_control_get_exclusive_by_index(
563569
struct device_node *node, int index)
564570
{
565-
return __of_reset_control_get(node, NULL, index, RESET_CONTROL_EXCLUSIVE);
571+
return __fwnode_reset_control_get(of_fwnode_handle(node), NULL, index,
572+
RESET_CONTROL_EXCLUSIVE);
566573
}
567574

568575
/**
@@ -590,7 +597,8 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(
590597
static inline struct reset_control *of_reset_control_get_shared_by_index(
591598
struct device_node *node, int index)
592599
{
593-
return __of_reset_control_get(node, NULL, index, RESET_CONTROL_SHARED);
600+
return __fwnode_reset_control_get(of_fwnode_handle(node), NULL, index,
601+
RESET_CONTROL_SHARED);
594602
}
595603

596604
/**
@@ -1032,30 +1040,35 @@ devm_reset_control_array_get_optional_shared(struct device *dev)
10321040
static inline struct reset_control *
10331041
of_reset_control_array_get_exclusive(struct device_node *node)
10341042
{
1035-
return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE);
1043+
return fwnode_reset_control_array_get(of_fwnode_handle(node),
1044+
RESET_CONTROL_EXCLUSIVE);
10361045
}
10371046

10381047
static inline struct reset_control *
10391048
of_reset_control_array_get_exclusive_released(struct device_node *node)
10401049
{
1041-
return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE_RELEASED);
1050+
return fwnode_reset_control_array_get(of_fwnode_handle(node),
1051+
RESET_CONTROL_EXCLUSIVE_RELEASED);
10421052
}
10431053

10441054
static inline struct reset_control *
10451055
of_reset_control_array_get_shared(struct device_node *node)
10461056
{
1047-
return of_reset_control_array_get(node, RESET_CONTROL_SHARED);
1057+
return fwnode_reset_control_array_get(of_fwnode_handle(node),
1058+
RESET_CONTROL_SHARED);
10481059
}
10491060

10501061
static inline struct reset_control *
10511062
of_reset_control_array_get_optional_exclusive(struct device_node *node)
10521063
{
1053-
return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
1064+
return fwnode_reset_control_array_get(of_fwnode_handle(node),
1065+
RESET_CONTROL_OPTIONAL_EXCLUSIVE);
10541066
}
10551067

10561068
static inline struct reset_control *
10571069
of_reset_control_array_get_optional_shared(struct device_node *node)
10581070
{
1059-
return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_SHARED);
1071+
return fwnode_reset_control_array_get(of_fwnode_handle(node),
1072+
RESET_CONTROL_OPTIONAL_SHARED);
10601073
}
10611074
#endif

0 commit comments

Comments
 (0)