[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240830033351.233263-1-liyuesong@vivo.com>
Date: Fri, 30 Aug 2024 11:33:51 +0800
From: Yuesong Li <liyuesong@...o.com>
To: p.zabel@...gutronix.de
Cc: linux-kernel@...r.kernel.org,
opensource.kernel@...o.com,
Yuesong Li <liyuesong@...o.com>
Subject: [PATCH RFC] reset: Provide new devm_reset helpers for get and deassert reset control
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@...o.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
Powered by blists - more mailing lists