linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] usb: meson: fix shared reset control use
@ 2020-12-01 19:00 Amjad Ouled-Ameur
  2020-12-01 19:00 ` [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use Amjad Ouled-Ameur
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Amjad Ouled-Ameur @ 2020-12-01 19:00 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Amjad Ouled-Ameur, Philipp Zabel, Felipe Balbi, Jerome Brunet,
	linux-amlogic, linux-kernel, linux-usb

This patchset fixes a usb suspend warning seen on the libretech-cc by
using reset_control_rearm() call of the reset framework API. 
This call allows a reset consummer to release the reset line even when 
just triggered so that it may be triggered again by other reset
consummers.

reset_control_(de)assert() calls are called, in some meson usb drivers, 
on a shared reset line when reset_control_reset has been used. This is not
allowed by the reset framework.

Finally the meson usb drivers are updated to use this new call, which
solves the suspend issue addressed by the previous reverted 
commit 7a410953d1fb ("usb: dwc3: meson-g12a: fix shared reset control
use").

changes since v1: [1]
* Moved reset_control_rearm after clk_disable_unprepare to clean things up
in reverse order of initialization for phy: amlogic: meson drivers

IMPORTANT:
This patchset depends on this patch [2], it adds reset_control_rearm() call
to the reset framework API, it has been approved by the maintainer, and
will be applied to reset/next

There is currently an immutable branch with it [3]

[1]: https://lore.kernel.org/lkml/20201113000508.14702-1-aouledameur@baylib
re.com/
[2]: https://lore.kernel.org/lkml/20201112230043.28987-1-aouledameur@baylib
re.com/
[3]: git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

Amjad Ouled-Ameur (3):
  phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use
  usb: dwc3: meson-g12a: fix shared reset control use
  phy: amlogic: meson8b-usb2: fix shared reset control use

 drivers/phy/amlogic/phy-meson-gxl-usb2.c |  5 ++++-
 drivers/phy/amlogic/phy-meson8b-usb2.c   |  4 ++++
 drivers/usb/dwc3/dwc3-meson-g12a.c       | 19 +++++++++++++------
 3 files changed, 21 insertions(+), 7 deletions(-)

-- 
2.17.1


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

* [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use
  2020-12-01 19:00 [PATCH v2 0/3] usb: meson: fix shared reset control use Amjad Ouled-Ameur
@ 2020-12-01 19:00 ` Amjad Ouled-Ameur
  2020-12-05 21:53   ` Martin Blumenstingl
  2020-12-01 19:00 ` [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use Amjad Ouled-Ameur
  2020-12-01 19:01 ` [PATCH v2 3/3] phy: amlogic: meson8b-usb2: " Amjad Ouled-Ameur
  2 siblings, 1 reply; 8+ messages in thread
From: Amjad Ouled-Ameur @ 2020-12-01 19:00 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Amjad Ouled-Ameur, Philipp Zabel, Felipe Balbi, Jerome Brunet,
	linux-amlogic, linux-kernel, linux-usb

Use reset_control_rearm() call if an error occurs in case
phy_meson_gxl_usb2_init() fails after reset() has been called ; or in case
phy_meson_gxl_usb2_exit() is called i.e the resource is no longer used
and the reset line may be triggered again by other devices.

reset_control_rearm() keeps use of triggered_count sane in the reset
framework. Therefore, use of reset_control_reset() on shared reset line
should be balanced with reset_control_rearm().

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
changes since v1: [1]
* Moved reset_control_rearm after clk_disable_unprepare to clean things up
in reverse order of initialization for phy: amlogic: meson drivers

IMPORTANT:
This patchset depends on this patch [2], it adds reset_control_rearm() call
to the reset framework API, it has been approved by the maintainer, and
will be applied to reset/next

There is currently an immutable branch with it [3]

[1]: https://lore.kernel.org/lkml/20201113000508.14702-1-aouledameur@baylibre.com/
[2]: https://lore.kernel.org/lkml/20201112230043.28987-1-aouledameur@baylibre.com/
[3]: git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

 drivers/phy/amlogic/phy-meson-gxl-usb2.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/amlogic/phy-meson-gxl-usb2.c b/drivers/phy/amlogic/phy-meson-gxl-usb2.c
index 43ec9bf24abf..1ddf5e5e4184 100644
--- a/drivers/phy/amlogic/phy-meson-gxl-usb2.c
+++ b/drivers/phy/amlogic/phy-meson-gxl-usb2.c
@@ -114,8 +114,10 @@ static int phy_meson_gxl_usb2_init(struct phy *phy)
 		return ret;
 
 	ret = clk_prepare_enable(priv->clk);
-	if (ret)
+	if (ret) {
+		reset_control_rearm(priv->reset);
 		return ret;
+	}
 
 	return 0;
 }
@@ -125,6 +127,7 @@ static int phy_meson_gxl_usb2_exit(struct phy *phy)
 	struct phy_meson_gxl_usb2_priv *priv = phy_get_drvdata(phy);
 
 	clk_disable_unprepare(priv->clk);
+	reset_control_rearm(priv->reset);
 
 	return 0;
 }
-- 
2.17.1


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

* [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use
  2020-12-01 19:00 [PATCH v2 0/3] usb: meson: fix shared reset control use Amjad Ouled-Ameur
  2020-12-01 19:00 ` [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use Amjad Ouled-Ameur
@ 2020-12-01 19:00 ` Amjad Ouled-Ameur
  2020-12-05 21:42   ` Martin Blumenstingl
  2020-12-01 19:01 ` [PATCH v2 3/3] phy: amlogic: meson8b-usb2: " Amjad Ouled-Ameur
  2 siblings, 1 reply; 8+ messages in thread
From: Amjad Ouled-Ameur @ 2020-12-01 19:00 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Amjad Ouled-Ameur, Philipp Zabel, Kevin Hilman, Jerome Brunet,
	linux-amlogic, linux-kernel, linux-usb

reset_control_(de)assert() calls are called on a shared reset line when
reset_control_reset has been used. This is not allowed by the reset
framework.

Use reset_control_rearm() call in suspend() and remove() as a way to state
that the resource is no longer used, hence the shared reset line
may be triggered again by other devices. Use reset_control_rearm() also in
case probe fails after reset() has been called.

reset_control_rearm() keeps use of triggered_count sane in the reset
framework, use of reset_control_reset() on shared reset line should be
balanced with reset_control_rearm().

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
changes since v1: [1]
* None for this driver

IMPORTANT:
This patchset depends on this patch [2], it adds reset_control_rearm() call
to the reset framework API, it has been approved by the maintainer, and
will be applied to reset/next

There is currently an immutable branch with it [3]

[1]: https://lore.kernel.org/lkml/20201113000508.14702-1-aouledameur@baylibre.com/
[2]: https://lore.kernel.org/lkml/20201112230043.28987-1-aouledameur@baylibre.com/
[3]: git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

 drivers/usb/dwc3/dwc3-meson-g12a.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c
index 417e05381b5d..3fec8f591c93 100644
--- a/drivers/usb/dwc3/dwc3-meson-g12a.c
+++ b/drivers/usb/dwc3/dwc3-meson-g12a.c
@@ -750,7 +750,7 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 
 	ret = dwc3_meson_g12a_get_phys(priv);
 	if (ret)
-		goto err_disable_clks;
+		goto err_rearm;
 
 	ret = priv->drvdata->setup_regmaps(priv, base);
 	if (ret)
@@ -759,7 +759,7 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 	if (priv->vbus) {
 		ret = regulator_enable(priv->vbus);
 		if (ret)
-			goto err_disable_clks;
+			goto err_rearm;
 	}
 
 	/* Get dr_mode */
@@ -772,13 +772,13 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 
 	ret = priv->drvdata->usb_init(priv);
 	if (ret)
-		goto err_disable_clks;
+		goto err_rearm;
 
 	/* Init PHYs */
 	for (i = 0 ; i < PHY_COUNT ; ++i) {
 		ret = phy_init(priv->phys[i]);
 		if (ret)
-			goto err_disable_clks;
+			goto err_rearm;
 	}
 
 	/* Set PHY Power */
@@ -816,6 +816,9 @@ static int dwc3_meson_g12a_probe(struct platform_device *pdev)
 	for (i = 0 ; i < PHY_COUNT ; ++i)
 		phy_exit(priv->phys[i]);
 
+err_rearm:
+	reset_control_rearm(priv->reset);
+
 err_disable_clks:
 	clk_bulk_disable_unprepare(priv->drvdata->num_clks,
 				   priv->drvdata->clks);
@@ -843,6 +846,8 @@ static int dwc3_meson_g12a_remove(struct platform_device *pdev)
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);
 
+	reset_control_rearm(priv->reset);
+
 	clk_bulk_disable_unprepare(priv->drvdata->num_clks,
 				   priv->drvdata->clks);
 
@@ -883,7 +888,7 @@ static int __maybe_unused dwc3_meson_g12a_suspend(struct device *dev)
 		phy_exit(priv->phys[i]);
 	}
 
-	reset_control_assert(priv->reset);
+	reset_control_rearm(priv->reset);
 
 	return 0;
 }
@@ -893,7 +898,9 @@ static int __maybe_unused dwc3_meson_g12a_resume(struct device *dev)
 	struct dwc3_meson_g12a *priv = dev_get_drvdata(dev);
 	int i, ret;
 
-	reset_control_deassert(priv->reset);
+	ret = reset_control_reset(priv->reset);
+	if (ret)
+		return ret;
 
 	ret = priv->drvdata->usb_init(priv);
 	if (ret)
-- 
2.17.1


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

* [PATCH v2 3/3] phy: amlogic: meson8b-usb2: fix shared reset control use
  2020-12-01 19:00 [PATCH v2 0/3] usb: meson: fix shared reset control use Amjad Ouled-Ameur
  2020-12-01 19:00 ` [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use Amjad Ouled-Ameur
  2020-12-01 19:00 ` [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use Amjad Ouled-Ameur
@ 2020-12-01 19:01 ` Amjad Ouled-Ameur
  2020-12-05 21:40   ` Martin Blumenstingl
  2 siblings, 1 reply; 8+ messages in thread
From: Amjad Ouled-Ameur @ 2020-12-01 19:01 UTC (permalink / raw)
  To: Kevin Hilman
  Cc: Amjad Ouled-Ameur, Philipp Zabel, Felipe Balbi, Jerome Brunet,
	linux-amlogic, linux-kernel, linux-usb

Use reset_control_rearm() call if an error occurs in case
phy_meson8b_usb2_power_on() fails after reset() has been called, or in
case phy_meson8b_usb2_power_off() is called i.e the resource is no longer
used and the reset line may be triggered again by other devices.

reset_control_rearm() keeps use of triggered_count sane in the reset
framework, use of reset_control_reset() on shared reset line should
be balanced with reset_control_rearm().

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reported-by: Jerome Brunet <jbrunet@baylibre.com>
---
changes since v1: [1]
* Moved reset_control_rearm after clk_disable_unprepare to clean things up
in reverse order of initialization for phy: amlogic: meson drivers

IMPORTANT:
This patchset depends on this patch [2], it adds reset_control_rearm() call
to the reset framework API, it has been approved by the maintainer, and
will be applied to reset/next

There is currently an immutable branch with it [3]

[1]: https://lore.kernel.org/lkml/20201113000508.14702-1-aouledameur@baylibre.com/
[2]: https://lore.kernel.org/lkml/20201112230043.28987-1-aouledameur@baylibre.com/
[3]: git://git.pengutronix.de/git/pza/linux.git reset/shared-retrigger

 drivers/phy/amlogic/phy-meson8b-usb2.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/phy/amlogic/phy-meson8b-usb2.c b/drivers/phy/amlogic/phy-meson8b-usb2.c
index 03c061dd5f0d..651eec41a896 100644
--- a/drivers/phy/amlogic/phy-meson8b-usb2.c
+++ b/drivers/phy/amlogic/phy-meson8b-usb2.c
@@ -154,6 +154,7 @@ static int phy_meson8b_usb2_power_on(struct phy *phy)
 	ret = clk_prepare_enable(priv->clk_usb_general);
 	if (ret) {
 		dev_err(&phy->dev, "Failed to enable USB general clock\n");
+		reset_control_rearm(priv->reset);
 		return ret;
 	}
 
@@ -161,6 +162,7 @@ static int phy_meson8b_usb2_power_on(struct phy *phy)
 	if (ret) {
 		dev_err(&phy->dev, "Failed to enable USB DDR clock\n");
 		clk_disable_unprepare(priv->clk_usb_general);
+		reset_control_rearm(priv->reset);
 		return ret;
 	}
 
@@ -199,6 +201,7 @@ static int phy_meson8b_usb2_power_on(struct phy *phy)
 				dev_warn(&phy->dev, "USB ID detect failed!\n");
 				clk_disable_unprepare(priv->clk_usb);
 				clk_disable_unprepare(priv->clk_usb_general);
+				reset_control_rearm(priv->reset);
 				return -EINVAL;
 			}
 		}
@@ -218,6 +221,7 @@ static int phy_meson8b_usb2_power_off(struct phy *phy)
 
 	clk_disable_unprepare(priv->clk_usb);
 	clk_disable_unprepare(priv->clk_usb_general);
+	reset_control_rearm(priv->reset);
 
 	return 0;
 }
-- 
2.17.1


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

* Re: [PATCH v2 3/3] phy: amlogic: meson8b-usb2: fix shared reset control use
  2020-12-01 19:01 ` [PATCH v2 3/3] phy: amlogic: meson8b-usb2: " Amjad Ouled-Ameur
@ 2020-12-05 21:40   ` Martin Blumenstingl
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2020-12-05 21:40 UTC (permalink / raw)
  To: Amjad Ouled-Ameur
  Cc: Kevin Hilman, Felipe Balbi, linux-usb, linux-kernel,
	Philipp Zabel, linux-amlogic, Jerome Brunet

On Tue, Dec 1, 2020 at 8:02 PM Amjad Ouled-Ameur
<aouledameur@baylibre.com> wrote:
>
> Use reset_control_rearm() call if an error occurs in case
> phy_meson8b_usb2_power_on() fails after reset() has been called, or in
> case phy_meson8b_usb2_power_off() is called i.e the resource is no longer
> used and the reset line may be triggered again by other devices.
>
> reset_control_rearm() keeps use of triggered_count sane in the reset
> framework, use of reset_control_reset() on shared reset line should
> be balanced with reset_control_rearm().
>
> Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
> Reported-by: Jerome Brunet <jbrunet@baylibre.com>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Tested-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> #
on Odroid-C1+

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

* Re: [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use
  2020-12-01 19:00 ` [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use Amjad Ouled-Ameur
@ 2020-12-05 21:42   ` Martin Blumenstingl
  2020-12-10 17:35     ` Amjad Ouled-Ameur
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Blumenstingl @ 2020-12-05 21:42 UTC (permalink / raw)
  To: Amjad Ouled-Ameur
  Cc: Felipe Balbi, Kevin Hilman, linux-usb, linux-kernel,
	Philipp Zabel, linux-amlogic, Jerome Brunet

Hello Amjad,

On Tue, Dec 1, 2020 at 8:01 PM Amjad Ouled-Ameur
<aouledameur@baylibre.com> wrote:
>
> reset_control_(de)assert() calls are called on a shared reset line when
> reset_control_reset has been used. This is not allowed by the reset
> framework.
>
> Use reset_control_rearm() call in suspend() and remove() as a way to state
> that the resource is no longer used, hence the shared reset line
> may be triggered again by other devices. Use reset_control_rearm() also in
> case probe fails after reset() has been called.
>
> reset_control_rearm() keeps use of triggered_count sane in the reset
> framework, use of reset_control_reset() on shared reset line should be
> balanced with reset_control_rearm().
I think this should be updated after [0] is applied
The goto from that patch needs to use err_rearm from this patch.


Best regards,
Martin


[0] https://patchwork.kernel.org/project/linux-usb/patch/20201111095256.10477-1-zhengzengkai@huawei.com/

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

* Re: [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use
  2020-12-01 19:00 ` [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use Amjad Ouled-Ameur
@ 2020-12-05 21:53   ` Martin Blumenstingl
  0 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2020-12-05 21:53 UTC (permalink / raw)
  To: Amjad Ouled-Ameur
  Cc: Kevin Hilman, Felipe Balbi, linux-usb, linux-kernel,
	Philipp Zabel, linux-amlogic, Jerome Brunet

On Tue, Dec 1, 2020 at 8:01 PM Amjad Ouled-Ameur
<aouledameur@baylibre.com> wrote:
>
> Use reset_control_rearm() call if an error occurs in case
> phy_meson_gxl_usb2_init() fails after reset() has been called ; or in case
> phy_meson_gxl_usb2_exit() is called i.e the resource is no longer used
> and the reset line may be triggered again by other devices.
>
> reset_control_rearm() keeps use of triggered_count sane in the reset
> framework. Therefore, use of reset_control_reset() on shared reset line
> should be balanced with reset_control_rearm().
>
> Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
> Reported-by: Jerome Brunet <jbrunet@baylibre.com>
Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

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

* Re: [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use
  2020-12-05 21:42   ` Martin Blumenstingl
@ 2020-12-10 17:35     ` Amjad Ouled-Ameur
  0 siblings, 0 replies; 8+ messages in thread
From: Amjad Ouled-Ameur @ 2020-12-10 17:35 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: Felipe Balbi, Kevin Hilman, linux-usb, linux-kernel,
	Philipp Zabel, linux-amlogic, Jerome Brunet

Hi Martin


On 05/12/2020 22:42, Martin Blumenstingl wrote:

>    
> Hello Amjad,
>
> On Tue, Dec 1, 2020 at 8:01 PM Amjad Ouled-Ameur
> <aouledameur@baylibre.com> wrote:
>    
>> reset_control_(de)assert() calls are called on a shared reset line when
>> reset_control_reset has been used. This is not allowed by the reset
>> framework.
>>
>> Use reset_control_rearm() call in suspend() and remove() as a way to state
>> that the resource is no longer used, hence the shared reset line
>> may be triggered again by other devices. Use reset_control_rearm() also in
>> case probe fails after reset() has been called.
>>
>> reset_control_rearm() keeps use of triggered_count sane in the reset
>> framework, use of reset_control_reset() on shared reset line should be
>> balanced with reset_control_rearm().
>    
> I think this should be updated after [0] is applied
> The goto from that patch needs to use err_rearm from this patch.
>
>
> Best regards,
> Martin
>
>
> [0] https://patchwork.kernel.org/project/linux-usb/patch/20201111095256.10477-1-zhengzengkai@huawei.com/

Thank you Martin for reviewing this patchset.

I have reviewed the patch you mentioned, and I think as well that
we should use 'err_rearm' instead of 'err_disable_clks' to
cleanup things properly in case setup_regmaps fails.


Best,

Amjad


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

end of thread, other threads:[~2020-12-10 17:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 19:00 [PATCH v2 0/3] usb: meson: fix shared reset control use Amjad Ouled-Ameur
2020-12-01 19:00 ` [PATCH v2 1/3] phy: amlogic: phy-meson-gxl-usb2: fix shared reset controller use Amjad Ouled-Ameur
2020-12-05 21:53   ` Martin Blumenstingl
2020-12-01 19:00 ` [PATCH v2 2/3] usb: dwc3: meson-g12a: fix shared reset control use Amjad Ouled-Ameur
2020-12-05 21:42   ` Martin Blumenstingl
2020-12-10 17:35     ` Amjad Ouled-Ameur
2020-12-01 19:01 ` [PATCH v2 3/3] phy: amlogic: meson8b-usb2: " Amjad Ouled-Ameur
2020-12-05 21:40   ` Martin Blumenstingl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).