]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
reset: convert the core API to using firmware nodes
authorBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Fri, 6 Mar 2026 17:22:56 +0000 (18:22 +0100)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 9 Mar 2026 09:20:04 +0000 (10:20 +0100)
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>
Documentation/driver-api/reset.rst
drivers/reset/core.c
include/linux/reset.h

index f773100daaa415ac2c74b7b0db7a4f6f05d736d8..7a6571849664f08758a975fca3e078cd45967c8d 100644 (file)
@@ -198,7 +198,6 @@ query the reset line status using reset_control_status().
                reset_control_rearm
                reset_control_put
                of_reset_control_get_count
-               of_reset_control_array_get
                devm_reset_control_array_get
                reset_control_get_count
 
index f1b644a86ad081155e1026745812d6b5f3f9282d..0da5079ea9dbbf835d9fc7c44ce98d2c8be42552 100644 (file)
@@ -1061,7 +1061,7 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
        rgpio_dev->of_args = *args;
        /*
         * We keep the device_node reference, but of_args.np is put at the end
-        * of __of_reset_control_get(), so get it one more time.
+        * of __fwnode_reset_control_get(), so get it one more time.
         * Hold reference as long as rgpio_dev memory is valid.
         */
        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
 }
 
 struct reset_control *
-__of_reset_control_get(struct device_node *node, const char *id, int index,
-                      enum reset_control_flags flags)
+__fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int index,
+                          enum reset_control_flags flags)
 {
        bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
        bool gpio_fallback = false;
+       struct device_node *node = to_of_node(fwnode);
        struct reset_control *rstc = ERR_PTR(-EINVAL);
        struct reset_controller_dev *rcdev;
        struct of_phandle_args args;
        int rstc_id;
        int ret;
 
-       if (!node)
+       if (!fwnode)
                return ERR_PTR(-EINVAL);
 
        if (id) {
@@ -1193,7 +1194,7 @@ out_put:
 
        return rstc;
 }
-EXPORT_SYMBOL_GPL(__of_reset_control_get);
+EXPORT_SYMBOL_GPL(__fwnode_reset_control_get);
 
 struct reset_control *__reset_control_get(struct device *dev, const char *id,
                                          int index, enum reset_control_flags flags)
@@ -1201,12 +1202,13 @@ struct reset_control *__reset_control_get(struct device *dev, const char *id,
        bool shared = flags & RESET_CONTROL_FLAGS_BIT_SHARED;
        bool acquired = flags & RESET_CONTROL_FLAGS_BIT_ACQUIRED;
        bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
+       struct fwnode_handle *fwnode = dev_fwnode(dev);
 
        if (WARN_ON(shared && acquired))
                return ERR_PTR(-EINVAL);
 
-       if (dev->of_node)
-               return __of_reset_control_get(dev->of_node, id, index, flags);
+       if (fwnode)
+               return __fwnode_reset_control_get(fwnode, id, index, flags);
 
        return optional ? NULL : ERR_PTR(-ENOENT);
 }
@@ -1468,23 +1470,24 @@ static int fwnode_reset_control_get_count(struct fwnode_handle *fwnode)
 }
 
 /**
- * of_reset_control_array_get - Get a list of reset controls using
- *                             device node.
+ * fwnode_reset_control_array_get - Get a list of reset controls using
+ *                                  a firmware node.
  *
- * @np: device node for the device that requests the reset controls array
+ * @fwnode: firmware node for the device that requests the reset controls array
  * @flags: whether reset controls are shared, optional, acquired
  *
  * Returns pointer to allocated reset_control on success or error on failure
  */
 struct reset_control *
