All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amjad Ouled-Ameur <aouledameur@baylibre.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Amjad Ouled-Ameur <aouledameur@baylibre.com>,
	linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org,
	linux-usb@vger.kernel.org, Jerome Brunet <jbrunet@baylibre.com>
Subject: [PATCH] reset: Add reset controller API
Date: Thu,  1 Oct 2020 15:27:58 +0200	[thread overview]
Message-ID: <20201001132758.12280-1-aouledameur@baylibre.com> (raw)

The current reset framework API does not allow to release what is done by
reset_control_reset(), IOW decrement triggered_count. Add the new
reset_control_resettable() call to do so.

When reset_control_reset() has been called once, the counter
triggered_count, in the reset framework, is incremented i.e the resource
under the reset is in-use and the reset should not be done again.
reset_control_resettable() would be the way to state that the resource is 
no longer used and, that from the caller's perspective, the reset can be 
fired again if necessary.

This patch will fix a usb suspend warning seen on the libretech-cc
related to the shared reset line. This warning was addressed by the 
previously reverted commit 7a410953d1fb ("usb: dwc3: meson-g12a: fix shared
reset control use")

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/reset/core.c  | 57 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  1 +
 2 files changed, 58 insertions(+)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 01c0c7aa835c..53653d4b55c4 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -207,6 +207,19 @@ static int reset_control_array_reset(struct reset_control_array *resets)
 	return 0;
 }
 
