include/linux/reset.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
When a driver wants to get reset control and deassert it,this
helper will handle the return value of these function, also it
will register a devres so that when the device been detached, the
reset control will be assert.
Signed-off-by: Yuesong Li <liyuesong@vivo.com>
---
include/linux/reset.h | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 514ddf003efc..d7e02968b63b 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -806,6 +806,35 @@ devm_reset_control_get_shared_by_index(struct device *dev, int index)
return __devm_reset_control_get(dev, NULL, index, true, false, false);
}
+/**
+ * devm_reset_control_get_deassert - resource managed
+ * @dev: device to be reset by the controller
+ * @index: index of the reset controller
+ *
+ * A helper function to automatically handle return value of
+ * devm_reset_control_get_exclusive() and reset_control_deassert().
+ */
+static struct reset_control *devm_reset_control_get_deassert(
+ struct device *dev, const char *id)
+{
+ int ret;
+ struct reset_control *reset;
+
+ reset = devm_reset_control_get_exclusive(dev, id);
+ if (IS_ERR(reset))
+ return reset;
+
+ ret = reset_control_deassert(reset);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = devm_add_action_or_reset(dev, (void *)reset_control_assert, (void *)reset);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return reset;
+}
+
/*
* TEMPORARY calls to use during transition:
*
--
2.34.1
On 2024/8/30 11:33, Yuesong Li wrote:
> When a driver wants to get reset control and deassert it,this
> helper will handle the return value of these function, also it
> will register a devres so that when the device been detached, the
> reset control will be assert.
>
> Signed-off-by: Yuesong Li <liyuesong@vivo.com>
> ---
> include/linux/reset.h | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/include/linux/reset.h b/include/linux/reset.h
> index 514ddf003efc..d7e02968b63b 100644
> --- a/include/linux/reset.h
> +++ b/include/linux/reset.h
> @@ -806,6 +806,35 @@ devm_reset_control_get_shared_by_index(struct device *dev, int index)
> return __devm_reset_control_get(dev, NULL, index, true, false, false);
> }
>
> +/**
> + * devm_reset_control_get_deassert - resource managed
> + * @dev: device to be reset by the controller
> + * @index: index of the reset controller
> + *
> + * A helper function to automatically handle return value of
> + * devm_reset_control_get_exclusive() and reset_control_deassert().
> + */
> +static struct reset_control *devm_reset_control_get_deassert(
> + struct device *dev, const char *id)
> +{
> + int ret;
> + struct reset_control *reset;
> +
> + reset = devm_reset_control_get_exclusive(dev, id);
> + if (IS_ERR(reset))
> + return reset;
> +
> + ret = reset_control_deassert(reset);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + ret = devm_add_action_or_reset(dev, (void *)reset_control_assert, (void *)reset);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return reset;
> +}
> +
> /*
> * TEMPORARY calls to use during transition:
> *
Please ignore this patch, I did not use clang to check the compile
process. This patch is meant to simplify a common pattern appears in
more than 10 files. For example in
"drivers/thermal/sun8i_thermal.c" line 393-401
But to pass the complier test, we need to include other header which
does not make sense. So drop this patch.
On Mo, 2024-09-02 at 17:52 +0800, Yuesong Li wrote: > > On 2024/8/30 11:33, Yuesong Li wrote: > > When a driver wants to get reset control and deassert it,this > > helper will handle the return value of these function, also it > > will register a devres so that when the device been detached, the > > reset control will be assert. > > > > Signed-off-by: Yuesong Li <liyuesong@vivo.com> Could you have a look at the pre-deasserted / auto-reasserting reset control series [1] and see if that would fit your use case? [1] https://lore.kernel.org/all/20240621-reset-get-deasserted-v1-0-94ee76fb7b7d@pengutronix.de/ regards Philipp
On 2024/9/2 18:44, Philipp Zabel wrote: > On Mo, 2024-09-02 at 17:52 +0800, Yuesong Li wrote: >> >> On 2024/8/30 11:33, Yuesong Li wrote: >>> When a driver wants to get reset control and deassert it,this >>> helper will handle the return value of these function, also it >>> will register a devres so that when the device been detached, the >>> reset control will be assert. >>> >>> Signed-off-by: Yuesong Li <liyuesong@vivo.com> > > Could you have a look at the pre-deasserted / auto-reasserting reset > control series [1] and see if that would fit your use case? > > [1] https://lore.kernel.org/all/20240621-reset-get-deasserted-v1-0-94ee76fb7b7d@pengutronix.de/ > > regards > Philipp Thanks for reaching out, this patch fit my case exactly. Best regards, Yuesong
© 2016 - 2026 Red Hat, Inc.