Skip to content

Commit 2a6cb2b

Browse files
geertupH5
authored andcommitted
reset: Add reset_control_get_count()
Currently the reset core has internal support for counting the number of resets for a device described in DT. Generalize this to devices using lookup resets, and export it for public use. This will be used by generic drivers that need to be sure a device is controlled by a single, dedicated reset line (e.g. vfio-platform). Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
1 parent 9449f7a commit 2a6cb2b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

drivers/reset/core.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,3 +795,44 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
795795
return rstc;
796796
}
797797
EXPORT_SYMBOL_GPL(devm_reset_control_array_get);
798+
799+
static int reset_control_get_count_from_lookup(struct device *dev)
800+
{
801+
const struct reset_control_lookup *lookup;
802+
const char *dev_id = dev_name(dev);
803+
int count = 0;
804+
805+
if (!dev)
806+
return -EINVAL;
807+
808+
mutex_lock(&reset_lookup_mutex);
809+
810+
list_for_each_entry(lookup, &reset_lookup_list, list) {
811+
if (!strcmp(lookup->dev_id, dev_id))
812+
count++;
813+
}
814+
815+
mutex_unlock(&reset_lookup_mutex);
816+
817+
if (count == 0)
818+
count = -ENOENT;
819+
820+
return count;
821+
}
822+
823+
/**
824+
* of_reset_control_get_count - Count number of resets available with a device
825+
*
826+
* @dev: device for which to return the number of resets
827+
*
828+
* Returns positive reset count on success, or error number on failure and
829+
* on count being zero.
830+
*/
831+
int reset_control_get_count(struct device *dev)
832+
{
833+
if (dev->of_node)
834+
return of_reset_control_get_count(dev->of_node);
835+
836+
return reset_control_get_count_from_lookup(dev);
837+
}
838+
EXPORT_SYMBOL_GPL(reset_control_get_count);

include/linux/reset.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct reset_control *devm_reset_control_array_get(struct device *dev,
3232
struct reset_control *of_reset_control_array_get(struct device_node *np,
3333
bool shared, bool optional);
3434

35+
int reset_control_get_count(struct device *dev);
36+
3537
#else
3638

3739
static inline int reset_control_reset(struct reset_control *rstc)
@@ -97,6 +99,11 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
9799
return optional ? NULL : ERR_PTR(-ENOTSUPP);
98100
}
99101

102+
static inline int reset_control_get_count(struct device *dev)
103+
{
104+
return -ENOENT;
105+
}
106+
100107
#endif /* CONFIG_RESET_CONTROLLER */
101108

102109
static inline int __must_check device_reset(struct device *dev)

0 commit comments

Comments
 (0)