Skip to contentSkip to conversation

reset: make shared pulsed reset controls re-triggerable

PATCH Applied Amjad Ouled-Ameur 3 participants 7 messages Nov 12, 2020 – Nov 16, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 reset: make shared pulsed reset controls re-triggerable

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_rearm() 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_rearm() 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.

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

[0] https://lore.kernel.org/lkml/[email protected]

 drivers/reset/core.c  | 73 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  1 +
 2 files changed, 74 insertions(+)
drivers/reset/core.c +73 -0
index a2df88e90011..34e89aa0fb5e 100644
@@ -208,6 +208,39 @@ static int reset_control_array_reset(struct reset_control_array *resets)
 	return 0;
 }
 
+static int reset_control_array_rearm(struct reset_control_array *resets)
+{
+	struct reset_control *rstc;
+	int i;
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		rstc = resets->rstc[i];
+
+		if (!rstc)
+			continue;
+
+		if (WARN_ON(IS_ERR(rstc)))
+			return -EINVAL;
+
+		if (rstc->shared) {
+			if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+				return -EINVAL;
+		} else {
+			if (!rstc->acquired)
+				return -EPERM;
+		}
+	}
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		rstc = resets->rstc[i];
+
+		if (rstc && rstc->shared)
+			WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0);
+	}
+
+	return 0;
+}
+
 static int reset_control_array_assert(struct reset_control_array *resets)
 {
 	int ret, i;
@@ -325,6 +358,46 @@ int reset_control_reset(struct reset_control *rstc)
 }
 EXPORT_SYMBOL_GPL(reset_control_reset);
 