-of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
+fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
+                              enum reset_control_flags flags)
 {
        bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
        struct reset_control_array *resets;
        struct reset_control *rstc;
        int num, i;
 
-       num = fwnode_reset_control_get_count(of_fwnode_handle(np));
+       num = fwnode_reset_control_get_count(fwnode);
        if (num < 0)
                return optional ? NULL : ERR_PTR(num);
 
@@ -1494,7 +1497,7 @@ of_reset_control_array_get(struct device_node *np, enum reset_control_flags flag
        resets->num_rstcs = num;
 
        for (i = 0; i < num; i++) {
-               rstc = __of_reset_control_get(np, NULL, i, flags);
+               rstc = __fwnode_reset_control_get(fwnode, NULL, i, flags);
                if (IS_ERR(rstc))
                        goto err_rst;
                resets->rstc[i] = rstc;
@@ -1511,7 +1514,7 @@ err_rst:
 
        return rstc;
 }
-EXPORT_SYMBOL_GPL(of_reset_control_array_get);
+EXPORT_SYMBOL_GPL(fwnode_reset_control_array_get);
 
 /**
  * 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)
        if (!ptr)
                return ERR_PTR(-ENOMEM);
 
-       rstc = of_reset_control_array_get(dev->of_node, flags);
+       rstc = fwnode_reset_control_array_get(dev_fwnode(dev), flags);
        if (IS_ERR_OR_NULL(rstc)) {
                devres_free(ptr);
                return rstc;
index 44f9e3415f92c9d7591b898cdb4bf7f05f2b0568..9c391cf0c82298a06a4d84eebd293864ef8c48da 100644 (file)
@@ -5,10 +5,12 @@
 #include <linux/bits.h>
 #include <linux/err.h>
 #include <linux/errno.h>
+#include <linux/of.h>
 #include <linux/types.h>
 
 struct device;
 struct device_node;
+struct fwnode_handle;
 struct reset_control;
 
 /**
@@ -84,7 +86,7 @@ int reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *r
 int reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs);
 void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs);
 
-struct reset_control *__of_reset_control_get(struct device_node *node,
+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);
@@ -103,7 +105,8 @@ int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
 
 struct reset_control *devm_reset_control_array_get(struct device *dev,
                                                   enum reset_control_flags flags);
-struct reset_control *of_reset_control_array_get(struct device_node *np, enum reset_control_flags);
+struct reset_control *fwnode_reset_control_array_get(struct fwnode_handle *fwnode,
+                                                    enum reset_control_flags);
 
 int reset_control_get_count(struct device *dev);
 
@@ -152,8 +155,8 @@ static inline int __device_reset(struct device *dev, bool optional)
        return optional ? 0 : -ENOTSUPP;
 }
 
-static inline struct reset_control *__of_reset_control_get(
-                                       struct device_node *node,
+static inline struct reset_control *__fwnode_reset_control_get(
+                                       struct fwnode_handle *fwnode,
                                        const char *id, int index, enum reset_control_flags flags)
 {
        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)
 }
 
 static inline struct reset_control *
-of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
+fwnode_reset_control_array_get(struct fwnode_handle *fwnode, enum reset_control_flags flags)
 {
        bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
 
@@ -500,7 +503,8 @@ reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
 static inline struct reset_control *of_reset_control_get_exclusive(
                                struct device_node *node, const char *id)
 {
-       return __of_reset_control_get(node, id, 0, RESET_CONTROL_EXCLUSIVE);
+       return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
+                                         RESET_CONTROL_EXCLUSIVE);
 }
 
 /**
@@ -520,7 +524,8 @@ static inline struct reset_control *of_reset_control_get_exclusive(
 static inline struct reset_control *of_reset_control_get_optional_exclusive(
                                struct device_node *node, const char *id)
 {
-       return __of_reset_control_get(node, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
+       return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
+                                         RESET_CONTROL_OPTIONAL_EXCLUSIVE);
 }
 
 /**
@@ -545,7 +550,8 @@ static inline struct reset_control *of_reset_control_get_optional_exclusive(
 static inline struct reset_control *of_reset_control_get_shared(
                                struct device_node *node, const char *id)
 {
-       return __of_reset_control_get(node, id, 0, RESET_CONTROL_SHARED);
+       return __fwnode_reset_control_get(of_fwnode_handle(node), id, 0,
+                                         RESET_CONTROL_SHARED);
 }
 
 /**
@@ -562,7 +568,8 @@ static inline struct reset_control *of_reset_control_get_shared(
 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
                                        struct device_node *node, int index)
 {
-       return __of_reset_control_get(node, NULL, index, RESET_CONTROL_EXCLUSIVE);
+       return __fwnode_reset_control_get(of_fwnode_handle(node), NULL, index,
+                                         RESET_CONTROL_EXCLUSIVE);
 }
 
 /**
@@ -590,7 +597,8 @@ static inline struct reset_control *of_reset_control_get_exclusive_by_index(
 static inline struct reset_control *of_reset_control_get_shared_by_index(
                                        struct device_node *node, int index)
 {
-       return __of_reset_control_get(node, NULL, index, RESET_CONTROL_SHARED);
+       return __fwnode_reset_control_get(of_fwnode_handle(node), NULL, index,
+                                         RESET_CONTROL_SHARED);
 }
 
 /**
@@ -1032,30 +1040,35 @@ devm_reset_control_array_get_optional_shared(struct device *dev)
 static inline struct reset_control *
 of_reset_control_array_get_exclusive(struct device_node *node)
 {
-       return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE);
+       return fwnode_reset_control_array_get(of_fwnode_handle(node),
+                                             RESET_CONTROL_EXCLUSIVE);
 }
 
 static inline struct reset_control *
 of_reset_control_array_get_exclusive_released(struct device_node *node)
 {
-       return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE_RELEASED);
+       return fwnode_reset_control_array_get(of_fwnode_handle(node),
+                                             RESET_CONTROL_EXCLUSIVE_RELEASED);
 }
 
 static inline struct reset_control *
 of_reset_control_array_get_shared(struct device_node *node)
 {
-       return of_reset_control_array_get(node, RESET_CONTROL_SHARED);
+       return fwnode_reset_control_array_get(of_fwnode_handle(node),
+                                             RESET_CONTROL_SHARED);
 }
 
 static inline struct reset_control *
 of_reset_control_array_get_optional_exclusive(struct device_node *node)
 {
-       return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
+       return fwnode_reset_control_array_get(of_fwnode_handle(node),
+                                             RESET_CONTROL_OPTIONAL_EXCLUSIVE);
 }
 
 static inline struct reset_control *
 of_reset_control_array_get_optional_shared(struct device_node *node)
 {
-       return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_SHARED);
+       return fwnode_reset_control_array_get(of_fwnode_handle(node),
+                                             RESET_CONTROL_OPTIONAL_SHARED);
 }
 #endif