[PATCH v4 4/8] reset: Add reset_control_get_from_provider_exclusive()
Geert Uytterhoeven
geert+renesas at glider.be
Fri Oct 16 08:55:43 PDT 2026
When stacking two reset controllers, the upper one should go through the
proper channels: request exclusive reset controls and use them via the
reset_control_*() APIs. However, unlike the clock subsystem, which has
of_clk_get_from_provider(), the reset subsystem does not offer a way to
lookup and obtain a reset from a reset provider.
Hence add a public helper reset_control_get_from_provider_exclusive()
to lookup and obtain an exclusive reference to a reset controller, based
on the recently introduced __reset_control_get_from_provider() helper.
This will be used by the R-Car X5H Module Controller driver.
Signed-off-by: Geert Uytterhoeven <geert+renesas at glider.be>
---
v4:
- Check for overflow when converting (u64) fwnode args to (uint32_t)
OF args,
- Document that reset_control_get_from_provider_exclusive() must not
be given a reference to a GPIO provider,
- Let the dummy return ERR_PTR(-ENOTSUPP) instead of NULL,
v3:
- Replace reset_controller_get_provider() by
reset_control_get_from_provider_exclusive(),
- Add kerneldoc,
v2:
- No changes.
---
drivers/reset/core.c | 41 ++++++++++++++++++++++++++++++++++++-----
include/linux/reset.h | 8 ++++++++
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 0e11f4c81c10d601..421bcc4c89cc21ac 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -1141,6 +1141,7 @@ __reset_control_get_from_provider(const struct fwnode_reference_args *args,
bool gpio_fallback,
enum reset_control_flags flags)
{
+ struct fwnode_handle *fwnode = consumer ?: args->fwnode;
struct reset_controller_dev *rcdev;
int rstc_id = -EINVAL;
@@ -1153,18 +1154,30 @@ __reset_control_get_from_provider(const struct fwnode_reference_args *args,
if (WARN_ON(args->nargs != rcdev->fwnode_reset_n_cells))
return ERR_PTR(-EINVAL);
- if (rcdev->of_xlate && is_of_node(consumer)) {
- struct device_node *np = to_of_node(consumer);
+ if (rcdev->of_xlate && is_of_node(fwnode)) {
+ struct device_node *np = to_of_node(fwnode);
struct of_phandle_args of_args;
int ret;
- ret = of_parse_phandle_with_args(np,
+ if (consumer) {
+ ret = of_parse_phandle_with_args(np,
gpio_fallback ? "reset-gpios" : "resets",
gpio_fallback ? "#gpio-cells" : "#reset-cells",
gpio_fallback ? 0 : index,
&of_args);
- if (ret)
- return ERR_PTR(ret);
+ if (ret)
+ return ERR_PTR(ret);
+ } else {
+ of_args.np = of_node_get(np);
+ of_args.args_count = args->nargs;
+
+ for (unsigned int i = 0; i < args->nargs; i++) {
+ if (args->args[i] > U32_MAX)
+ return ERR_PTR(-EINVAL);
+
+ of_args.args[i] = args->args[i];
+ }
+ }
rstc_id = rcdev->of_xlate(rcdev, &of_args);
of_node_put(of_args.np);
@@ -1254,6 +1267,24 @@ struct reset_control *__reset_control_get(struct device *dev, const char *id,
}
EXPORT_SYMBOL_GPL(__reset_control_get);
+/**
+ * reset_control_get_from_provider_exclusive - Lookup and obtain an exclusive
+ * reference to a reset controller.
+ * @args: Reference to the reset controller provider with all the args like
+ * reset number. This must not be a reference to a GPIO provider.
+ *
+ * Returns a struct reset_control or IS_ERR() condition containing errno.
+ * If this function is called more than once for the same reset control it will
+ * return -EBUSY.
+ */
+struct reset_control *
+reset_control_get_from_provider_exclusive(const struct fwnode_reference_args *args)
+{
+ return __reset_control_get_from_provider(args, NULL, 0, false,
+ RESET_CONTROL_EXCLUSIVE);
+}
+EXPORT_SYMBOL_GPL(reset_control_get_from_provider_exclusive);
+
int __reset_control_bulk_get(struct device *dev, int num_rstcs,
struct reset_control_bulk_data *rstcs,
enum reset_control_flags flags)
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 9c391cf0c82298a0..384273ec0c7cbef7 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -90,6 +90,8 @@ struct reset_control *__fwnode_reset_control_get(struct fwnode_handle *fwnode,
const char *id, int index, enum reset_control_flags flags);
struct reset_control *__reset_control_get(struct device *dev, const char *id,
int index, enum reset_control_flags flags);
+struct reset_control *reset_control_get_from_provider_exclusive(
+ const struct fwnode_reference_args *args);
void reset_control_put(struct reset_control *rstc);
int __reset_control_bulk_get(struct device *dev, int num_rstcs,
struct reset_control_bulk_data *rstcs,
@@ -173,6 +175,12 @@ static inline struct reset_control *__reset_control_get(
return optional ? NULL : ERR_PTR(-ENOTSUPP);
}
+static inline struct reset_control *reset_control_get_from_provider_exclusive(
+ const struct fwnode_reference_args *args)
+{
+ return ERR_PTR(-ENOTSUPP);
+}
+
static inline int
reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs)
{
--
2.43.0
More information about the linux-arm-kernel
mailing list