+static int reset_control_array_resettable(struct reset_control_array *resets)
+{
+	int ret, i;
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		ret = reset_control_resettable(resets->rstc[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int reset_control_array_assert(struct reset_control_array *resets)
 {
 	int ret, i;
@@ -324,6 +337,50 @@ int reset_control_reset(struct reset_control *rstc)
 }
 EXPORT_SYMBOL_GPL(reset_control_reset);
 
+/**
+ * reset_control_resettable - decrements triggered_count of the controlled device
+ * @rstc: reset controller
+ *
+ * On a shared reset line the actual reset pulse is only triggered once for the
+ * lifetime of the reset_control instance, except if this function is used.
+ * In fact, It decrements triggered_count that makes sure of not allowing
+ * a reset if triggered_count is not null.
+ *
+ * This is a no-op in case triggered_count is already null i.e shared reset line
+ * is ready to be triggered.
+ *
+ * Consumers must not use reset_control_(de)assert on shared reset lines when
+ * reset_control_reset has been used.
+ *
+ * If rstc is NULL it is an optional clear and the function will just
+ * return 0.
+ */
+int reset_control_resettable(struct reset_control *rstc)
+{
+	if (!rstc)
+		return 0;
+
+	if (WARN_ON(IS_ERR(rstc)))
+		return -EINVAL;
+
+	if (reset_control_is_array(rstc))
+		return reset_control_array_resettable(rstc_to_array(rstc));
+
+	if (rstc->shared) {
+		if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+			return -EINVAL;
+
+		if (atomic_read(&rstc->triggered_count) > 0)
+			atomic_dec(&rstc->triggered_count);
+	} else {
+		if (!rstc->acquired)
+			return -EPERM;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(reset_control_resettable);
+
 /**
  * reset_control_assert - asserts the reset line
  * @rstc: reset controller
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 05aa9f440f48..ffa447d0d1d6 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -13,6 +13,7 @@ struct reset_control;
 #ifdef CONFIG_RESET_CONTROLLER
 
 int reset_control_reset(struct reset_control *rstc);
+int reset_control_resettable(struct reset_control *rstc);
 int reset_control_assert(struct reset_control *rstc);
 int reset_control_deassert(struct reset_control *rstc);
 int reset_control_status(struct reset_control *rstc);
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Amjad Ouled-Ameur <aouledameur@baylibre.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Jerome Brunet <jbrunet@baylibre.com>,
	linux-amlogic@lists.infradead.org, linux-usb@vger.kernel.org,
	Amjad Ouled-Ameur <aouledameur@baylibre.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] reset: Add reset controller API
Date: Thu,  1 Oct 2020 15:27:58 +0200	[thread overview]
Message-ID: <20201001132758.12280-1-aouledameur@baylibre.com> (raw)

The current reset framework API does not allow to release what is done by
reset_control_reset(), IOW decrement triggered_count. Add the new
reset_control_resettable() call to do so.

When reset_control_reset() has been called once, the counter
triggered_count, in the reset framework, is incremented i.e the resource
under the reset is in-use and the reset should not be done again.
reset_control_resettable() would be the way to state that the resource is 
no longer used and, that from the caller's perspective, the reset can be 
fired again if necessary.

This patch will fix a usb suspend warning seen on the libretech-cc
related to the shared reset line. This warning was addressed by the 
previously reverted commit 7a410953d1fb ("usb: dwc3: meson-g12a: fix shared
reset control use")

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/reset/core.c  | 57 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  1 +
 2 files changed, 58 insertions(+)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 01c0c7aa835c..53653d4b55c4 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -207,6 +207,19 @@ static int reset_control_array_reset(struct reset_control_array *resets)
 	return 0;
 }
 
+static int reset_control_array_resettable(struct reset_control_array *resets)
+{
+	int ret, i;
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		ret = reset_control_resettable(resets->rstc[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int reset_control_array_assert(struct reset_control_array *resets)
 {
 	int ret, i;
@@ -324,6 +337,50 @@ int reset_control_reset(struct reset_control *rstc)
 }
 EXPORT_SYMBOL_GPL(reset_control_reset);
 
+/**
+ * reset_control_resettable - decrements triggered_count of the controlled device
+ * @rstc: reset controller
+ *
+ * On a shared reset line the actual reset pulse is only triggered once for the
+ * lifetime of the reset_control instance, except if this function is used.
+ * In fact, It decrements triggered_count that makes sure of not allowing
+ * a reset if triggered_count is not null.
+ *
+ * This is a no-op in case triggered_count is already null i.e shared reset line
+ * is ready to be triggered.
+ *
+ * Consumers must not use reset_control_(de)assert on shared reset lines when
+ * reset_control_reset has been used.
+ *
+ * If rstc is NULL it is an optional clear and the function will just
+ * return 0.
+ */
+int reset_control_resettable(struct reset_control *rstc)
+{
+	if (!rstc)
+		return 0;
+
+	if (WARN_ON(IS_ERR(rstc)))
+		return -EINVAL;
+
+	if (reset_control_is_array(rstc))
+		return reset_control_array_resettable(rstc_to_array(rstc));
+
+	if (rstc->shared) {
+		if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+			return -EINVAL;
+
+		if (atomic_read(&rstc->triggered_count) > 0)
+			atomic_dec(&rstc->triggered_count);
+	} else {
+		if (!rstc->acquired)
+			return -EPERM;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(reset_control_resettable);
+
 /**
  * reset_control_assert - asserts the reset line
  * @rstc: reset controller
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 05aa9f440f48..ffa447d0d1d6 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -13,6 +13,7 @@ struct reset_control;
 #ifdef CONFIG_RESET_CONTROLLER
 
 int reset_control_reset(struct reset_control *rstc);
+int reset_control_resettable(struct reset_control *rstc);
 int reset_control_assert(struct reset_control *rstc);
 int reset_control_deassert(struct reset_control *rstc);
 int reset_control_status(struct reset_control *rstc);
-- 
2.17.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

             reply	other threads:[~2020-10-01 13:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 13:27 Amjad Ouled-Ameur [this message]
2020-10-01 13:27 ` [PATCH] reset: Add reset controller API Amjad Ouled-Ameur
2020-10-01 13:55 ` Amjad Ouled-Ameur
2020-10-01 13:55   ` Amjad Ouled-Ameur
2020-10-02 11:14   ` Philipp Zabel
2020-10-02 11:14     ` Philipp Zabel
2020-11-12 13:44     ` Amjad Ouled-Ameur
2020-11-12 13:44       ` Amjad Ouled-Ameur
2020-10-02 23:00 ` Kevin Hilman
2020-10-02 23:00   ` Kevin Hilman
2020-11-12 13:14   ` Amjad Ouled-Ameur
2020-11-12 13:14     ` Amjad Ouled-Ameur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201001132758.12280-1-aouledameur@baylibre.com \
    --to=aouledameur@baylibre.com \
    --cc=jbrunet@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.