diff mbox

[U-Boot,v9,02/10] reset: add reset_release_all()

Message ID 1498048966-32626-3-git-send-email-patrice.chotard@st.com
State Superseded
Delegated to: Marek Vasut
Headers show

Commit Message

Patrice CHOTARD June 21, 2017, 12:42 p.m. UTC
From: Patrice Chotard <patrice.chotard@st.com>

Add reset_release_all() method which Assert/Free an
array of resets signal that has been previously successfully
requested by reset_get_by_*()

Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
v9:	_ to avoid confusion, rename reset_assert_all() in reset_release_all() 
	  as this function not only assert all resets but also free all of them
	_ add a check in reset_release_all() to verify if a reset has been previously 
	  requested before asserting and freeing it.
v8:	_ none
v7:	_ none
v6:	_ none
v5:	_ none
v4:	_ add reset_assert_all() method as suggested by Marek Vasut
	  and Simon Glass

 drivers/reset/reset-uclass.c | 25 +++++++++++++++++++++++++
 include/reset.h              | 18 ++++++++++++++++++
 2 files changed, 43 insertions(+)

Comments

Simon Glass July 6, 2017, 4:48 a.m. UTC | #1
On 21 June 2017 at 06:42,  <patrice.chotard@st.com> wrote:
> From: Patrice Chotard <patrice.chotard@st.com>
>
> Add reset_release_all() method which Assert/Free an
> array of resets signal that has been previously successfully
> requested by reset_get_by_*()
>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> v9:     _ to avoid confusion, rename reset_assert_all() in reset_release_all()
>           as this function not only assert all resets but also free all of them
>         _ add a check in reset_release_all() to verify if a reset has been previously
>           requested before asserting and freeing it.
> v8:     _ none
> v7:     _ none
> v6:     _ none
> v5:     _ none
> v4:     _ add reset_assert_all() method as suggested by Marek Vasut
>           and Simon Glass
>
>  drivers/reset/reset-uclass.c | 25 +++++++++++++++++++++++++
>  include/reset.h              | 18 ++++++++++++++++++
>  2 files changed, 43 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index 4fd82b9..307a297 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -42,6 +42,7 @@  int reset_get_by_index(struct udevice *dev, int index,
 
 	debug("%s(dev=%p, index=%d, reset_ctl=%p)\n", __func__, dev, index,
 	      reset_ctl);
+	reset_ctl->dev = NULL;
 
 	ret = dev_read_phandle_with_args(dev, "resets", "#reset-cells", 0,
 					  index, &args);
@@ -87,6 +88,7 @@  int reset_get_by_name(struct udevice *dev, const char *name,
 
 	debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
 	      reset_ctl);
+	reset_ctl->dev = NULL;
 
 	index = dev_read_stringlist_search(dev, "reset-names", name);
 	if (index < 0) {
@@ -133,6 +135,29 @@  int reset_deassert(struct reset_ctl *reset_ctl)
 	return ops->rst_deassert(reset_ctl);
 }
 
+int reset_release_all(struct reset_ctl *reset_ctl, int count)
+{
+	int i, ret;
+
+	for (i = 0; i < count; i++) {
+		debug("%s(reset_ctl[%d]=%p)\n", __func__, i, &reset_ctl[i]);
+
+		/* check if reset has been previously requested */
+		if (!reset_ctl[i].dev)
+			continue;
+
+		ret = reset_assert(&reset_ctl[i]);
+		if (ret)
+			return ret;
+
+		ret = reset_free(&reset_ctl[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(reset) = {
 	.id		= UCLASS_RESET,
 	.name		= "reset",
diff --git a/include/reset.h b/include/reset.h
index 4f2e35f..7185ade 100644
--- a/include/reset.h
+++ b/include/reset.h
@@ -144,6 +144,18 @@  int reset_assert(struct reset_ctl *reset_ctl);
  */
 int reset_deassert(struct reset_ctl *reset_ctl);
 
+/**
+ * reset_release_all - Assert/Free an array of previously requested resets.
+ *
+ * For each reset contained in the reset array, this function will check if
+ * reset has been previously requested and then will assert and free it.
+ *
+ * @reset_ctl:	A reset struct array that was previously successfully
+ *		requested by reset_get_by_*().
+ * @count	Number of reset contained in the array
+ * @return 0 if OK, or a negative error code.
+ */
+int reset_release_all(struct reset_ctl *reset_ctl, int count);
 #else
 static inline int reset_get_by_index(struct udevice *dev, int index,
 				     struct reset_ctl *reset_ctl)
@@ -171,6 +183,12 @@  static inline int reset_deassert(struct reset_ctl *reset_ctl)
 {
 	return 0;
 }
+
+static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
+{
+	return 0;
+}
+
 #endif
 
 #endif