All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] reset: Provide new devm_reset helpers for get and deassert reset control
@ 2024-08-30  3:33 Yuesong Li
  2024-09-02  8:00 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Yuesong Li @ 2024-08-30  3:33 UTC (permalink / raw)
  To: p.zabel; +Cc: linux-kernel, opensource.kernel, Yuesong Li

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-09-03  3:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30  3:33 [PATCH RFC] reset: Provide new devm_reset helpers for get and deassert reset control Yuesong Li
2024-09-02  8:00 ` kernel test robot
2024-09-02  8:20 ` kernel test robot
2024-09-02  9:22 ` kernel test robot
2024-09-02  9:52 ` Yuesong Li
2024-09-02 10:44   ` Philipp Zabel
2024-09-03  3:17     ` Yuesong Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.