+/**
+ * reset_control_rearm - allow shared reset line to be re-triggered"
+ * @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 call is used.
+ *
+ * Calls to this function must be balanced with calls to reset_control_reset,
+ * a warning is thrown in case triggered_count ever dips below 0.
+ *
+ * Consumers must not use reset_control_(de)assert on shared reset lines when
+ * reset_control_reset or reset_control_rearm have been used.
+ *
+ * If rstc is NULL the function will just return 0.
+ */
+int reset_control_rearm(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_rearm(rstc_to_array(rstc));
+
+	if (rstc->shared) {
+		if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+			return -EINVAL;
+
+		WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0);
+	} else {
+		if (!rstc->acquired)
+			return -EPERM;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(reset_control_rearm);
+
 /**
  * reset_control_assert - asserts the reset line
  * @rstc: reset controller
include/linux/reset.h +1 -0
index 05aa9f440f48..439fec7112a9 100644
@@ -13,6 +13,7 @@ struct reset_control;
 #ifdef CONFIG_RESET_CONTROLLER
 
 int reset_control_reset(struct reset_control *rstc);
+int reset_control_rearm(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);
Signature · 1 line
2.17.1
#1 lore raw

Please find in this patchset [0] a use case of the reset_control_rearm() call on some of meson usb drivers:

[0] https://lore.kernel.org/lkml/[email protected]/

Quoted 131 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

[0] https://lore.kernel.org/lkml/[email protected]

  drivers/reset/core.c  | 73 +++++++++++++++++++++++++++++++++++++++++++
  include/linux/reset.h |  1 +
  2 files changed, 74 insertions(+)
drivers/reset/core.c +73 -0
index a2df88e90011..34e89aa0fb5e 100644
@@ -208,6 +208,39 @@ static int reset_control_array_reset(struct reset_control_array *resets)
  	return 0;
  }
 
+static int reset_control_array_rearm(struct reset_control_array *resets)
+{
+	struct reset_control *rstc;
+	int i;
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		rstc = resets->rstc[i];
+
+		if (!rstc)
+			continue;
+
+		if (WARN_ON(IS_ERR(rstc)))
+			return -EINVAL;
+
+		if (rstc->shared) {
+			if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+				return -EINVAL;
+		} else {
+			if (!rstc->acquired)
+				return -EPERM;
+		}
+	}
+
+	for (i = 0; i < resets->num_rstcs; i++) {
+		rstc = resets->rstc[i];
+
+		if (rstc && rstc->shared)
+			WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0);
+	}
+
+	return 0;
+}
+
  static int reset_control_array_assert(struct reset_control_array *resets)
  {
  	int ret, i;
@@ -325,6 +358,46 @@ int reset_control_reset(struct reset_control *rstc)
  }
  EXPORT_SYMBOL_GPL(reset_control_reset);
 
+/**
+ * reset_control_rearm - allow shared reset line to be re-triggered"
+ * @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 call is used.
+ *
+ * Calls to this function must be balanced with calls to reset_control_reset,
+ * a warning is thrown in case triggered_count ever dips below 0.
+ *
+ * Consumers must not use reset_control_(de)assert on shared reset lines when
+ * reset_control_reset or reset_control_rearm have been used.
+ *
+ * If rstc is NULL the function will just return 0.
+ */
+int reset_control_rearm(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_rearm(rstc_to_array(rstc));
+
+	if (rstc->shared) {
+		if (WARN_ON(atomic_read(&rstc->deassert_count) != 0))
+			return -EINVAL;
+
+		WARN_ON(atomic_dec_return(&rstc->triggered_count) < 0);
+	} else {
+		if (!rstc->acquired)
+			return -EPERM;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(reset_control_rearm);
+
  /**
   * reset_control_assert - asserts the reset line
   * @rstc: reset controller
include/linux/reset.h +1 -0
index 05aa9f440f48..439fec7112a9 100644
@@ -13,6 +13,7 @@ struct reset_control;
  #ifdef CONFIG_RESET_CONTROLLER
 
  int reset_control_reset(struct reset_control *rstc);
+int reset_control_rearm(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);
maintainer Applied
#2 lore raw
In reply to Amjad Ouled-Ameur
Quoted 13 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

Quoted 8 lines

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

Thank you, applied to reset/next.

regards
Philipp

reviewer
#3 lore raw
Quoted 23 lines · Philipp Zabel
Quoted 13 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

Quoted 8 lines

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

Quoted 1 line

Thank you, applied to reset/next.

Hi Philipp,

Would it be possible to get an immutable branch/tag with this ? It would allow to move forward on the USB side, without waiting for the next rc1.

Thx
Jerome

Quoted 3 lines

regards
Philipp

maintainer
#4 lore raw
Quoted 25 lines · Jerome Brunet
Quoted 23 lines · Philipp Zabel
Quoted 21 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

Quoted 7 lines
Quoted 1 line

Thank you, applied to reset/next.

Hi Philipp,

Would it be possible to get an immutable branch/tag with this ? It would allow to move forward on the USB side, without waiting for the next rc1.

Here you go,

The following changes since commit 3650b228f83adda7e5ee532e2b90429c03f7b9ec:

Linux 5.10-rc1 (2020-10-25 15:14:11 -0700)

are available in the Git repository at:

git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

for you to fetch changes up to 557acb3d2cd9c82de19f944f6cc967a347735385:

reset: make shared pulsed reset controls re-triggerable (2020-11-16 17:05:28 +0100)

----------------------------------------------------------------
Amjad Ouled-Ameur (1):
reset: make shared pulsed reset controls re-triggerable

 drivers/reset/core.c  | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  1 +
 2 files changed, 74 insertions(+)

regards
Philipp

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

reviewer
#5 lore raw
Quoted 48 lines · Philipp Zabel
Quoted 25 lines · Jerome Brunet
Quoted 23 lines · Philipp Zabel
Quoted 21 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

Quoted 7 lines
Quoted 1 line

Thank you, applied to reset/next.

Hi Philipp,

Would it be possible to get an immutable branch/tag with this ? It would allow to move forward on the USB side, without waiting for the next rc1.

Here you go,

The following changes since commit 3650b228f83adda7e5ee532e2b90429c03f7b9ec:

Linux 5.10-rc1 (2020-10-25 15:14:11 -0700)

are available in the Git repository at:

git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

for you to fetch changes up to 557acb3d2cd9c82de19f944f6cc967a347735385:

reset: make shared pulsed reset controls re-triggerable (2020-11-16 17:05:28 +0100)

Quoted 8 lines

----------------------------------------------------------------
Amjad Ouled-Ameur (1):
reset: make shared pulsed reset controls re-triggerable

 drivers/reset/core.c  | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/reset.h |  1 +
 2 files changed, 74 insertions(+)

Thx Philipp !

Quoted 2 lines

regards
Philipp

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

#6 lore raw
In reply to Philipp Zabel
Quoted 22 lines · Philipp Zabel
Quoted 13 lines · Amjad Ouled-Ameur

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_rearm() 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_rearm() 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.

Quoted 8 lines

---
Change since v1: [0]
* Renamed the new call from reset_control_(array_)resettable to reset_control_(array_)rearm
* Open-coded reset_control_array_rearm to check for errors before decrementing triggered_count because we cannot roll back in case an error occurs while decrementing one of the rstc.
* Reworded the new call's description.

Quoted 4 lines

Thank you, applied to reset/next.

regards
Philipp

Thank you for reviewing and approving my patch !

Furthermore, I think your idea of open coding reset_control_array_rearm was accurate, and should be also applied to reset_control_array_reset() and reset_control_array_(de)assert()

What do you think ?

In case you agree it is necessary to do so, I can work out an upcoming patchset to fix this matter.

Best,
Amjad