* [PATCH 1/2] reset: add __reset_control_get()
2024-10-25 8:58 [PATCH 0/2] reset: implement reset_control_bulk_get() Sascha Hauer
@ 2024-10-25 8:58 ` Sascha Hauer
2024-10-25 8:58 ` [PATCH 2/2] reset: implement reset_control_bulk_get() Sascha Hauer
2024-10-28 12:12 ` [PATCH 0/2] " Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-10-25 8:58 UTC (permalink / raw)
To: open list:BAREBOX
reset_control_get_optional() is implemented as a static inline function
which calls reset_control_get() first and then handles the _optional
part.
Change this to implement a __reset_control_get() taking a bool optional
argument. This is done as a preparation to implement
__reset_control_bulk_get() in the next step which can reuse
__reset_control_get().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/reset/core.c | 11 ++++++++---
include/linux/reset.h | 13 +++++++++----
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 94bfad2067..679deee3c1 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -359,7 +359,7 @@ gpio_reset_control_get(struct device *dev, const char *id)
*
* Use of id names is optional.
*/
-struct reset_control *reset_control_get(struct device *dev, const char *id)
+struct reset_control *__reset_control_get(struct device *dev, const char *id, bool optional)
{
struct reset_control *rstc;
@@ -368,7 +368,7 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
rstc = of_reset_control_get(dev->of_node, id);
if (IS_ERR(rstc))
- return ERR_CAST(rstc);
+ goto err;
/*
* If there is no dedicated reset controller device, check if we have
@@ -377,7 +377,7 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
if (!rstc) {
rstc = gpio_reset_control_get(dev, id);
if (IS_ERR(rstc))
- return ERR_CAST(rstc);
+ goto err;
}
if (!rstc)
@@ -386,6 +386,11 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
rstc->dev = dev;
return rstc;
+err:
+ if (optional && rstc == ERR_PTR(-ENOENT))
+ return NULL;
+
+ return ERR_CAST(rstc);
}
EXPORT_SYMBOL_GPL(reset_control_get);
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 7db3d3162a..183d7d55a0 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -13,7 +13,7 @@ int reset_control_reset(struct reset_control *rstc);
int reset_control_assert(struct reset_control *rstc);
int reset_control_deassert(struct reset_control *rstc);
-struct reset_control *reset_control_get(struct device *dev, const char *id);
+struct reset_control *__reset_control_get(struct device *dev, const char *id, bool optional);
struct reset_control *of_reset_control_get(struct device_node *node,
const char *id);
void reset_control_put(struct reset_control *rstc);
@@ -57,7 +57,7 @@ of_reset_control_get(struct device_node *node, const char *id)
}
static inline struct reset_control *
-reset_control_get(struct device *dev, const char *id)
+__reset_control_get(struct device *dev, const char *id, bool optional)
{
return NULL;
}
@@ -96,8 +96,13 @@ static inline struct reset_control *reset_control_array_get(struct device *dev)
static inline struct reset_control *reset_control_get_optional(struct device *dev,
const char *id)
{
- struct reset_control *rstc = reset_control_get(dev, id);
- return rstc == ERR_PTR(-ENOENT) ? NULL : rstc;
+ return __reset_control_get(dev, id, true);
+}
+
+static inline struct reset_control *reset_control_get(struct device *dev,
+ const char *id)
+{
+ return __reset_control_get(dev, id, false);
}
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] reset: implement reset_control_bulk_get()
2024-10-25 8:58 [PATCH 0/2] reset: implement reset_control_bulk_get() Sascha Hauer
2024-10-25 8:58 ` [PATCH 1/2] reset: add __reset_control_get() Sascha Hauer
@ 2024-10-25 8:58 ` Sascha Hauer
2024-10-28 12:12 ` [PATCH 0/2] " Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-10-25 8:58 UTC (permalink / raw)
To: open list:BAREBOX
This implements reset_control_bulk_get() to get multiple reset
controllers at once.
This somewhat overlaps with reset_control_array_get(). The difference is
that reset_control_array_get() returns a single reset controller which
internally handles the array of reset controllers whereas
reset_control_bulk_get() allows the consumer to control each reset
controller individually.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/reset/core.c | 24 ++++++++++++++++++++++++
include/linux/reset.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 679deee3c1..2431a9374a 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -484,6 +484,30 @@ struct reset_control *reset_control_array_get(struct device *dev)
return rstc;
}
+int __reset_control_bulk_get(struct device *dev, int num_rstcs,
+ struct reset_control_bulk_data *rstcs,
+ bool optional)
+{
+ int ret, i;
+
+ for (i = 0; i < num_rstcs; i++) {
+ rstcs[i].rstc = __reset_control_get(dev, rstcs[i].id, optional);
+ if (IS_ERR(rstcs[i].rstc)) {
+ ret = PTR_ERR(rstcs[i].rstc);
+ goto err;
+ }
+ }
+
+ return 0;
+
+err:
+ while (i--)
+ reset_control_put(rstcs[i].rstc);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(__reset_control_bulk_get);
+
int device_reset_all(struct device *dev)
{
struct reset_control *rstc;
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 183d7d55a0..9469825faf 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -6,6 +6,21 @@
struct device;
struct reset_control;
+/**
+ * struct reset_control_bulk_data - Data used for bulk reset control operations.
+ *
+ * @id: reset control consumer ID
+ * @rstc: struct reset_control * to store the associated reset control
+ *
+ * The reset APIs provide a series of reset_control_bulk_*() API calls as
+ * a convenience to consumers which require multiple reset controls.
+ * This structure is used to manage data for these calls.
+ */
+struct reset_control_bulk_data {
+ const char *id;
+ struct reset_control *rstc;
+};
+
#ifdef CONFIG_RESET_CONTROLLER
int reset_control_status(struct reset_control *rstc);
@@ -28,6 +43,10 @@ int reset_control_get_count(struct device *dev);
struct reset_control *reset_control_array_get(struct device *dev);
+int __reset_control_bulk_get(struct device *dev, int num_rstcs,
+ struct reset_control_bulk_data *rstcs,
+ bool optional);
+
#else
static inline int reset_control_status(struct reset_control *rstc)
@@ -91,6 +110,14 @@ static inline struct reset_control *reset_control_array_get(struct device *dev)
return NULL;
}
+static inline int
+__reset_control_bulk_get(struct device *dev, int num_rstcs,
+ struct reset_control_bulk_data *rstcs,
+ bool optional)
+{
+ return optional ? 0 : -EOPNOTSUPP;
+}
+
#endif /* CONFIG_RESET_CONTROLLER */
static inline struct reset_control *reset_control_get_optional(struct device *dev,
@@ -105,4 +132,21 @@ static inline struct reset_control *reset_control_get(struct device *dev,
return __reset_control_get(dev, id, false);
}
+/**
+ * reset_control_bulk_get - Lookup and obtain references to
+ * multiple reset controllers.
+ * @dev: device to be reset by the controller
+ * @num_rstcs: number of entries in rstcs array
+ * @rstcs: array of struct reset_control_bulk_data with reset line names set
+ *
+ * Fills the rstcs array with pointers to reset controls and
+ * returns 0, or an IS_ERR() condition containing errno.
+ */
+static inline int __must_check
+reset_control_bulk_get(struct device *dev, int num_rstcs,
+ struct reset_control_bulk_data *rstcs)
+{
+ return __reset_control_bulk_get(dev, num_rstcs, rstcs, false);
+}
+
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] reset: implement reset_control_bulk_get()
2024-10-25 8:58 [PATCH 0/2] reset: implement reset_control_bulk_get() Sascha Hauer
2024-10-25 8:58 ` [PATCH 1/2] reset: add __reset_control_get() Sascha Hauer
2024-10-25 8:58 ` [PATCH 2/2] reset: implement reset_control_bulk_get() Sascha Hauer
@ 2024-10-28 12:12 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2024-10-28 12:12 UTC (permalink / raw)
To: open list:BAREBOX, Sascha Hauer
On Fri, 25 Oct 2024 10:58:01 +0200, Sascha Hauer wrote:
> reset_control_bulk_get() is useful for drivers which need multiple reset
> controllers and has to control each of them individually.
>
>
Applied, thanks!
[1/2] reset: add __reset_control_get()
https://git.pengutronix.de/cgit/barebox/commit/?id=48ff114d8ae2 (link may not be stable)
[2/2] reset: implement reset_control_bulk_get()
https://git.pengutronix.de/cgit/barebox/commit/?id=c31057ebe929 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 4+ messages in thread